/* ============ Blast Off, Theo! ============ */

@font-face {
  font-family: 'Fredoka';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('../assets/fonts/fredoka-latin.woff2') format('woff2');
}
/* Medieval display face for the Knight & Dragon theme (design spec uses
   Cinzel Decorative for the numeral, banner, tower runes and tiles). Bundled
   for offline PWA use; applied only where --display-font is switched. */
@font-face {
  font-family: 'Cinzel Decorative';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../assets/fonts/cinzel-decorative-700-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Cinzel Decorative';
  font-style: normal;
  font-weight: 900;
  font-display: swap;
  src: url('../assets/fonts/cinzel-decorative-900-latin.woff2') format('woff2');
}

:root {
  /* the numeral/banner/tile/tower typeface; a theme may switch it (knight →
     Cinzel Decorative). Chrome reads it so a theme's look reaches the shared
     HUD, not just its SVG scene. */
  --display-font: 'Fredoka', ui-rounded, -apple-system, system-ui, sans-serif;
  --sky-top: #0b0f33;
  --sky-mid: #221850;
  --sky-bottom: #43307c;
  --ground: #171040;
  --star-gold: #ffd94a;
  /* one stable color per number — rainbow order doubles as a sequence cue */
  --n1: #ff5a5a; --n2: #ff9438; --n3: #ffc93c; --n4: #7ed957; --n5: #35c99e;
  --n6: #3ec5ff; --n7: #4f7bff; --n8: #8f6bff; --n9: #e06bff; --n10: #ff6bb3;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--sky-top);
  overscroll-behavior: none;
}

body {
  font-family: 'Fredoka', ui-rounded, -apple-system, system-ui, sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#app {
  position: fixed; inset: 0;
  overflow: hidden;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 55%, var(--sky-bottom) 100%);
  /* sky heals gently when the palette changes (knight peace/round arc) */
  transition: background 1.2s ease;
}

#scene { position: absolute; inset: 0; z-index: 1; }
#scene svg { width: 100%; height: 100%; display: block; }

#fx { position: absolute; inset: 0; z-index: 10; pointer-events: none; }

/* ---------- tile tray ---------- */

#tray {
  position: absolute;
  left: 0; right: 0;
  bottom: max(2.5vh, env(safe-area-inset-bottom));
  display: flex; justify-content: center; align-items: flex-end;
  gap: 3.5vmin;
  z-index: 20;
  pointer-events: none;
}

.tile {
  pointer-events: auto;
  width: clamp(100px, 22vmin, 260px);
  aspect-ratio: 1;
  border: none;
  border-radius: 24%;
  background: var(--tile-color, #4f7bff);
  color: #fff;
  font-family: inherit;
  font-weight: 600;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4%;
  cursor: pointer;
  box-shadow:
    0 1.2vmin 0 rgba(0,0,0,.28),
    0 2vmin 4vmin rgba(0,0,0,.35),
    inset 0 -1vmin 0 rgba(0,0,0,.15),
    inset 0 0.8vmin 0 rgba(255,255,255,.25);
  transition: transform .12s ease;
  animation: tile-in .38s cubic-bezier(.2,1.6,.4,1) backwards;
}
.tile:active { transform: scale(.93) translateY(.6vmin); }
.tile.solo { width: clamp(140px, 30vmin, 340px); }

.tile .numeral {
  font-family: var(--display-font);
  font-size: 11vmin;
  line-height: 1;
  text-shadow: 0 .5vmin 0 rgba(0,0,0,.2);
}
.tile.solo .numeral { font-size: 16vmin; }

/* ten-frame dots under the numeral — subitizing support */
.tile .dots {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .7vmin;
}
.tile .dots i {
  width: 1.7vmin; height: 1.7vmin;
  border-radius: 50%;
  background: rgba(255,255,255,.9);
  box-shadow: 0 .2vmin .3vmin rgba(0,0,0,.25);
}
.tile.solo .dots i { width: 2.2vmin; height: 2.2vmin; }

@keyframes tile-in {
  from { transform: scale(0) translateY(8vmin); opacity: 0; }
  to   { transform: scale(1) translateY(0);     opacity: 1; }
}

.tile.wiggle { animation: wiggle .5s ease; }
@keyframes wiggle {
  0%,100% { transform: rotate(0); }
  20% { transform: rotate(-7deg) translateX(-1vmin); }
  40% { transform: rotate(6deg) translateX(1vmin); }
  60% { transform: rotate(-5deg); }
  80% { transform: rotate(4deg); }
}

.tile.pulse { animation: pulse 1s ease infinite; }
@keyframes pulse {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.09); box-shadow: 0 0 6vmin var(--tile-color), 0 1.2vmin 0 rgba(0,0,0,.28); }
}

