:root { --gutter: 16px; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  --bg: #f4f2ff; --bg2: #e6f6ff; --ink: #211c4a; --muted: #565178; --card: #ffffff; --line: #d9d4f4;
  --accent: #5b4bdb; --on-accent: #ffffff; --accent2: #ff7a59; --good: #0b7a4b; --bad: #b3261e;
  --radius: 18px; --border: 2px; --shadow: 0 6px 0 rgba(33, 28, 74, .12);
  --font: ui-rounded, "Nunito", "Trebuchet MS", "DejaVu Sans", sans-serif;
  --title-font: var(--font); --title-transform: none; --title-spacing: 0;
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  color: var(--ink); font-family: var(--font); line-height: 1.45;
  background: linear-gradient(160deg, var(--bg), var(--bg2)) fixed;
}

/* Kindergarten: teddy bear playground */
body[data-theme="g0"] {
  --bg: #ffe3f1; --bg2: #e7dcff; --ink: #4a2f45; --muted: #6d4c66; --line: #4a2f45;
  --accent: #c2185b; --accent2: #ff9ec7; --radius: 32px; --border: 4px; --shadow: 0 7px 0 #4a2f45;
  --font: "Comic Sans MS", "Chalkboard SE", "Comic Neue", ui-rounded, "DejaVu Sans", sans-serif;
}
/* Grade 1: duck pond */
body[data-theme="g1"] {
  --bg: #c6f1ff; --bg2: #a8e6cf; --ink: #17405c; --muted: #2f5d78; --line: #17405c;
  --accent: #0b6fa8; --accent2: #ffd23f; --radius: 30px; --border: 4px; --shadow: 0 6px 0 #17405c;
  --font: "Comic Sans MS", "Chalkboard SE", "Comic Neue", ui-rounded, "DejaVu Sans", sans-serif;
}
/* Grade 2: bunny garden */
body[data-theme="g2"] {
  --bg: #e4f8d4; --bg2: #ffe0e9; --ink: #27512b; --muted: #40693f; --card: #fffefa; --line: #27512b;
  --accent: #2e7d32; --accent2: #f0628f; --radius: 28px; --border: 3px; --shadow: 0 6px 0 #27512b;
  --font: "Comic Sans MS", "Chalkboard SE", "Comic Neue", ui-rounded, "DejaVu Sans", sans-serif;
}
/* Grade 3: robot workshop */
body[data-theme="g3"] {
  --bg: #d6f5f0; --bg2: #ffe7d3; --ink: #123c3a; --muted: #2f5e5a; --line: #123c3a;
  --accent: #00796b; --accent2: #f26b21; --radius: 14px; --border: 3px; --shadow: 5px 5px 0 #123c3a;
  --font: "Trebuchet MS", ui-rounded, "DejaVu Sans", sans-serif;
  background: linear-gradient(rgba(18, 60, 58, .06) 1px, transparent 1px) 0 0 / 24px 24px, linear-gradient(90deg, rgba(18, 60, 58, .06) 1px, transparent 1px) 0 0 / 24px 24px, linear-gradient(160deg, var(--bg), var(--bg2)) fixed;
}
/* Grade 4: treasure cove */
body[data-theme="g4"] {
  --bg: #fbecc8; --bg2: #bfe6ea; --ink: #2a2032; --muted: #514559; --card: #fffaf0; --line: #2a2032;
  --accent: #9a3412; --accent2: #d99a00; --radius: 12px; --border: 3px; --shadow: 0 5px 0 #2a2032;
  --font: Georgia, "DejaVu Serif", serif; --title-font: Georgia, "DejaVu Serif", serif;
}
/* Grade 5: cartoon space camp */
body[data-theme="g5"] {
  --bg: #bdeaff; --bg2: #fff3b8; --ink: #17315c; --muted: #3b5580; --line: #17315c;
  --accent: #e0392f; --accent2: #ffc928; --radius: 26px; --border: 3px; --shadow: 0 6px 0 #17315c;
  --font: "Comic Sans MS", "Chalkboard SE", "Comic Neue", ui-rounded, "DejaVu Sans", sans-serif;
  background: radial-gradient(circle at 12% 18%, #fff 0 34px, transparent 35px),
    radial-gradient(circle at 88% 12%, #fff 0 24px, transparent 25px), linear-gradient(170deg, var(--bg), var(--bg2)) fixed;
}
/* Grade 6: dinosaur dig */
body[data-theme="g6"] {
  --bg: #dff3c4; --bg2: #f6e2b3; --ink: #2f3a16; --muted: #55602f; --card: #fffdf3; --line: #4d6b1f;
  --accent: #3f7d20; --accent2: #e9862d; --radius: 22px; --border: 3px; --shadow: 0 5px 0 #4d6b1f;
  --font: "Trebuchet MS", "Chalkboard SE", ui-rounded, "DejaVu Sans", sans-serif;
}
/* Grade 7: comic book */
body[data-theme="g7"] {
  --bg: #ffe14d; --bg2: #ffd02b; --ink: #101010; --muted: #333; --line: #101010;
  --accent: #1746d1; --accent2: #e8112d; --radius: 4px; --border: 3px; --shadow: 6px 6px 0 #101010;
  --font: "Trebuchet MS", "DejaVu Sans", sans-serif; --title-font: Impact, "Arial Black", "DejaVu Sans Condensed", sans-serif;
  --title-transform: uppercase; --title-spacing: .03em;
  background: radial-gradient(rgba(232, 17, 45, .28) 1.6px, transparent 2px) 0 0 / 12px 12px, linear-gradient(var(--bg), var(--bg2)) fixed;
}
/* Grade 8: pixel arcade */
body[data-theme="g8"] {
  --bg: #15123a; --bg2: #241a5c; --ink: #e9fff4; --muted: #b6c9e8; --card: #1f1a4d; --line: #4fffb0;
  --accent: #4fffb0; --on-accent: #0c1f18; --accent2: #ff5fa2; --good: #4fffb0; --bad: #ff8a9e;
  --radius: 0; --border: 3px; --shadow: 5px 5px 0 #000;
  --font: "Courier New", "DejaVu Sans Mono", monospace; --title-font: "Courier New", "DejaVu Sans Mono", monospace;
  --title-transform: uppercase; --title-spacing: .04em;
  background: linear-gradient(rgba(255, 255, 255, .035) 2px, transparent 2px) 0 0 / 100% 6px, linear-gradient(var(--bg), var(--bg2)) fixed;
}
/* Grade 9: music studio */
body[data-theme="g9"] {
  --bg: #17111f; --bg2: #2a1433; --ink: #fbf3ff; --muted: #c9b8d6; --card: #261b30; --line: #4c3a59;
  --accent: #ff4fd8; --on-accent: #240019; --accent2: #38e1ff; --good: #5df2a8; --bad: #ff8d8d;
  --radius: 14px; --border: 1px; --shadow: 0 10px 30px rgba(0, 0, 0, .4);
  --font: "Avenir Next", "Segoe UI", "Helvetica Neue", "DejaVu Sans", sans-serif; --title-transform: lowercase; --title-spacing: -.02em;
}
/* Grade 10: night drive */
body[data-theme="g10"] {
  --bg: #0d1226; --bg2: #3a1c4d; --ink: #f4f1ff; --muted: #bdb8d9; --card: rgba(24, 25, 54, .94); --line: #47427a;
  --accent: #ffb454; --on-accent: #231400; --accent2: #ff5e7e; --good: #62e8b5; --bad: #ff9090;
  --radius: 8px; --border: 1px; --shadow: 0 12px 34px rgba(0, 0, 0, .45);
  --font: "Avenir Next", "Segoe UI", "Helvetica Neue", "DejaVu Sans", sans-serif; --title-transform: uppercase; --title-spacing: .08em;
}

/* Grade 11: lo-fi study cafe */
body[data-theme="g11"] {
  --bg: #2a1c16; --bg2: #4a3026; --ink: #fff4e4; --muted: #dcc7ae; --card: #38261e; --line: #7b5a45;
  --accent: #f2b56b; --on-accent: #2a1508; --accent2: #8fd3c1; --good: #8fe3b6; --bad: #ffa593;
  --radius: 12px; --border: 1px; --shadow: 0 10px 26px rgba(0, 0, 0, .38);
  --font: Georgia, "DejaVu Serif", serif; --title-font: Georgia, "DejaVu Serif", serif; --title-spacing: -.01em;
}
/* Grade 12: graduation */
body[data-theme="g12"] {
  --bg: #0e1b3d; --bg2: #1d3270; --ink: #f6f3e7; --muted: #c3cbe3; --card: #16264f; --line: #c9a227;
  --accent: #f0c93a; --on-accent: #1a1400; --accent2: #f0c93a; --good: #7be8b4; --bad: #ff9f9f;
  --radius: 6px; --border: 2px; --shadow: 0 10px 28px rgba(0, 0, 0, .42);
  --font: "Avenir Next", "Segoe UI", "Helvetica Neue", "DejaVu Sans", sans-serif;
  --title-font: Georgia, "DejaVu Serif", serif; --title-spacing: .01em;
}

a { color: inherit; }
.topbar { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; justify-content: space-between; width: 100%; max-width: 1120px; margin: 0 auto; padding: 14px var(--gutter); }
.brand { font: 900 1.55rem/1 var(--title-font); text-decoration: none; }
.brand span { color: var(--accent); }
body[data-theme="g7"] .brand span { color: var(--accent2); }
.brand-line { display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: baseline; }
.brand-by { color: var(--muted); font-size: .875rem; font-weight: 700; text-underline-offset: 3px; }
.topbar nav { display: flex; gap: 16px; font-weight: 700; }
.topbar nav a { text-underline-offset: 4px; }
main { flex: 1; width: 100%; max-width: 1120px; margin: 0 auto; padding: 8px var(--gutter) 36px; outline: none; }
footer { padding: 16px var(--gutter) 24px; text-align: center; color: var(--muted); font-size: .875rem; }
.noscript { text-align: center; padding: 16px; }

h1, h2, h3 { font-family: var(--title-font); text-transform: var(--title-transform); letter-spacing: var(--title-spacing); line-height: 1.12; margin: 0; }
.hero { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: center; padding: 18px 0 26px; }
.hero h1 { font-size: clamp(2rem, 6vw, 3.5rem); }
.hero p { margin: 10px 0 0; font-size: 1.1rem; color: var(--muted); max-width: 60ch; }
.hero .mascot { width: clamp(92px, 20vw, 170px); height: auto; display: block; }
.eyebrow { font-weight: 800; color: var(--muted); font-size: .9rem; margin-bottom: 6px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 18px; }
.card { display: block; position: relative; background: var(--card); color: var(--ink); border: var(--border) solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; text-decoration: none; transition: transform .12s ease; }
a.card:hover, a.card:focus-visible { transform: translateY(-3px); }
:focus-visible { outline: 3px solid var(--accent2); outline-offset: 2px; }

/* Grade cards carry their own theme colors on the home page. */
.grade-card { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 14px; align-items: center; min-height: 130px; font-family: var(--font); background: linear-gradient(150deg, var(--bg), var(--bg2)); }
.grade-card .mascot { width: 84px; height: 84px; }
.grade-card h2 { font-size: 1.3rem; }
.grade-card p { margin: 4px 0 0; color: var(--muted); font-size: .92rem; }
.grade-card .eyebrow { margin-bottom: 2px; }

.section { margin-top: 30px; }
.section > h2 { display: flex; align-items: center; gap: 10px; font-size: 1.45rem; margin-bottom: 14px; }
.jump { display: flex; flex-wrap: wrap; gap: 8px; }
.jump a { padding: 6px 12px; border: var(--border) solid var(--line); border-radius: 999px; background: var(--card); font-weight: 700; font-size: .9rem; text-decoration: none; }
body[data-theme="g7"] .jump a, body[data-theme="g8"] .jump a { border-radius: 0; }
.topic h3 { font-size: 1.08rem; padding-right: 58px; }
.topic p { margin: 5px 0 0; color: var(--muted); font-size: .92rem; }
.stars { position: absolute; top: 15px; right: 14px; font-size: .9rem; letter-spacing: 1px; color: var(--muted); white-space: nowrap; }
.stars b { color: var(--accent2); font-weight: 400; }
body[data-theme="g0"] .stars b, body[data-theme="g1"] .stars b, body[data-theme="g2"] .stars b, body[data-theme="g3"] .stars b, body[data-theme="g4"] .stars b,
body[data-theme="g5"] .stars b, body[data-theme="g7"] .stars b, body[data-theme="home"] .stars b { color: #c2410c; }

.practice { max-width: 720px; margin: 0 auto; }
.practice-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; flex-wrap: wrap; margin-bottom: 10px; }
.practice-head h1 { font-size: clamp(1.4rem, 4vw, 2rem); }
.status { font-weight: 800; font-variant-numeric: tabular-nums; }
.bar { height: 14px; border: var(--border) solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--card); margin-bottom: 18px; }
.bar i { display: block; height: 100%; background: var(--accent); transition: width .25s ease; }
.qcard { padding: clamp(18px, 4vw, 30px); }
.cheer { display: flex; align-items: center; gap: 10px; color: var(--muted); font-weight: 700; margin-bottom: 14px; }
.cheer .mascot { width: 46px; height: 46px; flex: none; }
.question { font-size: clamp(1.25rem, 4.2vw, 1.75rem); font-weight: 700; margin: 0 0 20px; overflow-wrap: anywhere; line-height: 1.6; }
.question sup, .steps sup { font-size: .68em; line-height: 0; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: .86em; line-height: 1.15; margin: 0 .14em; }
.frac > span:first-child { border-bottom: 2px solid currentColor; padding: 0 .28em .05em; }
.frac > span:last-child { padding: .05em .28em 0; }

.answer-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: stretch; }
.answer-wrap { flex: 1 1 200px; display: flex; align-items: center; gap: 8px; min-width: 0; }
input.answer { flex: 1; min-width: 0; min-height: 52px; padding: 10px 14px; font: 700 1.25rem var(--font); color: var(--ink); background: transparent; border: 2px solid var(--line); border-radius: min(var(--radius), 14px); }
.unit { font-weight: 800; color: var(--muted); }
.help { margin: 8px 0 0; color: var(--muted); font-size: .9rem; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 10px; }

