/* Read with Glass — kid-first UI. Palette matches glasspals.com */
:root {
  --sky: #aee1f5; --sky-deep: #7ec8e3;
  --grass: #f3d27a; --grass-deep: #e8b84b;
  --green: #58a55c; --green-bright: #7bc47f;
  --berry: #d9486e; --lava: #e86a2e;
  --cream: #fff6e3; --paper: #fffdf6; --ink: #33291f;
  --shadow: 0 6px 0 rgba(51, 41, 31, .14);
  --tile: min(17vw, 96px);
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Fredoka', sans-serif; color: var(--ink);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  background: var(--sky);
}
button { font-family: inherit; color: inherit; border: none; background: none; cursor: pointer; }

#stage { position: fixed; inset: 0; overflow: hidden; }
#sky {
  position: absolute; inset: 0; z-index: 0;
  background:
    radial-gradient(circle at 82% 12%, #ffe9a3 0 7%, rgba(255, 233, 163, 0) 20%),
    linear-gradient(var(--sky) 0 55%, var(--sky-deep) 78%, var(--grass) 78.2%, var(--grass-deep) 100%);
}
.screen { position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column; align-items: center; }
.hidden { display: none !important; }

/* ---------- title ---------- */
#title { justify-content: center; gap: 4vh; text-align: center; }
.clouds span { position: absolute; font-size: 46px; opacity: .9; animation: drift 60s linear infinite; }
.clouds span:nth-child(1) { top: 8%; animation-duration: 74s; }
.clouds span:nth-child(2) { top: 16%; animation-delay: -30s; font-size: 34px; }
.clouds span:nth-child(3) { top: 4%; animation-delay: -55s; font-size: 60px; }
@keyframes drift { from { left: -12%; } to { left: 108%; } }
.logo { line-height: .95; font-weight: 700; transform: rotate(-2deg); }
.logo-read { display: block; font-size: clamp(52px, 14vw, 110px); color: var(--berry);
  text-shadow: 0 4px 0 rgba(51, 41, 31, .15); }
.logo-with { display: block; font-family: 'Patrick Hand', cursive; font-size: clamp(20px, 5vw, 34px); }
.logo-glass { display: block; font-size: clamp(52px, 14vw, 110px); color: var(--green);
  text-shadow: 0 4px 0 rgba(51, 41, 31, .15); }
#title-glass { width: clamp(110px, 26vw, 190px); image-rendering: auto; animation: bob 2.2s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-12px) rotate(2deg); } }
.big-btn {
  font-size: clamp(26px, 6vw, 40px); font-weight: 600; background: var(--berry); color: #fff;
  padding: .5em 1.4em; border-radius: 999px; box-shadow: var(--shadow);
  transition: transform .12s;
}
.big-btn:active { transform: scale(.94); }
#btn-grownups { position: absolute; bottom: max(10px, env(safe-area-inset-bottom)); right: 14px;
  font-size: 14px; opacity: .55; padding: 8px; }
#btn-lang-back { position: absolute; bottom: max(10px, env(safe-area-inset-bottom)); left: 14px;
  font-size: 20px; opacity: .55; padding: 8px; }

/* ---------- language select ---------- */
#lang { justify-content: center; gap: 4vh; text-align: center; }
#lang-glass { width: clamp(110px, 26vw, 190px); animation: bob 2.2s ease-in-out infinite; }
#lang-buttons { display: flex; flex-direction: column; gap: 2.4vh; }
#btn-lang-es { background: var(--green); }

