/* Phosphor: a green CRT terminal. One column, top to bottom, like a shell session. */
:root {
  /* Where the main block starts under the header, on every screen, so moving between screens doesn't jump. */
  --stage: clamp(32px, 9vh, 96px);
  --hero: clamp(2.2em, 11vw, 3em);
  color-scheme: dark;
  --bg: #03140a;
  --bg-glow: #062a14;
  --g: #3dff8f;
  --g-dim: #2aa866;
  --g-hi: #b9ffd4;
  --g-wash: #3dff8f1f;
  --bad: #ff5c5c;
  --glow: 0 0 6px #3dff8f80;
  --font: "VT323", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
  background: radial-gradient(ellipse at 50% 35%, var(--bg-glow), var(--bg) 70%) fixed, var(--bg);
  color: var(--g);
  font: clamp(20px, 4.8vw, 26px) / 1.2 var(--font);
  /* Code answers must read as typed: no "fi"/"fl" ligatures turning undefined into undeﬁned. */
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0;
  text-shadow: var(--glow);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--g-hi); color: var(--bg); text-shadow: none; }

/* scanlines */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, #0000 0 2px, #00000059 2px 3px);
  z-index: 5;
}

.crt {
  max-width: 680px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: calc(env(safe-area-inset-top, 0px) + 22px);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
  padding-left: max(18px, env(safe-area-inset-left, 0px));
  padding-right: max(18px, env(safe-area-inset-right, 0px));
}

