:root {
  --bg: #161126;
  --bg-2: #1d1638;
  --surface: #241c45;
  --surface-2: #2d2456;
  --tile: #352a63;
  --ink: #fdf6ec;
  --ink-soft: rgba(253, 246, 236, 0.74);
  --ink-dim: rgba(253, 246, 236, 0.5);
  --line: rgba(253, 246, 236, 0.12);
  --line-2: rgba(253, 246, 236, 0.24);

  --coral: #ff5a7e;
  --tang: #ff8c3b;
  --sun: #ffd23f;
  --mint: #2fe6a8;
  --sky: #41d3ff;
  --grape: #a878ff;

  --shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  --radius: 18px;
  --font-display: "Fredoka", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: 600;
  background:
    radial-gradient(circle at 12% -4%, rgba(255, 90, 126, 0.22), transparent 38%),
    radial-gradient(circle at 92% 4%, rgba(65, 211, 255, 0.18), transparent 40%),
    radial-gradient(circle at 78% 96%, rgba(168, 120, 255, 0.18), transparent 42%),
    radial-gradient(circle at 0% 100%, rgba(47, 230, 168, 0.12), transparent 36%),
    linear-gradient(160deg, #18122c 0%, #120e22 60%, #0e0a1a 100%);
  background-attachment: fixed;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: radial-gradient(rgba(253, 246, 236, 0.05) 1px, transparent 1.4px);
  background-size: 26px 26px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.6), transparent 70%);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.02;
}

.game-shell {
  margin: 0 auto;
  padding: 22px 0 64px;
  position: relative;
  width: min(1180px, calc(100% - 32px));
  z-index: 1;
}

/* ---------- shared surfaces ---------- */
.game-hero,
.mode-lab,
.game-stage,
.builder-panel,
.source-panel,
.session-card {
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}

/* ---------- hero ---------- */
.game-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
}

.hero-copy {
  align-content: center;
  display: grid;
  gap: 6px;
  padding: clamp(26px, 4vw, 46px);
  position: relative;
  overflow: hidden;
}

.hero-copy::before {
  content: "🎮 🍬 ⭐ 🏆 🚀";
  position: absolute;
  top: -10px;
  right: 18px;
  font-size: 2rem;
  letter-spacing: 14px;
  opacity: 0.16;
  transform: rotate(-8deg);
  white-space: nowrap;
}

