/* ══════════════════════════════════════════════════════════════════════════
   My Little Phonics — base styles, portrait frame, loader, animations
   Screen-level styling is applied inline from JS to mirror the design system;
   this file owns layout, the loading screen, and shared keyframes.
   ══════════════════════════════════════════════════════════════════════════ */

:root {
  /* Design tokens (mirrors the app colour system) */
  --bg: #F8F9FB;
  --card: #FFFFFF;
  --blue: #3A9FD5;
  --blue-dark: #1D7FB8;
  --coral: #E8604A;
  --coral-dark: #C0432C;
  --green: #3BB87A;
  --green-dark: #258C5A;
  --red: #DC2626;
  --red-dark: #991B1B;
  --star: #FFC234;
  --text: #1A2330;
  --muted: #8896A5;
  --pill: #EEF2F7;
  --frame-w: 430px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }

body {
  font-family: "Baloo 2", "Nunito", "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: #0f1830;
  background-image:
    radial-gradient(circle at 20% 15%, rgba(58,159,213,0.35), transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(232,96,74,0.30), transparent 45%),
    linear-gradient(160deg, #16233f 0%, #0c1428 100%);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Centre the portrait frame on any viewport ─────────────────────────── */
#stage {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

#frame {
  position: relative;
  width: 100%;
  max-width: var(--frame-w);
  height: 100%;
  max-height: 940px;
  background: var(--bg);
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0,0,0,0.55);
}

/* On roomy screens, show it as a rounded device */
@media (min-width: 480px) and (min-height: 720px) {
  #stage { padding: 20px; }
  #frame { border-radius: 40px; height: calc(100% - 4px); }
}

#app { position: absolute; inset: 0; }

/* Every screen fills the frame */
.screen { position: absolute; inset: 0; height: 100%; display: flex; flex-direction: column; }
.screen-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; }

/* ══ LOADING SCREEN ══════════════════════════════════════════════════════ */
#loader {
  position: absolute; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 26px; padding: 32px;
  background:
    radial-gradient(circle at 50% 30%, rgba(255,220,120,0.28), transparent 60%),
    linear-gradient(165deg, #3A9FD5 0%, #1D6FA8 60%, #14507d 100%);
  transition: opacity 0.5s ease;
}
#loader.hide { opacity: 0; pointer-events: none; }
.loader-inner { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; max-width: 300px; }
.loader-mascot { width: 132px; height: 132px; animation: bob 2.4s ease-in-out infinite; filter: drop-shadow(0 10px 18px rgba(0,0,0,0.25)); }
.loader-title { font-size: 30px; font-weight: 900; color: #fff; text-shadow: 0 2px 10px rgba(0,0,0,0.28); letter-spacing: .01em; }
.loader-sub { font-size: 14px; font-weight: 700; color: rgba(255,255,255,0.85); margin-top: -6px; }
.loader-track {
  width: 100%; height: 18px; border-radius: 999px; margin-top: 8px;
  background: rgba(0,0,0,0.20); box-shadow: inset 0 2px 4px rgba(0,0,0,0.25);
  overflow: hidden;
}
.loader-fill {
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, #FFD166, #FFC234);
  box-shadow: 0 0 12px rgba(255,210,80,0.8);
  transition: width 0.25s ease;
}
.loader-pct { font-size: 15px; font-weight: 900; color: #fff; }
.loader-note { font-size: 12px; font-weight: 700; color: rgba(255,255,255,0.75); min-height: 16px; }

.tap-to-start {
  border: none; cursor: pointer;
  display: inline-flex; align-items: center; gap: 12px;
  padding: 18px 34px; border-radius: 999px;
  font-size: 20px; font-weight: 900; color: #1D7FB8;
  background: #fff;
  box-shadow: 0 6px 0 rgba(0,0,0,0.15), 0 12px 30px rgba(0,0,0,0.3);
  animation: pop 0.4s ease-out, bob 2s ease-in-out infinite 0.4s;
  transition: transform 0.12s ease;
}
.tap-to-start:active { transform: scale(0.96); }
.tts-icon { font-size: 18px; color: var(--green); }

/* ══ SHARED KEYFRAMES ════════════════════════════════════════════════════ */
@keyframes bob { 0%,100% { transform: translateY(0);} 50% { transform: translateY(-10px);} }
@keyframes pop { 0% { transform: scale(0.4); opacity: 0;} 70% { transform: scale(1.06);} 100% { transform: scale(1); opacity: 1;} }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(16px);} to { opacity: 1; transform: translateY(0);} }
@keyframes fadeInDown { from { opacity: 0; transform: translateY(-16px);} to { opacity: 1; transform: translateY(0);} }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.86);} to { opacity: 1; transform: scale(1);} }
@keyframes spin { from { transform: rotate(0);} to { transform: rotate(360deg);} }
@keyframes countPop { 0% { opacity:0; transform: scale(0.9);} 45% { opacity:1; transform: scale(1.06);} 100% { opacity:1; transform: scale(1);} }
@keyframes dotPulse { 0%,100% { transform: scale(1); opacity:.6;} 50% { transform: scale(1.95); opacity:0;} }
@keyframes float { 0%,100% { transform: translateY(0);} 50% { transform: translateY(-8px);} }
@keyframes sparkleRise { 0% { transform: translateY(0); opacity: 0;} 20% { opacity: .9;} 80% { opacity:.6;} 100% { transform: translateY(-700px); opacity: 0;} }
@keyframes wiggle { 0%,100% { transform: rotate(0);} 25% { transform: rotate(12deg);} 60% { transform: rotate(-8deg);} }

/* ── Utility ─────────────────────────────────────────────────────────────── */
.anim-fade { animation: fadeIn .3s ease both; }
.anim-up { animation: fadeInUp .4s ease both; }
.anim-down { animation: fadeInDown .4s ease both; }
.anim-scale { animation: scaleIn .4s cubic-bezier(.2,.9,.3,1.2) both; }
.press { transition: transform .12s ease; cursor: pointer; }
.press:active { transform: scale(0.97); }
button { font-family: inherit; }

/* Hidden helper */
[hidden] { display: none !important; }

/* Custom scrollbars inside the frame (closing screen scrolls) */
.scroll-y { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.scroll-y::-webkit-scrollbar { width: 6px; }
.scroll-y::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.18); border-radius: 999px; }

/* Screen enter transition managed by scene manager */
.screen.entering { animation: fadeIn .28s ease both; }