.tile.glow {
  animation: glow 1s ease infinite;
  z-index: 2;
}
@keyframes glow {
  0%,100% { transform: scale(1.12); box-shadow: 0 0 5vmin #fff, 0 0 9vmin var(--tile-color); }
  50%     { transform: scale(1.22); box-shadow: 0 0 8vmin #fff, 0 0 14vmin var(--tile-color); }
}

.tile.dim {
  opacity: .22;
  transform: scale(.85);
  pointer-events: none;
  transition: opacity .4s, transform .4s;
}

.tile.correct-pop { animation: correct-pop .5s cubic-bezier(.2,1.8,.4,1); }
@keyframes correct-pop {
  30% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* ---------- giant countdown number ---------- */

#bigNum {
  position: absolute;
  top: max(3vh, env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  font-family: var(--display-font);
  font-size: 17vmin;
  font-weight: 700;
  color: #fff;
  line-height: 1;
  text-shadow: 0 0 4vmin var(--big-glow, #4f7bff), 0 1vmin 0 rgba(0,0,0,.3);
  pointer-events: none;
  transition: color .2s;
}
#bigNum.solo {
  top: 34%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 46vmin;
  pointer-events: auto;
  cursor: pointer;
}
#bigNum.tick { animation: num-tick .45s cubic-bezier(.2,1.6,.4,1); }
@keyframes num-tick {
  0% { opacity: 0; scale: 1.9; }
  100% { opacity: 1; scale: 1; }
}

/* ---------- HUD ---------- */

/* stars live top-right so the persistent progress numeral owns top-center */
#hud {
  position: absolute;
  top: max(1.5vh, env(safe-area-inset-top));
  left: 0; right: max(2vmin, env(safe-area-inset-right));
  display: flex; justify-content: flex-end;
  z-index: 30;
  pointer-events: none;
}
#stars { display: flex; gap: 2vmin; font-size: 6vmin; filter: drop-shadow(0 .4vmin .6vmin rgba(0,0,0,.4)); }
#stars .slot { opacity: .35; }
#stars .slot.earned { opacity: 1; animation: star-pop .6s cubic-bezier(.2,1.8,.4,1); }
@keyframes star-pop { 30% { transform: scale(1.8) rotate(20deg); } }

/* listening indicator for the experimental mic mode. DEBUG: a filled ring
   makes muted-vs-listening readable at a glance across every theme — not
   trying to look nice, just unmissable while watching the hint-block bug. */
#micDot {
  position: absolute;
  top: max(9vh, calc(env(safe-area-inset-top) + 7vh));
  right: max(2vmin, env(safe-area-inset-right));
  z-index: 30;
  width: 7vmin; height: 7vmin;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-size: 4vmin;
  pointer-events: none;
  background: rgba(40, 210, 110, .55);
  box-shadow: 0 0 0 .5vmin rgba(40, 210, 110, .3);
  animation: mic-pulse 1.4s ease infinite;
  filter: drop-shadow(0 .3vmin .5vmin rgba(0,0,0,.5));
}
/* game's own voice audible — informational blue, NOT a mute (input stays
   live; the echo ledger discounts the game's own words) */
#micDot.muted {
  background: rgba(70, 130, 235, .6);
  box-shadow: 0 0 0 .5vmin rgba(70, 130, 235, .35);
  animation: none;
}
/* zombie recognizer: session "live" but eventless — the ear is deaf and a
   rebuild is imminent (energy detector ~2-3s / silence fallback 20s) */
#micDot.stale {
  background: rgba(235, 170, 40, .65);
  box-shadow: 0 0 0 .5vmin rgba(235, 170, 40, .4);
  animation: none;
}
@keyframes mic-pulse { 50% { opacity: .45; transform: scale(.9); } }

/* what the mic heard — parent-facing audit strip under the 🎤 */
#micCaption {
  position: absolute;
  top: max(14vh, calc(env(safe-area-inset-top) + 12vh));
  right: max(2vmin, env(safe-area-inset-right));
  z-index: 30;
  max-width: 40vw;
  padding: .8vmin 1.6vmin;
  border-radius: 1.4vmin;
  background: rgba(12, 16, 50, .75);
  color: #aab1e8;
  font-size: 2.2vmin;
  text-align: right;
  pointer-events: none;
  transition: opacity .3s;
}
#micCaption.match { color: #7ed957; font-weight: 600; }
#micCaption.idle { opacity: .5; }
#micCaption.muted-state { color: #8db4ff; opacity: .85; }  /* game talking — informational */
#micCaption.stale-state { color: #ffc04d; opacity: .95; }  /* deaf ear — rebuild imminent */

