/* Co giãn theo cửa sổ thực tế, dùng chung trên trình duyệt và ứng dụng. */
:root{--screen-height:100vh;--screen-height:100dvh;--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)}
html{min-width:0;-webkit-text-size-adjust:100%;text-size-adjust:100%}
body{min-width:0}
html:has(body:not(.battle-mode)>.hunt-page){scrollbar-gutter:stable}
body>.game.unified-mine,body>.manual-page,body>.five-elements,body>.character-page,body>.npc-page,body:not(.battle-mode)>.hunt-page{width:100%;max-width:none;min-width:0}
body>.game.unified-mine,body>.npc-page,body>.five-elements{height:var(--screen-height);max-height:var(--screen-height)}
body>.manual-page,body>.character-page,body:not(.battle-mode)>.hunt-page{min-height:var(--screen-height)}
body>.manual-page,body>.character-page,body>.five-elements{padding-left:max(12px,var(--safe-left));padding-right:max(12px,var(--safe-right));padding-bottom:calc(78px + var(--safe-bottom))}
body .global-bottom-nav,body .five-elements .global-bottom-nav,body:not(.battle-mode) .hunt-bottom-nav{width:100%;max-width:none;left:0;right:0;transform:none;padding-left:max(10px,var(--safe-left));padding-right:max(10px,var(--safe-right));height:calc(62px + var(--safe-bottom));padding-bottom:calc(5px + var(--safe-bottom))}
.npc-content{padding-left:max(12px,var(--safe-left));padding-right:max(12px,var(--safe-right))}
.npc-list{grid-template-columns:repeat(auto-fit,minmax(min(100%,280px),1fr))}
.npc-sheet,.npc-hero,.npc-tabs{max-width:960px;margin-left:auto;margin-right:auto}
.five-elements>:is(.element-overview,.element-detail,#element-rules).panel-open{position:fixed;z-index:200;grid-area:auto;top:max(12px,var(--safe-top));bottom:calc(78px + var(--safe-bottom));left:50%;right:auto;transform:translateX(-50%);width:min(800px,calc(100% - 24px - var(--safe-left) - var(--safe-right)));margin:0;overflow:auto;background:#173f3d;color:#fff1d0}
.five-elements .panel-open .detail-heading h2,.five-elements .panel-open .detail-heading small{color:#ffe0a6}
.element-panel-close{display:block;position:sticky;top:0;margin:0 0 10px auto;z-index:2;min-height:44px;padding:8px 12px;border:1px solid #a17d45;border-radius:6px;background:#fff3d5;color:#493519;font-weight:700}
.modal-card,.quick-menu{overscroll-behavior:contain}
.modal-card{max-height:calc(var(--screen-height) - 24px - var(--safe-top) - var(--safe-bottom))}
/* Không dịch chuyển khung chứa thanh điều hướng cố định khi chuyển trang. */
@media(prefers-reduced-motion:no-preference){
 .five-elements,.manual-page,.character-page{animation-name:screen-page-enter}
 @keyframes screen-page-enter{from{opacity:0}to{opacity:1}}
}
.game.unified-mine .mine-caption{color:#fff3d4;background:#173e36db;text-shadow:0 1px 2px #071c18}
.game.unified-mine .cultivation h2{font-size:18px;line-height:1.2;margin:2px 0 4px}
.game.unified-mine .cultivation .flow{margin-top:4px;line-height:1.2}
/* Màn dọc: chia chiều cao cho trang bị và điều khiển, phần còn lại là cảnh. */
@media(max-width:759px){
 body>.game.unified-mine{--dock-height:clamp(126px,18dvh,164px);--gear-height:clamp(174px,27dvh,230px)}
 .game.unified-mine .equipment-panel{top:auto;bottom:calc(var(--dock-height) + var(--safe-bottom));height:var(--gear-height);overflow-y:auto}
 .game.unified-mine .cultivation{top:auto;bottom:calc(var(--dock-height) + var(--gear-height) + 12px + var(--safe-bottom));height:96px;transform:none}
 .game.unified-mine .miner{top:88px;left:0;width:72%;height:calc(100% - var(--dock-height) - var(--gear-height) - 200px - var(--safe-bottom));min-height:70px}
 .game.unified-mine .ore-deposit{top:88px;left:58%;width:42%;height:calc(100% - var(--dock-height) - var(--gear-height) - 200px - var(--safe-bottom));min-height:70px}
 .game.unified-mine .mine-caption{top:auto;bottom:calc(var(--dock-height) + var(--gear-height) + 110px + var(--safe-bottom));left:4%;right:4%;font-size:9px;min-height:18px}
 .game.unified-mine .resonance{top:auto;bottom:calc(var(--dock-height) + var(--gear-height) + 2px + var(--safe-bottom));left:4%;right:4%;height:10px}
 .game.unified-mine .bottom-nav{height:calc(var(--dock-height) + var(--safe-bottom));padding:0 max(6px,var(--safe-right)) calc(4px + var(--safe-bottom)) max(6px,var(--safe-left));grid-template-columns:1fr 1fr 96px 1fr 1fr}
 .game.unified-mine .bottom-nav button{height:48px}
 .game.unified-mine .mine-action{top:auto;bottom:calc(8px + var(--safe-bottom));width:88px;height:88px}
 .game.unified-mine .pickaxe-badge,.game.unified-mine .auto-mine-toggle{top:auto;bottom:calc(62px + var(--safe-bottom))}
 .game.unified-mine .quest-card{bottom:calc(56px + var(--safe-bottom));width:calc(50% - 54px);left:max(8px,var(--safe-left))}
}
/* Màn rộng hoặc điện thoại xoay ngang: chia cảnh và bảng điều khiển. */
@media(min-width:760px),(orientation:landscape) and (min-width:520px) and (max-height:520px){
 .game.unified-mine{--side-width:clamp(330px,36%,580px);--home-nav:calc(70px + var(--safe-bottom))}
 .game.unified-mine .masthead{top:max(8px,var(--safe-top));left:max(16px,var(--safe-left));right:max(16px,var(--safe-right));grid-template-columns:minmax(0,1fr) 52px}
 .game.unified-mine .profile{max-width:min(460px,calc(100% - 350px))}
 .game.unified-mine .resources{position:absolute;grid-area:auto;right:68px;top:0;height:44px;margin:0;min-width:260px}
 .game.unified-mine .resources button{flex:1}
 .game.unified-mine .cultivation{top:calc(74px + var(--safe-top));bottom:auto;left:auto;right:max(16px,var(--safe-right));width:var(--side-width);height:90px;transform:none;padding:7px 10px}
 .game.unified-mine .equipment-panel{top:calc(176px + var(--safe-top));bottom:calc(var(--home-nav) + 16px);height:auto;left:auto;right:max(16px,var(--safe-right));width:var(--side-width);overflow:auto;padding:12px}
 .game.unified-mine .equipment-grid{gap:6px}
 .game.unified-mine .equipment-slot{height:clamp(46px,10dvh,90px)}
 .game.unified-mine .slot-art{width:clamp(30px,6dvh,54px);height:clamp(30px,6dvh,54px)}
 .game.unified-mine .slot-name{font-size:11px}
 .game.unified-mine .miner{top:100px;left:0;width:calc((100% - var(--side-width)) * .8);height:calc(100% - 250px - var(--safe-bottom));min-height:90px}
 .game.unified-mine .ore-deposit{top:100px;left:calc((100% - var(--side-width)) * .56);width:calc((100% - var(--side-width)) * .4);height:calc(100% - 250px - var(--safe-bottom));min-height:90px}
 .game.unified-mine .mine-caption{top:auto;left:16px;right:calc(var(--side-width) + 32px);bottom:calc(var(--home-nav) + 122px);font-size:11px}
 .game.unified-mine .resonance{top:auto;left:24px;right:calc(var(--side-width) + 40px);bottom:calc(var(--home-nav) + 112px)}
 .game.unified-mine .npc-home-entry{top:calc(74px + var(--safe-top));left:max(16px,var(--safe-left));right:auto;min-height:66px}
 .game.unified-mine .mine-action{top:auto;bottom:calc(var(--home-nav) + 12px);left:calc((100% - var(--side-width)) * .48);width:88px;height:88px}
 .game.unified-mine .pickaxe-badge{top:auto;bottom:calc(var(--home-nav) + 34px);left:calc((100% - var(--side-width)) * .48 + 56px)}
 .game.unified-mine .auto-mine-toggle{top:auto;bottom:calc(var(--home-nav) + 34px);left:calc((100% - var(--side-width)) * .48 + 108px)}
 .game.unified-mine .quest-card{left:max(16px,var(--safe-left));bottom:calc(var(--home-nav) + 24px);width:clamp(110px,15%,190px);height:62px}
 .game.unified-mine .bottom-nav{height:var(--home-nav);padding:4px max(16px,var(--safe-right)) calc(4px + var(--safe-bottom)) max(16px,var(--safe-left));grid-template-columns:repeat(4,minmax(0,1fr));align-items:center}
 .game.unified-mine .bottom-nav button:nth-child(n){grid-column:auto;grid-row:1;height:58px}
 .game.unified-mine .quick-menu-grid{grid-template-columns:repeat(auto-fit,minmax(150px,1fr))}
 body>.character-page{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px;align-content:start}
 .character-page .character-header{grid-column:1/-1}
 .character-page .character-sheet{margin-top:0}
 body>.manual-page{display:grid;grid-template-columns:minmax(280px,.8fr) minmax(360px,1.2fr);gap:16px;align-content:start;height:auto;overflow:visible}
 .manual-page .manual-header{grid-column:1/-1}
 .manual-page .manual-panel{min-width:0;max-height:none;overflow:visible;margin-top:0}
 .manual-page #manual-browser,.manual-page #element-school,.manual-page #mind-panel{grid-column:1}
 .manual-page #manual-detail{grid-column:2;grid-row:2/span 3}
 body>.five-elements{display:grid;grid-template-columns:minmax(280px,.8fr) minmax(360px,1.2fr);gap:14px;align-content:start}
 .five-elements>.page-header,.five-elements>.resource-card,.five-elements>.element-tools{grid-column:1}
 .five-elements>.formation{grid-column:2;grid-row:1/span 4;min-height:420px;height:calc(var(--screen-height) - 100px - var(--safe-top) - var(--safe-bottom));margin:12px 0}
 .five-elements .formation-map{max-width:600px}
 .five-elements>.element-overview{grid-column:1}
 body:not(.battle-mode) .hunt-header{padding-left:16px;padding-right:16px}
 body:not(.battle-mode) .realm-view .stage-list{height:clamp(220px,calc(100dvh - 420px),620px)!important;min-height:220px!important}
 body:not(.battle-mode) .realm-view{display:grid;grid-template-columns:minmax(0,1fr) clamp(320px,32vw,400px);grid-template-areas:"menu menu" "zones zones" "heading heading" "map detail";gap:10px 16px;align-items:start}
 body:not(.battle-mode) .realm-view #stage-menu-toggle{grid-area:menu}
 body:not(.battle-mode) .realm-view #hunt-zones{grid-area:zones}
 body:not(.battle-mode) .realm-view .stage-map-head{grid-area:heading}
 body:not(.battle-mode) .realm-view .stage-list{grid-area:map}
 body:not(.battle-mode) .realm-view .stage-select-prompt{grid-area:detail;margin:0;padding:20px 12px}
 body:not(.battle-mode) .realm-view #stage-detail:not([hidden]){grid-area:detail;min-width:0;min-height:0;max-height:calc(var(--screen-height) - 240px - var(--safe-top) - var(--safe-bottom))!important;overflow-y:auto!important;overscroll-behavior:contain;margin:0!important;scroll-margin-top:150px;align-content:start}
}
@media(min-width:760px) and (max-height:600px){
 body:not(.battle-mode) .realm-view #stage-detail:not([hidden]){max-height:calc(var(--screen-height) - 160px - var(--safe-top) - var(--safe-bottom))!important;scroll-margin-top:72px}
}
/* Cửa sổ quá thấp vẫn cho cuộn tới các nút, không cắt nội dung. */
@media(max-height:520px) and (max-width:519px){
 html:has(.game.unified-mine),body:has(>.game.unified-mine){overflow:auto;height:auto;display:block}
 body>.game.unified-mine{height:560px;max-height:none}
}
/* Cảnh chiến đấu cùng tỷ lệ với tọa độ trận; tiêu đề bám mép cảnh. */
body.battle-mode:not(.world-boss-screen) #battle-card{height:var(--screen-height);max-height:var(--screen-height);--battle-height:calc(var(--screen-height) - var(--safe-top) - var(--safe-bottom))}
body.battle-mode:not(.world-boss-screen) #battle-card .battle-title{top:max(var(--safe-top),calc((var(--screen-height) - (100vw - 16px - var(--safe-left) - var(--safe-right)) * 9 / 16) / 2))}

@media (max-width:759px) and (orientation:portrait){
 .game.unified-mine .masthead{top:max(6px,var(--safe-top));left:max(8px,var(--safe-left));right:max(8px,var(--safe-right))}
}
@media (max-width:759px) and (orientation:portrait),(orientation:landscape) and (min-width:520px) and (max-height:520px){
 .game.unified-mine .equipment-panel{display:flex;flex-direction:column}
 .game.unified-mine .equipment-heading{flex:none}
 .game.unified-mine .equipment-grid{flex:1;min-height:0;grid-template-rows:repeat(3,minmax(0,1fr))}
 .game.unified-mine .equipment-slot{height:100%;min-height:0;min-width:0;grid-template-rows:minmax(0,1fr) auto}
 .game.unified-mine .slot-art{max-height:100%;min-height:0}
 .game.unified-mine .slot-name{font-size:clamp(8px,2.4vw,11px);line-height:1.1;white-space:nowrap}
}
@media (orientation:landscape) and (min-width:520px) and (max-height:520px){
 body>.game.unified-mine{--side-width:clamp(240px,41%,410px);--home-nav:calc(46px + var(--safe-bottom))}
 .game.unified-mine .resources{right:60px;min-width:0;width:36%}
 .game.unified-mine .profile{max-width:45%}
 .game.unified-mine .bottom-nav button:nth-child(n){height:40px}
 .game.unified-mine .equipment-slot .slot-art{width:28px;height:26px}
 .game.unified-mine .equipment-slot .slot-name{font-size:9px}
 .game.unified-mine .equipment-panel{top:calc(151px + var(--safe-top));bottom:calc(var(--home-nav) + 2px);padding:4px;overflow:auto}
 .game.unified-mine .cultivation{top:calc(58px + var(--safe-top));height:88px}
}

@media (orientation:landscape) and (min-width:520px) and (max-height:520px){
 .game.unified-mine .npc-home-entry{left:auto;right:calc(var(--side-width) + 24px);top:calc(60px + var(--safe-top));width:58px;min-height:54px}
 .game.unified-mine .bottom-nav button:nth-child(n){display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;min-height:0;padding:1px 2px}
 .game.unified-mine .bottom-nav button span,.game.unified-mine .bottom-nav .nav-art{height:20px;line-height:20px}
 .game.unified-mine .bottom-nav button small{font-size:9px;line-height:11px}
}
@media (orientation:portrait) and (max-height:620px){
 .game.unified-mine .npc-home-entry{top:84px;min-height:46px;padding:2px}
 .game.unified-mine .npc-home-entry span{font-size:16px;line-height:18px}
}
