:root {
  color-scheme: dark;
  scrollbar-gutter: stable;
  --page: #111311;
  --panel: #1a1d19;
  --line: #34382f;
  --ink: #f2e9d7;
  --subtle: #b8b6a7;
  --muted: #a29e8c;
  --copper: #efa45d;
  --green: #8fa87e;
  --gold: #d9ae6e;
  --mono: "DejaVu Sans Mono", Consolas, monospace;
  font: 16px/1.45 system-ui, sans-serif;
  background: var(--page);
  color: var(--ink);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button { font: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid #ffce88; outline-offset: 3px; }
button:disabled { opacity: .42; cursor: default; }
.shell { max-width: 1416px; margin: auto; padding: 0 36px 30px; }
.masthead { height: 79px; display: flex; justify-content: space-between; align-items: center; }
.brand, .header-actions { display: flex; align-items: center; gap: 10px; }
.brand { font: 750 .84rem/1 var(--mono); letter-spacing: .075em; }
.brand-end { color: var(--copper); }
.brand-mark { width: 16px; height: 19px; border: 1px solid var(--copper); clip-path: polygon(0 0,100% 0,100% 70%,50% 100%,0 70%); background: linear-gradient(135deg,#efa45d 0 31%,#463222 32% 47%,#efa45d 48% 61%,#6f4a32 62%); }
.quiet { border: 1px solid var(--line); color: var(--subtle); background: #1a1c18; border-radius: 5px; padding: 7px 12px; font-size: .82rem; }
.quiet:hover:enabled { border-color: var(--copper); color: var(--ink); }
.game-layout { display: grid; grid-template-columns: minmax(0,1fr) 284px; gap: 18px; align-items: start; }
.left { min-width: 0; }
.arena { position: relative; isolation: isolate; overflow: hidden; border-radius: 8px; border: 1px solid #4a4135; background: #24291f; aspect-ratio: 8 / 5; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.arena[data-screen="battle"] canvas { cursor: none; }
.cover, .overlay { position: absolute; inset: 0; }
.cover {
  display: flex;
  align-items: center;
  padding: 4% 6%;
  background: linear-gradient(90deg,rgba(14,16,14,.97) 2%,rgba(14,16,14,.76) 28%,rgba(14,16,14,.16) 69%,rgba(14,16,14,.02)), url("./siege-cover.webp") center 47%/cover, #29271f;
}
.cover::after { content: ""; position: absolute; inset: 8px; border: 1px solid #dbcbb22c; border-radius: 4px; pointer-events: none; }
.cover-inner { position: relative; z-index: 1; }
.eyebrow, .panel h3 {
  margin: 0;
  font: 650 .68rem/1.25 var(--mono);
  letter-spacing: .16em;
  color: var(--copper);
}
.cover-inner .eyebrow { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.cover-inner .eyebrow::before { content: ""; width: 30px; height: 1px; background: var(--copper); }
h1, h2 { margin: 0; }
h1, .modal h2 { font-family: Georgia, "Times New Roman", serif; }
h1 { font-size: clamp(3rem,7.7vw,8.1rem); letter-spacing: -.065em; line-height: .94; text-shadow: 0 4px 30px #110d09b3; }
.cover p { margin: 18px 0 26px; color: #e6dbca; font-size: .99rem; max-width: 275px; }
.primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 22px;
  color: #21150b; background: var(--copper); border: 1px solid #ffb878; border-radius: 5px;
  padding: 12px 17px; font-size: .88rem; font-weight: 800; box-shadow: inset 0 1px #ffffff3d;
}
.primary:hover { background: #ffb877; }
.primary span { font-size: 1.1rem; line-height: 1; }
.wide { width: 100%; }
.controls { min-height: 49px; display: flex; align-items: center; padding: 9px 2px; }
.desktop-controls, .touch-controls { display: flex; flex-wrap: wrap; gap: 7px 20px; font-size: .76rem; color: var(--subtle); }
.desktop-controls span { display: inline-flex; align-items: center; gap: 5px; }
kbd { background: #20231e; color: var(--ink); border: 1px solid #3b3d34; border-radius: 3px; padding: 2px 5px; font: 650 .66rem/1.1 var(--mono); }
.touch-controls { display: none; }
.report { display: grid; gap: 0; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.report-heading { display: flex; justify-content: space-between; gap: 6px; align-items: center; padding: 16px 1px 13px; }
.report-heading h2 { font-weight: 710; font-size: 1.08rem; letter-spacing: -.025em; }
.status { display: flex; gap: 6px; align-items: center; color: var(--subtle); font: .65rem var(--mono); }
.status i, .coin { display: inline-block; background: var(--green); border-radius: 50%; width: 6px; height: 6px; }
.status[data-danger="true"] i { background: var(--copper); box-shadow: 0 0 8px #efa45d75; }
.metrics { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid #3b3b30; border-radius: 5px; background: #151713; }
.metrics div { padding: 9px 11px 10px; display: grid; gap: 3px; }
.metrics div + div { border-left: 1px solid #3b3b30; }
.metrics span, .record span { color: var(--muted); font: .64rem var(--mono); text-transform: uppercase; letter-spacing: .055em; }
.metrics strong { font: 700 1.62rem/1.05 var(--mono); }
.panel { padding: 15px 1px; border-bottom: 1px solid var(--line); }
.panel h3 { color: #ceba98; text-transform: uppercase; margin: 0 0 10px; }
.meter + .meter { margin-top: 9px; }
.meter div, .resource, .record { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.meter div, .resource { font-size: .79rem; color: var(--subtle); }
.meter strong, .resource strong, .record strong { color: var(--ink); font: 650 .73rem var(--mono); }
progress { appearance: none; display: block; width: 100%; height: 4px; border: 0; border-radius: 2px; overflow: hidden; margin: 4px 0 0; background: #33372e; color: var(--green); }
progress::-webkit-progress-bar { background: #33372e; }
progress::-webkit-progress-value { background: currentColor; }
progress::-moz-progress-bar { background: currentColor; }
progress[data-level="low"] { color: #e37859; }
progress[data-level="mid"] { color: var(--gold); }
.resource + .resource { margin-top: 6px; }
.resource strong { display: inline-flex; align-items: center; gap: 5px; }
.coin { background: #d8a35b; border: 1px solid #f5c681; width: 8px; height: 8px; }
.record { padding: 12px 1px; }

.battle-hud { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; justify-content: space-between; align-items: start; pointer-events: none; }
.wave-chip, .ammo-chip { border: 1px solid #83745a80; border-radius: 5px; background: #161a15eb; color: var(--ink); padding: 6px 10px; font: .75rem var(--mono); }
.wave-chip strong { color: var(--copper); }
.ammo-chip { pointer-events: auto; text-align: right; min-width: 72px; }
.ammo-chip strong { font-size: 1rem; color: var(--copper); }
.ammo-chip small { display: block; color: var(--subtle); font-size: .56rem; margin-top: 2px; text-transform: uppercase; }
.message { pointer-events: none; position: absolute; z-index: 2; background: #221a14ed; border: 1px solid #9c6546; border-radius: 4px; color: #ffcf9c; padding: 5px 10px; top: 11px; left: 50%; transform: translateX(-50%); max-width: 65%; width: max-content; text-align: center; font: .68rem var(--mono); }
.overlay { z-index: 4; display: flex; justify-content: center; align-items: safe center; overflow: auto; background: #0c0f0cc0; padding: 16px; }
.modal { width: min(100%,380px); background: #1f221bee; border: 1px solid #71634e; box-shadow: 0 12px 32px #0008; border-radius: 7px; padding: 22px; }
.regroup-banner {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 12px;
  background: #0c0f0c6e; pointer-events: none;
}
.regroup-banner div {
  display: grid; gap: 6px; padding: 15px 22px; text-align: center;
  background: #1f221bf2; border: 1px solid #71634e; border-radius: 6px;
}
.regroup-banner strong { font: 700 clamp(1.4rem,3.4vw,2.3rem)/1.1 Georgia, serif; }
.regroup-banner span { color: var(--subtle); font-size: .79rem; }
.regroup { grid-column: 1 / -1; padding: 12px 0; border-bottom: 1px solid var(--line); }
.regroup-heading { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.report:has(.regroup:not([hidden])) .treasury { display: none; }
.regroup h3 { margin: 0; font-size: 1rem; }
.regroup p { margin: 4px 0 10px; font-size: .76rem; color: var(--subtle); }
.regroup .primary { padding: 9px 10px; }
.modal h2 { font-size: clamp(1.6rem,3.8vw,2.5rem); line-height: 1; margin: 6px 0 11px; }
.modal p { font-size: .82rem; color: var(--subtle); margin: 0 0 12px; }
.modal h2 + .primary { margin-top: 7px; }
.shop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 0 0 13px; }
.shop-item { min-width: 0; display: grid; padding: 6px 8px; gap: 2px; text-align: left; color: var(--ink); background: #2a2e25; border: 1px solid #494937; border-radius: 4px; }
.shop-item:hover:enabled { border-color: #c48854; }
.deploy-shop { border-block: 1px solid var(--line); padding: 9px 0 0; margin: 0 0 11px; }
.deploy-shop h4, .garrison h4, .supplies h4 { color: #ceba98; margin: 0 0 7px; font: 650 .65rem var(--mono); text-transform: uppercase; letter-spacing: .10em; }
.deploy-shop .shop-grid { margin-bottom: 3px; }
.defense-option { background: #353124; border-color: #725938; }
.defense-option[aria-pressed="true"] { border-color: var(--copper); background: #413322; }
.garrison { margin-top: 13px; }
.theater { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 9px; padding: 0 1px 10px; }
.theater strong { color: #e6c89d; font-size: .79rem; }
.theater span { color: var(--subtle); font: .64rem var(--mono); }
.dispatch { border: 1px solid #66523b; border-radius: 5px; background: #252419; padding: 9px; margin: 0 0 11px; }
.dispatch h4 { margin: 0; font-size: .83rem; color: var(--copper); }
.dispatch p { margin-bottom: 7px; }
.dispatch .shop-grid { margin: 0; }
.dispatch .shop-item { background: #353022; }
.dispatch .travel { color: #f4bb83; min-height: 35px; }
.recover-button { margin: 0 0 10px; color: #f0c387; }
.regroup #next { margin-bottom: 10px; }
.weapon-offer { order: -1; background: #393025; border-color: #8a6339; }
.supplies { margin-top: 12px; }
.supplies .shop-grid { margin-bottom: 0; }
.move-options { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 2px; }
.move-options .quiet { font-size: .66rem; padding: 4px 6px; }
.placement-surface { position: absolute; inset: 0; width: 100%; background: transparent; border: 0; cursor: crosshair; touch-action: none; }
.placement-surface:focus-visible { outline-offset: -4px; }
.recovery-markers { position: absolute; inset: 0; pointer-events: none; }
.cache-marker {
  position: absolute; transform: translate(-50%, -50%); pointer-events: auto;
  background: #c99448; color: #20170b; border: 1px solid #ffd28c;
  min-height: 28px; padding: 4px 6px; border-radius: 4px; font: 750 .68rem var(--mono);
  white-space: nowrap; box-shadow: 0 2px 10px #100c08b0;
}
.cache-marker:hover { background: #ffbf6f; }
.arena.placing .recovery-markers { visibility: hidden; }
.arena.placing .regroup-banner, .arena.scavenging .regroup-banner { align-items: start; }
.arena.placing .regroup-banner div, .arena.scavenging .regroup-banner div { padding: 8px 14px; }
.arena.placing .regroup-banner strong, .arena.scavenging .regroup-banner strong { font-size: clamp(1rem,2.1vw,1.65rem); }
.arena.placing .regroup-banner span, .arena.scavenging .regroup-banner span { display: none; }

.shop-item > span:first-child { display: flex; justify-content: space-between; gap: 4px; font-size: .73rem; font-weight: 700; }
.shop-item b { color: #f2b06b; font: 700 .68rem var(--mono); white-space: nowrap; }
.shop-item small { font-size: .66rem; color: var(--subtle); }
.end-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 7px; margin-bottom: 16px; }
.end-stats div { display: grid; gap: 3px; padding: 7px; border: 1px solid var(--line); border-radius: 4px; }
.end-stats strong { font: 700 1.05rem var(--mono); color: var(--copper); }
.end-stats span { font-size: .68rem; color: var(--subtle); }

@media (hover:none) and (pointer:coarse) {
  .desktop-controls { display: none; }
  .touch-controls { display: flex; }
}
@media (max-width:900px) {
  .shell { padding: 0 18px 18px; }
  .masthead { height: 65px; }
  .game-layout { grid-template-columns: minmax(0,1fr) 224px; gap: 12px; }
}
@media (max-width:700px) {
  .game-layout { grid-template-columns: minmax(0,1fr); }
  .shell { padding: 0 12px 14px; }
  .masthead { height: 53px; }
  .report { grid-template-columns: 1fr 1fr; gap: 0 13px; }
  .report-heading, .theater, .metrics, .record { grid-column: 1 / -1; }
  .arena:has(.overlay:not([hidden])) { min-height: 290px; }
}
@media (max-width:470px) {
  .cover { padding-left: 7%; background-position: center, 55% 47%; }
  .cover-inner .eyebrow { margin-bottom: 10px; }
  h1 { font-size: clamp(2.8rem,13vw,4.3rem); }
  .cover p { font-size: .82rem; line-height: 1.3; margin: 10px 0 15px; max-width: 195px; }
  .cover .primary { padding: 8px 11px; font-size: .8rem; }
  .brand { font-size: .72rem; }
  .quiet { padding: 5px 8px; font-size: .72rem; }
  .controls { min-height: 0; padding: 7px 1px 0; }
  .touch-controls { font-size: .67rem; gap: 3px 11px; }
  .modal { padding: 14px; }
  .message { top: 8px; max-width: 54%; }
}

.cover-actions { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.cover-actions .quiet { padding: 11px 12px; background: #1a1c18; color: var(--ink); border-color: #75614a; box-shadow: none; }
.field-hud {
  position: absolute; inset: auto 9px 8px; display: flex; flex-wrap: wrap; gap: 5px;
  pointer-events: none; color: #dfd4bf; font: .7rem/1.2 var(--mono);
}
.field-hud > span { background: #191d18ea; border: 1px solid #6d604b; border-radius: 4px; padding: 5px 7px; }
.field-hud strong { color: #fff0c8; margin-left: 3px; }
#combat-goal { margin-left: auto; max-width: 66%; text-align: right; }
.mission-card { border: 1px solid #685636; background: #28251b; border-radius: 5px; padding: 8px; margin-bottom: 9px; }
.mission-line { display: flex; justify-content: space-between; align-items: baseline; gap: 5px; }
.mission-line h4 { margin: 0; font-size: .82rem; color: #efc190; }
.mission-line strong { flex: none; color: #eab878; font: 700 .69rem var(--mono); }
.mission-card p { margin: 4px 0 0; }
.mission-report .resource { align-items: start; }
.mission-report .resource strong { white-space: nowrap; color: #efc190; }
.battle-orders { border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.battle-orders summary { cursor: pointer; color: #d9cbb0; font-size: .78rem; padding: 0 0 8px; }
.battle-orders .shop-grid { margin-bottom: 8px; }
.battle-orders .shop-item[aria-pressed="true"] { border-color: #c8915d; background: #3a3022; }
.move-options { display: grid; }
.unit-orders { display: grid; grid-template-columns: minmax(0,1fr) auto auto; gap: 3px; align-items: center; padding: 3px 0; }
.unit-orders span { font-size: .66rem; color: #dfd6bf; }
.unit-orders button { white-space: nowrap; }

.atlas {
  width: min(95vw,920px); max-height: 94dvh; color: var(--ink); padding: 0; overflow: auto;
  background: #1d201a; border: 1px solid #8a785b; border-radius: 9px;
  box-shadow: 0 18px 70px #000b;
}
.atlas::backdrop { background: #0b0e0cce; }
.atlas-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; }
.atlas-head h2 { font: 700 clamp(1.3rem,3.5vw,2.05rem)/1.15 Georgia,serif; margin: 2px 0 0; }
.atlas-scroll { overflow: hidden; border-block: 1px solid #6d654a; }
.atlas-terrain { position: relative; aspect-ratio: 8/5; width: 100%; background: #323f31; isolation: isolate; }
.atlas-art { position: absolute; inset: 0; background: linear-gradient(0deg,#17170d12,#241b1240), url("./campaign-atlas.webp") center/100% 100%; }
.atlas-terrain.pan .atlas-art,
.atlas-terrain.pan #atlas-markers {
  animation: reveal-atlas .95s cubic-bezier(.18,.74,.25,1) both;
  transform-origin: var(--focus-x,25%) var(--focus-y,62%);
}
@keyframes reveal-atlas {
  0% { transform: scale(1.78); }
  100% { transform: scale(1); }
}
#atlas-markers { position: absolute; inset: 0; pointer-events: none; }
.atlas-marker {
  position: absolute; pointer-events: auto; transform: translate(-50%,-50%); white-space: nowrap;
  border: 1px solid #d5b47a; border-radius: 5px; background: #23281eea; color: #f5e7cd;
  font-size: clamp(.68rem,1.5vw,.89rem); font-weight: 750; padding: 8px 10px; box-shadow: 0 4px 13px #12150c91;
}
.atlas-marker::before { content: ''; display: inline-block; width: .5em; height: .5em; margin-right: .45em; border-radius: 50%; background: #9ab77e; vertical-align: .11em; }
.atlas-marker[data-state="current"] { background: #cb9053; border-color: #fbd29c; color: #1e180f; }
.atlas-marker[data-state="current"]::before { background: #382a16; }
.atlas-marker[data-state="locked"] { border-style: dashed; background: #262820d9; color: #d5cbb2; }
.atlas-marker[data-state="locked"]::before { background: #929484; }
.atlas-marker[aria-pressed="true"] { outline: 2px solid #ffe0aa; outline-offset: 2px; }
.atlas-caption { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; padding: 12px 16px; color: #d5cbb4; font-size: .85rem; }
.atlas-caption strong { color: #efb976; }

@media (prefers-reduced-motion:reduce) {
  .atlas-terrain.pan .atlas-art, .atlas-terrain.pan #atlas-markers { animation: none; }
}
@media (max-width:700px) {
  .mission-report { grid-column: 1 / -1; }
  .atlas-marker { padding: 6px; }
  .field-hud { inset: auto 4px 4px; gap: 3px; font-size: .62rem; }
  .field-hud > span { padding: 3px 5px; }
  #combat-goal { max-width: 62%; }
}
@media (max-width:430px) {
  .header-actions { gap: 4px; }
  .header-actions .quiet { padding-inline: 6px; }
  .brand { gap: 5px; font-size: .64rem; }
  .brand-mark { width: 12px; height: 14px; }
  .message { max-width: 55%; font-size: .55rem; }
}
@media (pointer:coarse) {
  .battle-hud .ammo-chip { min-height: 43px; min-width: 59px; }
  .touch-controls { line-height: 1.32; }
  .atlas-marker { min-height: 35px; }
}
@media (orientation:landscape) and (max-height:540px) and (pointer:coarse) {
  .shell { padding-inline: 8px; }
  .masthead { height: 40px; }
  .game-layout { grid-template-columns: minmax(0,1fr) 180px; gap: 7px; }
  .arena[data-screen="battle"] { width: min(100%,calc((100dvh - 52px) * 1.6)); margin-inline: auto; }
  .game-layout:has(.arena[data-screen="battle"]) .report { max-height: calc(100dvh - 46px); overflow: auto; }
  .report { padding-inline: 8px; }
  .controls { min-height: 28px; padding-top: 3px; }
}

.touch-deck { display: none; }
.touch-pad {
  position: relative; min-height: 91px; display: grid; place-items: end center; padding: 3px;
  border: 1px solid #443f33; border-radius: 7px; color: #d8c6a9; font: 650 .64rem/1.1 var(--mono);
  background: radial-gradient(circle at 50% 42%,#37372b 0 21%,#282a22 22% 31%,#1b1e18 32%);
  user-select: none; touch-action: none;
}
.touch-pad i {
  position: absolute; inset: 42% auto auto 50%; width: 16px; height: 16px; border-radius: 50%;
  background: #ca9960; border: 1px solid #f7c391;
  transform: translate(calc(-50% + var(--stick-x,0px)),calc(-50% + var(--stick-y,0px)));
}
@media (pointer:coarse) and (orientation:portrait) {
  .touch-deck:not([hidden]) { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 5px; }
}
@media (max-width:430px) {
  .cover-actions .primary { gap: 8px; padding: 8px 9px; font-size: .73rem; }
  .cover-actions .quiet { padding: 8px 9px; }
}

.battle-actions { display: flex; align-items: center; gap: 5px; }
.battle-hud .dodge { pointer-events: auto; border-color: #8c7658; min-width: 60px; min-height: 37px; color: #ffe3ad; }
@media (max-width:570px) {
  .arena .message { top: 56px; max-width: 86%; }
  .battle-hud .dodge { min-height: 39px; padding-inline: 7px; }
}

/* Combat controls share the battlefield on every screen size. */
.wave-chip small { display: block; color: var(--subtle); font-size: .61rem; margin-top: 2px; }
.combat-pause { pointer-events: auto; margin-left: auto; margin-right: 6px; min-height: 39px; }
.field-hud { gap: 4px; }
#combat-goal { flex: 1 1 100%; max-width: 100%; margin-left: 0; text-align: left; }
.touch-deck { position: absolute; inset: auto 14px 57px; pointer-events: none; justify-content: space-between; z-index: 2; }
.touch-pad { pointer-events: auto; width: 90px; height: 90px; min-height: 90px; border-radius: 50%; background-color: #17251dba; }
.touch-pad span { padding-bottom: 6px; }
.modal > .wide + .wide { margin-top: 8px; }
.arrival-note { border-left: 2px solid var(--copper); padding-left: 8px; }
.regroup .save-status { color: #a6c396; font-size: .69rem; }
@media (pointer:coarse) {
  .touch-deck:not([hidden]) { display: flex; }
}
@media (max-width:700px), (pointer:coarse) and (max-width:1100px), (max-width:1100px) and (max-height:540px) {
  body.combat-view { overflow: hidden; scrollbar-gutter: auto; }
  body.combat-view .shell { padding: 0; }
  body.combat-view .masthead,
  body.combat-view .report,
  body.combat-view .controls { display: none; }
  body.combat-view .game-layout { display: block; }
  body.combat-view .arena {
    position: fixed; inset: 0; width: 100%; height: 100dvh; min-height: 0; margin: 0;
    aspect-ratio: auto; border: 0; border-radius: 0; background: #17221a;
  }
  body.combat-view canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
  .battle-hud { z-index: 3; inset: max(9px,env(safe-area-inset-top)) max(10px,env(safe-area-inset-right)) max(15px,env(safe-area-inset-bottom)) max(10px,env(safe-area-inset-left)); }
  .wave-chip { max-width: 64%; padding: 7px 10px; font-size: .77rem; }
  .combat-pause { min-height: 44px; min-width: 64px; margin: 0; }
  .battle-actions { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); gap: 8px; }
  .battle-hud .dodge, .battle-hud .ammo-chip { min-height: 52px; min-width: 63px; font-size: .8rem; }
  .field-hud { z-index: 2; inset: calc(max(9px,env(safe-area-inset-top)) + 56px) 10px auto; font-size: .66rem; }
  .field-hud > span { padding: 5px 6px; }
  .arena .message { top: auto; bottom: 127px; max-width: 92%; font-size: .66rem; }
  .touch-deck:not([hidden]) { display: flex; inset: auto max(14px,env(safe-area-inset-right)) max(17px,env(safe-area-inset-bottom)) max(14px,env(safe-area-inset-left)); margin: 0; }
  .touch-pad { width: 88px; height: 88px; min-height: 88px; font-size: .63rem; }
  .combat-view .overlay { padding: 14px; z-index: 5; }
  .combat-view .modal { max-height: 94dvh; overflow: auto; }
  .regroup-banner div { max-width: 88%; padding: 10px; }
  .regroup-banner span { font-size: .7rem; }
}
@media (orientation:landscape) and (max-height:540px) {
  .combat-view .field-hud { top: 60px; max-width: calc(100% - 185px); }
  .combat-view #combat-goal { flex-basis: auto; }
  .combat-view .battle-actions { bottom: 0; }
  .combat-view .arena .message { bottom: 110px; }
}
@media (max-width:700px), (pointer:coarse) and (max-width:1100px), (max-width:1100px) and (max-height:540px) {
  body[data-screen="regroup"] { overflow: hidden; }
  body[data-screen="regroup"] .shell { padding: 0; }
  body[data-screen="regroup"] .masthead { height: 46px; padding-inline: 9px; }
  body[data-screen="regroup"] .game-layout {
    height: calc(100dvh - 46px); display: grid; grid-template-columns: minmax(0,1fr);
    grid-template-rows: minmax(160px,34dvh) minmax(0,1fr); gap: 0;
  }
  body[data-screen="regroup"] .left { height: 100%; min-height: 0; }
  body[data-screen="regroup"] .arena { height: 100%; min-height: 0; width: 100%; aspect-ratio: auto; border-radius: 0; }
  body[data-screen="regroup"] canvas { width: 100%; height: 100%; object-fit: contain; }
  body[data-screen="regroup"] .controls { display: none; }
  body[data-screen="regroup"] .report { min-height: 0; overflow: auto; display: block; border-radius: 0; padding: 0 12px 12px; }
  body[data-screen="regroup"] .report-heading,
  body[data-screen="regroup"] .theater,
  body[data-screen="regroup"] .metrics { display: none; }
  body[data-screen="regroup"] .regroup-banner { display: none; }
  body[data-screen="regroup"] .field-hud { inset: 5px 5px auto; font-size: .57rem; }
  body[data-screen="regroup"] #combat-goal { display: none; }
  body[data-screen="regroup"] .field-hud > span { padding: 3px 5px; }
}
@media (orientation:landscape) and (max-height:540px) and (max-width:1100px) {
  body[data-screen="regroup"] .game-layout { grid-template-columns: minmax(0,1fr) 290px; grid-template-rows: minmax(0,1fr); }
  body[data-screen="regroup"] .arena { height: 100%; }
}

/* Phone-first flow: scroll to prepare; clear combat lanes for thumbs. */
html { overflow-x: clip; }
canvas { touch-action: pan-y; }
.arena[data-screen="battle"] canvas { touch-action: none; }
.quick-guide { color: var(--subtle); font-size: .9rem; }
#view-mode { display: none; pointer-events: auto; }
.deploy-shop summary, .supplies summary { cursor: pointer; padding: 12px 0; font-weight: 700; color: var(--copper); }
@media (max-width:700px) {
  :root { scrollbar-gutter: auto; }
  .shell { padding: 0 10px 20px; }
  .masthead { height: auto; min-height: 60px; gap: 8px; flex-wrap: wrap; padding-block: 8px; }
  .header-actions .quiet, button.quiet, button.primary { min-height: 44px; font-size: .875rem; }
  .brand { font-size: .7rem; }
  #pause { display: none; }
  .arena[data-screen="title"] { aspect-ratio: auto; min-height: 440px; }
  .cover { position: relative; min-height: 440px; padding: 36px 24px; align-items: end; background-position: center,60% center; }
  .cover-inner { width: 100%; }
  .cover p { font-size: 1rem; max-width: 285px; line-height: 1.45; }
  .cover .quick-guide { font-size: .875rem; }
  .cover-actions { display: grid; }
  .cover-actions button { width: 100%; min-height: 52px; font-size: 1rem; }
  body[data-screen="title"] .report, body[data-screen="title"] .controls { display: none; }
  body[data-screen="regroup"] { overflow: auto; }
  body[data-screen="regroup"] .shell { padding-bottom: 24px; }
  body[data-screen="regroup"] .game-layout { height: auto; display: flex; flex-direction: column; gap: 0; }
  body[data-screen="regroup"] .left { width: 100%; height: auto; }
  body[data-screen="regroup"] .arena { aspect-ratio: 8/5; height: auto; }
  body[data-screen="regroup"] .report { width: 100%; overflow: visible; padding: 0 14px 20px; }
  body[data-screen="regroup"] .field-hud { display: none; }
  .regroup { display: flex; flex-direction: column; }
  .regroup-heading { order: -3; }
  #next { order: -2; position: sticky; top: 8px; z-index: 4; margin-top: 8px; box-shadow: 0 3px 15px #0009; min-height: 52px; }
  #wave-summary { order: -1; }
  .report .panel, .report .resources, .report .record { display: none; }
  .shop-item > span:first-child, .battle-orders summary { font-size: .875rem; }
  .shop-item small, .regroup p, .unit-orders span { font-size: .875rem; }
  .shop-item { min-height: 60px; }
  .battle-orders summary { padding-block: 12px; }
  body.combat-view canvas { inset: 104px 0 160px; height: calc(100% - 264px); }
  .combat-view .battle-hud { inset: max(8px,env(safe-area-inset-top)) 10px max(14px,env(safe-area-inset-bottom)); gap: 6px; }
  .combat-view .wave-chip { font-size: .75rem; max-width: 45%; }
  .combat-view #view-mode { display: block; margin-left: auto; min-height: 44px; }
  .combat-view .field-hud { top: 66px; font-size: .75rem; flex-wrap: nowrap; }
  .combat-view .field-hud > span:nth-child(2), .combat-view .field-hud > span:nth-child(4), .combat-view .field-hud > span:nth-child(5), .combat-view #combat-goal { display: none; }
  .combat-view .touch-deck:not([hidden]) { bottom: 60px; }
  .combat-view .touch-pad { width: 100px; height: 100px; font-size: .875rem; }
  .combat-view .battle-actions { bottom: 0; width: 100%; justify-content: center; }
  .combat-view .battle-hud .dodge, .combat-view .battle-hud .ammo-chip { min-height: 44px; min-width: 110px; }
  .combat-view .arena .message { bottom: 168px; }
}
@media (orientation:landscape) and (max-height:540px) and (max-width:1100px) {
  body[data-screen="regroup"] { overflow: auto; }
  body[data-screen="regroup"] .game-layout { height: auto; min-height: calc(100dvh - 46px); }
  body[data-screen="regroup"] .report { overflow: visible; }
}
/* Daylight command post and readable army orders. */
:root { --page: #202d31; --panel: #2c3d40; --line: #577074; --subtle: #d3dfdc; --muted: #bacdca; --copper: #ffc17c; --green: #a5d797; }
.arena { background: #657c52; border-color: #8da39a; }
.report { background: linear-gradient(145deg,#31454a,#293b3d); }
.quiet { background: #263b40; color: #e2eeeb; }
.metrics, .shop-item { background: #24383b; }
.mission-card { background: #3e4837; border-color: #a6ac71; }
.troop-commands { pointer-events: auto; display: flex; gap: 5px; position: absolute; top: 64px; right: 0; }
.troop-commands button { min-height: 44px; }
.troop-commands [aria-pressed="true"] { background: #aee2de; color: #13343c; border-color: #e2ffff; }
.threat-preview { border-block: 1px solid var(--line); margin: 6px 0 14px; padding: 10px 0; }
.threat-preview h4 { margin: 0 0 6px; color: var(--copper); }
.threat-preview p, .performance { font-size: .875rem; line-height: 1.5; }
.performance { color: #b7efeb; border-left: 2px solid #83d9dc; padding-left: 9px; }
.unit-orders { grid-template-columns: minmax(0,1fr) auto; width: 100%; border-top: 1px solid var(--line); padding: 8px 0; gap: 6px; }
.unit-specialization { color: var(--ink); background: #263b40; border: 1px solid #7b9596; border-radius: 4px; min-height: 44px; font: inherit; font-size: .875rem; padding: 6px 24px 6px 8px; min-width: 0; width: 100%; appearance: none; background-image: linear-gradient(45deg,transparent 50%,#ddd 50%),linear-gradient(135deg,#ddd 50%,transparent 50%); background-position: calc(100% - 12px) 19px,calc(100% - 8px) 19px; background-size: 4px 4px; background-repeat: no-repeat; }
#combat-phase { color: #ffe2a6; }
@media (min-width:701px) { .quick-guide { display: none; } .battle-hud .troop-commands { top: 62px; } }
@media (max-width:700px) {
  body.combat-view .arena { background: #243d42; }
  .combat-view canvas { inset: 110px 0 210px; height: calc(100% - 320px); }
  .combat-view .troop-commands { top: auto; bottom: 0; left: 0; right: 0; justify-content: center; }
  .combat-view .troop-commands button { flex: 1; min-height: 44px; max-width: 130px; }
  .combat-view .battle-actions { bottom: 52px; }
  .combat-view .touch-deck:not([hidden]) { bottom: 112px; }
  .combat-view .arena .message { bottom: 215px; }
  .combat-view .field-hud { flex-wrap: wrap; gap: 3px; }
  .combat-view #combat-phase { display: block; }
}
@media (orientation:landscape) and (max-height:540px) {
  .combat-view .troop-commands { top: auto; bottom: 62px; right: 104px; left: auto; }
  .combat-view .troop-commands button { min-height: 40px; font-size: .8rem; }
}
@media (max-width:700px) and (orientation:portrait) {
  body.combat-view canvas { inset: 110px 0 210px; height: calc(100% - 320px); }
}
