/* ============================================================
   Aanya's Math Stories — pencil-sketch style
   Paper background, graphite lines, Atkinson Hyperlegible.
   ============================================================ */

:root {
  --paper:        #F4F0E4;  /* page (warm paper)            */
  --paper-card:   #FCFAF3;  /* card                         */
  --graphite:     #2A2A2A;  /* primary text / pencil lines  */
  --graphite-mid: #555048;  /* secondary text               */
  --graphite-soft:#8A8377;  /* tertiary / placeholder       */
  --line-soft:    #DCD4BF;  /* subtle dividers, grid lines  */
  --line-mid:     #BCB39C;
  --red-pencil:   #B83A3A;  /* the one accent colour        */
  --red-pencil-soft:#E0BFBF;

  --radius: 8px;
  --shadow: 0 6px 22px rgba(80, 60, 30, 0.10);

  --font: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: var(--font);
  color: var(--graphite);
  background: var(--paper);
  min-height: 100vh;
}

main.card {
  max-width: 920px;
  margin: 28px auto;
  padding: 28px 34px 36px;
  background: var(--paper-card);
  border: 1.5px solid var(--line-mid);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ----------------------------------------------------------
   Test screen — two-column layout:
   LEFT = question in words + animation/drawing area
   RIGHT = answer input + on-screen number pad
   Scratchpad spans full width below.
   ---------------------------------------------------------- */
main.test-card { max-width: 1200px; }

.test-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.brand-chip {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.5px;
  color: var(--graphite);
}
.test-top .score-meta {
  font-size: 13px;
  font-weight: 700;
  color: var(--graphite-mid);
}
.test-top #quit-test { margin-left: auto; }
/* End test reads as a reddish text link. */
#quit-test.link-btn { color: var(--red-pencil); }
#quit-test.link-btn:hover { color: var(--red-pencil); opacity: 0.78; }

.test-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 1fr);
  gap: 24px;
  align-items: start;
}
.test-col { min-width: 0; }

.panel-head {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--graphite-mid);
  border-bottom: 1.5px solid var(--line-mid);
  padding-bottom: 7px;
  margin-bottom: 14px;
}

/* In the narrow answer column, stack input → actions → keypad → result. */
.test-answer .answer-bar {
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.answer-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.test-answer .keypad { margin: 16px auto 4px; }
.test-answer #result { margin-top: 0; }

/* ---- Flip card: the right column flips to reveal the solution ---- */
.flip-card { perspective: 1600px; }
.flip-inner {
  display: grid;               /* stack both faces in one cell → tallest sets height */
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.2, 0.7, 0.3, 1);
}
.flip-card.flipped .flip-inner { transform: rotateY(180deg); }
.flip-face {
  grid-area: 1 / 1;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  min-width: 0;
}
.flip-back {
  transform: rotateY(180deg);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
/* Front-side nudge ("type your answer first") — never on the flipped face. */
.input-nudge {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--graphite-mid);
  text-align: center;
}
.input-nudge.hidden { display: none; }

/* Topic chips — flat, no rounded balloons */
.topic-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}
.topic-chip {
  display: inline-block;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 700;
  color: var(--graphite);
  background: transparent;
  border: 1.5px solid var(--graphite);
  border-radius: 2px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.topic-chip.secondary {
  color: var(--red-pencil);
  border-color: var(--red-pencil);
}

/* Question text */
h1#question-text {
  margin: 0 0 18px;
  font-size: 21px;
  line-height: 1.55;
  font-weight: 400;
  color: var(--graphite);
}
h1#question-text b { font-weight: 700; }
.ask {
  display: block;
  margin-top: 8px;
  color: var(--red-pencil);
  font-weight: 700;
}

/* SVG scene — aspect-ratio locked so the box never grows or shrinks
   when we swap between road / bar / pie scenes. */