/* DEBUG: collapsed tab (bottom-right, clear of the tile tray) that expands
   into a live voice-log panel — "what was heard and why it was/wasn't
   accepted," visible without the parent-panel hold gesture. Not styled to
   look nice; styled to be legible while watching a real playtest. */
#debugTab {
  position: absolute;
  bottom: max(2vh, calc(env(safe-area-inset-bottom) + 1vh));
  right: max(2vmin, env(safe-area-inset-right));
  z-index: 40;
  width: 8vmin; height: 8vmin;
  border: none; border-radius: 50%;
  font-size: 4vmin;
  background: rgba(20, 24, 60, .55);
  box-shadow: 0 .3vmin 1vmin rgba(0,0,0,.4);
  cursor: pointer;
}
#debugTab.open { background: rgba(60, 140, 230, .75); }

#debugPanel {
  position: absolute;
  bottom: max(11vh, calc(env(safe-area-inset-bottom) + 10vh));
  right: max(2vmin, env(safe-area-inset-right));
  z-index: 40;
  width: min(88vw, 480px);
  max-height: 55vh;
  display: flex; flex-direction: column;
  background: rgba(8, 10, 26, .92);
  border-radius: 1.2vmin;
  box-shadow: 0 1vmin 3vmin rgba(0,0,0,.5);
  overflow: hidden;
}
#debugPanelHead {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1.2vh 1.6vmin;
  background: rgba(60, 140, 230, .25);
  color: #cfe0ff;
  font-size: 2vmin;
  font-weight: 600;
}
#debugPanelHead button {
  font-size: 1.7vmin;
  padding: .4vh 1.2vmin;
  border: none; border-radius: 1vmin;
  background: rgba(255,255,255,.15);
  color: #fff;
  cursor: pointer;
}
#debugLog {
  margin: 0;
  padding: 1vh 1.6vmin 1.6vh;
  overflow-y: auto;
  font: 1.7vmin/1.5 ui-monospace, monospace;
  color: #b9c2e8;
  white-space: pre-wrap;
}
#debugLog .dbg-accept { color: #7ed957; }
#debugLog .dbg-block { color: #ff7a68; }
#debugLog .dbg-clip { color: #7fb0ff; opacity: .8; }

/* on-device error reporter — debugging eyes for phones we can't inspect */
#errBadge {
  position: absolute;
  bottom: max(1vh, env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  z-index: 300;
  max-width: 92vw;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(160, 40, 55, .92);
  color: #fff;
  font-size: 12px;
  overflow-wrap: anywhere;
}

/* ---------- banner ---------- */

#banner {
  position: absolute;
  top: 38%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 40;
  font-family: var(--display-font);
  font-size: 11vmin;
  font-weight: 700;
  color: var(--star-gold);
  text-align: center;
  text-shadow: 0 0 4vmin rgba(255,217,74,.7), 0 1vmin 0 rgba(0,0,0,.35);
  white-space: nowrap;
  pointer-events: none;
  animation: banner-in .5s cubic-bezier(.2,1.8,.4,1);
}
/* Two-line finale ("Victory!" + "The wyrm is slayne") — the design's title
   is heavier with a dark stroke, the subtitle smaller and letter-spaced. */
#banner .banner-title { font-weight: 900; display: block; }
#banner .banner-sub {
  display: block;
  margin-top: 2vmin;
  font-size: 4vmin;
  font-weight: 700;
  letter-spacing: .3vmin;
  color: var(--banner-sub, currentColor);
}
@keyframes banner-in { from { transform: translate(-50%,-50%) scale(0); } }

/* ---------- ghost hand / hint ---------- */

#ghost {
  position: absolute;
  z-index: 50;
  font-size: 12vmin;
  pointer-events: none;
  filter: drop-shadow(0 1vmin 1.5vmin rgba(0,0,0,.5));
  transition: left .9s cubic-bezier(.5,0,.3,1), top .9s cubic-bezier(.5,0,.3,1);
}
#ghost.pressing { animation: ghost-press .5s ease; }
@keyframes ghost-press { 40% { transform: scale(.7) translateY(1.5vmin); } }
#ghost.bouncing { animation: ghost-bounce .8s ease infinite; }
@keyframes ghost-bounce { 50% { transform: translateY(-3vmin); } }

