/* SwiftRL Learn — kid-focused, mobile/tablet first. */
@font-face { font-family: "Baloo 2"; src: url("/assets/fonts/baloo2-latin-var.woff2") format("woff2"); font-weight: 400 800; font-display: swap; }
@font-face { font-family: "Nunito"; src: url("/assets/fonts/nunito-latin-var.woff2") format("woff2"); font-weight: 200 1000; font-style: normal; font-display: swap; }
@font-face { font-family: "Nunito"; src: url("/assets/fonts/nunito-latin-italic-var.woff2") format("woff2"); font-weight: 200 1000; font-style: italic; font-display: swap; }

:root {
  --robot: #2F6BFF; --robot-shade: #1D48B8; --robot-soft: #DCE7FF;
  --y1: #F59E0B;    --y1-shade: #B86E00;    --y1-soft: #FFF0D1;
  --y4: #139E63;    --y4-shade: #0B6E44;    --y4-soft: #D5F5E6;
  --star: #F5B301;
  --bg: #EAF3FF; --surface: #FFFFFF; --surface-2: #F4F8FF; --ink: #1B2350; --ink-soft: #4A5480;
  --line: #CBD9F2; --good: #16A34A; --good-soft: #DCFCE7; --bad: #DC2626; --bad-soft: #FEE2E2;
  --btn: #FFFFFF; --btn-shade: #B9C9E8; --focus: #7C3AED;
  --radius: 20px; --radius-sm: 14px;
  --font-head: "Baloo 2", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  --font-body: "Nunito", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --robot: #5B8CFF; --robot-shade: #2F55C7; --robot-soft: #1E2C5C;
    --y1: #FBB63B;    --y1-shade: #B37508;    --y1-soft: #3D3016;
    --y4: #2BC486;    --y4-shade: #11805A;    --y4-soft: #143A2C;
    --bg: #0E1530; --surface: #18214A; --surface-2: #1F2A58; --ink: #EEF3FF; --ink-soft: #AEB8DF;
    --line: #2E3A72; --good: #34D399; --good-soft: #0F3B2C; --bad: #F87171; --bad-soft: #43171C;
    --btn: #24306A; --btn-shade: #0A0F28; --focus: #C4B5FD;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --robot: #5B8CFF; --robot-shade: #2F55C7; --robot-soft: #1E2C5C;
  --y1: #FBB63B;    --y1-shade: #B37508;    --y1-soft: #3D3016;
  --y4: #2BC486;    --y4-shade: #11805A;    --y4-soft: #143A2C;
  --bg: #0E1530; --surface: #18214A; --surface-2: #1F2A58; --ink: #EEF3FF; --ink-soft: #AEB8DF;
  --line: #2E3A72; --good: #34D399; --good-soft: #0F3B2C; --bad: #F87171; --bad-soft: #43171C;
  --btn: #24306A; --btn-shade: #0A0F28; --focus: #C4B5FD;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 18px; line-height: 1.45; min-height: 100vh; }
h1, h2, h3 { font-family: var(--font-head); line-height: 1.1; margin: 0 0 .4em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.9rem, 5vw, 2.6rem); font-weight: 800; }
h2 { font-size: clamp(1.4rem, 4vw, 1.8rem); font-weight: 800; }
h3 { font-size: 1.25rem; font-weight: 700; }
a { color: var(--robot); font-weight: 700; }
p { margin: 0 0 .8em; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; border-radius: 10px; }
[tabindex="-1"]:focus { outline: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-soft); }
.skip-link { position: absolute; left: 8px; top: -60px; background: var(--surface); padding: 10px 14px; border-radius: 10px; z-index: 100; }
.skip-link:focus { top: 8px; }

