/* SAND: the game's one stylesheet (DESIGN.md section 11).
 *
 * Four layouts, chosen by media queries on the viewport and never by pointer
 * type: `tall` is the default below; `short`, `squat` and `wide` override it.
 * Every HUD group is a direct child of .game and a CSS grid area places it,
 * so one DOM serves all four and a rotation only reflows. (`squat` dissolves
 * the header button group with `display: contents` and places each button in
 * its own cell.)
 *
 * The rule every layout keeps: the fixed tracks add up to less than the
 * viewport, so no control can be pushed past a screen edge, and every
 * pressable box is >= 44x44 with >= 8 px to its neighbours.
 *
 * Look: dark sand-metal panels (warm near-black, a brushed top light, a 1 px
 * bevel), system type, the house colour as the in-game identity accent and
 * sand as the accent of primary actions. Contrast is set for a phone in sun:
 * primary ink is 14:1 on the panel, secondary 7.9:1, disabled 3.6:1.
 */

:root {
  --bg: #100c09;
  --panel: #1f1812;
  --panel-2: #2a2119;
  --panel-3: #362a1f;
  --well: #120d09;
  --edge: #4a3a2a;
  --edge-2: #5d4a35;
  --hi: rgba(255, 230, 190, 0.09);
  --ink: #f3e9d6;
  --ink-2: #cdbb9c;
  --ink-3: #8d7b62;
  --sand: #e6ad5e;
  --sand-ink: #22160a;
  --good: #86d46e;
  --warn: #f2b744;
  --bad: #f0503e;
  --house: #3a78d8;
  --r: 6px;
  --r2: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  touch-action: none;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.35 var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  font-variant-numeric: tabular-nums;
}

#app { position: fixed; inset: 0; }
[hidden] { display: none !important; }
.noscript { padding: 24px; }

button {
  font: inherit;
  color: inherit;
  margin: 0;
  cursor: pointer;
}
button:focus { outline: none; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--sand);
  outline-offset: 2px;
}
a { color: var(--sand); }

.gl { display: inline-flex; width: 20px; height: 20px; flex: none; }
.gl svg { width: 100%; height: 100%; display: block; }
.gl svg .f { fill: currentColor; stroke: none; }

/* ======================================================================
 * The game root and its four layouts
 * ==================================================================== */

.game {
  position: fixed;
  inset: 0;
  max-height: 100%;
  display: grid;
  background:
    linear-gradient(180deg, rgba(255, 228, 180, 0.035), rgba(0, 0, 0, 0) 30%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.012) 0 1px, rgba(0, 0, 0, 0) 1px 3px),
    var(--panel);
  overflow: hidden;
  /* tall: everything else. The selection line is 54 px: 44 px chips, 2 px
     under the strip's 6 px foot and 8 px over the tabs (bottom panel 202). */
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: calc(44px + var(--sat)) minmax(0, 1fr) 56px 54px 44px calc(104px + var(--sab));
  grid-template-areas:
    "stat btns"
    "map  map"
    "cmd  cmd"
    "sel  sel"
    "tabs tabs"
    "build build";
}

.map { grid-area: map; position: relative; overflow: hidden; background: #0b0806; min-width: 0; min-height: 0; }
.map-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.mini { grid-area: mini; position: relative; }
.stat { grid-area: stat; }
.btns { grid-area: btns; }
.tabs { grid-area: tabs; }
.build { grid-area: build; }
.sel { grid-area: sel; }
.cmd { grid-area: cmd; }
.hints { grid-row: 1 / -1; grid-column: 1 / -1; position: relative; pointer-events: none; z-index: 20; }

/* --- tall --------------------------------------------------------------- */

.stat {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-content: center;
  column-gap: 12px;
  padding: var(--sat) 8px 0 calc(12px + var(--sal));
  min-width: 0;
  /* The rule under the top bar is a shadow, not a border: a border took 1 px
     of the 44 px row, so the 44 px header buttons stuck out 0.5 px above the screen. */
  box-shadow: inset 0 -1px 0 #0a0705;
}
.stat .credits { grid-row: 1; grid-column: 1; }
.stat .power { grid-row: 1; grid-column: 2; }

.btns {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: var(--sat) calc(8px + var(--sar)) 0 0;
  box-shadow: inset 0 -1px 0 #0a0705;
}

.mini {
  grid-area: map;
  justify-self: end;
  align-self: start;
  width: 156px;
  height: 156px;
  margin: 8px calc(8px + var(--sar)) 0 0;
  z-index: 6;
  display: none;
  border-radius: var(--r);
  padding: 3px;
  background: linear-gradient(180deg, var(--edge-2), var(--panel));
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
}
.mini.open { display: block; animation: drop-in 160ms var(--ease); }
.mini-canvas { width: 100%; height: 100%; display: block; border-radius: 4px; background: #0b0806; image-rendering: auto; }
/* Over the static when there is no radar: what would bring it up. */
.mini-note {
  display: none;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: calc(100% - 20px);
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 750;
  line-height: 1.25;
  text-align: center;
  color: var(--ink);
  background: rgba(12, 8, 5, 0.86);
  box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.12);
  pointer-events: none;
}
.mini-note.show { display: block; }

/* The strip is a frame (.cmd: positioned, it anchors the refusal notice
   and the edge hints) round a scroller (.cmd-row: the grid of the seven
   slots). Seven slots of 44 px with 8 px gaps take 356 px: where they do not
   fit (tall below 372 px wide, short below 372 px high) the row scrolls
   along its length with the finger (pan-x, pan-y in the columns) and every
   slot keeps its 44 px; an edge with a slot past it that is not empty shows
   a fade and a chevron (commandbar.js marks it: more-l, more-r, more-t,
   more-b). The mode banner is a grid item of the row, over slots 1-4; the
   refusal notice is positioned against the frame from the measured box of
   slots 1-4 (.banner.flash below), so the scroller never clips it. */
.cmd {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  position: relative;
  /* A shadow, not a border: 6 + 44 + 6 fills the 56 px row exactly, so the
     slots end 6 px above the selection line's chips (+2 = 8 px apart). */
  box-shadow: inset 0 1px 0 #0a0705;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.25), rgba(0, 0, 0, 0) 60%);
}
.cmd-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(44px, 1fr));
  grid-template-rows: minmax(44px, 1fr);
  gap: 8px;
  min-width: 0;
  min-height: 0;
  padding: 6px calc(8px + var(--sar)) 6px calc(8px + var(--sal));
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior: contain;
  scrollbar-width: none;
}
.cmd-row::-webkit-scrollbar { display: none; }
.cmd-row, .cmd-row * { touch-action: pan-x; }
/* The edge hints: a fade and a chevron over the edge past which a slot that
   is not empty lies; they take no press. */
.cmd::before, .cmd::after {
  content: '';
  position: absolute;
  z-index: 2;
  display: none;
  pointer-events: none;
  align-items: center;
  justify-content: center;
  color: var(--sand);
  font: 800 20px/1 var(--font);
}
.cmd.more-l::before { display: flex; content: '\2039'; left: 0; top: 0; bottom: 0; width: 22px; background: linear-gradient(90deg, rgba(10, 7, 5, 0.92), rgba(10, 7, 5, 0)); justify-content: flex-start; padding-left: 3px; }
.cmd.more-r::after { display: flex; content: '\203A'; right: 0; top: 0; bottom: 0; width: 22px; background: linear-gradient(270deg, rgba(10, 7, 5, 0.92), rgba(10, 7, 5, 0)); justify-content: flex-end; padding-right: 3px; }
.cmd.more-t::before { display: flex; content: '\2039'; top: 0; left: 0; right: 0; height: 18px; background: linear-gradient(180deg, rgba(10, 7, 5, 0.92), rgba(10, 7, 5, 0)); }
.cmd.more-b::after { display: flex; content: '\203A'; bottom: 0; left: 0; right: 0; height: 18px; background: linear-gradient(0deg, rgba(10, 7, 5, 0.92), rgba(10, 7, 5, 0)); }
.cmd.more-t::before, .cmd.more-b::after { writing-mode: vertical-lr; }

.sel {
  padding: 2px calc(12px + var(--sar)) 8px calc(12px + var(--sal));
  display: flex;
  align-items: center;
  overflow: hidden;
  min-width: 0;
  /* A shadow, not a border: a border would take 1 px of the 44 px chip box. */
  box-shadow: inset 0 1px 0 rgba(255, 230, 190, 0.05);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  padding: 0 calc(8px + var(--sar)) 0 calc(8px + var(--sal));
}

.build {
  display: grid;
  grid-auto-flow: column;
  /* sidebar.js fitTiles shares the strip's width so a whole number of tiles
     fits (72.6 px at 411 px wide); 76 px until it has measured. */
  grid-auto-columns: var(--tile-w, 76px);
  grid-template-rows: 88px;
  gap: 8px;
  padding: 8px calc(8px + var(--sar)) calc(8px + var(--sab)) calc(8px + var(--sal));
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior: contain;
  scrollbar-width: none;
}
.build::-webkit-scrollbar { display: none; }
.build, .build * { touch-action: pan-x; }

/* --- tall, narrow phones (below 380 px) --------------------------------- */

/* The four top-bar buttons become 44 px icons (200 px with the gaps), so the
   credits and the power margin keep their room at 360 and at 320 px; the
   power bar goes and its number stays. (Rules that override a component
   rule further down carry `.game` to win the cascade.) */
@media (max-width: 379px) and (orientation: portrait) {
  .btns .hb { width: 44px; }
  .btns .hb .lbl { display: none; }
  .btns .hb .gl { width: 20px; height: 20px; }
  .stat { grid-template-columns: auto minmax(0, 1fr); column-gap: 6px; padding-left: calc(8px + var(--sal)); padding-right: 4px; }
  .game .cr-ic { display: none; }
  .game .cr-val { font-size: 16px; }
  .game .power { gap: 3px; overflow: hidden; }
  .game .power .gl { width: 13px; height: 13px; }
  .game .pw-bar { display: none; }
  .game .tab .lbl { font-size: 9px; letter-spacing: -0.01em; }
  /* 44 px slots at 320: 'Deselect' fits at 9.5 px with 1 px padding. */
  .game .slot { padding: 2px 1px; }
  .game .slot .lbl { font-size: 9.5px; }
  /* A stance word breaks at its soft hyphen instead of losing its tail. */
  .game .slot .lbl.long { white-space: normal; text-align: center; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: normal; line-height: 1.05; }
}
/* Below 340 px even 9 px 'Structures' does not fit a sixth of the row. */
@media (max-width: 339px) and (orientation: portrait) {
  .game .tab .lf { display: none; }
  .game .tab .ls { display: inline; }
}

/* --- tall, short pages: the thumb band ---------------------------------- */

/* The command strip and the build strip lie in the lowest 35% of the page
   (DESIGN.md section 15). The strip and bottom panel take 258 px, which
   holds from 738 px high; Vivaldi's portrait page with its bars is 411x717
   (strip top 459.3 against the line at 466.3, measured on the AVD). So up to
   740 px high the build strip gives 12 px (tiles 88 -> 80, its foot 8 -> 4),
   which holds down to 703 px; up to 704 px it gives 16 px (tiles 76), the
   most the bottom panel may give, which holds down to 692 px. Tiles keep
   their 8 px gaps; the icon shrinks with the tile so a two-line name fits.
   The predicate is `tall` only: a portrait page this low is never `wide`, and
   a landscape one is `tall` only from 560 px high below 900 px wide. */
@media (orientation: portrait) and (max-height: 740px), (orientation: landscape) and (min-height: 560px) and (max-height: 740px) and (max-width: 899px) {
  .game { grid-template-rows: calc(44px + var(--sat)) minmax(0, 1fr) 56px 54px 44px calc(92px + var(--sab)); }
  .build { grid-template-rows: 80px; padding-bottom: calc(4px + var(--sab)); }
  .game .tile .ic { width: 46px; height: 46px; }
  .game .tile .nm { margin-top: 3px; }
}
@media (orientation: portrait) and (max-height: 704px), (orientation: landscape) and (min-height: 560px) and (max-height: 704px) and (max-width: 899px) {
  .game { grid-template-rows: calc(44px + var(--sat)) minmax(0, 1fr) 56px 54px 44px calc(88px + var(--sab)); }
  .build { grid-template-rows: 76px; }
  .game .tile .ic { width: 42px; height: 42px; }
}

/* --- short: landscape phones in fullscreen ----------------------------- */

/* Fixed parts 244 px (stat 36, buttons 52, tabs 104, selection 52), so the
   build grid holds a full row of 88 px tiles from 360 px up. */
@media (orientation: landscape) and (max-height: 559px) and (min-height: 360px) {
  .game {
    grid-template-columns: minmax(0, 1fr) 56px calc(216px + var(--sar));
    grid-template-rows: calc(36px + var(--sat)) 52px 104px minmax(0, 1fr) calc(52px + var(--sab));
    grid-template-areas:
      "map cmd stat"
      "map cmd btns"
      "map cmd tabs"
      "map cmd build"
      "map cmd sel";
  }
  .stat {
    padding: var(--sat) calc(8px + var(--sar)) 0 10px;
    column-gap: 8px;
    box-shadow: none;
  }
  .game .cr-val { font-size: 16px; }
  .btns {
    display: grid;
    grid-template-columns: repeat(4, 44px);
    gap: 8px;
    align-content: start;
    padding: 0 calc(8px + var(--sar)) 8px 8px;
    box-shadow: none;
  }
  .btns .hb { width: 44px; }
  .cmd {
    box-shadow: none;
    border-left: 1px solid #0a0705;
    border-right: 1px solid #0a0705;
    background: linear-gradient(90deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.1));
  }
  /* One column of seven: 49.7 px rows at 412 px high; below 372 px it
     scrolls up and down. */
  .cmd-row {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: repeat(7, minmax(44px, 1fr));
    padding: calc(8px + var(--sat)) 5px calc(8px + var(--sab)) 5px;
    overflow-x: hidden;
    overflow-y: auto;
  }
  .cmd-row, .cmd-row * { touch-action: pan-y; }
  .tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: 48px 48px;
    gap: 8px;
    padding: 0 calc(8px + var(--sar)) 0 8px;
  }
  .game .tab { height: 48px; }
  .game .tab .tab-ic { width: 22px; height: 22px; }
  .build {
    grid-auto-flow: row;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: 88px;
    grid-template-rows: none;
    grid-auto-columns: auto;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 8px calc(8px + var(--sar)) 8px 8px;
    align-content: start;
  }
  .build, .build * { touch-action: pan-y; }
  /* 8 px over the chips keeps them clear of a tile resting on the grid's foot. */
  .sel { padding: 8px calc(8px + var(--sar)) var(--sab) 8px; }
  .mini { width: 148px; height: 148px; margin: calc(8px + var(--sat)) 8px 0 0; }
}