.eyebrow {
  color: var(--sun);
  font-family: var(--font-display);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(2.1rem, 4vw, 3.5rem);
  max-width: 16ch;
  background: linear-gradient(100deg, var(--ink) 30%, var(--sun) 60%, var(--coral) 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

h2 { font-size: clamp(1.5rem, 2.6vw, 2.3rem); }
h3 { font-size: clamp(1.2rem, 2vw, 1.7rem); }

.lead {
  color: var(--ink-soft);
  font-size: clamp(0.98rem, 1.3vw, 1.12rem);
  line-height: 1.5;
  margin-top: 10px;
  max-width: 46ch;
}

.hero-actions,
.stage-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.hero-actions { margin-top: 20px; }

/* ---------- control card ---------- */
.control-card {
  background:
    radial-gradient(circle at 50% -10%, rgba(65, 211, 255, 0.16), transparent 60%),
    linear-gradient(180deg, var(--surface-2), var(--surface));
  border-left: 1px solid var(--line);
  padding: 22px;
}

label {
  color: var(--ink);
  display: grid;
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 600;
  gap: 7px;
  letter-spacing: 0.04em;
  margin-top: 14px;
  text-transform: uppercase;
}
label:first-child { margin-top: 0; }

input, select, textarea {
  background: rgba(13, 10, 24, 0.7);
  border: 1.5px solid var(--line-2);
  border-radius: 12px;
  color: var(--ink);
  font-weight: 600;
  min-height: 46px;
  padding: 12px 14px;
  text-transform: none;
  width: 100%;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
select option { color: #161126; }
textarea { line-height: 1.4; resize: vertical; }
input::placeholder, textarea::placeholder { color: rgba(253, 246, 236, 0.34); }

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  border-color: var(--sky);
  box-shadow: 0 0 0 4px rgba(65, 211, 255, 0.22);
  outline: none;
}
button:focus-visible {
  outline: 3px solid var(--sky);
  outline-offset: 2px;
}

/* ---------- buttons (tactile / pushable) ---------- */
.primary-button,
.primary-link {
  align-items: center;
  background: linear-gradient(180deg, var(--sun), var(--tang));
  border: 0;
  border-radius: 14px;
  box-shadow: 0 6px 0 #b8541a, 0 14px 24px rgba(255, 140, 59, 0.3);
  color: #2a1505;
  display: inline-flex;
  font-family: var(--font-display);
  font-size: 1.02rem;
  font-weight: 600;
  justify-content: center;
  margin-top: 18px;
  min-height: 50px;
  padding: 13px 20px;
  text-decoration: none;
  transition: transform 90ms ease, box-shadow 90ms ease;
  width: 100%;
}
.primary-button:hover,
.primary-link:hover { transform: translateY(-2px); box-shadow: 0 8px 0 #b8541a, 0 18px 30px rgba(255, 140, 59, 0.36); }
.primary-button:active,
.primary-link:active { transform: translateY(4px); box-shadow: 0 2px 0 #b8541a; }
.primary-button:disabled { cursor: wait; opacity: 0.6; transform: none; }

.hero-actions .primary-link { margin-top: 0; width: auto; }

.secondary-button {
  background: var(--surface-2);
  border: 1.5px solid var(--line-2);
  border-radius: 12px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 500;
  min-height: 44px;
  padding: 9px 15px;
  transition: transform 90ms ease, box-shadow 90ms ease, background 140ms ease;
}
.secondary-button:hover { background: var(--tile); transform: translateY(-2px); }
.secondary-button:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35); }
.secondary-button[aria-pressed="false"] { opacity: 0.55; }

.student-actions {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
  margin-top: 12px;
}

.secondary-link {
  align-items: center;
  background: rgba(13, 10, 24, 0.5);
  border: 1.5px solid var(--line-2);
  border-radius: 12px;
  color: var(--ink);
  display: inline-flex;
  font-family: var(--font-display);
  font-weight: 600;
  min-height: 44px;
  overflow: hidden;
  padding: 9px 12px;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.secondary-link:hover { background: var(--tile); }

.compact-button {
  min-height: 44px;
  padding-inline: 12px;
}

.control-note {
  color: var(--ink-soft);
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.45;
  margin-top: 12px;
}

/* ---------- mode lab ---------- */
.mode-lab,
.builder-panel {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.mode-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.mode-card {
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1.5px solid var(--line-2);
  border-radius: 16px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.32);
  color: var(--ink);
  display: grid;
  gap: 4px;
  min-height: 150px;
  overflow: hidden;
  padding: 16px 14px;
  position: relative;
  text-align: left;
  transition: transform 110ms ease, box-shadow 110ms ease, border-color 140ms ease;
}
.mode-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 5px;
  background: var(--accent, var(--grape));
}
.mode-card:nth-child(1) { --accent: var(--coral); }
.mode-card:nth-child(2) { --accent: var(--tang); }
.mode-card:nth-child(3) { --accent: var(--grape); }
.mode-card:nth-child(4) { --accent: var(--sky); }
.mode-card:nth-child(5) { --accent: var(--mint); }
.mode-card:nth-child(6) { --accent: var(--sun); }
.mode-card:nth-child(7) { --accent: var(--coral); }

.mode-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.mode-card[aria-checked="true"] {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 26%, var(--surface)), var(--surface));
  border-color: var(--accent);
  box-shadow: 0 6px 0 color-mix(in srgb, var(--accent) 50%, #000), 0 14px 30px color-mix(in srgb, var(--accent) 28%, transparent);
  transform: translateY(-2px);
}
.mode-card b {
  font-size: 1.9rem;
  font-style: normal;
  line-height: 1;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4));
}
.mode-card strong {
  font-family: var(--font-display);
  font-size: 1.02rem;
  font-weight: 600;
}
.mode-card span {
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.3;
}

