* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #faf9f5;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #1a1a1a;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-user-select: none;
  user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* =========================================================
   Screen containers
   ========================================================= */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen.active { display: flex; }

/* Setup screen: viewport-fit; wider max so settings can lay out as a grid */
#setup-screen {
  overflow-y: auto;
  align-items: center;
  justify-content: flex-start;
  padding: 1rem;
}
#setup-screen .inner {
  width: 100%;
  max-width: 1400px;
  margin: auto 0;
}

/* End screen: full-bleed night sky */
#end-screen {
  overflow: hidden;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: radial-gradient(ellipse at 50% 110%, #1a2a66 0%, #0b1537 45%, #05051a 100%);
  color: #fff;
}
#end-screen .inner {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 680px;
  padding: 2rem 1.5rem;
}

/* Game screen: full viewport, no scroll */
#game-screen {
  padding: 0.75rem 1rem;
}

/* =========================================================
   Typography
   ========================================================= */
h1 {
  font-size: clamp(24px, 4vw, 32px);
  font-weight: 600;
  margin: 0 0 0.5rem;
  text-align: center;
}
h2 {
  font-size: clamp(15px, 2.2vw, 18px);
  font-weight: 600;
  margin: 1.5rem 0 0.75rem;
}
p { margin: 0; }
.subtitle {
  text-align: center;
  color: #666;
  font-size: clamp(14px, 2.2vw, 17px);
}

/* =========================================================
   Buttons (shared)
   ========================================================= */
button {
  font-family: inherit;
  background: #ffffff;
  border: 2px solid rgba(0,0,0,0.12);
  border-radius: 14px;
  padding: 14px 18px;
  cursor: pointer;
  font-size: 16px;
  color: #1a1a1a;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
  touch-action: manipulation;
}
button:active:not(:disabled) { transform: scale(0.97); }
button:disabled { cursor: default; }
@media (hover: hover) {
  button:hover:not(:disabled) {
    background: #f5f4ef;
    border-color: rgba(0,0,0,0.25);
  }
}

.primary-btn {
  background: #1a1a1a;
  color: #ffffff;
  border-color: #1a1a1a;
  font-size: 18px;
  padding: 16px 36px;
  font-weight: 500;
  width: 100%;
  margin-top: 1.5rem;
}
.primary-btn:disabled {
  background: #ccc;
  border-color: #ccc;
  color: #888;
}

.back-btn {
  font-size: 14px;
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: #666;
}

/* =========================================================
   Setup screen option buttons
   ========================================================= */
.option-group {
  display: grid;
  gap: 8px;
}
.row-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.choice-btn {
  padding: 12px 16px;
  text-align: left;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.choice-btn strong {
  display: block;
  font-size: 16px;
  font-weight: 600;
}
.choice-btn span.desc {
  font-size: 13px;
  color: #666;
  display: block;
  margin-top: 2px;
}
.choice-btn.selected {
  background: #e6f1fb;
  border-color: #378add;
  color: #0c447c;
}
.choice-btn.selected strong { color: #0c447c; }
.choice-btn.selected span.desc { color: #185fa5; }
.choice-btn .preview {
  font-weight: 500;
  font-size: 17px;
  color: #1a1a1a;
  margin-left: 12px;
  white-space: nowrap;
}
.choice-btn.selected .preview { color: #0c447c; }

.setup-card {
  background: #ffffff;
  border-radius: 20px;
  padding: 1.25rem 1.5rem 1.5rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.06);
}
.setup-header {
  text-align: center;
  margin-bottom: 0.75rem;
}
.setup-header .app-icon {
  font-size: clamp(44px, 7vw, 60px);
  line-height: 1;
  margin-bottom: 0.25rem;
}
.setup-header h1 { margin: 0; }

/* Settings: auto-fit columns of at least 240px — naturally fills the viewport */
.settings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.75rem 1.5rem;
}
.settings h2 {
  margin: 0 0 0.5rem;
}

/* =========================================================
   Game screen layout
   ========================================================= */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: #666;
  flex-shrink: 0;
  padding: 4px 0 8px;
}
.game-header .star-count {
  font-weight: 500;
  color: #1a1a1a;
}

.progress-bar {
  height: 6px;
  background: #f0ede4;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.75rem;
  flex-shrink: 0;
}
.progress-fill {
  height: 100%;
  background: #378add;
  transition: width 0.4s;
  border-radius: 999px;
}

/* Prompt box: holds either the emoji (find-word) or the word (find-picture) */
.prompt-box {
  background: #f5f4ef;
  border-radius: 20px;
  flex: 1 1 40%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  margin-bottom: 0.75rem;
}
.prompt-box.tappable { cursor: pointer; }
.prompt-box.tappable:active { transform: scale(0.97); transition: transform 0.1s; }
.prompt-emoji {
  font-size: clamp(80px, 22vmin, 200px);
  line-height: 1;
}
.prompt-word {
  font-size: clamp(36px, 10vmin, 96px);
  font-weight: 600;
  text-align: center;
  word-break: break-word;
}

/* Game body: by default just passes through so prompt-box + options-grid
   are direct flex children of #game-screen (they share the vertical space
   via their flex: 1 1 N% rules). */
.game-body { display: contents; }

/* Options: 2x2 grid filling remaining space */
.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 10px;
  flex: 1 1 50%;
  min-height: 0;
}
.option-btn {
  font-size: clamp(22px, 6vmin, 56px);
  padding: 12px;
  font-weight: 500;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  border: 2px solid rgba(0,0,0,0.12);
  background: #ffffff;
}
.option-btn.emoji-option {
  font-size: clamp(60px, 20vmin, 180px);
}
.option-btn.correct {
  background: #e1f5ee !important;
  border-color: #1d9e75 !important;
  color: #085041 !important;
}
.option-btn.wrong {
  background: #fcebeb !important;
  border-color: #e24b4a !important;
  color: #791f1f !important;
}

