/* Layout: full-bleed WebGL canvas, HUD pinned to safe-area corners, overlays centred over a dimmed scene */
:root {
  --ink: #05060a;
  --panel: rgba(8, 10, 16, 0.78);
  --bone: #e8e2d2;
  --fog: #8d95a6;
  --ecto: #7dffcf;
  --ember: #ff8a2a;
  --blood: #d62b40;
  --display: 'Pirata One', 'Iowan Old Style', Georgia, serif;
  --hud: 'Chakra Petch', 'Avenir Next Condensed', 'Arial Narrow', system-ui, sans-serif;
  color-scheme: dark;
}

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--ink);
  color: var(--bone);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: var(--hud);
}

#game { position: fixed; inset: 0; }
#game canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
body.playing #game canvas { cursor: none; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 7; } /* above touch controls; only its buttons take taps */
.label {
  font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--fog); font-weight: 500;
}
.big { font-size: 34px; line-height: 1; font-weight: 700; font-variant-numeric: tabular-nums; text-shadow: 0 0 18px rgba(125,255,207,0.35); }
.small { font-size: 13px; color: var(--fog); margin-top: 4px; font-variant-numeric: tabular-nums; }

.hud-top-left, .hud-top-right, .hud-bottom-left, .hud-bottom-right { position: absolute; }
.hud-top-left { top: calc(16px + env(safe-area-inset-top, 0px)); left: calc(18px + env(safe-area-inset-left, 0px)); }
.hud-top-right { top: calc(16px + env(safe-area-inset-top, 0px)); right: calc(18px + env(safe-area-inset-right, 0px)); text-align: right; }
.hud-bottom-left { bottom: calc(18px + env(safe-area-inset-bottom, 0px)); left: calc(18px + env(safe-area-inset-left, 0px)); }
.hud-bottom-right { bottom: calc(18px + env(safe-area-inset-bottom, 0px)); right: calc(18px + env(safe-area-inset-right, 0px)); text-align: right; }

.pause-btn {
  pointer-events: auto; margin-top: 10px;
  background: rgba(0,0,0,0.35); color: var(--bone); border: 1px solid rgba(232,226,210,0.25);
  font: 700 13px var(--hud); width: 38px; height: 34px; border-radius: 6px; letter-spacing: 0.1em;
}

