/* One Question Math
   Layout: one narrow column on faint graph paper. The current question is the only big thing on
   screen; tools (stuck, calculator) sit quietly below it; the learner's own findings collect last. */

@font-face { font-family: "Figtree"; src: url("/fonts/figtree-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Figtree"; src: url("/fonts/figtree-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "Figtree"; src: url("/fonts/figtree-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "Figtree"; src: url("/fonts/figtree-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "STIX Two Text"; src: url("/fonts/stix-two-text-latin-400-normal.woff2") format("woff2"); font-weight: 400 500; font-style: normal; font-display: swap; }
@font-face { font-family: "STIX Two Text"; src: url("/fonts/stix-two-text-latin-600-normal.woff2") format("woff2"); font-weight: 600 700; font-style: normal; font-display: swap; }
@font-face { font-family: "STIX Two Text"; src: url("/fonts/stix-two-text-latin-400-italic.woff2") format("woff2"); font-weight: 400 700; font-style: italic; font-display: swap; }

:root {
  --paper: #F5F7FA;
  --surface: #FFFFFF;
  --ink: #18202C;
  --muted: #566073;
  --line: #DCE1E9;
  --grid: rgba(31, 92, 153, 0.055);
  --accent: #1F5C99;
  --accent-ink: #FFFFFF;
  --accent-soft: #E7EFF8;
  --good: #1B7149;
  --good-bg: #E5F2EA;
  --warn: #87500F;
  --warn-bg: #FAEEDD;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px -12px rgba(16, 24, 40, 0.14);
  --font-math: "STIX Two Text", "Cambria Math", Cambria, Georgia, serif;
  --font-ui: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #10141B; --surface: #171C25; --ink: #E6E9EF; --muted: #9AA4B5; --line: #29303D;
    --grid: rgba(127, 176, 230, 0.05); --accent: #82B3E8; --accent-ink: #0D1320; --accent-soft: #1B2638;
    --good: #72CB9E; --good-bg: #15281E; --warn: #E7B46E; --warn-bg: #2A2116;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
var { font-family: var(--font-math); font-style: italic; }
button { font: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: 12px; top: -48px; z-index: 20;
  background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: 8px; font-weight: 600;
}
.skip:focus { top: 12px; }

/* Header */
.site-header {
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.site-header-inner {
  max-width: 580px; margin: 0 auto; padding-block: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.brand-mark { width: 28px; height: 28px; flex: none; }
.brand-mark rect { fill: var(--accent); }
.brand-mark path { fill: none; stroke: var(--accent-ink); stroke-width: 2.4; stroke-linecap: round; }
.brand-mark circle { fill: var(--accent-ink); }
.site-header nav a { color: var(--muted); text-decoration: none; font-weight: 600; font-size: 15px; padding: 6px 2px; }
.site-header nav a:hover, .site-header nav a[aria-current="page"] { color: var(--ink); }

/* Page column */
.wrap {
  max-width: 580px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 28px 64px;
  display: flex; flex-direction: column; gap: 22px;
}
.wrap:focus { outline: none; }
.wrap > * { min-width: 0; }

.label { font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.notice {
  margin: 0; padding: 12px 14px; border-radius: 10px;
  background: var(--warn-bg); color: var(--warn); font-size: 15px;
}

/* Library */
.intro { display: flex; flex-direction: column; gap: 8px; }
.intro h1 { font-family: var(--font-math); font-weight: 500; font-size: clamp(1.7rem, 5.5vw, 2.2rem); line-height: 1.2; margin: 0; text-wrap: balance; }
.intro p { margin: 0; color: var(--muted); max-width: 52ch; }
.problem-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.problem-link {
  display: flex; flex-direction: column; gap: 8px;
  padding: 18px 20px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); text-decoration: none; box-shadow: var(--shadow);
  transition: border-color .15s;
}
.problem-link:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.problem-link:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
.problem-link h2 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.problem-link .q { margin: 0; font-family: var(--font-math); font-size: 1.08rem; line-height: 1.45; }
.problem-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 14px; color: var(--muted); }
.problem-meta b { font-family: var(--font-math); font-weight: 600; color: var(--ink); font-size: 1.02rem; }
.go { color: var(--accent); font-weight: 600; }

/* Problem header */
.problem { display: flex; flex-direction: column; gap: 10px; }
.back-link { align-self: flex-start; font-size: 14px; font-weight: 600; text-decoration: none; color: var(--muted); }
.back-link:hover { color: var(--ink); }
.problem-q { font-family: var(--font-math); font-size: 1.15rem; line-height: 1.45; margin: 0; text-wrap: pretty; }
.problem-a { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; font-size: 15px; color: var(--muted); }
.problem-a strong { font-family: var(--font-math); font-size: 1.15rem; color: var(--ink); font-weight: 600; }

/* Progress: one segment per top-level question, because the path really is a sequence */
.progress { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 5px; }
.seg { height: 4px; border-radius: 2px; background: var(--line); transition: background .3s; }
.seg.done { background: var(--accent); }
.seg.now { background: var(--muted); }

/* The one question */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 26px 24px 20px; display: flex; flex-direction: column; gap: 16px; box-shadow: var(--shadow);
}
.lead { margin: 0; font-size: 15px; color: var(--muted); }
.depth { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.chip {
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px; background: var(--warn-bg); color: var(--warn);
}
.depth .for { min-width: 0; overflow-wrap: anywhere; }
.question { font-family: var(--font-math); font-size: clamp(1.45rem, 4.6vw, 1.85rem); line-height: 1.3; margin: 0; text-wrap: balance; }
.question:focus { outline: none; }
.answer-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field {
  flex: 1 1 200px; min-width: 0; display: flex; align-items: center;
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--paper);
}
.field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.field input {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink);
  font-family: var(--font-math); font-size: 1.35rem; padding: 10px 14px; font-variant-numeric: tabular-nums;
}
.field input:focus { outline: none; }
.unit { padding-right: 14px; font-family: var(--font-math); font-size: 1.1rem; color: var(--muted); white-space: nowrap; }

.btn {
  font-family: var(--font-ui); font-size: 15px; font-weight: 600; line-height: 1.2;
  border-radius: 10px; padding: 12px 20px; cursor: pointer; border: 1.5px solid transparent;
}
.btn:focus-visible, .key:focus-visible, .val:focus-visible, .tool:focus-visible, .icon-btn:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-secondary { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { border-color: var(--muted); }
.btn:disabled, .tool:disabled { opacity: .5; cursor: default; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; }
.tool {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  background: transparent; color: var(--muted); border: 1.5px solid var(--line); border-radius: 10px;
  font-family: var(--font-ui); font-size: 14px; font-weight: 600; padding: 8px 14px;
}
.tool:hover:not(:disabled) { color: var(--ink); border-color: var(--muted); }
.tool[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.tool svg { width: 16px; height: 16px; flex: none; }
.feedback { min-height: 1.5em; margin: 0; font-size: 15px; font-weight: 500; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--warn); }

/* Calculator */
.calc {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.calc-display {
  display: flex; align-items: center; gap: 4px;
  background: var(--paper); border: 1.5px solid var(--line); border-radius: 10px;
}
.calc-display:focus-within { border-color: var(--accent); }
.calc-display input {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink);
  font-family: var(--font-math); font-size: 1.3rem; padding: 9px 12px; text-align: right; font-variant-numeric: tabular-nums;
}
.calc-display input:focus { outline: none; }
.icon-btn { display: inline-grid; place-items: center; background: transparent; color: var(--muted); border: 0; border-radius: 8px; padding: 8px 10px; cursor: pointer; }
.icon-btn:hover { color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; }
.calc-result { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; min-height: 38px; }
.calc-result .eq { font-family: var(--font-math); font-size: 1.25rem; font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }
.calc-result .eq.placeholder { font-family: var(--font-ui); font-size: 14px; color: var(--muted); }
.use { background: var(--good-bg); color: var(--good); font-size: 14px; padding: 8px 14px; }
.keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.key {
  font-family: var(--font-math); font-size: 1.2rem; font-weight: 500; cursor: pointer;
  padding: 10px 0; border-radius: 9px; background: var(--paper); color: var(--ink); border: 1px solid var(--line);
}
.key:hover { border-color: var(--muted); }
.key.op { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.key.fn { color: var(--muted); font-family: var(--font-ui); font-size: 15px; font-weight: 600; }
.key.eq-key { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* What you've found */
.found { display: flex; flex-direction: column; gap: 8px; }
.found-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.found-head small { font-size: 13px; color: var(--muted); }
.found ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.found li {
  display: flex; justify-content: space-between; gap: 16px; align-items: center;
  padding: 5px 0; border-bottom: 1px dashed var(--line); font-size: 14.5px;
}
.found li > span { color: var(--muted); min-width: 0; }
.found li.empty { color: var(--muted); border: 0; }
.val {
  font-family: var(--font-math); font-size: 1.05rem; font-variant-numeric: tabular-nums; white-space: nowrap; cursor: pointer;
  background: transparent; color: var(--ink); padding: 3px 8px; border-radius: 7px; border: 1px solid transparent;
}
.val:hover { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }

/* Finale */
.finale { display: flex; flex-direction: column; gap: 14px; }
.finale h2 { margin: 0; font-size: 15px; font-weight: 600; color: var(--muted); }
.big { font-family: var(--font-math); font-size: 3rem; line-height: 1; margin: 0; color: var(--good); }
.finale p { margin: 0; }
.stats { display: flex; gap: 24px; flex-wrap: wrap; padding-top: 4px; }
.stat { display: flex; flex-direction: column; }
.stat b { font-family: var(--font-math); font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--muted); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Loading, error, empty, not found */
.state { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.state h1 { font-family: var(--font-math); font-weight: 500; font-size: 1.7rem; margin: 0; }
.state p { margin: 0; color: var(--muted); max-width: 52ch; }
.skeleton { display: flex; flex-direction: column; gap: 14px; }
.sk { background: var(--line); border-radius: 8px; animation: pulse 1.4s ease-in-out infinite; }
.sk-line { height: 18px; }
.w40 { width: 40%; } .w90 { width: 90%; }
.sk-card { height: 220px; border-radius: 14px; }
@keyframes pulse { 50% { opacity: .55; } }

.enter { animation: rise .32s ease-out; }
@keyframes rise { from { opacity: .35; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.flash { animation: flash .6s; }
@keyframes flash { from { background: var(--accent-soft); } }
@media (prefers-reduced-motion: reduce) {
  .enter, .shake, .flash, .sk { animation: none; }
  .seg, .problem-link { transition: none; }
}
@media (max-width: 420px) {
  .card { padding: 20px 16px 16px; }
  .answer-row .btn-primary { flex: 1 1 100%; }
}
