/* ==========================================================================
   The ONE theme layer for tool pages: light first, then dark
   --------------------------------------------------------------------------
   Every tool page loads this file before its own <style>. The :root block
   below is the LIGHT palette -- every shared token at its shared value, plus
   the body base every tool used to repeat (font, ink, background). The html[data-theme="dark"]
   blocks after it are the dark override, activated by assets/theme.js (or
   the inline FOUC snippet in <head>) setting <html data-theme="dark">.

   A tool declares ONLY the tokens it adds or changes, in its own :root after
   this file (later wins at equal specificity). It does not repeat the
   shared palette: scripts/test-tool-source.js fails a page that does.

   Until 2026-09-25 this file was dark-only and every tool carried its own
   light :root. A tool that forgot it had EVERY custom property undefined in
   light mode -- transparent header, white-on-white buttons, Times New Roman
   -- and looked perfect in dark, so both MCAS apps shipped that way. Defining
   light here makes that bug impossible instead of documented.

   Naming: the tools grew two spellings for some tokens (--gray-soft / --gs,
   --maroon-dark / --maroon-dk, --radius / --r). Both are defined, in both
   themes, so either spelling reads the same value.
   ========================================================================== */

:root {
  /* Tell the browser which theme the page is in, so native controls (select,
     checkbox, date input, scrollbars) draw to match. Without it they stayed
     light in dark mode on every tool page that did not set it itself. */
  color-scheme: light;
  --bg: var(--brand-page);
  --card: #fff;
  --ink: #1b1b1d;
  --muted: #6b6b70;
  --line: #E3E6F0;
  --gray: #9EA2A6;
  --gray-soft: #c9ccce;
  --gs: #c9ccce;

  /* The brand colour comes from assets/brand.css, generated from
     site.config.js brand.colors; these names are kept so every tool keeps
     working. Never write a brand hex here or in a tool. */
  --maroon: var(--brand-primary);
  --maroon-dark: var(--brand-primary-dark);
  --maroon-dk: var(--brand-primary-dark);
  --maroon-text: var(--brand-text);
  --search-border: var(--line);

  --ok: #1f7a3d;
  --no: #b22338;
  --warn: #8a5a00;
  --teal: #1C7293;
  --raise: #EDF0F8;
  --sunken: #F0F2F8;

  --radius: 14px;
  --r: 14px;
}
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

/* Readable font (2026-09-27). Atkinson Hyperlegible Next, Braille Institute,
   OFL 1.1 (assets/vendor/fonts/OFL.txt), a variable file that covers 400 and 700.
   Switched on from the gear (settings.js writes lehs.font and sets
   html[data-font="readable"]). The rule needs !important because most tool
   pages still set body{font-family} in their own <style>; KaTeX keeps its
   own faces so math is unchanged. The same two rules sit in styles.css for
   the launchpads, which never load this file. */
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("vendor/fonts/AtkinsonHyperlegibleNext.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("vendor/fonts/AtkinsonHyperlegibleNext-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
html[data-font="readable"] :where(body, body *):not(.katex, .katex *, code, pre, kbd, samp, .mny) {
  font-family: "Atkinson Hyperlegible Next", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
}

/* ==========================================================================
   Dark override. Every alias above is re-pointed here; a tool that never
   reads a given alias is unaffected.
   ========================================================================== */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: var(--brand-page);
  --card: #1B2038;
  --ink: #e6e8eb;
  --muted: #9aa0a8;
  --line: #2C3354;
  --gray-soft: #3a3f49;
  --gs: #3a3f49;
  --gray: #8a9099;

  /* The dark brand values (assets/brand.css) are lightened for contrast
     against the dark background. */
  --maroon: var(--brand-primary);
  --maroon-dark: var(--brand-primary-dark);
  --maroon-dk: var(--brand-primary-dark);
  /* --maroon itself is tuned as a fill/accent color, not body text. Anything
     that sets it as a foreground color (link, label) reads --maroon-text,
     which stays legible at normal text size. */
  --maroon-text: var(--brand-text);
  /* Dark-mode border for controls whose light-mode border comes from --line
     (e.g. the tile search box) -- --line alone is under 3:1 against --bg. */
  --search-border: #6b7280;

  /* Status colors, when a tool defines them. */
  --ok: #4ade80;
  --no: #f87171;
  --sunken: #171B30;
}

