  :root {
    /* Single design scale driving all sidebar/HUD sizing. Computed in
       fitCanvas (JS) from viewport vs. 1920×1080 reference. Floored so
       the UI stops shrinking below ~iPad (1024 wide). */
    --ui-scale: 1;
    --bg: #0b0f16;
    --panel: #141c28;
    --panel2: #1a2230;
    --ink: #e6e6e6;
    --muted: #8a96a8;
    --line: #232c3a;
    --accent: #4aa3ff;
    --danger: #ff5252;
    --ok: #5fd17a;
    --warn: #ffb84a;
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: ui-sans-serif, system-ui, sans-serif; }
  /* Viewport floor — the game is tuned for roughly 1200×720+. Below
     that size the layout squishes the stage and HUD into tiny,
     unreadable pieces. Instead of letting everything compress, we
     set a min-width / min-height on body and switch to auto overflow
     so the window scrolls when the viewport dips below the floor.
     At or above the floor, `overflow:hidden` behaviour is effectively
     restored because the body already fits inside the viewport. */
  body { display: grid; grid-template-columns: 1fr 380px; grid-template-rows: 1fr; gap: 12px; padding: 12px; height: 100vh; min-width: 1024px; min-height: 768px; overflow: auto; }

  /* Stage — 16:9 aspect ratio, fills available space */
  #stage { background: #0a0e15; border: 1px solid var(--line); border-radius: 8px; position: relative; overflow: hidden; visibility: hidden; min-height: 0; }
  #stage.active { visibility: visible; }
  #canvas { display: block; width: 100%; height: 100%; }
  #hud { position: absolute; top: 8px; left: 10px; right: 10px; display: flex; justify-content: flex-end; pointer-events: none; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; color: #cfd6e4; text-shadow: 0 1px 2px #000; }
  #hud .right { background: rgba(10,14,21,0.65); border: 1px solid var(--line); padding: 4px 8px; border-radius: 4px; }

  /* Side */
  #side { display: flex; flex-direction: column; gap: calc(10px * var(--ui-scale)); min-width: 0; min-height: 0; visibility: hidden; }
  #side.active { visibility: visible; }
  .panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: calc(10px * var(--ui-scale)); }
  h1 { margin: 0 0 6px; font-size: 15px; letter-spacing: 0.5px; }
  h2 { margin: 0 0 6px; font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: 1px; }
  button { background: #2a3548; color: var(--ink); border: 1px solid #36435a; border-radius: 6px; padding: 7px 11px; cursor: pointer; font: inherit; font-size: 13px; }
  button:hover { background: #344058; }
  button.primary { background: var(--accent); border-color: var(--accent); color: #07111c; font-weight: 600; }
  button.danger  { background: var(--danger); border-color: var(--danger); color: #1c0707; font-weight: 600; }
  input[type=password], input[type=text] { width: 100%; background: #0f1622; color: var(--ink); border: 1px solid #2a3548; border-radius: 6px; padding: 6px 8px; font: inherit; }
  .row { display: flex; gap: 8px; align-items: center; }
  .grow { flex: 1; min-width: 0; }

  /* Commanders — two-level hierarchy: each commander group contains 2 squads. */
  #commanders { display: flex; flex-direction: column; gap: 16px; }
  .cmdr-group {
    display: flex; flex-direction: column; gap: 6px;
    padding: 8px;
    border: 2px solid var(--cmdr-col, var(--line));
    border-radius: 8px;
    background: var(--panel2);
    transition: box-shadow 0.2s, transform 0.2s;
  }
  .cmdr-group.speaking {
    box-shadow: 0 0 0 2px var(--cmdr-col, var(--accent)), 0 0 22px var(--cmdr-col, var(--accent));
    transform: translateY(-1px);
  }
  .cmdr-row {
    display: grid; grid-template-columns: 36px 1fr; gap: 8px; align-items: center;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--line);
  }
  .cmdr-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--cmdr-col, #4aa3ff);
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 16px; color: #0a0e15;
    border: 2px solid rgba(255,255,255,0.25);
  }
  .cmdr-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
  .cmdr-name { font-weight: 700; font-size: 13px; }
  .cmdr-rank { font-size: 9px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; }
  .squad-row {
    display: flex; flex-direction: column; gap: 4px;
    padding: 6px 10px;
    background: #0f1622;
    border-left: 6px solid var(--squad-col, var(--line));
    border-radius: 4px;
  }
  .squad-header {
    display: flex; align-items: center; gap: 6px;
  }
  .squad-name { font-weight: 700; font-size: 13px; flex: 1; }
  .squad-units-row {
    display: flex; gap: 6px; align-items: center;
  }
  .unit-bar-wrap {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  }
  .unit-bar {
    width: 100%; height: 7px;
    background: #1a1a22;
    border: 1px solid #3a3a48;
    border-radius: 3px;
    overflow: hidden;
  }
  .unit-bar > div { height: 100%; transition: width 0.2s; border-radius: 2px; }
  .unit-bar.dead { opacity: 0.25; border-color: #2a2a32; }
  .unit-bar.dead > div { width: 0 !important; }
  .squad-orders {
    font-size: 13px;
    font-family: ui-sans-serif, system-ui, sans-serif;
    color: #cfd6e4;
    padding: 2px 0;
    font-weight: 600;
  }
  .squad-orders.idle { color: var(--muted); font-style: italic; }
  /* engaging class removed — units auto-engage within stance radius */
  .squad-orders.defending { color: #5fd17a; }
  .squad-orders.moving { color: #7ec8ff; }
  .squad-orders.regrouping { color: #c4a5e8; }
  .stance-toggle {
    display: inline-flex; gap: 4px; align-items: center;
    cursor: pointer; user-select: none;
    font-size: 14px; margin-left: auto;
  }
  .stance-toggle .stance-icon { opacity: 0.3; transition: opacity 0.2s; }
  .stance-toggle .stance-icon.active { opacity: 1.0; }

  /* Transcript log panel — z-index 900 keeps it above overlays during testing */
  .log-panel { flex: 1; min-height: 0; display: none; flex-direction: column; position: relative; z-index: 900; }
  .log-panel.open { display: flex; }
  .log-panel h2 { margin: 0 0 4px; }
  /* Tiny toggle button for transcript — bottom-right corner */
  #transcriptToggle, #diagBtn {
    position: fixed; bottom: 6px; z-index: 950;
    width: 22px; height: 22px; border-radius: 4px;
    background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.15); font-size: 11px; font-weight: 700;
    cursor: pointer; display: none; /* hidden until in-game */
    align-items: center; justify-content: center;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    padding: 0; line-height: 1;
  }
  #transcriptToggle { right: 6px; }
  #diagBtn { right: 32px; }
  #transcriptToggle:hover, #diagBtn:hover { color: rgba(255,255,255,0.5); background: rgba(255,255,255,0.08); }
  #transcriptToggle.active, #diagBtn.active { display: flex; }
  #diagBtn.has-errors { color: #ff4444; border-color: rgba(255,68,68,0.3); }
  #log {
    flex: 1; min-height: 0;
    overflow-y: auto; overflow-x: hidden;
    background: #0a0e15; border: 1px solid var(--line);
    border-radius: 6px; padding: 6px 8px;
  }
  #log > div {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    line-height: 1.4;
    padding: 1px 0;
  }
  #log .you {
    color: #4ae0ff; font-size: 14px; font-weight: 700;
    margin-top: 6px; padding: 4px 6px;
    background: rgba(74,224,255,0.07); border-radius: 4px;
  }
  #log .gen {
    color: #ffc94a; font-size: 13px; font-weight: 600;
    padding: 2px 6px;
    background: rgba(255,201,74,0.06); border-radius: 4px;
    margin-bottom: 4px;
  }
  #log .sys  { color: #4a5568; font-size: 10px; }
  #log .err  { color: #ff5252; font-size: 11px; font-weight: 600; }
  .stance-toggle:hover .stance-icon { opacity: 0.6; }
  .stance-toggle:hover .stance-icon.active { opacity: 1.0; }

  /* Ensure side scrolls if tight */
  #side { overflow: hidden; }
  /* Commanders panel grows to fill remaining sidebar space after controls
     + stats panels. min-height:0 lets it shrink below content size on
     short viewports; the inner #commanders then scrolls as a last-resort
     safety net. Normally the clamp()-driven tile sizing keeps content in
     bounds without scrollbars appearing. */
  .panel.commanders-panel { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; overflow: hidden; }
  .panel.commanders-panel #commanders { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; }

  /* Controls panel — wave indicator + buttons in the right column */
  .controls-panel { padding: 10px 28px !important; position: relative; z-index: 1000; }
  .controls-row {
    display: flex; align-items: center; justify-content: center; gap: 12px;
  }
  #waveBox {
    display: flex; flex-direction: column; align-items: center;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    line-height: 1;
  }
  #waveBox .wave-label { font-size: 14px; letter-spacing: 4px; color: var(--muted); font-weight: 600; }
  #waveBox .wave-num   { font-size: 38px; font-weight: 800; letter-spacing: 4px; color: var(--ink); }
  .controls-btns { display: flex; gap: 8px; }
  .ctrl-btn {
    width: 40px;
    height: 36px;
    padding: 0;
    font-size: 18px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid #36435a;
    background: #2a3548;
    color: var(--ink);
  }
  .ctrl-btn:hover { background: #344058; }
  /* Mute button is styled identically to the other ctrl-btns; the 🔊 / 🔇 icon
     is the only visual indicator of state. No background colour coding. */
  /* pauseBtn z-index no longer needed — controls-panel handles layering */

  /* Pause overlay — pointer-events:none so the pause button underneath
     stays clickable for unpausing. */
  /* Pause overlay removed — start overlay handles both start + pause */
  /* (pause overlay styles removed — unified into #startOverlay) */

  /* Day/Night toggle uses .ctrl-btn styling from the controls panel. */

  /* Day mode overrides */

  /* Full-screen splash — opaque, no blur (standalone screen).
     Grid rows 1fr / auto / 2fr push the content block into a row whose
     top gap is exactly half the bottom gap. The lower 2/3 of the free
     space is reserved for the fly-by animation. */
  #startOverlay {
    position: fixed; inset: 0;
    /* Vertical layout (percentages from top of viewport):
       0%–15%   empty (top gap)
       15%–75%  static content (title, illustration, tagline, play button)
       75%–85%  empty (buffer above animation)
       85%–95%  fly-by animation band
       95%–100% empty (bottom margin)
       Implemented by reserving 25 vh of bottom padding and aligning the
       content block to the END of the remaining 75 vh. The fly-by
       canvas draws absolutely in its 85–95 vh strip (see fxPickYIn). */
    display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
    background: radial-gradient(ellipse at 50% 40%, #14243c 0%, #080c14 70%);
    z-index: 100;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0 16px 25vh 16px;
    opacity: 1;
    filter: blur(0);
    transition: opacity 0.5s ease, filter 0.5s ease;
  }
  .splash-content {
    display: flex; flex-direction: column; align-items: center;
  }
  #startOverlay.fading { opacity: 0; filter: blur(8px); }
  #startOverlay.hidden { display: none; }

  /* Pause overlay — blurred backdrop over the game */
  #pauseOverlay {
    position: fixed; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: radial-gradient(ellipse at 50% 40%, rgba(20, 36, 60, 0.85) 0%, rgba(8, 12, 20, 0.92) 70%);
    z-index: 100;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    gap: 1.4rem;
    overflow: hidden;
  }
  #pauseOverlay.hidden { display: none; }
  #pauseOverlay::before {
    content: '';
    position: absolute; inset: 0;
    background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(74,163,255,0.03) 2px, rgba(74,163,255,0.03) 4px);
    pointer-events: none; z-index: 1;
  }
  /* Pause overlay reuses the .go-panel / .go-btn look from the mission
     report. Trim the title's bottom-margin since the panel has no
     subtitle / body to separate from. */
  #pauseOverlay .go-panel { padding-top: 40px; padding-bottom: 40px; }
  #pauseOverlay .go-title { margin-bottom: 36px; }
  #pauseOverlay .go-btn-row { margin-top: 36px; }

  /* Game-over overlay — same blur effect as the start screen */
  #gameOverOverlay {
    position: fixed; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: radial-gradient(ellipse at 50% 40%, rgba(20, 36, 60, 0.95) 0%, rgba(8, 12, 20, 0.98) 70%);
    z-index: 100;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    overflow: hidden;
  }
  #gameOverOverlay.hidden { display: none; }
  #gameOverOverlay::before {
    content: '';
    position: absolute; inset: 0;
    background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(74,163,255,0.03) 2px, rgba(74,163,255,0.03) 4px);
    pointer-events: none; z-index: 1;
  }
  .go-panel {
    position: relative; z-index: 2;
    background: rgba(12,18,30,0.97);
    border: 1.5px solid rgba(74,163,255,0.35);
    box-shadow: inset 0 0 0 3px rgba(74,163,255,0.12);
    border-radius: 12px;
    padding: 40px 48px 36px;
    min-width: 320px; max-width: 520px;
    text-align: center;
    font-family: ui-sans-serif, system-ui, sans-serif;
  }
  .go-accent { width: 80px; height: 3px; background: #ffd166; margin: 0 auto 20px; }
  .go-title { color: #ffd166; font-weight: bold; font-size: 22px; letter-spacing: 4px; margin-bottom: 36px; }
  .go-sub { color: #c8d1dd; font-size: 18px; margin-bottom: 6px; }
  .go-wave { color: #fff; font-weight: bold; font-size: 56px; margin-bottom: 8px; }
  .go-kills { color: #ffd166; font-weight: bold; font-size: 16px; margin-bottom: 28px; }
  .go-divider { height: 1px; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2) 20%, rgba(255,255,255,0.2) 80%, transparent); margin: 0 0 20px; }
  .go-hdr { color: #c8d1dd; font-weight: bold; font-size: 15px; letter-spacing: 3px; margin-bottom: 16px; }
  .go-row { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 4px 12px; margin-bottom: 2px; border-radius: 4px; }
  .go-row.mvp { background: rgba(95,209,122,0.08); }
  .go-rank { color: #4a5568; font-weight: bold; font-size: 14px; width: 24px; text-align: right; }
  .go-row.mvp .go-rank { color: #5fd17a; }
  .go-squad { font-size: 15px; text-align: left; min-width: 110px; }
  .go-row.mvp .go-squad { font-weight: bold; font-size: 16px; }
  .go-squad-kills { color: #8a96a8; font-size: 15px; min-width: 28px; text-align: right; }
  .go-row.mvp .go-squad-kills { color: #fff; font-weight: bold; font-size: 16px; }
  .go-kills-label { color: #4a5568; font-size: 12px; }
  .go-mvp-badge { color: #5fd17a; font-weight: bold; font-size: 10px; min-width: 28px; text-align: left; }
  .go-bottom { color: #5a6a80; font-size: 13px; margin-top: 20px; }
  .go-bottom.go-bottom-strong { color: #ffd166; font-weight: bold; font-size: 18px; letter-spacing: 1px; }
  .go-btn {
    margin-top: 24px; padding: 12px 48px;
    background: #ffd166; color: #0c121e;
    font-weight: bold; font-size: 16px;
    border: none; border-radius: 24px; cursor: pointer;
    box-shadow: 0 0 20px rgba(255,209,102,0.3);
    transition: transform 0.1s;
  }
  .go-btn:hover { transform: scale(1.05); }
  .go-btn-row {
    display: flex; gap: 16px; justify-content: center; margin-top: 24px;
  }
  .go-btn-row .go-btn { margin-top: 0; }
  .go-btn-secondary {
    background: transparent; color: #8a9ab5;
    border: 1.5px solid rgba(138,154,181,0.35);
    box-shadow: none;
  }
  .go-btn-secondary:hover { color: #c8d6e8; border-color: rgba(138,154,181,0.6); }

  /* ── Map Select (sequenced animation: fade image → slide GENERAL → fade tiles in) ────
     The splash layout must NOT reflow when the player presses play —
     if layout changes, flex-end anchoring drifts "Armchair" from its
     original Y. So every transition uses opacity or transform, never
     layout. GENERAL's upward translation is computed at click time
     from measured title positions (--shift-y); the grid's top is
     likewise pinned via --grid-top so it lands directly under the
     shifted GENERAL. Sequence: illustration fades (~80 ms) → GENERAL
     translates up (~240 ms) → tiles cascade in (each 280 ms, 55 ms
     stagger). Total ~900 ms. */
  .splash-illustration {
    transition: opacity 0.08s ease;
  }
  #startBtn, .splash-tagline {
    transition: opacity 0.12s ease;
  }
  .title-general {
    transition: transform 0.24s cubic-bezier(0.4,0,0.2,1) 0.08s;
    will-change: transform;
  }
  #startOverlay.level-select-mode .splash-illustration { opacity: 0; pointer-events: none; }
  #startOverlay.level-select-mode #startBtn            { opacity: 0; pointer-events: none; }
  /* Tagline stays visible — grid is vertically centred between
     GENERAL's shifted bottom and the tagline's top. */
  #startOverlay.level-select-mode .title-general {
    transform: translateY(calc(-1 * var(--shift-y, 0px)));
  }
  /* Grid container is visible whenever level-select-mode is on; the
     per-card cardSlideUp animation (with its own staggered
     animation-delay) is what the player sees fade in. */
  .ls-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));   /* minmax(0,1fr) lets columns shrink below content — no overflow on narrow viewports */
    gap: clamp(0.35rem, 0.8vw, 0.9rem);
    width: min(70vw, 1200px);                /* ≥15% empty gutter each side */
    position: absolute;
    left: 50%;
    top: var(--grid-cy, 60%);
    transform: translate(-50%, -50%);        /* centre the grid on (--grid-cy) */
    pointer-events: none;
    z-index: 3;
    visibility: hidden;
  }
  #startOverlay.level-select-mode .ls-grid {
    pointer-events: auto;
    visibility: visible;
  }
  @keyframes cardSlideUp {
    from { opacity: 0; transform: translateY(24px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
  }
  /* Tile — vibrant themed card, title on top, icon below.
     Theme colour is driven by the --tile-hue / --tile-rgb custom
     properties set per-card variant. */
  .ls-card {
    --tile-rgb: 74,163,255;
    --tile-glow: 0.45;
    background:
      linear-gradient(160deg,
        rgba(var(--tile-rgb), 0.28) 0%,
        rgba(var(--tile-rgb), 0.10) 55%,
        rgba(var(--tile-rgb), 0.04) 100%);
    border: 1.5px solid rgba(var(--tile-rgb), 0.55);
    box-shadow:
      0 0 22px rgba(var(--tile-rgb), calc(var(--tile-glow) * 0.35)),
      inset 0 1px 0 rgba(255,255,255,0.08);
    border-radius: 14px;
    padding: clamp(0.5rem, 1.2vw, 1.6rem) clamp(0.35rem, 0.9vw, 1.1rem);
    aspect-ratio: 1 / 1.2;
    min-width: 0;                              /* allow shrinking below content */
    display: flex; flex-direction: column; align-items: center; justify-content: space-between;
    cursor: pointer;
    transition: background 0.18s, border-color 0.18s, box-shadow 0.18s, transform 0.12s;
    text-align: center;
    opacity: 0;
    animation: cardSlideUp 0.45s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
  }
  .ls-card:hover {
    background:
      linear-gradient(160deg,
        rgba(var(--tile-rgb), 0.42) 0%,
        rgba(var(--tile-rgb), 0.18) 55%,
        rgba(var(--tile-rgb), 0.08) 100%);
    border-color: rgba(var(--tile-rgb), 0.85);
    box-shadow:
      0 0 38px rgba(var(--tile-rgb), calc(var(--tile-glow) * 0.7)),
      inset 0 1px 0 rgba(255,255,255,0.14);
    transform: translateY(-4px);
  }
  /* Per-theme accent colours. RGB triplets only — the card renders them
     through the gradient + border + glow equations above. */
  .ls-card.theme-tutorial { --tile-rgb: 74,163,255;  --tile-glow: 0.55; }  /* blue    */
  .ls-card.theme-classic  { --tile-rgb: 255,176,64;  --tile-glow: 0.55; }  /* amber   */
  .ls-card.theme-tutorial2{ --tile-rgb: 122,210,180; --tile-glow: 0.55; }  /* teal — distinguishes from tutorial 1 */
  .ls-card.theme-tba      { --tile-rgb: 120,135,160; --tile-glow: 0.25; }  /* muted   */
  .ls-card.tba            { filter: saturate(0.4) brightness(0.75); cursor: default; pointer-events: none; }
  .ls-card-name {
    font-family: 'Rajdhani', sans-serif; font-size: clamp(0.75rem, 1.3vw, 1.65rem); font-weight: 700;
    color: #f5f8ff; letter-spacing: 0.06em;
    text-shadow: 0 0 18px rgba(var(--tile-rgb), 0.55);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
  }
  .ls-card-icon {
    width: 60%; aspect-ratio: 1;
    color: rgba(var(--tile-rgb), 0.95);
    filter: drop-shadow(0 0 10px rgba(var(--tile-rgb), 0.45));
    display: flex; align-items: center; justify-content: center;
  }
  .ls-card-icon svg { width: 100%; height: 100%; display: block; }

  /* Scanline effect */
  #startOverlay::before {
    content: '';
    position: absolute; inset: 0;
    background: repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(74, 163, 255, 0.03) 2px,
      rgba(74, 163, 255, 0.03) 4px
    );
    pointer-events: none;
    z-index: 1;
  }

  /* Title */
  .splash-title {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-weight: 900;
    color: #e6e6e6;
    text-shadow:
      0 0 20px rgba(74, 163, 255, 0.6),
      0 0 60px rgba(74, 163, 255, 0.3),
      0 2px 0 #1a2a40;
    position: relative;
    z-index: 2;
    text-align: center;
    line-height: 1;
  }
  .title-armchair {
    font-size: clamp(32px, min(8vw, 9vh), 160px);
    letter-spacing: clamp(2px, 0.4vw, 6px);
    margin-bottom: -6px;
  }
  .title-general {
    font-size: clamp(38px, min(10vw, 12vh), 200px);
    letter-spacing: clamp(6px, 1.5vw, 22px);
    text-transform: uppercase;
    margin-top: -6px;
    margin-bottom: clamp(6px, 2vh, 22px);
  }

  /* Splash hero image — scales by whichever dimension is tighter.
     The fly-by animation is pinned to a narrow strip at 85-95% vh,
     so the content can be big on both large and small viewports. */
  .splash-illustration {
    position: relative;
    z-index: 2;
    width: clamp(220px, min(48vw, 36vh), 720px);
    height: auto;
    margin-bottom: 0;
  }

  /* Tagline */
  .splash-tagline {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: clamp(11px, min(2vw, 2.2vh), 20px);
    color: var(--muted);
    letter-spacing: 3px;
    text-transform: uppercase;
    position: relative;
    z-index: 2;
    margin-bottom: clamp(8px, 2.5vh, 28px);
    text-align: center;
  }

  /* Start button */
  #startBtn {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: clamp(14px, min(2.2vw, 2.5vh), 24px);
    font-weight: 700;
    letter-spacing: 3px;
    text-transform: none;
    padding: clamp(8px, 1.4vh, 16px) clamp(28px, 5vw, 64px);
    border-radius: 8px;
    background: linear-gradient(180deg, #5bb8ff 0%, #3a8edf 100%);
    color: #07111c;
    border: 2px solid rgba(255,255,255,0.3);
    cursor: pointer;
    box-shadow:
      0 0 40px rgba(74, 163, 255, 0.4),
      0 0 80px rgba(74, 163, 255, 0.2),
      inset 0 1px 0 rgba(255,255,255,0.3);
    transition: transform 0.15s, box-shadow 0.15s;
    position: relative;
    z-index: 2;
    animation: btnPulse 2.5s ease-in-out infinite;
  }
  #startBtn:hover {
    transform: scale(1.06);
    box-shadow:
      0 0 60px rgba(74, 163, 255, 0.6),
      0 0 120px rgba(74, 163, 255, 0.3),
      inset 0 1px 0 rgba(255,255,255,0.4);
  }
  #splashVersion {
    position: fixed;
    bottom: clamp(6px, 0.6vw, 12px);
    right: clamp(8px, 0.8vw, 16px);
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: clamp(11px, 1vw, 24px);    /* 24px on a 32" (~2400vw+), scales down proportionally */
    color: rgba(200,210,228,0.7);
    letter-spacing: 0.08em;               /* proportional to font-size */
    z-index: 960;
  }
  #splashVersion.hidden { display: none; }
  #splashVersion { cursor: pointer; transition: color 0.2s; }
  #splashVersion:hover { color: rgba(74,163,255,0.9); }

  /* Changelog slide-out panel */
  #changelogPanel {
    position: fixed;
    top: 0; right: -420px;
    width: 400px; height: 100%;
    background: rgba(12, 16, 24, 0.96);
    border-left: 1px solid rgba(74,163,255,0.25);
    z-index: 970;
    transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex; flex-direction: column;
    font-family: ui-monospace, Menlo, Consolas, monospace;
  }
  #changelogPanel.open { right: 0; }
  #changelogPanel .cl-header {
    padding: 20px 20px 12px;
    font-size: 16px; font-weight: 700;
    color: rgba(74,163,255,0.9);
    letter-spacing: 2px;
    border-bottom: 1px solid rgba(74,163,255,0.15);
    display: flex; justify-content: space-between; align-items: center;
  }
  #changelogPanel .cl-close {
    cursor: pointer; font-size: 22px; color: rgba(200,210,228,0.5);
    background: none; border: none; padding: 0 4px;
    transition: color 0.2s;
  }
  #changelogPanel .cl-close:hover { color: #fff; }
  #changelogPanel .cl-body {
    flex: 1; overflow-y: auto; padding: 16px 20px;
    font-size: 13px; line-height: 1.7;
    color: rgba(200,210,228,0.8);
    white-space: pre-wrap;
  }
  #changelogPanel .cl-body .cl-version {
    color: rgba(74,163,255,0.9); font-weight: 700; font-size: 14px;
  }
  #changelogPanel .cl-loading {
    padding: 40px 20px; text-align: center;
    color: rgba(200,210,228,0.4); font-style: italic;
  }
  #changelogBackdrop {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.4); z-index: 965;
    opacity: 0; pointer-events: none;
    transition: opacity 0.35s;
  }
  #changelogBackdrop.open { opacity: 1; pointer-events: auto; }
  @keyframes btnPulse {
    0%, 100% { box-shadow: 0 0 40px rgba(74, 163, 255, 0.4), 0 0 80px rgba(74, 163, 255, 0.2), inset 0 1px 0 rgba(255,255,255,0.3); }
    50% { box-shadow: 0 0 55px rgba(74, 163, 255, 0.55), 0 0 100px rgba(74, 163, 255, 0.3), inset 0 1px 0 rgba(255,255,255,0.3); }
  }
  button:disabled { opacity: 0.45; cursor: not-allowed; }

  /* ── HUD — right-side panel, vertical HP bars ─────────────────────
     Stage + sidebar sit as a centred pair with a small gap between
     them. Any leftover width is split equally as black strips on the
     far-outside edges. The stage's exact pixel size is set by
     fitCanvas (JS) based on viewport − sidebar − gap, so the 14:9
     world aspect is maintained while filling the most viewport we
     can. Commander tiles use vertical HP bars per unit, two squad
     clusters side by side inside each tile. */
  body {
    display: flex;
    grid-template-columns: none;
    grid-template-rows: none;
    justify-content: center;
    /* Sidebar is top-aligned to the stage top. It's natural height —
       often shorter than the map — so any spare vertical space sits
       empty beneath the last commander tile, not stretched into giant
       bars. On small viewports the content still fills down. */
    align-items: flex-start;
    gap: 14px;
    padding: 12px;
    /* Hard floor on layout size — below this, the browser scrolls rather
       than cramming the HUD. Roughly a 10-inch laptop screen. */
    min-width: 1100px;
    min-height: 720px;
  }
  #stage { flex-shrink: 0; }
  #side {
    flex-shrink: 0;
    width: calc(300px * var(--ui-scale));
    /* Height is set by fitCanvas to match the stage height so the
       map + sidebar look like a single block. */
    display: flex;
    flex-direction: column;
  }

  .buff-stats-panel {
    display: flex;
    flex-direction: column;
    gap: calc(4px * var(--ui-scale));
    padding: calc(8px * var(--ui-scale)) calc(12px * var(--ui-scale));
    flex: 0 0 auto;
  }
  #minimap { display: none; }

  /* ── Buff stats panel (SHIELDS / WEAPONS / SPEED) ─────────────── */
  .buff-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: calc(14px * var(--ui-scale));
    font-family: ui-monospace, Menlo, Consolas, monospace;
    color: #9aa7bc;
    transition: color 0.2s;
  }
  .buff-row.active   { color: var(--ink); }
  .buff-row.inactive .buff-bar,
  .buff-row.inactive .buff-timer { visibility: hidden; }
  .buff-label {
    font-size: calc(13px * var(--ui-scale));
    font-weight: 700;
    letter-spacing: 2px;
    min-width: 9ch;
  }
  .buff-value {
    font-size: calc(14px * var(--ui-scale));
    font-weight: 700;
    text-align: left;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
    min-width: 4ch;
  }
  .buff-row.active .buff-value { color: #ffd166; }
  /* ── Active effects block — temporary buffs with countdown ───── */
  .active-effects {
    display: flex;
    flex-direction: column;
    gap: calc(4px * var(--ui-scale));
    margin-top: calc(6px * var(--ui-scale));
    padding-top: calc(6px * var(--ui-scale));
    border-top: 1px solid #2a3344;
  }
  .active-effects.empty { display: none; }
  .ae-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: calc(10px * var(--ui-scale));
    font-family: ui-monospace, Menlo, Consolas, monospace;
    color: var(--ink);
  }
  .ae-label {
    font-size: calc(13px * var(--ui-scale));
    font-weight: 700;
    letter-spacing: 2px;
  }
  .ae-timer {
    font-size: calc(13px * var(--ui-scale));
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    min-width: 3ch;
    text-align: right;
  }
  .ae-bar {
    grid-column: 1 / -1;
    height: calc(5px * var(--ui-scale));
    background: #1a1a22;
    border: 1px solid #3a3a48;
    border-radius: 3px;
    overflow: hidden;
    margin-top: 2px;
  }
  .ae-fill {
    height: 100%;
    width: 0;
    transition: width 0.15s linear;
    background: #ffb84a;  /* temporary-buff amber */
  }
  .ae-shield .ae-label { color: #ffb84a; }
  .ae-damage .ae-label { color: #ffb84a; }

  /* ── Commander tile — vertical HP bars ────────────────────────── */
  .bhud-cmdr-col {
    display: flex;
    flex-direction: column;
    gap: calc(10px * var(--ui-scale));
    padding: calc(12px * var(--ui-scale)) calc(14px * var(--ui-scale));
    background:
      linear-gradient(180deg, color-mix(in srgb, var(--cmdr-col) 15%, transparent) 0%, transparent 50%),
      rgba(20,28,40,0.7);
    border: 1px solid color-mix(in srgb, var(--cmdr-col) 45%, var(--line));
    border-radius: 8px;
    transition: box-shadow 0.25s, border-color 0.25s, transform 0.25s;
    position: relative;
  }
  .bhud-cmdr-col.speaking {
    box-shadow: 0 0 0 2px var(--cmdr-col), 0 0 22px color-mix(in srgb, var(--cmdr-col) 55%, transparent);
    border-color: var(--cmdr-col);
    transform: translateY(-1px);
  }
  .bhud-cmdr-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid color-mix(in srgb, var(--cmdr-col) 25%, var(--line));
  }
  .bhud-cmdr-swatch {
    width: calc(14px * var(--ui-scale));
    height: calc(14px * var(--ui-scale));
    border-radius: 50%;
    background: var(--cmdr-col);
    box-shadow: 0 0 7px color-mix(in srgb, var(--cmdr-col) 75%, transparent);
    flex: 0 0 auto;
  }
  .bhud-cmdr-label {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: calc(16px * var(--ui-scale));
    font-weight: 700;
    letter-spacing: 1.5px;
    color: var(--ink);
    text-transform: uppercase;
  }
  /* Body of the tile — the two squad clusters share one horizontal
     row, with a subtle divider between them. */
  .bhud-cmdr-body {
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    gap: calc(16px * var(--ui-scale));
    padding-top: calc(8px * var(--ui-scale));
  }
  .bhud-sq-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: calc(8px * var(--ui-scale));
    min-width: 0;
  }
  .bhud-sq-num {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: calc(22px * var(--ui-scale));
    font-weight: 800;
    letter-spacing: 0;
    color: var(--cmdr-col);
    opacity: 0.95;
    align-self: flex-start;
    width: calc(18px * var(--ui-scale));
    text-align: center;
    line-height: 1;
  }
  /* Vertical-bar cluster — each bar stands upright, fills bottom→top. */
  .bhud-sq-vbars {
    display: flex;
    gap: calc(6px * var(--ui-scale));
    align-items: flex-end;
    justify-content: flex-start;
    height: calc(70px * var(--ui-scale));
    width: 100%;
  }
  .bhud-hp-vbar {
    --hp-frac: 1;
    flex: 0 0 auto;
    width: calc(18px * var(--ui-scale));
    height: 100%;
    border-radius: 3px;
    background:
      linear-gradient(to top,
        var(--chip-col) 0%,
        var(--chip-col) calc(var(--hp-frac) * 100%),
        #1a1d24 calc(var(--hp-frac) * 100%),
        #12151a 100%);
    border: 1px solid color-mix(in srgb, var(--chip-col) 55%, #000 40%);
    box-shadow:
      inset 1px 0 0 rgba(255,255,255,0.08),
      0 0 6px color-mix(in srgb, var(--chip-col) 35%, transparent);
    transition:
      background 0.25s ease,
      box-shadow 0.25s ease,
      opacity 0.3s ease,
      width 0.3s ease,
      margin-right 0.3s ease,
      border-width 0.3s ease,
      padding 0.3s ease;
  }
  /* When a unit dies, its bar collapses to zero width over 300 ms; flex
     reflow makes the surviving bars slide left smoothly in the same
     window. The negative margin-right absorbs the flex gap so there's
     no lingering empty column. */
  .bhud-hp-vbar.collapsing {
    width: 0;
    opacity: 0;
    border-width: 0;
    padding: 0;
    margin-right: calc(-6px * var(--ui-scale));
    pointer-events: none;
  }
  .bhud-hp-vbar.dead {
    background: transparent;
    border: 1px dashed rgba(200,210,228,0.18);
    box-shadow: none;
    opacity: 0.4;
  }
  .bhud-hp-vbar.critical {
    animation: hpVCritical 0.85s ease-in-out infinite;
  }
  @keyframes hpVCritical {
    0%, 100% { box-shadow: inset 1px 0 0 rgba(255,255,255,0.08), 0 0 6px color-mix(in srgb, var(--chip-col) 35%, transparent); }
    50%      { box-shadow: inset 1px 0 0 rgba(255,255,255,0.08), 0 0 14px #ff5252; }
  }

  /* Commander list spacing — a touch more room between
     tiles since each one is taller. */
  #commanders { display: flex; flex-direction: column; gap: calc(14px * var(--ui-scale)); }

  /* Controls panel — just the four mission buttons now. WAVE was
     pulled out of here and inlined as the top row of the stats panel
     below, so the controls-panel contains only .controls-btns. */
  .controls-panel {
    padding: calc(12px * var(--ui-scale)) calc(14px * var(--ui-scale)) !important;
    flex: 0 0 auto;
  }
  /* Mission report overlay takes over the whole view — hide the whole
     sidebar (controls + stats + commander tiles) so only the report
     card is visible. */
  body:has(#gameOverOverlay:not(.hidden)) #side { visibility: hidden; }
  .controls-btns {
    display: flex;
    gap: 6px;
    justify-content: space-between;
  }
  .controls-btns .ctrl-btn {
    flex: 1;
    padding: calc(6px * var(--ui-scale)) calc(10px * var(--ui-scale));
    font-size: calc(16px * var(--ui-scale));
    height: calc(36px * var(--ui-scale));
  }
  /* WAVE row inside the stats panel — the number is larger and
     brighter than the stat values, but otherwise matches the row
     styling so it reads as "a stat, just at the top". */
  #buff-row-wave .buff-value {
    font-size: calc(22px * var(--ui-scale));
    color: var(--ink);
    letter-spacing: 2px;
  }

  /* Minimap — fixed overlay in the bottom-right of the stage */
  #minimap {
    position: absolute;
    bottom: 24px; right: 24px;
    width: 172px; height: 97px;
    background: rgba(10, 14, 21, 0.85);
    border: 1px solid #2a3548;
    border-radius: 4px;
    cursor: crosshair;
    z-index: 5;
    image-rendering: pixelated;
  }
  /* Make the canvas grab when held to communicate panning */
  #stage.panning #canvas { cursor: grabbing; }
  #canvas { cursor: grab; }
