/* NPC design system (spec 16).
 *
 * Colors live in the three token blocks below: light, dark (chosen by hand),
 * and dark (following the device). The two dark blocks must match;
 * tests/test_design.py checks that, and checks every text/background pair
 * against WCAG AA.
 *
 * Fonts are self-hosted (OFL licenses beside them in /static/fonts):
 *   Press Start 2P for the logo only, Atkinson Hyperlegible for text,
 *   Atkinson Hyperlegible Mono for code (clear 0/O and l/1).
 */

@font-face { font-family: "Atkinson Hyperlegible"; src: url("/static/fonts/AtkinsonHyperlegible-Regular.ttf") format("truetype"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("/static/fonts/AtkinsonHyperlegible-Bold.ttf") format("truetype"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible Mono"; src: url("/static/fonts/AtkinsonHyperlegibleMono-Variable.ttf") format("truetype"); font-weight: 200 800; font-style: normal; font-display: swap; }
@font-face { font-family: "Press Start 2P"; src: url("/static/fonts/PressStart2P-Regular.ttf") format("truetype"); font-weight: 400; font-style: normal; font-display: swap; }

/* tokens: light */
:root {
  color-scheme: light;
  --bg: #fafdff;
  --card: #ffffff;
  --ink: #16171a;
  --muted: #4a5160;
  --accent: #007899;
  --on-accent: #ffffff;
  --border: #16171a;
  --line: #c9d3df;
  --bot: #eaf4f8;
  --me: #eef9f2;
  --code-bg: #eef2f6;
  --ok-bg: #10d275;
  --on-ok: #16171a;
  --err-bg: #d62411;
  --on-err: #ffffff;
  --tag-bg: #234975;
  --on-tag: #ffffff;
  --focus: #ff2674;
  --logo-line: #16171a;
}

/* tokens: dark (chosen) */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a1830;
  --card: #002859;
  --ink: #fafdff;
  --muted: #c3cfe0;
  --accent: #68aed4;
  --on-accent: #16171a;
  --border: #8fa3bf;
  --line: #234975;
  --bot: #0d3a73;
  --me: #12384a;
  --code-bg: #061227;
  --ok-bg: #10d275;
  --on-ok: #16171a;
  --err-bg: #d62411;
  --on-err: #ffffff;
  --tag-bg: #ffd100;
  --on-tag: #16171a;
  --focus: #ff2674;
  --logo-line: #dfe7f2;
}

/* tokens: dark (device) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0a1830;
    --card: #002859;
    --ink: #fafdff;
    --muted: #c3cfe0;
    --accent: #68aed4;
    --on-accent: #16171a;
    --border: #8fa3bf;
    --line: #234975;
    --bot: #0d3a73;
    --me: #12384a;
    --code-bg: #061227;
    --ok-bg: #10d275;
    --on-ok: #16171a;
    --err-bg: #d62411;
    --on-err: #ffffff;
    --tag-bg: #ffd100;
    --on-tag: #16171a;
    --focus: #ff2674;
    --logo-line: #dfe7f2;
  }
}

/* base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.5;
  background: var(--bg);
  color: var(--ink);
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; margin-top: 1em; }
a { color: var(--accent); text-underline-offset: .15em; }
a:hover { text-decoration-thickness: 2px; }
code, pre, textarea#code { font-family: "Atkinson Hyperlegible Mono", ui-monospace, "Cascadia Mono", Consolas, monospace; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 8px; top: -100px; z-index: 10; padding: 10px 14px; background: var(--card); color: var(--ink); border: 2px solid var(--border); border-radius: 8px; }
.skip:focus { top: 8px; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }

/* layout: phone first, one column, nothing wider than the screen */
.page { max-width: 760px; margin: 0 auto; padding: 16px; }
.page.narrow { max-width: 460px; padding-top: 8vh; }
main:focus { outline: none; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin: 0 0 16px; }

/* logo: "NPC" in Press Start 2P inside an outlined badge. The outline follows the
   text color (near-black in light mode, soft white in dark). All three letters are
   plain colors with no edge; the C is warm orange (Darren's picks, Nov 27).
   Press Start 2P leaves an empty pixel column on the right of every letter and an
   empty row under it, so the right and bottom padding are 1/8em smaller (less the
   letter spacing on the right) to center "NPC" in the badge. */
.logo { display: inline-flex; gap: .1em; align-items: center; padding: .45em .405em .325em .55em; border-radius: 6px; background: transparent; border: 2px solid var(--logo-line); font-family: "Press Start 2P", ui-monospace, monospace; font-size: 1rem; line-height: 1; letter-spacing: .02em; }
.logo-n { color: #007899; }
.logo-p { color: #ff2674; }
.logo-c { color: #f28c28; }
.login-head { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.login-head .logo { font-size: 1.75rem; }
.login-head .sub { font-size: 1.1rem; font-weight: 400; color: var(--muted); }

/* header */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; max-width: 760px; margin: 0 auto; padding: 12px 16px 0; }
.home { display: inline-flex; align-items: center; min-height: 44px; text-decoration: none; }
.nav { display: flex; gap: 4px; }
/* Wide screens: logo, links, then the account menu on the right. Narrow: logo and
   account menu on the first row, the links on their own row underneath. */
@media (max-width: 639px) { .top .nav { order: 3; flex-basis: 100%; } }
.nav a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 8px; font-weight: 700; text-decoration: none; color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent); color: var(--on-accent); }
.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-left: auto; }
.who { font-weight: 700; }

/* account menu (phase 8): the name in the top right opens Theme, Language and Log out */
.account { position: relative; }
.account-btn { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; cursor: pointer; list-style: none; user-select: none; }
.account-btn::-webkit-details-marker { display: none; }
.account-btn::marker { content: ""; }
.caret { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 6px solid currentColor; transition: transform .15s; }
.account[open] .caret { transform: rotate(180deg); }
.account-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; display: flex; flex-direction: column; gap: 4px; min-width: 220px; padding: 8px; background: var(--card); color: var(--ink); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); }
.account-menu form { margin: 0; }
.menu-item { display: flex; align-items: center; width: 100%; min-height: 44px; padding: 0 12px; background: transparent; color: var(--ink); border: 0; border-radius: 8px; font: inherit; font-weight: 700; text-align: left; cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { background: var(--line); }
.menu-item .muted { font-weight: 400; }
.theme-form { display: flex; align-items: center; gap: 8px; }
.theme-form label { font-weight: 700; }
.theme-form select { width: auto; min-height: 44px; }
.account-menu .theme-form { justify-content: space-between; padding: 0 0 0 12px; }
.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; }

