@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap');

/* ── Design tokens (16-bit Retro) ── */
:root {
  --bg: #000000;
  --surface: #0d1410f2;
  --surface-2: #141c17;
  --border: #27382d;
  --border-2: #3a5443;
  --text: #e2f0e6;
  --text-dim: #94b0a0;
  --muted: #526b5d;
  --accent: #39ff14;
  /* classic neon terminal green */
  --accent-dim: #39ff1444;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ff003c;
  --cyan: #0ea5e9;

  /* Hard retro borders, no radius */
  --radius: 0px;
  --radius-lg: 0px;

  --font-data: 'VT323', monospace;
  --font-body: 'VT323', monospace;
  --font-brand: 'Press Start 2P', monospace;
}

/* ── Reset ── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background: var(--bg) url('bg.png') center/cover fixed;
  color: var(--text);
  min-height: 100vh;
  font-size: 18px;
  /* VT323 needs to be larger to be readable */
  line-height: 1.5;
  border-top: 4px solid var(--accent);
  cursor: crosshair;
  overflow-x: hidden;
}

/* dark overlay to ensure text readability over the image */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  pointer-events: none;
  z-index: 0;
}

/* ── Loading Screen ── */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #000000;
  /* Pure black for loading */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.1s ease, visibility 0.1s ease;
  /* Fast fade */
}

.loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
}

.loading-video {
  width: 800px;
  max-width: 90vw;
  max-height: 70vh;
  object-fit: cover;
  border: 4px solid var(--accent);
  box-shadow: 8px 8px 0px var(--accent-dim);
  image-rendering: pixelated;
}

.loading-text {
  font-family: var(--font-brand);
  color: var(--accent);
  margin-top: 32px;
  font-size: 14px;
  letter-spacing: 0.1em;
  text-shadow: 2px 2px 0px var(--border);
  animation: blink 1s step-start infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* ── Disclaimer Screen ── */
.disclaimer-screen {
  position: fixed;
  inset: 0;
  z-index: 9998;
  /* Just below loading screen */
  background: rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  text-align: center;
  transition: opacity 1s ease, visibility 1s ease;
}

.disclaimer-screen.hidden {
  opacity: 0;
  visibility: hidden;
}

.disclaimer-content {
  position: relative;
  max-width: 800px;
  background: rgba(0, 0, 0, 0.85);
  border: 4px solid var(--accent);
  padding: 40px;
  box-shadow: 12px 12px 0px var(--accent-dim);
}

.btn-close-disc {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--bg);
  color: var(--accent);
  border: 2px solid var(--accent);
  font-family: var(--font-brand);
  font-size: 16px;
  padding: 8px 12px;
  cursor: pointer;
}

.btn-close-disc:hover {
  background: var(--accent);
  color: var(--bg);
}

.disclaimer-text {
  font-family: var(--font-data);
  font-size: 24px;
  color: #ff9800;
  line-height: 1.6;
  margin-bottom: 40px;
}

.disclaimer-buttons {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 40px;
}

.disclaimer-buttons button {
  font-family: var(--font-brand);
  cursor: pointer;
  border: 4px solid;
  transition: transform 0.1s, box-shadow 0.1s;
}

.disclaimer-buttons button:active {
  transform: translate(4px, 4px);
  box-shadow: none !important;
}

.btn-ack {
  font-size: 12px;
  padding: 16px 24px;
  background: var(--bg);
  color: var(--red);
  border-color: var(--red);
  box-shadow: 4px 4px 0px rgba(255, 0, 60, 0.4);
}

.btn-ack:hover {
  background: var(--red);
  color: #fff;
}

.btn-ignore {
  font-size: 28px;
  /* Significantly bigger */
  padding: 24px 48px;
  background: var(--accent);
  color: var(--bg);
  border-color: var(--bg);
  box-shadow: 8px 8px 0px var(--accent-dim);
}

.btn-ignore:hover {
  background: #fff;
  color: var(--accent);
}

.meme-reaction {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 30px;
}

