* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #0a0512; }
body {
  font-family: 'Nunito', sans-serif;
  color: #f2eefc;
  display: flex; align-items: center; justify-content: center;
  height: 100vh; height: 100svh;
  touch-action: none;
}

#game-root {
  position: relative;
  width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 20%, #221436 0%, #0a0512 70%);
}

#game-canvas {
  display: block;
  aspect-ratio: 16 / 8;
  width: min(98vw, calc(78svh * 16 / 8));
  height: auto;
  max-height: 78svh;
  background: #150c26;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.55), 0 0 0 3px #150c26, 0 0 0 6px #4a3a7a;
  image-rendering: pixelated;
}

/* ── HUD ── */
.hud { position: absolute; top: 0; left: 0; right: 0; display: flex; flex-direction: column; gap: 6px; padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 0; z-index: 20; pointer-events: none; align-items: center; }
.hud.hidden { display: none; }
.hud-top, .hud-mid { display: flex; align-items: center; justify-content: space-between; gap: 8px; pointer-events: auto; width: min(98vw, calc(78svh * 16 / 8)); }
.hud-title { background: rgba(10,5,20,0.72); border: 1px solid rgba(255,210,74,0.3); border-radius: 20px; padding: 5px 14px; font-weight: 800; font-size: 0.82rem; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.18); background: rgba(10,5,20,0.72); color: #fff; font-size: 1.05rem; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.icon-btn:active { transform: scale(0.92); }

