/* ============================================================
   GAME THEORY MASTERY — drafting-paper design system
   Players: row = vermilion (you), col = cobalt (them), eq = gold
   Type: IBM Plex Serif (display) / Sans (body) / Mono (data)
   ============================================================ */

:root {
  /* light — "graph paper" */
  --paper: #F2F4EF;
  --paper-raised: #FBFCF9;
  --grid: #DDE3D9;
  --grid-strong: #C8D0C3;
  --ink: #17211B;
  --ink-soft: #55635C;
  --ink-faint: #66716A;
  --row: #C0361C;         /* you */
  --row-soft: #F6E2DC;
  --col: #1F49C0;         /* them */
  --col-soft: #E0E6F8;
  --gold: #7A5E00;        /* equilibrium (text-safe) */
  --gold-fill: #F3CE49;
  --gold-soft: #FAF0CC;
  --ok: #1D6E42;
  --ok-soft: #DFEEE4;
  --bad: #A32014;
  --bad-soft: #F6E0DD;
  --topbar-bg: rgba(251, 252, 249, 0.92);
  --scrim: rgba(23, 33, 27, 0.45);
  --shadow-card: 0 1px 0 var(--grid-strong), 0 6px 22px -12px rgba(23, 33, 27, 0.28);
  color-scheme: light;

  --serif: "IBM Plex Serif", Georgia, serif;
  --sans: "IBM Plex Sans", -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", "SF Mono", monospace;

  --rail-w: 292px;
  --measure: 46rem;
  --r-card: 6px;
  --dur: 220ms;
  --ease: cubic-bezier(0.22, 0.9, 0.3, 1);
}

:root[data-theme="dark"] {
  /* dark — "the blackboard": same drafting room, lights off */
  --paper: #151A17;
  --paper-raised: #1D2320;
  --grid: #212823;
  --grid-strong: #39423B;
  --ink: #E8ECE7;
  --ink-soft: #A9B4AC;
  --ink-faint: #8A948B;
  --row: #E87A5F;
  --row-soft: #3A231D;
  --col: #8AA2F2;
  --col-soft: #212B4A;
  --gold: #D9B44A;
  --gold-fill: #E8C33C;
  --gold-soft: #33301C;
  --ok: #5FBE8B;
  --ok-soft: #1C2F25;
  --bad: #E57368;
  --bad-soft: #3A211E;
  --topbar-bg: rgba(21, 26, 23, 0.92);
  --scrim: rgba(0, 0, 0, 0.6);
  --shadow-card: 0 1px 0 rgba(0, 0, 0, 0.55), 0 6px 22px -12px rgba(0, 0, 0, 0.65);
  color-scheme: dark;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  color: var(--ink);
  background-color: var(--paper);
  /* the graph paper */
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  min-height: 100dvh;
}

::selection { background: var(--gold-fill); color: #17211B; }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--ink); color: var(--paper); padding: 10px 16px;
  z-index: 200; font-family: var(--mono); font-size: 0.85rem;
}
.skip-link:focus { left: 8px; top: 8px; }

:focus-visible {
  outline: 2px solid var(--col);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px; height: 58px;
  background: var(--topbar-bg);
  backdrop-filter: blur(6px);
  border-bottom: 1.5px solid var(--ink);
}
.wordmark {
  font-family: var(--serif); font-weight: 700; font-size: 1.12rem;
  color: var(--ink); text-decoration: none; letter-spacing: 0.01em;
}
.wordmark em { font-style: italic; font-weight: 400; color: var(--ink-soft); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.streak-chip {
  font-family: var(--mono); font-size: 0.8rem; color: var(--ink-soft);
  border: 1px solid var(--grid-strong); background: var(--paper-raised);
  padding: 4px 10px; border-radius: 999px; white-space: nowrap;
}
.streak-chip.hot { color: var(--gold); border-color: var(--gold-fill); background: var(--gold-soft); }

.board-toggle {
  display: none;
  width: 44px; height: 44px; align-items: center; justify-content: center;
  background: none; border: none; color: var(--ink); cursor: pointer;
}

.hub-link {
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-soft); text-decoration: none; margin-right: 4px;
  padding: 6px 4px; border-radius: 4px;
}
.hub-link:hover { color: var(--ink); }

