/* UI palette tokens — names match DESIGN.md. Animal artwork colors live in
   js/core/animals.js and are intentionally NOT tokens (art, not theme). */
:root {
  --sky-foam: #bfe6f2;
  --shallow-water: #6db7d8;
  --mid-water: #2f86b8;
  --deep-water: #155e8d;
  --abyss: #0d3f63;
  --foam-white: #ffffff;
  --ice-mist: #e8f2f8;
  --ink-deep: #13496e;
  --slate-muted: #3f6a87;
  --glow-pale: #dceefb;
  --glacier-blue: #79b8d6;
  --sunset-orange: #f2a25c;
  --kelp-green: #6ec99a;
  --kelp-light: #a8e6c4; /* with kelp-green: the correct-answer highlight surface */
  --anemone-purple: #c98ad9;
  --sun-gold: #f7d154;
  --coral: #ef7d6e;
  --teal-mem: #2fb6a8;
  --shadow-soft-lift: 0 6px 16px rgba(0, 20, 40, .3);
  --text-halo: 0 1px 0 rgba(255, 255, 255, .35);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
body { touch-action: none; user-select: none; -webkit-user-select: none; }

#app { position: fixed; inset: 0; background: linear-gradient(180deg, var(--sky-foam) 0%, var(--shallow-water) 12%, var(--mid-water) 45%, var(--deep-water) 78%, var(--abyss) 100%); overflow: hidden; }

/* rotate hint: only shown in portrait */
#rotate-hint { display: none; position: fixed; inset: 0; z-index: 99; background: var(--abyss); color: #fff; text-align: center; flex-direction: column; align-items: center; justify-content: center; gap: 16px; font-size: 22px; line-height: 1.6; }
#rotate-hint .rotate-icon { font-size: 64px; animation: spin 2.5s linear infinite; }
@media (orientation: portrait) { #rotate-hint { display: flex; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* big tappable buttons */
.btn { min-width: 80px; min-height: 80px; border: none; cursor: pointer; border-radius: 22px; background: linear-gradient(180deg, var(--foam-white), var(--ice-mist)); box-shadow: var(--shadow-soft-lift); font-family: inherit; transition: transform .12s ease; }
.btn:active { transform: scale(.93); }
.btn:focus-visible { outline: 4px solid var(--ink-deep); outline-offset: 3px; }
.btn-round { width: 56px; height: 56px; min-width: 56px; min-height: 56px; border-radius: 50%; font-size: 26px; }

/* language switch is a parent control: requires press-and-hold; the fill bar
   shows hold progress and retracts quickly when released early */
#lang-btn { position: relative; overflow: hidden; }
#lang-btn .hold-fill { position: absolute; inset: 0; background: color-mix(in srgb, var(--deep-water) 18%, transparent); transform: scaleX(0); transform-origin: left; pointer-events: none; transition: transform .15s ease; }
#lang-btn.holding .hold-fill { transform: scaleX(1); transition: transform .7s linear; }

/* hub game tiles: fixed three-band layout (animal zone / name / age) so
   baselines align across tiles regardless of each animal's aspect ratio */
.game-tile { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 18px 14px; overflow: hidden; }
.game-tile .animal-zone { flex: 1 1 0; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; padding: 8px 0 10px; }
.game-tile .animal-zone svg { width: 100%; height: 100%; }
.game-tile .game-name { font-weight: 800; font-size: clamp(16px, 2.6vw, 24px); color: var(--ink-deep); }
.game-tile .game-age { font-size: clamp(11px, 1.6vw, 15px); color: var(--slate-muted); }

/* short screens (phone landscape): shrink text bands so the animal keeps the room */
@media (max-height: 520px) {
  .game-tile { padding: 5px 12px 7px; gap: 0; }
  .game-tile .animal-zone { padding: 2px 0 3px; }
  .game-tile .game-name { font-size: 15px; }
  .game-tile .game-age { font-size: 10px; }
}

/* hub shelves: vertical list of skill rows; each row scrolls horizontally.
   Gameplay scenes keep touch-action:none — only the hub may pan. */
#hub-shelves { position: absolute; inset: 84px 0 0; overflow-y: auto; overflow-x: hidden; touch-action: pan-y; padding: 0 4vw 4vh; -webkit-overflow-scrolling: touch; }
.shelf { margin-bottom: 2.5vh; }
.shelf-label { display: inline-flex; align-items: center; gap: 10px; min-height: 56px; padding: 0 18px; border: none; border-radius: 16px; cursor: pointer; background: color-mix(in srgb, var(--abyss) 35%, transparent); color: var(--foam-white); font-family: inherit; font-weight: 800; font-size: clamp(16px, 2.4vw, 22px); text-shadow: 0 1px 3px rgba(0,30,60,.6); margin-bottom: 1.2vh; }
.shelf-label:focus-visible { outline: 4px solid var(--foam-white); outline-offset: 3px; }
.shelf-row { display: flex; gap: 2vw; overflow-x: auto; touch-action: pan-x pan-y; padding: 4px 2px 12px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.shelf-row::-webkit-scrollbar { display: none; }
.shelf-row .game-tile { flex: 0 0 clamp(220px, 26vw, 320px); height: clamp(180px, 30vh, 250px); }
@media (max-height: 520px) {
  .shelf-label { min-height: 44px; font-size: 15px; }
  .shelf-row .game-tile { flex-basis: 200px; height: 140px; }
}

/* trace-letters */
#letter-grid { position: absolute; inset: 84px 4vw 3vh; overflow-y: auto; touch-action: pan-y; display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 12px; align-content: start; padding: 4px; -webkit-overflow-scrolling: touch; }
.letter-cell { min-height: 90px; font-size: 44px; font-weight: 800; color: var(--slate-muted); }
.letter-cell[data-done] { color: var(--ink-deep); background: linear-gradient(180deg, var(--kelp-light), var(--kelp-green)); }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: .9; } 50% { transform: scale(1.3); opacity: 1; } }
.trace-start { animation: pulse 1.2s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }

/* spell-word: letter tiles dragged into ghosted slots */
.spell-slot { width: clamp(60px, 11vw, 82px); height: clamp(70px, 13vw, 92px); border-radius: 16px; border: 3px dashed color-mix(in srgb, var(--ink-deep) 35%, transparent); display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,.45); }
.spell-slot .ghost { font: 800 clamp(32px, 7vw, 54px) system-ui, sans-serif; color: var(--ink-deep); opacity: .18; }
.spell-slot.filled { border-style: solid; border-color: var(--coral); background: linear-gradient(180deg, var(--foam-white), var(--ice-mist)); }
.spell-slot.filled .ghost { opacity: 1; color: var(--coral); }
.spell-tile { width: clamp(60px, 11vw, 82px); height: clamp(70px, 13vw, 92px); min-width: 0; min-height: 0; padding: 0; font: 800 clamp(32px, 7vw, 54px) system-ui, sans-serif; color: var(--ink-deep); cursor: grab; }

