/* Deliberately single-theme (dark), like the original: nebula ground, cyan HUD panels. */
:root {
  color-scheme: dark;
  --bg: #071014;
  --panel: #0c1c22;
  --panel-2: #10252d;
  --ink: #e2eef0;
  --muted: #8aa6ad;
  --line: #1f3d47;
  --hud: #5fd3e6;
  --hud-soft: rgba(95, 211, 230, 0.12);
  --you: #86e05a;
  --me: var(--you);  /* your empire's color, set by the game */
  --p1: #f0a33a;
  --good: #86e05a;
  --warn: #f0c04a;
  --bad: #ef6b6b;
  --f-logo: "Exo 2", "Arial Narrow", sans-serif;
  --f-display: "Saira Condensed", "Arial Narrow", Impact, sans-serif;
  --f-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
  font-family: var(--f-body); font-size: 15px; line-height: 1.5;
}
button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--hud); outline-offset: 2px; }
h2, h3 { font-family: var(--f-display); text-transform: uppercase; margin: 0; line-height: 1.05; }
h2 { font-size: 1.6rem; font-weight: 800; letter-spacing: 0.03em; }
h3 { font-size: 0.95rem; font-weight: 600; letter-spacing: 0.08em; color: var(--hud); }

/* ---------- top bar ---------- */
.bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 28px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.logo {
  font-family: var(--f-logo); font-style: italic; font-weight: 900; font-size: 1.7rem; line-height: 0.85;
  text-transform: uppercase; display: grid; transform: skewX(-6deg);
  text-shadow: 0 0 18px rgba(95, 211, 230, 0.35);
}
.logo span { font-size: 0.55em; }
.stat { display: grid; gap: 1px; }
.stat .k { font-family: var(--f-mono); font-size: 0.66rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.stat b { font-family: var(--f-display); font-size: 1.35rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat small { font-size: 0.75rem; color: var(--muted); }
.stat small.warn { color: var(--warn); }
.vp-row { display: flex; align-items: center; gap: 8px; }
.vp-row b.you { color: var(--me); }
.vp-track { position: relative; width: 150px; height: 8px; background: var(--line); }
.vp-track i { position: absolute; top: 0; bottom: 0; left: 0; transition: width .4s; }
.vp-track i.you { background: var(--me); opacity: 0.85; }
.vp-track .tick { position: absolute; top: -3px; bottom: -3px; width: 3px; }
.vp-lead { font-family: var(--f-mono); font-size: 0.75rem; color: var(--muted); display: flex; gap: 7px; font-variant-numeric: tabular-nums; }
.vp-lead .me { font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.bar-actions { margin-left: auto; display: flex; gap: 10px; }
.primary, .ghost {
  border: 1px solid var(--hud); padding: 8px 18px; cursor: pointer;
  font-family: var(--f-display); font-weight: 800; font-size: 1.05rem; letter-spacing: 0.05em; text-transform: uppercase;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}
.primary { background: var(--you); border-color: var(--you); color: #0b1a05; }
.primary:disabled { background: var(--line); border-color: var(--line); color: var(--muted); cursor: default; }
.ghost { background: transparent; color: var(--hud); }
.small { padding: 5px 12px; font-size: 0.9rem; }

/* ---------- layout ---------- */
.game { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 370px; }
.mapwrap { min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; background: #050b0e; overflow: hidden; }
#map { width: 100%; height: 100%; max-height: 100%; display: block; user-select: none; }
#map text { font-family: var(--f-mono); pointer-events: none; }
#map .planet, #map .fleet, #map .battle-marker { cursor: pointer; }
#map .planet:hover .ring { stroke-opacity: 0.9; }
.panel { border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 14px 16px 24px; display: grid; gap: 18px; align-content: start; }
@media (max-width: 900px) {
  .game { grid-template-columns: 1fr; grid-template-rows: auto auto; }
  #map { height: auto; }
  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  body { height: auto; min-height: 100%; }
  .bar-actions { margin-left: 0; }
}

/* ---------- panel ---------- */
.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.chip {
  display: grid; justify-items: center; gap: 2px; padding: 6px 4px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); text-align: center;
}
.chip svg { width: 16px; height: 20px; }
.chip span { font-size: 0.72rem; font-weight: 600; }
.chip small { font-family: var(--f-mono); font-size: 0.7rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip.on { border-color: var(--me); box-shadow: inset 0 0 0 1px var(--me); }
.chip.dead { opacity: 0.55; }
.chip.busy small { color: var(--me); }
.sel { display: grid; gap: 12px; }
.head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.where { font-family: var(--f-mono); font-size: 0.78rem; color: var(--muted); }
.capbar { display: grid; gap: 4px; }
.capbar .track { height: 6px; background: var(--line); }
.capbar .track i { display: block; height: 100%; background: var(--me); }
.capbar .lbl { display: flex; justify-content: space-between; font-family: var(--f-mono); font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.comp { display: grid; gap: 4px; }
.comp-row, .build-row { display: grid; grid-template-columns: 46px 1fr auto; gap: 10px; align-items: center; }
.comp-row b { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.comp-row .q, .build-row .q { color: var(--you); font-family: var(--f-mono); font-size: 0.8rem; }
.glyph { width: 46px; height: 18px; display: block; }
.status { padding: 8px 10px; background: var(--panel-2); border-left: 2px solid var(--hud); font-size: 0.9rem; }
.status.colonize { border-left-color: var(--you); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.build { display: grid; gap: 8px; padding-top: 4px; }
.build-row { grid-template-columns: 46px 1fr auto; }
.build-row .nm small { display: block; color: var(--muted); font-family: var(--f-mono); font-size: 0.7rem; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 28px; height: 28px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-family: var(--f-mono); }
.stepper button:hover { border-color: var(--hud); }
.stepper input { width: 52px; height: 28px; background: var(--bg); border: 1px solid var(--line); color: var(--ink); text-align: right; padding: 0 6px; font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.hint { font-size: 0.85rem; color: var(--muted); margin: 0; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; font-size: 0.9rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; }
.howto { margin: 0; padding-left: 1.2em; display: grid; gap: 6px; font-size: 0.9rem; }
.howto li::marker { color: var(--hud); }
.dispatch { display: grid; gap: 8px; }
.dispatch ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; font-family: var(--f-mono); font-size: 0.78rem; }
.dispatch li { padding-left: 12px; position: relative; }
.dispatch li::before { content: ""; position: absolute; left: 0; top: 0.55em; width: 5px; height: 5px; background: var(--muted); }
.dispatch li.good::before { background: var(--good); }
.dispatch li.bad::before { background: var(--bad); }
.dispatch li button { all: unset; cursor: pointer; color: var(--hud); text-decoration: underline; text-underline-offset: 2px; }
.empty { color: var(--muted); font-size: 0.85rem; }

/* ---------- modal + battle screen ---------- */
.modal { position: fixed; inset: 0; z-index: 10; background: rgba(3, 8, 10, 0.78); display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.modal-card { width: min(920px, 100%); background: var(--panel); border: 1px solid var(--hud); padding: 20px; display: grid; gap: 16px; }
.modal-card.narrow { width: min(480px, 100%); }
.eyebrow { font-family: var(--f-mono); font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--hud); }
.vs { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; }
.side { padding: 14px; background: var(--panel-2); border: 1px solid var(--line); display: grid; gap: 10px; align-content: start; min-width: 0; }
.side-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.side-head b { font-family: var(--f-display); font-size: 1.4rem; font-weight: 800; text-transform: uppercase; }
.val { font-family: var(--f-mono); font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.glyphs {
  min-height: 84px; padding: 8px; display: flex; flex-wrap: wrap; gap: 3px; align-content: flex-start; justify-content: flex-end;
  background: var(--bg);
  background-image: linear-gradient(rgba(95,211,230,.07) 1px, transparent 1px), linear-gradient(90deg, rgba(95,211,230,.07) 1px, transparent 1px);
  background-size: 14px 14px;
}
.glyphs svg { display: block; }
.rows { display: grid; gap: 6px; }
.rows .row { display: grid; grid-template-columns: 46px 1fr auto; gap: 10px; align-items: center; font-size: 0.9rem; }
.rows .row b { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.mid { display: grid; justify-items: center; align-content: center; gap: 14px; }
.vs-word { font-family: var(--f-display); font-weight: 800; font-size: 2.8rem; line-height: 1; }
.battle-btn {
  width: 100px; height: 100px; border-radius: 50%; border: 3px solid rgba(255,255,255,.35); cursor: pointer;
  background: radial-gradient(circle at 40% 35%, #b8f58e, var(--you) 55%, #3d8a1f); color: #0b1a05;
  font-family: var(--f-display); font-weight: 800; font-size: 1.3rem; text-transform: uppercase;
  box-shadow: 0 0 24px rgba(134, 224, 90, 0.35); transition: transform .15s;
}
.battle-btn:hover:not(:disabled) { transform: scale(1.05); }
.battle-btn:disabled { filter: grayscale(0.7); cursor: default; }
.verdict { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: baseline; }
.pct { font-family: var(--f-display); font-size: 2.2rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.pill { font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; padding: 2px 8px; border-radius: 99px; border: 1px solid currentColor; }
.note { color: var(--muted); font-size: 0.85rem; }
.oddsbar { height: 8px; background: var(--line); }
.oddsbar i { display: block; height: 100%; }
.report { font-family: var(--f-mono); font-size: 0.85rem; background: var(--bg); border: 1px solid var(--line); padding: 10px 12px; display: grid; gap: 4px; }
.report .t { color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
@media (max-width: 720px) {
  .vs { grid-template-columns: 1fr; }
  .mid { grid-auto-flow: column; justify-content: center; align-items: center; }
}

/* end of game */
.result-title { font-family: var(--f-logo); font-style: italic; font-weight: 900; font-size: clamp(2.6rem, 9vw, 4rem); text-transform: uppercase; line-height: 1; text-align: center; }
.result-title.win { color: var(--you); }
.result-title.lose { color: var(--bad); }
.result-sub { text-align: center; color: var(--muted); font-family: var(--f-display); text-transform: uppercase; letter-spacing: 0.05em; font-size: 1.1rem; margin: 0; }
.stats { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stats th, .stats td { padding: 8px 10px; border-bottom: 1px solid var(--line); }
.stats th { font-family: var(--f-display); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.85rem; text-align: center; color: var(--muted); }
.stats td { font-family: var(--f-mono); }
.stats td:first-child { text-align: left; color: var(--you); }
.stats td:last-child { text-align: right; color: var(--p1); }
.stats tr:nth-child(even) { background: var(--hud-soft); }
.choices { display: grid; gap: 8px; }
.choice { display: grid; gap: 2px; text-align: left; padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--line); cursor: pointer; }
.choice b { font-family: var(--f-display); text-transform: uppercase; font-size: 1.1rem; letter-spacing: 0.04em; }
.choice span { font-size: 0.85rem; color: var(--muted); }
.choice.on { border-color: var(--you); box-shadow: inset 0 0 0 1px var(--you); }
.error { color: var(--bad); font-size: 0.9rem; margin: 0; }

/* map animation */
.route-dash { stroke-dasharray: 6 6; animation: march 1.1s linear infinite; }
@keyframes march { to { stroke-dashoffset: -24; } }
.pulse { animation: pulse 2s ease-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pulse { 0% { opacity: .9; transform: scale(.8); } 100% { opacity: 0; transform: scale(1.8); } }
.spin { animation: spin 3s linear infinite; transform-box: fill-box; transform-origin: center; }
@keyframes spin { to { transform: rotate(360deg); } }
.crackle { animation: crackle 1.6s steps(4) infinite; }
@keyframes crackle { 50% { stroke-dashoffset: 7; opacity: .5; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* empires list */
.empires { display: grid; gap: 6px; }
.emp { display: grid; grid-template-columns: 10px 1fr auto auto; gap: 8px; align-items: center; font-size: 0.88rem; }
.emp .dot { width: 10px; height: 10px; border-radius: 50%; }
.emp .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.emp .vpv { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.emp .st { font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); min-width: 64px; text-align: right; }
.emp .st.ready { color: var(--good); }
.emp.out .nm, .emp.out .vpv { text-decoration: line-through; color: var(--muted); }
.banner { padding: 10px 12px; border: 1px solid var(--warn); color: var(--warn); font-size: 0.9rem; background: rgba(240, 192, 74, 0.08); }

/* lobby */
.seats { display: grid; gap: 6px; }
.seat { display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: center; padding: 8px 10px; background: var(--panel-2); border: 1px solid var(--line); }
.seat .dot { width: 10px; height: 10px; border-radius: 50%; }
.seat .tag { font-family: var(--f-mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.seat.open { border-style: dashed; }
.invite { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; }
.invite input { flex: 1; min-width: 0; background: var(--bg); color: var(--ink); border: 1px solid var(--line); padding: 8px 10px; font-family: var(--f-mono); font-size: 0.85rem; }
.field { display: grid; gap: 4px; }
.field label { font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.field input { background: var(--bg); color: var(--ink); border: 1px solid var(--line); padding: 8px 10px; font: inherit; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { min-width: 44px; padding: 6px 10px; background: var(--panel-2); border: 1px solid var(--line); cursor: pointer; font-family: var(--f-display); font-weight: 800; font-size: 1.05rem; }
.seg button.on { border-color: var(--you); box-shadow: inset 0 0 0 1px var(--you); color: var(--you); }
.sides { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.center-row { display: flex; justify-content: center; }
.stats-wrap { overflow-x: auto; }
.stats.multi td, .stats.multi th { text-align: right; white-space: nowrap; }
.stats.multi td:first-child, .stats.multi th:first-child { text-align: left; color: var(--muted); }
.stats.multi tr:nth-child(even) { background: var(--hud-soft); }

/* fleet ships: one row per class */
.ships { display: grid; gap: 6px; }
.ship-head, .ship-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) 40px auto; gap: 8px; align-items: center; }
.ship-head.no-build, .ship-row.no-build { grid-template-columns: 34px minmax(0, 1fr) 40px; }
.ship-head span { font-family: var(--f-mono); font-size: 0.66rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.ship-head span:nth-child(3), .ship-row .have { text-align: right; }
.ship-head span:nth-child(4) { text-align: center; }
.ship-row .glyph { width: 34px; height: 14px; }
.ship-row .nm { font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ship-row .nm small { display: block; color: var(--muted); font-family: var(--f-mono); font-size: 0.7rem; }
.ship-row .have { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.ship-row .q { color: var(--you); font-size: 0.8rem; }
.ship-row .stepper { gap: 3px; }
.ship-row .stepper button { width: 26px; height: 28px; }
.ship-row .stepper input { width: 48px; }

.stepper button:disabled { opacity: 0.35; cursor: not-allowed; }
.stepper button:disabled:hover { border-color: var(--line); }
.note-line { margin: 0; font-size: 0.82rem; color: var(--muted); }
.note-line.warn { color: var(--warn); }
.stepper input.scrap { color: var(--bad); border-color: var(--bad); }
.game-id { display: flex; align-items: baseline; gap: 12px; }
.game-id .k { font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.game-id b { font-family: var(--f-mono); font-size: 1.8rem; letter-spacing: 0.18em; color: var(--you); user-select: all; }
.join-row { display: grid; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
#mJoinId { text-transform: uppercase; letter-spacing: 0.12em; }

/* battle arena */
.arena { position: relative; background: #04090c; border: 1px solid var(--line); }
.arena canvas { display: block; width: min(100%, calc(52vh * 1000 / 560)); aspect-ratio: 1000 / 560; margin: 0 auto; }
.arena-go { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
.arena-go:hover:not(:disabled) { transform: translate(-50%, -50%) scale(1.05); }
.arena-time { position: absolute; right: 10px; top: 8px; font-family: var(--f-mono); font-size: 0.8rem; color: var(--muted); }
.modal-card { width: min(980px, 100%); }
.rejoin { display: grid; gap: 6px; padding-top: 10px; border-top: 1px solid var(--line); }
.rejoin input { letter-spacing: 0.1em; }
b.code { font-family: var(--f-mono); color: var(--you); letter-spacing: 0.08em; user-select: all; }

/* races and research */
.race { font-family: var(--f-mono); font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 400; }
.side-head .race { margin-left: auto; margin-right: 10px; }
.races { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.race-card { display: grid; gap: 3px; align-content: start; text-align: left; padding: 10px; background: var(--panel-2); border: 1px solid var(--line); cursor: pointer; }
.race-card b { font-family: var(--f-display); font-size: 1.2rem; text-transform: uppercase; letter-spacing: 0.04em; }
.race-card .style { font-family: var(--f-mono); font-size: 0.66rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--hud); }
.race-card span:last-child { font-size: 0.78rem; color: var(--muted); line-height: 1.4; }
.race-card.on { border-color: var(--you); box-shadow: inset 0 0 0 1px var(--you); }
.techs { display: grid; gap: 6px; }
.tech { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--line); }
.tech b { font-weight: 600; }
.tech p { margin: 2px 0 0; font-size: 0.85rem; color: var(--muted); }
.tech.owned { border-color: rgba(134, 224, 90, 0.5); }
.tech.queued { border-color: var(--you); box-shadow: inset 0 0 0 1px var(--you); }
.tech.locked { opacity: 0.6; }
.tech .counter { margin-left: 8px; font-family: var(--f-mono); font-size: 0.66rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--warn); }
.tech-act { text-align: right; max-width: 200px; }
.tag { font-family: var(--f-mono); font-size: 0.72rem; color: var(--muted); }
.tag.good { color: var(--good); }
.bstats { display: grid; gap: 10px; }
.bstat { background: var(--bg); border: 1px solid var(--line); padding: 10px 12px; display: grid; gap: 6px; overflow-x: auto; }
.bstat-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.bstat-head .t { color: var(--muted); font-size: 0.82rem; }
.bstat table { width: auto; justify-self: start; border-collapse: collapse; font-family: var(--f-mono); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.bstat th, .bstat td { padding: 3px 18px 3px 0; text-align: right; white-space: nowrap; }
.bstat th:first-child, .bstat thead th { text-align: left; color: var(--muted); font-weight: 400; }
.bstat tbody th { color: var(--ink); }

/* ===================================================================== */
/* HUD theme: full-screen galaxy with floating holographic panels.       */
/* ===================================================================== */
:root {
  --glass: rgba(7, 20, 26, 0.74);
  --glass-strong: rgba(6, 16, 21, 0.9);
  --edge: rgba(95, 211, 230, 0.38);
  --edge-strong: rgba(95, 211, 230, 0.75);
  --cut: 14px;
}
body {
  background: radial-gradient(ellipse 80% 60% at 70% 20%, rgba(40, 110, 130, 0.22), transparent 70%),
              radial-gradient(ellipse 60% 50% at 15% 80%, rgba(90, 60, 160, 0.16), transparent 70%), #02070a;
}
#stars { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
.holo {
  background: var(--glass);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  backdrop-filter: blur(12px) saturate(1.2);
  border: 1px solid var(--edge);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), 0 10px 40px rgba(0, 0, 0, 0.45), inset 0 0 40px rgba(95, 211, 230, 0.05);
}

/* top HUD */
.bar {
  position: fixed; top: calc(10px + env(safe-area-inset-top, 0px)); left: 12px; right: 12px; z-index: 6;
  padding: 8px 18px; border-bottom: 1px solid var(--edge);
  background: var(--glass); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border: 1px solid var(--edge);
  clip-path: polygon(var(--cut) 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% 100%, 0 100%, 0 var(--cut));
  box-shadow: 0 0 30px rgba(95, 211, 230, 0.08);
}
.bar::after { content: ""; position: absolute; left: 24px; right: 24px; bottom: -1px; height: 1px; background: linear-gradient(90deg, transparent, var(--edge-strong), transparent); }
.stat .k::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 6px; background: var(--hud); transform: rotate(45deg); vertical-align: 1px; box-shadow: 0 0 8px var(--hud); }
.stat b { text-shadow: 0 0 14px rgba(95, 211, 230, 0.25); }

/* the map fills the screen; panels float over it */
.game { position: fixed; inset: 0; display: block; z-index: 1; }
.mapwrap { position: absolute; inset: 0; padding: 92px 404px 14px 14px; background: transparent; }
#map { filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.6)); }
.panel {
  position: fixed; top: 92px; right: 12px; bottom: 12px; width: 378px; z-index: 5;
  background: var(--glass); -webkit-backdrop-filter: blur(14px) saturate(1.2); backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid var(--edge); border-left: 1px solid var(--edge);
  clip-path: polygon(var(--cut) 0, 100% 0, 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, 0 100%, 0 var(--cut));
  box-shadow: inset 0 0 50px rgba(95, 211, 230, 0.04);
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.panel h3 { display: flex; align-items: center; gap: 8px; }
.panel h3::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, var(--edge), transparent); }
.chip, .status, .ship-row .stepper button, .stepper input { transition: border-color .15s, box-shadow .15s; }
.chip { background: rgba(16, 37, 45, 0.7); }
.chip:hover { border-color: var(--edge-strong); box-shadow: 0 0 14px rgba(95, 211, 230, 0.18); }
.status { background: rgba(16, 37, 45, 0.6); }
.trait-name { color: var(--warn); font-weight: 600; }

/* buttons glow */
.primary { box-shadow: 0 0 18px rgba(134, 224, 90, 0.25); }
.primary:hover:not(:disabled) { filter: brightness(1.1); box-shadow: 0 0 26px rgba(134, 224, 90, 0.45); }
.ghost { background: rgba(95, 211, 230, 0.06); }
.ghost:hover { background: rgba(95, 211, 230, 0.14); box-shadow: 0 0 16px rgba(95, 211, 230, 0.25); }

/* dialogs: holographic frame with corner brackets and faint scanlines */
.modal { background: radial-gradient(ellipse at center, rgba(2, 10, 14, 0.6), rgba(1, 4, 6, 0.88)); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.modal-card {
  position: relative; background: var(--glass-strong); border: 1px solid var(--edge);
  clip-path: polygon(18px 0, 100% 0, 100% calc(100% - 18px), calc(100% - 18px) 100%, 0 100%, 0 18px);
  box-shadow: 0 0 60px rgba(95, 211, 230, 0.12), inset 0 0 80px rgba(95, 211, 230, 0.04);
  background-image: repeating-linear-gradient(0deg, rgba(95, 211, 230, 0.025) 0 1px, transparent 1px 3px);
  animation: holo-in .22s ease-out;
}
.modal-card::before, .modal-card::after { content: ""; position: absolute; width: 22px; height: 22px; border: 2px solid var(--hud); pointer-events: none; opacity: 0.8; }
.modal-card::before { top: 6px; left: 6px; border-right: 0; border-bottom: 0; }
.modal-card::after { bottom: 6px; right: 6px; border-left: 0; border-top: 0; }
@keyframes holo-in { from { opacity: 0; transform: scale(0.97) translateY(6px); filter: blur(2px); } to { opacity: 1; transform: none; filter: none; } }
.arena { border-color: var(--edge); box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.6); }

@media (max-width: 900px) {
  body { height: auto; min-height: 100%; }
  .bar { position: sticky; top: 0; left: 0; right: 0; margin: 0; clip-path: none; }
  .game { position: relative; inset: auto; }
  .mapwrap { position: relative; inset: auto; padding: 8px; height: 62vh; }
  #map { height: 100%; }
  .panel { position: relative; top: auto; right: auto; bottom: auto; width: auto; margin: 0 8px 12px; clip-path: none; }
}
@media (max-width: 900px) {
  .mapwrap { height: auto; padding: 4px 6px; }
  #map { height: auto; }
  .bar { gap: 6px 16px; padding: 8px 10px; }
  .bar .logo { font-size: 1.4rem; }
  .bar-actions { width: 100%; display: grid; grid-template-columns: auto 1fr 1fr 1.25fr; gap: 6px; }
  .bar-actions button { padding: 7px 6px; font-size: 0.85rem; }
  #creditsNote { display: none; }
  .vp-track { width: 110px; }
}

/* 3D ship preview */
.preview { margin: 0; display: grid; gap: 2px; }
.ship-preview { width: 100%; aspect-ratio: 720 / 260; display: block; background: radial-gradient(ellipse at 50% 60%, rgba(95, 211, 230, 0.10), transparent 70%); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.preview figcaption { font-family: var(--f-mono); font-size: 0.66rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); text-align: right; }

.ship-thumb { width: 72px; height: 29px; object-fit: contain; display: block; filter: drop-shadow(0 0 6px rgba(95, 211, 230, 0.25)); }
.ship-head, .ship-row { grid-template-columns: 72px minmax(0, 1fr) 40px auto; }
.ship-head.no-build, .ship-row.no-build { grid-template-columns: 72px minmax(0, 1fr) 40px; }

/* research tree */
.modal-card.wide { width: min(1180px, 100%); }
.budget { display: grid; grid-template-columns: auto minmax(120px, 1fr) auto auto; gap: 10px; align-items: center; padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--line); }
.budget label { font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.budget input { accent-color: var(--you); width: 100%; }
.budget b { font-family: var(--f-display); font-size: 1.4rem; color: var(--you); font-variant-numeric: tabular-nums; min-width: 3ch; text-align: right; }
.ttrack { position: relative; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 34px; overflow-x: auto; }
.tlinks { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.tlinks path { fill: none; stroke: var(--line); stroke-width: 2; }
.tlinks path.next { stroke: var(--you); stroke-dasharray: 5 5; }
.tlinks path.done { stroke: rgba(134, 224, 90, 0.6); }
.tcol { display: grid; gap: 10px; align-content: start; position: relative; z-index: 1; min-width: 210px; }
.tier { font-family: var(--f-mono); font-size: 0.66rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--hud); }
.fork { display: grid; gap: 4px; padding: 6px; border: 1px dashed rgba(240, 192, 74, 0.45); }
.or { justify-self: center; font-family: var(--f-display); font-weight: 800; font-size: 0.9rem; color: var(--warn); letter-spacing: 0.1em; }
.tnode { display: grid; gap: 4px; padding: 10px 12px; background: rgba(16, 37, 45, 0.85); border: 1px solid var(--line); clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px); }
.tnode[data-toggle] { cursor: pointer; }
.tnode[data-toggle]:hover { border-color: var(--edge-strong); box-shadow: 0 0 16px rgba(95, 211, 230, 0.2); }
.tnode p { margin: 0; font-size: 0.8rem; color: var(--muted); line-height: 1.4; }
.tnode-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.tnode-head b { font-weight: 600; font-size: 0.92rem; }
.tnode .cost { font-family: var(--f-mono); font-size: 0.75rem; color: var(--warn); }
.tnode .path { font-family: var(--f-mono); font-size: 0.62rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--hud); }
.tnode .path.counter { color: var(--warn); }
.tnode.owned { border-color: rgba(134, 224, 90, 0.55); background: rgba(30, 60, 30, 0.45); }
.tnode.queued { border-color: var(--you); box-shadow: inset 0 0 0 1px var(--you); }
.tnode.locked { opacity: 0.55; }
.tnode.variant { background-image: linear-gradient(135deg, rgba(240, 192, 74, 0.12), transparent 60%); }
.tnode.variant .tnode-head b::before { content: "◆ "; color: var(--warn); }
.tprog { height: 4px; background: var(--line); }
.tprog i { display: block; height: 100%; background: var(--you); }
@media (max-width: 720px) { .ttrack { grid-template-columns: repeat(3, 230px); } }
.modal-card.wide .preview { width: min(560px, 100%); justify-self: center; }

/* battle orders */
.orders { display: grid; gap: 6px; }
.seg.stance button { flex: 1; min-width: 0; font-size: 0.85rem; padding: 6px 4px; }
.retreat { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; align-items: center; }
.retreat label { font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.retreat select { background: var(--bg); color: var(--ink); border: 1px solid var(--line); padding: 5px 8px; font: inherit; font-size: 0.85rem; }
.retreat .note-line { grid-column: 1 / -1; }

button.link { all: unset; cursor: pointer; color: var(--hud); text-decoration: underline; text-underline-offset: 2px; margin-left: 4px; }

/* comms */
.badge { display: inline-block; min-width: 18px; margin-left: 6px; padding: 0 5px; border-radius: 9px; background: var(--warn); color: #1a1205; font-family: var(--f-mono); font-size: 0.7rem; line-height: 18px; text-align: center; }
.chat {
  position: fixed; left: 12px; bottom: 12px; width: min(380px, calc(100vw - 24px)); height: min(440px, 55vh); z-index: 12;
  display: grid; grid-template-rows: auto 1fr auto;
  background: var(--glass-strong); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid var(--edge); clip-path: polygon(14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 14px);
  box-shadow: 0 0 40px rgba(95, 211, 230, 0.12); animation: holo-in .2s ease-out;
}
.chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.chat-head b { font-family: var(--f-display); font-size: 1.1rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--hud); }
.chat-head select { flex: 1; min-width: 0; background: var(--bg); color: var(--ink); border: 1px solid var(--line); padding: 5px 6px; font: inherit; font-size: 0.85rem; }
.chat-log { overflow-y: auto; padding: 10px 12px; display: grid; gap: 8px; align-content: start; scrollbar-width: thin; }
.msg { display: grid; grid-template-columns: auto auto 1fr; gap: 2px 8px; align-items: baseline; font-size: 0.9rem; }
.msg .who { font-weight: 600; }
.msg .when { font-family: var(--f-mono); font-size: 0.66rem; color: var(--muted); }
.msg .text { grid-column: 1 / -1; overflow-wrap: anywhere; color: var(--ink); }
.msg.mine .text { color: #cfe9d2; }
.chat-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; min-width: 0; background: var(--bg); color: var(--ink); border: 1px solid var(--line); padding: 8px 10px; font: inherit; }
@media (max-width: 900px) { .chat { left: 8px; right: 8px; width: auto; bottom: 8px; height: 60vh; } }

.research-now { display: grid; gap: 6px; }
.rn-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.rn-head span { font-family: var(--f-mono); font-size: 0.8rem; color: var(--warn); font-variant-numeric: tabular-nums; }
.research-now .tprog { height: 6px; }

/* tutorial coach */
.coach {
  position: fixed; z-index: 13; width: min(330px, calc(100vw - 24px)); padding: 14px 16px; display: grid; gap: 8px;
  background: rgba(6, 18, 24, 0.94); border: 1px solid var(--you); box-shadow: 0 0 30px rgba(134, 224, 90, 0.25);
  clip-path: polygon(12px 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%, 0 12px);
  transition: left .25s ease, top .25s ease; animation: holo-in .2s ease-out;
}
.coach h3 { color: var(--you); font-size: 1.15rem; }
.coach p { margin: 0; font-size: 0.92rem; line-height: 1.45; }
.coach-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.coach-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.coach-ring {
  position: fixed; z-index: 13; pointer-events: none; border: 2px solid var(--you); border-radius: 6px;
  box-shadow: 0 0 0 4px rgba(134, 224, 90, 0.15), 0 0 24px rgba(134, 224, 90, 0.5);
  animation: coach-pulse 1.4s ease-in-out infinite; transition: all .2s ease;
}
@keyframes coach-pulse { 50% { box-shadow: 0 0 0 8px rgba(134, 224, 90, 0.05), 0 0 34px rgba(134, 224, 90, 0.7); } }
.tutorial-offer { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid rgba(134, 224, 90, 0.5); background: rgba(30, 60, 30, 0.35); }
.tutorial-offer div { display: grid; gap: 2px; }
.tutorial-offer span { font-size: 0.85rem; color: var(--muted); }

a.ghost, a.primary { display: inline-flex; align-items: center; text-decoration: none; }

#endTurn.undo { background: transparent; color: var(--warn); border: 1px solid var(--warn); }

.note-line.good { color: var(--good); }

/* new game: fits one screen, two columns on wide screens */
.modal[data-kind="new"] .modal-card { width: min(780px, 100%); gap: 14px; }
.ng-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.ng-link { font-family: var(--f-mono); font-size: 0.78rem; color: var(--hud); }
.ng-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px 22px; }
.ng-col { display: grid; gap: 12px; align-content: start; min-width: 0; }
.ng-rows { gap: 9px; }
.ng-row { display: grid; grid-template-columns: 4.6rem minmax(0, 1fr); align-items: center; gap: 8px; }
.ng-row label { font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.ng-row .seg { flex-wrap: nowrap; gap: 5px; }
.ng-row .seg button { flex: 1; min-width: 0; padding: 5px 4px; font-size: 0.95rem; white-space: nowrap; }
.ng-row .seg button small { font-family: var(--f-mono); font-weight: 400; font-size: 0.7rem; opacity: 0.8; }
.ng-rows .hint { margin: 2px 0 0; font-size: 0.82rem; }
.modal[data-kind="new"] .races { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.modal[data-kind="new"] .race-card, .modal[data-kind="join"] .race-card { padding: 7px 9px; gap: 1px; }
.race-info { margin: 4px 0 0; font-size: 0.82rem; color: var(--muted); line-height: 1.4; min-height: 2.8em; }
.modal[data-kind="new"] .tutorial-offer { padding: 7px 10px; }
.modal[data-kind="new"] .tutorial-offer span { color: var(--ink); font-size: 0.88rem; }
.modal[data-kind="new"] .join-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding-top: 12px; }
.modal[data-kind="new"] .join-row .invite { flex: 1; min-width: 220px; }
.modal[data-kind="new"] .join-row .error { flex-basis: 100%; margin: 0; }
@media (max-width: 680px) {
  .ng-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .modal[data-kind="new"] .modal-card { padding: 14px; gap: 11px; }
  .modal[data-kind="new"] h2 { font-size: 1.5rem; }
  .race-info { min-height: 0; }
}

/* the research screen is long: keep Done in reach at the bottom edge */
.modal[data-kind="research"] .modal-actions { position: sticky; bottom: -20px; margin: 0 -20px -20px; padding: 12px 20px; background: linear-gradient(to top, var(--panel) 70%, transparent); z-index: 2; }
