/* ============================================================
   Crit Zone - arcade / sci-fi shell.

   Only the HUD and the menus live here. Everything inside the
   arena is drawn to <canvas> by js/render/*.

   No web fonts: the CSP allows font-src 'self' only, and a
   condensed system monospace already reads as arcade hardware.
   ============================================================ */

:root {
  --bg:        #04070d;
  --bg-2:      #070c16;
  --ink:       #cfe6ff;
  --ink-dim:   #6c8199;
  --cyan:      #46e8ff;
  --orange:    #ff9a3c;
  --amber:     #ffd23b;
  --red:       #ff3b53;
  --green:     #4dff9e;
  --pink:      #ff5ecb;
  --line:      rgba(70, 232, 255, .22);
  --panel:     rgba(6, 14, 24, .82);

  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono",
          Menlo, Consolas, "DejaVu Sans Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: .04em;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body { touch-action: none; }

/* The arena. Cursor is drawn in-canvas as a reticle. */
#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: var(--bg);
}
body.playing #stage { cursor: none; }

button { font: inherit; letter-spacing: inherit; }

/* ============================================================
   HUD
   ============================================================ */

.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  padding: clamp(10px, 2vmin, 22px);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "tl tc tr"
    ".  .  ."
    "bl bc .";
  gap: 12px;
  text-shadow: 0 0 12px currentColor;
  user-select: none;
}
.hud[hidden] { display: none; }

.hud-tl { grid-area: tl; }
.hud-tc { grid-area: tc; text-align: center; }
.hud-tr { grid-area: tr; text-align: right; }
.hud-bl { grid-area: bl; align-self: end; }
.hud-bc { grid-area: bc; align-self: end; justify-self: center; }

.lbl {
  font-size: .68rem;
  color: var(--ink-dim);
  letter-spacing: .22em;
  text-shadow: none;
}
.val { font-variant-numeric: tabular-nums; }

/* --- arcade panels ----------------------------------------
   Chunky bracketed boxes rather than floating text: at a glance
   the readouts should look like cabinet hardware, and the hull
   number in particular has to be legible without looking away
   from the middle of the screen.                             */

.panel-hud {
  position: relative;
  padding: 10px 14px 12px;
  background: linear-gradient(180deg, rgba(6, 16, 28, .88), rgba(4, 9, 16, .78));
  border: 1px solid var(--line);
  clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 14px 100%, 0 calc(100% - 14px));
}
.panel-hud::before {
  content: '';
  position: absolute;
  left: -1px; top: -1px;
  width: 18px; height: 18px;
  border-left: 2px solid var(--cyan);
  border-top: 2px solid var(--cyan);
}

/* --- hull -------------------------------------------------- */

.hull-panel { min-width: clamp(240px, 26vw, 360px); }

.hp-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 6px;
}
.hp-num {
  font-size: clamp(1.7rem, 3.4vw, 2.5rem);
  font-weight: 700;
  line-height: 1;
  color: #fff;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
  text-shadow: 0 0 20px rgba(77, 255, 158, .8);
}

.hp-bar {
  position: relative;
  height: 20px;
  border: 1px solid var(--line);
  background: rgba(70, 232, 255, .06);
  overflow: hidden;
}
.hp-bar i {
  position: absolute;
  inset: 0 auto 0 0;
  display: block;
  width: 100%;
  transform-origin: left center;
}
/* Ghost trails behind the real bar so a big hit is legible. */
#hp-ghost {
  background: rgba(255, 59, 83, .5);
  transition: transform .55s cubic-bezier(.2, .7, .3, 1) .12s;
  z-index: 1;
}
#hp-fill {
  background: linear-gradient(90deg, var(--green), var(--cyan));
  box-shadow: 0 0 22px rgba(77, 255, 158, .7);
  transition: transform .12s linear, background .3s;
  z-index: 2;
}
/* Notches drawn over the fill turn it into an arcade segment bar. */
#hp-seg {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: block;
  background: repeating-linear-gradient(
    90deg, transparent 0 calc(5% - 3px), rgba(4, 7, 13, .85) calc(5% - 3px) 5%
  );
  pointer-events: none;
}
.hp-bar.low #hp-fill { background: linear-gradient(90deg, var(--amber), var(--orange)); box-shadow: 0 0 22px rgba(255, 154, 60, .7); }
.hp-bar.low ~ .hp-row .hp-num, .hull-panel:has(.hp-bar.low) .hp-num { text-shadow: 0 0 20px rgba(255, 154, 60, .8); }
.hp-bar.crit #hp-fill {
  background: linear-gradient(90deg, var(--red), var(--orange));
  animation: pulse .55s steps(2, end) infinite;
}
.hull-panel:has(.hp-bar.crit) { border-color: rgba(255, 59, 83, .5); }
.hull-panel:has(.hp-bar.crit) .hp-num { color: var(--red); text-shadow: 0 0 22px rgba(255, 59, 83, .9); }
@keyframes pulse { 50% { opacity: .45; } }

