.stage {
  background: #f1cfa6;
  width: 100vw;   /* exact px size is set from game.js */
  height: 100vh;
  max-width: none;
  max-height: none;
  box-shadow: none;
  position: relative;
  overflow: hidden;
}

.ui {
  --k: 1;
  position: absolute;
  top: 0;
  left: 0;
  width: 1180px;
  height: 820px;
  transform-origin: 0 0;
  pointer-events: none;
  z-index: 3;
  font-family: "Nunito", system-ui, sans-serif;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* ---------- in-game buttons ---------- */

.hud {
  position: absolute;
  top: calc(14px + var(--safe-top) / var(--k));
  left: calc(16px + var(--safe-left) / var(--k));
  right: calc(16px + var(--safe-right) / var(--k));
  display: flex;
  align-items: center;
  pointer-events: none;
}
.hud > *, .hud-right > * { pointer-events: auto; }
.hud-right { margin-left: auto; display: flex; gap: 12px; }

.hud-btn, .corner-btn {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 6px 16px rgba(70, 40, 15, 0.22);
  color: #6b4423;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.hud-btn:active, .corner-btn:active { transform: scale(0.92); }

/* ---------- menu screens ---------- */

.screen {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background:
    radial-gradient(circle at 82% 14%, rgba(255, 240, 170, 0.95) 0 54px, rgba(255, 240, 170, 0.35) 90px, rgba(255, 240, 170, 0) 180px),
    radial-gradient(ellipse 70% 38% at 18% 100%, #74c64c 0 70%, rgba(116, 198, 76, 0) 71%),
    radial-gradient(ellipse 80% 42% at 85% 104%, #86d35a 0 70%, rgba(134, 211, 90, 0) 71%),
    radial-gradient(ellipse 120% 40% at 50% 112%, #a6e07c 0 70%, rgba(166, 224, 124, 0) 71%),
    linear-gradient(#86ccf7 0%, #c9ebff 55%, #eaf7ff 100%);
  color: #4a2f17;
  text-align: center;
}
.screen.scroll {
  justify-content: flex-start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(24px + var(--safe-top) / var(--k)) 24px 40px;
  background: linear-gradient(#8fd3ff 0%, #d9f2ff 40%, #f6e2c4 100%);
}

.corner-btn {
  position: absolute;
  top: calc(14px + var(--safe-top) / var(--k));
  left: calc(16px + var(--safe-left) / var(--k));
  text-decoration: none;
}
.screen.scroll .corner-btn { position: fixed; }

.title-heroes { display: flex; gap: 8px; margin-top: -40px; }
.title-heroes img { width: 110px; height: 110px; animation: bob 2.4s ease-in-out infinite; }
.title-heroes img:nth-child(2) { animation-delay: -0.6s; }
.title-heroes img:nth-child(3) { animation-delay: -1.2s; }
.title-heroes img:nth-child(4) { animation-delay: -1.8s; }
@keyframes bob { 50% { transform: translateY(-10px) rotate(-4deg); } }

.logo {
  font-size: 96px;
  font-weight: 900;
  letter-spacing: 1px;
  color: #fff;
  -webkit-text-stroke: 3px #8a5532;
  text-shadow: 0 7px 0 #8a5532, 0 14px 20px rgba(70, 40, 15, 0.3);
  line-height: 1;
}
.sub { font-size: 24px; font-weight: 800; color: #3d6b2a; background: rgba(255, 255, 255, 0.7); padding: 6px 18px; border-radius: 999px; }

.play-btn {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  border: 8px solid #fff;
  background: radial-gradient(circle at 35% 30%, #ffd166, #ff9f1c);
  color: #fff;
  box-shadow: 0 10px 0 #c76d00, 0 18px 30px rgba(70, 40, 15, 0.3);
  display: grid;
  place-items: center;
  cursor: pointer;
  animation: pulse 1.6s ease-in-out infinite;
}
.play-btn svg { margin-left: 8px; }
.play-btn:active { transform: translateY(6px); box-shadow: 0 4px 0 #c76d00; }
@keyframes pulse { 50% { transform: scale(1.06); } }

.screen-title { font-size: 48px; font-weight: 900; color: #fff; -webkit-text-stroke: 2px #8a5532; text-shadow: 0 5px 0 #8a5532; }

.hero-grid { display: grid; grid-template-columns: repeat(4, 170px); gap: 22px; }
.hero-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 8px 12px;
  border-radius: 28px;
  border: 5px solid #fff;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 8px 20px rgba(70, 40, 15, 0.18);
  font: 900 24px/1 "Nunito", system-ui, sans-serif;
  color: #6b4423;
  cursor: pointer;
}
.hero-btn img { width: 130px; height: 130px; }
.hero-btn.picked { border-color: #ffb703; background: #fff6d6; }
.hero-btn:active { transform: scale(0.95); }

.chapter-list { width: min(640px, 100%); display: flex; flex-direction: column; gap: 14px; margin-top: 10px; }
.chapter { background: rgba(255, 255, 255, 0.82); border: 4px solid #fff; border-radius: 30px; box-shadow: 0 8px 20px rgba(70, 40, 15, 0.15); overflow: hidden; }
.chapter.open { border-color: #ffb703; }
.chapter-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 22px 10px 12px;
  background: none;
  border: 0;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: #4a2f17;
}
.chapter-head img { width: 84px; height: 84px; border-radius: 50%; background: #fff3dc; }
.chapter-head div { display: flex; flex-direction: column; }
.chapter-head b { font-size: 18px; color: #a0703f; font-weight: 800; }
.chapter-head span { font-size: 30px; font-weight: 900; }
.chapter-head em { margin-left: auto; font-style: normal; font-weight: 900; font-size: 22px; color: #a0703f; }
.chapter-levels { display: flex; flex-wrap: wrap; gap: 14px; padding: 4px 22px 20px 112px; }
.level-dot {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 4px solid #e8c79a;
  background: #fff;
  font: 900 26px/1 "Nunito", system-ui, sans-serif;
  color: #8a5532;
  cursor: pointer;
}
.level-dot.done { background: #ffd166; border-color: #f4a300; color: #6b4423; }
.level-dot:active { transform: scale(0.92); }

.splash-icon { width: 160px; height: 160px; border-radius: 50%; background: rgba(255, 255, 255, 0.85); border: 6px solid #fff; box-shadow: 0 10px 24px rgba(70, 40, 15, 0.2); animation: pop 0.5s ease-out; }
.splash-title { font-size: 64px; font-weight: 900; color: #fff; -webkit-text-stroke: 2px #8a5532; text-shadow: 0 6px 0 #8a5532; }
.splash-name { font-size: 28px; font-weight: 800; color: #3d6b2a; background: rgba(255, 255, 255, 0.75); padding: 6px 20px; border-radius: 999px; }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } }

@media (max-aspect-ratio: 1/1) {
  .hero-grid { grid-template-columns: repeat(2, 170px); }
  .logo { font-size: 80px; }
}

/* gentle fades between screens */
.screen { animation: screenIn 0.35s ease-out; }
@keyframes screenIn { from { opacity: 0; transform: scale(1.02); } }
.hero-btn img, .chapter-head img { filter: drop-shadow(0 4px 6px rgba(70, 40, 15, 0.18)); }
.chapter-head img { padding: 8px; }

/* app mode: no rubber-band scrolling, no text selection or callouts */
html, body { overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