/* ---------- map ---------- */
#map-head, #play-head {
  width: min(100%, 640px); display: flex; align-items: center; justify-content: space-between;
  padding: calc(6px + env(safe-area-inset-top)) 14px 6px; font-size: 22px; z-index: 5;
}
#map-title { font-weight: 600; color: var(--ink); opacity: .75; font-size: 18px; }
#star-count { background: var(--paper); border-radius: 999px; padding: 4px 12px; box-shadow: var(--shadow); font-size: 17px; }
#btn-home { text-decoration: none; font-size: 24px; }
#map-scroll { flex: 1; width: 100%; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
#map-path { position: relative; width: min(94vw, 520px); margin: 0 auto; padding: 10px 0 40px; }
#map-path::before {
  content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 0;
  border-left: 5px dashed rgba(51, 41, 31, .18);
}
.group-banner {
  position: relative; z-index: 1; margin: 34px auto 14px; width: fit-content; max-width: 88%;
  background: var(--green); color: #fff; font-weight: 600; font-size: 20px;
  padding: 8px 22px; border-radius: 999px; box-shadow: var(--shadow); text-align: center;
}
.group-banner .letters { font-family: 'Patrick Hand', cursive; opacity: .92; margin-left: 8px; }
.node-row { position: relative; display: flex; margin: 10px 0; z-index: 1; }
.node-row.left { justify-content: flex-start; padding-left: 17%; }
.node-row.right { justify-content: flex-end; padding-right: 17%; }
.node {
  width: 92px; height: 92px; border-radius: 50%;
  background: var(--paper); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 34px; position: relative; transition: transform .12s;
}
.node small { font-size: 12px; font-weight: 600; color: var(--ink); opacity: .7; margin-top: -2px; }
.node .stars { font-size: 13px; letter-spacing: -2px; position: absolute; bottom: 8px; }
.node.locked { filter: grayscale(.8); opacity: .6; }
.node.story-node { background: var(--cream); outline: 4px solid var(--berry); outline-offset: -4px; }
.node:not(.locked):active { transform: scale(.92); }
.node .here {
  position: absolute; top: -40px; left: 50%; transform: translateX(-50%); width: 52px;
  animation: bob 1.6s ease-in-out infinite; pointer-events: none; z-index: 2;
}

/* ---------- play ---------- */
#play-head button { font-size: 26px; background: var(--paper); border-radius: 50%;
  width: 52px; height: 52px; box-shadow: var(--shadow); }
#round-dots { display: flex; gap: 8px; }
#round-dots span { width: 14px; height: 14px; border-radius: 50%; background: rgba(51, 41, 31, .18); }
#round-dots span.done { background: var(--green-bright); }
#round-dots span.now { background: var(--berry); transform: scale(1.25); }
#play-area { flex: 1; width: 100%; max-width: 640px; position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center; }
#play-glass {
  position: absolute; bottom: max(8px, env(safe-area-inset-bottom));
  left: max(10px, calc(50% - min(50vw, 320px) + 10px));
  width: clamp(74px, 17vw, 120px); z-index: 3; pointer-events: none;
  transition: transform .25s;
}
#tongue { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 4; pointer-events: none; }
#tongue path { stroke: #e86a8e; stroke-width: 2.2; stroke-linecap: round; }

.prompt {
  margin-top: 2vh; background: var(--paper); border-radius: 22px; box-shadow: var(--shadow);
  padding: 12px 22px; font-size: clamp(19px, 4.5vw, 26px); font-weight: 500; text-align: center;
  max-width: 88%;
}
.prompt .big-letter { font-family: 'Patrick Hand', cursive; font-size: 1.9em; color: var(--berry); }