/* =========================================================
   Syllable display (rounded boxes, unique color per syllable)
   Precalculated soft pastels: evenly-spaced hues, S 65%, L 88%.
   ========================================================= */
.syl {
  display: inline-block;
  padding: 0;
  border-radius: 0.3em;
  margin: 0 0.02em;
  color: #1a1a1a;
  line-height: 1.15;
}
/* Hues step by 150° for maximum contrast between neighbours */
.syl-0 { background: hsl(20,  65%, 88%); }  /* peach    */
.syl-1 { background: hsl(170, 65%, 88%); }  /* teal     */
.syl-2 { background: hsl(320, 65%, 88%); }  /* pink     */
.syl-3 { background: hsl(110, 65%, 88%); }  /* green    */
.syl-4 { background: hsl(260, 65%, 88%); }  /* lavender */
.syl-5 { background: hsl(50,  65%, 88%); }  /* yellow   */
.option-btn.correct .syl {
  background: transparent !important;
  color: #085041 !important;
}
.option-btn.wrong .syl {
  background: transparent !important;
  color: #791f1f !important;
}

/* =========================================================
   Success overlay (full-screen)
   ========================================================= */
.success-overlay {
  position: fixed;
  inset: 0;
  background: #1d9e75;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: successFadeIn 0.3s ease-out;
  overflow: hidden;
}
.success-overlay.fade-out {
  animation: successFadeOut 0.4s ease-in forwards;
}
.success-check {
  font-size: clamp(120px, 30vmin, 260px);
  color: white;
  line-height: 1;
  animation: checkBounce 0.7s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.success-text {
  font-size: clamp(36px, 8vmin, 72px);
  color: white;
  font-weight: 700;
  margin-top: 1rem;
  animation: textSlideUp 0.6s 0.2s both;
}
.confetti {
  position: absolute;
  top: -50px;
  font-size: clamp(24px, 4vmin, 40px);
  animation: confettiFall linear forwards;
  pointer-events: none;
}
@keyframes successFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes successFadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}
@keyframes checkBounce {
  0% { transform: scale(0) rotate(-180deg); opacity: 0; }
  60% { transform: scale(1.3) rotate(10deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}
@keyframes textSlideUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0.7; }
}

/* =========================================================
   Success overlay — themed variants
   ========================================================= */