.scene-wrap {
  background: var(--paper);
  border: 1.5px solid var(--line-mid);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 20px;
}
#scene {
  width: 100%;
  height: auto;
  display: block;
  aspect-ratio: 800 / 340;
}
#scene text {
  font-family: var(--font);
  fill: var(--graphite);
  font-weight: 400;
}
.ruler-label  { font-size: 14px; font-weight: 700; }
.city-label   { font-size: 14px; font-weight: 700; }
.tick-labels text { font-size: 11px; fill: var(--graphite-mid); }
.counter      { font-size: 17px; font-weight: 700; }
.aanya-label  { font-size: 13px; font-weight: 700; }
.qmark-text   { font-size: 26px; font-weight: 700; fill: var(--red-pencil); }
.dim-label    { font-size: 14px; font-weight: 700; fill: var(--graphite); }
.cell-annot   { font-size: 10px; font-weight: 700; fill: var(--graphite-mid); }

/* Pulsing for question mark */
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.18); }
}
#qmark-sketch.pulse, #qmark-text.pulse {
  transform-origin: center;
  transform-box: fill-box;
  animation: pulse 0.95s ease-in-out infinite;
}

/* ----------------------------------------------------------
   Answer bar (worksheet "fill in the blank" look)
   ---------------------------------------------------------- */
.answer-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  padding: 14px 16px;
  background: var(--paper);
  border: 1.5px solid var(--line-mid);
  border-radius: var(--radius);
}
.answer-bar label {
  font-weight: 700;
  font-size: 16px;
}
.input-line {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}
.prefix {
  font-size: 22px;
  font-weight: 700;
  color: var(--graphite);
}
.prefix:empty { display: none; }
.suffix:empty { display: none; }
#answer-input {
  width: 80px;
  border: none;
  border-bottom: 2.5px solid var(--graphite);
  outline: none;
  font-family: var(--font);
  font-size: 22px;
  font-weight: 700;
  color: var(--graphite);
  text-align: center;
  background: transparent;
  padding: 2px 4px;
}
#answer-input:focus { border-bottom-color: var(--red-pencil); }
#answer-input:disabled { color: var(--graphite-soft); border-bottom-style: dashed; }
.suffix {
  font-size: 22px;
  font-weight: 700;
  color: var(--graphite);
}

/* Fraction two-input layout — stacked num over denom with a horizontal bar. */
.fraction-line {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 84px;
}
.fraction-line input {
  width: 70px;
  border: none;
  outline: none;
  font-family: var(--font);
  font-size: 22px;
  font-weight: 700;
  color: var(--graphite);
  text-align: center;
  background: transparent;
  padding: 2px 4px;
  border-bottom: 2.5px solid var(--graphite);
}
.fraction-line input:focus { color: var(--red-pencil); border-bottom-color: var(--red-pencil); }
.fraction-line input:disabled { color: var(--graphite-soft); border-bottom-style: dashed; }
.fraction-line .frac-bar {
  display: block;
  width: 64px;
  height: 2.5px;
  background: var(--graphite);
  border-radius: 2px;
}
/* Fixed-denom mode: denom shown as plain text instead of a second input. */
.fraction-line .frac-denom-fixed {
  font-size: 22px;
  font-weight: 700;
  color: var(--graphite);
  text-align: center;
  min-width: 70px;
  padding: 2px 4px;
}

/* Two-integer layout (e.g. wholes + extra parts) — side-by-side labeled boxes,
   intentionally NO fraction bar so kids don't read it as a fraction. */