/* ---------- Core surfaces ---------- */
html[data-theme="dark"] body {
  background: var(--bg);
  color: var(--ink);
}
html[data-theme="dark"] .card {
  background: var(--card);
}

/* How to use this. One disclosure on every tool page. Colors are the shared
   tokens, so the dark override above restyles it with no second palette.
   The summary is the control: 44px tall, and the focus ring is the keyboard
   target. A hub's own guide (how-to-hub) and a PhET note (how-to-phet) stay
   visible when that page is framed inside another hub. A plain guide hides
   there, so a view does not repeat the hub's instructions. The header
   calculator's ?embed=1 hides the guide so only the keypad shows. */
.how-to {
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--r, 14px);
  background: var(--card);
  color: var(--ink);
}
.how-to > summary {
  box-sizing: border-box;
  min-height: 44px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
}
.how-to > summary:focus-visible {
  outline: 2px solid var(--maroon);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--maroon);
}
.how-to-body {
  padding: 0 14px 12px;
  font-size: .95rem;
  line-height: 1.5;
}
.how-to-body p,
.how-to-body li { margin: 0 0 8px; }
.how-to-body ul { margin: 0; padding-left: 1.25em; }
.how-to-body li:last-child,
.how-to-body p:last-child { margin-bottom: 0; }
html.lab-embed .how-to:not(.how-to-phet):not(.how-to-hub) { display: none !important; }
html.embed .how-to { display: none !important; }
@media print { .how-to { display: none !important; } }

/* ---------- Canvas exception ----------
   Canvas plot areas (grapher, quadratic, slope-explorer, stats, systems,
   transformations) draw hardcoded light-mode colors onto their bitmap and
   are NOT re-themed. Give them an explicit light "tile" treatment so they
   read as an intentional light plot surface sitting on a dark card, rather
   than a broken/undithered element. */
html[data-theme="dark"] canvas {
  background: #fff;
  border-radius: 8px;
}

/* ---------- Theme toggle button ---------- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  margin-left: 8px;
  flex: none;
  border: 1px solid rgba(255, 255, 255, .5);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: background .14s ease, border-color .14s ease;
}
.theme-toggle:hover {
  background: rgba(255, 255, 255, .15);
  border-color: #fff;
}
.theme-toggle:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* ---------- Reduced-motion-safe transition ---------- */
@media (prefers-reduced-motion: no-preference) {
  body,
  .card {
    transition: background-color .15s ease, color .15s ease;
  }
}

/* ==========================================================================
   Per-tool special cases
   ========================================================================== */

/* NOTE: tools/mcas/ was removed 2026-08-31 (the bank moved upstream) and came
   back 2026-09-09 as a copy of that bank, skinned by assets/mcas.css, so the
   dashboard these rules were written for no longer reads them. KEPT ON PURPOSE: the
   selectors are generic (select, #search, .toolbar, .tray ...) and other tools
   still rely on them for dark mode. Do not delete as "dead CSS" without
   checking each selector against the remaining tools.
   Original rationale: the MCAS item bank used the standard token names for
   most chrome, but several "chip" surfaces (sticky toolbar, filter panel,
   multi-select popovers, the worksheet tray, inputs) are hardcoded to
   literal #fff rather than var(--card). Without this, the MCAS dashboard
   would go half-dark: dark page background with bright white toolbars. */
html[data-theme="dark"] .toolbar,
html[data-theme="dark"] .filterpanel,
html[data-theme="dark"] .ms-trigger,
html[data-theme="dark"] .ms-pop,
html[data-theme="dark"] .ms-grp,
html[data-theme="dark"] .tray,
html[data-theme="dark"] #search,
html[data-theme="dark"] .tb-btn,
html[data-theme="dark"] .f select,
html[data-theme="dark"] select,
html[data-theme="dark"] .tray-foot button {
  background: var(--card);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] .tb-btn[aria-pressed="true"] {
  background: var(--maroon);
  color: #fff;
  border-color: var(--maroon);
}

