:root {
  --ink: #31304d;
  --cream: #fff8e9;
  --paper: #fffdf8;
  --purple: #7b69d5;
  --blue: #5ab9ea;
  --green: #55c992;
  --shadow: 0 10px 0 rgba(74, 59, 90, 0.12), 0 18px 34px rgba(74, 59, 90, 0.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: ui-rounded, "Arial Rounded MT Bold", "Avenir Next", Arial, sans-serif;
  background:
    radial-gradient(circle at 12% 8%, rgba(122, 105, 213, .28) 0 4%, transparent 4.2%),
    linear-gradient(180deg, #d9f0ff 0 28%, var(--cream) 28% 100%);
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible, a:focus-visible { outline: 5px solid #3d8dde; outline-offset: 3px; }

.sky {
  position: fixed;
  inset: 3vh 4vw auto;
  display: flex;
  justify-content: space-between;
  font-size: clamp(2rem, 7vw, 4rem);
  opacity: .78;
  pointer-events: none;
}

.app { width: min(100%, 760px); min-height: 100vh; margin: auto; padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); position: relative; }

/* Locked viewport only while a game round is active (menu stays scrollable). */
body.game-active {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
body.game-active .app {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.game-active .topbar { flex: 0 0 58px; }
body.game-active #gameScreen.active {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  /* round-top / prompt / flexible play-area / speech card (rule: play area gets 1fr) */
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}
body.game-active #gameScreen .round-top { grid-row: 1; }
body.game-active #gameScreen .prompt { grid-row: 2; }
body.game-active #gameScreen .play-area { grid-row: 3; }
body.game-active #gameScreen .speech-card { grid-row: 4; }

.topbar { height: 58px; display: grid; grid-template-columns: 50px 1fr 50px; align-items: center; gap: 8px; position: relative; z-index: 2; }
.brand { justify-self: center; display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: rgba(255,255,255,.8); border-radius: 999px; font-size: clamp(.83rem, 3.4vw, 1rem); font-weight: 900; box-shadow: 0 4px 14px rgba(62,81,110,.1); }
.brand-icon { font-size: 1.35rem; }
.icon-button { width: 48px; height: 48px; border: 0; border-radius: 50%; background: white; box-shadow: 0 5px 0 rgba(66,67,98,.13); font-size: 1.5rem; }
.hidden { display: none !important; }

.screen { display: none; }
.screen.active { display: block; animation: arrive .3s ease-out; }
@keyframes arrive { from { opacity: 0; transform: translateY(10px) scale(.99); } }

.hero { text-align: center; padding: 3vh 0 18px; }
.hero-friends { display: flex; justify-content: center; align-items: flex-end; gap: 8px; font-size: clamp(3.2rem, 15vw, 6.5rem); filter: drop-shadow(0 7px 3px rgba(78,65,81,.15)); }
.hero-friends span:nth-child(2) { font-size: 1.18em; transform: translateY(-5px); }
.hero h1 { margin: 8px 0 4px; font-size: clamp(1.9rem, 8vw, 3.6rem); line-height: .98; color: #5f50ad; text-shadow: 0 3px white; }
.hero h1 span { color: #ef6c68; }
.hero p { margin: 10px 0 0; font-size: clamp(.95rem, 3.8vw, 1.25rem); font-weight: 800; }

.sets-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.set-card { min-height: 150px; padding: 16px 8px; border: 5px solid white; border-radius: 30px; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; transition: transform .12s; }
.set-card:active { transform: translateY(5px); box-shadow: 0 5px 0 rgba(74,59,90,.12); }
.set-card:nth-child(5n+1) { background: linear-gradient(145deg, #b9f0c8, #74d8a5); }
.set-card:nth-child(5n+2) { background: linear-gradient(145deg, #ffe078, #ffb65d); }
.set-card:nth-child(5n+3) { background: linear-gradient(145deg, #a3e8dd, #67cbe8); }
.set-card:nth-child(5n+4) { background: linear-gradient(145deg, #d7c7ff, #9f8bea); }
.set-card:nth-child(5n+5) { background: linear-gradient(145deg, #ffc3d8, #ff8fb1); }
.set-emojis { font-size: clamp(2rem, 9vw, 3.4rem); letter-spacing: 2px; }
.set-card strong { font-size: clamp(1.25rem, 5.2vw, 1.8rem); }
.set-sub { font-size: clamp(.82rem, 3.2vw, 1rem); font-weight: 800; color: #54506e; }

.activities-link { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; align-items: center; column-gap: 12px; margin: 20px auto 0; max-width: 430px; padding: 13px 16px; border: 5px solid white; border-radius: 26px; background: linear-gradient(145deg, #fff1b8, #ffd45a); box-shadow: var(--shadow); color: inherit; text-decoration: none; }
.activities-link > span:first-child { grid-row: 1 / span 2; font-size: 2rem; }
.activities-link strong { font-size: 1.1rem; }
.activities-sub { grid-column: 2; font-size: .78rem; font-weight: 800; color: #6b6486; }

.grownup-link { display: block; margin: 14px auto 0; border: 0; background: rgba(255,255,255,.75); border-radius: 999px; padding: 10px 18px; font-weight: 800; }

.round-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin: 10px 0 4px; }
.mode-switch { display: flex; gap: 6px; min-width: 0; }
.mode-pill { border: 0; border-radius: 999px; padding: 9px 13px; font-weight: 900; background: rgba(255,255,255,.6); box-shadow: 0 4px 0 rgba(66,67,98,.1); font-size: clamp(.8rem, 3.3vw, .95rem); }
.mode-pill.active { background: var(--purple); color: white; box-shadow: 0 4px 0 #55459c; }
.pill-button { margin-left: auto; border: 0; border-radius: 999px; background: white; padding: 10px 14px; font-weight: 900; box-shadow: 0 4px 0 rgba(66,67,98,.12); font-size: clamp(.8rem, 3.3vw, .95rem); white-space: nowrap; }
.pill-button:active, .mode-pill:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(66,67,98,.12); }

.prompt { text-align: center; font-weight: 900; margin: 4px 0 6px; display: grid; justify-items: center; min-width: 0; overflow: hidden; }
.prompt-q { font-size: clamp(1.1rem, 4.6vw, 1.6rem); line-height: 1.15; }
.prompt-sub { color: #6555ad; font-size: clamp(.78rem, 3vw, .95rem); font-weight: 800; margin-top: 2px; }
.replay-button { margin-top: 6px; border: 4px solid white; border-radius: 999px; background: linear-gradient(145deg, #ffe078, #ffb65d); padding: 7px 16px; font-weight: 1000; font-size: clamp(.95rem, 4vw, 1.15rem); box-shadow: 0 5px 0 rgba(196,124,44,.32); }
.replay-button:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(196,124,44,.32); }

.play-area { min-width: 0; min-height: 0; display: grid; place-items: center; border: 5px solid white; border-radius: 34px; background: rgba(255,253,248,.92); box-shadow: var(--shadow); overflow: hidden; position: relative; container-type: size; }

.find-board { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: min(3cqw, 14px); width: 100%; height: 100%; padding: min(5cqw, 22px); }
.find-choice { min-width: 0; min-height: 0; border: 5px solid white; border-radius: 24px; background: linear-gradient(145deg, #e8f6ff, #c9e7ff); box-shadow: 0 6px 0 rgba(64,132,171,.25); display: grid; place-items: center; padding: 6px; font-size: clamp(2rem, min(30cqh, 21cqw), 6.2rem); line-height: 1; filter: drop-shadow(0 5px 2px rgba(77,65,81,.14)); animation: choiceIn .4s backwards cubic-bezier(.2,1.4,.4,1); }
.find-choice:nth-child(2) { animation-delay: 60ms; }
.find-choice:nth-child(3) { animation-delay: 120ms; }
.find-choice:active { transform: scale(.92); }
@keyframes choiceIn { from { transform: translateY(-18px) scale(.4) rotate(-10deg); opacity: 0; } }

.explore-board { display: grid; gap: 2.5cqh; width: 100%; height: 100%; padding: 4cqw; grid-template-rows: repeat(var(--erows, 5), minmax(0, 1fr)); grid-auto-flow: column; grid-template-columns: repeat(var(--ecols, 1), minmax(0, 1fr)); place-items: stretch; }
.explore-tile { min-width: 0; min-height: 0; border: 5px solid white; border-radius: 20px; background: linear-gradient(145deg, #fff3c8, #ffd97e); box-shadow: 0 5px 0 rgba(196,124,44,.25); display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: 1fr auto; align-items: center; column-gap: 2cqw; padding: 0 4cqw; text-align: left; }
.explore-tile:active { transform: scale(.96); box-shadow: 0 2px 0 rgba(196,124,44,.25); }
.tile-emoji { font-size: min(13cqh, 11cqw); line-height: 1; }
.tile-es { font-size: min(6.2cqh, 5.6cqw); font-weight: 1000; color: #4c3f92; justify-self: start; }
.tile-sub { grid-column: 2; font-size: min(3.6cqh, 3.4cqw); font-weight: 800; color: #756d89; justify-self: start; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

.speech-card { text-align: center; background: rgba(255,255,255,.78); border-radius: 22px; padding: 6px 10px 9px; margin-top: 8px; }
.speech-status { min-height: 17px; margin: 2px 0 1px; color: #756d89; font-size: .78rem; font-weight: 800; }

.celebration { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; overflow: hidden; background: radial-gradient(circle, rgba(255,246,173,.38), rgba(91,65,139,.28)); backdrop-filter: blur(3px); }
.celebration::before { content: ""; position: absolute; width: 135vmax; height: 135vmax; background: repeating-conic-gradient(from 0deg, rgba(255,255,255,.34) 0 8deg, transparent 8deg 20deg); animation: happyRays 3.5s linear infinite; }
.confetti { position: absolute; z-index: 2; left: 0; right: 0; text-align: center; font-size: clamp(2rem, 9vw, 5rem); word-spacing: 5vw; }
.confetti-back { top: 7%; animation: confettiRain .7s infinite alternate cubic-bezier(.2,1.5,.4,1); }
.confetti-front { bottom: 5%; animation: confettiRain .55s .12s infinite alternate-reverse cubic-bezier(.2,1.5,.4,1); }
@keyframes confettiRain { to { transform: translateY(28px) rotate(5deg) scale(1.12); } }
@keyframes happyRays { to { transform: rotate(360deg); } }
.party-friends { position: absolute; z-index: 4; width: min(98vw, 540px); display: flex; justify-content: space-between; align-items: center; font-size: clamp(3.8rem, 16vw, 7rem); pointer-events: none; }
.party-friends span { filter: drop-shadow(0 8px 2px rgba(74,59,90,.18)); animation: friendJump .38s infinite alternate cubic-bezier(.2,1.5,.4,1); }
.party-friends span:nth-child(2) { align-self: flex-start; animation-delay: .12s; }
.party-friends span:nth-child(3) { animation-delay: .24s; }
@keyframes friendJump { to { transform: translateY(-24px) rotate(8deg) scale(1.08); } }
.celebration-card { position: relative; z-index: 5; min-width: min(82vw, 390px); padding: 28px 20px; border: 7px solid white; border-radius: 42px; background: linear-gradient(135deg, #fff6ad, #ffc875 48%, #ff91ae); box-shadow: 0 15px 0 rgba(102,76,65,.2), 0 0 70px rgba(255,222,88,.85); text-align: center; animation: celebrationPop .42s cubic-bezier(.15,1.65,.35,1), partyGlow .45s .35s infinite alternate; }
.celebration-face { font-size: 6rem; animation: happyDance .28s 3 alternate ease-in-out; }
@keyframes celebrationPop { from { transform: scale(.2) rotate(-12deg); opacity: 0; } 65% { transform: scale(1.1) rotate(4deg); } }
@keyframes happyDance { to { transform: translateY(-9px) rotate(8deg) scale(1.08); } }
@keyframes partyGlow { to { box-shadow: 0 15px 0 rgba(102,76,65,.2), 0 0 95px rgba(255,111,166,.9); transform: scale(1.035); } }
.celebration-card strong, .celebration-card span { display: block; font-size: clamp(2rem, 9vw, 3rem); }
.celebration-card span { color: #e95f68; font-size: clamp(1.6rem, 7vw, 2.3rem); font-weight: 900; }

.try-again {
  position: fixed;
  z-index: 12;
  left: 50%;
  top: 44%;
  width: min(74vw, 310px);
  padding: 18px 20px 20px;
  transform: translate(-50%, -50%);
  border: 6px solid white;
  border-radius: 34px;
  background: linear-gradient(145deg, #b9efff, #d9c8ff);
  box-shadow: 0 12px 0 rgba(86, 72, 126, .18), 0 22px 50px rgba(67, 51, 93, .25);
  text-align: center;
  pointer-events: none;
  animation: sillyBounce .72s cubic-bezier(.2, 1.5, .35, 1);
}
.try-again-friend { font-size: 5.5rem; animation: peekaboo .45s 2 alternate ease-in-out; }
.try-again-sparkles { font-size: 1.7rem; letter-spacing: 5px; }
.try-again strong, .try-again span { display: block; font-size: 2rem; }
.try-again span { color: #6555ad; font-size: 1.35rem; font-weight: 900; }
@keyframes sillyBounce {
  0% { transform: translate(-50%, -50%) scale(.25) rotate(-10deg); opacity: 0; }
  55% { transform: translate(-50%, -50%) scale(1.08) rotate(5deg); }
  100% { transform: translate(-50%, -50%) scale(1) rotate(0); }
}
@keyframes peekaboo { to { transform: rotate(10deg) scale(.9); } }

/* Explore tiles are 1, 3, or 4 per row */
#playArea[data-set="animales"] .explore-board { --erows: 2; --ecols: 3; }
#playArea[data-set="comida"] .explore-board { --erows: 2; --ecols: 3; }
#playArea[data-set="juguetes"] .explore-board { --erows: 2; --ecols: 3; }
#playArea[data-set="ropa"] .explore-board { --erows: 2; --ecols: 2; }
#playArea[data-set="acciones"] .explore-board { --erows: 2; --ecols: 3; }
#playArea[data-set="ropa"] .explore-tile .tile-sub { writing-mode: initial; }

@media (max-width: 430px) {
  .app { padding-left: 10px; padding-right: 10px; }
  .sets-grid { gap: 10px; }
  .set-card { min-height: 130px; border-radius: 25px; }
  .hero { padding-top: 1vh; }
  .hero-friends { font-size: clamp(2.6rem, 12vw, 4.6rem); }
}

@media (max-height: 700px) and (orientation: landscape) {
  .mode-pill { padding: 7px 10px; }
  .prompt-q { font-size: 1rem; }
  .celebration-card { padding: 18px 14px; min-width: min(70vw, 300px); }
  .celebration-face { font-size: 3.5rem; }
  .celebration-card strong, .celebration-card span { font-size: 1.4rem; }
  .celebration-card span { font-size: 1.1rem; }
  .try-again { width: min(56vw, 260px); padding: 10px 14px 12px; }
  .try-again-friend { font-size: 3rem; }
  .try-again strong, .try-again span { font-size: 1.2rem; }
  .try-again span { font-size: .95rem; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; } }
/* Identical solid shapes avoid platform-dependent color emoji. */
.color-swatch { display:inline-block; width:1em; height:1em; border-radius:18%; background:var(--swatch); vertical-align:middle; }
.set-emojis .color-swatch { width:.72em; height:.72em; }
.find-choice:has(.color-swatch) { background:#f7f7fc; filter:none; }
.find-choice > span:has(.color-swatch) { display:grid;place-items:center;width:100%;height:100%; }
.find-choice .color-swatch { width:min(24cqw,25cqh);height:min(24cqw,25cqh);max-width:100%;max-height:100%; }
.tile-emoji:has(.color-swatch) { display:grid;place-items:center; }
