:root {
  --bg: #f7f7f5; --panel: #ffffff; --fg: #1d1d1f; --muted: #6b6b70; --line: #d9d9de;
  --accent: #2456c7; --me: #2f6fdf; --opp0: #d2453b; --opp1: #e08a1e; --opp2: #8b4fc8;
  --opp3: #188a6e; --neutral: #b9b9bf; --fog: #e4e4e8; --hatch: #c4c4cc;
  --good: #1d7a3e; --warn: #9a6200; --bad: #b3261e; --busy: #2456c7; --edge: #c9c9cf;
  --focus: #ffb000;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416; --panel: #1e1e22; --fg: #ececf0; --muted: #a0a0a8; --line: #34343a;
    --accent: #7aa5ff; --me: #4f8cff; --opp0: #ff6b5e; --opp1: #f0a94a; --opp2: #b48cf0;
    --opp3: #3cc49d; --neutral: #5a5a62; --fog: #2a2a30; --hatch: #3e3e46;
    --good: #5fd08a; --warn: #f0b64a; --bad: #ff7a70; --busy: #7aa5ff; --edge: #3a3a42;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--fg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  overflow-x: hidden;
}
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1 { font-size: 1.3rem; margin: 0.4rem 0 0.8rem; }
h2 { font-size: 0.95rem; margin: 0 0 0.4rem; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--bad); }
.note { color: var(--muted); font-size: 0.9em; }

.top {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 1rem;
  border-bottom: 1px solid var(--line); background: var(--panel); min-height: 48px;
}
.brand { font-weight: 700; text-decoration: none; color: var(--fg); padding: 0.5rem 0; }
.crumbs { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.live { width: 10px; height: 10px; border-radius: 50%; background: var(--neutral); flex: none; }
.live.on { background: var(--good); }
button, .btn, select, input {
  font: inherit; min-height: 40px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--fg); padding: 0.35rem 0.8rem;
}
button { cursor: pointer; }
button.link { border: none; background: none; color: var(--accent); padding: 0.35rem 0.4rem; }
.btn { display: inline-flex; align-items: center; text-decoration: none; }
.btn.disabled { opacity: 0.4; pointer-events: none; }

main { padding: 0.8rem 1rem 2rem; max-width: 1400px; margin: 0 auto; }

/* sign-in */
.signin { display: grid; gap: 0.4rem; max-width: 340px; margin: 2rem auto; }
.signin input { width: 100%; }
.signin button { margin-top: 0.6rem; background: var(--accent); color: #fff; border: none; }
.signin #code { letter-spacing: 0.3em; font-size: 1.2rem; }

/* games */
.games { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: 0.5rem; }
.game {
  display: grid; grid-template-columns: 1fr auto; gap: 0.2rem 0.6rem; align-items: center;
  padding: 0.7rem 0.9rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--fg); text-decoration: none; min-height: 56px;
}
.game .who { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.game .meta { grid-column: 1 / -1; color: var(--muted); font-size: 0.85rem; }
.chip { font-size: 0.8rem; padding: 0.15rem 0.55rem; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.chip.good { color: var(--good); } .chip.warn { color: var(--warn); } .chip.bad { color: var(--bad); }
.chip.busy { color: var(--busy); } .chip.info { color: var(--accent); } .chip.idle { color: var(--muted); }
.finished summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; color: var(--muted); }

/* turn */
.turn-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }
.turn-head h1 { margin: 0; flex: 1 1 auto; min-width: 0; }
.stepper { display: flex; align-items: center; gap: 0.4rem; }
.turn-no { min-width: 4.5rem; text-align: center; }
.runs select { max-width: 70vw; }
.turn { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 1rem; margin-top: 0.8rem; }
@media (max-width: 900px) { .turn { grid-template-columns: minmax(0, 1fr); } }
.map-wrap { position: relative; min-width: 0; }
.map {
  height: min(70vh, 640px); border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); overflow: hidden; touch-action: none;
}
@media (max-width: 600px) { .map { height: min(62vh, 110vw); } }
.reset { position: absolute; right: 0.4rem; top: 0.4rem; background: var(--panel); min-height: 36px; }
.side { display: grid; gap: 0.6rem; align-content: start; min-width: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 0.7rem 0.8rem; }
.card ul { margin: 0; padding-left: 1.1rem; }
.income { margin: 0; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.3rem; }
.step {
  width: 100%; text-align: left; display: flex; gap: 0.6rem; align-items: baseline;
  border-color: transparent; background: transparent; padding: 0.45rem 0.4rem;
}
.step[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.step .kind { min-width: 2.2rem; font-weight: 700; color: var(--accent); }
.step .kind.deploy { color: var(--good); }
.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
th, td { text-align: left; padding: 0.25rem 0.4rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }

/* board */
svg.board { width: 100%; height: 100%; display: block; user-select: none; cursor: grab; }
.edges line { stroke: var(--edge); stroke-width: 0.8; }
.terr .body { stroke: var(--panel); stroke-width: 1.2; }
.terr .armies { font-size: 8px; font-weight: 700; text-anchor: middle; fill: #fff; pointer-events: none; }
.terr .armies.small { font-size: 5px; }
.own-me .body { fill: var(--me); }
.own-opp0 .body { fill: var(--opp0); } .own-opp1 .body { fill: var(--opp1); }
.own-opp2 .body { fill: var(--opp2); } .own-opp3 .body { fill: var(--opp3); }
.own-neutral .body { fill: var(--neutral); }
.own-neutral .armies { fill: var(--fg); }
.fog .body { fill: url(#hatch); stroke: var(--hatch); }
.fog .armies { fill: var(--fg); }
.hatch-bg { fill: var(--fog); }
.hatch-line { stroke: var(--hatch); stroke-width: 2; }
.arrow path { fill: none; stroke-width: 2.4; stroke-linecap: round; }
.arrow.attack path { stroke: var(--bad); } .arrow.transfer path { stroke: var(--good); }
.head.attack { fill: var(--bad); } .head.transfer { fill: var(--good); } .head.hl { fill: var(--focus); }
.arrow .num-bg { fill: var(--panel); stroke: currentColor; stroke-width: 1; }
.arrow.attack { color: var(--bad); } .arrow.transfer { color: var(--good); }
.arrow .num { font-size: 8px; font-weight: 700; text-anchor: middle; fill: var(--fg); }
.deploy { font-size: 9px; font-weight: 800; fill: var(--good); paint-order: stroke; stroke: var(--panel); stroke-width: 2.5px; }
.arrow.hl path { stroke-width: 3.6; }
.dim { opacity: 0.2; }
.side > * { min-width: 0; }
.clip { display: inline-block; max-width: 11rem; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
.own-unknown .body { fill: var(--fog); stroke: var(--hatch); }
.own-unknown .armies { fill: var(--fg); }