.shields { display: flex; gap: 6px; margin-top: 8px; height: 10px; }
.shields i {
  width: 34px; height: 8px;
  background: var(--cyan);
  box-shadow: 0 0 14px var(--cyan);
  transform: skewX(-24deg);
}

/* --- score ------------------------------------------------ */

.score {
  font-size: clamp(2.1rem, 5.4vw, 3.8rem);
  font-weight: 700;
  color: #fff;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-shadow: 0 0 30px rgba(70, 232, 255, .9), 0 0 70px rgba(70, 232, 255, .4);
}
.score.bump { animation: bump .18s ease-out; }
@keyframes bump { 40% { transform: scale(1.09); } }

.combo {
  margin-top: 4px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--amber);
  letter-spacing: .16em;
  min-height: 1.2em;
  text-shadow: 0 0 18px rgba(255, 210, 59, .7);
}

/* --- right stack ------------------------------------------ */

.stat-panel { min-width: 190px; }
.hud-tr .stat {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-size: 1.05rem;
  line-height: 1.5;
}
.hud-tr .lbl { font-size: .62rem; align-self: center; }
.hud-tr .stat.threat .val { color: var(--green); }
.hud-tr .stat.threat .val.hot { color: var(--red); text-shadow: 0 0 16px rgba(255, 59, 83, .9); }

/* --- boost + ordnance -------------------------------------- */

.arms { min-width: clamp(230px, 24vw, 320px); }