/* --- squat: landscape phones with the browser's bars (914x262) --------- */

/* Measured on the pando AVD: Vivaldi in landscape leaves 914x262 CSS px.
   Fixed rows 156 px (8 + 44 + 8 + 44 + 8 + 44); the build strip takes the
   rest and scrolls sideways, so nothing needs a vertical scroll and slot 6
   is always on screen. Panel columns: 8 | 48 | 8 | 48 | 8 | 48 | 8 | 48 | 8. */
@media (orientation: landscape) and (max-height: 359px) {
  .game {
    grid-template-columns: minmax(0, 1fr) 112px 8px 48px 8px 48px 8px 48px 8px 48px calc(8px + var(--sar));
    grid-template-rows: calc(8px + var(--sat)) 44px 8px 44px 8px 44px minmax(0, 1fr);
    grid-template-areas:
      "map cmd .     .     .     .     .     .     .     .     ."
      "map cmd .     stat  stat  stat  .     fs    .     menu  ."
      "map cmd .     .     .     .     .     .     .     .     ."
      "map cmd .     tabs  tabs  tabs  tabs  tabs  .     bmap  ."
      "map cmd .     tabs  tabs  tabs  tabs  tabs  .     .     ."
      "map cmd .     tabs  tabs  tabs  tabs  tabs  .     bsel  ."
      "map cmd build build build build build build build build build";
  }
  .btns { display: contents; }
  .hb-sel { grid-area: bsel; }
  .hb-map { grid-area: bmap; }
  .hb-fs { grid-area: fs; }
  .hb-menu { grid-area: menu; }
  .btns .hb { width: 48px; height: 44px; }
  .stat {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-content: center;
    column-gap: 6px;
    row-gap: 3px;
    padding: 0;
    box-shadow: none;
  }
  .game .cr-ic { display: none; }
  .game .cr-val { font-size: 15px; }
  .game .power { gap: 3px; overflow: hidden; }
  .game .power .gl { width: 13px; height: 13px; }
  .game .pw-bar { display: none; }
  .cmd {
    box-shadow: none;
    border-left: 1px solid #0a0705;
    border-right: 1px solid #0a0705;
    background: linear-gradient(90deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.1));
  }
  /* A 2x4 grid: slots 1 to 6 in the top three rows, Follow (slot 7) the
     whole fourth row; 55.5 px rows at 262 px high, 44 px at 216. Lower
     still, it scrolls up and down. */
  .cmd-row {
    grid-template-columns: repeat(2, minmax(44px, 1fr));
    grid-template-rows: repeat(4, minmax(44px, 1fr));
    padding: calc(8px + var(--sat)) 4px calc(8px + var(--sab)) 4px;
    overflow-x: hidden;
    overflow-y: auto;
  }
  .cmd-row, .cmd-row * { touch-action: pan-y; }
  .tabs {
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: 44px 44px;
    gap: 8px;
    padding: 0;
  }
  .game .tab .tab-ic { width: 18px; height: 18px; }
  .game .tab .lbl { font-size: 9px; letter-spacing: -0.02em; }
  .sel { display: none; }
  /* The tiles take the height that is left (90 px at 262), up to 104 px. */
  .build {
    grid-auto-flow: column;
    grid-auto-columns: 76px;
    grid-template-columns: none;
    grid-template-rows: minmax(0, 104px);
    grid-auto-rows: auto;
    align-content: start;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px calc(8px + var(--sar)) calc(8px + var(--sab)) 8px;
  }
  .build, .build * { touch-action: pan-x; }
  .mini { width: 140px; height: 140px; margin: calc(8px + var(--sat)) 8px 0 0; }
}

/* --- wide: desks and tablets in landscape ------------------------------ */

/* From 760 px high: header 64, minimap 240x240 (row 248), tabs 96, selection
   96 beside the strip: fixed parts 504 px, so the grid keeps two 98 px rows. */
@media (min-width: 900px) and (min-height: 560px) {
  .game {
    grid-template-columns: minmax(0, 1fr) 136px calc(104px + var(--sar));
    grid-template-rows: calc(64px + var(--sat)) 248px auto minmax(0, 1fr) 40px calc(56px + var(--sab));
    grid-template-areas:
      "map stat  btns"
      "map mini  mini"
      "map tabs  tabs"
      "map build build"
      "map sel   sel"
      "cmd sel   sel";
  }
  .stat {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-content: center;
    row-gap: 4px;
    padding: var(--sat) 0 0 12px;
    box-shadow: none;
  }
  .stat .credits { grid-row: 1; grid-column: 1 / -1; }
  .stat .power { grid-row: 2; grid-column: 1 / -1; }
  .btns { padding: var(--sat) calc(8px + var(--sar)) 0 0; justify-content: flex-end; box-shadow: none; }
  .hb-map, .hb-sel { display: none !important; }
  .mini {
    grid-area: mini;
    justify-self: start;
    align-self: start;
    display: block;
    width: 240px;
    height: 240px;
    margin: 0 0 8px;
    padding: 0;
    border-radius: 0;
    background: #0b0806;
    box-shadow: inset 0 0 0 1px #0a0705, 0 1px 0 var(--hi);
  }
  .mini-canvas { border-radius: 0; }
  .tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-auto-rows: 44px;
    padding: 0 calc(12px + var(--sar)) 0 12px;
  }
  .build {
    grid-auto-flow: row;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: none;
    grid-auto-rows: 98px;
    grid-auto-columns: auto;
    align-content: start;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 8px calc(12px + var(--sar)) 8px 12px;
  }
  .build, .build * { touch-action: pan-y; }
  .sel {
    padding: 8px calc(12px + var(--sar)) var(--sab) 12px;
    align-items: center;
    border-top: 1px solid #0a0705;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.22), rgba(0, 0, 0, 0));
  }
  .cmd-row {
    grid-template-columns: repeat(7, minmax(44px, 132px));
    justify-content: safe center;
    padding: 6px 12px calc(6px + var(--sab)) calc(12px + var(--sal));
  }
}

/* wide, 640 to 759 px high (a laptop with browser chrome): a 160 px minimap
   and 88 px tile rows; fixed parts 424 px, so two rows show from 640 up. */
@media (min-width: 900px) and (min-height: 640px) and (max-height: 759px) {
  .game { grid-template-rows: calc(64px + var(--sat)) 168px auto minmax(0, 1fr) 40px calc(56px + var(--sab)); }
  .mini { width: 160px; height: 160px; justify-self: center; }
  .build { grid-auto-rows: 88px; }
}

/* wide, 560 to 639 px high: the minimap opens over the map with Map, as in
   tall and short, and the header takes two rows (credits and power 44,
   Map Full Menu 52); fixed parts 288 px, so two tile rows show at 560. */
@media (min-width: 900px) and (min-height: 560px) and (max-height: 639px) {
  .game {
    grid-template-rows: calc(44px + var(--sat)) 52px auto minmax(0, 1fr) 40px calc(56px + var(--sab));
    grid-template-areas:
      "map stat  stat"
      "map btns  btns"
      "map tabs  tabs"
      "map build build"
      "map sel   sel"
      "cmd sel   sel";
  }
  .stat {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    column-gap: 12px;
    row-gap: 2px;
    padding: var(--sat) calc(12px + var(--sar)) 0 12px;
  }
  .stat .credits { grid-row: 1; grid-column: 1; }
  .stat .power { grid-row: 1; grid-column: 2; }
  .btns { padding: 0 calc(12px + var(--sar)) 8px 12px; align-items: start; }
  .hb-map { display: inline-flex !important; }
  .mini {
    grid-area: map;
    justify-self: end;
    align-self: start;
    display: none;
    width: 200px;
    height: 200px;
    margin: 8px 8px 0 0;
    padding: 3px;
    border-radius: var(--r);
    background: linear-gradient(180deg, var(--edge-2), var(--panel));
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
  }
  .mini.open { display: block; }
  .mini-canvas { border-radius: 4px; }
  .build { grid-auto-rows: 88px; }
}

/* --- left-handed: the horizontal order mirrors ------------------------- */

.game.lefty .cmd-row { direction: rtl; }
.game.lefty .cmd-row > * { direction: ltr; }
.game.lefty { grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "btns stat" "map map" "cmd cmd" "sel sel" "tabs tabs" "build build"; }
.game.lefty .btns { padding: var(--sat) 0 0 calc(8px + var(--sal)); }
.game.lefty .stat { padding: var(--sat) calc(12px + var(--sar)) 0 8px; justify-items: end; }
.game.lefty .mini { justify-self: start; margin: 8px 0 0 calc(8px + var(--sal)); }
@media (orientation: landscape) and (max-height: 559px) and (min-height: 360px) {
  .game.lefty {
    grid-template-columns: calc(216px + var(--sal)) 56px minmax(0, 1fr);
    grid-template-areas:
      "stat cmd map"
      "btns cmd map"
      "tabs cmd map"
      "build cmd map"
      "sel cmd map";
  }
  .game.lefty .cmd-row { direction: ltr; }
  .game.lefty .stat { padding: var(--sat) 8px 0 calc(10px + var(--sal)); justify-items: start; }
  .game.lefty .btns { padding: 0 8px 8px calc(8px + var(--sal)); }
  .game.lefty .build { padding: 8px 8px 8px calc(8px + var(--sal)); }
  .game.lefty .sel { padding: 8px 8px var(--sab) calc(8px + var(--sal)); }
  .game.lefty .tabs { padding: 0 8px 0 calc(8px + var(--sal)); }
  .game.lefty .mini { justify-self: end; margin: calc(8px + var(--sat)) calc(8px + var(--sar)) 0 0; }
}
@media (orientation: landscape) and (max-height: 359px) {
  .game.lefty {
    grid-template-columns: calc(8px + var(--sal)) 48px 8px 48px 8px 48px 8px 48px 8px 112px minmax(0, 1fr);
    grid-template-areas:
      ".     .     .     .     .     .     .     .     .     cmd map"
      ".     menu  .     fs    .     stat  stat  stat  .     cmd map"
      ".     .     .     .     .     .     .     .     .     cmd map"
      ".     bmap  .     tabs  tabs  tabs  tabs  tabs  .     cmd map"
      ".     .     .     tabs  tabs  tabs  tabs  tabs  .     cmd map"
      ".     bsel  .     tabs  tabs  tabs  tabs  tabs  .     cmd map"
      "build build build build build build build build build cmd map";
  }
  .game.lefty .stat { padding: 0; justify-items: start; }
  .game.lefty .build { padding: 8px 8px calc(8px + var(--sab)) calc(8px + var(--sal)); }
  .game.lefty .mini { justify-self: end; margin: calc(8px + var(--sat)) calc(8px + var(--sar)) 0 0; }
}
@media (min-width: 900px) and (min-height: 560px) {
  .game.lefty {
    grid-template-columns: calc(104px + var(--sal)) 136px minmax(0, 1fr);
    grid-template-areas:
      "btns  stat  map"
      "mini  mini  map"
      "tabs  tabs  map"
      "build build map"
      "sel   sel   map"
      "sel   sel   cmd";
  }
  .game.lefty .btns { justify-content: flex-start; padding: var(--sat) 0 0 calc(8px + var(--sal)); }
  .game.lefty .stat { padding: var(--sat) 12px 0 0; justify-items: end; }
  .game.lefty .mini { justify-self: end; margin: 0 0 8px; }
}
@media (min-width: 900px) and (min-height: 640px) and (max-height: 759px) {
  .game.lefty .mini { justify-self: center; }
}
@media (min-width: 900px) and (min-height: 560px) and (max-height: 639px) {
  .game.lefty {
    grid-template-areas:
      "stat  stat  map"
      "btns  btns  map"
      "tabs  tabs  map"
      "build build map"
      "sel   sel   map"
      "sel   sel   cmd";
  }
  .game.lefty .btns { padding: 0 12px 8px calc(12px + var(--sal)); }
  .game.lefty .stat { padding: var(--sat) 12px 0 calc(12px + var(--sal)); justify-items: start; }
  .game.lefty .mini { grid-area: map; justify-self: start; margin: 8px 0 0 8px; }
}

/* ======================================================================
 * Header: credits, power, buttons
 * ==================================================================== */

.credits {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  border-radius: var(--r);
  transition: color 180ms;
}
.cr-ic {
  width: 12px;
  height: 12px;
  flex: none;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffc27a, #e2642a 55%, #8e2a0e);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
}
.cr-val { font-size: 19px; font-weight: 750; letter-spacing: 0.01em; color: var(--ink); line-height: 1; }
.credits.full .cr-val { color: var(--warn); }
.credits.flash-good .cr-val { animation: flash-good 600ms var(--ease); }
.credits.flash-bad { animation: flash-bad 600ms var(--ease); }
.credits.flash-warn .cr-val { animation: flash-warn 600ms var(--ease); }

/* When the header is tight (five-digit credits at 412 px) the bar gives way
   first; the margin number never clips. */
