:root {
  --bg: #fff4e0;
  --bg-2: #ffe9c7;
  --text: #3d3326;
  --muted: #8a7a63;
  --blue: #3b6fd8;
  --green: #2fb36b;
  --orange: #ffb938;
  --coral: #ef6a4c;
  --card: #ffffff;
  --shadow: #e3cfa9;
  --ui: 'Fredoka', 'Nunito', system-ui, sans-serif;
  --word: 'Andika', 'Fredoka', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: radial-gradient(circle at 20% 10%, #fffaf0 0, var(--bg) 45%, var(--bg-2) 100%);
  color: var(--text);
  font-family: var(--ui);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.screen {
  height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
}
.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
}

h1 { font-size: clamp(40px, 8vw, 72px); margin: 0; font-weight: 700; letter-spacing: 0.5px; }
.sub { font-size: clamp(18px, 3vw, 26px); color: var(--muted); margin: 0 0 12px; }

/* ---------- inicio ---------- */
.logo { display: flex; gap: 10px; }
.logo span {
  font-family: var(--word);
  font-weight: 700;
  font-size: 56px;
  width: 84px; height: 84px;
  display: grid; place-items: center;
  border-radius: 24px;
  color: #fff;
  box-shadow: 0 6px 0 rgba(0,0,0,.12);
  animation: bob 2.4s ease-in-out infinite;
}
.logo span:nth-child(1) { background: var(--coral); }
.logo span:nth-child(2) { background: var(--blue); animation-delay: .2s; }
.logo span:nth-child(3) { background: var(--green); animation-delay: .4s; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-3deg); } }