#meme-text {
  font-family: var(--font-brand);
  color: var(--accent);
  font-size: 32px;
  text-shadow: 4px 4px 0px var(--border);
}

#meme-gif-container {
  width: 500px;
  max-width: 90vw;
  border: 4px solid var(--accent);
  box-shadow: 8px 8px 0px var(--accent-dim);
  background: #000;
}

/* ── Header ── */
header {
  position: sticky;
  top: 0;
  z-index: 200;
  background: var(--bg);
  border-bottom: 2px solid var(--accent);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: 0 4px 0px rgba(57, 255, 20, 0.3);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.brand-name {
  font-family: var(--font-brand);
  font-size: 16px;
  color: var(--accent);
  line-height: 1;
  text-shadow: 2px 2px 0px var(--border-2);
}

.brand-sub {
  font-family: var(--font-data);
  font-size: 16px;
  color: var(--muted);
  text-transform: uppercase;
}

/* Freshness badge */
.freshness-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-data);
  font-size: 16px;
  padding: 2px 8px;
  border: 2px solid currentColor;
  background: #000;
  cursor: default;
}

.freshness-badge::before {
  content: '';
  width: 8px;
  height: 8px;
  background: currentColor;
  flex-shrink: 0;
}

.freshness-badge.fresh {
  color: var(--green);
}

.freshness-badge.fresh::before {
  animation: blink 1s step-start infinite;
}

.freshness-badge.stale {
  color: var(--amber);
}

.freshness-badge.very-stale {
  color: var(--red);
}

.freshness-badge.unknown {
  color: var(--muted);
}

/* stale banner */
.stale-banner {
  background: var(--red);
  color: #fff;
  border-left: 4px solid #8b0000;
  padding: 9px 20px;
  font-family: var(--font-brand);
  font-size: 10px;
  letter-spacing: 0.05em;
}

/* ── Tab bar ── */
.tab-bar {
  position: sticky;
  top: 60px;
  z-index: 150;
  display: flex;
  gap: 0;
  background: var(--bg);
  border-bottom: 2px solid var(--border);
  padding: 0 20px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tab-bar::-webkit-scrollbar {
  display: none;
}

.tab-bar button {
  background: none;
  border: none;
  border-bottom: 4px solid transparent;
  padding: 12px 18px 8px;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--font-brand);
  font-size: 10px;
  transition: none;
  /* Instant hover for retro feel */
  white-space: nowrap;
}

.tab-bar button:hover {
  color: var(--text);
  background: var(--border);
}

.tab-bar button[aria-selected="true"] {
  color: var(--bg);
  background: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Tab panels ── */
.tab-panel {
  display: none;
  padding: 20px 24px 40px;
  position: relative;
  z-index: 1;
}

.tab-panel.active {
  display: block;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 2px solid var(--border-2);
  padding: 0;
  margin-bottom: 24px;
  overflow: hidden;
  box-shadow: 6px 6px 0px rgba(0, 0, 0, 0.8);
}

.card-title {
  font-family: var(--font-brand);
  font-size: 10px;
  color: var(--bg);
  background: var(--border-2);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-title::before {
  content: '>';
  color: var(--accent);
}

/* ── Tables ── */
.card>div {
  padding: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
}

th {
  font-family: var(--font-brand);
  text-align: left;
  color: var(--accent);
  font-size: 8px;
  padding: 12px 14px;
  border-bottom: 2px solid var(--border-2);
  white-space: nowrap;
  background: #000;
  cursor: pointer;
}

th:hover {
  color: #fff;
  background: var(--border-2);
}

td {
  padding: 8px 14px;
  border-bottom: 1px dashed var(--border);
  vertical-align: middle;
  font-family: var(--font-data);
  font-size: 18px;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: var(--border-2);
  color: #fff;
}

/* rank column */
td:first-child {
  color: var(--muted);
  width: 32px;
  text-align: right;
}

/* symbol column bold */
td:nth-child(2) b {
  font-family: var(--font-brand);
  font-size: 11px;
  color: var(--accent);
}

/* ── Score bar ── */
.score-bar-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 110px;
}

.score-bar-wrap span {
  font-weight: bold;
  min-width: 30px;
}

.score-bar {
  flex: 1;
  height: 12px;
  background: #000;
  border: 1px solid var(--border-2);
  max-width: 90px;
}

.score-bar-fill {
  height: 100%;
  background: var(--accent);
  /* Segmented look using repeating linear gradient */
  background-image: repeating-linear-gradient(to right,
      transparent,
      transparent 2px,
      rgba(0, 0, 0, 0.5) 2px,
      rgba(0, 0, 0, 0.5) 4px);
}

/* ── Chips ── */
.chip {
  display: inline-block;
  font-family: var(--font-brand);
  font-size: 8px;
  padding: 4px 6px;
  border: 1px solid currentColor;
}

.chip-green {
  background: #000;
  color: var(--green);
}

.chip-red {
  background: #000;
  color: var(--red);
}

.chip-amber {
  background: #000;
  color: var(--amber);
}

.chip-gray {
  background: #000;
  color: var(--muted);
}

/* ── AI Research ── */
.ai-entry {
  border-bottom: 2px solid var(--border-2);
}

.ai-entry:last-child {
  border-bottom: none;
}

.ai-entry-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
}

