/* LATTICE overlay. Dark translucent panels over the map; faction colour as accent. */
:root {
  --bg: #04060c;
  --panel: rgba(11, 16, 28, 0.86);
  --panel-solid: #0b101c;
  --line: rgba(110, 126, 170, 0.32);
  --line-strong: rgba(140, 156, 200, 0.55);
  --text: #e2e8f5;
  --muted: #8d97b2;
  --accent: #8fa8ff;
  --good: #63d9a4;
  --warn: #ffb54d;
  --bad: #ff6464;
  --gold: #ffd23a;
  --radius: 8px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden;
  font: 13px/1.4 var(--font); -webkit-font-smoothing: antialiased; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#ui, .game-layer { position: fixed; inset: 0; pointer-events: none; }
#ui > .game-layer > *, .menu-overlay, .toast.solo { pointer-events: auto; }
#ui > .game-layer > .map-labels, #ui > .game-layer > .toasts, #ui > .game-layer > .target-banner { pointer-events: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
b { font-weight: 600; }
h1, h2, h3 { margin: 0; font-weight: 600; }

button, .btn {
  font: inherit; color: var(--text); background: rgba(30, 40, 64, 0.9); border: 1px solid var(--line-strong);
  border-radius: 6px; padding: 6px 12px; cursor: pointer; transition: background 80ms, border-color 80ms;
}
button:hover:not(:disabled), .btn:hover { background: rgba(48, 62, 98, 0.95); border-color: var(--accent); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); color: #060a14; border-color: var(--accent); font-weight: 600; }
button.primary:hover:not(:disabled) { background: #a9bcff; }
button.danger { color: #ffb0b0; border-color: rgba(255, 100, 100, 0.5); background: rgba(80, 20, 28, 0.6); }
button.small { padding: 3px 9px; font-size: 12px; }
button.x { background: none; border: none; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 4px; }
button.x:hover { color: var(--text); background: none; }

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.bar { display: inline-block; position: relative; flex: 1; height: 7px; min-width: 60px; border-radius: 4px;
  background: rgba(255, 255, 255, 0.08); overflow: hidden; vertical-align: middle; }
.bar > i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); border-radius: 4px; }
.bar.good > i { background: var(--good); } .bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--bad); }

/* ── HUD ─────────────────────────────────────────────────────────────────── */
.hud { position: fixed; top: 0; left: 0; right: 0; height: 46px; display: flex; align-items: center; gap: 22px;
  padding: 0 14px; background: linear-gradient(180deg, rgba(8, 12, 22, 0.94), rgba(8, 12, 22, 0.7));
  border-bottom: 1px solid var(--line); }