.boost-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; }
.boost-bar {
  position: relative;
  height: 14px;
  border: 1px solid var(--line);
  background: rgba(70, 232, 255, .06);
  overflow: hidden;
}
.boost-bar i {
  position: absolute; inset: 0 auto 0 0;
  display: block; width: 100%;
  transform-origin: left center;
  background: linear-gradient(90deg, #2f7fa8, var(--cyan));
  transition: transform .08s linear;
}
.boost-bar i.on { background: linear-gradient(90deg, var(--cyan), #ffffff); box-shadow: 0 0 20px var(--cyan); }
.boost-bar i.full { background: linear-gradient(90deg, #2f7fa8, var(--green)); }
.boost-bar i.dry { background: rgba(255, 59, 83, .5); }

.ammo-row { display: flex; gap: 10px; margin-top: 10px; }
.ammo {
  flex: 1;
  display: flex; align-items: center; gap: 7px;
  border: 1px solid var(--line);
  padding: 4px 8px;
  background: rgba(70, 232, 255, .04);
}
.ammo .key {
  font-size: .68rem; font-weight: 700; color: #04121a;
  background: var(--cyan);
  padding: 1px 7px;
  text-shadow: none;
}
.ammo .lbl { flex: 1; font-size: .58rem; }
.ammo .val { font-size: 1.5rem; font-weight: 700; color: var(--orange); line-height: 1; }
.ammo.empty .key { background: #33475a; color: var(--ink-dim); }
.ammo.empty .val { color: var(--ink-dim); }

.buffs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; max-width: 46vw; }
.buff {
  font-size: .74rem;
  font-weight: 700;
  padding: 3px 9px;
  border: 1px solid currentColor;
  background: rgba(0, 0, 0, .45);
  position: relative;
  overflow: hidden;
}
.buff span { position: relative; z-index: 1; }
/* Width is set from JS as a percentage of the buff's remaining time. */
.buff i {
  position: absolute; inset: 0 auto 0 0;
  background: currentColor; opacity: .22;
}

/* --- special slots ---------------------------------------- */

.slots { display: flex; gap: 10px; }
.slot {
  width: 76px;
  padding: 7px 4px 6px;
  text-align: center;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-dim);
  transition: color .15s, border-color .15s, transform .12s;
}
.slot.ready { color: var(--cyan); border-color: currentColor; box-shadow: 0 0 18px rgba(70, 232, 255, .18) inset; }
.slot.fired { transform: translateY(3px) scale(.94); }
.slot .glyph { font-size: 1.3rem; display: block; line-height: 1.1; }
.slot .name  { font-size: .55rem; letter-spacing: .1em; display: block; }
.slot .qty   { font-size: .86rem; font-weight: 700; display: block; color: #fff; }
.slot:not(.ready) .qty { color: var(--ink-dim); }
.slot .kbd {
  font-size: .62rem; font-weight: 700; color: var(--ink-dim);
  border-top: 1px solid var(--line); display: block; margin-top: 3px; padding-top: 2px;
}
.slot.ready .kbd { color: var(--cyan); }

/* --- toasts ----------------------------------------------- */

.toasts {
  position: absolute;
  left: 50%; top: 26%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.toast {
  font-size: .95rem;
  letter-spacing: .2em;
  animation: toast 1.5s ease-out forwards;
  white-space: nowrap;
}
@keyframes toast {
  0%   { opacity: 0; transform: translateY(10px) scale(.9); }
  14%  { opacity: 1; transform: none; }
  70%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-22px); }
}

/* ============================================================
   Overlay screens
   ============================================================ */

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 4vmin;
  overflow-y: auto;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(9, 24, 44, .72), rgba(2, 4, 8, .94) 70%);
  backdrop-filter: blur(3px);
}
.overlay[hidden] { display: none; }

.screen {
  width: min(1080px, 100%);
  text-align: center;
  animation: in .22s ease-out;
}
.screen[hidden] { display: none; }
@keyframes in { from { opacity: 0; transform: translateY(8px); } }

h1, h2, h3 { font-weight: 700; letter-spacing: .18em; margin: 0 0 .6em; }
h2 { font-size: clamp(1.1rem, 3vw, 1.7rem); color: var(--cyan); text-shadow: 0 0 24px rgba(70, 232, 255, .6); }
h3 { font-size: .8rem; color: var(--ink-dim); letter-spacing: .26em; }
h2.dead { color: var(--red); text-shadow: 0 0 24px rgba(255, 59, 83, .6); }

.logo {
  font-size: clamp(2.6rem, 11vw, 6.5rem);
  line-height: .92;
  margin-bottom: .1em;
  color: #fff;
  text-shadow: 0 0 40px rgba(70, 232, 255, .75), 0 0 90px rgba(70, 232, 255, .35);
}
.logo span { color: var(--orange); text-shadow: 0 0 40px rgba(255, 154, 60, .8); }

.tagline { color: var(--ink-dim); margin: 0 0 2.2em; letter-spacing: .3em; font-size: .78rem; }
.hint  { color: var(--ink-dim); font-size: .74rem; margin-top: 1.6em; }
.hint b { color: var(--ink); }
.muted { color: var(--ink-dim); font-size: .8rem; }
.conn  { min-height: 1.2em; font-size: .7rem; color: var(--amber); }

/* --- buttons ---------------------------------------------- */

.menu { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 1.4em; }

.btn {
  pointer-events: auto;
  min-width: 260px;
  padding: 12px 26px;
  color: var(--ink);
  background: rgba(70, 232, 255, .05);
  border: 1px solid var(--line);
  letter-spacing: .24em;
  font-size: .82rem;
  cursor: pointer;
  transition: background .14s, color .14s, border-color .14s, transform .1s;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}
.btn:hover, .btn:focus-visible {
  background: rgba(70, 232, 255, .16);
  border-color: var(--cyan);
  color: #fff;
  outline: none;
}
.btn:active { transform: translateY(2px); }
.btn-primary {
  color: #04121a;
  background: var(--cyan);
  border-color: var(--cyan);
  font-weight: 700;
  box-shadow: 0 0 34px rgba(70, 232, 255, .38);
}
.btn-primary:hover, .btn-primary:focus-visible { background: #8df3ff; color: #04121a; }

/* --- panels ----------------------------------------------- */

.cols {
  /* Same phantom-track problem as .settings: three panels, four tracks.
     Flex keeps them centred whatever the count. */
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  text-align: left;
  margin-bottom: 1.6em;
}
.cols > .panel { flex: 1 1 250px; max-width: 420px; }
.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 16px 18px;
}

.keys { list-style: none; margin: 0; padding: 0; }
.keys li { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-size: .78rem; }
.keys b { color: var(--cyan); }
.keys span { color: var(--ink-dim); }

.bestiary { list-style: none; margin: 0; padding: 0; }
.bestiary li { display: flex; gap: 10px; align-items: flex-start; padding: 5px 0; font-size: .74rem; }
.bestiary .mark { width: 1.4em; flex: none; text-align: center; font-size: 1rem; line-height: 1.1; }
.bestiary .nm { color: var(--ink); display: block; letter-spacing: .12em; }
.bestiary .ds { color: var(--ink-dim); display: block; letter-spacing: 0; }

/* --- leaderboard ------------------------------------------ */

.board-wrap { max-height: 58vh; overflow-y: auto; border: 1px solid var(--line); background: var(--panel); }

table { width: 100%; border-collapse: collapse; font-size: .78rem; }
th, td { padding: 7px 12px; text-align: right; font-variant-numeric: tabular-nums; }
th {
  position: sticky; top: 0;
  background: #071019;
  color: var(--ink-dim);
  font-size: .62rem; letter-spacing: .2em; font-weight: 400;
  border-bottom: 1px solid var(--line);
}
th:first-child, td:first-child { text-align: left; width: 3.5em; }
th:nth-child(2), td:nth-child(2) { text-align: left; }
tbody tr:nth-child(odd) { background: rgba(70, 232, 255, .035); }
tbody tr.me { background: rgba(255, 154, 60, .16); color: #fff; }
td.tag { letter-spacing: .3em; color: var(--amber); }
tr.gold td.tag   { color: #ffe98a; }
tr.silver td.tag { color: #dfe9f5; }
tr.bronze td.tag { color: #ffb679; }
td.sc { color: #fff; }

/* --- global stats ----------------------------------------- */

.stats-wrap { max-height: 62vh; overflow-y: auto; text-align: left; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.tile {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 12px 14px;
}
.tile .k { display: block; font-size: .6rem; color: var(--ink-dim); letter-spacing: .2em; }
.tile .n {
  display: block; margin-top: 4px;
  font-size: clamp(1.1rem, 2.4vw, 1.6rem); color: #fff;
  font-variant-numeric: tabular-nums;
}
.tile .n.cyan { color: var(--cyan); }

.bars { list-style: none; margin: 0 0 16px; padding: 0; }
.bars li { padding: 5px 0; font-size: .74rem; }
.bars .row { display: flex; justify-content: space-between; margin-bottom: 3px; }
.bars .row span:last-child { color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.bars .track { height: 6px; background: rgba(70, 232, 255, .08); }
/* Inline width comes from JS; colour comes from the type class. */
.bars .bar { height: 100%; background: var(--cyan); box-shadow: 0 0 12px currentColor; }
.bar.swarmer { background: #35a7ff; }
.bar.gunner  { background: var(--red); }
.bar.turret  { background: var(--amber); }
.bar.layer   { background: var(--pink); }
.bar.bomber  { background: #eaf6ff; }

/* --- game over -------------------------------------------- */

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin: 1.2em 0;
}
.summary .cell { border: 1px solid var(--line); background: var(--panel); padding: 10px; }
.summary .k { display: block; font-size: .58rem; color: var(--ink-dim); letter-spacing: .2em; }
.summary .n { display: block; margin-top: 3px; font-size: 1.25rem; color: #fff; font-variant-numeric: tabular-nums; }
.summary .cell.hero .n { color: var(--amber); font-size: 1.8rem; }

.entry { margin: 1.4em 0; }
.entry-title { color: var(--amber); letter-spacing: .24em; font-size: .82rem; }

.initials { display: flex; justify-content: center; gap: 12px; outline: none; }
.initials b {
  width: 58px; height: 74px;
  display: grid; place-items: center;
  font-size: 2.3rem;
  border: 1px solid var(--line);
  background: var(--panel);
  color: #fff;
}
.initials b.on {
  border-color: var(--amber);
  color: var(--amber);
  box-shadow: 0 0 26px rgba(255, 210, 59, .35) inset;
  animation: caret .9s steps(2, end) infinite;
}
@keyframes caret { 50% { border-color: var(--line); } }

/* ============================================================
   Misc
   ============================================================ */

.noscript {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 2rem; text-align: center;
  background: var(--bg); color: var(--ink);
}

/* Raised by js/boot-check.js when the module graph fails to load. */
.bootfail {
  position: fixed;
  left: 50%; bottom: 24px;
  transform: translateX(-50%);
  z-index: 999;
  max-width: min(680px, 92vw);
  padding: 14px 18px;
  border: 1px solid var(--red);
  background: rgba(10, 4, 8, .95);
  color: var(--ink);
  font-size: .78rem;
  text-align: left;
}
.bootfail strong { color: var(--red); letter-spacing: .16em; display: block; }
.bootfail p { margin: .6em 0 0; color: var(--ink-dim); }
.bootfail pre {
  margin: .7em 0 0;
  padding: .6em;
  overflow-x: auto;
  font-size: .68rem;
  color: var(--amber);
  background: rgba(255, 210, 59, .07);
  white-space: pre-wrap;
  word-break: break-all;
}

@media (max-width: 640px) {
  .hud { grid-template-areas: "tl tl tr" ". . ." "bl bc bc"; }
  .slots { gap: 6px; }
  .slot { width: 52px; }
  .btn { min-width: 0; width: 100%; }
}

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

/* ============================================================
   Co-op
   ============================================================ */

.btn-coop {
  color: var(--green);
  border-color: rgba(124, 243, 200, .4);
  background: rgba(124, 243, 200, .06);
}
.btn-coop:hover, .btn-coop:focus-visible {
  background: rgba(124, 243, 200, .18);
  border-color: #7cf3c8;
  color: #fff;
}

.cols-2 > .panel { flex: 1 1 280px; max-width: 460px; display: flex; flex-direction: column; gap: 12px; }
.cols-2 .panel .btn { margin-top: auto; }

/* --- join code -------------------------------------------- */

.joincode {
  font-size: clamp(2.4rem, 8vw, 4.2rem);
  letter-spacing: .34em;
  /* The trailing letter-spacing would otherwise push it off-centre. */
  text-indent: .34em;
  color: var(--green);
  text-shadow: 0 0 40px rgba(124, 243, 200, .55);
  margin: .2em 0;
  user-select: all;
}

.joinlink {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; flex-wrap: wrap;
  font-size: .72rem; color: var(--ink-dim);
  margin: 0 0 1.6em;
}
.joinlink span { user-select: all; }

.btn-tiny {
  min-width: 0;
  padding: 5px 12px;
  font-size: .6rem;
  clip-path: none;
}

.initials.code b { width: 46px; height: 58px; font-size: 1.7rem; }
.initials.code { gap: 7px; margin: 4px 0 12px; }

/* --- lobby ------------------------------------------------ */

.lobby-panel { max-width: 460px; margin: 0 auto 1.2em; text-align: left; }

.members { list-style: none; margin: 0; padding: 0; }
.members li {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 2px;
  border-bottom: 1px solid rgba(70, 232, 255, .12);
  font-size: .78rem;
}
.members li:last-child { border-bottom: 0; }
.members li.empty { opacity: .4; }
.members li.me .who { color: #fff; }
.members .who { flex: 1; letter-spacing: .14em; }
.members .role { font-size: .6rem; color: var(--ink-dim); letter-spacing: .2em; }
.members .dot {
  width: 10px; height: 10px; flex: none;
  background: var(--green);
  box-shadow: 0 0 12px currentColor;
  transform: skewX(-20deg);
}
.members .dot.off { background: #33475a; box-shadow: none; }
.members .dot.slot0 { background: #ff9a3c; }
.members .dot.slot1 { background: #7cf3c8; }
.members .dot.slot2 { background: #b6a6ff; }
.members .dot.slot3 { background: #ff5ecb; }
.members .dot.off.slot0, .members .dot.off.slot1,
.members .dot.off.slot2, .members .dot.off.slot3 { background: #33475a; }

.btn[disabled] { opacity: .35; pointer-events: none; }

/* --- wingman strip (HUD) ---------------------------------- */

.wingmen {
  grid-area: tr;
  justify-self: end;
  align-self: start;
  margin-top: 78px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}
.wingmen[hidden] { display: none; }

.wing {
  display: flex; align-items: center; gap: 8px;
  font-size: .68rem; letter-spacing: .1em;
}
.wing.down { opacity: .45; }
.wing b { min-width: 1.6em; }
.wing i {
  display: block; width: 74px; height: 5px;
  background: rgba(70, 232, 255, .12);
  overflow: hidden;
}
.wing u {
  display: block; height: 100%;
  background: currentColor;
  box-shadow: 0 0 10px currentColor;
}
.wing span { min-width: 4.5em; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); }

.ping { font-size: .6rem; letter-spacing: .16em; text-shadow: none; }
.ping.good { color: var(--green); }
.ping.warn { color: var(--amber); }
.ping.bad  { color: var(--red); }

/* ============================================================
   Death-shot hover preview
   ============================================================ */

.shot-preview {
  position: fixed;
  z-index: 60;
  margin: 0;
  padding: 6px;
  width: 332px;
  border: 1px solid var(--line);
  background: rgba(4, 8, 14, .96);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .7);
  pointer-events: none;
  animation: in .12s ease-out;
}
.shot-preview[hidden] { display: none; }
.shot-preview img {
  display: block;
  width: 320px; height: auto;
  background: #04070d;
}
.shot-preview figcaption {
  margin-top: 5px;
  font-size: .62rem;
  letter-spacing: .18em;
  color: var(--amber);
  text-align: center;
}

tr.has-shot { cursor: help; }
tr.has-shot td:first-child::after {
  content: '\25A3';
  margin-left: 6px;
  color: var(--ink-dim);
  font-size: .8em;
}

@media (max-width: 860px) {
  .shot-preview { display: none; }
}

/* Guest sees this while the host's simulation is not advancing -
   almost always because the host backgrounded their tab. */
.hud.stalled::after {
  content: 'WAITING FOR HOST';
  position: absolute;
  left: 50%; top: 42%;
  transform: translateX(-50%);
  padding: 10px 22px;
  border: 1px solid var(--amber);
  background: rgba(20, 14, 2, .9);
  color: var(--amber);
  font-size: .82rem;
  letter-spacing: .28em;
  animation: pulse 1.1s ease-in-out infinite;
}

/* Pickup toast: larger and bolder than a status message, because
   "what did I just grab" needs to land in peripheral vision. */
.toast.big {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: .16em;
  animation-duration: 1.9s;
}

/* Accuracy reads as a stat worth comparing, so give it its own colour;
   wave and chain drop back so the row does not become a wall of numbers. */
td.acc { color: var(--green); }
td.dim { color: var(--ink-dim); }

/* Eight columns is a lot on a narrow screen. CHAIN is the least
   load-bearing, so it goes first. */
@media (max-width: 780px) {
  table th:last-child, table td:last-child { display: none; }
}

/* ============================================================
   Settings
   ============================================================ */

:root { --ui-scale: 1; }

/* UI scale is applied with `zoom` on the HUD's corner blocks and on
   the overlay screens, rather than on #hud or #overlay themselves.
   Those are position:fixed with inset:0, so zooming them would scale
   the box past the viewport; zooming their auto-sized children keeps
   everything pinned to the right corners and reflows normally. */
.hud > div { zoom: var(--ui-scale); }
.screen { zoom: var(--ui-scale); width: min(1080px, calc(100% / var(--ui-scale))); }
.screen.wide { width: min(1240px, calc(100% / var(--ui-scale))); }

.fps {
  position: absolute;
  right: 0; top: 0;
  margin: 2px 6px;
  font-size: .62rem;
  letter-spacing: .16em;
  color: var(--ink-dim);
  text-shadow: none;
  font-variant-numeric: tabular-nums;
}
.fps[hidden] { display: none; }

.settings {
  text-align: left;
  margin: 0 0 1.4em;
  max-height: 58vh;
  overflow-y: auto;
  /* Symmetric, so a scrollbar gutter cannot nudge the content sideways. */
  padding: 0 4px;
}

.set-groups {
  /* Flex, not `repeat(auto-fit, minmax(260px, 1fr))`.
     auto-fit sized four tracks for three panels here and did not
     collapse the empty one, so the groups filled the left 3/4 of the
     row and the whole block sat visibly off-centre while the button
     under it stayed centred. Flex cannot produce a phantom column. */
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: stretch;
  gap: 14px;
}

.set-groups .set-group {
  flex: 1 1 260px;
  max-width: 340px;
}

.set-group {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 14px 16px;
}
.set-group h3 { margin-bottom: .9em; }

.set-row { pointer-events: auto; margin-bottom: 14px; }
.set-row:last-child { margin-bottom: 0; }

.set-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 5px;
}
.set-label { font-size: .72rem; letter-spacing: .14em; color: var(--ink); }
.set-value {
  font-size: .68rem;
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
  min-width: 3.4em;
  text-align: right;
}
.set-hint { margin: 4px 0 0; font-size: .6rem; color: var(--ink-dim); letter-spacing: 0; }

/* --- toggle ------------------------------------------------ */

button.set-switch {
  pointer-events: auto;
  display: block;
  width: 52px; height: 22px;
  padding: 0;
  border: 1px solid var(--line);
  background: rgba(70, 232, 255, .06);
  cursor: pointer;
  position: relative;
  transition: background .15s, border-color .15s;
}
button.set-switch i {
  position: absolute;
  top: 2px; left: 2px;
  width: 22px; height: 16px;
  background: var(--ink-dim);
  transform: skewX(-16deg);
  transition: transform .15s, background .15s;
}
button.set-switch.on { border-color: var(--cyan); background: rgba(70, 232, 255, .16); }
button.set-switch.on i { transform: translateX(26px) skewX(-16deg); background: var(--cyan); box-shadow: 0 0 12px var(--cyan); }
button.set-switch:focus-visible { outline: 1px solid var(--cyan); outline-offset: 2px; }

/* --- range -------------------------------------------------- */

input.set-range {
  pointer-events: auto;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  cursor: pointer;
}
/* The filled portion is driven by --fill, set from JS via CSSOM. */
input.set-range::-webkit-slider-runnable-track {
  height: 6px;
  background: linear-gradient(90deg, var(--cyan) var(--fill, 50%), rgba(70, 232, 255, .12) var(--fill, 50%));
  border: 1px solid var(--line);
}
input.set-range::-moz-range-track {
  height: 6px;
  background: linear-gradient(90deg, var(--cyan) var(--fill, 50%), rgba(70, 232, 255, .12) var(--fill, 50%));
  border: 1px solid var(--line);
}
input.set-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 18px;
  margin-top: -7px;
  background: #fff;
  box-shadow: 0 0 12px var(--cyan);
  transform: skewX(-16deg);
  border: 0;
}
input.set-range::-moz-range-thumb {
  width: 12px; height: 18px;
  background: #fff;
  box-shadow: 0 0 12px var(--cyan);
  transform: skewX(-16deg);
  border: 0;
  border-radius: 0;
}
input.set-range:focus-visible { outline: 1px solid var(--cyan); outline-offset: 4px; }

.set-reset { display: block; margin: 14px auto 2px; }

.menu-row { flex-direction: row; justify-content: center; flex-wrap: wrap; }
.menu-row .btn { min-width: 200px; }

@media (max-width: 640px) {
  .settings { max-height: 48vh; }
  .menu-row .btn { min-width: 0; }
}

/* In-game HUD transparency, from the settings panel.
   Applied to the whole HUD rather than to individual panels so the
   readouts, toasts and slots all fade together - a half-transparent
   panel with opaque text on it looks like a bug, not a setting. */
:root { --hud-opacity: 1; }
.hud { opacity: var(--hud-opacity); }
