/* Gunship — interface styles.
   Look: a cold, monochrome instrument panel. Black and white do the work; color only carries meaning
   (red = hostile or critical, cyan = friendly, amber = marked target). Titillium Web for everything:
   names, headings, uppercase labels and readouts, hairline rules, corner brackets only on FIRE and Deploy.
   The fonts are bundled in /fonts (SIL Open Font License), so the game stays offline and loads nothing from other sites.
   Layout is mobile first: full-width cards, list rows and bottom sheets, touch targets of 48 px or more.
   One dark look on purpose (it is a night-vision display), so there is no light theme. */
@font-face { font-family: "Titillium Web"; font-weight: 300; font-style: normal; font-display: swap; src: url("../fonts/TitilliumWeb-Light.ttf") format("truetype"); }
@font-face { font-family: "Titillium Web"; font-weight: 400; font-style: normal; font-display: swap; src: url("../fonts/TitilliumWeb-Regular.ttf") format("truetype"); }
@font-face { font-family: "Titillium Web"; font-weight: 500 600; font-style: normal; font-display: swap; src: url("../fonts/TitilliumWeb-SemiBold.ttf") format("truetype"); }
@font-face { font-family: "Titillium Web"; font-weight: 700; font-style: normal; font-display: swap; src: url("../fonts/TitilliumWeb-Bold.ttf") format("truetype"); }

:root {
  --bg: #000;
  --panel: #0a0a0b;
  --panel-2: #131315;
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.3);
  --fg: #f2f3f4;
  --text: #c3c6c9;        /* body copy */
  --dim: #85898d;         /* labels, notes */
  --faint: #55595c;       /* indices, disabled */
  --accent: #f2f3f4;      /* primary actions are inverted white, not colored */
  --accent-ink: #000;
  --ally: #86e0ff;        /* friendly forces */
  --hostile: #ff5a48;     /* enemy forces, critical */
  --target: #ffb648;      /* marked targets (matches the HUD and the editor map) */
  --font-display: "Titillium Web", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Titillium Web", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-body: var(--font-display);
  --touch: 48px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 15px/1.5 var(--font-body);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
  -webkit-touch-callout: none;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
h1, h2, h3 { text-wrap: balance; }

/* ---------------------------------------------------------------- canvases */
#gl, #hud, .aim-layer { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#gl { z-index: 0; }
.aim-layer { z-index: 1; touch-action: none; pointer-events: none; cursor: crosshair; }
body.in-game .aim-layer { pointer-events: auto; }
#hud { z-index: 2; pointer-events: none; }

/* ---------------------------------------------------------------- corner brackets
   Four L-shaped ticks drawn on a pseudo-element, like a sensor's target box.
   --bk-in sets how far outside (negative) or inside (positive) the box they sit, --bk-len their length. */
:is(.ctl-fire, .brief-actions .btn-primary, .deploy-actions .btn-primary)::before {
  --bk: currentColor;
  content: ""; position: absolute; inset: var(--bk-in, 0); pointer-events: none;
  background:
    linear-gradient(var(--bk), var(--bk)) top left / var(--bk-len, 8px) 1px,
    linear-gradient(var(--bk), var(--bk)) top left / 1px var(--bk-len, 8px),
    linear-gradient(var(--bk), var(--bk)) top right / var(--bk-len, 8px) 1px,
    linear-gradient(var(--bk), var(--bk)) top right / 1px var(--bk-len, 8px),
    linear-gradient(var(--bk), var(--bk)) bottom left / var(--bk-len, 8px) 1px,
    linear-gradient(var(--bk), var(--bk)) bottom left / 1px var(--bk-len, 8px),
    linear-gradient(var(--bk), var(--bk)) bottom right / var(--bk-len, 8px) 1px,
    linear-gradient(var(--bk), var(--bk)) bottom right / 1px var(--bk-len, 8px);
  background-repeat: no-repeat;
}