/* memory-match: flip cards in a responsive grid */
#memory-grid { position: absolute; inset: 72px 4vw 3vh; display: grid; gap: 2vmin; align-content: center; justify-items: center; }
.mem-card { width: 100%; height: 100%; max-width: 150px; max-height: 150px; min-width: 80px; min-height: 80px; aspect-ratio: 1; border: none; background: none; padding: 0; cursor: pointer; perspective: 600px; }
.mem-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .35s ease; border-radius: 18px; }
.mem-card.up .mem-inner { transform: rotateY(180deg); }
.mem-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 18px; box-shadow: var(--shadow-soft-lift); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.mem-back { background: linear-gradient(180deg, var(--mid-water), var(--deep-water)); }
.mem-back .bub { position: absolute; border: 2px solid rgba(255,255,255,.4); border-radius: 50%; }
.mem-front { background: linear-gradient(180deg, var(--foam-white), var(--ice-mist)); transform: rotateY(180deg); }
.mem-front svg { width: 86%; height: 86%; }
/* bounce the whole card, not .mem-inner — boing's scale transform would
   override the inner's rotateY(180deg) and briefly show the card back */
.mem-card.matched { animation: boing .55s ease; }
.mem-card.matched .mem-front { box-shadow: 0 0 0 4px var(--teal-mem), var(--shadow-soft-lift); }
.mem-card:focus-visible { outline: 4px solid var(--foam-white); outline-offset: 3px; border-radius: 18px; }
@media (prefers-reduced-motion: reduce) {
  .mem-inner { transition: none; }
}

