: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;
}

/* 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;
}

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); }
.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="g5"] .stars b, body[data-theme="g7"] .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); }
.steps { margin: 8px 0 0; padding-left: 22px; color: var(--ink); font-weight: 500; line-height: 1.8; }

.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="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; }
}
