/* HEDGED — terminal parody theme.
   Dark only, by design (a trading terminal). No webfonts, no CDN.
   Readability pass: larger type, higher contrast, left-aligned copy, ≤ ~76ch lines. */

:root {
  --bg: #0a0e12;            /* page + chart surface (palette validated against this) */
  --panel: #10161d;
  --panel-2: #131b24;
  --border: #26364a;
  --amber: #ffb000;         /* brand / chrome ink */
  --amber-dim: #b08a20;
  --ink: #f2f0ec;           /* primary body text */
  --ink-2: #c0c9d2;         /* secondary */
  --ink-3: #8b96a2;         /* muted (axis labels) */
  --grid: #1a222c;          /* hairline gridlines */
  --baseline: #2c3640;
  --up: #0ca30c;            /* P&L up (text + marks) */
  --down: #ff5c57;          /* P&L down text */
  --down-mark: #e66767;     /* P&L down marks */
  --warn: #fab219;
  --critical: #d03b3b;
  --series-you: #c98500;    /* validated categorical: you / picking */
  --series-spx: #3987e5;    /* market / S&P */
  --series-monkey: #199e70; /* monkey benchmark */
  --series-theme: #d55181;  /* theme factor */
  --paper: #f4f0e6;         /* newsletter interludes */
  --paper-ink: #1c1a15;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --serif: Georgia, "Times New Roman", serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 16px;
  line-height: 1.55;
  overflow: hidden;
}

/* ---------- screens ---------- */
.screen { display: none; height: 100vh; flex-direction: column; overflow: hidden; }
.screen.active { display: flex; }
.screen-scroll { overflow-y: auto; flex: 1; }

/* ---------- generic chrome ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; row-gap: 4px;
  flex-wrap: wrap;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex: 0 0 auto;
}
.topbar .daycount { white-space: nowrap; }
.topbar .fncode { color: var(--amber); letter-spacing: 0.12em; font-weight: 700; }
.topbar .fncode .go { color: var(--ink-2); font-weight: 400; }
.topbar .spacer { flex: 1; }
.topbar .daycount { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.topbar .speed-label { color: var(--ink-3); font-size: 12px; letter-spacing: 0.14em; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-height: 0;
}
.panel-header {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--amber);
  font-size: 12.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  display: flex; align-items: center; gap: 8px;
  flex: 0 0 auto;
}
.panel-header .right { margin-left: auto; color: var(--ink-3); letter-spacing: 0; text-transform: none; }
.panel-body { padding: 12px; overflow-y: auto; min-height: 0; }

button {
  font-family: var(--mono);
  font-size: 15px;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--border);
  padding: 9px 16px;
  cursor: pointer;
  letter-spacing: 0.06em;
}
button:hover:not(:disabled) { border-color: var(--amber); color: var(--amber); }
button:focus-visible { outline: 2px solid var(--amber); outline-offset: 1px; }
button:disabled { opacity: 0.4; cursor: default; }
.btn-primary {
  background: var(--amber);
  color: #0a0e12;
  border-color: var(--amber);
  font-weight: 700;
  letter-spacing: 0.12em;
}
.btn-primary:hover:not(:disabled) { background: #ffc23d; color: #0a0e12; }
.btn-ghost { background: transparent; }
.btn-small { padding: 4px 10px; font-size: 12.5px; }

/* ---------- title screen ---------- */
/* everything flows: centered while it fits, scrollable when it doesn't (no overlaps on small screens) */
#screen-title {
  align-items: center; justify-content: flex-start; position: relative; gap: 18px;
  overflow-y: auto; padding: 0 16px;
}
#screen-title .logo {
  margin-top: auto; padding-top: 24px;
  font-size: 64px; font-weight: 700; letter-spacing: 0.28em;
  color: var(--amber);
  text-shadow: 0 0 24px rgba(255, 176, 0, 0.35);
}
#screen-title .tagline { color: var(--ink-2); max-width: 58ch; text-align: left; }
#screen-title .menu { display: flex; gap: 12px; margin-top: 12px; flex-wrap: wrap; justify-content: center; }
#screen-title .disclaimer {
  margin-top: auto; padding-top: 12px;
  color: var(--ink-3); font-size: 13px; text-align: left; max-width: 76ch;
}
.site-foot { color: var(--ink-3); font-size: 13px; max-width: 76ch; width: 100%; text-align: left; }
.site-foot a { color: var(--ink-2); text-underline-offset: 2px; }
.site-foot a:hover, .site-foot a:focus-visible { color: var(--amber); }
.site-foot a:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.modal .site-foot { margin-top: 18px; padding-top: 10px; border-top: 1px solid var(--border); }
.scanlines::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,0.22) 0 1px, transparent 1px 3px);
}
.level-menu { display: grid; grid-template-columns: repeat(3, minmax(200px, 1fr)); gap: 8px; margin-top: 10px; max-width: 780px; width: 100%; }
.level-menu button { text-align: left; font-size: 13.5px; padding: 8px 10px; }
.level-menu button .lvl-no { color: var(--amber); margin-right: 6px; }
.level-menu button:disabled .lvl-no { color: var(--ink-3); }