/* shared win celebration: starburst + hero star + happy jump */
.cele-burst { position: absolute; inset: 0; pointer-events: none; z-index: 30; }
.cele-star { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); animation: cele-fly 1.4s ease-out forwards; }
@keyframes cele-fly {
  0% { transform: translate(-50%, -50%) scale(.3) rotate(0deg); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1) rotate(160deg); opacity: 0; }
}
.cele-hero { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; pointer-events: none; z-index: 31; }
.cele-hero-star { width: clamp(90px, 18vw, 150px); aspect-ratio: 1; background: var(--sun-gold); clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); filter: drop-shadow(0 6px 16px rgba(0,20,40,.35)); animation: cele-pop 1.7s ease forwards; }
.cele-hero-label { font: 800 clamp(24px, 5vw, 46px) system-ui, sans-serif; color: var(--foam-white); text-shadow: 0 2px 8px rgba(0,30,60,.6); animation: cele-pop 1.7s ease forwards; }
@keyframes cele-pop {
  0% { transform: scale(0) rotate(-20deg); opacity: 0; }
  18% { transform: scale(1.2) rotate(8deg); opacity: 1; }
  30% { transform: scale(1) rotate(0deg); }
  82% { opacity: 1; }
  100% { transform: scale(1); opacity: 0; }
}
.cheer-jump { animation: cele-jump .5s ease 3 !important; }
@keyframes cele-jump { 0%, 100% { transform: translateY(0); } 35% { transform: translateY(-22px); } 62% { transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) {
  .cele-star { animation: none; opacity: .85; }
  .cele-hero-star, .cele-hero-label { animation: cele-fade 1.7s ease forwards; }
  .cheer-jump { animation: none !important; }
}
@keyframes cele-fade { 0% { opacity: 0; } 15%, 80% { opacity: 1; } 100% { opacity: 0; } }

/* top bar shared by all scenes */
.topbar { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; z-index: 10; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.topbar .title { font-size: clamp(18px, 3.5vw, 30px); font-weight: 800; color: var(--ink-deep); text-shadow: var(--text-halo); }
.topbar .controls { display: flex; gap: 10px; }

/* animal animations */
.animal { transform-origin: center; }
.animal.float { animation: float 3.2s ease-in-out infinite alternate; }
@keyframes float { from { transform: translateY(-8px) rotate(-1.5deg); } to { transform: translateY(8px) rotate(1.5deg); } }
.animal.boing { animation: boing .55s ease; }
@keyframes boing { 0% { transform: scale(1); } 35% { transform: scale(1.25, .8); } 65% { transform: scale(.85, 1.15); } 100% { transform: scale(1); } }
.animal.shake { animation: shake .5s ease; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-10px) rotate(-4deg); } 75% { transform: translateX(10px) rotate(4deg); } }
.animal .eye-blink { animation: blink 4s infinite; animation-delay: var(--blink-delay, 0s); transform-box: fill-box; transform-origin: center; }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.08); } }
.pop-in { animation: popin .45s cubic-bezier(.18,1.4,.4,1); }
@keyframes popin { from { transform: scale(0); } to { transform: scale(1); } }
.fade-out { animation: fadeout .8s ease forwards; }
@keyframes fadeout { to { opacity: 0; transform: scale(.6); } }

/* celebration confetti */
.confetti { position: absolute; width: 14px; height: 14px; border-radius: 3px; pointer-events: none; animation: confetti-fall 1.6s ease-in forwards; }
@keyframes confetti-fall { 0% { transform: translateY(-20px) rotate(0deg); opacity: 1; } 100% { transform: translateY(70vh) rotate(540deg); opacity: 0; } }

/* decorative bubbles */
/* duration is set per element in JS (e.g. style.animationDuration) */
.bubble { position: absolute; border: 2px solid rgba(255,255,255,.4); border-radius: 50%; pointer-events: none; animation: bubble-rise linear infinite; }
@keyframes bubble-rise { from { transform: translateY(0); opacity: .7; } to { transform: translateY(-110vh); opacity: 0; } }

/* motion sensitivity: settle every animation to its end state instantly */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
