/**
 * CodeKids design system.
 * Bright, playful, chunky game-like UI for kids (10-14).
 * Sections: tokens/base - HUD - buttons - cards/text - hero/map -
 *           module screen - code editor/console - quiz - type-sorter game -
 *           summary - modal/toast/floats/crash - responsive/a11y
 */

/* ---------- tokens & base ---------- */
:root {
  --ink: #1e293b;
  --ink-soft: #475569;
  --primary: #7c3aed;
  --primary-d: #6d28d9;
  --accent: #f59e0b;
  --accent-d: #b45309;
  --success: #22c55e;
  --success-d: #15803d;
  --error: #ef4444;
  --error-d: #b91c1c;
  --card: #ffffff;
  --radius: 22px;
  --shadow: 0 10px 24px rgba(30, 41, 59, 0.12);
  --font-body: 'Nunito', system-ui, -apple-system, sans-serif;
  --font-display: 'Baloo 2', 'Nunito', system-ui, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Code', 'JetBrains Mono', Consolas, monospace;
}

* { box-sizing: border-box; }

/* CRITICAL: author rules like '#crash { display:grid }' would otherwise
   override the UA [hidden] style, making 'hidden' overlays intercept
   every click. Keep [hidden] authoritative. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: linear-gradient(160deg, #bfdbfe 0%, #e0e7ff 45%, #fef3c7 100%);
  background-attachment: fixed;
  min-height: 100vh;
}

h1, h2, h3 { font-family: var(--font-display); line-height: 1.15; margin: 0 0 0.5em; }
p { line-height: 1.6; }

code {
  font-family: var(--font-mono);
  background: #ede9fe;
  color: var(--primary-d);
  border-radius: 6px;
  padding: 0.1em 0.4em;
  font-size: 0.92em;
}

main#screen {
  max-width: 860px;
  margin: 0 auto;
  padding: 90px 16px 120px;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 3px solid #c7d2fe;
}
.hud-brand { font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; color: var(--primary-d); }
.hud-center { display: flex; align-items: center; gap: 10px; flex: 1; max-width: 460px; }
.lvl-badge {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(160deg, var(--accent), #fbbf24);
  border: 3px solid #fff;
  border-radius: 50%;
  font-family: var(--font-display); font-weight: 800; color: #fff;
  box-shadow: 0 3px 0 var(--accent-d);
}
.xp-wrap { flex: 1; }
.xp-bar {
  height: 18px;
  background: #e2e8f0;
  border-radius: 999px;
  border: 2px solid #fff;
  overflow: hidden;
}
.xp-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: repeating-linear-gradient(45deg, var(--success) 0 12px, #4ade80 12px 24px);
  background-size: 34px 34px;
  animation: xp-stripes 1.2s linear infinite;
  transition: width 0.5s ease;
}
@keyframes xp-stripes { to { background-position: 34px 0; } }
.xp-label { font-size: 0.75rem; font-weight: 800; color: var(--ink-soft); text-align: center; }
.streak { font-weight: 800; white-space: nowrap; }
.icon-btn {
  border: none; background: #e0e7ff; border-radius: 50%;
  width: 42px; height: 42px; font-size: 1.15rem; cursor: pointer;
  box-shadow: 0 3px 0 #a5b4fc;
}
.icon-btn:active { transform: translateY(2px); box-shadow: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font-display); font-weight: 700; font-size: 1rem;
  color: #fff; background: var(--primary);
  border: none; border-radius: 999px;
  padding: 0.65em 1.5em;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--primary-d);
  transition: transform 0.06s ease, box-shadow 0.06s ease;
  user-select: none;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--primary-d); }
.btn:disabled { background: #cbd5e1; box-shadow: 0 5px 0 #94a3b8; cursor: not-allowed; transform: none; }
.btn-accent { background: var(--accent); box-shadow: 0 5px 0 var(--accent-d); }
.btn-accent:active { box-shadow: 0 1px 0 var(--accent-d); }
.btn-accent:disabled { background: #e2e8f0; box-shadow: 0 5px 0 #94a3b8; }
.btn-ghost { background: #fff; color: var(--primary-d); box-shadow: 0 4px 0 #c7d2fe; }
.btn-ghost:active { box-shadow: 0 1px 0 #c7d2fe; }
.btn-big { font-size: 1.2rem; padding: 0.7em 1.8em; }
.btn-s { font-size: 0.85rem; padding: 0.4em 1em; box-shadow: 0 4px 0 var(--primary-d); }
.btn-attention { animation: btn-pulse 1.4s ease-in-out infinite; }
@keyframes btn-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* ---------- cards & text steps ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
  border: 3px solid #fff;
}
.card-pop { animation: card-pop 0.45s ease; }
@keyframes card-pop { 0% { transform: scale(1); } 40% { transform: scale(1.03); } 100% { transform: scale(1); } }
.card-shake { animation: card-shake 0.4s ease; }
@keyframes card-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.text-step { font-size: 1.06rem; }
.text-emoji { font-size: 2.6rem; margin-bottom: 6px; }
.text-step code { font-size: 0.95em; }
.fact-box {
  background: #fef9c3;
  border: 2px dashed #eab308;
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 700;
}
.mini-cards { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; }
.mini-card {
  flex: 1; min-width: 160px;
  background: #f1f5f9; border-radius: 16px; padding: 14px 16px;
  border: 3px solid #e2e8f0; text-align: center; line-height: 1.5;
}

.img-grid { display: grid; gap: 16px; }
.img-grid-multi { grid-template-columns: 1fr 1fr; }
.img-card { padding: 12px; text-align: center; }
.img-card img { width: 100%; border-radius: 14px; display: block; }
.img-card figcaption { padding-top: 10px; font-weight: 700; color: var(--ink-soft); }

/* ---------- hero & map ---------- */
.hero { display: flex; gap: 22px; align-items: center; margin-bottom: 34px; flex-wrap: wrap; }
.hero-mascot { width: 170px; height: 170px; object-fit: contain; flex: none; animation: mascot-bob 3s ease-in-out infinite; }
@keyframes mascot-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
.speech { flex: 1; min-width: 240px; }
.speech h1 { font-size: 1.7rem; }
.speech .accent { color: var(--primary); }