/* ---------------------------------------------------------------- shared controls */
.ico { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: square; stroke-linejoin: miter; flex: none; }
.btn {
  position: relative;
  display: inline-flex; align-items: center; gap: 10px;
  min-height: 52px; padding: 0 20px;
  border: 1px solid var(--line-strong); border-radius: 0;
  background: rgba(0, 0, 0, 0.55);
  font: 400 13px/1 var(--font-mono); letter-spacing: 0.16em; text-transform: uppercase;
  cursor: pointer; transition: border-color .15s, background .15s, color .15s;
}
.btn:hover { border-color: var(--fg); }
.btn:active { background: rgba(255, 255, 255, 0.08); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #fff; border-color: #fff; }
.btn-primary:active { background: #d6d8da; }
.brief-actions .btn-primary::before, .deploy-actions .btn-primary::before { --bk: var(--fg); --bk-in: -6px; --bk-len: 7px; }
.btn-sm { min-height: 44px; padding: 0 14px; font-size: 12px; gap: 8px; }
.btn-danger { color: var(--hostile); border-color: rgba(255, 90, 72, 0.45); }
.btn-danger:hover { border-color: var(--hostile); }
.btn[disabled] { opacity: .35; pointer-events: none; }
.icon-btn {
  position: relative;
  display: inline-grid; place-items: center; flex: none;
  width: var(--touch); height: var(--touch); padding: 0;
  border: 1px solid transparent; border-radius: 0;
  background: none; color: var(--fg); cursor: pointer; transition: border-color .15s, background .15s;
}
.icon-btn:hover { border-color: var(--line-strong); }
.icon-btn:active { background: rgba(255, 255, 255, 0.08); }
.icon-btn[disabled] { opacity: .3; pointer-events: none; }
.icon-sm { width: 44px; height: 44px; }
.minus { display: block; width: 14px; height: 1.5px; background: currentColor; }
:is(.btn, .icon-btn, .tab, .tool, .card-link, .ctl, .seg button, input, select, textarea):focus-visible { outline: 1px solid var(--fg); outline-offset: 3px; }
kbd {
  display: inline-block; min-width: 1.8em; padding: 1px 5px; margin-right: 3px;
  border: 1px solid var(--line-strong);
  font: 400 13px/1.4 var(--font-mono); text-align: center; color: var(--fg);
}
.label, .field > label, .field > .label {
  font: 400 12px/1.2 var(--font-mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim);
}

/* ---------------------------------------------------------------- screens */
.screen { position: fixed; inset: 0; z-index: 5; }
.sheet-screen {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: rgba(0, 0, 0, 0.93);
  padding-block: max(12px, var(--safe-t)) max(24px, var(--safe-b));
  padding-left: max(16px, var(--safe-l)); padding-right: max(16px, var(--safe-r));
  user-select: text; -webkit-user-select: text;
}
.sheet-inner { max-width: 1080px; margin: 0 auto; }
.bar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding-block: 4px 16px; margin-bottom: 20px; border-bottom: 1px solid var(--line);
}
.bar h2 { flex: 1; margin: 0; font: 400 30px/1 var(--font-display); letter-spacing: -0.01em; }
.tabs { display: flex; border: 1px solid var(--line-strong); }
.tab {
  min-height: var(--touch); padding: 0 18px; border: 0; background: none; cursor: pointer;
  font: 400 13px var(--font-mono); letter-spacing: 0.16em; text-transform: uppercase; color: var(--dim);
}
.tab + .tab { border-left: 1px solid var(--line-strong); }
.tab[aria-selected="true"] { background: var(--fg); color: #000; }
@media (max-width: 600px) {
  .tabs { flex: 1 1 100%; }
  .tab { flex: 1; }
}

/* ---------------------------------------------------------------- title */
.title {
  display: flex; align-items: center;
  padding-block: max(24px, var(--safe-t)) max(24px, var(--safe-b));
  padding-left: max(24px, calc(var(--safe-l) + 6vw)); padding-right: max(24px, var(--safe-r));
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.92) 0%, rgba(0, 0, 0, 0.6) 45%, rgba(0, 0, 0, 0.1) 80%),
    radial-gradient(ellipse at 70% 50%, transparent 30%, rgba(0, 0, 0, 0.6) 100%);
}
.title-wrap { display: grid; gap: 36px; width: min(440px, 100%); }
.wordmark {
  margin: 0; font: 500 clamp(58px, 16vw, 128px)/0.86 var(--font-display);
  letter-spacing: -0.03em; text-transform: uppercase; color: var(--fg);
}
.tagline { margin: 18px 0 0; font: 400 13px/1.6 var(--font-mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); }

/* main menu: numbered list rows with a dotted arrow */
.menu { display: grid; width: min(380px, 100%); border-top: 1px solid var(--line); }
.menu .btn {
  justify-content: flex-start; gap: 18px;
  min-height: 62px; padding: 0 2px;
  border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--fg);
  font: 400 21px/1 var(--font-display); letter-spacing: 0; text-transform: none;
}
.menu .btn:hover, .menu .btn:active { background: rgba(255, 255, 255, 0.04); }
.menu-idx { width: 2.4em; font: 400 12px var(--font-mono); letter-spacing: 0.12em; color: var(--faint); }
.menu-arrow { display: inline-flex; margin-left: auto; color: var(--faint); transition: transform .15s, color .15s; }
.menu-arrow .ico, .card-go .ico { stroke-width: 2; stroke-linecap: butt; stroke-dasharray: 1.6 2.4; }
.menu .btn:hover .menu-arrow { color: var(--fg); transform: translateX(4px); }
.menu .btn-primary .menu-idx, .menu .btn-primary .menu-arrow { color: var(--fg); }
.title-readout {
  position: absolute; right: max(24px, var(--safe-r)); bottom: max(20px, var(--safe-b));
  display: flex; gap: 24px; font: 400 12px var(--font-mono); letter-spacing: 0.16em; color: rgba(255, 255, 255, 0.5);
}
@media (orientation: portrait), (max-height: 480px) {
  .title {
    align-items: flex-end; padding-left: max(20px, var(--safe-l)); padding-right: max(20px, var(--safe-r));
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.45) 0%, rgba(0, 0, 0, 0.55) 25%, rgba(0, 0, 0, 0.9) 50%, #000 78%);
  }
  .title-readout { display: none; }
  .menu { width: 100%; }
  .title-wrap { gap: 28px; }
}
@media (max-height: 480px) and (orientation: landscape) {
  .title { align-items: center; background: linear-gradient(90deg, rgba(0, 0, 0, 0.92) 0%, rgba(0, 0, 0, 0.5) 70%, rgba(0, 0, 0, 0.15) 100%); }
  .title-readout { display: none; }
  .title-wrap { grid-template-columns: auto auto; align-items: end; gap: 32px; width: auto; }
  .wordmark { font-size: clamp(52px, 10vw, 92px); }
  .menu { width: 300px; }
  .menu .btn { min-height: 48px; font-size: 18px; }
}