/* ---------- header ---------- */
.topbar { position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 2px solid var(--line); }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 8px 16px; display: flex; align-items: center; gap: 10px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-family: var(--font-head); font-weight: 800; font-size: 1.35rem; margin-right: auto; min-height: 48px; }
.brand-mark { width: 40px; height: 40px; border-radius: 12px; background: var(--robot); color: #fff; display: grid; place-items: center; font-size: 1.4rem; box-shadow: 0 4px 0 var(--robot-shade); }
.brand small { display: block; font-family: var(--font-body); font-size: .72rem; font-weight: 700; color: var(--ink-soft); letter-spacing: .02em; margin-top: -4px; }
.star-count { display: inline-flex; align-items: center; gap: 6px; min-height: 48px; padding: 0 14px; border-radius: 999px; background: var(--surface); border: 2px solid var(--line); font-weight: 900; font-size: 1.1rem; }
.star-count .star { color: var(--star); font-size: 1.3rem; }
.star-count.bump { animation: bump .5s ease; }
@keyframes bump { 30% { transform: scale(1.18); } }
.icon-btn { min-width: 48px; min-height: 48px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); cursor: pointer; font-size: 1.25rem; display: inline-grid; place-items: center; text-decoration: none; color: var(--ink); }
.who { display: inline-flex; align-items: center; gap: 6px; min-height: 48px; padding: 0 12px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); text-decoration: none; color: var(--ink); font-weight: 800; font-size: .95rem; max-width: 160px; }
.who span.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 64px; }
.footer { max-width: 1200px; margin: 0 auto; padding: 0 16px 32px; color: var(--ink-soft); font-size: .9rem; display: flex; gap: 16px; flex-wrap: wrap; }
.footer a { color: var(--ink-soft); }

/* ---------- brick buttons ---------- */
.btn { --c: var(--btn); --s: var(--btn-shade); --t: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; min-width: 48px; padding: 10px 22px; border: 0; border-radius: 16px;
  background: var(--c); color: var(--t); font-family: var(--font-head); font-weight: 800; font-size: 1.2rem; line-height: 1.1;
  box-shadow: 0 6px 0 var(--s); transform: translateY(0); cursor: pointer; text-decoration: none;
  transition: transform .06s ease, box-shadow .06s ease; -webkit-tap-highlight-color: transparent; user-select: none; }