.theme-toggle {
  display: inline-flex; width: 44px; height: 44px;
  align-items: center; justify-content: center;
  background: none; border: none; color: var(--ink-soft);
  cursor: pointer; border-radius: 6px;
  touch-action: manipulation;
  transition: color 150ms, background 150ms;
}
.theme-toggle:hover { color: var(--ink); background: var(--paper); }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: calc(100dvh - 58px); }

.rail {
  width: var(--rail-w); flex-shrink: 0;
  border-right: 1.5px solid var(--ink);
  background: var(--paper-raised);
  padding: 26px 22px 34px;
  position: sticky; top: 58px;
  height: calc(100dvh - 58px);
  overflow-y: auto;
}
.rail-eyebrow {
  font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--ink-faint); margin-bottom: 6px;
}
.mastery-line { font-family: var(--serif); font-size: 1.05rem; font-weight: 600; }
.mastery-track {
  height: 6px; background: var(--grid); border-radius: 3px;
  margin: 10px 0 22px; overflow: hidden;
}
.mastery-fill {
  height: 100%; width: 0; background: var(--ink); border-radius: 3px;
  transition: width 500ms var(--ease);
}

/* the 30-cell board */
.day-board {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px;
  margin-bottom: 26px;
}
.day-cell {
  aspect-ratio: 1; border: 1.5px solid var(--grid-strong);
  background: var(--paper-raised);
  font-family: var(--mono); font-size: 0.82rem; font-weight: 500;
  color: var(--ink-faint);
  display: flex; align-items: center; justify-content: center;
  position: relative; cursor: pointer; text-decoration: none;
  border-radius: 3px;
  transition: transform 150ms var(--ease), border-color 150ms, background 150ms;
}
.day-cell:hover { transform: translateY(-1px); }
.day-cell.locked { cursor: not-allowed; background: transparent; }
.day-cell.locked:hover { transform: none; }
.day-cell.locked::after {
  content: ""; position: absolute; width: 4px; height: 4px; border-radius: 50%;
  background: var(--grid-strong); bottom: 4px;
}
.day-cell.open { border-color: var(--ink); color: var(--ink); }
.day-cell.done { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.day-cell.exam { border-style: dashed; }
.day-cell.exam.done { border-style: solid; }
.day-cell.exam::before {
  content: ""; position: absolute; top: 3px; right: 3px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--gold-fill); border: 1px solid var(--gold);
}
.day-cell.current { box-shadow: 0 0 0 2.5px var(--gold-fill); border-color: var(--ink); color: var(--ink); }

.rail-links { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--grid); padding-top: 16px; }
.rail-link {
  font-family: var(--sans); font-size: 0.92rem; font-weight: 500;
  color: var(--ink-soft); text-decoration: none; padding: 9px 10px;
  border-radius: 4px; display: flex; align-items: center; gap: 8px;
}
.rail-link:hover { background: var(--paper); color: var(--ink); }
.due-badge {
  font-family: var(--mono); font-size: 0.72rem; background: var(--row);
  color: #fff; border-radius: 999px; padding: 1px 8px;
}
.rail-scrim { display: none; }
.rail-scrim[hidden] { display: none !important; }

/* ---------- main column ---------- */
.main { flex: 1; min-width: 0; padding: 44px 40px 90px; }
.page { max-width: var(--measure); margin: 0 auto; }
.page-wide { max-width: 56rem; margin: 0 auto; }

.eyebrow {
  font-family: var(--mono); font-size: 0.76rem; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--ink-soft); margin-bottom: 10px;
  display: flex; align-items: center; gap: 10px;
}
.eyebrow .tick { width: 26px; height: 1.5px; background: var(--ink); display: inline-block; }

h1 {
  font-family: var(--serif); font-weight: 700; font-size: clamp(1.9rem, 4vw, 2.6rem);
  line-height: 1.15; letter-spacing: -0.01em; margin-bottom: 10px;
}
.tagline { font-size: 1.08rem; color: var(--ink-soft); max-width: 40rem; }

h2.section-head {
  font-family: var(--serif); font-weight: 600; font-size: 1.42rem;
  line-height: 1.25; margin: 2.6em 0 0.7em;
  display: flex; align-items: baseline; gap: 12px;
}
h2.section-head .sec-n {
  font-family: var(--mono); font-weight: 500; font-size: 0.85rem;
  color: var(--ink-faint); flex-shrink: 0;
}