.two-int-line {
  display: inline-flex;
  align-items: flex-end;
  gap: 12px;
}
.two-int-field {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.two-int-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--graphite-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.two-int-line input {
  width: 70px;
  border: none;
  border-bottom: 2.5px solid var(--graphite);
  outline: none;
  font-family: var(--font);
  font-size: 22px;
  font-weight: 700;
  color: var(--graphite);
  text-align: center;
  background: transparent;
  padding: 2px 4px;
}
.two-int-line input:focus { color: var(--red-pencil); border-bottom-color: var(--red-pencil); }
.two-int-line input:disabled { color: var(--graphite-soft); border-bottom-style: dashed; }
.two-int-and {
  font-size: 16px;
  font-weight: 600;
  color: var(--graphite-soft);
  padding-bottom: 4px;
}

/* The active input the on-screen keypad is currently typing into. */
.input-line input.keypad-active {
  border-bottom-color: var(--red-pencil);
  background: rgba(184, 58, 58, 0.06);
}

/* Tap-to-choose buttons (compare questions). */
.choice-line {
  display: inline-flex;
  align-items: stretch;
  gap: 14px;
}
.choice-btn {
  font-family: var(--font);
  font-size: 26px;
  font-weight: 700;
  color: var(--graphite);
  background: var(--paper-card);
  border: 2.2px solid var(--graphite);
  border-radius: 8px;
  padding: 14px 28px;
  min-width: 92px;
  cursor: pointer;
  transition: transform 0.07s ease, background 0.15s, border-color 0.15s;
}
.choice-btn:hover:not(:disabled) { transform: translateY(-2px); }
.choice-btn:active:not(:disabled) { transform: translateY(1px); }
.choice-btn.chosen-correct {
  border-color: #2E7D32; background: rgba(46, 125, 50, 0.14); color: #1B5E20;
}
.choice-btn.chosen-wrong {
  border-color: var(--red-pencil); background: rgba(184, 58, 58, 0.12); color: var(--red-pencil);
}
.choice-btn.is-answer {
  border-color: #2E7D32; border-style: dashed;
}
.choice-btn:disabled { cursor: default; }

/* Mixed-number input — a whole-number box + a stacked num/denom fraction. */
.mixed-line {
  display: inline-flex;
  align-items: flex-end;
  gap: 14px;
}
.mixed-field {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.mixed-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--graphite-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.mixed-and {
  font-size: 16px;
  font-weight: 600;
  color: var(--graphite-soft);
  padding-bottom: 4px;
}
.mixed-frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 78px;
}
.mixed-line input {
  width: 70px;
  border: none;
  border-bottom: 2.5px solid var(--graphite);
  outline: none;
  font-family: var(--font);
  font-size: 22px;
  font-weight: 700;
  color: var(--graphite);
  text-align: center;
  background: transparent;
  padding: 2px 4px;
}
.mixed-line input:focus { color: var(--red-pencil); border-bottom-color: var(--red-pencil); }
.mixed-line input:disabled { color: var(--graphite-soft); border-bottom-style: dashed; }
.mixed-frac .frac-bar {
  display: block;
  width: 64px;
  height: 2.5px;
  background: var(--graphite);
  border-radius: 2px;
}

/* Tap-to-arrange (order) input — a pool of chips tapped into a sequence. */
.order-line {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  width: 100%;
}
.order-instruction {
  font-size: 14px;
  font-weight: 600;
  color: var(--graphite-soft);
}
.order-chosen, .order-pool {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 44px;
}
.order-chosen {
  padding: 6px;
  border: 2px dashed var(--line-soft);
  border-radius: 8px;
}
.order-chosen:empty::before {
  content: "your order appears here";
  color: var(--graphite-soft);
  font-size: 13px;
  font-style: italic;
  align-self: center;
}
.order-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 700;
  color: var(--graphite);
  background: var(--paper-card);
  border: 2.2px solid var(--graphite);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: transform 0.07s ease, background 0.15s, border-color 0.15s;
}
.order-chip:hover:not(:disabled) { transform: translateY(-2px); }
.order-chip:active:not(:disabled) { transform: translateY(1px); }
.order-chip.chosen {
  border-color: var(--red-pencil);
  background: rgba(184, 58, 58, 0.07);
}
.order-chip:disabled { cursor: default; opacity: 0.85; }
.order-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--red-pencil);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}
.order-reset {
  align-self: flex-start;
  font-size: 13px;
}