/* ---------------------------------------------------------------- mission cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 12px; }
.card {
  position: relative; display: flex; flex-direction: column; min-width: 0;
  border: 1px solid var(--line); border-radius: 0;
  background: var(--panel); text-align: left; cursor: pointer;
  transition: border-color .15s;
}
.card:focus-within { border-color: var(--fg); }
.card:active { background: var(--panel-2); }
@media (hover: hover) { .card:hover { border-color: var(--line-strong); } }
.card-map { display: block; width: 100%; aspect-ratio: 16 / 9; max-width: 100%; background: #0b0b0c; border-bottom: 1px solid var(--line); }
.card-body { display: grid; gap: 10px; padding: 16px 16px 0; min-width: 0; }
.card h3 { margin: 0; font: 400 23px/1.15 var(--font-display); letter-spacing: -0.005em; }
.card-link { padding: 0; border: 0; background: none; font: inherit; letter-spacing: inherit; text-align: left; cursor: pointer; }
.card-link::after { content: ""; position: absolute; inset: 0; z-index: 1; }
.card-link:focus-visible { outline: 0; }
.card-actions, .grade { position: relative; z-index: 2; }
.card p { margin: 0; color: var(--dim); font-size: 14px; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px;
  margin-top: auto; padding: 14px 16px; border-top: 1px solid var(--line);
  font: 400 12px var(--font-mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); font-variant-numeric: tabular-nums;
}
.card-body + .card-meta { margin-top: 16px; }
.card-meta .hostile { color: var(--fg); }
.card-meta .hostile::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 8px; background: var(--hostile); vertical-align: 1px; }
.card-go { display: inline-flex; margin-left: auto; color: var(--fg); }
.card-actions { display: flex; gap: 8px; padding: 0 16px 16px; flex-wrap: wrap; }
.card-actions .btn { flex: 1 1 0; justify-content: center; }
.chip {
  display: inline-flex; align-items: center; width: fit-content; color: var(--fg);
  font: 400 13px/1.2 var(--font-mono); letter-spacing: 0.14em; text-transform: uppercase;
}
.chip-row .chip + .chip::before { content: "/"; margin-right: 10px; color: var(--faint); }
.chip-row { gap: 10px; }
.chip-level, .chip-theme { color: var(--dim); }
.chip-hard { color: var(--fg); }
.chip-brutal { color: var(--hostile); }
/* difficulty of a built-in operation: three steps, filled up to the level */
.card-tags { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; min-width: 0; }
.level {
  display: inline-flex; align-items: center; gap: 8px; width: fit-content; color: var(--dim);
  font: 400 12px/1.2 var(--font-mono); letter-spacing: 0.14em; text-transform: uppercase;
}
.level-pips { display: inline-flex; gap: 3px; }
.level-pips i { width: 5px; height: 11px; border: 1px solid currentColor; opacity: 0.45; }
.level-pips i.on { background: currentColor; opacity: 1; }
.level-hard { color: var(--fg); }
.level-brutal { color: var(--hostile); }
.chip-row .level::before { content: "/"; margin-right: 2px; color: var(--faint); }
.grade {
  position: absolute; top: 10px; right: 10px; display: grid; place-items: center; align-content: center;
  min-width: 36px; height: 36px; padding: 0 6px;
  background: var(--fg); color: #000; font: 700 16px var(--font-mono);
}
.grade b { font: inherit; line-height: 1; }
/* the target-marker mode the grade was earned with */
.grade small { margin-top: 2px; font: 700 8px/1 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; }
.grade:has(small) { height: auto; min-height: 36px; padding: 5px 6px 4px; }
/* briefing: best grade under each target-marker mode */
.record { display: grid; gap: 10px; }
.record ul { display: flex; flex-wrap: wrap; gap: 1px; margin: 0; padding: 0; list-style: none; background: var(--line); border: 1px solid var(--line); }
.record li { flex: 1 1 0; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 10px 12px; background: var(--panel); min-width: 0; color: var(--faint); }
.record li span { font: 400 12px var(--font-mono); letter-spacing: 0.12em; text-transform: uppercase; }
.record li b { font: 400 20px/1 var(--font-mono); }
.record li.on { color: var(--fg); }
.empty {
  position: relative; padding: 44px 20px; border: 1px solid var(--line);
  text-align: center; color: var(--dim); display: grid; gap: 16px; justify-items: center;
}
.empty p { margin: 0; max-width: 42ch; line-height: 1.6; }

