:root {
  --bg: #0d1013;
  --steel-0: #14181c;
  --steel-1: #1a1f24;
  --steel-2: #222930;
  --steel-3: #2c343b;
  --line: #363f47;
  --line-2: #4c5862;
  --text: #dde3e8;
  --text-hi: #f3f6f8;
  --muted: #949fa8;
  --dim: #66717a;
  --amber: #e3a72f;
  --amber-hi: #f4c25a;
  --amber-lo: #6e5219;
  --teal: #5cc4cf;
  --violet: #a98ae6;
  --ok: #63c27a;
  --bad: #e25a43;
  --bad-lo: #4a1f19;
  --display: "Saira Stencil One", "Saira Condensed", "Arial Narrow", sans-serif;
  --ui: "Saira Condensed", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --brushed: repeating-linear-gradient(90deg, rgba(255,255,255,.012) 0 1px, rgba(0,0,0,.018) 1px 3px);
  color-scheme: dark;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 500 15px/1.35 var(--ui);
  letter-spacing: .01em;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.label { font: 600 11px/1 var(--ui); letter-spacing: .14em; text-transform: uppercase; color: var(--dim); }
#app { height: 100dvh; }

/* Plates & buttons */
.plate {
  background: var(--brushed), linear-gradient(180deg, var(--steel-2), var(--steel-1));
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05), 0 1px 0 rgba(0,0,0,.4);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px;
  background: linear-gradient(180deg, var(--steel-3), var(--steel-2));
  border: 1px solid var(--line-2); border-radius: 3px;
  font-weight: 600; letter-spacing: .06em; text-transform: uppercase; font-size: 13px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.07);
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
}
.btn:hover:not(:disabled) { border-color: var(--muted); color: var(--text-hi); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, var(--amber-hi), var(--amber)); color: #1b1407; border-color: var(--amber-hi); }
.btn.primary:hover:not(:disabled) { color: #000; filter: brightness(1.06); }
.btn.danger { background: linear-gradient(180deg, #5a261e, var(--bad-lo)); border-color: var(--bad); color: #ffd9d1; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 12px; }
.btn.wide { width: 100%; }

/* Menu */
.menu { height: 100%; overflow-y: auto; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(ellipse at 50% 0%, #1f262c 0%, var(--bg) 70%); }
.menu-inner { width: min(560px, 100%); display: grid; gap: 18px; }
.brand { text-align: center; }
.brand h1 { font: 400 clamp(56px, 16vw, 96px)/.9 var(--display); color: var(--text-hi); letter-spacing: .04em; }
.brand h1 span { color: var(--amber); }
.brand p { margin-top: 8px; color: var(--muted); font-size: 13px; letter-spacing: .3em; text-transform: uppercase; }
.defcon-strip { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-top: 14px; }
.defcon-strip div { height: 6px; }
.menu .plate { padding: 16px; border-radius: 4px; }
.menu .plate .label { margin-bottom: 10px; display: block; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg button { min-height: 48px; background: var(--steel-0); border: 1px solid var(--line); border-radius: 3px; font: 600 22px var(--mono); color: var(--muted); }
.seg button[aria-pressed="true"] { background: linear-gradient(180deg, var(--steel-3), var(--steel-2)); border-color: var(--amber); color: var(--amber-hi); }
.brief { display: grid; gap: 6px; color: var(--muted); font-size: 14px; }
.brief b { color: var(--text); font-weight: 600; }
.roster { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 4px 12px; }
.roster-row { display: grid; grid-template-columns: 30px 1fr auto; gap: 8px; align-items: center; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,.04); font-size: 14px; }
.roster-row img, .roster-row svg { width: 30px; height: 30px; object-fit: contain; }
.roster-row .stats { font: 500 12px var(--mono); color: var(--muted); }
.roster-row .stats i { font-style: normal; color: var(--amber); }
.menu-actions { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.menu-actions .btn { min-height: 52px; font-size: 16px; }
.menu-actions .btn:only-child { grid-column: 1 / -1; }

/* Game layout */
.game { height: 100%; display: grid; grid-template-rows: auto 1fr auto; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 6px 12px; padding-top: max(6px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: var(--brushed), linear-gradient(180deg, var(--steel-2), var(--steel-1)); min-height: 48px; }
.topbar .logo { font: 400 22px/1 var(--display); color: var(--text-hi); letter-spacing: .05em; }
.topbar .logo span { color: var(--amber); }
.turnchip { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border: 1px solid var(--line-2); border-radius: 3px; background: var(--steel-0); }
.turnchip .sw { width: 22px; height: 22px; border-radius: 2px; box-shadow: inset 0 0 0 2px rgba(0,0,0,.25); }
.turnchip b { font-weight: 700; letter-spacing: .04em; }
.stat { display: flex; flex-direction: column; line-height: 1.05; }
.stat .v { font: 600 15px var(--mono); color: var(--text-hi); }
.stat .v.gold { color: var(--amber-hi); }
.stat .k { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--dim); }
.topbar .spacer { flex: 1; }
.pips { display: flex; gap: 3px; }
.pip { width: 8px; height: 22px; border-radius: 1px; }
.pip.dead { opacity: .2; }
.iconbtn { width: 36px; height: 36px; display: grid; place-items: center; background: transparent; border: 1px solid var(--line); border-radius: 3px; color: var(--muted); }
.iconbtn:hover { color: var(--text-hi); border-color: var(--line-2); }

.main { position: relative; display: grid; grid-template-columns: 280px 1fr 250px; min-height: 0; }
.side { min-height: 0; overflow-y: auto; background: var(--steel-1); border-right: 1px solid var(--line); }
.side.right { border-right: 0; border-left: 1px solid var(--line); }
.sec { padding: 12px; border-bottom: 1px solid var(--line); }
.sec > .label { display: block; margin-bottom: 8px; }
.hint { color: var(--muted); font-size: 13px; }
.hint.warn { color: var(--amber-hi); }
.hint.bad { color: #ff9b88; }

.buy { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 8px; width: 100%; min-height: 44px; padding: 3px 8px 3px 4px; margin-bottom: 3px; text-align: left; background: var(--steel-0); border: 1px solid var(--line); border-radius: 3px; }
.buy:hover:not(:disabled) { border-color: var(--line-2); background: var(--steel-2); }
.buy:disabled { opacity: .38; cursor: not-allowed; }
.buy img, .buy svg { width: 34px; height: 34px; object-fit: contain; }
.buy .nm { font-weight: 600; font-size: 14px; color: var(--text); }
.buy .sub { display: block; font: 500 11px var(--mono); color: var(--muted); }
.buy .cost { font: 600 14px var(--mono); color: var(--amber-hi); }
.buy.owned { border-color: var(--ok); }
.buy.owned .cost { color: var(--ok); }

.reserve { display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; align-items: center; width: 100%; min-height: 48px; padding: 3px 6px 3px 4px; margin-bottom: 3px; background: rgba(169,138,230,.07); border: 1px dashed rgba(169,138,230,.5); border-radius: 3px; text-align: left; }
.reserve.armed { background: rgba(169,138,230,.2); border: 1px solid var(--violet); box-shadow: 0 0 0 1px var(--violet) inset; }
.reserve img, .reserve svg { width: 34px; height: 34px; object-fit: contain; }
.reserve .nm { font-weight: 600; }
.reserve .nm .num { color: var(--amber-hi); }
.qty { display: flex; align-items: center; gap: 2px; }
.qty button { width: 28px; height: 28px; background: var(--steel-2); border: 1px solid var(--line-2); border-radius: 2px; font: 600 15px var(--mono); }
.qty .num { min-width: 22px; text-align: center; color: var(--text-hi); }
.xbtn { width: 28px; height: 28px; background: transparent; border: 1px solid var(--line); border-radius: 2px; color: var(--muted); }
.xbtn:hover { color: var(--bad); border-color: var(--bad); }

.mover { display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; align-items: center; padding: 3px 6px 3px 4px; margin-bottom: 3px; background: var(--steel-0); border: 1px solid var(--line); border-radius: 3px; min-height: 46px; }
.mover.sel { border-color: var(--teal); background: rgba(92,196,207,.08); }
.mover img, .mover svg { width: 34px; height: 34px; object-fit: contain; }
.mover .sub { display: block; font: 500 11px var(--mono); color: var(--muted); }
.btnrow { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.btnrow .btn { flex: 1; }

.score { display: grid; grid-template-columns: 10px 1fr auto auto auto; gap: 8px; align-items: center; padding: 5px 0; font-size: 14px; border-bottom: 1px solid rgba(255,255,255,.04); }
.score .sw { width: 10px; height: 10px; border-radius: 1px; }
.score.cur { color: var(--text-hi); font-weight: 700; }
.score.dead { opacity: .35; text-decoration: line-through; }
.score .num { font-size: 12px; color: var(--muted); }
.score .num.g { color: var(--amber-hi); }
.score .num.p { color: var(--ok); }
.progress { margin-top: 8px; font-size: 12px; color: var(--dim); }

.tagrow { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.tag { padding: 2px 8px; border-radius: 2px; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; background: var(--steel-3); border: 1px solid var(--line-2); }
.ulist { display: grid; gap: 2px; }
.urow { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; font-size: 14px; }
.urow img, .urow svg { width: 28px; height: 28px; object-fit: contain; }
.urow .num { color: var(--text-hi); }
.log { max-height: 220px; overflow-y: auto; font-size: 12.5px; color: var(--muted); display: grid; gap: 2px; }
.log div { padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,.03); }
.log .turn { color: var(--amber-hi); font-weight: 700; }
.log .kill { color: #ff9b88; }
.log .win { color: var(--ok); }

/* Board */
.board { position: relative; overflow: hidden; touch-action: none; perspective: 1100px; perspective-origin: 50% 40%; /* keep in sync with PERSPECTIVE / PERSP_OY in game.js */
  background: radial-gradient(ellipse at 50% 45%, #2a3138 0%, #161b20 60%, #0c0f12 100%); cursor: grab; }
.board.panning { cursor: grabbing; }
.cam { position: absolute; left: 0; top: 0; transform-style: preserve-3d; will-change: transform; }
.table { position: absolute; border-radius: 18px;
  background: var(--brushed), radial-gradient(ellipse at 50% 30%, #49535c 0%, #333b42 45%, #262c32 100%);
  box-shadow: 0 30px 60px rgba(0,0,0,.55), inset 0 0 0 1px rgba(255,255,255,.06), inset 0 2px 0 rgba(255,255,255,.08); }
.cam svg.tiles { position: absolute; left: 0; top: 0; overflow: visible; }
.tiles .hx { cursor: pointer; }
.tiles .hx.mtn { cursor: default; }
.props { position: absolute; left: 0; top: 0; transform-style: preserve-3d; pointer-events: none; }
.piece { position: absolute; transform-style: preserve-3d; }
.piece .base { position: absolute; left: 0; top: 0; border-radius: 50%; opacity: .7; box-shadow: 0 0 0 1.5px rgba(0,0,0,.55), 0 2px 4px rgba(0,0,0,.5); }
.piece .stand { position: absolute; left: 50%; bottom: 0; transform-origin: 50% 100%; }
.piece img, .piece svg.fallback { display: block; width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 3px 2px rgba(0,0,0,.55)); }
.piece.peak img { opacity: .92; transition: opacity .2s; }
.board.tilted .piece.peak img { opacity: .7; }
.piece .count { position: absolute; right: -4px; bottom: -3px; min-width: 16px; height: 16px; padding: 0 3px; border-radius: 8px; font: 600 11px/16px var(--mono); text-align: center; color: #fff; border: 1px solid rgba(0,0,0,.5); box-shadow: 0 1px 2px rgba(0,0,0,.6); }
.zoomctl { position: absolute; right: 10px; bottom: 10px; display: grid; gap: 4px; z-index: 5; }
.zoomctl button { width: 40px; height: 40px; background: rgba(20,24,28,.85); border: 1px solid var(--line-2); border-radius: 3px; font: 600 18px var(--mono); color: var(--text); }
.boardhint { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 5; padding: 6px 12px; border-radius: 3px; background: rgba(13,16,19,.88); border: 1px solid var(--line-2); font-size: 13px; color: var(--text); white-space: nowrap; max-width: calc(100% - 20px); overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.boardhint.violet { border-color: var(--violet); }
.boardhint.teal { border-color: var(--teal); }
.boardhint.amber { border-color: var(--amber); }

/* Bottom bar */
.bottombar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--brushed), linear-gradient(180deg, var(--steel-2), var(--steel-1)); }
.phases { display: flex; gap: 2px; flex: 1; min-width: 0; }
.phase { flex: 1; max-width: 160px; padding: 6px 4px; text-align: center; font: 600 11px/1 var(--ui); letter-spacing: .1em; text-transform: uppercase; color: var(--dim); background: var(--steel-0); border: 1px solid var(--line); clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 50%, calc(100% - 8px) 100%, 0 100%, 8px 50%); }
.phase:first-child { clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 50%, calc(100% - 8px) 100%, 0 100%); }
.phase.on { color: #1b1407; background: var(--amber); border-color: var(--amber); }
.phase.done { color: var(--muted); }
.bottombar .btn.primary { min-width: 150px; min-height: 44px; }
.tabs { display: none; }

/* Overlays */
#overlay:empty { display: none; }
.ov { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(6,8,10,.82); backdrop-filter: blur(3px); }
.dialog { width: min(720px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; border-radius: 4px; padding: 18px; }
.dialog h2 { font: 400 30px/1 var(--display); letter-spacing: .04em; color: var(--text-hi); }
.dialog .sub { color: var(--muted); margin-top: 6px; }
.handoff { text-align: center; display: grid; gap: 14px; justify-items: center; }
.handoff .sw { width: 72px; height: 72px; border-radius: 4px; box-shadow: inset 0 0 0 4px rgba(0,0,0,.25); }
.handoff h2 { font-size: 40px; }

.battle-sides { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; margin-top: 14px; align-items: start; }
.vs { align-self: center; font: 400 24px var(--display); color: var(--dim); }
.side-h { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 8px; padding-bottom: 6px; border-bottom: 2px solid; }
.side-h .need { margin-left: auto; font: 600 12px var(--mono); color: var(--amber-hi); }
.cu { display: grid; grid-template-columns: 34px 1fr auto 30px; gap: 8px; align-items: center; min-height: 42px; padding: 3px 6px 3px 3px; margin-bottom: 3px; background: var(--steel-0); border: 1px solid var(--line); border-radius: 3px; width: 100%; text-align: left; }
.cu img, .cu svg { width: 34px; height: 34px; object-fit: contain; }
.cu .st { font: 600 12px var(--mono); color: var(--muted); }
.cu.pick { border-color: var(--amber); background: rgba(227,167,47,.08); cursor: pointer; }
.cu.pick:hover { background: rgba(227,167,47,.18); }
.cu.dead { opacity: .5; background: var(--bad-lo); border-color: var(--bad); }
.cu.dead .nm { text-decoration: line-through; }
.die { width: 28px; height: 28px; border-radius: 4px; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 3px; gap: 1px; background: #e9ecef; box-shadow: inset 0 -2px 0 rgba(0,0,0,.25); }
.die.hit { background: var(--ok); }
.die.miss { background: #4a535b; }
.die i { border-radius: 50%; }
.die.blank { background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.tally { display: flex; justify-content: center; gap: 40px; margin-top: 12px; padding: 8px; background: var(--steel-0); border: 1px solid var(--line); border-radius: 3px; }
.tally div { text-align: center; }
.tally .num { display: block; font-size: 26px; font-weight: 600; }
.battle-actions { display: flex; justify-content: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.adline { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 10px; }
.adline span { display: inline-flex; gap: 6px; align-items: center; padding: 3px 8px; border: 1px solid var(--line); border-radius: 3px; font-size: 13px; }
.winner { text-align: center; display: grid; gap: 12px; justify-items: center; }
.winner h2 { font-size: 56px; }

/* Mobile */
@media (max-width: 860px) {
  .main { grid-template-columns: 1fr; }
  .side { position: absolute; left: 0; right: 0; bottom: 0; z-index: 10; max-height: 52%; display: none; border: 0; border-top: 1px solid var(--line-2); box-shadow: 0 -12px 30px rgba(0,0,0,.5); }
  .side.show { display: block; }
  .tabs { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); background: var(--steel-1); }
  .tabs button { min-height: 44px; background: transparent; border: 0; border-top: 2px solid transparent; font-weight: 600; font-size: 13px; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); }
  .tabs button[aria-pressed="true"] { color: var(--text-hi); border-top-color: var(--amber); background: var(--steel-2); }
  .game { grid-template-rows: auto 1fr auto auto; }
  .topbar .logo { font-size: 18px; }
  .topbar .hide-sm { display: none; }
  .phases .phase { font-size: 10px; letter-spacing: .04em; }
  .bottombar .btn.primary { min-width: 118px; }
  .battle-sides { grid-template-columns: 1fr; }
  .vs { justify-self: center; }
  .dialog { padding: 14px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
