:root {
  --bg-gradient: radial-gradient(ellipse at 50% -10%, #fff7ed 0%, #fdf6ec 55%, #f5ece0 100%);
  --bg: #fdf6ec;
  --card: rgba(255, 255, 255, 0.92);
  --card-solid: #ffffff;
  --card-border: rgba(255, 255, 255, 0.85);
  --ink: #2c2520;
  --dim: #8c7e72;
  --line: #ede2d4;
  
  /* Brand Palettes */
  --p1: #ff7e36;
  --p1-light: #fff0e6;
  --p1-glow: rgba(255, 126, 54, 0.28);
  
  --p2: #22b8cf;
  --p2-light: #e6fcf5;
  --p2-glow: rgba(34, 184, 207, 0.28);
  
  --p3: #40c057;
  --p3-light: #ebfbee;
  --p3-glow: rgba(64, 192, 87, 0.28);
  
  --p4: #7950f2;
  --p4-light: #f3f0ff;
  --p4-glow: rgba(121, 80, 242, 0.28);
  
  --bad: #fa5252;
  --bad-light: #ffe3e3;
  
  --shadow-sm: 0 2px 8px rgba(90, 60, 30, 0.05);
  --shadow-card: 0 10px 30px -6px rgba(110, 70, 30, 0.09), 0 2px 6px rgba(0, 0, 0, 0.03);
  --shadow-hover: 0 18px 40px -8px rgba(110, 70, 30, 0.16), 0 4px 12px rgba(0, 0, 0, 0.04);
  --shadow-active: 0 4px 14px -2px rgba(110, 70, 30, 0.12);
  
  --r: 24px;
  --r-sm: 14px;
}

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

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  position: fixed;
  background: var(--bg);
  background-image: var(--bg-gradient);
  color: var(--ink);
  font: 16px/1.45 'Nunito', system-ui, -apple-system, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

h1, h2, h3, h4, b {
  font-family: 'Outfit', 'Nunito', sans-serif;
  font-weight: 800;
  letter-spacing: -0.015em;
}

#root {
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
  overflow: hidden;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Ambient Background Glow */
.ambient-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}
.glow-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.45;
}
.orb-1 {
  width: 420px;
  height: 420px;
  background: #ffd8a8;
  top: -120px;
  left: 10%;
  animation: floatOrb 18s ease-in-out infinite alternate;
}
.orb-2 {
  width: 380px;
  height: 380px;
  background: #c3fae8;
  bottom: -100px;
  right: 5%;
  animation: floatOrb 14s ease-in-out infinite alternate-reverse;
}
.orb-3 {
  width: 320px;
  height: 320px;
  background: #d0ebff;
  top: 40%;
  left: 60%;
  animation: floatOrb 22s ease-in-out infinite alternate;
}
@keyframes floatOrb {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(40px, 30px) scale(1.12); }
}

/* Screens */
.screen {
  position: absolute;
  top: 56px;
  bottom: 0;
  left: 0;
  right: 0;
  display: none;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}
.screen.on {
  display: flex;
  opacity: 1;
  transform: translateY(0);
}

#stage {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 16px 14px;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
}

#scLogin {
  overflow-y: auto !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch !important;
  touch-action: pan-y !important;
  overscroll-behavior-y: contain;
}

/* Landscape Gate */
#gate {
  position: fixed;
  inset: 0;
  background: var(--bg);
  background-image: var(--bg-gradient);
  z-index: 90;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 36px;
}
#gate.on { display: flex; }
#gate .rot {
  font-size: 78px;
  animation: tipRotate 2.2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
@keyframes tipRotate {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}
#gate h2 {
  margin: 22px 0 10px;
  font-size: 26px;
  color: var(--ink);
}
#gate p {
  color: var(--dim);
  max-width: 420px;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

/* ==========================================================================
   KID-FIRST HOME MENU & MASCOT ADVENTURE STAGE
   ========================================================================== */
#scHome {
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding: 6px 16px 14px;
}