/* On-screen number pad. */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-width: 280px;
  margin: 14px 0 4px;
}
.keypad.hidden { display: none; }
.keypad .key {
  font-family: var(--font);
  font-size: 22px;
  font-weight: 700;
  color: var(--graphite);
  background: var(--paper-card);
  border: 2px solid var(--graphite);
  border-radius: 8px;
  padding: 14px 0;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.12s;
}
.keypad .key:hover { background: #F1ECDD; }
.keypad .key:active { transform: translateY(1px); background: #E8E1CE; }
.keypad .key-del { color: var(--red-pencil); }
.keypad .key-dot { font-size: 28px; line-height: 0.7; }

button {
  font-family: var(--font);
  font-size: 15px;
  padding: 8px 16px;
  border: 1.8px solid var(--graphite);
  border-radius: 4px;
  background: var(--paper-card);
  color: var(--graphite);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.07s ease, background 0.15s, color 0.15s;
}
button:active { transform: translateY(1px); }
button.primary {
  background: var(--graphite);
  color: var(--paper-card);
}
button.primary:hover { background: #000; }
button.ghost { background: transparent; }
button.ghost:hover { background: var(--graphite); color: var(--paper-card); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

/* ----------------------------------------------------------
   Result panel
   ---------------------------------------------------------- */
.result {
  margin-top: 18px;
  padding: 16px 20px;
  border-radius: var(--radius);
  font-size: 17px;
  line-height: 1.55;
  border: 1.5px solid var(--graphite);
  background: var(--paper);
}
.result.hidden { display: none; }
.result.correct { border-color: var(--graphite); }
.result.correct strong { color: var(--graphite); }
.result.wrong   { border-color: var(--red-pencil); }
.result.wrong   strong { color: var(--red-pencil); }
.result.reveal  { border-color: var(--graphite-mid); border-style: dashed; }
.result strong { font-size: 19px; }
.result .math {
  display: block;
  margin-top: 10px;
  padding: 10px 14px;
  background: var(--paper-card);
  border: 1px solid var(--line-mid);
  font-size: 16px;
  font-weight: 400;
  color: var(--graphite);
}

/* ----------------------------------------------------------
   Rough-work scratchpad (looks like notebook paper)
   ---------------------------------------------------------- */
.scratchpad {
  margin-top: 22px;
  border: 1.5px solid var(--line-mid);
  border-radius: var(--radius);
  background: var(--paper-card);
}
.scratchpad-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1.5px dashed var(--line-mid);
  flex-wrap: wrap;
}
.scratchpad h3 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--graphite-mid);
  font-weight: 700;
}
.tools { display: flex; gap: 8px; flex-wrap: wrap; }
.tool {
  font-size: 13px;
  padding: 5px 12px;
  background: transparent;
  border: 1.5px solid var(--graphite);
  color: var(--graphite);
}
.tool.active {
  background: var(--graphite);
  color: var(--paper-card);
}
.tool.danger {
  border-color: var(--red-pencil);
  color: var(--red-pencil);
}
.tool.danger:hover {
  background: var(--red-pencil);
  color: var(--paper-card);
}
/* Icon-only tool buttons (Pen / Eraser / Clear all) — square, no label text. */
.tool.icon {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
}
.tool.icon svg { display: block; }

/* Link-style button — looks like a text link, not a button (e.g. "End test"). */
button.link-btn {
  padding: 0;
  border: none;
  background: transparent;
  color: var(--graphite-mid);
  font-size: 14px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}
button.link-btn:hover {
  background: transparent;
  color: var(--red-pencil);
}
button.link-btn:active { transform: none; }

.scratchpad-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 0;
}
#scratch-canvas {
  width: 100%;
  height: 240px;
  display: block;
  background:
    linear-gradient(to right, transparent 23px, var(--line-soft) 23px, var(--line-soft) 24px, transparent 24px) 0 0 / 24px 24px,
    linear-gradient(to bottom, transparent 23px, var(--line-soft) 23px, var(--line-soft) 24px, transparent 24px) 0 0 / 24px 24px,
    var(--paper-card);
  cursor: crosshair;
  border-right: 1.5px dashed var(--line-mid);
  touch-action: none; /* prevent scroll while drawing */
}
#scratch-canvas.eraser-mode { cursor: cell; }

#scratch-text {
  width: 100%;
  height: 240px;
  display: block;
  resize: none;
  border: none;
  outline: none;
  padding: 14px 16px;
  font-family: var(--font);
  font-size: 15px;
  line-height: 24px;
  color: var(--graphite);
  background:
    linear-gradient(to bottom, transparent 23px, var(--line-soft) 23px, var(--line-soft) 24px, transparent 24px) 0 0 / 100% 24px,
    var(--paper-card);
}
#scratch-text::placeholder { color: var(--graphite-soft); }

