/* Wartide - parchment board look. All colours are CSS variables. */
:root {
  --parchment: #f1e7cf;
  --parchment-2: #e8dcc0;
  --paper: #fbf6e8;
  --ink: #2b2620;
  --ink-soft: #6b6254;
  --line: #3a332a;
  --accent: #8a2f27;
  --accent-ink: #fff6e6;
  --sea-a: #d7e6ec;
  --sea-b: #c3d9e3;
  --land-neutral: #d9cfae;
  --decor: #bdb9ad;
  --ussr: #a0522d; /* power colours mirror crates/engine/data/map.json */
  --germany: #6b6b6b;
  --uk: #9c8b5a;
  --japan: #e2b007;
  --usa: #4f8a3c;
  --ok: #4d7a3a;
  --warn: #b07a1a;
  --bad: #a3322b;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(40, 30, 10, .18);
  --font-display: "Staatliches", "Oswald", Impact, sans-serif;
  --font-serif: "Spectral", Georgia, serif;
  --font-ui: "Inter", system-ui, sans-serif;
}
:root[data-theme="dark"] {
  --parchment: #1f1c17; --parchment-2: #2a261f; --paper: #26221c; --ink: #eadfc6;
  --ink-soft: #a89d86; --line: #8a7f68; --sea-a: #223640; --sea-b: #1c2e37;
  --land-neutral: #4a4435; --decor: #3a3629; --shadow: 0 2px 8px rgba(0, 0, 0, .5);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--parchment); color: var(--ink); font-family: var(--font-ui); font-size: 15px;
  background-image: url(/assets/brand/board_texture.png);
  background-size: 512px 512px;
  background-attachment: fixed;
}
h1, h2, h3, h4 { font-family: var(--font-display); letter-spacing: .04em; font-weight: 400; margin: 0 0 .5rem; }
h1 { font-size: 2.4rem; } h2 { font-size: 1.6rem; } h3 { font-size: 1.2rem; }
a { color: var(--accent); }
.serif { font-family: var(--font-serif); }
.muted { color: var(--ink-soft); }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: .6rem; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }

/* Layout */
.page { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow);
}
.card > h2:first-child, .card > h3:first-child { border-bottom: 2px solid var(--line); padding-bottom: .25rem; }