.lesson p { margin-bottom: 1.05em; }
.lesson ul, .lesson ol { margin: 0 0 1.05em 1.4em; }
.lesson li { margin-bottom: 0.45em; }
.lesson strong { font-weight: 600; }
.lesson .callout {
  border-left: 3px solid var(--gold-fill); background: var(--gold-soft);
  padding: 14px 18px; margin: 1.4em 0; border-radius: 0 var(--r-card) var(--r-card) 0;
}
.lesson .callout p:last-child { margin-bottom: 0; }
.lesson pre.tree {
  font-family: var(--mono); font-size: 0.85rem; line-height: 1.5;
  background: var(--paper-raised); border: 1.5px solid var(--grid-strong);
  border-radius: var(--r-card); padding: 18px 22px; margin: 1.4em 0;
  overflow-x: auto;
}
.lesson table.mini {
  border-collapse: collapse; margin: 1.4em auto; font-size: 0.92rem;
}
.lesson table.mini th, .lesson table.mini td {
  border: 1px solid var(--grid-strong); padding: 8px 14px; text-align: left;
}
.lesson table.mini th { font-family: var(--mono); font-size: 0.78rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft); background: var(--paper-raised); }

/* ---------- the signature: payoff matrix ---------- */
.matrix-block { margin: 2em 0; }
.matrix-caption {
  font-family: var(--mono); font-size: 0.8rem; color: var(--ink-soft);
  margin-bottom: 12px; letter-spacing: 0.02em;
}
.matrix-wrap { overflow-x: auto; padding: 6px 2px; }
.pm { border-collapse: collapse; margin: 0 auto; }
.pm .pm-blank { border: none; }
.pm .pm-player-col {
  font-family: var(--mono); font-size: 0.78rem; font-weight: 600;
  color: var(--col); text-align: center; padding: 4px 8px 8px; border: none;
  text-transform: uppercase; letter-spacing: 0.08em;
}
.pm .pm-player-row {
  font-family: var(--mono); font-size: 0.78rem; font-weight: 600;
  color: var(--row); border: none; padding: 4px 12px 4px 0;
  text-transform: uppercase; letter-spacing: 0.08em;
  writing-mode: vertical-rl; transform: rotate(180deg); text-align: center;
}
.pm .pm-strat {
  font-family: var(--sans); font-size: 0.88rem; font-weight: 600;
  padding: 8px 14px; border: none; background: none;
}
.pm th.pm-strat-col { color: var(--col); }
.pm th.pm-strat-row { color: var(--row); text-align: right; }
.pm button.pm-strat { cursor: pointer; border-radius: 4px; }
.pm button.pm-strat:hover { background: var(--paper); }
.pm button.pm-strat[aria-pressed="true"].pm-strat-col { background: var(--col-soft); box-shadow: inset 0 -2.5px 0 var(--col); }
.pm button.pm-strat[aria-pressed="true"].pm-strat-row { background: var(--row-soft); box-shadow: inset 0 -2.5px 0 var(--row); }
.pm td.pm-cell {
  border: 1.5px solid var(--ink); background: var(--paper-raised);
  min-width: 110px; height: 74px; text-align: center; position: relative;
  font-family: var(--mono); font-size: 1.02rem; font-weight: 500;
  padding: 6px 10px;
}
.pm td.pm-cell .pr { color: var(--row); }
.pm td.pm-cell .pc { color: var(--col); }
.pm td.pm-cell .comma { color: var(--ink-faint); }
.pm td.pm-cell.hl { background: var(--gold-soft); }
/* best-response marks */
.pm .br-row .pr, .pm .br-col .pc { position: relative; }
.pm .br-row .pr::after, .pm .br-col .pc::after {
  content: ""; position: absolute; inset: -5px -8px;
  border: 2px solid currentColor; border-radius: 50%;
  opacity: 0; transform: scale(0.6);
}
.pm.solved .br-row .pr::after, .pm.solved .br-col .pc::after {
  opacity: 1; transform: scale(1);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.pm td.pm-cell.nash { box-shadow: inset 0 0 0 3px var(--gold-fill); background: var(--gold-soft); }
.pm td.pm-cell.nash::after {
  content: "EQ"; position: absolute; top: 3px; right: 5px;
  font-size: 0.62rem; font-weight: 600; color: var(--gold); letter-spacing: 0.08em;
}
.matrix-tools { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; align-items: center; justify-content: center; }
.matrix-note { font-size: 0.9rem; color: var(--ink-soft); margin-top: 12px; text-align: center; }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--sans); font-size: 0.95rem; font-weight: 600;
  padding: 11px 22px; border-radius: 5px; cursor: pointer;
  border: 1.5px solid var(--ink); background: var(--ink); color: var(--paper);
  transition: transform 120ms var(--ease), box-shadow 120ms;
  min-height: 44px;
  touch-action: manipulation;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 3px 10px -4px rgba(23,33,27,0.5); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: var(--paper-raised); }