/* ---------- parent gear button ---------- */
/* Visible so parents can find it; on touch devices it needs a 2s hold
   (progress ring fills), so a mashing toddler can't open it. */

#parentBtn {
  position: absolute;
  top: max(1.5vh, env(safe-area-inset-top));
  left: max(2vmin, env(safe-area-inset-left));
  width: 9vmin; height: 9vmin;
  min-width: 44px; min-height: 44px;
  z-index: 90;
  border: none;
  border-radius: 50%;
  background:
    conic-gradient(#7ed957 calc(var(--hold, 0) * 360deg), transparent 0deg) border-box;
  padding: 0.5vmin;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
#parentBtn .gear {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  border-radius: 50%;
  background: rgba(20, 24, 64, .75);
  font-size: 4.5vmin;
  opacity: .75;
}
#parentBtn:active .gear { opacity: 1; }

#parentHint {
  margin-top: 2.5vh;
  font-size: 2.4vmin;
  color: #aab1e8;
  opacity: .75;
}

/* ---------- overlays ---------- */

.overlay {
  position: absolute; inset: 0;
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
}
.hidden { display: none !important; }

#title { background: radial-gradient(ellipse at 50% 45%, rgba(8,10,40,.25) 0%, rgba(8,10,40,.72) 100%); cursor: pointer; }
#title h1 {
  font-size: 12vmin;
  font-weight: 700;
  color: #fff;
  line-height: 1.05;
  text-shadow: 0 0 5vmin rgba(120,140,255,.8), 0 1vmin 0 rgba(0,0,0,.4);
}
#playHint {
  margin-top: 5vh;
  font-size: 5.5vmin;
  font-weight: 600;
  color: var(--star-gold);
  letter-spacing: .35vmin;
  animation: hint-pulse 1.6s ease infinite;
}
@keyframes hint-pulse { 50% { transform: scale(1.12); opacity: .85; } }
.rocket-bounce { display: inline-block; animation: rocket-bounce 1.6s ease infinite; }
@keyframes rocket-bounce { 50% { transform: translateY(-1.5vmin); } }

/* ---------- theme picker (title screen) ---------- */

#themePicker {
  margin-top: 4vh;
  display: flex;
  justify-content: center;
  gap: 3.5vmin;
}
.theme-card {
  pointer-events: auto;
  width: clamp(84px, 16vmin, 170px);
  aspect-ratio: 1;
  border: none;
  border-radius: 26%;
  background: rgba(255,255,255,.12);
  box-shadow: 0 .8vmin 0 rgba(0,0,0,.25), inset 0 .6vmin 0 rgba(255,255,255,.14);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .2s ease;
}
.theme-card span { font-size: 8vmin; line-height: 1; filter: drop-shadow(0 .4vmin .6vmin rgba(0,0,0,.4)); }
.theme-card:active { transform: scale(.93); }
.theme-card.selected {
  background: rgba(255,217,74,.22);
  box-shadow: 0 0 0 .5vmin var(--star-gold), 0 .8vmin 0 rgba(0,0,0,.25);
}

.shelf {
  margin-top: 6vh;
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 1.5vmin;
  max-width: 80vw;
  font-size: 6vmin;
  filter: drop-shadow(0 .4vmin .6vmin rgba(0,0,0,.4));
  min-height: 7vmin;
}
.shelf span { animation: tile-in .4s cubic-bezier(.2,1.6,.4,1) backwards; }