.success-overlay.variant-rocket    { background: linear-gradient(180deg, #0b1537, #1a2a66); }
.success-overlay.variant-firetruck { background: linear-gradient(180deg, #b91c1c, #dc2626); }
.success-overlay.variant-airplane  { background: linear-gradient(180deg, #87ceeb 0%, #bde4f5 100%); }
.success-overlay.variant-solar     { background: radial-gradient(ellipse at center, #1a1a3e 0%, #05051a 80%); }
.success-overlay.variant-ocean     { background: linear-gradient(180deg, #1abc9c 0%, #148a9e 50%, #0a3d52 100%); }

.success-text.top,
.success-text.bottom {
  position: absolute;
  margin-top: 0;
  z-index: 10;
  text-shadow: 0 2px 8px rgba(0,0,0,0.35);
}
.success-text.top    { top: 12vh; }
.success-text.bottom { bottom: 12vh; }

.success-overlay .star {
  position: absolute;
  color: #fff;
  font-size: 12px;
  pointer-events: none;
  animation: starTwinkle 1.8s infinite;
}
@keyframes starTwinkle {
  0%, 100% { opacity: 0.25; transform: scale(0.8); }
  50%      { opacity: 1;    transform: scale(1.2); }
}

/* Rocket */
.variant-rocket .rocket {
  position: relative;
  isolation: isolate;
  font-size: clamp(100px, 22vmin, 200px);
  line-height: 1;
  filter: drop-shadow(0 8px 20px rgba(255,200,100,0.6));
  animation: rocketLaunch 2.2s cubic-bezier(0.5, 0, 0.7, 1) forwards;
}
.variant-rocket .rocket::before {
  content: '';
  position: absolute;
  left: 0.15em;
  top: 0.7em;
  width: 220vmax;
  height: 0.35em;
  background: linear-gradient(to left, rgba(255,255,255,0.85), rgba(255,255,255,0));
  border-radius: 999px;
  transform-origin: 0% 50%;
  transform: rotate(135deg);
  filter: blur(6px);
  pointer-events: none;
  z-index: -1;
}
@keyframes rocketLaunch {
  0%   { transform: translate(-30vmin, 30vmin) scale(0.4); opacity: 0; }
  15%  { transform: translate(-18vmin, 18vmin) scale(1);   opacity: 1; }
  100% { transform: translate(120vmin, -120vmin) scale(1); opacity: 1; }
}

/* Firetruck */
.variant-firetruck .firetruck {
  font-size: clamp(100px, 22vmin, 200px);
  line-height: 1;
  animation: driveAcross 2.4s ease-in-out forwards;
}
.variant-firetruck .siren-pulse {
  position: absolute;
  inset: 0;
  pointer-events: none;
  animation: sirenFlash 0.35s infinite;
}
@keyframes driveAcross {
  0%   { transform: translateX(95vw); }
  50%  { transform: translateX(0); }
  100% { transform: translateX(-95vw); }
}
@keyframes sirenFlash {
  0%, 100% { box-shadow: inset 0 0 0 rgba(255,255,255,0); background: rgba(255,255,255,0); }
  50%      { box-shadow: inset 0 0 120px rgba(80,140,255,0.35); background: rgba(255,255,255,0.18); }
}

/* Airplane */
.variant-airplane .airplane-wrap {
  display: flex;
  align-items: center;
  white-space: nowrap;
  animation: flyDiagonal 2.4s linear forwards;
}
.variant-airplane .airplane {
  position: relative;
  isolation: isolate;
  font-size: clamp(80px, 18vmin, 160px);
  line-height: 1;
}
.variant-airplane .airplane::before {
  content: '';
  position: absolute;
  right: 0.55em;
  top: 0.55em;
  width: 220vmax;
  height: 0.18em;
  background: linear-gradient(to left, rgba(255,255,255,0.95), rgba(255,255,255,0));
  border-radius: 999px;
  transform-origin: 100% 50%;
  transform: rotate(-45deg);
  filter: blur(2px);
  pointer-events: none;
  z-index: -1;
}
.variant-airplane .cloud {
  position: absolute;
  left: -10vw;
  line-height: 1;
  opacity: 0.85;
  animation: cloudDrift linear forwards;
}
@keyframes flyDiagonal {
  0%   { transform: translate(-60vmin, 60vmin); }
  100% { transform: translate(60vmin, -60vmin); }
}
@keyframes cloudDrift {
  0%   { transform: translateX(0); }
  100% { transform: translateX(130vw); }
}

/* Solar system */
.variant-solar .solar-system {
  position: relative;
  width: min(85vmin, 640px);
  height: min(85vmin, 640px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.variant-solar .sun {
  font-size: clamp(40px, 9vmin, 90px);
  line-height: 1;
  z-index: 2;
  animation: sunGlow 2s infinite alternate;
}
.variant-solar .orbit {
  position: absolute;
  inset: 0;
  margin: auto;
  border: 1px dashed rgba(255,255,255,0.12);
  border-radius: 50%;
  animation: spinOrbit linear infinite;
}
.variant-solar .orbit-1 { width: 24%;  height: 24%;  animation-duration: 2.4s; }
.variant-solar .orbit-2 { width: 35%;  height: 35%;  animation-duration: 3.1s; }
.variant-solar .orbit-3 { width: 46%;  height: 46%;  animation-duration: 3.9s; }
.variant-solar .orbit-4 { width: 57%;  height: 57%;  animation-duration: 4.8s; }
.variant-solar .orbit-5 { width: 68%;  height: 68%;  animation-duration: 5.7s; }
.variant-solar .orbit-6 { width: 79%;  height: 79%;  animation-duration: 6.7s; }
.variant-solar .orbit-7 { width: 90%;  height: 90%;  animation-duration: 7.8s; }
.variant-solar .orbit-8 { width: 100%; height: 100%; animation-duration: 9s;   }
.variant-solar .planet {
  position: absolute;
  top: -0.5em;
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(20px, 4.4vmin, 40px);
  line-height: 1;
}
@keyframes spinOrbit {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@keyframes sunGlow {
  from { filter: drop-shadow(0 0 15px #ffd700); transform: scale(1); }
  to   { filter: drop-shadow(0 0 35px #ffa500); transform: scale(1.08); }
}

/* Ocean */
.variant-ocean .bubble {
  position: absolute;
  bottom: -40px;
  line-height: 1;
  pointer-events: none;
  animation: bubbleRise linear forwards;
}
@keyframes bubbleRise {
  0%   { transform: translateY(0)      translateX(0);    opacity: 0.9; }
  100% { transform: translateY(-120vh) translateX(10px); opacity: 0; }
}
.variant-ocean .fish {
  position: absolute;
  right: -15vw;
  font-size: clamp(28px, 5.5vmin, 56px);
  line-height: 1;
  animation-name: fishSwimLeft;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}
@keyframes fishSwimLeft {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-130vw); }
}

/* =========================================================
   End screen
   ========================================================= */
.end-card {
  background: rgba(10, 14, 40, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px;
  padding: 2.5rem 1.5rem;
  box-shadow: 0 8px 40px rgba(0,0,0,0.35);
  text-align: center;
  color: #fff;
}
.end-card h1 {
  color: #fff;
}
.big-emoji {
  font-size: clamp(72px, 14vmin, 120px);
  margin-bottom: 1rem;
  line-height: 1;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.4));
}
.end-score {
  font-size: clamp(16px, 2.5vw, 20px);
  color: rgba(255,255,255,0.78);
  margin-bottom: 0.5rem;
}
.end-score strong {
  color: #fff;
  font-size: clamp(22px, 3.5vw, 28px);
}
.end-message {
  font-size: clamp(15px, 2.2vw, 18px);
  color: rgba(255,255,255,0.78);
  margin-bottom: 1rem;
}
#end-screen .primary-btn {
  background: #fff;
  color: #0b1537;
  border-color: #fff;
}
#end-screen .back-btn {
  color: rgba(255,255,255,0.7);
}

/* Night-sky stars + fireworks */
.end-stars,
.fireworks-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.end-stars { z-index: 0; }
.fireworks-layer { z-index: 1; }

.end-stars .star {
  position: absolute;
  color: #fff;
  font-size: 10px;
  animation: starTwinkle 2.4s infinite;
}

.firework {
  position: absolute;
  width: 0;
  height: 0;
}
.firework-particle {
  position: absolute;
  left: 0;
  top: 0;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor, 0 0 16px currentColor;
  animation: fireworkBurst 1.4s cubic-bezier(0.15, 0.7, 0.3, 1) forwards;
}
@keyframes fireworkBurst {
  0%   { transform: translate(0, 0) scale(0.6); opacity: 1; }
  20%  { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0.4); opacity: 0; }
}

/* =========================================================
   Landscape iPad: extra horizontal padding for wider screens
   ========================================================= */
@media (orientation: landscape) and (min-width: 900px) {
  #game-screen { padding: 0.75rem 1.5rem; }
}

/* =========================================================
   Small phones: tighter spacing
   ========================================================= */
@media (max-width: 400px) {
  #game-screen { padding: 0.5rem 0.5rem; }
  .options-grid { gap: 6px; }
  .prompt-box { margin-bottom: 0.5rem; }
}