/* ---------- score strip ---------- */
.score-strip {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 16px;
}
.score-strip article {
  background: linear-gradient(180deg, var(--surface-2), var(--bg-2));
  border: 1.5px solid var(--line-2);
  border-radius: 16px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.3);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
}
.score-strip article::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 4px;
}
.score-strip article:nth-child(1)::after { background: var(--grape); }
.score-strip article:nth-child(2)::after { background: var(--sky); }
.score-strip article:nth-child(3)::after { background: var(--sun); }
.score-strip article:nth-child(4)::after { background: var(--mint); }
.score-strip span {
  color: var(--ink-dim);
  display: block;
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.score-strip strong {
  display: block;
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 2.4vw, 2.1rem);
  font-weight: 700;
  line-height: 1.05;
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.score-strip strong.bump { animation: bump 360ms ease; }

/* ---------- game stage ---------- */
.stage-head {
  align-items: center;
  background:
    radial-gradient(circle at 0% 0%, rgba(168, 120, 255, 0.14), transparent 50%),
    var(--bg-2);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 20px 24px;
}
.stage-head h2 {
  background: linear-gradient(90deg, var(--ink), var(--sky));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
#gameSubtitle { color: var(--ink-soft); font-weight: 700; margin-top: 4px; }

.play-area {
  background:
    radial-gradient(circle at 22% 14%, rgba(65, 211, 255, 0.12), transparent 40%),
    radial-gradient(circle at 82% 8%, rgba(255, 90, 126, 0.12), transparent 40%),
    linear-gradient(180deg, #140f28, #0f0b1f);
  min-height: 480px;
  padding: 24px;
  position: relative;
}
.play-area.shake { animation: shake 380ms cubic-bezier(0.36, 0.07, 0.19, 0.97); }

.help-panel {
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border-top: 1px solid var(--line);
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  padding: 18px 24px 24px;
}

.help-panel[hidden] { display: none; }

.help-panel .primary-button { margin-top: 12px; }

.help-answer {
  align-self: end;
  background: rgba(13, 10, 24, 0.52);
  border: 1.5px solid var(--line-2);
  border-radius: var(--radius);
  color: var(--ink-soft);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.5;
  min-height: 112px;
  padding: 16px;
}

.boss-layout,
.race-layout,
.tower-layout,
.candy-layout,
.card-layout {
  align-items: stretch;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(240px, 0.78fr) minmax(0, 1fr);
}

.boss-card,
.race-track,
.tower,
.question-card,
.memory-card,
.candy-board,
.card-table {
  background: linear-gradient(180deg, rgba(253, 246, 236, 0.06), rgba(253, 246, 236, 0.02));
  border: 1.5px solid var(--line-2);
  border-radius: var(--radius);
}

/* ---------- question card + answers ---------- */
.question-card {
  animation: rise 320ms ease both;
  padding: clamp(18px, 3vw, 30px);
}
.question-card h3 { max-width: 40ch; margin-top: 4px; }

.answer-grid {
  counter-reset: answer;
  display: grid;
  gap: 11px;
  grid-template-columns: 1fr 1fr;
  margin-top: 22px;
}
.answer-grid button {
  align-items: center;
  background: var(--surface-2);
  border: 1.5px solid var(--line-2);
  border-radius: 13px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.34);
  color: var(--ink);
  display: flex;
  font-family: var(--font-display);
  font-weight: 500;
  gap: 12px;
  min-height: 64px;
  padding: 14px 16px;
  text-align: left;
  transition: transform 90ms ease, box-shadow 90ms ease, background 140ms ease, border-color 140ms ease;
}
.answer-grid button::before {
  align-items: center;
  background: var(--tile);
  border: 1.5px solid var(--line-2);
  border-radius: 9px;
  color: var(--sun);
  content: counter(answer, upper-alpha);
  counter-increment: answer;
  display: flex;
  flex: 0 0 auto;
  font-size: 0.95rem;
  font-weight: 700;
  height: 30px;
  justify-content: center;
  width: 30px;
}
.answer-grid button:hover::before { background: rgba(65, 211, 255, 0.2); border-color: var(--sky); color: var(--sky); }
.answer-grid button.correct::before { background: rgba(6, 36, 23, 0.25); border-color: rgba(6, 36, 23, 0.4); color: #062417; }
.answer-grid button.wrong::before { background: rgba(255, 255, 255, 0.18); border-color: rgba(255, 255, 255, 0.5); color: #fff; }
.answer-grid button:hover { background: var(--tile); transform: translateY(-2px); border-color: var(--sky); }
.answer-grid button:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.34); }
.answer-grid button.correct {
  background: linear-gradient(180deg, var(--mint), #14b87f);
  border-color: var(--mint);
  color: #062417;
  animation: pop 340ms ease;
}
.answer-grid button.wrong {
  background: linear-gradient(180deg, var(--coral), #c8264a);
  border-color: var(--coral);
  color: #fff;
  animation: nope 380ms ease;
}

/* ---------- boss ---------- */
.boss-card {
  align-content: center;
  display: grid;
  gap: 14px;
  justify-items: center;
  min-height: 340px;
  padding: 24px;
  text-align: center;
}
.boss-card span {
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.boss-card strong { font-family: var(--font-display); font-size: 1.5rem; }
.boss-face {
  align-items: center;
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.9), transparent 0.5rem),
    linear-gradient(140deg, var(--coral), var(--grape));
  border: 2px solid rgba(253, 246, 236, 0.3);
  border-radius: 32px;
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.45);
  display: flex;
  font-size: 5rem;
  height: 156px;
  justify-content: center;
  width: 156px;
  animation: bob 3.2s ease-in-out infinite;
}
.boss-face.hit { animation: bosshit 420ms ease; }
.hp {
  background: rgba(0, 0, 0, 0.35);
  border: 1.5px solid var(--line-2);
  border-radius: 999px;
  height: 20px;
  overflow: hidden;
  width: min(320px, 100%);
}
.hp i {
  background: linear-gradient(90deg, var(--coral), var(--tang), var(--sun));
  display: block;
  height: 100%;
  transition: width 420ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ---------- race ---------- */
.race-track {
  min-height: 340px;
  overflow: hidden;
  padding: 34px 22px;
  position: relative;
}
.race-track::before {
  content: "";
  background: repeating-linear-gradient(90deg, rgba(253, 246, 236, 0.34) 0 18px, transparent 18px 34px);
  border-radius: 999px;
  height: 12px;
  left: 28px; right: 28px; top: 50%;
  position: absolute;
}
.race-track i {
  align-items: center;
  background: var(--surface-2);
  border: 1.5px solid var(--line-2);
  border-radius: 999px;
  display: inline-flex;
  font-family: var(--font-display);
  height: 44px;
  justify-content: center;
  margin-right: calc((100% - 264px) / 4);
  position: relative;
  top: calc(50% - 18px);
  width: 44px;
  z-index: 1;
}
.race-track i.done { background: var(--mint); border-color: var(--mint); color: #062417; }
.race-track i.active { background: var(--sun); border-color: var(--sun); color: #2a1505; animation: bump 700ms ease infinite; }
.runner {
  filter: drop-shadow(0 14px 18px rgba(0, 0, 0, 0.5));
  font-size: 3.2rem;
  position: absolute;
  top: calc(50% - 80px);
  transition: left 420ms cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 2;
}

/* ---------- memory ---------- */
.memory-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
.memory-card {
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 600;
  min-height: 130px;
  padding: 14px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.3);
  transition: transform 120ms ease, background 160ms ease, border-color 160ms ease;
}
.memory-card:hover:not(:disabled) { transform: translateY(-3px); border-color: var(--sky); }
.memory-card.selected { background: rgba(255, 210, 63, 0.22); border-color: var(--sun); animation: pop 280ms ease; }
.memory-card.matched { background: linear-gradient(180deg, var(--mint), #14b87f); border-color: var(--mint); color: #062417; }

/* ---------- target pop ---------- */
.target-arena { min-height: 480px; position: relative; }
.target-arena .question-card {
  bottom: 16px;
  left: 50%;
  max-width: 720px;
  position: absolute;
  transform: translateX(-50%);
  width: min(720px, calc(100% - 24px));
  z-index: 2;
}
.target {
  align-items: center;
  background:
    radial-gradient(circle at 34% 26%, #fff 0 9%, transparent 10%),
    radial-gradient(circle, var(--sun) 0 28%, var(--tang) 29% 50%, var(--coral) 51% 100%);
  border: 3px solid rgba(253, 246, 236, 0.8);
  border-radius: 999px;
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.45);
  color: #fff;
  display: flex;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  height: 86px;
  justify-content: center;
  position: absolute;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  width: 86px;
  animation: floaty 3.6s ease-in-out infinite;
  transition: transform 120ms ease;
}
.target:hover:not(:disabled) { transform: scale(1.08); }
.target.popped { animation: popgone 360ms ease forwards; }

/* ---------- tower ---------- */
.tower {
  align-content: end;
  display: grid;
  gap: 8px;
  justify-items: center;
  min-height: 390px;
  padding: 24px;
}
.tower i {
  align-items: center;
  background: linear-gradient(140deg, var(--sky), var(--grape));
  border: 1.5px solid rgba(253, 246, 236, 0.3);
  border-radius: 12px;
  display: flex;
  font-size: 1.7rem;
  font-style: normal;
  height: 56px;
  justify-content: center;
  width: min(260px, 90%);
  animation: drop 420ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* ---------- candy cascade ---------- */
.candy-board {
  align-content: start;
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(7, 1fr);
  min-height: 340px;
  padding: 14px;
  position: relative;
}
.candy-board i {
  aspect-ratio: 1;
  align-items: center;
  background: rgba(253, 246, 236, 0.05);
  border-radius: 11px;
  display: flex;
  font-size: clamp(1rem, 2.6vw, 1.5rem);
  font-style: normal;
  justify-content: center;
}
.candy-board i.cleared {
  background: radial-gradient(circle, rgba(47, 230, 168, 0.4), transparent 70%);
  animation: sparkle 900ms ease infinite;
}
.combo-panel {
  grid-column: 1 / -1;
  background: linear-gradient(120deg, rgba(255, 90, 126, 0.2), rgba(168, 120, 255, 0.2));
  border: 1.5px solid var(--line-2);
  border-radius: 14px;
  margin-top: 6px;
  padding: 12px 16px;
  text-align: center;
}
.combo-panel strong {
  color: var(--sun);
  display: block;
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
}
.combo-panel span { color: var(--ink-soft); font-size: 0.85rem; }

/* ---------- card clash ---------- */
.card-table {
  display: grid;
  gap: 18px;
  justify-items: center;
  padding: 22px;
}
.discard-card {
  align-items: center;
  border-radius: 16px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4);
  display: grid;
  gap: 6px;
  height: 200px;
  justify-items: center;
  padding: 18px;
  width: 150px;
  border: 3px solid rgba(255, 255, 255, 0.7);
  animation: pop 360ms ease;
}
.discard-card strong { font-family: var(--font-display); font-size: 3.4rem; line-height: 1; }
.discard-card span { font-family: var(--font-display); font-weight: 600; }
.discard-card small { color: rgba(0, 0, 0, 0.6); font-weight: 800; }
.card-hand {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.card-hand i {
  align-items: center;
  border-radius: 11px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.6);
  display: grid;
  font-style: normal;
  gap: 2px;
  height: 92px;
  justify-items: center;
  padding: 8px;
  width: 64px;
  transition: transform 140ms ease;
}
.card-hand i:not(.played):hover { transform: translateY(-6px) rotate(-3deg); }
.card-hand i span { font-size: 0.7rem; font-weight: 800; }
.card-hand i strong { font-family: var(--font-display); font-size: 1.5rem; }
.card-hand i.played { opacity: 0.3; transform: translateY(8px) rotate(-6deg); }
.red { background: linear-gradient(180deg, #ff6b81, #d63251); color: #fff; }
.blue { background: linear-gradient(180deg, #5aa0ff, #2f5fd6); color: #fff; }
.yellow { background: linear-gradient(180deg, #ffd23f, #e0a017); color: #2a1505; }
.green { background: linear-gradient(180deg, #45e0a0, #14b87f); color: #062417; }

/* ---------- builder panel ---------- */
.builder-panel { grid-template-columns: minmax(0, 0.92fr) minmax(300px, 0.78fr); align-items: start; }
.builder-panel > div:first-child { grid-column: 1 / -1; }
.builder-panel p { color: var(--ink-soft); line-height: 1.5; }
.builder-form {
  background: var(--surface-2);
  border: 1.5px solid var(--line-2);
  border-radius: 16px;
  padding: 18px;
}
.builder-chat { display: grid; gap: 10px; align-content: start; }
.builder-chat p {
  background: rgba(13, 10, 24, 0.5);
  border: 1px solid var(--line);
  border-left: 4px solid var(--grape);
  border-radius: 12px;
  display: grid;
  gap: 3px;
  padding: 12px 14px;
}
.builder-chat strong {
  color: var(--sky);
  font-family: var(--font-display);
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.builder-chat span { color: var(--ink-soft); line-height: 1.4; }

/* ---------- details panels ---------- */
.source-panel,
.session-card { padding: 0; }
details.source-panel,
details.session-card { display: block; }
details summary {
  align-items: center;
  cursor: pointer;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  list-style: none;
  padding: 20px 24px;
}
details summary::-webkit-details-marker { display: none; }
details summary .eyebrow { display: block; margin-bottom: 4px; }
details summary strong {
  display: block;
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 2.2vw, 1.7rem);
  font-weight: 600;
}
details[open] summary { border-bottom: 1px solid var(--line); }
.summary-action {
  background: var(--surface-2);
  border: 1.5px solid var(--line-2);
  border-radius: 999px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
  color: var(--ink);
  flex: 0 0 auto;
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 9px 14px;
}
.panel-body {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 0.95fr) minmax(320px, 0.7fr);
  padding: 20px 24px 24px;
}
.panel-body p { color: var(--ink-soft); line-height: 1.5; }
.source-form {
  background: var(--surface-2);
  border: 1.5px solid var(--line-2);
  border-radius: 16px;
  padding: 18px;
}
.source-form input[type="file"] { min-height: auto; }
.session-card pre {
  background: rgba(13, 10, 24, 0.7);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: #c8f5e8;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.5;
  margin: 0;
  max-height: 360px;
  overflow: auto;
  padding: 16px;
}

/* ---------- quiz runner ---------- */
.runner-stage {
  display: grid;
  gap: 12px;
}
.runner-hud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.runner-hud .rh {
  background: var(--surface-2);
  border: 1.5px solid var(--line-2);
  border-radius: 999px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.92rem;
  padding: 7px 14px;
}
.runner-hud .hearts { letter-spacing: 2px; }
.runner-banner {
  background: linear-gradient(120deg, rgba(168, 120, 255, 0.22), rgba(65, 211, 255, 0.16));
  border: 1.5px solid var(--line-2);
  border-radius: 14px;
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 500;
  line-height: 1.35;
  min-height: 52px;
  display: flex;
  align-items: center;
  padding: 12px 16px;
}
.runner-canvas-wrap {
  position: relative;
  border: 1.5px solid var(--line-2);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  background: #120e22;
}
.runner-question-panel {
  background: linear-gradient(120deg, rgba(13, 10, 24, 0.96), rgba(32, 25, 58, 0.96));
  border-bottom: 1.5px solid rgba(253, 246, 236, 0.24);
  color: var(--ink);
  display: grid;
  gap: 8px;
  padding: 14px;
}
.runner-question-panel[hidden] { display: none; }
.runner-question-panel p {
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(0.92rem, 2vw, 1.2rem);
  font-weight: 600;
  line-height: 1.25;
}
.runner-question-panel strong { color: var(--sun); margin-right: 6px; }
.runner-question-panel ol {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  list-style: none;
  margin: 0;
  padding: 0;
}
.runner-question-panel li {
  background: rgba(65, 211, 255, 0.12);
  border: 1px solid rgba(253, 246, 236, 0.16);
  border-radius: 10px;
  color: var(--ink-soft);
  font-size: clamp(0.78rem, 1.55vw, 0.95rem);
  line-height: 1.25;
  padding: 7px 9px;
}
#runCanvas {
  display: block;
  width: 100%;
  height: clamp(320px, 52vw, 460px);
  touch-action: none;
  cursor: pointer;
}
.runner-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 40%, rgba(20, 15, 40, 0.82), rgba(14, 10, 26, 0.92));
  backdrop-filter: blur(2px);
}
.runner-gameover {
  text-align: center;
  padding: 24px;
  animation: rise 320ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.runner-gameover .go-emoji { font-size: 3.4rem; }
.runner-gameover h3 {
  background: linear-gradient(100deg, var(--coral), var(--sun));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 6px 0;
}
.runner-gameover p { color: var(--ink-soft); margin-bottom: 16px; }
.runner-gameover .primary-button { margin-top: 0; width: auto; padding-inline: 28px; }
.runner-controls {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, 1fr);
}
.runner-controls .secondary-button {
  font-size: 1.05rem;
  min-height: 52px;
}
.runner-pause-button {
  border-color: rgba(255, 210, 63, 0.55);
  color: var(--sun);
}

/* ---------- juice overlays ---------- */
.fx-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  overflow: hidden;
}
.confetti {
  position: absolute;
  width: 11px;
  height: 14px;
  border-radius: 2px;
  will-change: transform, opacity;
  animation: fall var(--dur, 1400ms) cubic-bezier(0.2, 0.6, 0.4, 1) forwards;
}
.float-pts {
  position: fixed;
  z-index: 61;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.8rem;
  color: var(--sun);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  animation: floatup 900ms ease forwards;
}
.combo-burst {
  position: fixed;
  top: 30%;
  left: 50%;
  z-index: 62;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.4rem, 7vw, 4.5rem);
  background: linear-gradient(100deg, var(--sun), var(--coral), var(--grape));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  pointer-events: none;
  animation: comboPop 1000ms ease forwards;
  text-align: center;
  white-space: nowrap;
}
.win-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 40%, rgba(29, 22, 56, 0.86), rgba(14, 10, 26, 0.94));
  animation: fadein 260ms ease;
}
.win-card {
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1.5px solid var(--line-2);
  border-radius: 26px;
  box-shadow: var(--shadow);
  max-width: 420px;
  margin: 16px;
  padding: 36px 32px;
  text-align: center;
  animation: rise 360ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.win-card .trophy { font-size: 4.5rem; animation: bob 2.4s ease-in-out infinite; }
.win-card h2 {
  background: linear-gradient(100deg, var(--sun), var(--coral));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 8px 0;
}
.win-card p { color: var(--ink-soft); margin-bottom: 18px; }

/* ---------- keyframes ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { 0% { transform: scale(0.92); } 55% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes nope { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(6px); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 15% { transform: translateX(-10px); } 30% { transform: translateX(9px); } 45% { transform: translateX(-7px); } 60% { transform: translateX(6px); } 75% { transform: translateX(-4px); } }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-10px) rotate(3deg); } }
@keyframes bosshit { 0% { transform: translateX(0) scale(1); filter: brightness(1); } 25% { transform: translateX(-12px) scale(1.05); filter: brightness(2.2); } 50% { transform: translateX(10px) scale(0.97); } 75% { transform: translateX(-6px); } 100% { transform: translateX(0) scale(1); } }
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
@keyframes drop { from { opacity: 0; transform: translateY(-22px) scale(0.9); } to { opacity: 1; transform: none; } }
@keyframes sparkle { 0%,100% { opacity: 0.6; transform: scale(0.94); } 50% { opacity: 1; transform: scale(1.05); } }
@keyframes popgone { 0% { transform: scale(1); opacity: 1; } 40% { transform: scale(1.3); opacity: 1; } 100% { transform: scale(0.2); opacity: 0; } }
@keyframes fall { 0% { transform: translateY(-10vh) rotate(0); opacity: 1; } 100% { transform: translateY(105vh) rotate(720deg); opacity: 0.9; } }
@keyframes floatup { 0% { transform: translateY(0) scale(0.8); opacity: 0; } 20% { opacity: 1; transform: translateY(-6px) scale(1.1); } 100% { transform: translateY(-70px) scale(1); opacity: 0; } }
@keyframes comboPop { 0% { transform: translate(-50%, -50%) scale(0.4); opacity: 0; } 25% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; } 70% { transform: translate(-50%, -50%) scale(1); opacity: 1; } 100% { transform: translate(-50%, -90%) scale(0.95); opacity: 0; } }

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

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .game-hero,
  .builder-panel,
  .panel-body,
  .boss-layout,
  .race-layout,
  .tower-layout,
  .candy-layout,
  .card-layout { grid-template-columns: 1fr; }
  .control-card { border-left: 0; border-top: 1px solid var(--line); }
  .score-strip { grid-template-columns: repeat(2, 1fr); }
  .memory-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 620px) {
  .game-shell { width: min(100% - 18px, 1180px); padding-top: 14px; }
  .hero-copy, .control-card, .mode-lab, .builder-panel,
  .stage-head, .play-area { padding: 16px; }
  .panel-body, details summary { padding: 16px; }
  .stage-head { align-items: stretch; flex-direction: column; }
  .stage-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .answer-grid { grid-template-columns: 1fr; }
  .memory-grid { grid-template-columns: repeat(2, 1fr); }
  .runner-question-panel ol { grid-template-columns: 1fr; }
  .runner-controls { grid-template-columns: 1fr 1fr; }
  .runner-pause-button { grid-column: 1 / -1; }
  .hero-actions .primary-link, .hero-actions .secondary-button { width: 100%; justify-content: center; }
}
