:root {
  --bg: #070b16;
  --surface: #0d1424;
  --surface-2: #131c31;
  --line: #24304a;
  --grid: #1c2740;
  --text: #e6ebf5;
  --text-2: #b4bdd0;
  --muted: #8592ab;
  --accent: #f2c14e;
  --danger: #ff5a5a;
  --hex-planet: #11203d;
  --hex-empty: #0c172c;
  --hex-stroke: #2b3b5e;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at 30% 20%, #101a33 0%, var(--bg) 60%) fixed;
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font: 700 20px "Saira Semi Condensed", system-ui, sans-serif; margin: 0; letter-spacing: .08em; text-transform: uppercase; }
h2 { font-family: "Saira Semi Condensed", system-ui, sans-serif; font-size: 14px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); }
code { background: var(--surface-2); padding: 0 4px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: rgba(7, 11, 22, .85);
  position: sticky; top: 0; z-index: 5;
}
.game-title { color: var(--text-2); margin-left: auto; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 12px; font: inherit; cursor: pointer; min-height: 32px;
}
.btn:hover:not(:disabled) { border-color: #3d5280; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: #2c3f6b; border-color: #4a6299; }
.btn.icon { min-width: 40px; padding: 6px 8px; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: 12px; padding: 0; }
.field { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
select, input[type=text] {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 8px; font: inherit; min-height: 32px;
}
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }

.empty { padding: 60px 16px; text-align: center; color: var(--text-2); }

/* Layout */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 380px; grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "map side" "time time"; height: calc(100vh - 54px);
}
.map-wrap { grid-area: map; position: relative; min-height: 0; overflow: hidden; }
.map-wrap svg { width: 100%; height: 100%; display: block; }
.side { grid-area: side; overflow-y: auto; padding: 12px; border-left: 1px solid var(--line); background: rgba(13, 20, 36, .6); }
.timeline { grid-area: time; padding: 8px 16px 10px; border-top: 1px solid var(--line); background: rgba(7, 11, 22, .9); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 60vh auto auto; grid-template-areas: "map" "time" "side"; height: auto; }
  .side { border-left: 0; }
  .editor { grid-template-columns: 1fr !important; }
}

/* Scoreboard */
.scoreboard { list-style: none; margin: 0; padding: 0; }
.scoreboard li { display: grid; grid-template-columns: 14px 1fr auto; gap: 4px 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--grid); }
.scoreboard li:last-child { border-bottom: 0; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: none; }
.p-name { font-weight: 600; }
.p-faction { color: var(--muted); font-size: 12px; }
.p-vp { font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; text-align: right; }
.vp-bar { grid-column: 2 / 4; display: flex; gap: 2px; }
.vp-bar span { flex: 1; height: 5px; border-radius: 2px; background: var(--grid); }
.badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }
.badge { font-size: 10px; letter-spacing: .04em; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--line); color: var(--text-2); }
.badge.speaker { border-color: var(--accent); color: var(--accent); }
.badge.win { border-color: var(--accent); background: var(--accent); color: #1a1300; font-weight: 700; }

/* Step lines */
.lines { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; font-size: 12.5px; }
.lines li { padding: 3px 0 3px 8px; border-left: 2px solid var(--grid); margin-bottom: 2px; color: var(--text-2); }
.lines li.vp { border-left-color: var(--accent); color: var(--text); }
.lines li.combat { border-left-color: var(--danger); }
.pdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: 0; }