@media (max-width: 960px) {
  /* Stack the two columns on tablets/phones. */
  main.test-card { max-width: 920px; }
  .test-grid { grid-template-columns: 1fr; gap: 18px; }
  .test-answer .answer-bar { align-items: stretch; }
}

@media (max-width: 720px) {
  main.card { margin: 12px; padding: 20px; }
  h1#question-text { font-size: 18px; }
  .answer-bar { gap: 10px; }
  #answer-input { width: 64px; font-size: 18px; }
  .suffix { font-size: 18px; }
  button { font-size: 13px; padding: 7px 12px; }
  .scratchpad-grid { grid-template-columns: 1fr; }
  #scratch-canvas { border-right: none; border-bottom: 1.5px dashed var(--line-mid); height: 200px; }
  #scratch-text { height: 160px; }
}

/* ----------------------------------------------------------
   Page chrome — breadcrumb (top) + site footer (bottom),
   shared across every screen. Mirrors the Just Practice
   breadcrumb/footer pattern, re-styled in the pencil look.
   ---------------------------------------------------------- */
/* ── Site chrome: pencil skin over the shared /assets/chrome.css ──
   Structure (layout + 1080px positioning) comes from chrome.css so the
   JustPractice wordmark sits at the same XY as the rest of the site.
   Here we only override colours/fonts to the pencil-sketch identity. */
.site-header, .breadcrumb, .site-footer { font-family: var(--font); }  /* keep Atkinson, not Inter */
.brand-mark { color: var(--graphite); font-weight: 800; }
.brand-mark span { color: var(--red-pencil); }
.brand-domain { color: var(--graphite-soft); }
.feedback-link {
  color: var(--red-pencil); background: var(--red-pencil-soft);
  border-radius: 4px; font-weight: 700;
  border: 1.5px solid transparent;
}
.feedback-link:hover {
  background: var(--red-pencil); color: var(--paper-card);
  border-color: var(--red-pencil);
}

.breadcrumb-path { font-weight: 700; }
.breadcrumb-path a {
  color: var(--graphite-mid);
  border: 1.5px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.breadcrumb-path a:hover {
  color: var(--red-pencil);
  border-color: var(--red-pencil-soft);
  background: var(--paper-card);
}
.breadcrumb-path .sep { color: var(--line-mid); font-size: 15px; }
.breadcrumb-path .current { color: var(--graphite); }

/* Footer: pencil skin over the shared chrome.css layout. Match the footer
   width to YoungMath's content card (920px) so the divider + links line up
   with the card instead of overhanging it. */
.site-footer-inner { max-width: 920px; border-top-color: var(--line-mid); font-weight: 700; }
.site-footer a {
  color: var(--graphite-mid);
  border-bottom: 1px dashed var(--graphite-soft); border-radius: 0;
}
.site-footer a:hover {
  color: var(--red-pencil); background: none;
  border-bottom-color: var(--red-pencil);
}
.site-footer .sep { color: var(--line-mid); }

/* ----------------------------------------------------------
   Setup modal — shown once per browser to collect profile.
   ---------------------------------------------------------- */
.setup-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(42, 42, 42, 0.55);
  backdrop-filter: blur(2px);
}
.setup-modal.hidden { display: none; }

.setup-card {
  width: 100%;
  max-width: 480px;
  background: var(--paper-card);
  border: 1.5px solid var(--graphite);
  border-radius: var(--radius);
  padding: 26px 28px 28px;
  box-shadow: var(--shadow);
}
.setup-card h2 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 700;
  color: var(--graphite);
}
.setup-sub {
  margin: 0 0 22px;
  font-size: 14px;
  color: var(--graphite-mid);
}

.setup-field {
  display: block;
  margin: 0 0 18px;
  padding: 0;
  border: none;
}
.setup-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--graphite-mid);
  margin-bottom: 6px;
}

.setup-field input[type="text"] {
  width: 100%;
  font-family: var(--font);
  font-size: 17px;
  font-weight: 400;
  color: var(--graphite);
  background: var(--paper);
  border: none;
  border-bottom: 2px solid var(--graphite);
  padding: 8px 4px;
  outline: none;
}
.setup-field input[type="text"]:focus { border-bottom-color: var(--red-pencil); }
.setup-field input[type="text"]::placeholder { color: var(--graphite-soft); }

