:root {
  --hw-gold: #e0b840; --hw-red: #e05038;
  --hw-panel-top: #43433a; --hw-panel-bot: #2a2a24;
  --hw-edge-lo: #1c1c17; --hw-edge-hi: #7a7a6e;
  --accent: var(--hw-gold);          /* faction accent, retinted on pick */
  --scan: rgba(0, 0, 0, 0.16);
}
body[data-side="srp"] { --accent: var(--hw-red); }

html, body {
  margin: 0; padding: 0;
  background: #000;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: "Lucida Console", Monaco, monospace;
}

#wrap {
  position: relative;
  width: 100vw; height: 100vh;
  display: flex; align-items: center; justify-content: center;
  touch-action: none;
}

#screen {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: none;
  /* keep 16:10 of 640x400, integer-ish scale to fit */
  width: min(100vw, 160vh);
  height: min(62.5vw, 100vh);
  background: #000;
  /* the game handles all touch gestures itself — no browser pan/zoom,
     no long-press callout, no text selection */
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}

/* mobile browsers: size against the DYNAMIC viewport, so the canvas isn't
   cropped while the address bar is still showing (100vh is the large
   viewport on iOS Safari) */
@supports (height: 100dvh) {
  #wrap { height: 100dvh; }
  #screen {
    width: min(100vw, 160dvh);
    height: min(62.5vw, 100dvh);
  }
}

/* touch devices: the "minimal-ui" scroll shim. Mobile browsers only collapse
   their address bar in response to a real page scroll — so keep the document
   exactly one bar-height taller than the visible viewport (100vh is the
   LARGE viewport on mobile, the dynamic viewport is the visible one) and pin
   the game to the visible area with position:fixed. While the bar is
   showing, the page has that much scrollable slack; one swipe (via the
   #swipeHint overlay, whose touches we deliberately DON'T intercept)
   collapses the bar, after which the slack is zero and nothing can scroll —
   the game's own touch handling keeps it locked away. */
@media (pointer: coarse) {
  html, body { height: 100vh; overflow: visible; }
  #wrap {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
  }
  @supports (height: 100dvh) {
    #wrap { width: 100dvw; height: 100dvh; }
  }
}

#swipeHint {
  position: fixed; inset: 0;
  z-index: 30;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px;
  background: rgba(0, 0, 0, 0.78);
  color: #d8d0a8;
  font-size: 14px;
  letter-spacing: 1px;
  text-align: center;
  touch-action: pan-y; /* the whole point: this swipe must scroll the page */
}
#swipeHint.hidden { display: none; }
#swipeHint .chev {
  font-size: 34px;
  color: #e0b840;
  animation: chevUp 1.1s ease-in-out infinite;
}
@keyframes chevUp {
  0%, 100% { transform: translateY(10px); opacity: 0.45; }
  50% { transform: translateY(-10px); opacity: 1; }
}
#swipeHint button { width: auto; padding: 8px 22px; }

.coarseOnly { display: none; }
@media (pointer: coarse) {
  .coarseOnly { display: block; }
}

#rotateHint {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  background: rgba(20, 20, 16, 0.92);
  color: #d8d0a8;
  font-size: 12px;
  letter-spacing: 1px;
  padding: 10px;
  text-align: center;
  pointer-events: none;
}
@media (orientation: portrait) and (max-width: 760px) and (pointer: coarse) {
  #rotateHint { display: block; }
}

.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  /* radial veil: darkest at the panel, lifting at the edges so the living
     backdrop drifts through around the frame */
  background: radial-gradient(ellipse 62% 62% at center, rgba(0, 0, 0, 0.32), rgba(0, 0, 0, 0.66));
  z-index: 10;
  /* panels may scroll on short (landscape phone) screens; the ancestor
     #wrap sets touch-action:none, so re-allow vertical pans here */
  touch-action: pan-y;
}
.hidden { display: none; }
.overlay.hidden { display: none; }

.panel {
  position: relative;
  background-image:
    repeating-linear-gradient(0deg, transparent 0 3px, var(--scan) 3px 4px),
    linear-gradient(180deg, var(--hw-panel-top), var(--hw-panel-bot));
  border: 2px solid var(--hw-edge-lo);
  border-radius: 5px;
  box-shadow:
    0 0 46px rgba(0, 0, 0, 0.85),
    inset 0 1px 0 var(--hw-edge-hi),
    inset 0 -2px 5px var(--hw-edge-lo),
    inset 0 0 34px rgba(0, 0, 0, 0.4),
    0 0 30px -6px var(--accent);          /* faction glow bleed */
  padding: 30px 46px;
  text-align: center;
  color: #d8d0a8;
  max-width: 560px;
  max-height: 94vh;
  overflow-y: auto;
}
/* targeting-frame corner brackets */
.panel::before, .panel::after {
  content: ""; position: absolute; width: 20px; height: 20px;
  pointer-events: none; border: 2px solid var(--accent); opacity: 0.85;
}
.panel::before { top: 7px; left: 7px; border-right: 0; border-bottom: 0; }
.panel::after { bottom: 7px; right: 7px; border-left: 0; border-top: 0; }
@supports (height: 100dvh) {
  .panel { max-height: 94dvh; }
}
.panel.small { padding: 20px 32px; }

