:root {
  --ink: #2a2530;
  --ink-soft: #6b6470;
  --paper: rgba(255, 251, 248, 0.86);
  --line: rgba(60, 40, 50, 0.12);
  --shadow: 0 8px 28px rgba(60, 30, 50, 0.16);
  --acc: #e5484d;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: 'M PLUS Rounded 1c', ui-rounded, system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #f6dfe2;
  touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#ui { position: fixed; inset: 0; pointer-events: none; }
button { font: inherit; color: inherit; cursor: pointer; }

.panel {
  pointer-events: auto;
  background: var(--paper);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.chip { display: inline-block; width: 12px; height: 12px; border-radius: 4px; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }

/* ---------------------------------------------------------------- top bar */
.hud-top {
  position: absolute; top: 12px; left: 12px; right: 12px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
}
#ui:not(.playing) .hud-top, #ui:not(.playing) #controls { display: none; }

.players { padding: 8px 10px; display: grid; gap: 4px; min-width: 210px; }
.prow {
  display: grid; grid-template-columns: 12px 1fr 72px 34px; align-items: center; gap: 8px;
  padding: 4px 6px; border-radius: 10px; font-size: 13px; font-weight: 700;
}
.prow.active { background: rgba(255, 255, 255, 0.9); box-shadow: 0 1px 6px rgba(60,30,50,.12); }
.prow.dead { opacity: 0.4; }
.prow.dead .pname { text-decoration: line-through; }
.pname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hp { position: relative; height: 6px; border-radius: 4px; background: var(--line); overflow: hidden; }
.hp b { position: absolute; left: 0; bottom: 0; height: 2px; background: #4fb8e8; }
.tag { font-style: normal; font-size: 9px; font-weight: 800; letter-spacing: .06em; margin-left: 5px; padding: 1px 4px; border-radius: 4px; background: rgba(60,40,50,.1); color: var(--ink-soft); vertical-align: 1px; }
.hp i { display: block; height: 100%; border-radius: 4px; transition: width .4s; }
.score { color: #e0a21a; font-size: 11px; letter-spacing: -1px; text-align: right; }

.top-right { display: flex; gap: 8px; align-items: flex-start; }
.wind { display: flex; align-items: center; gap: 8px; padding: 7px 12px 7px 8px; }
.compass {
  width: 40px; height: 40px; border-radius: 50%; position: relative;
  background: radial-gradient(circle, #fff 55%, #f3e6ea 56%);
  box-shadow: inset 0 0 0 1px var(--line);
}
.needle { position: absolute; inset: 0; transition: transform .25s ease-out; }
.needle::before {
  content: ''; position: absolute; left: 50%; top: 5px; transform: translateX(-50%);
  border: 7px solid transparent; border-bottom: 12px solid #3e7bfa; border-top: 0;
}
.needle::after {
  content: ''; position: absolute; left: 50%; top: 16px; bottom: 7px; width: 3px; transform: translateX(-50%);
  background: #3e7bfa; border-radius: 2px;
}
.wind-text { display: grid; line-height: 1.1; }
.wind-text b { font-size: 20px; font-weight: 800; }
.cap { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-soft); font-weight: 700; }

.cams { display: grid; padding: 4px; gap: 2px; }
.cams button {
  width: 38px; height: 38px; border: 0; background: transparent; border-radius: 10px;
  display: grid; place-items: center;
}
.cams button:hover { background: rgba(255,255,255,.9); }
.cams svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.cams svg .fill { fill: var(--ink); }
.menuSound { position: absolute; top: 12px; right: 12px; width: 38px; height: 38px; border: 0; border-radius: 10px; background: rgba(60,40,50,.06); display: grid; place-items: center; }
.menuSound svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.menuSound svg .fill { fill: var(--ink); }
.menuFs { position: absolute; top: 12px; right: 56px; width: 38px; height: 38px; border: 0; border-radius: 10px; background: rgba(60,40,50,.06); display: grid; place-items: center; }
.menuFs svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
#menu .card { position: relative; }

/* ---------------------------------------------------------------- banner */
#banner {
  position: absolute; top: 16%; left: 0; right: 0; text-align: center;
  opacity: 0; pointer-events: none;
}
#banner.show { animation: banner 2.2s ease-out forwards; }
.btext {
  font-size: clamp(26px, 5vw, 44px); font-weight: 800; letter-spacing: -0.01em;
  text-shadow: 0 2px 0 #fff, 0 0 18px rgba(255,255,255,.9), 0 0 40px rgba(255,255,255,.6);
}
.bsub { font-size: 14px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .2em; text-shadow: 0 0 10px #fff; }
@keyframes banner {
  0% { opacity: 0; transform: translateY(10px) scale(.96); }
  12% { opacity: 1; transform: none; }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-6px); }
}

/* ---------------------------------------------------------------- tank labels */
#labels { position: absolute; inset: 0; overflow: hidden; }
.tlabel {
  position: absolute; left: 0; top: 0; display: grid; justify-items: center; gap: 3px;
  font-size: 12px; font-weight: 800; white-space: nowrap; will-change: transform;
  transition: opacity .25s;
}
#labels.quiet .tlabel { opacity: .12; } /* an explosion is playing */
.tname { background: rgba(255,251,248,.85); padding: 1px 8px; border-radius: 8px; box-shadow: 0 1px 4px rgba(60,30,50,.15); }
.thp { width: 46px; height: 5px; border-radius: 3px; background: rgba(42,37,48,.18); overflow: hidden; }
.thp { position: relative; }
.thp i { display: block; height: 100%; transition: width .4s; }
.thp b { position: absolute; left: 0; top: 0; height: 2px; background: #4fb8e8; transition: width .4s; }
.tmark { visibility: hidden; font-size: 13px; line-height: 1; color: var(--ink); animation: bob 1s ease-in-out infinite; }
.tlabel.active .tmark { visibility: visible; }
.tlabel.dead .thp, .tlabel.dead .tmark { display: none; }
@keyframes bob { 50% { transform: translateY(3px); } }
/* damage numbers: comic lettering with an ink outline and a hard shadow */
.popup {
  position: absolute; left: 0; top: 0; pointer-events: none;
  font-family: Bangers, Impact, sans-serif; font-size: 34px; letter-spacing: .04em;
  text-shadow:
    -2px -2px 0 #1a1216, 2px -2px 0 #1a1216, -2px 2px 0 #1a1216, 2px 2px 0 #1a1216,
    0 -2px 0 #1a1216, 0 2px 0 #1a1216, -2px 0 0 #1a1216, 2px 0 0 #1a1216, 4px 4px 0 #1a1216;
}

/* ---------------------------------------------------------------- speech bubbles */
/* urgent messages (ui/speechBubbles.js): an inked balloon with a halftone
   shadow; the SVG draws the shape and tail, the words set its size */
#bubbles { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.bubble { position: absolute; left: 0; top: 0; will-change: transform; }
.bshape { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; }
.bfill { fill: #fffdf8; stroke: #1a1216; stroke-width: 3; stroke-linejoin: round; }
.bubble.urgent .bfill { stroke-width: 4; }
.bwords {
  position: relative; max-width: min(270px, 70vw); padding: 14px 20px 15px; text-align: center;
  font-family: 'Comic Neue', 'Comic Sans MS', ui-rounded, sans-serif; font-weight: 700;
  font-size: 17px; line-height: 1.15; text-transform: uppercase; color: #1a1216;
}
.bwords b {
  display: block; margin-bottom: 3px; font-family: Bangers, Impact, sans-serif; font-weight: 400;
  font-size: 30px; letter-spacing: .04em; line-height: 1;
  text-shadow: -1.5px -1.5px 0 #1a1216, 1.5px -1.5px 0 #1a1216, -1.5px 1.5px 0 #1a1216, 1.5px 1.5px 0 #1a1216, 3px 3px 0 #1a1216;
}

/* ---------------------------------------------------------------- controls */
#controls {
  position: absolute; left: 50%; bottom: calc(12px + var(--safe-b)); transform: translateX(-50%);
  width: min(600px, calc(100vw - 24px)); padding: 10px 12px 8px;
  transition: opacity .25s, transform .25s;
}
#controls.cpu { pointer-events: none; }
#controls.cpu .fire { opacity: .7; }
#controls.cpu .hint { visibility: hidden; }
#controls.disabled { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(calc(100% + 24px)); }
.ctl-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; gap: 8px; }
.who { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 15px; min-width: 0; }
.who span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* the weapon picker, and its menu opening upwards over the island */
#controls.picking { z-index: 3; }
.weapon { position: relative; flex: none; }
.wpick {
  display: flex; align-items: center; gap: 7px; height: 32px; padding: 0 9px 0 7px; border: 0; border-radius: 10px;
  background: rgba(255,255,255,.85); box-shadow: inset 0 0 0 1px var(--line); font-weight: 800; font-size: 13px; color: var(--ink);
}
.wpick:hover, .wpick.open { background: #fff; }
#weaponName { min-width: 96px; text-align: left; white-space: nowrap; }
.wpick .caret { font-style: normal; font-size: 11px; color: var(--ink-soft); transition: transform .15s; }
.wpick.open .caret { transform: rotate(180deg); }
.wico { display: grid; place-items: center; width: 22px; height: 22px; flex: none; } /* (not the shop's .ico tiles) */
.wico svg { width: 20px; height: 20px; display: block; }
.wmenu {
  position: absolute; right: 0; bottom: calc(100% + 10px); z-index: 5; display: none;
  width: min(540px, calc(100vw - 24px)); max-height: min(58vh, 430px); overflow-y: auto; overscroll-behavior: contain;
  grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 6px; padding: 8px;
  background: rgba(255,251,248,.97); border-radius: 14px; box-shadow: 0 10px 30px rgba(60,30,50,.25), inset 0 0 0 1px var(--line);
}
.wmenu.open { display: grid; animation: wmenu .14s ease-out; }
@keyframes wmenu { from { opacity: 0; transform: translateY(8px); } }
.witem {
  display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 7px; padding: 7px 9px; border: 0; border-radius: 10px;
  background: rgba(60,40,50,.05); text-align: left; font-weight: 800; font-size: 13px; color: var(--ink);
}
.witem:hover { background: #fff; box-shadow: 0 1px 4px rgba(60,30,50,.15); }
.witem.on { background: #fff; box-shadow: inset 0 0 0 2px var(--acc); }
.wname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wcount { font-size: 11px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
/* the Aim / Drive switch: whether the controls (and keys) aim the gun or drive the tank */
.mode { display: flex; gap: 2px; background: rgba(60,40,50,.08); border-radius: 10px; padding: 2px; flex: none; }
.mode button { height: 28px; border: 0; background: transparent; border-radius: 8px; padding: 0 10px; font-size: 13px; font-weight: 800; color: var(--ink-soft); }
.mode button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(60,30,50,.18); }
.mode b { margin-left: 5px; font-size: 11px; color: var(--acc); font-variant-numeric: tabular-nums; }
.mode.gone { display: none; } /* no fuel: no driving, and no sign of it */

.ctl-body { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.rows { display: grid; gap: 2px; }
.row { display: grid; grid-template-columns: 46px 30px 1fr 30px 42px; align-items: center; gap: 4px; }
.lbl { font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.val { font-weight: 800; font-size: 14px; text-align: right; font-variant-numeric: tabular-nums; }
.step {
  width: 30px; height: 30px; border-radius: 9px; border: 0; background: rgba(255,255,255,.9);
  box-shadow: inset 0 0 0 1px var(--line); font-size: 18px; font-weight: 700; touch-action: none;
}
.step:active { background: var(--acc); color: #fff; }

/* driving: fuel gauge and a pad of arrows in place of the aiming sliders */
.drive { display: none; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
#controls.driving .rows { display: none; }
#controls.driving .drive { display: grid; }
.fuel { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 4px 8px; }
.fuel b { font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums; text-align: right; min-width: 42px; }
.gauge { height: 8px; border-radius: 6px; background: rgba(60,40,50,.14); overflow: hidden; }
.gauge i { display: block; height: 100%; border-radius: 6px; background: var(--acc); transition: width .15s; }
.drive-msg { grid-column: 1 / -1; min-height: 16px; font-size: 12px; font-weight: 800; color: #c8402e; }
.pad { display: grid; grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(2, 44px); gap: 4px; }
.pad .step { width: 44px; height: 44px; font-size: 15px; }
.pad [data-hold="drive-fwd"] { grid-column: 2; grid-row: 1; }
.pad [data-hold="drive-left"] { grid-column: 1; grid-row: 2; }
.pad [data-hold="drive-back"] { grid-column: 2; grid-row: 2; }
.pad [data-hold="drive-right"] { grid-column: 3; grid-row: 2; }

input[type=range] {
  --pct: 50%; --cap: 100%;
  -webkit-appearance: none; appearance: none; width: 100%; min-width: 0; height: 30px; margin: 0;
  background: transparent; touch-action: none;
}
input[type=range]:focus { outline: none; }
input[type=range]::-webkit-slider-runnable-track {
  height: 8px; border-radius: 6px;
  background:
    linear-gradient(90deg, var(--acc) var(--pct), transparent var(--pct)),
    linear-gradient(90deg, rgba(60,40,50,.14) var(--cap), rgba(200,60,60,.28) var(--cap));
}
input[type=range]::-moz-range-track {
  height: 8px; border-radius: 6px;
  background:
    linear-gradient(90deg, var(--acc) var(--pct), transparent var(--pct)),
    linear-gradient(90deg, rgba(60,40,50,.14) var(--cap), rgba(200,60,60,.28) var(--cap));
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; margin-top: -7px; border-radius: 50%;
  background: #fff; border: 3px solid var(--acc); box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
input[type=range]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 3px solid var(--acc);
}
/* jammed by an EMP: static instead of numbers, sliders without their marks */
#controls.jammed .val { color: #d23b2a; font-family: Bangers, Impact, sans-serif; font-weight: 400; letter-spacing: .06em; }
#controls.jammed input[type=range]::-webkit-slider-runnable-track {
  background: repeating-linear-gradient(90deg, rgba(60,40,50,.28) 0 3px, rgba(60,40,50,.08) 3px 7px, rgba(60,40,50,.2) 7px 9px);
}
#controls.jammed input[type=range]::-moz-range-track {
  background: repeating-linear-gradient(90deg, rgba(60,40,50,.28) 0 3px, rgba(60,40,50,.08) 3px 7px, rgba(60,40,50,.2) 7px 9px);
}
#controls.jammed input[type=range]::-webkit-slider-thumb { opacity: 0; }
#controls.jammed input[type=range]::-moz-range-thumb { opacity: 0; }

.fire {
  width: 92px; height: 92px; border-radius: 50%; border: 0;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--acc) 70%, #fff), var(--acc) 60%);
  color: #fff; font-weight: 800; font-size: 18px; letter-spacing: .08em;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--acc) 45%, transparent), inset 0 -4px 0 rgba(0,0,0,.15);
  transition: transform .1s;
}
.fire:active { transform: scale(.94); }
.hint { margin-top: 4px; text-align: center; font-size: 11px; color: var(--ink-soft); }
@media (pointer: coarse) { .hint { display: none; } }

/* ---------------------------------------------------------------- drop panel */
#drop {
  position: absolute; left: 50%; bottom: calc(12px + var(--safe-b)); transform: translateX(-50%);
  width: min(600px, calc(100vw - 24px)); padding: 10px 12px;
  display: none; align-items: center; justify-content: space-between; gap: 12px;
}
#ui.dropping #drop { display: flex; }
#ui.dropping #controls { display: none; }
.drop-info { display: grid; gap: 2px; min-width: 0; }
.drop-hint { font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.alt b { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.drop-btns { display: flex; align-items: center; gap: 8px; flex: none; }
.steer {
  width: 60px; height: 60px; border-radius: 16px; border: 0; font-size: 22px;
  background: rgba(255,255,255,.92); box-shadow: inset 0 0 0 1px var(--line); touch-action: none;
}
.steer:active { background: var(--acc); color: #fff; }
#drop .fire { width: 80px; height: 80px; font-size: 16px; touch-action: none; }
#drop .dive { font-size: 14px; }
#drop[data-stage="plane"] .dive { display: none; }
#drop[data-stage="chute"] #jump { display: none; }
#drop[data-stage="landed"] .drop-btns, #drop[data-stage="cpu"] .drop-btns { visibility: hidden; }

/* ---------------------------------------------------------------- shooting range */
#rangePanel {
  position: absolute; top: 12px; left: 12px; /* in place of the players panel: tank labels show the health */
  display: none; gap: 6px; padding: 8px 10px; width: min(320px, calc(100vw - 24px));
}
#ui.ranging #rangePanel { display: grid; }
#ui.ranging .players { visibility: hidden; }
#ui.ranging #banner { top: 26%; }
#ui.ranging .exitBtn { display: none; } /* the range has its own Exit */
.range-head { display: flex; justify-content: space-between; align-items: center; }
.range-exit { border: 0; border-radius: 8px; padding: 3px 10px; font-size: 12px; font-weight: 800; background: rgba(60,40,50,.08); }
.range-btns { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
/* sound board: every sound in the game, playable one by one */
#soundBoard {
  position: absolute; top: 124px; left: 12px; width: min(340px, calc(100vw - 24px));
  max-height: calc(100vh - 350px); display: none; flex-direction: column; gap: 4px; padding: 8px 10px;
}
#ui.ranging.sounding #soundBoard { display: flex; }
.sb-list { overflow-y: auto; touch-action: pan-y; display: grid; gap: 2px; padding-right: 2px; }
.sb-group { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-soft); font-weight: 800; margin: 8px 0 2px; }
.sb-row { display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 6px; }
.sb-play { width: 30px; height: 26px; border: 0; border-radius: 8px; background: #fff; box-shadow: inset 0 0 0 1px var(--line); font-size: 11px; }
.sb-play:active { background: var(--acc); color: #fff; }
.sb-name { border: 0; background: none; text-align: left; font-size: 12px; font-weight: 700; padding: 4px 0; }
.sb-use { border: 0; border-radius: 7px; padding: 3px 8px; font-size: 11px; font-weight: 800; background: rgba(60,40,50,.07); color: var(--ink-soft); }
.sb-use.on { background: #2a2530; color: #fff; }
.range-btns button { height: 32px; border: 0; border-radius: 10px; font-size: 13px; font-weight: 800; background: #fff; box-shadow: inset 0 0 0 1px var(--line); }
.range-btns button:active, .range-exit:active { background: var(--acc); color: #fff; }
#rangePanel .hint { margin: 0; }
.secondary {
  width: 100%; height: 42px; margin-top: 8px; border: 0; border-radius: 14px;
  background: rgba(60,40,50,.07); font-size: 15px; font-weight: 800; color: var(--ink);
}
.secondary:active { transform: translateY(1px); }

/* ---------------------------------------------------------------- overlays */
.overlay {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px;
  pointer-events: auto;
  background: radial-gradient(ellipse at center, rgba(255,245,248,.35), rgba(80,40,60,.25));
}
.overlay.hidden { display: none; }
.card {
  width: min(380px, 100%); padding: 26px 24px 20px; border-radius: 22px; text-align: center;
  background: rgba(255, 251, 248, 0.92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px rgba(60, 30, 50, .28); border: 1px solid #fff;
}
.title h1 { margin: 14px 0 6px; }
#logo { display: block; width: 100%; aspect-ratio: 5 / 2; cursor: pointer; }
.title p { margin: 0 0 18px; color: var(--ink-soft); font-weight: 700; font-size: 13px; }
.field { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-weight: 700; }
.seg { display: flex; background: rgba(60,40,50,.08); border-radius: 12px; padding: 3px; }
.seg button { height: 34px; border: 0; background: transparent; border-radius: 9px; font-weight: 800; }
.seg button.on { background: #fff; box-shadow: 0 1px 4px rgba(60,30,50,.18); }
#names { display: grid; gap: 6px; margin-bottom: 14px; }
.custom { margin-bottom: 16px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: left; }
.custom summary {
  display: flex; align-items: center; gap: 10px; padding: 12px 2px; list-style: none; cursor: pointer; font-weight: 800;
}
.custom summary::-webkit-details-marker { display: none; }
.custom summary::after {
  content: ''; flex: none; width: 7px; height: 7px; margin: 0 4px 3px 0;
  border-right: 2px solid var(--ink-soft); border-bottom: 2px solid var(--ink-soft); transform: rotate(45deg); transition: transform .2s;
}
.custom[open] summary::after { transform: rotate(-135deg); margin-bottom: -3px; }
.custom .sum { flex: 1; min-width: 0; text-align: right; font-size: 12px; font-weight: 700; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.custom[open] .sum { visibility: hidden; }
.settings { display: grid; gap: 10px; padding: 2px 0 14px; }
.settings .field { margin: 0; }
.settings .secondary { margin-top: 2px; }
.field.stack { flex-direction: column; align-items: stretch; gap: 6px; text-align: left; }
.seg button { min-width: 42px; width: auto; padding: 0 8px; }
.toggle { cursor: pointer; text-align: left; gap: 12px; }
.toggle small { display: block; font-size: 11px; font-weight: 700; color: var(--ink-soft); }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  flex: none; position: relative; width: 44px; height: 26px; border-radius: 13px;
  background: rgba(60,40,50,.18); transition: background .2s;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s;
}
.toggle input:checked + .switch { background: #d9472b; }
.toggle input:checked + .switch::after { transform: translateX(18px); }
.toggle input:focus-visible + .switch { outline: 2px solid #d9472b; outline-offset: 2px; }
#menu .card { width: min(420px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; touch-action: pan-y; scrollbar-width: none; padding-top: 22px; }
#menu .card::-webkit-scrollbar { display: none; }
.field.stack .seg button { flex: 1; font-size: 13px; padding: 0 4px; }
#place button { flex: 1 1 auto; } /* longer names get more room */
.field.hidden { display: none; }
.name-row { display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 12px; padding: 0 12px; box-shadow: inset 0 0 0 1px var(--line); }
.ptype {
  flex: none; border: 0; border-radius: 8px; padding: 6px 9px; font-size: 12px; font-weight: 800;
  background: rgba(60,40,50,.07); color: var(--ink);
}
.ptype.cpu { background: #2a2530; color: #fff; }
.name-row input { flex: 1; min-width: 0; border: 0; background: transparent; font: inherit; font-weight: 700; padding: 11px 0; outline: none; color: var(--ink); user-select: text; -webkit-user-select: text; }
.primary {
  width: 100%; height: 50px; border: 0; border-radius: 14px; background: #d9472b; color: #fff;
  font-size: 17px; font-weight: 800; letter-spacing: .04em; box-shadow: 0 6px 16px rgba(217,71,43,.35);
}
.primary:active { transform: translateY(1px); }
.small { margin: 14px 0 0; font-size: 12px; color: var(--ink-soft); line-height: 1.55; }
#roundOver h2 { margin: 4px 0 14px; font-size: 30px; font-weight: 800; }
#roScores { display: grid; gap: 6px; margin-bottom: 18px; }
.srow { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: #fff; border-radius: 12px; font-weight: 700; }
.srow .pname { flex: 1; text-align: left; display: grid; min-width: 0; white-space: normal; }
#roundOver .card, #matchOver .card { width: min(460px, 100%); }
.srow .pname small { font-size: 11px; font-weight: 700; color: var(--ink-soft); line-height: 1.35; }
.srow .earn, .srow .score { flex: none; }
.srow .earn { font-weight: 800; color: #2f8a4a; }
.srow .score { color: #e0a21a; letter-spacing: -1px; min-width: 20px; text-align: right; }
.srow .place { font-weight: 800; width: 16px; color: var(--ink-soft); }
#matchOver h2 { margin: 4px 0 14px; font-size: 26px; font-weight: 800; }
#confirm .card { width: min(340px, 100%); }
.confirm h2 { margin: 0 0 4px; font-size: 22px; font-weight: 800; }
.confirm .small { margin: 0 0 16px; }
.cf-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cf-btns .secondary { margin: 0; height: 50px; }

/* ---------------------------------------------------------------- shop */
.card.shop { width: min(760px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; padding: 18px 18px 14px; text-align: left; }
.shop-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.shop-head .chip { width: 16px; height: 16px; border-radius: 5px; }
.shop-who { flex: 1; min-width: 0; }
.shop-who h2 { margin: 0; font-size: 22px; font-weight: 800; }
.cash { font-size: 26px; font-weight: 800; color: #2f8a4a; font-variant-numeric: tabular-nums; }
.shop-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 8px;
  overflow-y: auto; padding: 2px; margin: 0 -2px; touch-action: pan-y;
}
.item {
  display: grid; grid-template-columns: 34px 1fr; grid-template-rows: auto auto auto; column-gap: 8px; row-gap: 1px;
  text-align: left; padding: 10px; border: 0; border-radius: 14px; background: #fff;
  box-shadow: inset 0 0 0 1px var(--line); transition: transform .1s, box-shadow .15s;
}
.item:not(:disabled):hover { box-shadow: inset 0 0 0 2px var(--acc); }
.item:not(:disabled):active { transform: scale(.97); }
.item:disabled { cursor: default; }
.item:disabled:not(.flash) { opacity: .45; }
#shop.cpu .item:disabled { opacity: .8; }
.item.flash { animation: buyflash .6s ease-out; opacity: 1; }
@keyframes buyflash { 0% { box-shadow: inset 0 0 0 3px #2f8a4a, 0 0 0 6px rgba(47,138,74,.25); transform: scale(1.04); } 100% { box-shadow: inset 0 0 0 1px var(--line); } }
.ico { grid-row: 1 / 3; width: 34px; height: 34px; border-radius: 10px; background: #f6efea; display: grid; place-items: center; }
.ico svg { width: 24px; height: 24px; }
.iname { font-weight: 800; font-size: 14px; }
.iname small { color: var(--ink-soft); font-weight: 700; }
.idesc { font-size: 11px; color: var(--ink-soft); line-height: 1.3; }
.ifoot { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; margin-top: 6px; }
.ifoot b { font-size: 14px; }
.iown { font-size: 11px; font-weight: 800; color: var(--acc); }
.shop-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.shop-foot .small { margin: 0; }
.shop-foot .primary { width: auto; padding: 0 36px; }
#shop.cpu #shopDone { visibility: hidden; }

/* ---------------------------------------------------------------- phones */
@media (max-width: 640px) {
  .hud-top { top: calc(8px + env(safe-area-inset-top, 0px)); left: 8px; right: 8px; }
  .players { min-width: 0; padding: 6px; }
  .prow { grid-template-columns: 10px minmax(0, 72px) 44px; font-size: 11px; gap: 6px; padding: 3px 4px; }
  .prow .score { display: none; }
  .wind { padding: 5px 8px 5px 5px; }
  .compass { width: 34px; height: 34px; }
  .needle::before { top: 4px; border-width: 0 6px 10px; }
  .needle::after { top: 13px; bottom: 6px; }
  .wind-text b { font-size: 16px; }
  .cams button { width: 34px; height: 34px; }
  #controls { bottom: calc(8px + var(--safe-b)); width: calc(100vw - 16px); padding: 8px 10px; }
  .row { grid-template-columns: 40px 34px 1fr 34px 36px; }
  .step { width: 34px; height: 34px; }
  .fire { width: 76px; height: 76px; font-size: 16px; }
  #weaponName { min-width: 0; font-size: 12px; }
  .wmenu { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mode button { padding: 0 7px; font-size: 12px; }
  .mode b { margin-left: 3px; }
  .drive { gap: 8px; }
  .fuel { grid-template-columns: auto 1fr; }
  .fuel b { min-width: 0; }
  .gauge { grid-column: 1 / -1; grid-row: 2; }
  .pad { grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(2, 50px); }
  .pad .step { width: 50px; height: 50px; }
  #drop { bottom: calc(8px + var(--safe-b)); width: calc(100vw - 16px); flex-direction: column; align-items: stretch; gap: 8px; }
  .drop-info { grid-template-columns: 1fr auto; align-items: center; }
  .drop-hint { grid-column: 1 / -1; grid-row: 2; }
  .drop-btns { justify-content: space-between; }
  .steer { width: 84px; height: 72px; }
  #drop .fire { width: 76px; height: 76px; }
  .prow { grid-template-columns: 10px minmax(0, 86px) 44px; }
  .tag { display: none; }
  .card.shop { padding: 14px 12px 12px; }
  .shop-grid { grid-template-columns: 1fr 1fr; }
  .item { padding: 8px; grid-template-columns: 28px 1fr; }
  .ico { width: 28px; height: 28px; }
  .idesc { display: none; }
  .cash { font-size: 20px; }
  .shop-foot .small { display: none; }
  .shop-foot .primary { flex: 1; }
  #rangePanel { top: auto; bottom: calc(196px + var(--safe-b)); width: calc(100vw - 16px); }
  #soundBoard { top: calc(8px + env(safe-area-inset-top, 0px)); left: 8px; width: auto; right: 64px; max-height: calc(100vh - 330px); }
}