/* ---------- ticker tape ---------- */
.ticker {
  position: sticky; bottom: 0; flex: 0 0 34px;
  align-self: stretch; margin: 0 -16px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  overflow: hidden; white-space: nowrap;
  height: 34px; line-height: 34px;
  font-size: 13.5px;
}
.ticker-inner { display: inline-block; padding-left: 100%; animation: tickerscroll 45s linear infinite; }
.ticker.paused .ticker-inner { animation-play-state: paused; }
@keyframes tickerscroll { to { transform: translateX(-100%); } }
.ticker .tk { margin-right: 28px; color: var(--ink-2); }
.ticker .tk b { color: var(--ink); font-weight: 400; }
.ticker .tk .d-up { color: var(--up); }
.ticker .tk .d-dn { color: var(--down); }
@media (prefers-reduced-motion: reduce) {
  .ticker-inner { animation: none; padding-left: 0; }
}

/* ---------- level screen layout ---------- */
#screen-level .layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-rows: 1fr auto;
  gap: 10px; padding: 10px;
  flex: 1; min-height: 0;
}
/* expanded picking mode: wide side column for comfortable card selection */
#screen-level .layout.side-wide { grid-template-columns: minmax(500px, 46%) 1fr; }
#screen-level .side { grid-row: 1 / 3; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
#screen-level .main { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
#screen-level .statrow { display: flex; gap: 10px; flex: 0 0 auto; }

/* stat tiles */
.stat-tile {
  flex: 1;
  background: var(--panel); border: 1px solid var(--border);
  padding: 8px 12px;
}
.stat-tile .label { font-size: 11.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-3); }
.stat-tile .value { font-size: 25px; font-weight: 600; color: var(--ink); }
.stat-tile .value.pos { color: var(--up); }
.stat-tile .value.neg { color: var(--down); }
.stat-tile .sub { font-size: 13px; color: var(--ink-2); }

/* how-to block (per-level beginner steps) */
.howto {
  padding: 10px 12px;
  font-size: 14px; color: var(--ink-2);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.howto b { color: var(--ink); }

/* pick list */
.pick-list { display: flex; flex-direction: column; gap: 6px; }
.pick-list.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pick-card {
  border: 1px solid var(--border); background: var(--panel-2);
  padding: 9px 10px; cursor: pointer; position: relative;
}
.pick-card:hover { border-color: var(--amber-dim); }
.pick-card.picked { border-color: var(--amber); background: #1a1a10; }
.pick-card.picked-short { border-color: var(--down-mark); background: #1d1113; }
.pick-card .tick { color: var(--amber); font-weight: 700; }
.pick-card .nm { color: var(--ink); }
.pick-card .blurb { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.pick-card .flag { float: right; margin: 0 0 4px 8px; font-size: 11.5px; letter-spacing: 0.08em; color: var(--amber); }
.pick-card.picked-short .flag { color: var(--down); }

/* sliders & dials */
.control-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.control-row label { font-size: 12.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-2); }
.control-row .val { color: var(--amber); font-weight: 700; }
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; background: var(--baseline); outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; background: var(--amber); border: 2px solid var(--bg);
  cursor: pointer; border-radius: 50%;
}
input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--amber); }
input[type="range"]:disabled::-webkit-slider-thumb { background: var(--ink-3); }