/* Interactive Pip Mascot Guide Banner */
.home-pip-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-shrink: 0;
  margin-bottom: 2px;
  user-select: none;
}
.pip-hero-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4C6FFF 0%, #3451db 100%);
  border: 2.5px solid #ffffff;
  box-shadow: 0 6px 18px rgba(76, 111, 255, 0.3), 0 3px 0 rgba(52, 81, 219, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.pip-hero-avatar:hover {
  transform: scale(1.12) rotate(-4deg);
}
.pip-hero-avatar.hop {
  animation: mascotHop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
}
.pip-hero-mark {
  width: 32px;
  height: 32px;
  object-fit: contain;
  display: block;
}
.pip-hero-wave {
  position: absolute;
  top: -4px;
  right: -5px;
  font-size: 17px;
  animation: handWave 2s infinite ease-in-out;
}
@keyframes handWave {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(20deg); }
  75% { transform: rotate(-10deg); }
}

.pip-speech-bubble {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 2px solid rgba(228, 215, 200, 0.95);
  border-radius: 999px;
  padding: 6px 12px 6px 18px;
  box-shadow: 0 6px 20px rgba(44, 37, 32, 0.08), 0 3px 0 rgba(215, 195, 175, 0.7);
}
.pip-bubble-msg {
  font: 900 clamp(15px, 2vw, 19px) 'Outfit', sans-serif;
  color: #2d241e;
  letter-spacing: -0.01em;
}
.pip-bubble-audio-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #ffd43b, #f59f00);
  color: #ffffff;
  display: grid;
  place-items: center;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 3px 0 #d97706, 0 4px 10px rgba(245, 159, 0, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
}
.pip-bubble-audio-btn:hover {
  transform: scale(1.1);
}
.pip-bubble-audio-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #d97706;
}

/* Kid-Friendly Montessori Level Exploration Track */
.kid-roadmap {
  display: flex;
  justify-content: center;
  padding: 0 16px 4px;
  flex-shrink: 0;
}
.kid-roadmap .roadmap-track {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 2px solid rgba(228, 215, 200, 0.95);
  padding: 4px 16px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(44, 37, 32, 0.06), 0 2px 0 rgba(215, 195, 175, 0.5);
}
.kid-roadmap .roadmap-node {
  border: none;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 999px;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.18s ease;
}
.kid-roadmap .roadmap-node:hover {
  transform: scale(1.08);
  background: rgba(0, 0, 0, 0.04);
}
.kid-roadmap .roadmap-node.n1 .node-badge { color: #d6336c; }
.kid-roadmap .roadmap-node.n2 .node-badge { color: #1971c2; }
.kid-roadmap .roadmap-node.n3 .node-badge { color: #2b8a3e; }
.kid-roadmap .node-badge {
  font: 900 12px 'Outfit', sans-serif;
  letter-spacing: 0.02em;
}
.kid-roadmap .node-sub {
  font: 800 11px 'Nunito', sans-serif;
  color: var(--dim);
  background: rgba(0, 0, 0, 0.04);
  padding: 2px 7px;
  border-radius: 999px;
}
.kid-roadmap .roadmap-arrow {
  color: #c9bcae;
  font-weight: 900;
  font-size: 11px;
}

/* Home Menu Grid */
#menu {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(12px, 1.8vw, 20px);
  padding: 4px 18px 10px;
  align-content: center;
  flex: 0 0 auto;
  max-width: 1080px;
  margin: 0 auto;
  width: 100%;
}

/* 3D Tactile Game Tile Cards */
.tile {
  background: #ffffff;
  border: 2.5px solid rgba(228, 215, 200, 0.95);
  border-radius: 22px;
  box-shadow: 0 8px 22px rgba(44, 37, 32, 0.08), 0 4px 0 rgba(215, 195, 175, 0.8);
  padding: 8px 8px 12px;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font: inherit;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 252px;
  position: relative;
  overflow: hidden;
  transition: transform 0.24s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.24s ease, border-color 0.24s ease;
}
.tile::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 6px;
  border-radius: 22px 22px 0 0;
  z-index: 2;
}
.tile.t1 { animation: cardFloat 4s ease-in-out infinite 0.05s; }
.tile.t2 { animation: cardFloat 4.2s ease-in-out infinite 0.25s; }
.tile.t3 { animation: cardFloat 4.1s ease-in-out infinite 0.45s; }
.tile.t4 { animation: cardFloat 4.3s ease-in-out infinite 0.65s; }
@keyframes cardFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.tile:hover {
  animation: none !important;
  transform: translateY(-8px) scale(1.02);
  box-shadow: 0 20px 36px rgba(44, 37, 32, 0.16), 0 8px 0 rgba(215, 195, 175, 0.95);
}
.tile:active {
  animation: none !important;
  transform: scale(0.96, 1.04) translateY(2px) !important;
  box-shadow: 0 4px 10px rgba(44, 37, 32, 0.08), 0 1px 0 rgba(215, 195, 175, 0.9);
}

/* 3D Art Frame with Audio Speaker Preview Button */
.tile-art-frame {
  position: relative;
  width: 100%;
  height: clamp(118px, 17.5vh, 150px);
  border-radius: 16px;
  overflow: hidden;
  background: #ece5dc;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
}
.tile-art-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}
.tile:hover .tile-art-img {
  transform: scale(1.08);
}

