/* Touch mode can also be previewed with ?touch=1. Only the battlefield owns gestures. */
#battle { touch-action:none; -webkit-user-select:none; user-select:none; -webkit-touch-callout:none; }
.battle-navigation,.battle-tools,.touch-hint { display:none; }
.touch-controls .battle-navigation { display:block; }
.touch-controls .battle-tools { display:flex;align-items:center;gap:4px;flex-wrap:wrap;margin:6px 0; }
.touch-controls .battle-tools button { min-width:44px;min-height:44px;padding:8px 10px;background:#182c30;color:#ecdfc3;border:1px solid #73908a;border-radius:3px;font:inherit;font-size:12px;touch-action:manipulation; }
.touch-controls .battle-tools output { min-width:42px;font-size:11px;text-align:center; }
.touch-controls .battle-tools button[aria-expanded="true"] { border-color:#ebbd70;background:#463c29; }
.touch-controls .battle-tools [hidden] { display:none; }
.touch-controls #touch-inspector,.touch-controls #cancel-placement { flex:0 0 112px;height:44px;padding:6px 5px;line-height:14px; }
.touch-controls #cancel-placement { order:-1; }
.touch-controls .touch-hint { display:block;margin:4px 0 8px;font-size:11px;color:#c1d5cf; }
.touch-hint small { display:block;color:#b4c4bb;margin-top:3px; }
.touch-controls .battle-wrap { overflow:clip; }
.touch-controls button,.touch-controls select,.touch-controls summary { min-height:44px;touch-action:manipulation; }
.touch-controls input[type="range"] { min-height:44px; }
.touch-controls input[type="range"]::-webkit-slider-thumb { min-width:24px;min-height:24px; }
.touch-controls .tower-tooltip { display:none!important; }
.touch-controls .build-editor { display:none!important; }
.touch-controls.touch-inspector-open .build-editor { display:grid!important; }
.touch-controls .field-settings>summary { display:flex;align-items:center; }
.touch-controls .main-menu-panel button { min-height:44px; }
.turret-flyout { display:none; }
.touch-controls .turret-flyout:not([hidden]) { position:fixed;z-index:9;display:grid;gap:3px;width:min(284px,calc(100vw - 16px));max-height:calc(100dvh - 16px);overflow:auto;padding:10px;border:1px solid #a5bfad;border-radius:7px;background:#14252cf5;box-shadow:0 8px 28px #0009;font-size:12px;touch-action:pan-y; }
.turret-flyout header { display:flex;align-items:center;justify-content:space-between;gap:6px; }
.turret-flyout header strong { color:#eddfb6;font-size:13px; }
.turret-flyout label { display:flex;justify-content:space-between;color:#d0ded6; }
.turret-flyout input { width:100%;margin:0;accent-color:#e8bc6c;touch-action:pan-y; }
.touch-controls .turret-flyout button { padding:7px 8px;border:1px solid #6c8a8a;border-radius:3px;background:#243b42;color:#edf0df;font-size:12px; }
.touch-controls .turret-flyout header button { min-width:44px;font-size:23px;padding:0; }
.turret-flyout-actions { display:grid;grid-template-columns:1fr 1.25fr;gap:6px; }
.touch-controls .turret-flyout .remove-control { grid-column:auto;background:#462c29;border-color:#b27765;color:#f0c7b0; }
.turret-flyout button:disabled,.turret-flyout input:disabled { opacity:.45; }
.turret-flyout p { margin:3px 0;color:#e3c18e;font-size:11px;line-height:1.4; }
.turret-flyout p[hidden] { display:none; }
@media(prefers-reduced-motion:no-preference) { .touch-controls .turret-flyout:not([hidden]) { animation:turret-flyout-in .14s ease-out; } }
@keyframes turret-flyout-in { from { opacity:0;transform:translateY(5px); } to { opacity:1;transform:translateY(0); } }
/* Keep a desktop-like field and docked inspector in landscape; page scroll stays
   available outside the canvas. No stretched map or document-wide gesture trap. */
@media(orientation:landscape) {
  .touch-controls .game-shell:is([data-phase="build"],[data-phase="combat"]) { display:grid;grid-template-columns:minmax(0,1fr);gap:6px 10px;width:calc(100% - 16px);max-width:none;padding:8px 0; }
  .touch-controls.touch-inspector-open .game-shell:is([data-phase="build"],[data-phase="combat"]) { grid-template-columns:minmax(0,1fr) min(300px,36vw); }
  .touch-controls .game-shell:is([data-phase="build"],[data-phase="combat"]) .topbar { grid-column:1/-1;grid-row:1;grid-template-columns:auto 1fr;gap:5px;margin:0; }
  .touch-controls .field-brand { display:none; }
  .touch-controls .topbar .hud { grid-column:1;grid-row:1;gap:3px; }
  .touch-controls .hud>div { min-width:0;padding:4px 6px; }
  .touch-controls .hud>.integrity { min-width:88px; }
  .touch-controls .hud strong { font-size:13px; }.touch-controls .hud span { font-size:8px; }
  .touch-controls .combat-tools { grid-column:2;grid-row:1;max-width:none!important;display:flex;flex-wrap:wrap!important;gap:4px;padding:0!important; }
  .touch-controls .combat-tools button { padding:5px 7px;min-width:44px;font-size:10px; }
  .touch-controls #save-status,.touch-controls .combat-tools small { display:none; }
  .touch-controls .game-shell>.field-settings { grid-column:1/-1;grid-row:2;margin:0; }
  .touch-controls .game-shell>.battle-navigation { grid-column:1;grid-row:3; }
  .touch-controls .game-shell>.battle-wrap { grid-column:1;grid-row:4;justify-self:center;align-self:start;width:100%; }
  .touch-controls #battle { width:100%;height:max(170px,calc(100dvh - 230px)); }
  .touch-controls .game-shell>.coach { grid-column:1;grid-row:7;margin:0; }
  .touch-controls .controls { display:contents; }
  .touch-controls .build-list { grid-column:1;grid-row:5;grid-template-columns:repeat(4,minmax(0,1fr)); }
  .touch-controls .build-list .build { min-height:50px;padding:6px 4px 6px 36px;text-align:left; }
  .touch-controls .build-list .build span { font-size:11px; }.touch-controls .build-list .build small { font-size:9px; }
  .touch-controls .turret-card-art { width:32px;height:32px;left:0;top:7px; }
  .touch-controls [data-kind="ricochet"] .turret-card-art:before { width:25px;height:25px;line-height:21px;font-size:21px;margin:2px; }
  .touch-controls .action-list { grid-column:1;grid-row:6; }
  .touch-controls .action-list button { min-height:44px!important;padding:5px 10px; }.touch-controls .action-list span { font-size:12px; }
  .touch-controls .game-shell .build-editor { grid-column:2;grid-row:3/8;grid-template-columns:minmax(0,1fr)!important;align-self:start;gap:8px;padding:10px;margin:0;max-height:calc(100dvh - 120px);overflow:auto; }
  .touch-controls .game-shell .build-editor>* { grid-column:1!important;grid-row:auto!important; }
  .touch-controls .touch-hint { margin-bottom:0; }
}
@media(orientation:portrait) {
  .touch-controls .game-shell { max-width:100%; }
  .touch-controls #battle { width:100%;height:var(--portrait-battle-height,calc(100dvh - 250px)); }
  .touch-controls .field-brand { display:none; }
  .touch-controls .game-shell:is([data-phase="build"],[data-phase="combat"]) { display:flex;flex-direction:column;gap:6px; }
  .touch-controls .topbar { display:flex;flex-direction:column;align-items:stretch;gap:5px;margin:0; }
  .touch-controls .topbar .hud { gap:3px; }
  .touch-controls .hud>div { min-width:0;padding:4px 5px; }
  .touch-controls .hud>.integrity { min-width:88px; }
  .touch-controls .hud strong { font-size:13px; }.touch-controls .hud span { font-size:8px; }
  .touch-controls .combat-tools { display:flex;flex-wrap:wrap;gap:4px; }
  .touch-controls .combat-tools button { flex:1;min-width:44px;padding:5px;font-size:10px; }
  .touch-controls #save-status,.touch-controls #path-heatmap:disabled,.touch-controls .combat-tools small { display:none; }
  .touch-controls .field-settings { margin:0; }
  .touch-controls .battle-tools { margin:0; }
  .touch-controls .controls { display:grid; }
  .touch-controls .game-shell .build-editor { grid-template-columns:minmax(0,1fr);max-height:55dvh;overflow:auto; }
  .touch-controls .game-shell .build-editor>* { grid-column:1!important;grid-row:auto!important; }
  .touch-controls .battle-navigation { margin-bottom:8px; }
  .touch-controls .build-list { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .touch-controls .build-list .build { min-height:70px;padding:10px 6px 10px 52px;text-align:left; }
  .touch-controls .turret-card-art { left:2px;top:8px;width:44px;height:44px; }
}

/* Compact mobile command strip. Existing controls move here once on touch
   activation; desktop markup and handlers are not duplicated. */
.mobile-icon,.touch-build-heading,.touch-more-actions,.touch-build-open { display:none; }
body.touch-controls { min-width:280px; }
.touch-controls .mobile-icon { display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;flex-shrink:0; }
.mobile-icon svg { width:100%;height:100%; }
.touch-controls .mobile-sr-label,.touch-controls .hud-label { position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap; }
.touch-controls .game-shell:is([data-phase="build"],[data-phase="combat"]) { width:calc(100% - 12px);max-width:none;padding:4px 0 12px;gap:4px 8px; }
.touch-controls .game-shell .topbar { display:grid;grid-template-columns:minmax(0,1fr);gap:4px;position:sticky;top:0;z-index:6;align-items:center;margin:0;padding:3px 0;background:#101d22f7; }
.touch-controls .topbar .hud { display:grid;grid-template-columns:1.35fr 1fr .85fr 1fr .85fr;grid-column:auto;grid-row:auto;gap:3px;width:100%; }
.touch-controls .hud>div,.touch-controls .hud>.integrity { display:grid;justify-items:center;align-content:center;gap:0;min-width:0;min-height:36px;padding:2px 3px 4px; }
.touch-controls .hud .mobile-icon { width:13px;height:13px;color:#b4cec4; }
.touch-controls .hud .credits .mobile-icon { color:#e7b963; }
.touch-controls .hud strong { margin:0;font-size:12px;line-height:14px; }
.touch-controls #safehouse-meter { left:4px;bottom:1px;width:calc(100% - 8px);height:2px; }
.touch-controls .game-shell .combat-tools { display:flex;flex-wrap:nowrap!important;grid-column:auto;grid-row:auto;gap:4px;justify-content:stretch;width:100%;max-width:none!important;padding:0!important; }
.touch-controls .combat-tools>#speed,.touch-controls .combat-tools>#pause,.touch-controls .combat-tools>#battle-fit { flex:0 0 44px;min-width:44px;height:44px;padding:5px;margin:0;border:1px solid #657e81;border-radius:3px;background:#1e3339;color:#eae4cc; }
.touch-controls .combat-tools>#speed { flex-basis:56px;order:1;justify-content:center; }
.touch-controls #speed span { font-size:13px; }
.touch-controls #speed::before { content:'»';font-size:19px; }
.touch-controls .combat-tools>#pause { order:2;font-size:19px; }
.touch-controls .combat-tools>#battle-fit { order:3; }
.touch-controls #battle-fit .mobile-icon { width:20px;height:20px; }
.touch-controls .combat-tools>#touch-build-open,.touch-controls .combat-tools>#cancel-placement { display:flex;align-items:center;justify-content:center;gap:4px;order:0;flex:1 1 84px;min-width:84px;height:44px;padding:5px;font-size:13px;line-height:15px;border:1px solid #a59060;border-radius:3px;background:#3e3827;color:#f2dfb8; }
.touch-controls #touch-build-open[aria-expanded="true"] { background:#665432; }
.touch-controls #touch-build-open b { font-size:20px; }
.touch-controls .combat-tools>.field-settings { order:4;flex:0 0 44px;margin:0; }
.touch-controls .field-settings>summary { display:grid;place-items:center;list-style:none;width:44px;height:44px;padding:5px;border-radius:3px; }
.touch-controls .field-settings>summary::-webkit-details-marker { display:none; }
.touch-controls .field-settings>summary .mobile-icon { width:21px;height:21px; }
.touch-controls .field-settings[open]>summary { border-color:#e7b963;background:#433d2a; }
.touch-controls .settings-content { position:fixed;top:calc(var(--touch-hud-height,90px) + 8px);left:8px;right:8px;width:auto;max-width:560px;max-height:calc(100dvh - var(--touch-hud-height,90px) - 20px);margin-left:auto;overflow:auto;padding:12px; }
.touch-controls .main-menu-panel .field-settings>summary { display:none; }
.touch-controls .main-menu-panel .settings-content { position:static;width:100%;max-width:none;max-height:none;margin:0;padding:0;overflow:visible; }
.touch-controls .touch-more-actions { display:flex;gap:6px;flex-wrap:wrap;margin-bottom:10px; }
.touch-controls .touch-more-actions #save-status { display:block;text-align:left;width:100%; }
.touch-controls .touch-more-actions #path-heatmap:disabled { display:block; }
.touch-controls .settings-content .battle-navigation { display:block;margin:10px 0 0; }
.touch-controls .settings-content .battle-tools { display:flex;flex-wrap:wrap; }
.touch-controls .game-shell>.battle-wrap { grid-row:2;grid-column:1; }
.touch-controls .game-shell #battle { height:var(--touch-battle-height,calc(100dvh - 115px)); }
.touch-controls .game-shell>.coach { grid-row:4; }
.touch-controls .game-shell .action-list { grid-row:3; }
.touch-controls .game-shell .build-editor { grid-row:2/5; }
.touch-controls .touch-build-backdrop:not([hidden]) { display:block;position:fixed;inset:0;z-index:10;background:#030b10a6;touch-action:manipulation; }
.touch-controls .game-shell .build-list:not([hidden]) { position:fixed;z-index:11;left:50%;bottom:max(8px,env(safe-area-inset-bottom));transform:translateX(-50%);display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;width:min(720px,calc(100% - 24px));max-height:calc(100dvh - 24px);overflow:auto;margin:0;padding:12px;border:1px solid #95b5ac;border-radius:10px;background:#14272dfc;box-shadow:0 8px 40px #000b; }
.touch-controls .touch-build-heading { display:flex;grid-column:1/-1;align-items:center;justify-content:space-between;gap:8px; }
.touch-build-heading h3 { margin:0;color:#eee1bc;font-size:16px; }
.touch-controls #touch-build-close { width:44px;min-width:44px;padding:0;border:1px solid #69858b;border-radius:3px;background:#223a40;color:#e5e5d6;font-size:23px; }
.touch-controls .game-shell .build-list .build { min-height:82px;padding:10px 6px 10px 48px; }
.touch-controls .game-shell .build-list .build span { font-size:13px; }.touch-controls .game-shell .build-list .build small { font-size:11px; }
.touch-controls .game-shell .turret-card-art { width:40px;height:40px;left:3px;top:12px; }
.touch-controls .touch-build-status { position:absolute;top:6px;left:6px;right:6px;z-index:3;margin:0;padding:6px 8px;border:1px solid #c4ac70;border-radius:3px;background:#15252de8;color:#f2ddaf;font-size:11px;pointer-events:none; }
.touch-controls .turret-flyout:not([hidden]) { max-height:calc(100dvh - var(--touch-hud-height,90px) - 16px); }
@media(orientation:portrait) {
  .touch-controls .game-shell #battle { height:min(var(--touch-battle-height,calc(100dvh - 115px)),calc((100vw - 14px)*var(--battle-ratio,1.777778))); }
  .touch-controls .game-shell>.battle-wrap { order:1; }.touch-controls .game-shell>.controls { order:2; }.touch-controls .game-shell>.coach { order:3; }
  .touch-controls .game-shell>.controls { display:block;margin:0; }
}
@media(orientation:landscape) and (min-width:700px) {
  .touch-controls .game-shell:is([data-phase="build"],[data-phase="combat"]) .topbar { grid-template-columns:minmax(0,1fr) minmax(300px,1fr);gap:8px; }
  .touch-controls .game-shell .build-list:not([hidden]) { grid-template-columns:repeat(4,minmax(0,1fr)); }
}
/* Controls occupy their own layout area, never the selected gun's pixels. */
.touch-controls .game-shell { overflow-anchor:none; }
.touch-controls .turret-flyout:not([hidden]) { position:relative;left:auto!important;top:auto!important;z-index:4;order:2;grid-column:1;grid-row:3;width:100%;max-height:none;box-shadow:none;display:grid;grid-template-columns:1fr 1fr;gap:2px 12px;padding:6px 10px;margin:0;overflow:visible; }
.touch-controls .turret-flyout header { grid-column:1/-1;grid-row:1; }
.touch-controls .turret-flyout label[for="touch-rotation"] { grid-column:1;grid-row:2; }
.touch-controls #touch-rotation { grid-column:1;grid-row:3; }
.touch-controls .turret-flyout label[for="touch-cone"] { grid-column:2;grid-row:2; }
.touch-controls #touch-cone { grid-column:2;grid-row:3; }
.touch-controls .turret-flyout-actions,.touch-controls #touch-place-confirm { grid-column:1;grid-row:4; }
.touch-controls #touch-turret-details { grid-column:2;grid-row:4; }
.touch-controls #touch-place-confirm { grid-column:1/-1;background:#4c6344;border-color:#a9d68f; }
.touch-controls #touch-turret-lock { grid-column:1/-1;grid-row:5; }
.touch-controls .turret-flyout [hidden] { display:none!important; }
@media(orientation:landscape) {
  .touch-controls.touch-panel-open .game-shell:is([data-phase="build"],[data-phase="combat"]) { grid-template-columns:minmax(0,1fr) min(300px,38vw); }
  .touch-controls .turret-flyout:not([hidden]) { grid-column:2;grid-row:2/5;align-self:start;max-height:calc(100dvh - var(--touch-hud-height,54px) - 14px);overflow:auto; }
}
