/* UI4: screen hierarchy. Art fills the scene; controls retain purposeful maximum sizes. */
:root{--review-town:url('../assets/backgrounds/bg_02_town_square.png');--review-forest:url('../assets/backgrounds/bg_03_forest.png');--review-backdrop:linear-gradient(90deg,#0f3438c9,#133d3ee8 26%,#133d3ee8 74%,#0f3438c9),var(--review-town);}
/* Title: the same center axis at every supported aspect ratio. */
#entry:not([hidden]){position:relative;display:flex;flex-direction:column;justify-content:center;align-items:center;width:100%;height:100dvh;min-height:0;isolation:isolate;padding:0;gap:0;overflow:hidden;background:#22434a}
#entry .entry-scene,#entry.intro .entry-scene{position:absolute;inset:0;width:100%;height:100%;border:0;border-radius:0;box-shadow:none;overflow:hidden;z-index:-1}
#entry .entry-town{object-position:center 56%;object-fit:cover}
#entry .entry-shade{background:linear-gradient(180deg,#102e3930 0%,transparent 40%,#102e3970 75%,#102e39b0 100%)}
#entry .entry-brand,#entry.intro .entry-brand{position:absolute;top:clamp(10px,5dvh,54px);left:50%;right:auto;transform:translateX(-50%);width:min(68vw,660px,95dvh);height:clamp(112px,45dvh,440px);filter:drop-shadow(0 6px 5px #142c3780)}
#entry.intro .entry-art{object-fit:cover!important}#entry.intro .entry-brand{width:min(40vw,360px);height:24dvh;top:4px}
#entry .entry-controls{position:absolute;bottom:clamp(8px,5dvh,50px);left:50%;transform:translateX(-50%);height:auto;max-height:48dvh;overflow:visible;width:min(94%,480px);padding:0 10px;gap:6px;align-content:center;border:0;background:none;box-shadow:none;display:grid;justify-items:center}
#entry .entry-actions{width:min(100%,380px);grid-template-columns:1fr;gap:2px}
#entry .entry-btn{min-height:clamp(44px,9dvh,72px);font-size:clamp(16px,3.1dvh,25px);padding:5px 18px;color:#fff4d6;text-shadow:0 2px 3px #49290d;line-height:1.1}
#entry .entry-btn.primary{background:var(--reg-primary) center/100% 100% no-repeat!important}
#entry .entry-btn.secondary{background:var(--reg-secondary) center/100% 100% no-repeat!important}
#entry .entry-btn:disabled{opacity:.53}
#entry .entry-tools{gap:4px;flex-wrap:nowrap;justify-content:center;width:100%}
#entry .entry-tools button{min-height:clamp(32px,5.8dvh,43px);padding:5px 12px;background:var(--reg-secondary) center/100% 100% no-repeat!important;color:#fff5dc;text-shadow:0 1px 2px #17332f;font-size:clamp(10px,1.7dvh,14px);white-space:nowrap}
#entry .entry-progress{color:white;text-shadow:0 1px 3px #12252d;font-weight:800;width:90%;font-size:10px}
#entry .entry-notice{min-height:0;margin:0;font-weight:700;text-shadow:0 1px 3px #102936;color:#fff5df;font-size:11px;max-width:100%}
#entry .entry-mast{top:7px;right:10px;font-size:9px}#entry .entry-splash-caption{display:none}
@media(max-height:400px){#entry .entry-brand{top:3px;height:42dvh;width:min(62vw,80dvh)}#entry .entry-controls{bottom:7px;gap:3px;max-height:55dvh}#entry .entry-actions{width:min(72%,310px)}#entry .entry-btn{min-height:40px}#entry .entry-btn small{font-size:8px}#entry .entry-tools button{min-height:32px;padding:4px 9px}#entry .entry-notice{font-size:10px}}
/* Camp: the plaza stays visible; related navigation is a compact central dock. */
#home.camp-mode{position:relative;background:var(--review-town) center/cover no-repeat}
#home.camp-mode .home-head{position:relative;justify-content:center;isolation:isolate;flex:none;padding:4px 8px 6px;border:0;background:linear-gradient(0deg,#163f40 4%,#1d4a4be6 100%);box-shadow:0 -2px 0 #c9a96b;min-height:0}
#home.camp-mode .home-nav{flex:0 1 auto;justify-content:center;gap:clamp(4px,1vw,12px);width:min(100%,600px);max-width:600px}
#home.camp-mode .home-nav button,#home.camp-mode .home-nav #go{flex:0 1 clamp(65px,10vw,105px);width:clamp(65px,10vw,105px);font-size:clamp(10px,1.4vw,15px);padding:0 2px}
#home.camp-mode .home-nav button::before{width:clamp(48px,8dvh,82px);height:clamp(48px,8dvh,82px);max-height:none}
#home.camp-mode .welcome{position:absolute;left:12px;top:calc(-100dvh + 104px + 13dvh);pointer-events:none;padding:0;margin:0;z-index:4}
/* Wallet lives in the plaza header rather than occupying the navigation dock. */
#home.camp-mode .welcome{position:fixed;top:clamp(42px,7dvh,66px);left:50%;transform:translateX(-50%);z-index:5;max-width:45vw}
#home.camp-mode .wallet{justify-content:center;flex-wrap:nowrap}
#home #wachaDialog:not([hidden]){grid-template-rows:minmax(0,1fr);background:transparent}
#home #wachaDialog #wachaField{grid-row:1;min-height:0}
#wachaDialog .wacha-head{top:6px;left:8px;right:8px}
#wachaDialog .wacha-head h2{font-size:clamp(13px,2.6dvh,21px);padding:4px 20px;background:var(--reg-heading) center/100% 100% no-repeat;border:0}
#wachaDialog .wacha-caption{display:none}
#wachaDialog .wacha-head #wachaPickerToggle{margin-left:auto}
#wachaDialog #wachaClose{margin-left:0}
#wachaDialog .wacha-bottom{position:absolute;z-index:8;bottom:6px;left:50%;transform:translateX(-50%);width:min(calc(100% - 16px),720px);border:1px solid #d2b16b;border-radius:8px;background:#174649f2;box-shadow:0 3px 12px #152d36a0;grid-template-columns:auto minmax(0,1fr);padding:5px;gap:5px}
#wachaDialog .wacha-bottom[hidden]{display:none!important}
#wachaDialog .wacha-tools{gap:3px}#wachaDialog #wachaPicker{max-height:85px}
@media(max-width:700px){#home.camp-mode .welcome{top:76px;left:8px;transform:none;max-width:60vw}#home.camp-mode .home-nav button,#home.camp-mode .home-nav #go{flex-basis:74px;width:74px}#home.camp-mode .home-nav button::before{width:44px;height:44px}#wachaDialog .wacha-head .wacha-control{font-size:10px;padding:3px 6px;min-height:30px}}
/* Mission: fixed readable measure, illustrated scenery at the perimeter, real scroll area. */
#missionDialog{background:var(--review-backdrop) center/cover no-repeat;--mission-measure:min(100%,820px)}
#missionDialog .mission-header,#missionDialog .mission-tabs,#missionDialog .mission-summary,#missionDialog #missionNote,#missionDialog #missionNotice,#missionDialog #missionList{width:var(--mission-measure);max-width:820px;align-self:center;box-sizing:border-box;margin-inline:0}
#missionDialog .mission-header{background:none;min-height:0;padding:6px 12px;gap:8px;border:0;justify-content:space-between}
#missionDialog .mission-header .eyebrow{display:none}#missionDialog .mission-header h2{margin:0;font-size:clamp(15px,3.2dvh,25px);padding:7px 22px}
#missionDialog .mission-header button{min-height:36px;min-width:92px}
#missionDialog .mission-tabs{justify-content:center;gap:5px;padding:3px 10px}#missionDialog .mission-tabs button{flex:0 1 175px;min-height:35px}
#missionDialog .mission-summary{justify-content:space-between;align-items:center;background:#10393edb;border-top:1px solid #ac995e;border-bottom:1px solid #ac995e;font-size:clamp(10px,1.5vw,14px);padding:4px 12px;gap:4px}
#missionDialog #missionNote,#missionDialog #missionNotice{padding:2px 12px;font-size:11px;line-height:1.3;min-height:0}
#missionDialog #missionList{background:#103d3edb;padding:4px 10px 10px;scrollbar-width:thin;scrollbar-color:#c7ab6f #193a3c}
#missionDialog .mission-group h3{font-size:13px;min-width:112px;margin:4px 0;padding:5px 14px;line-height:1.2}
#missionDialog .mission-row{grid-template-columns:minmax(0,1fr) minmax(86px,auto) clamp(90px,15vw,130px);gap:8px;border-width:10px 12px;padding:1px 5px;min-height:64px;margin-bottom:4px}
#missionDialog .mission-text{gap:2px}#missionDialog .mission-text strong{font-size:clamp(12px,1.6vw,16px)}#missionDialog .mission-text small{font-size:11px;line-height:1.15}#missionDialog .mission-text progress{height:9px}#missionDialog .mission-reward span{font-size:12px;white-space:nowrap}#missionDialog .mission-reward img{width:22px;height:22px}
#missionDialog .mission-row button{min-height:40px;padding:5px 7px;font-size:12px}
@media(max-height:400px){#missionDialog .mission-header{padding:2px 9px}#missionDialog .mission-header h2{padding:5px 18px}#missionDialog .mission-header button{min-height:30px}#missionDialog .mission-tabs{padding:2px 8px}#missionDialog .mission-tabs button{min-height:31px}#missionDialog .mission-summary{padding:2px 9px}#missionDialog #missionNote,#missionDialog #missionNotice{font-size:10px;padding:1px 9px}#missionDialog .mission-row{min-height:57px;border-width:7px 10px;gap:5px}#missionDialog .mission-row button{min-height:36px}#missionDialog .mission-group h3{margin:2px 0;padding:4px 10px}}
/* Party: shared vertical axis and one contiguous work area. Cards never stretch to fill a column. */
#partySelect{--party-width:min(100%,1100px);background:linear-gradient(90deg,#143738ca,#123b3ee8 22%,#123b3ee8 78%,#143738ca),var(--review-town) center/cover no-repeat;padding:6px clamp(8px,2vw,18px);gap:5px;overflow:hidden!important}
#partySelect .party-head,#partySelect .party-main,#partySelect .party-actions{width:var(--party-width);max-width:1100px;justify-self:center}
#partySelect .party-head{padding:2px 4px;gap:8px;border-bottom:1px solid #c1a268}
#partySelect .party-head h1{font-size:clamp(15px,3.1dvh,25px);line-height:1.15}#partySelect .party-head small{font-size:10px}#partySelect .party-head #partyCount{font-size:clamp(18px,3.5dvh,27px)}
#partySelect .party-main{grid-template-columns:1fr;grid-template-rows:auto minmax(0,1fr);gap:4px;overflow:hidden;align-items:stretch;--slot-w:clamp(54px,12dvh,105px);--card-w:clamp(80px,19dvh,154px)}
#partySelect .party-slots,#partySelect .party-collection{gap:3px;align-items:center;min-height:0}
#partySelect .party-label{width:100%;max-width:860px;font-size:12px;text-align:center;letter-spacing:0;padding:2px 0;border:0;color:#ffe8ac;background:var(--reg-heading) center/contain no-repeat;min-height:24px}
#partySelect #partySlots{display:flex;justify-content:center;gap:clamp(3px,1vw,10px);width:100%;overflow:visible;flex:none}
#partySelect #partySlots .party-slot{width:var(--slot-w);max-width:none;max-height:none;height:auto;aspect-ratio:4/5;padding:14% 0 0;flex:0 0 var(--slot-w);padding:8px 6px 9px}
#partySelect #partyGrid{display:grid;grid-template-columns:repeat(auto-fill,var(--card-w));justify-content:center;align-content:start;gap:5px;overflow:auto;width:100%;max-width:950px;flex:1;padding:1px 4px 4px}
#partySelect #partyGrid .party-card{width:var(--card-w);max-height:none;aspect-ratio:4/5;padding:12% 10% 13%;font-size:12px}
#partySelect .party-card b,#partySelect .party-slot span{font-size:clamp(10px,1.5vw,15px)}#partySelect .party-card small{font-size:clamp(9px,1.2vw,12px);white-space:normal;line-height:1.1}
#partySelect .party-card img,#partySelect .party-slot img{object-fit:contain;scale:1.06}
#partySelect #partyHint{font-size:11px;line-height:1.15;text-align:center;margin:0}
#partySelect .party-actions{justify-content:center;align-items:center;gap:10px;border:0;padding:2px 0}
#partySelect .party-actions button{min-height:42px;min-width:115px;font-size:13px}#partySelect #partyConfirm{min-width:190px}
@media(max-height:600px){#partySelect .party-main{--slot-w:clamp(45px,14dvh,75px);--card-w:clamp(72px,22dvh,118px)}#partySelect .party-label{min-height:17px;padding:0;font-size:11px}#partySelect .party-head{min-height:32px}#partySelect .party-head button{min-height:31px}#partySelect .party-actions button{min-height:36px}#partySelect #partySlots .party-slot{padding:5px 5px 7px}#partySelect #partyHint{display:none}}
@media(max-height:350px){#partySelect .party-main{--slot-w:42px;--card-w:72px;grid-template-columns:minmax(0, .9fr) minmax(0,1.2fr);grid-template-rows:1fr;gap:8px}#partySelect #partySlots{display:grid;grid-template-columns:repeat(3,48px);justify-content:center;gap:3px}#partySelect #partySlots .party-slot{width:48px}#partySelect #partyGrid{grid-template-columns:repeat(auto-fill,72px)}#partySelect .party-label{margin-bottom:2px}#partySelect .party-actions button{min-height:34px}#partySelect .party-head h1{font-size:14px}}
/* Stage: fixed-width center card and genuine end padding; arrows frame the card cluster. */
#stageSelect{background:linear-gradient(#133c40c9,#133638e8),var(--review-forest) center/cover no-repeat;gap:5px}
#stageSelect .stage-head,#stageSelect .stage-mode-row{width:min(100%,1000px);align-self:center}
#stageSelect .stage-carousel{width:min(100%,1000px);max-width:1000px;grid-template-columns:clamp(32px,5vw,56px) minmax(0,1fr) clamp(32px,5vw,56px);gap:4px}
#stageSelect .stage-grid{padding:0;scroll-padding:0;--stage-width:min(55cqw,540px);gap:clamp(6px,1.4vw,16px);justify-content:flex-start}
#stageSelect .stage-grid::before,#stageSelect .stage-grid::after{content:'';flex:0 0 max(0px,calc((100% - var(--stage-width))/2 - clamp(6px,1.4vw,16px)));height:1px;pointer-events:none}
#stageSelect .stage-thumb{max-height:42dvh}
@media(max-height:600px){#stageSelect .stage-grid{--stage-width:min(52cqw,400px)}#stageSelect .stage-thumb{max-height:33dvh}}
@media(max-height:350px){#stageSelect .stage-grid{--stage-width:min(52cqw,310px)}#stageSelect .stage-thumb{max-height:26dvh}}
/* Visual review correction: align the actual cards, not empty grid columns. */
#entry .entry-actions{width:min(100%,290px);gap:4px}
#entry .entry-btn{min-height:clamp(55px,11dvh,90px)}
#entry .entry-controls{bottom:clamp(10px,7dvh,74px);max-height:none}
@media(max-height:600px){#entry .entry-actions{width:min(100%,350px);grid-template-columns:1fr 1fr;gap:6px}#entry .entry-btn{min-height:clamp(48px,14dvh,72px);padding:5px 10px;font-size:clamp(14px,4dvh,20px)}#entry .entry-controls{bottom:clamp(10px,5dvh,25px)}#entry .entry-brand{top:clamp(8px,6dvh,30px);height:52dvh;width:min(70vw,110dvh)}#entry.intro .entry-brand{height:24dvh;top:4px;width:min(40vw,360px)}}
#home.camp-mode .home-nav button::before{width:clamp(52px,10dvh,88px);height:clamp(52px,10dvh,88px)}
#home.camp-mode .home-nav{gap:clamp(4px,.8vw,10px)}
#partySelect{background:linear-gradient(90deg,#14373872,#123b3ecd 27%,#123b3ecd 73%,#14373872),var(--review-town) center/cover no-repeat!important}
#stageSelect{background:linear-gradient(#133c4099,#133638c9),var(--review-forest) center/cover no-repeat!important}
#partySelect .party-main{--card-w:clamp(96px,22dvh,155px);--slot-w:clamp(64px,14dvh,112px)}
#partySelect #partyGrid{display:flex;flex-wrap:wrap;justify-content:center;align-content:start;align-items:start;gap:7px}
#partySelect #partyGrid .party-card{flex:0 0 var(--card-w);height:auto;padding:10px 9px 12px;min-height:0}
#partySelect .party-label{background-size:150px 100%;font-size:12px;min-height:25px}
#partySelect .party-actions{background:linear-gradient(90deg,transparent,#173d40d0 25%,#173d40d0 75%,transparent);padding:4px 0}
@media(max-height:600px){#partySelect .party-main{--card-w:clamp(90px,25dvh,128px);--slot-w:clamp(54px,15dvh,78px)}#partySelect .party-label{min-height:20px}#partySelect #partyGrid .party-card{padding:8px 6px 9px}#partySelect .party-actions{padding:2px 0}}
@media(max-height:350px){#partySelect .party-main{--card-w:72px;--slot-w:48px}#partySelect #partyGrid{gap:4px}#partySelect #partyGrid .party-card{padding:7px 5px 8px}#partySelect .party-label{min-height:18px}}
/* Use explicit background layers: scenery remains independent of the UI surface. */
#partySelect{background-image:linear-gradient(90deg,#14373875,#123b3ebd 27%,#123b3ebd 73%,#14373875),url('../assets/backgrounds/bg_02_town_square.png')!important;background-size:cover!important;background-position:center!important;background-repeat:no-repeat!important}
#stageSelect{background-image:linear-gradient(#133c4070,#133638bf),url('../assets/backgrounds/bg_03_forest.png')!important;background-size:cover!important;background-position:center!important;background-repeat:no-repeat!important}
#missionDialog{background-image:linear-gradient(90deg,#0f34388a,#133d3ee8 26%,#133d3ee8 74%,#0f34388a),url('../assets/backgrounds/bg_02_town_square.png');background-size:cover;background-position:center}
/* Short landscape screens: enough vertical space for the entire portrait and label. */
@media(max-height:600px){
 #partySelect .party-main{grid-template-columns:minmax(0,.8fr) minmax(0,1.2fr);grid-template-rows:1fr;gap:8px;--slot-w:clamp(56px,17dvh,82px);--card-w:clamp(78px,24dvh,118px)}
 #partySelect #partySlots{display:grid;grid-template-columns:repeat(3,var(--slot-w));justify-content:center;align-content:start;gap:5px;flex:1;min-height:0;overflow:auto;padding:3px}
 #partySelect #partyGrid{padding-top:4px;align-content:start;gap:5px}
 #partySelect .party-label{margin-bottom:3px}
 #partySelect .party-slots,#partySelect .party-collection{padding:5px 3px;border-top:1px solid #d4b06d;background:linear-gradient(180deg,#173c40bc,#173c4030);border-radius:6px}
}
@media(max-height:350px){#partySelect .party-main{--slot-w:51px;--card-w:64px;gap:5px}#partySelect #partyGrid .party-card{padding:7px 4px 8px}#partySelect .party-card b{font-size:10px}#partySelect .party-card small{font-size:9px}#partySelect .party-slots,#partySelect .party-collection{padding:2px}}
/* Keep every label inside the usable center of the art frame. Level is independent of the role. */
#partySelect #partyGrid .party-card{padding:12px 9px 18px}
#partySelect .party-card small{position:relative;z-index:3;line-height:1.1;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;font-size:clamp(10px,1.4vw,13px)}
#partySelect .party-card b{z-index:3;line-height:1.1}
#partySelect .party-level{position:absolute;z-index:3;top:14%;left:12%;font-size:clamp(9px,1.2vw,12px);line-height:1.1;background:#183a3de8;border:1px solid #c7ab6f;border-radius:4px;padding:1px 3px;color:#fff2c7;font-weight:800}
@media(max-height:600px){#partySelect #partyGrid .party-card{padding:9px 7px 14px}#partySelect .party-card small{font-size:10px}}
@media(max-height:350px){#partySelect #partyGrid .party-card{padding:8px 5px 11px}#partySelect .party-card small{font-size:9px}#partySelect .party-level{font-size:8px;left:10%;padding:1px 2px}}


/* UI4.1 hotfix: utility header spacing, text-fit safety, and consistent battle placement bounds. */
.bar,.app>.bar{justify-content:flex-start!important;flex-wrap:nowrap;gap:6px!important;padding:4px clamp(8px,1.5vw,16px)!important}
.bar .logo{flex:0 0 auto;min-width:0}
.bar .logo img{display:block;max-width:clamp(96px,12vw,160px);height:clamp(30px,5dvh,40px);width:auto}
.bar #record{margin-right:auto;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.bar .secondary{flex:0 0 auto;min-width:0;padding:6px 10px;white-space:nowrap}
#titleBack,#gameSave,#helpBtn{margin:0}

/* Keep headers from crushing the right edge and stop button clusters from looking isolated. */
.stage-head,.party-head,.scout-head,.battlebar,#missionDialog .mission-header{padding-inline:clamp(6px,1vw,14px)!important;gap:clamp(4px,.9vw,10px)!important}
#stageSelect .stage-head>* ,#partySelect .party-head>* ,#battle .battlebar>* ,#missionDialog .mission-header>*{min-width:0}
#stageSelect .stageCount,#stageCount,#partyCount,#record{overflow:hidden;text-overflow:ellipsis}

/* Text should stay inside frames instead of colliding with borders. */
#stageSelect .stage-card,#partySelect .party-card,#partySelect .party-slot,#battle .battle-roster button,#missionDialog .mission-row{min-width:0}
#stageSelect .stage-body strong,#partySelect .party-card b,#partySelect .party-card small,#battle .battle-roster b,#battle .battle-roster small,#missionDialog .mission-text strong,#missionDialog .mission-text small{display:block;max-width:100%;overflow:hidden;text-overflow:ellipsis}
#stageSelect .stage-body strong,#partySelect .party-card b,#battle .battle-roster b,#battle .battle-roster small,#missionDialog .mission-text strong{white-space:nowrap}
#partySelect .party-card small,#missionDialog .mission-text small{white-space:nowrap}
#partySelect .party-card b{padding-inline:2px}
#partySelect .party-card small,#battle .battle-roster small{font-size:clamp(9px,1.1vw,12px);line-height:1.15}
#battle .battle-roster button{padding:6px 6px 8px}
#battle .battle-roster b{font-size:clamp(10px,1.15vw,13px);line-height:1.1}

/* Battle field: keep the visible field centered and the interaction band aligned. */
.fieldwrap{display:grid;place-items:center;padding-inline:0}
#field{width:min(100%,1200px)!important;max-width:100%!important;height:auto!important;display:block;margin-inline:auto}

@media(max-width:900px){
  .bar,.app>.bar{gap:4px!important;padding-inline:6px!important}
  .bar .secondary{padding:5px 8px;font-size:10px;min-height:30px}
  .bar small{font-size:9px}
}
@media(max-width:640px){
  .bar .logo img{max-width:86px;height:28px}
  .bar .secondary{padding:4px 7px;font-size:9px;min-height:28px}
  #missionDialog .mission-row{grid-template-columns:minmax(0,1fr) minmax(72px,auto) 82px}
}
