:root {
  --bg: #eaeef2;
  --surface: #ffffff;
  --ink: #10151c;
  --muted: #66727f;
  --line: #dfe5eb;
  --line-strong: #cfd7df;
  --up: #067a57;
  --up-bg: #e4f4ee;
  --down: #b8371f;
  --down-bg: #fbe9e6;
  --tape-bg: #10151c;
  --tape-ink: #e7edf3;
  --pulse: #37d6a0;
  --accent: #0b6cff;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --display: "Space Grotesk", system-ui, -apple-system, sans-serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

/* ---- Signature: market tape ------------------------------------------- */
.tape {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  background: var(--tape-bg);
  color: var(--tape-ink);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  position: sticky;
  top: 0;
  z-index: 10;
}
.tape__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--pulse);
  box-shadow: 0 0 0 0 rgba(55, 214, 160, 0.6);
  animation: pulse 2.2s infinite;
}
.tape__label { font-weight: 600; color: var(--pulse); }
.tape__sep { color: #4a5561; }
.tape__time { color: var(--tape-ink); }
.tape__meta { color: #9aa7b4; }
.tape__spacer { flex: 1; }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(55, 214, 160, 0.55); }
  70%  { box-shadow: 0 0 0 7px rgba(55, 214, 160, 0); }
  100% { box-shadow: 0 0 0 0 rgba(55, 214, 160, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .tape__dot { animation: none; }
}

/* ---- Nav bar ----------------------------------------------------------- */
.nav {
  background: var(--surface);
  border-bottom: 1px solid var(--line-strong);
  position: sticky;
  top: 34px;
  z-index: 9;
}
.nav__inner {
  max-width: 940px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
}
.nav__brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  border-radius: 8px;
  transition: color 0.15s;
}
.nav__brand:hover { color: var(--ink); }
.nav__logo {
  flex-shrink: 0;
  color: var(--accent);
  display: block;
}
.nav__links { display: flex; gap: 4px; }
.nav__link {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}
.nav__link:hover { color: var(--ink); background: #f2f5f8; }
.nav__link.is-active {
  color: var(--ink);
  background: #eef2f6;
  box-shadow: inset 0 -2px 0 0 var(--accent);
}
/* Hamburger button: hidden on desktop, shown in the mobile media query. */
.nav__burger { display: none; }

/* ---- Layout ------------------------------------------------------------ */
.wrap {
  max-width: 940px;
  margin: 0 auto;
  padding: 44px 24px 64px;
}
.crumb { color: var(--accent); text-decoration: none; }
.crumb:hover { text-decoration: underline; }

.masthead { margin-bottom: 28px; }
.masthead__row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.masthead__actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.masthead__actions form { margin: 0; }

/* ---- Buttons ----------------------------------------------------------- */
.btn {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn--danger {
  color: var(--down);
  background: var(--down-bg);
  border-color: #f2c9c1;
}
.btn--danger:hover { background: var(--down); color: #fff; border-color: var(--down); }
.btn--warn {
  color: #8a5a00;
  background: #fbf1dd;
  border-color: #f0dbaa;
}
.btn--warn:hover { background: #b8791a; color: #fff; border-color: #b8791a; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--danger:disabled:hover { background: var(--down-bg); color: var(--down); border-color: #f2c9c1; }
.btn--warn:disabled:hover { background: #fbf1dd; color: #8a5a00; border-color: #f0dbaa; }

/* ---- Exhausted flag ---------------------------------------------------- */
.exhausted-col { text-align: center; width: 96px; }
.flag { display: inline-flex; align-items: center; justify-content: center; }
.flag--on { color: var(--down); }
.flag--off { color: var(--line-strong); font-family: var(--mono); }
.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}
.masthead h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(34px, 6vw, 52px);
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1;
}
.sub {
  margin: 12px 0 0;
  color: var(--muted);
  max-width: 52ch;
  font-size: 14px;
  line-height: 1.5;
}

/* ---- Board (table) ----------------------------------------------------- */
/* Wraps every .board table so it scrolls horizontally instead of overflowing
   the viewport on narrow screens. Padding/negative margin reserve room for the
   table's drop shadow while keeping vertical rhythm unchanged. */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 16px;
  margin-bottom: -16px;
}
.board {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(16, 21, 28, 0.04), 0 12px 28px -20px rgba(16, 21, 28, 0.3);
}

.board thead th {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: left;
  padding: 14px 18px;
  background: #f6f8fa;
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
  user-select: none;
}
.board th.num, .board td.num { text-align: right; font-variant-numeric: tabular-nums; }

.board th.sortable { cursor: pointer; position: relative; }
.board th.sortable:hover { color: var(--ink); }
.board th .arrow {
  display: inline-block;
  width: 0;
  margin-left: 6px;
  opacity: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  transform: translateY(-1px);
}
.board th.sorted-asc .arrow  { opacity: 1; border-bottom: 5px solid var(--ink); }
.board th.sorted-desc .arrow { opacity: 1; border-top: 5px solid var(--ink); }

.board tbody td {
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.board tbody tr:last-child td { border-bottom: none; }
.board tbody tr:hover { background: #f8fafc; }

.rank {
  font-family: var(--mono);
  color: var(--muted);
  font-size: 13px;
  width: 48px;
}
.ticker {
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: 0.01em;
}
.price { font-family: var(--mono); }

.change {
  font-family: var(--mono);
  font-weight: 600;
  width: 130px;
}
.change.up   { color: var(--up); }
.change.down { color: var(--down); }
.change.up::before, .change.down::before { content: ""; }

.time {
  font-family: var(--mono);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

/* ---- Summary cards ----------------------------------------------------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(16, 21, 28, 0.04);
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 1px 2px rgba(16, 21, 28, 0.04), 0 10px 22px -16px rgba(11, 108, 255, 0.5);
}
.card__symbol {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
  letter-spacing: 0.01em;
}
.card--exhausted { border-color: #f2c9c1; }
.card--exhausted:hover { border-color: var(--down); }
.count-head {
  margin: 14px 0 0;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
}
.count-head strong { color: var(--ink); font-size: 15px; }
.count-head__sep { color: var(--line-strong); margin: 0 4px; }

/* ---- Filters ----------------------------------------------------------- */
.filters {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.filters__btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.filters__btn:hover { color: var(--ink); border-color: var(--accent); }
.filters__btn.is-active {
  color: #fff;
  background: var(--ink);
  border-color: var(--ink);
}
.filters__n {
  font-size: 12px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--muted);
}
.filters__btn.is-active .filters__n { background: rgba(255, 255, 255, 0.18); color: #fff; }
.card__count {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
  background: #eef2f6;
  border-radius: 999px;
  padding: 3px 10px;
  min-width: 34px;
  text-align: center;
}
.card:hover .card__count { color: var(--accent); }

/* ---- Snapshots table --------------------------------------------------- */
.wrap--wide { max-width: 1200px; }
.board--snaps { table-layout: fixed; }
.board--snaps .day {
  font-family: var(--mono);
  font-size: 13px;
  white-space: nowrap;
}
.board--snaps .muted-cell { color: var(--muted); }
.board--snaps .summary-cell {
  vertical-align: top;
  white-space: normal;
}
.cell-n {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--muted);
  margin-bottom: 4px;
}
.cell-list {
  display: block;
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink);
  word-break: break-word;
}
.pct-cell {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--up);
  white-space: nowrap;
}

/* ---- Simulation -------------------------------------------------------- */
.warn-note {
  margin: 12px 0 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--down);
}
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(16, 21, 28, 0.04);
}
.stat__label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat__val {
  font-family: var(--display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.stat__val.up, .stat__sub.up { color: var(--up); }
.stat__val.down, .stat__sub.down { color: var(--down); }
.stat__sub { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.section-title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 18px;
  margin: 30px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title__n {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--muted);
}
.muted-inline { color: var(--muted); font-weight: 400; }
.badge {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
}
.badge--tp { color: var(--up); background: var(--up-bg); }
.badge--sl { color: var(--down); background: var(--down-bg); }

/* ---- Empty state ------------------------------------------------------- */
.empty {
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  padding: 48px 28px;
  text-align: center;
}
.empty__title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 20px;
  margin: 0 0 8px;
}
.empty__body { color: var(--muted); margin: 0; }

/* ---- Pagination -------------------------------------------------------- */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 22px;
  flex-wrap: wrap;
}
.pager__btn,
.pager__page {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.pager__pages { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pager__gap {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
  padding: 0 2px;
  user-select: none;
}
.pager__btn:hover,
.pager__page:hover { border-color: var(--accent); color: var(--accent); }
.pager__page.is-current {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
  cursor: default;
}
.pager__btn.is-disabled {
  color: var(--line-strong);
  border-color: var(--line);
  cursor: not-allowed;
}
.pager__btn.is-disabled:hover { color: var(--line-strong); border-color: var(--line); }
.pager__summary {
  text-align: center;
  margin: 12px 0 0;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

/* ---- Footer ------------------------------------------------------------ */
.foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  flex-wrap: wrap;
}
.foot a { color: var(--accent); text-decoration: none; }
.foot a:hover { text-decoration: underline; }

/* ---- Responsive -------------------------------------------------------- */
@media (max-width: 640px) {
  .wrap { padding: 28px 14px 48px; }
  .board thead th, .board tbody td { padding: 11px 12px; }
  .time { font-size: 11px; }
  .board { font-size: 13px; }

  /* Tables: keep intended column widths and scroll horizontally instead of
     crushing. Let the scroll strip run edge-to-edge on phones. */
  .table-scroll { margin-left: -14px; margin-right: -14px; padding-left: 14px; padding-right: 14px; }
  .table-scroll .board { min-width: 560px; }
  .table-scroll .board--snaps { min-width: 720px; }

  /* Nav: collapse links behind a hamburger toggle. */
  .nav__inner { flex-wrap: wrap; padding: 0 14px; min-height: 46px; }
  .nav__burger {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 36px;
    height: 34px;
    padding: 8px 8px;
    border-radius: 8px;
    border: 1px solid var(--line-strong);
    background: var(--surface);
    cursor: pointer;
  }
  .nav__burger span {
    display: block;
    height: 2px;
    width: 100%;
    background: var(--muted);
    border-radius: 2px;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }
  .nav__links {
    display: none;
    flex-basis: 100%;
    flex-direction: column;
    gap: 2px;
    padding-bottom: 10px;
  }
  .nav__toggle:checked ~ .nav__links { display: flex; }
  .nav__link { padding: 11px 12px; font-size: 14px; border-radius: 8px; }

  /* Animate the burger into an X when the menu is open. */
  .nav__toggle:checked ~ .nav__burger span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .nav__toggle:checked ~ .nav__burger span:nth-child(2) { opacity: 0; }
  .nav__toggle:checked ~ .nav__burger span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
