:root {
  --bg-0: #04050a;
  --bg-1: #0a0e18;
  --card: #0d1322;
  --card-edge: #1b2438;
  --ink: #e9ecf4;
  --muted: #8b94aa;
  --accent: #5ee6d0;
  --accent-dim: rgba(94, 230, 208, 0.14);
  --purple: #a06bff;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --gold: #d4a94f;
  --hud-bg: rgba(10, 14, 26, 0.82);
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg-0);
}

body {
  background:
    radial-gradient(1100px 500px at 80% -10%, rgba(94, 230, 208, 0.10), transparent 60%),
    radial-gradient(900px 500px at 10% 110%, rgba(160, 107, 255, 0.12), transparent 60%),
    radial-gradient(700px 400px at 45% 55%, rgba(212, 169, 79, 0.08), transparent 65%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0) 70%);
  background-attachment: fixed;
  background-size: 160% 160%;
  animation: bgDrift 24s ease-in-out infinite alternate;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
@keyframes bgDrift {
  from { background-position: 0% 0%; }
  to { background-position: 100% 100%; }
}

/* playful display font */
.word, .acc-num, .score, .tab, .scene-title, .bubble-word, .tray-count,
.modal-card h2, .primary, .mini, .nav-btn, .progress {
  font-family: "Fredoka", "Segoe UI", system-ui, sans-serif;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 12px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  backdrop-filter: blur(10px);
}
.brand img { height: 30px; display: block; }
.logo-plate {
  background: #fff;
  border-radius: 12px;
  padding: 7px 14px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  transition: transform 0.25s ease;
}
.logo-plate:hover { transform: rotate(-2deg) scale(1.05); }
.tabs { display: flex; gap: 6px; }
.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: all .2s;
}
.tab:hover { color: var(--ink); }
.tab.active {
  color: var(--ink);
  background: var(--accent-dim);
  border-color: rgba(94,230,208,0.3);
}
.deck-select { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.deck-select label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.deck-select select {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--card-edge);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 14px;
}

/* ---------- main / views ---------- */
main { flex: 1; display: flex; align-items: center; justify-content: center; padding: 28px 20px; }
.view { display: none; width: 100%; max-width: 980px; margin: 0 auto; }
.view.active { display: block; }

/* ---------- card ---------- */
.stage { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.card-wrap {
  width: min(94vw, 1080px);
  aspect-ratio: 16 / 9;
  perspective: 1400px;
  cursor: pointer;
  outline: none;
}
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .55s cubic-bezier(.4, .1, .2, 1);
}
.card-wrap.flipped .card-inner { transform: rotateY(180deg); }
.card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  backface-visibility: hidden;
  overflow: hidden;
  border: 1px solid var(--card-edge);
  box-shadow: 0 20px 60px rgba(0,0,0,0.55), 0 0 0 1px rgba(94,230,208,0.08);
  transition: box-shadow .3s;
}
.card-wrap:hover .card-face {
  box-shadow: 0 24px 70px rgba(0,0,0,0.6), 0 0 0 1px rgba(94,230,208,0.25), 0 0 40px rgba(94,230,208,0.12);
}
.card-front { background: var(--card); }
.card-front img { width: 100%; height: 100%; object-fit: cover; display: block; }
.flip-hint {
  position: absolute; right: 12px; bottom: 10px;
  font-size: 11px; color: rgba(233,236,244,0.7);
  background: rgba(0,0,0,0.45); padding: 4px 10px; border-radius: 999px;
  letter-spacing: .04em;
}
.card-back {
  transform: rotateY(180deg);
  background: linear-gradient(160deg, #0f1628, #0a0f1c);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; text-align: center; padding: 24px;
}
.phoneme {
  font-size: 12px; letter-spacing: .22em; text-transform: uppercase;
  color: var(--accent);
}
.word { font-size: clamp(34px, 6vw, 56px); font-weight: 800; letter-spacing: -0.01em; }
.sentence { font-size: clamp(15px, 2.4vw, 20px); color: var(--muted); max-width: 60ch; }
.review-flag {
  font-size: 12px; color: var(--amber); border: 1px solid rgba(251,191,36,0.4);
  padding: 3px 10px; border-radius: 999px; background: rgba(251,191,36,0.1);
}

.card-nav { display: flex; align-items: center; gap: 16px; }
.nav-btn {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--card-edge); font-size: 22px; cursor: pointer;
  transition: all .15s;
}
.nav-btn:hover { border-color: var(--accent); color: var(--accent); }
.nav-hint { display: flex; gap: 18px; font-size: 12px; color: var(--muted); }
.stage-actions { display: flex; align-items: center; gap: 14px; }
.progress { font-size: 13px; color: var(--muted); }

.ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--card-edge); border-radius: 999px;
  padding: 8px 18px; font-size: 13px; cursor: pointer; transition: all .15s;
}
.ghost:hover { color: var(--ink); border-color: var(--accent); }

/* ---------- webtoon ---------- */
.comic {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px;
}
.panel { position: relative; border-radius: 14px; overflow: hidden; border: 1px solid var(--card-edge); background: var(--card); }
.panel img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
.bubble {
  position: absolute; left: 8px; right: 8px; top: 8px;
  min-height: 52px; background: rgba(255,255,255,0.92); color: #14161c;
  border-radius: 14px; padding: 10px 12px; font-size: 13px; line-height: 1.35;
  outline: none; cursor: text;
}
.bubble:empty::before { content: attr(data-ph); color: #9aa0ad; }
.comic + .ghost { margin-top: 16px; }

/* ---------- HUD ---------- */
.hud {
  position: sticky; bottom: 0;
  display: flex; align-items: center; gap: 20px;
  padding: 14px 20px;
  background: var(--hud-bg);
  backdrop-filter: blur(14px);
  border-top: 1px solid rgba(255,255,255,0.07);
  flex-wrap: wrap;
}
.hud-block { display: flex; align-items: center; gap: 10px; }
.hud-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.cue-pills { display: flex; gap: 5px; }
.cue-pill {
  background: transparent; border: 1px solid var(--card-edge); color: var(--muted);
  font-size: 12px; padding: 5px 10px; border-radius: 999px; cursor: pointer;
}
.cue-pill.active { color: var(--ink); background: var(--accent-dim); border-color: rgba(94,230,208,0.4); }

.scores { gap: 12px; }
.score {
  display: flex; align-items: center; gap: 8px;
  border-radius: 999px; padding: 12px 22px; font-size: 18px; font-weight: 700;
  cursor: pointer; border: 1px solid transparent;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  transition: transform .12s, box-shadow .15s;
}
.score:hover { transform: translateY(-2px); }
.score:active { transform: scale(0.92); }
.score .cnt { font-size: 13px; opacity: 0.9; }
.score.correct   { background: rgba(52,211,153,0.16); color: var(--green);  border-color: rgba(52,211,153,0.4); }
.score.cued      { background: rgba(251,191,36,0.14); color: var(--amber);  border-color: rgba(251,191,36,0.4); }
.score.incorrect { background: rgba(248,113,113,0.15); color: var(--red);    border-color: rgba(248,113,113,0.4); }

.stats { flex-direction: column; align-items: flex-start; gap: 4px; min-width: 120px; }
.acc-num { font-size: 26px; font-weight: 800; line-height: 1; }
.acc-bar { width: 100%; height: 6px; background: rgba(255,255,255,0.08); border-radius: 999px; overflow: hidden; }
#accFill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--purple)); border-radius: 999px; transition: width .3s; }
.acc-label { font-size: 11px; color: var(--muted); }

.tools { margin-left: auto; gap: 12px; }
.mini {
  background: var(--card); color: var(--ink); border: 1px solid var(--card-edge);
  border-radius: 999px; padding: 9px 16px; font-size: 13px; cursor: pointer;
}
.mini:hover { border-color: var(--accent); }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; }
.toggle input { display: none; }
.toggle .tgl {
  width: 36px; height: 20px; border-radius: 999px; background: var(--card-edge);
  position: relative; transition: background .2s;
}
.toggle .tgl::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: transform .2s;
}
.toggle input:checked + .tgl { background: var(--accent); }
.toggle input:checked + .tgl::after { transform: translateX(16px); }

.primary {
  background: linear-gradient(135deg, var(--accent), #3ec9b3);
  color: #04140f; font-weight: 800; font-size: 14px;
  border: none; border-radius: 999px; padding: 11px 22px; cursor: pointer;
  box-shadow: 0 8px 24px rgba(94,230,208,0.25);
}
.primary:hover { filter: brightness(1.05); }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(6px); z-index: 50;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(92vw, 620px); background: #0e1422; border: 1px solid var(--card-edge);
  border-radius: 20px; padding: 26px; box-shadow: 0 30px 80px rgba(0,0,0,0.6);
  position: relative;
}
.modal-card h2 { margin: 0 0 4px; font-size: 22px; }
.modal-sub { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.modal-card textarea {
  width: 100%; min-height: 160px; resize: vertical;
  background: #070b14; color: var(--ink); border: 1px solid var(--card-edge);
  border-radius: 12px; padding: 14px; font-size: 14px; line-height: 1.6; font-family: inherit;
}
.modal-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.copied {
  position: absolute; top: 18px; right: 20px; color: var(--green);
  font-size: 13px; font-weight: 600;
}

/* student view — hide scoring from the student */
.hud.student .score .cnt { display: none; }
.hud.student .stats { visibility: hidden; }
.mini-select {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--card-edge);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 13px;
}

