/* Ghost Command v0.4 UI (owner: ui builder). Phone first at 375 x 812, desktop scales up.
   Layout budget: docs/V04_SPEC.md section 13.1. Colours: graphite, cyan (you), coral (enemy), amber (oil). */
:root {
  --bg: #0b1115; --surface: #152025; --border: #35484c; --ink: #f1f6f4; --muted: #93aaa8;
  --cyan: #50efd3; --coral: #f08370; --amber: #f1c476; --oil: #7dd6eb; --good: #8ee6a0;
  --head: 'Arial Black', Arial, sans-serif; --font: 'Trebuchet MS', Arial, sans-serif;
  --card-w: 84px; --card-h: 88px; --art: 36px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
body { overflow: hidden; }
button, select { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible, select:focus-visible, canvas:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
button:active:not(:disabled) { transform: translateY(1px); }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; display: block; }
[hidden] { display: none !important; }
[inert] { opacity: .55; pointer-events: none; }
.battlefield > [inert] { opacity: 1; } /* map layers behind the start/pause sheet are inert for focus only; the sheet backdrop already dims them */

.game-shell {
  height: 100vh; height: 100dvh; max-width: 1800px; margin: 0 auto; display: flex; flex-direction: column; background: #10191d;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}
.game-shell > :not(.battlefield) { flex: none; }

/* ---------------------------------------------------------------- top bar */
.topbar { height: 46px; display: flex; align-items: center; gap: 5px; padding: 0 6px; background: linear-gradient(120deg, #172022, #0b1116); border-bottom: 1px solid #3b5351; }
.brand { display: none; align-items: center; gap: 8px; margin: 0 8px 0 0; font: 900 18px/1 var(--head); letter-spacing: .03em; white-space: nowrap; }
.brand svg { width: 22px; height: 24px; fill: var(--cyan); stroke: none; }
.hp-block { flex: 1 1 0; min-width: 0; }
.hp-top { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; font-size: 9px; font-weight: 800; letter-spacing: .06em; color: #a9c0b8; }
.hp-top b { font-size: 11px; letter-spacing: 0; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.foe .hp-top b.unknown { font-size: 9px; color: var(--muted); font-weight: 700; }
.foe.stale #enemy-label { color: var(--amber); } /* stale HP: the label reads LAST SEEN (UI-11) */
.meter { height: 5px; margin-top: 3px; background: #354044; overflow: hidden; border-radius: 2px; }
.meter i { display: block; height: 100%; width: 100%; background: var(--cyan); transition: width .15s; }
.foe .meter i { background: var(--coral); }
.foe.stale .meter i { opacity: .55; }
.hp-block.low .meter i { background: var(--coral); }
.res { flex: none; display: flex; align-items: center; gap: 4px; }
.res-art { width: 18px; height: 18px; flex: none; object-fit: contain; display: block; }
.res-art[hidden], .res svg[hidden], .res-icon[hidden] { display: none; }
.res-icon { font-size: 16px; color: var(--amber); line-height: 1; }
.res svg { width: 12px; height: 17px; fill: var(--oil); stroke: none; }
.res-text { display: flex; flex-direction: column; min-width: 36px; }
.res-text b { font-size: 15px; line-height: 1.05; font-variant-numeric: tabular-nums; }
.res-text small { font-size: 8px; color: #b6d0c6; white-space: nowrap; font-variant-numeric: tabular-nums; }
.res.short b { color: var(--coral); }
.res.power svg { fill: #5df08d; }
.res.power.warn svg { fill: var(--amber); }
.res.power.warn b, .res.power.warn small { color: var(--amber); }
.res.power.low svg { fill: var(--coral); }
.res.power.low b, .res.power.low small { color: var(--coral); }
.res.tritium .res-icon { color: #c084fc; }
.icon-button { flex: none; width: 36px; height: 36px; display: grid; place-items: center; background: #10191b; border: 1px solid #647b79; border-radius: 6px; }
.icon-button svg { width: 20px; height: 20px; stroke-width: 2.4; }
.icon-button:disabled { opacity: .35; }

/* ---------------------------------------------------------------- battlefield */
.battlefield { position: relative; flex: 1 1 0; min-height: 0; overflow: hidden; background: #2f2b27; }
#battle { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; outline: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#battle:focus-visible { outline: 2px solid var(--cyan); outline-offset: -2px; } /* keyboard focus ring (UI-10) */
.battlefield::after { content: ''; position: absolute; inset: 0; pointer-events: none; border: 2px solid transparent; z-index: 2; transition: border-color .15s; }
.battlefield[data-mode=attack]::after { border-color: var(--coral); }
.battlefield[data-mode=defend]::after, .battlefield[data-mode=rally]::after { border-color: var(--amber); }
.battlefield[data-mode=airstrike]::after { border-color: var(--coral); border-style: dashed; }
.battlefield[data-mode=place]::after { border-color: var(--cyan); }
.battlefield[data-mode=attack] #battle, .battlefield[data-mode=airstrike] #battle { cursor: crosshair; }
#battle.panning { cursor: grabbing; }

/* left command bar */
.command-bar { position: absolute; left: 8px; top: 8px; z-index: 3; width: 46px; display: flex; flex-direction: column; gap: 4px; }
.command-bar button { height: 42px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 0; background: #0f1a1eeb; border: 1px solid #4a6560; border-radius: 6px; color: #cfe3dc; }
.command-bar svg { width: 18px; height: 18px; }
.command-bar span { font-size: 9px; font-weight: 800; letter-spacing: .02em; }
.command-bar button[aria-pressed=true] { background: var(--cyan); border-color: var(--cyan); color: #06201b; }
#tool-attack[aria-pressed=true] { background: var(--coral); border-color: var(--coral); color: #2a0d07; }
#tool-defend[aria-pressed=true] { background: var(--amber); border-color: var(--amber); color: #2b1d05; }
.command-bar button:hover:not([aria-pressed=true]):not(:disabled) { border-color: var(--cyan); }

/* minimap */
.minimap { position: absolute; top: 8px; right: 8px; z-index: 3; width: 112px; height: 70px; background: #070d10cc; border: 1px solid #5fbfae80; border-radius: 4px; overflow: hidden; }
.minimap canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: pointer; }

/* HUD pills */
.hud-stack { position: absolute; top: 8px; left: 62px; right: 128px; z-index: 3; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; pointer-events: none; }
.objective { max-width: 100%; height: 26px; display: flex; align-items: center; gap: 6px; padding: 0 9px; background: #0f1a1eeb; border: 1px solid #50efd37a; border-radius: 13px; font-size: 10px; color: var(--ink); pointer-events: auto; }
.objective b { color: var(--cyan); font-variant-numeric: tabular-nums; }
.objective span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.objective i { font-style: normal; color: var(--cyan); }
.objective.collapsed span { display: none; }
.objective.done { border-color: #8ee6a07a; }
.chip { height: 22px; display: flex; align-items: center; padding: 0 9px; background: #0f1a1eeb; border: 1px solid #f1c47680; border-radius: 11px; font-size: 10px; font-weight: 700; color: #ffe2a8; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip.warn { border-color: var(--coral); color: #ffc3b6; animation: blink 1s steps(2, jump-none) infinite; }
@keyframes blink { 50% { background: #3a1a15eb; } }
.toasts { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; max-width: 100%; }
.toast { min-height: 28px; max-width: 100%; display: flex; align-items: center; padding: 4px 10px; background: #0b171cf2; border-left: 3px solid var(--cyan); border-radius: 4px; font-size: 11px; color: #e1fff6; pointer-events: none; animation: toast-in .18s ease-out; }
.toast.warn { border-color: var(--amber); } .toast.bad { border-color: var(--coral); color: #ffd1c7; } .toast.good { border-color: var(--good); }
.toast.tappable { pointer-events: auto; cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-4px); } }

/* mode banner, placement bar, map controls, footer */
.mode-banner { position: absolute; left: 62px; right: 92px; bottom: 30px; z-index: 3; min-height: 34px; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px 4px 10px; background: #0f1a1ef5; border: 1px solid var(--coral); border-radius: 8px; font-size: 11px; line-height: 1.3; }
.battlefield[data-mode=defend] .mode-banner, .battlefield[data-mode=rally] .mode-banner { border-color: var(--amber); }
.mode-banner button { flex: none; min-width: 48px; height: 28px; padding: 0 10px; background: transparent; border: 1px solid #ffffff55; border-radius: 6px; font-size: 11px; }
.place-bar { position: absolute; left: 62px; right: 8px; bottom: 30px; z-index: 3; height: 46px; display: flex; align-items: center; gap: 8px; padding: 4px 6px; background: #0f1a1ef5; border: 1px solid var(--cyan); border-radius: 8px; }
.place-hint { flex: 1; min-width: 0; font-size: 10px; line-height: 1.25; color: #d5ece4; }
.place-hint.bad { color: #ffc3b6; }
.ghost-button, .solid-button { flex: none; height: 36px; min-width: 62px; padding: 0 12px; border-radius: 6px; font-size: 12px; font-weight: 800; }
.ghost-button { background: transparent; border: 1px solid #ffffff59; }
.solid-button { background: var(--cyan); border: 1px solid var(--cyan); color: #06201b; }
.solid-button:disabled { opacity: .4; }
.map-controls { position: absolute; right: 8px; bottom: 30px; z-index: 3; display: flex; gap: 4px; }
.battlefield[data-mode=place] .map-controls, .battlefield[data-mode=rally] .map-controls { bottom: 84px; }
.map-controls button { width: 36px; height: 36px; display: grid; place-items: center; background: #102025eb; border: 1px solid #637e75; color: #d6eee6; border-radius: 6px; font-size: 22px; line-height: 1; }
.map-controls svg { width: 18px; height: 18px; }
.map-controls button:hover { border-color: var(--cyan); color: var(--cyan); }
.wide-only { display: none !important; }
.field-footer { position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; height: 22px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 10px; background: linear-gradient(transparent, #07131de8); font-size: 9px; font-weight: 700; letter-spacing: .06em; pointer-events: none; text-shadow: 0 1px 3px #000; white-space: nowrap; }
.field-footer #order-hint { display: none; color: #c4d9d2; font-weight: 400; overflow: hidden; text-overflow: ellipsis; }
.field-footer #clock { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- overlay sheet */
.overlay { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; background: #071016cc; padding: 10px; }
.sheet { width: min(520px, 100%); max-height: 100%; overflow-y: auto; overscroll-behavior: contain; text-align: center; padding: 18px 20px 16px; background: linear-gradient(140deg, #1c2a2efa, #0d191ffa); border: 1px solid #689c8d9c; border-radius: 6px; box-shadow: 0 20px 90px #0009; scrollbar-width: thin; }
.sheet-mark { width: 24px; height: 24px; margin: 0 auto 6px; color: var(--cyan); }
.sheet-mark svg { width: 100%; height: 100%; fill: currentColor; stroke: none; }
.kicker { font-size: 9px; letter-spacing: .15em; color: var(--cyan); margin: 0 0 6px; }
.sheet h2 { font: 900 25px/1.1 var(--head); margin: 0 0 8px; letter-spacing: -.02em; }
.sheet-copy { font-size: 12px; line-height: 1.5; color: #b9cec4; margin: 0; }
.setup { display: grid; grid-template-columns: 1.25fr 1fr; gap: 6px 10px; margin: 14px 0 0; text-align: left; }
.setup label { font-size: 10px; font-weight: 700; color: #9fb8ae; display: flex; flex-direction: column; gap: 4px; }
.setup select { width: 100%; height: 38px; border: 1px solid #4d6b5f; border-radius: 4px; background: #15282b; padding: 0 8px; font-size: 12px; }
.setup p { grid-column: 1 / 3; font-size: 10px; color: var(--cyan); margin: 0; text-align: center; min-height: 14px; }
.tips { list-style: none; margin: 12px 0; padding: 0; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.tips li { display: flex; gap: 9px; align-items: baseline; font-size: 11px; line-height: 1.4; color: #b6cdc3; }
.tips b { flex: none; color: var(--cyan); font-size: 12px; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 8px; margin: 14px 0; }
.result-stats span { display: flex; flex-direction: column; gap: 3px; font-size: 9px; letter-spacing: .04em; color: #9ab7a7; }
.result-stats b { font-size: 20px; color: #e8fff0; font-variant-numeric: tabular-nums; }
.loading-error { font-size: 11px; color: var(--coral); margin: 8px 0; }
.primary-button { width: 100%; min-height: 44px; padding: 10px 14px; background: var(--cyan); color: #0c211c; border: 1px solid var(--cyan); font-size: 13px; font-weight: 900; border-radius: 4px; }
.primary-button:hover:not(:disabled) { background: #92ffe6; }
.primary-button:disabled { opacity: .5; }
.sheet-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; margin-top: 10px; }
.sheet-links button, .sheet-links a { min-height: 32px; display: inline-flex; align-items: center; background: none; border: 0; padding: 0 2px; color: #a9c5b8; font-size: 11px; text-decoration: underline; }
.sheet-links button:hover, .sheet-links a:hover { color: var(--cyan); }
.sheet[data-view=victory] h2 { color: var(--cyan); }
.sheet[data-view=defeat] h2 { color: var(--coral); }
.sheet[data-view=victory] #setup, .sheet[data-view=defeat] #setup, .sheet[data-view=paused] #setup, .sheet[data-view=paused] .tips, .sheet[data-view=victory] .tips, .sheet[data-view=defeat] .tips { display: none; }

/* ---------------------------------------------------------------- tactical bar */
.tactical-bar { height: 50px; display: flex; align-items: center; gap: 6px; padding: 5px 8px; background: #101b20; border-block: 1px solid #45605a; }
.group-controls { flex: 1 1 0; min-width: 0; display: flex; gap: 3px; }
.group-controls button { flex: 1 1 0; min-width: 0; height: 40px; padding: 0; border: 1px solid #3a514a; background: #14232a; border-radius: 6px; font-size: 9px; color: #a9c0b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group-controls button[aria-pressed=true] { color: #071a18; background: var(--cyan); border-color: var(--cyan); font-weight: 900; }
.group-controls .long { display: none; }
.ability-controls { flex: none; display: flex; gap: 3px; }
.ability-controls button { width: 38px; height: 40px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 0; border: 1px solid #5d6c61; background: #192627; border-radius: 6px; }
.ability-controls svg { width: 16px; height: 16px; color: var(--cyan); }
.ability-controls small { font-size: 8px; color: #b3c9bf; white-space: nowrap; }
.ability-controls button:disabled { opacity: .4; }
#strike { border-color: #765a50; } #strike svg { color: var(--coral); }
#strike[aria-pressed=true] { background: #603326; border-color: var(--coral); }

/* v0.5.4 base chips: an overlay along the bottom of the battlefield (no layout shift), clear of the command column, banner and map controls */
.base-row { position: absolute; left: 62px; right: 62px; bottom: 68px; z-index: 4; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.base-row::-webkit-scrollbar { display: none; }
.base-row[hidden] { display: none; }
.base-row button { flex: none; min-height: 40px; padding: 0 12px; background: #0f1a1ef5; border: 1px solid #f1c476b0; border-radius: 8px; color: #ffe2a8; font-size: 12px; font-weight: 800; white-space: nowrap; }
.base-row button[aria-pressed=true] { background: var(--cyan); border-color: var(--cyan); color: #071a18; }
.base-row button.rallying { background: var(--amber); border-color: var(--amber); }

/* ---------------------------------------------------------------- production panel */
.production { padding: 0 8px 4px; background: linear-gradient(#1b282a, #10191d); }
.production-header { height: 36px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.production-tabs { display: flex; gap: 2px; }
.production-tabs button { min-height: 34px; padding: 4px 12px; background: none; border: 0; border-bottom: 2px solid transparent; color: #7f9a91; font-weight: 800; font-size: 12px; }
.production-tabs button[aria-pressed=true] { border-color: var(--cyan); color: #f0fff8; }
.unit-count { font-size: 11px; color: #a9c5b9; font-variant-numeric: tabular-nums; white-space: nowrap; }
.unit-count.over-cap { color: var(--amber); font-weight: 800; } /* v0.4.3: finished units wait for room (a Robo Factory was lost) */
.production-scroll { display: flex; gap: 6px; height: 104px; align-items: flex-end; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 4px; }
.production-scroll::-webkit-scrollbar { display: none; }
#army-panel { gap: 10px; align-items: stretch; }
.card-group { flex: none; display: flex; flex-direction: column; gap: 3px; justify-content: flex-end; }
.group-label { height: 11px; font-size: 9px; letter-spacing: .12em; color: #7e9a92; white-space: nowrap; text-transform: uppercase; }
.card-row { display: flex; gap: 6px; flex: none; align-items: flex-end; }
.card { position: relative; flex: none; width: var(--card-w); height: var(--card-h); }
.card-main { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 3px 10px; background: radial-gradient(ellipse at bottom left, #36585150, #152126 80%); border: 1px solid #5c90816b; border-radius: 8px; text-align: center; color: var(--ink); -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.card-main:hover { border-color: var(--cyan); }
.card-art { position: relative; flex: none; width: var(--art); height: var(--art); filter: drop-shadow(0 3px 3px #0006); }
.art-img { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background-repeat: no-repeat; }
.card-art.monogram { display: grid; place-items: center; font: 900 15px var(--head); color: #7fd6c5; border: 1px dashed #4f7a6e; border-radius: 6px; background: #1a2b2e; filter: none; }
/* v0.4.3: card icon for a unit with no usable art (Heavy Tank stand-in, ui-panels.js paintStandIn; since v0.4.4 only while
   its Codex image is missing or fails): a side-view tank in CSS.
   Parts are placed in percentages of the icon box (designed on 36 px), so it scales with --art: 42 px desktop down to
   20 px for a locked card in a landscape phone. The hull strip is the friendly team colour, as on the map (TEAM_COLOR.friendly). */
.card-art.standin { filter: drop-shadow(0 3px 3px #0006); }
.standin-heavy { position: absolute; inset: 0; }
.standin-heavy span { position: absolute; display: block; }
.standin-heavy .tread { left: 2.8%; right: 8.3%; bottom: 16.7%; height: 25%; border-radius: 999px; background: repeating-linear-gradient(90deg, #1b2326 0 3px, #2f3b3f 3px 5px); border: 1px solid #0b1214; }
.standin-heavy .hull { left: 8.3%; right: 13.9%; bottom: 36.1%; height: 22.2%; border-radius: 15% 30% 10% 10% / 40% 60% 20% 20%; background: linear-gradient(#5f6f70, #36464a); border: 1px solid #0b1214; box-shadow: inset 0 -2px 0 #61f5df; }
.standin-heavy .turret { left: 25%; width: 38.9%; bottom: 52.8%; height: 22.2%; border-radius: 45% 45% 15% 15% / 70% 70% 20% 20%; background: linear-gradient(#6d7d7e, #415154); border: 1px solid #0b1214; }
.standin-heavy .gun { left: 58.3%; right: 0; bottom: 61.1%; height: max(2px, 8.3%); border-radius: 1px; background: #2a3437; outline: 1px solid #0b1214; }
.card-perk { position: absolute; left: 3px; right: 3px; bottom: 1px; font-size: 9px; line-height: 9px; font-weight: 700; color: #7fe9d6; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.card-perk:empty { display: none; }
/* v0.5 phase 1b (spec 8.2): hit glyphs at the art's bottom-left. Tread (amber) = hits ground, wing (cyan) = hits aircraft.
   Armed kinds show one or two 10 px glyphs; Engineer and Medic show none. */
.card-hits { position: absolute; left: calc(50% - var(--art) / 2 - 4px); top: calc(6px + var(--art) - 12px); display: flex; gap: 1px; padding: 1px; background: #0b1115c4; border-radius: 3px; pointer-events: none; }
.card-hit { display: block; width: 10px; height: 10px; }
.card-hit svg { width: 10px; height: 10px; fill: currentColor; stroke: none; }
.card-hit.ground { color: #f2a93b; }
.card-hit.air { color: var(--cyan); }
.card-title { max-width: 100%; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font: 800 10px/1.1 var(--font); }
.card-cost { display: flex; justify-content: center; gap: 5px; font-size: 10px; font-weight: 800; white-space: nowrap; margin-top: auto; }
.card-cost b:empty, .card-cost i:empty { display: none; }
.card-cost .m { color: var(--amber); } .card-cost .m::before { content: '◆'; font-size: 8px; margin-right: 1px; }
.card-cost .o { color: var(--oil); } .card-cost .o::before { content: '●'; font-size: 7px; margin-right: 1px; }
.card-cost i { color: #a9c0b8; font-style: normal; font-weight: 600; }
.card-cost .short { color: var(--coral); }
.card.low-power .card-cost i:last-child { color: var(--amber); }
.card.low-power .card-bar i { background: var(--amber); }
.card-lock { display: none; max-width: 100%; font-size: 10px; line-height: 1.1; color: #e5b97f; margin-top: auto; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; } /* >= 10 px, two lines (UI-11) */
.card.locked .card-lock:not(:empty) { display: -webkit-box; }
.card.locked .card-cost { display: none; }
.card.locked .card-main { opacity: .62; }
.card.locked .card-art { filter: grayscale(1); width: calc(var(--art) - 8px); height: calc(var(--art) - 8px); }
.card.busy .card-main { opacity: .7; }
.card.busy .card-lock:not(:empty) { display: -webkit-box; }
.card.busy .card-cost { display: none; }
.card.active .card-main { border-color: var(--cyan); box-shadow: inset 0 0 0 1px var(--cyan); background-color: #183b36; }
.card.hint .card-main { border-color: var(--amber); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 3px #f1c47655; } }
.card-bar { position: absolute; left: 6px; right: 6px; bottom: 4px; height: 4px; background: #2b383b; border-radius: 2px; overflow: hidden; pointer-events: none; }
.card-bar i { display: block; height: 100%; width: 0; background: var(--cyan); }
.card-badge { position: absolute; top: 3px; right: 3px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--cyan); color: #06201b; font: 900 10px/18px var(--font); text-align: center; pointer-events: none; }
.card-x { position: absolute; top: 0; left: 0; width: 28px; height: 28px; display: grid; place-items: center; padding: 0; background: #2a1518e6; border: 1px solid var(--coral); border-radius: 8px 0 8px 0; color: #ffc3b6; font-size: 17px; line-height: 1; }
.card-sub { font-size: 9px; line-height: 1.2; color: #a9c0b8; max-width: 100%; }
.build-card.constructing { width: 128px; display: flex; flex-direction: column; gap: 3px; padding: 6px 8px 14px; background: #183b36; border: 1px solid var(--cyan); border-radius: 8px; }
.build-card.constructing .card-bar { left: 8px; right: 8px; bottom: 6px; position: static; margin: 2px 0; }
.card-action { align-self: flex-start; height: 28px; padding: 0 10px; background: transparent; border: 1px solid var(--coral); color: #ffc3b6; border-radius: 6px; font-size: 11px; }
.send-card .card-art { font-size: 20px; }
.info-card { width: auto; min-width: 120px; max-width: 180px; padding: 7px 9px 12px; background: #142226; border: 1px solid #3a5b4c; border-radius: 8px; display: flex; flex-direction: column; gap: 3px; text-align: left; align-items: flex-start; }
.info-card .card-title { font-size: 11px; -webkit-line-clamp: 1; }
.info-card .card-sub { font-size: 9px; }
.info-card .card-bar { left: 9px; right: 9px; bottom: 5px; }
.info-card.unit-count { width: 88px; min-width: 0; align-items: center; text-align: center; }
.queue-card { background: radial-gradient(ellipse at bottom left, #36585150, #152126 80%); border: 1px solid #5c90816b; border-radius: 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 3px 10px; }
/* v0.5 phase 1b (spec 8.4 first slice): one selected unit. 180 x 88 portrait, 200 x 76 landscape (the card height follows --card-h). */
.detail-card { width: 180px; display: flex; align-items: flex-start; gap: 7px; padding: 7px 9px 12px; background: #142226; border: 1px solid #3a5b4c; border-radius: 8px; text-align: left; overflow: hidden; }
.detail-card .card-art { width: var(--art); height: var(--art); margin-top: 1px; }
.detail-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.detail-card .card-title { font-size: 11px; -webkit-line-clamp: 1; }
.detail-card .card-sub { font-size: 9px; }
.detail-card .card-bar { left: 9px; right: 9px; bottom: 5px; }
.card-state, .card-ammo, .card-threat { display: block; max-width: 100%; font-size: 10px; line-height: 1.2; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-state { color: var(--cyan); }
.card-state:empty, .card-ammo:empty, .card-threat:empty { display: none; }
.card-ammo { color: var(--amber); }
.card-threat { color: var(--coral); }
.info-card .card-state { margin-top: 1px; }
.fx-debug { position: absolute; left: 6px; bottom: 26px; z-index: 5; max-width: calc(100% - 12px); padding: 1px 5px; font: 10px/14px ui-monospace, Menlo, monospace; color: #bfe9de; background: #0b1115cc; border-radius: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.queue-card .card-x { border-radius: 8px 0 8px 0; }
.action-card .card-sub { font-size: 9px; margin-top: auto; }

/* ---------------------------------------------------------------- field guide */
dialog { max-width: 560px; width: calc(100% - 24px); max-height: 90vh; max-height: 90dvh; overflow-y: auto; background: #142126; color: #e5f1e9; border: 1px solid #4f7766; border-radius: 6px; padding: 22px 20px; box-shadow: 0 20px 100px #0008; }
dialog::backdrop { background: #01080de0; }
dialog h2 { font: 900 22px var(--head); margin: 0 0 12px; }
dialog p { font-size: 12px; line-height: 1.6; color: #b1cbbb; }
.dialog-close { position: absolute; top: 4px; right: 8px; width: 40px; height: 40px; border: 0; background: transparent; font-size: 28px; color: #a4c7b2; }
.guide-row { padding: 10px 0; border-bottom: 1px solid #314c3d; display: flex; flex-direction: column; gap: 5px; }
.guide-row strong { font-size: 11px; color: var(--cyan); letter-spacing: .06em; }
.guide-row span { font-size: 11px; line-height: 1.6; color: #bed4c7; }
.guide-note { font-size: 10px !important; color: #819f8d !important; }

/* ---------------------------------------------------------------- compact mobile topbar */
@media (max-width: 479px) {
  .topbar { gap: 4px; padding: 0 4px; }
  .topbar .res { gap: 2px; }
  .topbar .res-text { min-width: 24px; }
  .topbar .res-text b { font-size: 12px; }
  .topbar .res-text small { font-size: 7px; }
  .topbar .res-icon { font-size: 12px; }
  .topbar .res-art { width: 14px; height: 14px; }
  .topbar .res svg { width: 10px; height: 14px; }
  .topbar .icon-button { width: 32px; height: 32px; }
}
/* ---------------------------------------------------------------- wider screens */
@media (min-width: 480px) {
  .brand { display: flex; } .brand span { display: none; }
  .group-controls .long { display: inline; } .group-controls .short { display: none; } .group-controls button { font-size: 10px; }
}
@media (min-width: 700px) {
  :root { --card-w: 96px; --card-h: 92px; --art: 42px; }
  .topbar { height: 52px; padding: 0 14px; gap: 14px; }
  .brand span { display: inline; }
  .hp-block { flex: 0 1 190px; } .hp-top { font-size: 10px; } .hp-top b { font-size: 12px; }
  .foe .hp-top b.unknown { font-size: 10px; }
  .res-text b { font-size: 18px; } .res-text small { font-size: 9px; }
  .topbar .res:first-of-type { margin-left: auto; }
  .minimap { width: 176px; height: 110px; top: 10px; right: 10px; }
  .command-bar { left: 12px; top: 12px; width: 52px; } .command-bar button { height: 46px; } .command-bar span { font-size: 10px; }
  .hud-stack { left: 76px; right: 202px; top: 12px; }
  .mode-banner { left: 76px; right: 180px; } .place-bar { left: 76px; right: 12px; } /* clear of the 156 px map controls (UI-8) */
  .map-controls { right: 12px; } .wide-only { display: grid !important; }
  .field-footer { padding: 0 14px; font-size: 10px; } .field-footer #order-hint { display: block; flex: 1; text-align: center; }
  .tactical-bar { height: 54px; padding: 6px 14px; gap: 12px; } .group-controls { flex: 0 1 460px; } .group-controls button { font-size: 11px; }
  .ability-controls button { width: 56px; } .ability-controls small { font-size: 9px; }
  .production { padding: 0 14px 6px; } .production-scroll { height: 112px; }
  .toast { font-size: 12px; }
}
@media (min-width: 900px) {
  .battlefield { max-height: 820px; }
  .sheet { padding: 24px 30px 20px; } .sheet h2 { font-size: 29px; }
}
/* landscape phones and short windows: trim vertical chrome */
@media (max-height: 520px) {
  :root { --card-h: 76px; --art: 28px; }
  .detail-card { width: 200px; padding: 5px 8px 11px; gap: 6px; } .detail-text { gap: 1px; }
  .topbar { height: 42px; } .tactical-bar { height: 44px; padding-block: 3px; } .group-controls button, .ability-controls button { height: 36px; }
  .production-header { height: 30px; } .production-tabs button { min-height: 28px; }
  .production-scroll { height: 92px; } .card-title { font-size: 9px; } .group-label { display: none; }
  .command-bar button { height: 36px; } .command-bar svg { width: 16px; height: 16px; }
  .sheet { padding: 10px 16px; } .sheet-mark, .tips { display: none; } .sheet h2 { font-size: 20px; margin-bottom: 4px; } .setup { margin-top: 8px; }
}
/* landscape phones (UI-2): the battlefield is only ~100-170 px tall, too short for a 5-button column.
   The command bar becomes a row along the top, the minimap shrinks, the map controls sit beside it
   (hidden while placing or setting a rally), and the banners start right of the command row. */
@media (max-height: 520px) and (min-width: 560px) {
  .command-bar { flex-direction: row; width: auto; top: 6px; left: 6px; }
  .command-bar button { width: 44px; height: 34px; }
  .minimap { width: 112px; height: 70px; top: 6px; right: 6px; }
  .map-controls { top: 6px; bottom: auto; right: 124px; }
  .battlefield[data-mode=place] .map-controls, .battlefield[data-mode=rally] .map-controls { display: none; }
  /* The HUD stack (objective, chips, toasts, tappable alerts) shares the centre column with the mode
     banner and Place bar; on a short battlefield they can meet, so the stack paints above them and its
     alerts stay readable and tappable (audit CHD-1). The banner's Done button sits right of the stack. */
  .hud-stack { top: 6px; left: 250px; right: 208px; z-index: 4; }
  /* The start/pause sheet covers the whole screen, not just the short battlefield, so Begin stays
     reachable when Safari's toolbars leave the battlefield ~90 px tall (audit CHD-2). */
  .overlay { position: fixed; inset: 0; overflow-y: auto; align-items: flex-start;
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
  .overlay .sheet { margin-block: auto; }
  .mode-banner, .place-bar { left: 250px; right: 124px; bottom: 26px; }
  .place-bar { height: 42px; }
  /* While placing, the Place bar's Cancel / hint / Place stay on top of the raised HUD stack (skeptic LV-1). */
  .battlefield[data-mode=place] .place-bar { z-index: 5; }
  .production-scroll { height: 84px; }
  .base-row { left: 8px; right: 124px; bottom: 62px; } .base-row button { min-height: 34px; font-size: 11px; }
}
@media (max-height: 520px) and (min-width: 700px) { .hud-stack { right: 288px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