/* Nav */
.nav {
  display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; background: var(--ink);
  color: var(--parchment); position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.nav a { color: var(--parchment); text-decoration: none; }
.nav a:hover, .nav a.active { text-decoration: underline; }
.brand { font-family: var(--font-display); font-size: 1.6rem; letter-spacing: .1em; }
.nav .user { display: flex; gap: .5rem; align-items: center; }

/* Forms & buttons */
label { display: flex; flex-direction: column; gap: .2rem; font-size: .85rem; color: var(--ink-soft); }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fffdf5; border: 1px solid var(--line);
  border-radius: 6px; padding: .45rem .6rem; min-width: 0;
}
:root[data-theme="dark"] input, :root[data-theme="dark"] select, :root[data-theme="dark"] textarea { background: #15130f; }
input[type="checkbox"] { width: 1.1rem; height: 1.1rem; padding: 0; }
.check { flex-direction: row; align-items: center; gap: .5rem; color: var(--ink); font-size: .95rem; }
button, .btn {
  font: inherit; font-family: var(--font-display); letter-spacing: .08em; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--line);
  border-radius: 6px; padding: .45rem .9rem; text-decoration: none; display: inline-block;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.secondary { background: var(--parchment-2); color: var(--ink); }
button.small { padding: .2rem .55rem; font-size: .85rem; }
.error { color: var(--bad); font-size: .9rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .35rem .5rem; border-bottom: 1px solid rgba(60, 50, 40, .25); }
th { font-family: var(--font-display); font-weight: 400; letter-spacing: .05em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Tags / badges */
.pill { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .75rem; background: var(--parchment-2); border: 1px solid var(--line); }
.pill.hot { background: var(--accent); color: var(--accent-ink); }
.power-badge {
  display: inline-flex; align-items: center; gap: .35rem; padding: .1rem .55rem .1rem .3rem;
  border-radius: 999px; background: var(--pc); color: #fff; border: 1px solid rgba(0, 0, 0, .5);
  font-family: var(--font-display); letter-spacing: .06em; font-size: .85rem; white-space: nowrap;
}
.power-badge .dot { width: .8rem; height: .8rem; border-radius: 50%; background: #fff; opacity: .85; }
.power-ussr { --pc: var(--ussr); } .power-germany { --pc: var(--germany); }
.power-uk { --pc: var(--uk); } .power-japan { --pc: var(--japan); } .power-usa { --pc: var(--usa); }
.countdown { font-variant-numeric: tabular-nums; font-weight: 600; }
.countdown.urgent { color: var(--bad); }

/* Landing */
.hero { text-align: center; padding: 2rem 1rem; }
.hero h1 { font-size: 4rem; letter-spacing: .15em; margin: 0; color: var(--accent); }
.hero p { font-family: var(--font-serif); font-size: 1.2rem; max-width: 40rem; margin: .5rem auto 1.5rem; }

/* Toasts & modal */
.toasts { position: fixed; right: 1rem; top: 4rem; pointer-events: none; display: flex; flex-direction: column; gap: .5rem; z-index: 100; }
.toast { pointer-events: auto; background: var(--ink); color: var(--parchment); padding: .6rem .9rem; border-radius: 6px; box-shadow: var(--shadow); max-width: 22rem; border-left: 5px solid var(--ok); }
.toast.error { border-color: var(--bad); } .toast.warn { border-color: var(--warn); }
.modal-back { position: fixed; inset: 0; background: rgba(20, 15, 5, .55); display: grid; place-items: center; z-index: 50; padding: 1rem; }
.modal { background: var(--paper); border: 2px solid var(--line); border-radius: var(--radius); max-width: 640px; width: 100%; max-height: 90vh; overflow: auto; padding: 1rem 1.2rem; }

/* Game screen */
.game { display: grid; grid-template-rows: auto 1fr; height: calc(100vh - 48px); min-height: 480px; }
.topbar { display: flex; gap: 1rem; align-items: center; padding: .4rem .8rem; background: var(--paper); border-bottom: 2px solid var(--line); flex-wrap: wrap; }
.stepper { display: flex; gap: 2px; flex-wrap: wrap; }
.step { font-size: .7rem; padding: .15rem .45rem; background: var(--parchment-2); border: 1px solid var(--line); color: var(--ink-soft); font-family: var(--font-display); letter-spacing: .05em; }
.step.done { opacity: .55; }
.step.on { background: var(--accent); color: var(--accent-ink); }
.game-body { display: grid; grid-template-columns: 1fr 340px; min-height: 0; position: relative; }
.board-wrap { position: relative; min-height: 0; background: var(--sea-a); overflow: hidden; touch-action: none; cursor: grab; }
.board-wrap.dragging { cursor: grabbing; }
.board-svg { width: 100%; height: 100%; display: block; user-select: none; }
.loc { vector-effect: non-scaling-stroke; stroke: var(--line); stroke-width: .8; transition: filter .1s; cursor: pointer; }
.loc.sea-a { fill: var(--sea-a); } .loc.sea-b { fill: var(--sea-b); }
.loc.land { fill: var(--land-neutral); stroke-width: 1.1; }
.loc.owner-ussr { fill: var(--ussr); } .loc.owner-germany { fill: var(--germany); }
.loc.owner-uk { fill: var(--uk); } .loc.owner-japan { fill: var(--japan); } .loc.owner-usa { fill: var(--usa); }
.loc:hover { filter: brightness(1.12); }
.loc.hl-move { stroke: var(--ok); stroke-width: 3px; }
.loc.hl-attack { stroke: var(--bad); stroke-width: 3px; }
.loc.hl-battle { stroke: #000; stroke-width: 3px; stroke-dasharray: 6 3; }
.loc.selected { stroke: #fff; stroke-width: 4; filter: drop-shadow(0 0 4px #000); }
.lbl { font-family: var(--font-display); font-size: 20px; fill: var(--ink); pointer-events: none; text-anchor: middle; paint-order: stroke; stroke: rgba(255, 250, 235, .8); stroke-width: 4px; letter-spacing: .05em; }
/* Whole-map zoom: smaller land labels (see map::LABEL_FONT_L0); hidden on narrow screens. */
.lbl.l0 { font-size: 14px; stroke-width: 3px; letter-spacing: .03em; }
@media (max-width: 800px), (max-height: 500px) and (pointer: coarse) { .lbl.l0 { display: none !important; } }
:root[data-theme="dark"] .lbl { stroke: rgba(20, 18, 14, .85); }
:root[data-theme="dark"] .lbl.sea { fill: #9db8c4; }
.lbl.sea { font-style: italic; font-family: var(--font-serif); fill: #4a6672; }
.ipc { font-family: var(--font-display); font-size: 11px; fill: #fff; pointer-events: none; text-anchor: middle; }
.ipc-bg { fill: var(--ink); stroke: var(--paper); stroke-width: 1; }
/* legacy */ .stack rect { fill: var(--pc); stroke: #111; stroke-width: 1; }
.stack text { font: 700 9px var(--font-ui); fill: #fff; pointer-events: none; }
.board-ctl { position: absolute; left: .6rem; bottom: .6rem; display: flex; gap: .3rem; }
.side { background: var(--paper); border-left: 2px solid var(--line); overflow: auto; padding: .8rem; display: flex; flex-direction: column; gap: .8rem; }
.side-toggle { display: none; }
.unit-badge { display: inline-flex; align-items: center; gap: .25rem; background: var(--pc, #888); color: #fff; border-radius: 999px; border: 1px solid #111; padding: 0 .45rem 0 .15rem; font-weight: 700; font-size: .8rem; }
.unit-icon { display: inline-block; width: 1.3rem; height: 1.3rem; vertical-align: middle; position: relative; }
.unit-icon svg { width: 100%; height: 100%; display: block; }
.on-badge .unit-icon { color: #fff; }
.topbar { row-gap: .3rem; }
.topbar .countdown { white-space: nowrap; }
.die { display: inline-grid; place-items: center; width: 1.9rem; height: 1.9rem; border: 2px solid var(--line); background: #fffdf5; border-radius: 6px; font-weight: 700; margin: 0 .15rem; color: var(--ink); }
.die.hit { background: var(--ok); color: #fff; }
.dice-roll { animation: tumble .5s ease-out; }
@keyframes tumble { from { transform: rotate(180deg) scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
.battle { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.battle > div { border: 1px solid var(--line); padding: .4rem; border-radius: 6px; background: var(--parchment-2); }

/* Chat */
.chat { border-top: 2px solid var(--line); display: flex; flex-direction: column; min-height: 180px; max-height: 40vh; }
.tabs { display: flex; gap: 2px; }
.tab { padding: .2rem .7rem; background: var(--parchment-2); border: 1px solid var(--line); cursor: pointer; font-family: var(--font-display); letter-spacing: .05em; font-size: .85rem; }
.tab.on { background: var(--ink); color: var(--parchment); }
.msgs { overflow: auto; flex: 1; padding: .3rem 0; display: flex; flex-direction: column; gap: .3rem; }
.msg { font-size: .88rem; padding: .2rem .5rem; border-left: 4px solid var(--pc, var(--line)); background: rgba(255, 255, 255, .35); }
.msg.bot { font-family: var(--font-serif); font-style: italic; }
.log { font-size: .8rem; max-height: 9rem; overflow: auto; }
.log div { padding: .1rem 0; border-bottom: 1px dotted rgba(60, 50, 40, .3); }

/* Brand & polish */
.brand { display: inline-flex; align-items: center; gap: .5rem; }
.brand .logo { width: 32px; height: 32px; border-radius: 6px; }
.hero .wordmark { max-width: min(520px, 90%); height: auto; }
.center { text-align: center; }
.banner { background: var(--warn); color: #fff; padding: .4rem 1rem; font-size: .9rem; }
.avatar { width: 72px; height: 72px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-family: var(--font-display); font-size: 1.8rem; }
.code { font-family: ui-monospace, Menlo, monospace; letter-spacing: .12em; background: var(--parchment-2); padding: .1rem .4rem; border-radius: 4px; user-select: all; }
.power-badge .emblem { width: 1.15rem; height: 1.15rem; border-radius: 50%; box-shadow: 0 0 0 1.5px rgba(255, 255, 255, .85); }
.decor { fill: var(--decor); stroke: none; pointer-events: none; opacity: .85; }
.ov { pointer-events: none; }
.ipc-g .ipc-bg { fill: var(--ink); }
.preview-wrap { background: var(--sea-a); border-radius: 6px; overflow: hidden; }
.preview-wrap .board-svg { height: auto; aspect-ratio: 2 / 1; }
.seat { padding: .15rem .3rem; border-radius: 6px; font-size: .9rem; }
.seat.me { background: var(--parchment-2); }
.seat.cur { outline: 2px solid var(--accent); }
.invite { font-size: .95rem; }
.game-info { border-bottom: 1px solid var(--line); padding-bottom: .6rem; }
.msg.system { color: var(--ink-soft); font-size: .8rem; }
.toast { cursor: pointer; } .toast a { color: #ffd98a; }

/* ---- Interactive game screen ---- */
.stack-row { display: inline-flex; align-items: center; gap: 3px; pointer-events: none; }
.stack-row.picked .unit-badge { outline: 2px solid #fff; box-shadow: 0 0 0 4px var(--accent); }
/* Compact stacks: up to 2 rows of 3 small badges. */
.cstack { display: grid; grid-auto-rows: 16px; pointer-events: none; }
.cbadge { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 29px; height: 14px; margin: 1px; box-sizing: border-box; background: rgba(28, 22, 12, .88); color: #fff; border: 1px solid #111; border-radius: 999px; font-size: 9px; line-height: 1; white-space: nowrap; pointer-events: none; }
.cbadge.ring { box-shadow: 0 0 0 2px var(--pc, #888); }
.cbadge .drag-handle { display: inline-flex; align-items: center; gap: 1px; }
.cbadge .unit-icon { width: 12px; height: 12px; color: #fff; }
.cbadge b { font-weight: 700; }
.cbadge.more { background: rgba(255, 250, 235, .92); color: #222; pointer-events: auto; }
.cbadge.picked { outline: 2px solid #fff; box-shadow: 0 0 0 4px var(--accent); }
.cbadge .cargo { position: absolute; top: -7px; right: -3px; font-size: 8px; padding: 0 2px; border-radius: 6px; }
.cbadge .cargo .unit-icon { width: 9px; height: 9px; }
.cargo { display: inline-flex; gap: 2px; background: rgba(20, 15, 5, .75); border-radius: 8px; padding: 0 4px; color: #fff; font-size: .7rem; font-weight: 700; }
.cargo .cg { display: inline-flex; align-items: center; }
.cargo .unit-icon { width: .95rem; height: .95rem; color: #fff; }
.loc.hl-place { stroke: #2b6cb0; stroke-width: 3px; stroke-dasharray: 2 4; }
.loc.hl-movable { stroke: #f2c94c; stroke-width: 2.4px; }
.loc.hl-move { stroke: #3b8f3b; stroke-width: 4px; filter: drop-shadow(0 0 3px #3b8f3b); }
.loc.hl-attack { stroke: #c0392b; stroke-width: 4px; filter: drop-shadow(0 0 3px #c0392b); }
.pill.tip { white-space: pre-line; border-radius: 8px; max-width: 340px; font-size: .78rem; line-height: 1.3; padding: .3rem .6rem; background: var(--paper); color: var(--ink); pointer-events: none; }
.board-ctl { align-items: flex-end; }
.sandbox-note { background: var(--parchment-2); border: 1px dashed var(--line); padding: .4rem .6rem; border-radius: 6px; font-size: .85rem; }
.wait { padding: .6rem; border: 1px dashed var(--line); border-radius: 6px; background: var(--parchment-2); }
.income-note { padding: .3rem .6rem; border-left: 4px solid var(--ok); background: var(--parchment-2); font-size: .85rem; }
.hint { font-size: .85rem; color: var(--ink-soft); padding: .3rem 0; }
.warn { font-size: .82rem; color: var(--warn); border-left: 3px solid var(--warn); padding: .2rem .5rem; background: rgba(176, 122, 26, .08); }
.preview { border: 1px solid var(--line); border-radius: 6px; padding: .5rem; display: flex; flex-direction: column; gap: .35rem; background: var(--parchment-2); font-size: .88rem; }
.tag { display: inline-block; font-size: .75rem; padding: 0 .4rem; border-radius: 4px; width: fit-content; }
.tag.attack { background: var(--bad); color: #fff; } .tag.ok { background: var(--ok); color: #fff; } .tag.bad { background: var(--warn); color: #fff; }
.urow { display: flex; align-items: center; gap: .4rem; padding: .2rem 0; border-bottom: 1px dotted rgba(60, 50, 40, .3); font-size: .88rem; }
.urow.dim, tr.dim { opacity: .5; }
.stepval { min-width: 1.4rem; text-align: center; }
.stepper-s { gap: .2rem; flex-wrap: nowrap; }
.sub { display: flex; flex-direction: column; gap: .3rem; padding: .4rem 0; border-top: 1px solid var(--line); margin-top: .3rem; }
.chip { padding: .1rem .3rem; background: var(--parchment-2); }
.chip.on { outline: 3px solid var(--accent); }
.ptable td, .ptable th { padding: .2rem .4rem; }
.battlerow { display: flex; gap: .5rem; align-items: center; padding: .4rem; border: 1px solid var(--line); border-radius: 6px; background: var(--parchment-2); margin-bottom: .3rem; }
.battle-board .bside { display: flex; flex-direction: column; gap: .2rem; }
.brow { display: flex; align-items: center; gap: .3rem; font-size: .85rem; }
.brow.dead { opacity: .45; text-decoration: line-through; }
.hitnum { font-family: var(--font-display); background: var(--ink); color: var(--parchment); border-radius: 4px; padding: 0 .35rem; }
.decision { border: 2px solid var(--accent); border-radius: 6px; padding: .5rem; display: flex; flex-direction: column; gap: .4rem; margin-top: .5rem; background: rgba(138, 47, 39, .06); }
.dicerow { margin-top: .4rem; }
.dice { display: flex; gap: 6px; flex-wrap: wrap; padding: .2rem 0; }
.dieface { width: 30px; height: 30px; border-radius: 6px; background: #2b2620; border: 2px solid #11100d; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 4px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08); }
.dieface i { border-radius: 50%; place-self: center; width: 5px; height: 5px; }
.dieface i.pip { background: #f3e6c4; }
.dieface.hit { box-shadow: 0 0 0 3px #4d9a3a, 0 0 8px #6cc653; }
.dieface.miss { background: #4a443a; border-color: #2b2620; }
.dieface.miss i.pip { background: #d9ccaa; }
.dieface.roll { animation: dieroll .5s cubic-bezier(.2, .8, .3, 1) both; }
@keyframes dieroll { 0% { transform: translateY(-18px) rotate(-220deg) scale(.4); opacity: 0; } 70% { opacity: 1; } 100% { transform: none; } }
.actionlog .log { max-height: 10rem; }
.actionlog .log.expanded { max-height: 60vh; }
.logline { padding-left: .35rem; }
.loglevel .tab { padding: .1rem .5rem; font-size: .75rem; user-select: none; }
.econ { gap: .25rem; }
.econ-pill { font-size: .72rem; border-width: 2px; }
.econ-pill .techs { color: var(--accent); font-weight: 700; }
.pill.hot .techs { color: #ffd98a; }
.gameover { padding: 1rem; text-align: center; border: 2px solid var(--accent); border-radius: 6px; }

/* ---- Web integration pass ---- */
.small-text { font-size: .8rem; }
.hidden { display: none !important; }
button.danger { background: var(--bad); }
.btn.small { padding: .2rem .55rem; font-size: .85rem; }
.big-tabs .tab { font-size: 1rem; padding: .35rem 1.1rem; }
.winner-banner { padding: .45rem .7rem; border-radius: 6px; font-family: var(--font-display); letter-spacing: .06em; text-align: center; background: var(--ink); color: var(--parchment); border: 2px solid var(--line); }
.winner-banner.axis { border-color: var(--germany); box-shadow: inset 0 0 0 2px var(--germany); }
.winner-banner.allies { border-color: var(--usa); box-shadow: inset 0 0 0 2px var(--usa); }
.pending-note { font-size: .85rem; padding: .3rem .6rem; border-left: 4px solid var(--warn); background: rgba(176, 122, 26, .12); }
.warn-pill { background: rgba(176, 122, 26, .2); border-color: var(--warn); }
.seats { display: flex; flex-direction: column; gap: 2px; }
.seat { padding: .05rem .3rem; font-size: .82rem; flex-wrap: nowrap; gap: .3rem; }
.seat .pill { font-size: .68rem; white-space: nowrap; }
.seat-cfg { display: flex; flex-direction: column; gap: .15rem; }
.seat-label { width: 11rem; }
.opt { display: flex; flex-direction: column; gap: .05rem; }
.opt-help { margin-left: 1.6rem; }
.create-form select { max-width: 100%; }
.skeleton { display: flex; flex-direction: column; gap: .5rem; padding: .4rem 0; }
.sk-line { height: .9rem; border-radius: 4px; background: linear-gradient(90deg, var(--parchment-2), var(--paper), var(--parchment-2)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.empty { text-align: center; padding: 1rem .5rem; border: 1px dashed var(--line); border-radius: 6px; }
.empty p { margin: 0; }
.pager { justify-content: center; }
.deadline { white-space: nowrap; }
.replay { display: flex; flex-direction: column; gap: .4rem; padding: .5rem; border: 2px solid var(--accent); border-radius: 6px; background: rgba(138, 47, 39, .06); }
.replay input[type="range"] { width: 100%; padding: 0; }
.help .plain { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: .3rem 1.2rem; }
.help ol.phases li, .help ul li { margin: .25rem 0; }
.sec { display: flex; flex-direction: column; gap: .8rem; }
.mtabs { display: none; }

/* Mobile: the side panel becomes a bottom sheet with tabs Board / Actions / Chat / Log. */
@media (max-width: 800px), (max-height: 500px) and (pointer: coarse) {
  .hero h1 { font-size: 2.6rem; }
  .page { padding: .6rem; }
  .nav { gap: .5rem .8rem; padding: .4rem .6rem; }
  .game { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; height: calc(100dvh - var(--nav-h)); min-height: 0; }
  .topbar { gap: .3rem .5rem; padding: .3rem .5rem; max-height: 5.2rem; overflow-y: auto; }
  .topbar h3 { font-size: 1rem; }
  .stepper .step { font-size: .58rem; padding: .08rem .25rem; }
  .econ-pill { font-size: .62rem; padding: 0 .35rem; white-space: nowrap; }
  .topbar { min-width: 0; }
  .topbar .econ { flex-wrap: nowrap; overflow-x: auto; width: 100%; min-width: 0; padding-bottom: 2px; }
  .game-body { min-width: 0; } .board-wrap, .side { min-width: 0; }
  .topbar { max-height: none; overflow: visible; }
  .game-body { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .side { border-left: 0; border-top: 2px solid var(--line); max-height: 52dvh; padding: .6rem; }
  .game[data-mtab="board"] .side { display: none; }
  .game[data-mtab="actions"] .sec-log, .game[data-mtab="actions"] .sec-chat,
  .game[data-mtab="chat"] .sec-actions, .game[data-mtab="chat"] .sec-log,
  .game[data-mtab="log"] .sec-actions, .game[data-mtab="log"] .sec-chat { display: none; }
  .game[data-mtab="log"] .log { max-height: none; }
  .sec-actions .sidepanel { order: -1; }
  .sec-actions .game-info { border-bottom: 0; border-top: 1px solid var(--line); padding-top: .6rem; }
  .mtabs { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 2px solid var(--line); background: var(--paper); }
  .mtab { border-radius: 0; border: 0; border-right: 1px solid var(--line); background: var(--parchment-2); color: var(--ink); padding: .55rem 0; font-size: .9rem; position: relative; }
  .mtab.on { background: var(--ink); color: var(--parchment); }
  .mtab .dot { position: absolute; top: .35rem; right: 18%; width: .6rem; height: .6rem; border-radius: 50%; background: var(--bad); box-shadow: 0 0 0 2px var(--paper); }
  .toasts { left: .6rem; right: .6rem; top: 3.2rem; }
  .toast { max-width: none; }
  .seat-label { width: auto; }
  button, .btn { min-height: 2.2rem; }
  .modal { max-height: 94dvh; }
  .chat { max-height: none; }
}
.seat-cfg > .row { flex-wrap: nowrap; }
.seat-cfg select { flex: 1 1 8rem; min-width: 0; width: auto; }
.seat-label { flex: 0 0 11rem; }
@media (max-width: 800px), (max-height: 500px) and (pointer: coarse) { .seat-cfg > .row { flex-wrap: wrap; } .seat-label { flex-basis: 100%; } }
td { vertical-align: top; } .games-table td:nth-child(2) { white-space: nowrap; }
.loc.flash { animation: locflash 1.6s ease-out; }
@keyframes locflash { 0% { filter: brightness(1.8) drop-shadow(0 0 8px #fff); } 100% { filter: none; } }
@media (max-width: 800px), (max-height: 500px) and (pointer: coarse) { button.small { min-height: 1.9rem; } }
@media (max-width: 800px), (max-height: 500px) and (pointer: coarse) { .games-table th:nth-child(2), .games-table td:nth-child(2), .games-table th:nth-child(5), .games-table td:nth-child(5) { display: none; } .games-table .pill { white-space: normal; } }
.power-picks { display: flex; flex-wrap: wrap; gap: .3rem .8rem; }
.power-pick { display: inline-flex; flex-direction: row; align-items: center; gap: .3rem; }
.power-pick select { width: auto; }
.seat-label { display: flex; align-items: center; flex-wrap: wrap; gap: .2rem; }

/* Pop-up battle board: columns by combat value, attacker above, defender below. */
.bb-back { position: fixed; inset: 0; background: rgba(20, 15, 5, .5); display: grid; place-items: center; z-index: 60; padding: .6rem; }
.bb-modal { background: var(--paper); color: var(--ink); border: 2px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); width: min(760px, 100%); max-height: 94dvh; overflow: auto; padding: .8rem 1rem; display: flex; flex-direction: column; gap: .5rem; }
.bb-scroll { overflow-x: auto; }
.bb-grid { display: grid; grid-template-columns: 5rem repeat(var(--n), minmax(3.6rem, 1fr)); min-width: 25rem; border: 1px solid var(--line); border-radius: 6px; background: var(--parchment-2); }
.bb-colhead { text-align: center; font-family: var(--font-display); background: var(--ink); color: var(--parchment); padding: .1rem 0; border-left: 1px solid var(--parchment-2); }
.bb-corner { font-size: .75rem; padding: .1rem .3rem; background: var(--ink); color: var(--parchment); }
.bb-side { display: flex; flex-direction: column; gap: .2rem; padding: .4rem; border-top: 1px solid var(--line); justify-content: center; }
.bb-col { display: flex; flex-direction: column; align-items: center; gap: .25rem; padding: .35rem .15rem; border-top: 1px solid var(--line); border-left: 1px dotted var(--line); min-height: 3.2rem; }
.bb-cell { display: flex; flex-direction: column; align-items: center; gap: .1rem; font-size: .85rem; position: relative; padding: .1rem .25rem; border-radius: 6px; }
.bb-cell.dead { opacity: .4; text-decoration: line-through; }
.bb-cell.marked .bb-count { text-decoration: line-through; }
.bb-lost { font-size: .7rem; color: var(--bad); }
.bb-cell.pickable { cursor: pointer; outline: 1px dashed var(--accent); }
.bb-cell.pickable:hover { background: rgba(138, 47, 39, .12); }
.bb-pick { position: absolute; top: -.3rem; right: -.3rem; background: var(--bad); color: #fff; border-radius: 999px; font-size: .72rem; padding: 0 .3rem; font-weight: 700; }
.bb-band { grid-column: 1 / -1; border-top: 2px solid var(--line); background: var(--parchment); padding: .4rem .5rem; }
.bb-step { display: flex; flex-wrap: wrap; gap: .2rem .6rem; align-items: baseline; }
.bb-hits { margin-left: auto; font-size: .8rem; color: var(--accent); font-weight: 600; }
.bb-dicegrid { display: grid; grid-template-columns: 5rem repeat(var(--n), minmax(3.6rem, 1fr)); margin-top: .3rem; }
.bb-dicelabel { grid-column: 1 / -1; font-size: .8rem; margin-top: .25rem; }
.bb-dicegrid .bb-side, .bb-dicegrid .bb-col { border-top: 0; padding: .15rem; min-height: 0; }
.bb-dicecol { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 3px; align-items: flex-start; }
.bb-dicecol .dieface { width: 24px; height: 24px; padding: 3px; }
.bb-mini { position: fixed; left: 50%; bottom: 3.6rem; transform: translateX(-50%); z-index: 60; display: flex; align-items: center; gap: .6rem; background: var(--paper); color: var(--ink); border: 2px solid var(--accent); border-radius: 999px; box-shadow: var(--shadow); padding: .3rem .4rem .3rem .9rem; font-size: .88rem; }
.bb-mini .dot { width: .6rem; height: .6rem; border-radius: 50%; background: var(--bad); }
@media (min-width: 801px) and (min-height: 501px) { .bb-mini { bottom: 1rem; } }
@media (max-width: 800px), (max-height: 500px) and (pointer: coarse) {
  .bb-modal { padding: .6rem .7rem; }
  .bb-grid, .bb-dicegrid { grid-template-columns: 4.2rem repeat(var(--n), minmax(2.9rem, 1fr)); }
  .bb-grid { min-width: 21rem; }
  .bb-side { padding: .3rem .25rem; }
  .bb-hits { margin-left: 0; flex-basis: 100%; }
  .bb-dicecol .dieface { width: 20px; height: 20px; padding: 2px; }
  .bb-dicecol .dieface i { width: 4px; height: 4px; }
}
.bb-mini span { white-space: nowrap; }
/* ---- Dragging unit stacks ---- */
.drag-handle { display: inline-block; }
.drag-handle.on { pointer-events: auto; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.drag-handle.on:hover .unit-badge, .cbadge:hover { box-shadow: 0 0 0 2px var(--accent); }
.board-wrap.unit-drag, .board-wrap.unit-drag .loc { cursor: grabbing; }
.drag-ghost { opacity: .9; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .6)); }
.board-wrap.unit-drag .loc.hl-move, .board-wrap.unit-drag .loc.hl-attack { animation: dragpulse .9s ease-in-out infinite alternate; }
@keyframes dragpulse { from { stroke-opacity: .55; } to { stroke-opacity: 1; } }
.count-picker { position: fixed; z-index: 50; transform: translateX(-50%); width: 250px; padding: .6rem .7rem; display: flex; flex-direction: column; gap: .45rem; background: var(--paper); color: var(--ink); border: 2px solid var(--line); border-radius: 8px; box-shadow: 0 6px 18px rgba(0, 0, 0, .45); }
.count-picker .cp-title { font-weight: 700; font-size: .9rem; }
.count-picker .cp-row { display: flex; gap: .35rem; align-items: center; }
.count-picker .cp-row input[type=range] { flex: 1; min-width: 0; }
.count-picker .cp-row button { flex: 1; }
.count-picker .cp-row button.step { flex: 0 0 auto; }
.moved-section { gap: .2rem; }
.moved-dest { padding: .2rem 0; }
.moved-dest .urow { padding-left: .4rem; }
button.undo-unit { padding: 0 .4rem; }

rect.seam-cover.loc { stroke: none !important; pointer-events: none; filter: none !important; }

/* ================= Phone pass =================
   Everything below the "Phone pass" marker is either size-independent hardening or lives inside
   the phone media query; desktop (> 800px wide, or a mouse-driven short window) is unchanged. */
:root { --nav-h: 52px; }
body {
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
.hero h1 { font-size: clamp(2rem, 11vw, 4rem); overflow-wrap: anywhere; }
.grid2 { grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }
.card, .msg, .modal, td, th { overflow-wrap: break-word; }
.card, .grid2 > *, .page > *, .col > * { min-width: 0; }
input, select, textarea { max-width: 100%; }
.count-picker { width: min(250px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); overflow: auto; }
.nav-toggle, .m-only { display: none; }
.nav-links { display: contents; }
.topbar-toggle, .phase-now { display: none; }

@media (max-width: 800px), (max-height: 500px) and (pointer: coarse) {
  /* --- nav: brand + menu button + user chip; the links drop down --- */
  .nav { flex-wrap: nowrap; gap: .4rem; height: var(--nav-h); padding: 0 .6rem; }
  .brand { font-size: 1.3rem; min-height: 44px; }
  .brand .logo { width: 30px; height: 30px; }
  .nav a { display: inline-flex; align-items: center; min-height: 44px; }
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; padding: 0 .8rem; }
  .nav-links {
    display: none; position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; gap: 0;
    padding: .2rem .8rem .6rem; background: var(--ink); border-top: 1px solid var(--line);
    box-shadow: var(--shadow); max-height: calc(100dvh - var(--nav-h)); overflow-y: auto;
  }
  .nav-links.open { display: flex; }
  .nav-links a, .nav-links button { font-size: 1.05rem; justify-content: flex-start; }
  .nav-links button.m-only { align-self: flex-start; margin-top: .3rem; }
  .m-only { display: inline-flex; }
  .d-only { display: none !important; }
  .nav .user { min-width: 0; }
  .nav .user a { max-width: 8.5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .banner { font-size: .9rem; }

  /* --- type, forms, tap targets --- */
  body { font-size: 16px; }
  input, select, textarea { font-size: 16px; min-height: 44px; }
  input[type="checkbox"], input[type="radio"] { width: 1.5rem; height: 1.5rem; min-height: 0; flex: none; }
  input[type="range"] { min-height: 44px; }
  .check, .power-pick { min-height: 44px; }
  button, .btn, button.small, .btn.small, button.undo-unit { min-height: 44px; }
  button.small, .btn.small { min-width: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .tab, .loglevel .tab, .big-tabs .tab { min-height: 44px; display: inline-flex; align-items: center; }
  td a, .games-table a, .pager a { display: inline-flex; align-items: center; min-height: 44px; }
  .small-text, .hint, .log, .msg, .msg.system, .warn, .pending-note, .income-note, .sandbox-note,
  .preview, .urow, .brow, .invite, .seat, .error, .count-picker .cp-title { font-size: .9rem; }
  .pill, .tag, .econ-pill { font-size: .75rem; }
  .page { padding: .6rem max(.6rem, env(safe-area-inset-left)) .6rem max(.6rem, env(safe-area-inset-right)); }
  .card { padding: .8rem; }

  /* --- game screen --- */
  .game { grid-template-rows: auto minmax(0, 1fr) auto; }
  .topbar { flex-wrap: wrap; align-items: center; gap: .1rem .5rem; padding: .15rem .5rem; position: relative; }
  .topbar h3 { font-size: 1.05rem; white-space: nowrap; }
  .phase-now { display: block; flex: 1 1 0; min-width: 0; font-family: var(--font-display); letter-spacing: .05em; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .deadline .dl-text { display: none; }
  .topbar-toggle { display: inline-flex; margin-left: auto; font-size: 1rem; }
  .topbar .stepper, .topbar .econ { display: none; }
  .topbar.open .stepper { display: flex; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .topbar.open .econ { display: flex; flex: 1 0 100%; padding-bottom: 4px; }
  .topbar .stepper .step { font-size: .75rem; padding: .25rem .5rem; flex: 0 0 auto; white-space: nowrap; }
  .topbar .econ .econ-pill { font-size: .75rem; padding: .1rem .5rem; flex: 0 0 auto; }
  .mtabs { padding-bottom: env(safe-area-inset-bottom); background: var(--parchment-2); }
  .mtab { min-height: 48px; font-size: 1rem; }
  .board-ctl { left: max(.6rem, env(safe-area-inset-left)); right: .6rem; bottom: .6rem; flex-wrap: wrap-reverse; align-items: flex-end; pointer-events: none; }
  .board-ctl > * { pointer-events: auto; }
  .board-ctl button { min-width: 44px; }
  .pill.tip { font-size: .8rem; max-width: 100%; }
  .side { padding-bottom: max(.6rem, env(safe-area-inset-bottom)); max-height: 60dvh; overscroll-behavior: contain; }
  .sec-log .log, .actionlog .log { font-size: .875rem; }

  /* --- toasts, dialogs --- */
  .toasts { top: calc(var(--nav-h) + .5rem); left: max(.6rem, env(safe-area-inset-left)); right: max(.6rem, env(safe-area-inset-right)); }
  .modal-back, .bb-back { padding: max(.6rem, env(safe-area-inset-top)) max(.6rem, env(safe-area-inset-right)) max(.6rem, env(safe-area-inset-bottom)) max(.6rem, env(safe-area-inset-left)); }
  .modal { max-height: 100%; }
  .bb-modal { max-height: 100%; }
  .bb-mini { bottom: calc(56px + env(safe-area-inset-bottom) + .5rem); max-width: calc(100vw - 1.2rem); }
  a:has(> .btn), a:has(> strong) { display: inline-flex; align-items: center; min-height: 44px; }
  .bb-cell.pickable { min-width: 44px; min-height: 44px; justify-content: center; }
  .bb-pick { font-size: .75rem; }
  .bb-side .power-badge { font-size: .75rem; padding-right: .35rem; max-width: 100%; }
  .bb-corner, .bb-hits, .bb-dicelabel { font-size: .8125rem; }
  .loglevel .tab { font-size: .8125rem; }
  .count-picker .cp-row { gap: .45rem; }
  .count-picker .cp-row button { min-width: 44px; }
}

/* Phone held sideways: the tab bar becomes a rail at the right edge so the map keeps the height. */
@media (max-height: 500px) and (pointer: coarse) {
  :root { --nav-h: 48px; }
  .game { grid-template-columns: minmax(0, 1fr) 4.6rem; grid-template-rows: auto minmax(0, 1fr); }
  .topbar { grid-column: 1; }
  .game-body { grid-column: 1; grid-row: 2; }
  .mtabs { grid-column: 2; grid-row: 1 / 3; grid-template-columns: 1fr; grid-template-rows: repeat(4, 1fr); border-top: 0; border-left: 2px solid var(--line); padding-bottom: 0; padding-right: env(safe-area-inset-right); }
  .mtab { border-right: 0; border-bottom: 1px solid var(--line); }
  .side { max-height: 65dvh; }
  .modal, .bb-modal { max-height: 100%; }
}

/* WebKit (iOS Safari) paints HTML inside an SVG foreignObject at the wrong place -- every unit
   stack piles up in the top-left corner of the board -- when a descendant is `position: relative`.
   Keep the counters free of positioned elements; the cargo chip is nudged with margins instead. */
foreignObject .cbadge, foreignObject .unit-icon { position: static; }
foreignObject .cbadge .cargo { position: static; align-self: flex-start; margin: -8px -4px 0 -8px; }