/* floating letter bugs */
#bug-field { position: relative; flex: 1; width: 100%; }
.bug {
  position: absolute; width: var(--tile); height: var(--tile);
  transform: translate(-50%, -50%);
  animation: floaty ease-in-out infinite alternate;
}
@keyframes floaty { from { margin-top: -14px; } to { margin-top: 14px; } }
.bug .body {
  width: 100%; height: 100%; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Patrick Hand', cursive; font-size: calc(var(--tile) * .58);
  background: var(--paper); box-shadow: var(--shadow), inset 0 -6px 0 rgba(51, 41, 31, .06);
  border: 4px solid var(--c, var(--green-bright)); color: var(--ink);
  position: relative; transition: transform .12s;
}
.bug .body::before, .bug .body::after {
  content: ""; position: absolute; top: -12px; width: 34%; height: 40%;
  background: rgba(255, 255, 255, .8); border: 3px solid rgba(51, 41, 31, .14);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
}
.bug .body::before { left: 2%; transform: rotate(-24deg); }
.bug .body::after { right: 2%; transform: rotate(24deg); }
.bug.pic .body { font-family: inherit; font-size: calc(var(--tile) * .5); }
.bug:active .body { transform: scale(.9); }
.bug.wrong { animation: wobble .5s; }
@keyframes wobble { 25% { transform: translate(-50%, -50%) rotate(-8deg); } 75% { transform: translate(-50%, -50%) rotate(8deg); } }
.bug.hint .body { animation: hintPulse .8s ease-in-out infinite; border-color: var(--berry); }
@keyframes hintPulse { 50% { transform: scale(1.14); box-shadow: 0 0 0 10px rgba(217, 72, 110, .25); } }
.bug.zapped { pointer-events: none; }

/* leaves (sight words) */
.leaf-row { display: flex; flex-wrap: wrap; gap: 18px; justify-content: center; align-items: center; flex: 1; }
.leaf {
  background: var(--green-bright); color: #fff; border-radius: 12px 60% 12px 60%;
  padding: 20px 30px; font-family: 'Patrick Hand', cursive; font-size: clamp(30px, 8vw, 46px);
  box-shadow: var(--shadow); transition: transform .12s; border: none;
}
.leaf:active { transform: scale(.92) rotate(-3deg); }
.leaf.wrong { animation: wobble .5s; }
.leaf.hint { animation: hintPulse .8s ease-in-out infinite; }

/* letter party cards */
.party-grid { display: flex; flex-wrap: wrap; gap: 20px; justify-content: center; align-content: center; flex: 1; padding: 10px; }
.party-card {
  width: clamp(120px, 26vw, 170px); aspect-ratio: 3/4; background: var(--paper);
  border-radius: 26px; box-shadow: var(--shadow); border: 4px solid var(--grass-deep);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-family: 'Patrick Hand', cursive; transition: transform .15s;
}
.party-card .glyph { font-size: clamp(56px, 13vw, 88px); line-height: 1; color: var(--ink); }
.party-card .ex { font-size: 30px; opacity: 0; transition: opacity .3s; }
.party-card .exword { font-family: 'Fredoka', sans-serif; font-size: 15px; font-weight: 600; opacity: 0; transition: opacity .3s; }
.party-card.met { border-color: var(--green); }
.party-card.met .ex, .party-card.met .exword { opacity: 1; }
.party-card:active { transform: scale(.93); }
.party-card.pop { animation: cardPop .45s; }
@keyframes cardPop { 40% { transform: scale(1.12) rotate(2deg); } }

/* word builder */
.build-wrap { flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3.5vh; width: 100%; padding-bottom: 12vh; }
.slots, .tiles { display: flex; gap: 12px; justify-content: center; }
.slot {
  width: var(--tile); height: calc(var(--tile) * 1.12); border-radius: 18px;
  background: rgba(255, 253, 246, .55); border: 4px dashed rgba(51, 41, 31, .25);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Patrick Hand', cursive; font-size: calc(var(--tile) * .66);
}
.slot.filled { background: var(--paper); border-style: solid; border-color: var(--green); animation: cardPop .35s; }
.tile {
  width: var(--tile); height: calc(var(--tile) * 1.12); border-radius: 18px;
  background: var(--paper); box-shadow: var(--shadow); border: 4px solid var(--grass-deep);
  font-family: 'Patrick Hand', cursive; font-size: calc(var(--tile) * .66); color: var(--ink);
  transition: transform .12s, opacity .3s;
}
.tile:active { transform: scale(.9); }
.tile.used { opacity: 0; pointer-events: none; }
.tile.wrong { animation: wobble .4s; }
.build-reveal { min-height: 16vh; display: flex; align-items: center; justify-content: center; font-size: clamp(70px, 22vw, 140px); }
.build-reveal .word-said { font-family: 'Patrick Hand', cursive; font-size: clamp(44px, 12vw, 80px); color: var(--berry); }