/* character speech */
.speech {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 10px; font-size: 14.5px;
  text-align: left;
}
.speech .avatar { font-size: 30px; line-height: 1; flex: 0 0 auto; filter: saturate(0.9); }
.speech .who { color: var(--amber); font-size: 11.5px; letter-spacing: 0.14em; text-transform: uppercase; }
.speech .txt { color: var(--ink-2); }
.speech .txt b, .speech .txt strong { color: var(--ink); font-weight: 600; }
.speech .txt p { margin: 6px 0; }
.speech .txt p:first-child { margin-top: 0; }

/* toasts */
#toasts {
  position: fixed; right: 16px; top: 158px; z-index: 60;
  display: flex; flex-direction: column; gap: 8px; max-width: 380px;
}
.toast {
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--amber);
  padding: 9px 12px; font-size: 13.5px; color: var(--ink-2);
  text-align: left;
  animation: toastin 0.25s ease-out;
}
.toast b { color: var(--ink); }
.toast.warn { border-left-color: var(--warn); }
.toast.bad { border-left-color: var(--critical); }
@keyframes toastin { from { transform: translateX(20px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---------- charts ---------- */
.chart-empty {
  display: flex; align-items: center; justify-content: center;
  height: 100%; min-height: 200px;
  color: var(--ink-3); letter-spacing: 0.14em; font-size: 14px;
  text-align: center; padding: 20px;
}
.chart-box { position: relative; flex: 1; min-height: 110px; display: flex; flex-direction: column; }
.chart-box canvas { width: 100%; height: 100%; display: block; }
.chart-canvas-wrap { position: relative; flex: 1; min-height: 0; }
.chart-legend {
  display: flex; gap: 16px; flex-wrap: wrap;
  padding: 7px 12px 0; font-size: 13px; color: var(--ink-2);
  flex: 0 0 auto; align-items: center;
}
.chart-legend .key { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .key .line { width: 14px; height: 0; border-top: 2.5px solid; border-radius: 1px; }
.chart-legend .key .swatch { width: 11px; height: 11px; border-radius: 2px; }
.chart-tooltip {
  position: absolute; pointer-events: none; z-index: 40;
  background: #060a0e; border: 1px solid var(--border);
  padding: 7px 10px; font-size: 13px; display: none; min-width: 150px;
}
.chart-tooltip .tt-x { color: var(--ink-3); margin-bottom: 3px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.chart-tooltip .tt-row .line { width: 10px; height: 0; border-top: 2.5px solid; flex: 0 0 auto; }
.chart-tooltip .tt-row .v { color: var(--ink); font-weight: 600; margin-left: auto; font-variant-numeric: tabular-nums; }
.chart-tooltip .tt-row .n { color: var(--ink-2); }
.chart-table { overflow: auto; max-height: 220px; border-top: 1px solid var(--border); }
.chart-table table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.chart-table th, .chart-table td { padding: 3px 10px; text-align: right; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
.chart-table th:first-child, .chart-table td:first-child { text-align: left; }
.chart-table th { color: var(--ink-3); font-weight: 400; position: sticky; top: 0; background: var(--panel); }

/* ---------- results screen ---------- */
#screen-results .wrap { max-width: 900px; margin: 0 auto; padding: 28px 20px 60px; display: flex; flex-direction: column; gap: 18px; }
.result-headline { font-size: 27px; color: var(--ink); text-align: left; max-width: 76ch; }
.result-headline .pos { color: var(--up); } .result-headline .neg { color: var(--down); }
.insight {
  border: 1px solid var(--amber); background: #161206;
  padding: 14px 16px; color: var(--ink);
  text-align: left; max-width: 76ch;
}
.insight .tag { color: var(--amber); font-size: 11.5px; letter-spacing: 0.2em; }
.debrief { color: var(--ink-2); text-align: left; max-width: 76ch; }
.debrief b, .debrief strong { color: var(--ink); }
.debrief p { margin: 8px 0; }

/* ---------- interlude (parody newsletter, paper) ---------- */
#screen-interlude { background: #241f18; align-items: center; justify-content: center; }
.paper {
  background: var(--paper); color: var(--paper-ink);
  font-family: var(--serif); font-size: 16.5px; line-height: 1.65;
  max-width: 660px; max-height: 86vh; overflow-y: auto;
  padding: 36px 44px; box-shadow: 0 12px 40px rgba(0,0,0,0.6);
  position: relative;
  text-align: left;
}
.paper .masthead { font-size: 23px; font-weight: 700; letter-spacing: 0.04em; border-bottom: 3px double #1c1a15; padding-bottom: 6px; }
.paper .masthead small { display: block; font-size: 12px; font-weight: 400; letter-spacing: 0.14em; color: #6b6357; }
.paper h3 { margin: 14px 0 6px; font-size: 18px; }
.paper p { margin: 9px 0; }
.paper .fn { font-size: 13.5px; color: #6b6357; border-top: 1px solid #c9c1b2; margin-top: 16px; padding-top: 8px; }
.paper .fn sup { color: #a33; }
.paper sup { color: #a33; cursor: default; }
.paper .actions { margin-top: 20px; display: flex; justify-content: flex-end; }
.paper .actions button { font-family: var(--mono); }

/* rubber stamps */
.stamp {
  display: inline-block;
  border: 2.5px solid var(--critical); color: var(--critical);
  font-family: var(--mono); font-size: 12px; font-weight: 700; letter-spacing: 0.16em;
  padding: 2px 8px; transform: rotate(-4deg);
  text-transform: uppercase; border-radius: 3px;
  opacity: 0.95; white-space: nowrap;
}
.stamp.ok { border-color: var(--up); color: var(--up); }
.stamp.warn { border-color: var(--warn); color: var(--warn); }
.stamp.neutral { border-color: var(--ink-3); color: var(--ink-3); }
.stamp.big { font-size: 21px; padding: 6px 16px; border-width: 4px; }

/* ---------- glossary chips + help ---------- */
.term {
  color: var(--ink);
  border-bottom: 1px dashed var(--amber-dim);
  cursor: help; position: relative;
}
.term:hover, .term:focus-visible { color: var(--amber); outline: none; }
#glossary-pop {
  position: fixed; z-index: 80; max-width: 360px;
  background: #060a0e; border: 1px solid var(--amber-dim);
  padding: 10px 12px; font-size: 14px; display: none;
  text-align: left;
}
#glossary-pop .t { color: var(--amber); letter-spacing: 0.1em; text-transform: uppercase; font-size: 11.5px; }
#glossary-pop .d { color: var(--ink-2); margin-top: 4px; }
#glossary-pop .e { color: var(--ink-3); margin-top: 4px; font-style: italic; }

/* modal (help / gates / sources) */
.modal-veil {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(4, 6, 8, 0.8);
  display: none; align-items: center; justify-content: center; padding: 24px;
}
.modal-veil.open { display: flex; }
.modal {
  background: var(--panel); border: 1px solid var(--amber-dim);
  max-width: 760px; width: 100%; max-height: 84vh;
  display: flex; flex-direction: column;
  text-align: left;
}
.modal .panel-body { overflow-y: auto; }
.modal .panel-body p { max-width: 76ch; }
.modal .modal-actions { padding: 12px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; flex: 0 0 auto; }

/* gate quiz */
.gate-q { font-size: 18px; color: var(--ink); margin-bottom: 14px; text-align: left; max-width: 72ch; }
.gate-opts { display: flex; flex-direction: column; gap: 8px; }
.gate-opts button { text-align: left; }
.gate-feedback { margin-top: 12px; font-size: 14.5px; color: var(--ink-2); display: none; text-align: left; }
.gate-feedback.ok { color: var(--up); display: block; }
.gate-feedback.retry { color: var(--warn); display: block; }

/* glossary list in help modal */
.gloss-list dt { color: var(--amber); margin-top: 10px; letter-spacing: 0.08em; }
.gloss-list dd { color: var(--ink-2); margin-left: 0; font-size: 14.5px; max-width: 72ch; }
.gloss-list dd .e { color: var(--ink-3); font-style: italic; }

/* sources panel */
.source-item { border-bottom: 1px solid var(--grid); padding: 12px 0; font-size: 14.5px; text-align: left; }
.source-item .claim { color: var(--ink); max-width: 76ch; }
.source-item .srcs { margin-top: 4px; font-size: 13.5px; color: var(--ink-2); }
.source-item .srcs a { color: var(--series-spx); text-decoration: none; }
.source-item .srcs a:hover { text-decoration: underline; }
.source-item .muted { max-width: 76ch; }

/* briefing card */
.brief-card { max-width: 760px; margin: 0 auto; padding: 32px 20px; display: flex; flex-direction: column; gap: 14px; text-align: left; }
.brief-card h2 { color: var(--amber); letter-spacing: 0.14em; font-size: 20px; }
.brief-card .obj { border-left: 3px solid var(--amber); padding: 8px 12px; background: var(--panel-2); color: var(--ink); max-width: 76ch; }
.brief-card p { color: var(--ink-2); max-width: 76ch; }
.brief-card p b, .brief-card p strong { color: var(--ink); }

/* overlay banner for the big shock moment */
#shock-banner {
  position: fixed; inset: 0; z-index: 65; display: none;
  align-items: center; justify-content: center; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(208,59,59,0.16), transparent 70%);
}
#shock-banner.show { display: flex; }
#shock-banner .inner {
  font-size: 32px; font-weight: 700; letter-spacing: 0.2em; color: var(--critical);
  border: 4px solid var(--critical); padding: 14px 30px; transform: rotate(-3deg);
  background: rgba(10, 14, 18, 0.92); text-align: center;
}
#shock-banner .inner small { display: block; font-size: 14.5px; font-weight: 400; letter-spacing: 0.05em; color: var(--ink-2); margin-top: 6px; }

/* utility */
.pos { color: var(--up); } .neg { color: var(--down); }
.muted { color: var(--ink-3); }
.hidden { display: none !important; }
.mt { margin-top: 12px; }
a { color: var(--series-spx); }

/* narrow fallback */
@media (max-width: 900px) {
  #screen-level .layout, #screen-level .layout.side-wide { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  #screen-level .side { grid-row: auto; max-height: 45vh; overflow-y: auto; }
  /* while picking, give the card list most of the screen */
  #screen-level .layout.side-wide .side { max-height: 78vh; }
  .level-menu { grid-template-columns: 1fr 1fr; }
  #screen-title .logo { font-size: 48px; }
  /* phones: let the level screen scroll so the chart keeps a readable height */
  #screen-level { overflow-y: auto; }
  #screen-level .layout, #screen-level .layout.side-wide { flex: 0 0 auto; grid-template-rows: auto auto auto; }
  #lvl-chart-panel { flex: 0 0 320px !important; min-height: 320px !important; }
  /* one toast at a time, at the bottom, so it never covers the controls */
  #toasts { left: 12px; right: 12px; top: auto; bottom: 12px; max-width: none; }
  #toasts .toast:not(:last-child) { display: none; }
}