.world-badge { padding: 5px 14px; border-radius: 20px; font-weight: 800; font-size: 0.8rem; letter-spacing: 0.03em; border: 1px solid rgba(255,255,255,0.25); transition: background 0.25s, color 0.25s, border-color 0.25s; }
.world-badge.light { background: linear-gradient(135deg,#ffe58a,#ffb703); color: #3a2400; border-color: #ffe58a; }
.world-badge.shadow { background: linear-gradient(135deg,#5a3a9a,#2a1a4a); color: #e8dcff; border-color: #8a6fd9; }

.hud-chips { display: flex; gap: 6px; }
.hud-chip { background: rgba(10,5,20,0.72); border: 1px solid rgba(255,255,255,0.18); border-radius: 14px; padding: 4px 10px; font-size: 0.78rem; font-weight: 700; }
.hud-chip.hidden { display: none; }

.hint-btn { pointer-events: auto; margin-top: 4px; background: rgba(255,210,74,0.18); border: 1px solid #ffd24a; color: #ffe58a; border-radius: 14px; padding: 5px 12px; font-size: 0.75rem; font-weight: 700; }
.hint-btn.hidden { display: none; }
.hint-toast { pointer-events: none; margin-top: 4px; background: rgba(10,5,20,0.88); border: 1px solid rgba(255,210,74,0.4); border-radius: 10px; padding: 8px 14px; font-size: 0.8rem; max-width: 90%; text-align: center; }
.hint-toast.hidden { display: none; }

/* ── touch controls ── */
.touch-controls { position: absolute; inset: 0; z-index: 25; pointer-events: none; }
.touch-controls.hidden { display: none; }
.tc-left, .tc-right { position: absolute; bottom: calc(env(safe-area-inset-bottom, 0px) + 16px); display: flex; gap: 10px; pointer-events: auto; }
.tc-left { left: 14px; }
.tc-right { right: 14px; align-items: flex-end; }
.tc-btn { width: 58px; height: 58px; border-radius: 50%; background: rgba(20,10,35,0.72); border: 1px solid rgba(255,255,255,0.22); color: #fff; font-size: 1.4rem; }
.tc-btn:active { background: rgba(255,210,74,0.32); }
.tc-jump { width: 70px; height: 70px; background: radial-gradient(circle at 35% 30%, #ffe58a, #ffb703 70%, #d98c00); border: 3px solid #7a4a00; color: #3a2400; }
.tc-switch { background: radial-gradient(circle at 35% 30%, #c9a8ff, #7a4fd9 70%, #4a2a9a); border: 3px solid #2a1a4a; }

/* ── screens (shared skeleton) ── */
.screen { position: absolute; inset: 0; z-index: 30; display: none; align-items: center; justify-content: center; padding: 16px; }
.screen.active { display: flex; }
.overlay-screen { background: rgba(6,2,14,0.84); backdrop-filter: blur(3px); }

.title-card, .panel-card {
  width: min(92vw, 460px); max-height: 90vh; overflow-y: auto;
  background: linear-gradient(180deg, #241636, #170e28);
  border: 3px solid #6a4fae; border-radius: 16px; padding: 26px 22px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.55);
}

.game-title { font-family: 'Press Start 2P', monospace; font-size: 1.4rem; line-height: 1.6; text-align: center; background: linear-gradient(180deg,#ffe58a,#c9a8ff); -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none; }
.subtitle { font-size: 0.9rem; opacity: 0.8; margin-top: -6px; }

.menu-buttons { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.btn-pixel { font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 0.95rem; padding: 13px 18px; border-radius: 10px; border: none; cursor: pointer; box-shadow: 0 3px 0 rgba(0,0,0,0.35); letter-spacing: 0.01em; }
.btn-pixel:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,0.35); }
.btn-primary { background: linear-gradient(180deg,#ffe58a,#ffb703); color: #3a2400; }
.btn-secondary { background: linear-gradient(180deg,#8a6fd9,#5a3a9a); color: #f2eefc; }
.btn-text { background: transparent; color: #cfc3e8; box-shadow: none; font-size: 0.85rem; }

.title-footer { display: flex; align-items: center; justify-content: space-between; width: 100%; font-size: 0.75rem; opacity: 0.65; margin-top: 4px; }

.howto-list { list-style: none; display: flex; flex-direction: column; gap: 10px; font-size: 0.86rem; line-height: 1.4; }

h2 { font-family: 'Press Start 2P', monospace; font-size: 0.95rem; color: #ffd24a; text-align: center; }

.chapter-tabs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.chapter-tab { padding: 7px 12px; border-radius: 10px; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.16); font-size: 0.72rem; font-weight: 700; cursor: pointer; }
.chapter-tab.active { background: #8a6fd9; color: #fff; }

.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; width: 100%; }
.level-tile { aspect-ratio: 1; border-radius: 10px; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.18); display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 800; cursor: pointer; gap: 2px; font-size: 0.85rem; }
.level-tile.locked { opacity: 0.35; cursor: not-allowed; }
.level-tile .lt-medal { font-size: 0.8rem; }
.levels-card { max-height: 92vh; }

.medal-row { display: flex; gap: 10px; width: 100%; justify-content: center; }
.medal-badge { display: flex; flex-direction: column; align-items: center; gap: 2px; background: rgba(255,255,255,0.08); border-radius: 10px; padding: 8px 16px; font-size: 0.72rem; }
.medal-icon { font-size: 1.2rem; }
.medal-tier { font-weight: 800; color: #ffd24a; }

.results-score-val { font-family: 'Press Start 2P', monospace; font-size: 1.6rem; color: #ffe58a; }
.result-detail { font-size: 0.85rem; opacity: 0.8; }

.nn-score-nudge { background: rgba(255,255,255,0.08); border-radius: 10px; padding: 10px; width: 100%; text-align: center; font-size: 0.85rem; }
.nn-nudge-btns { display: flex; gap: 8px; margin-top: 8px; justify-content: center; }
.nn-nudge-signup { background: #ffb703; color: #3a2400; padding: 8px 14px; border-radius: 8px; text-decoration: none; font-weight: 800; font-size: 0.8rem; }
.nn-nudge-later { background: transparent; border: 1px solid rgba(255,255,255,0.3); color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 0.8rem; }

@media (prefers-reduced-motion: reduce) {
  .world-badge { transition: none; }
}