/* read mode */
.word-card {
  background: var(--paper); border-radius: 26px; box-shadow: var(--shadow);
  padding: 14px 34px; margin-top: 2vh;
  font-family: 'Patrick Hand', cursive; font-size: clamp(54px, 15vw, 96px); line-height: 1.1;
  display: flex; gap: 2px;
}
.word-card span { transition: color .2s, transform .2s; }
.word-card span.lit { color: var(--berry); transform: translateY(-6px); }

/* story mode */
#story-scene {
  width: min(94vw, 620px); height: 42vh; margin-top: 1vh; position: relative; overflow: hidden;
  border-radius: 26px; box-shadow: var(--shadow); border: 6px solid var(--paper);
  background: linear-gradient(var(--sky) 60%, var(--grass) 60%);
}
#story-scene.bg-sand { background: linear-gradient(#8fd3f0 55%, #f7e3b0 55%); }
#story-scene.bg-dig { background: linear-gradient(#8fd3f0 50%, #e8c98b 50%); }
#story-scene.bg-sunny { background: linear-gradient(#ffdf80 0%, #97d5ef 45%, #f3d27a 75%); }
#story-scene.bg-meadow { background: linear-gradient(#8fd3f0 55%, #9fd98a 55%); }
#story-scene.bg-party { background: linear-gradient(#c9b6f2 55%, #f3d27a 55%); }
.actor { position: absolute; font-size: 54px; transform: translate(-50%, -50%); will-change: transform; }
.actor img { width: 90px; display: block; }
#story-bar {
  width: min(94vw, 620px); margin-top: 12px; background: var(--paper); border-radius: 22px;
  box-shadow: var(--shadow); padding: 14px; display: flex; flex-wrap: wrap; gap: 10px;
  justify-content: center; min-height: 92px; align-items: center;
}
.word-chip {
  font-family: 'Patrick Hand', cursive; font-size: clamp(24px, 6.4vw, 40px);
  background: var(--cream); padding: 4px 14px; border-radius: 14px;
  border: 3px solid rgba(51, 41, 31, .12); color: var(--ink); transition: all .15s;
}
.word-chip.next { border-color: var(--berry); animation: hintPulse 1.1s infinite; }
.word-chip.said { background: var(--green-bright); color: #fff; border-color: var(--green); }
.word-chip.namechip { padding-left: 6px; }
.word-chip img { height: .95em; vertical-align: -12%; margin-right: 4px; }
#story-next {
  margin-top: 10px; font-size: 30px; background: var(--berry); color: #fff;
  border-radius: 999px; padding: 6px 40px; box-shadow: var(--shadow);
}
.story-title { font-family: 'Patrick Hand', cursive; font-size: clamp(34px, 9vw, 54px); margin-top: 4vh; }

/* celebration */
.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(51, 41, 31, .35);
  display: flex; align-items: center; justify-content: center; }
#celebrate-card {
  background: var(--paper); border-radius: 34px; box-shadow: var(--shadow);
  padding: 34px 44px; text-align: center; animation: cardIn .45s cubic-bezier(.2, 1.6, .4, 1);
}
@keyframes cardIn { from { transform: scale(.4); opacity: 0; } }
#celebrate-stars span { font-size: clamp(44px, 12vw, 70px); display: inline-block; opacity: .18; transform: scale(.7); }
#celebrate-stars span.on { opacity: 1; transform: scale(1); animation: starIn .5s cubic-bezier(.2, 1.8, .4, 1); }
@keyframes starIn { from { transform: scale(0) rotate(-120deg); } }
#celebrate-glass { width: 110px; margin: 8px 0; animation: dance .5s ease-in-out infinite alternate; }
@keyframes dance { from { transform: rotate(-8deg) translateY(0); } to { transform: rotate(8deg) translateY(-8px); } }
#celebrate-msg { font-size: 26px; font-weight: 600; }