/* ==========================================================================
   Per-tool dark-mode surface overrides
   --------------------------------------------------------------------------
   Most tools hardcode LITERAL light hex backgrounds (#fff, #faf8f7, #f5f0f1,
   #f1ecec, #ece7e6, #fdf4f5, #fff8e5, #eef7ee, #e8f5ec, #fde8ea, #fef3c7,
   etc.) on buttons/boxes/inputs while the TEXT color uses var(--ink) /
   var(--maroon) / var(--ok) / var(--no), which DO flip in dark mode. Result:
   a light surface with near-invisible flipped-light text. Each block below
   re-surfaces one tool's literal-light elements to the dark palette:
     - raised control surface: #242832
     - input surface:          #1a1d23  (= var(--card))
     - borders:                var(--line)/#2a2e37 or var(--gray-soft)/#3a3f49
     - success tint:           bg #12351f / text #4ade80
     - warning tint:           bg #3a2e12 / text #fbbf24
     - error tint:             bg #3a1518 / text #f87171
   Canvas plot areas are intentionally NOT touched (handled above). Question/
   figure <img> containers (.fig, .q-image) are also left with a light
   background on purpose -- they hold external light-background image assets,
   same rationale as canvas.
   ========================================================================== */

/* ---------- Shared local accent token used by systems + transformations ---------- */
html[data-theme="dark"] {
  --teal: #4fd1d9;
}

/* ---------- Global: every tool's inputs/selects/textareas ---------- */
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] math-field {
  background: #1a1d23;
  color: var(--ink);
  border-color: #3a3f49;
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
  color: #7a808a;
}

/* ---------- calc: keypad (worst offender -- white digit keys, faint text) ---------- */
html[data-theme="dark"] .btn.fn,
html[data-theme="dark"] .btn.ctrl,
html[data-theme="dark"] .btn.op,
html[data-theme="dark"] .btn.num {
  background: #242832;
}

/* ---------- converter ---------- */
html[data-theme="dark"] .bar-track {
  background: #2a2e37;
}
html[data-theme="dark"] .btn.secondary {
  background: #242832;
}
html[data-theme="dark"] .result-box {
  background: #242832;
}

/* ---------- core-skills ---------- */
html[data-theme="dark"] .pills button:not([aria-pressed="true"]) {
  background: #242832;
}
html[data-theme="dark"] .reveal {
  background: #242832;
}

/* ---------- exit-ticket ---------- */
html[data-theme="dark"] .btn.sec {
  background: #242832;
}
html[data-theme="dark"] .btn.dng {
  background: #242832;
  border-color: #5a2530;
}
html[data-theme="dark"] .type-pills button:not([aria-pressed="true"]):not(.on) {
  background: #242832;
}
html[data-theme="dark"] .code-big {
  background: #242832;
  border-color: #5a3540;
}
html[data-theme="dark"] .resume-box,
html[data-theme="dark"] .rules-box,
html[data-theme="dark"] .info-box {
  background: #3a2e12;
  border-color: #6b5518;
  color: #fbbf24;
}
html[data-theme="dark"] .resume-box .rb-meta {
  color: #e0c27a;
}
html[data-theme="dark"] .chip:not(.sel) {
  background: #242832;
}
/* Four tools namespace their card class rather than using .card, so the rule
   below would have missed them -- and since they now carry a literal light
   border like every other card, without this they would show a bright #ece7e6
   hairline in dark mode. */
html[data-theme="dark"] .lp-card,
html[data-theme="dark"] .pr-card,
html[data-theme="dark"] .ps-card,
html[data-theme="dark"] .sd-card,
html[data-theme="dark"] .card {
  /* Matches the launchpad tile, which uses var(--line)/#2a2e37 in dark. This
     was #3a3f49 (--gray-soft), a heavier line than the tiles a student has
     just clicked through, so a tool card read as a different component from
     the thing that opened it. Both values are in the dark palette; the card
     had simply been assigned the wrong one. */
  border-color: #2a2e37;
}