.power { display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; color: var(--ink-2); }
.power .gl { width: 14px; height: 14px; color: var(--good); flex: none; }
.pw-num { flex: none; }
.pw-bar { position: relative; flex: 1 1 auto; min-width: 0; max-width: 120px; height: 6px; border-radius: 3px; background: rgba(134, 212, 110, 0.2); box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.08); overflow: hidden; }
.pw-bar i { position: absolute; inset: 0; transform-origin: left center; background: linear-gradient(90deg, #5fae4c, var(--good)); border-radius: 3px; }
.pw-num { font-size: 11px; color: var(--ink-2); white-space: nowrap; }
.power.tight .gl { color: var(--warn); }
.power.tight .pw-bar i { background: linear-gradient(90deg, #c98d22, var(--warn)); }
.power.low .gl, .power.low .pw-num { color: var(--bad); }
.power.low .pw-bar i { background: linear-gradient(90deg, #b02c1f, var(--bad)); }
.power.flash-bad { animation: flash-bad 600ms var(--ease); }

.hb {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 44px;
  width: 50px;
  height: 44px;
  padding: 0 4px;
  border: 0;
  border-radius: var(--r);
  color: var(--ink);
  background: linear-gradient(180deg, var(--panel-3), var(--panel-2));
  box-shadow: inset 0 1px 0 var(--hi), inset 0 0 0 1px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.4);
}
.hb .gl { width: 18px; height: 18px; color: var(--ink-2); }
.hb .lbl { font-size: 10px; font-weight: 650; letter-spacing: 0.02em; line-height: 1; white-space: nowrap; }
.hb:active, .hb.pressed { transform: translateY(1px); background: var(--panel-2); }
.hb.lit { background: linear-gradient(180deg, color-mix(in srgb, var(--house) 55%, var(--panel-3)), color-mix(in srgb, var(--house) 35%, var(--panel-2))); }
.hb.lit .gl { color: var(--ink); }
@media (hover: hover) { .hb:hover { background: linear-gradient(180deg, #43342566, var(--panel-3)); } }

/* ======================================================================
 * Tabs
 * ==================================================================== */

/* A tab is icon over label in every layout. The progress bar runs along the
   top edge (y 2-4) and the active underline along the bottom (2 px), so
   neither crosses the label: 5 px above the content, 3 px below it. */
.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  height: 44px;
  padding: 5px 2px 3px;
  border: 0;
  border-radius: var(--r);
  color: var(--ink-2);
  background: linear-gradient(180deg, var(--panel-2), #241c15);
  box-shadow: inset 0 1px 0 var(--hi), inset 0 0 0 1px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.tab-ic { width: 20px; height: 20px; border-radius: 4px; display: block; flex: none; }
.tab .lbl { font-size: 10px; font-weight: 650; line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tab .ls { display: none; }
.tab.on {
  color: var(--ink);
  background: linear-gradient(180deg, color-mix(in srgb, var(--house) 34%, var(--panel-3)), color-mix(in srgb, var(--house) 18%, var(--panel-2)));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), inset 0 0 0 1px color-mix(in srgb, var(--house) 70%, #000), inset 0 -2px 0 var(--house);
}
.tab.idle .tab-ic { filter: grayscale(0.85) brightness(0.8); }
.tab.idle:not(.on) { color: var(--ink-3); }
.tab.off { opacity: 0.42; }
.tab.off .tab-ic { filter: grayscale(1) brightness(0.65); }
.tab .dot { position: absolute; top: 6px; right: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 2px var(--panel); transform: scale(0); transition: transform 160ms var(--ease); }
.tab .dot.show { transform: scale(1); }
/* Its factory repeats (sidebar.js Repeat): a corner mark seen from any tab. */
.tab.rep::after {
  content: '';
  position: absolute;
  top: 5px;
  left: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 2px solid var(--sand);
  border-right-color: transparent;
}
.tab .tbar { position: absolute; left: 7px; right: 7px; top: 2px; height: 2px; border-radius: 1px; background: rgba(0, 0, 0, 0.5); opacity: 0; }
.tab .tbar.show { opacity: 1; }
.tab .tbar i { position: absolute; inset: 0; transform-origin: left center; background: var(--sand); border-radius: 1px; }

/* ======================================================================
 * Build tiles
 * ==================================================================== */

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-width: 0;
  padding: 4px 4px 3px;
  border: 0;
  border-radius: var(--r);
  color: var(--ink);
  background: linear-gradient(180deg, var(--panel-3), var(--panel-2) 70%);
  box-shadow: inset 0 1px 0 var(--hi), inset 0 0 0 1px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.45);
  text-align: center;
  transition: transform 90ms var(--ease);
}
.tile .ic {
  position: relative;
  display: block;
  width: 50px;
  height: 50px;
  margin: 0 auto;
  border-radius: 4px;
  overflow: hidden;
  background: var(--well);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.6);
  flex: none;
}
/* Wide from 760 px high has 98 px tile rows; below that 88, as elsewhere. */
@media (min-width: 900px) and (min-height: 760px) {
  .tile .ic { width: 60px; height: 60px; }
}
.tile canvas { width: 100%; height: 100%; display: block; }
.tile .sweep {
  --p: 1;
  position: absolute;
  inset: 0;
  background: conic-gradient(from 0deg, rgba(0, 0, 0, 0) 0 calc(var(--p) * 360deg), rgba(10, 7, 4, 0.66) calc(var(--p) * 360deg) 360deg);
  pointer-events: none;
}
.tile.building .ic { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.6), 0 0 0 2px color-mix(in srgb, var(--house) 75%, #fff 0%); }
.tile.stalled .sweep { background: conic-gradient(from 0deg, rgba(240, 180, 60, 0.18) 0 calc(var(--p) * 360deg), rgba(10, 7, 4, 0.72) calc(var(--p) * 360deg) 360deg); }
.tile .badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 800;
  line-height: 18px;
  color: #fff;
  background: var(--house);
  box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.7);
  transform: scale(0);
  transition: transform 140ms var(--ease);
}
.tile .badge.show { transform: scale(1); }
/* The queue's speed (sidebar.js multText): '×1.45' with two factories of its
   type, '×0.5' on low power; top left, opposite the count badge. */
.tile .mult {
  position: absolute;
  top: 2px;
  left: 2px;
  height: 15px;
  padding: 0 3px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 800;
  line-height: 15px;
  letter-spacing: -0.02em;
  color: var(--sand-ink);
  background: var(--sand);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
  display: none;
  pointer-events: none;
}
.tile .mult.show { display: block; }
.tile .mult.slow { color: #fff; background: var(--bad); }
/* Names break between words only ('Ornithopter' once split as 'Ornithopte' +
   'r'). A name with a word of 10 letters or more carries `long` (sidebar.js)
   and a smaller face, so that word fits the narrowest tile (wide, 59 px). */
.tile .nm {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-top: 4px;
  font-size: 10.5px;
  font-weight: 650;
  line-height: 1.12;
  overflow: hidden;
  color: var(--ink);
  overflow-wrap: normal;
  word-break: normal;
  hyphens: manual;
}
.tile .nm.long { font-size: 9.5px; letter-spacing: -0.01em; }
.tile .cap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 2px 1px 1px;
  font-size: 10.5px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--sand);
  background: rgba(12, 8, 5, 0.82);
  box-shadow: 0 -1px 0 rgba(255, 230, 190, 0.08);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile .cap.long { white-space: normal; font-size: 9.5px; line-height: 1.08; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
/* Words in place of the caption (a reason, 'Sure?', 'Building 40%') keep
   their case on the Place tile too, so 'No room' is not cut to 'NO R...'. */
.tile.ready .cap.say { text-transform: none; letter-spacing: 0; }
.tile .cap.cheap { color: var(--good); }
/* The Repeat toggle of a unit tab: a tile with the loop glyph; on, it takes
   the house colour like a lit tile. */
.tile-rep .ic { display: flex; align-items: center; justify-content: center; color: var(--ink-2); }
.tile-rep .ic .gl { width: 26px; height: 26px; margin-bottom: 12px; }
.tile-rep.on { background: linear-gradient(180deg, color-mix(in srgb, var(--house) 40%, var(--panel-3)), var(--panel-2)); }
.tile-rep.on .ic .gl { color: var(--ink); }
.tile-rep.on .cap { color: #10200b; background: var(--good); }
.tile .cap.dear { color: #ff8a70; }
.tile.off .ic canvas { filter: grayscale(0.9) brightness(0.62); }
.tile.off .nm { color: var(--ink-3); }
.tile.off .cap { color: var(--ink-3); }
.tile.ready { box-shadow: inset 0 1px 0 var(--hi), inset 0 0 0 1px var(--good), 0 0 0 1px rgba(134, 212, 110, 0.35); animation: ready-glow 1.6s ease-in-out infinite; }
.tile.ready .cap { color: #10200b; background: var(--good); letter-spacing: 0.05em; text-transform: uppercase; }
.tile.lit { background: linear-gradient(180deg, color-mix(in srgb, var(--house) 40%, var(--panel-3)), var(--panel-2)); }
.tile.pulse { animation: sand-pulse 1.4s ease-in-out infinite; }
.tile.down { transform: translateY(1px) scale(0.98); }
.tile.confirming, .slot.confirming, .btn.confirming, .slot-row.confirming {
  background: linear-gradient(180deg, #8f2418, #6d1a11) !important;
  box-shadow: inset 0 0 0 1px #ff7a68, 0 0 0 1px rgba(240, 80, 62, 0.45) !important;
  color: #fff !important;
}
.tile.confirming .nm { color: #ffe1d9 !important; }
.tile.confirming .cap, .tile.refusing .cap { color: #fff !important; background: var(--bad) !important; text-transform: none; letter-spacing: 0; }
@media (hover: hover) { .tile:hover { background: linear-gradient(180deg, #44352777, var(--panel-3) 30%, var(--panel-2)); } }

/* starport cart */
.cart {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px;
  border-radius: var(--r);
  background: rgba(0, 0, 0, 0.25);
  box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.06);
}
.cart-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.cart-head > span { font-size: 11px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.06em; }
.cart-list { display: grid; grid-template-columns: repeat(6, 20px); gap: 3px; }
.cart-ic, .cart-slot { width: 20px; height: 20px; border-radius: 3px; display: block; }
.cart-slot { background: rgba(0, 0, 0, 0.35); box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.06); }
.cart-btns { display: flex; gap: 8px; }
.cart-btns button {
  flex: 1 1 0;
  min-width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 0;
  border-radius: var(--r);
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  background: linear-gradient(180deg, var(--panel-3), var(--panel-2));
  box-shadow: inset 0 1px 0 var(--hi), inset 0 0 0 1px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
}
.cart-btns .gl { width: 16px; height: 16px; }
.cart-send.go { color: var(--sand-ink); background: linear-gradient(180deg, #f1bf74, var(--sand)); }
.cart-btns .off { color: var(--ink-3); }
/* tall and squat: the cart sits at the end of the sideways strip */
.build[data-tab="starport"] > .cart { grid-column: auto; grid-row: 1; width: 196px; }
/* short and wide: under the tiles, across the grid */
@media (orientation: landscape) and (max-height: 559px) and (min-height: 360px), (min-width: 900px) and (min-height: 560px) {
  .build[data-tab="starport"] > .cart { width: auto; grid-column: 1 / -1; grid-row: auto; }
}

/* ======================================================================
 * Selection panel
 * ==================================================================== */

.sel-none { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sel-one { display: flex; align-items: center; gap: 8px; min-width: 0; width: 100%; }
.sel-ic { width: 32px; height: 32px; border-radius: 4px; flex: none; display: block; }
.worm-ic { background: radial-gradient(circle at 50% 40%, #e3b77a, #8a5a2c 60%, #3b2412); }
.sel-txt { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.sel-name { font-size: 12.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.sel-one.enemy .sel-name { color: #ffb1a3; }
/* A worm's name and what it is may take two lines (one own worm: 'Rumok,
   sandworm'; the Queen's 'Irdanul, the Worm Queen' is the longest). */
.sel-name.wrap { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.2; overflow-wrap: anywhere; }
.chip .worm-ic { box-shadow: inset 0 0 0 2px var(--hc, transparent); }
.sel-sub { display: flex; align-items: center; gap: 6px; flex: none; }
.sel-hp { font-size: 11px; color: var(--ink-2); white-space: nowrap; }
.hp { position: relative; width: 56px; height: 5px; border-radius: 3px; background: rgba(0, 0, 0, 0.55); overflow: hidden; box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.06); flex: none; }
.hp i { position: absolute; inset: 0; transform-origin: left center; border-radius: 3px; background: var(--good); }
.hp.mid i { background: var(--warn); }
.hp.low i { background: var(--bad); }
/* A chip is a 44 px button in every layout that has the panel: a tap selects
   that type in the viewport, or narrows a mixed selection to it. */
.chips { display: flex; gap: 8px; min-width: 0; overflow: hidden; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: none;
  height: 44px;
  min-width: 44px;
  padding: 0 8px 0 4px;
  border: 0;
  border-radius: var(--r);
  color: var(--ink);
  background: linear-gradient(180deg, var(--panel-3), var(--panel-2));
  box-shadow: inset 0 1px 0 var(--hi), inset 0 0 0 1px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.4);
  font-size: 13px;
  font-weight: 750;
}
.chip .sel-ic { width: 30px; height: 30px; border-radius: 4px; }
button.chip:active { transform: translateY(1px); }
@media (hover: hover) { button.chip:hover { filter: brightness(1.12); } }
.chip-name { display: none; font-weight: 600; color: var(--ink-2); }
/* Chips that would not fit whole are left out (hud.js fitChips); this says how many. */
.chip-more { flex: none; align-self: center; padding: 0 4px; font-size: 13px; font-weight: 750; color: var(--ink-2); }
/* A group's total before its chips: the count over the word. */
.sel-total { flex: none; align-self: center; display: flex; flex-direction: column; align-items: center; min-width: 30px; line-height: 1; }
.sel-total b { font-size: 16px; font-weight: 800; color: var(--ink); }
.sel-total span { margin-top: 2px; font-size: 9.5px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.04em; }

@media (orientation: landscape) and (max-height: 559px) and (min-height: 360px) {
  .sel-ic { width: 30px; height: 30px; }
  .sel-sub .sel-hp { display: none; }
  .hp { width: 40px; }
  .sel-txt { flex-direction: column; align-items: flex-start; gap: 3px; }
  .sel-name { font-size: 11.5px; max-width: 100%; }
  .sel-none { font-size: 11.5px; white-space: normal; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .chip { font-size: 12.5px; }
  /* One unit: its HP is text beside the chip here too (the bar alone is the
     building's and the enemy's line, which have no chip to make room for). */
  .sel-unit .sel-sub .sel-hp { display: inline; font-size: 10.5px; }
}

@media (min-width: 900px) and (min-height: 560px) {
  .sel-ic { width: 52px; height: 52px; border-radius: 5px; }
  .sel-one { gap: 10px; }
  .sel-txt { flex-direction: column; align-items: flex-start; gap: 6px; }
  .sel-name { font-size: 14px; max-width: 100%; }
  .hp { width: 110px; height: 6px; }
  .sel-none { white-space: normal; line-height: 1.4; }
  /* One unit or building: the bar gives way so 'HP / max' stays whole inside
     the 216 px the panel has for icon or chip and words. */
  .sel-one .sel-sub { align-self: stretch; min-width: 0; }
  .sel-one .hp { flex: 1 1 auto; width: auto; min-width: 32px; max-width: 110px; }
  .sel-one .sel-hp { flex: none; }
}

/* ======================================================================
 * Command strip
 * ==================================================================== */

.slot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 44px;
  min-height: 44px;
  padding: 2px 3px;
  border: 0;
  border-radius: var(--r);
  color: var(--ink);
  background: linear-gradient(180deg, var(--panel-3), var(--panel-2));
  box-shadow: inset 0 1px 0 var(--hi), inset 0 0 0 1px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
.slot[data-slot="1"] { grid-column: 1; grid-row: 1; }
.slot[data-slot="2"] { grid-column: 2; grid-row: 1; }
.slot[data-slot="3"] { grid-column: 3; grid-row: 1; }
.slot[data-slot="4"] { grid-column: 4; grid-row: 1; }
.slot[data-slot="5"] { grid-column: 5; grid-row: 1; }
.slot[data-slot="6"] { grid-column: 6; grid-row: 1; }
.slot[data-slot="7"] { grid-column: 7; grid-row: 1; }
.slot .gl { width: 19px; height: 19px; color: var(--ink-2); }
.slot .lbl { font-size: 10.5px; font-weight: 700; line-height: 1.05; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.slot .lbl.long { font-size: 9.5px; letter-spacing: -0.01em; }
/* Seven slots share a phone's row (49.7 px at 411): a long word (a stance)
   breaks at its soft hyphen instead of losing its tail ('Aggress...' on the
   pando AVD, 2026-10-09). */
.slot .lbl.long { white-space: normal; text-align: center; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: normal; line-height: 1.05; }
.slot .kbd {
  display: none;
  position: absolute;
  top: 3px;
  right: 4px;
  font: 700 9px/1 var(--font);
  color: var(--ink-3);
  padding: 2px 3px;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.12);
}
.slot .kbd:empty { display: none !important; }
/* Not `any-pointer`: the AVD matches `any-pointer: fine` as well as coarse,
   and that put key letters on a phone (DESIGN.md section 11, Keys). */
@media (hover: hover) and (pointer: fine) { .slot .kbd { display: block; } }
.slot:active, .slot.pressed { transform: translateY(1px); filter: brightness(0.92); }
.slot.empty { background: rgba(0, 0, 0, 0.18); box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.04); cursor: default; }
.slot.empty .gl, .slot.empty .lbl { visibility: hidden; }
.slot.off { color: var(--ink-3); }
.slot.off .gl { color: var(--ink-3); opacity: 0.7; }
.slot.active { background: linear-gradient(180deg, color-mix(in srgb, var(--house) 50%, var(--panel-3)), color-mix(in srgb, var(--house) 30%, var(--panel-2))); }
.slot.active .gl { color: var(--ink); }
.slot.danger .gl { color: #ff8d7c; }
.slot.warn { box-shadow: inset 0 1px 0 var(--hi), inset 0 0 0 1.5px var(--bad); }
.slot.warn .gl { color: #ff8d7c; }
.slot.go { color: #0f1d0a; background: linear-gradient(180deg, #a6e48f, var(--good)); }
.slot.go .gl { color: #0f1d0a; }
.slot.hidden { visibility: hidden; }
@media (hover: hover) { .slot:not(.empty):hover { filter: brightness(1.12); } }
@media (min-width: 900px) and (min-height: 560px) {
  .slot { flex-direction: row; gap: 7px; }
  .slot .lbl { font-size: 12px; }
}
@media (orientation: landscape) and (max-height: 559px) {
  .slot { padding: 2px 1px; }
  .slot .lbl { font-size: 9.5px; white-space: normal; text-align: center; line-height: 1.05; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: normal; }
  .slot .gl { width: 18px; height: 18px; }
}
/* short: one column of six */
@media (orientation: landscape) and (max-height: 559px) and (min-height: 360px) {
  .slot[data-slot] { grid-column: 1; }
  .slot[data-slot="1"] { grid-row: 1; }
  .slot[data-slot="2"] { grid-row: 2; }
  .slot[data-slot="3"] { grid-row: 3; }
  .slot[data-slot="4"] { grid-row: 4; }
  .slot[data-slot="5"] { grid-row: 5; }
  .slot[data-slot="6"] { grid-row: 6; }
  .slot[data-slot="7"] { grid-row: 7; }
}
/* squat: two columns of three; slot 6 (the back-out ladder) bottom right */
@media (orientation: landscape) and (max-height: 359px) {
  .slot[data-slot="1"] { grid-column: 1; grid-row: 1; }
  .slot[data-slot="2"] { grid-column: 2; grid-row: 1; }
  .slot[data-slot="3"] { grid-column: 1; grid-row: 2; }
  .slot[data-slot="4"] { grid-column: 2; grid-row: 2; }
  .slot[data-slot="5"] { grid-column: 1; grid-row: 3; }
  .slot[data-slot="6"] { grid-column: 2; grid-row: 3; }
  .slot[data-slot="7"] { grid-column: 1 / 3; grid-row: 4; flex-direction: row; gap: 6px; }
}
/* Slot 8, Airlift (section 7 Air, By hand): only while the player owns a
   Carryall (has-lift); then the row has eight slots and scrolls where eight
   44 px slots do not fit (tall below 424 px wide, short below 424 px high). */
.slot[data-slot="8"] { display: none; grid-column: 8; grid-row: 1; }
.cmd-row.has-lift .slot[data-slot="8"] { display: flex; }
.cmd-row.has-lift { grid-template-columns: repeat(8, minmax(44px, 1fr)); }
@media (min-width: 900px) and (min-height: 560px) {
  .cmd-row.has-lift { grid-template-columns: repeat(8, minmax(44px, 132px)); }
}
/* A phone upright: eight slots are 44 px, so the words take the smaller face
   ('Deselect' read 'Desel...' at 10.5 px on a 412 px phone). */
@media (orientation: portrait) and (max-width: 519px) {
  .cmd-row.has-lift .slot .lbl { font-size: 9.5px; letter-spacing: -0.01em; }
}
@media (orientation: landscape) and (max-height: 559px) and (min-height: 360px) {
  .cmd-row.has-lift { grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(8, minmax(44px, 1fr)); }
  .slot[data-slot="8"] { grid-column: 1; grid-row: 8; }
}
/* squat: Follow and Airlift share the fourth row */
@media (orientation: landscape) and (max-height: 359px) {
  .cmd-row.has-lift { grid-template-columns: repeat(2, minmax(44px, 1fr)); }
  .cmd-row.has-lift .slot[data-slot="7"] { grid-column: 1; grid-row: 4; flex-direction: column; gap: 3px; }
  .slot[data-slot="8"] { grid-column: 2; grid-row: 4; }
}

.banner {
  grid-column: 1 / 5;
  grid-row: 1;
  z-index: 1;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  padding: 0 10px;
  border-radius: var(--r);
  font-size: 13px;
  font-weight: 750;
  color: var(--ink);
  background: linear-gradient(180deg, color-mix(in srgb, var(--house) 46%, var(--panel-3)), color-mix(in srgb, var(--house) 28%, var(--panel-2)));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), inset 0 0 0 1px color-mix(in srgb, var(--house) 70%, #000);
  overflow: hidden;
}
.banner.show { display: flex; animation: banner-in 140ms var(--ease); }
.banner .gl { width: 18px; height: 18px; }
.banner .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (orientation: landscape) and (max-height: 559px) and (min-height: 360px) {
  .banner { grid-column: 1; grid-row: 1 / 5; flex-direction: column; padding: 8px 3px; text-align: center; font-size: 11px; line-height: 1.15; }
  .banner .lbl { white-space: normal; }
}
/* squat: the banner spans the top two rows over both columns (slots 1-4) */
@media (orientation: landscape) and (max-height: 359px) {
  .banner { grid-column: 1 / -1; grid-row: 1 / 3; flex-direction: column; padding: 6px 4px; text-align: center; font-size: 11.5px; line-height: 1.2; }
  .banner .lbl { white-space: normal; }
}
/* A refusal reason outside a mode (a map tap the selection cannot obey):
   for 2 s a narrow notice over the map's edge beside slots 1-4, never over
   them, that takes no press. The slots keep their icons and words in view
   and answer where they always are, so a Stop or a Deploy right after the
   refusal is not a blind press. The banner lives in the scroller (.cmd-row),
   which is not positioned, so the notice is absolute against the frame
   (.cmd) and placed from the measured box of slots 1-4 (commandbar.js
   placeNotice: --na-x, --na-y, --na-w, --na-h in frame coordinates, held
   8 px inside the viewport so the 5 px shake never leaves it): above that
   box where the strip runs along the map's foot (tall, wide), beside it
   where the strip is a column (short, squat). */
.banner.flash {
  position: absolute;
  left: var(--na-x, 8px);
  bottom: calc(100% - var(--na-y, 0px) + 12px);
  width: max-content;
  max-width: var(--na-w, calc(100% - 16px));
  min-height: 30px;
  flex-direction: row;
  padding: 0 12px;
  font-size: 12.5px;
  line-height: 1.2;
  z-index: 7;
  pointer-events: none;
  color: #ffd9d1;
  background: linear-gradient(180deg, #7d2014, #5c160e);
  box-shadow: inset 0 0 0 1px var(--bad), 0 4px 12px rgba(0, 0, 0, 0.45);
}
.banner.flash .gl { display: none; }
.banner.flash .lbl { white-space: nowrap; }
@media (orientation: landscape) and (max-height: 559px) {
  .banner.flash { left: auto; right: calc(100% - var(--na-x, 0px) + 12px); top: var(--na-y, 0px); bottom: auto; max-width: 220px; padding: 6px 12px; text-align: left; }
  .game.lefty .banner.flash { right: auto; left: calc(var(--na-x, 0px) + var(--na-w, 100%) + 12px); }
}
@media (orientation: landscape) and (max-height: 359px) {
  .banner.flash { right: calc(100% - var(--na-x, 0px) + 10px); }
  .game.lefty .banner.flash { left: calc(var(--na-x, 0px) + var(--na-w, 100%) + 10px); }
}

/* ======================================================================
 * Refusal and feedback
 * ==================================================================== */

.refusing { animation: shake 300ms linear !important; }
.refusing.tile, .refusing.slot, .refusing.tab, .refusing.btn, .refusing.hb, .refusing.cart-send, .refusing.cart-clear, .refusing.mission, .refusing.slot-row, .refusing.banner {
  background: linear-gradient(180deg, #7d2014, #5c160e) !important;
  box-shadow: inset 0 0 0 1px var(--bad) !important;
}
.refusing .cap, .refusing.slot .lbl, .refusing.banner .lbl { color: #ffd9d1 !important; }

/* The goal button (section 11, Goal): over the map's top-left corner for the
 * whole game, 44 px high, the toasts in a column under it. Short words in
 * `squat` and narrow `tall` ('Goal 640/1,000', 'Goal 7 left'), full words
 * where the map is wide ('Goal 640 / 1,000 spice', 'Goal: enemy base, 7
 * buildings left'); the card holds the whole goal either way. Its box never
 * moves; only its width follows its words. */
.goal-b {
  position: absolute;
  top: calc(8px + var(--sat));
  left: calc(8px + var(--sal));
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 44px;
  height: 44px;
  max-width: calc(100% - 16px);
  padding: 0 12px 0 9px;
  border: 0;
  border-left: 3px solid var(--sand);
  border-radius: var(--r);
  font: inherit;
  font-size: 12.5px;
  font-weight: 750;
  line-height: 1.15;
  text-align: left;
  white-space: nowrap;
  color: var(--ink);
  background: rgba(16, 12, 9, 0.84);
  box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.14), 0 4px 12px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}
.goal-b .gl { width: 16px; height: 16px; color: var(--sand); }
.goal-b:active { transform: translateY(1px); }
.goal-b.lit { background: rgba(48, 36, 24, 0.94); box-shadow: inset 0 0 0 1px var(--sand), 0 4px 12px rgba(0, 0, 0, 0.4); }
@media (hover: hover) { .goal-b:hover { background: rgba(40, 30, 21, 0.92); } }
.goal-txt { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.goal-full { display: none; }
.goal-bar { display: none; position: relative; height: 4px; border-radius: 2px; overflow: hidden; background: rgba(230, 173, 94, 0.22); }
.goal-b.harvest .goal-bar { display: block; }
.goal-bar i, .gc-bar i { position: absolute; inset: 0; transform-origin: left center; transform: scaleX(0); background: linear-gradient(90deg, #c7883f, var(--sand)); border-radius: 2px; }
.goal-b.flash-good .goal-words { animation: flash-good 600ms var(--ease); }
@media (min-width: 600px) and (min-height: 360px), (orientation: landscape) and (min-height: 360px) {
  .goal-full { display: inline; }
  .goal-short { display: none; }
}

/* The goal card: the whole goal, how to get there and how far it is, at
 * the top centre of the map when a game starts (and from the goal button).
 * It takes no press and draws under every other control over the map;
 * ui/hud.js puts it under the goal button where the two share a column. */
.goal-card {
  position: absolute;
  top: 8px;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: fit-content;
  max-width: min(400px, calc(100% - 24px));
  z-index: 3;
  display: grid;
  gap: 3px;
  padding: 11px 16px 12px;
  border-radius: 8px;
  color: var(--ink);
  background: rgba(20, 15, 11, 0.93);
  box-shadow: inset 0 0 0 1px rgba(230, 173, 94, 0.5), 0 10px 30px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  animation: hint-in 200ms var(--ease);
}
.gc-kick { font-size: 11px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--sand); }
.gc-goal { font-size: 17px; font-weight: 850; line-height: 1.2; }
.gc-how { font-size: 13px; line-height: 1.35; color: var(--ink-2); }
.gc-foot { display: flex; align-items: center; gap: 10px; margin-top: 4px; font-size: 12px; font-weight: 750; color: var(--ink); }
.gc-bar { position: relative; flex: 1 1 auto; min-width: 60px; max-width: 160px; height: 5px; border-radius: 3px; overflow: hidden; background: rgba(230, 173, 94, 0.22); }
@media (orientation: landscape) and (max-height: 359px) {
  .goal-card { padding: 8px 12px 9px; gap: 2px; }
  .gc-goal { font-size: 15px; }
  .gc-how { font-size: 12px; }
  .gc-foot { margin-top: 2px; }
}

.toasts {
  position: absolute;
  top: calc(60px + var(--sat));
  left: calc(10px + var(--sal));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  /* 8 px: two stacked Show buttons keep the gap every pair of targets has. */
  gap: 8px;
  pointer-events: none;
  max-width: calc(100% - 190px);
  z-index: 4;
}
.toast {
  padding: 6px 10px;
  border-radius: var(--r);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink);
  background: rgba(16, 12, 9, 0.84);
  box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.1), 0 4px 12px rgba(0, 0, 0, 0.4);
  border-left: 3px solid var(--ink-3);
  animation: toast-in 180ms var(--ease);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.toast.good { border-left-color: var(--good); }
.toast.bad { border-left-color: var(--bad); }
/* A toast that is a camera link ('Refinery dock blocked', 'Harvester under
   attack'): its words take no press, like every toast, so a tap on them
   reaches the unit under them; only the 44 px Show button at its end does.
   The words may wrap rather than lose a word. */
.toast.link {
  display: inline-flex;
  align-items: stretch;
  padding: 0 0 0 10px;
  min-height: 44px;
  line-height: 1.2;
  white-space: normal;
}
.toast.link .toast-txt { align-self: center; min-width: 0; padding: 6px 10px 6px 0; }
.toast.link .toast-go {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: none;
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px 0 10px;
  border: 0;
  border-radius: 0;
  font: inherit;
  font-size: 12.5px;
  font-weight: 800;
  color: var(--sand);
  background: rgba(62, 46, 30, 0.98);
  box-shadow: inset 1px 0 0 rgba(255, 230, 190, 0.14);
  cursor: pointer;
}
.toast.link .gl { width: 16px; height: 16px; }
.toast.link .toast-go:active { transform: translateY(1px); }
@media (hover: hover) { .toast.link .toast-go:hover { filter: brightness(1.15); } }
/* Read: the line dims so the map shows through; a Show button stays solid. */
.toast.dim { opacity: 0.5; transition: opacity 500ms; }
.toast.link.dim { opacity: 1; background: rgba(16, 12, 9, 0.42); box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.06); }
.toast.link.dim .toast-txt { opacity: 0.6; transition: opacity 500ms; }
.toast.out, .toast.link.out { opacity: 0; transform: translateY(-4px); transition: opacity 350ms, transform 350ms; }
@media (min-width: 900px) and (min-height: 560px) { .toasts { max-width: 60%; } }

/* The quiet note when a session ends during a game (section 13): no alarm
 * colour, no link, no press; it fades after a few seconds. One line where it
 * fits; the longest ('Signed in elsewhere as another account: ...') wraps
 * inside a phone's width instead of running off both edges. */
.signedout {
  position: absolute;
  top: calc(60px + var(--sat));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 24px);
  box-sizing: border-box;
  padding: 7px 12px;
  border-radius: var(--r);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  color: var(--ink-2);
  background: rgba(16, 12, 9, 0.78);
  box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.12);
  z-index: 5;
  pointer-events: none;
  transition: opacity 500ms;
}
.signedout.out { opacity: 0; }

/* first-run callouts */
.hint {
  position: absolute;
  top: 0;
  left: 0;
  max-width: 230px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.3;
  color: #1d140b;
  background: #fbe9c8;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(0, 0, 0, 0.35);
  animation: hint-in 220ms var(--ease);
  transition: opacity 160ms;
}
.hint.away { opacity: 0; }
.hints.paused .hint { opacity: 0; }
.hint-arrow { position: absolute; width: 12px; height: 12px; background: #fbe9c8; transform: rotate(45deg); }
.hint[data-side="top"] .hint-arrow { bottom: -5px; left: calc(var(--ax, 50%) - 6px); }
.hint[data-side="below"] .hint-arrow { top: -5px; left: calc(var(--ax, 50%) - 6px); }
.hint[data-side="left"] .hint-arrow { right: -5px; top: calc(var(--ay, 50%) - 6px); }
.hint[data-side="right"] .hint-arrow { left: -5px; top: calc(var(--ay, 50%) - 6px); }
/* Hint 4's line: no tip, centred at the map's top or bottom edge, placed
   once by firstrun.js (its max-width is 90% of the map's); the scouts are
   marked on the canvas. It takes no press: a tap through it reaches the map. */
.hint.hint-line { max-width: none; text-align: center; pointer-events: none; }
.hint-pulse { animation: hint-ring 1.2s ease-out infinite !important; }

/* ======================================================================
 * Screens: title, campaign, skirmish, settings, how to play, end
 * ==================================================================== */

/* The desert at dusk in CSS: what the splash, the loading screen and the
 * title show before (or instead of) the painted desert. The shade is the
 * title's darkening toward its text, the same over the gradient and the map. */
:root {
  --dusk: radial-gradient(130% 95% at 78% 38%, #8a5a2e 0%, #5a3a1f 34%, #2a1b10 68%, #120c08 100%);
  --shade:
    linear-gradient(90deg, rgba(12, 8, 5, 0.92) 0%, rgba(12, 8, 5, 0.72) 34%, rgba(12, 8, 5, 0.18) 70%, rgba(12, 8, 5, 0.05) 100%),
    linear-gradient(0deg, rgba(12, 8, 5, 0.65), rgba(12, 8, 5, 0) 40%);
}
.screens { position: fixed; inset: 0; z-index: 30; background: var(--bg); background-image: var(--dusk); }
.screens.over-game { background: rgba(8, 6, 4, 0.55); }
.screens.over-game .backdrop, .screens.over-game .backdrop-shade, .screens.over-game .backdrop-worm { display: none; }
/* Painted once per size at dpr 1 and scaled by CSS; it fades in when done. */
.backdrop { position: absolute; inset: 0; width: 100%; height: 100%; display: block; opacity: 0; transition: opacity 360ms ease-out; }
.backdrop.ready { opacity: 1; }
/* The worm: a small canvas moved by a transform; nothing else on the title moves. */
.backdrop-worm { position: absolute; left: 0; top: 0; display: block; pointer-events: none; opacity: 0; transition: opacity 360ms ease-out; will-change: transform; }
.backdrop-worm.ready { opacity: 1; }
.backdrop-shade {
  position: absolute;
  inset: 0;
  background: var(--shade);
}

/* The splash in index.html: the first paint, before any module has loaded.
 * Its word sits where the title's wordmark will, so the title only adds. */
.splash { position: fixed; inset: 0; z-index: 60; background: var(--shade), var(--bg); background-image: var(--shade), var(--dusk); pointer-events: none; }
.splash-in { padding: calc(28px + var(--sat)) calc(20px + var(--sar)) 0 calc(20px + var(--sal)); max-width: 440px; }
.splash .tagline { animation: splash-breathe 1.6s ease-in-out infinite alternate; }
@keyframes splash-breathe { from { opacity: 0.55; } to { opacity: 1; } }
@media (min-width: 900px) {
  .splash-in { padding-left: calc(64px + var(--sal)); padding-top: calc(56px + var(--sat)); }
}
@media (max-height: 560px) and (orientation: landscape) {
  .splash .wordmark { font-size: 72px; }
}

/* While a game is prepared under the loading screen the HUD is laid out (the
 * camera measures the map) but not painted, so it is rasterised once, in the
 * frame of the reveal (main.js, buildGame). */
.game.preparing { visibility: hidden; }

/* The loading screen (section 11, Paint promptly): over everything, it takes
 * every press, and it is up in the frame of the tap that starts a game. */
.loading {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  background: var(--bg);
  background-image: var(--dusk);
  padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(16px + var(--sab)) calc(16px + var(--sal));
}
.load-in { width: min(420px, 100%); display: grid; gap: 10px; justify-items: center; text-align: center; }
.load-mark {
  font-size: clamp(48px, 13vw, 88px);
  font-weight: 850;
  letter-spacing: 0.14em;
  line-height: 1;
  color: #f7e6c4;
  text-shadow: 0 2px 0 #6e3f17, 0 10px 30px rgba(0, 0, 0, 0.55);
  margin-right: -0.14em; /* the letter spacing after the last letter */
}
.load-title { font-size: 18px; font-weight: 800; color: var(--ink); min-height: 1.35em; }
.load-sub { font-size: 14px; font-weight: 600; color: var(--ink-2); min-height: 1.35em; }
.load-bar { width: 100%; height: 8px; margin-top: 10px; border-radius: 4px; overflow: hidden; background: rgba(0, 0, 0, 0.45); box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.14); }
.load-bar i { display: block; width: 100%; height: 100%; background: linear-gradient(90deg, #c7883f, var(--sand)); transform-origin: 0 50%; transform: scaleX(0); transition: transform 140ms linear; }
@media (max-height: 360px) {
  .load-in { gap: 4px; }
  .load-mark { font-size: 44px; }
}
.page {
  position: absolute;
  inset: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: calc(20px + var(--sat)) calc(20px + var(--sar)) calc(24px + var(--sab)) calc(20px + var(--sal));
}
.page, .page * { touch-action: pan-y; }
.page input[type="range"] { touch-action: none; }
.page:not([data-screen="title"]):not([data-screen="end"]) { background: rgba(14, 10, 7, 0.82); }
.page > * { max-width: 760px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  min-width: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--r);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  background: linear-gradient(180deg, rgba(58, 45, 33, 0.94), rgba(38, 29, 21, 0.94));
  box-shadow: inset 0 1px 0 rgba(255, 230, 190, 0.1), inset 0 0 0 1px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.35);
  text-align: left;
  transition: transform 90ms var(--ease), filter 120ms;
}
.btn .gl { width: 18px; height: 18px; }
.btn:active { transform: translateY(1px) scale(0.99); }
@media (hover: hover) { .btn:hover { filter: brightness(1.14); } }
.btn.primary { color: var(--sand-ink); background: linear-gradient(180deg, #f3c47e, var(--sand)); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 6px 18px rgba(230, 173, 94, 0.22); }
.btn.big { min-height: 58px; font-size: 18px; font-weight: 800; letter-spacing: 0.01em; }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.2); min-height: 44px; font-size: 13px; }

.title {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 28px;
  max-width: 440px;
}
.brand { padding-top: 8px; }
.wordmark {
  margin: 0;
  font-size: clamp(64px, 17vw, 128px);
  font-weight: 850;
  letter-spacing: 0.14em;
  line-height: 0.95;
  color: #f7e6c4;
  text-shadow: 0 2px 0 #6e3f17, 0 10px 30px rgba(0, 0, 0, 0.55);
}
.tagline { margin: 12px 0 0; font-size: 15px; font-weight: 600; color: var(--ink-2); max-width: 44ch; line-height: 1.45; }
.title-menu { display: flex; flex-direction: column; gap: 10px; align-self: center; }
.title-menu .btn { width: 100%; justify-content: flex-start; }
/* Continue's place while it is absent: the height of Continue (always
   .btn.big), and no press (section 11, Screens). */
.title-gap { height: 58px; flex: none; pointer-events: none; }
.title-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
/* One height for both feet (the name and Sign out; Sign in and its caption
   up to three lines), so the menu centred above never moves when the foot
   changes. */
.title-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 54px; }
.who { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); min-width: 0; }
.who-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; font-size: 12px; font-weight: 800; color: var(--sand-ink); background: var(--sand); flex: none; }
/* Imprint and Privacy: a small, muted line under the foot. A plain link, and a
   44 px tall tap area on a finger, so it is easy to hit and never in the way. */
.title-small { margin: -10px 0 0; display: flex; flex-direction: column; align-items: flex-start; }
.title-small .title-legal { margin: 0; }
.title-legal { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--ink-2); opacity: 0.75; }
.title-legal a { color: inherit; text-decoration: underline; text-underline-offset: 3px; display: inline-flex; align-items: center; min-height: 32px; padding: 0 6px; }
.title-legal a:hover, .title-legal a:focus-visible { opacity: 1; color: var(--ink); }
.title-legal .sep { opacity: 0.6; }
@media (pointer: coarse) { .title-legal a { min-height: 44px; padding: 0 10px; } }
/* Made by Pyfio, and Pando: two small lines under Imprint and Privacy, and the
   same two under an end screen. Quieter than the legal line, and never a
   press target the thumb hits by mistake (a short row, not a 44 px one). */
.title-promo { margin: 0; display: flex; flex-direction: column; align-items: flex-start; font-size: 12px; line-height: 1.3; color: var(--ink-2); opacity: 0.7; }
.title-promo[hidden] { display: none; }
.title-promo .promo-row { display: block; }
.title-promo a { color: inherit; text-decoration: underline; text-underline-offset: 3px; display: inline-block; padding: 5px 2px; margin: 0 -2px; }
.title-promo a:hover, .title-promo a:focus-visible { opacity: 1; color: var(--ink); }
.title-small .title-promo { padding-left: 6px; }
.end .title-promo { margin-top: 14px; align-items: center; text-align: center; }
@media (pointer: coarse) { .title-promo a { padding: 8px 4px; margin: 0 -4px; } }
/* A guest: the optional Sign in, and what it is for beside it. */
.title-foot.guest { justify-content: flex-start; }
.signin-b { flex: none; padding: 0 16px; }
.signin-cap { min-width: 0; font-size: 13px; line-height: 1.35; color: var(--ink-2); }
@media (min-width: 900px) {
  .page[data-screen="title"] { padding-left: calc(64px + var(--sal)); padding-top: calc(48px + var(--sat)); }
}
@media (max-height: 560px) and (orientation: landscape) {
  .title { gap: 14px; max-width: 760px; grid-template-columns: 1fr 1fr; grid-template-rows: auto 1fr; column-gap: 28px; }
  .brand { grid-column: 1; grid-row: 1; }
  .title-menu { grid-column: 2; grid-row: 1 / 3; align-self: start; }
  /* Under the brand, not at the grid's foot, so Sign in sits beside the
     menu and never under its last row. */
  .title-foot { grid-column: 1; grid-row: 2; align-self: start; }
  .title-small { grid-column: 1; grid-row: 3; margin: 0; align-self: end; }
  .title-menu { grid-row: 1 / 4; }
  .wordmark { font-size: 72px; }
  .title-menu .btn { min-height: 44px; }
  .btn.big { min-height: 50px; }
  .title-gap { height: 50px; }
}
/* A squat landscape screen with room across (914x262, Vivaldi with its bars):
   one column of buttons with Continue's kept place is taller than the screen
   (272 px of 218), so the menu takes the width instead, in three rows of two:
   Continue's cell over Play, Campaign over Skirmish beside them, Settings and
   How to play under both (164 px). Continue's cell is the row's height with
   or without Continue, so nothing moves when it comes or goes (section 11,
   Screens). The column of the big buttons is the wider one, so 'Continue
   (12:56 PM)' stays on one line from 780 px across; the columns are shares
   of the width, never of the words, so no button moves sideways when a label
   changes. Narrower squat screens (568x320) keep the one column, which fits.
   The desk's 48 px over the title is the phone's 20 here, so nothing scrolls. */
@media (orientation: landscape) and (max-height: 359px) and (min-width: 780px) {
  .page[data-screen="title"] { padding-top: calc(20px + var(--sat)); }
  .title { max-width: 880px; grid-template-columns: minmax(min-content, 1fr) minmax(0, 2fr); }
  .title-menu { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 10px; align-content: start; }
  .title-menu > [data-action="continue"], .title-menu > .title-gap { grid-column: 1; grid-row: 1; }
  .title-menu > [data-action="play"] { grid-column: 1; grid-row: 2; }
  .title-menu > [data-action="campaign"] { grid-column: 2; grid-row: 1; }
  .title-menu > [data-action="skirmish"] { grid-column: 2; grid-row: 2; }
  .title-row { display: contents; }
  .title-row > [data-action="settings"] { grid-column: 1; grid-row: 3; }
  .title-row > [data-action="howto"] { grid-column: 2; grid-row: 3; }
  /* The squat screen has no height to spare: Imprint and Privacy sit under the
     menu in the second column, out of the grid flow, so the title is no taller. */
  .title { position: relative; }
  .title-menu { grid-row: 1 / 3; }
  .title-small { position: absolute; grid-column: 2; grid-row: 1 / 3; align-self: end; justify-self: start; margin: 0; }
  .title-legal a { min-height: 32px; }
}
/* Squat landscape, any width (914x262, 568x320): Imprint, Privacy and the two
   promo links share rows, the promo without its trailing words, so the title
   is no taller than it was and nothing scrolls. */
@media (orientation: landscape) and (max-height: 359px) {
  .title-small { flex-direction: row; flex-wrap: wrap; align-items: center; column-gap: 12px; max-width: 100%; }
  .title-promo { flex-direction: row; flex-wrap: wrap; column-gap: 12px; padding-left: 0; }
  .title-small .title-promo { padding-left: 0; }
  .title-promo .promo-row { display: inline-flex; align-items: center; min-height: 28px; }
  .title-promo a { padding: 0 2px; }
  .promo-tail { display: none; }
  .end .title-promo { margin-top: 2px; justify-content: center; }
  .end .title-promo .promo-row { min-height: 22px; }
  .title-legal a { min-height: 28px; }
}
/* Shorter still (a 360 px phone with the browser's bars, about 800x211): a
   smaller wordmark and tighter edges keep the foot's Sign in on screen. */
@media (orientation: landscape) and (max-height: 250px) and (min-width: 780px) {
  .page[data-screen="title"] { padding-top: calc(12px + var(--sat)); padding-bottom: calc(12px + var(--sab)); }
  .title { row-gap: 10px; }
  .brand { padding-top: 0; }
  .title .wordmark { font-size: 56px; }
  .title .tagline { margin-top: 6px; }
  .title-legal a { min-height: 24px; }
}

.scr-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.scr-title { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: 0.01em; }
.back-b {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 44px;
  height: 44px;
  padding: 0 12px 0 6px;
  border: 0;
  border-radius: var(--r);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255, 230, 190, 0.07);
  box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.1);
}
.scr-lead { margin: -6px 0 16px; color: var(--ink-2); max-width: 52ch; }

.houses { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 700px) { .houses { grid-template-columns: 1fr; } }
.house-card {
  position: relative;
  display: grid;
  grid-template-columns: 64px 1fr;
  grid-template-rows: auto 1fr auto;
  column-gap: 12px;
  row-gap: 4px;
  padding: 14px;
  border: 0;
  border-radius: var(--r2);
  text-align: left;
  color: var(--ink);
  background: linear-gradient(160deg, color-mix(in srgb, var(--hc) 26%, #2a2119), #1c150f 70%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), inset 0 0 0 1px color-mix(in srgb, var(--hc) 45%, #000), 0 6px 20px rgba(0, 0, 0, 0.35);
}
.house-card:active { transform: translateY(1px); }
.house-ic { grid-row: 1 / 4; width: 64px; height: 64px; border-radius: 6px; }
.house-name { font-size: 18px; font-weight: 850; color: color-mix(in srgb, var(--hc) 45%, #fff); }
.house-text { font-size: 12.5px; color: var(--ink-2); line-height: 1.4; }
.house-prog { display: flex; align-items: center; gap: 8px; font-size: 11.5px; font-weight: 700; color: var(--ink-2); }
.pips { display: inline-flex; gap: 3px; }
.pips i { width: 8px; height: 8px; border-radius: 2px; background: rgba(255, 255, 255, 0.12); }
.pips i.won { background: var(--hc); box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25); }
@media (min-width: 701px) {
  .house-card { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr auto; }
  .house-ic { grid-row: auto; width: 72px; height: 72px; }
}

.missions { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.mission {
  width: 100%;
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 12px 8px 8px;
  border: 0;
  border-radius: var(--r);
  text-align: left;
  color: var(--ink);
  background: linear-gradient(180deg, rgba(58, 45, 33, 0.9), rgba(36, 28, 20, 0.9));
  box-shadow: inset 0 1px 0 rgba(255, 230, 190, 0.08), inset 0 0 0 1px rgba(0, 0, 0, 0.4);
}
.m-n { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 6px; font-size: 18px; font-weight: 850; background: color-mix(in srgb, var(--hc) 40%, #1a130d); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hc) 60%, #000); }
.m-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.m-goal { font-size: 15px; font-weight: 750; }
.m-meta { font-size: 12px; color: var(--ink-2); }
.m-state { width: 96px; font-size: 12px; font-weight: 750; color: var(--ink-2); display: inline-flex; align-items: center; justify-content: flex-end; gap: 6px; text-align: right; }
.m-state .lock { display: inline-flex; align-items: center; justify-content: flex-end; gap: 6px; min-width: 0; }
.m-state .lock .cap { font-size: 11px; line-height: 1.15; white-space: normal; }
.m-state .lock .cap:empty { display: none; }
.mission.won .m-state { color: var(--good); }
.mission.locked { opacity: 0.55; }
.mission.locked .m-n { background: rgba(255, 255, 255, 0.06); box-shadow: none; }
.mission:not(.locked):not(.won) { box-shadow: inset 0 1px 0 rgba(255, 230, 190, 0.08), inset 0 0 0 1px var(--sand); }
.mission:not(.locked):not(.won) .m-state { color: var(--sand); }

.briefing {
  max-width: 560px;
  padding: 22px;
  border-radius: var(--r2);
  background: linear-gradient(160deg, color-mix(in srgb, var(--hc) 22%, #261d15), #17110c 75%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), inset 0 0 0 1px color-mix(in srgb, var(--hc) 40%, #000), 0 10px 30px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.brief-kicker { font-size: 13px; font-weight: 750; color: color-mix(in srgb, var(--hc) 45%, #fff); }
.brief-goal { margin: 0; font-size: 26px; font-weight: 850; line-height: 1.15; }
.brief-text { margin: 0; font-size: 15.5px; color: var(--ink-2); line-height: 1.5; max-width: 46ch; }
.brief-meta { display: flex; flex-wrap: wrap; gap: 8px; }
.brief-meta span { font-size: 12px; font-weight: 700; padding: 5px 9px; border-radius: 4px; background: rgba(0, 0, 0, 0.3); color: var(--ink-2); }
.briefing .btn { margin-top: 6px; align-self: flex-start; min-width: 180px; }
.brief-hint { margin: 0; font-size: 12px; color: var(--ink-3); }
.brief-wrap { min-height: 100%; cursor: pointer; }
.page[data-screen^="brief-"] > .brief-wrap { max-width: none; }

.form { display: grid; gap: 14px; max-width: 620px; }
.field { display: grid; gap: 6px; }
.field-label { font-size: 12px; font-weight: 750; color: var(--ink-2); letter-spacing: 0.03em; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg-b {
  flex: 1 1 0;
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--r);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-2);
  background: rgba(255, 230, 190, 0.06);
  box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.12);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}
.seg-b[aria-checked="true"] { color: var(--sand-ink); background: var(--sand); box-shadow: none; }
/* Five choices (Settings, Chat sound): equal cells that wrap as whole rows, never one stretched across. */
.seg.seg-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(56px, 1fr)); }
.house-b .swatch { width: 12px; height: 12px; border-radius: 3px; background: var(--hc); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5); }
.house-b[aria-checked="true"] { background: color-mix(in srgb, var(--hc) 70%, #1a130d); color: #fff; }
.stepper { display: inline-flex; align-items: center; gap: 8px; }
.step-b { min-width: 44px; height: 44px; padding: 0 12px; border: 0; border-radius: var(--r); font-size: 18px; font-weight: 800; color: var(--ink); background: rgba(255, 230, 190, 0.08); box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.14); }
.step-b.wide { font-size: 14px; font-weight: 700; }
.step-val { min-width: 32px; text-align: center; font-size: 20px; font-weight: 850; }
.seed { display: flex; gap: 8px; }
.seed-in {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--r);
  font: 600 15px var(--font);
  color: var(--ink);
  background: rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.18);
  user-select: text;
  -webkit-user-select: text;
}
.seed-in::placeholder { color: var(--ink-3); }
/* Start skirmish stays at the bottom of the screen while the form scrolls:
   on a landscape phone the form is twice the screen high, and the one action
   that matters should not need a 470 px scroll to reach. */
.form-foot {
  position: sticky;
  /* Sticky measures from the page's content box, 24 px + inset above the
     screen edge: reach down over that padding so nothing scrolls under it. */
  bottom: calc(-24px - var(--sab));
  z-index: 1;
  margin-top: 20px;
  max-width: 620px;
  padding: 16px 0 calc(16px + var(--sab));
  background: linear-gradient(180deg, rgba(14, 10, 7, 0), #0e0a07 16px);
}
.form-foot .btn { width: 100%; }

.settings { display: grid; gap: 4px; max-width: 620px; }
.set-row { display: grid; grid-template-columns: minmax(120px, 0.9fr) minmax(0, 1.4fr); align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid rgba(255, 230, 190, 0.07); }
.set-label { display: flex; flex-direction: column; gap: 2px; font-size: 14px; font-weight: 700; }
.set-label small { font-size: 11.5px; font-weight: 500; color: var(--ink-3); }
.sl { display: flex; align-items: center; gap: 10px; }
.sl input { flex: 1; min-width: 0; height: 44px; accent-color: var(--sand); }
.sl-out { width: 42px; text-align: right; font-size: 13px; color: var(--ink-2); }
@media (max-width: 480px) { .set-row { grid-template-columns: 1fr; gap: 6px; } }

/* The Admin menu (DESIGN.md 19): one row per tunable, a slider and a number
   field of 44 px, the default and a Reset; Save, Cancel and Reset all stay at
   the foot of what scrolls (the page or the menu panel). No row is wider
   than its box: the slider takes what the field and the unit leave. */
.admin { display: grid; gap: 2px; max-width: 620px; min-width: 0; }
.admin-lead { margin: 0 0 6px; font-size: 13px; line-height: 1.4; color: var(--ink-2); }
/* The Statistics link at the Admin menu's top: a whole-width tap target, well
   over 44 px, that opens the statistics page in a new tab. */
.admin-stats { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; margin: 0 0 8px; padding: 8px 14px; border-radius: var(--r); color: var(--ink); text-decoration: none; background: rgba(230, 173, 94, 0.12); box-shadow: inset 0 0 0 1px rgba(230, 173, 94, 0.45); -webkit-tap-highlight-color: transparent; }
.admin-stats:active { transform: translateY(1px); }
.admin-stats:focus-visible { outline: 2px solid var(--sand); outline-offset: 2px; }
.admin-stats .as-main { display: grid; gap: 1px; min-width: 0; }
.admin-stats .as-t { font-size: 16px; font-weight: 800; }
.admin-stats small { font-size: 11.5px; line-height: 1.3; color: var(--ink-2); overflow-wrap: anywhere; }
.admin-stats .as-go { flex: none; font-size: 13px; font-weight: 800; color: var(--sand); }
.admin-scope { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 14px 0 2px; font-size: 13px; font-weight: 850; letter-spacing: 0.04em; text-transform: uppercase; color: var(--sand); }
.admin-scope small { font-size: 11.5px; font-weight: 650; letter-spacing: 0; text-transform: none; color: var(--ink-3); }
.adm-row { display: grid; gap: 4px; min-width: 0; padding: 10px 0 12px; border-bottom: 1px solid rgba(255, 230, 190, 0.07); }
.adm-row.changed { box-shadow: inset 3px 0 0 var(--warn); padding-left: 10px; }
.adm-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
.adm-label { font-size: 14px; font-weight: 750; color: var(--ink); min-width: 0; overflow-wrap: anywhere; }
.adm-reset { flex: none; min-width: 64px; min-height: 44px; padding: 0 12px; border: 0; border-radius: var(--r); font-size: 13px; font-weight: 700; color: var(--ink-2); background: rgba(255, 230, 190, 0.06); box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.14); }
.adm-reset:disabled { opacity: 0.38; }
.adm-help { font-size: 12px; line-height: 1.35; color: var(--ink-3); }
.adm-ctl { display: flex; align-items: center; gap: 10px; min-width: 0; }
.adm-range { flex: 1 1 auto; min-width: 0; height: 44px; margin: 0; accent-color: var(--sand); }
.adm-num {
  flex: none;
  width: 86px;
  height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--r);
  font: 700 16px var(--font);
  text-align: right;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.18);
  user-select: text;
  -webkit-user-select: text;
}
.adm-num:focus { outline: none; box-shadow: inset 0 0 0 2px var(--sand); }
.adm-row.invalid .adm-num { box-shadow: inset 0 0 0 2px var(--bad); }
.adm-unit { flex: none; width: 52px; font-size: 12px; font-weight: 650; line-height: 1.2; color: var(--ink-2); }
.adm-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11.5px; color: var(--ink-3); }
.adm-when { color: var(--warn); }
.adm-row:not(.changed) .adm-when { color: var(--good); }
.adm-err { color: var(--bad); font-weight: 700; }
.admin-foot {
  position: sticky;
  bottom: 0;
  z-index: 1;
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding: 12px 0 calc(4px + var(--sab));
  background: linear-gradient(180deg, rgba(31, 24, 18, 0), var(--panel) 14px);
}
.page .admin-foot { bottom: calc(-24px - var(--sab)); padding-bottom: calc(16px + var(--sab)); background: linear-gradient(180deg, rgba(14, 10, 7, 0), #0e0a07 14px); }
.menu-panel .admin-foot { bottom: -16px; padding-bottom: 16px; }
.admin-status { min-height: 18px; margin: 0; font-size: 13px; font-weight: 650; color: var(--ink-2); }
.admin-status[data-kind="ok"] { color: var(--good); }
.admin-status[data-kind="error"] { color: var(--bad); }
.admin-btns { display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 8px; }
.admin-btns .btn { justify-content: center; min-width: 0; padding: 0 10px; }
.admin-btns .btn.idle { filter: saturate(0.6) brightness(0.85); }
.admin-btns .btn:disabled { opacity: 0.5; }
.admin-status:empty { display: none; }
/* In the game's menu the Admin view takes a wider panel: its help lines fit
   on one line, and the rows need less height. */
.menu-panel:has(.admin) { width: min(720px, 100%); }
/* squat (914x262): label and help beside the control, so a whole row fits
   between the menu's head and Save; less padding round the panel. */
@media (orientation: landscape) and (max-height: 359px) {
  .admin-lead { display: none; }
  .admin-stats { min-height: 44px; margin-bottom: 2px; padding: 4px 12px; }
  .admin-stats small { display: none; }
  .adm-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); grid-template-areas: "head ctl" "help ctl" "meta meta"; column-gap: 12px; row-gap: 0; padding: 4px 0 6px; }
  .adm-row.changed { padding-left: 8px; }
  .adm-head { grid-area: head; }
  .adm-help { grid-area: help; font-size: 11px; line-height: 1.25; }
  .adm-ctl { grid-area: ctl; align-self: center; }
  .adm-meta { grid-area: meta; }
  .admin-scope { margin-top: 6px; }
  .admin-foot { gap: 4px; padding-top: 6px; }
  .menu:has(.admin) { padding: calc(6px + var(--sat)) calc(8px + var(--sar)) calc(6px + var(--sab)) calc(8px + var(--sal)); }
  .menu-panel:has(.admin) { padding: 8px 12px; }
  .menu-panel:has(.admin) .admin-foot { bottom: -8px; padding-bottom: 8px; }
  .menu-panel:has(.admin) .menu-head { margin-bottom: 4px; }
}

.howto-goals { margin: 0 0 18px; padding-left: 20px; display: grid; gap: 8px; max-width: 62ch; color: var(--ink-2); line-height: 1.45; }
.howto-goals strong { color: var(--ink); }
.table-wrap { overflow-x: auto; }
.howto { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.howto th, .howto td { text-align: left; vertical-align: top; padding: 10px 10px 10px 0; border-bottom: 1px solid rgba(255, 230, 190, 0.08); }
.howto thead th { font-size: 11.5px; letter-spacing: 0.04em; color: var(--sand); font-weight: 800; }
.howto tbody th { font-weight: 750; width: 30%; color: var(--ink); }
.howto td { color: var(--ink-2); }

/* `safe`: a panel taller than the page starts at its top and scrolls, instead
   of overflowing both edges where its top can never be scrolled to. */
.page[data-screen="end"] { display: grid; place-items: safe center; background: radial-gradient(ellipse at center, rgba(14, 10, 7, 0.55), rgba(14, 10, 7, 0.88)); }
.end {
  width: min(460px, 100%);
  padding: 26px 24px 22px;
  border-radius: var(--r2);
  background: linear-gradient(170deg, color-mix(in srgb, var(--hc) 20%, #2a2018), #16100b 80%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), inset 0 0 0 1px color-mix(in srgb, var(--hc) 40%, #000), 0 20px 60px rgba(0, 0, 0, 0.6);
  animation: rise-in 260ms var(--ease);
}
.end-kicker { font-size: 13px; font-weight: 750; color: var(--ink-2); }
.end-title { margin: 2px 0 16px; font-size: 52px; font-weight: 850; letter-spacing: 0.04em; line-height: 1.05; }
.end.won .end-title { color: #ffe0a3; text-shadow: 0 2px 0 #6b3c12, 0 0 28px rgba(230, 173, 94, 0.35); }
.end.lost .end-title { color: #ff9c8c; text-shadow: 0 2px 0 #5c160e; }
/* What was achieved or lost (section 11, Goal), under Victory or Defeat. */
.end-what { margin: -8px 0 16px; font-size: 15.5px; font-weight: 700; line-height: 1.35; color: var(--ink); }
.stats { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; margin: 0 0 20px; }
.stats dt { color: var(--ink-2); font-size: 13.5px; }
.stats dd { margin: 0; font-size: 14px; font-weight: 800; text-align: right; }
.end-btns { display: grid; grid-auto-flow: row; gap: 10px; }
.end-btns .btn { justify-content: center; width: 100%; }
.end-row { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 10px; }
/* A landscape phone (412 px high) cannot hold the panel in one column:
   result and stats on the left, the buttons on the right, all without a scroll. */
@media (max-height: 559px) and (min-width: 560px) {
  .end {
    width: min(720px, 100%);
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "kick btns" "title btns" "what btns" "stats btns";
    grid-template-rows: auto auto auto 1fr;
    column-gap: 24px;
    padding: 18px 20px;
  }
  .end-kicker { grid-area: kick; }
  .end-title { grid-area: title; font-size: 38px; margin: 0 0 10px; }
  .end-what { grid-area: what; margin: -4px 0 10px; font-size: 14px; }
  .stats { grid-area: stats; margin: 0; gap: 3px 16px; }
  .end-btns { grid-area: btns; align-self: center; }
}
/* squat heights (a browser's bars in landscape, 262 px): the whole panel fits. */
@media (max-height: 359px) and (min-width: 560px) {
  .page[data-screen="end"] { padding-top: calc(10px + var(--sat)); padding-bottom: calc(10px + var(--sab)); }
  .end { padding: 12px 18px; }
  .end-title { font-size: 28px; margin: 0 0 6px; }
  .end-what { margin: -3px 0 6px; font-size: 13px; }
  .stats { gap: 0 16px; }
  .stats dt { font-size: 12px; }
  .stats dd { font-size: 12.5px; }
}

/* ======================================================================
 * In-game menu
 * ==================================================================== */

.menu { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(16px + var(--sab)) calc(16px + var(--sal)); }
.menu-scrim { position: absolute; inset: 0; background: rgba(8, 6, 4, 0.62); }
.menu-panel {
  position: relative;
  width: min(420px, 100%);
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  border-radius: var(--r2);
  background:
    linear-gradient(180deg, rgba(255, 228, 180, 0.04), rgba(0, 0, 0, 0) 40%),
    var(--panel);
  box-shadow: inset 0 1px 0 rgba(255, 230, 190, 0.1), inset 0 0 0 1px #0a0705, 0 24px 60px rgba(0, 0, 0, 0.6);
  animation: rise-in 200ms var(--ease);
}
.menu-panel, .menu-panel * { touch-action: pan-y; }
.menu-panel input[type="range"] { touch-action: none; }
.menu-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.menu-title h2 { margin: 0; font-size: 20px; font-weight: 850; }
.menu-sub { font-size: 12.5px; color: var(--ink-2); }
/* The goal and its progress at the top of the menu (section 11, Goal). */
.menu-goal {
  display: grid;
  gap: 5px;
  margin: -4px 0 14px;
  padding: 9px 12px 10px;
  border-left: 3px solid var(--sand);
  border-radius: var(--r);
  background: rgba(0, 0, 0, 0.25);
}
.mg-goal { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.mg-kick { font-size: 11px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--sand); }
.mg-text { font-size: 14.5px; font-weight: 800; color: var(--ink); }
.mg-prog { display: flex; align-items: center; gap: 10px; font-size: 12.5px; font-weight: 650; color: var(--ink-2); }
.mg-bar { position: relative; flex: 1 1 auto; max-width: 160px; height: 5px; border-radius: 3px; overflow: hidden; background: rgba(230, 173, 94, 0.22); }
.mg-bar i { position: absolute; inset: 0; transform-origin: left center; background: linear-gradient(90deg, #c7883f, var(--sand)); border-radius: 3px; }
@media (max-height: 359px) {
  .menu-goal { margin: -8px 0 10px; padding: 6px 10px 7px; gap: 3px; }
}
.menu-list { display: grid; gap: 10px; }
.menu-list .btn { width: 100%; justify-content: center; }
.menu-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
/* Save and Load: the word, and under it where the slots are. */
.btn.two { flex-direction: column; gap: 1px; line-height: 1.15; }
.btn .where { display: block; font-size: 11.5px; font-weight: 600; color: var(--ink-2); }
.slots-where { margin: -6px 0 10px; font-size: 12.5px; color: var(--ink-2); }
/* Signed in, over a guest's slots the merge left on this device (section 13). */
.slots .slots-here { margin: 8px 0 0; }
.slots { display: grid; gap: 8px; }
.slots-wait, .slots-err { margin: 6px 0 10px; color: var(--ink-2); }
.slot-row {
  display: grid;
  grid-template-columns: 70px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 8px 12px;
  border: 0;
  border-radius: var(--r);
  text-align: left;
  color: var(--ink);
  background: linear-gradient(180deg, var(--panel-3), var(--panel-2));
  box-shadow: inset 0 1px 0 var(--hi), inset 0 0 0 1px rgba(0, 0, 0, 0.4);
}
.slot-row.empty .slot-desc { color: var(--ink-3); }
.slot-name { font-weight: 800; font-size: 14px; }
.slot-desc { display: flex; flex-direction: column; gap: 1px; font-size: 13px; min-width: 0; }
.slot-desc span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot-desc small { color: var(--ink-3); font-size: 11.5px; }
.slot-row .cap { font-size: 12px; font-weight: 800; color: var(--sand); }

/* ======================================================================
 * Motion
 * ==================================================================== */

@keyframes shake {
  0% { transform: translateX(0); }
  16% { transform: translateX(-5px); }
  33% { transform: translateX(5px); }
  50% { transform: translateX(-5px); }
  66% { transform: translateX(5px); }
  83% { transform: translateX(-3px); }
  100% { transform: translateX(0); }
}
@keyframes ready-glow {
  0%, 100% { box-shadow: inset 0 1px 0 var(--hi), inset 0 0 0 1px var(--good), 0 0 0 1px rgba(134, 212, 110, 0.3); }
  50% { box-shadow: inset 0 1px 0 var(--hi), inset 0 0 0 1px var(--good), 0 0 0 4px rgba(134, 212, 110, 0.28); }
}
@keyframes sand-pulse {
  0%, 100% { box-shadow: inset 0 1px 0 var(--hi), inset 0 0 0 1px var(--sand), 0 0 0 0 rgba(230, 173, 94, 0.45); }
  50% { box-shadow: inset 0 1px 0 var(--hi), inset 0 0 0 1px var(--sand), 0 0 0 5px rgba(230, 173, 94, 0); }
}
@keyframes hint-ring {
  0% { box-shadow: 0 0 0 0 rgba(251, 233, 200, 0.85), inset 0 0 0 2px #fbe9c8; }
  100% { box-shadow: 0 0 0 10px rgba(251, 233, 200, 0), inset 0 0 0 2px #fbe9c8; }
}
@keyframes flash-good { 0% { color: var(--good); } 100% { color: var(--ink); } }
@keyframes flash-warn { 0% { color: var(--warn); } 100% { color: var(--ink); } }
@keyframes flash-bad { 0%, 60% { background: rgba(240, 80, 62, 0.35); } 100% { background: transparent; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes hint-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes banner-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes drop-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .tile.ready, .tile.pulse, .hint-pulse { animation: none !important; }
  .hint-pulse { box-shadow: inset 0 0 0 2px #fbe9c8 !important; }
  .refusing { animation-duration: 120ms !important; }
  .mini.open, .banner.show, .toast, .hint, .end, .menu-panel { animation-duration: 1ms !important; }
}

/* ======================================================================
 * Coop (COOP.md, stage 2): the title's Coop button, the Coop screen and the
 * lobby, the in-game corner (status pill, Ping, Send credits, the credits
 * sheet), and the combined end screen.
 * ==================================================================== */

/* Skirmish and Coop share one row of the title, so the menu is no taller. */
@media (orientation: landscape) and (max-height: 359px) and (min-width: 780px) {
  .title-menu > .title-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; grid-column: 2; grid-row: 2; }
}

.coop-form { max-width: 520px; }
.coop-form .btn.big { width: 100%; }
/* The lobby's two groups (who plays, the setup): stacked like the form's own fields. */
.coop-col { display: grid; gap: 14px; align-content: start; min-width: 0; }
/* On a desk the two groups stand side by side, so the setup with Worm Riders
   and the Worm Queen and Start are all in view without a scroll (at 1440x900
   the one column put Difficulty under Start's sticky foot). */
@media (min-width: 900px) and (min-height: 560px) {
  .page[data-screen="lobby"] > .coop-lobby { max-width: 1080px; }
  .coop-lobby > .coop-form { max-width: 1080px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 40px; }
  .coop-lobby > .coop-form > .coop-note { grid-column: 1 / -1; }
}
.coop-code { text-transform: uppercase; letter-spacing: 0.3em; font-weight: 800; max-width: 160px; }
.coop-note { margin: 0; min-height: 1.35em; font-size: 13px; font-weight: 650; color: var(--warn); }
.coop-note:empty { min-height: 0; }
.coop-invite { display: grid; gap: 6px; margin: 0 0 18px; max-width: 520px; }
.coop-code-big { font-size: 46px; font-weight: 850; letter-spacing: 0.32em; line-height: 1.05; color: #f7e6c4; text-shadow: 0 2px 0 #6e3f17; user-select: text; -webkit-user-select: text; }
.coop-share-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.coop-share { flex: none; }
.coop-share.copied { background: linear-gradient(180deg, #3f5b2e, #2c4320); }
.coop-link { font-size: 13px; color: var(--ink-2); overflow-wrap: anywhere; user-select: text; -webkit-user-select: text; }
.coop-seats { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.coop-seat { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 12px; border-radius: var(--r); background: rgba(255, 230, 190, 0.05); box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.1); }
.coop-seat.me { box-shadow: inset 0 0 0 1px var(--sand); }
.coop-seat.off { opacity: 0.6; }
.coop-dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--hc, var(--pc, #888)); box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.5); }
.coop-seat-txt { display: flex; flex-direction: column; min-width: 0; }
.coop-seat-name { font-size: 15px; font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.coop-seat-meta { font-size: 12px; color: var(--ink-2); }
.seg-b.soon { opacity: 0.45; }
.seg-b.ro:not([aria-checked="true"]) { opacity: 0.55; }
.btn.wait { filter: saturate(0.4) brightness(0.8); }
.coop-wait { margin: 8px 0 0; min-height: 1.35em; font-size: 13px; color: var(--ink-2); text-align: center; }
.coop-wait:empty { display: none; }
.menu-note { margin: -6px 0 12px; font-size: 12.5px; color: var(--ink-2); }

/* The in-game corner: over the map's bottom-right, clear of the refusal
   notice (beside slots 1-4) and of the goal button and toasts (top-left). */
.coop-bar {
  position: absolute;
  right: calc(8px + var(--sar));
  bottom: 8px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}
.coop-bar[hidden] { display: none; }
.game.lefty .coop-bar { right: auto; left: calc(8px + var(--sal)); align-items: flex-start; }
.coop-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: min(220px, calc(100vw - 32px));
  min-width: 44px;
  min-height: 44px;
  padding: 5px 10px;
  border: 0;
  border-radius: 14px;
  font: inherit;
  text-align: left;
  cursor: pointer;
  pointer-events: auto;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--ink);
  background: rgba(16, 12, 9, 0.82);
  box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.14), 0 4px 12px rgba(0, 0, 0, 0.4);
}
.cp-dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.45); }
.coop-pill.slow .cp-dot { background: var(--warn); }
.coop-pill.lost .cp-dot, .coop-pill.closed .cp-dot { background: var(--bad); }
.cp-txt { display: flex; flex-direction: column; min-width: 0; }
.cp-l1, .cp-l2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cp-l2 { font-weight: 600; color: var(--ink-2); }
.cp-l2:empty { display: none; }
.coop-pill.partner-away .cp-l2 { color: var(--warn); }
.coop-pill.open { border-radius: var(--r); align-items: flex-start; }
.coop-pill.open .cp-dot { margin-top: 3px; }
.cp-net { margin-top: 4px; font-size: 11px; font-weight: 600; line-height: 1.35; color: var(--ink); white-space: pre; }
.cp-net[hidden] { display: none; }
.cb-row { display: flex; gap: 8px; pointer-events: auto; }
.cb {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 56px;
  height: 52px;
  padding: 0;
  border: 0;
  border-radius: var(--r);
  font: inherit;
  color: var(--ink);
  background: rgba(16, 12, 9, 0.86);
  box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.18), 0 4px 12px rgba(0, 0, 0, 0.45);
  cursor: pointer;
}
.cb .gl { width: 20px; height: 20px; color: var(--sand); }
.cb .lbl { font-size: 11px; font-weight: 750; line-height: 1; }
.cb:active { transform: translateY(1px); }
.cb.lit { background: rgba(62, 46, 30, 0.96); box-shadow: inset 0 0 0 2px var(--sand), 0 4px 12px rgba(0, 0, 0, 0.45); }
@media (hover: hover) { .cb:hover { background: rgba(40, 30, 21, 0.94); } }

/* The credits sheet: above the corner, inside the map, every button 48 px. */
.coop-sheet {
  position: absolute;
  right: calc(8px + var(--sar));
  bottom: 68px;
  z-index: 7;
  width: min(300px, calc(100% - 16px));
  max-height: calc(100% - 84px);
  overflow-y: auto;
  display: grid;
  gap: 8px;
  padding: 10px 12px 12px;
  border-radius: var(--r2);
  background: rgba(24, 18, 13, 0.97);
  box-shadow: inset 0 0 0 1px rgba(230, 173, 94, 0.45), 0 12px 30px rgba(0, 0, 0, 0.6);
  touch-action: pan-y;
}
.coop-sheet[hidden] { display: none; }
/* The AI holds this player's base (30 s of absence, COOP.md 7): a banner over
   the map, clear of the goal button and the toasts at the top, with Take back. */
.coop-ai {
  position: absolute;
  top: 28%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 12px;
  width: max-content;
  max-width: calc(100% - 16px);
  padding: 8px 8px 8px 14px;
  border-radius: var(--r2);
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
  background: rgba(40, 18, 12, 0.95);
  box-shadow: inset 0 0 0 2px var(--warn), 0 12px 30px rgba(0, 0, 0, 0.6);
}
.coop-ai[hidden] { display: none; }
.ai-take { min-height: 48px; min-width: 96px; justify-content: center; }
.coop-sheet * { touch-action: pan-y; }
.game.lefty .coop-sheet { right: auto; left: calc(8px + var(--sal)); }
.cs-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cs-title { font-size: 14px; font-weight: 800; min-width: 0; }
.cs-room { font-size: 12px; color: var(--ink-2); }
.cs-amts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cs-amt { min-height: 48px; justify-content: center; padding: 0 8px; font-size: 14px; }
@media (orientation: landscape) and (max-height: 359px) {
  /* Beside the corner's three buttons (3 x 56 + 2 x 8 = 184 px, 8 px in, 8 px apart). */
  /* 8 px between rows: with two partners the choice row sits under Close. */
  .coop-sheet { bottom: 8px; right: calc(200px + var(--sar)); width: min(280px, calc(100% - 216px)); max-height: calc(100% - 16px); gap: 8px; padding: 8px 10px; }
  .game.lefty .coop-sheet { left: calc(200px + var(--sal)); }
  .cs-amts { grid-template-columns: 1fr 1fr 1fr 1fr; gap: 8px; }
  .cs-amt { min-height: 44px; font-size: 12.5px; padding: 0 4px; }
}

/* Chat (COOP.md 16): the corner's Chat button carries a count of unread lines. */
.cb { position: relative; }
.cb-badge {
  position: absolute;
  top: 3px;
  right: 5px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  font-size: 10.5px;
  font-weight: 800;
  line-height: 16px;
  text-align: center;
  color: #fff;
  background: var(--bad);
  pointer-events: none;
}
.cb-badge[hidden] { display: none; }
/* The chat panel: above the corner like the credits sheet, lifted over a
   phone's keyboard by --kbc (the part of the map the keyboard covers, set by
   ui/coophud.js from visualViewport); its top never leaves the map. */
.coop-chat {
  --chb: max(68px, calc(var(--kbc, 0px) + 8px));
  position: absolute;
  right: calc(8px + var(--sar));
  bottom: var(--chb);
  z-index: 7;
  width: min(400px, calc(100% - 16px));
  max-height: calc(100% - 8px - var(--chb));
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px 12px;
  border-radius: var(--r2);
  background: rgba(24, 18, 13, 0.97);
  box-shadow: inset 0 0 0 1px rgba(230, 173, 94, 0.45), 0 12px 30px rgba(0, 0, 0, 0.6);
}
.coop-chat[hidden] { display: none; }
.game.lefty .coop-chat { right: auto; left: calc(8px + var(--sal)); }
.ch-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex: none; }
.ch-title { font-size: 14px; font-weight: 800; }
.ch-log {
  list-style: none;
  margin: 0;
  padding: 0 2px;
  flex: 1 1 auto;
  min-height: 44px;
  max-height: 220px;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  line-height: 1.3;
}
.ch-log:empty::before { content: attr(data-empty); color: var(--ink-2); font-size: 12.5px; }
.ch-line { overflow-wrap: anywhere; }
.ch-name, .cf-name { font-weight: 800; }
.ch-line.me .ch-text { color: #ffe0a3; }
.ch-quick { display: flex; flex-wrap: wrap; gap: 8px; flex: none; }
.ch-q { min-height: 44px; min-width: 44px; padding: 0 12px; font-size: 13px; justify-content: center; }
.ch-form { display: flex; gap: 8px; margin: 0; flex: none; }
.ch-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--r);
  font: inherit;
  font-size: 16px; /* 16 px: no browser zooms in on the field */
  color: var(--ink);
  background: rgba(255, 230, 190, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.22);
}
.ch-input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--sand); }
.ch-send { min-height: 44px; min-width: 64px; padding: 0 14px; justify-content: center; }
@media (orientation: landscape) and (max-height: 359px) {
  /* 262 px high: the quick messages share a row with Close, the field below the log. */
  .coop-chat {
    --chb: max(8px, calc(var(--kbc, 0px) + 8px));
    width: calc(100% - 16px);
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "quick close" "log log" "form form";
    gap: 8px;
    padding: 8px 10px;
  }
  .ch-head { display: contents; }
  .ch-title { display: none; }
  .ch-close { grid-area: close; }
  .ch-quick { grid-area: quick; flex-wrap: nowrap; }
  .ch-q { padding: 0 10px; font-size: 12.5px; }
  .ch-log { grid-area: log; max-height: none; min-height: 36px; }
  .ch-form { grid-area: form; }
}
/* Incoming lines over the map's top right: under no control, clear of the
   goal button and the toasts (top left, at most 100% - 190 px wide), and
   they take no press. */
.chat-feed {
  position: absolute;
  top: calc(8px + var(--sat));
  right: calc(8px + var(--sar));
  z-index: 5;
  width: 172px;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  pointer-events: none;
}
.chat-feed[hidden] { display: none; }
@media (min-width: 900px) and (min-height: 560px) { .chat-feed { width: min(260px, calc(40% - 18px)); } }
.cf-line {
  max-width: 100%;
  padding: 4px 8px;
  border-radius: var(--r);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.25;
  color: var(--ink);
  background: rgba(16, 12, 9, 0.84);
  box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.12), 0 4px 12px rgba(0, 0, 0, 0.4);
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  animation: toast-in 180ms var(--ease);
}
.cf-line.out { opacity: 0; transition: opacity 350ms; }
.coop-free { margin: -4px 0 0; font-size: 12.5px; color: var(--ink-2); }
.coop-free:empty { display: none; }
.coop-take { display: grid; gap: 8px; }
.coop-take-b { min-height: 48px; justify-content: center; }

/* The combined end screen: every human's stats side by side. */
.coop-end { width: min(560px, 100%); }
.coop-stats { border-collapse: collapse; width: 100%; margin: 0 0 18px; font-size: 13.5px; }
.coop-stats th, .coop-stats td { padding: 6px 8px; text-align: right; border-bottom: 1px solid rgba(255, 230, 190, 0.08); }
.coop-stats thead th { font-size: 12.5px; font-weight: 800; white-space: nowrap; }
.coop-stats thead th:first-child { text-align: left; color: var(--ink-2); font-weight: 700; }
.coop-stats thead th .coop-dot { display: inline-block; margin-right: 6px; vertical-align: -1px; }
.coop-stats tbody th { text-align: left; font-weight: 600; color: var(--ink-2); }
.coop-stats td { font-weight: 800; }
.coop-stats .me { color: #ffe0a3; }
@media (max-height: 559px) and (min-width: 560px) {
  .coop-end { grid-template-areas: "kick btns" "title btns" "what btns" "stats btns"; }
  .coop-end .table-wrap { grid-area: stats; }
  .coop-end .coop-stats { margin: 0; font-size: 12.5px; }
  .coop-end .coop-stats th, .coop-end .coop-stats td { padding: 3px 6px; }
}
/* The lobby on a landscape phone: the invite and Start on the left, always
   in view at the page's top; the seats and the setup on the right, which
   scroll with the page. The sticky foot of a portrait page would cover the
   invite at 262 px high. */
@media (orientation: landscape) and (max-height: 559px) {
  .page[data-screen="lobby"] > * { max-width: 920px; }
  .coop-lobby { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); grid-template-rows: auto auto auto 1fr; column-gap: 24px; align-items: start; }
  .coop-lobby > .scr-head { grid-column: 1 / -1; }
  .coop-lobby > .coop-invite { grid-column: 1; grid-row: 2; margin-bottom: 12px; }
  .coop-lobby > .coop-form { grid-column: 2; grid-row: 2 / 5; }
  .coop-lobby > .form-foot { grid-column: 1; grid-row: 3; position: static; margin: 0; padding: 0; background: none; }
}
@media (orientation: landscape) and (max-height: 359px) {
  .page[data-screen="lobby"] { padding-top: calc(12px + var(--sat)); }
  .coop-lobby > .scr-head { margin-bottom: 8px; }
  .coop-invite { grid-template-columns: auto 1fr; align-items: center; column-gap: 14px; row-gap: 2px; }
  .coop-invite > .field-label { grid-column: 1 / -1; }
  .coop-code-big { font-size: 34px; letter-spacing: 0.24em; }
  .coop-share-row { flex-wrap: nowrap; min-width: 0; }
  .coop-link { display: none; }
  .coop-wait { margin-top: 6px; }
}
/* The stats table's dots are each player's own colour, not the panel's. */
.coop-stats .coop-dot { background: var(--pc); }
@media (max-height: 359px) and (min-width: 560px) {
  .coop-end .coop-stats { font-size: 11.5px; }
  .coop-end .coop-stats th, .coop-end .coop-stats td { padding: 1px 6px; }
  .coop-end .coop-stats thead th { font-size: 11.5px; }
}
/* The Coop screen on a landscape phone: the name and the code side by side,
   Create a game under both, the lead line only where there is room. */
@media (orientation: landscape) and (max-height: 559px) {
  .page[data-screen="coop"] .coop-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 16px; max-width: 760px; }
  .page[data-screen="coop"] .coop-form > .btn.big { grid-column: 1 / -1; grid-row: 2; }
  .page[data-screen="coop"] .coop-form > .coop-note { grid-column: 1 / -1; }
}
@media (orientation: landscape) and (max-height: 359px) {
  .page[data-screen="coop"] { padding-top: calc(12px + var(--sat)); }
  .page[data-screen="coop"] .scr-head { margin-bottom: 8px; }
  .page[data-screen="coop"] .scr-lead { display: none; }
  .page[data-screen="coop"] .coop-form { gap: 10px 16px; }
}