/* controls: every tap target is at least 44px tall */
label { display: block; margin: 12px 0 4px; font-weight: 700; }
label.check { display: flex; align-items: center; gap: 10px; min-height: 44px; margin: 0; font-weight: 400; }
label.check input { width: 22px; height: 22px; flex: none; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 4px 12px 8px; margin: 8px 0; }
legend { font-weight: 700; padding: 0 4px; }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
}
select:disabled { opacity: .7; }
textarea { resize: vertical; }
textarea#code { font-size: .95rem; white-space: pre; overflow-x: auto; overflow-wrap: normal; tab-size: 4; }
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 700;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  text-decoration: none;
}
button.primary, .button.primary { background: var(--accent); color: var(--on-accent); }
button.secondary, .button.secondary { background: transparent; color: var(--accent); border-color: var(--accent); }
button.wide { width: 100%; margin-top: 16px; }
button.link { min-height: 44px; padding: 0 4px; background: none; color: var(--accent); text-decoration: underline; }
a.chip { display: inline-flex; align-items: center; text-decoration: none; }
button.chip, a.chip { min-height: 44px; padding: 6px 12px; background: transparent; color: var(--ink); border: 1px solid var(--border); border-radius: 999px; font-size: .95rem; }
button:disabled { opacity: .6; cursor: progress; }
.buttons { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
details { margin-top: 10px; }
summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; font-weight: 700; }
.alert { padding: 10px 12px; border-radius: 8px; }
.alert.error { background: var(--err-bg); color: var(--on-err); }
.alert.ok { background: var(--ok-bg); color: var(--on-ok); }
.login-tools { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

/* chat */
.welcome { font-size: 1.35rem; }
.picker { padding: 12px; margin: 8px 0 12px; border: 1px solid var(--line); border-radius: 10px; }
.picker .label { margin: 0; font-weight: 700; }
.picker-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 12px; }
@media (min-width: 600px) { .picker-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.working-on { margin: 10px 0 0; padding: 6px 10px; border-radius: 8px; background: var(--tag-bg); color: var(--on-tag); font-weight: 700; overflow-wrap: anywhere; }
.log { margin: 16px 0; display: flex; flex-direction: column; gap: 10px; }
.bubble { padding: 10px 12px; border-radius: 10px; white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; }
.bubble.me { background: var(--me); align-self: flex-end; max-width: 90%; }
.bubble.bot { background: var(--bot); max-width: 100%; }
.bubble code { padding: 0 .3em; border-radius: 4px; background: var(--card); border: 1px solid var(--line); }
.bubble strong { font-weight: 700; }
/* Code in flashcards, quiz questions and answers (spans, since buttons can't hold a <pre>). */
span.code-block { display: block; margin: .4em 0; padding: .5em .7em; border-radius: 8px; background: var(--bg); color: var(--ink); border: 1px solid var(--line); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .95rem; font-weight: 400; white-space: pre-wrap; overflow-wrap: anywhere; text-align: left; }
.card-face code, .choice code, .quiz-question code, .quiz-result code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; padding: 0 .3em; border-radius: 4px; border: 1px solid var(--line); font-weight: 400; }
.working-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 10px; }
.working-row .working-on { margin: 0; flex: 1 1 auto; }