/* ---------- geometry ---------- */
html[data-theme="dark"] .shape-btn {
  background: #242832;
}
html[data-theme="dark"] .shape-btn[aria-pressed="true"] {
  background: #3a1520;
}
html[data-theme="dark"] .result-row {
  background: #242832;
}

/* ---------- grapher ---------- */
html[data-theme="dark"] .ro {
  background: #242832;
}

/* ---------- groups / timer: mode + secondary buttons ---------- */
html[data-theme="dark"] .modes button:not([aria-pressed="true"]):not(.active) {
  background: #242832;
}
html[data-theme="dark"] .presets button:not([aria-pressed="true"]),
html[data-theme="dark"] .iconbtn {
  background: #242832;
}

/* Giant status faces are not controls. Their glyphs overflow the line
   box and steal clicks from nearby buttons (Class Timer Stopwatch). */
.timer-display,
.picker-display,
.picked-name,
.live-prompt,
.q-num {
  pointer-events: none;
}

/* ---------- mcas-practice (tool removed 2026-08-31; .choice/.nofig kept
     because test-taker and other tools reuse these class names) ---------- */
html[data-theme="dark"] .topicsel {
  background: #1a1d23;
}
html[data-theme="dark"] .nofig {
  background: #3a2e12;
  color: #fbbf24;
}
html[data-theme="dark"] .choice {
  background: #1a1d23;
}
html[data-theme="dark"] .choice.correct {
  background: #12351f;
}
html[data-theme="dark"] .choice.wrong {
  background: #3a1518;
}

/* ---------- quadratic ---------- */
html[data-theme="dark"] .form-row {
  background: #242832;
}
html[data-theme="dark"] .disc-box.two {
  background: #12351f;
}
html[data-theme="dark"] .disc-box.one {
  background: #3a2e12;
  color: #fbbf24;
}
html[data-theme="dark"] .disc-box.none {
  background: #3a1518;
}

/* ---------- stats ---------- */
html[data-theme="dark"] .stepper button,
html[data-theme="dark"] .pills button:not([aria-pressed="true"]) {
  background: #242832;
}
html[data-theme="dark"] .stepper button:hover,
html[data-theme="dark"] .pills button:not([aria-pressed="true"]):hover {
  background: #2f3542;
}
html[data-theme="dark"] #data-err {
  background: #3a1518;
}

/* ---------- systems ---------- */
html[data-theme="dark"] .solution {
  background: #242832;
}
html[data-theme="dark"] .solution.none {
  background: #3a1518;
  color: #f87171;
}
html[data-theme="dark"] .solution.infinite {
  background: #0f3a3d;
  color: #5eead4;
}

/* ---------- transformations ---------- */
html[data-theme="dark"] .mapping .img {
  color: #5eead4;
}

/* ---------- test-builder / test-taker / test-results / exit-ticket shared chrome ---------- */
html[data-theme="dark"] .center-card,
html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .resp-card,
html[data-theme="dark"] .recent-row {
  border-color: #3a3f49;
}
html[data-theme="dark"] .preview {
  background: #242832;
}
html[data-theme="dark"] .key-box {
  background: #12351f;
  border-color: #2f7a4a;
}
html[data-theme="dark"] .key-box .klabel {
  color: #4ade80;
}
html[data-theme="dark"] .key-val {
  background: #0f2a18;
  color: #86efac;
}
html[data-theme="dark"] .fx-btn {
  background: #242832;
}
html[data-theme="dark"] .fx-btn:hover {
  background: #2a1c20;
}
html[data-theme="dark"] .src-tag {
  background: #12351f;
  color: #4ade80;
  border-color: #2f7a4a;
}
html[data-theme="dark"] .modal {
  background: #1a1d23;
}
html[data-theme="dark"] .bank-item:hover {
  background: #2a1c20;
}
html[data-theme="dark"] .bank-item.picked {
  background: #331c22;
}