.btn.small { padding: 7px 14px; font-size: 0.85rem; min-height: 36px; }
.btn.gold { background: var(--gold-fill); border-color: var(--gold-fill); color: #17211B; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---------- cards / stages ---------- */
.stage {
  background: var(--paper-raised); border: 1.5px solid var(--ink);
  border-radius: var(--r-card); box-shadow: var(--shadow-card);
  padding: 28px 30px; margin: 1.8em 0;
}
.stage-label {
  font-family: var(--mono); font-size: 0.74rem; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--ink-soft); margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}
.stage-label::before { content: ""; width: 8px; height: 8px; background: var(--ink); flex-shrink: 0; }
.stage-label.recall::before { background: var(--col); }
.stage-label.quiz::before { background: var(--row); }
.stage-label.apply::before { background: var(--gold-fill); border: 1px solid var(--gold); }

/* key ideas */
.key-ideas { border: 1.5px dashed var(--grid-strong); border-radius: var(--r-card); padding: 20px 24px; margin: 2em 0; background: var(--paper-raised); }
.key-ideas h3 { font-family: var(--mono); font-size: 0.76rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 10px; }
.key-ideas ul { margin: 0 0 0 1.2em; }
.key-ideas li { margin-bottom: 0.4em; }

/* ---------- quiz ---------- */
.quiz-progress {
  display: flex; gap: 5px; margin-bottom: 20px;
}
.qp-seg { height: 5px; flex: 1; background: var(--grid); border-radius: 2px; }
.qp-seg.done-right { background: var(--ok); }
.qp-seg.done-wrong { background: var(--row); }
.qp-seg.now { background: var(--ink); }

.quiz-q { font-family: var(--serif); font-size: 1.18rem; font-weight: 600; line-height: 1.4; margin-bottom: 18px; }
.quiz-opts { display: flex; flex-direction: column; gap: 10px; }
.quiz-opt {
  text-align: left; font-family: var(--sans); font-size: 0.98rem; line-height: 1.5;
  padding: 13px 16px 13px 46px; border: 1.5px solid var(--grid-strong);
  background: var(--paper-raised); border-radius: 5px; cursor: pointer;
  position: relative; color: var(--ink); min-height: 44px;
  transition: border-color 130ms, background 130ms, transform 120ms var(--ease);
  touch-action: manipulation;
}
.quiz-opt .opt-key {
  position: absolute; left: 14px; top: 13px;
  font-family: var(--mono); font-size: 0.8rem; font-weight: 600; color: var(--ink-faint);
}
.quiz-opt:hover:not(:disabled) { border-color: var(--ink); transform: translateX(2px); }
.quiz-opt:disabled { cursor: default; }
.quiz-opt.right { border-color: var(--ok); background: var(--ok-soft); }
.quiz-opt.right .opt-key { color: var(--ok); }
.quiz-opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.quiz-opt.wrong .opt-key { color: var(--bad); }
.quiz-opt.dim { opacity: 0.55; }

.quiz-explain {
  margin-top: 16px; padding: 15px 18px; border-radius: 5px;
  border-left: 3px solid var(--ink); background: var(--paper);
  font-size: 0.95rem;
}
.quiz-explain .verdict { font-family: var(--mono); font-size: 0.78rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; display: block; margin-bottom: 6px; }
.quiz-explain.good { border-left-color: var(--ok); }
.quiz-explain.good .verdict { color: var(--ok); }
.quiz-explain.bad { border-left-color: var(--bad); }
.quiz-explain.bad .verdict { color: var(--bad); }
.quiz-next { margin-top: 18px; display: flex; justify-content: flex-end; }