h1 {
  margin: 0 0 4px;
  font-size: 34px;
  letter-spacing: 6px;
  color: #e0b840;
  text-shadow: 0 2px 0 #000, 0 0 14px rgba(224, 184, 64, 0.55), 0 0 34px rgba(224, 184, 64, 0.22);
}
/* scanning shimmer rule — a divider in clear space between the header and
   the faction cards (it used to hang off the h1 and struck through the
   subtitle text) */
.menuRule {
  height: 2px; width: 64%;
  margin: 0 auto 16px;
  background: linear-gradient(90deg, transparent, var(--hw-gold), transparent);
  background-size: 220% 100%;
  animation: titleScan 3.6s linear infinite;
  opacity: 0.6;
}
@keyframes titleScan { 0% { background-position: 180% 0; } 100% { background-position: -80% 0; } }
h2 { margin: 0 0 14px; letter-spacing: 4px; color: #e0b840; text-shadow: 0 2px 0 #000, 0 0 11px rgba(224, 184, 64, 0.42); }
.sub { margin: 0 0 12px; font-size: 11px; color: #9a9280; }
.hint { margin: 18px 0 0; font-size: 10px; color: #9a9280; }

/* the main menu gets a tighter panel than the shared overlays */
#menu .panel { max-width: 500px; padding: 26px 40px 20px; }
#menu h1 { margin-bottom: 8px; }
#menu .hint { margin: 11px 0 0; }
#menu .finePrint {
  margin: 15px 0 0; padding-top: 9px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 9px; color: #7d7666;
}
#menuActions { display: flex; gap: 10px; margin: 10px 0 0; }
#menuActions button { flex: 1 1 0; margin: 0; padding: 8px 8px 7px; font-size: 12px; }
.bsub {
  display: block; margin-top: 3px;
  font-size: 9px; letter-spacing: 1px; color: #9a9280;
}
#menuActions button:hover .bsub { color: #c8c0a0; }
#menu #btnInstall { width: auto; margin: 10px auto 0; padding: 8px 22px; font-size: 12px; }

.fineOnly { display: block; }
@media (pointer: coarse) { .fineOnly { display: none; } }

/* short screens (landscape phones): compact the menu so it never scrolls —
   a scrolling panel drags the corner brackets along with the content */
@media (max-height: 480px) {
  #menu .panel { padding: 14px 26px 12px; }
  #menu h1 { font-size: 22px; margin-bottom: 4px; }
  .menuRule { margin-bottom: 9px; }
  .sub { margin-bottom: 9px; }
  .logoSlot, .logoSlot canvas { width: 96px; height: 72px; }
  .faction { padding: 9px 10px 7px; gap: 7px; }
  #menu .hint, #menu .finePrint { display: none; }
}

#factionRow { display: flex; gap: 22px; justify-content: center; margin: 0 0 2px; }
.faction {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 14px 14px 12px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--hw-edge-lo);
  border-radius: 5px;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
}
#pickUdc { --accent: var(--hw-gold); }
#pickSrp { --accent: var(--hw-red); }
.faction:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 6px 20px -6px var(--accent), inset 0 0 22px rgba(0, 0, 0, 0.4);
}
.logoSlot {
  width: 120px; height: 90px; image-rendering: pixelated;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(255, 255, 255, 0.05), rgba(0, 0, 0, 0.35));
  box-shadow: inset 0 0 14px #000;
  border-radius: 3px;
}
.logoSlot canvas { width: 120px; height: 90px; image-rendering: pixelated; }
.fmotto {
  font-size: 8px; letter-spacing: 2px; color: #8a836e; text-transform: uppercase;
  margin-top: -2px;
}