/* Speaker Audio Preview Button on Tile Corner */
.tile-speak-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.98);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18), 0 2px 0 rgba(180, 160, 140, 0.5);
  display: grid;
  place-items: center;
  font-size: 16px;
  cursor: pointer;
  z-index: 6;
  user-select: none;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.18s ease;
}
.tile-speak-btn:hover {
  transform: scale(1.18);
  background: #ffffff;
}
.tile-speak-btn:active {
  transform: scale(0.92);
}
.tile-speak-btn.speaking {
  animation: speakPulse 0.6s infinite alternate ease-in-out;
  background: #ffec99;
}
.tile-speak-btn.speaking::after,
.pip-bubble-audio-btn.speaking::after,
.prompt-audio-btn.speaking::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2.5px solid #f59f00;
  animation: soundWaveRadiate 0.9s infinite ease-out;
  pointer-events: none;
}
@keyframes soundWaveRadiate {
  0% { transform: scale(0.85); opacity: 0.95; }
  100% { transform: scale(1.65); opacity: 0; }
}
@keyframes speakPulse {
  0% { transform: scale(1); box-shadow: 0 0 0 rgba(245, 159, 0, 0.4); }
  100% { transform: scale(1.22); box-shadow: 0 0 14px rgba(245, 159, 0, 0.7); }
}