p { margin: 0; text-wrap: pretty; }
.bar { display: flex; justify-content: space-between; gap: 4px 12px; flex-wrap: wrap; }
.dim { color: var(--g-dim); text-shadow: none; }
.hi { color: var(--g-hi); }
.bad-text { color: var(--bad); text-shadow: 0 0 6px #ff5c5c80; }
.foot { margin-top: auto; }
.nums { font-variant-numeric: tabular-nums; }
.prog { letter-spacing: .18em; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.title { font-size: var(--hero); font-weight: 400; line-height: 1.05; margin: 0; }
.title .cursor { width: .4em; height: .72em; margin-left: .08em; vertical-align: 0; }
/* Intro: three groups (masthead, rules, start) with real air between them. */
.intro {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: clamp(32px, 6vh, 56px);
  margin-top: var(--stage);
}
/* Small label over big text: the same shape as the question, so the title becomes the term in place. */
.masthead { margin: 0; display: grid; gap: 6px; }
.rules { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; line-height: 1.3; max-width: 46ch; text-wrap: pretty; }
/* Line items: the ">" hangs in its own column so wrapped lines align with the text, not the marker. */
.rules li { display: grid; grid-template-columns: 2ch 1fr; }
.rules li::before { content: ">"; }

.prompt b { font-weight: 400; color: var(--g-hi); }
.prompt-block { display: grid; gap: 6px; margin: var(--stage) 0 8px; }
.term {
  margin: 0;
  font-size: var(--hero);
  font-weight: 400;
  line-height: 1.05;
  color: var(--g-hi);
  text-wrap: balance;
  overflow-wrap: anywhere;
}
.term.long { font-size: clamp(1.6em, 7vw, 2.2em); }
.nb, .term .nb { white-space: nowrap; }
.prompt-block .code { font-size: 1.15em; margin-top: 2px; }
.ask { margin-top: 8px; }
.prompt-block:focus { outline: none; }
.code {
  margin: 0;
  padding: 10px 12px;
  border: 1px dashed var(--g-dim);
  font: inherit;
  color: var(--g-hi);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.cursor {
  display: inline-block;
  width: .55em;
  height: 1em;
  background: var(--g);
  vertical-align: -.14em;
  box-shadow: 0 0 8px var(--g);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

button { font: inherit; }

/* Answers. A leading column holds the state mark: ">" for the one you're on, ✓ / ✗ once judged. */
.opts { display: grid; gap: 6px; }
.opt {
  all: unset;
  display: grid;
  grid-template-columns: 1.4ch 1fr;
  column-gap: .4ch;
  align-content: center;
  align-items: start;
  padding: 4px 8px 4px 4px;
  cursor: pointer;
  overflow-wrap: anywhere;
}
.opt::before { content: ""; }
.opt:disabled { cursor: default; }
.opt:not(:disabled):hover,
.opt:focus-visible { background: var(--g-wash); color: var(--g-hi); }
.opt:focus-visible { box-shadow: inset 0 0 0 1px var(--g-hi); }
.opt:not(:disabled):hover::before,
.opt:focus-visible::before { content: ">"; }
.opt.ok { background: var(--g); color: var(--bg); text-shadow: none; }
.opt.ok::before { content: "✓"; }
.opt.bad { color: var(--bad); text-shadow: 0 0 6px #ff5c5c80; }
.opt.bad::before { content: "✗"; }
/* Answered: only the answer and your pick stay lit; the rest step back. */
.opts.answered .opt:not(.ok):not(.bad) { color: var(--g-dim); text-shadow: none; opacity: .6; }

.cta {
  all: unset;
  align-self: flex-start;
  cursor: pointer;
  padding: 6px 14px;
  border: 1px solid var(--g-dim);
  color: var(--g-hi);
}
/* One focus language everywhere: hover washes, keyboard focus washes and brightens the frame.
   A solid fill only ever means "the right answer". */
.cta:hover { background: var(--g-wash); border-color: var(--g); }
.cta:focus-visible { border-color: var(--g-hi); background: var(--g-wash); }

.status { color: var(--g-hi); display: grid; gap: 8px; }
/* Question screen sections: question, choices, feedback, action. Tight inside each, clear air between. */
.crt[data-screen="question"] .opts { margin-top: 10px; }
.crt[data-screen="question"] .status { margin-top: 18px; }
.crt[data-screen="question"] .slot { margin-top: 10px; }
.crt[data-screen="question"] .status:empty + .slot { margin-top: 18px; }
.verdict { font-size: 1.25em; line-height: 1.1; }
.verdict.bad { color: var(--bad); text-shadow: 0 0 6px #ff5c5c80; }
.status:empty { display: none; }
.status .x { color: var(--g); }
.slot { min-height: 1.2em; display: flex; }
/* Timer: 15 cells drawn in CSS, one goes dark each second. Red and stepping in the last 5. */
.timer { display: flex; align-items: center; gap: 1.2ch; color: var(--g-dim); text-shadow: none; }
.timer .cells { display: flex; gap: 3px; }
.timer .cells i { width: .45em; height: .7em; background: var(--g); box-shadow: 0 0 4px #3dff8f66; }
.timer .cells i.off { background: #3dff8f1f; box-shadow: none; }
.timer.low { color: var(--bad); }
.timer.low .cells i:not(.off) { background: var(--bad); box-shadow: 0 0 6px #ff5c5c80; animation: urgent .5s steps(1) infinite; }
@keyframes urgent { 50% { opacity: .35; } }
.verdict .speed { color: var(--g); font-size: .8em; }

/* Results: today (score, verdict, marks, share), tomorrow (streak, countdown, totals), then details. */
.res-today { margin-top: var(--stage); display: grid; justify-items: start; gap: 10px; }
.res-today .row { margin-top: 14px; }
.res-next, .res-more { display: grid; justify-items: start; gap: 8px; margin-top: clamp(28px, 6vh, 52px); }
.res-more { gap: 4px; }
/* The world: a quiet label, then the numbers. Same shape on home and results. */
.world, .res-world { display: grid; justify-items: start; gap: 6px; }
.world[hidden], .res-world[hidden] { display: none; }
.res-world { margin-top: clamp(28px, 6vh, 52px); }
/* Results type steps: hero score, then rank (1.25em, bright), then where you stand (1.15em), then body, then dim meta. */
.stand { font-size: 1.15em; }
.res-world details { margin-top: 4px; }
.whist { list-style: none; padding: 0; display: grid; gap: 4px; margin: 6px 0; width: 100%; max-width: 30em; }
/* Toggles that hold a chart span the column, so the chart has a real width to fill. */
.res-world details, .res-more details { justify-self: stretch; }
.wrow { display: grid; grid-template-columns: 3ch 1fr 4ch 6ch; gap: 1.5ch; align-items: center; color: var(--g-dim); text-shadow: none; }
.wrow > :nth-child(3) { text-align: right; white-space: pre; }
.wbar { height: .6em; }
.wbar i { display: block; height: 100%; background: var(--g-dim); }
.wrow.you { color: var(--g-hi); text-shadow: var(--glow); }
.wrow.you .wbar i { background: var(--g); box-shadow: 0 0 6px #3dff8f80; }
.res-next p:empty { display: none; }
.score { margin: 0; font-size: var(--hero); font-weight: 400; line-height: 1.05; color: var(--g-hi); }
.score .unit { font-size: .45em; color: var(--g-dim); text-shadow: none; }
.rank { font-size: 1.25em; line-height: 1.1; color: var(--g-hi); }
.rank.bad { color: var(--bad); text-shadow: 0 0 6px #ff5c5c80; }
.cats { display: flex; flex-wrap: wrap; gap: 4px 2.5ch; color: var(--g-dim); text-shadow: none; }
.m-ok { color: var(--g-hi); text-shadow: var(--glow); }
.m-miss { color: var(--bad); text-shadow: none; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }

/* Disclosures: [+] closed, [-] open, like a tree view. */
details summary { cursor: pointer; color: var(--g-hi); list-style: none; padding: 4px 8px; margin-left: -8px; width: fit-content; }
details summary::before { content: "[+]"; margin-right: 1ch; }
details[open] summary::before { content: "[-]"; }
details summary:hover, details summary:focus-visible { background: var(--g-wash); outline: none; }
details summary:focus-visible { box-shadow: inset 0 0 0 1px var(--g-hi); }
.opt:focus-visible, .cta:focus-visible { outline: none; }
details summary::-webkit-details-marker { display: none; }
details[open] summary { margin-bottom: 8px; }
/* History: one row per finished day, newest first. Number, date, marks, score. */
.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; width: 100%; max-width: 30em; }
.hrow { display: grid; grid-template-columns: 4ch 11ch 1fr auto; gap: 1.5ch; align-items: center; color: var(--g-dim); text-shadow: none; }
.hrow .marks { letter-spacing: .18em; }
.hrow > :nth-child(4) { text-align: right; color: var(--g); }
.hrow.you, .hrow.you > :nth-child(4) { color: var(--g-hi); text-shadow: var(--glow); }
.review { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.review li { display: grid; grid-template-columns: 1.4em 1fr; gap: 2px 6px; }
.review li > :not(:first-child) { grid-column: 2; }

/* Keyboard hints for keyboards, touch wording for touch. */
.touch-only { display: none; }

@media (pointer: coarse) {
  .key, .kbd-only { display: none; }
  .touch-only { display: inline; }
  .opt, .cta, details summary { min-height: 44px; }
  .cta { display: inline-flex; align-items: center; }
  details summary { display: flex; align-items: center; }
  .opts { gap: 8px; }
}

/* On phones, the Next button spans the width so it's an easy tap. */
@media (pointer: coarse) and (max-width: 600px) {
  .crt[data-screen="question"] .slot .cta { flex: 1; justify-content: center; }
}

/* feedback */
.crt.hit { animation: hit .35s ease-out; }
@keyframes hit { from { filter: brightness(1.7); } to { filter: none; } }
.crt.miss { animation: miss .3s steps(3); }
@keyframes miss { 33% { transform: translateX(-4px); } 66% { transform: translateX(4px); } }

@media (prefers-reduced-motion: reduce) {
  .cursor, .timer.low .cells i { animation: none; }
  .crt.hit, .crt.miss { animation: none; }
}

/* Cookie notice: a small terminal window pinned bottom-right, under the scanlines. */
.notice {
  position: fixed;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  left: auto;
  width: min(26em, calc(100vw - 32px));
  z-index: 4;
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  font-size: .8em;
  background: var(--bg);
  border: 1px solid var(--g-dim);
  box-shadow: 0 0 0 4px var(--bg), 0 0 18px #3dff8f33;
}
.notice .bar { flex-wrap: nowrap; align-items: baseline; }
.notice .bar .hi { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notice-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 4px; }
.notice-x, .notice-out {
  all: unset;
  cursor: pointer;
  color: var(--g-dim);
  text-shadow: none;
}
.notice-out { text-decoration: underline; text-underline-offset: 3px; }
.notice-x:hover, .notice-out:hover, .notice-x:focus-visible, .notice-out:focus-visible { color: var(--g-hi); }
.notice-x:focus-visible, .notice-out:focus-visible { outline: 1px solid var(--g-hi); outline-offset: 2px; }
@media (pointer: coarse) {
  .notice-x, .notice-out { min-height: 44px; display: inline-flex; align-items: center; }
}
