:root {
  color-scheme: dark;
  --bg: #05070d;
  --panel: #090d16;
  --ink: #edf2f7;
  --muted: #8290a3;
  --red: #e12b38;
  --blue: #2376ac;
  --line: rgba(179, 197, 216, 0.22);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #020307;
  color: var(--ink);
  font-family: "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

button { font: inherit; }
.desktop-hint { display: none; }

#game-shell {
  width: 100dvw;
  height: 100dvh;
  min-height: 260px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) clamp(74px, 19dvh, 128px);
  overflow: hidden;
  background: var(--bg);
}

#viewport {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #050914;
  isolation: isolate;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  place-content: center;
  justify-items: center;
  padding: clamp(16px, 4vw, 48px);
  text-align: center;
  background:
    radial-gradient(circle at 50% 45%, rgba(23, 38, 57, 0.58), transparent 45%),
    linear-gradient(90deg, rgba(2, 4, 9, 0.96), rgba(5, 8, 14, 0.76), rgba(2, 4, 9, 0.96));
}

.screen.active { display: grid; }

.eyebrow {
  margin: 0 0 8px;
  color: #97a7ba;
  font-size: clamp(9px, 1.2vw, 13px);
  font-weight: 700;
  letter-spacing: 0.28em;
}

h1, h2 { margin: 0; line-height: 0.92; letter-spacing: 0.08em; }
h1 { font-size: clamp(44px, 10vw, 104px); font-weight: 900; }
h1 span, #result-screen.fail h2 { color: var(--red); }
h2 { font-size: clamp(26px, 5vw, 58px); }

.tagline {
  margin: 14px 0 22px;
  color: #aab5c2;
  font-size: clamp(13px, 2vw, 18px);
  letter-spacing: 0.16em;
}