#ceremony { background: rgba(8,8,34,.82); }
#bigSticker { font-size: 34vmin; animation: sticker-land 1s cubic-bezier(.2,1.5,.4,1); filter: drop-shadow(0 0 6vmin rgba(255,217,74,.6)); }
@keyframes sticker-land {
  0% { transform: scale(0) rotate(-360deg); opacity: 0; }
  70% { transform: scale(1.15) rotate(8deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
#ceremonyText {
  margin-top: 2vh;
  font-size: 7.5vmin; font-weight: 700;
  color: var(--star-gold);
  text-shadow: 0 .6vmin 0 rgba(0,0,0,.35);
}

#alldone { background: rgba(8,8,34,.82); }
.alldone-inner { display: flex; gap: 6vmin; flex-wrap: wrap; justify-content: center; }
.choice-btn {
  width: clamp(150px, 34vmin, 340px);
  aspect-ratio: 1;
  border: none; border-radius: 22%;
  background: linear-gradient(180deg, #4f7bff, #3b5fd9);
  color: #fff;
  font-family: inherit; font-weight: 600;
  font-size: 4.5vmin;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2vmin;
  cursor: pointer;
  box-shadow: 0 1.2vmin 0 rgba(0,0,0,.3), 0 2vmin 4vmin rgba(0,0,0,.35);
  transition: transform .12s ease;
}
.choice-btn:active { transform: scale(.93); }
.choice-btn:first-child { background: linear-gradient(180deg, #ff9438, #ef7418); }
.choice-btn > :first-child { font-size: 13vmin; line-height: 1; }

/* ---------- parent panel ---------- */

#parent { background: rgba(8,8,30,.9); z-index: 200; }
.parent-inner {
  position: relative;
  background: #1c2150;
  color: #e8eaff;
  border-radius: 20px;
  padding: 28px;
  width: min(92vw, 660px);
  max-height: min(88vh, 88dvh);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  text-align: left;
  font-size: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
#btnCloseParentX {
  position: sticky;
  top: 0;
  float: right;
  width: 40px; height: 40px;
  border: none; border-radius: 12px;
  background: #3a4070; color: #fff;
  font-size: 20px; font-family: inherit;
  cursor: pointer;
  z-index: 2;
}
.parent-inner h2 { font-size: 24px; margin-bottom: 14px; }
.parent-inner h3 { font-size: 15px; margin: 16px 0 8px; opacity: .8; font-weight: 600; }

.stat-line { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 4px; font-size: 15px; }
.tgrid { display: flex; flex-wrap: wrap; gap: 5px; }
.tcell {
  padding: 5px 8px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  background: #333a6e;
  color: #cdd3ff;
}
.tcell.good { background: #1d6b45; color: #c6ffdf; }
.tcell.warn { background: #7a5c19; color: #ffe9b0; }
.tcell.bad  { background: #7a2530; color: #ffc9cf; }

.stepper {
  display: flex; align-items: center; gap: 10px;
  margin: 6px 0;
  font-size: 15px;
}
.stepper span { flex: 1; }
.stepper b { min-width: 26px; text-align: center; font-size: 18px; }
.stepper button {
  width: 38px; height: 38px;
  border: none; border-radius: 10px;
  background: #4f7bff; color: #fff;
  font-family: inherit; font-size: 22px; font-weight: 600;
  cursor: pointer;
}
.stepper button:active { transform: scale(.92); }

#parentToggles { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
#parentToggles label { display: flex; align-items: center; gap: 10px; cursor: pointer; }
#parentToggles input { width: 22px; height: 22px; accent-color: #7ed957; }

.parent-actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.parent-actions button {
  font-family: inherit; font-size: 15px; font-weight: 600;
  padding: 10px 16px; border: none; border-radius: 10px;
  background: #4f7bff; color: #fff; cursor: pointer;
}
.parent-actions #btnReset { background: #b03a4a; }
.parent-actions #btnCloseParent { background: #3a4070; }
.parent-tip { margin-top: 16px; font-size: 13px; opacity: .6; }

#parentVoice .voicelog {
  max-height: 180px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #12163c;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 11px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: #cdd3ff;
}
#parentVoice button {
  font-family: inherit; font-size: 13px; font-weight: 600;
  margin-top: 8px; padding: 8px 14px; border: none; border-radius: 10px;
  background: #3a4070; color: #fff; cursor: pointer;
}

/* Phones: three tiles must still fit side by side */
@media (max-width: 460px) {
  .tile { width: clamp(92px, 27vw, 300px); }
  .tile .numeral { font-size: 16vw; }
  #tray { gap: 2.5vw; }
}

/* ---------- screen shake ---------- */

.shake-sm { animation: shake-sm .3s linear infinite; }
@keyframes shake-sm {
  0%,100% { transform: translate(0,0); }
  25% { transform: translate(.25vmin,-.2vmin); }
  50% { transform: translate(-.2vmin,.25vmin); }
  75% { transform: translate(.2vmin,.2vmin); }
}
.shake-lg { animation: shake-lg .22s linear infinite; }
@keyframes shake-lg {
  0%,100% { transform: translate(0,0); }
  25% { transform: translate(.8vmin,-.6vmin); }
  50% { transform: translate(-.7vmin,.8vmin); }
  75% { transform: translate(.6vmin,.6vmin); }
}
