/* GB16.1 button layout repair. Historical implementations remain in the archived releases.
   Layout controls the presentation only; world geometry and combat stay fixed. */
:root{--bg:#e8e3ce;--panel:#f7f0d9;--ink:#293c32;--muted:#677361;--accent:#316350;--line:#9caa80}
*{box-sizing:border-box}
html,body{height:100%;min-height:100dvh}
body{margin:0;overflow:hidden;font-size:14px;background:#92ac75}
.defense-shell{width:100%;padding:0;margin:0}
.game-header{display:none!important}
.game-shell{--rail-width:192px;--safe-top:env(safe-area-inset-top,0px);--safe-right:env(safe-area-inset-right,0px);--safe-bottom:env(safe-area-inset-bottom,0px);--safe-left:env(safe-area-inset-left,0px);position:fixed;left:var(--visible-left,0px);top:var(--visible-top,0px);width:var(--visible-width,100%);height:var(--visible-height,100dvh);min-height:0;overflow:hidden;background:#92ac75;container-name:battlefield;container-type:size}
.game-shell [hidden],.error[hidden]{display:none!important}
.battle-region,.map-frame{position:absolute;inset:0;overflow:hidden}
#battle{display:block;width:100%;height:100%;touch-action:none;cursor:url('./cursor-glove.svg') 16 3,pointer}
#battle[data-pannable="true"]{cursor:grab}
#battle[data-dragging="true"]{cursor:grabbing}
button{display:flex;align-items:center;justify-content:center;min-height:44px;min-width:44px;border:1px solid #a6aa7a;border-radius:9px;padding:7px 10px;gap:5px;font-size:13px;line-height:1.2;color:#314334;background:linear-gradient(#fff5d9,#e9deb7);box-shadow:0 2px #26362622;touch-action:manipulation;cursor:pointer}
button:hover{background:#fff3cb;border-color:#427346}
button:disabled{opacity:.55;cursor:default}
button:focus-visible,summary:focus-visible,[role="button"]:focus-visible{outline:3px solid #1d645c;outline-offset:2px}
button.primary{background:linear-gradient(#b74631,#973327);border:2px solid #923a2a;color:#fff9df;font-weight:800;box-shadow:0 3px #793321}
button.primary:hover{background:#a93c2b}
button.primary:disabled{background:#baa880;border-color:#938167;color:#f8f2dc;box-shadow:none}
.game-shell :is(button,summary,input,[role="button"],canvas){-webkit-tap-highlight-color:transparent}
.control-rail{pointer-events:none}
.control-rail>*{pointer-events:auto}
.hud,.selected-info,.selected-info *{pointer-events:none}
.hud{position:absolute;z-index:5;left:6px;right:auto;top:6px;bottom:auto;width:240px;max-width:calc(100% - 12px);height:70px;min-height:70px;display:grid;grid-template-columns:repeat(3,minmax(0,1fr));grid-template-rows:18px 38px;align-content:center;gap:2px 5px;padding:5px 7px;border:1px solid #96a977;border-radius:9px;color:#fff7db;background:linear-gradient(#426b51f5,#2f5141f5);box-shadow:0 2px 5px #263e2922;transform:none}
.map-heading{grid-column:1/-1;grid-row:1;min-width:0}
.map-heading strong{display:block;font-size:14px;line-height:18px;white-space:nowrap}
.map-heading>span{display:none}
.hud-item{display:flex;align-items:center;grid-row:2;min-width:0;gap:3px}
.hud-item:nth-of-type(2){grid-column:1}
.hud-item:nth-of-type(3){grid-column:2}
.hud-item:nth-of-type(4){grid-column:3}
.hud .resource-icon{display:flex;align-items:center;justify-content:center;flex:none;width:18px;height:18px;font-size:0;line-height:0;color:#e3eab6}
.hud .resource-icon svg{display:block;width:100%;height:100%;overflow:visible;filter:drop-shadow(0 1px 1px #203b3544)}
.hud .lives-icon{color:#ffae96}
.hud .coin-icon{color:#ffd46d}
.hud .resource-copy{display:grid;align-content:center;min-width:0;gap:0;white-space:nowrap}
.hud .resource-label{display:block;font-size:9px;line-height:12px;font-weight:600;color:#e5edce;white-space:nowrap}
.hud .resource-copy strong{display:block;margin:0;font-size:18px;line-height:23px;font-weight:800;font-variant-numeric:tabular-nums;color:#fff9e2;white-space:nowrap}
.hud[data-compact="narrow"]{width:168px;height:80px;min-height:80px;grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:18px 24px 24px;gap:2px 4px;padding:3px 6px}
.hud[data-compact="narrow"] .hud-item:nth-of-type(4){grid-column:1/-1;grid-row:3}
.hud[data-compact="narrow"] .resource-label,.hud[data-compact="true"] .resource-label{position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0,0,0,0);clip-path:inset(50%);white-space:nowrap}
.hud[data-compact="narrow"] .map-heading strong{font-size:12px}
.hud[data-compact="true"]{width:334px;height:34px;min-height:34px;display:flex;gap:7px;padding:4px 6px}
.hud[data-compact="true"] .map-heading{flex:1;min-width:0}
.hud[data-compact="true"] .map-heading strong{font-size:12px;line-height:22px;overflow:hidden;text-overflow:ellipsis}
.hud[data-compact="true"] .hud-item{flex:none;gap:2px}
.hud[data-compact="true"] .resource-icon{width:15px;height:15px}
.hud[data-compact="true"] .resource-copy #wave{font-size:14px}
.wave-forecast{position:absolute;z-index:5;left:6px;top:82px;right:auto;bottom:auto;display:flex;align-items:center;gap:5px;width:max-content;max-width:calc(100% - 12px);min-width:44px;min-height:44px;height:auto;margin:0;padding:5px 7px;border:1px solid #96a977;border-radius:9px;background:#f8f1d8f2;box-shadow:0 2px 5px #263e2922;color:#344a36;font-size:12px;line-height:16px;white-space:nowrap;cursor:pointer;touch-action:manipulation;transform:none;pointer-events:auto}
.wave-forecast:hover{background:#fff8e2;border-color:#427346}
.wave-forecast #wave-label{flex:none;font-size:10px;line-height:13px;color:#4d6443}
.wave-forecast #wave-preview{display:flex;align-items:center;flex-wrap:wrap;gap:4px;min-width:0;overflow:visible}
.wave-forecast #reward{display:none}
.forecast-open-icon{flex:none;font-size:16px;line-height:20px;color:#46664c}
.enemy-card{display:flex;align-items:center;flex:none;gap:3px;min-width:0;min-height:24px;margin:0;padding:0;background:none}
.enemy-icon{width:22px;height:22px;flex:none}
.enemy-name{font-size:11px;line-height:16px}
.enemy-count{font-size:12px;line-height:16px;white-space:nowrap;color:#344a36;font-variant-numeric:tabular-nums}
.enemy-count::before{content:'×';font-size:11px;margin-right:1px}
.enemy-trait,.wave-tactic{display:none}
.selected-info{position:absolute;z-index:5;left:6px;top:132px;width:266px;max-width:calc(100% - 12px);min-height:58px;padding:4px 6px;border:1px solid #96a977;border-radius:9px;background:#f8f1d8f2;box-shadow:0 2px 5px #263e2922}
.panel-heading{display:flex;align-items:center;gap:5px;min-height:44px;margin:0}
.panel-heading canvas{display:block;width:28px;height:28px;flex:none}
.panel-heading>div,.selected-copy{flex:1;min-width:0}
.panel-heading strong{display:block;font-size:13px;line-height:17px;white-space:nowrap}
.selected-values{display:flex;flex-wrap:wrap;gap:0 5px;margin:1px 0 0;font-size:11px;line-height:15px;color:#516246}
.selected-values>span{white-space:nowrap}
.selected-values b{font-size:13px;line-height:15px;color:#354e39}
#close-tower-panel{display:flex;pointer-events:auto;width:44px;height:44px;min-width:44px;min-height:44px;margin-left:auto;padding:2px;font-size:22px;line-height:1;flex:none}
.selected-info[data-compact="true"]{width:178px}
.selected-info[data-compact="true"] .panel-heading canvas{display:none}
.selected-info[data-compact="true"] .selected-values{display:grid;gap:0}
.selected-info[data-compact="true"] .panel-heading{min-height:66px}
.game-dock{position:absolute;z-index:5;left:6px;right:6px;bottom:calc(6px + var(--safe-bottom));height:116px;min-height:116px;padding:2px 6px;border:0;border-radius:11px;outline:1px solid #acb587;background:linear-gradient(#fcf5dcf5,#e7deb9f5);box-shadow:0 3px 8px #2f4b2f33;transform:none;overflow:visible;touch-action:manipulation}
.dock-row{display:flex;flex-direction:column;align-items:stretch;gap:4px;height:100%;min-width:0;min-height:0}
#shop-inline{flex:none;min-width:0;width:100%;margin:0}
#tower-shop{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:4px;width:100%;height:64px}
.tower-button{display:flex;flex-direction:column;align-items:center;justify-content:center;min-width:0;min-height:64px;height:64px;width:100%;padding:2px;gap:0;overflow:visible;text-align:center}
.tower-icon{display:block;width:28px;height:28px;flex:none;background:none;border:0;border-radius:0;box-shadow:none;overflow:visible}
.tower-icon canvas{display:block;width:100%;height:100%}
.tower-copy{display:block;min-width:0;text-align:center}
.tower-copy strong{display:block;font-size:11px;line-height:14px;white-space:nowrap}
.tower-copy small,.tower-afford{display:none}
.tower-price{display:block;font-size:11px;line-height:16px;color:#836122;white-space:nowrap}
.tower-button.active{border:1px solid #377f68;background:#e2edbd;box-shadow:inset 0 0 0 1px #377f68}
.tower-button.unaffordable{background:#e7e3cd;color:#73735f}
.tower-button.unaffordable .tower-price{color:#96633e}
.shop-open,#open-tower-shop{display:none!important}
.play-controls{display:flex;align-items:stretch;gap:4px;width:100%;height:44px;flex:none;flex-wrap:nowrap}
.play-controls>button{height:44px;min-height:44px;min-width:44px;padding:3px;font-size:12px;line-height:14px;white-space:nowrap;flex:none}
#start-wave{flex:1;min-width:44px;width:auto}
.start-icon{display:block;font-size:19px;line-height:24px;height:24px;flex:none}
.wave-button-label{display:block;line-height:16px;white-space:nowrap}
#pause,#speed,#maps{width:44px;min-width:44px;padding:2px}
#pause,#maps{font-size:11px}
/* Pause and Resume share one stable width, including their text padding. */
#pause{width:60px;min-width:60px}
#cancel-placement{width:44px;min-width:44px;padding:2px;font-size:10px;line-height:12px;white-space:normal;color:#783c25;border:2px solid #b27049;background:#ffdfb5;font-weight:700}
#remove-tower{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:0;width:56px;min-width:56px;height:44px;min-height:44px;margin:0;padding:1px;background:#f1dbaa;color:#684c31;border-color:#b9915e;white-space:nowrap}
#remove-icon{display:block;width:20px;height:20px;flex:none}
#refund-value{font-size:12px;line-height:16px;font-weight:750;white-space:nowrap}
.settings-menu{position:relative;display:block;flex:none;width:44px;height:44px;min-width:44px;color:#314334}
.settings-menu summary{list-style:none;width:44px;height:44px;min-width:44px;min-height:44px;display:grid;place-items:center;cursor:pointer;border:1px solid #a6aa7a;border-radius:8px;background:linear-gradient(#fff5d9,#e9deb7);font-size:23px;line-height:1;touch-action:manipulation}
.settings-menu summary::-webkit-details-marker{display:none}
.settings-card{position:absolute;z-index:30;display:grid;gap:8px;width:272px;max-width:calc(var(--visible-width,100vw) - 14px);padding:12px;border:2px solid #92a46c;border-radius:12px;background:#f5ebcc;color:#344a38;box-shadow:0 6px 24px #273d3655;overflow:auto;overscroll-behavior:contain;touch-action:pan-y}
.settings-heading,.forecast-heading{display:flex;align-items:center;justify-content:space-between;gap:6px;min-width:0}
.settings-heading strong{font-size:16px;line-height:21px;min-width:0}
.settings-heading #close-settings{width:44px;min-width:44px;height:44px;min-height:44px;padding:2px;flex:0 0 44px;font-size:22px;line-height:1}
.settings-card>button{width:100%;min-width:44px}
.settings-card input{width:100%;min-height:44px;margin:0;accent-color:#486f4e}
.settings-card a{min-height:44px;display:flex;align-items:center;font-size:13px}
.settings-card small{font-size:12px;line-height:1.35}
.settings-card label{font-size:13px}
#settings-state{color:#39583d;font-weight:700}
.view-settings{display:grid;grid-template-columns:1fr 1fr;gap:6px}
.view-settings button[aria-pressed="true"]{border:2px solid #377f68;background:#e2edbd}
.settings-card .storage-notice{position:static;max-width:100%;padding:8px;border:1px solid #b19459;border-radius:6px;background:#f4e4b7;color:#674827;font-size:12px;line-height:1.4;overflow-wrap:anywhere}
.placement-hint{position:absolute;left:0;right:0;bottom:calc(100% + 5px);display:flex;flex-wrap:wrap;gap:3px 6px;width:max-content;max-width:100%;height:auto;margin:0;padding:5px 7px;border:1px solid #96a977;border-radius:8px;background:#f8f1d8f2;box-shadow:0 2px 5px #263e2922;color:#34482c;pointer-events:none}
.placement-hint strong{font-size:12px;line-height:16px;white-space:nowrap}
.placement-hint>span{font-size:12px;line-height:16px;min-width:0}
.placement-hint .invalid{color:#9b3f28}
.game-shell[data-preview="true"] .placement-hint,.placement-hint[data-preview="true"]{display:none}
.map-caption{display:none}
.scene-help{position:absolute;z-index:5;left:6px;bottom:132px;width:max-content;max-width:calc(100% - 12px);margin:0;padding:5px 8px;border:1px solid #96a977;border-radius:8px;background:#f8f1d8f2;color:#34482c;font-size:12px;line-height:16px;box-shadow:0 2px 5px #263e2922;pointer-events:none}
#first-build-help[data-compact="true"]{max-width:144px}
.tower-panel{position:absolute;z-index:8;width:330px;max-width:calc(100% - 14px);padding:7px;border:2px solid #789052;border-radius:12px;background:linear-gradient(#fff6dbfa,#e6ddb8fc);box-shadow:0 5px 16px #293c3740;overflow:visible;touch-action:manipulation}
.tower-panel[data-layout="dock"]{position:static;left:auto;top:auto;width:100%;max-width:none;max-height:none;margin:0;padding:0;border:0;border-radius:0;background:none;box-shadow:none;overflow:visible}
#branches{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:4px;width:100%;height:88px}
.branch-button,#range-upgrade{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:0;width:100%;min-width:0;min-height:88px;height:88px;margin:0;padding:2px;text-align:center}
.upgrade-preview{display:block;width:22px;height:22px;flex:none}
.branch-copy{display:block;flex:none;width:100%;min-width:0;text-align:center}
.branch-copy strong{display:block;font-size:11px;line-height:14px;white-space:nowrap}
.branch-copy strong span{display:block;font-size:11px;line-height:14px;color:#805d22;white-space:nowrap}
.branch-copy strong .branch-full-name{display:inline;font-size:inherit;line-height:inherit;color:inherit;white-space:inherit}
.branch-copy strong .branch-short-name{display:none;font-size:inherit;line-height:inherit;color:inherit;white-space:inherit}
.branch-role{display:none}
.branch-stats{display:block;min-width:0;font-size:10px;line-height:13px;white-space:nowrap;color:#3e573b;font-weight:650}
.branch-afford{display:block;font-size:10px;line-height:13px;white-space:nowrap;color:#8d3c28;font-weight:700}
.branch-short-reason{display:none}
.branch-button:disabled,#range-upgrade:disabled{opacity:1;background:#e9e7ca;color:#66715b;border-color:#b8c099}
.branch-button.chosen,#range-upgrade[data-purchased="true"]{background:#d9e7bb;color:#37583b;border-color:#72945e}
.branch-button.chosen .branch-afford{color:#37583b}
#range-upgrade{background:#dce9c5;border-color:#739757}
#range-icon{display:block;width:26px;height:26px;flex:none}
.range-copy{display:block;min-width:0;max-width:100%;text-align:center}
#range-upgrade strong{display:block;font-size:11px;line-height:14px;white-space:nowrap}
.range-name-prefix{display:none}
#range-detail{display:block;font-size:10px;line-height:13px;white-space:normal;color:#3e573b;font-weight:650}
#range-price{display:block;font-size:11px;line-height:14px;color:#805d22;white-space:nowrap}
.game-shell[data-selected-tower="true"] .game-dock{height:144px;min-height:144px;padding:6px}
.placement-actions{position:absolute;z-index:9;display:flex;flex-direction:column;align-items:stretch;gap:4px;width:max-content;max-width:min(220px,calc(100% - 14px));padding:4px;border:1px solid #687d4b;border-radius:10px;background:#f4edc8;box-shadow:0 3px 10px #243d3455;touch-action:manipulation;pointer-events:none}
.placement-actions .confirm-build{pointer-events:auto;min-width:104px;min-height:44px;font-size:14px;padding:7px 12px}
.confirm-build.primary{background:linear-gradient(#4d8b60,#356c49);border-color:#295e3f;color:#fff8e1;box-shadow:0 2px #294f34}
#placement-reason{display:block;max-width:208px;padding:0 3px;text-align:center;font-size:12px;line-height:16px;color:#34482c}
#placement-reason:empty{display:none}
#placement-reason.invalid{color:#963c26;font-weight:700}
.placement-actions::before{content:'';position:absolute;width:10px;height:10px;background:#f4edc8;border-left:1px solid #687d4b;border-top:1px solid #687d4b;pointer-events:none}
.placement-actions[data-side="below"]::before{left:var(--anchor-x);top:-6px;transform:translateX(-50%) rotate(45deg)}
.placement-actions[data-side="above"]::before{left:var(--anchor-x);bottom:-6px;transform:translateX(-50%) rotate(225deg)}
.placement-actions[data-side="right"]::before{left:-6px;top:var(--anchor-y);transform:translateY(-50%) rotate(-45deg)}
.placement-actions[data-side="left"]::before{right:-6px;top:var(--anchor-y);transform:translateY(-50%) rotate(135deg)}
.feedback{position:absolute;z-index:10;pointer-events:none;padding:7px 10px;border-radius:7px;background:#fff4d8f5;border:1px solid #b6ac78;font-size:12px;line-height:1.3;max-width:min(270px,calc(100% - 14px));box-shadow:0 3px 10px #344b3840}
.pause-note{position:absolute;z-index:3;top:6px;left:7px;padding:5px 8px;background:#293f32dc;color:#fff0b7;border-radius:6px;font-size:12px;pointer-events:none}
.pause-note span{display:none}
.camera-controls{position:absolute;z-index:6;display:flex;gap:4px;padding:3px;border:1px solid #9caa80;border-radius:10px;background:#f7f0d9ef;box-shadow:0 2px 8px #18352a33}
.camera-controls button{width:44px;height:44px;padding:2px;min-width:44px;font-size:21px;line-height:1}
.camera-controls #zoom-fit{font-size:13px}
.forecast-details{position:absolute;z-index:26;left:7px;top:7px;width:min(310px,calc(100% - 14px));max-height:calc(100% - 14px);padding:8px 10px;border:2px solid #789052;border-radius:12px;background:linear-gradient(#fff6db,#e6ddb8);box-shadow:0 5px 18px #293c3755;overflow:auto;overscroll-behavior:contain;touch-action:pan-y}
.forecast-heading{margin-bottom:6px}
.forecast-heading strong{font-size:16px;line-height:21px}
#close-forecast{width:44px;height:44px;min-width:44px;min-height:44px;flex:none;padding:2px;font-size:22px}
#forecast-detail-content{font-size:13px;line-height:1.45}
#forecast-detail-content .enemy-card{display:grid;grid-template-columns:30px 1fr auto;grid-template-rows:auto auto;gap:1px 6px;margin:6px 0;padding:6px;border-radius:7px;background:#d8e1bb66}
#forecast-detail-content .enemy-icon{width:30px;height:30px;grid-column:1;grid-row:1/3}
#forecast-detail-content .enemy-name{display:block;grid-column:2;grid-row:1;font-size:13px;line-height:18px}
#forecast-detail-content .enemy-count{grid-column:3;grid-row:1;font-size:14px;line-height:18px}
#forecast-detail-content .enemy-trait{display:block;grid-column:2/4;grid-row:2;font-size:12px;line-height:17px;white-space:normal;color:#53644b}
#forecast-detail-content p{margin:6px 0}
.game-overlay{position:absolute;inset:0;z-index:40;display:flex;align-items:center;justify-content:center;padding:calc(7px + var(--safe-top)) calc(7px + var(--safe-right)) calc(7px + var(--safe-bottom)) calc(7px + var(--safe-left));background:#2a422b75;backdrop-filter:blur(2px)}
.overlay-card{width:min(540px,100%);max-height:100%;overflow:auto;overscroll-behavior:contain;touch-action:pan-y;padding:16px;border:2px solid #a1aa6c;border-radius:15px;background:linear-gradient(#fff4d6,#e6dfb9);box-shadow:0 8px 26px #233a3a55}
.overlay-card .eyebrow{font-size:11px;margin:0;color:#6b7850}
.overlay-card h2{font-size:23px;margin:7px 0;color:#39573d;line-height:1.2}
.overlay-card p{font-size:13px;line-height:1.4}
.overlay-actions{display:flex;flex-wrap:wrap;gap:8px}
.overlay-heading{display:flex;justify-content:space-between;align-items:center;gap:8px}
.overlay-heading>div{min-width:0}
.map-picker{width:min(850px,100%);padding:12px}
#map-cards{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:8px}
.map-card{display:flex;flex-direction:column;align-items:stretch;min-width:0;padding:6px;gap:4px}
.map-card canvas{width:100%;aspect-ratio:20/13;border-radius:5px}
.map-card strong{font-size:14px;line-height:1.4}
.map-card small{font-size:12px;line-height:1.4}
.map-strategy-tip{display:none}
.map-card.chosen{box-shadow:inset 0 0 0 2px #68934e;background:#e7ecce}
#map-warning{color:#81513c}
#tower-picker{width:min(540px,calc(100% - 14px));padding:16px;border:2px solid #a1aa6c;border-radius:15px;background:linear-gradient(#fff4d6,#e6dfb9);color:#293c32}
#tower-picker:not([open]){display:none}
#tower-picker::backdrop{background:#2a422b75;backdrop-filter:blur(2px)}
.shop-heading{display:flex;justify-content:space-between;align-items:center;gap:8px}
.shop-heading h2{margin:7px 0;font-size:23px;line-height:1.2}
#shop-drawer-body #tower-shop{height:auto;grid-template-columns:repeat(3,minmax(0,1fr))}
.sr-only{position:absolute;top:0;left:0;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}
.error{position:fixed;z-index:100;top:8px;left:8px;right:8px;display:flex;align-items:center;gap:10px;padding:10px;border:2px solid #b27049;border-radius:10px;background:#fff0cb;color:#673e2b;box-shadow:0 4px 18px #293c3740}
#load-error-message{flex:1;min-width:0;overflow-wrap:anywhere;font-size:14px;line-height:1.4}
#load-retry{flex:none}
#start-wave[data-ready="true"]{animation:ready-glow 2s ease-in-out infinite}
@keyframes ready-glow{0%,100%{box-shadow:0 3px #793321,0 0 0 0 #ffe8a300}50%{box-shadow:0 3px #793321,0 0 0 3px #ffe8a388}}
@media(prefers-reduced-motion:reduce){#start-wave[data-ready="true"]{animation:none}}

/* A crowded portrait scene uses a small resource card as its final fallback.
   It preserves number size without spanning a road with a full-width stripe. */
.game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="true"]{width:128px;height:96px;min-height:96px;display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:16px 22px 22px 22px;align-content:center;gap:2px;padding:3px 4px}
.game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="true"] .map-heading{grid-column:1/-1;grid-row:1;min-width:0}
.game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="true"] .map-heading strong{font-size:12px;line-height:16px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="true"] .hud-item{grid-row:2;gap:2px;min-width:0}
.game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="true"] .hud-item:nth-of-type(2){grid-column:1;grid-row:2}
.game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="true"] .hud-item:nth-of-type(3){grid-column:1;grid-row:3}
.game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="true"] .hud-item:nth-of-type(4){grid-column:1;grid-row:4}
.game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="true"] .resource-icon{width:14px;height:14px}
.game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="true"] .resource-copy strong{font-size:18px;line-height:22px}
.game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="true"] .resource-copy #wave{font-size:14px;line-height:22px}

/* Keep the enlarged first-map citadel beside the road on narrow phones.
   Use the existing vertical resource shape before moving the card down-field. */
@media(max-width:340px){
  .game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="narrow"]{width:128px;height:96px;min-height:96px;display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:16px 22px 22px 22px;align-content:center;gap:2px;padding:3px 4px}
  .game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="narrow"] .map-heading{grid-column:1/-1;grid-row:1;min-width:0}
  .game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="narrow"] .map-heading strong{font-size:12px;line-height:16px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  .game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="narrow"] .hud-item{grid-column:1;grid-row:2;gap:2px;min-width:0}
  .game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="narrow"] .hud-item:nth-of-type(3){grid-row:3}
  .game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="narrow"] .hud-item:nth-of-type(4){grid-column:1;grid-row:4}
  .game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="narrow"] .resource-icon{width:14px;height:14px}
  .game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="narrow"] .resource-copy strong{font-size:18px;line-height:22px}
  .game-shell[data-layout-device="portrait"][data-side-controls="false"] .hud[data-compact="narrow"] .resource-copy #wave{font-size:14px;line-height:22px}
}
@media(max-width:420px){
  .game-shell[data-layout-device="portrait"][data-side-controls="false"] .scene-help{width:160px;max-width:calc(100% - 12px);white-space:normal}
}
@media(max-width:340px){
  .game-shell[data-layout-device="portrait"][data-side-controls="false"] .scene-help{width:88px}
}

/* Normal mouse/tablet landscape keeps the compact, complete-world desktop UI. */
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .hud{width:344px;height:96px;min-height:96px;display:grid;grid-template-columns:1fr 1.35fr 1.4fr;grid-template-rows:22px 49px;align-content:center;gap:6px 8px;padding:8px 10px;border-radius:11px;box-shadow:0 3px 10px #18352a44}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .map-heading strong{font-size:16px;line-height:22px}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .hud-item{grid-row:2;grid-column:auto;gap:6px;flex:none}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .hud .resource-icon{width:24px;height:24px}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .hud .resource-label{position:static;width:auto;height:auto;margin:0;clip:auto;clip-path:none;overflow:visible;font-size:11px;line-height:14px;letter-spacing:.15px}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .hud .resource-copy strong{font-size:26px;line-height:35px}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .hud .resource-copy #lives{font-size:28px;line-height:35px}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .wave-forecast{top:108px}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .game-dock{left:50%;right:auto;bottom:calc(8px + var(--safe-bottom));width:calc(100% - 16px);max-width:1180px;height:78px;min-height:78px;padding:9px;transform:translateX(-50%)}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .dock-row{flex-direction:row;align-items:center;gap:8px;height:60px}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] #shop-inline{flex:1;min-width:0;width:auto}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] #tower-shop,.game-shell[data-layout-device="desktop"][data-side-controls="false"] #branches{height:60px;gap:6px}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .tower-button,.game-shell[data-layout-device="desktop"][data-side-controls="false"] .branch-button{display:grid;grid-template-columns:28px minmax(0,1fr);align-content:center;justify-content:stretch;gap:0 6px;min-height:60px;height:60px;padding:4px 6px;text-align:left}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .tower-icon,.game-shell[data-layout-device="desktop"][data-side-controls="false"] .upgrade-preview{grid-column:1;grid-row:1/3;width:28px;height:28px}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .tower-copy{grid-column:2;grid-row:1;align-self:end;text-align:left}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .tower-copy strong{font-size:12px;line-height:16px}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .tower-price{grid-column:2;grid-row:2;align-self:start;font-size:12px;line-height:16px}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .branch-copy{grid-column:2;grid-row:1/3;text-align:left}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .branch-copy strong,.game-shell[data-layout-device="desktop"][data-side-controls="false"] .branch-copy strong span{font-size:11px;line-height:12px}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .branch-stats,.game-shell[data-layout-device="desktop"][data-side-controls="false"] .branch-afford{font-size:10px;line-height:11px}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] #range-upgrade{display:grid;grid-template-columns:28px minmax(0,1fr) auto;align-content:center;gap:0 5px;min-height:60px;height:60px;padding:4px 6px;text-align:left}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .range-copy{text-align:left}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .range-name-prefix{display:inline}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] #range-upgrade strong{font-size:12px;line-height:16px}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] #range-detail{font-size:10px;line-height:13px}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] #range-price{font-size:12px;line-height:16px}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] .play-controls{width:auto}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] #start-wave{min-width:90px;flex:none}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] #cancel-placement{width:60px;min-width:60px;white-space:nowrap;font-size:11px}
.game-shell[data-layout-device="desktop"][data-side-controls="false"] #remove-tower{flex-direction:row;gap:4px;min-width:80px;width:80px}

/* Portrait phone cards retain direct access to all three upgrades. */
.game-shell[data-layout-device="portrait"] .enemy-name{display:none}
@container battlefield (max-width:650px) and (max-aspect-ratio:1/1){
  #map-cards{grid-template-columns:repeat(2,minmax(0,1fr));gap:6px}
  .map-card canvas{max-height:77px;object-fit:cover}
  .map-card strong{font-size:13px}
}
/* Keep all actions inside a narrow phone's existing44px row. The crowded
   Start button retains both its play icon and label without growing the dock. */
@container battlefield (max-width:345px) and (max-aspect-ratio:1/1){
  .game-shell[data-layout-device="portrait"] .play-controls{gap:3px}
  .game-shell[data-layout-device="portrait"] #remove-tower{width:44px;min-width:44px}
  .game-shell[data-layout-device="portrait"] .play-controls:has(#cancel-placement:not([hidden])) #start-wave,
  .game-shell[data-layout-device="portrait"][data-selected-tower="true"] #start-wave{flex-direction:column;gap:0;padding:1px}
  .game-shell[data-layout-device="portrait"] .play-controls:has(#cancel-placement:not([hidden])) .start-icon,
  .game-shell[data-layout-device="portrait"][data-selected-tower="true"] .start-icon{font-size:14px;line-height:16px;height:16px}
  .game-shell[data-layout-device="portrait"] .play-controls:has(#cancel-placement:not([hidden])) .wave-button-label,
  .game-shell[data-layout-device="portrait"][data-selected-tower="true"] .wave-button-label{font-size:11px;line-height:14px}
}
@container battlefield (max-width:1050px) and (min-aspect-ratio:1/1){
  .game-shell[data-layout-device="desktop"] .range-name-prefix{display:none}
  .game-shell[data-layout-device="desktop"] .upgrade-preview{width:24px;height:24px}
}

/* Touch landscape is a full-height192px rail. Six visible actions always occupy
   exactly two rows, whether Cancel or Recover replaces the extra Start span. */
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .battle-region{left:var(--safe-left);right:calc(192px + var(--safe-right))}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .control-rail{position:absolute;z-index:5;left:auto;right:var(--safe-right);top:var(--safe-top);bottom:var(--safe-bottom);width:192px;padding:6px;display:flex;flex-direction:column;gap:4px;overflow:visible;border-left:1px solid #7e9566;background:linear-gradient(#f7efd5,#e5ddb9);pointer-events:auto}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .hud{position:relative;inset:auto;width:100%;max-width:none;height:64px;min-height:64px;flex:none;padding:4px;grid-template-columns:.9fr 1fr 1.1fr;grid-template-rows:16px 36px;gap:2px 2px;box-shadow:none;transform:none}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .map-heading strong{font-size:12px;line-height:16px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .hud-item{grid-row:2;gap:2px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .resource-icon{width:14px;height:14px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .resource-label{font-size:9px;line-height:12px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .resource-copy strong{font-size:18px;line-height:22px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .resource-copy #wave{font-size:14px;line-height:22px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .wave-forecast{position:relative;inset:auto;flex:none;width:100%;max-width:none;min-height:44px;height:44px;padding:3px 4px;gap:4px;box-shadow:none;transform:none}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .wave-forecast #wave-label{font-size:10px;line-height:12px;max-width:35px;white-space:normal}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .wave-forecast #wave-preview{gap:2px;flex-wrap:wrap}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .enemy-icon{width:20px;height:20px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .enemy-name{display:none}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .enemy-count{font-size:12px;line-height:16px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .selected-info{position:relative;inset:auto;flex:none;width:100%;max-width:none;min-height:56px;height:56px;padding:2px 3px;transform:none;box-shadow:none}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .selected-info .panel-heading{min-height:50px;gap:3px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .selected-info .panel-heading canvas{display:none}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .selected-info .panel-heading strong{font-size:12px;line-height:16px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .selected-values{font-size:11px;line-height:14px;gap:0 4px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .selected-values b{font-size:12px;line-height:14px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-selected-tower="true"] .wave-forecast{display:none}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .game-dock{position:relative;inset:auto;flex:1;min-height:0;height:auto;width:100%;max-width:none;margin:0;padding:0;border:0;border-radius:0;outline:0;background:none;box-shadow:none;transform:none;overflow:visible}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .dock-row{height:100%;min-height:0;gap:4px;justify-content:space-between}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] #shop-inline{margin-top:auto;margin-bottom:auto;flex:none}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] #tower-shop{grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:repeat(3,48px);height:152px;gap:4px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .tower-button{display:grid;grid-template-columns:28px minmax(0,1fr);grid-template-rows:14px 16px;align-content:center;align-items:center;justify-content:stretch;gap:0 3px;min-height:48px;height:48px;padding:3px;text-align:left}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .tower-button:last-child{grid-column:1/-1}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .tower-icon{grid-column:1;grid-row:1/3;width:28px;height:28px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .tower-copy{grid-column:2;grid-row:1;text-align:left}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .tower-price{grid-column:2;grid-row:2}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] #branches{grid-template-columns:repeat(3,minmax(0,1fr));height:96px;gap:3px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .branch-button,.game-shell[data-layout-device="landscape"][data-side-controls="true"] #range-upgrade{min-height:96px;height:96px;padding:2px 1px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .upgrade-preview{width:22px;height:22px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .branch-copy strong{font-size:10px;line-height:12px;white-space:normal}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .branch-copy strong span{font-size:11px;line-height:13px;white-space:nowrap}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .branch-copy strong .branch-full-name{display:none}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .branch-copy strong .branch-short-name{display:block;font-size:inherit;line-height:inherit;color:inherit}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .branch-stats{font-size:10px;line-height:12px;white-space:normal}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .branch-afford{font-size:10px;line-height:12px;white-space:nowrap}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .branch-full-reason{display:none}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .branch-short-reason{display:inline}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] #range-icon{width:24px;height:24px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] #range-upgrade strong{font-size:10px;line-height:12px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] #range-detail{font-size:10px;line-height:12px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .play-controls{display:grid;grid-template-columns:repeat(3,minmax(44px,1fr));grid-template-rows:44px 44px;grid-auto-flow:row;width:100%;height:92px;gap:4px;flex:none;margin-top:auto}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .play-controls>button,.game-shell[data-layout-device="landscape"][data-side-controls="true"] .play-controls>.settings-menu{width:100%;min-width:44px;height:44px;min-height:44px;flex:none;margin:0;padding:2px;font-size:11px;white-space:normal}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .play-controls>.settings-menu{padding:0}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] #pause{width:100%;min-width:44px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .settings-menu summary{width:100%;min-width:44px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] #start-wave{grid-column:span 2;min-width:44px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .play-controls:has(#cancel-placement:not([hidden])) #start-wave,.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-selected-tower="true"] #start-wave{grid-column:auto}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] #remove-tower{flex-direction:column;width:100%;min-width:44px;gap:0;padding:1px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] #remove-icon{width:18px;height:18px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] #refund-value{font-size:11px;line-height:14px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .placement-hint{position:fixed;left:7px;right:auto;top:auto;bottom:7px;max-width:calc(100% - 213px)}
.game-shell[data-layout-device="landscape"][data-side-controls="true"] .scene-help{bottom:5px}

/* Browser-chrome-shortened landscape: no scrolling tower/upgrade controls. */
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .control-rail{padding:4px;gap:4px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .scene-help{bottom:3px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .hud{height:32px;min-height:32px;grid-template-columns:.8fr 1fr 1.2fr;grid-template-rows:26px;gap:2px;padding:2px 3px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .map-heading{display:none}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .hud-item{grid-row:1}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .resource-label{position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0,0,0,0);clip-path:inset(50%);white-space:nowrap}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .resource-copy strong{font-size:18px;line-height:24px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .resource-copy #wave{font-size:14px;line-height:24px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .wave-forecast{min-height:44px;height:44px;padding:2px 3px;gap:3px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .selected-info{height:48px;min-height:48px;padding:0 3px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .selected-info .panel-heading{min-height:46px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] #tower-shop{grid-template-columns:repeat(3,minmax(0,1fr));grid-template-rows:44px 44px;height:92px;gap:4px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .tower-button{display:flex;flex-direction:column;justify-content:center;align-items:center;min-height:44px;height:44px;padding:0;gap:0;text-align:center}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .tower-button:last-child{grid-column:auto}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .tower-icon{grid-column:auto;grid-row:auto;width:18px;height:18px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .tower-copy{grid-column:auto;grid-row:auto;text-align:center}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .tower-copy strong{font-size:10px;line-height:12px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .tower-price{grid-column:auto;grid-row:auto;font-size:10px;line-height:12px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] #branches{height:88px;gap:3px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .branch-button,.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] #range-upgrade{min-height:88px;height:88px;padding:1px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .upgrade-preview{width:18px;height:18px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] #range-icon{width:22px;height:22px}
.game-shell[data-layout-device="landscape"][data-side-controls="true"][data-short-rail="true"] .branch-copy strong{font-size:10px;line-height:12px}
