* { 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: #0f0a06; }
body { font-family: 'Nunito', sans-serif; color: #f5ead8; 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%, #2a1c10 0%, #0f0a06 70%); }

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

.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 * 12 / 9)); }
.hud-title { background: rgba(15,10,6,0.75); border: 1px solid rgba(255,180,80,0.32); 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(15,10,6,0.75); color: #fff; font-size: 1.05rem; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.icon-btn:active { transform: scale(0.92); }

.air-wrap { display: flex; align-items: center; gap: 6px; background: rgba(15,10,6,0.75); border: 1px solid rgba(120,200,255,0.35); border-radius: 20px; padding: 5px 12px; flex: 1; max-width: 220px; }
.air-icon { font-size: 0.95rem; }
.air-track { width: 120px; height: 10px; border-radius: 6px; background: rgba(255,255,255,0.12); overflow: hidden; border: 1px solid rgba(255,255,255,0.15); }
.air-fill { height: 100%; width: 100%; background: linear-gradient(90deg,#8fd3ff,#3fa9ff); transition: width 0.25s ease, background 0.25s ease; }
.air-fill.low { background: linear-gradient(90deg,#ff5a5a,#ff2d2d); animation: pulse-low 0.7s infinite; }
@keyframes pulse-low { 0%,100%{opacity:1;} 50%{opacity:0.5;} }

.hud-chips { display: flex; gap: 6px; }
.hud-chip { background: rgba(15,10,6,0.75); 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; }

.interact-btn { position: absolute; z-index: 25; right: 18px; bottom: calc(env(safe-area-inset-bottom, 0px) + 18px); width: 72px; height: 72px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffb54a, #d97b1e 70%, #8a4a0a); border: 3px solid #4a2800; box-shadow: 0 4px 14px rgba(0,0,0,0.4); font-size: 1.5rem; }
.interact-btn.hidden { display: none; }
.interact-btn:active { transform: scale(0.92); }

.touch-controls { position: absolute; z-index: 25; left: 14px; bottom: calc(env(safe-area-inset-bottom, 0px) + 14px); }
.touch-controls.hidden { display: none; }
.dpad { position: relative; width: 150px; height: 150px; }
.dpad-btn { position: absolute; width: 50px; height: 50px; border-radius: 12px; background: rgba(15,10,6,0.75); border: 1px solid rgba(255,255,255,0.22); color: #fff; font-size: 1.2rem; }
.dpad-btn:active { background: rgba(255,180,80,0.35); }
.dpad-up { left: 50px; top: 0; } .dpad-down { left: 50px; top: 100px; }
.dpad-left { left: 0; top: 50px; } .dpad-right { left: 100px; top: 50px; }

.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(10,6,3,0.84); backdrop-filter: blur(3px); }

.title-card, .panel-card { width: min(92vw, 460px); max-height: 90vh; overflow-y: auto; background: linear-gradient(180deg, #3a2614, #22160a); border: 3px solid #8a5a2e; 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.5); }

.title-miner { width: 40px; height: 48px; background: linear-gradient(180deg,#e8c088,#c9925a); border-radius: 10px 10px 6px 6px; border: 3px solid #5a3a1a; position: relative; }
.title-miner::after { content:''; position:absolute; left:50%; top:-16px; transform:translateX(-50%); width:22px; height:8px; background:#ffd24a; border-radius:3px; box-shadow:0 0 10px #ffd24a; }

.game-title { font-family: 'Press Start 2P', monospace; font-size: 1.15rem; color: #ffb54a; text-shadow: 2px 2px 0 #4a2800; text-align: center; line-height: 1.5; }
.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,#ffcf7a,#ffb54a); color: #3a2400; }
.btn-secondary { background: linear-gradient(180deg,#c9925a,#8a5a2e); color: #f5ead8; }
.btn-text { background: transparent; color: #d9c0a0; 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: #ffb54a; 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: #ffb54a; color: #3a2400; }

.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.75rem; }
.levels-card { max-height: 92vh; }

.stars-row { font-size: 1.6rem; letter-spacing: 4px; color: #ffb54a; }
.results-score-val { font-family: 'Press Start 2P', monospace; font-size: 1.6rem; color: #ffcf7a; }
.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: #ffb54a; 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) { .air-fill.low { animation: none; } }