/* ---------- scenes (I-Spy hotspot) ---------- */
.scene-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}
.scene-title { font-size: 20px; font-weight: 800; }
.scene-sound {
  font-size: 12px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--accent);
}
.scene-controls { margin-left: auto; display: flex; gap: 14px; align-items: center; }
.scene-stage {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--card-edge);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  background: #000;
  cursor: crosshair;
}
.scene-stage img { width: 100%; display: block; }

.zone {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 9%;
  aspect-ratio: 1;
  border-radius: 50%;
  cursor: pointer;
}
.zone:hover { transform: translate(-50%, -50%) scale(1.3); }
.scene-stage.ghost .zone:not(.found) {
  background: radial-gradient(circle, rgba(94, 230, 208, 0.30), rgba(94, 230, 208, 0.06) 70%);
  border: 2px dashed rgba(94, 230, 208, 0.65);
  animation: zonePulse 1.5s ease-in-out infinite;
}
@keyframes zonePulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}
.zone.found::after {
  content: "✓";
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--green);
  color: #04140f;
  font-size: 13px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 10px rgba(52, 211, 153, 0.55);
}

.scene-bubble {
  position: absolute;
  z-index: 5;
  min-width: 160px;
  max-width: 230px;
  background: rgba(16, 22, 38, 0.97);
  border: 1px solid rgba(94, 230, 208, 0.4);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
  transform-origin: bottom center;
  animation: bubblePop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes bubblePop {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.bubble-x {
  position: absolute; top: 4px; right: 8px;
  background: none; border: none;
  color: var(--muted); font-size: 18px; cursor: pointer;
}
.bubble-x:hover { color: var(--ink); }
.bubble-word { font-size: 24px; font-weight: 800; margin: 4px 0 2px; }
.bubble-word .ph { color: var(--accent); }
.bubble-syll {
  color: var(--muted); font-size: 13px;
  letter-spacing: 0.35em; margin-bottom: 10px;
}
.bubble-sound {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(94, 230, 208, 0.4);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}
.bubble-sound:hover { background: rgba(94, 230, 208, 0.25); }

.scene-tray {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}
.tray-label {
  font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .1em;
}
.tray-bar {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}
#trayFill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--green), var(--accent));
  border-radius: 999px;
  transition: width 0.3s;
}
.tray-count { font-size: 15px; font-weight: 700; min-width: 56px; text-align: right; }

.scene-sub {
  font-size: 12px;
  color: var(--muted);
  background: var(--accent-dim);
  border: 1px solid rgba(94, 230, 208, 0.3);
  padding: 3px 10px;
  border-radius: 999px;
}
.scene-tray.complete #trayFill {
  background: linear-gradient(90deg, var(--gold), #ffd76a);
}
.scene-tray.complete .tray-label { color: var(--gold); font-weight: 700; }

/* score feedback pop */
.float-pop {
  position: fixed;
  left: 50%;
  bottom: 150px;
  transform: translateX(-50%);
  font-size: 26px;
  font-weight: 800;
  z-index: 60;
  pointer-events: none;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  animation: floatUp 0.75s ease-out forwards;
}
@keyframes floatUp {
  0%   { opacity: 0; transform: translate(-50%, 8px) scale(0.6); }
  25%  { opacity: 1; transform: translate(-50%, -4px) scale(1.2); }
  100% { opacity: 0; transform: translate(-50%, -52px) scale(1); }
}

/* celebration confetti */
.confetti-piece {
  position: fixed;
  width: 10px;
  height: 14px;
  z-index: 60;
  pointer-events: none;
  border-radius: 3px;
  animation: confettiFly 1s cubic-bezier(0.2, 0.7, 0.4, 1) forwards;
}
@keyframes confettiFly {
  0%   { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; }
}

@media (max-width: 720px) {
  .hud { gap: 12px; }
  .tools { margin-left: 0; }
  .nav-hint { display: none; }
  .comic { grid-template-columns: 1fr; }
  .deck-select { display: none; }
}
