:root {
  --bg: #0c0f12;
  --panel: rgba(12, 16, 20, 0.86);
  --panel2: rgba(22, 28, 34, 0.9);
  --line: rgba(255, 255, 255, 0.12);
  --text: #e6ebef;
  --dim: #8d99a6;
  --accent: #4d9bff;
  --amber: #e8b04a;
  --good: #6fdc5a;
  --bad: #ff5a4a;
  --font: "Rajdhani", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
:root { --hud-bottom: 226px; }
html, body { margin: 0; height: 100%; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; user-select: none; }
canvas#game { position: fixed; inset: 0; display: block; touch-action: none; }
button, select, input { touch-action: manipulation; }
.hidden { display: none !important; }
.dim { color: var(--dim); font-weight: 500; }
button { font-family: var(--font); font-weight: 600; letter-spacing: 0.06em; cursor: pointer; border: 1px solid var(--line); background: var(--panel2); color: var(--text); padding: 8px 16px; border-radius: 3px; transition: background 0.12s, border-color 0.12s; }
button:hover { background: rgba(77, 155, 255, 0.18); border-color: rgba(77, 155, 255, 0.5); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: rgba(77, 155, 255, 0.28); border-color: rgba(77, 155, 255, 0.7); }
button.primary:hover { background: rgba(77, 155, 255, 0.42); }
button.ghost { background: transparent; }
select, input { font-family: var(--font); font-size: 15px; background: #141a20; color: var(--text); border: 1px solid var(--line); padding: 6px 8px; border-radius: 3px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; touch-action: none; }
#hud > * { pointer-events: auto; }
#topbar { position: absolute; top: 0; left: 0; right: 0; height: 52px; display: flex; align-items: center; justify-content: space-between; padding: 0 14px; background: linear-gradient(180deg, rgba(8, 10, 13, 0.92), rgba(8, 10, 13, 0.6)); border-bottom: 1px solid var(--line); }
.tb-group { display: flex; gap: 22px; align-items: center; }
.tb-group.right { gap: 8px; }
.tb-center { font-weight: 700; letter-spacing: 0.2em; color: var(--dim); font-size: 14px; }
.stat { display: flex; flex-direction: column; line-height: 1; }
.stat .lbl { font-size: 10px; letter-spacing: 0.18em; color: var(--dim); }
.stat .val { font-size: 22px; font-weight: 700; color: var(--amber); margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 11px; color: var(--good); }
.stat:nth-child(2) .val, .stat:nth-child(3) .val { color: var(--text); }
.stat .val.phase-day { color: #ffe9a8; }
.stat .val.phase-dusk, .stat .val.phase-dawn { color: #ffb070; }
.stat .val.phase-night { color: #9fb8ff; }
.stat .sub.dim { color: var(--dim); }
.tb-btn { padding: 5px 10px; font-size: 12px; }

#tutorial { position: absolute; top: 62px; left: 12px; width: 300px; background: rgba(12, 16, 20, 0.92); border: 1px solid rgba(232, 176, 74, 0.6); padding: 10px 12px; }
#tutorial-text { font-size: 15px; font-weight: 600; line-height: 1.4; }
#tutorial-step { font-size: 11px; letter-spacing: 0.15em; margin-top: 6px; }
#objectives li.inactive { opacity: 0.45; }
#objectives-wrap { position: absolute; top: 62px; right: 12px; width: 280px; background: var(--panel); border: 1px solid var(--line); padding: 8px 10px; }
.panel-title { font-size: 11px; letter-spacing: 0.2em; color: var(--dim); font-weight: 700; margin-bottom: 6px; }
#objectives { list-style: none; margin: 0; padding: 0; font-size: 14px; font-weight: 600; }
#objectives li { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
#objectives .chk { width: 12px; height: 12px; border: 1px solid var(--dim); flex: none; }
#objectives li.done .chk { background: var(--good); border-color: var(--good); }
#objectives li.done { color: var(--dim); text-decoration: line-through; }
#objectives li.failed { color: var(--bad); }
#objectives .prog { margin-left: auto; color: var(--amber); font-variant-numeric: tabular-nums; }

#messages { position: absolute; left: 50%; bottom: calc(var(--hud-bottom) + 10px); transform: translateX(-50%); width: 560px; display: flex; flex-direction: column; align-items: center; gap: 3px; pointer-events: none; }
.msg { font-size: 14px; font-weight: 600; padding: 3px 12px; background: rgba(8, 10, 13, 0.7); border-left: 3px solid var(--accent); animation: msgin 0.25s ease-out; }
.msg.good { border-color: var(--good); }
.msg.bad { border-color: var(--bad); color: #ffb8b0; }
.msg.warn { border-color: var(--amber); }
.msg.tip { border-color: var(--dim); color: var(--dim); font-style: italic; }
@keyframes msgin { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

#bottombar { position: absolute; left: 0; right: 0; bottom: 0; height: var(--hud-bottom); box-sizing: border-box; display: grid; grid-template-columns: 236px 1fr 470px; gap: 8px; padding: 8px; background: linear-gradient(0deg, rgba(8, 10, 13, 0.95), rgba(8, 10, 13, 0.75)); border-top: 1px solid var(--line); }
#minimap-wrap { border: 1px solid var(--line); background: #000; display: flex; align-items: center; justify-content: center; }
#minimap { width: 100%; height: 100%; image-rendering: auto; cursor: crosshair; }
#selection-wrap, #dropship-wrap { background: var(--panel); border: 1px solid var(--line); padding: 8px 10px; display: flex; flex-direction: column; min-width: 0; }
#selection { display: flex; flex-wrap: wrap; gap: 6px; overflow-y: auto; flex: 1; align-content: flex-start; }
#selection .empty { color: var(--text); font-weight: 600; margin: auto; text-align: center; font-size: 15px; line-height: 1.4; }
.card { width: 150px; background: var(--panel2); border: 1px solid var(--line); padding: 6px 8px; cursor: pointer; font-size: 13px; }
.card.single { width: 260px; }
.card:hover { border-color: rgba(255, 255, 255, 0.35); }
.c-head { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.c-head .c-name { flex: 1; }
.c-ic { width: 34px; height: 22px; object-fit: contain; }
.c-rank { color: var(--amber); font-size: 9px; letter-spacing: 1px; }
.c-hp { height: 5px; background: rgba(0, 0, 0, 0.6); margin: 4px 0; }
.c-hp-bar { height: 100%; }
.c-meta { display: flex; justify-content: space-between; font-size: 12px; }
.c-modes { display: flex; gap: 4px; margin-top: 5px; }
.mode-btn { flex: 1; padding: 3px 4px; font-size: 11px; letter-spacing: 0.03em; }
.mode-btn.active { background: rgba(232, 176, 74, 0.25); border-color: var(--amber); color: #ffe2a8; }
.c-status { font-size: 12px; margin-top: 4px; }
#selection .more { align-self: center; color: var(--dim); }

#buy-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.buy-btn:hover:not(.disabled) { background: rgba(232, 176, 74, 0.18); border-color: rgba(232, 176, 74, 0.6); }
.buy-btn { display: grid; grid-template-columns: 44px 1fr 16px; align-items: center; gap: 6px; padding: 3px 6px 3px 4px; text-align: left; font-size: 13px; min-height: 40px; }
.buy-btn .ic { width: 44px; height: 30px; object-fit: contain; }
.buy-btn .txt { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.buy-btn .hk { font-size: 10px; color: var(--dim); border: 1px solid var(--line); text-align: center; border-radius: 2px; line-height: 14px; }
.buy-btn .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.buy-btn .cost { color: var(--amber); font-variant-numeric: tabular-nums; font-size: 11px; }
.buy-btn.disabled { opacity: 0.45; }
#queue-row { margin-top: 8px; }
#queue { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.slot { height: 30px; border: 1px dashed var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 6px; font-size: 12px; font-weight: 600; }
.slot.filled { border-style: solid; background: rgba(77, 155, 255, 0.12); border-color: rgba(77, 155, 255, 0.5); }
.slot button { padding: 0 5px; font-size: 13px; line-height: 18px; }
#dz-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
#dz-row label { font-size: 11px; letter-spacing: 0.15em; color: var(--dim); font-weight: 700; display: flex; align-items: center; gap: 8px; }
#dz-row select { min-width: 150px; font-size: 14px; padding: 4px 6px; }
#btn-launch { background: rgba(232, 176, 74, 0.25); border-color: rgba(232, 176, 74, 0.7); color: #ffe2a8; padding: 7px 18px; }
#btn-launch:hover:not(:disabled) { background: rgba(232, 176, 74, 0.4); }

#tooltip { position: fixed; z-index: 30; max-width: 320px; background: rgba(8, 10, 13, 0.96); border: 1px solid rgba(255, 255, 255, 0.2); padding: 8px 10px; font-size: 13px; pointer-events: none; line-height: 1.35; }
.tt-title { font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.tt-desc { margin: 6px 0; }
.tt-mode { border-top: 1px solid var(--line); padding-top: 4px; margin-top: 4px; }

/* ---------- Menus ---------- */
#menu-layer { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at 50% 40%, #1a2430 0%, #0c0f12 65%); }
#menu-layer.hidden { display: none; }
.screen { width: min(860px, 92vw); max-height: 92vh; overflow: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch; background: var(--panel); border: 1px solid var(--line); padding: 34px 40px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6); }
.screen.small { width: min(560px, 92vw); }
.screen h3 { font-size: 13px; letter-spacing: 0.2em; color: var(--dim); margin: 18px 0 6px; }
.screen ul { margin: 0; padding-left: 18px; line-height: 1.5; font-size: 15px; }
.screen ul li.done { color: var(--dim); text-decoration: line-through; }
.screen-title { font-size: 34px; font-weight: 700; letter-spacing: 0.12em; margin: 0 0 6px; }
.eyebrow { font-size: 11px; letter-spacing: 0.3em; color: var(--dim); font-weight: 700; }
.title-block { text-align: center; margin-bottom: 30px; }
.title-block h1 { font-size: 64px; margin: 8px 0 0; letter-spacing: 0.08em; line-height: 1; }
.title-block h1 span { color: var(--accent); }
.title-block h2 { font-size: 24px; letter-spacing: 0.5em; color: var(--amber); margin: 6px 0 0; font-weight: 600; }
.menu-buttons { display: flex; flex-direction: column; gap: 10px; align-items: center; }
button.big { width: 320px; padding: 14px; font-size: 18px; letter-spacing: 0.25em; }
.footer { text-align: center; margin-top: 30px; font-size: 14px; }
.row { display: flex; gap: 10px; margin-top: 24px; justify-content: flex-end; }
.row .btn-back, .row #btn-briefing-back { margin-right: auto; }
#campaign-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.campaign-card { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left; padding: 12px 14px; border: 1px solid var(--line); opacity: 0.75; }
.campaign-card:hover { opacity: 1; }
.campaign-card.active { opacity: 1; border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent), 0 0 18px rgba(80, 200, 255, 0.15); }
.campaign-card .fac { font-size: 10px; letter-spacing: 0.3em; padding: 2px 6px; border-radius: 3px; background: rgba(255,255,255,0.08); }
.campaign-card .fac.nsa { color: #7fc7ff; } .campaign-card .fac.terran { color: #ffb070; } .campaign-card .fac.viron { color: #9df08a; }
.campaign-card .name { font-size: 18px; font-weight: 700; letter-spacing: 0.05em; }
.campaign-card .sub { font-size: 12px; color: var(--dim); letter-spacing: 0.1em; }
.campaign-card .state { font-size: 11px; color: var(--amber); letter-spacing: 0.2em; margin-top: 4px; }
#campaign-desc { margin: 12px 0 0; font-size: 14px; line-height: 1.5; min-height: 42px; }
#campaign-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; max-height: 46vh; overflow-y: auto; padding-right: 4px; }
.mission-btn.done .num { color: var(--good); }
.mission-btn { display: grid; grid-template-columns: 40px 1fr auto; align-items: center; text-align: left; padding: 12px 16px; font-size: 18px; }
.mission-btn .num { color: var(--accent); font-size: 22px; font-weight: 700; }
.mission-btn .diff { font-size: 11px; letter-spacing: 0.2em; color: var(--dim); }
.mission-btn.locked { opacity: 0.4; cursor: default; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 24px; margin-top: 14px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; letter-spacing: 0.1em; color: var(--dim); font-weight: 700; }
.help-cols, .briefing-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; }
.help-cols ul { padding-left: 18px; }
.help-cols li { margin-bottom: 6px; }
.briefing p { font-size: 17px; line-height: 1.55; margin: 10px 0; }
.stats { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; font-size: 16px; }
.stats div { display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 4px 0; }
#end-title.win { color: var(--good); }
#end-title.lose { color: var(--bad); }
@media (max-width: 1100px) {
  #bottombar { grid-template-columns: 180px 1fr 340px; }
  #buy-buttons { grid-template-columns: repeat(2, 1fr); }
  #objectives-wrap { width: 230px; }
}

/* ---------- Saves, replays, settings ---------- */
.menu-row { display: flex; gap: 10px; margin-top: 4px; }
.menu-row button { padding: 10px 18px; font-size: 13px; letter-spacing: 0.15em; }
.slot-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.slot-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; align-items: center; padding: 10px 14px; border: 1px solid var(--line); background: var(--panel2); }
.slot-row .slot-name { font-weight: 700; font-size: 16px; }
.slot-row .slot-label { grid-column: 1; font-size: 13px; }
.slot-row .slot-actions { grid-row: 1 / span 2; grid-column: 2; display: flex; gap: 6px; }
.file-btn { position: relative; overflow: hidden; display: inline-block; font-weight: 600; letter-spacing: 0.06em; cursor: pointer; border: 1px solid var(--line); background: var(--panel2); padding: 8px 16px; border-radius: 3px; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; text-transform: none; letter-spacing: 0; font-size: 14px; }
.form input[type=range] { width: 100%; }
.key-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 18px; margin-top: 8px; }
.key-row { display: flex; justify-content: space-between; align-items: center; font-size: 14px; border-bottom: 1px solid var(--line); padding: 4px 0; }
.key-btn { min-width: 64px; padding: 3px 8px; font-size: 12px; }
.key-btn.waiting { border-color: var(--amber); color: #ffe2a8; }

/* ---------- Map editor ---------- */
.screen.editor { width: 96vw; max-height: 94vh; height: 94vh; display: grid; grid-template-columns: 300px 1fr; gap: 16px; padding: 18px; overflow: hidden; }
#editor-side { overflow-y: auto; padding-right: 6px; }
#editor-side .screen-title { font-size: 24px; }
#editor-side h3 { margin: 12px 0 4px; }
#editor-wrap { display: flex; align-items: center; justify-content: center; background: #05080c; border: 1px solid var(--line); overflow: hidden; }
#editor-canvas { image-rendering: pixelated; cursor: crosshair; max-width: 100%; max-height: 100%; }
.ed-field { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; letter-spacing: 0.1em; color: var(--dim); font-weight: 700; margin: 6px 0; }
.ed-field input, .ed-field select { flex: 1; font-size: 14px; }
.ed-row { display: flex; gap: 6px; margin: 6px 0; flex-wrap: wrap; align-items: center; }
.ed-row select { flex: 1; min-width: 100px; }
.ed-tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.ed-tools button { padding: 6px 4px; font-size: 12px; border-left: 6px solid var(--c); }
.ed-tools button.active, #ed-tool-vl.active { background: rgba(232, 176, 74, 0.3); border-color: var(--amber); }
#ed-tool-vl { width: 100%; }
#ed-info { font-size: 12px; margin: 6px 0; min-height: 30px; }
.file-btn.small { padding: 5px 8px; font-size: 11px; }

/* ---------- Chat & rooms ---------- */
#chat-log { position: absolute; left: 12px; bottom: calc(var(--hud-bottom) + 10px); width: 380px; display: flex; flex-direction: column; gap: 3px; pointer-events: none; }
.chat-line { font-size: 14px; background: rgba(8, 10, 13, 0.7); padding: 3px 10px; border-left: 3px solid var(--amber); transition: opacity 1s; }
.chat-line.fade { opacity: 0; }
#chat-box { position: absolute; left: 12px; bottom: calc(var(--hud-bottom) + 10px); width: 380px; display: flex; align-items: center; gap: 8px; background: rgba(8, 10, 13, 0.9); border: 1px solid var(--line); padding: 6px 10px; }
#chat-box input { flex: 1; }
.room-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; align-items: center; padding: 8px 12px; border: 1px solid var(--line); background: var(--panel2); }
.room-row .slot-actions { grid-row: 1 / span 2; grid-column: 2; display: flex; gap: 6px; }
.room-row .dim { grid-column: 1; font-size: 12px; }

/* ---------- Multiplayer ---------- */
.status { margin-top: 16px; padding: 8px 12px; border-left: 3px solid var(--accent); background: rgba(77, 155, 255, 0.08); font-weight: 600; min-height: 20px; }
.status.bad { border-color: var(--bad); background: rgba(255, 90, 74, 0.1); color: #ffb8b0; }
.screen code { font-family: ui-monospace, Menlo, monospace; background: rgba(255, 255, 255, 0.08); padding: 1px 5px; border-radius: 3px; }

#ability-bar { position: absolute; right: 12px; bottom: calc(var(--hud-bottom) + 10px); display: flex; gap: 6px; }
.ab-btn { position: relative; width: 96px; height: 58px; padding: 6px 8px; text-align: left; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; }
.ab-btn .ab-name { font-size: 12px; font-weight: 700; line-height: 1.1; }
.ab-btn .ab-meta { font-size: 10px; color: var(--dim); display: flex; justify-content: space-between; }
.ab-btn .ab-hk { position: absolute; top: 4px; right: 5px; font-size: 9px; border: 1px solid var(--line); padding: 0 4px; border-radius: 2px; color: var(--dim); }
.ab-btn .ab-cd { position: absolute; left: 0; bottom: 0; width: 100%; background: rgba(0, 0, 0, 0.55); pointer-events: none; }
.ab-btn.ready { border-color: rgba(232, 176, 74, 0.6); }
.ab-btn.active { background: rgba(232, 176, 74, 0.3); border-color: var(--amber); }
.ab-btn.poor { opacity: 0.55; }
.c-actions { display: flex; gap: 4px; margin-top: 4px; }
.act-btn { flex: 1; padding: 2px 4px; font-size: 10px; letter-spacing: 0.02em; }
.act-btn.merge { background: rgba(143, 227, 106, 0.18); border-color: rgba(143, 227, 106, 0.6); color: #dcffc8; }
.act-btn.active { background: rgba(255, 90, 74, 0.25); border-color: var(--bad); color: #ffc0b8; }
button.small { padding: 5px 8px; font-size: 11px; }
#btn-rally.active { background: rgba(232, 176, 74, 0.3); border-color: var(--amber); }

/* ---------- Touch devices ---------- */
.touch-only { display: none; }
body.touch .touch-only { display: inline-block; }
body.touch .panel-title .dim { display: none; }
body.touch .buy-btn .hk, body.touch .ab-btn .ab-hk { display: none; }
body.touch #btn-rot-l, body.touch #btn-rot-r { display: none; }
body.touch #chat-log { bottom: calc(var(--hud-bottom) + 58px); }
body.touch #chat-box { bottom: calc(var(--hud-bottom) + 58px); }
body.touch .mode-btn, body.touch .act-btn { min-height: 30px; font-size: 12px; }
body.touch .buy-btn { min-height: 44px; }
body.touch #btn-launch { min-height: 40px; }
#touch-bar { display: none; position: absolute; left: 8px; bottom: calc(var(--hud-bottom) + 8px); flex-wrap: wrap; gap: 5px; max-width: 62vw; }
body.touch #touch-bar { display: flex; }
.t-btn { min-width: 46px; height: 40px; padding: 0 9px; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; background: rgba(8, 10, 13, 0.85); }
.t-btn.active { background: rgba(232, 176, 74, 0.32); border-color: var(--amber); color: #ffe2a8; }
.t-btn.hidden { display: none; }
#rotate-hint { display: none; position: fixed; inset: 0; z-index: 50; background: rgba(8, 10, 13, 0.97); flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 24px; }
#rotate-hint .rh-icon { font-size: 54px; animation: rh-turn 1.6s ease-in-out infinite alternate; }
@keyframes rh-turn { from { transform: rotate(0); } to { transform: rotate(-90deg); } }
#rotate-hint h2 { margin: 0; letter-spacing: 0.2em; font-size: 22px; }
#rotate-hint p { max-width: 320px; margin: 0; font-size: 14px; line-height: 1.5; }
@media (orientation: portrait) { body.touch:not(.rotate-dismissed) #rotate-hint { display: flex; } }

/* ---------- Compact layout: phones and small windows ---------- */
@media (max-width: 1100px), (max-height: 720px) {
  :root { --hud-bottom: 160px; }
  #topbar { height: 40px; padding: 0 8px; padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .tb-group { gap: 12px; } .tb-group.right { gap: 5px; }
  .stat .lbl { font-size: 8px; letter-spacing: 0.12em; }
  .stat .val { font-size: 15px; margin-top: 1px; }
  .stat .sub { display: none; }
  .tb-center { display: none; }
  .tb-btn { padding: 4px 7px; font-size: 10px; }
  #btn-music { display: none; }
  #tutorial { top: 46px; left: 8px; width: 210px; padding: 6px 8px; }
  #tutorial-text { font-size: 12px; }
  #objectives-wrap { top: 46px; right: 8px; width: 190px; padding: 5px 8px; }
  #objectives { font-size: 11px; } #objectives li { padding: 2px 0; gap: 5px; }
  .panel-title { font-size: 9px; margin-bottom: 4px; }
  #messages { width: 60vw; top: 46px; bottom: auto; } .msg { font-size: 12px; padding: 2px 8px; }
  #bottombar { grid-template-columns: 136px 1fr 290px; gap: 6px; padding: 6px; padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); }
  #selection-wrap, #dropship-wrap { padding: 4px 6px; overflow: hidden; }
  #dropship-wrap { overflow-y: auto; }
  #queue-row, #dz-row { margin-top: 4px; }
  .slot { height: 18px; font-size: 9px; padding: 0 4px; } .slot button { font-size: 11px; line-height: 14px; }
  #queue { gap: 3px; }
  .formation-bar { font-size: 10px; gap: 3px; } .formation-bar button { padding: 2px 5px; font-size: 10px; }
  .card { width: 140px; }
  .card { width: 128px; padding: 4px 6px; font-size: 11px; } .card.single { width: 200px; }
  .c-ic { width: 26px; height: 18px; } .c-meta, .c-status { font-size: 10px; } .mode-btn { font-size: 10px; padding: 2px 3px; }
  #buy-buttons { grid-template-columns: repeat(3, 1fr); gap: 3px; }
  .buy-btn { min-height: 30px; font-size: 11px; grid-template-columns: 30px 1fr; gap: 4px; padding: 1px 4px; }
  body.touch .buy-btn { min-height: 32px; }
  .buy-btn .ic { width: 30px; height: 20px; } .buy-btn .hk { display: none; } .buy-btn .cost { font-size: 10px; }
  #dz-row { gap: 4px; } #dz-row label { font-size: 0; gap: 0; letter-spacing: 0; flex: 1; min-width: 0; } #dz-row select { font-size: 11px; width: 100%; min-width: 0; }
  button.small { padding: 4px 6px; font-size: 10px; white-space: nowrap; }
  #btn-launch { padding: 4px 8px; font-size: 11px; white-space: nowrap; flex: none; }
  .mode-btn, .act-btn { font-size: 9px; padding: 1px 2px; } body.touch .mode-btn, body.touch .act-btn { min-height: 26px; font-size: 10px; }
  #ability-bar { right: 8px; gap: 4px; }
  .ab-btn { width: 66px; height: 42px; padding: 4px 5px; } .ab-btn .ab-name { font-size: 10px; } .ab-btn .ab-meta { font-size: 8px; }
  #chat-log, #chat-box { width: 240px; } .chat-line { font-size: 12px; }
  .t-btn { min-width: 36px; height: 32px; padding: 0 6px; font-size: 10px; }
  #touch-bar { max-width: calc(100vw - 300px); gap: 4px; }
  body.touch #chat-log, body.touch #chat-box { bottom: calc(var(--hud-bottom) + 44px); }
  .screen { padding: 16px 14px; width: 96vw; max-height: 94vh; }
  .screen.small { width: min(560px, 96vw); }
  .screen-title { font-size: 22px; }
  .form { gap: 8px 12px; } .form label { font-size: 11px; }
  .help-cols, .briefing-cols { grid-template-columns: 1fr; gap: 10px; }
  .briefing p { font-size: 14px; }
  #campaign-picker { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
  .campaign-card { padding: 8px 10px; } .campaign-card .name { font-size: 14px; }
  #campaign-list { max-height: 40vh; }
  .mission-btn { padding: 8px 10px; font-size: 14px; }
  .key-grid { grid-template-columns: 1fr 1fr; }
  .title-block h1 { font-size: 34px; } .title-block h2 { font-size: 14px; letter-spacing: 0.3em; margin-top: 2px; }
  .title-block { margin-bottom: 10px; } .eyebrow { font-size: 10px; }
  .menu-buttons { gap: 6px; }
  button.big { width: min(320px, 100%); padding: 11px; font-size: 15px; }
  .menu-row { flex-wrap: wrap; justify-content: center; }
  .row { flex-wrap: wrap; gap: 6px; }
  .footer { margin-top: 14px; font-size: 12px; }
}
@media (max-width: 640px) {
  .form { grid-template-columns: 1fr; }
  #campaign-picker { grid-template-columns: 1fr; }
  .key-grid { grid-template-columns: 1fr; }
  #bottombar { grid-template-columns: 110px 1fr 220px; }
  #buy-buttons { grid-template-columns: repeat(2, 1fr); }
}

/* Portrait phones: two-column bottom bar, minimap hidden, everything full width */
@media (orientation: portrait) and (max-width: 640px) {
  :root { --hud-bottom: 210px; }
  #bottombar { grid-template-columns: 1fr 1fr; }
  #minimap-wrap { display: none; }
  #buy-buttons { grid-template-columns: repeat(2, 1fr); }
  #touch-bar { max-width: calc(100vw - 16px); }
  #ability-bar { left: 8px; right: 8px; bottom: calc(var(--hud-bottom) + 88px); flex-wrap: wrap; }
  .ab-btn { width: calc(25% - 4px); height: 38px; }
  #objectives-wrap { width: calc(100vw - 16px); left: 8px; right: 8px; box-sizing: border-box; }
  #messages { width: 90vw; top: 128px; }
  #dz-row select { min-width: 96px; } #dz-row label { flex: 1; }
  #btn-rally { padding: 4px 5px; }
  .card { width: calc(50% - 4px); }
}

/* ---------- Collapsible HUD on touch devices ---------- */
#panel-tab { display: none; position: absolute; left: 50%; transform: translateX(-50%); bottom: var(--hud-bottom); z-index: 5; padding: 4px 14px; font-size: 10px; letter-spacing: 0.15em; font-weight: 700; background: rgba(8, 10, 13, 0.92); border-bottom: none; border-radius: 4px 4px 0 0; }
body.touch #panel-tab { display: block; }
body.touch.panel-collapsed { --hud-bottom: 0px; }
body.touch.panel-collapsed #bottombar { display: none; }
body.touch.panel-collapsed #panel-tab { bottom: max(0px, env(safe-area-inset-bottom)); }
body.touch.tb-collapsed #touch-bar .t-btn:not(#tb-menu) { display: none; }
#tb-menu { font-size: 16px; }
body.touch #objectives-wrap .panel-title { cursor: pointer; }
body.touch #objectives-wrap .panel-title::after { content: ' \25B4'; }
body.touch #objectives-wrap.collapsed .panel-title::after { content: ' \25BE'; }
body.touch #objectives-wrap.collapsed .panel-title { margin-bottom: 0; }
body.touch #objectives-wrap.collapsed #objectives { display: none; }
body.touch #objectives-wrap.collapsed { width: auto; }

/* ---------- Main menu: hero layout over the live attract battle ---------- */
body.demo #menu-layer { background: linear-gradient(90deg, rgba(8, 10, 13, 0.97) 0%, rgba(8, 10, 13, 0.93) 46%, rgba(8, 10, 13, 0.35) 70%, rgba(8, 10, 13, 0.12) 100%); }
body.demo .screen:not(.hero) { background: rgba(12, 16, 20, 0.95); }
.screen.hero { width: 100vw; max-width: none; height: 100vh; max-height: none; padding: 0; background: transparent; border: none; box-shadow: none; display: grid; grid-template-columns: minmax(520px, 52vw) 1fr; overflow: hidden; }
.hero-left { padding: 3vh 72px; display: flex; flex-direction: column; justify-content: center; gap: 16px; text-align: left; min-width: 0; }
.hero-left .title-block { text-align: left; margin: 0; }
.audio-start-hint { color: var(--dim); font-size: 14px; line-height: 1.4; margin: 0; }
.hero-left .title-block h1 { font-size: clamp(44px, 5vw, 76px); line-height: 0.98; }
.hero-left .title-block h1 .nowrap { white-space: nowrap; color: inherit; }
.hero-left .title-block h2 { font-size: clamp(16px, 1.6vw, 24px); }
.hero-left .eyebrow { font-size: 11px; }
.pitch { margin: 0; max-width: 640px; font-size: 17px; line-height: 1.6; color: var(--text); opacity: 0.9; }
.hero-left .menu-buttons { align-items: stretch; max-width: 640px; gap: 8px; }
.hero-left button.big { padding: 11px; }
.hero-left button.big { width: 100%; text-align: center; }
.hero-left button.big.primary { background: rgba(77, 155, 255, 0.18); border-color: rgba(77, 155, 255, 0.65); }
.hero-left button.big.ghost { background: transparent; }
.hero-left .menu-row { justify-content: flex-start; flex-wrap: wrap; gap: 8px; }
.hero-left .menu-row button { flex: 1 1 120px; padding: 11px 12px; }
.hero-stats { display: flex; gap: 28px; margin-bottom: 6px; padding: 10px 16px; background: rgba(8, 10, 13, 0.6); border-right: 3px solid var(--amber); }
.hero-stats div { text-align: right; align-items: flex-end; }
.hero-stats div { display: flex; flex-direction: column; line-height: 1; }
.hero-stats b { font-size: 26px; color: var(--amber); font-weight: 700; }
.hero-stats span { font-size: 10px; letter-spacing: 0.2em; color: var(--dim); margin-top: 4px; }
.hero-right { display: flex; flex-direction: column; justify-content: flex-end; align-items: flex-end; gap: 10px; padding: 24px 28px; min-width: 0; }
.hero-caption { font-size: 11px; letter-spacing: 0.18em; color: var(--dim); text-transform: uppercase; background: rgba(8, 10, 13, 0.6); padding: 4px 10px; border-left: 3px solid var(--bad); }
.hero-caption .live { color: var(--bad); font-weight: 700; margin-right: 6px; animation: live-blink 2.4s ease-in-out infinite; }
@keyframes live-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.hero-factions { display: flex; gap: 8px; flex-wrap: nowrap; justify-content: flex-end; max-width: 100%; }
.fac-card { flex: 1 1 0; min-width: 0; max-width: 215px; background: rgba(12, 16, 20, 0.86); border: 1px solid var(--line); padding: 9px 11px; backdrop-filter: blur(4px); }
.fac-card .fac-name { font-size: 12px; letter-spacing: 0.2em; font-weight: 700; color: var(--amber); }
.fac-card .fac-icons { display: flex; gap: 6px; margin: 8px 0 6px; }
.fac-card .fac-icons img { height: 24px; width: 36px; object-fit: contain; }
.fac-card .fac-blurb { font-size: 11px; line-height: 1.35; color: var(--dim); }
@media (max-width: 1100px), (max-height: 720px) {
  .screen.hero { grid-template-columns: 1fr; height: 100vh; overflow-y: auto; }
  .hero-left { padding: 20px 18px; justify-content: flex-start; gap: 12px; }
  .hero-left .title-block h1 { font-size: 36px; }
  .pitch { font-size: 13px; }
  .hero-stats { gap: 16px; padding: 6px 10px; } .hero-stats b { font-size: 20px; }
  .hero-right { padding: 0 18px 18px; align-items: stretch; }
  .hero-caption { display: none; }
  .hero-factions { justify-content: flex-start; }
  .hero-factions { flex-wrap: wrap; }
  .fac-card { flex: 1 1 150px; max-width: none; }
}
.hero-art { display: none; max-width: min(46vw, 760px); max-height: 46vh; object-fit: cover; border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6); margin-bottom: auto; }
.hero-art.show { display: block; }
@media (max-width: 1100px), (max-height: 720px) { .hero-art { max-width: 100%; max-height: 32vh; margin: 0 0 8px; } }