/* Chart */
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 10px; }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; }
.chart .now { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .cross { stroke: var(--text-2); stroke-width: 1; }
.score-log { max-height: 240px; overflow-y: auto; margin-top: 8px; }
.score-log table { width: 100%; border-collapse: collapse; font-size: 12px; }
.score-log th, .score-log td { text-align: left; padding: 3px 4px; border-bottom: 1px solid var(--grid); }
.score-log th { color: var(--muted); font-weight: 600; }
.score-log tr { cursor: pointer; }
.score-log tr:hover td { background: var(--surface-2); }

.tooltip {
  position: absolute; pointer-events: none; background: #0a1020; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; min-width: 160px; max-width: 280px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5); z-index: 10;
}
.tooltip h3 { margin: 0 0 4px; font-size: 12px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tooltip .tt-row span:last-child { font-variant-numeric: tabular-nums; }

/* Timeline */
.controls { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
#slider { width: 100%; accent-color: var(--accent); }
.round-marks { position: relative; height: 16px; font-size: 11px; color: var(--muted); }
.round-marks button { position: absolute; transform: translateX(-50%); background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; font-size: 11px; padding: 0 2px; }
.round-marks button:hover { color: var(--text); }

/* Map SVG */
.map-wrap { background: #03060f; }
#map { cursor: grab; touch-action: none; }
#map.panning { cursor: grabbing; }
.zoom-ctrls { position: absolute; right: 12px; top: 12px; display: flex; flex-direction: column; gap: 6px; z-index: 4; }
.zoom-ctrls .btn { background: rgba(19, 28, 49, .85); font-size: 18px; line-height: 1; }
.map-font, .planet-name, .tile-caption, .coord-label, .ship-count, .ground, .worm { font-family: "Saira Semi Condensed", "Arial Narrow", system-ui, sans-serif; }
.hex.unknown { fill: none; stroke-dasharray: 4 4; stroke: #33415f; stroke-width: 1.5; }
.hex.active { stroke: var(--accent); stroke-width: 3.5; filter: drop-shadow(0 0 4px rgba(242, 193, 78, .8)); }
.hex.combat { stroke: var(--danger); stroke-width: 5; animation: pulse .9s ease-in-out 3; }
.hex.selected { stroke: var(--accent); stroke-width: 3; }
.hexhit { fill: transparent; cursor: pointer; outline: none; }
.hexhit:focus-visible { stroke: var(--accent); stroke-width: 2; }
#map .hexhit { cursor: inherit; }
@keyframes pulse { 50% { stroke-opacity: .25; } }
.tile-edge { fill: none; stroke: #8fb0e6; stroke-opacity: .5; stroke-width: 1.5; }
.tile-inner { fill: none; stroke: #ffffff; stroke-opacity: .06; stroke-width: 1; }
.planet-name {
  fill: #f1f5ff; font-size: 11px; font-weight: 700; text-anchor: middle; letter-spacing: .01em;
  paint-order: stroke; stroke: #03060f; stroke-width: 3.2px; stroke-linejoin: round;
}
.planet-name.small { font-size: 9.5px; }
.tile-caption {
  fill: #b7c3dd; font-size: 8px; font-weight: 600; text-anchor: middle; text-transform: uppercase; letter-spacing: .12em;
  paint-order: stroke; stroke: #03060f; stroke-width: 2.5px; opacity: .85;
}
.tile-caption.home { opacity: 1; font-weight: 700; letter-spacing: .06em; text-transform: none; font-size: 9px; }
.coord-label { fill: #8592ab; font-size: 9px; text-anchor: middle; }
.ground { font-size: 9px; font-weight: 700; text-anchor: middle; }
.worm { font-weight: 700; text-anchor: middle; dominant-baseline: middle; }
.unit-body { stroke: rgba(255, 255, 255, .8); stroke-width: .8; stroke-linejoin: round; }
.unit-detail { fill: none; stroke: rgba(0, 0, 0, .5); stroke-width: .9; stroke-linecap: round; }
.fleet-pill { fill: #03060f; fill-opacity: .72; stroke-width: 1; stroke-opacity: .7; }
.ship-count {
  fill: #fff; font-size: 10px; font-weight: 700;
  paint-order: stroke; stroke: #03060f; stroke-width: 2.5px; stroke-linejoin: round;
}
.move-under { fill: none; stroke: #000; stroke-width: 7; stroke-linecap: round; opacity: .45; }
.move-path { fill: none; stroke-width: 3.5; stroke-linecap: round; opacity: .95; stroke-dasharray: 7 5; animation: dash .8s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -24; } }

/* Editor */
.editor { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: calc(100vh - 54px); }
.editor .side { grid-area: auto; border-left: 0; border-right: 1px solid var(--line); }
.editor .map-wrap { grid-area: auto; }
#editMap .hexhit { cursor: pointer; }
.system-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.system-list button { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font: inherit; font-size: 12px; cursor: pointer; }
.system-list button.sel { border-color: var(--accent); color: var(--accent); }
.system-list .home { font-size: 10px; color: var(--muted); }
.color-list { list-style: none; margin: 0 0 8px; padding: 0; }
.color-list li { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.color-list input[type=color] { width: 32px; height: 24px; border: 0; background: none; padding: 0; }
