/* Flipped Economics design system v1 (Option A, "Workbook").
   One file for every page. Tokens first, then site chrome, then lesson components,
   then the learning layer (quiz, exam practice, review, starters). */

:root {
  --ink: #15233B;          /* text and diagram ink */
  --muted: #51627A;        /* secondary text, 6.1:1 on white */
  --line: #E3E9F1;         /* hairlines */
  --line-strong: #C9D3E2;  /* control borders */
  --panel: #F3F6FA;        /* page wash behind cards */
  --bg: #FFFFFF;
  --accent: #2457D6;       /* the one accent: current step, primary action */
  --accent-ink: #1C46B0;   /* accent on hover */
  --accent-soft: #E8EEFC;
  --good: #116432;         /* "Correct." */
  --good-soft: #EAF6EE;
  --warn: #B42318;         /* "Not quite." and diagram warnings */
  --warn-soft: #FDECEA;
  --player-b: #A84B07;     /* second firm in a payoff matrix */
  --radius: 10px;
  --radius-card: 16px;
  --ease: cubic-bezier(.22,.61,.36,1);
  --font: Figtree, system-ui, -apple-system, "Segoe UI", sans-serif;
  --hand: Kalam, "Comic Sans MS", cursive;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
img, svg { max-width: 100%; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Site chrome ---------- */
.container { max-width: 1160px; margin: 0 auto; padding: 0 32px; }
@media (max-width: 640px) { .container { padding: 0 18px; } }

.site-header { border-bottom: 1px solid var(--line); background: var(--bg); }
.site-header .container { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; letter-spacing: -0.01em; text-decoration: none; }
.brand svg { flex-shrink: 0; }
.site-nav { display: flex; gap: 28px; font-weight: 500; font-size: 16px; flex-wrap: wrap; }
.site-nav a { text-decoration: none; color: var(--ink); }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--accent); }
@media (max-width: 640px) { .site-header .container { min-height: 60px; padding-top: 10px; padding-bottom: 10px; } .site-nav { gap: 18px; font-size: 15px; } .site-header .btn { display: none; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: var(--radius); font: inherit; font-weight: 600; font-size: 15px; text-decoration: none; cursor: pointer; border: 1px solid transparent; transition: background-color .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease); }
.btn:active { transform: scale(.97); }
.btn-lg { min-height: 48px; padding: 0 22px; font-size: 16px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); }
.btn-secondary { background: var(--bg); color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover { border-color: var(--ink); }
.btn-ghost { background: transparent; color: var(--muted); padding: 0 10px; }
.btn-ghost:hover { color: var(--ink); }
.btn[disabled] { opacity: .45; cursor: default; transform: none; }

.site-footer { border-top: 1px solid var(--line); }
.site-footer .container { padding-top: 32px; padding-bottom: 32px; display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.site-footer strong { color: var(--ink); font-size: 15px; }
.site-footer nav { display: flex; gap: 24px; flex-wrap: wrap; }
.site-footer a { text-decoration: none; }
.site-footer a:hover { color: var(--accent); }

h1, h2, h3 { letter-spacing: -0.02em; text-wrap: balance; }
.lede { font-size: 19px; color: var(--muted); max-width: 54ch; text-wrap: pretty; margin: 0; }
.eyebrow { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.section { padding: 64px 0; }
.section-wash { background: var(--panel); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.section-head h2 { margin: 0; font-size: 30px; }
.section-head p { margin: 0; font-size: 15px; color: var(--muted); }

/* Lesson list (homepage, course page) */
.lesson-list { list-style: none; margin: 0; padding: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.lesson-list + .lesson-list { margin-top: 20px; }
.lesson-list li + li { border-top: 1px solid var(--line); }
.lesson-row { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; gap: 20px; align-items: center; padding: 20px 24px; text-decoration: none; color: var(--ink); }
a.lesson-row:hover { background: #FAFBFD; }
a.lesson-row:hover strong { color: var(--accent); }
.lesson-row .n { font-size: 15px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.lesson-row strong { display: block; font-size: 18px; font-weight: 600; transition: color .15s var(--ease); }
.lesson-row .sum { display: block; font-size: 15px; color: var(--muted); margin-top: 2px; }
.lesson-row .meta { display: flex; align-items: center; gap: 14px; font-size: 14px; color: var(--muted); white-space: nowrap; }
.tag { display: inline-flex; align-items: center; height: 30px; padding: 0 10px; border-radius: 8px; font-size: 14px; font-weight: 600; background: var(--panel); color: var(--muted); }
.tag-live { background: var(--accent-soft); color: var(--accent); }
.tag-due { background: var(--warn-soft); color: var(--warn); }
.tag-secure { background: var(--good-soft); color: var(--good); }
.module-title { font-size: 15px; font-weight: 600; color: var(--muted); margin: 28px 0 10px; }
.module-title:first-child { margin-top: 0; }
@media (max-width: 640px) {
  .lesson-row { grid-template-columns: 32px minmax(0, 1fr); gap: 12px; padding: 16px; }
  .lesson-row .meta { grid-column: 2; }
}

/* ---------- Lesson pages ---------- */
body.lesson { background: var(--panel); }
.lesson-bar { background: var(--bg); border-bottom: 1px solid var(--line); }
.lesson-bar .inner { max-width: 1040px; margin: 0 auto; padding: 0 20px; min-height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.lesson-bar .back { font-size: 15px; font-weight: 500; color: var(--muted); text-decoration: none; white-space: nowrap; }
.lesson-bar .back:hover { color: var(--ink); }
.lesson-bar .brand { font-size: 17px; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 22px 20px 56px; }
.top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.top h1 { font-size: 24px; line-height: 1.2; font-weight: 700; margin: 0; }
.route { font-size: 14px; color: var(--muted); }

.stages { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.stages span { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-strong); color: var(--muted); font-size: 14px; font-weight: 500; background: var(--bg); }
.stages span.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.stages span.done { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); font-weight: 600; }
.stages span.done::before { content: ""; width: 10px; height: 6px; border-left: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg) translateY(-2px); }
.stages span.skipped { text-decoration: line-through; opacity: .7; }

.card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-card); }
svg.diagram { display: block; width: 100%; height: auto; touch-action: none; user-select: none; -webkit-user-select: none; }
.caption { border-top: 1px solid var(--line); padding: 16px 22px; min-height: 76px; }
.caption p { margin: 0; font-size: 17px; line-height: 1.5; max-width: 72ch; }
.fb { margin-top: 10px; font-weight: 600; font-size: 16px; line-height: 1.45; }
.fb:empty { margin: 0; }
.fb.good { color: var(--good); }
.fb.bad { color: var(--warn); }
.fb.good, .fb.bad { background: var(--good-soft); padding: 10px 14px; border-radius: 10px; font-weight: 500; color: var(--ink); }
.fb.bad { background: var(--warn-soft); }
.fb b { font-weight: 700; }
.fb.good b { color: var(--good); } .fb.bad b { color: var(--warn); }

.controls { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; align-items: center; }
body.lesson button:not(.btn):not(.plain) { font: inherit; font-weight: 600; font-size: 15px; min-height: 44px; padding: 0 18px; background: var(--bg); color: var(--ink); border: 1px solid var(--line-strong); border-radius: var(--radius); cursor: pointer; transition: background-color .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease); }
body.lesson button:not(.btn):not(.plain):hover { border-color: var(--ink); }
body.lesson button:not(.btn):not(.plain):active { transform: scale(.97); }
body.lesson button:not(.btn):not(.plain):disabled { opacity: .45; cursor: default; transform: none; }
body.lesson button.primary:not(.btn):not(.plain) { background: var(--accent); border-color: var(--accent); color: #fff; }
body.lesson button.primary:not(.btn):not(.plain):hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.spacer { flex: 1; }

.panel { padding: 24px 26px 26px; }
.panel h2 { margin: 0 0 8px; font-size: 22px; line-height: 1.25; font-weight: 700; }
.panel h3 { margin: 18px 0 6px; font-size: 17px; font-weight: 700; }
.panel p { margin: 0 0 12px; line-height: 1.55; font-size: 16px; max-width: 72ch; }
.panel .eyebrow { display: block; margin-bottom: 6px; }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 16px; }
body.lesson .choice button:not(.btn):not(.plain) { text-align: left; padding: 16px 18px; min-height: 88px; display: block; font-weight: 500; }
.choice b { display: block; font-size: 16px; margin-bottom: 4px; font-weight: 700; }
.choice small { font-weight: 400; color: var(--muted); font-size: 14px; line-height: 1.45; display: block; }
@media (max-width: 640px) { .choice { grid-template-columns: 1fr; } .panel { padding: 20px 18px; } .caption { padding: 14px 16px; } .top h1 { font-size: 21px; } }

/* options for multiple-choice inside a lesson */
.opts { display: grid; gap: 10px; margin: 14px 0 6px; }
.opts button { font: inherit; font-size: 16px; color: var(--ink); background: var(--bg); border: 1px solid var(--line-strong); border-radius: var(--radius); cursor: pointer; transition: border-color .15s var(--ease), background-color .15s var(--ease), transform .1s var(--ease); }
.opts button:hover:not(:disabled) { border-color: var(--ink); }
.opts button:active:not(:disabled) { transform: scale(.98); }
.opts button:disabled { cursor: default; }
body.lesson .opts button, .opts button { text-align: left; font-weight: 500; padding: 12px 16px; min-height: 52px; line-height: 1.4; display: flex; align-items: center; gap: 12px; }
.opts .key { flex-shrink: 0; width: 28px; height: 28px; border-radius: 7px; background: var(--panel); color: var(--muted); display: inline-flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; }
.opts button.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.opts button.right { border-color: var(--good); background: var(--good-soft); }
.opts button.right .key { background: var(--good); color: #fff; }
.opts button.wrong { border-color: var(--warn); background: var(--warn-soft); }
.opts button.wrong .key { background: var(--warn); color: #fff; }

/* spectrum drag task */
.spectrum { position: relative; margin: 46px 6px 24px; height: 120px; }
.track { position: absolute; left: 0; right: 0; top: 40px; height: 3px; background: var(--ink); border-radius: 2px; }
.end { position: absolute; top: 52px; font-size: 14px; font-weight: 600; max-width: 40%; }
.end.l { left: 0; } .end.r { right: 0; text-align: right; }
.chip { position: absolute; top: -36px; padding: 6px 12px; font-size: 14px; font-weight: 600; background: var(--bg); border: 1px solid var(--line-strong); border-radius: 8px; cursor: grab; touch-action: none; white-space: nowrap; box-shadow: 0 1px 2px rgba(21,35,59,.08); }
.chip.placed { top: 20px; transform: translateX(-50%); border-color: var(--accent); }
.tick { position: absolute; top: 28px; width: 2px; height: 28px; background: var(--good); display: none; }

/* marking grid and checklists */
table.grid { width: 100%; border-collapse: collapse; margin: 6px 0 14px; font-size: 15px; }
table.grid th, table.grid td { border-bottom: 1px solid var(--line); padding: 10px 10px; text-align: left; vertical-align: top; line-height: 1.45; }
table.grid th { font-weight: 600; color: var(--muted); font-size: 14px; border-bottom-color: var(--line-strong); }
table.grid td:first-child, table.grid th:first-child { width: 40px; text-align: center; color: var(--muted); }
table.grid td:last-child, table.grid th:last-child { width: 72px; text-align: center; }
table.grid input { width: 22px; height: 22px; accent-color: var(--accent); }
.check label { display: flex; gap: 12px; align-items: flex-start; padding: 8px 0; font-size: 16px; line-height: 1.45; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); flex-shrink: 0; }
body.lesson textarea, .fe-textarea { width: 100%; min-height: 120px; font: 16px/1.55 var(--font); color: var(--ink); padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--bg); resize: vertical; }
body.lesson textarea:focus, .fe-textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.conf { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 6px; }
body.lesson .conf button { font-weight: 500; }
body.lesson .conf button:not(.btn):not(.plain).sel { background: var(--accent); border-color: var(--accent); color: #fff; }
body.lesson button.piece:not(.btn):not(.plain) { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 10px; min-width: 86px; min-height: 64px; font-weight: 600; }
button.piece span { font-size: 12px; color: var(--muted); font-weight: 500; }
body.lesson button.piece:not(.btn):not(.plain).sel { opacity: .35; }
.model { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 12px 16px; margin: 12px 0 16px; font-size: 16px; line-height: 1.55; }
.label-tool { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; color: var(--accent); letter-spacing: .04em; text-transform: uppercase; margin-bottom: 6px; }

/* mastery bar */
.bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 14px 0 6px; }
.bar div { height: 10px; background: var(--line); border-radius: 5px; }
.bar div.full { background: var(--accent); }
.bar div.half { background: repeating-linear-gradient(45deg, var(--accent) 0 4px, var(--accent-soft) 4px 8px); }
.barlabels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; font-size: 13px; color: var(--muted); }
table.sum { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 15px; }
table.sum td { border-top: 1px solid var(--line); padding: 9px 4px; vertical-align: top; }
table.sum td:last-child { text-align: right; white-space: nowrap; font-weight: 600; }
.note { margin-top: 24px; font-size: 14px; color: var(--muted); line-height: 1.5; }

/* ---------- Learning layer ---------- */
.after { margin-top: 28px; display: grid; gap: 18px; }
.after-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.after-head h2 { margin: 0; font-size: 22px; }
.after-head p { margin: 0; color: var(--muted); font-size: 15px; }

.quiz-q { font-size: 18px; font-weight: 600; line-height: 1.45; margin: 4px 0 4px; max-width: 70ch; }
.quiz-meta { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; color: var(--muted); }
.quiz-progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 10px 0 16px; }
.quiz-progress span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .25s var(--ease); }
.quiz-done { display: grid; gap: 6px; }
.quiz-score { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.mini-matrix { border-collapse: collapse; margin: 10px 0 4px; font-size: 15px; font-variant-numeric: tabular-nums; }
.mini-matrix th, .mini-matrix td { border: 1px solid var(--line-strong); padding: 6px 12px; text-align: center; }
.mini-matrix th { background: var(--panel); font-weight: 600; }
.pa { color: var(--accent); font-weight: 700; } .pb { color: var(--player-b); font-weight: 700; }

/* exam practice */
.exam-q { font-size: 18px; font-weight: 600; line-height: 1.5; max-width: 70ch; margin: 0 0 4px; }
.exam-q .marks { color: var(--muted); font-weight: 500; white-space: nowrap; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 3px; gap: 3px; background: var(--bg); margin: 12px 0 14px; }
body.lesson .seg button, .seg button { min-height: 38px; border: 0; border-radius: 7px; padding: 0 14px; font: inherit; font-size: 15px; font-weight: 600; background: transparent; color: var(--muted); cursor: pointer; }
body.lesson .seg button.on, .seg button.on { background: var(--accent-soft); color: var(--accent); }
.wordcount { font-size: 14px; color: var(--muted); margin-top: 6px; font-variant-numeric: tabular-nums; }
.paper { background: #fff; border: 1px solid var(--line-strong); border-radius: 6px; padding: 18px 22px 22px 56px; font: 20px/32px var(--hand); color: #1A2A6C; white-space: pre-wrap; word-wrap: break-word; min-height: 200px;
  background-image: linear-gradient(to right, transparent 40px, #F2B8B5 40px, #F2B8B5 41px, transparent 41px), repeating-linear-gradient(to bottom, transparent 0, transparent 31px, #D6E0F0 31px, #D6E0F0 32px); background-position: 0 0, 0 17px; }
.photo-answer { max-width: 100%; border-radius: 10px; border: 1px solid var(--line); display: block; }
.mark-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); gap: 16px; margin: 14px 0; }
.mark-split { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr)); gap: 22px; align-items: start; }
@media (min-width: 900px) { .mark-split > div:first-child { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; } }
.ao { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.ao h4 { margin: 0 0 2px; font-size: 16px; display: flex; justify-content: space-between; gap: 8px; }
.ao h4 span { color: var(--muted); font-weight: 500; font-size: 14px; }
.ao .what { font-size: 14px; color: var(--muted); margin: 0 0 10px; }
.band { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 15px; line-height: 1.45; }
.band:hover { background: var(--panel); }
.band input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0; }
.band b { white-space: nowrap; }
.band.picked { background: var(--accent-soft); }
.total-line { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; font-size: 16px; padding: 14px 0 4px; border-top: 1px solid var(--line); margin-top: 6px; }
.total-line .big { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

/* ---------- Review and starters ---------- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 16px; }
.stat { border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; background: var(--bg); }
.stat .v { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 14px; color: var(--muted); }
.strength { display: flex; align-items: center; gap: 10px; min-width: 160px; }
.strength .track2 { flex: 1; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.strength .track2 span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

.starter-stage { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-card); padding: 28px 32px; }
.starter-stage ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 18px; counter-reset: s; }
.starter-stage li { counter-increment: s; display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 14px; align-items: start; font-size: 21px; line-height: 1.4; font-weight: 500; }
.starter-stage li::before { content: counter(s); width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; font-size: 18px; }
.starter-stage .ans { display: block; font-size: 17px; color: var(--good); font-weight: 600; margin-top: 4px; }
.starter-stage .src { display: block; font-size: 13px; color: var(--muted); font-weight: 500; margin-top: 2px; }
.starter-stage.fullscreen { position: fixed; inset: 0; z-index: 50; border-radius: 0; overflow: auto; padding: 48px 6vw; }
.starter-stage.fullscreen li { font-size: clamp(22px, 2.6vw, 38px); grid-template-columns: 64px minmax(0,1fr); }
.starter-stage.fullscreen li::before { width: 56px; height: 56px; font-size: 26px; }
.starter-stage.fullscreen .ans { font-size: clamp(18px, 2vw, 30px); }
.topic-pick { columns: 2 280px; column-gap: 28px; }
.topic-pick label { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; break-inside: avoid; font-size: 15px; cursor: pointer; }
.topic-pick input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); }
@media print {
  .site-header, .site-footer, .no-print { display: none !important; }
  .starter-stage { border: 0; padding: 0; }
  .starter-stage li { font-size: 16pt; }
}

@media (prefers-reduced-motion: reduce) { * { transition-duration: 0s !important; animation-duration: 0s !important; } }
