:root {
  --bg: #070a12;
  --panel: #0e1320;
  --panel-2: #141b2c;
  --line: #222c42;
  --text: #d6deee;
  --muted: #7f8aa3;
  --accent: #38d3e6;
  --gold: #f2c94c;
  --green: #6fdc8c;
  --amber: #ffa840;
  --pink: #ff5fa2;
  --red: #ff6b6b;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }

header {
  height: 48px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { font-weight: 700; letter-spacing: 0.2em; color: var(--accent); }
.brand span { font-weight: 400; letter-spacing: 0.05em; color: var(--muted); margin-left: 8px; font-size: 12px; }
.toolbar { display: flex; gap: 8px; align-items: center; }
.toolbar label { color: var(--muted); display: flex; gap: 6px; align-items: center; }

button, select, input[type="text"], textarea {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 10px; font: inherit;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: #0f3640; border-color: #1e6370; }
button.primary.accepted { background: #123d22; border-color: #2c7a46; color: var(--green); }
textarea { width: 100%; resize: vertical; font-family: ui-monospace, monospace; font-size: 11px; margin: 6px 0; }

main { display: grid; grid-template-columns: 320px 1fr 330px; height: calc(100vh - 48px); }
aside { overflow-y: auto; background: var(--panel); }
#settings { border-right: 1px solid var(--line); padding: 8px 12px 24px; }
#side { border-left: 1px solid var(--line); padding: 8px 12px 24px; }

details.group { border-bottom: 1px solid var(--line); padding: 6px 0 10px; }
details.group > summary {
  cursor: pointer; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em;
  font-size: 12px; color: var(--accent); padding: 6px 0;
}
.field { margin: 10px 0; }
.field label { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.field output { color: var(--gold); font-variant-numeric: tabular-nums; }
.field input[type="range"] { width: 100%; accent-color: var(--accent); }
.field select, .field input[type="text"] { width: 100%; }
.field small, .small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; line-height: 1.35; }
.note { font-size: 12px; color: var(--green); background: #0f2018; border: 1px solid #1d3d2a; border-radius: 6px; padding: 6px 8px; }
.muted { color: var(--muted); }

#mapWrap { position: relative; overflow: hidden; background: radial-gradient(ellipse at center, #0c1222 0%, var(--bg) 70%); }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
#map:active { cursor: grabbing; }
#hoverTip {
  position: absolute; pointer-events: none; background: rgba(14, 19, 32, 0.95); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 8px; font-size: 12px; white-space: nowrap; z-index: 2;
}
.legend {
  position: absolute; left: 12px; top: 12px; display: flex; flex-wrap: wrap; gap: 4px 12px; max-width: 70%;
  background: rgba(14, 19, 32, 0.8); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12px;
}
.legend span { display: flex; align-items: center; gap: 5px; color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; }
.dot.hub { background: #ffd866; box-shadow: 0 0 6px #ffd866; }
.dot.safe { background: var(--gold); }
.dot.port { background: var(--accent); }
.dot.planet { border: 2px solid var(--green); }
.dot.plain { background: #7d879b; }
.tag.preserve { background: rgba(201,168,255,0.15); color: #c9a8ff; }
.dot.preserve { background: transparent; border: 1.5px solid #c9a8ff; }
.game-over { background: rgba(255,216,102,0.12); color: #ffd866; padding: 6px 8px; border-radius: 6px; margin: 6px 0; font-weight: 600; }
.secret { color: #c9a8ff; margin: 6px 0; }
.news { max-height: 220px; overflow-y: auto; font-size: 13px; line-height: 1.4; }
.news > div { padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
body.playing .intro-card { display: none; }
.intro-card p { margin: 0 0 8px; line-height: 1.45; }
.dot.fog { background: rgba(125,135,155,0.28); }
.swatch.neb { display: inline-block; width: 14px; height: 10px; border-radius: 4px; background: rgba(160, 90, 230, 0.45); }
.line.oneway { display: inline-block; width: 16px; height: 2px; background: var(--amber); }
.hint { position: absolute; left: 12px; bottom: 10px; font-size: 12px; color: var(--muted); }
#genStatus { position: absolute; right: 12px; bottom: 10px; font-size: 12px; color: var(--muted); }
#toast {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); z-index: 3;
  background: #2a2412; border: 1px solid #6b5a22; color: var(--gold); padding: 8px 14px; border-radius: 8px;
}

.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 8px 0 12px; }
.card h2 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent); }
.fp { display: flex; justify-content: space-between; align-items: center; }
.fp code { font-size: 16px; color: var(--gold); letter-spacing: 0.08em; }
.row { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.issue { font-size: 12px; border-radius: 6px; padding: 6px 8px; margin: 6px 0; line-height: 1.35; }
.issue.error { background: #2d1216; border: 1px solid #6d2a32; color: #ffb3b3; }
.issue.warn { background: #2a2412; border: 1px solid #6b5a22; color: #ffe1a0; }
.issue.info { background: #121c2d; border: 1px solid #23395c; color: #b7cdf0; }
#players { list-style: none; padding: 0; margin: 10px 0; }
#players li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
#players .status { margin-left: auto; font-size: 12px; color: var(--muted); }
#players .dot.ok { background: var(--green); }
#players .dot.wait { background: var(--amber); }
#players .dot.empty { border: 1px dashed var(--muted); }
details summary { cursor: pointer; color: var(--muted); margin-top: 6px; }

dl#stats { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: 13px; }
dl#stats dt { color: var(--muted); }
dl#stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
dl#stats dd.sub { grid-column: 1 / -1; text-align: left; color: var(--muted); font-size: 11px; margin-top: -2px; }

.sec-title { font-size: 18px; font-weight: 600; margin-bottom: 6px; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.tag { font-size: 11px; border-radius: 10px; padding: 2px 8px; border: 1px solid var(--line); }
.tag.safe { color: var(--gold); border-color: #6b5a22; }
.tag.neb { color: #c9a0ff; border-color: #4e3570; }
.kv { display: flex; justify-content: space-between; margin: 4px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.chip { padding: 2px 8px; font-size: 12px; border-radius: 10px; font-variant-numeric: tabular-nums; }
.chip.oneway { color: var(--amber); border-color: #6b4a22; }
.subhead { margin-top: 10px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
table.trade { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; }
table.trade td { padding: 3px 0; border-bottom: 1px solid var(--line); }
table.trade td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.buy { color: var(--green); }
.sell { color: var(--accent); }
.route { margin-top: 10px; background: #2a1222; border: 1px solid #6d2a56; border-radius: 6px; padding: 8px; }
.route .path { font-family: ui-monospace, monospace; font-size: 12px; margin-top: 4px; word-break: break-word; color: #ffc2dc; }
button.on { border-color: var(--accent); color: var(--accent); }
.game-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.row-btns { display: flex; gap: 4px; }
#viewing { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
#viewing[hidden], .card[hidden] { display: none; }
form.login { display: grid; gap: 6px; }
input[type="password"], input[type="number"] {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; font: inherit;
}
.gold { color: var(--gold); }
#shipCard { border-color: #2c7a46; }
.play-here { color: var(--green); margin-top: 8px; }
table.trade.play td { padding: 3px 4px 3px 0; }
table.trade.play input { width: 58px; padding: 3px 4px; }
table.trade.play button { padding: 3px 8px; }
.log { margin-top: 8px; font-size: 12px; color: var(--muted); max-height: 120px; overflow-y: auto; }
.log div { padding: 2px 0; border-top: 1px solid var(--line); }
.log div:first-child { color: var(--text); }
.log .err { color: #ffb3b3; }
code { font-family: ui-monospace, monospace; font-size: 12px; }

/* In a server game (viewing or playing): the galaxy setup goes away. */
body.in-game main { grid-template-columns: 1fr 380px; }
body.in-game #settings, body.in-game .setup-only { display: none; }
body.playing .lobby-only { display: none; }
.host { margin-top: 14px; padding-top: 6px; border-top: 1px solid var(--line); }
.card-head { display: flex; align-items: center; gap: 6px; }
.card-head .small-btn { margin-left: auto; text-transform: none; letter-spacing: 0; font-size: 12px; padding: 2px 8px; color: var(--muted); }
table.fleet { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; }
table.fleet td { padding: 3px 4px 3px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.fleet td.n { text-align: right; }
table.fleet input { width: 48px; padding: 3px 4px; }
table.fleet button { padding: 3px 8px; }
table.fleet tr.too-dear td { color: var(--muted); }
.hullbar { display: inline-block; width: 44px; height: 6px; background: #2d1216; border-radius: 3px; vertical-align: middle; }
.hullbar i { display: block; height: 100%; background: var(--green); border-radius: 3px; }
.others { margin-top: 8px; background: #2a1216; border: 1px solid #6d2a32; border-radius: 6px; padding: 6px 8px; font-size: 13px; }
.yard-filter { display: flex; gap: 4px; flex-wrap: wrap; margin: 6px 0; }
.yard-filter button { padding: 2px 8px; font-size: 12px; }
.small-inline { font-size: 11px; }
.other-row { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 4px 0; }
.other-row select { padding: 2px 4px; font-size: 12px; }
button.danger { background: #3d1218; border-color: #7a2c36; color: #ffb3b3; }
.battle-row { font-size: 12px; padding: 5px 0; border-bottom: 1px solid var(--line); line-height: 1.4; }
.err-text { color: var(--red); }
#standing { padding: 2px 4px; font-size: 12px; }
/* Battle replay (replay.js) */
.replay { display: flex; flex-direction: column; min-height: 0; }
.replay-head { padding: 8px 12px; font-weight: 600; }
.replay-head .att { color: var(--accent); }
.replay-head .def { color: var(--pink); }
.replay-stage { flex: 1; min-height: 240px; position: relative; }
.replay-stage canvas { position: absolute; inset: 0; display: block; }
.replay-bar { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); }
.replay-bar input[type="range"] { flex: 1; }
.replay-caption { padding: 0 12px 10px; }
body.replay-page main#replayMain { display: flex; flex-direction: column; height: calc(100vh - 48px); }
body.replay-page main#replayMain .replay { flex: 1; }
#replayOverlay { position: absolute; inset: 0; background: var(--bg); z-index: 5; display: flex; flex-direction: column; }
#replayOverlay[hidden] { display: none; }
#replayOverlay .replay { flex: 1; }
.overlay-bar { display: flex; gap: 8px; justify-content: flex-end; padding: 8px 12px; border-bottom: 1px solid var(--line); }
table.standings tr.me td { color: var(--green); }
.statbar { display: inline-flex; gap: 2px; vertical-align: middle; }
.statbar i, .statbar b { display: inline-block; width: 7px; height: 8px; border-radius: 2px; }
.statbar i { background: var(--accent); }
.statbar b { background: #1d2538; }
table.captain button { padding: 0 7px; }

/* Touch and small screens (STAR-42) */
#map { touch-action: none; }
.touch-hint { display: none; }
@media (hover: none) { .mouse-hint { display: none; } .touch-hint { display: block; } }
@media (max-width: 820px) {
  header { height: auto; flex-wrap: wrap; gap: 6px; padding: 6px 10px; }
  .toolbar { flex-wrap: wrap; gap: 4px; }
  .toolbar button, .toolbar select { padding: 5px 8px; font-size: 13px; }
  main, body.in-game main { display: flex; flex-direction: column; height: auto; }
  #mapWrap { order: 1; } #side { order: 2; } #settings { order: 3; }
  #mapWrap { height: 62vh; min-height: 320px; }
  #settings, #side { border: none; padding: 4px 10px 16px; }
  #settings { border-top: 1px solid var(--line); }
  body:not(.in-game) #side { border-top: 1px solid var(--line); }
  .legend { display: none; }
  button { min-height: 34px; }
  table.fleet button, table.trade.play button { min-height: 30px; }
  #replayOverlay { position: fixed; z-index: 20; }
}

/* ---------- front page (welcome.html) ---------- */
body.welcome-page { min-height: 100vh; overflow-x: hidden; }
#welcomeBattle { position: fixed; inset: 0; z-index: 0; }
#welcomeBattle.replay { display: block; }
#welcomeBattle .replay-stage { position: absolute; inset: 0; min-height: 0; }
.replay.ambient .replay-head, .replay.ambient .replay-bar, .replay.ambient .replay-caption { display: none; }
.welcome-shade { position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(7,10,18,0.55) 0%, rgba(7,10,18,0.82) 70%, rgba(7,10,18,0.92) 100%); }
main.welcome { display: block; position: relative; z-index: 2; max-width: 640px; height: auto; min-height: 0; margin: 0 auto; padding: 8vh 18px 48px; overflow: visible; }
.welcome-title { font-size: clamp(36px, 8vw, 64px); letter-spacing: 0.35em; margin: 0; color: var(--accent); font-weight: 700; text-shadow: 0 0 24px rgba(56,211,230,0.35); }
.welcome-tag { color: var(--text); font-size: 17px; margin: 8px 0 28px; opacity: 0.9; }
.welcome-card { background: rgba(14,19,32,0.78); border: 1px solid var(--line); border-radius: 10px; padding: 16px 20px; margin-bottom: 16px; backdrop-filter: blur(3px); }
.welcome-card h2 { font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); margin: 0 0 10px; }
.welcome-card p { line-height: 1.55; margin: 0 0 10px; }
.welcome-login .login { display: flex; flex-direction: column; gap: 8px; }
#welcomeError { color: var(--red); min-height: 1em; margin: 8px 0 4px; }
.welcome-points { list-style: none; padding: 0; margin: 20px 0 0; display: grid; gap: 8px; color: var(--muted); font-size: 14px; }
.welcome-points b { color: var(--text); }

/* cliques (standings card) */
#standings h3.sub { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin: 10px 0 4px; }
.clique-form { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.clique-form input { flex: 1 1 120px; min-width: 0; }
.clique-tag { color: var(--accent); }
