/* Layout: a single thumb-reach column. Top bar, one card per screen, a sticky Next bar at the bottom; settings slide in from the right. */
:root {
  --bg: #f3f4f8;
  --surface: #ffffff;
  --ink: #1a1d2b;
  --muted: #5d6378;
  --line: #dfe2ea;
  --stim: #eceef5;
  --accent: #4a46a8;
  --accent-ink: #ffffff;
  --accent-soft: #e7e6f7;
  --right: #23805a;
  --right-soft: #e3f3ea;
  --wrong: #b5443a;
  --wrong-soft: #f8e6e3;
  --hl-concl: #ddd9ff;
  --hl-prem: #2d7f8f;
  --hl-sig: #8a5d00;
  --hl-pivot: #b5443a;

  --font-ui: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-read: "Literata", Georgia, "Times New Roman", serif;
  --fs: 17px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12131c; --surface: #1a1c28; --ink: #e6e8f0; --muted: #9ba1b5; --line: #2b2e3d; --stim: #222534;
    --accent: #a7a3ff; --accent-ink: #12131c; --accent-soft: #2a2950; --right: #6fcf9f; --right-soft: #183427;
    --wrong: #ef8f86; --wrong-soft: #3a2220; --hl-concl: #3a3870; --hl-prem: #6cc4d4; --hl-sig: #e0b44d; --hl-pivot: #ef8f86;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12131c; --surface: #1a1c28; --ink: #e6e8f0; --muted: #9ba1b5; --line: #2b2e3d; --stim: #222534;
  --accent: #a7a3ff; --accent-ink: #12131c; --accent-soft: #2a2950; --right: #6fcf9f; --right-soft: #183427;
  --wrong: #ef8f86; --wrong-soft: #3a2220; --hl-concl: #3a3870; --hl-prem: #6cc4d4; --hl-sig: #e0b44d; --hl-pivot: #ef8f86;
  color-scheme: dark;
}
:root[data-size="s"] { --fs: 15px; }
:root[data-size="m"] { --fs: 17px; }
:root[data-size="l"] { --fs: 19px; }
:root[data-size="xl"] { --fs: 21px; }
:root[data-font="literata"] { --font-read: "Literata", Georgia, serif; }
:root[data-font="sourceserif"] { --font-read: "Source Serif 4", Georgia, serif; }
:root[data-font="plex"] { --font-read: "IBM Plex Sans", system-ui, sans-serif; }
:root[data-font="atkinson"] { --font-read: "Atkinson Hyperlegible", system-ui, sans-serif; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-ui); font-size: var(--fs); line-height: 1.5;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 0 112px;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Top bar */
.bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bg);
  max-width: 680px; margin: 0 auto; display: flex; align-items: center; gap: 12px; padding-block: 10px;
}
.brand { font-weight: 600; letter-spacing: 0.01em; font-size: 0.95em; white-space: nowrap; }
.brand span { color: var(--accent); }
.step { flex: 1; min-width: 0; text-align: center; font-size: 0.78em; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-btn { width: 44px; height: 44px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; display: grid; place-content: center; gap: 4px; cursor: pointer; }
.menu-btn span { display: block; width: 18px; height: 2px; background: var(--ink); border-radius: 2px; }

/* Screen */
.screen { max-width: 680px; margin: 0 auto; display: grid; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: grid; gap: 14px; min-width: 0; }
.ask { margin: 0; font-weight: 600; }
.stim {
  margin: 0; background: var(--stim); border-radius: 10px; padding: 14px 16px;
  font-family: var(--font-read); font-size: 1.04em; line-height: 1.65; font-size-adjust: 0.52;
}
.choices { display: grid; gap: 8px; }
.choice {
  width: 100%; min-height: 52px; padding: 12px 14px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; line-height: 1.35;
}
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice:disabled { cursor: default; }
.choice.right { border-color: var(--right); background: var(--right-soft); }
.choice.wrong { border-color: var(--wrong); background: var(--wrong-soft); }
/* Right and wrong are never shown by color alone (brand bible): an icon marks each. */
.choice.right::after { content: " ✅"; }
.choice.wrong::after { content: " ❌"; }
.choice.none { color: var(--muted); }

.feedback { display: grid; gap: 10px; }
.verdict { margin: 0; font-weight: 700; font-size: 1.05em; }
.verdict.right { color: var(--right); }
.verdict.wrong { color: var(--wrong); }
.kv { margin: 0; }
.kv b { font-weight: 600; }
.type-tag { font-size: 0.78em; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

/* Highlights: each uses form as well as color */
.h-concl { background: var(--hl-concl); font-weight: 600; border-radius: 3px; box-decoration-break: clone; -webkit-box-decoration-break: clone; padding: 0 2px; }
.h-prem { text-decoration: underline; text-decoration-color: var(--hl-prem); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.h-sig { color: var(--hl-sig); font-style: italic; font-weight: 600; }
.h-pivot { color: var(--hl-pivot); font-style: italic; font-weight: 600; text-decoration: underline wavy; text-underline-offset: 3px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.8em; color: var(--muted); margin: 0; }
.legend span { white-space: nowrap; }

/* Next bar */
.next-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 12px max(16px, env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.primary {
  display: block; width: 100%; max-width: 680px; margin: 0 auto; min-height: 54px; border: none; border-radius: 14px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 1em; cursor: pointer;
}
/* Next after a question is answered: a ring, plus a short pulse where motion is allowed. Space / Enter work only now. */
.primary.ready { outline: 3px solid var(--accent); outline-offset: 3px; }
@media (prefers-reduced-motion: no-preference) {
  .primary.ready { animation: nextPulse 900ms ease-out 2; }
  @keyframes nextPulse { 50% { outline-offset: 7px; } }
}

/* Reading comprehension */
.rc-passage p { margin: 0 0 0.85em; }
.rc-passage p:last-child { margin-bottom: 0; }
.rcq { scroll-margin-top: 72px; }
.choice .ltr { font-weight: 600; margin-right: 10px; color: var(--muted); }
.rc-label { font-family: var(--font-ui); font-size: 0.72em !important; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin: 0.4em 0 0.35em !important; }
.rc-label:first-child { margin-top: 0 !important; }

/* RC lesson highlights: seven roles from twimoon-rc-lessons.json. Each pairs a tint with a form, so none relies on color alone. */
:root {
  --rh-claim: #d7e6ff; --rh-signal: #ece0ff; --rh-evidence: #d9f0dc; --rh-view: #ffe3c7;
  --rh-concession: #e4e5ea; --rh-target: #fff0a3; --rh-trap: #ffd6d2; --rh-trap-line: #b5443a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --rh-claim: #233a63; --rh-signal: #3d2a5e; --rh-evidence: #1f4229; --rh-view: #573a1c;
    --rh-concession: #34374a; --rh-target: #5a4d12; --rh-trap: #5c2420; --rh-trap-line: #ef8f86;
  }
}
:root[data-theme="dark"] {
  --rh-claim: #233a63; --rh-signal: #3d2a5e; --rh-evidence: #1f4229; --rh-view: #573a1c;
  --rh-concession: #34374a; --rh-target: #5a4d12; --rh-trap: #5c2420; --rh-trap-line: #ef8f86;
}
mark.rh { color: inherit; border-radius: 3px; padding: 0 1px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.rh-claim { background: var(--rh-claim); font-weight: 600; }
.rh-signal { background: var(--rh-signal); font-style: italic; }
.rh-evidence { background: var(--rh-evidence); text-decoration: underline; text-underline-offset: 3px; }
.rh-view { background: var(--rh-view); text-decoration: underline dotted; text-underline-offset: 3px; }
.rh-concession { background: var(--rh-concession); }
.rh-target { background: var(--rh-target); outline: 1.5px solid currentColor; outline-offset: 0; }
.rh-trap { background: var(--rh-trap); text-decoration: underline wavy var(--rh-trap-line); text-underline-offset: 3px; }
.rc-caps { margin: 0; padding-left: 1.3em; display: grid; gap: 8px; }
.rc-caps mark { font-family: var(--font-read); }
.rc-strat h3 { margin: 0 0 4px; font-size: 1em; }
.rc-strat ol { margin: 0; padding-left: 1.3em; display: grid; gap: 4px; }
.rc-stem { margin: 0 0 4px; font-style: italic; }

/* Lessons */
.lesson dl { margin: 0; display: grid; gap: 12px; }
.lesson dt { font-size: 0.72em; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.lesson dd { margin: 3px 0 0; min-width: 0; }
.lesson h2 { margin: 0; font-size: 1.3em; line-height: 1.2; text-wrap: balance; }
.lesson .kicker { margin: 0; font-size: 0.75em; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.shape { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.9em; }
.take { font-weight: 600; }
.lesson-read { font-family: var(--font-read); font-size-adjust: 0.52; }

.list { display: grid; gap: 18px; }
.group h3 { margin: 0 0 8px; font-size: 0.78em; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.group ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.group button {
  width: 100%; text-align: left; min-height: 48px; padding: 10px 14px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; display: flex; justify-content: space-between; gap: 10px; align-items: center;
}
.group button .seen { font-size: 0.75em; color: var(--muted); white-space: nowrap; }
.back { justify-self: start; background: none; border: none; color: var(--accent); cursor: pointer; padding: 6px 0; font-weight: 500; min-height: 40px; }

.summary { text-align: center; }
.summary .big { font-size: 2.4em; font-weight: 700; margin: 0; font-variant-numeric: tabular-nums; }

/* Menu */
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / 0.35); z-index: 20; }
.menu {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 21; width: min(340px, 88vw); overflow-y: auto;
  background: var(--surface); border-left: 1px solid var(--line);
  padding: calc(14px + env(safe-area-inset-top, 0px)) calc(18px + env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) 18px;
  display: grid; align-content: start; gap: 18px;
}
.menu-head { display: flex; justify-content: space-between; align-items: center; }
.menu-head h2 { margin: 0; font-size: 1.1em; }
.close { width: 44px; height: 44px; border: none; background: none; font-size: 1.1em; cursor: pointer; }
fieldset { border: none; margin: 0; padding: 0; display: grid; gap: 4px; }
legend { font-size: 0.72em; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; padding: 0; }
fieldset > label { display: flex; align-items: center; gap: 10px; min-height: 40px; cursor: pointer; }
input[type="radio"], input[type="checkbox"] { accent-color: var(--accent); width: 18px; height: 18px; margin: 0; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.seg span { display: grid; place-items: center; min-height: 42px; border: 1px solid var(--line); border-radius: 10px; font-weight: 500; }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.f-literata { font-family: "Literata", Georgia, serif; }
.f-sourceserif { font-family: "Source Serif 4", Georgia, serif; }
.f-plex { font-family: "IBM Plex Sans", system-ui, sans-serif; }
.f-atkinson { font-family: "Atkinson Hyperlegible", system-ui, sans-serif; }
.menu-note { margin: 0; font-size: 0.8em; color: var(--muted); }
.app-info { padding-top: 10px; border-top: 1px solid var(--line); }

/* Your progress (metrics).
   Chart colors are their own tokens. By default they follow the theme's colors, so light and dark work with no
   extra rules. A new color scheme can set any of them in its own theme block to tune the charts. */
:root {
  --ch-bar: var(--accent); --ch-bar-soft: var(--accent-soft); --ch-line: var(--right); --ch-warn: var(--wrong);
  --ch-track: var(--stim); --ch-grid: var(--line); --ch-text: var(--ink); --ch-muted: var(--muted); --ch-tile: var(--bg);
}
.metrics-btn { font-size: 1em; font-weight: 600; min-height: 48px; }
.share-text { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--stim); font-size: 0.9em; overflow-wrap: anywhere; }
.share-url { color: var(--accent); font-weight: 600; }
.share-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }

/* Achievements */
.ach-notice {
  position: fixed; z-index: 15; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top, 0px) + 66px);
  width: min(460px, calc(100vw - 32px)); display: flex; gap: 12px; align-items: flex-start; text-align: left;
  padding: 12px 14px; border-radius: 14px; border: 1px solid var(--accent); background: var(--surface); color: var(--ink);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.18); font-size: 0.9em; line-height: 1.35; cursor: pointer;
}
.ach-notice .ach-star { color: #d9a300; font-size: 1.5em; line-height: 1; }
@media (prefers-reduced-motion: no-preference) { .ach-notice:not([hidden]) { animation: rise 220ms ease-out; } }
.ach-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ach { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.ach.earned { border-color: var(--accent); background: var(--accent-soft); }
.ach-icon { font-size: 1.6em; line-height: 1; color: var(--muted); }
.ach.earned .ach-icon { color: #d9a300; }
.ach-body { min-width: 0; }
.ach-name { margin: 0; font-weight: 700; }
.ach-date { display: block; font-weight: 500; font-size: 0.75em; color: var(--muted); }
.ach-desc { margin: 2px 0 0; font-size: 0.85em; color: var(--muted); }
.ach:not(.earned) .ach-name { color: var(--muted); }
.ach-bar { display: inline-block; width: 90px; height: 6px; border-radius: 3px; background: var(--ch-track, var(--stim)); vertical-align: middle; margin-top: 6px; overflow: hidden; }
.ach-bar span { display: block; height: 100%; background: var(--accent); }
.ach-prog { font-size: 0.75em; color: var(--muted); margin-left: 8px; vertical-align: middle; }
.ach-share { min-height: 36px; padding: 4px 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.msec h2 { margin: 0; font-size: 1.15em; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.tile { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--ch-tile); }
.tile-big { margin: 0; font-size: 1.6em; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile-small { margin: 2px 0 0; font-size: 0.78em; color: var(--muted); }
.m-export { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chart { width: 100%; max-width: 560px; height: auto; display: block; }
.ch-label { fill: var(--ch-text); font: 11.5px var(--font-ui); }
.ch-label.small { font-size: 10px; fill: var(--ch-muted); }
.ch-value { fill: var(--ch-muted); font: 600 11px var(--font-ui); }
.ch-track { fill: var(--ch-track); }
.ch-bar { fill: var(--ch-bar); }
.ch-bar.soft { fill: var(--ch-bar-soft); stroke: var(--ch-bar); stroke-width: 1; }
.ch-bar.warn { fill: var(--ch-warn); }
.ch-grid { stroke: var(--ch-grid); stroke-dasharray: 3 3; }
.ch-line { fill: none; stroke: var(--ch-line); stroke-width: 2.5; }
.ch-dot { fill: var(--ch-line); }
.ch-key { margin: 0; font-size: 0.78em; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.key-bar { display: inline-block; width: 12px; height: 10px; background: var(--ch-bar-soft); border: 1px solid var(--ch-bar); border-radius: 2px; }
.key-line { display: inline-block; width: 16px; height: 3px; background: var(--ch-line); border-radius: 2px; margin-left: 8px; }
.tbl-wrap { overflow-x: auto; }
.mtable { width: 100%; border-collapse: collapse; font-size: 0.85em; }
.mtable th { text-align: left; font-size: 0.8em; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.mtable td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.mtable td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mtable td:first-child { min-width: 7.5em; }
.mtable td .sub { display: block; font-size: 0.82em; color: var(--muted); }
.mtable th:not(:first-child) { text-align: right; }
.cell-bar { display: inline-block; width: 46px; height: 7px; border-radius: 4px; background: var(--ch-track); margin-right: 8px; vertical-align: middle; overflow: hidden; }
.cell-bar span { display: block; height: 100%; background: var(--ch-bar); }
.debug { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.72em; padding: 8px; border: 1px dashed var(--wrong); border-radius: 8px; overflow-wrap: anywhere; display: grid; gap: 4px; }

/* Progress code: popup and menu section */
.code-scrim { z-index: 30; }
.code-box {
  position: fixed; z-index: 31; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(420px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 20px; display: grid; gap: 12px;
}
.code-box h2 { margin: 0; font-size: 1.2em; }
.code-box p { margin: 0; }
.code-big {
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 1.15em; font-weight: 600; text-align: center;
  padding: 12px; border-radius: 10px; background: var(--accent-soft); user-select: all; -webkit-user-select: all; overflow-wrap: anywhere;
}
.code-menu .code-big { font-size: 1em; padding: 10px; }
.code-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ghost {
  display: grid; place-items: center; min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--accent); font-weight: 500; text-decoration: none; text-align: center; cursor: pointer; font-size: 0.9em;
}
.code-menu { display: grid; gap: 10px; }
.linkish { background: none; border: none; padding: 0; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }
.linkish.small { font-size: 0.8em; justify-self: start; min-height: 32px; }
.menu-note.warn { color: var(--wrong); }
.bk-panel { display: grid; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; }
.bk-head { margin: 4px 0 0; font-weight: 600; font-size: 0.9em; }
.bk-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.bk-list li { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; font-size: 0.85em; }
.code-form { display: grid; gap: 6px; margin: 4px 0 0; }
.code-form label { font-size: 0.85em; }
.code-row { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.code-row input {
  min-width: 0; min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); font: inherit; font-size: 16px; font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

@media (prefers-reduced-motion: no-preference) {
  .card { animation: rise 180ms ease-out; }
  @keyframes rise { from { transform: translateY(6px); opacity: 0.6; } to { transform: none; opacity: 1; } }
}