button, .btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 10px 20px; cursor: pointer; text-decoration: none; font: 800 1rem var(--font); color: var(--on-accent); background: var(--accent); border: var(--border) solid var(--line); border-radius: min(var(--radius), 14px); }
body[data-theme="g9"] button, body[data-theme="g10"] button, body[data-theme="g9"] .btn, body[data-theme="g10"] .btn { border-color: var(--accent); }
button.ghost, .btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
button.choice { background: transparent; color: var(--ink); border-color: var(--line); font-size: 1.1rem; text-transform: none; }
button.choice:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 16%, transparent); }
button:disabled { cursor: default; opacity: .55; }
button.choice.right { opacity: 1; color: var(--good); border-color: var(--good); border-width: 3px; }
.tools { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

.feedback { margin-top: 16px; padding: 12px 14px; border-radius: min(var(--radius), 12px); border: 2px solid currentColor; font-weight: 700; }
.feedback.ok { color: var(--good); }
.feedback.no { color: var(--bad); }
.feedback.tip { color: var(--muted); }
.feedback .grownups { display: block; margin-top: 8px; font-size: .85rem; font-weight: 500; line-height: 1.45; }
.steps { margin: 8px 0 0; padding-left: 22px; color: var(--ink); font-weight: 500; line-height: 1.8; }

/* Pictures for the younger grades */
.objs { display: inline-flex; flex-wrap: wrap; gap: 3px 5px; vertical-align: middle; font-size: 1.35em; line-height: 1.2; }
.shape { display: block; width: min(170px, 48vw); height: auto; margin: 12px 0 0; fill: var(--accent2); stroke: var(--ink); stroke-width: 3; stroke-linejoin: round; }
.pie .on { fill: var(--accent); }
.pie .off { fill: var(--card); }
.clock { width: min(210px, 58vw); }
.clock circle { fill: #fff; }
.clock text { fill: #1c1c28; stroke: none; font: 700 9px "DejaVu Sans", sans-serif; text-anchor: middle; dominant-baseline: central; }
.clock line { stroke: #1c1c28; stroke-linecap: round; }
.clock .hour { stroke-width: 4.5; }
.clock .minute { stroke-width: 2.5; stroke: #c2185b; }
.coins { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 1em; }
.coin { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 50px; height: 50px; color: #2b2118; font: 800 15px/1 "DejaVu Sans", sans-serif; border: 3px solid #5b4630; border-radius: 50%; }
.coin.penny { width: 46px; height: 46px; background: #d98b4f; }
.coin.nickel { width: 52px; height: 52px; background: #c9ced6; }
.coin.dime { width: 42px; height: 42px; background: #e6e9ee; font-size: 13px; }
.coin.quarter { width: 56px; height: 56px; background: #d7dbe1; }
.bill { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 76px; height: 42px; color: #123a22; background: #bfe3c4; font: 800 17px/1 "DejaVu Sans", sans-serif; border: 3px solid #2f6b41; border-radius: 5px; box-shadow: inset 0 0 0 3px #e7f5e9; }
.bill.five { background: #a9d8b4; }
.bill.ten { background: #8fcaa0; }
.chart { display: grid; gap: 6px; margin-top: 12px; font-size: .78em; }
.chart > div { display: grid; grid-template-columns: 92px minmax(0, 1fr) 2.2em; align-items: center; gap: 8px; }
.chart i { display: block; height: 18px; background: var(--accent); border-radius: 4px; grid-column: 2; }
.chart b { grid-column: 3; text-align: right; }
body[data-theme="g0"] .question, body[data-theme="g1"] .question { font-size: clamp(1.45rem, 5vw, 2.1rem); }
body[data-theme="g0"] .choices, body[data-theme="g1"] .choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
body[data-theme="g0"] button.choice, body[data-theme="g1"] button.choice { min-height: 68px; font-size: 1.6rem; }

.shape.figure { width: min(320px, 100%); fill: var(--accent2); }
.figure text { fill: var(--ink); stroke: none; font: 800 13px var(--font); text-anchor: middle; dominant-baseline: central; }
.question sub, .steps sub { font-size: .68em; line-height: 0; }
.matrix { display: inline-grid; grid-template-columns: repeat(2, auto); gap: 2px 14px; padding: 4px 9px; margin: 0 4px; vertical-align: middle; text-align: right; font-size: .88em; line-height: 1.25; border-left: 2px solid currentColor; border-right: 2px solid currentColor; border-radius: 6px; }

.notes { margin-top: 16px; }
.notes [hidden] { display: none !important; }
.notes-toggle { width: 100%; background: var(--card) !important; }
.notes-panel { margin-top: 10px; padding: 12px; background: var(--card); border: var(--border) solid var(--line); border-radius: min(var(--radius), 16px); }
.notes-bar { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-bottom: 10px; }
.notes-group { display: flex; gap: 6px; }
.notes-bar button { min-height: 42px; padding: 6px 12px; font-size: .92rem; }
.notes-bar button[aria-pressed="true"] { color: var(--on-accent); background: var(--accent); }
.notes-canvas { display: block; width: 100%; height: 300px; touch-action: none; cursor: crosshair; border: 2px solid var(--line); border-radius: min(var(--radius), 10px);
  background: repeating-linear-gradient(transparent 0 27px, color-mix(in srgb, var(--ink) 16%, transparent) 27px 28px); }
.notes-text { display: block; width: 100%; min-height: 200px; padding: 10px 12px; resize: vertical; font: 500 1.05rem/1.5 var(--font); color: var(--ink); background: transparent; border: 2px solid var(--line); border-radius: min(var(--radius), 10px); }

.results { text-align: center; padding: 26px 18px; }
.results .mascot { width: 130px; height: auto; margin: 0 auto 8px; display: block; }
.results h1 { font-size: clamp(1.8rem, 6vw, 2.6rem); }
.big-stars { font-size: 2.6rem; letter-spacing: 6px; margin: 10px 0; color: var(--muted); }
.big-stars b { color: var(--accent2); font-weight: 400; }
body[data-theme="g0"] .big-stars b, body[data-theme="g1"] .big-stars b, body[data-theme="g2"] .big-stars b, body[data-theme="g3"] .big-stars b, body[data-theme="g4"] .big-stars b,
body[data-theme="g5"] .big-stars b, body[data-theme="g7"] .big-stars b { color: #c2410c; }
.results .tools { justify-content: center; }

.skill-grades { display: grid; gap: 26px; }
.skill-grades h2 { font-size: 1.25rem; margin-bottom: 12px; }

@media (max-width: 520px) {
  .hero { grid-template-columns: minmax(0, 1fr) 84px; }
  .answer-row > button { flex: 1 1 100%; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