button {
  font-family: inherit;
  font-size: 13px;
  padding: 9px 18px;
  margin: 5px 0;
  background: linear-gradient(180deg, #52524a, #3c3c34);
  color: #d8d0a8;
  border: 2px solid var(--hw-edge-lo);
  border-radius: 3px;
  box-shadow: inset 0 1px 0 var(--hw-edge-hi);
  cursor: pointer;
  display: block;
  width: 100%;
  letter-spacing: 1px;
  transition: box-shadow 0.09s, background 0.09s, color 0.09s, border-color 0.09s;
  touch-action: manipulation; /* no double-tap zoom or tap delay on menus */
}
button:hover {
  background: linear-gradient(180deg, #64645a, #46463c);
  border-color: var(--accent);
  box-shadow: 0 0 13px -2px var(--accent), inset 0 1px 0 var(--hw-edge-hi);
  color: #fff;
}
button:active {
  transform: translateY(1px);
  box-shadow: inset 0 2px 5px var(--hw-edge-lo);
}

#pickUdc button:hover { color: #e0b840; box-shadow: 0 0 14px -2px var(--hw-gold), inset 0 1px 0 var(--hw-edge-hi); border-color: var(--hw-gold); }
#pickSrp button:hover { color: #e05038; box-shadow: 0 0 14px -2px var(--hw-red), inset 0 1px 0 var(--hw-edge-hi); border-color: var(--hw-red); }

#speedRow {
  display: block; font-size: 11px; margin: 8px 0; color: #b8b09a;
}
#speedRow input { width: 100%; }

/* the options panel grew tall — keep it comfortably on one screen */
#pause .panel button { padding: 8px 16px; margin: 4px 0; }
#pause h2 { margin-bottom: 10px; }

/* pause-menu volume sliders */
.volRow {
  display: flex; align-items: center; gap: 10px;
  font-size: 11px; margin: 3px 0; color: #b8b09a; letter-spacing: 1px;
}
.volRow input { flex: 1; min-width: 0; }
#seedLine {
  margin: 9px 0 0; font-size: 9px; color: #7d7666; letter-spacing: 0.5px;
}
/* landscape phones: the options panel is tall — tighten it */
@media (max-height: 520px) {
  .volRow { margin: 1px 0; font-size: 10px; }
  #pause .panel button { padding: 6px 14px; margin: 3px 0; }
  #seedLine { display: none; }
}

/* multiplayer lobby */
#mpSideRow { display: flex; gap: 10px; }
#mpSideRow button { opacity: 0.55; }
#mpSideRow button.sel { opacity: 1; border-color: #e0b840; color: #e0b840; }
#mplobby textarea {
  width: 100%;
  height: 64px;
  box-sizing: border-box;
  background: #0b1108;                 /* phosphor terminal */
  color: #7fe07f;
  border: 2px solid var(--hw-edge-lo);
  border-radius: 3px;
  box-shadow: inset 0 0 12px #000, inset 0 1px 0 rgba(255,255,255,0.04);
  font-family: inherit;
  font-size: 10px;
  resize: none;
  margin: 4px 0;
}
#mpSideRow button.sel { box-shadow: 0 0 12px -2px var(--accent), inset 0 1px 0 var(--hw-edge-hi); }
.mpStep {
  text-align: left;
  font-size: 11px;
  color: #b8b09a;
  margin: 10px 0 2px;
  letter-spacing: 1px;
}
#mpStatus { min-height: 14px; color: #e0b840; }

/* controls reference (from the pause menu / F1) */
#controls .panel { max-width: 640px; }
#controlCols {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 6px 34px;
  text-align: left;
  margin: 0 0 6px;
}
.cgroup h3 {
  margin: 8px 0 6px; font-size: 11px; letter-spacing: 3px;
  color: var(--hw-gold); text-transform: uppercase;
  border-bottom: 1px solid rgba(224, 184, 64, 0.25); padding-bottom: 4px;
}
.ckey {
  display: flex; justify-content: space-between; gap: 14px;
  font-size: 11px; color: #9a9280; padding: 1px 0;
}
.ckey .k { color: #d8d0a8; white-space: nowrap; }
@media (max-height: 480px) {
  #controls .panel { padding: 14px 26px 12px; }
  .ckey { font-size: 10px; }
}

/* the skirmish window: a settings sheet of labeled rows */
#skirmish .panel { max-width: 420px; }
#skSideRow { display: flex; gap: 10px; justify-content: center; margin: 4px 0 12px; }
#skSideRow button { opacity: 0.55; }
#skSideRow button.sel {
  opacity: 1; border-color: var(--accent); color: var(--accent);
  box-shadow: 0 0 12px -2px var(--accent), inset 0 1px 0 var(--hw-edge-hi);
}
#skOpts {
  display: flex; flex-direction: column;
  gap: 7px;
  margin: 0 0 14px; padding: 10px 14px 12px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--hw-edge-lo);
  border-radius: 4px;
  font-size: 11px; color: #b8b09a; letter-spacing: 1px;
}
#skOpts label { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#skOpts select, #skOpts input {
  font-family: inherit; font-size: 11px;
  background: #0b1108; color: #7fe07f;
  border: 1px solid var(--hw-edge-lo); border-radius: 3px;
  padding: 3px 6px;
  min-width: 130px;
}
#skOpts input { width: 130px; }
#btnSkLaunch { width: 100%; }