.btn:active:not(:disabled), .btn.pressed { transform: translateY(5px); box-shadow: 0 1px 0 var(--s); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.robot { --c: var(--robot); --s: var(--robot-shade); --t: #fff; }
.btn.y1 { --c: var(--y1); --s: var(--y1-shade); --t: #1B2350; }
.btn.y4 { --c: var(--y4); --s: var(--y4-shade); --t: #fff; }
.btn.good { --c: var(--good); --s: #0E7A37; --t: #fff; }
.btn.danger { --c: var(--bad); --s: #991B1B; --t: #fff; }
.btn.small { min-height: 48px; padding: 8px 16px; font-size: 1.05rem; box-shadow: 0 4px 0 var(--s); }
.btn.small:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--s); }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

/* ---------- home ---------- */
.hero { text-align: center; margin: 8px 0 24px; }
.hero p { color: var(--ink-soft); font-size: 1.1rem; font-weight: 700; }
.worlds { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }
.world { --c: var(--robot); --s: var(--robot-shade); --soft: var(--robot-soft);
  position: relative; display: flex; flex-direction: column; gap: 6px; padding: 22px; min-height: 230px; border-radius: 26px;
  background: var(--surface); border: 3px solid var(--c); box-shadow: 0 8px 0 var(--s); color: var(--ink); text-decoration: none;
  transition: transform .08s ease, box-shadow .08s ease; overflow: hidden; }
.world:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--s); }
.world.y1 { --c: var(--y1); --s: var(--y1-shade); --soft: var(--y1-soft); }
.world.y4 { --c: var(--y4); --s: var(--y4-shade); --soft: var(--y4-soft); }
.world .art { width: 84px; height: 84px; border-radius: 22px; background: var(--soft); display: grid; place-items: center; font-size: 3rem; margin-bottom: 6px; }
.world h2 { margin: 0; }
.world p { margin: 0; color: var(--ink-soft); font-weight: 700; }
.world .stars-earned { margin-top: auto; display: inline-flex; align-items: center; gap: 8px; font-weight: 900; font-size: 1.1rem; }
.world .stars-earned .star { color: var(--star); font-size: 1.4rem; }
.world .go { position: absolute; right: 18px; bottom: 16px; width: 52px; height: 52px; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center; font-size: 1.5rem; box-shadow: 0 4px 0 var(--s); }
.world.y1 .go { color: #1B2350; }
.parent-strip { margin-top: 28px; padding: 16px 20px; border-radius: var(--radius); background: var(--surface); border: 2px dashed var(--line); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: space-between; }
.parent-strip p { margin: 0; font-weight: 700; color: var(--ink-soft); }

/* ---------- section pages ---------- */
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.back { min-height: 48px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; font-weight: 800; font-size: .85rem; background: var(--surface-2); border: 2px solid var(--line); }
.topics { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.topic { --c: var(--y1); --s: var(--y1-shade); --soft: var(--y1-soft);
  display: flex; flex-direction: column; gap: 4px; padding: 16px; border-radius: var(--radius); min-height: 170px;
  background: var(--surface); border: 3px solid var(--line); box-shadow: 0 6px 0 var(--line); color: var(--ink); text-decoration: none;
  transition: transform .06s ease, box-shadow .06s ease, border-color .1s; }
.topic:hover { border-color: var(--c); }
.topic:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--line); }
.topics.y4 .topic { --c: var(--y4); --s: var(--y4-shade); --soft: var(--y4-soft); }
.topics.robot .topic { --c: var(--robot); --s: var(--robot-shade); --soft: var(--robot-soft); }
.topic .emoji { width: 56px; height: 56px; border-radius: 16px; background: var(--soft); display: grid; place-items: center; font-size: 2rem; }
.topic h3 { margin: 6px 0 0; }
.topic .meta { font-size: .8rem; color: var(--ink-soft); font-weight: 700; }
.topic .stars { margin-top: auto; font-size: 1.35rem; letter-spacing: 2px; }
.topic.locked { opacity: .55; pointer-events: none; }
.stars .on { color: var(--star); }
.stars .off { color: var(--line); }

/* ---------- quiz ---------- */
.quiz { max-width: 760px; margin: 0 auto; }
.quiz-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.progress { flex: 1; height: 16px; border-radius: 999px; background: var(--surface); border: 2px solid var(--line); overflow: hidden; }
.progress > div { height: 100%; background: var(--c, var(--y1)); border-radius: 999px; transition: width .3s ease; }
.qcount { font-weight: 900; white-space: nowrap; }
.qcard { background: var(--surface); border-radius: 26px; border: 3px solid var(--line); padding: 20px; box-shadow: 0 8px 0 var(--line); }
.qprompt { display: flex; gap: 12px; align-items: flex-start; }
.qprompt .text { flex: 1; font-family: var(--font-head); font-size: clamp(1.4rem, 4.6vw, 2rem); font-weight: 800; line-height: 1.2; }
.qvisual { margin: 14px 0 4px; display: flex; justify-content: center; align-items: center; min-height: 40px; flex-wrap: wrap; gap: 6px; font-size: 2.3rem; text-align: center; }
.qvisual svg { max-width: 100%; height: auto; }
.qvisual .count-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px 10px; font-size: 2.3rem; line-height: 1.1; }
.qvisual .big-emoji { font-size: 5rem; line-height: 1; }
.qvisual .cvc { font-family: var(--font-head); font-size: 3.4rem; font-weight: 800; letter-spacing: .35em; margin-left: .35em; }
.qvisual .cvc .gap { display: inline-block; min-width: .9em; border-bottom: 6px solid var(--c, var(--y1)); letter-spacing: 0; margin-right: .35em; color: transparent; }
.qvisual .sentence { font-size: 1.5rem; font-weight: 700; line-height: 1.5; }
.qvisual mark { background: var(--y4-soft); color: var(--ink); padding: 0 .25em; border-radius: 8px; border-bottom: 4px solid var(--y4); font-weight: 900; }
.qvisual .number { font-family: var(--font-head); font-size: 3.2rem; font-weight: 800; letter-spacing: .06em; }
.qvisual .number .hl { background: var(--y4); color: #fff; border-radius: 10px; padding: 0 .12em; box-shadow: 0 4px 0 var(--y4-shade); }
.qvisual .seq { font-family: var(--font-head); font-size: 2.2rem; font-weight: 800; display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.qvisual .seq span { min-width: 64px; padding: 4px 10px; border-radius: 14px; background: var(--surface-2); border: 2px solid var(--line); }
.qvisual .seq span.q { border-style: dashed; border-color: var(--c, var(--y1)); color: var(--c, var(--y1)); }
.qvisual .sum { font-family: var(--font-head); font-size: 3.2rem; font-weight: 800; }
.frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; font-family: var(--font-head); font-weight: 800; line-height: 1; margin: 0 .1em; }
.frac > span { padding: 0 .15em; }
.frac > span:first-child { border-bottom: .09em solid currentColor; padding-bottom: .06em; }
.frac > span:last-child { padding-top: .06em; }
.qvisual .frac { font-size: 3rem; }
.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 18px; }
.answer { --c: var(--btn); --s: var(--btn-shade); min-height: 84px; padding: 12px; border-radius: 20px; border: 3px solid var(--line);
  background: var(--c); color: var(--ink); box-shadow: 0 6px 0 var(--s); font-family: var(--font-head); font-weight: 800; font-size: clamp(1.25rem, 4vw, 1.7rem);
  cursor: pointer; display: flex; align-items: center; justify-content: center; text-align: center; line-height: 1.15; transition: transform .06s, box-shadow .06s; }
.answer:active:not(:disabled) { transform: translateY(5px); box-shadow: 0 1px 0 var(--s); }
.answer:disabled { cursor: default; }
.answer .frac { font-size: 1.9rem; }
.answer svg { max-height: 88px; width: auto; }
.answer.correct { --c: var(--good-soft); --s: var(--good); border-color: var(--good); }
.answer.wrong { --c: var(--bad-soft); --s: var(--bad); border-color: var(--bad); }
.answer.dim { opacity: .55; }
.answer .mark { margin-left: 8px; font-size: 1.3rem; }
.feedback { margin-top: 18px; padding: 14px 16px; border-radius: 18px; font-weight: 800; font-size: 1.2rem; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: space-between; }
.feedback.good { background: var(--good-soft); color: var(--ink); border: 3px solid var(--good); }
.feedback.bad { background: var(--bad-soft); color: var(--ink); border: 3px solid var(--bad); }
.speak-btn { flex: none; }
.results { text-align: center; padding: 28px 20px; }
.results .big-stars { font-size: 4rem; letter-spacing: 8px; margin: 10px 0; }
.results .big-stars .on { display: inline-block; animation: pop .5s ease backwards; }
.results .big-stars .on:nth-child(2) { animation-delay: .15s; } .results .big-stars .on:nth-child(3) { animation-delay: .3s; }
@keyframes pop { 0% { transform: scale(0) rotate(-40deg); } 70% { transform: scale(1.25); } }
.results .btn-row { justify-content: center; margin-top: 18px; }

/* ---------- robotics ---------- */
.lab { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.lab-panel { background: var(--surface); border-radius: var(--radius); border: 3px solid var(--line); padding: 12px; min-width: 0; }
.board-wrap { aspect-ratio: 1 / 1; width: 100%; max-width: 560px; margin: 0 auto; border-radius: 16px; overflow: hidden; background: var(--robot-soft); }
.board-wrap canvas { display: block; }
.blockly-wrap { height: 480px; border-radius: 14px; overflow: hidden; border: 2px solid var(--line); }
.lab-controls { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.lab-status { margin-top: 12px; min-height: 52px; padding: 10px 14px; border-radius: 14px; background: var(--surface-2); font-weight: 800; display: flex; align-items: center; gap: 10px; }
.lab-status.good { background: var(--good-soft); } .lab-status.bad { background: var(--bad-soft); }
.tip { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 14px; background: var(--robot-soft); font-weight: 700; margin-bottom: 12px; }
.block-count { font-weight: 800; color: var(--ink-soft); font-size: .95rem; }
@media (max-width: 860px) {
  .lab { grid-template-columns: 1fr; }
  .board-wrap { max-width: 420px; }
  .blockly-wrap { height: 380px; }
}

/* ---------- forms / parents ---------- */
.panel { background: var(--surface); border-radius: var(--radius); border: 3px solid var(--line); padding: 20px; margin-bottom: 18px; }
.form { display: grid; gap: 14px; max-width: 460px; }
.field { display: grid; gap: 6px; }
.field label { font-weight: 800; }
.field input, .field select { min-height: 52px; padding: 10px 14px; border-radius: 14px; border: 3px solid var(--line); background: var(--surface-2); font-size: 1.05rem; }
.field input:focus, .field select:focus { border-color: var(--robot); outline: none; box-shadow: 0 0 0 4px color-mix(in srgb, var(--robot) 30%, transparent); }
.field .hint { font-size: .85rem; color: var(--ink-soft); font-weight: 600; }
.error { background: var(--bad-soft); border: 2px solid var(--bad); border-radius: 12px; padding: 10px 14px; font-weight: 700; }
.ok-msg { background: var(--good-soft); border: 2px solid var(--good); border-radius: 12px; padding: 10px 14px; font-weight: 700; }
.avatars { display: flex; gap: 8px; flex-wrap: wrap; }
.avatars label { cursor: pointer; }
.avatars input { position: absolute; opacity: 0; }
.avatars span { width: 56px; height: 56px; display: grid; place-items: center; font-size: 2rem; border-radius: 16px; border: 3px solid var(--line); background: var(--surface-2); }
.avatars input:checked + span { border-color: var(--robot); background: var(--robot-soft); box-shadow: 0 4px 0 var(--robot-shade); }
.avatars input:focus-visible + span { outline: 4px solid var(--focus); outline-offset: 2px; }
.kids { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.kid { background: var(--surface); border: 3px solid var(--line); border-radius: var(--radius); padding: 16px; }
.kid.active { border-color: var(--robot); }
.kid-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.kid-avatar { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; font-size: 2rem; background: var(--surface-2); }
.kid table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.kid td, .kid th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.kid th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
.kid td.s { text-align: right; white-space: nowrap; }
details.topic-breakdown summary { cursor: pointer; font-weight: 800; min-height: 44px; display: flex; align-items: center; }
.prose { max-width: 760px; }
.prose h2 { margin-top: 1.2em; }
.prose li { margin-bottom: .4em; }

/* ---------- celebration ---------- */
.burst { position: fixed; pointer-events: none; z-index: 60; font-size: 2rem; left: 0; top: 0; animation: fly 900ms cubic-bezier(.2,.8,.3,1) forwards; }
@keyframes fly { 0% { transform: translate(var(--x0), var(--y0)) scale(.4); opacity: 1; } 100% { transform: translate(var(--x1), var(--y1)) scale(1.2) rotate(var(--r)); opacity: 0; } }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 800; z-index: 70; max-width: calc(100vw - 32px); }

@media (max-width: 520px) {
  body { font-size: 17px; }
  main { padding: 14px 12px 56px; }
  .topbar-inner { padding: 6px 12px; gap: 8px; }
  .brand { font-size: 1.1rem; }
  .brand small { display: none; }
  .who .name { display: none; }
  .answers { gap: 10px; }
  .answer { min-height: 76px; }
  .qcard { padding: 16px; }
  .qvisual .count-grid { font-size: 1.9rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
