/* One common UI scale, with flexible logical bounds for each screen shape. */
.battle-fit{--safe-left:env(safe-area-inset-left,0px);--safe-right:env(safe-area-inset-right,0px);--safe-top:env(safe-area-inset-top,0px);--safe-bottom:env(safe-area-inset-bottom,0px)}
.battle-page:has(.match-active){overflow:hidden}
.battle-page:has(.match-active) #siteHeader{position:fixed;left:0;right:0;top:0;z-index:2;min-height:44px;height:calc(44px + env(safe-area-inset-top,0px));padding:calc(2px + env(safe-area-inset-top,0px)) max(8px,env(safe-area-inset-right)) 2px max(8px,env(safe-area-inset-left));display:block;overflow:hidden}
.battle-page:has(.match-active) #siteHeader .brand,.battle-page:has(.match-active) #siteHeader .test-label{display:none}
.battle-page:has(.match-active) #siteHeader nav{height:40px;min-height:40px;display:flex;flex-wrap:nowrap;gap:18px;overflow-x:auto;overflow-y:hidden;scrollbar-width:none;white-space:nowrap}
.battle-page:has(.match-active) #siteHeader nav::-webkit-scrollbar{display:none}
.battle-page:has(.match-active) #siteHeader .nav{min-height:36px;font-size:12px;flex-shrink:0}
.battle-page .match-active #battleFit{position:fixed;inset:0;overflow:hidden;pointer-events:none;z-index:1}
.battle-page .match-active #battleStage{position:absolute;display:flex;flex-direction:column;align-items:stretch;gap:0;transform-origin:0 0;pointer-events:auto;text-size-adjust:100%;-webkit-text-size-adjust:100%;font-size:14px}
.battle-page .match-active #arenaPanel{display:flex;flex-direction:column;flex:1;width:100%;min-height:0;min-width:0;border-radius:6px;overflow:hidden}
.battle-page .match-active #arenaToolbar{height:52px;min-height:52px;flex:0 0 52px;padding:4px 10px}
.battle-page .match-active #arenaToolbar .muted{display:none}
.battle-page .match-active #arenaToolbar .arena-title-line{gap:8px;flex-wrap:nowrap}
.battle-page .match-active #arenaToolbar .arena-toolbar-start>strong{font-size:14px}
.battle-page .match-active #newButton{font-size:12px;min-height:40px;padding:6px 10px;flex-shrink:0}
.battle-page .match-active #arenaToolbar .playback{gap:8px;min-width:0}
.battle-page .match-active #arenaToolbar .playback button{min-height:40px;min-width:40px;font-size:13px}