.ai-entry-header:hover {
  background: var(--border-2);
}

.ai-entry-header b {
  font-family: var(--font-brand);
  font-size: 12px;
  color: var(--accent);
}

.ai-entry-body {
  display: none;
  padding: 16px 20px;
  background: #000;
  border-top: 2px solid var(--border-2);
}

.ai-entry.open .ai-entry-body {
  display: block;
}

.ai-field-label {
  font-family: var(--font-brand);
  font-size: 8px;
  color: var(--accent);
  margin-top: 14px;
  margin-bottom: 6px;
}

.ai-field-label:first-child {
  margin-top: 0;
}

/* ── Watchlist table ── */
#panel-watchlist .card td:nth-child(2) {
  /* last price */
  font-family: var(--font-data);
  font-size: 18px;
}

/* ── History leaderboard ── */
.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  border-bottom: 1px dashed var(--border);
}

.leaderboard-row:last-child {
  border-bottom: none;
}

.leaderboard-row:hover {
  background: var(--border-2);
}

.lb-rank {
  font-family: var(--font-brand);
  font-size: 10px;
  width: 24px;
  color: var(--muted);
  text-align: right;
  flex-shrink: 0;
}

.lb-symbol {
  font-family: var(--font-brand);
  font-size: 12px;
  color: var(--accent);
  min-width: 64px;
  flex-shrink: 0;
}

.lb-bar {
  flex: 1;
  height: 12px;
  background: #000;
  border: 1px solid var(--border-2);
}

.lb-bar-fill {
  height: 100%;
  background: var(--cyan);
  background-image: repeating-linear-gradient(to right,
      transparent,
      transparent 2px,
      rgba(0, 0, 0, 0.5) 2px,
      rgba(0, 0, 0, 0.5) 4px);
}

.lb-count {
  font-family: var(--font-data);
  font-size: 16px;
  color: var(--text);
  min-width: 56px;
  text-align: right;
}

/* ── Alerts feed ── */
.alert-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  border-bottom: 1px dashed var(--border);
}

.alert-row:last-child {
  border-bottom: none;
}

.alert-row:hover {
  background: var(--border-2);
}

.alert-ts {
  color: var(--muted);
  min-width: 140px;
  flex-shrink: 0;
}

.alert-type {
  min-width: 120px;
  flex-shrink: 0;
}

.alert-symbol {
  font-family: var(--font-brand);
  font-size: 12px;
  color: var(--accent);
  min-width: 56px;
}

.alert-ctx {
  color: var(--text-dim);
}

/* alert filters */
.filter-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 14px 16px;
  background: #000;
  border-bottom: 2px solid var(--border-2);
}

.filter-btn {
  font-family: var(--font-brand);
  font-size: 8px;
  padding: 8px 12px;
  border: 2px solid var(--border-2);
  background: #000;
  color: var(--muted);
  cursor: pointer;
}