/* score panel */
.score-panel { text-align: center; padding: 16px 0 6px; }
.score-big { font-family: var(--serif); font-size: 3.2rem; font-weight: 700; line-height: 1; }
.score-big .of { font-size: 1.4rem; color: var(--ink-faint); font-weight: 400; }
.score-msg { margin: 12px auto 20px; max-width: 30rem; color: var(--ink-soft); }
.score-pass { color: var(--ok); font-weight: 600; }
.score-fail { color: var(--bad); font-weight: 600; }

/* ---------- apply / journal ---------- */
.apply-prompt { font-size: 1.02rem; margin-bottom: 14px; }
textarea.apply-input {
  width: 100%; min-height: 150px; resize: vertical;
  font-family: var(--sans); font-size: 1rem; line-height: 1.6;
  padding: 14px 16px; border: 1.5px solid var(--grid-strong); border-radius: 5px;
  background: var(--paper-raised); color: var(--ink);
}
textarea.apply-input:focus { border-color: var(--col); outline: none; box-shadow: 0 0 0 3px var(--col-soft); }
.apply-hint { font-family: var(--mono); font-size: 0.78rem; color: var(--ink-faint); margin-top: 8px; }
.apply-hint.ready { color: var(--ok); }

.journal-entry { border-bottom: 1px solid var(--grid); padding: 20px 0; }
.journal-entry .je-day { font-family: var(--mono); font-size: 0.78rem; color: var(--ink-soft); margin-bottom: 6px; }
.journal-entry .je-prompt { font-weight: 600; margin-bottom: 8px; }
.journal-entry .je-text { color: var(--ink-soft); white-space: pre-wrap; }

/* ---------- dashboard ---------- */
.hero-board { margin: 2.2em 0; }
.dash-cta { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-top: 1.8em; }
.dash-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 2.4em; }
.stat-card { border: 1.5px solid var(--grid-strong); border-radius: var(--r-card); background: var(--paper-raised); padding: 16px 18px; }
.stat-card .sc-n { font-family: var(--serif); font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat-card .sc-l { font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); margin-top: 4px; }

.week-strip { margin-top: 2.6em; }
.week-row { display: flex; align-items: baseline; gap: 14px; padding: 13px 0; border-bottom: 1px solid var(--grid); }
.week-row .wk { font-family: var(--mono); font-size: 0.8rem; color: var(--ink-faint); flex-shrink: 0; width: 64px; }
.week-row .wt { font-weight: 600; }
.week-row .wscore { margin-left: auto; font-family: var(--mono); font-size: 0.85rem; color: var(--ink-soft); }

/* review queue */
.review-item { border: 1.5px solid var(--grid-strong); border-radius: var(--r-card); background: var(--paper-raised); padding: 20px 22px; margin-bottom: 14px; }
.review-meta { font-family: var(--mono); font-size: 0.75rem; color: var(--ink-faint); margin-bottom: 8px; }

.empty-note { color: var(--ink-soft); padding: 30px 0; }
.day-footer-nav { display: flex; justify-content: space-between; margin-top: 3em; gap: 12px; flex-wrap: wrap; }

.locked-note {
  border: 1.5px dashed var(--grid-strong); border-radius: var(--r-card);
  padding: 26px; text-align: center; color: var(--ink-soft); margin-top: 2em;
  background: var(--paper-raised);
}

/* done ribbon */
.done-ribbon {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 0.8rem; font-weight: 600;
  color: var(--ok); background: var(--ok-soft); border: 1px solid var(--ok);
  padding: 4px 12px; border-radius: 999px; margin-bottom: 14px;
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .board-toggle { display: inline-flex; }
  .rail {
    position: fixed; left: 0; top: 58px; z-index: 90;
    transform: translateX(-104%);
    transition: transform 260ms var(--ease);
    box-shadow: 14px 0 40px -20px rgba(23,33,27,0.4);
    width: min(84vw, 330px);
  }
  .rail.open { transform: translateX(0); }
  .rail-scrim {
    display: block; position: fixed; inset: 58px 0 0 0; z-index: 80;
    background: var(--scrim);
  }
  .main { padding: 30px 20px 80px; }
  .stage { padding: 22px 18px; }
  .pm td.pm-cell { min-width: 88px; height: 64px; font-size: 0.92rem; }
}

@media (max-width: 480px) {
  .topbar { padding: 0 10px; gap: 8px; }
  .hub-link { display: none; }
  .streak-chip { font-size: 0.72rem; padding: 3px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}