.setup-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}
.setup-options label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  color: var(--graphite);
  padding: 6px 10px;
  border: 1.5px solid var(--line-mid);
  border-radius: 4px;
  cursor: pointer;
  background: var(--paper);
}
.setup-options label:has(input:checked) {
  border-color: var(--graphite);
  background: var(--paper-card);
  font-weight: 700;
}
.setup-options input[type="radio"] {
  accent-color: var(--graphite);
}

button.big {
  width: 100%;
  font-size: 17px;
  padding: 12px 18px;
  margin-top: 6px;
}

/* Spacing tweak so the buttons row wraps neatly on narrow screens */
.answer-bar > button { white-space: nowrap; }

/* ----------------------------------------------------------
   Multi-screen layout — only one screen is visible at a time.
   The .card class still styles each as a paper card; .screen
   adds the show/hide hook.
   ---------------------------------------------------------- */
.screen.hidden { display: none; }

/* Global hide utility. Several elements (answer input lines, the fixed-denom
   text, the result banner) toggle visibility purely via this class, so it must
   force display:none regardless of the element's own display rule. */
.hidden { display: none !important; }

/* ----- Home screen ----- */
#home-screen h1 {
  margin: 0 0 8px;
  font-size: 30px;
  font-weight: 700;
}
.lede {
  font-size: 17px;
  color: var(--graphite-mid);
  margin: 0 0 28px;
  line-height: 1.5;
}
.home-actions, .builder-actions {
  display: flex;
  gap: 12px;
  margin-top: 18px;
  flex-wrap: wrap;
  align-items: center;
}

/* ----- Builder screen ----- */
.builder-section {
  margin: 22px 0 8px;
}
.builder-section h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--graphite);
}
/* Section heading row with bulk actions on the right (e.g. Topics + Select all). */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.topic-bulk {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}
.topic-bulk .bulk-sep { color: var(--line-mid); }
.builder-hint {
  font-size: 13px;
  color: var(--graphite-mid);
  margin: 0 0 12px;
  line-height: 1.5;
}
.topic-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}
.topic-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1.5px solid var(--line-mid);
  border-radius: var(--radius);
  background: var(--paper);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.topic-option:hover:not(.coming-soon) {
  border-color: var(--graphite);
}
.topic-option:has(input:checked) {
  border-color: var(--graphite);
  background: var(--paper-card);
}
.topic-option.coming-soon {
  opacity: 0.45;
  cursor: not-allowed;
}
.topic-option input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--graphite);
  margin: 0;
}
.topic-option .topic-name {
  font-size: 15px;
  font-weight: 700;
  flex: 1;
}
.topic-option .topic-count {
  font-size: 12px;
  color: var(--graphite-soft);
  font-style: italic;
}

/* ----- Difficulty picker (in builder) -----
   Explicit grid placement so the radio sits in column 1 / rows 1-2 and the
   two text spans land deterministically in column 2. Avoids the auto-placement
   ambiguity that some browsers resolve differently. */