.bar { width: min(240px, 42vw); height: 10px; margin-top: 6px; background: rgba(255,255,255,0.08); border: 1px solid rgba(232,226,210,0.2); border-radius: 2px; overflow: hidden; }
.bar-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #3ad1a0, var(--ecto)); box-shadow: 0 0 12px var(--ecto); transition: width 0.15s; }
.bar-fill.low { background: linear-gradient(90deg, #8f1b2b, var(--blood)); box-shadow: 0 0 12px var(--blood); }

.shells { display: flex; gap: 5px; justify-content: flex-end; margin-top: 6px; }
.shells i { width: 9px; height: 22px; border-radius: 2px 2px 1px 1px; background: var(--ecto); box-shadow: 0 0 8px var(--ecto); display: block; transition: opacity 0.1s, transform 0.1s; }
.shells i.spent { opacity: 0.14; box-shadow: none; transform: scaleY(0.8); }
#hudAmmoLabel.reloading { color: var(--ember); }

.crosshair { position: absolute; left: 50%; top: 50%; width: 0; height: 0; }
.crosshair i { position: absolute; background: rgba(232,226,210,0.85); box-shadow: 0 0 4px rgba(0,0,0,0.8); transition: transform 0.08s; }
.crosshair i:nth-child(1) { width: 2px; height: 8px; left: -1px; top: -16px; }
.crosshair i:nth-child(2) { width: 2px; height: 8px; left: -1px; top: 8px; }
.crosshair i:nth-child(3) { width: 8px; height: 2px; left: -16px; top: -1px; }
.crosshair i:nth-child(4) { width: 8px; height: 2px; left: 8px; top: -1px; }
.crosshair.kick i:nth-child(1) { transform: translateY(-5px); }
.crosshair.kick i:nth-child(2) { transform: translateY(5px); }
.crosshair.kick i:nth-child(3) { transform: translateX(-5px); }
.crosshair.kick i:nth-child(4) { transform: translateX(5px); }

.hitmarker { position: absolute; left: 50%; top: 50%; width: 26px; height: 26px; margin: -13px 0 0 -13px; opacity: 0; }
.hitmarker::before, .hitmarker::after { content: ""; position: absolute; left: 12px; top: -2px; width: 2px; height: 30px; background: var(--bone); transform: rotate(45deg); }
.hitmarker::after { transform: rotate(-45deg); }
.hitmarker.show { animation: hit 0.22s ease-out; }
.hitmarker.crit::before, .hitmarker.crit::after { background: var(--ember); }
@keyframes hit { 0% { opacity: 1; transform: scale(0.7); } 100% { opacity: 0; transform: scale(1.25); } }

.banner { position: absolute; left: 0; right: 0; top: 26%; text-align: center; opacity: 0; transition: opacity 0.5s; padding-inline: 20px; }
.banner.show { opacity: 1; }
.banner-title { font-family: var(--display); font-size: clamp(44px, 9vw, 86px); color: var(--bone); text-shadow: 0 0 30px rgba(125,255,207,0.45), 0 3px 0 rgba(0,0,0,0.6); line-height: 1; }
.banner-sub { margin-top: 10px; font-size: 13px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--fog); }

#vignette { position: fixed; inset: 0; pointer-events: none; z-index: 4; opacity: 0; background: radial-gradient(ellipse at center, transparent 45%, rgba(170, 10, 30, 0.75) 100%); transition: opacity 0.25s; }

/* ---------- Touch ---------- */
#touch { position: fixed; inset: 0; z-index: 6; }
#touchLayer { position: absolute; inset: 0; }
#joyBase { position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; border: 1.5px solid rgba(232,226,210,0.25); background: rgba(0,0,0,0.2); display: none; pointer-events: none; }
#joyKnob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(232,226,210,0.3); }
.tbtn {
  position: absolute; border-radius: 50%; border: 1.5px solid rgba(125,255,207,0.5);
  background: rgba(10, 30, 24, 0.45); color: var(--bone); font: 700 14px var(--hud); letter-spacing: 0.12em;
  touch-action: none;
}
.tbtn:active, .tbtn.down { background: rgba(125,255,207,0.3); }
#btnFire { width: 92px; height: 92px; right: calc(26px + env(safe-area-inset-right, 0px)); bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
#btnReload { width: 54px; height: 54px; right: calc(132px + env(safe-area-inset-right, 0px)); bottom: calc(150px + env(safe-area-inset-bottom, 0px)); font-size: 16px; }
#btnJump { width: 62px; height: 62px; right: calc(128px + env(safe-area-inset-right, 0px)); bottom: calc(70px + env(safe-area-inset-bottom, 0px)); font-size: 11px; }
body.touch .hud-bottom-right { bottom: calc(200px + env(safe-area-inset-bottom, 0px)); }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 16px;
  background: radial-gradient(ellipse at 50% 40%, rgba(5,6,10,0.25), rgba(5,6,10,0.85));
}
.panel { max-width: 460px; width: 100%; text-align: left; }
.panel.compact { text-align: center; max-width: 380px; }
.eyebrow { font-size: 12px; letter-spacing: 0.24em; text-transform: uppercase; color: var(--ember); }
h1, h2 { font-family: var(--display); font-weight: 400; margin: 6px 0 10px; line-height: 0.95; text-wrap: balance; }
h1 { font-size: clamp(60px, 16vw, 104px); text-shadow: 0 0 40px rgba(125,255,207,0.35); }
h2 { font-size: clamp(40px, 10vw, 60px); }
.lede { font-size: 15px; line-height: 1.55; color: #c9c4b6; max-width: 40ch; margin: 0 0 22px; }
.cta {
  font: 700 15px var(--hud); letter-spacing: 0.14em; text-transform: uppercase;
  color: #04110c; background: var(--ecto); border: 0; border-radius: 4px; padding: 15px 26px; cursor: pointer;
  box-shadow: 0 0 28px rgba(125,255,207,0.45);
}
.cta:hover { filter: brightness(1.08); }
.cta:focus-visible, .pause-btn:focus-visible { outline: 2px solid var(--bone); outline-offset: 3px; }
.controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 18px; margin-top: 26px; font-size: 13px; color: var(--fog); }
kbd { font: 700 11px var(--hud); color: var(--bone); border: 1px solid rgba(232,226,210,0.3); border-radius: 3px; padding: 2px 6px; margin-right: 6px; }
.best { margin-top: 18px; font-size: 13px; color: var(--fog); font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0 6px; }
.stats b { display: block; font-size: 28px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.panel.compact .cta { margin-top: 18px; }

.loading { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: var(--ink); font-family: var(--display); font-size: 34px; color: var(--fog); transition: opacity 0.6s; }
.loading.done { opacity: 0; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  .banner, .bar-fill, #vignette { transition: none; }
}

/* ---------- Radar, map, threats ---------- */
.hud-top-left { display: flex; gap: 12px; align-items: flex-start; }
#radar { width: 150px; height: 150px; border-radius: 50%; pointer-events: auto; cursor: pointer; flex: none; }
body.touch #radar { width: 112px; height: 112px; }
.wave-info { padding-top: 4px; }
.wave-line { display: flex; align-items: baseline; gap: 6px; }
.hud-btns { display: flex; gap: 6px; justify-content: flex-end; margin-top: 10px; }
.hud-btns .pause-btn { margin-top: 0; width: auto; min-width: 38px; padding-inline: 8px; }

#bossBar { position: absolute; left: 50%; transform: translateX(-50%); top: calc(18px + env(safe-area-inset-top, 0px)); width: min(420px, 46vw); text-align: center; }
.boss-name { font-family: var(--display); font-size: 24px; color: #ffd0f0; text-shadow: 0 0 16px rgba(255,122,217,0.6); }
.bar.boss { width: 100%; height: 8px; }
.bar.boss .bar-fill { background: linear-gradient(90deg, #8a1f6a, #ff7ad9); box-shadow: 0 0 12px #ff7ad9; }
body.touch #bossBar { top: calc(132px + env(safe-area-inset-top, 0px)); width: 70vw; }

#dmgRing { position: absolute; left: 50%; top: 50%; width: 0; height: 0; }
.dmg-arc {
  position: absolute; left: -120px; top: -120px; width: 240px; height: 240px; border-radius: 50%;
  border-top: 7px solid rgba(214, 43, 64, 0.95); border-left: 7px solid transparent; border-right: 7px solid transparent; border-bottom: 7px solid transparent;
  filter: drop-shadow(0 0 8px rgba(214,43,64,0.9)); animation: arcFade 1.3s ease-out forwards;
}
@keyframes arcFade { 0% { opacity: 1; } 60% { opacity: 0.85; } 100% { opacity: 0; } }
#edgeWarn { position: absolute; inset: 0; }
.chev { position: absolute; left: 0; top: 0; width: 28px; height: 28px; opacity: 0; transform-origin: 14px 14px; --c: #7dffcf; }
.chev::before { content: ""; position: absolute; left: 4px; top: 2px; border-left: 10px solid transparent; border-right: 10px solid transparent; border-bottom: 16px solid var(--c); filter: drop-shadow(0 0 6px var(--c)); }
.chev::after { content: ""; position: absolute; left: 9px; top: 18px; width: 10px; height: 4px; background: var(--c); border-radius: 2px; opacity: 0.6; }
#threatText { position: absolute; left: 0; right: 0; top: calc(50% + 44px); text-align: center; font-size: 13px; letter-spacing: 0.3em; text-transform: uppercase; color: #ff6a7a; text-shadow: 0 0 10px rgba(214,43,64,0.9); opacity: 0; transition: opacity 0.2s; }
#threatText.show { opacity: 1; }
.banner-roster { margin-top: 12px; display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; font-size: 13px; letter-spacing: 0.08em; }
.banner-roster span { display: inline-flex; align-items: center; gap: 6px; }
.banner-roster i, .legend .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; box-shadow: 0 0 8px currentColor; }

#mapOverlay { position: fixed; inset: 0; z-index: 8; display: grid; place-items: center; background: rgba(3,4,8,0.55); padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 16px; }
.map-wrap { width: min(560px, 92vw, 78vh); }
.map-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.map-head .pause-btn { margin-top: 0; width: auto; padding-inline: 12px; pointer-events: auto; }
#mapCanvas { width: 100%; aspect-ratio: 1; max-width: 100%; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: center; margin-top: 10px; font-size: 12px; color: var(--fog); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot.you { background: var(--bone); color: var(--bone); }
.dot.wisp { background: #9fe6ff; color: #9fe6ff; }
.dot.wraith { background: #7dffcf; color: #7dffcf; }
.dot.banshee { background: #c49aff; color: #c49aff; }
.dot.queen { background: #ff7ad9; color: #ff7ad9; }
.legend .ring { width: 10px; height: 10px; border-radius: 50%; border: 1.5px dashed var(--bone); display: inline-block; }

/* ---------- Campaign screens ---------- */
.cta-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.cta-row.center { justify-content: center; }
.cta.ghost-btn { background: transparent; color: var(--ecto); box-shadow: inset 0 0 0 1.5px var(--ecto); }
.text-btn { background: none; border: 0; color: var(--fog); font: 500 14px var(--hud); letter-spacing: 0.1em; text-transform: uppercase; padding: 12px 6px; cursor: pointer; }
.text-btn:hover { color: var(--bone); }
.panel.wide { max-width: 560px; }
.overlay { overflow-y: auto; }
.chapters { list-style: none; padding: 0; margin: 18px 0 10px; display: grid; gap: 8px; }
.chapters button {
  width: 100%; display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 12px; align-items: center; text-align: left;
  background: rgba(232,226,210,0.04); border: 1px solid rgba(232,226,210,0.14); border-radius: 6px; padding: 12px 14px; color: var(--bone); cursor: pointer; font-family: var(--hud);
}
.chapters button:hover:not(:disabled) { border-color: var(--ecto); background: rgba(125,255,207,0.07); }
.chapters button:disabled { opacity: 0.38; cursor: not-allowed; }
.chapters .ch-num { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ember); }
.chapters .ch-name { font-family: var(--display); font-size: 24px; line-height: 1.05; }
.chapters .ch-time { font-size: 12px; color: var(--fog); font-variant-numeric: tabular-nums; }
.chapters .ch-state { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--fog); }
.chapters .ch-state.done { color: var(--ecto); }
.objective { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.objective b { font-size: 15px; }
.wave-plan { list-style: none; padding: 0; margin: 0 0 22px; display: grid; gap: 6px; font-size: 13px; color: #c9c4b6; }
.wave-plan li { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.wave-plan .wn { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--fog); width: 56px; }
.wave-plan span.g { display: inline-flex; align-items: center; gap: 5px; }
.wave-plan i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.small-lede { font-size: 14px; margin: 14px auto 6px; }

/* ---------- Weapons ---------- */
.slots { display: flex; gap: 6px; justify-content: flex-end; margin-bottom: 6px; flex-wrap: wrap; }
.slots span { font-size: 11px; letter-spacing: 0.08em; padding: 3px 7px; border-radius: 3px; border: 1px solid rgba(232,226,210,0.18); color: var(--fog); background: rgba(0,0,0,0.3); font-variant-numeric: tabular-nums; }
.slots span.on { color: #04110c; background: var(--wc, var(--ecto)); border-color: transparent; }
.weapon-name { font-family: var(--display); font-size: 22px; line-height: 1; color: var(--wc, var(--bone)); text-shadow: 0 0 12px rgba(0,0,0,0.8); }
.ammo-row { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin: 6px 0 4px; min-height: 22px; }
.ammo-num { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--wc, var(--bone)); }
.ammo-num small { font-size: 13px; color: var(--fog); font-weight: 500; margin-left: 3px; }
.shells { margin-top: 0; }
.shells i { background: var(--wc, var(--ecto)); box-shadow: 0 0 8px var(--wc, var(--ecto)); }
#toast { position: absolute; left: 50%; top: 64%; transform: translate(-50%, 8px); padding: 8px 14px; border-radius: 4px; background: rgba(6,10,14,0.75); border: 1px solid rgba(232,226,210,0.2); font-size: 14px; letter-spacing: 0.06em; opacity: 0; transition: opacity 0.25s, transform 0.25s; white-space: nowrap; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast b { color: var(--wc, var(--ecto)); }
#btnSwap { width: 58px; height: 58px; right: calc(28px + env(safe-area-inset-right, 0px)); bottom: calc(200px + env(safe-area-inset-bottom, 0px)); font-size: 11px; }
body.touch .hud-bottom-right { bottom: calc(272px + env(safe-area-inset-bottom, 0px)); }
.legend .diamond { width: 8px; height: 8px; background: #ffd25a; transform: rotate(45deg); display: inline-block; }
.unlock { display: grid; gap: 4px; margin: 14px auto 0; padding: 12px 14px; border: 1px solid rgba(255,200,96,0.5); border-radius: 6px; background: rgba(255,200,96,0.08); max-width: 320px; }
.unlock b { font-family: var(--display); font-weight: 400; font-size: 30px; color: #ffc860; line-height: 1; }
.unlock span:last-child { font-size: 13px; color: #c9c4b6; line-height: 1.45; }

/* ---------- Linear route objective ---------- */
#objective { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); display: flex; align-items: center; gap: 10px; padding: 7px 14px 7px 10px; border-radius: 999px; background: rgba(6,10,14,0.62); border: 1px solid rgba(255,216,144,0.35); font-size: 13px; letter-spacing: 0.08em; white-space: nowrap; }
#objArrow { width: 0; height: 0; border-left: 7px solid transparent; border-right: 7px solid transparent; border-bottom: 13px solid #ffd890; filter: drop-shadow(0 0 6px rgba(255,216,144,0.8)); transition: transform 0.1s linear; }
#objDist { color: var(--fog); font-variant-numeric: tabular-nums; }
#objective.fight { border-color: rgba(214,43,64,0.6); color: #ffb0b8; }
#objective.fight #objArrow { display: none; }

body.touch #objective { bottom: auto; top: calc(132px + env(safe-area-inset-top, 0px)); font-size: 12px; }
body.touch #bossBar { top: calc(170px + env(safe-area-inset-top, 0px)); }
.legend .star { width: 9px; height: 9px; background: #ffd890; clip-path: polygon(50% 0, 61% 38%, 100% 38%, 68% 60%, 80% 100%, 50% 75%, 20% 100%, 32% 60%, 0 38%, 39% 38%); display: inline-block; }