/* pause / options: sliders in one sheet, utility buttons in a 2-col grid */
.pgroup {
  display: flex; flex-direction: column; gap: 6px;
  margin: 10px 0 12px; padding: 10px 12px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--hw-edge-lo); border-radius: 4px;
}
.pauseGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 8px; }
.pauseGrid button { width: 100%; margin: 0; }

/* mission select: the theater MAP is the whole selector — no ledger. The
   panel is compact (title, map, caption, two buttons) so it fits a phone. */
#missions .panel { display: flex; flex-direction: column; overflow: hidden; }
#missions #theaterMap { flex: 0 0 auto; width: 100%; height: auto; }
#missionsBtns { display: flex; gap: 10px; justify-content: center; margin-top: 10px; }
#missionsBtns button { width: auto; margin: 0; padding: 7px 22px; }
#btnSkirmish { border-left: 3px solid var(--accent); }
@media (max-width: 760px), (max-height: 520px) {
  #missions .panel { padding: 8px 12px 10px; max-width: 96vw; }
  #missions h2 { font-size: 13px; margin: 2px 0 6px; }
  /* the map shrinks to whatever height is left after title/caption/buttons,
     keeping its aspect — the whole panel must fit a phone screen unscrolled */
  #missions #theaterMap { width: auto; max-width: 100%; max-height: 52vh; margin: 0 auto; }
  #theaterCap { font-size: 8px; }
  #missionsBtns { margin-top: 6px; }
  #missionsBtns button { padding: 5px 13px; font-size: 11px; }
}
#missionList button.done .tag { color: #40c040; }
.backBtn { width: auto; margin: 10px auto 0; padding: 7px 26px; }
.brief {
  text-align: left;
  font-size: 12px;
  line-height: 1.75;
  color: #c8c0a0;
  max-height: 46vh;
  overflow-y: auto;
  margin: 0 0 10px;
}
.brief p { margin: 0 0 12px; }
#briefObjective {
  text-align: left;
  font-size: 11px;
  color: #e0b840;
  margin: 0 0 16px;
  letter-spacing: 1px;
  padding: 8px 12px;
  border-left: 3px solid var(--hw-gold);
  background: rgba(224, 184, 64, 0.08);
  border-radius: 0 3px 3px 0;
}

#scoreLines {
  text-align: left;
  font-size: 13px;
  margin: 6px 0 18px;
  line-height: 1.9;
  min-width: 320px;
}
#scoreLines .row {
  display: flex; justify-content: space-between; gap: 40px;
  border-bottom: 1px dotted #4a463c; padding: 2px 0;
}
#scoreLines .val { color: #e0b840; }
#scoreTitle { text-shadow: 0 2px 0 #000, 0 0 16px currentColor; }

/* ---- mission briefing: sitrep teletype + tactical survey ---- */
.panel.briefPanel { max-width: 900px; }
#briefSector {
  color: #8a836e; font-size: 12px; letter-spacing: 3px;
  margin: -8px 0 10px; text-align: left;
}
#briefClass {
  display: inline-block; align-self: flex-start;
  border: 1px solid var(--accent); color: var(--accent);
  padding: 3px 12px; margin: 0 0 12px; float: left;
  font-size: 11px; letter-spacing: 4px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.briefCols { display: flex; gap: 20px; align-items: flex-start; clear: both; }
.briefLeft { flex: 1 1 auto; min-width: 0; text-align: left; }
.briefRight { flex: 0 0 auto; }
#briefMap {
  display: block; border: 1px solid #6a5a28;
  background: #05060a; image-rendering: pixelated;
  box-shadow: inset 0 0 24px rgba(0,0,0,0.6), 0 0 18px -6px var(--accent);
}
#briefMapCap {
  color: #8a836e; font-size: 10px; letter-spacing: 2px;
  margin-top: 6px; text-align: center;
}
#briefIntel { margin-top: 10px; font-size: 12px; color: #b0a880; line-height: 1.7; }
.brief .tt-hid { visibility: hidden; }
.brief .tt-on::after {
  content: '\258C'; color: var(--accent);
  animation: briefBlink 0.7s steps(1) infinite;
}
@keyframes briefBlink { 50% { opacity: 0; } }
@media (max-width: 860px) {
  .briefCols { flex-direction: column-reverse; align-items: center; }
  .briefLeft { width: 100%; }
}

/* ---- theater of war: the campaign map ---- */
#missions .panel { max-width: 740px; }
#theaterMap {
  display: block; margin: 0 auto 6px; max-width: 100%;
  border: 1px solid #6a5a28; background: #070b12;
  box-shadow: inset 0 0 28px rgba(0,0,0,0.65), 0 0 18px -6px var(--accent);
}
#theaterCap {
  color: #8a836e; font-size: 10px; letter-spacing: 2px;
  margin: 0 0 10px; text-align: center; min-height: 13px;
}
