:root {
  --bg: #fff8ec;
  --ink: #2f3542;
  --muted: #747d8c;
  --card: #ffffff;
  --line: #f1e3c8;
  --primary: #5f27cd;
  --primary-ink: #fff;
  --good: #10ac84;
  --bad: #ee5253;
  --hint: #ff9f43;
  --radius: 18px;
  font-family: "Nunito", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0; color: var(--ink); font-size: 18px; line-height: 1.5;
  background-color: var(--bg);
  background-image: radial-gradient(circle at 10% 10%, #ffe9c7 0, transparent 40%), radial-gradient(circle at 90% 30%, #e3f3ff 0, transparent 35%);
  background-attachment: fixed;
  min-height: 100vh;
}
#main { max-width: 980px; margin: 0 auto; padding: 0 16px 60px; }
h1, h2, h3 { line-height: 1.2; margin: .4em 0; }
h1 { font-size: 1.9rem; }
small { color: var(--muted); font-weight: 400; }
a { color: var(--primary); }
.center { text-align: center; }
.small { font-size: .85rem; }
.big { font-size: 1.25rem; }
.big-emoji { font-size: 3.5rem; line-height: 1.1; }
.row { display: flex; gap: 12px; align-items: center; margin-top: 18px; }
.row.wrap { flex-wrap: wrap; }
.row.center { justify-content: center; }
.row.between { justify-content: space-between; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 700; border: 3px solid #e6dcc8; background: #fff; color: var(--ink);
  border-radius: 999px; padding: 10px 20px; cursor: pointer; transition: transform .1s, box-shadow .1s;
  box-shadow: 0 4px 0 #e6dcc8;
}
.btn:hover:not(:disabled) { transform: translateY(-2px); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #e6dcc8; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: #4a1fa3; color: var(--primary-ink); box-shadow: 0 4px 0 #3b1782; }
.btn.big { font-size: 1.15rem; padding: 14px 26px; }
.btn.small { font-size: .9rem; padding: 6px 14px; }
.btn.danger { color: var(--bad); }
.icon-btn { font-size: 1.4rem; background: #fff; border: 2px solid var(--line); border-radius: 12px; width: 46px; height: 46px; cursor: pointer; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 0; flex-wrap: wrap; }
.chip { font: inherit; font-weight: 800; display: flex; align-items: center; gap: 8px; background: #fff; border: 3px solid var(--c); border-radius: 999px; padding: 4px 14px 4px 4px; cursor: pointer; }
.chip .av { font-size: 1.5rem; background: var(--c); border-radius: 50%; width: 40px; height: 40px; display: grid; place-items: center; }
.score { display: flex; gap: 14px; font-weight: 800; }
.top-actions { margin-left: auto; display: flex; gap: 8px; }

/* ---------- profiles ---------- */
.welcome { text-align: center; padding-top: 40px; }
.logo { font-size: 2.4rem; font-weight: 900; color: var(--primary); }
.profile-grid { display: flex; flex-wrap: wrap; gap: 20px; justify-content: center; margin: 30px 0; }
.profile-card {
  font: inherit; width: 190px; padding: 22px 10px; border-radius: 24px; border: 4px solid var(--c, #ddd); background: #fff; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; box-shadow: 0 6px 0 var(--c, #ddd); transition: transform .15s;
}
.profile-card:hover { transform: translateY(-4px) rotate(-1deg); }
.profile-card.add { border-style: dashed; box-shadow: none; }
.big-av { font-size: 4rem; }
.profile-form label, .profile-form .field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; font-weight: 700; }
.profile-form input:not([type=radio]), .profile-form select { font: inherit; padding: 10px 14px; border: 3px solid var(--line); border-radius: 12px; }
.avatar-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.avatar-grid input { display: none; }
.avatar-grid span { display: grid; place-items: center; font-size: 1.8rem; border: 3px solid transparent; border-radius: 12px; cursor: pointer; padding: 4px; }
.avatar-grid input:checked + span { border-color: var(--primary); background: #efe7ff; }

/* ---------- panels ---------- */
.panel { background: var(--card); border-radius: 28px; padding: 26px; box-shadow: 0 8px 30px rgba(120, 90, 30, .12); margin-top: 8px; }
.panel.narrow { max-width: 520px; margin: 40px auto; }
.mascot { font-size: 3.4rem; float: right; margin: 0 0 8px 12px; animation: bob 2.5s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(4deg); } }

/* ---------- map ---------- */
.hero { display: flex; gap: 18px; align-items: center; background: linear-gradient(120deg, #efe7ff, #e3f7ff); border-radius: 28px; padding: 22px 26px; }
.hero .mascot { float: none; font-size: 4.5rem; margin: 0; }
.fixit-banner { display: flex; gap: 16px; align-items: center; background: #fff1e0; border: 3px dashed var(--hint); border-radius: 22px; padding: 14px 20px; margin-top: 16px; }
.fixit-banner p { margin: 2px 0; }
.fixit-banner .btn { margin-left: auto; flex-shrink: 0; }
.stage { margin-top: 26px; }
.stage h2 { display: flex; align-items: center; gap: 10px; color: var(--c); font-size: 1.4rem; }
.stage h2 span { background: var(--c); border-radius: 14px; width: 46px; height: 46px; display: grid; place-items: center; font-size: 1.5rem; }
.path { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.node {
  font: inherit; text-align: left; background: #fff; border: 3px solid var(--line); border-radius: 20px; padding: 14px; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px; position: relative; transition: transform .15s;
}
.node:hover { transform: translateY(-3px); }
.node-emoji { font-size: 2.2rem; }
.node small { font-size: .8rem; }
.node.open { border-color: var(--c); box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 25%, transparent); animation: pulse 2s infinite; }
.node.done { border-color: var(--good); background: #f0fff8; }
.node.locked, .node.soon { opacity: .55; filter: grayscale(.6); }
.node.soon { border-style: dashed; }
@keyframes pulse { 50% { box-shadow: 0 0 0 9px color-mix(in srgb, var(--c) 10%, transparent); } }
.tag { font-size: .78rem; font-weight: 800; background: #f1f2f6; border-radius: 999px; padding: 2px 10px; align-self: flex-start; }
.tag.go { background: var(--c); color: #fff; }
.stars { color: #f9a825; font-size: 1.2rem; letter-spacing: 2px; }
.stars.huge { font-size: 3rem; }

/* ---------- lesson ---------- */
.lesson-head { display: flex; gap: 16px; align-items: center; }
.lesson-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.lesson-bar span { margin-left: auto; color: var(--muted); }
.dots { margin-left: auto; display: flex; gap: 5px; }
.dots span { width: 12px; height: 12px; border-radius: 50%; background: #e5e5ea; }
.dots .done { background: var(--good); }
.dots .now { background: var(--primary); transform: scale(1.3); }
.step-card { background: #fffdf7; border: 3px solid var(--line); border-radius: 24px; padding: 22px; min-height: 240px; }
.step-card::after { content: ""; display: block; clear: both; }
.step-card h2 { color: var(--primary); }
.fun-fact { background: #fff6d6; border-radius: 14px; padding: 10px 14px; }
.example { background: #eef8ff; border-radius: 14px; padding: 10px 14px; margin: 8px 0; text-align: center; }
.progress { height: 12px; background: #eee; border-radius: 99px; overflow: hidden; margin-bottom: 16px; }
.progress div { height: 100%; background: linear-gradient(90deg, #feca57, #ff9f43); transition: width .4s; }
.notes { background: #f3edff; border-radius: 16px; padding: 12px 18px; margin: 16px auto; max-width: 560px; text-align: left; }
.notes div { margin-top: 4px; }

/* ---------- maths bits ---------- */
.frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; line-height: 1.05; font-weight: 800; margin: 0 2px; }
.frac span:first-child { border-bottom: 2px solid currentColor; padding: 0 3px; }
.seq { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 12px 0; }
.seq span { min-width: 54px; padding: 8px 12px; text-align: center; font-size: 1.4rem; font-weight: 800; background: #fff; border: 3px solid #54a0ff; border-radius: 14px; }
.seq .q { border-style: dashed; color: var(--primary); border-color: var(--primary); }
.equation { font-size: 2rem; font-weight: 800; text-align: center; margin: 14px 0; }
.box { display: inline-block; min-width: 54px; border: 3px dashed var(--primary); border-radius: 10px; color: var(--primary); padding: 0 8px; }
.machine { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 16px 0; flex-wrap: wrap; }
.m-in, .m-out { font-size: 1.6rem; font-weight: 800; min-width: 60px; text-align: center; background: #fff; border: 3px solid #0abde3; border-radius: 14px; padding: 6px 12px; }
.m-out { border-color: #10ac84; }
.m-box { background: linear-gradient(135deg, #576574, #8395a7); color: #fff; font-weight: 800; border-radius: 18px; padding: 16px 20px; display: flex; gap: 8px; align-items: center; }
.m-arrow { font-size: 1.6rem; color: var(--muted); }
.machine.whirr .gear { display: inline-block; animation: spin .6s linear 2; }
.machine.whirr .m-out { animation: popin .5s; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes popin { 0% { transform: scale(.3); } 70% { transform: scale(1.2); } }
table.io { border-collapse: collapse; margin: 12px auto; font-size: 1.2rem; }
table.io th, table.io td { border: 2px solid #c8d6e5; padding: 6px 14px; text-align: center; }
table.io th { background: #eef5ff; }
.stack { display: flex; flex-direction: column; align-items: center; gap: 8px; }
svg { max-width: 100%; height: auto; }
.grid-svg.clickable { cursor: crosshair; }

/* ---------- questions ---------- */
.question { text-align: center; }
.q-label { font-weight: 800; color: var(--hint); }
.q-prompt { font-size: 1.3rem; font-weight: 700; margin: 6px 0 10px; }
.q-visual { margin: 10px 0; display: flex; justify-content: center; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; max-width: 620px; margin: 14px auto; }
.choice { font: inherit; font-size: 1.3rem; font-weight: 800; background: #fff; border: 3px solid #c8d6e5; border-radius: 16px; padding: 14px; cursor: pointer; box-shadow: 0 4px 0 #c8d6e5; }
.choice:hover:not(:disabled) { border-color: var(--primary); }
.choice.right { background: #dcfce7; border-color: var(--good); box-shadow: 0 4px 0 var(--good); }
.choice.wrong { background: #ffe4e4; border-color: var(--bad); animation: shake .4s; }
.num-form { display: flex; gap: 10px; justify-content: center; margin: 14px 0; }
.num-input { font: inherit; font-size: 1.6rem; font-weight: 800; width: 150px; text-align: center; border: 3px solid #c8d6e5; border-radius: 16px; padding: 8px; }
.num-input:focus { outline: none; border-color: var(--primary); }
.num-input.wrong { border-color: var(--bad); animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.q-feedback { margin: 12px auto; max-width: 620px; border-radius: 16px; }
.q-feedback:not(:empty) { padding: 12px 16px; }
.q-feedback.good { background: #dcfce7; }
.q-feedback.bad { background: #ffe9e9; }
.q-feedback.hint { background: #fff3dc; }
.q-feedback .small { margin-top: 4px; }

/* ---------- games ---------- */
.game-head { display: flex; justify-content: space-between; font-weight: 800; font-size: 1.2rem; }
.timebar { height: 14px; background: #eee; border-radius: 99px; overflow: hidden; margin: 8px 0 14px; }
.timebar div { height: 100%; width: 100%; background: linear-gradient(90deg, #ee5253, #feca57, #1dd1a1); transition: width 1s linear; }
.game.speed { text-align: center; }
.flash { font-weight: 800; height: 28px; }
.flash.good { color: var(--good); }
.flash.bad { color: var(--bad); }
.game-start, .game-over { text-align: center; }
.new-best { font-weight: 800; color: #f9a825; }
.balloons { text-align: center; }
.balloon-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 22px; margin: 26px 0 10px; }
.balloon {
  font: inherit; font-size: 1.25rem; font-weight: 800; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.35);
  width: 108px; height: 128px; border: none; border-radius: 50% 50% 48% 48%; background: radial-gradient(circle at 30% 30%, #ffffffaa 0, transparent 25%), var(--c);
  cursor: pointer; position: relative; animation: float 3s ease-in-out infinite; animation-delay: var(--d);
}
.balloon::after { content: ""; position: absolute; left: 50%; bottom: -26px; width: 2px; height: 26px; background: #999; }
.balloon .frac span:first-child { border-color: #fff; }
.balloon.pop { animation: pop .4s forwards; }
.balloon.fly-away { animation: fly 1s forwards; }
@keyframes float { 50% { transform: translateY(-14px) rotate(3deg); } }
@keyframes pop { 50% { transform: scale(1.4); } 100% { transform: scale(0); opacity: 0; } }
@keyframes fly { to { transform: translateY(-160px) rotate(-20deg); opacity: 0; } }

/* ---------- widgets ---------- */
.controls { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; align-items: center; margin: 10px 0; font-weight: 700; }
.controls label { display: flex; align-items: center; gap: 8px; }
.controls input[type=range] { width: 160px; accent-color: var(--primary); }
.controls select { font: inherit; padding: 6px 10px; border-radius: 10px; border: 2px solid var(--line); }
.stepper { display: flex; align-items: center; gap: 6px; background: #fff; border: 2px solid var(--line); border-radius: 999px; padding: 4px 8px; }
.stepper button { font: inherit; font-weight: 800; width: 34px; height: 34px; border-radius: 50%; border: none; background: #efe7ff; cursor: pointer; }
.stepper b { min-width: 28px; text-align: center; }
.hops { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: center; gap: 4px; margin: 18px 0; }
.hop { display: flex; flex-direction: column; align-items: center; animation: popin .4s backwards; }
.hop .frog { font-size: 1.8rem; height: 36px; }
.hop span { font-weight: 800; font-size: 1.2rem; background: #fff; border: 3px solid #1dd1a1; border-radius: 12px; padding: 4px 10px; }
.arc { color: #1dd1a1; font-size: 1.4rem; padding-bottom: 8px; }

/* ---------- skills / results ---------- */
.skill-row { display: grid; grid-template-columns: minmax(150px, 1.3fr) 2fr 54px; gap: 12px; align-items: center; margin: 8px 0; }
.meter { height: 16px; background: #eee; border-radius: 99px; overflow: hidden; }
.meter div { height: 100%; border-radius: 99px; }
.meter.low div { background: var(--bad); }
.meter.mid div { background: #feca57; }
.meter.high div { background: var(--good); }
.reexplain-list { margin-top: 20px; }
.reexplain { background: #f6fbff; border: 3px solid #c7e3ff; border-radius: 18px; padding: 10px 18px; margin: 12px 0; }
.reexplain h4 { margin: 6px 0; color: #2e86de; }
details.worked { margin-top: 16px; background: #fff; border: 2px dashed var(--line); border-radius: 16px; padding: 10px 16px; }
details.worked summary { cursor: pointer; font-weight: 800; }

/* ---------- grown-ups ---------- */
.report { border-left: 6px solid var(--c); padding: 4px 0 4px 18px; margin: 24px 0; }
.report h2 small { font-size: .9rem; }
.report-table { border-collapse: collapse; width: 100%; font-size: .95rem; }
.report-table th, .report-table td { border-bottom: 1px solid #eee; padding: 6px 8px; text-align: left; }

/* ---------- misc ---------- */
.toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 999px; font-weight: 700; z-index: 10; animation: popin .3s; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 20; }

@media (max-width: 640px) {
  body { font-size: 16px; }
  h1 { font-size: 1.5rem; }
  .panel { padding: 16px; border-radius: 20px; }
  .step-card { padding: 14px; }
  .hero { flex-direction: column; text-align: center; }
  .fixit-banner { flex-direction: column; text-align: center; }
  .fixit-banner .btn { margin: 0; }
  .skill-row { grid-template-columns: 1fr 1fr 44px; }
  .avatar-grid { grid-template-columns: repeat(4, 1fr); }
  .balloon { width: 92px; height: 110px; }
  .dots { display: none; }
}
.sync-dot { font-size: 1.3rem; display: grid; place-items: center; width: 34px; cursor: help; }
