/* Kid Phonics Fun — bright pastel kids UI */
:root {
  --bg1: #E0F2FE;
  --bg2: #FCE7F3;
  --bg3: #FEF3C7;
  --purple: #A78BFA;
  --pink: #F9A8D4;
  --blue: #60A5FA;
  --mint: #6EE7B7;
  --yellow: #FDE68A;
  --coral: #FCA5A5;
  --ink: #334155;
  --ink-soft: #64748B;
  --card: #FFFFFF;
  --shadow: 0 8px 24px rgba(99, 102, 241, 0.18);
  --radius: 20px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", "Nunito", "Rounded Mplus 1c", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg1), var(--bg2) 50%, var(--bg3));
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 720px;
  margin: 0 auto;
  position: relative;
}

/* —— HUD —— */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(10px);
  border-bottom: 3px solid #E9D5FF;
  z-index: 20;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.hud-left, .hud-center, .hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.world-label {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--purple);
}
.stat {
  background: var(--yellow);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 700;
}
.stat.stars { background: #FDE68A; letter-spacing: 2px; }
.mission {
  font-size: 0.78rem;
  color: var(--ink-soft);
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-icon {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 14px;
  background: var(--mint);
  font-size: 1.3rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.btn-icon:active { transform: scale(0.92); }

/* —— 3D stage —— */
#stage-wrap {
  position: relative;
  height: 28vh;
  min-height: 160px;
  max-height: 240px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #C4B5FD 0%, #A5F3FC 100%);
  border-bottom: 4px solid #DDD6FE;
  overflow: hidden;
}
#c3d {
  display: block;
  width: 100%;
  height: 100%;
}
.bubble {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 10px;
  background: #FFF;
  border-radius: 16px;
  padding: 10px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  border: 3px solid var(--pink);
  z-index: 5;
  line-height: 1.35;
}
.bubble::before {
  content: "";
  position: absolute;
  top: -10px;
  left: 40%;
  border: 8px solid transparent;
  border-bottom-color: var(--pink);
}
.bubble.hidden { display: none; }

/* —— Screens —— */
#screens {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px calc(18px + var(--safe-b));
}
.screen { display: none; animation: fadeIn 0.3s ease; }
.screen.active { display: block; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.title {
  text-align: center;
  font-size: 1.7rem;
  color: #7C3AED;
  margin-bottom: 4px;
}
.subtitle {
  text-align: center;
  color: var(--ink-soft);
  margin-bottom: 16px;
  font-weight: 600;
}
.level-title {
  text-align: center;
  font-size: 1.35rem;
  color: #7C3AED;
  margin-bottom: 6px;
}
.progress-line {
  text-align: center;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 12px;
}
.hint {
  text-align: center;
  margin-top: 16px;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

/* —— Hub map —— */
.hub-map {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 8px 0;
}
.hub-node {
  width: min(92%, 320px);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border: 4px solid #E9D5FF;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  text-align: left;
}
.hub-node:not(:disabled):hover,
.hub-node:not(:disabled):active {
  transform: scale(1.03);
  border-color: var(--purple);
}
.hub-node.unlocked { background: linear-gradient(135deg, #FFF, #F5F3FF); }
.hub-node.locked {
  opacity: 0.55;
  cursor: not-allowed;
  filter: grayscale(0.4);
}
.hub-node .node-emoji { font-size: 2rem; }
.hub-node .node-name {
  flex: 1;
  font-weight: 800;
  font-size: 1.05rem;
}
.hub-node .node-tag {
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--mint);
  padding: 4px 10px;
  border-radius: 999px;
}
.hub-node.locked .node-tag { background: #CBD5E1; }
.hub-path {
  width: 6px;
  height: 22px;
  background: linear-gradient(var(--purple), var(--pink));
  border-radius: 4px;
}
.hub-path.locked-path {
  background: #CBD5E1;
}

/* —— Tile grids —— */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.tile-grid.compact {
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
}
.tile {
  aspect-ratio: 1;
  border: none;
  border-radius: 16px;
  font-size: 1.6rem;
  font-weight: 900;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s, box-shadow 0.12s;
  color: var(--ink);
  background: linear-gradient(145deg, #FFF, #EDE9FE);
}
.tile:active { transform: scale(0.9); }
.tile.selected {
  outline: 4px solid var(--purple);
  transform: scale(1.06);
  background: linear-gradient(145deg, #FDE68A, #F9A8D4);
}
.tile.done {
  background: linear-gradient(145deg, #A7F3D0, #6EE7B7);
  outline: 3px solid #34D399;
}
.tile.vowel {
  background: linear-gradient(145deg, #FECACA, #F9A8D4);
}
.tile.blend-tile { font-size: 1.2rem; }
.tile.word-tile { font-size: 1rem; aspect-ratio: auto; min-height: 56px; padding: 8px; }

/* —— Action bar —— */
.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-bottom: 12px;
  position: sticky;
  bottom: 0;
  z-index: 12;
  padding: 10px 4px calc(10px + var(--safe-b));
  background: linear-gradient(180deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.92) 28%, #FFF 100%);
}
.btn {
  border: none;
  border-radius: 16px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s;
  color: var(--ink);
}
.btn:active { transform: scale(0.94); }
.btn.big {
  padding: 14px 20px;
  font-size: 1.05rem;
  min-height: 52px;
}
.btn.primary { background: linear-gradient(135deg, #A78BFA, #60A5FA); color: #FFF; }
.btn.secondary { background: linear-gradient(135deg, #FDE68A, #FBBF24); }
.btn.accent { background: linear-gradient(135deg, #6EE7B7, #34D399); color: #064E3B; }

.tip-box {
  background: #FFF;
  border: 3px dashed var(--pink);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.4;
  min-height: 52px;
}

/* —— Blend arena —— */
.blend-arena {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.blend-parts {
  display: flex;
  gap: 8px;
}
.blend-part {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 900;
  background: linear-gradient(145deg, #FEF3C7, #FDE68A);
  border-radius: 14px;
  box-shadow: var(--shadow);
  border: 3px solid #FBBF24;
}
.blend-arrow {
  font-size: 1.6rem;
  color: var(--purple);
  font-weight: 900;
}
.blend-result {
  min-width: 88px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 900;
  background: linear-gradient(145deg, #DDD6FE, #C4B5FD);
  border-radius: 14px;
  box-shadow: var(--shadow);
  border: 3px solid var(--purple);
  text-transform: lowercase;
}

/* —— Word display —— */
.word-display {
  text-align: center;
  margin-bottom: 14px;
  min-height: 80px;
}
.word-letters {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.word-letter {
  width: 52px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  font-weight: 900;
  background: linear-gradient(145deg, #BAE6FD, #7DD3FC);
  border-radius: 12px;
  border: 3px solid var(--blue);
  box-shadow: var(--shadow);
  text-transform: uppercase;
  transition: transform 0.2s;
}
.word-letter.pulse {
  animation: letterPulse 0.45s ease;
}
@keyframes letterPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2) translateY(-6px); }
}
.word-whole {
  font-size: 2.2rem;
  font-weight: 900;
  color: #7C3AED;
  letter-spacing: 2px;
  text-transform: lowercase;
}
.word-whole.hidden { display: none; }

/* —— Modal —— */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(51, 65, 85, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal-card {
  background: #FFF;
  border-radius: 24px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
  border: 5px solid var(--yellow);
  max-width: 340px;
  width: 100%;
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes popIn {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.modal-stars { font-size: 2.2rem; margin-bottom: 8px; }
.modal-card h2 {
  color: #7C3AED;
  margin-bottom: 8px;
  font-size: 1.4rem;
}
.modal-card p {
  color: var(--ink-soft);
  margin-bottom: 18px;
  font-weight: 600;
  line-height: 1.4;
}

/* —— Responsive —— */
@media (min-width: 600px) {
  #stage-wrap { height: 32vh; max-height: 280px; }
  .tile-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
  .mission { max-width: 280px; }
}
@media (max-height: 640px) {
  #stage-wrap { height: 22vh; min-height: 120px; }
  .btn.big { padding: 10px 16px; min-height: 44px; font-size: 0.95rem; }
}

.tile.mini { min-height: 48px; font-size: 1.2rem; padding: 6px 10px; display: inline-flex; align-items: center; justify-content: center; }
.plus { font-size: 1.4rem; font-weight: 800; margin: 0 6px; color: #7c3aed; }
.blend-parts { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px; }

/* Mobile: keep Speak/Next visible without hunting */
@media (max-width: 480px) {
  #stage-wrap {
    height: 16vh;
    min-height: 96px;
    max-height: 130px;
  }
  .bubble {
    font-size: 0.78rem;
    padding: 8px 10px;
    bottom: 6px;
  }
  .tile-grid {
    gap: 8px;
    margin-bottom: 10px;
  }
  .tile {
    font-size: 1.35rem;
    border-radius: 14px;
  }
  .level-title { font-size: 1.15rem; margin-bottom: 4px; }
  .progress-line { margin-bottom: 8px; font-size: 0.9rem; }
  .tip-box { font-size: 0.85rem; padding: 10px 12px; }
  .btn.big {
    padding: 12px 16px;
    font-size: 0.98rem;
    min-height: 48px;
    flex: 1 1 140px;
  }
  .hud { padding: 8px 10px; }
  .mission { max-width: 140px; font-size: 0.72rem; }
}

@media (max-height: 700px) {
  #stage-wrap {
    height: 14vh;
    min-height: 88px;
    max-height: 120px;
  }
}

