:root {
  --bg: #0b1020;
  --bg2: #121a30;
  --panel: rgba(18, 26, 48, 0.94);
  --panel-border: #2a3a5e;
  --text: #dde6f5;
  --muted: #8fa0c0;
  --accent: #4fd1c5;
  --accent2: #6ba4ff;
  --danger: #ff6b6b;
  --warn: #ffcf5c;
  --ok: #7bd88f;
  --metal: #cbd5e1;
  --energy: #ffd45c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  user-select: none;
}

#game-canvas {
  position: fixed;
  inset: 0;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.hidden { display: none !important; }

/* ---------- Screens (menu/lobby/result) ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 30%, #16203c 0%, #0b1020 70%, #070b16 100%);
  z-index: 50;
}

.menu-card {
  width: min(760px, 92vw);
  max-height: 92vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 28px 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.confirmation-popup { width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; color: var(--text); background: #121a30; border: 1px solid var(--panel-border); border-radius: 14px; box-shadow: 0 20px 60px #0009; }
.confirmation-popup::backdrop { background: rgba(0, 0, 0, .2); }
.confirmation-card { padding: 24px; }
.confirmation-card h2 { margin: 0 0 12px; font-size: 21px; }
.confirmation-card p { color: var(--muted); line-height: 1.6; margin: 0; }
.confirmation-card .menu-actions { justify-content: flex-end; gap: 8px; margin: 22px 0 0; }

.logo {
  font-size: 46px;
  letter-spacing: 6px;
  margin: 0 0 4px;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(79, 209, 197, 0.35);
}
.tagline { color: var(--muted); margin: 0 0 20px; }

.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.field > span { color: var(--muted); font-size: 12px; }
.field.row { flex-direction: row; align-items: center; gap: 8px; }

input[type="text"], select {
  background: #0e1526;
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 15px;
  outline: none;
}
input[type="text"]:focus, select:focus { border-color: var(--accent2); }

.menu-actions { display: flex; gap: 12px; margin: 18px 0; flex-wrap: wrap; }
.menu-footer { display: flex; justify-content: flex-end; margin-top: 4px; }

.menu-split { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 8px; }
.menu-col { background: #0e1526; border: 1px solid var(--panel-border); border-radius: 10px; padding: 14px 16px; }
.menu-col h3 { margin: 0 0 8px; color: var(--accent2); }
.credits { margin-top: 10px; color: var(--muted); font-size: 12px; }
.credits summary { width: fit-content; cursor: pointer; }
.credits ul { margin: 8px 0 0; padding-left: 18px; line-height: 1.7; }
.credits a { color: var(--accent2); }

.btn {
  background: #1c2947;
  color: var(--text);
  border: 1px solid var(--panel-border);
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.12s, border 0.12s, transform 0.05s;
}
.btn:hover { background: #24365c; border-color: var(--accent2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(180deg, #2f8f86, #23726b); border-color: #3fb0a4; color: #eafffb; }
.btn.primary:hover { background: linear-gradient(180deg, #37a89d, #2a857d); }
.btn.big { padding: 14px 22px; font-size: 16px; font-weight: 600; }
.btn.danger { background: #5a2330; border-color: #a23b4d; }
.btn.danger:hover { background: #7a2c3e; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.settings-card { width: min(520px, 92vw); padding: 0; }
.settings-head { padding: 16px 20px; }
.settings-head h2 { margin: 0; font-size: 20px; }
.settings-body { padding: 4px 20px 0; }
.settings-section { padding: 12px 0 4px; }
.settings-section + .settings-section { border-top: 1px solid var(--panel-border); }
.settings-section h3 { margin: 0 0 4px; color: var(--accent2); }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 54px; border-top: 1px solid rgba(42, 58, 94, 0.55); }
.settings-row span { display: flex; flex-direction: column; gap: 3px; }
.settings-row small { color: var(--muted); font-size: 12px; }
.settings-row.disabled { opacity: 0.55; }
.settings-row input[type="range"] { width: 150px; accent-color: var(--accent); }
.settings-actions { justify-content: flex-end; padding: 0 20px 20px; margin-bottom: 0; }

.status { color: var(--warn); min-height: 18px; margin: 8px 0 0; }
.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
.code { color: var(--accent); font-family: monospace; letter-spacing: 3px; }
.room-share-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.room-share-head h2 { margin: 0; }
.room-link-field { margin: 12px 0; }
.room-link-row { display: flex; gap: 8px; }
.room-link-row input { flex: 1; min-width: 0; font-size: 12px; user-select: text; }
.room-link-row .btn { flex: 0 0 auto; }

.lobby-players { list-style: none; padding: 0; margin: 12px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.lobby-players li { background: #0e1526; border: 1px solid var(--panel-border); border-radius: 6px; padding: 6px 10px; display: flex; align-items: center; gap: 8px; }
.lobby-players li.disconnected { opacity: .65; }
.lobby-player-state { margin-left: auto; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.lobby-player-state.ready { color: var(--ok); }
.lobby-player-state.disconnected { color: var(--warn); }
.lobby-ready-summary { min-height: 20px; color: var(--muted); margin: 10px 0 0; }
.swatch { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }

.connection-status {
  position: fixed; z-index: 100; top: 56px; left: 50%; transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 24px)); padding: 9px 14px;
  color: #fff3d0; background: rgba(67, 51, 17, .97); border: 1px solid var(--warn); border-radius: 6px;
  box-shadow: 0 8px 24px #0008; text-align: center; pointer-events: none;
}
.connection-status.ok { color: #dcffe4; background: rgba(24, 67, 37, .97); border-color: var(--ok); }
.connection-status.error { color: #ffe1e4; background: rgba(79, 25, 35, .97); border-color: var(--danger); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
#hud .panel, #hud button, #hud #feed, #hud #warnings, #topbar, #toolbar, #spectator-bar { pointer-events: auto; }

#topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 46px;
  display: flex; align-items: center; gap: 18px;
  background: linear-gradient(180deg, rgba(11,16,32,0.96), rgba(11,16,32,0.75));
  border-bottom: 1px solid var(--panel-border);
  padding: 0 16px;
}
#topbar .res { display: flex; align-items: center; gap: 6px; font-weight: 600; }
#topbar .res small { color: var(--muted); font-weight: 400; }
#topbar .res.small { font-weight: 400; }
#topbar .res small .inc { color: var(--ok); font-weight: 600; }
#topbar .spacer { flex: 1; }
#topbar .attack-status { margin-left: auto; flex: 0 0 auto; flex-direction: column; align-items: flex-end; gap: 1px; line-height: 1.1; }
#topbar .attack-status small { white-space: nowrap; }
#topbar #identity-focus { display: flex; flex: 0 0 auto; align-items: center; gap: 9px; min-height: 34px; padding: 4px 9px; color: #eef7ec; background: #202e23; border: 1px solid #5b754d; border-radius: 6px; cursor: pointer; }
#topbar #identity-focus:hover { background: #2b3d2d; border-color: #b6e88b; }
#res-you { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.identity-you { color: #b6e88b; font-size: 10px; font-weight: 800; letter-spacing: .08em; }
.identity-symbol { font-size: 13px; line-height: 1; }
.identity-name { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 600; }
.identity-out { color: #ff9c9c; font-size: 9px; font-weight: 800; letter-spacing: .06em; }
.identity-locate { color: #b6e88b; font-size: 18px; line-height: 1; }
.ico { font-size: 15px; }
.ico.metal { color: var(--metal); }
.ico.energy { color: var(--energy); }
.ico.cap { color: var(--accent2); }
.ico.hq { color: var(--warn); }
.ico.resource-icon { display: block; width: 15px; height: 15px; flex: none; object-fit: contain; }
.inline-icon { width: 16px; height: 16px; object-fit: contain; vertical-align: -3px; margin-right: 3px; }
.scoreboard-icon { width: 13px; height: 13px; object-fit: contain; vertical-align: middle; }
.diplomacy-icon { width: 15px; height: 15px; object-fit: contain; vertical-align: middle; }

.spectator-bar {
  position: absolute; left: 50%; bottom: 56px; transform: translateX(-50%);
  min-height: 38px; display: flex; align-items: center; gap: 8px; padding: 5px 7px 5px 12px;
  color: var(--text); background: rgba(14, 21, 38, .96); border: 1px solid var(--accent2); border-radius: 6px;
  box-shadow: 0 8px 24px #0008;
}
.spectator-bar strong { color: var(--accent2); font-size: 11px; text-transform: uppercase; }
.spectator-bar span { min-width: 130px; text-align: center; font-weight: 600; }
.spectator-bar button { width: 30px; height: 28px; padding: 0; color: var(--text); background: #1c2947; border: 1px solid var(--panel-border); border-radius: 5px; cursor: pointer; font-size: 18px; }
.spectator-bar button:hover { border-color: var(--accent2); }

.panel {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 0;
  width: 300px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.45);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; background: #16203c; border-bottom: 1px solid var(--panel-border);
  font-weight: 600;
}
.panel-head .x { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; }
.panel-head .x:hover { color: var(--danger); }

#panel-context { right: 12px; top: 58px; }
#panel-split { right: 12px; bottom: 56px; width: 240px; padding-bottom: 10px; }
#panel-drone { right: 12px; bottom: 56px; width: 260px; }
#panel-diplo { left: 12px; top: 58px; width: 320px; }

#drone-body { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
#drone-body input[type="range"] { width: 100%; }
#drone-body { max-height: min(55vh, 480px); overflow-y: auto; }
.drone-health-list { display: grid; gap: 6px; }
.drone-health-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 0; border-bottom: 1px solid #344239; font-size: 11px; }
.drone-health-row meter { width: 70px; }
#drone-body .drone-count { font-weight: 600; color: var(--accent); }

#ctx-body, #diplo-body { padding: 12px; display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow: auto; }

.build-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: #0e1526; border: 1px solid var(--panel-border); border-radius: 8px; padding: 8px 10px; }
.build-item .bi-info { display: flex; flex-direction: column; gap: 2px; }
.build-item .bi-name { font-weight: 600; }
.build-item .bi-cost { font-size: 12px; color: var(--muted); }
.build-item button { padding: 6px 12px; }
.build-item.disabled { opacity: 0.55; }
.build-item .lvl { color: var(--warn); font-weight: 700; font-size: 11px; }

.split-btns { display: flex; gap: 8px; padding: 12px; }
.split-btns .btn.split { flex: 1; text-align: center; }
.split-btns .btn.split.active { border-color: var(--accent); background: #234; }

#scoreboard { left: 12px; bottom: 56px; width: min(380px, calc(100vw - 24px)); font-size: 12px; }
#scoreboard .panel-head small { color: var(--muted); font-size: 10px; font-weight: 400; }
.scoreboard-scroll { max-height: 34vh; overflow: auto; }
#scoreboard table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
#scoreboard th, #scoreboard td { padding: 8px; text-align: right; border-bottom: 1px solid #ffffff08; }
#scoreboard th:first-child { text-align: left; }
#scoreboard thead { position: sticky; top: 0; background: #121a30; color: var(--muted); font-size: 10px; text-transform: uppercase; }
#scoreboard tbody th { font-weight: 500; }
.scoreboard-player { display: flex; align-items: center; gap: 7px; }
.scoreboard-player .swatch { flex-shrink: 0; width: 10px; height: 10px; }
.scoreboard-rank { width: 14px; color: var(--muted); font-size: 10px; }
.scoreboard-name { max-width: 124px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scoreboard-player small { font-size: 9px; color: var(--muted); }
#scoreboard .is-you { background: #6ba4ff12; }
#scoreboard .is-out { opacity: .5; }
.territory-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.owner-chip { padding: 2px 7px; border-radius: 5px; background: #ffffff0b; border: 1px solid currentColor; font-weight: 600; overflow-wrap: anywhere; }
@keyframes fadein { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; } }

#warnings { position: absolute; top: 56px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; }
.warning {
  background: rgba(90, 30, 40, 0.92); border: 1px solid var(--danger); color: #ffdfe2;
  padding: 8px 16px; border-radius: 20px; cursor: pointer; font-weight: 600;
  animation: pulse 1.1s infinite;
}
.warning.air { background: rgba(90, 70, 20, 0.92); border-color: var(--warn); color: #fff3d0; }
.warning.front { background: rgba(25, 45, 67, 0.94); border-color: #55b8e8; color: #dff6ff; animation: none; }
.warning.production { background: rgba(22, 58, 52, 0.94); border-color: #54d6b0; color: #dffff5; animation: none; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,107,107,0.5);} 50% { box-shadow: 0 0 0 8px rgba(255,107,107,0);} }

#toolbar {
  position: absolute; left: 0; right: 0; bottom: 0; height: 46px;
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  background: linear-gradient(0deg, rgba(11,16,32,0.96), rgba(11,16,32,0.65));
  border-top: 1px solid var(--panel-border);
}
.tool { background: #1c2947; border: 1px solid var(--panel-border); color: var(--text); padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.tool:hover { border-color: var(--accent2); }
.tool-exit { border-color: #70404a; color: #ffb4bd; }
.tool-exit:hover { border-color: var(--danger); background: #5a2330; }
.hint-bar { color: var(--muted); font-size: 12px; margin-left: auto; }

.result-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 16px 0; }
.result-stats .stat { background: #0e1526; border: 1px solid var(--panel-border); border-radius: 8px; padding: 10px 12px; }
.result-stats .stat b { color: var(--accent); font-size: 20px; display: block; }
.result-note { color: var(--muted); line-height: 1.5; }
.result-note:empty { display: none; }
#result-title.win { color: var(--ok); }
#result-title.lose { color: var(--danger); }

.tooltip {
  position: fixed; z-index: 60; pointer-events: none;
  background: rgba(8,12,24,0.97); border: 1px solid var(--panel-border);
  border-radius: 8px; padding: 8px 10px; max-width: 260px; font-size: 12px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.5); line-height: 1.4;
}
.tooltip b { color: var(--accent2); }
.tag { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; background: #23324f; margin-right: 4px; }
/* Lightweight menu: system type, flat surfaces, no media downloads. */
#screen-menu { background: #101713; overflow-y: auto; padding: 32px 20px; }
#screen-menu .menu-card { width: min(580px, 100%); max-height: none; margin: auto; background: transparent; border: 0; border-radius: 0; padding: 20px; box-shadow: none; overflow: visible; }
#screen-menu .eyebrow { color: #b6e88b; font-size: 10px; font-weight: 600; letter-spacing: 3px; margin: 0 0 24px; }
#screen-menu .logo { color: #edf1e9; font-size: clamp(48px, 10vw, 76px); line-height: .95; letter-spacing: -4px; font-weight: 800; text-shadow: none; display: flex; gap: 14px; margin-bottom: 22px; }
#screen-menu .logo span { color: #b6e88b; }
#screen-menu .tagline { color: #9ca99f; max-width: 360px; line-height: 1.7; font-size: 15px; margin-bottom: 32px; }
#screen-menu .field { gap: 8px; margin: 14px 0; }
#screen-menu .field > span { color: #a8b4ab; }
#screen-menu input[type=text], #screen-menu select { background: #18221c; border-color: #344239; border-radius: 5px; min-width: 0; width: 100%; }
#screen-menu .btn { background: #1b271f; border-color: #344239; border-radius: 5px; }
#screen-menu .btn:hover { background: #28392d; border-color: #8ab16c; }
#screen-menu .menu-actions { margin: 20px 0 0; }
#screen-menu .btn.primary { display: flex; justify-content: space-between; width: 100%; background: #b6e88b; color: #172211; border-color: #b6e88b; padding: 17px 20px; }
#screen-menu .btn.primary:hover { background: #c8f5a3; }
.launch-note { color: #819086; font-size: 12px; line-height: 1.6; margin: 10px 0 22px; }
#screen-menu .menu-footer { gap: 8px; justify-content: flex-start; margin-bottom: 26px; }
#screen-menu .menu-footer .btn { background: transparent; color: #a8b4ab; padding: 7px 12px; font-size: 12px; }
.room-options { border-top: 1px solid #344239; padding-top: 18px; }
.room-options summary { cursor: pointer; color: #dce5d9; padding: 4px 0; font-size: 13px; }
.room-browser { margin-top: 14px; border-top: 1px solid #28362d; padding-top: 14px; }
.room-browser-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.room-browser-head h3 { margin: 0; color: #c4d1c5; font-size: 13px; }
.room-browser-head .hint { margin: 4px 0 0; }
#screen-menu .room-browser-head .btn { padding: 7px 12px; font-size: 12px; }
.open-rooms { list-style: none; display: grid; gap: 7px; padding: 0; margin: 12px 0 0; }
.open-room { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 10px; border: 1px solid #344239; border-radius: 5px; background: #18221c; }
.open-room-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.open-room-info b { color: #e4ece3; font-family: monospace; letter-spacing: 1px; }
.open-room-info small, .room-empty { color: #9ca99f; font-size: 12px; }
.open-room .btn { flex: 0 0 auto; padding: 7px 12px; }
.room-empty { padding: 8px 0; }
#screen-menu .menu-col { background: transparent; border: 0; padding: 12px 0; min-width: 0; }
#screen-menu .menu-col h3 { font-size: 13px; color: #c4d1c5; }
#screen-menu .menu-col input[type=checkbox] { align-self: flex-start; accent-color: #b6e88b; }
.menu-meta { display: flex; justify-content: space-between; border-top: 1px solid #28362d; margin-top: 22px; padding-top: 18px; font-size: 9px; letter-spacing: 1.5px; color: #7d8d81; }
button:focus-visible, summary:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid #b6e88b; outline-offset: 4px; }
@media (max-width: 440px) { #screen-menu .menu-card { padding: 10px 0; } #screen-menu .menu-split { grid-template-columns: 1fr; gap: 0; } }
@media (prefers-reduced-motion: reduce) { .btn { transition: none; } }

#res-penalty { color: var(--warn); font-size: 12px; }
/* In-game UI: quiet surfaces, consistent controls, unobstructed map input. */
#hud { --panel: #141e19; --panel-border: #344239; --text: #edf1e9; --muted: #a0afa4; --accent: #b6e88b; --accent2: #b6e88b; color: var(--text); }
#topbar { height: 52px; gap: 20px; background: #111a15; border-color: #344239; }
#topbar .res { white-space: nowrap; font-variant-numeric: tabular-nums; }
#hud .panel { border-radius: 8px; box-shadow: 0 8px 24px #0003; z-index: 2; }
#hud .panel-head { background: transparent; padding: 10px 14px; font-size: 13px; }
#hud .panel-head .x { width: 30px; height: 30px; border-radius: 5px; }
#hud .panel-head .x:hover { background: #26382b; color: var(--text); }
.panel-head-tools { display: flex; align-items: center; gap: 4px; }
.panel-drag-handle { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 26px; color: #89978d; cursor: grab; user-select: none; touch-action: none; font-size: 18px; line-height: 1; }
.panel-drag-handle:active { cursor: grabbing; color: var(--accent); }
#panel-context { top: 64px; left: auto; right: 12px; width: 340px; max-height: calc(100dvh - 140px); display: flex; flex-direction: column; }
#hud:has(#panel-split:not(.hidden)) #panel-context { max-height: calc(100dvh - 280px); }
#panel-split, #panel-drone { bottom: 76px; right: 12px; width: 340px; }
#panel-split { left: 50%; top: auto; right: auto; bottom: 76px; width: 300px; padding-bottom: 8px; transform: translateX(-50%); }
#panel-diplo { top: 64px; left: auto; right: 12px; width: 320px; max-height: calc(100dvh - 140px); display: flex; flex-direction: column; }
#ctx-body, #diplo-body { min-height: 0; max-height: none; padding: 12px; gap: 10px; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #526756 transparent; }
#hud .build-item { border: 0; border-bottom: 1px solid #2a382e; border-radius: 0; padding: 10px 0; background: transparent; flex-wrap: wrap; }
#hud .bi-info { flex: 1 1 150px; min-width: 0; line-height: 1.5; }
#hud .bi-name { font-size: 13px; }
#hud .build-item > span:last-child { display: flex; flex-wrap: wrap; gap: 5px; }
#hud button { font: inherit; font-size: 12px; color: var(--text); background: #223027; border: 1px solid #415447; border-radius: 5px; min-height: 34px; padding: 7px 10px; cursor: pointer; transition: background .12s; }
#hud button:hover:not(:disabled) { background: #304534; border-color: #b6e88b; }
#hud button:disabled { opacity: .4; cursor: not-allowed; }
#hud button[data-act^="prod:"] { background: #b6e88b; border-color: #b6e88b; color: #172211; font-weight: 600; }
#hud button[data-act^="prod:"]:hover:not(:disabled) { background: #cef5af; }
#hud button[data-act="demolish"], #hud .danger, #hud .tool-exit { color: #ffb4bd; }
#hud .build-item.disabled { opacity: 1; }
#hud .split-btns { padding: 8px 10px 0; }
#hud .split-btns .active { color: #b6e88b; background: #30412a; border-color: #b6e88b; }
#split-hint { margin: 7px 10px 0; }
#toolbar { height: 52px; bottom: 12px; left: 12px; right: auto; max-width: calc(100% - 24px); background: #111a15; border: 1px solid #344239; border-radius: 8px; padding: 8px; gap: 6px; z-index: 3; }
#toolbar .hint-bar { display: none; }
#hud #feed { pointer-events: none; bottom: 80px; width: min(300px, 35vw); max-height: 22vh; opacity: .85; }
#hud:has(#panel-diplo:not(.hidden)) #feed { visibility: hidden; }
#hud #warnings { pointer-events: none; top: 64px; max-width: calc(100% - 720px); z-index: 1; }
#hud .warning { pointer-events: auto; border-radius: 6px; font-size: 12px; animation: none; padding: 8px 12px; }
#hud .tag { background: #293e30; cursor: pointer; }
@media (max-width: 1000px) {
  #topbar { gap: 12px; padding: 0 12px; overflow-x: auto; }
  #topbar .spacer { display: none; }
  #topbar #identity-focus { display: flex; }
  #topbar .res { font-size: 12px; }
  #topbar .res small { font-size: 10px; }
  #hud #warnings { max-width: calc(100% - 380px); left: 12px; transform: none; }
}
#mobile-queue, .mobile-only { display: none !important; }
@media (max-width: 720px) and (pointer: coarse) {
  .mobile-only { display: inline-flex !important; }
}
@media (max-width: 720px) {
  #topbar { height: calc(48px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 8px 0; gap: 14px; scrollbar-width: none; }
  #topbar::-webkit-scrollbar, #toolbar::-webkit-scrollbar { display: none; }
  #topbar .res { gap: 4px; font-size: 12px; }
  #topbar .res small { display: none; }
  #topbar #identity-focus { gap: 6px; padding: 3px 7px; }
  #topbar .identity-name { max-width: 76px; font-size: 11px; }
  #panel-context, #panel-split, #panel-drone {
    left: 8px; right: 8px; width: auto; max-width: none;
    border-radius: 10px;
  }
  #panel-diplo { left: 8px; right: 8px; width: auto; max-width: none; }
  #panel-context { top: auto; bottom: calc(62px + env(safe-area-inset-bottom)); max-height: min(56dvh, 650px); }
  #panel-split { left: 8px; right: 8px; top: auto; bottom: calc(62px + env(safe-area-inset-bottom)); width: auto; max-height: min(30dvh, 250px); overflow-y: auto; transform: none; }
  #panel-drone { top: auto; bottom: calc(62px + env(safe-area-inset-bottom)); max-height: min(54dvh, 600px); }
  #panel-diplo { top: calc(54px + env(safe-area-inset-top)); bottom: calc(62px + env(safe-area-inset-bottom)); max-height: none; }
  #hud:has(#panel-split:not(.hidden)) #panel-context {
    bottom: calc(72px + min(30dvh, 250px) + env(safe-area-inset-bottom));
    max-height: min(38dvh, 440px);
  }
  #ctx-body, #diplo-body { max-height: 48dvh; overflow-y: auto; overscroll-behavior: contain; }
  #panel-split #split-hint { margin-bottom: 8px; }
  #panel-drone #drone-body { max-height: 50dvh; }
  #hud:has(#panel-diplo:not(.hidden)) #panel-context,
  #hud:has(#panel-diplo:not(.hidden)) #panel-split,
  #hud:has(#panel-diplo:not(.hidden)) #panel-drone { display: none; }
  #toolbar { left: 8px; right: 8px; bottom: env(safe-area-inset-bottom); width: auto; max-width: none; height: 48px; padding: 4px; gap: 5px; overflow-x: auto; white-space: nowrap; scrollbar-width: none; }
  #toolbar button { flex-shrink: 0; min-height: 38px; padding: 7px 10px; }
  #hud #scoreboard-toggle { top: calc(58px + env(safe-area-inset-top)); bottom: auto; }
  #hud #scoreboard { top: calc(96px + env(safe-area-inset-top)); bottom: auto; }
  #hud #feed { display: none; }
  #hud #warnings { max-width: calc(100% - 24px); top: auto; bottom: calc(58px + env(safe-area-inset-bottom)); max-height: 24dvh; overflow-y: auto; }
  #hud .warning { max-width: 100%; min-height: 40px; }
  #alliance-notices { top: calc(54px + env(safe-area-inset-top)); left: 8px; right: 8px; width: auto; max-height: 35dvh; transform: none; }
  #hud button { min-height: 40px; }
}
#hud .split-range { display: grid; gap: 6px; padding: 9px 12px 0; font-size: 12px; }
#hud .split-range > span { display: flex; justify-content: space-between; }
#split-percent { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
#split-slider { width: 100%; margin: 0; accent-color: var(--accent); cursor: pointer; }
#split-count { color: var(--muted); font-variant-numeric: tabular-nums; }
#hud:has(#panel-split:not(.hidden)) #panel-context { max-height: calc(100dvh - 360px); }
@media (max-width: 720px) {
  #hud:has(#panel-split:not(.hidden)) #panel-context { max-height: min(38dvh, 440px); }
}
/* Narrow desktop windows keep the panels floating so mouse users retain direct map access. */
@media (max-width: 720px) and (pointer: fine) {
  #panel-context, #panel-split {
    width: min(340px, calc(100vw - 96px));
    max-width: none;
  }
  #panel-context {
    left: auto;
    right: 12px;
    top: 64px;
    bottom: auto;
    max-height: calc(100dvh - 140px);
  }
  #panel-split {
    left: 50%;
    right: auto;
    top: auto;
    bottom: calc(62px + env(safe-area-inset-bottom));
    width: min(300px, calc(100vw - 96px));
    max-height: calc(100dvh - 48px);
    transform: translateX(-50%);
  }
  #hud:has(#panel-split:not(.hidden)) #panel-context {
    top: 64px;
    bottom: auto;
    max-height: calc(100dvh - 140px);
  }
}
#hud .production-batches { width: 100%; display: grid; gap: 14px; }
#hud .production-batch { display: grid; gap: 8px; border-top: 1px solid #344239; padding-top: 12px; }
#hud .production-batch label { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; }
#hud .production-batch label span { color: var(--accent); font-variant-numeric: tabular-nums; }
#hud .production-batch input { width: 100%; margin: 0; accent-color: var(--accent); cursor: pointer; }
#hud .production-batch input:disabled { opacity: .4; cursor: not-allowed; }
#hud .production-order { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
#hud .production-order small { color: var(--muted); font-size: 11px; line-height: 1.5; }
#hud .production-order button { flex-shrink: 0; }

#alliance-notices { position: absolute; top: 120px; left: 50%; transform: translateX(-50%); width: min(330px, calc(100vw - 24px)); max-height: 45vh; overflow-y: auto; z-index: 5; pointer-events: auto; display: grid; gap: 8px; }
.alliance-notice { background: #17271f; border: 1px solid #b6e88b; border-radius: 8px; padding: 14px; box-shadow: 0 8px 28px #0008; line-height: 1.6; }
.alliance-notice b { color: #c9f3a7; }
.dev-toggle { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.surrender-vote { position: absolute; z-index: 8; top: 72px; left: 50%; transform: translateX(-50%); width: min(410px, calc(100vw - 24px)); padding: 14px; border: 1px solid #e6bd72; border-radius: 8px; background: #28251ddd; box-shadow: 0 8px 28px #0008; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.surrender-vote p { flex-basis: 100%; margin: 0; color: #ddd5c4; font-size: 12px; }
.surrender-vote button { flex: 1; min-height: 38px; border: 1px solid #82927f; border-radius: 5px; background: #243b2a; color: #f2f3e9; cursor: pointer; }
.surrender-vote button[data-vote="no"] { background: #49302a; }
@media (max-width: 700px) { #alliance-notices { top: 60px; } }

/* Compact, optional scoreboard. Keep the map visible around it. */
#hud #scoreboard-toggle { position: absolute; left: 12px; top: 58px; bottom: auto; width: 28px; min-height: 28px; height: 28px; padding: 0; font-size: 21px; line-height: 1; background: #1c2731dd; border-color: #657784; }
#hud #scoreboard-toggle[aria-expanded="true"] { color: #b6e88b; border-color: #b6e88b; }
#hud #scoreboard { left: 12px; top: 94px; bottom: auto; width: max-content; max-width: calc(100vw - 24px); border-radius: 5px; background: #1a2632ed; border: 1px solid #526372; box-shadow: 0 4px 12px #0003; font-size: 11px; }
#hud #scoreboard .panel-head { padding: 3px 7px; min-height: 26px; background: #293744; font-size: 11px; border-bottom: 1px solid #526372; }
#hud #scoreboard .panel-head > span:last-child { display: flex; gap: 4px; margin-left: 16px; }
#hud #scoreboard .panel-head button { min-height: 22px; height: 22px; padding: 0 5px; background: transparent; border: 0; color: #aab9c7; }
#scoreboard .scoreboard-scroll { max-height: min(230px, calc(100dvh - 340px)); overflow: auto; scrollbar-width: thin; }
#hud #scoreboard th, #hud #scoreboard td { padding: 5px 7px; border-right: 1px solid #53637255; border-bottom: 1px solid #53637288; white-space: nowrap; }
#hud #scoreboard thead { background: #354454; font-size: 12px; color: #dce5ef; }
#scoreboard tbody tr:nth-child(even) { background: #ffffff04; }
#scoreboard .scoreboard-name { max-width: 105px; }
#scoreboard .scoreboard-player { gap: 5px; }
#scoreboard-options { padding: 8px; display: flex; flex-wrap: wrap; gap: 8px 12px; max-width: 330px; border-bottom: 1px solid #526372; background: #263541; }
#scoreboard-options label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
#scoreboard-options input { margin: 0; accent-color: #b6e88b; }

#mobile-command-bar { display: none; }
@media (max-width: 720px) {
  #mobile-command-bar {
    display: flex; position: absolute; left: 8px; right: 8px;
    bottom: calc(52px + env(safe-area-inset-bottom)); min-height: 48px;
    align-items: center; gap: 8px; padding: 4px 6px 4px 10px;
    overflow: hidden; border: 1px solid #485747; border-radius: 7px;
    background: #111a15f2; box-shadow: 0 4px 16px #0006; pointer-events: auto; z-index: 4;
  }
  #mobile-command-label { flex: 1 1 auto; min-width: 82px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; color: #d7e1d7; }
  #mobile-command-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 4px; overflow-x: auto; scrollbar-width: none; }
  #mobile-command-actions::-webkit-scrollbar { display: none; }
  #mobile-command-actions button { flex: 0 0 auto; min-height: 38px; padding: 5px 9px; font-size: 11px; white-space: nowrap; }
  #mobile-command-actions button.active { color: #172211; background: #b6e88b; border-color: #b6e88b; }
  #mobile-command-actions button:disabled { opacity: .4; }
  #mobile-command-actions .mobile-fractions { display: flex; gap: 3px; }
}

.tutorial-dialog { width: min(960px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; color: var(--text); background: #141e18; border: 1px solid #415447; border-radius: 12px; box-shadow: 0 24px 80px #0009; }
.tutorial-dialog::backdrop { background: #0009; }
.tutorial-dialog > .panel-head { background: #1c2a20; }
.tutorial-dialog h2 { margin: 0; font-size: 20px; }
.tutorial-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); }
#tutorial-lessons { padding: 16px; display: flex; flex-direction: column; gap: 7px; border-right: 1px solid #344239; }
#tutorial-lessons button { text-align: left; font-size: 12px; background: transparent; border-color: transparent; }
#tutorial-lessons button[aria-current="true"] { background: #2a3b2c; border-color: #799c64; color: #c6eeaa; }
.tutorial-layout article { padding: 24px; min-width: 0; }
.tutorial-layout h3 { margin: 6px 0 16px; font-size: 23px; }
#tutorial-description { line-height: 1.7; }
#tutorial-controls { line-height: 1.6; }
.tutorial-preview { position: relative; margin-bottom: 12px; overflow: auto; border: 1px solid #415447; border-radius: 8px; background: repeating-linear-gradient(0deg, transparent 0 31px, #ffffff04 31px 32px), repeating-linear-gradient(90deg, #101813 0 31px, #ffffff04 31px 32px); }
.training-objective { padding: 12px; border-left: 3px solid #d4b768; background: #d4b7680b; line-height: 1.5; }
.training-objective.complete { border-color: #b6e88b; color: #c6eeaa; background: #b6e88b0b; }
.training-resources { display: flex; flex-wrap: wrap; gap: 12px; padding: 10px 12px; background: #1e2a23; font-size: 12px; font-variant-numeric: tabular-nums; }
.training-resources small { color: #a7b4a8; }
.training-resources > small { margin-left: auto; }
.training-map { position: relative; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 30px; padding: 32px 18px 18px; min-height: 224px; min-width: 330px; }
.training-map::before { content: ""; position: absolute; top: 92px; left: 15%; right: 15%; height: 4px; background: #546957; }
.training-node { position: relative; z-index: 1; text-align: center; }
.training-territory { width: 100%; min-height: 136px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; border: 2px solid #627181; border-radius: 14px; color: #e3eae3; background: #26313b; cursor: pointer; font: inherit; font-size: 11px; padding: 8px 4px; }
.training-territory.owner-you { background: #243d2b; border-color: #749e5f; }
.training-territory.owner-ally { background: #243d55; border-color: #6ba4ff; }
.training-territory.selected { outline: 2px solid #eef7de; outline-offset: 4px; }
.training-territory:hover { filter: brightness(1.2); }
.training-territory:focus-visible, .training-move:focus-visible { outline: 2px solid white; outline-offset: 4px; }
.training-territory small { color: #b3c0b5; }
.training-glyph { font-size: 26px; color: #c6eeaa; }
.training-army { padding: 3px 12px; background: #0004; border-radius: 5px; font-size: 14px; }
.training-move { margin-top: 12px; background: #253a2a; color: #c6eeaa; border: 1px solid #749e5f; border-radius: 4px; padding: 6px; cursor: pointer; }
.training-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-height: 38px; }
.training-actions .btn { font-size: 12px; }
.training-split { display: flex; align-items: center; gap: 10px; width: 100%; font-size: 13px; }
.training-split output { min-width: 38px; color: #c6eeaa; }
.training-split input { flex: 1; min-width: 60px; accent-color: #b6e88b; }
.training-alliance { display: flex; align-items: center; gap: 12px; padding: 8px; background: #253342; border-radius: 6px; font-size: 12px; }
.training-feedback { min-height: 36px; color: #b9d7a8; line-height: 1.5; font-size: 13px; }
.tutorial-modes { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px; border-bottom: 1px solid #344239; }
.tutorial-modes .btn { background: transparent; font-size: 13px; }
.tutorial-modes .btn[aria-pressed="true"] { border-color: #94ba75; color: #c6eeaa; background: #283a2a; }
#tutorial-guide { padding: 16px 24px 24px; }
.guide-search { display: grid; gap: 7px; font-size: 12px; color: #b9c8b9; }
#panel-dev { left: 12px; top: 64px; width: min(320px, calc(100vw - 24px)); max-height: calc(100dvh - 150px); overflow-y: auto; z-index: 8; }
#dev-actions { display: grid; gap: 12px; padding: 14px; }
#dev-actions label { display: flex; justify-content: space-between; align-items: center; font-size: 12px; gap: 10px; }
#dev-actions input { width: 110px; padding: 7px; background: #101813; border: 1px solid #526756; color: var(--text); border-radius: 4px; }
#dev-actions > div { display: flex; gap: 8px; }
#dev-actions .hint { margin: 0; line-height: 1.5; }
#dev-status { min-height: 20px; margin: 0; font-size: 12px; color: #c6eeaa; }
#hud #tool-dev { color: #f5cd78; border-color: #a38b54; }
.guide-search input { width: 100%; padding: 11px 12px; background: #101813; color: #e3eae3; border: 1px solid #415447; border-radius: 6px; font: inherit; user-select: text; }
.guide-search input:focus { outline: 2px solid #94ba75; outline-offset: 2px; }
.guide-chapter { border: 1px solid #344239; border-radius: 7px; margin-top: 8px; overflow: hidden; }
.guide-chapter summary { cursor: pointer; padding: 13px 15px; background: #1c2a20; font-weight: 600; font-size: 14px; }
.guide-chapter summary:hover { background: #283a2a; }
.guide-chapter summary:focus-visible { outline: 2px solid #94ba75; outline-offset: -3px; }
.guide-body { padding: 8px 16px 16px; line-height: 1.75; font-size: 13px; user-select: text; }
.guide-body ul { margin: 8px 0 0; padding-left: 20px; }
.guide-body li + li { margin-top: 10px; }
.guide-table { overflow-x: auto; margin-top: 8px; }
.guide-table table { width: 100%; border-collapse: collapse; text-align: left; font-size: 12px; }
.guide-table th, .guide-table td { padding: 8px 10px; border-bottom: 1px solid #344239; vertical-align: top; }
.guide-table th { color: #c6eeaa; background: #1c2a20; }
@media (max-width: 600px) { #tutorial-guide { padding: 12px; } .guide-body { padding: 8px 12px 12px; } }
@media (max-width: 600px) { .tutorial-layout { grid-template-columns: 1fr; } #tutorial-lessons { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid #344239; padding: 10px; } #tutorial-lessons button { flex-shrink: 0; } .tutorial-layout article { padding: 16px; } }

.supply-warning { margin: 10px 0; padding: 10px; border: 1px solid #ff9966; border-radius: 6px; background: #38221e; color: #ffd0ad; line-height: 1.5; }

.capture-status { display: grid; gap: 6px; padding: 9px 10px; border: 1px solid #53637a; border-radius: 6px; background: #152130; color: #d8e4f1; font-size: 12px; line-height: 1.45; }
.capture-status.capturing { border-color: #78aa6c; background: #17271c; }
.capture-status.paused, .capture-status.blocked { border-color: #d49a55; background: #2b2117; }
.capture-status.contested { border-color: #d66b72; background: #2a1b22; }
.capture-status.protected { border-color: #7496c7; background: #18243a; }
.capture-status.fading, .capture-status.waiting { border-color: #667586; background: #18212d; }
.capture-status-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.capture-status-head > span { flex-shrink: 0; color: #bdc9d6; font-variant-numeric: tabular-nums; font-size: 11px; }
.capture-status-track { height: 4px; overflow: hidden; border-radius: 4px; background: #080e17; }
.capture-status-track > span { display: block; height: 100%; border-radius: inherit; transition: width .12s linear; }
.battle-feedback { display: grid; gap: 8px; padding: 9px 10px; border: 1px solid #526477; border-radius: 6px; background: #172230; }
.battle-feedback-head, .battle-feedback-side > div:first-child { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.battle-feedback-head > span, .battle-feedback-side > div:first-child > span { color: #b9c6d4; text-align: right; font-size: 11px; }
.battle-feedback-side { display: grid; gap: 4px; font-size: 12px; }
.battle-feedback-track { height: 4px; overflow: hidden; border-radius: 4px; background: #080e17; }
.battle-feedback-track > span { display: block; height: 100%; border-radius: inherit; }
.battle-feedback .hint { margin: 0; line-height: 1.4; }

.aa-status { padding: 8px; border: 1px solid currentColor; border-radius: 5px; font-size: 12px; line-height: 1.5; }
.aa-status.ready { color: #6be1c0; }
.aa-status.waiting { color: #ffb464; }
.rally-controls { padding: 8px 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.rally-controls b { display: inline-flex; align-items: center; gap: 5px; }
.rally-icon { width: 16px; height: 16px; object-fit: contain; vertical-align: middle; }
.rally-controls .hint { flex-basis: 100%; }