.difficulty-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}
.difficulty-option {
  display: grid;
  grid-template-columns: 24px 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 12px;
  row-gap: 2px;
  padding: 12px 14px;
  border: 1.5px solid var(--line-mid);
  border-radius: var(--radius);
  background: var(--paper);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.difficulty-option:hover { border-color: var(--graphite); }
.difficulty-option:has(input:checked) {
  border-color: var(--graphite);
  background: var(--paper-card);
}
.difficulty-option input[type="radio"] {
  grid-column: 1;
  grid-row: 1 / 3;
  margin: 0;
  align-self: center;
  justify-self: center;
  accent-color: var(--graphite);
}
.difficulty-option .difficulty-name {
  grid-column: 2;
  grid-row: 1;
  align-self: end;
  font-size: 16px;
  font-weight: 800;
  color: var(--graphite);
}
.difficulty-option .difficulty-desc {
  grid-column: 2;
  grid-row: 2;
  align-self: start;
  font-size: 12px;
  color: var(--graphite-mid);
  line-height: 1.4;
}

/* ----- Score-bar difficulty chip ----- */
.score-bar .score-difficulty {
  font-weight: 700;
  font-size: 13px;
  color: var(--graphite-mid);
  padding: 3px 10px;
  border: 1.2px solid var(--graphite);
  border-radius: 999px;
  background: var(--paper-card);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.count-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
#question-count {
  width: 96px;
  font-family: var(--font);
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  color: var(--graphite);
  background: var(--paper);
  border: 1.5px solid var(--graphite);
  border-radius: 4px;
  padding: 8px 10px;
  outline: none;
}
#question-count:focus { border-color: var(--red-pencil); }
.count-suffix {
  font-size: 15px;
  font-weight: 700;
  color: var(--graphite-mid);
}
.count-presets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.count-preset {
  min-width: 56px;
  padding: 9px 14px;
  font-size: 17px;
  font-weight: 700;
  background: transparent;
  border: 1.5px solid var(--graphite);
  color: var(--graphite);
  border-radius: 4px;
}
.count-preset:hover { background: var(--paper-card); }
.count-preset.active {
  background: var(--graphite);
  color: var(--paper-card);
}
button.ghost.small,
button.tool.small {
  font-size: 13px;
  padding: 5px 10px;
}
.builder-error {
  margin: 12px 0 0;
  padding: 10px 14px;
  border: 1.5px solid var(--red-pencil);
  background: var(--paper);
  color: var(--red-pencil);
  font-weight: 700;
  border-radius: var(--radius);
}
.builder-error.hidden { display: none; }

/* ----- Test screen — score bar at the very top ----- */
.score-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 16px;
  margin-bottom: 16px;
  background: var(--paper);
  border: 1.5px solid var(--line-mid);
  border-radius: var(--radius);
}
.score-bar .score-question,
.score-bar .score-correct {
  font-weight: 700;
  font-size: 15px;
  color: var(--graphite-mid);
}
.score-bar .score-question span,
.score-bar .score-correct span {
  color: var(--graphite);
  font-weight: 800;
  font-size: 17px;
}
.score-bar .score-correct span { color: #2E8B3F; }
.score-bar #quit-test { margin-left: auto; }

/* ----- Result screen ----- */
.result-summary {
  text-align: center;
  margin: 22px 0 24px;
}
.result-score {
  font-family: var(--font);
}
.result-score-big {
  font-size: 72px;
  font-weight: 800;
  color: var(--graphite);
  letter-spacing: -2px;
}
.result-score-mid {
  font-size: 28px;
  font-weight: 700;
  color: var(--graphite-soft);
}
.result-percent {
  font-size: 36px;
  font-weight: 700;
  margin-top: 6px;
  color: var(--graphite);
}
.result-percent.good  { color: #2E8B3F; }
.result-percent.okay  { color: #D67A1F; }
.result-percent.poor  { color: var(--red-pencil); }
.result-message {
  margin: 8px 0 0;
  font-size: 17px;
  color: var(--graphite-mid);
  font-style: italic;
}

.recap-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--graphite-mid);
  margin: 24px 0 10px;
  border-bottom: 1.5px dashed var(--line-mid);
  padding-bottom: 6px;
}
.recap-list {
  list-style: none;
  padding: 0;
  margin: 0 0 18px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}
.recap-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1.5px solid var(--line-mid);
  border-radius: 4px;
  background: var(--paper);
  font-size: 14px;
}
.recap-list li.correct { border-left: 4px solid #2E8B3F; }
.recap-list li.wrong   { border-left: 4px solid var(--red-pencil); }
.recap-num   { color: var(--graphite-soft); font-weight: 700; min-width: 22px; }
.recap-skill { flex: 1; color: var(--graphite); }
.recap-mark  { font-weight: 800; font-size: 18px; }
.recap-list li.correct .recap-mark { color: #2E8B3F; }
.recap-list li.wrong   .recap-mark { color: var(--red-pencil); }

/* Big primary CTAs (home + builder Start) */
button.primary.big {
  font-size: 18px;
  padding: 12px 22px;
}

@media (max-width: 720px) {
  .topic-list { grid-template-columns: 1fr; }
  .count-presets { margin-left: 0; }
  .result-score-big { font-size: 56px; }
}