.battle-page .match-active #timer{font-size:16px;overflow:hidden;text-overflow:ellipsis;min-width:0}
.battle-page .match-active #rankingPanel{height:170px;min-height:170px;flex:0 0 170px;padding:6px 10px;overflow:hidden}
.battle-page .match-active #rankingPanel .section-heading{height:18px;min-height:18px;margin:0;gap:8px}
.battle-page .match-active #rankingPanel h2{font-size:12px}
.battle-page .match-active #rankingPanel .rank-labels{display:none}
.battle-page .match-active #leaderboard{display:flex;flex-direction:column;gap:3px;margin-top:4px;max-height:none;overflow:visible}
.battle-page .match-active #leaderboard .rank-row{display:grid;grid-template-columns:34px 104px minmax(0,1fr) 44px;gap:8px;height:24px;min-height:24px;padding:2px 6px}
.battle-page .match-active #leaderboard .rank-stage{font-size:10px;line-height:16px;grid-row:auto}
.battle-page .match-active #leaderboard .rank-name{font-size:12px}
.battle-page .match-active #leaderboard .rank-skills{grid-column:auto;grid-row:auto;gap:3px}
.battle-page .match-active #leaderboard .rank-skill{height:18px;line-height:16px;font-size:10px}
.battle-page .match-active #leaderboard .rank-kills{font-size:16px;line-height:16px;grid-column:auto;grid-row:auto}
.battle-page .match-active #battleViewport{height:auto;min-height:0;flex:1;aspect-ratio:auto;overflow:hidden}
.battle-page .match-active #battleControls{height:194px;min-height:194px;flex:0 0 194px;overflow:hidden;overscroll-behavior:none}
.battle-page .match-active #battleControls .army-commandbar{padding:8px 10px}
.battle-page .match-active #battleControls .command-targets{display:flex;flex-wrap:nowrap;gap:6px;margin-bottom:6px;padding-bottom:6px}
.battle-page .match-active #targetLabel{width:auto;font-size:12px;white-space:nowrap}
.battle-page .match-active #battleControls .target-options{display:flex;flex:1;gap:4px;min-width:0}
.battle-page .match-active #battleControls .target-options button{min-height:36px;min-width:32px;padding:5px 8px;font-size:11px}
.battle-page .match-active #targetCount{display:block;font-size:11px;white-space:nowrap}
.battle-page .match-active #battleControls .army-heading{margin-bottom:4px;gap:8px;flex-wrap:nowrap;min-height:18px}
.battle-page .match-active #battleControls .army-heading strong{font-size:12px}
.battle-page .match-active #battleControls .army-heading span{font-size:10px}
.battle-page .match-active #battleControls .army-heading small{display:none}
.battle-page .match-active #battleControls .army-buttons{display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:4px}
.battle-page .match-active #battleControls .army-button{min-height:46px;padding:5px 7px}
.battle-page .match-active #battleControls .army-button span{display:block;font-size:9px;line-height:12px;margin-bottom:2px}
.battle-page .match-active #battleControls .army-button strong{font-size:11px;line-height:15px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.battle-page .match-active #battleControls .selection-commands{display:grid;grid-template-columns:40px minmax(0,1fr);padding:4px 10px 8px;gap:8px;align-items:center}
.battle-page .match-active #battleControls .selection-commands .section-heading{display:block;margin:0}
.battle-page .match-active #battleControls .selection-commands h2{font-size:12px}
.battle-page .match-active #battleControls .selection-commands small{display:none}
.battle-page .match-active #battleControls .commands{display:flex;flex-wrap:nowrap;gap:6px}
.battle-page .match-active #battleControls .commands button{min-height:40px;min-width:0;padding:8px 4px;flex:1;font-size:11px}
.battle-page .match-active #arenaFooter{height:22px;min-height:22px;flex:0 0 22px;padding:4px 10px;display:flex;flex-wrap:nowrap;gap:4px;font-size:9px;line-height:12px}
.battle-page .match-active #arenaFooter>span:first-child{display:none}
.battle-page .match-active #controlHint{font-size:9px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.battle-page .match-active #alive{font-size:9px;margin-left:auto;white-space:nowrap}
.battle-page .match-active #battleStage>.right-panel{display:none}
.battle-page .match-active #battleViewport .map-groups{left:8px;top:8px;z-index:3;gap:4px}
.battle-page .match-active #battleViewport .map-groups button{width:36px;min-height:40px;font-size:12px}
.battle-page .match-active #cameraControls{left:auto;right:8px;top:8px;transform:none;z-index:3;gap:3px;padding:3px}
.battle-page .match-active #cameraControls button{min-width:32px;min-height:36px;padding:3px 5px;font-size:11px}
.battle-page .match-active #minimap{width:150px;height:122px;right:8px;bottom:8px;z-index:2}
.battle-page .match-active #battleViewport .map-legend{font-size:9px;left:10px;bottom:8px;gap:6px;max-width:55%}
.battle-page .match-active #battleViewport .map-legend>span:last-child{display:none}
.battle-page .match-active #unitTooltip{z-index:4;left:10px;top:60px;max-width:260px;font-size:11px}
.battle-page .match-active .chronicle,.battle-page .match-active>footer{display:none}
/* Layout modes depend on the reference design, not the physical screen's media queries. */
.battle-page .match-active #battleStage.battle-design-portrait #arenaToolbar .arena-toolbar-start>strong,
.battle-page .match-active #battleStage.battle-design-portrait #arenaToolbar .live-dot{display:none}
.battle-page .match-active #battleStage.battle-design-portrait #leaderboard .rank-row{grid-template-columns:29px 64px minmax(0,1fr) 34px;gap:4px}
.battle-page .match-active #battleStage.battle-design-portrait #leaderboard .rank-name{font-size:10px}
.battle-page .match-active #battleStage.battle-design-portrait #leaderboard .rank-skill{font-size:9px}
.battle-page .match-active #battleStage.battle-design-portrait #battleControls{height:246px;min-height:246px;flex-basis:246px}
.battle-page .match-active.team-three #battleStage.battle-design-portrait #battleControls{height:300px;min-height:300px;flex-basis:300px}
.battle-page .match-active #battleStage.battle-design-portrait .army-buttons{grid-template-columns:repeat(3,minmax(0,1fr))}
.battle-page .match-active #battleStage.battle-design-portrait #minimap{width:120px;height:98px}
/* Desktop HUD: left ranking, map above a two-row command dock. */
.battle-page .match-active #battleStage.battle-design-desktop #arenaPanel{display:grid;grid-template-columns:272px minmax(0,1fr);grid-template-rows:52px minmax(0,1fr) 132px 22px}
.battle-page .match-active #battleStage.battle-design-desktop #arenaToolbar{grid-column:1/-1;grid-row:1}
.battle-page .match-active #battleStage.battle-design-desktop #rankingPanel{grid-column:1;grid-row:2/4;width:auto;height:auto;min-height:0;padding:12px;overflow-y:auto;border-right:1px solid var(--line);border-bottom:0}
.battle-page .match-active #battleStage.battle-design-desktop #rankingPanel .section-heading{height:24px;min-height:24px}
.battle-page .match-active #battleStage.battle-design-desktop #rankingPanel h2{font-size:14px}
.battle-page .match-active #battleStage.battle-design-desktop #leaderboard{gap:8px;margin-top:8px}
.battle-page .match-active #battleStage.battle-design-desktop #leaderboard .rank-row{grid-template-columns:36px minmax(0,1fr) 40px;grid-template-rows:auto auto;gap:8px;height:auto;min-height:86px;padding:10px 8px}
.battle-page .match-active #battleStage.battle-design-desktop #leaderboard .rank-stage{grid-column:1;grid-row:1}
.battle-page .match-active #battleStage.battle-design-desktop #leaderboard .rank-name{grid-column:2;grid-row:1;font-size:13px}
.battle-page .match-active #battleStage.battle-design-desktop #leaderboard .rank-kills{grid-column:3;grid-row:1;font-size:18px}
.battle-page .match-active #battleStage.battle-design-desktop #leaderboard .rank-skills{grid-column:1/-1;grid-row:2;max-width:none}
.battle-page .match-active #battleStage.battle-design-desktop #leaderboard .rank-skill{height:24px;line-height:22px;font-size:10px}
.battle-page .match-active #battleStage.battle-design-desktop #battleViewport{grid-column:2;grid-row:2}
.battle-page .match-active #battleStage.battle-design-desktop #battleControls{grid-column:2;grid-row:3;display:grid;grid-template-columns:minmax(0,1fr) 248px;grid-template-rows:44px 64px;gap:4px 12px;height:132px;min-height:0;padding:8px 10px;overflow:hidden}
.battle-page .match-active #battleStage.battle-design-desktop #battleControls .army-commandbar{grid-column:1;grid-row:1/3;display:grid;grid-template-columns:64px minmax(0,1fr);grid-template-rows:44px 64px;gap:4px 6px;padding:0}
.battle-page .match-active #battleStage.battle-design-desktop #battleControls .command-targets{grid-column:1/-1;grid-row:1;padding:0;margin:0;border:0}
.battle-page .match-active #battleStage.battle-design-desktop #targetLabel{min-width:64px}
.battle-page .match-active #battleStage.battle-design-desktop #battleControls .target-options{flex:0 1 auto}
.battle-page .match-active #battleStage.battle-design-desktop #battleControls .target-options button{min-width:44px;min-height:40px;font-size:13px}
.battle-page .match-active #battleStage.battle-design-desktop #targetCount{margin-left:auto;font-size:12px}
.battle-page .match-active #battleStage.battle-design-desktop #battleControls .army-heading{grid-column:1;grid-row:2;display:flex;align-items:center;margin:0}
.battle-page .match-active #battleStage.battle-design-desktop #battleControls .army-heading span{display:none}
.battle-page .match-active #battleStage.battle-design-desktop #battleControls .army-buttons{grid-column:2;grid-row:2;grid-template-columns:repeat(6,minmax(0,1fr))}
.battle-page .match-active #battleStage.battle-design-desktop #battleControls .army-button{min-height:0;padding:6px}
.battle-page .match-active #battleStage.battle-design-desktop #battleControls .army-button strong{font-size:12px;line-height:18px}
.battle-page .match-active #battleStage.battle-design-desktop #battleControls .selection-commands{grid-column:2;grid-row:1/3;display:block;padding:0}
.battle-page .match-active #battleStage.battle-design-desktop #battleControls .selection-commands>.section-heading{display:none}
.battle-page .match-active #battleStage.battle-design-desktop #battleControls .commands{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:44px 64px;gap:4px;height:100%}
.battle-page .match-active #battleStage.battle-design-desktop #battleControls .commands button{min-height:0;font-size:14px}
.battle-page .match-active #battleStage.battle-design-desktop #arenaFooter{grid-column:1/-1;grid-row:4}
.battle-page:has(.match-active) #helpButton{display:block}
.battle-page .match-active #battleControls .commands kbd{display:inline-block}
.battle-page .match-active #battleControls .army-button kbd{display:inline-block;font:700 10px monospace;color:var(--gold);border:1px solid #9b8757;border-radius:3px;padding:1px 4px;margin-right:3px}
/* Transient system messages never intercept map gestures. */
.battle-page #logs.battle-messages{position:absolute;left:12px;top:auto;bottom:30px;z-index:3;height:auto;max-height:35%;margin:0;overflow:hidden;max-width:min(65%,640px);display:flex;flex-direction:column;gap:5px;pointer-events:none;color:#fff;text-shadow:0 1px 3px #000,1px 0 3px #000;font-size:13px;line-height:1.45}
.battle-page #logs .battle-message{overflow-wrap:anywhere}
.battle-page #logs .battle-message time{color:#fff;opacity:.8;font:11px monospace}
.battle-page .battle-design-portrait #logs.battle-messages{font-size:11px;max-width:65%;left:10px}
/* Never transform popups with the stage: fixed positioning must remain viewport-relative. */
.battle-page #overlay{position:fixed;inset:auto;z-index:50;display:flex;align-items:center;justify-content:center;box-sizing:border-box;max-width:none;max-height:none;padding:max(12px,env(safe-area-inset-top)) max(12px,env(safe-area-inset-right)) max(12px,env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left));overflow:hidden}
.battle-page #overlay.hidden{display:none}
.battle-page #overlay>.intro{max-width:100%;max-height:100%;min-height:0;box-sizing:border-box;overflow-y:auto}
html:has(body.battle-page #overlay.lobby-open:not(.hidden)),body.battle-page:has(#overlay.lobby-open:not(.hidden)){overflow:hidden;overscroll-behavior:none}
/* Measure the full start card before uniformly fitting it to the visible viewport. */
.battle-page #overlay.lobby-open>.lobby-intro{max-width:none;max-height:none;overflow:hidden}
.battle-page #overlay>.dynasty-reveal{width:min(100%,680px);height:auto;max-height:100%;display:flex;flex-direction:column;padding:20px}
.battle-page #overlay .reveal-details{flex:1;min-height:0;overflow-y:auto}
.battle-page #overlay .reveal-actions{flex-shrink:0}
.battle-page #overlay .reveal-seal{width:48px;height:48px;font-size:30px;margin:12px auto}
.battle-page #overlay .dynasty-reveal h2{font-size:26px;margin:10px 0}
.battle-page #overlay .result-card{max-height:100%;height:auto}
.battle-page #rankTooltip{z-index:60}


/* Temporary effects use game-time countdowns without changing the fitted stage. */
.battle-page .match-active #rankingPanel{overflow-y:auto}
.battle-page .match-active #leaderboard .rank-effects{grid-column:1/-1;grid-row:2;display:flex;flex-wrap:wrap;gap:4px;min-width:0}
.battle-page .match-active #leaderboard .rank-effects:empty{display:none}
.battle-page .match-active #leaderboard .rank-row.has-effects{height:auto;min-height:44px}
.battle-page .match-active #leaderboard .rank-effect{display:inline-block;font-size:9px;line-height:14px;padding:1px 4px;border:1px solid #6e805b;border-radius:3px;color:#dfefcf;background:#11231d}
.battle-page .match-active #leaderboard .rank-effect.peakUntil{color:#ffe29b;border-color:#967c3f}
.battle-page .match-active #leaderboard .rank-effect.desperateUntil{color:#ffb9a3;border-color:#aa6954}
.battle-page .match-active #battleStage.battle-design-desktop #leaderboard .rank-effects{grid-row:3}
.battle-page .match-active #battleStage.battle-design-desktop #leaderboard .rank-effect{font-size:10px}
/* Unit inspection overlays the existing map; the stage and command dock keep their size. */
.battle-page #unitInfo{position:absolute;left:10px;bottom:28px;z-index:5;width:320px;max-width:calc(100% - 20px);max-height:calc(100% - 84px);overflow:auto;overscroll-behavior:contain;box-sizing:border-box;padding:12px;color:#e6eddf;background:#101e1bf2;border:1px solid #9c8b5e;border-radius:7px;box-shadow:0 4px 18px #0006;font-size:12px;line-height:1.5;scrollbar-width:thin}
.battle-page #unitInfo[hidden]{display:none}
.battle-page #unitInfo header{display:block;padding:0;height:auto;position:static;background:none;border:0}
.battle-page #unitInfo header strong{display:block;color:#e9d399;font-size:14px}
.battle-page #unitInfo header small{display:block;color:#adbdb3;font-size:11px}
.battle-page #unitInfo dl{display:grid;grid-template-columns:1fr 1fr;gap:5px 12px;margin:10px 0}
.battle-page #unitInfo dl div{min-width:0}
.battle-page #unitInfo dt{color:#9faf9f;font-size:10px}
.battle-page #unitInfo dd{margin:0;font-variant-numeric:tabular-nums}
.battle-page #unitInfo summary{cursor:pointer;color:#e9d399;padding:5px 0}
.battle-page #unitInfo ul{padding:0;list-style:none;margin:0}
.battle-page #unitInfo li{padding:6px 0;border-top:1px solid #ffffff14}
.battle-page #unitInfo li b,.battle-page #unitInfo li span,.battle-page #unitInfo li small{display:block}
.battle-page #unitInfo li small{color:#a4b4a8;margin-top:4px}
.battle-page #unitInfo .unit-ultimate b{color:#ead290}
.battle-page #unitInfo .unit-state{color:#b9dfc5;margin:6px 0}
.battle-page #unitInfo .unit-info-note{font-size:10px;color:#9faf9f;margin:8px 0 0}
.battle-page .battle-design-portrait #unitInfo{width:250px;font-size:11px;padding:10px}
.battle-page .battle-design-portrait #unitInfo header strong{font-size:12px}
.battle-page #battleViewport:has(#unitInfo:not([hidden])) #unitTooltip{display:none}
.signature-notes{color:#b0c6b6;font-size:12px}

.battle-page [id^="allEnemy"][hidden]{display:none}
/* Fit the compact controls into the original single-row, 52px toolbar. */
.battle-page #arenaToolbar #speed .speed-number{min-width:0;min-height:34px;padding:0;font:bold 20px Georgia,serif}
.battle-page #arenaToolbar #speed .speed-arrow{min-width:22px;min-height:34px;padding:0;font-size:22px}
.battle-page #arenaToolbar #pause{width:40px;min-width:40px;height:40px;padding:0;border:2px solid #8dc7ab;border-radius:6px;background:#28483b;color:#f1fff6;font-size:22px;font-weight:800;line-height:1;box-shadow:inset 0 1px #ffffff16}
.battle-page #arenaToolbar #pause.paused{border-color:#f1d58a;background:#d9bf78;color:#17271c;box-shadow:0 0 7px #d4bb7928}
.battle-page #arenaToolbar #pause:disabled{opacity:.45;box-shadow:none;cursor:default}
.battle-page #arenaToolbar #pause.online{font-size:11px}

.battle-page .match-active.team-three #battleStage.battle-design-desktop #battleControls .army-buttons,.battle-page .match-active.team-three #battleStage.battle-design-landscape #battleControls .army-buttons{grid-template-columns:repeat(7,minmax(0,1fr))}

/* Disable double-tap zoom across command backgrounds as well as buttons. */
.battle-page .match-active #battleControls,
.battle-page .match-active #battleControls *,
.battle-page .match-active .map-groups,
.battle-page .match-active .map-groups *{touch-action:manipulation}
/* Online connection state: realtime socket, reconnecting, or slower HTTP fallback. */
.net-mode{display:inline-flex;align-items:center;gap:5px;font-size:10px;line-height:1;padding:3px 7px;border:1px solid var(--line);border-radius:10px;color:var(--muted);white-space:nowrap;font-variant-numeric:tabular-nums}
.net-mode::before{content:"";width:6px;height:6px;border-radius:50%;background:currentColor}
.net-mode[data-state=realtime]{color:var(--mint)}.net-mode[data-state=connecting]{color:var(--gold)}.net-mode[data-state=http]{color:#e08a6b}
/* Phones: the new-match button keeps only its icon so the toolbar items never overlap. */
.battle-page .match-active #battleStage.battle-design-portrait #newButton .new-label{display:none}
.battle-page .match-active #battleStage.battle-design-portrait #newButton{min-width:40px;padding:6px 12px}
@media(max-width:700px){.battle-page #newButton .new-label{display:none}}
/* During a match the page itself never scrolls, so swipes on the HUD cannot pull the browser's
   address bar in or out (which resized the whole battle screen) or trigger pull-to-refresh. */
html:has(body.battle-page .match-active){overflow:hidden;overscroll-behavior:none;height:100%}
body.battle-page:has(.match-active){position:fixed;inset:0;width:100%;height:100%;overflow:hidden;overscroll-behavior:none}
.battle-page .match-active #battleStage{touch-action:none;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}
.battle-page:has(.match-active) #siteHeader{touch-action:pan-x}