/* The chat page fits the window, like a messaging app: the header, the
   "working on" line and the question box stay put, and only the
   conversation scrolls. */
body.chat-page { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
body.chat-page .top { flex: 0 0 auto; width: 100%; }
body.chat-page main { flex: 1 1 auto; min-height: 0; width: 100%; display: flex; flex-direction: column; overflow-y: auto; padding-bottom: 8px; }
body.chat-page .card.chat { flex: 1 0 auto; display: flex; flex-direction: column; margin: 0; }
body.chat-page .welcome { margin: 0 0 4px; }
body.chat-page .picker { flex: 0 0 auto; margin: 4px 0 8px; }
body.chat-page .log { flex: 1 1 0; min-height: 8rem; margin: 0; padding: 4px 4px 4px 0; overflow-y: auto; overscroll-behavior: contain; }
body.chat-page #ask-form { flex: 0 0 auto; padding-top: 8px; border-top: 1px solid var(--line); }
body.chat-page textarea#message { max-height: 30vh; }
body.chat-page textarea#code { max-height: 35vh; }
/* After the first question, the welcome line and the menus fold away to give
   the conversation room; "Change" brings the menus back. */
.chat.started .welcome { display: none; }
.chat.started:not(.picking) #picker-label, .chat.started:not(.picking) .picker-row, .chat.started:not(.picking) .no-units { display: none; }
.chat.started:not(.picking) .working-row { margin-top: 0; }

/* code never wraps or squishes blanks: it scrolls sideways in its own box */
pre {
  max-width: 100%;
  margin: 8px 0;
  padding: 10px 12px;
  overflow-x: auto;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  background: var(--code-bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: .95rem;
  tab-size: 4;
}
:not(pre) > code { padding: .1em .3em; border-radius: 4px; background: var(--code-bg); font-size: .95em; overflow-wrap: anywhere; }

/* library */
.unit h2 { padding-bottom: 6px; border-bottom: 2px solid var(--line); }
.docs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.docs li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.podcasts { margin-top: 12px; }
.podcast { margin: 0 0 12px; }
.podcast figcaption { margin-bottom: 4px; overflow-wrap: anywhere; }
.podcast audio { width: 100%; max-width: 520px; display: block; }
.speed { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.speed-label { font-weight: 700; margin-right: 2px; }
.speed button { min-width: 52px; font-variant-numeric: tabular-nums; }
.speed button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.script { margin: 8px 0 0; padding-left: 1.2em; }
.script li { margin-bottom: 4px; }
.doc-link { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 700; }
.tag { display: inline-block; min-width: 5.5em; padding: 2px 8px; border-radius: 6px; background: var(--tag-bg); color: var(--on-tag); font-size: .85rem; text-align: center; }
.crumbs { margin: 0 0 8px; }
.crumbs a { display: inline-flex; align-items: center; min-height: 44px; font-weight: 700; }
.doc .meta { margin: 0 0 6px; color: var(--muted); font-size: .95rem; }
.switch-lang { display: flex; flex-wrap: wrap; gap: 8px; }
.prose { overflow-wrap: break-word; }
.prose blockquote { margin: 12px 0; padding: 4px 14px; border-left: 4px solid var(--accent); }
.table-wrap { max-width: 100%; overflow-x: auto; }
.prose table { border-collapse: collapse; margin: 12px 0; }
.prose th, .prose td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* "This hint didn't help" and the test-student badge */
.feedback-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 6px; white-space: normal; font-size: .95rem; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--tag-bg); color: var(--on-tag); font-size: .85rem; font-weight: 700; }

/* teacher dashboard: wider, with tables that scroll sideways on a phone */
.page.wide, .top.wide { max-width: 1100px; }
.data { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: .95rem; }
.data th, .data td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.data th { font-weight: 700; white-space: nowrap; }
.data td.text { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 16em; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(9em, 1fr)); gap: 10px; margin: 8px 0; }
.stat { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.stat b { display: block; font-size: 1.5rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions form { margin: 0; }
.actions input, .actions select { width: auto; }
button.danger { background: var(--err-bg); color: var(--on-err); }
.pause-switch { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.pause-switch button { min-width: 12em; }
.safety-flag { border-left: 6px solid var(--err-bg); }
.secret { font-family: "Atkinson Hyperlegible Mono", ui-monospace, monospace; font-size: 1.2rem; overflow-wrap: anywhere; }

/* Chromebooks and desktops: more room, same single column */
@media (min-width: 900px) {
  .card { padding: 20px 24px; }
  h1 { font-size: 1.8rem; }
}

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

/* --- study tools: flashcards and Quiz Me ------------------------------------ */
.nav { flex-wrap: wrap; }
.study-form select { max-width: 100%; }
.study-status { min-height: 1.5em; margin: 12px 0 0; font-weight: 700; }
.cards { list-style: none; margin: 16px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); gap: 12px; }
.flashcard { display: flex; flex-direction: column; align-items: stretch; gap: 10px; width: 100%; min-height: 160px; padding: 14px; text-align: left; background: var(--card); color: var(--ink); border: 2px solid var(--border); border-radius: 12px; font-weight: 400; white-space: normal; }
.flashcard[aria-pressed="true"] { border-color: var(--accent); background: var(--bot); }
.card-count, .card-hint { font-size: .85rem; color: var(--muted); }
.card-face { flex: 1; font-size: 1.1rem; font-weight: 700; overflow-wrap: anywhere; }
.quiz { margin-top: 16px; }
.quiz-count { margin: 0 0 4px; color: var(--muted); font-weight: 700; }
.quiz-question { font-size: 1.25rem; overflow-wrap: anywhere; }
.quiz-question:focus { outline: none; }
.choices { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin: 12px 0; }
.choice { justify-content: flex-start; width: 100%; min-height: 56px; padding: 12px 16px; text-align: left; background: var(--card); color: var(--ink); border: 2px solid var(--border); border-radius: 12px; font-size: 1.05rem; white-space: normal; overflow-wrap: anywhere; }
.choice.right { border-color: var(--ok-bg); background: var(--ok-bg); color: var(--on-ok); }
.choice.wrong { border-color: var(--err-bg); background: var(--err-bg); color: var(--on-err); }
.choice:disabled { cursor: default; opacity: 1; }
.quiz-result p { margin: 6px 0; }
.quiz-result .ok, .quiz-result .streak { font-weight: 700; }
.quiz-result .miss { font-weight: 700; }
.scores { list-style: none; margin: 0; padding: 0; }
.scores li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
@media (min-width: 640px) { .choices { grid-template-columns: 1fr 1fr; } }

/* Slides on the doc page (phase 8): one picture at a time, arrows underneath. */
.slides { margin: 12px 0 16px; border-radius: 12px; outline-offset: 4px; }
.slide-frame { display: grid; gap: 12px; }
.slide { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; background: #ffffff; cursor: pointer; user-select: none; -webkit-user-drag: none; -webkit-touch-callout: none; }
.slide[hidden] { display: none; }
.slide-controls { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 10px; }
.slide-controls[hidden] { display: none; }
.slide-controls .chip { min-width: 56px; font-size: 1.2rem; }
.slide-controls .chip:disabled { opacity: .4; cursor: default; }
.slide-count { min-width: 9em; text-align: center; font-weight: 700; }