.big-play {
  width: 160px; height: 160px;
  border-radius: 50%;
  border: 0;
  background: var(--orange);
  color: #fff;
  font-size: 72px;
  padding-left: 14px;
  box-shadow: 0 10px 0 #d9952a;
  cursor: pointer;
  animation: pulse 1.8s ease-in-out infinite;
}
.big-play:active { transform: translateY(8px); box-shadow: 0 2px 0 #d9952a; animation: none; }
@keyframes pulse { 50% { transform: scale(1.06); } }

/* ---------- juego ---------- */
#game {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.progress { display: flex; gap: 8px; flex-wrap: wrap; }
.pip {
  border: 0;
  padding: 0;
  font-family: var(--ui);
  cursor: pointer;
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: 20px;
  background: var(--card);
  color: var(--muted);
  box-shadow: 0 3px 0 var(--shadow);
}
.pip.now { background: var(--orange); color: #fff; box-shadow: 0 3px 0 #d9952a; transform: scale(1.12); }
.pip.done { background: var(--green); color: #fff; box-shadow: 0 3px 0 #23874f; }
.pip.star-pip { background: #ffd23f; color: #fff; box-shadow: 0 3px 0 #d4a514; font-size: 22px; width: auto; min-width: 44px; padding: 0 10px; border-radius: 22px; }
.pip.star-pip.now { font-size: 16px; }
.pip:active { transform: translateY(2px); }

.step {
  display: flex; align-items: center; gap: 10px;
  background: var(--card);
  padding: 8px 20px;
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--shadow);
  font-size: clamp(18px, 2.6vw, 26px);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#step-icon { font-size: 1.3em; }

.round {
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 0;
  font-size: 30px;
  cursor: pointer;
  flex: none;
}
.listen { background: var(--blue); box-shadow: 0 5px 0 #2a52a6; }
.listen:active { transform: translateY(4px); box-shadow: 0 1px 0 #2a52a6; }

/* Palabra modelo */
.model {
  font-family: var(--word);
  font-size: clamp(56px, 11vw, 120px);
  line-height: 1.15;
  text-align: center;
  font-weight: 400;
  letter-spacing: 0.06em;
  min-height: 1.3em;
  transition: opacity .3s;
}
.model.hidden { visibility: hidden; height: 0; min-height: 0; }
.model .unit {
  display: inline-block;
  position: relative;
  margin: 0 0.1em;
  padding-bottom: 0.18em;
  letter-spacing: 0;
  transition: transform .15s, color .15s;
}
/* Sound buttons de phonics: punto = un sonido de una letra, raya = varias letras, un sonido */
.model .unit::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  background: var(--muted);
  opacity: .55;
  border-radius: 999px;
  height: 0.09em;
  width: 0.09em;
}
.model .unit.multi::after { width: 80%; }
.model .unit.lit { color: var(--coral); transform: translateY(-10px) scale(1.2); }
.model .unit.lit::after { background: var(--coral); opacity: 1; }
#game[data-step="escucha"] .model {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(80px, 18vw, 200px);
}
#game[data-step="copia"] .model { font-size: clamp(40px, 7vw, 76px); }

.board-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}
#board {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* Botones de abajo */
.actions {
  display: flex;
  justify-content: center;
  gap: 16px;
  min-height: 76px;
}
.btn {
  border: 0;
  border-radius: 999px;
  padding: 0 34px;
  height: 72px;
  font-family: var(--ui);
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 700;
  color: #fff;
  cursor: pointer;
}
.btn.soft { background: var(--card); color: var(--muted); box-shadow: 0 6px 0 var(--shadow); }
.btn.go { background: var(--green); box-shadow: 0 6px 0 #23874f; }
.btn.next { background: var(--orange); box-shadow: 0 6px 0 #d9952a; }
.btn:active { transform: translateY(5px); box-shadow: 0 1px 0 rgba(0,0,0,.15); }

/* "¡Bien!" que salta */
.cheer {
  position: fixed;
  left: 50%; top: 42%;
  transform: translate(-50%, -50%) scale(0);
  font-size: clamp(60px, 12vw, 120px);
  font-weight: 700;
  color: var(--green);
  text-shadow: 0 6px 0 rgba(0,0,0,.08);
  pointer-events: none;
  opacity: 0;
}
.cheer.pop { animation: pop 1.2s ease-out; }
@keyframes pop {
  0% { transform: translate(-50%, -50%) scale(.2) rotate(-10deg); opacity: 0; }
  25% { transform: translate(-50%, -50%) scale(1.15) rotate(4deg); opacity: 1; }
  70% { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
  100% { transform: translate(-50%, -70%) scale(1); opacity: 0; }
}

/* Nombre del niño arriba a la izquierda: tocarlo vuelve al inicio */
.kid-chip {
  border: 0;
  height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font-family: var(--ui);
  font-size: 18px;
  font-weight: 600;
  box-shadow: 0 3px 0 var(--shadow);
  cursor: pointer;
  white-space: nowrap;
  flex: none;
}
.kid-chip:active { transform: translateY(2px); }

/* Palabra conseguida (con confeti) */
.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 50; }
.win {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: rgba(255, 244, 224, .75);
  pointer-events: none;
}
.win-card {
  background: var(--card);
  border-radius: 36px;
  padding: 24px 56px 28px;
  text-align: center;
  box-shadow: 0 10px 0 var(--shadow);
}
.win.show .win-card { animation: winpop .6s cubic-bezier(.2, 1.6, .4, 1) both; }
.win-stars { font-size: clamp(32px, 6vw, 52px); letter-spacing: 6px; }
.win.show .win-stars { animation: bob 1.2s ease-in-out infinite; }
.win-word { font-family: var(--word); font-size: clamp(80px, 16vw, 170px); line-height: 1.1; color: var(--green); }
.win-text { font-size: clamp(28px, 5vw, 44px); font-weight: 700; color: var(--orange); }
@keyframes winpop { 0% { transform: scale(.3) rotate(-8deg); opacity: 0; } 100% { transform: scale(1) rotate(0); opacity: 1; } }

/* Caja sorpresa */
.gift {
  position: fixed; inset: 0; z-index: 45;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(circle, #fffaf0 0, rgba(255, 233, 199, .97) 70%);
  touch-action: manipulation;
  cursor: pointer;
}
.gift-hint { margin: 0; font-size: clamp(30px, 5vw, 46px); font-weight: 700; color: var(--blue); animation: bob 1.6s ease-in-out infinite; }
.gift-box {
  --grow: 1;
  border: 0; background: none; cursor: pointer; padding: 0;
  font-size: clamp(130px, 24vw, 210px); line-height: 1;
  margin: 50px 0; /* aire para que al crecer no tape el texto ni los puntos */
  transform: scale(var(--grow));
  transition: transform .15s;
  filter: drop-shadow(0 12px 0 rgba(0, 0, 0, .1));
}
.gift-box.shake { animation: giftshake .35s ease-in-out; }
.gift-box.burst { animation: giftburst .4s ease-in forwards; }
@keyframes giftshake {
  0%, 100% { transform: scale(var(--grow)) rotate(0); }
  20% { transform: scale(calc(var(--grow) * 1.08)) rotate(-12deg); }
  45% { transform: scale(calc(var(--grow) * .96)) rotate(10deg); }
  70% { transform: scale(calc(var(--grow) * 1.04)) rotate(-6deg); }
}
@keyframes giftburst { to { transform: scale(2.2) rotate(15deg); opacity: 0; } }
.gift-dots { display: flex; gap: 10px; }
.gift-dots span { width: 18px; height: 18px; border-radius: 50%; background: #e8dcc6; transition: background .15s, transform .15s; }
.gift-dots span.on { background: var(--orange); transform: scale(1.2); }
.gift-toy { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.gift-toy[hidden] { display: none; }
.gift-glow {
  position: absolute; width: min(80vw, 520px); aspect-ratio: 1; border-radius: 50%;
  background: repeating-conic-gradient(rgba(255, 210, 63, .35) 0 10deg, transparent 10deg 20deg);
  animation: spin 8s linear infinite; z-index: -1;
}
@keyframes spin { to { transform: rotate(360deg); } }
.gift-emoji { font-size: clamp(150px, 30vw, 240px); line-height: 1.1; animation: toyin .7s cubic-bezier(.2, 1.6, .4, 1) both, bob 2s ease-in-out .7s infinite; }
@keyframes toyin { 0% { transform: translateY(80px) scale(.2) rotate(-30deg); opacity: 0; } 100% { transform: none; opacity: 1; } }
.gift-name { font-size: clamp(34px, 6vw, 56px); font-weight: 700; color: var(--green); }
.gift-go { margin-top: 10px; }

/* ---------- final ---------- */
.end-actions { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.end-rank { width: 100%; max-width: 640px; }
.stars { display: flex; gap: 12px; font-size: clamp(70px, 14vw, 120px); }
.stars span { color: #e8dcc6; }
.stars span.on { color: #ffd23f; text-shadow: 0 6px 0 #d4a514; animation: bob 1.6s ease-in-out infinite; }
.stars span.on:nth-child(2) { animation-delay: .2s; }
.stars span.on:nth-child(3) { animation-delay: .4s; }

@media (max-width: 640px) {
  .step #step-text { display: none; }
  .btn { padding: 0 22px; height: 64px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

#end { overflow-y: auto; justify-content: safe center; }
