:root {
  --bg: #06040f;
  --bg-grad-1: #241452;
  --bg-grad-2: #0d0826;
  --panel: #140f33;
  --panel-2: #1c1547;
  --ink: #2b1a4a;
  --violet: #8b7bff;
  --violet-soft: #c9beff;
  --cyan: #5ce0ff;
  --gold: #ffcf5c;
  --p1: #ff8a3c;      /* warm — player 1 */
  --p1-bright: #ff6b3c;
  --p2: #2f8bff;      /* cool — player 2 */
  --p2-bright: #4aa8ff;
  --danger: #ff5c5c;
  --text: #e9e4ff;
  --muted: #9a8fd0;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Nunito', sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 50% -8%, var(--bg-grad-1) 0%, var(--bg-grad-2) 55%, var(--bg) 100%);
  min-height: 100vh;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; padding: 16px 28px; flex-wrap: wrap;
  border-bottom: 1px solid #ffffff14;
}
.brand-kicker { font: 800 11px 'Nunito'; letter-spacing: 3px; color: var(--cyan); text-transform: uppercase; }
.brand h1 { margin: 2px 0 0; font-family: 'Baloo 2'; font-weight: 800; font-size: 28px; letter-spacing: .5px; }
.setup { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.setup label { font-weight: 700; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
select, input {
  font-family: 'Nunito'; font-weight: 700; color: var(--text);
  background: var(--panel-2); border: 1px solid #ffffff22; border-radius: 10px;
  padding: 7px 10px; font-size: 13px;
}

/* ---------- buttons ---------- */
.btn {
  font-family: 'Baloo 2'; font-weight: 700; font-size: 14px; cursor: pointer;
  color: var(--text); background: var(--panel-2); border: 1px solid #ffffff22;
  border-radius: 12px; padding: 8px 16px; transition: transform .06s, background .15s, box-shadow .15s;
}
.btn:hover { background: #241a5c; box-shadow: 0 4px 16px #0006; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(180deg, var(--violet), #6c5ce0); border-color: #ffffff33; color: #fff; }
.btn-primary:hover { background: linear-gradient(180deg, #9d8fff, #7a68ea); }
.btn-ghost { background: transparent; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px;
  padding: 20px 28px 32px; align-items: start; max-width: 1560px; margin: 0 auto;
}
@media (max-width: 1080px) { .layout { grid-template-columns: 1fr; } }

.board-wrap { position: relative; }
.board-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.chip {
  font: 700 12px 'Nunito'; padding: 6px 12px; border-radius: 999px;
  background: var(--panel); border: 1px solid #ffffff1f; color: var(--muted); letter-spacing: .4px;
}
.chip-turn { color: var(--ink); background: var(--gold); border: none; font-weight: 800; }
.watch-controls { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.watch-controls .speed { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px; font-weight: 700; }
.persp-seg { display: inline-flex; background: #ffffff10; border-radius: 8px; padding: 2px; gap: 2px; }
.persp-seg .seg-btn { font: 700 11px 'Nunito'; color: var(--muted); background: none; border: 0; padding: 4px 9px; border-radius: 6px; cursor: pointer; }
.persp-seg .seg-btn.is-on { background: var(--violet, #8b7bff); color: #fff; }

#board {
  width: 100%; height: auto; aspect-ratio: 1000 / 780;
  background:
    radial-gradient(1200px 500px at 50% -20%, #2a1a5e55, transparent 60%),
    radial-gradient(circle at 20% 80%, #5ce0ff14, transparent 45%),
    #0a0722;
  border: 1px solid #ffffff1a; border-radius: 20px; box-shadow: inset 0 0 80px #0008;
}

/* ---------- board elements ---------- */
.edge { stroke: #6b5ca8; stroke-width: 2.5; stroke-linecap: round; opacity: .38; stroke-dasharray: 2 9; }
.sys-hit { cursor: pointer; }
.sys-label {
  font: 700 13px 'Nunito'; fill: var(--text); text-anchor: middle;
  paint-order: stroke; stroke: #06040f; stroke-width: 4px; pointer-events: none;
}
.sys-sub { font: 700 10px 'JetBrains Mono'; fill: var(--gold); text-anchor: middle; pointer-events: none; }
.sys-warn { font: 800 13px 'Baloo 2', sans-serif; fill: var(--danger); text-anchor: middle; pointer-events: none;
  paint-order: stroke; stroke: #06040f; stroke-width: 4px; }
.node-jumpable { filter: drop-shadow(0 0 10px var(--cyan)); }
.jump-ring { fill: none; stroke: var(--cyan); stroke-width: 3.5; stroke-dasharray: 6 7; opacity: .9; }
.candidate-halo { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .5 } 50% { opacity: .95 } }
@keyframes bob { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-5px) } }
.ship-bob { animation: bob 2.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }

/* ---------- banner ---------- */
.banner {
  position: absolute; inset: auto 0 24px 0; margin: 0 auto; width: max-content; max-width: 90%;
  padding: 14px 26px; border-radius: 16px; font-family: 'Baloo 2'; font-weight: 800; font-size: 20px;
  background: #140f33ee; border: 1px solid #ffffff2a; box-shadow: 0 12px 40px #000a; text-align: center;
}
.banner.win-0 { color: var(--p1); } .banner.win-1 { color: var(--p2-bright); } .banner.draw { color: var(--violet-soft); }

/* ---------- side panels ---------- */
.side { display: flex; flex-direction: column; gap: 16px; }
.panel { background: var(--panel); border: 1px solid #ffffff14; border-radius: 18px; padding: 16px 18px; }
.panel h2 { margin: 0 0 12px; font-family: 'Baloo 2'; font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }

/* HUD */
.ship-card { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 14px; margin-bottom: 10px; background: #ffffff08; border: 1px solid transparent; }
.ship-card:last-child { margin-bottom: 0; }
.ship-card.p0 { border-color: #ff8a3c55; } .ship-card.p1 { border-color: #2f8bff55; }
.ship-card.active { box-shadow: 0 0 0 2px var(--gold) inset; }
.ship-card .avatar { width: 46px; height: 46px; flex: 0 0 46px; }
.ship-card .meta { flex: 1; min-width: 0; }
.ship-card .name { font-family: 'Baloo 2'; font-weight: 800; font-size: 14px; }
.ship-card .stats { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 4px; font-size: 12px; color: var(--muted); font-weight: 700; }
.stat b { color: var(--text); }
.stat .ic { width: 14px; height: 14px; vertical-align: -2px; margin-right: 2px; }
.dom { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.dom-label { display: inline-flex; align-items: center; gap: 3px; font: 800 8.5px 'Nunito'; letter-spacing: 1px; color: var(--muted); flex: 0 0 auto; }
.dom-label .ic-dom { width: 12px; height: 12px; }
/* Fog of war: a system whose ownership this player hasn't scouted. The star type
   is still public, so we haze + desaturate the whole node (reads as "unexplored")
   rather than hide it, and the ring-fogged sprite marks the unknown owner. */
.sys-node.fogged { opacity: 0.4; filter: grayscale(0.55) brightness(0.8); }
.sys-node.fogged .sys-label { opacity: 0.7; }
.dom-bar { flex: 1 1 auto; height: 7px; border-radius: 6px; background: #ffffff14; overflow: hidden; }
.dom-fill { height: 100%; border-radius: 6px; transition: width .25s ease; }
.dom-num { font: 700 10px 'JetBrains Mono'; color: var(--violet-soft); flex: 0 0 auto; min-width: 42px; text-align: right; }
.lives { display: flex; align-items: center; gap: 3px; margin-top: 5px; }
.lives .ic-life { width: 15px; height: 15px; }
.badges { display: flex; gap: 4px; margin-top: 4px; }
.badge { font: 700 9px 'Nunito'; padding: 2px 6px; border-radius: 6px; background: #ffcf5c22; color: var(--gold); text-transform: uppercase; letter-spacing: .5px; }
.pos-hidden { color: var(--violet); font-style: italic; }

/* actions */
/* minmax(0,1fr) lets tracks shrink below their content so long labels can't
   push a column past its share and overflow the panel. */
.actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.act-btn {
  display: flex; align-items: center; gap: 8px; text-align: left; padding: 9px 10px; border-radius: 12px;
  min-width: 0; overflow: hidden;
  background: var(--panel-2); border: 1px solid #ffffff1c; cursor: pointer; color: var(--text);
  font-family: 'Nunito'; font-weight: 700; font-size: 12.5px; transition: background .12s, transform .05s;
}
.act-btn:hover { background: #2a1f66; }
.act-btn:active { transform: translateY(1px); }
.act-btn .ic { width: 22px; height: 22px; flex: 0 0 22px; }
/* label (and, when disabled, the reason beneath it) take the remaining room */
.act-btn .body { display: flex; flex-direction: column; gap: 1px; flex: 1 1 auto; min-width: 0; }
.act-btn .label { overflow-wrap: break-word; line-height: 1.15; }
.act-btn .reason { font: 700 9px 'JetBrains Mono'; color: var(--muted); overflow-wrap: break-word; }
.act-btn .cost { margin-left: auto; flex: 0 0 auto; font: 700 10px 'JetBrains Mono'; color: var(--cyan); }
.act-btn.act-FIRE { border-color: #ff5c5c66; }
.act-btn.act-END_TURN { border-color: var(--gold); background: #2a2148; grid-column: 1 / -1; justify-content: center; }
.act-btn.jump-highlight { border-color: var(--cyan); }
/* Unaffordable / unavailable: shown but dimmed and non-interactive. */
.act-btn.disabled { opacity: .34; cursor: not-allowed; filter: grayscale(0.4); }
.act-btn.disabled:hover { background: var(--panel-2); opacity: .5; }
.act-btn.disabled:active { transform: none; }

/* Hover tooltip explaining what an action does (works on disabled ones too). */
#act-tooltip {
  position: fixed; z-index: 1000; max-width: 264px; pointer-events: none;
  background: linear-gradient(180deg, #201850, #171040);
  border: 1px solid #ffffff2e; border-radius: 12px; padding: 10px 12px;
  box-shadow: 0 12px 34px #000b; opacity: 0; transform: translateY(3px);
  transition: opacity .1s, transform .1s; font-family: 'Nunito';
}
#act-tooltip.show { opacity: 1; transform: translateY(0); }
#act-tooltip .tip-title { font-family: 'Baloo 2'; font-weight: 800; font-size: 13px; color: var(--cyan); }
#act-tooltip .tip-desc { font-weight: 700; font-size: 12px; line-height: 1.4; color: var(--violet-soft); margin-top: 3px; }
#act-tooltip .tip-cost { font: 700 10px 'JetBrains Mono'; color: var(--cyan); margin-top: 6px; }
#act-tooltip .tip-warn { font-weight: 800; font-size: 11px; color: var(--gold); margin-top: 6px; }
.hint { color: var(--muted); font-size: 12px; margin: 10px 2px 0; }
.pips { display: inline-flex; gap: 3px; }
.pips .ic { width: 16px; height: 16px; }

/* log */
.log { max-height: 240px; overflow-y: auto; font-family: 'JetBrains Mono'; font-size: 11.5px; line-height: 1.7; color: var(--violet-soft); }
.log .ev { padding: 1px 0; border-bottom: 1px solid #ffffff08; }
.log .ev.hot { color: var(--gold); }
.log .ev.win { color: var(--cyan); font-weight: 700; }
.log::-webkit-scrollbar { width: 8px; } .log::-webkit-scrollbar-thumb { background: #ffffff22; border-radius: 8px; }

/* ---------- rules modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: #05030bcc; backdrop-filter: blur(4px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 20px; overflow-y: auto;
}
.modal-overlay[hidden] { display: none; }
.modal {
  position: relative; width: min(760px, 100%);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid #ffffff26; border-radius: 18px;
  box-shadow: 0 24px 80px #000a; padding: 28px 32px 32px;
}
.modal h2 { font-family: 'Baloo 2'; font-weight: 800; font-size: 24px; margin: 0 0 6px; }
.modal h3 {
  font-family: 'Baloo 2'; font-weight: 700; font-size: 15px; color: var(--cyan);
  text-transform: uppercase; letter-spacing: 1.5px; margin: 22px 0 8px;
}
.modal p, .modal li { font-size: 14px; line-height: 1.6; color: var(--violet-soft); }
.modal .modal-lead { color: var(--text); }
.modal ul { margin: 6px 0; padding-left: 20px; }
.modal li { margin: 3px 0; }
.modal b { color: var(--text); }
.warn-inline { color: var(--gold); font-weight: 700; }
.rules-table { width: 100%; border-collapse: collapse; margin: 6px 0; font-size: 13px; }
.rules-table th, .rules-table td {
  text-align: left; padding: 6px 10px; border-bottom: 1px solid #ffffff14; vertical-align: top;
}
.rules-table th { color: var(--muted); text-transform: uppercase; letter-spacing: 1px; font-size: 11px; }
.rules-table td:first-child { color: var(--text); font-weight: 700; white-space: nowrap; }
.rules-table td:nth-child(2) { color: var(--gold); font-weight: 700; white-space: nowrap; }
.rules-table td { color: var(--violet-soft); }
.modal-close {
  position: absolute; top: 16px; right: 16px; width: 34px; height: 34px;
  border-radius: 10px; border: 1px solid #ffffff22; background: var(--panel);
  color: var(--text); font-size: 15px; cursor: pointer; line-height: 1;
}
.modal-close:hover { background: #241a5c; }

/* ---------- games browser ---------- */
.games-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.games-empty { color: var(--muted); font-size: 13px; padding: 12px 2px; }
.game-row {
  display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 12px; background: #ffffff08; border: 1px solid #ffffff14;
}
.game-row:hover { background: #ffffff12; }
.game-when { font: 700 11px 'JetBrains Mono'; color: var(--muted); white-space: nowrap; }
.game-main { min-width: 0; }
.game-players { font-family: 'Baloo 2'; font-weight: 700; font-size: 14px; }
.game-sub { font: 700 11px 'Nunito'; color: var(--muted); margin-top: 2px; }
.game-outcome { font: 800 12px 'Baloo 2'; white-space: nowrap; }
.game-outcome.win-0 { color: var(--p1); } .game-outcome.win-1 { color: var(--p2-bright); }
.game-outcome.draw { color: var(--violet-soft); }
.game-actions { display: flex; gap: 6px; }
.game-actions .btn { padding: 6px 12px; font-size: 12px; }
.btn-danger { border-color: #ff5c5c55; color: var(--danger); }
.btn-danger:hover { background: #3a1420; }

/* ---------- replay control bar ---------- */
.replay-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px;
  padding: 8px 12px; border-radius: 14px;
  background: linear-gradient(180deg, #211a52, #171040); border: 1px solid var(--cyan);
}
.replay-bar[hidden] { display: none; }
.replay-bar .btn { padding: 6px 12px; font-size: 13px; }
.replay-tag { font: 800 11px 'Baloo 2'; letter-spacing: 2px; color: var(--cyan); }
.replay-slider { flex: 1 1 160px; min-width: 120px; accent-color: var(--cyan); }
.replay-counter { font: 700 12px 'JetBrains Mono'; color: var(--violet-soft); white-space: nowrap; min-width: 64px; text-align: right; }
.replay-bar .speed { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px; font-weight: 700; }