/* ---------- test-taker ---------- */
html[data-theme="dark"] .calc-panel {
  background: #1a1d23;
  border-left-color: #3a3f49;
}
html[data-theme="dark"] .nav-btn:not(.primary) {
  background: #242832;
}
html[data-theme="dark"] .progress-bar {
  background: #2a2e37;
}
html[data-theme="dark"] .mc-opt {
  background: #1a1d23;
}
html[data-theme="dark"] .mc-opt:hover {
  background: #2a1c20;
}
html[data-theme="dark"] .mc-opt.selected {
  background: #331c22;
}
html[data-theme="dark"] .warn-box {
  background: #1a1d23;
}
html[data-theme="dark"] .warn-count {
  color: #9aa0a8;
}

/* ---------- test-results ---------- */
html[data-theme="dark"] tr.flagged td {
  background: #2a1519;
}
html[data-theme="dark"] .flag {
  background: #3a1518;
  border-color: #5a2530;
}
html[data-theme="dark"] .score-pill.good {
  background: #12351f;
  color: #4ade80;
}
html[data-theme="dark"] .score-pill.mid {
  background: #3a2e12;
  color: #fbbf24;
}
html[data-theme="dark"] .score-pill.low {
  background: #3a1518;
}
html[data-theme="dark"] .score-pill.na {
  background: #242832;
}
html[data-theme="dark"] .q-bar-track {
  background: #2a2e37;
}
html[data-theme="dark"] .btn.red {
  background: #242832;
  border-color: #5a2530;
}

/* KaTeX inherits the page ink. Without this, math stays black in dark mode
   and answer choices look empty or broken. */
html[data-theme="dark"] .katex,
html[data-theme="dark"] .katex-display {
  color: var(--ink);
}

/* ...except on paper. The bank worksheet sheet (#ws-body) and the Composer
   page (.page) stay white in dark mode because they print, so their math
   takes the sheet's own ink. The rule above used to reach inside them and
   set every expression to --ink (#ebe7de) on white: near-invisible on
   screen, and printed that way by Ctrl+P and the bank Print button. Paper
   never takes dark ink, so print drops the rule everywhere. */
html[data-theme="dark"] #ws-body .katex,
html[data-theme="dark"] #ws-body .katex-display,
html[data-theme="dark"] .page .katex,
html[data-theme="dark"] .page .katex-display {
  color: inherit;
}
@media print {
  html[data-theme="dark"] .katex,
  html[data-theme="dark"] .katex-display {
    color: inherit;
  }
}

/* ==========================================================================
   Site chrome: the tool header (.bar) and the credit footer. The chrome
   (src/chrome/) writes both on every page, so they are styled here once and
   no tool repeats them. The header is a sheet of graph paper in the brand's
   header colours (assets/brand.css): the one decorative thing on the site.
   ========================================================================== */
.bar, .site-header {
  background-color: var(--brand-header-bg);
  background-image:
    linear-gradient(var(--brand-header-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--brand-header-grid) 1px, transparent 1px);
  background-size: 18px 18px;
  background-position: -1px -1px;
  color: var(--brand-header-ink);
  border-bottom: 1px solid var(--brand-header-grid);
}
.bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
}
.bar a {
  color: inherit;
  text-decoration: none;
  font-weight: 600;
  font-size: .9rem;
}
.bar a:hover { text-decoration: underline; text-underline-offset: 3px; }
.bar a:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.bar h1 { font-size: 1.05rem; margin: 0; font-weight: 700; }

.site-credit {
  max-width: var(--maxw, 1080px);
  margin: 48px auto 0;
  padding: 16px 20px 32px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.5;
}
.site-credit p { margin: 0; }
.site-credit__made { color: var(--ink); font-weight: 600; }
html.lab-embed .site-credit { display: none; }
/* ?embed=1 on the calculator pages (html.embed, set by the page): the header
   calculator panel shows only the calculator, no header, back link or credit. */
html.embed .bar, html.embed .site-credit { display: none !important; }
@media print { .site-credit { display: none; } }
