:root {
  color-scheme: dark;
  --ink: #f8f5eb;
  --muted: #b8c8c7;
  --night: #071416;
  --panel: rgba(7, 20, 22, 0.9);
  --line: rgba(245, 249, 241, 0.19);
  --aurora: #74d99c;
  --violet: #a88bdc;
  --rescue: #e54f47;
  --amber: #f4c760;
  --ocean: #0d6d7b;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; background: var(--night); color: var(--ink); -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button, a, canvas, .storm-world { touch-action: none; }
button, a, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.game-header { position: relative; z-index: 20; height: 64px; padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); display: flex; align-items: center; gap: 12px; background: rgba(5, 15, 17, 0.97); border-bottom: 1px solid rgba(255,255,255,.12); box-shadow: 0 10px 30px rgba(0,0,0,.32); }
.icon-button { width: 42px; height: 42px; flex: 0 0 42px; display: grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: rgba(255,255,255,.06); color: var(--ink); font-size: 19px; font-weight: 900; text-decoration: none; cursor: pointer; }
.icon-button:hover, .icon-button:focus-visible { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.42); }
.brand-lockup { min-width: 0; display: flex; align-items: center; gap: 10px; }
.brand-lockup > span:last-child { min-width: 0; display: grid; }
.brand-lockup strong { font-family: Georgia, serif; font-size: 17px; line-height: 1; white-space: nowrap; }
.brand-lockup small { margin-top: 4px; color: var(--aurora); font-size: 8px; font-weight: 950; }
.cutter-mark { position: relative; width: 36px; height: 31px; display: block; }
.cutter-mark::before { content: ""; position: absolute; left: 1px; bottom: 1px; width: 34px; height: 13px; background: var(--rescue); border-radius: 3px 3px 14px 14px; clip-path: polygon(0 0,100% 0,80% 100%,20% 100%); }
.cutter-mark::after { content: ""; position: absolute; left: 10px; top: 5px; width: 17px; height: 13px; border: 3px solid #f5f1e8; border-bottom: 0; box-shadow: 6px -5px 0 -4px var(--amber); }
.header-status { margin-left: auto; display: flex; align-items: center; gap: 7px; }
.status-pill { min-width: 60px; height: 42px; padding: 5px 9px; display: grid; align-content: center; border-left: 1px solid var(--line); }
.status-pill small { color: var(--muted); font-size: 8px; font-weight: 900; }
.status-pill b { font-size: 15px; font-variant-numeric: tabular-nums; }

.game-shell { height: calc(100dvh - 64px); min-height: 0; }
.storm-world { position: relative; isolation: isolate; width: 100%; height: 100%; overflow: hidden; background: url("assets/skergardsvaktin-world.webp") center 48% / cover no-repeat; }
.storm-world::before { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(90deg, rgba(3,10,14,.72), rgba(3,10,14,.18) 50%, rgba(3,10,14,.72)); }
.world-shade { position: absolute; inset: 0; z-index: -1; background: linear-gradient(180deg, rgba(2,8,12,.08), rgba(2,8,12,.72)); }
.channel-banner { position: absolute; z-index: 5; top: 14px; left: max(14px, env(safe-area-inset-left)); display: grid; padding: 8px 12px 9px; border-left: 3px solid var(--aurora); background: rgba(5,18,21,.84); backdrop-filter: blur(12px); }
.channel-banner small { color: var(--aurora); font-size: 8px; font-weight: 950; }
.channel-banner strong { font-family: Georgia, serif; font-size: 19px; }
.combat-hud { position: absolute; z-index: 5; top: 14px; right: max(14px, env(safe-area-inset-right)); width: min(610px, calc(100vw - 205px)); height: 54px; display: grid; grid-template-columns: auto minmax(120px,1fr) auto auto auto; align-items: center; gap: 14px; padding: 7px 12px; background: rgba(5,18,21,.84); border: 1px solid rgba(255,255,255,.14); backdrop-filter: blur(12px); }
.combat-hud > span, .enemy-progress > div { display: grid; }
.combat-hud small { color: var(--muted); font-size: 8px; font-weight: 900; }
.combat-hud strong, .enemy-progress b { font-variant-numeric: tabular-nums; }
.lives-readout strong { color: var(--rescue); font-size: 12px; white-space: nowrap; }
.shield-readout strong { color: var(--aurora); font-size: 12px; white-space: nowrap; }
.weapon-readout strong { display: flex; gap: 7px; color: var(--amber); font-size: 9px; white-space: nowrap; }
.weapon-readout b { font: inherit; }
.enemy-progress > div { grid-template-columns: 1fr auto; }
.enemy-progress > i { display: block; height: 5px; margin-top: 5px; overflow: hidden; background: rgba(255,255,255,.14); }
.enemy-progress > i > b { display: block; width: 0; height: 100%; background: var(--violet); transition: width 150ms linear; }

.play-layout { position: absolute; inset: 77px 14px 12px; display: grid; grid-template-columns: minmax(0,1fr); grid-template-rows: minmax(0,1fr) 62px; align-items: center; justify-items: center; gap: 8px; }
.battle-frame { position: relative; height: 100%; max-height: 780px; max-width: calc(100vw - 28px); aspect-ratio: 5 / 7; overflow: hidden; border: 2px solid rgba(246,246,237,.54); border-radius: 6px; background: #061a21; box-shadow: 0 24px 80px rgba(0,0,0,.55), 0 0 0 5px rgba(5,18,22,.32); }
#gameCanvas { display: block; width: 100%; height: 100%; }
.start-overlay { position: absolute; inset: 0; z-index: 8; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 28px; text-align: center; background: rgba(3,15,20,.87); backdrop-filter: blur(8px); }
.start-overlay[hidden] { display: none; }
.start-overlay > small { color: var(--aurora); font-size: 9px; font-weight: 950; }
.start-overlay h1 { margin: 7px 0 6px; font-family: Georgia, serif; font-size: clamp(32px, 5.5vh, 54px); letter-spacing: 0; }
.start-overlay p { max-width: 350px; margin: 0 0 21px; color: #d6e1df; font-size: 14px; line-height: 1.5; }
.radar-emblem { position: relative; width: 84px; height: 84px; margin-bottom: 12px; border: 2px solid rgba(116,217,156,.65); border-radius: 50%; box-shadow: inset 0 0 0 18px rgba(116,217,156,.06); }
.radar-emblem::before, .radar-emblem::after { content: ""; position: absolute; background: rgba(116,217,156,.45); }
.radar-emblem::before { width: 1px; height: 100%; left: 50%; }
.radar-emblem::after { width: 100%; height: 1px; top: 50%; left: 0; }
.radar-emblem i { position: absolute; width: 36px; height: 2px; left: 50%; top: 50%; background: var(--aurora); transform-origin: left; animation: radar-sweep 2.1s linear infinite; }
.primary-command, .secondary-command { min-height: 46px; padding: 0 24px; border: 1px solid transparent; border-radius: 5px; font-size: 12px; font-weight: 950; cursor: pointer; }
.primary-command { background: #fbf8ee; color: #0d1819; box-shadow: 0 7px 0 #c7c0b3; }
.primary-command:active { transform: translateY(4px); box-shadow: 0 3px 0 #c7c0b3; }
.secondary-command { border-color: var(--line); background: rgba(255,255,255,.06); }

.combat-controls { width: 220px; display: grid; grid-template-columns: 50px 1fr 50px; gap: 7px; align-self: center; margin: 0; }
.move-button, .fire-button { height: 56px; padding: 0; border: 1px solid rgba(255,255,255,.27); border-radius: 6px; background: rgba(6,20,22,.87); backdrop-filter: blur(10px); font-weight: 950; }
.move-button { font-size: 24px; }
.fire-button { display: grid; place-items: center; align-content: center; background: var(--rescue); border-color: #ff8179; box-shadow: 0 5px 0 #8f2d2b; }
.fire-button i { font-size: 17px; font-style: normal; line-height: 1; }
.fire-button span { margin-top: 2px; font-size: 8px; }
.move-button:active, .move-button.is-active { background: var(--ocean); transform: scale(.95); }
.fire-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #8f2d2b; }
.fire-button.is-active { background: #e54f47; border-color: #ffd0c7; box-shadow: 0 5px 0 #8f2d2b, 0 0 22px rgba(229,79,71,.34); }
.fire-button:not(.is-active) { background: #304345; border-color: rgba(255,255,255,.22); box-shadow: 0 5px 0 #172629; }
.countdown, .toast { position: absolute; left: 50%; z-index: 7; transform: translateX(-50%); pointer-events: none; text-align: center; font-weight: 950; }
.countdown { top: 43%; font-family: Georgia, serif; font-size: 40px; text-shadow: 0 3px 16px #000; }
.toast { bottom: 10%; min-width: 160px; padding: 8px 14px; background: rgba(5,18,21,.92); color: var(--aurora); font-size: 11px; opacity: 0; transition: opacity 160ms ease; }
.toast.show { opacity: 1; }

.game-dialog { width: min(92vw, 530px); max-height: min(88dvh,730px); padding: 0; border: 1px solid rgba(255,255,255,.22); border-radius: 7px; overflow: auto; background: #102124; color: var(--ink); box-shadow: 0 35px 100px rgba(0,0,0,.66); }
.game-dialog::backdrop { background: rgba(2,8,11,.8); backdrop-filter: blur(7px); }
.dialog-sheet, .result-sheet { position: relative; padding: 30px; }
.dialog-close { position: absolute; top: 12px; right: 12px; width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 5px; background: transparent; font-size: 23px; cursor: pointer; }
.dialog-sheet > small, .result-sheet > small { color: var(--aurora); font-size: 9px; font-weight: 950; }
.dialog-sheet h2, .result-sheet h2 { margin: 5px 0 18px; font-family: Georgia, serif; font-size: 31px; }
.help-sheet ol { padding-left: 22px; color: #d7e2e0; font-size: 14px; line-height: 1.55; }
.help-sheet li { margin: 0 0 11px; padding-left: 5px; }
.help-sheet .primary-command { width: 100%; margin-top: 10px; }
.settings-sheet label { min-height: 54px; display: grid; grid-template-columns: 130px minmax(0,1fr) 50px; align-items: center; gap: 10px; border-top: 1px solid var(--line); font-size: 13px; font-weight: 800; }
.settings-sheet input[type="range"] { width: 100%; accent-color: var(--rescue); }
.settings-sheet output { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.settings-sheet .toggle-row { grid-template-columns: 1fr auto; }
.toggle-row input { position: absolute; opacity: 0; }
.toggle-row i { position: relative; width: 44px; height: 24px; border-radius: 12px; background: #324548; transition: background 160ms ease; }
.toggle-row i::after { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: transform 160ms ease; }
.toggle-row input:checked + i { background: #459a6d; }
.toggle-row input:checked + i::after { transform: translateX(20px); }
.settings-sheet .secondary-command, .settings-sheet .primary-command { width: 100%; margin-top: 12px; }
.result-sheet { text-align: center; }
.result-radar { height: 105px; display: grid; place-items: center; }
.result-radar span { position: relative; width: 84px; height: 84px; border: 2px solid var(--aurora); border-radius: 50%; box-shadow: inset 0 0 0 17px rgba(116,217,156,.08); }
.result-radar span::before, .result-radar span::after { content:""; position:absolute; left:50%; top:50%; background:var(--aurora); }
.result-radar span::before { width:48px; height:2px; transform:translate(-50%,-50%); }
.result-radar span::after { width:2px; height:48px; transform:translate(-50%,-50%); }
.result-sheet p { margin: -7px auto 20px; max-width: 360px; color: var(--muted); line-height: 1.45; }
.result-stats { display: grid; grid-template-columns: repeat(3,1fr); margin: 16px 0 22px; border-block: 1px solid var(--line); }
.result-stats span { display: grid; padding: 13px 8px; }
.result-stats span + span { border-left: 1px solid var(--line); }
.result-stats small { color: var(--muted); font-size: 8px; font-weight: 900; }
.result-stats b { margin-top: 3px; font-size: 20px; font-variant-numeric: tabular-nums; }
.result-sheet .primary-command { width: 100%; }
.primary-command:disabled { opacity: .42; cursor: not-allowed; transform: none; box-shadow: 0 4px 0 #8e8980; }
.upgrade-choice { margin: -4px 0 20px; padding-top: 15px; border-top: 1px solid var(--line); text-align: left; }
.upgrade-choice[hidden] { display: none; }
.upgrade-choice > small { display: block; margin-bottom: 9px; color: var(--amber); font-size: 9px; font-weight: 950; text-align: center; }
.upgrade-choice > div { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.upgrade-button { min-width: 0; min-height: 78px; padding: 10px; display: grid; grid-template-columns: 30px minmax(0,1fr); grid-template-rows: 1fr auto; gap: 2px 8px; align-items: center; border: 1px solid rgba(255,255,255,.2); border-radius: 5px; background: rgba(255,255,255,.055); color: var(--ink); text-align: left; cursor: pointer; }
.upgrade-button > i { grid-row: 1 / 3; display: grid; place-items: center; width: 30px; height: 38px; color: var(--amber); font-size: 25px; font-style: normal; }
.upgrade-button > span { display: grid; }
.upgrade-button strong { font-size: 12px; }
.upgrade-button small { margin-top: 3px; color: var(--muted); font-size: 9px; line-height: 1.25; }
.upgrade-button > b { color: var(--aurora); font-size: 10px; }
.upgrade-button:hover:not(:disabled), .upgrade-button:focus-visible { border-color: var(--amber); background: rgba(244,199,96,.11); }
.upgrade-button.is-selected { border-color: var(--aurora); background: rgba(116,217,156,.13); box-shadow: inset 0 0 0 1px var(--aurora); }
.upgrade-button:disabled:not(.is-selected) { opacity: .42; cursor: not-allowed; }
.upgrade-choice > p { margin: 10px 0 0; color: var(--aurora); font-size: 11px; font-weight: 900; text-align: center; }

@keyframes radar-sweep { to { transform: rotate(360deg); } }

@media (max-width:760px) {
  .game-header { height:58px; gap:7px; padding-block:6px; }
  .game-shell { height:calc(100dvh - 58px); }
  .brand-lockup { gap:7px; }
  .brand-lockup strong { font-size:12px; }
  .brand-lockup small { font-size:6px; }
  .cutter-mark { width:29px; transform:scale(.85); }
  .icon-button { width:38px; height:38px; flex-basis:38px; }
  .header-status { gap:4px; }
  .status-pill { display:none; }
  .header-status .score-pill { display:grid; min-width:48px; height:38px; padding-inline:6px; }
  .channel-banner { top:8px; left:8px; padding:6px 9px; }
  .channel-banner strong { font-size:14px; }
  .combat-hud { top:8px; right:8px; width:calc(100vw - 152px); height:42px; grid-template-columns:minmax(72px,1fr) auto auto auto; gap:6px; padding:5px 7px; }
  .combat-hud > span:first-child { display:none; }
  .combat-hud small { font-size:6px; }
  .combat-hud strong { font-size:10px; }
  .weapon-readout strong { display:grid; gap:0; font-size:7px; }
  .enemy-progress > div small { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .play-layout { inset:58px 6px max(6px,env(safe-area-inset-bottom)); grid-template-columns:1fr; grid-template-rows:minmax(0,1fr) 72px; gap:4px; }
  .battle-frame { width:auto; height:100%; max-width:100%; max-height:100%; }
  .combat-controls { width:min(100%,280px); grid-template-columns:60px 1fr 60px; gap:8px; margin:3px 0 0; }
  .move-button, .fire-button { height:56px; }
  .start-overlay { padding:19px; }
  .radar-emblem { width:66px; height:66px; margin-bottom:8px; }
  .start-overlay h1 { font-size:32px; }
  .start-overlay p { font-size:12px; }
}

@media (max-width:380px) {
  .brand-lockup small { display:none; }
  .combat-hud { width:calc(100vw - 134px); }
  .shield-readout { display:none !important; }
  .combat-hud { grid-template-columns:1fr auto auto; }
  .weapon-readout strong { font-size:6px; }
}

@media (max-width:520px) {
  .upgrade-choice > div { grid-template-columns:1fr; }
  .upgrade-button { min-height:66px; }
}

@media (orientation:landscape) and (max-height:650px) {
  .game-header { height:50px; padding-block:4px; }
  .game-shell { height:calc(100dvh - 50px); }
  .status-pill { height:36px; }
  .icon-button { width:36px; height:36px; flex-basis:36px; }
  .channel-banner { top:7px; }
  .combat-hud { top:7px; height:42px; }
  .play-layout { inset:55px 9px 7px; grid-template-columns:minmax(0,1fr) 145px; grid-template-rows:1fr; gap:9px; }
  .battle-frame { width:auto; height:100%; max-width:calc(100vw - 175px); }
  .combat-controls { width:142px; grid-template-columns:43px 1fr 43px; gap:5px; align-self:center; margin:0; }
  .move-button, .fire-button { height:50px; }
}

@media (hover:hover) and (pointer:fine) {
  .move-button:hover { border-color:var(--aurora); background:rgba(6,31,34,.96); }
  .fire-button:hover { filter:brightness(1.1); }
}

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