:root {
  --ussr: #b8322a;
  --ussr-soft: #f6dcda;
  --us: #245fa8;
  --us-soft: #dbe6f5;
  --ink: #23201c;
  --muted: #6e675d;
  --paper: #f4f1ea;
  --panel: #fffdf8;
  --line: #d9d2c4;
  --accent: #e0a100;
  --good: #2e7d4f;
  --bad: #b8322a;
  --font: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --narrow: "Arial Narrow", "Helvetica Neue Condensed", "Roboto Condensed", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 13px;
  color: var(--ink);
  background: var(--paper);
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  overflow: hidden;
}
button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 4px;
  padding: 3px 8px;
  color: var(--ink);
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
button.loses { color: var(--bad); border-color: var(--bad); border-style: dashed; }

/* -- top bar ----------------------------------------------------------------- */

#top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
#top .title { font-weight: 700; letter-spacing: 0.02em; }
#top .group { display: flex; align-items: center; gap: 6px; }
#top .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
#top .spacer { flex: 1; }
.defcon { display: flex; gap: 2px; }
.defcon span {
  width: 20px; height: 20px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 3px; color: var(--muted); font-weight: 700;
}
.defcon span.on { color: #fff; border-color: transparent; }
.vpbar { position: relative; width: 160px; height: 14px; border-radius: 7px; overflow: hidden;
  background: linear-gradient(90deg, var(--ussr-soft) 50%, var(--us-soft) 50%); border: 1px solid var(--line); }
.vpbar .mark { position: absolute; top: -1px; width: 4px; height: 14px; background: var(--ink); margin-left: -2px; }
.side-USSR { color: var(--ussr); }
.side-US { color: var(--us); }
.you { font-size: 10px; border-radius: 3px; padding: 0 3px; margin-left: 2px; background: var(--ink); color: #fff; }

/* -- main layout ------------------------------------------------------------------ */

main { display: grid; grid-template-columns: 1fr 460px; min-height: 0; }
#left { display: grid; grid-template-rows: 1fr auto; min-width: 0; min-height: 0; }
#board-wrap { position: relative; overflow: auto; min-width: 0; min-height: 0; padding: 4px; }
#board { width: 100%; height: auto; display: block; user-select: none; }
#zoom { position: sticky; top: 0; left: 0; z-index: 5; display: inline-flex; gap: 2px; float: left; margin-bottom: -28px; }
#zoom button { padding: 1px 7px; background: rgba(255, 253, 248, 0.9); }
/* The side panel: the tabs, then the log below them, always on screen. The
   log's height is dragged with the splitter and kept in --log-height. */
#side {
  display: grid; min-height: 0; border-left: 1px solid var(--line); background: var(--panel);
  grid-template-areas: "tabs" "panel" "split" "log";
  grid-template-rows: auto minmax(0, 1fr) 7px var(--log-height, 38%);
}
#tabs { grid-area: tabs; display: flex; border-bottom: 1px solid var(--line); }
#tabs[hidden] { display: none; }
#tabs button { flex: 1; border: none; border-radius: 0; padding: 8px; background: transparent; color: var(--muted); }
#tabs button.on { color: var(--ink); font-weight: 700; box-shadow: inset 0 -2px 0 var(--ink); }
#panel { grid-area: panel; overflow: auto; padding: 10px 12px 16px; min-height: 0; }
#splitter { grid-area: split; cursor: row-resize; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #f1ecdf; touch-action: none; }
#splitter:hover { background: #e3dac6; }
#log-wrap { grid-area: log; display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; }
#log-wrap .log-title { padding: 5px 12px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); border-bottom: 1px solid var(--line); }
#log { overflow: auto; padding: 0 12px 12px; min-height: 0; }
@media (max-width: 1100px) {
  body { overflow: auto; height: auto; }
  main { grid-template-columns: 1fr; }
  #side { border-left: none; border-top: 1px solid var(--line); grid-template-rows: auto auto 0 auto; }
  #panel { max-height: none; }
  #splitter { display: none; }
  #log { max-height: 60vh; }
}

/* -- board ------------------------------------------------------------------------- */

#board .edge { fill: none; }
#board .edge.regional { stroke: #7a6a55; stroke-width: 2.4; }
#board .edge.inter { stroke: #c0392b; stroke-width: 2.6; stroke-dasharray: 5 4; }
#board .edge.superpower { stroke: #2a2622; stroke-width: 4.5; }
#board .country { cursor: default; }
#board .country .body { stroke: #8f8676; stroke-width: 1; }
#board .country .name { font-family: var(--narrow); font-size: 12.5px; font-weight: 700; }
#board .country .stab { font-size: 12px; font-weight: 700; }
#board .country .inf { font-size: 19px; font-weight: 800; text-anchor: middle; }
#board .country .outline { fill: none; stroke: none; }
#board .civilwar .cwnote { font-family: var(--narrow); font-size: 12px; fill: #2a2622; }
#board .civilwar.won { opacity: 0.55; }
#board .country.changed .outline { stroke: #ff7a00; stroke-width: 3; stroke-dasharray: 6 3; }
#board .country.target { cursor: pointer; }
#board .country.target .outline { stroke: var(--accent); stroke-width: 5; }
#board .country.target:hover .outline { stroke: #ff5a00; }
#board .country.preview .outline { stroke: #149174; stroke-width: 5; stroke-dasharray: none; }
#board .chip { font-size: 15px; font-weight: 800; }
#board .regionlabel rect { fill: #fffbe9; stroke: #b3a785; }
#board .regionlabel .rname { font-size: 18px; font-weight: 800; }
#board .regionlabel text { font-size: 14px; }
#board .regionlabel .thresholds { font-size: 12.5px; fill: #5d5548; }
#board .regionlabel .colhead { font-size: 11px; fill: #5d5548; font-weight: 600; }
#board .regionlabel .side .who { font-weight: 800; }
#board .regionlabel .side .count { font-weight: 800; }
#board .regionlabel .scoreband { stroke: none; fill-opacity: 0.12; }
#board .regionlabel .scoredlabel { font-size: 12.5px; fill: #5d5548; }
#board .scored, #board .regionlabel .scored { font-size: 21px; font-weight: 900; font-style: normal; }
#board .sublabel { font-size: 12px; font-style: italic; fill: #5d5548; }
#board .superpower text { fill: #fff; font-size: 26px; font-weight: 900; letter-spacing: 0.08em; text-anchor: middle; }
#board .spacetitle { font-size: 18px; font-weight: 800; fill: #2a2622; }
#board .spacetitle .spacenote { font-size: 12.5px; font-weight: 400; fill: #5d5548; }
#board .spacebox .sbody { fill: #e7eef4; stroke: #8b9bab; }
#board .spacebox.ability .sbody { fill: #f3ead0; stroke: #b3a785; }
#board .spacebox .snum { font-size: 14px; font-weight: 900; fill: #8b9bab; }
#board .spacebox .sname { font-family: var(--narrow); font-size: 12px; font-weight: 700; fill: #2a2622; }
#board .spacebox .sreq { font-size: 11px; fill: #5d5548; }
#board .spacebox .svp { font-size: 12.5px; font-weight: 800; fill: #2a2622; }
#board .spacebox .svp .claimed { fill: #aaa195; text-decoration: line-through; }
#board .spacebox .seffect { font-family: var(--narrow); font-size: 11.5px; font-style: italic; fill: #5d5548; }
#board .spacebox .stoken { font-size: 12px; font-weight: 800; fill: #fff; text-anchor: middle; }
#board .stub { font-size: 12px; fill: #2a2622; font-style: italic; }

/* -- hand ---------------------------------------------------------------------------- */

#hand-wrap {
  display: flex; align-items: stretch; gap: 14px;
  padding: 8px 12px; border-top: 1px solid var(--line); background: var(--panel);
  overflow-x: auto; min-height: 104px;
}
#hand-wrap:empty { display: none; }
#hand-wrap .info { min-width: 150px; display: flex; flex-direction: column; gap: 4px; justify-content: center; color: var(--muted); }
.hand { display: flex; gap: 6px; align-items: stretch; }
.card {
  position: relative; width: 112px; min-height: 84px; padding: 18px 6px 6px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff;
  font-size: 12px; line-height: 1.2; font-weight: 600;
}
.card .stripe { position: absolute; left: 0; right: 0; top: 0; height: 12px; border-radius: 5px 5px 0 0; }
.card.USSR .stripe { background: var(--ussr); }
.card.US .stripe { background: var(--us); }
.card.both .stripe { background: #8a8173; }
.card.scoring .stripe { background: #222; }
.card .ops { position: absolute; top: 15px; right: 5px; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; border: 1.5px solid var(--ink); background: #fff; }
.card .name { padding-right: 22px; }
.card .tags { margin-top: 4px; font-size: 10.5px; font-weight: 400; color: var(--muted); }
.card.playable { cursor: pointer; box-shadow: 0 0 0 2px var(--accent); }
.card.playable:hover { box-shadow: 0 0 0 3px #ff5a00; }
.card.picked { box-shadow: 0 0 0 3px #ff5a00; transform: translateY(-3px); }
.card.facedown { opacity: 0.55; }
.card[draggable="true"] { cursor: grab; }
.card.playable[draggable="true"] { cursor: pointer; }
/* A dragged card leaves the row, and a gap opens where it would land. */
.slot.dragging { display: none; }
.slot-gap { flex: none; width: 112px; border: 2px dashed var(--accent); border-radius: 6px;
  background: rgba(0, 0, 0, 0.03); }
.card.tag-target { outline: 2px dashed #5b3fa0; outline-offset: 2px; }
.card .badges { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 5px; }
.slot { display: flex; flex-direction: column; gap: 3px; }
.slot > .card { flex: 1; }
.slot-label { font-size: 10.5px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  text-align: center; color: var(--muted); }
/* Held cards sit on a hatched shelf, set off from the plays by a dashed rule. */
.slot.held { padding: 0 3px 3px; border-radius: 6px;
  background: repeating-linear-gradient(135deg, transparent 0 6px, rgba(35, 32, 28, 0.06) 6px 12px); }
.slot.held .slot-label { font-style: italic; }
.slot.first-held { margin-left: 6px; position: relative; }
.slot.first-held::before { content: ""; position: absolute; left: -7px; top: 0; bottom: 0;
  border-left: 2px dashed var(--line); }
.hand-col { display: flex; flex-direction: column; gap: 6px; }
.tray { display: flex; align-items: center; gap: 6px; min-height: 22px; padding: 2px 4px;
  border: 1px dashed transparent; border-radius: 6px; font-size: 11.5px; color: var(--muted); }
.tray.over { border-color: #5b3fa0; background: #efe9f8; }
.htag { display: inline-block; padding: 1px 6px; border-radius: 9px; font-size: 10.5px; font-weight: 700;
  line-height: 15px; white-space: nowrap; }
.htag.space { background: #5b3fa0; color: #fff; cursor: grab; }
.card.short .htag.space { background: #fff; color: var(--bad); border: 1px solid var(--bad); }
.card.short .htag.space::after { content: " (short)"; font-weight: 400; }
.htag.held { background: #e8e3d8; color: var(--muted); border: 1px solid var(--line); }
.htag.held.bad { background: var(--ussr-soft); color: var(--bad); border-color: var(--bad); }

/* -- side panel --------------------------------------------------------------------------- */

h3 { margin: 16px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
h3:first-child { margin-top: 2px; }
.prompt { font-size: 15px; font-weight: 700; margin: 2px 0 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 5px; }
.actions button { text-align: left; }
.cardrow { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: center; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.cardrow .modes { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.controls { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.banner { padding: 10px; border-radius: 6px; font-weight: 700; margin-bottom: 10px; }
.banner.win { background: #e3f3e8; color: var(--good); }
.banner.loss { background: #f8e1df; color: var(--bad); }
.banner.notice { background: #fff3cd; color: #6b5200; font-weight: 400; }
.waiting { color: var(--muted); font-style: italic; }
.hold { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-top: 4px; }
.hold-count { color: var(--muted); }
.hold-count b { color: var(--ink); font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-block; padding: 1px 6px; border-radius: 10px; background: #efe9dc; font-size: 11.5px; white-space: nowrap; }
.chip.USSR { background: var(--ussr-soft); color: var(--ussr); }
.chip.US { background: var(--us-soft); color: var(--us); }
.ref { border-bottom: 1px dotted currentColor; cursor: help; }
.ref.card-USSR { color: var(--ussr); }
.ref.card-US { color: var(--us); }
.ref.country { color: inherit; }
.hint-box { margin-top: 12px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: #fbf8ef; }

/* log */
.log .turn { margin: 12px 0 4px; font-weight: 800; }
.log .entry { display: grid; grid-template-columns: 10px 1fr; gap: 6px; padding: 2px 0; }
.log .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 4px; background: #aaa; }
.log .dot.w0 { background: var(--ussr); }
.log .dot.w1 { background: var(--us); }
.log .dot.w-3 { background: var(--ink); }
.log .entry.chance { color: var(--muted); }
.log .entry .deltas { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 2px; }
.log a, .linkish { color: inherit; text-decoration: underline; cursor: pointer; }

/* explorer */
.moves .round { margin: 8px 0 2px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.moves .move { display: grid; grid-template-columns: 1fr auto; gap: 6px; padding: 3px 4px; border-radius: 4px; cursor: pointer; }
.moves .move:hover { background: #f1ecdf; }
.moves .move.replay { padding-left: 18px; color: var(--muted); }
.moves .move.forced { color: var(--muted); }
.moves .ms { color: var(--muted); font-variant-numeric: tabular-nums; }
.explain .head { padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.explain .chosen { font-size: 14px; font-weight: 700; margin-top: 4px; }
.explain .meta { color: var(--muted); margin-top: 2px; }
.explain .note { color: var(--muted); font-size: 12px; line-height: 1.4; }
.explain table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.explain th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11px; padding: 3px 4px; border-bottom: 1px solid var(--line); }
.explain td { padding: 3px 4px; border-bottom: 1px solid #eee8dc; vertical-align: top; }
.explain td.num, .explain th.num { text-align: right; white-space: nowrap; }
.explain tr.cand { cursor: pointer; }
.explain tr.cand:hover td { background: #f6f1e4; }
.explain tr.cand.chosen td { background: #fff4cf; font-weight: 700; }
.explain tr.cand.open td { background: #efe8d6; }
.explain tr.detail > td { background: #fbf9f3; padding: 8px; }
.badge { display: inline-block; font-size: 10px; padding: 0 4px; border-radius: 3px; background: #e7e0cf; color: var(--muted); margin-left: 4px; font-weight: 600; }
.badge.chosen { background: var(--ink); color: #fff; }
.badge.danger { background: var(--bad); color: #fff; }
.bars { display: grid; grid-template-columns: 130px 1fr 58px; gap: 3px 6px; align-items: center; }
.bars .track { position: relative; height: 10px; background: #f0ebe0; border-radius: 2px; }
.bars .track .zero { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: #9a917f; }
.bars .bar { position: absolute; top: 0; height: 10px; border-radius: 2px; }
.bars .bar.pos { background: var(--good); }
.bars .bar.neg { background: var(--bad); }
.pos-text { color: var(--good); }
.neg-text { color: var(--bad); }
.worlds .world { margin-bottom: 6px; }
.terms td:first-child { white-space: nowrap; }
.terms .weight { color: var(--muted); font-size: 11.5px; }
.leaves tr:hover td { background: #e9f5f1; }

/* -- overlays ---------------------------------------------------------------------------- */

#tooltip {
  position: fixed; z-index: 50; max-width: 340px; pointer-events: none;
  background: #1f1c18; color: #f6f2ea; padding: 8px 10px; border-radius: 6px;
  font-size: 12px; line-height: 1.4; box-shadow: 0 4px 18px rgba(0,0,0,0.25);
}
#tooltip .tt-title { font-weight: 800; font-size: 13px; margin-bottom: 2px; }
#tooltip .tt-meta { color: #c9c1b2; margin-bottom: 4px; }
#tooltip:has(.tt-card) { padding: 0; max-width: none; background: none; border-radius: 10px; }
#tooltip .tt-card { display: block; border-radius: 10px; width: auto; max-height: calc(100vh - 16px); }
#popover {
  position: fixed; z-index: 40; background: var(--panel); border: 1px solid var(--muted);
  border-radius: 6px; padding: 6px; display: flex; flex-direction: column; gap: 4px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.2);
}
#popover .ptitle { font-weight: 700; padding: 2px 4px 4px; }
#modal {
  position: fixed; inset: 0; z-index: 60; background: rgba(30, 26, 20, 0.45);
  display: grid; place-items: center;
}
#modal[hidden], #busy[hidden], #tooltip[hidden], #popover[hidden], #toast[hidden] { display: none; }
#modal .box { background: var(--panel); border-radius: 8px; padding: 18px 20px; width: min(640px, 94vw); max-height: 86vh; overflow: auto; }
#modal h2 { margin: 0 0 12px; }
#modal .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
#modal input { font: inherit; padding: 3px 6px; width: 110px; }
#modal input.wide { width: min(300px, 70vw); padding: 5px 8px; }
#modal .spacer { flex: 1; }
.invite .row { display: flex; gap: 6px; margin-top: 6px; }
.invite input.link { flex: 1; min-width: 0; font: inherit; font-size: 12px; padding: 3px 6px; }
#modal label input { margin-left: 4px; }
#modal h2 .note { font-size: 13px; font-weight: 400; }
#modal table.lobby td { vertical-align: top; line-height: 1.7; }
#modal table.lobby tr.current td { background: #faf3e0; }
#modal table.lobby .actions-cell { text-align: right; white-space: nowrap; }
#modal details { margin-top: 12px; }
#modal summary { cursor: pointer; font-weight: 700; }
button .count { display: inline-block; min-width: 16px; padding: 0 4px; border-radius: 8px; background: var(--accent); color: var(--ink); font-size: 11px; font-weight: 700; text-align: center; }
.turnpill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 10px; background: #efe9dc; color: var(--muted); }
.turnpill.on { background: var(--accent); color: var(--ink); }
#modal table { width: 100%; border-collapse: collapse; }
#modal td { padding: 4px; border-bottom: 1px solid var(--line); }
#modal .cards { display: flex; flex-wrap: wrap; gap: 6px; }
#busy {
  position: fixed; right: 16px; bottom: 120px; z-index: 55; display: flex; gap: 10px; align-items: center;
  background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px;
}
.spinner { width: 16px; height: 16px; border: 2px solid #fff; border-top-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#toast { position: fixed; top: 54px; left: 50%; transform: translateX(-50%); z-index: 70; background: var(--bad); color: #fff; padding: 8px 14px; border-radius: 6px; max-width: 80vw; }

/* explorer: the search, step by step */
body.wide main { grid-template-columns: 1fr min(920px, 62vw); }
.explain .right { float: right; }
.explain h4 { margin: 12px 0 4px; font-size: 12.5px; }
.explain ol.steps { margin: 4px 0 8px; padding-left: 20px; line-height: 1.45; }
.explain ol.steps li { margin-bottom: 4px; }
.explain .rows > div { padding: 2px 0; }
.explain table.beam td { font-size: 12px; }
.explain table.beam tr.cut td { color: var(--muted); }
.explain table.beam tr.kept td.status { color: var(--good); font-weight: 600; }
.explain table.beam tr.chosen td { background: #fff4cf; }
.explain table.beam tr.brow:hover td, .explain table.flow tr:hover td { background: #e9f5f1; }
.explain td.status { font-size: 11px; white-space: nowrap; }
.tchip { display: inline-block; font-size: 11px; padding: 0 5px; margin: 1px 2px 1px 0; border-radius: 8px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tchip.pos { background: #e3f3e8; color: var(--good); }
.tchip.neg { background: #f8e1df; color: var(--bad); }