.primary-button {
  min-width: 190px;
  min-height: 48px;
  padding: 11px 34px;
  border: 1px solid rgba(255, 90, 99, 0.65);
  border-radius: 3px;
  color: white;
  background: linear-gradient(135deg, #8d1824, #d92a37);
  box-shadow: 0 0 26px rgba(211, 29, 47, 0.24);
  font-weight: 900;
  font-size: 16px;
  letter-spacing: 0.18em;
  cursor: pointer;
}

.primary-button:active { transform: scale(0.97); }
.best-line { margin: 14px 0 0; color: var(--muted); font-size: 11px; letter-spacing: 0.15em; }
.best-line strong { color: #d7e0ea; margin-left: 7px; }

.target-card {
  display: grid;
  grid-template-columns: clamp(92px, 17vw, 150px) minmax(180px, 320px);
  align-items: center;
  gap: clamp(14px, 3vw, 28px);
  margin: clamp(12px, 3vh, 26px) 0;
  padding: 12px 20px 12px 12px;
  border: 1px solid var(--line);
  background: rgba(5, 10, 18, 0.75);
  text-align: left;
}

#portrait-canvas { width: 100%; height: auto; border: 1px solid rgba(210, 225, 240, 0.12); background: #101925; }
.target-card strong { display: block; margin: 5px 0 9px; color: #ff5160; font-size: clamp(18px, 3vw, 28px); letter-spacing: 0.08em; }
.target-card p { margin: 0; color: #aab4c2; font-size: clamp(10px, 1.5vw, 13px); line-height: 1.65; }
.hud-label { display: block; color: #738296; font-size: 9px; font-weight: 800; letter-spacing: 0.18em; }

#hud { position: absolute; inset: 0; z-index: 5; pointer-events: none; }
#hud.hidden, .hidden { display: none !important; }
.hud-block { position: absolute; top: max(12px, env(safe-area-inset-top)); text-shadow: 0 1px 4px #000; }
.hud-block strong { display: block; margin-top: 3px; font-size: clamp(12px, 1.8vw, 18px); letter-spacing: 0.08em; }
.wind-panel { left: max(14px, env(safe-area-inset-left)); }
.time-panel { left: 50%; transform: translateX(-50%); text-align: center; }
.ammo-panel { right: max(14px, env(safe-area-inset-right)); text-align: right; }
.ammo-panel strong { color: #ff5965; }

.breath-meter { position: absolute; left: max(14px, env(safe-area-inset-left)); bottom: 13px; width: clamp(112px, 19vw, 210px); font-size: 8px; letter-spacing: 0.15em; color: #9aacbd; }
.breath-meter i { display: block; height: 4px; margin-top: 4px; overflow: hidden; background: rgba(255,255,255,0.13); }
.breath-meter b { display: block; width: 100%; height: 100%; background: #48a9dd; transform-origin: left; }
.breath-meter.exhausted b { background: #e54853; }

#controls {
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(210px, 1fr) clamp(115px, 19vw, 210px) clamp(105px, 17vw, 190px);
  gap: clamp(8px, 1.5vw, 16px);
  padding: 8px max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  border-top: 1px solid rgba(118, 143, 167, 0.18);
  background: linear-gradient(#0c111b, #060910);
  touch-action: none;
}

.aim-pad, .control-button {
  position: relative;
  min-height: 54px;
  overflow: hidden;
  border: 1px solid rgba(154, 176, 197, 0.22);
  border-radius: 5px;
  color: #cad5e0;
  background: rgba(21, 31, 43, 0.72);
  touch-action: none;
}

.aim-pad { cursor: grab; }
.aim-pad.active { cursor: grabbing; background: rgba(30, 44, 59, 0.9); }
.control-label { position: absolute; top: 7px; left: 10px; color: #77889a; font-size: 9px; font-weight: 800; letter-spacing: 0.16em; }
.pad-mark { position: absolute; inset: 50% auto auto 50%; width: 34px; height: 34px; transform: translate(-50%, -42%); opacity: 0.45; }
.pad-mark i:first-child { position: absolute; top: 16px; left: 0; width: 100%; border-top: 1px solid #93a7ba; }
.pad-mark i:last-child { position: absolute; left: 16px; top: 0; height: 100%; border-left: 1px solid #93a7ba; }

.control-button { font-size: clamp(12px, 2vw, 18px); font-weight: 900; letter-spacing: 0.1em; cursor: pointer; }
.control-button span { display: block; font-size: 9px; opacity: 0.68; }
.breath-button { border-color: rgba(49, 136, 188, 0.55); background: linear-gradient(145deg, #10283a, #164d6e); }
.breath-button.active { color: white; background: #1977a8; box-shadow: inset 0 0 22px rgba(151, 224, 255, 0.25); }
.breath-button.exhausted { border-color: #a4323d; background: #4b1820; }
.fire-button { border-color: rgba(255, 72, 83, 0.72); color: white; background: linear-gradient(145deg, #781722, #d52734); box-shadow: inset 0 0 20px rgba(255,255,255,0.05), 0 0 16px rgba(210, 26, 44, 0.12); font-size: clamp(16px, 2.5vw, 23px); }
.fire-button:active { transform: scale(0.97); }
.control-button:disabled { opacity: 0.35; filter: grayscale(0.7); }

@media (pointer: fine) {
  .desktop-hint {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    min-height: 18px;
    padding: 2px 6px;
    border: 1px solid rgba(218, 230, 241, 0.35);
    border-bottom-width: 2px;
    border-radius: 3px;
    color: #e8f0f8;
    background: rgba(2, 5, 10, 0.5);
    font-family: inherit;
    font-size: 8px;
    font-weight: 900;
    line-height: 1;
    letter-spacing: 0.1em;
    vertical-align: middle;
  }
  .aim-key { position: absolute; top: 7px; right: 10px; }
  .control-button .desktop-hint { margin: 5px auto 0; }
  .primary-button .desktop-hint { margin-left: 8px; }
}

#flash { position: absolute; inset: 0; z-index: 12; pointer-events: none; opacity: 0; background: white; }
#flash.fire { animation: muzzle-flash 150ms ease-out; }
#flash.hit { animation: hit-flash 420ms ease-out; }
@keyframes muzzle-flash { 0% { opacity: .8; } 100% { opacity: 0; } }
@keyframes hit-flash { 0% { opacity: .85; background: white; } 32% { opacity: .38; background: #f2263a; } 100% { opacity: 0; } }

.impact-label { position: absolute; z-index: 14; transform: translate(-50%, -125%); padding: 3px 7px; border: 1px solid #ff4350; color: #fff; background: rgba(142, 13, 28, 0.86); font-size: 9px; font-weight: 900; letter-spacing: .13em; pointer-events: none; }

#result-screen { background: linear-gradient(90deg, rgba(2,4,8,.97), rgba(6,10,17,.8), rgba(2,4,8,.97)); }
.result-reason { margin: 10px 0 15px; color: #a8b4c2; font-weight: 700; letter-spacing: .18em; }
.score-row { display: flex; gap: 1px; margin-bottom: 8px; background: rgba(160,180,200,.18); }
.score-row div { min-width: clamp(120px, 22vw, 210px); padding: 8px 20px; background: rgba(5,9,16,.95); }
.score-row span { display: block; color: #758497; font-size: 8px; letter-spacing: .18em; }
.score-row strong { display: block; margin-top: 2px; font-size: clamp(21px, 4vw, 36px); }
.breakdown { min-height: 15px; margin: 0 0 14px; color: #8493a4; font-size: 10px; letter-spacing: .07em; }

#rotate-hint { display: none; }

@media (pointer: fine) and (min-width: 900px) {
  #game-shell { grid-template-rows: minmax(0, 1fr) 86px; }
  #controls { grid-template-columns: 1fr 190px 170px; }
}

@media (max-height: 430px) {
  .screen { padding: 8px 18px; }
  .target-card { margin: 7px 0; padding: 7px 14px 7px 7px; grid-template-columns: 76px minmax(170px, 300px); }
  h1 { font-size: clamp(40px, 12vh, 70px); }
  h2 { font-size: clamp(24px, 8vh, 38px); }
  .tagline { margin: 7px 0 10px; }
  .primary-button { min-height: 40px; padding: 7px 25px; }
  .best-line { margin-top: 7px; }
}

@media (orientation: portrait) and (max-width: 700px) {
  #rotate-hint {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-content: center;
    gap: 14px;
    text-align: center;
    background: #050811;
    color: #c7d1dc;
    letter-spacing: .1em;
  }
  #rotate-hint span { font-size: 48px; color: #d62b38; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; }
}