.filter-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
}

/* ── Empty & error states ── */
.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 56px 0;
  font-family: var(--font-brand);
  font-size: 10px;
  line-height: 1.8;
}

.error-banner {
  background: var(--bg);
  border: 4px solid var(--red);
  padding: 14px 24px;
  margin: 16px 24px;
  color: var(--red);
  box-shadow: 4px 4px 0px rgba(255, 0, 60, 0.3);
}

.error-banner button {
  margin-top: 10px;
  padding: 8px 16px;
  background: var(--red);
  color: #fff;
  border: 2px solid #fff;
  cursor: pointer;
  font-family: var(--font-brand);
  font-size: 10px;
}

.error-banner button:hover {
  background: #fff;
  color: var(--red);
}

/* ── Footer ── */
/* ── Claude Ranking panel ── */

.ranking-card {
  background: var(--surface);
  border: 2px solid var(--accent);
  margin: 16px;
  padding: 16px;
}

.ranking-header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.ranking-title {
  font-family: var(--font-brand);
  font-size: 11px;
  color: var(--accent);
}

.ranking-meta {
  font-size: 14px;
  color: var(--text-dim);
}

.ranking-tbl td,
.ranking-tbl th {
  max-width: 280px;
  white-space: normal;
  word-break: break-word;
  vertical-align: top;
}

.risk-badge {
  font-size: 13px;
  padding: 1px 6px;
  border: 1px solid currentColor;
}

.risk-low  { color: var(--green); }
.risk-med  { color: var(--amber); }
.risk-high { color: var(--red); }

.ranking-notes {
  margin: 14px 0;
  padding: 10px;
  border-left: 3px solid var(--accent-dim);
  color: var(--text-dim);
  font-size: 16px;
  white-space: pre-line;
}

.ranking-gem {
  color: var(--amber);
  font-size: 16px;
  margin: 8px 0;
}

.ranking-footer {
  color: var(--muted);
  font-size: 14px;
  margin-top: 8px;
}

.ranking-actions {
  margin: 12px 16px;
}

footer {
  position: relative;
  z-index: 1;
  padding: 20px 24px;
  text-align: center;
  color: var(--muted);
  background: #000;
  border-top: 2px solid var(--border-2);
  font-family: var(--font-brand);
  font-size: 8px;
  line-height: 1.8;
}

.footer-disclaimer {
  font-size: 1.5em;
  color: #ff9800;
  line-height: 1.8;
  display: block;
  margin-top: 16px;
}

/* ── Write UI — gear, modals, toast, buttons ── */

