:root {
  color-scheme: dark;
  --sky: #7bdcff;
  --deep: #0c1635;
  --panel: rgba(9, 16, 38, 0.78);
  --panel-strong: rgba(11, 20, 48, 0.94);
  --line: rgba(255, 255, 255, 0.16);
  --text: #f7fbff;
  --muted: #b9c8e7;
  --gold: #ffd166;
  --green: #57d68d;
  --shield: #50d7ff;
  --danger: #ff5f8f;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; overflow-x: hidden; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 14% 10%, rgba(255, 209, 102, .24), transparent 28rem),
    radial-gradient(circle at 85% 18%, rgba(80, 215, 255, .26), transparent 30rem),
    linear-gradient(135deg, #172a64 0%, #0b122e 52%, #11182f 100%);
  color: var(--text);
}

button { font: inherit; color: inherit; }
.shell { width: min(1180px, calc(100vw - 24px)); margin: 0 auto; padding: 22px 0 20px; }
.hero-card {
  border: 1px solid var(--line);
  background: linear-gradient(135deg, rgba(255,255,255,.13), rgba(255,255,255,.04));
  box-shadow: 0 20px 70px rgba(0,0,0,.26);
  border-radius: 28px;
  padding: clamp(16px, 3vw, 28px);
  margin-bottom: 14px;
}
.title-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.eyebrow { margin: 0 0 8px; color: var(--gold); letter-spacing: .12em; text-transform: uppercase; font-size: .76rem; font-weight: 800; }
h1 { margin: 0; font-size: clamp(2.35rem, 7vw, 5.4rem); line-height: .88; letter-spacing: -.07em; }
.lede { max-width: 760px; margin: 14px 0 0; color: #e9f1ff; font-size: clamp(1rem, 2vw, 1.18rem); }
.best-chip { min-height: 36px; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; background: rgba(0,0,0,.18); color: var(--muted); }
.control-copy { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.control-copy p { margin: 0; color: var(--muted); background: rgba(0,0,0,.15); border: 1px solid var(--line); border-radius: 16px; padding: 12px; }

.arena-wrap {
  position: relative;
  min-height: min(72vh, 720px);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 30px;
  overflow: hidden;
  background: #111a35;
  box-shadow: 0 24px 90px rgba(0,0,0,.35);
}
#gameCanvas { width: 100%; height: min(72vh, 720px); min-height: 540px; display: block; outline: none; background: linear-gradient(#7bdcff, #d7f6ff 58%, #98dc8e); touch-action: none; }

.hud { position: absolute; inset: 14px 14px auto 14px; display: flex; align-items: flex-start; gap: 10px; pointer-events: none; z-index: 2; }
.status-stack { display: grid; gap: 8px; width: min(250px, 28vw); }
.meter { position: relative; min-height: 38px; overflow: hidden; border-radius: 999px; background: rgba(10, 20, 45, .82); border: 1px solid var(--line); box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.meter span, .meter b { position: relative; z-index: 1; line-height: 38px; }
.meter span { padding-left: 13px; color: #e8fff2; font-size: .8rem; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; }
.meter b { float: right; padding-right: 13px; }
.meter i { position: absolute; inset: 0 auto 0 0; width: 100%; background: linear-gradient(90deg, #2ecb71, #8af27d); transition: width .16s ease; }
.meter.shield i { background: linear-gradient(90deg, #1aa7ff, #69e6ff); }
.hud-card, .hud-button {
  pointer-events: auto;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(12px);
  border-radius: 18px;
  min-height: 58px;
  padding: 10px 12px;
  box-shadow: 0 12px 34px rgba(0,0,0,.18);
}
.hud-card { display: grid; gap: 2px; min-width: 104px; }
.hud-card span, .hud-card small { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 800; }
.hud-card strong { font-size: 1.18rem; }
.count-card { grid-template-columns: auto auto; align-items: center; column-gap: 9px; }
.hud-button { width: 46px; height: 46px; margin-left: auto; cursor: pointer; }

.overlay { position: absolute; z-index: 3; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100% - 28px)); }
.panel { background: var(--panel-strong); border: 1px solid rgba(255,255,255,.22); border-radius: 28px; padding: clamp(20px, 4vw, 34px); box-shadow: 0 30px 90px rgba(0,0,0,.38); text-align: center; }
.panel h2 { margin: 0; font-size: clamp(1.8rem, 5vw, 3.2rem); line-height: .95; letter-spacing: -.04em; }
.panel p:not(.eyebrow) { color: #dce8ff; font-size: 1.05rem; line-height: 1.5; }
.overlay-actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
.primary, .secondary { min-height: 48px; border-radius: 999px; border: 0; padding: 0 20px; font-weight: 900; cursor: pointer; transition: transform .15s ease, filter .15s ease; }
.primary { background: linear-gradient(135deg, #ffcc5c, #ff7aa8); color: #161326; box-shadow: 0 13px 30px rgba(255,122,168,.28); }
.secondary { background: rgba(255,255,255,.1); border: 1px solid var(--line); color: #f1f7ff; }
.primary:hover, .secondary:hover { transform: translateY(-1px); filter: brightness(1.07); }
.hidden { display: none !important; }

.touch-ui { position: absolute; inset: auto 14px calc(14px + env(safe-area-inset-bottom)) 14px; display: none; justify-content: space-between; align-items: flex-end; gap: 12px; z-index: 2; pointer-events: none; }
.stick-zone { pointer-events: auto; width: 118px; height: 118px; border-radius: 50%; background: rgba(5, 12, 30, .46); border: 1px solid rgba(255,255,255,.22); display: grid; place-items: center; touch-action: none; }
.stick-zone span { width: 50px; height: 50px; border-radius: 50%; background: rgba(255,255,255,.46); box-shadow: 0 8px 24px rgba(0,0,0,.25); transform: translate(var(--knob-x, 0), var(--knob-y, 0)); }
.touch-actions { pointer-events: auto; display: grid; grid-template-columns: repeat(2, minmax(58px, 1fr)); gap: 10px; }
.touch-actions button { min-width: 58px; min-height: 52px; border-radius: 18px; border: 1px solid rgba(255,255,255,.22); background: rgba(13, 25, 58, .76); color: white; font-weight: 900; box-shadow: 0 12px 24px rgba(0,0,0,.2); touch-action: manipulation; }
#fireTouch { min-width: 74px; min-height: 74px; border-radius: 50%; background: linear-gradient(135deg, #ffcc5c, #ff5f8f); color: #180f22; }

body[data-game-state="playing"] #startOverlay { display: none; }
body[data-game-state="playing"] .hero-card { display: none; }
body[data-game-state="playing"] .shell { width: min(1400px, 100vw); padding: 0; }
body[data-game-state="playing"] .arena-wrap { min-height: 100vh; border-radius: 0; border: 0; }
body[data-game-state="playing"] #gameCanvas { height: 100vh; min-height: 100vh; }

@media (max-width: 760px), (pointer: coarse) {
  .shell { width: 100%; padding: 0; }
  .hero-card { border-radius: 0 0 24px 24px; border-left: 0; border-right: 0; }
  .control-copy { grid-template-columns: 1fr; }
  .arena-wrap { border-radius: 24px 24px 0 0; border-left: 0; border-right: 0; }
  #gameCanvas { min-height: 560px; height: calc(100vh - 150px); }
  .touch-ui { display: flex; }
  .hud { inset: 8px 8px auto 8px; gap: 6px; flex-wrap: wrap; }
  .status-stack { width: 160px; }
  .hud-card { min-height: 44px; padding: 7px 9px; border-radius: 14px; min-width: auto; }
  .resource-card { display: none; }
  .weapon-card { max-width: 124px; }
  .hud-card strong { font-size: .95rem; }
  .hud-card span, .hud-card small { font-size: .62rem; }
  .meter { min-height: 31px; }
  .meter span, .meter b { line-height: 31px; font-size: .72rem; }
  .panel { width: calc(100% - 22px); }
}
