* { 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: #0c1712; }
body {
  font-family: 'Nunito', sans-serif;
  color: #f2f7ec;
  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%, #1b3324 0%, #0c1712 70%);
}

#game-canvas {
  display: block;
  aspect-ratio: 11 / 7;
  width: min(98vw, calc(78svh * 11 / 7));
  height: auto;
  max-height: 78svh;
  background: #234126;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 0 3px #0e2015, 0 0 0 6px #3a6a3f;
  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;
}
.hud.hidden { display: none; }
.hud-top, .hud-mid { display: flex; align-items: center; justify-content: space-between; gap: 8px; pointer-events: auto; }
.hud-title { display: flex; align-items: center; gap: 6px; background: rgba(10,20,12,0.72); border: 1px solid rgba(255,210,74,0.35); border-radius: 20px; padding: 5px 14px; font-weight: 800; font-size: 0.85rem; letter-spacing: 0.02em; }
.hud-weather { font-size: 1rem; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.18);
  background: rgba(10,20,12,0.72); color: #fff; font-size: 1.05rem; cursor: pointer; backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { transform: scale(0.92); }

.battery-wrap { display: flex; align-items: center; gap: 6px; background: rgba(10,20,12,0.72); border: 1px solid rgba(255,210,74,0.35); border-radius: 20px; padding: 5px 12px; }
.battery-icon { font-size: 0.95rem; }
.battery-track { width: 96px; height: 10px; border-radius: 6px; background: rgba(255,255,255,0.12); overflow: hidden; border: 1px solid rgba(255,255,255,0.15); }
.battery-fill { height: 100%; width: 100%; background: linear-gradient(90deg,#ffd24a,#ffb703); transition: width 0.25s ease, background 0.25s ease; }
.battery-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;} }
#battery-pct { font-size: 0.75rem; font-weight: 700; min-width: 34px; text-align: right; }

.drone-chip { background: rgba(10,20,12,0.72); border: 1px solid rgba(120,200,255,0.4); border-radius: 20px; padding: 5px 12px; font-size: 0.8rem; font-weight: 700; }
.drone-chip.hidden { display: none; }

.orders-panel { display: flex; gap: 6px; flex-wrap: wrap; pointer-events: auto; }
.order-chip { display: flex; align-items: center; gap: 4px; background: rgba(10,20,12,0.72); border: 1px solid rgba(255,255,255,0.18); border-radius: 14px; padding: 4px 10px; font-size: 0.8rem; font-weight: 700; }
.order-chip.done { border-color: #7ee787; color: #7ee787; }
.order-chip .oc-emoji { font-size: 0.95rem; }

/* ── interact + touch controls ── */
.interact-btn {
  position: absolute; z-index: 25; right: 18px; bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  width: 74px; height: 74px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe58a, #ffb703 70%, #d98c00);
  border: 3px solid #7a4a00; box-shadow: 0 4px 14px rgba(0,0,0,0.4);
  font-size: 1.6rem; cursor: pointer;
}
.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(10,20,12,0.72); border: 1px solid rgba(255,255,255,0.22); color: #fff; font-size: 1.2rem;
}
.dpad-btn:active { background: rgba(255,210,74,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; }

/* ── screens ── */
.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,12,8,0.82); backdrop-filter: blur(3px); }

.title-card, .panel-card {
  width: min(92vw, 460px); max-height: 90vh; overflow-y: auto;
  background: linear-gradient(180deg, #1c3524, #142a1c);
  border: 3px solid #4a7a4f; 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-robot { width: 64px; height: 54px; background: linear-gradient(180deg,#8fa6b3,#5c7482); border-radius: 14px 14px 10px 10px; border: 3px solid #34424a; position: relative; }
.title-robot::before { content:''; position:absolute; left:50%; top:-14px; transform:translateX(-50%); width:4px; height:14px; background:#5c7482; }
.title-robot::after { content:''; position:absolute; left:50%; top:-20px; transform:translateX(-50%); width:8px; height:8px; border-radius:50%; background:#ffd24a; box-shadow:0 0 8px #ffd24a; }
.tr-eye { position:absolute; left:50%; top:18px; transform:translateX(-50%); width:26px; height:16px; background:#0c1712; border-radius:8px; }
.tr-eye::after { content:''; position:absolute; left:6px; top:3px; width:8px; height:8px; border-radius:50%; background:#7ee787; box-shadow:0 0 6px #7ee787; animation: blink 3.2s infinite; }
@keyframes blink { 0%,92%,100%{ transform: scaleY(1);} 96%{ transform: scaleY(0.1);} }

.game-title { font-family: 'Press Start 2P', monospace; font-size: 1.25rem; color: #ffd24a; text-shadow: 2px 2px 0 #7a4a00; 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,#ffe58a,#ffb703); color: #3a2400; }
.btn-secondary { background: linear-gradient(180deg,#5c9c68,#3d7a4a); color: #eafff0; }
.btn-text { background: transparent; color: #cfe8d3; 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.88rem; line-height: 1.4; }
.howto-list li { padding-left: 4px; }

h2 { font-family: 'Press Start 2P', monospace; font-size: 1rem; 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.75rem; font-weight: 700; cursor: pointer; }
.chapter-tab.active { background: #ffb703; 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; }
.level-tile.locked { opacity: 0.35; cursor: not-allowed; }
.level-tile .lt-medal { font-size: 0.85rem; }
.level-tile.daily { grid-column: span 5; aspect-ratio: auto; padding: 12px; flex-direction: row; justify-content: center; gap: 8px; }

.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 10px; font-size: 0.7rem; min-width: 76px; }
.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.7rem; 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 (min-width: 720px) {
  .interact-btn { width: 64px; height: 64px; font-size: 1.3rem; }
}
@media (prefers-reduced-motion: reduce) {
  .battery-fill.low, .tr-eye::after { animation: none; }
}