.map { position: relative; display: flex; flex-direction: column; gap: 8px; padding: 18px 0 10px; }
.map::before {
  content: '';
  position: absolute; inset: 0 0 0 50%;
  width: 0; border-left: 6px dashed rgba(255, 255, 255, 0.9);
  transform: translateX(-50%);
  filter: drop-shadow(0 1px 0 rgba(124, 58, 237, 0.25));
}
.map-row { display: flex; position: relative; }
.map-row.pos-0 { justify-content: center; transform: translateX(-26%); }
.map-row.pos-1 { justify-content: center; transform: translateX(18%); }
.map-row.pos-2 { justify-content: center; transform: translateX(26%); }
.map-row.pos-3 { justify-content: center; transform: translateX(-18%); }

.node {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 3px solid #fff; border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 12px 18px 12px 12px;
  cursor: pointer; text-align: left;
  font-family: var(--font-body);
  position: relative;
}
.node:disabled { cursor: default; }
.node-circle {
  position: relative; width: 74px; height: 74px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(160deg, #f5f3ff, #ede9fe);
  border-radius: 50%;
  border: 4px solid #ddd6fe;
}
.node-icon { font-size: 2rem; }
.node-check { position: absolute; right: -6px; bottom: -6px; font-size: 1.3rem; }
.node-label { display: flex; flex-direction: column; line-height: 1.25; }
.node-label b { font-family: var(--font-display); color: var(--primary-d); }
.node-label span { font-weight: 800; font-size: 1.02rem; }

.node-open .node-circle { border-color: var(--accent); animation: node-pulse 1.8s ease-in-out infinite; }
@keyframes node-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.55); }
  50% { box-shadow: 0 0 0 14px rgba(245, 158, 11, 0); }
}
.node-done .node-circle { border-color: var(--success); background: linear-gradient(160deg, #dcfce7, #bbf7d0); }
.node-locked { opacity: 0.6; filter: grayscale(0.85); }
.node-soon {
  position: absolute; top: -10px; right: -8px;
  background: var(--accent); color: #fff; font-weight: 800; font-size: 0.75rem;
  padding: 3px 10px; border-radius: 999px; border: 2px solid #fff;
}
.node-stars { display: flex; gap: 2px; }
.mini-star { color: #cbd5e1; font-size: 1.25rem; }
.mini-star.on { color: var(--accent); }

.route-loading { text-align: center; font-family: var(--font-display); font-size: 1.3rem; padding: 60px 0; }

/* ---------- module screen ---------- */
.module-top { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.seg-bar { display: flex; gap: 5px; flex: 1; }
.seg { height: 10px; flex: 1; background: rgba(255, 255, 255, 0.7); border-radius: 999px; }
.seg-done { background: var(--success); }
.seg-current { background: var(--accent); animation: seg-glow 1.4s ease-in-out infinite; }
@keyframes seg-glow { 50% { opacity: 0.55; } }

.step-in { animation: step-in 0.35s ease both; }
@keyframes step-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.module-foot { display: flex; justify-content: center; margin-top: 24px; }

.intro-card { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.intro-text { flex: 1; min-width: 240px; }
.intro-mascot { width: 150px; height: 150px; object-fit: contain; animation: mascot-bob 3s ease-in-out infinite; }
.pill {
  display: inline-block; background: var(--primary); color: #fff;
  font-family: var(--font-display); font-weight: 700;
  padding: 4px 16px; border-radius: 999px; margin-bottom: 10px;
}
.intro-goal { font-size: 1.1rem; }

/* ---------- code block / editor / console ---------- */
.codeblock-title { font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; margin-bottom: 6px; }
.codeblock-text { margin-top: 0; color: var(--ink-soft); font-weight: 600; }
.codeblock-bar { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.codeblock-status { font-weight: 800; }
.st-ok { color: var(--success-d); }
.st-err { color: var(--error-d); }
.st-info { color: var(--primary-d); }
.console-label { font-size: 0.75rem; font-weight: 800; color: var(--ink-soft); margin: 12px 0 4px; text-transform: uppercase; letter-spacing: 0.05em; }
.console {
  background: #0b1220; color: #d1e7ff;
  border-radius: 14px; padding: 12px 16px;
  font-family: var(--font-mono); font-size: 0.92rem;
  white-space: pre-wrap; word-break: break-word;
  margin: 0; border: 3px solid #1e293b;
}
.console-err { border-color: var(--error); color: #fecaca; }
.hint-box {
  margin-top: 12px; background: #fef9c3; border: 2px dashed #eab308;
  border-radius: 12px; padding: 10px 14px; font-weight: 700;
}

.code-editor { position: relative; margin-top: 14px; }
.code-hl, .code-input {
  margin: 0; padding: 14px 16px;
  font-family: var(--font-mono); font-size: 15px; line-height: 1.55;
  tab-size: 2; border-radius: 14px; border: 3px solid #1e293b;
}
.code-hl {
  position: absolute; inset: 0;
  background: #0f172a;
  overflow: hidden;
  pointer-events: none;
  white-space: pre;
}
.code-hl code { background: none; padding: 0; color: #cbd5e1; font-size: inherit; border-radius: 0; font-family: inherit; }
.code-input {
  position: relative; display: block; width: 100%;
  background: transparent; color: transparent; caret-color: #fbbf24;
  resize: vertical; overflow: auto; white-space: pre;
  min-height: 3.2em;
}
.code-input:focus { outline: 3px solid var(--accent); outline-offset: 1px; }
.tok-kw { color: #c084fc; font-weight: 700; }
.tok-str { color: #86efac; }
.tok-num { color: #fdba74; }
.tok-com { color: #64748b; font-style: italic; }

/* ---------- quiz ---------- */
.quiz-progress { font-weight: 800; color: var(--ink-soft); margin-bottom: 6px; }
.quiz-question { font-size: 1.25rem; }
.quiz-options { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.btn-option {
  background: #fff; color: var(--ink); justify-content: flex-start;
  font-family: var(--font-body); font-weight: 800; font-size: 1.05rem;
  border: 3px solid #e2e8f0; box-shadow: 0 4px 0 #cbd5e1;
  border-radius: 16px; padding: 0.8em 1.2em; text-align: left;
}
.btn-option:active { box-shadow: 0 1px 0 #cbd5e1; }
.opt-good { background: #dcfce7; border-color: var(--success); box-shadow: 0 4px 0 var(--success-d); animation: card-pop 0.4s ease; }
.opt-bad { background: #fee2e2; border-color: var(--error); box-shadow: 0 4px 0 var(--error-d); }
.quiz-feedback { min-height: 1.4em; font-weight: 800; margin: 14px 0 0; }
.fb-good { color: var(--success-d); }
.fb-bad { color: var(--error-d); }

/* ---------- type-sorter game ---------- */
.tsg { background: linear-gradient(170deg, #312e81, #4c1d95); border-radius: var(--radius); padding: 20px; color: #fff; box-shadow: var(--shadow); border: 3px solid #fff; position: relative; }
.tsg-hud { display: flex; justify-content: space-between; align-items: center; font-family: var(--font-display); font-size: 1.1rem; }
.tsg-score b, .tsg-combo b { color: #fde047; }
.tsg-combo { animation: card-pop 0.4s ease infinite alternate; }
.tsg-timer { height: 12px; background: rgba(255, 255, 255, 0.25); border-radius: 999px; margin: 10px 0; overflow: hidden; }
.tsg-timer-fill { height: 100%; width: 100%; background: var(--success); border-radius: 999px; transition: width 0.25s linear; }
.tsg-timer-fill.low { background: var(--error); }
.tsg-task { text-align: center; font-weight: 700; opacity: 0.95; }
.tsg-token-zone { display: grid; place-items: center; min-height: 120px; position: relative; }
.tsg-token {
  font-family: var(--font-mono); font-size: 1.9rem; font-weight: 700;
  background: #fff; color: var(--ink);
  padding: 14px 30px; border-radius: 18px;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.25);
}
.tsg-token-pop { animation: token-pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1) both; }
@keyframes token-pop { from { transform: scale(0.2); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.tsg-token-out { transition: transform 0.3s ease, opacity 0.3s ease; transform: translateY(60px) scale(0.15); opacity: 0; }
.tsg-token-bad { animation: token-bad 0.3s ease; }
@keyframes token-bad { 25% { transform: rotate(-6deg); } 75% { transform: rotate(6deg); } }
.tsg-gain {
  position: absolute; top: 8px; font-family: var(--font-display); font-size: 1.5rem;
  color: #fde047; animation: gain-up 0.9s ease-out both; font-weight: 800;
}
@keyframes gain-up { from { transform: translateY(10px); opacity: 0; } 30% { opacity: 1; } to { transform: translateY(-34px); opacity: 0; } }
.tsg-chests { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 8px; }
.tsg-chest {
  position: relative; border: 3px solid #fff; border-radius: 18px;
  padding: 16px 8px 12px; cursor: pointer; color: var(--ink);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-family: var(--font-body);
  transition: transform 0.08s ease;
}
.tsg-chest:active { transform: scale(0.94); }
.chest-pink { background: #fce7f3; }
.chest-sky { background: #e0f2fe; }
.chest-amber { background: #fef3c7; }
.chest-violet { background: #ede9fe; }
.tsg-key {
  position: absolute; top: 6px; right: 8px;
  width: 22px; height: 22px; border-radius: 6px;
  background: rgba(30, 41, 59, 0.12); font-weight: 800; font-size: 0.8rem;
  display: grid; place-items: center;
}
.tsg-chest-icon { font-size: 1.9rem; }
.tsg-chest-label { font-family: var(--font-display); font-weight: 800; }
.tsg-chest-sub { font-size: 0.75rem; font-weight: 700; color: var(--ink-soft); }
.chest-hit { animation: chest-hit 0.35s ease; border-color: var(--success); }
@keyframes chest-hit { 40% { transform: scale(1.12); } }
.chest-shake { animation: card-shake 0.4s ease; border-color: var(--error); }
.tsg-result { margin-top: 16px; }
.tsg-result-card { text-align: center; color: var(--ink); }
.tsg-hint-next { font-weight: 800; color: var(--primary-d); }

.big-star { font-size: 2.4rem; filter: grayscale(1); opacity: 0.35; }
.big-star.on { filter: none; opacity: 1; animation: star-pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
.big-star.on:nth-child(2) { animation-delay: 0.15s; }
.big-star.on:nth-child(3) { animation-delay: 0.3s; }
@keyframes star-pop { from { transform: scale(0) rotate(-40deg); } to { transform: scale(1) rotate(0); } }
.stars-row { display: flex; justify-content: center; gap: 6px; margin: 8px 0; }

/* ---------- treasure-assign game (module 2) ---------- */
.tag { background: linear-gradient(170deg, #78350f, #92400e); border-radius: var(--radius); padding: 20px; color: #fff; box-shadow: var(--shadow); border: 3px solid #fff; }
.tag-hud { display: flex; justify-content: space-between; font-family: var(--font-display); font-size: 1.1rem; }
.tag-hud b { color: #fde047; }
.tag-task { text-align: center; font-weight: 700; }
.tag-crates { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 12px 0; }
.tag-crate {
  border: 3px solid #fff; border-radius: 16px; padding: 12px 6px 10px;
  background: #92400e; color: #fff; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-family: var(--font-body); transition: transform 0.08s ease;
}
.tag-crate:active { transform: scale(0.94); }
.tag-crate-lid { font-size: 1.7rem; }
.tag-crate-name { font-family: var(--font-mono); font-weight: 700; font-size: 0.95rem; }
.tag-crate-value { font-family: var(--font-mono); color: #fde047; font-weight: 700; }
.tag-crate.crate-done { background: var(--success-d); animation: card-pop 0.4s ease; pointer-events: none; }
.tag-deal-label { font-weight: 800; font-size: 0.85rem; opacity: 0.9; margin-top: 4px; }
.tag-deal { display: flex; gap: 12px; flex-wrap: wrap; min-height: 64px; margin-top: 6px; }
.tag-token {
  font-family: var(--font-mono); font-size: 1.25rem; font-weight: 700;
  background: #fff; color: var(--ink); border: 4px solid transparent;
  padding: 10px 20px; border-radius: 14px; cursor: pointer;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.25);
  animation: token-pop 0.3s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.tag-token.sel { border-color: #fde047; transform: translateY(-4px); box-shadow: 0 9px 0 rgba(0, 0, 0, 0.25); }
.tag-token.token-out { transform: scale(0.1); opacity: 0; transition: all 0.28s ease; pointer-events: none; }
.tag-hint { min-height: 1.6em; font-weight: 700; margin-top: 10px; }
.tag-hint.hint-good { color: #bbf7d0; }
.tag-hint.hint-bad { color: #fecaca; }
.tag-hint.hint-neutral { color: #fef3c7; }
.tag-result-card { text-align: center; color: var(--ink); }
.tag-combo:not([hidden]) { animation: card-pop 0.4s ease infinite alternate; }

/* ---------- calc-battle game (module 3) ---------- */
.cb { background: linear-gradient(170deg, #0c4a6e, #164e63); border-radius: var(--radius); padding: 20px; color: #fff; box-shadow: var(--shadow); border: 3px solid #fff; }
.cb-boss { display: flex; align-items: center; gap: 14px; }
.cb-boss-face { font-size: 3rem; transition: transform 0.1s ease; }
.cb-boss-face.boss-hit { animation: boss-hit 0.5s ease; filter: grayscale(1) brightness(2); }
@keyframes boss-hit { 25% { transform: translateX(-10px) rotate(-8deg); } 75% { transform: translateX(10px) rotate(8deg); } }
.cb-boss-info { flex: 1; font-family: var(--font-display); }
.cb-hpbar { height: 14px; background: rgba(255, 255, 255, 0.25); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.cb-hpfill { height: 100%; width: 100%; background: linear-gradient(90deg, #f87171, #ef4444); border-radius: 999px; transition: width 0.4s ease; }
.cb-shields { font-size: 1.3rem; letter-spacing: 2px; }
.cb-hud { display: flex; justify-content: space-between; font-family: var(--font-display); font-size: 1.05rem; margin-top: 10px; }
.cb-hud b { color: #fde047; }
.cb-combo:not([hidden]) { animation: card-pop 0.4s ease infinite alternate; }
.cb-arena { background: rgba(2, 6, 23, 0.35); border-radius: 16px; padding: 16px; margin-top: 10px; text-align: center; }
.cb-expr { font-family: var(--font-mono); font-size: 1.9rem; font-weight: 700; color: #bae6fd; padding: 6px 0 12px; }
.cb-encounter { height: 8px; background: rgba(255, 255, 255, 0.18); border-radius: 999px; overflow: hidden; }
.cb-encounter-fill { height: 100%; background: #38bdf8; border-radius: 999px; }
.cb-encounter-fill.low { background: var(--error); }
.cb-options { display: flex; gap: 12px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.cb-option {
  font-family: var(--font-mono); font-size: 1.35rem; font-weight: 700;
  background: #fff; color: var(--ink); border: 4px solid transparent;
  padding: 10px 26px; border-radius: 14px; cursor: pointer;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.25);
}
.cb-option:disabled { opacity: 0.5; cursor: default; }
.cb-option:active { transform: translateY(3px); box-shadow: none; }
.cb-option.opt-good { border-color: var(--success); background: #dcfce7; animation: card-pop 0.4s ease; }
.cb-option.opt-bad { border-color: var(--error); background: #fee2e2; }
.cb-feedback { min-height: 1.5em; font-weight: 800; margin-top: 12px; text-align: center; }
.cb-feedback.fb-good { color: #bbf7d0; }
.cb-feedback.fb-bad { color: #fecaca; }
.cb-result-card { text-align: center; color: var(--ink); }

/* ---------- branch-runner game (module 4) ---------- */
.br { background: linear-gradient(170deg, #14532d, #166534); border-radius: var(--radius); padding: 20px; color: #fff; box-shadow: var(--shadow); border: 3px solid #fff; }
.br-hud { display: flex; justify-content: space-between; font-family: var(--font-display); font-size: 1.05rem; }
.br-hud b { color: #fde047; }
.br-combo:not([hidden]) { animation: card-pop 0.4s ease infinite alternate; }
.br-stage { position: relative; background: rgba(2, 22, 10, 0.35); border-radius: 16px; padding: 44px 16px 16px; margin-top: 12px; }
.br-runner {
  position: absolute; top: 8px; left: 50%; font-size: 2.2rem;
  transform: translateX(-50%); z-index: 2;
  transition: transform 0.9s cubic-bezier(0.3, 1.2, 0.4, 1);
}
.br-runner.run-left { transform: translateX(-320%) translateY(170px) scaleX(-1); }
.br-runner.run-right { transform: translateX(220%) translateY(170px); }
.br-vars { text-align: center; margin: 6px 0 10px; }
.br-var {
  display: inline-block; background: #fff; color: var(--ink);
  font-family: var(--font-mono); font-weight: 700; font-size: 1.05rem;
  border-radius: 12px; padding: 6px 18px;
}
.br-var b { color: var(--primary-d); }
.br-var i { font-style: normal; color: var(--accent-d); }
.br-code {
  background: #0b1f12; border-radius: 14px; padding: 14px 18px;
  font-family: var(--font-mono); font-size: 1.05rem; color: #bbf7d0;
  margin: 0; white-space: pre-wrap;
}
/* The global inline-`code` style (lavender background) must NOT apply to the
   big <code> element in the dark code box - yellow on lavender is unreadable
   (user report). */
.br-code .br-cond { background: none; padding: 0; border-radius: 0; color: #bbf7d0; }
.br-cond b { color: #fde047; }
.br-else-kw { color: #93c5fd; }
.br-question { text-align: center; font-weight: 800; margin: 12px 0 10px; }
.br-paths { display: flex; gap: 14px; }
.br-path {
  flex: 1; border: 3px solid #fff; border-radius: 18px; padding: 14px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-family: var(--font-body); color: var(--ink); cursor: pointer;
  transition: transform 0.08s ease;
}
.br-path:active { transform: scale(0.95); }
.br-path b { font-family: var(--font-display); font-size: 1.15rem; }
.br-path span:last-child { font-size: 0.85rem; font-weight: 700; color: var(--ink-soft); }
.br-path-icon { font-size: 1.8rem; }
.br-left { background: #e0f2fe; }
.br-right { background: #ffedd5; }
.br-path.opt-good { border-color: var(--success); background: #dcfce7; animation: card-pop 0.4s ease; }
.br-path.opt-bad { border-color: var(--error); background: #fee2e2; }
.br-verdict { min-height: 2.2em; font-weight: 800; margin-top: 12px; text-align: center; line-height: 1.5; }
.br-verdict code { background: rgba(2, 22, 10, 0.6); color: #fde047; padding: 0.05em 0.35em; border-radius: 6px; }
.br-verdict.verdict-good { color: #bbf7d0; }
.br-verdict.verdict-bad { color: #fecaca; }
.br-result-card { text-align: center; }

/* ---------- spell-book game (module 8) ---------- */
.sb { background: linear-gradient(170deg, #4a044e, #701a75); border-radius: var(--radius); padding: 20px; color: #fff; box-shadow: var(--shadow); border: 3px solid #fff; }
.sb-hud { display: flex; justify-content: space-between; font-family: var(--font-display); font-size: 1.05rem; }
.sb-hud b { color: #fde047; }
.sb-combo:not([hidden]) { animation: card-pop 0.4s ease infinite alternate; }
.sb-book { position: relative; background: rgba(24, 6, 36, 0.5); border: 3px solid #e9d5ff; border-radius: 16px; padding: 16px; margin-top: 12px; }
.sb-def { background: #2e1065; border-radius: 12px; padding: 14px 16px; font-family: var(--font-mono); font-size: 0.98rem; line-height: 1.5; color: #e9d5ff; margin: 0; white-space: pre-wrap; }
.sb-def code { background: none; padding: 0; color: #e9d5ff; font-size: inherit; }
.sb-def .sb-tok-str { color: #86efac; }
.sb-def .sb-tok-kw { color: #f0abfc; }
.sb-goal { text-align: center; font-weight: 800; font-size: 1.1rem; padding: 12px 0 4px; color: #fde047; }
.sb-options { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.sb-option {
  font-family: var(--font-mono); font-size: 1.05rem; font-weight: 700;
  background: #fdf4ff; color: var(--ink); border: 3px solid #e9d5ff;
  padding: 12px 14px; border-radius: 14px; cursor: pointer; text-align: left;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
}
.sb-option:disabled { opacity: 0.55; cursor: default; }
.sb-option:active { transform: translateY(3px); box-shadow: none; }
.sb-option.opt-good { border-color: var(--success); background: #dcfce7; animation: card-pop 0.4s ease; }
.sb-option.opt-bad { border-color: var(--error); background: #fee2e2; }
.sb-lesson { min-height: 1.6em; font-weight: 700; margin-top: 12px; text-align: center; }
.sb-lesson.lesson-good { color: #bbf7d0; }
.sb-lesson.lesson-bad { color: #fecaca; }
.sb-sparkles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.sb-spark { position: absolute; font-size: 1.2rem; animation: sb-spark 1.1s ease-out both; }
@keyframes sb-spark {
  0% { transform: translateY(0) scale(0.4); opacity: 0; }
  25% { opacity: 1; transform: translateY(-12px) scale(1.15); }
  100% { transform: translateY(-42px) scale(0.5); opacity: 0; }
}
.sb-result-card { text-align: center; color: var(--ink); }

/* ---------- loop-robot game (module 5) ---------- */
.lr { background: linear-gradient(170deg, #1e3a8a, #1d4ed8); border-radius: var(--radius); padding: 20px; color: #fff; box-shadow: var(--shadow); border: 3px solid #fff; }
.lr-hud { display: flex; justify-content: space-between; font-family: var(--font-display); font-size: 1.05rem; }
.lr-hud b { color: #fde047; }
.lr-combo:not([hidden]) { animation: card-pop 0.4s ease infinite alternate; }
.lr-program {
  background: #0b1f3a; border-radius: 14px; padding: 12px 16px;
  font-family: var(--font-mono); font-size: 1.02rem; color: #bfdbfe;
  margin: 12px 0 0; white-space: pre-wrap;
}
.lr-question { font-weight: 800; margin: 10px 0; }
.lr-track {
  display: flex; position: relative; background: rgba(255, 255, 255, 0.12);
  border-radius: 14px; padding: 26px 8px 8px; margin-top: 44px;
}
.lr-robot {
  position: absolute; top: -34px; left: 0; font-size: 1.9rem;
  transform: translateX(-50%); transition: left 0.24s ease;
}
.lr-cell {
  flex: 1; min-width: 0; height: 40px; border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.08); color: #fff;
  font-family: var(--font-mono); font-weight: 700; cursor: pointer; font-size: 0.85rem;
}
.lr-cell:hover { background: rgba(255, 255, 255, 0.25); }
.lr-cell.cell-sel { background: var(--accent); border-color: #fff; animation: card-pop 0.4s ease; }
.lr-choices { display: flex; gap: 12px; justify-content: center; margin-top: 12px; }
.lr-choice {
  font-family: var(--font-mono); font-size: 1.4rem; font-weight: 700;
  background: #fff; color: var(--ink); padding: 12px 34px; border-radius: 14px;
  border: 4px solid transparent; cursor: pointer; box-shadow: 0 5px 0 rgba(0, 0, 0, 0.25);
}
.lr-choice.opt-good { border-color: var(--success); background: #dcfce7; animation: card-pop 0.4s ease; }
.lr-choice.opt-bad { border-color: var(--error); background: #fee2e2; }
.lr-feedback { min-height: 1.6em; font-weight: 800; margin-top: 12px; text-align: center; }
.lr-feedback.fb-good { color: #bbf7d0; }
.lr-feedback.fb-bad { color: #fecaca; }
.lr-result-card { text-align: center; color: var(--ink); }

/* ---------- backpack-dungeon game (module 7) ---------- */
.bd { background: linear-gradient(170deg, #7c2d12, #9a3412); border-radius: var(--radius); padding: 20px; color: #fff; box-shadow: var(--shadow); border: 3px solid #fff; }
.bd-hud { display: flex; justify-content: space-between; font-family: var(--font-display); font-size: 1.05rem; }
.bd-hud b { color: #fde047; }
.bd-combo:not([hidden]) { animation: card-pop 0.4s ease infinite alternate; }
.bd-cmd { text-align: center; margin: 10px 0 12px; font-size: 1.25rem; }
.bd-cmd code {
  font-size: 1.25rem; padding: 0.3em 0.7em; background: #fff;
  color: var(--primary-d); border-radius: 10px; font-family: var(--font-mono);
}
.bd-slots { display: grid; grid-template-columns: repeat(7, 1fr); gap: 9px; }
.bd-slot {
  position: relative; border: 3px solid #fff; border-radius: 14px;
  background: #fff7ed; color: var(--ink); cursor: pointer;
  padding: 26px 4px 8px; font-family: var(--font-body); font-weight: 800;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: transform 0.08s ease; min-height: 74px;
}
.bd-slot:active { transform: scale(0.93); }
.bd-idx {
  position: absolute; top: 4px; left: 50%; transform: translateX(-50%);
  font-family: var(--font-mono); font-size: 0.75rem; font-weight: 700;
  color: #b45309;
}
.bd-item { font-size: 0.8rem; text-align: center; line-height: 1.15; }
.bd-slot.opt-good { border-color: var(--success); background: #dcfce7; animation: card-pop 0.4s ease; }
.bd-slot.opt-bad { border-color: var(--error); background: #fee2e2; animation: card-shake 0.4s ease; }
.bd-choices { display: flex; gap: 12px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.bd-choice {
  font-family: var(--font-body); font-size: 1.05rem; font-weight: 800;
  background: #fff; color: var(--ink); padding: 12px 22px; border-radius: 14px;
  border: 4px solid transparent; cursor: pointer; box-shadow: 0 5px 0 rgba(0, 0, 0, 0.25);
}
.bd-choice.opt-good { border-color: var(--success); background: #dcfce7; animation: card-pop 0.4s ease; }
.bd-choice.opt-bad { border-color: var(--error); background: #fee2e2; }
.bd-feedback { min-height: 1.6em; font-weight: 800; margin-top: 12px; text-align: center; }
.bd-feedback.fb-good { color: #bbf7d0; }
.bd-feedback.fb-bad { color: #fecaca; }
.bd-result-card { text-align: center; color: var(--ink); }
@media (max-width: 640px) { .bd-slots { grid-template-columns: repeat(4, 1fr); } }

/* ---------- turtle canvas (module 10) ---------- */
.turtle-wrap { margin-top: 14px; }
.turtle-canvas {
  display: block; width: 100%; max-width: 480px; height: auto;
  border: 3px solid #1e293b; border-radius: 14px;
  background: #fff; image-rendering: pixelated;
}

/* ---------- summary ---------- */
.summary-card { text-align: center; }
.summary-title { font-weight: 800; font-size: 1.1rem; color: var(--ink-soft); margin-top: 0; }
.summary-chest { width: 180px; margin: 6px auto 12px; display: block; animation: mascot-bob 2.6s ease-in-out infinite; }
.badge-win {
  display: inline-flex; align-items: center; gap: 12px;
  background: #fef3c7; border: 3px solid var(--accent);
  border-radius: 18px; padding: 10px 22px; margin: 8px 0;
  font-size: 1.05rem; text-align: left;
}
.badge-icon { font-size: 2.2rem; }
.summary-note { color: var(--ink-soft); font-weight: 700; }
.game-shell { margin-bottom: 8px; }

/* ---------- modal / toast / floats / confetti / crash ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(30, 41, 59, 0.55);
  display: grid; place-items: center;
  animation: fade-in 0.25s ease;
}
@keyframes fade-in { from { opacity: 0; } }
.modal-card {
  background: #fff; border-radius: 26px; border: 4px solid var(--accent);
  padding: 34px 44px; text-align: center; box-shadow: var(--shadow);
  animation: modal-pop 0.45s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}
@keyframes modal-pop { from { transform: scale(0.3); } }
.modal-emoji { font-size: 3.4rem; }
.modal-card h2 { font-size: 2rem; color: var(--primary-d); }

#toast-layer {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 210; display: flex; flex-direction: column; gap: 10px; align-items: center;
}
.toast {
  display: flex; align-items: center; gap: 12px;
  background: #fff; border: 3px solid var(--accent); border-radius: 18px;
  padding: 10px 20px; box-shadow: var(--shadow); font-size: 1rem;
  animation: toast-in 0.4s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}
.toast-icon { font-size: 2rem; }
@keyframes toast-in { from { transform: translateY(60px) scale(0.6); opacity: 0; } }
.toast-out { transition: opacity 0.4s ease, transform 0.4s ease; opacity: 0; transform: translateY(20px); }

.xp-float {
  position: fixed; z-index: 220;
  font-family: var(--font-display); font-weight: 800; font-size: 1.15rem;
  color: var(--success-d); background: #dcfce7;
  border: 2px solid var(--success); border-radius: 999px; padding: 3px 14px;
  pointer-events: none;
  animation: xp-rise 1.3s ease-out both;
}
@keyframes xp-rise {
  0% { transform: translateY(12px) scale(0.6); opacity: 0; }
  20% { opacity: 1; transform: translateY(0) scale(1); }
  100% { transform: translateY(-64px); opacity: 0; }
}

#confetti { position: fixed; inset: 0; z-index: 190; pointer-events: none; }

#crash {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(30, 41, 59, 0.6);
  display: grid; place-items: center; padding: 20px;
}
.crash-card { background: #fff; border-radius: 24px; padding: 30px 36px; text-align: center; max-width: 480px; border: 4px solid var(--error); }
.crash-emoji { font-size: 3rem; }
#crash-detail {
  background: #f1f5f9; border-radius: 10px; padding: 10px;
  font-size: 0.8rem; text-align: left; white-space: pre-wrap; word-break: break-word;
  color: var(--ink-soft); max-height: 140px; overflow: auto;
}

/* ---------- responsive & accessibility ---------- */
@media (max-width: 640px) {
  main#screen { padding: 84px 10px 100px; }
  .card { padding: 18px; }
  .img-grid-multi { grid-template-columns: 1fr; }
  .tsg-chests { grid-template-columns: 1fr 1fr; }
  .tag-crates { grid-template-columns: 1fr 1fr; }
  .hero-mascot, .intro-mascot { width: 110px; height: 110px; }
  .hud-brand span { display: none; }
  .map-row.pos-0, .map-row.pos-1, .map-row.pos-2, .map-row.pos-3 { transform: none; }
  .map-row.pos-0, .map-row.pos-2 { justify-content: flex-start; }
  .map-row.pos-1, .map-row.pos-3 { justify-content: flex-end; }
  .map::before { left: 50%; }
  .node { padding: 8px 12px 8px 8px; }
  .node-circle { width: 60px; height: 60px; }
  .code-hl, .code-input { font-size: 13.5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