/* grown-ups */
#grownups .panel {
  background: var(--paper); border-radius: 26px; max-width: min(92vw, 520px);
  padding: 28px; box-shadow: var(--shadow); font-size: 16px; line-height: 1.5;
}
#grownups h2 { margin-bottom: 10px; }
#grownups p { margin-bottom: 10px; }
#grownups a { color: var(--berry); }
#grownups .row { display: flex; gap: 12px; justify-content: flex-end; margin-top: 14px; }
#grownups button { padding: 10px 18px; border-radius: 999px; font-size: 15px; font-weight: 600;
  background: var(--cream); box-shadow: var(--shadow); }
#grownups button.primary { background: var(--green); color: #fff; }

/* confetti + fx */
.confetti { position: fixed; top: -20px; width: 12px; height: 12px; z-index: 60; pointer-events: none;
  animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
.float-emoji { position: fixed; z-index: 55; pointer-events: none; font-size: 34px; animation: floatUp 1.4s ease-out forwards; }
@keyframes floatUp { to { transform: translateY(-120px) scale(1.6); opacity: 0; } }

/* short screens (landscape phones): title lays out as a row, story compacts */
@media (max-height: 520px) {
  :root { --tile: min(17vw, 19vh); }
  #title, #lang { flex-direction: row; flex-wrap: wrap; column-gap: 5vw; row-gap: 2vh; }
  .party-grid { gap: 12px; }
  .party-card { width: clamp(84px, 28vh, 120px); border-radius: 18px; }
  .party-card .glyph { font-size: clamp(36px, 15vh, 60px); }
  .party-card .ex { font-size: 22px; }
  .party-card .exword { font-size: 12px; }
  .build-wrap { gap: 2vh; padding-bottom: 2vh; }
  .build-reveal { min-height: 10vh; font-size: clamp(50px, 16vh, 90px); }
  .logo-read, .logo-glass { font-size: clamp(44px, 16vh, 84px); }
  .logo-with { font-size: clamp(16px, 6vh, 26px); }
  #title-glass, #lang-glass { width: clamp(90px, 30vh, 150px); }
  .big-btn { font-size: clamp(22px, 8vh, 32px); }
  .prompt { margin-top: 1vh; padding: 8px 18px; font-size: clamp(16px, 6vh, 22px); }
  .story-title { font-size: clamp(22px, 7vh, 34px); margin-top: 1vh; }
  #story-scene { height: 32vh; margin-top: 0; }
  #story-bar { min-height: 60px; padding: 8px 10px; margin-top: 8px; }
  .word-chip { font-size: clamp(20px, 7vh, 30px); }
  #story-next { font-size: 24px; margin-top: 6px; padding: 4px 32px; }
}

@media (prefers-reduced-motion: reduce) {
  .bug, #title-glass, .clouds span, #celebrate-glass { animation: none !important; }
}

/* iOS audio diagnostic line in the grown-ups panel (hidden on other platforms). */
.diag {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  opacity: .65;
  word-break: break-word;
}

/* "You finished everything" banner + restart, shown on a fully-beaten map. */
#all-done {
  margin: 10px 12px 0;
  padding: 12px 14px;
  border-radius: 16px;
  background: #fff8e6;
  border: 2px solid #e8b84b;
  text-align: center;
}
#all-done-msg { margin: 0; font-weight: 800; font-size: 17px; }
#all-done-sub { margin: 2px 0 10px; font-size: 13px; opacity: .75; }
#btn-start-over { font-size: 16px; padding: 10px 18px; }
#btn-start-over.confirm { background: #e5484d; color: #fff; }