/* ---------------------------------------------------------------- random mission */
.gen-controls { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px 24px; align-items: start; margin-bottom: 28px; }
.gen-controls .field-note { margin-top: 10px; }
.mission-filter { max-width: 520px; margin-bottom: 20px; }
.mission-filter .field-note { margin-top: 10px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; min-width: 0; }
@media (max-width: 760px) { .gen-controls { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- briefing */
.brief { display: grid; gap: 24px; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: start; padding-top: 4px; }
.brief-map { width: 100%; aspect-ratio: 1; max-width: 100%; border: 1px solid var(--line); background: #0b0b0c; }
.brief-text { display: grid; gap: 20px; min-width: 0; }
.brief-text h2 { margin: 0; font: 400 clamp(32px, 8vw, 54px)/1.05 var(--font-display); letter-spacing: -0.015em; }
.brief-text p { margin: 0; max-width: 62ch; line-height: 1.6; color: var(--text); }
.brief-text > p.field-note { color: var(--dim); }
/* stat cells: label on top, figure below, hairline grid like an instrument panel */
.intel, .stats { display: flex; flex-wrap: wrap; gap: 1px; background: var(--line); border: 1px solid var(--line); }
.intel div, .stats div { flex: 1 1 40%; display: flex; flex-direction: column-reverse; justify-content: flex-end; gap: 14px; padding: 12px 14px 14px; background: var(--panel); min-width: 0; }
.intel b, .stats b { font: 400 29px/1 var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.intel span, .stats span { font: 400 12px var(--font-mono); letter-spacing: 0.16em; text-transform: uppercase; color: var(--dim); }
.objective { display: grid; gap: 8px; padding: 2px 0 2px 16px; border-left: 2px solid var(--fg); }
.objective strong { font: 400 12px var(--font-mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); }
.objective span { color: var(--fg); font-size: 15px; line-height: 1.5; }
.brief-actions { display: flex; gap: 14px; flex-wrap: wrap; }
.brief-actions .btn-primary { min-width: 200px; justify-content: center; }
/* Back and Deploy read the same on the briefing and the deploy screen: Back compact on the left, Deploy fills the row */
.brief-actions, .panel-actions.deploy-actions { flex-wrap: nowrap; gap: 14px; padding: 6px; }
.brief-actions .btn, .panel-actions.deploy-actions .btn { flex: none; padding: 0 20px; justify-content: center; order: -1; }
.brief-actions .btn-primary, .panel-actions.deploy-actions .btn-primary { flex: 1 1 auto; min-width: 0; min-height: 56px; order: 0; }
@media (min-width: 761px) { .intel div { flex-basis: 110px; } }
@media (max-width: 760px) {
  .brief { grid-template-columns: 1fr; gap: 18px; }
  .brief-map { aspect-ratio: 16 / 10; }
  /* the main action stays in reach of the thumb while the briefing scrolls */
  .brief-actions {
    position: sticky; bottom: calc(-1 * max(24px, var(--safe-b))); z-index: 3;
    margin-inline: -16px; padding: 18px 16px max(20px, calc(var(--safe-b) + 12px));
    background: linear-gradient(rgba(0, 0, 0, 0), #000 26%);
  }
  /* one row: secondary actions compact on the left, the primary action takes the rest, under the right thumb */
  .brief-actions { flex-wrap: nowrap; gap: 14px; }
  .brief-actions .btn { flex: none; padding: 0 14px; justify-content: center; order: -1; }
  .brief-actions .btn .ico { display: none; }
  .brief-actions .btn-primary { flex: 1 1 auto; min-width: 0; min-height: 56px; order: 0; }
  .brief-actions .btn-primary .ico { display: block; }
}

/* ---------------------------------------------------------------- in-game controls */
.game { pointer-events: none; z-index: 3; }
.game > * { pointer-events: auto; }
.pause-btn { position: fixed; top: calc(var(--safe-t) + 10px); right: calc(var(--safe-r) + 10px); background: rgba(0, 0, 0, 0.35); border-color: rgba(255, 255, 255, 0.3); }
.controls { position: fixed; display: grid; gap: 8px; touch-action: none; }
.ctl-weapons { display: flex; flex-direction: column; gap: 6px; }
.ctl-stack { display: flex; flex-direction: column; gap: 6px; justify-content: flex-end; }
.ctl {
  position: relative;
  min-width: 56px; min-height: 52px; padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.38); border-radius: 0;
  background: rgba(0, 0, 0, 0.4); color: var(--fg);
  font: 400 14px/1 var(--font-mono); letter-spacing: 0.1em;
  touch-action: none; -webkit-user-select: none; user-select: none; cursor: pointer;
}
.ctl.active { background: var(--fg); color: #000; border-color: var(--fg); }
.ctl-small { min-width: 84px; font-size: 13px; letter-spacing: 0.12em; white-space: nowrap; }
/* flare button: the dispenser state sits under the label (READY, or the recycle countdown), so the width never changes */
.ctl-flare { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.ctl-flare b { font: 500 10px/1 var(--font-mono); letter-spacing: 0.14em; }
.ctl-flare.alert { border-color: var(--hostile); color: #fff; border-width: 2px; animation: flare-alert .45s steps(2) infinite; }
/* recycling: dimmed, with a hairline bar along the foot that fills as the dispenser reloads (--p, 0..1, set by the app) */
.ctl-flare.cooling { color: var(--dim); border-color: var(--line-strong); background: linear-gradient(90deg, rgba(255, 255, 255, 0.08) calc(var(--p, 0) * 100%), rgba(0, 0, 0, 0.4) 0); }
.ctl-flare.cooling::after { content: ""; position: absolute; left: 0; bottom: 0; width: calc(var(--p, 0) * 100%); height: 2px; background: var(--fg); }
/* weapon buttons: the weapon's state under the caliber, and a hairline along the foot for rounds, reload or barrel heat (--p, 0..1, set by the app) */
.ctl-w { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.ctl-w b { font: 500 10px/1 var(--font-mono); letter-spacing: 0.08em; white-space: nowrap; }
.ctl-w.part::after { content: ""; position: absolute; left: 0; bottom: 0; width: calc(var(--p, 1) * 100%); height: 2px; background: currentColor; }
.ctl-w.busy b { color: var(--hostile); }
.ctl-fire {
  width: 100px; height: 100px; border: 0; align-self: end;
  background: rgba(0, 0, 0, 0.3); color: var(--fg);
  font-size: 14px; letter-spacing: 0.24em; text-indent: 0.24em;
}
.ctl-fire::before {
  background:
    linear-gradient(currentColor, currentColor) top left / 18px 2px,
    linear-gradient(currentColor, currentColor) top left / 2px 18px,
    linear-gradient(currentColor, currentColor) top right / 18px 2px,
    linear-gradient(currentColor, currentColor) top right / 2px 18px,
    linear-gradient(currentColor, currentColor) bottom left / 18px 2px,
    linear-gradient(currentColor, currentColor) bottom left / 2px 18px,
    linear-gradient(currentColor, currentColor) bottom right / 18px 2px,
    linear-gradient(currentColor, currentColor) bottom right / 2px 18px;
  background-repeat: no-repeat;
}
.ctl-fire.down { background: rgba(242, 243, 244, 0.92); color: #000; }
@keyframes flare-alert { 0% { background: var(--hostile); transform: scale(1.12); box-shadow: 0 0 18px var(--hostile); } 50% { background: rgba(0, 0, 0, 0.6); transform: scale(1); box-shadow: none; } }
@keyframes pulse { 50% { background: rgba(255, 90, 72, 0.28); } }
@media (orientation: landscape) {
  .controls {
    right: calc(var(--safe-r) + 16px); bottom: calc(var(--safe-b) + 14px);
    grid-template-columns: auto auto auto; align-items: end;
  }
}
@media (orientation: portrait) {
  .controls {
    left: 0; right: 0; bottom: 0;
    padding: 12px max(14px, var(--safe-r)) calc(var(--safe-b) + 14px) max(14px, var(--safe-l));
    /* zoom and flare on the top row, the weapons under them, fire on the right as tall as both rows */
    grid-template-columns: 1fr auto; gap: 6px 8px; align-items: stretch;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
  }
  .ctl-stack { grid-column: 1; grid-row: 1; flex-direction: row; }
  .ctl-stack .ctl { flex: 1; min-height: var(--ctl-h); }
  /* a row of equal columns, so all three weapon buttons share one width */
  .ctl-weapons { grid-column: 1; grid-row: 2; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
  .ctl-fire { grid-column: 2; grid-row: 1 / span 2; width: 96px; height: auto; align-self: stretch; }
  .ctl-w { min-width: 50px; }
}
@media (max-width: 370px) and (orientation: portrait) {
  .ctl-w { min-width: 46px; }
  .ctl-small { min-width: 70px; }
  .ctl-fire { width: 88px; }
}
@media (max-height: 420px) and (orientation: landscape) {
  .ctl { min-height: 46px; }
  .ctl-fire { width: 88px; height: 88px; }
}
/* weapon pickers and the flare button share one height */
.controls { --ctl-h: 64px; }
.controls .ctl-w, .controls .ctl-flare { min-height: var(--ctl-h); }
@media (max-height: 420px) and (orientation: landscape) { .controls { --ctl-h: 52px; } }
body.no-touch .controls { display: none; }
/* keyboard hints sit on the right edge, clear of the reticle and the radio subtitles */
.key-hint {
  position: fixed; right: calc(var(--safe-r) + 14px); top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
  padding: 12px 14px; background: rgba(0, 0, 0, 0.72); border: 1px solid var(--line);
  font: 400 13px var(--font-mono); letter-spacing: 0.08em; color: var(--dim);
  pointer-events: none; transition: opacity .6s;
}
.key-hint.fade { opacity: 0; }

/* ---------------------------------------------------------------- modals */
.modal {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center;
  padding-block: max(16px, var(--safe-t)) max(16px, var(--safe-b));
  padding-left: max(16px, var(--safe-l)); padding-right: max(16px, var(--safe-r));
  background: rgba(0, 0, 0, 0.72);
}
.dialog {
  width: min(540px, 100%); max-height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 24px; background: var(--panel); border: 1px solid var(--line-strong);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6); user-select: text; -webkit-user-select: text;
}
.dialog-sm { width: min(400px, 100%); }
.dialog-lg { width: min(780px, 100%); }
.dialog-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: -6px 0 20px; padding-bottom: 14px; border-bottom: 1px solid var(--line);
}
.dialog h2 { margin: 0; font: 400 26px/1.1 var(--font-display); letter-spacing: -0.01em; }
.dialog-sub { margin: 10px 0 0; color: var(--dim); font-size: 14px; line-height: 1.55; }
.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 24px; }
.stack .btn { justify-content: center; }
.stack .btn-primary { margin-bottom: 6px; }
/* phones: dialogs become bottom sheets, full width and anchored to the thumb */
@media (max-width: 600px) {
  .modal { place-items: end stretch; padding: max(24px, var(--safe-t)) 0 0; }
  .dialog, .dialog-sm, .dialog-lg {
    width: 100%; max-height: 100%;
    padding: 22px max(16px, var(--safe-r)) max(24px, calc(var(--safe-b) + 16px)) max(16px, var(--safe-l));
    border-width: 1px 0 0; animation: sheet-up .22s ease-out;
  }
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } }

.help { display: grid; gap: 0; }
.help section { padding: 18px 0; border-top: 1px solid var(--line); }
.help section:first-child { border-top: 0; padding-top: 0; }
.help h3 { margin: 0 0 10px; font: 400 12px var(--font-mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); }
.help p { margin: 0 0 10px; line-height: 1.6; max-width: 65ch; color: var(--text); }
.help strong { color: var(--fg); font-weight: 500; }
.defs { display: grid; grid-template-columns: auto 1fr; gap: 10px 18px; margin: 0 0 10px; }
.defs dt { font: 400 13px/1.7 var(--font-mono); letter-spacing: 0.1em; text-transform: uppercase; white-space: nowrap; color: var(--fg); }
.defs dd { margin: 0; line-height: 1.6; color: var(--text); }
@media (max-width: 480px) { .defs { grid-template-columns: 1fr; gap: 4px; } .defs dd { margin-bottom: 10px; } }

/* debrief */
.db-head { display: grid; gap: 10px; margin-bottom: 22px; }
.db-result { font: 400 clamp(34px, 9vw, 52px)/1.02 var(--font-display); letter-spacing: -0.015em; margin: 0; }
.db-result.win { color: var(--fg); }
.db-result.lose { color: var(--hostile); }
.db-reason { margin: 0; color: var(--dim); }
.db-markers { margin: 0; font: 400 12px var(--font-mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); }
.db-grade { display: flex; align-items: baseline; gap: 14px; margin-top: 6px; font: 400 12px var(--font-mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); }
.db-grade b { display: inline-grid; place-items: center; min-width: 56px; height: 56px; background: var(--fg); color: #000; font: 400 35px/1 var(--font-mono); letter-spacing: 0; }
.stats div { background: var(--panel-2); }
.stats b { font-size: 22px; }
.db-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 24px; }
.db-actions .btn { flex: 1 1 140px; justify-content: center; }
@media (max-width: 600px) { .db-actions .btn-primary { flex-basis: 100%; } }

/* ---------------------------------------------------------------- forms */
.form { display: grid; gap: 22px; }
.form-section { display: grid; gap: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.form-section:first-child { border-top: 0; padding-top: 0; }
.form-section > h3 { margin: 0; font: 400 12px var(--font-mono); letter-spacing: 0.16em; text-transform: uppercase; color: var(--fg); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: 18px 20px; }
.field { display: grid; gap: 10px; min-width: 0; }
.field-note { margin: 0; font-size: 13px; color: var(--dim); line-height: 1.55; }
/* segmented control: the chosen option is inverted, black on white */
.seg { display: flex; flex-wrap: wrap; border: 1px solid var(--line-strong); }
.seg button {
  flex: 1 1 auto; min-height: var(--touch); padding: 0 12px;
  border: 0; border-left: 1px solid var(--line); background: none; cursor: pointer;
  font: 400 13px var(--font-mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim);
}
.seg button:first-child { border-left: 0; }
.seg button:hover { color: var(--fg); }
.seg button[aria-pressed="true"] { background: var(--fg); color: #000; }
/* range: a tick-mark track that fills in white up to the value (--p is set by GS.rangeFill) */
.range-row { display: flex; align-items: center; gap: 14px; }
.range-row output { min-width: 5ch; text-align: right; font: 400 14px var(--font-mono); font-variant-numeric: tabular-nums; }
input[type="range"] {
  --ticks: repeating-linear-gradient(90deg, var(--fg) 0 2px, transparent 2px 6px);
  --ticks-off: repeating-linear-gradient(90deg, var(--line-strong) 0 2px, transparent 2px 6px);
  flex: 1; min-width: 0; height: var(--touch); margin: 0;
  -webkit-appearance: none; appearance: none; background: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 18px; background: var(--ticks) 0 0 / var(--p, 0%) 100% no-repeat, var(--ticks-off); }
input[type="range"]::-moz-range-track { height: 18px; background: var(--ticks-off); }
input[type="range"]::-moz-range-progress { height: 18px; background: var(--ticks); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 6px; height: 32px; margin-top: -7px; border: 0; border-radius: 0; background: var(--fg); box-shadow: 0 0 0 3px #000; }
input[type="range"]::-moz-range-thumb { width: 6px; height: 32px; border: 0; border-radius: 0; background: var(--fg); box-shadow: 0 0 0 3px #000; }
input[type="text"], input[type="number"], textarea, select {
  width: 100%; min-height: var(--touch); padding: 11px 12px;
  background: var(--panel-2); color: var(--fg);
  border: 1px solid var(--line-strong); border-radius: 0;
  font: 16px/1.4 var(--font-body); user-select: text; -webkit-user-select: text;
}
:is(input[type="text"], input[type="number"], textarea, select):focus { border-color: var(--fg); }
textarea { min-height: 104px; resize: vertical; }
select { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--dim) 50%), linear-gradient(135deg, var(--dim) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
/* switch: a square knob in a rectangular track; on is solid white */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: var(--touch); cursor: pointer; }
.field > label.switch { font: 400 15px/1.4 var(--font-body); letter-spacing: 0; text-transform: none; color: var(--fg); }
.switch input { appearance: none; -webkit-appearance: none; position: relative; flex: none; width: 52px; height: 28px; margin: 0; border: 1px solid var(--line-strong); background: transparent; cursor: pointer; transition: background .15s, border-color .15s; }
.switch input::after { content: ""; position: absolute; top: 4px; left: 4px; width: 18px; height: 18px; background: var(--dim); transition: transform .15s, background .15s; }
.switch input:checked { background: var(--fg); border-color: var(--fg); }
.switch input:checked::after { transform: translateX(24px); background: #000; }
.issues { margin: 0; padding: 14px 16px 14px 32px; border: 1px dashed var(--line-strong); color: var(--fg); font-size: 14px; line-height: 1.5; }
.issues li::marker { color: var(--target); }
.issues li + li { margin-top: 6px; }

/* ---------------------------------------------------------------- editor */
.editor {
  display: flex; flex-direction: column; background: var(--bg);
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}
.ed-top { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); background: #000; }
.ed-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.ed-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 400 19px/1.15 var(--font-display); }
.ed-chip { flex: none; }
.ed-dirty { flex: none; display: inline-flex; align-items: center; gap: 6px; font: 400 12px var(--font-mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--fg); }
.ed-dirty::before { content: ""; width: 6px; height: 6px; background: var(--fg); }
.ed-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.ed-actions .btn [data-icon] { display: inline-flex; }
.ed-body { flex: 1; min-height: 0; display: grid; grid-template-columns: auto minmax(0, 1fr) 310px; }
.ed-tools { display: flex; flex-direction: column; gap: 2px; width: 100px; padding: 8px 6px; overflow-y: auto; border-right: 1px solid var(--line); background: #000; }
.tool-group { display: contents; }
.tool-group-label { padding: 12px 4px 6px; font: 400 11px var(--font-mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--faint); text-align: center; }
.tool {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; flex: none;
  min-height: 60px; padding: 8px 4px; border: 1px solid transparent; border-radius: 0; background: none; cursor: pointer;
  font: 400 11px/1.15 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--text); text-align: center;
}
.tool:hover { border-color: var(--line-strong); color: var(--fg); }
.tool[aria-pressed="true"] { border-color: var(--fg); background: var(--fg); color: #000; }
.tool.hostile .ico { color: var(--hostile); }
.tool.friendly .ico { color: var(--ally); }
.tool.mission .ico { color: var(--fg); }
.tool[aria-pressed="true"] .ico { color: #000; }
.ed-stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#ed-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.ed-hint {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  max-width: calc(100% - 24px); margin: 0; padding: 8px 12px;
  background: rgba(0, 0, 0, 0.85); border: 1px solid var(--line);
  font: 400 13px/1.5 var(--font-mono); letter-spacing: 0.04em; color: var(--fg); text-align: center; pointer-events: none;
}
.ed-hint { transition: opacity .5s; }
.ed-hint.fade { opacity: 0; }
.ed-zoom { position: absolute; top: 12px; right: 12px; display: flex; flex-direction: column; gap: 6px; }
/* packed toolbars: plain hairline boxes read better than rows of brackets */
:is(.ed-actions, .ed-zoom) .icon-btn { border: 1px solid var(--line-strong); background: rgba(0, 0, 0, 0.7); }
:is(.ed-actions, .ed-zoom) .icon-btn::before { display: none; }
:is(.ed-actions, .ed-zoom) .icon-btn:hover { border-color: var(--fg); }
.ed-panel { display: flex; flex-direction: column; gap: 20px; padding: 18px 16px; overflow-y: auto; border-left: 1px solid var(--line); background: var(--panel); user-select: text; -webkit-user-select: text; }
.ed-panel h3 { margin: 0; font: 400 21px/1.15 var(--font-display); }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.panel-close { display: none; }
.panel-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.panel-actions .btn { flex: 1 1 auto; justify-content: center; }
.counts { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); }
.counts div { display: flex; flex-direction: column-reverse; justify-content: flex-end; gap: 8px; padding: 10px 12px; background: var(--panel-2); }
.counts div:last-child:nth-child(odd) { grid-column: 1 / -1; }
.counts b { font: 400 21px/1 var(--font-mono); font-variant-numeric: tabular-nums; }
.counts span { font: 400 11px var(--font-mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); }
.tips { margin: 0; padding-left: 18px; color: var(--dim); font-size: 13px; line-height: 1.6; }
.check-chip {
  display: flex; align-items: center; gap: 12px; min-height: var(--touch); padding: 0 14px;
  border: 1px solid var(--line-strong); cursor: pointer;
  font: 400 13px var(--font-mono); letter-spacing: 0.12em; text-transform: uppercase;
}
.check-chip input { width: 18px; height: 18px; margin: 0; accent-color: var(--fg); }
.check-chip.defend:has(input:checked) { border-color: var(--ally); color: var(--ally); }
.check-chip.target:has(input:checked) { border-color: var(--target); color: var(--target); }
.check-chip.defend input { accent-color: var(--ally); }
.check-chip.target input { accent-color: var(--target); }

@media (max-width: 820px), (orientation: portrait) {
  .ed-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .ed-stage { grid-row: 1; grid-column: 1; }
  .ed-tools { grid-row: 2; flex-direction: row; width: auto; padding: 6px 8px; overflow-x: auto; overflow-y: hidden; border-right: 0; border-top: 1px solid var(--line); -webkit-overflow-scrolling: touch; }
  .tool-group-label { writing-mode: vertical-rl; transform: rotate(180deg); padding: 4px 4px; border-left: 1px solid var(--line); margin-left: 6px; }
  .tool { min-width: 64px; min-height: 62px; }
  .ed-panel {
    grid-row: 1; grid-column: 1; align-self: end; z-index: 2;
    max-height: 62%; border-left: 0; border-top: 1px solid var(--line-strong);
    box-shadow: 0 -20px 40px rgba(0, 0, 0, 0.5); display: none;
  }
  .ed-panel.open { display: flex; animation: sheet-up .2s ease-out; }
  .panel-close { display: inline-grid; }
  .ed-actions .lbl { display: none; }
  .ed-actions .btn-sm { padding: 0 12px; }
  .ed-name { font-size: 17px; }
  .ed-hint { bottom: auto; top: 10px; left: 12px; transform: none; max-width: calc(100% - 76px); text-align: left; }
}
@media (max-width: 1000px) and (orientation: landscape) {
  .ed-body { grid-template-columns: auto minmax(0, 1fr) 270px; }
}
@media (max-width: 560px) {
  .ed-top { flex-wrap: wrap; row-gap: 8px; }
  .ed-title { flex: 1 1 calc(100% - 60px); }
  .ed-actions { width: 100%; justify-content: space-between; }
  .ed-actions .btn-sm { min-height: 44px; flex: 1; justify-content: center; }
}
@media (max-width: 360px) {
  .ed-chip { display: none; }
}

/* library */
.library { display: grid; gap: 24px; }
.lib-section { display: grid; gap: 10px; }
.lib-section > h3 { margin: 0; font: 400 12px var(--font-mono); letter-spacing: 0.16em; text-transform: uppercase; color: var(--fg); }
.lib-row { display: flex; align-items: center; gap: 14px; padding: 12px; border: 1px solid var(--line); background: var(--panel-2); min-width: 0; }
.lib-row canvas { width: 64px; height: 64px; flex: none; border: 1px solid var(--line); }
.lib-info { flex: 1; min-width: 0; display: grid; gap: 6px; }
.lib-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 400 17px var(--font-display); }
.lib-info > span:not(.level) { font: 400 12px var(--font-mono); color: var(--dim); letter-spacing: 0.1em; text-transform: uppercase; }
.lib-btns { display: flex; gap: 6px; flex: none; flex-wrap: wrap; justify-content: flex-end; }
.lib-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.lib-json { font: 12px/1.4 var(--font-mono); min-height: 120px; }
@media (max-width: 520px) {
  .lib-row { flex-wrap: wrap; }
  .lib-btns { width: 100%; justify-content: stretch; }
  .lib-btns .btn { flex: 1; justify-content: center; }
  .lib-tools .btn { flex: 1 1 140px; justify-content: center; }
}

/* ---------------------------------------------------------------- toasts / fatal */
.toasts { position: fixed; top: calc(var(--safe-t) + 14px); left: 50%; transform: translateX(-50%); z-index: 50; display: grid; gap: 8px; justify-items: center; pointer-events: none; width: max-content; max-width: calc(100% - 32px); }
.toast { padding: 12px 16px; background: var(--fg); color: #000; font: 400 13px var(--font-mono); letter-spacing: 0.1em; text-transform: uppercase; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); animation: toast-in .2s ease-out; }
.toast.warn { background: #000; color: var(--hostile); border: 1px solid var(--hostile); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }
.fatal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 24px; background: var(--bg); text-align: center; }
.fatal div { max-width: 46ch; display: grid; gap: 16px; justify-items: center; }
.fatal h2 { margin: 0; font: 400 28px var(--font-display); }
.fatal p { margin: 0; color: var(--dim); line-height: 1.6; }

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