.gear-btn {
  margin-left: auto;
  background: none;
  border: 2px solid var(--border-2);
  color: var(--muted);
  font-size: 18px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.gear-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.action-btn {
  font-family: var(--font-brand);
  font-size: 10px;
  padding: 10px 18px;
  background: var(--bg);
  color: var(--accent);
  border: 2px solid var(--accent);
  cursor: pointer;
  box-shadow: 4px 4px 0px var(--accent-dim);
  white-space: nowrap;
}

.action-btn:hover {
  background: var(--accent);
  color: var(--bg);
}

.action-btn:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

.tbl-actions {
  white-space: nowrap;
}

.tbl-btn {
  background: none;
  border: 1px solid var(--border-2);
  color: var(--muted);
  cursor: pointer;
  padding: 3px 7px;
  font-size: 13px;
  margin-right: 2px;
}

.tbl-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tbl-btn-danger:hover {
  border-color: var(--red);
  color: var(--red);
}

/* Modal overlay */
.modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-box {
  background: var(--bg);
  border: 4px solid var(--accent);
  box-shadow: 8px 8px 0px var(--accent-dim);
  padding: 32px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-title {
  font-family: var(--font-brand);
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.modal-label {
  font-family: var(--font-data);
  font-size: 17px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-input {
  font-family: var(--font-data);
  font-size: 18px;
  background: var(--surface-2);
  border: 2px solid var(--border-2);
  color: var(--text);
  padding: 8px 12px;
  width: 100%;
}

.modal-input:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.modal-btn {
  font-family: var(--font-brand);
  font-size: 10px;
  padding: 10px 16px;
  background: var(--bg);
  color: var(--muted);
  border: 2px solid var(--border-2);
  cursor: pointer;
}

.modal-btn:hover {
  color: var(--text);
  border-color: var(--text);
}

.modal-btn-primary {
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 3px 3px 0px var(--accent-dim);
}

.modal-btn-primary:hover {
  background: var(--accent);
  color: var(--bg);
}

.modal-btn-danger {
  color: var(--red);
  border-color: var(--red);
}

.modal-btn-danger:hover {
  background: var(--red);
  color: #fff;
}

.modal-confirm-text {
  font-family: var(--font-data);
  font-size: 20px;
  color: var(--text-dim);
}

/* Toast */
#cmd-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 20000;
  font-family: var(--font-data);
  font-size: 18px;
  padding: 12px 20px;
  border: 2px solid var(--border-2);
  background: var(--surface-2);
  color: var(--text);
  max-width: 380px;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

#cmd-toast.cmd-toast-visible {
  opacity: 1;
  transform: translateY(0);
}

#cmd-toast.cmd-toast-ok {
  border-color: var(--accent);
  color: var(--accent);
}

#cmd-toast.cmd-toast-error {
  border-color: var(--red);
  color: var(--red);
}

#cmd-toast.cmd-toast-info {
  border-color: var(--amber);
  color: var(--amber);
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: #000;
  border-left: 2px solid var(--border-2);
}

::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border: 2px solid #000;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* ── Responsive ── */

/* iOS Safari: background-attachment:fixed causes jank */
@supports (-webkit-touch-callout: none) {
  body {
    background-attachment: scroll;
  }
}

@media (max-width: 680px) {
  header {
    padding: 0 10px;
    gap: 10px;
    height: 52px;
  }

  .brand-name {
    font-size: 11px;
  }

  .brand-sub {
    display: none;
  }

  .freshness-badge {
    font-size: 13px;
    padding: 2px 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
  }

  .tab-panel {
    padding: 12px 10px 32px;
  }

  .tab-bar {
    padding: 0 4px;
    top: 52px;
  }

  .tab-bar button {
    padding: 10px 10px 6px;
    font-size: 8px;
  }

  td,
  th {
    padding: 6px 8px;
  }

  .score-bar {
    display: none;
  }

  /* Alert rows: stack on mobile */
  .alert-row {
    flex-wrap: wrap;
    gap: 6px;
  }

  .alert-ts {
    min-width: unset;
    font-size: 14px;
    width: 100%;
  }

  .alert-type {
    min-width: unset;
  }

  /* Toast: full-width on mobile */
  #cmd-toast {
    left: 12px;
    right: 12px;
    bottom: 16px;
    max-width: unset;
    font-size: 16px;
  }

  /* Modal: tighter padding */
  .modal {
    padding: 12px;
  }

  .modal-box {
    padding: 20px;
  }

  /* Disclaimer */
  .disclaimer-screen {
    padding: 12px;
  }

  .disclaimer-content {
    padding: 20px;
    box-shadow: 6px 6px 0px var(--accent-dim);
  }

  .disclaimer-text {
    font-size: 15px;
    margin-bottom: 20px;
  }

  .disclaimer-buttons {
    flex-direction: column-reverse;
    gap: 12px;
  }

  .btn-ignore {
    font-size: 20px;
    padding: 14px 20px;
    width: 100%;
  }

  .btn-ack {
    font-size: 10px;
    padding: 12px 16px;
    width: 100%;
  }

  #meme-text {
    font-size: 20px;
    text-align: center;
  }

  #meme-gif-container {
    width: 100%;
  }

  .footer-disclaimer {
    font-size: 1em;
  }

  /* Action buttons: wrap on mobile */
  .action-btn {
    font-size: 9px;
    padding: 8px 12px;
  }
}