:root {
  --bg: #f5f2ea;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --ink: #1e2340;
  --muted: #5e6482;
  --line: #e6e0d2;
  --accent: #3d5afe;
  --accent-ink: #ffffff;
  --accent-soft: #e8ecff;
  --verbal: #0b7285;
  --verbal-soft: #e0f4f6;
  --nonverbal: #6741d9;
  --nonverbal-soft: #efe9ff;
  --good: #2b8a3e;
  --good-soft: #e5f5e8;
  --bad: #c92a2a;
  --bad-soft: #fdeaea;
  --skip: #8a6d0b;
  --skip-soft: #fbf3d8;
  --fig-grey: #aab0c6;
  --shadow: 0 1px 2px rgba(30, 35, 64, .06), 0 8px 24px rgba(30, 35, 64, .07);
  --radius: 20px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11131d;
    --surface: #1a1d2b;
    --surface-2: #151824;
    --ink: #e9ebf6;
    --muted: #9da3bf;
    --line: #2b2f44;
    --accent: #7b8fff;
    --accent-ink: #0f1220;
    --accent-soft: #232a4e;
    --verbal: #5fd0de;
    --verbal-soft: #12313a;
    --nonverbal: #b39dff;
    --nonverbal-soft: #2a2148;
    --good: #69db7c;
    --good-soft: #15301d;
    --bad: #ff8787;
    --bad-soft: #3a1a1d;
    --skip: #f0c94a;
    --skip-soft: #33290d;
    --fig-grey: #6c7293;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

/* Per-level accent colours (applied to <body> and to each level card) */
[data-level="8"] { --accent: #2b8a3e; --accent-soft: #e3f5e6; }
[data-level="13"] { --accent: #c2255c; --accent-soft: #fde8ef; }
@media (prefers-color-scheme: dark) {
  [data-level="8"] { --accent: #69db7c; --accent-soft: #18321f; }
  [data-level="13"] { --accent: #f783ac; --accent-soft: #3a1b29; }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 17px;
  line-height: 1.55;
  min-height: 100vh;
}
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.wrap { width: min(980px, 100% - 32px); margin-inline: auto; }

/* Header */
.site-head { padding: 18px 0; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.05rem; color: var(--ink); text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-weight: 900; letter-spacing: -.02em; }

main { padding-bottom: 64px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

.eyebrow { font-size: .78rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin-bottom: 8px; }
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); line-height: 1.12; font-weight: 900; letter-spacing: -.02em; }
.lede { color: var(--muted); margin-top: 12px; font-size: 1.05rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 2px solid transparent; border-radius: 14px; padding: 11px 20px; font-weight: 800; cursor: pointer; transition: transform .12s ease, background .15s ease, box-shadow .15s ease, opacity .15s; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .option:focus-visible, .pip:focus-visible, .modes input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.primary.finish { background: var(--good); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.big { padding: 15px 28px; font-size: 1.1rem; margin-top: 26px; }

/* Start screen */
.hero { display: grid; grid-template-columns: 1.4fr 1fr; gap: 32px; padding: 40px; align-items: center; }
.modes { border: 0; padding: 0; margin: 26px 0 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.modes legend { font-weight: 800; font-size: .9rem; margin-bottom: 10px; padding: 0; }
.modes label { cursor: pointer; }
.modes input { position: absolute; opacity: 0; pointer-events: none; }
.modes span { display: flex; flex-direction: column; height: 100%; padding: 12px 14px; border: 2px solid var(--line); border-radius: 14px; background: var(--surface-2); transition: border-color .15s, background .15s; }
.modes small { color: var(--muted); font-size: .8rem; line-height: 1.3; margin-top: 2px; }
.modes input:checked + span { border-color: var(--accent); background: var(--accent-soft); }

.hero-art { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.art-tile { aspect-ratio: 1; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line); padding: 12px; }
.art-tile:nth-child(odd) { background: var(--accent-soft); border-color: transparent; }

.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 18px; }
.fact { display: flex; gap: 14px; align-items: center; padding: 16px 18px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-size: .92rem; line-height: 1.4; }
.fact-num { flex: none; min-width: 52px; height: 44px; padding: 0 8px; display: grid; place-items: center; border-radius: 12px; background: var(--accent-soft); color: var(--accent); font-weight: 900; font-size: 1.05rem; }

/* Quiz */
.quiz-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.q-count { font-weight: 900; font-size: 1.15rem; }
.q-count span { color: var(--muted); font-weight: 700; }
.timer { margin-left: auto; font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.tag { display: inline-flex; align-items: center; padding: 4px 12px; border-radius: 999px; font-size: .8rem; font-weight: 800; }
.tag-verbal { background: var(--verbal-soft); color: var(--verbal); }
.tag-nonverbal { background: var(--nonverbal-soft); color: var(--nonverbal); }

.progress { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; margin-bottom: 18px; }
#progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .3s ease; }

.q-card { padding: 32px; }
.q-card.enter { animation: rise .28s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.prompt { font-size: 1.3rem; font-weight: 800; line-height: 1.4; }

.stem { margin: 24px 0 4px; padding: 22px 16px; border-radius: 16px; background: var(--surface-2); border: 1px dashed var(--line); }
.stem-text { text-align: center; font-size: 1.45rem; font-weight: 800; letter-spacing: .02em; }
.blank { display: inline-grid; place-items: center; min-width: 1.6em; padding: 0 .2em; border-radius: 8px; background: var(--accent-soft); color: var(--accent); }
.stem-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px; }
.stem-fig { width: 104px; aspect-ratio: 1; padding: 8px; border-radius: 14px; background: var(--surface); border: 2px solid var(--line); }
.stem-fig.ask { display: grid; place-items: center; border: 2px dashed var(--accent); background: var(--accent-soft); color: var(--accent); font-size: 2.2rem; font-weight: 900; }
.stem-grid { display: grid; grid-template-columns: repeat(3, 90px); gap: 8px; justify-content: center; }
.stem-grid .stem-fig { width: 90px; }
.pair { display: flex; align-items: center; gap: inherit; }
.to, .sep { font-weight: 900; color: var(--muted); font-size: 1.2rem; }
.sep { padding: 0 6px; font-size: .95rem; text-transform: uppercase; letter-spacing: .08em; }
.mirror { align-self: stretch; width: 0; min-height: 104px; border-left: 3px dashed var(--accent); margin: 0 6px; }
.coded { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.code { font-weight: 900; letter-spacing: .12em; font-size: 1.05rem; }
.ask-code { color: var(--accent); }

.fig { display: block; width: 100%; height: auto; overflow: visible; }
.fig .s { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.fig .s.white { fill: var(--surface); }
.fig .s.grey { fill: var(--fig-grey); }
.fig .s.faint { stroke: var(--line); stroke-width: 2; }
.fig .s.solid { fill: var(--ink); }
.fig .s.thick { stroke-width: 6; }
.fig .s.thin { stroke-width: 2.5; }
.fig .dot { fill: var(--ink); }

.options { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 24px; }
.options.figs { grid-template-columns: repeat(5, 1fr); }
.option { position: relative; display: flex; align-items: center; gap: 12px; padding: 14px 16px; border: 2px solid var(--line); border-radius: 14px; background: var(--surface); text-align: left; cursor: pointer; transition: border-color .15s, background .15s, transform .12s; }
.option:hover:not(.static) { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); transform: translateY(-1px); }
.option .letter { flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--line); font-weight: 900; font-size: .9rem; color: var(--muted); transition: background .15s, color .15s; }
.opt-text { font-weight: 700; font-size: 1.05rem; }
.options.figs .option { flex-direction: column; padding: 10px 10px 14px; }
.options.figs .option .fig { max-width: 110px; }
.option.selected { border-color: var(--accent); background: var(--accent-soft); }
.option.selected .letter { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.quiz-nav { display: flex; align-items: center; gap: 12px; margin-top: 18px; }
.pips { flex: 1; display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; }
.pip { width: 32px; height: 32px; border-radius: 10px; border: 2px solid var(--line); background: var(--surface); font-size: .8rem; font-weight: 800; color: var(--muted); cursor: pointer; }
.pip.answered { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.pip.current { border-color: var(--accent); color: var(--ink); }

/* Dialog */
.dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; width: min(420px, calc(100% - 32px)); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(10, 12, 25, .45); }
.dialog h3 { font-size: 1.3rem; font-weight: 900; }
.dialog p { color: var(--muted); margin-top: 8px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

/* Results */
.result-hero { display: flex; align-items: center; gap: 36px; padding: 36px 40px; }
.ring { position: relative; flex: none; width: 180px; height: 180px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--line); stroke-width: 12; }
.ring-fill { fill: none; stroke: var(--accent); stroke-width: 12; stroke-linecap: round; transition: stroke-dashoffset 1.1s cubic-bezier(.2, .8, .2, 1); }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-label strong { font-size: 3.4rem; line-height: 1; font-weight: 900; }
.ring-label span { color: var(--muted); font-weight: 700; font-size: .9rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.chip { padding: 6px 14px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: .9rem; }
.chip.tag-verbal { background: var(--verbal-soft); color: var(--verbal); border-color: transparent; }
.chip.tag-nonverbal { background: var(--nonverbal-soft); color: var(--nonverbal); border-color: transparent; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }

.review-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 36px 0 14px; }
.review-bar h2 { font-size: 1.4rem; font-weight: 900; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: .92rem; color: var(--muted); font-weight: 700; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.only-wrong .review.good { display: none; }

.review-list { display: grid; gap: 16px; }
.review { padding: 24px 28px; border-left: 6px solid var(--line); }
.review.good { border-left-color: var(--good); }
.review.bad { border-left-color: var(--bad); }
.review.skip { border-left-color: var(--skip); }
.review-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.review-num { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--line); font-weight: 900; font-size: .9rem; }
.badge { margin-left: auto; padding: 4px 12px; border-radius: 999px; font-size: .82rem; font-weight: 900; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.skip { background: var(--skip-soft); color: var(--skip); }
.review .prompt { font-size: 1.1rem; }
.review .stem { margin-top: 16px; padding: 16px; }
.review .stem-fig { width: 78px; }
.review .stem-grid { grid-template-columns: repeat(3, 70px); }
.review .stem-grid .stem-fig { width: 70px; }
.review .mirror { min-height: 78px; }
.review .stem-text { font-size: 1.2rem; }
.review .options { margin-top: 16px; }
.option.static { cursor: default; }
.option.is-correct { border-color: var(--good); background: var(--good-soft); }
.option.is-correct .letter { background: var(--good); border-color: var(--good); color: var(--surface); }
.option.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.is-wrong .letter { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.opt-note { margin-left: auto; font-size: .72rem; font-weight: 900; text-transform: uppercase; letter-spacing: .06em; }
.is-correct .opt-note { color: var(--good); }
.is-wrong .opt-note { color: var(--bad); }
.options.figs .opt-note { margin: 0; text-align: center; }
.explain { margin-top: 18px; padding: 16px 18px; border-radius: 14px; background: var(--accent-soft); }
.explain-title { font-weight: 900; font-size: .78rem; text-transform: uppercase; letter-spacing: .1em; color: var(--accent); margin-bottom: 4px; }

/* Level select */
.levels-head { text-align: center; max-width: 640px; margin: 24px auto 0; }
.levels-head h1 { font-size: clamp(2.2rem, 5vw, 3.2rem); }
.level-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-top: 32px; }
.level-card { position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 10px; padding: 32px 28px 26px; border-radius: var(--radius); background: var(--surface); border: 2px solid var(--line); box-shadow: var(--shadow); color: var(--ink); text-decoration: none; transition: transform .15s ease, border-color .15s ease; }
.level-card::before { content: ''; position: absolute; inset: 0 0 auto; height: 6px; background: var(--accent); }
.level-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.level-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.level-badge { display: grid; place-items: center; width: 96px; height: 96px; border-radius: 24px; background: var(--accent-soft); color: var(--accent); font-size: 2.4rem; font-weight: 900; letter-spacing: -.03em; margin-bottom: 6px; }
.level-ages { font-size: 1.2rem; font-weight: 900; }
.level-desc { flex: 1; color: var(--muted); font-size: .95rem; line-height: 1.5; }
.level-go { margin-top: 10px; font-weight: 800; color: var(--accent); }
.back-link { display: inline-block; margin-bottom: 12px; color: var(--muted); font-weight: 800; text-decoration: none; }
.back-link:hover { color: var(--accent); }

/* Responsive */
@media (max-width: 820px) {
  .level-grid { grid-template-columns: 1fr; gap: 12px; }
  .level-card { flex-direction: row; flex-wrap: wrap; align-items: center; column-gap: 16px; padding: 22px 20px 18px; }
  .level-badge { width: 64px; height: 64px; font-size: 1.6rem; border-radius: 18px; margin: 0; }
  .level-card .level-ages { flex: 1; }
  .level-desc { flex-basis: 100%; }
  .level-go { margin-top: 0; }
  .hero { grid-template-columns: 1fr; padding: 28px 22px; }
  .hero-art { grid-template-columns: repeat(6, 1fr); gap: 8px; order: -1; }
  .art-tile { padding: 6px; border-radius: 12px; }
  .facts { grid-template-columns: 1fr; }
  .result-hero { flex-direction: column; text-align: center; padding: 28px 22px; }
  .chips, .result-actions { justify-content: center; }
}
@media (max-width: 600px) {
  body { font-size: 16px; }
  .modes { grid-template-columns: 1fr; }
  .q-card { padding: 22px 18px; }
  .prompt { font-size: 1.12rem; }
  .stem { padding: 14px 6px; }
  .stem-row { gap: 6px; }
  .stem-fig, .review .stem-fig { width: 52px; padding: 4px; border-radius: 10px; }
  .stem-grid, .review .stem-grid { grid-template-columns: repeat(3, 68px); }
  .stem-grid .stem-fig, .review .stem-grid .stem-fig { width: 68px; }
  .mirror, .review .mirror { min-height: 52px; }
  .to { font-size: 1rem; }
  .sep { padding: 0 2px; font-size: .75rem; }
  .stem-fig.ask { font-size: 1.6rem; }
  .stem-text { font-size: 1.15rem; }
  .options.figs { grid-template-columns: repeat(3, 1fr); }
  .options { grid-template-columns: 1fr 1fr; }
  .review { padding: 20px 16px; }
  .quiz-nav { flex-wrap: wrap; }
  .pips { order: -1; flex-basis: 100%; gap: 4px; }
  .pip { width: 28px; height: 28px; border-radius: 8px; }
  .quiz-nav .btn { flex: 1; }
}
