/* UI4_4: one continuous scene; related controls form compact floating groups.
   The original image skins and all interactive IDs are retained. */
:root{--town-scene:url('../assets/backgrounds/bg_02_town_square.png');--forest-scene:url('../assets/backgrounds/bg_03_forest.png');--legible-shadow:0 1px 2px #182e2e,0 0 4px #182e2e,0 0 7px #182e2e;}
/* Combat: no sidebar, no full-width opaque bar. The canvas retains its aspect ratio. */
#battle:not([hidden]){display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:auto minmax(0,1fr) auto;gap:0;padding:0;isolation:isolate;position:relative;background:var(--battle-scene,var(--forest-scene)) center/cover no-repeat;overflow:hidden!important}
.app:has(#battle:not([hidden]))>.bar{background:linear-gradient(90deg,#174b4d,#2b6867,#174b4d);min-height:32px;padding:1px 7px!important;gap:4px!important}
.app:has(#battle:not([hidden]))>.bar .logo img{height:28px}.app:has(#battle:not([hidden]))>.bar .secondary{min-height:28px;font-size:10px;padding:3px 12px;min-width:68px}
#battle .battlebar{grid-column:1;grid-row:1;display:flex;justify-content:center;align-items:center;gap:4px!important;padding:3px 6px!important;background:none;border:0;box-shadow:none;z-index:2;flex-wrap:wrap}
#battle .battlebar .stat{background:#fff2d7e8;color:#3e392a;border:1px solid #b38d4b;border-radius:7px;padding:4px 7px;white-space:nowrap;min-width:0;line-height:1.15;text-shadow:none}
#battle .battlebar .boss-stat{background:#fff1d5f0;color:#a12a20}#battle .battlebar .push{display:none}
#battle .fieldwrap{grid-column:1;grid-row:2;min-width:0;min-height:0;position:relative;container-type:size;display:grid;place-items:center;background:none;border:0;padding:0;overflow:hidden}
#battle #field{width:min(100cqw,calc(100cqh * 1200 / 610))!important;height:auto!important;aspect-ratio:1200/610;max-width:100%!important;max-height:100%;display:block;margin:0;padding:0;border:0;border-radius:0;box-shadow:none;touch-action:none}
#battle .bottombar{grid-column:1;grid-row:3;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;padding:3px 8px 6px;min-width:0;min-height:0;overflow:visible;background:none;border:0;box-shadow:none;z-index:3}
#battle .controls{display:flex;flex-wrap:wrap;align-items:center;justify-content:center;gap:4px;max-width:1050px;width:100%;background:none!important;margin:0;padding:0}
#battle .controls #battleHint{flex:0 0 100%;text-align:center;color:#fff9de;text-shadow:var(--legible-shadow);font-size:12px;line-height:1.15;min-width:0}
#battle .controls button{flex:0 0 auto;min-height:34px;min-width:72px;padding:5px 16px;white-space:nowrap;font-size:12px}
#battle .controls #start,#battle .controls #special{min-width:144px;min-height:38px;padding:5px 24px}
#battle .role-filter-bar{width:auto;justify-content:center;align-items:center;padding:0 3px;margin:0;color:#fff8dd;text-shadow:var(--legible-shadow);gap:5px;border:0;background:transparent;font-size:11px}
#battle .role-filter-bar span{color:#fff8dd}#battle .role-filter-bar select{max-width:135px;min-height:25px;color:#34443b;background:#fff8e4;text-shadow:none}
#battle .battle-roster{display:flex!important;flex-wrap:nowrap;justify-content:center;align-items:stretch;gap:5px;width:100%;max-width:890px;overflow:visible;padding:0;min-height:0;flex:none}
#battle .battle-roster button{flex:0 1 148px;width:148px;max-width:148px;min-width:0;display:grid;grid-template-columns:36px minmax(0,1fr) minmax(0,1fr);grid-template-rows:auto auto 7px;gap:2px 3px;padding:8px 10px 9px;min-height:50px!important;align-items:center;overflow:hidden}
#battle .battle-roster button>img{grid-column:1;grid-row:1/4;height:100%;max-height:45px;width:100%;object-fit:contain}
#battle .battle-roster button>b,#battle .battle-roster button>small{grid-column:2/4;white-space:normal;overflow-wrap:anywhere;text-overflow:clip;font-size:12px;line-height:1.1;text-align:left;letter-spacing:0;margin:0;padding:0;color:#fff4dc;text-shadow:var(--legible-shadow)}
#battle .battle-roster button>small{font-size:10px;grid-row:2}#battle .battle-roster button>b{grid-row:1}
#battle .battle-roster button>.mini:not(.sp){grid-row:3;grid-column:2}#battle .battle-roster button>.mini.sp{grid-row:3;grid-column:3}#battle .battle-roster button>.mini{width:100%;height:7px;max-width:none;margin:0}
#battle:has(#start:not([hidden])) .battle-roster button{grid-template-rows:auto auto;min-height:42px!important}#battle:has(#start:not([hidden])) .battle-roster button>img{grid-row:1/3}#battle:has(#start:not([hidden])) .battle-roster .roster-role-tags{display:none!important}
#battle #toast{top:4px;background:#fff2d9e8;color:#493b26;text-shadow:none;border:1px solid #d9b46c;font-size:11px;padding:4px 10px;z-index:4}
#battle #bossWarning:not([hidden]){z-index:5;background:var(--zp-warning) center/contain no-repeat}
@media(max-height:600px){
 #battle .battlebar{gap:3px!important;padding:2px 4px!important}#battle .battlebar .stat{font-size:10px;padding:3px 4px}#battle .battlebar button{font-size:10px;min-height:29px;padding:3px 8px}
 #battle .controls{gap:3px}#battle .controls #battleHint{font-size:10px}#battle .controls button{min-height:30px;font-size:10px;padding:4px 10px;min-width:0}#battle .controls #start,#battle .controls #special{min-width:110px;min-height:33px;padding:4px 18px}
 #battle .bottombar{padding:2px 5px 4px;gap:2px}#battle .battle-roster{gap:4px;max-width:690px}#battle .battle-roster button{flex-basis:125px;grid-template-columns:26px minmax(0,1fr) minmax(0,1fr);padding:6px 7px 8px;min-height:43px!important}#battle .battle-roster button>b{font-size:10px}#battle .battle-roster button>small{font-size:9px}#battle .battle-roster button>img{max-height:32px}#battle:has(#start:not([hidden])) .battle-roster button{min-height:35px!important}
}
@media(max-height:360px){#battle .battlebar .stat{font-size:9px;padding:2px 3px}#battle .battlebar button{min-height:26px;font-size:9px;padding:3px 7px}#battle .controls #battleHint{font-size:9px}#battle .controls button{min-height:27px;font-size:9px;padding:3px 9px}#battle .controls #start,#battle .controls #special{min-height:29px;min-width:95px}#battle .battle-roster button{grid-template-columns:20px minmax(0,1fr) minmax(0,1fr);padding:5px 5px 6px;min-height:40px!important}#battle .battle-roster button>b,#battle .battle-roster button>small{font-size:9px}#battle:has(#start:not([hidden])) .battle-roster button{min-height:32px!important}#battle .role-filter-bar{font-size:10px}#battle .role-filter-bar select{min-height:22px}}
/* Other main scenes: shared artwork, no full-screen black tint. */
#partySelect,#stageSelect,#heroDetails,#bookDialog,#missionDialog{background:var(--town-scene) center/cover no-repeat!important}
#partySelect .party-main{grid-template-columns:minmax(0,1fr)!important;grid-template-rows:auto minmax(0,1fr)!important;gap:5px}
#partySelect .party-slots,#partySelect .party-collection{background:none;border:0;padding:0;min-height:0}
#partySelect #partySlots{display:flex;flex:none;justify-content:center;gap:5px;overflow:visible;padding:1px}
#partySelect #partyGrid{width:100%;max-width:900px;display:flex;justify-content:center;align-items:start;align-content:start;gap:6px;overflow:auto}
#partySelect .party-label{color:#fff6d5;text-shadow:var(--legible-shadow);min-height:24px;background-size:175px 100%}
#partySelect .party-head{background:none;border:0;text-shadow:var(--legible-shadow);color:#fff7d9;justify-content:center}
#partySelect .party-head #partyCount{margin-left:8px}#partySelect .party-actions{background:none;border:0}
#partySelect #partyHint{color:#fff6d7;text-shadow:var(--legible-shadow)}
@media(max-height:600px){#partySelect .party-main{--slot-w:clamp(43px,12dvh,72px);--card-w:clamp(70px,21dvh,110px)}#partySelect .party-label{min-height:20px}#partySelect #partySlots .party-slot{padding:5px 4px 7px}#partySelect #partyGrid .party-card{padding:7px 5px 10px}#partySelect #partyGrid{flex-wrap:nowrap;justify-content:safe center;overflow-x:auto;overflow-y:auto;min-height:0}#partySelect .party-card small,#partySelect .party-card b{font-size:10px}}
@media(max-height:360px){#partySelect .party-main{--slot-w:42px;--card-w:65px}#partySelect .party-label{min-height:18px;font-size:10px}#partySelect .party-card small,#partySelect .party-card b{font-size:9px}#partySelect .party-actions button{min-height:30px}}
/* Summoning: central portal, controls directly below; pool is optional reference content. */
#scout:not([hidden]){display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:auto minmax(0,1fr) auto;gap:4px;padding:4px 8px;background:url('../assets/backgrounds/bg_09_demon_castle.png') center/cover no-repeat!important}
#scout .scout-head{grid-row:1;grid-column:1;justify-content:center;gap:6px}#scout .summon-stage{grid-row:2;grid-column:1;justify-self:center;align-self:stretch;width:min(100%,860px);background:transparent;border:0;border-radius:0;box-shadow:none;padding:0;min-height:0}
#scout .summon-caption{background:none;color:#fff5d9;text-shadow:var(--legible-shadow);min-height:22px;padding:3px;font-size:12px}
#scout .portal{width:min(100cqw,calc(100cqh - 24px));max-width:100%;aspect-ratio:1;flex:none}
#scout .scout-controls,#scout .scout-results{grid-row:3;grid-column:1;align-self:end;max-width:650px;width:100%;max-height:none;overflow:visible;background:none;border:0;box-shadow:none;padding:0;justify-self:center;color:#fff7dc;text-shadow:var(--legible-shadow)}
#scout .scout-actions{width:min(100%,420px);margin-inline:auto;gap:6px}#scout .scout-actions button{min-height:45px}#scout #scoutNotice:empty{display:none}#scout #scoutNotice{margin:2px 0;text-align:center}
#scout .scout-reference{width:min(100%,610px);margin:3px auto 0;position:relative;text-align:center;font-size:12px}#scout .scout-reference summary{cursor:pointer;font-weight:800;padding:4px 12px;width:max-content;max-width:100%;margin:auto;background:#fff0d8e8;color:#4c3921;border:1px solid #b88d51;border-radius:7px;text-shadow:none}
#scout .scout-reference[open]{background:#173e40f2;border:1px solid #d1b779;border-radius:8px;padding:4px 8px;max-height:37dvh;overflow:auto}#scout .scout-reference p{margin:4px 0;font-size:11px}#scout .scout-pool{display:flex;flex-wrap:wrap;justify-content:center;gap:4px}#scout .scout-pool div{flex:0 0 68px;padding:5px 5px 9px}
#scout:has(#scoutResults:not([hidden])){grid-template-rows:auto minmax(0,1fr)}#scout:has(#scoutResults:not([hidden])) .summon-stage{display:none}#scout .scout-results:not([hidden]){grid-row:2;align-self:center;max-height:100%;overflow:auto;gap:4px;padding:4px 6px}#scout .result-cards{max-height:none;overflow:auto;min-height:0}#scout #resultDone{min-height:38px;flex:none}
@media(max-height:450px){#scout .scout-head h1{font-size:15px}#scout .scout-actions button{min-height:36px;font-size:12px}#scout .summon-caption{min-height:18px;font-size:10px}#scout .portal{width:min(100cqw,calc(100cqh - 20px))}#scout .scout-reference summary{font-size:10px;padding:3px 8px}#scout .scout-reference{margin-top:2px}}
/* Archive and growth: bounded vertical content, not separate left/right screens. */
#heroDetails .detail-header,#bookDialog .book-head,#missionDialog .mission-header{background:none;border:0;justify-content:center;gap:10px;color:#fff4d6;text-shadow:var(--legible-shadow)}
#heroDetails .detail-body{max-width:860px;overflow:hidden}
#heroDetails .detail-layout{display:flex;flex-direction:column;align-items:stretch;gap:6px;overflow:auto;min-height:0}
#heroDetails .detail-portrait{flex:none;width:100%;height:clamp(138px,32dvh,320px);display:grid;grid-template-rows:minmax(0,1fr) auto;background:transparent;border:0;box-shadow:none;overflow:hidden;padding:0}
#heroDetails .detail-portrait img{transform:none;grid-area:1/1;max-width:100%;max-height:100%;width:100%;height:100%;object-fit:contain}
#heroDetails .detail-name{padding:4px 12px;justify-self:center;text-align:center;background:#194b4ce6;border:1px solid #d0af6b;border-radius:7px;max-width:100%}
#heroDetails .detail-data{flex:none;display:flex;flex-direction:column;overflow:visible;gap:5px;background:#204d4ce8;border:1px solid #c7ad70;border-radius:10px;padding:7px;min-height:0}
#heroDetails .detail-pane-scroll{overflow:visible;flex:none;min-height:0}#heroDetails .detail-sections{position:static;display:flex;justify-content:center;gap:4px}#heroDetails .detail-sections button{flex:0 1 180px}
#heroDetails .detail-tabs{justify-content:safe center;background:none;border:0;flex:none}#heroDetails .detail-header .detail-role-tags{max-width:100%;flex-wrap:wrap}
@media(max-height:450px){#heroDetails .detail-portrait{height:94px}#heroDetails .detail-name h3{font-size:14px}#heroDetails .detail-name p{font-size:10px}#heroDetails .detail-name{padding:2px 8px}#heroDetails .detail-data{padding:4px}}
#bookDialog .book-head,#bookDialog .book-mode,#bookDialog .book-scroll{max-width:940px}
#bookDialog .book-layout{grid-template-columns:minmax(0,1fr);max-width:720px;margin-inline:auto;gap:6px}#bookDialog .book-portrait,#bookDialog .book-stage-art,#bookDialog .book-data{background:#174b4ce8;border:1px solid #c9af75;border-radius:8px}#bookDialog .book-portrait img{height:clamp(95px,29dvh,240px)}#bookDialog .book-stage-art img{max-height:clamp(100px,30dvh,250px);object-fit:contain}
#bookDialog .book-mode{background:none;border:0}#bookDialog .book-scroll{background:none}
#missionDialog #missionList{background:transparent}#missionDialog #missionNote,#missionDialog #missionNotice{color:#fff8e1;text-shadow:var(--legible-shadow);background:#19494bc9;border-radius:3px}#missionDialog #missionNotice:empty{display:none}#missionDialog .mission-summary{background:#17494ce6}
/* Result: one centered sequence; the detailed growth list remains scrollable. */
#modal .paper.battle-result{background:var(--town-scene) center/cover no-repeat!important}
#modal .battle-result .br-header{background:none;border:0;color:#fff4d7;text-shadow:var(--legible-shadow)}#modal .battle-result .br-body{grid-template-columns:minmax(0,1fr);max-width:740px;gap:6px}
#modal .battle-result .br-overview{background:#1d4a4be6}#modal .battle-result .br-actions{gap:5px;max-width:740px}
#modal .battle-result .br-rewards{width:100%;margin:0 auto}#modal .battle-result .br-skip{margin-right:0}
/* Continuous battle backdrop: the canvas fills the scene, its input transform is shared with the game renderer. */
#battle:not([hidden]){background:#8ea9a2;position:relative;overflow:hidden!important}
#battle .fieldwrap{position:absolute;inset:0;z-index:0;display:block;width:100%;height:100%;overflow:hidden;background:transparent;pointer-events:auto}
#battle #field{position:absolute;inset:0;width:100%!important;height:100%!important;aspect-ratio:auto;max-width:none!important;max-height:none;display:block}
#battle #battleSpace{grid-column:1;grid-row:2;pointer-events:none;min-height:0;min-width:0;z-index:1}
#battle .battlebar,#battle .bottombar{pointer-events:none}#battle .battlebar>* ,#battle .bottombar button,#battle .bottombar select{pointer-events:auto}
#battle #toast{top:50%;transform:translate(-50%,-50%);max-width:90%;font-size:11px;opacity:.96;pointer-events:none}
#battle #toast:not([hidden]){top:var(--battle-toast-top,27%)}
#battle #bossWarning:not([hidden]){top:var(--battle-warning-top,45%)}
#battle .controls #battleHint{min-height:0;color:#fff9e4;font-weight:850;text-shadow:0 1px 2px #241b0f,0 0 4px #241b0f,0 0 7px #241b0f}
#battle .role-filter-bar{color:#fff9e4;text-shadow:0 1px 2px #241b0f,0 0 5px #241b0f}
/* Actual labels remain readable without stretching a large panel behind the command group. */
#battle .battle-roster button{padding:8px 12px 10px}
@media(max-height:600px){#battle .battle-roster button{padding:6px 7px 8px}}
@media(max-height:360px){#battle .battle-roster button{padding:5px 5px 6px}}
/* Absolute grid children must use the entire grid, not just the play-space row. */
#battle .fieldwrap{grid-row:1/-1;grid-column:1/-1;inset:0}
/* Show the original portrait rather than squeezing it between an ornamental rim and a multi-line nameplate. */
#heroDetails .detail-portrait::after{display:none}
#heroDetails .detail-portrait{height:clamp(160px,34dvh,340px);max-width:100%;padding:0;grid-template-rows:minmax(0,1fr) auto;gap:2px}
#heroDetails .detail-portrait img{grid-area:1/1;padding:0;min-height:0;width:auto;height:100%;max-width:100%;max-height:100%;object-fit:contain;justify-self:center}
#heroDetails .detail-name{grid-row:2;display:flex;flex-wrap:wrap;justify-content:center;align-items:center;gap:4px 8px;max-width:100%;min-height:0;width:max-content;padding:3px 10px;text-align:center;background:#194b4ce8}
#heroDetails .detail-name h3,#heroDetails .detail-name p{margin:0;line-height:1.2}
#heroDetails .detail-name #detailOwned{flex:none;line-height:1.2;padding:2px 5px}
#heroDetails .detail-tabs{width:100%;max-width:100%;min-width:0}
#heroDetails .detail-tab{padding:8px 7px 7px;grid-template-rows:minmax(16px,1fr) auto auto}
#heroDetails .detail-tab b,#heroDetails .detail-tab small{font-size:11px;line-height:1.1}
@media(max-height:450px){#heroDetails .detail-portrait{height:112px}#heroDetails .detail-name h3{font-size:14px}#heroDetails .detail-name p,#heroDetails .detail-name #detailOwned{font-size:10px}#heroDetails .detail-tab{height:57px;padding:5px 6px 6px;grid-template-rows:minmax(16px,1fr) auto auto}#heroDetails .detail-tab b,#heroDetails .detail-tab small{font-size:9px}}
/* On short landscape screens the collection is one scrollable horizontal strip; its cards fit its actual height. */
@media(max-height:600px){#partySelect #partyGrid{container-type:size;align-items:start;padding:2px 3px 3px;overflow-y:hidden}#partySelect #partyGrid .party-card{height:min(112px,calc(100cqh - 2px));aspect-ratio:auto;max-height:100%;padding:6px 6px 9px;grid-template-rows:minmax(0,1fr) auto auto}#partySelect .party-card img{min-height:0;max-height:100%;scale:1}#partySelect .party-card b,#partySelect .party-card small{line-height:1.1}}
@media(max-height:360px){#partySelect .party-head{min-height:28px;padding:0}#partySelect .party-label{min-height:18px;margin:0}#partySelect .party-main{gap:3px}#partySelect .party-slots,#partySelect .party-collection{gap:2px}#partySelect #partyGrid .party-card{padding:5px 5px 7px}#partySelect .party-card b,#partySelect .party-card small{font-size:9px}}
/* Warnings are contained in the safe play area; avoid competing toast text. */
#battle #bossWarning:not([hidden]){width:min(84%,var(--battle-warning-width,640px));max-width:100%;padding:0;top:var(--battle-warning-top,45%);aspect-ratio:832/256;gap:0}
#battle #bossWarning span{font-size:clamp(10px,2vw,23px);line-height:1.1}#battle #bossWarning strong{font-size:clamp(10px,2.25vw,26px);line-height:1.1}#battle #bossWarning small{font-size:clamp(8px,1.2vw,13px);line-height:1.1}
#battle:has(#bossWarning:not([hidden])) #toast{visibility:hidden}

/* UI4_5: road anchored battlefield, controls in the upper scene, roster on foreground edge. */
#scout .portal .circle-plane{display:none!important;animation:none!important}
#scout .portal .circle-plane img{animation:none!important}
#battle:not([hidden]){grid-template-rows:auto auto minmax(0,1fr) auto;grid-template-columns:minmax(0,1fr)}
#battle .fieldwrap{grid-row:1/-1;grid-column:1/-1}
#battle #battleSpace{grid-row:3;grid-column:1}
#battle .bottombar{display:contents!important}
#battle .controls{grid-row:2;grid-column:1;justify-self:center;align-self:start;position:relative;z-index:3;pointer-events:none;padding:0 4px 2px;max-width:1100px;gap:3px!important}
#battle .controls button,#battle .controls select{pointer-events:auto}
#battle .controls #battleHint{order:4;flex:0 0 100%;font-size:11px;line-height:1.15;min-height:0;margin:0}
#battle .controls #roleFilterBar{order:3;flex:0 0 auto;pointer-events:auto;min-width:0;gap:3px}
#battle .controls #roleFilterBar select{min-height:23px}
#battle .battle-roster{grid-row:4;grid-column:1;justify-self:center;align-self:end;z-index:3;padding:0 4px 4px;pointer-events:none}
#battle .battle-roster button{pointer-events:auto}
#battle #toast{font-size:10px;padding:2px 8px}
@media(max-height:600px){#battle .controls #battleHint{font-size:10px}#battle .controls #roleFilterBar{font-size:9px}#battle .controls #roleFilterBar select{min-height:20px;max-width:90px}#battle .battlebar{gap:2px!important}#battle .controls{gap:2px!important}}
@media(max-height:360px){#battle .controls #battleHint{font-size:9px}#battle .controls button{padding:3px 8px}#battle .battle-roster{padding-bottom:3px}}