.hud-faction { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: 0.02em; min-width: 150px; }
.hud-res { display: flex; gap: 18px; }
.res { display: flex; align-items: baseline; gap: 6px; font-variant-numeric: tabular-nums; }
.res i { width: 8px; height: 8px; border-radius: 2px; align-self: center; }
.res.alloys i { background: #e9b45c; } .res.energy i { background: #5fe0c0; } .res.research i { background: #b18cff; }
.res b { font-size: 15px; min-width: 34px; }
.res small { color: var(--muted); font-size: 11px; }
.hud-nexus { display: flex; align-items: center; gap: 8px; margin-left: auto; font-size: 12px; }
.nx-label { color: var(--gold); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; font-size: 11px; }
.nx-side { color: var(--muted); }
.nx-side.holding { color: var(--text); font-weight: 600; }
.hold { display: inline-block; width: 54px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.hold > span { display: block; height: 100%; }
.hold.you > span { background: var(--good); } .hold.them > span { background: var(--bad); }
.nx-warn { color: var(--bad); font-weight: 600; } .nx-good { color: var(--good); font-weight: 600; }
.nx-wait { color: var(--muted); }
.hud-time { display: flex; align-items: center; gap: 10px; }
.clock { font-variant-numeric: tabular-nums; font-size: 15px; min-width: 44px; text-align: right; }
.speed { display: flex; }
.speed button { border-radius: 0; padding: 4px 9px; font-size: 12px; margin-left: -1px; }
.speed button:first-child { border-radius: 6px 0 0 6px; } .speed button:last-child { border-radius: 0 6px 6px 0; }
.speed button.active { background: var(--accent); color: #060a14; border-color: var(--accent); }
.menu-btn { padding: 5px 12px; }

/* ── Panels ──────────────────────────────────────────────────────────────── */
.panel { position: fixed; top: 58px; max-height: calc(100vh - 70px); overflow-y: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; backdrop-filter: blur(8px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45); scrollbar-width: thin; }
.panel.right { right: 12px; width: 330px; }
.panel.left { left: 12px; width: 280px; max-height: calc(100vh - 392px); } /* stops above the feed (max 310 px) */
.panel h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 14px 0 6px; }
.panel section:first-child h3 { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: 8px; }
.card-head h2 { font-size: 16px; flex: 1; }
.sub { color: var(--muted); margin: 2px 0 8px; font-size: 12px; }
.kv { display: flex; align-items: center; gap: 10px; margin: 5px 0; font-size: 12px; }
.kv > span:first-child { color: var(--muted); width: 86px; flex: none; }
.kv b { font-weight: 500; }
.kv [data-v] { font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }
.note { font-size: 12px; color: var(--muted); margin: 8px 0; line-height: 1.45; }
.note.warn { color: var(--warn); } .note.bad { color: var(--bad); }
.build-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.build-grid button.build { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 6px 8px; text-align: left; }
.build-grid button.build small { color: var(--muted); font-size: 11px; }
.build-grid button.build.combat { border-left: 3px solid var(--accent); }
.queue { margin-top: 8px; }
.qrow { display: flex; align-items: center; gap: 8px; font-size: 12px; margin: 3px 0; }
.qrow > span:first-child { width: 110px; }
.fleet-row { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; margin: 3px 0;
  padding: 6px 8px; background: rgba(24, 32, 52, 0.7); font-size: 12px; }
.fleet-row.on { border-color: var(--accent); background: rgba(60, 78, 130, 0.55); }
.fleet-row .txt { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.fleet-row .txt b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.fleet-row .txt small { color: var(--muted); font-size: 11px; }
.fleet-row .kind { width: 6px; height: 22px; border-radius: 3px; flex: none; }
.fleet-row .kind.war { background: var(--accent); } .fleet-row .kind.civ { background: #8aa; }
.st { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.st.moving { color: var(--accent); } .st.busy { color: var(--warn); }
.comp { margin: 6px 0 8px; }
.crow { display: flex; align-items: center; gap: 8px; font-size: 12px; margin: 3px 0; }
.crow .cls { width: 86px; color: var(--muted); }
.crow b { flex: 1; font-weight: 500; }
.step { display: flex; align-items: center; gap: 4px; }
.step button { padding: 0 7px; line-height: 18px; }
.step span { min-width: 16px; text-align: center; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 6px; margin: 4px 0; }
.actions.wrap { flex-wrap: wrap; margin-top: 8px; }
.stance { display: flex; margin: 6px 0; }
.stance button { flex: 1; border-radius: 0; margin-left: -1px; font-size: 12px; padding: 4px 6px; }
.stance button:first-child { border-radius: 6px 0 0 6px; } .stance button:last-child { border-radius: 0 6px 6px 0; }
.stance button.on { background: rgba(143, 168, 255, 0.28); border-color: var(--accent); }
.tech { padding: 7px 0; border-bottom: 1px solid var(--line); }
.tech:last-child { border-bottom: none; }
.tech .th { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 3px; }
.tech small { color: var(--muted); font-size: 11px; display: block; }
.tech.done b { color: var(--good); }
.tech.locked { opacity: 0.55; }
.tech .pill { margin-left: 4px; }
.panel .tier { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin: 8px 0 0; }

/* ── Feed, toasts, banner ────────────────────────────────────────────────── */
.feed { position: fixed; left: 12px; bottom: 12px; width: 360px; max-height: 310px; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; gap: 5px; }
.feed .item { display: flex; gap: 8px; align-items: flex-start; background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 10px; font-size: 12px; animation: rise 160ms ease-out; }
.feed .item > i { width: 7px; height: 7px; border-radius: 50%; margin-top: 5px; flex: none; background: var(--accent); }
.feed .item.good > i { background: var(--good); } .feed .item.warn > i { background: var(--warn); } .feed .item.bad > i { background: var(--bad); }
.feed .item.bad { border-color: rgba(255, 100, 100, 0.45); }
.feed .item > div { flex: 1; }
.feed .item small { color: var(--muted); }
.feed .item .count { color: var(--muted); font-size: 11px; }
.feed .item.go { cursor: pointer; }
.feed .item.go:hover { border-color: var(--accent); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.toasts { position: fixed; top: 56px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; }
.toast { background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: 6px; padding: 7px 14px; font-size: 12px; animation: rise 160ms ease-out; }
.toast.warn { border-color: var(--warn); } .toast.bad { border-color: var(--bad); } .toast.good { border-color: var(--good); }
.toast.solo { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 100; }
.target-banner { position: fixed; top: 56px; left: 50%; transform: translateX(-50%); background: rgba(143, 168, 255, 0.95);
  color: #060a14; font-weight: 600; padding: 7px 16px; border-radius: 6px; }

/* ── Map labels ──────────────────────────────────────────────────────────── */
.map-labels { position: fixed; inset: 0; overflow: hidden; }
.sys-label, .fleet-label { position: absolute; left: 0; top: 0; white-space: nowrap; will-change: transform; }
.sys-label { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px;
  text-shadow: 0 1px 3px #000, 0 0 8px #000; }
.sys-label .n { font-weight: 600; letter-spacing: 0.02em; color: #c5cde0; }
.sys-label .n.nexus { color: var(--gold); }
.sys-label.fog { opacity: 0.55; }
.sys-label .badges { display: flex; gap: 3px; }
.sys-label .b { font-style: normal; font-size: 9px; font-weight: 700; padding: 0 4px; border-radius: 3px; background: rgba(140, 156, 200, 0.25); color: #d8def0; }
.sys-label .b.cap { background: rgba(255, 255, 255, 0.85); color: #060a14; }
.sys-label .b.nx { background: rgba(255, 210, 58, 0.85); color: #060a14; }
.sys-label .b.fort { background: rgba(255, 138, 61, 0.85); color: #060a14; }
.sys-label .b.mine { background: rgba(255, 100, 100, 0.7); color: #060a14; }
.sys-label .tag { font-size: 10px; padding: 0 5px; border-radius: 3px; background: rgba(140, 156, 200, 0.3); }
.sys-label .tag.battle { background: var(--bad); color: #060a14; font-weight: 700; }
.sys-label .tag.warn { background: rgba(255, 181, 77, 0.85); color: #060a14; }
.sys-label .tag.good { background: rgba(99, 217, 164, 0.85); color: #060a14; }
.fleet-label { font-size: 10px; font-weight: 700; padding: 0 4px; border-radius: 3px; background: rgba(8, 12, 22, 0.78);
  color: #dfe6ff; border: 1px solid rgba(143, 168, 255, 0.45); }
.fleet-label.enemy { border-color: rgba(255, 100, 100, 0.6); color: #ffd0d0; }

/* ── Menus ───────────────────────────────────────────────────────────────── */
.menu-overlay { position: fixed; inset: 0; display: grid; place-items: center; z-index: 80;
  background: radial-gradient(ellipse at center, rgba(10, 16, 32, 0.72), rgba(2, 3, 8, 0.92)); backdrop-filter: blur(3px); }
.menu-overlay.scenic { place-items: center start; padding-left: max(16px, 5vw); backdrop-filter: none;
  background: linear-gradient(90deg, rgba(2, 3, 8, 0.82) 0%, rgba(2, 3, 8, 0.5) 48%, rgba(2, 3, 8, 0) 78%); }
.menu-overlay.scenic .menu-card { background: rgba(10, 14, 26, 0.82); backdrop-filter: blur(6px); }
@media (max-width: 900px) { .menu-overlay.scenic { place-items: center; padding-left: 0; } }
.menu-card { width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--panel-solid);
  border: 1px solid var(--line-strong); border-radius: 12px; padding: 28px 32px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6); }
.menu-card h1 { font-size: 34px; letter-spacing: 0.34em; font-weight: 500; }
.menu-card h1.won { color: var(--good); letter-spacing: 0.12em; } .menu-card h1.lost { color: var(--bad); letter-spacing: 0.12em; }
.menu-card h2 { font-size: 20px; margin-bottom: 16px; }
.tagline { color: var(--muted); font-size: 14px; margin: 10px 0 22px; }
.fine { color: var(--muted); font-size: 12px; margin-top: 18px; }
.col-btns { display: flex; flex-direction: column; gap: 8px; max-width: 320px; }
.col-btns > button { padding: 10px 14px; text-align: left; font-size: 14px; }
.row-btns { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.factions { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.faction { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; text-align: left; padding: 16px;
  border: 1px solid var(--line-strong); border-top: 3px solid var(--fc); background: rgba(20, 28, 46, 0.9); }
.faction:hover:not(:disabled) { border-color: var(--fc); background: rgba(30, 40, 64, 0.95); }
.faction .fh { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.faction em { color: var(--muted); font-size: 12px; }
.faction ul { margin: 0; padding-left: 18px; font-size: 12px; line-height: 1.6; }
.faction .go { margin-top: auto; color: var(--fc); font-weight: 600; }
.saves { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.save { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 6px; background: rgba(20, 28, 46, 0.8); }
.save small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.save .row-btns { margin: 0; flex-wrap: nowrap; }
.pill { font-size: 10px; padding: 0 6px; border-radius: 8px; background: rgba(143, 168, 255, 0.25); color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; color: var(--muted); font-size: 12px; max-width: 360px; }
select, input[type=text] { font: inherit; color: var(--text); background: #111829; border: 1px solid var(--line-strong); border-radius: 6px; padding: 7px 9px; }
.save-as { display: flex; gap: 6px; }
.save-as input { flex: 1; }
.howto p { margin: 0 0 10px; line-height: 1.55; color: #cfd6e6; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 8px 0; }
.stats > div { background: rgba(20, 28, 46, 0.8); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; }
.stats b { font-size: 20px; display: block; }
.stats small { color: var(--muted); }

@media (max-width: 1100px) {
  .hud-faction { display: none; }
  .panel.left { width: 240px; }
  .panel.right { width: 300px; }
}

/* Planet screen (A-06): title over the 3D system view; the system card stays on the right. */
.card-head .view { margin-left: auto; margin-right: 6px; font-size: 12px; padding: 3px 9px; border-radius: 6px;
  background: rgba(120, 150, 255, 0.16); border: 1px solid rgba(140, 170, 255, 0.4); color: var(--text, #e2e8f5); cursor: pointer; }
.card-head .view:hover { background: rgba(120, 150, 255, 0.3); }
.planet-screen { position: fixed; left: 0; right: 0; top: 58px; text-align: center; pointer-events: none; }
.planet-screen.hidden { display: none; }
.planet-screen .back { pointer-events: auto; position: fixed; left: 304px; top: 62px; padding: 7px 14px; border-radius: 8px;
  background: rgba(10, 14, 28, 0.82); border: 1px solid rgba(140, 170, 255, 0.35); color: #e2e8f5; font: inherit; cursor: pointer; }
.planet-screen .back:hover { background: rgba(40, 54, 100, 0.9); }
.planet-screen h1 { margin: 6px 0 2px; font-size: 30px; font-weight: 600; letter-spacing: 0.06em; text-shadow: 0 2px 18px rgba(0, 0, 0, 0.9); }
.planet-screen .tags { font-size: 13px; color: #b8c2dc; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.9); }
.planet-screen .owner { color: var(--c); font-weight: 600; }
.planet-screen .battle, .planet-screen .fog { display: inline-block; margin-top: 8px; padding: 3px 10px; border-radius: 999px; font-size: 12px; }
.planet-screen .battle { background: rgba(255, 70, 50, 0.22); border: 1px solid rgba(255, 90, 70, 0.6); color: #ffb0a0; }
.planet-screen .fog { background: rgba(120, 130, 160, 0.18); border: 1px solid rgba(150, 160, 190, 0.35); color: #b8c2dc; margin-left: 6px; }
@media (max-width: 1100px) { .planet-screen .back { left: 264px; } }