/* World Category Badge */
.tile-tag {
  position: absolute;
  bottom: 6px;
  left: 8px;
  right: 8px;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 999px;
  text-align: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.14);
}
.tile.t1 .tile-tag { background: rgba(255, 237, 222, 0.95); color: #c2410c; }
.tile.t2 .tile-tag { background: rgba(224, 242, 254, 0.95); color: #0369a1; }
.tile.t3 .tile-tag { background: rgba(220, 252, 231, 0.95); color: #15803d; }
.tile.t4 .tile-tag { background: rgba(254, 249, 195, 0.95); color: #a16207; }

/* Tile Body */
.tile-body {
  padding: 6px 4px 2px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.tile-title {
  display: block;
  font-size: clamp(16px, 1.9vw, 19px);
  font-weight: 900;
  color: var(--ink);
  margin-bottom: 2px;
  letter-spacing: -0.015em;
}
.tile-feature-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 11.5px;
  font-weight: 800;
  color: var(--dim);
}

/* Chunky Glossy 3D PLAY Button */
.tile-play-btn {
  width: 100%;
  margin-top: 6px;
  padding: 7px 0;
  border-radius: 14px;
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.05em;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  position: relative;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.tile-play-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.4) 0%, rgba(255,255,255,0) 60%);
  pointer-events: none;
}
.play-arrow {
  font-size: 11px;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.tile:hover .play-arrow {
  transform: translateX(3px) scale(1.15);
}

.tile.t1 .tile-play-btn {
  background: linear-gradient(180deg, #ff922b 0%, #f76707 100%);
  box-shadow: 0 4px 0 #d9480f, 0 6px 14px rgba(247, 103, 7, 0.35);
}
.tile.t2 .tile-play-btn {
  background: linear-gradient(180deg, #4dabf7 0%, #228be6 100%);
  box-shadow: 0 4px 0 #1864ab, 0 6px 14px rgba(34, 139, 230, 0.35);
}
.tile.t3 .tile-play-btn {
  background: linear-gradient(180deg, #51cf66 0%, #2fb344 100%);
  box-shadow: 0 4px 0 #237b30, 0 6px 14px rgba(47, 179, 68, 0.35);
}
.tile.t4 .tile-play-btn {
  background: linear-gradient(180deg, #fcc419 0%, #f59f00 100%);
  box-shadow: 0 4px 0 #d97706, 0 6px 14px rgba(245, 159, 0, 0.35);
}

.tile:active .tile-play-btn {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3) !important;
}

/* Header Star & Trophy Badges */
.star-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: linear-gradient(135deg, #fff3bf, #ffd43b);
  border: 1.5px solid rgba(245, 159, 0, 0.4);
  color: #b45309;
  font: 900 13px 'Outfit', sans-serif;
  padding: 2px 10px;
  border-radius: 999px;
  box-shadow: 0 2px 6px rgba(245, 159, 0, 0.2);
}
.badge-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(0, 0, 0, 0.05);
  color: var(--ink);
  font: 900 13px 'Outfit', sans-serif;
  padding: 2px 8px;
  border-radius: 999px;
}

/* Discover Screen Kid-Friendly Prompt */
.kid-friendly-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  user-select: none;
}
.kid-friendly-prompt .hero-bounce {
  font-size: clamp(52px, 8vw, 76px);
  animation: bounce 2.2s infinite ease-in-out;
}
.kid-friendly-prompt h3 {
  font-size: clamp(24px, 3.5vw, 32px);
  margin: 0;
  background: linear-gradient(135deg, #2d241e 0%, #b45309 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.kid-prompt-bubble {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 2px solid rgba(228, 215, 200, 0.95);
  padding: 8px 16px 8px 20px;
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(44, 37, 32, 0.08), 0 2px 0 rgba(215, 195, 175, 0.6);
  font: 800 clamp(14px, 1.8vw, 17px) 'Nunito', sans-serif;
  color: var(--ink);
}
.prompt-audio-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #ffd43b, #f59f00);
  color: #ffffff;
  display: grid;
  place-items: center;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 3px 0 #d97706, 0 4px 8px rgba(245, 159, 0, 0.3);
  transition: transform 0.15s ease;
}
.prompt-audio-btn:hover {
  transform: scale(1.12);
}
.prompt-audio-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #d97706;
}

/* iPad Landscape Specific Layout (1024x768, 1080x810, 1180x820, 1366x1024) */
@media (min-width: 840px) and (orientation: landscape) {
  .home-hero {
    padding: 8px 20px 2px;
  }
  .home-hero h2 {
    font-size: clamp(20px, 3vw, 27px);
  }
  .level-roadmap {
    padding: 0 20px 4px;
  }
  #menu {
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    max-width: 1060px;
    padding: 4px 18px 8px;
  }
  .tile {
    min-height: 255px;
    padding: 9px 9px 12px;
  }
  .tile-art-frame {
    height: 118px;
  }
  .tile-title {
    font-size: 17.5px;
  }
  .tile-desc {
    font-size: 11px;
    min-height: 30px;
  }
  .tile-play-btn {
    padding: 7px 0;
    font-size: 13px;
  }
}

@media (max-height: 720px) {
  .home-hero {
    padding: 4px 20px 0;
  }
  .hero-explorer-pill {
    margin-bottom: 2px;
    padding: 2px 10px;
    font-size: 10px;
  }
  .home-hero h2 {
    font-size: 21px;
  }
  .home-hero p {
    margin: 1px 0 0;
    font-size: 12px;
  }
  .level-roadmap {
    padding: 1px 20px 3px;
  }
  .roadmap-track {
    padding: 3px 12px;
  }
  .tile {
    min-height: 210px;
    padding: 6px 6px 9px;
  }
  .tile-art-frame {
    height: 88px;
  }
  .tile-title {
    font-size: 15px;
  }
  .tile-desc {
    font-size: 10px;
    min-height: 25px;
  }
  .tile-play-btn {
    padding: 5px 0;
    font-size: 12px;
    margin-top: 4px;
  }
}
