/* ==========================================================================
   MindQuest Kids — Design System
   Palette: Midnight Indigo #241B4E · Twilight Purple #3E3272 ·
            Stardust Pink #FF8FB1 · Glow Teal #5EEAD4 · Sunburst Yellow #FFD166 ·
            Cloud White #FFF9F5
   Signature: a glowing constellation motif ties the whole app together — the
   same "stars connecting into light" idea used for the progress map is echoed
   in confetti bursts, idle-hint pulses, and card transitions.
   Type: no external webfonts (keeps the app 100% offline/zero-network) — a
   heavy-weight system rounded-font stack carries the friendly personality instead.
   ========================================================================== */

:root {
  --ink: #241B4E;
  --surface: #3E3272;
  --surface-2: #4A3F86;
  --pink: #FF8FB1;
  --teal: #5EEAD4;
  --yellow: #FFD166;
  --cloud: #FFF9F5;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "Segoe UI Rounded", "Segoe UI", Roboto, Verdana, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
body {
  font-family: var(--font);
  background: var(--ink);
  color: var(--cloud);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
#app { height: 100vh; height: 100dvh; width: 100vw; overflow: hidden; position: relative; }
button { font-family: inherit; border: none; cursor: pointer; touch-action: manipulation; }
input { font-family: inherit; }

/* Starfield ambient background on every screen */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(1px 1px at 10% 20%, #fff, transparent),
    radial-gradient(1px 1px at 80% 10%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 40% 70%, #fff, transparent),
    radial-gradient(1px 1px at 90% 80%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 60% 30%, #fff, transparent),
    radial-gradient(1px 1px at 25% 85%, #fff, transparent);
  opacity: .5;
  background-color: var(--ink);
}

/* ---------- Generic screen / button primitives ---------------------------- */
.mqk-screen { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; gap: 12px; }
.mqk-logo { font-size: 2rem; font-weight: 800; letter-spacing: -.02em; margin: 0; background: linear-gradient(90deg, var(--pink), var(--yellow)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.mqk-tagline { font-size: 1.05rem; opacity: .85; margin: 0 0 8px; }

.mqk-btn { padding: 16px 28px; border-radius: 999px; font-size: 1.05rem; font-weight: 700; min-height: 56px; transition: transform .15s ease; }
.mqk-btn:active { transform: scale(.96); }
.mqk-btn-primary { background: linear-gradient(135deg, var(--pink), #ff6f9c); color: #241B4E; box-shadow: 0 6px 18px rgba(255,143,177,.35); }
.mqk-btn-ghost { background: rgba(255,255,255,.08); color: var(--cloud); }
.mqk-btn-danger { background: rgba(255,90,90,.15); color: #ff9c9c; border: 1.5px solid rgba(255,90,90,.4); }

/* ---------- Loading ---------------------------------------------------------- */
.mqk-loading-star { font-size: 3rem; animation: mqk-spin-pulse 1.6s ease-in-out infinite; }
@keyframes mqk-spin-pulse { 0%,100% { transform: scale(1) rotate(0deg); opacity:.7; } 50% { transform: scale(1.25) rotate(15deg); opacity:1; } }

/* ---------- Profile select / onboarding -------------------------------------- */
.mqk-profile-grid, .mqk-avatar-grid { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; max-width: 420px; }
.mqk-profile-card {
  background: var(--surface); border-radius: 24px; padding: 20px 24px; min-width: 110px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--cloud); font-weight: 700;
  box-shadow: 0 8px 20px rgba(0,0,0,.25); border: 2px solid transparent;
}
.mqk-profile-card:active { transform: scale(.96); }
.mqk-profile-avatar { font-size: 2.4rem; }
.mqk-profile-add { background: rgba(255,255,255,.06); border: 2px dashed rgba(255,255,255,.3); }

.mqk-text-input { width: 100%; max-width: 320px; padding: 14px 18px; border-radius: 16px; border: none; font-size: 1.1rem; text-align: center; margin: 6px 0 12px; background: rgba(255,255,255,.92); color: #241B4E; font-weight: 600; }
.mqk-avatar-opt { font-size: 2.1rem; background: var(--surface); border-radius: 18px; padding: 12px 16px; border: 2px solid transparent; }
.mqk-avatar-opt.mqk-selected { border-color: var(--yellow); background: var(--surface-2); box-shadow: 0 0 0 4px rgba(255,209,102,.25); }
.mqk-add-profile .mqk-btn { margin-top: 16px; width: 100%; max-width: 320px; }

/* ---------- Top bar ------------------------------------------------------------ */
.mqk-topbar { position: absolute; top: 0; left: 0; right: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: env(safe-area-inset-top, 14px) 14px 10px; }
.mqk-topbar-profile { margin-right: auto; background: rgba(0,0,0,.25); border-radius: 999px; padding: 6px 10px; backdrop-filter: blur(6px); }
.mqk-topbar-avatar { font-size: 1.3rem; }
.mqk-topbar-btn { background: rgba(0,0,0,.25); backdrop-filter: blur(6px); color: var(--cloud); border-radius: 999px; padding: 8px 14px; font-size: 1.1rem; font-weight: 700; display: flex; align-items: center; gap: 4px; min-height: 40px; }

/* ---------- Feed & cards -------------------------------------------------------- */
.mqk-feed { height: 100%; width: 100%; overflow-y: scroll; scroll-snap-type: y mandatory; scrollbar-width: none; }
.mqk-feed::-webkit-scrollbar { display: none; }
.mqk-card { height: 100%; width: 100%; scroll-snap-align: start; scroll-snap-stop: always; display: flex; align-items: center; justify-content: center; position: relative; padding: 20px; }
.mqk-card-inner { width: 100%; max-width: 480px; height: 100%; max-height: 720px; display: flex; align-items: center; justify-content: center; }
.mqk-card-loading { opacity: .35; }
.mqk-skel-icon { font-size: 3rem; font-weight: 800; width: 90px; height: 90px; border-radius: 50%; background: rgba(255,255,255,.08); display: flex; align-items: center; justify-content: center; }

.mqk-swipe-hint { position: absolute; bottom: 28px; left: 0; right: 0; text-align: center; font-weight: 700; opacity: 0; animation: mqk-hint-fade 2.6s ease forwards; pointer-events: none; }
@keyframes mqk-hint-fade { 0% { opacity: 0; transform: translateY(6px);} 15% { opacity: 1; transform: translateY(0);} 80% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Shared game shell ---------------------------------------------------- */
.mqk-game { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px; border-radius: 32px; background: linear-gradient(160deg, var(--primary), var(--ink)); padding: 32px 20px; position: relative; overflow: hidden; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.mqk-prompt { font-size: 1.4rem; font-weight: 800; text-align: center; line-height: 1.35; text-shadow: 0 2px 8px rgba(0,0,0,.3); max-width: 340px; }

/* Tap-to-Match */
.mqk-options { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.mqk-option { background: rgba(255,255,255,.1); border-radius: 22px; padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; min-width: 96px; min-height: 96px; font-weight: 700; color: var(--cloud); border: 2px solid rgba(255,255,255,.15); transition: transform .12s ease; }
.mqk-option:active { transform: scale(.94); }
.mqk-option.mqk-correct { background: rgba(94,234,212,.28); border-color: var(--teal); }
.mqk-option.mqk-wrong { animation: mqk-shake .35s ease; }
@keyframes mqk-shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* Drag-and-Drop */
.mqk-zones { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; }
.mqk-zone { width: 84px; height: 84px; border-radius: 20px; border: 3px dashed rgba(255,255,255,.35); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .8rem; font-weight: 700; }
.mqk-tray { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; position: relative; min-height: 90px; }
.mqk-draggable { position: relative; touch-action: none; cursor: grab; padding: 8px; border-radius: 16px; background: rgba(255,255,255,.08); }
.mqk-draggable.mqk-dragging { z-index: 10; cursor: grabbing; filter: drop-shadow(0 10px 14px rgba(0,0,0,.4)); }
.mqk-draggable.mqk-placed { opacity: .55; pointer-events: none; }
.mqk-draggable.mqk-wrong { animation: mqk-shake .35s ease; }

/* Trace */
.mqk-trace-svg { width: 220px; height: 220px; touch-action: none; }
.mqk-trace-progress { transition: stroke-dashoffset .05s linear; }

/* Sequence */
.mqk-pads { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.mqk-pad { width: 72px; height: 72px; border-radius: 20px; background: var(--pad-color); display: flex; align-items: center; justify-content: center; opacity: .75; transition: transform .1s ease, opacity .1s ease; }
.mqk-pad:disabled { opacity: .4; }
.mqk-pad.mqk-pad-active { opacity: 1; transform: scale(1.12); box-shadow: 0 0 0 6px rgba(255,255,255,.25); }

/* Calm the Dragon */
.mqk-dragon-scene { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.mqk-dragon-char { font-size: 5rem; transition: transform .2s ease; }
.mqk-dragon-char.mqk-dragon-pressed { transform: scale(1.08); }
.mqk-dragon-char.mqk-dragon-asleep { filter: grayscale(.2); animation: mqk-sleepy-bob 1.4s ease-in-out infinite; }
@keyframes mqk-sleepy-bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.mqk-breath-meter { width: 220px; height: 18px; border-radius: 999px; background: rgba(255,255,255,.15); overflow: hidden; }
.mqk-breath-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--teal), var(--pink)); transition: width .1s linear; }
.mqk-dragon-hint { font-size: .95rem; opacity: .85; text-align: center; }

/* Idle "no-fail" pulse hint */
.mqk-pulse { animation: mqk-pulse-anim 1s ease-in-out; }
@keyframes mqk-pulse-anim { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); box-shadow: 0 0 0 10px rgba(255,255,255,.15); } }
.mqk-bounce-hint { animation: mqk-bounce-anim .5s ease; }
@keyframes mqk-bounce-anim { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* Confetti burst (signature motif) */
.mqk-confetti { position: absolute; inset: 0; pointer-events: none; display: flex; align-items: center; justify-content: center; }
.mqk-confetti span { position: absolute; width: 8px; height: 8px; border-radius: 2px; background: hsl(var(--hue, 340), 90%, 70%); animation: mqk-confetti-burst .9s ease-out forwards; }
@keyframes mqk-confetti-burst { 0% { transform: translate(0,0) rotate(0); opacity: 1; } 100% { transform: translate(var(--x), 140px) rotate(var(--rot)); opacity: 0; } }

/* ---------- Overlays / sheets ---------------------------------------------------- */
.mqk-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(10,6,30,.72); backdrop-filter: blur(4px); display: flex; align-items: flex-end; justify-content: center; animation: mqk-fade-in .2s ease; }
@keyframes mqk-fade-in { from { opacity: 0; } to { opacity: 1; } }
.mqk-sheet { background: var(--surface); width: 100%; max-width: 480px; border-radius: 28px 28px 0 0; padding: 28px 24px calc(28px + env(safe-area-inset-bottom, 0px)); position: relative; max-height: 88vh; overflow-y: auto; animation: mqk-sheet-up .25s ease; }
@keyframes mqk-sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.mqk-sheet h2 { margin: 0 0 4px; font-size: 1.4rem; }
.mqk-close { position: absolute; top: 18px; right: 18px; background: rgba(255,255,255,.1); width: 36px; height: 36px; border-radius: 50%; color: var(--cloud); font-size: 1rem; }

/* Math gate */
.mqk-mathgate-sub { opacity: .8; margin: 0 0 6px; }
.mqk-mathgate-question { font-size: 2rem; font-weight: 800; text-align: center; margin: 14px 0 20px; }
.mqk-mathgate-options { display: flex; gap: 14px; justify-content: center; }
.mqk-mathgate-opt { background: var(--surface-2); color: var(--cloud); font-size: 1.3rem; font-weight: 700; width: 76px; height: 76px; border-radius: 20px; }
.mqk-mathgate-opt.mqk-wrong { animation: mqk-shake .35s ease; }

/* Bedtime lock */
.mqk-bedtime-sheet { text-align: center; }
.mqk-bedtime-icon { font-size: 3.5rem; margin-bottom: 6px; }
.mqk-bedtime-sheet .mqk-btn { margin-top: 18px; width: 100%; }

/* Parent portal */
.mqk-portal-sub { opacity: .75; margin: 0 0 20px; }
.mqk-field { display: block; margin-bottom: 22px; }
.mqk-field span { display: block; margin-bottom: 10px; font-weight: 700; }
.mqk-field input[type=range] { width: 100%; }
.mqk-stat-row { display: flex; gap: 14px; margin-bottom: 22px; }
.mqk-stat { background: rgba(255,255,255,.06); border-radius: 16px; padding: 14px 20px; text-align: center; }
.mqk-stat strong { display: block; font-size: 1.4rem; }
.mqk-stat span { font-size: .8rem; opacity: .75; }
.mqk-portal-danger { border-top: 1px solid rgba(255,255,255,.1); padding-top: 18px; margin-bottom: 18px; }
.mqk-portal-note { font-size: .82rem; opacity: .7; margin: 8px 0 0; }
.mqk-portal-sheet .mqk-btn-primary { width: 100%; margin-top: 6px; }
.mqk-confirm-actions { display: flex; gap: 12px; margin-top: 18px; }
.mqk-confirm-actions .mqk-btn { flex: 1; }

/* Mind map */
.mqk-mindmap-svg { width: 100%; max-width: 320px; aspect-ratio: 1; margin: 10px auto; display: block; }
.mqk-mm-star circle { transition: r .2s ease; cursor: pointer; }
.mqk-mm-glow { animation: mqk-glow-pulse 2.4s ease-in-out infinite; }
@keyframes mqk-glow-pulse { 0%,100% { opacity: .18; } 50% { opacity: .4; } }
.mqk-mindmap-legend { text-align: center; font-weight: 700; min-height: 1.4em; }

/* Star toast */
.mqk-star-toast { position: fixed; top: 70px; left: 50%; transform: translateX(-50%) translateY(-16px); background: var(--yellow); color: #241B4E; font-weight: 800; padding: 10px 20px; border-radius: 999px; opacity: 0; transition: all .3s ease; z-index: 60; box-shadow: 0 8px 20px rgba(0,0,0,.3); }
.mqk-star-toast-show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Storage degraded notice */
.mqk-storage-notice { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.75); color: var(--cloud); font-size: .8rem; padding: 10px 16px; border-radius: 14px; max-width: 86%; text-align: center; z-index: 60; }

/* ---------- Accessibility: reduced motion (resolved decision) --------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ---------- Responsive: small phones --------------------------------------------- */
@media (max-width: 360px) {
  .mqk-prompt { font-size: 1.2rem; }
  .mqk-option, .mqk-zone { min-width: 80px; min-height: 80px; }
}
