/* Keep each authored module's own ratio. Only uniform fit, never stretch the model or frame. */
body #pui-bag-character-pair{--pair-height:min(824px,calc(100dvh - 24px),calc((100vw - 24px)/1.584632));position:fixed;inset:0;margin:auto;padding:0;border:0;background:transparent;width:max-content;max-width:calc(100vw - 24px);height:var(--pair-height);max-height:none;overflow:visible;box-shadow:none}
#pui-bag-character-pair[open]{display:flex;align-items:stretch;gap:0}
#pui-bag-character-pair:not([open]),#pui-bag-character-pair>dialog:not([open]){display:none!important}
#pui-bag-character-pair::backdrop{background:#020103a0}
/* Closing one child keeps the remaining module at its existing size. */
body #pui-bag-character-pair #character-frame-dialog[open]{--cf-u:calc(var(--pair-height)/1456);position:relative;inset:auto;margin:0;flex:none;width:calc(var(--pair-height)*.747253);height:var(--pair-height);min-width:0;min-height:0;max-width:none;max-height:none;padding:0;border:0;border-image:none;border-radius:0;display:block;box-shadow:none;overflow:hidden}
body.adventure-hud #pui-bag-character-pair #equipment-dialog.pui-module.pui-bag[data-page=bag][open]{position:relative;inset:auto;margin:0;flex:none;width:calc(var(--pair-height)*.837379);height:var(--pair-height);min-width:0;min-height:0;max-width:none;max-height:none;transform:none;display:flex;box-shadow:none}
#character-frame-dialog .cf-preview{object-fit:contain}
/* Restore portrait module geometry even on a short display; the native portrait canvas matches it. */
#pui-bag-character-pair .cf-frame{display:block;position:absolute;inset:0;width:100%;height:100%;object-fit:contain}
#pui-bag-character-pair .cf-preview{position:absolute;inset:0;width:100%;height:100%;margin:0;object-fit:contain}
#pui-bag-character-pair .cf-pedestal{position:absolute;left:12%;top:70%;bottom:auto;width:76%;height:21%;object-fit:contain}
#pui-bag-character-pair #character-frame-title{top:4%;left:26%;width:48%;font-size:clamp(16px,calc(65 * var(--cf-u)),38px);line-height:1.35;text-align:center}
#pui-bag-character-pair .cf-name{inset:11.2% 24% auto;line-height:1.4;font-size:clamp(12px,calc(37 * var(--cf-u)),24px);padding:0 0 calc(12 * var(--cf-u));border-bottom:1px solid #aa843f}
#pui-bag-character-pair .cf-close{top:4.2%;right:3.7%;width:8%;height:6%;min-width:26px;min-height:26px}
#pui-bag-character-pair .cf-slot{top:calc(20% + var(--row) * 14.6%);width:17%;height:13%;padding:calc(8 * var(--cf-u));display:flex;flex-direction:column;align-items:center;justify-content:flex-end;gap:2px}
#pui-bag-character-pair .cf-left{left:7%}#pui-bag-character-pair .cf-right{right:7%}
#pui-bag-character-pair .cf-slot-art{height:auto;width:100%;flex:1;min-height:0;display:grid;place-items:center}
#pui-bag-character-pair .cf-slot-art>img{height:100%;width:100%;max-height:calc(128 * var(--cf-u));object-fit:contain}
#pui-bag-character-pair .cf-slot-label{font-size:clamp(9px,calc(28 * var(--cf-u)),18px);line-height:1.3;white-space:nowrap;border-top:1px solid #96794f5c}
#pui-bag-character-pair .cf-slot-state{font-size:clamp(8px,calc(17 * var(--cf-u)),11px);line-height:1.3}
#pui-bag-character-pair .cf-life{font-size:clamp(8px,calc(23 * var(--cf-u)),15px)}
#pui-bag-character-pair .cf-rotation{inset:82% 24% auto;height:7%}#pui-bag-character-pair .cf-rotation button{width:20%;height:100%}
#pui-bag-character-pair .cf-caption{bottom:7.7%;left:20%;width:60%;font-size:clamp(8px,calc(24 * var(--cf-u)),15px);line-height:1.5}
/* Reduce control chrome, while the bag's actual grid and actions retain their own scroll. */
@media(max-width:1100px), (max-height:620px){
 body.adventure-hud #pui-bag-character-pair #equipment-dialog.pui-module.pui-bag[data-page=bag][open]{padding:8px!important}
 #pui-bag-character-pair .equipment-header{padding-bottom:4px!important}
 #pui-bag-character-pair .equipment-header h2{font-size:19px!important}
 body.adventure-hud #pui-bag-character-pair #close-equipment{width:30px;height:30px;padding:4px}
 body.adventure-hud #pui-bag-character-pair .adventure-inventory{margin-top:4px}
 body.adventure-hud #pui-bag-character-pair .adventure-grid-tabs{height:28px!important;min-height:28px!important;margin-bottom:4px!important;gap:4px!important}
 body.adventure-hud #pui-bag-character-pair .bag-top-tab{height:28px!important;min-height:28px!important;font-size:11px!important;padding:3px 6px!important}
 body.adventure-hud #pui-bag-character-pair .bag-top-tab .adventure-icon{display:none!important}
 body.adventure-hud #pui-bag-character-pair .adventure-search,body.adventure-hud #pui-bag-character-pair .adventure-search input{height:30px!important;min-height:30px!important;max-height:30px!important;font-size:12px!important;margin-bottom:4px!important}
 body.adventure-hud #pui-bag-character-pair .adventure-empty-note{display:none!important}
 body.adventure-hud #pui-bag-character-pair .bag-potion-disclosure{margin-top:4px!important;padding:2px 6px!important;max-height:100px!important}
 body.adventure-hud #pui-bag-character-pair .bag-potion-disclosure>summary{min-height:24px!important;font-size:12px!important}
 body.adventure-hud #pui-bag-character-pair #equipment-dialog>.equipment-footer{font-size:11px;padding-top:2px;margin-top:4px}
 body.adventure-hud #pui-bag-character-pair .equipment-footer small{display:none}
 body.adventure-hud #pui-bag-character-pair #adventure-item-grid{grid-template-rows:repeat(6,minmax(44px,1fr));grid-auto-rows:50px;gap:4px}
}
/* Compact bag: same nominal width as the player-info sheet; content reflows, not scales. */
body.adventure-hud #equipment-dialog.pui-module.pui-bag[data-page=bag][open]{--bag-height:min(824px,calc(100dvh - 24px),calc((100vw - 24px)*1.194203));width:calc(var(--bag-height)*.837379);height:var(--bag-height);padding:12px!important;overflow:hidden;container-type:inline-size}
body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] .equipment-header{padding:0 0 8px!important;flex:none;position:relative!important;top:auto;background:none;min-height:44px}
body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] .equipment-header h2{font-size:24px!important}
body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] .adventure-inventory{display:flex;flex-direction:column;flex:1;min-height:0;overflow:hidden;margin-top:8px}
body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] .adventure-bag-grid{display:flex;flex-direction:column;flex:1;min-height:0;overflow:hidden}
body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] .adventure-grid-tabs{display:grid!important;grid-template-columns:repeat(3,minmax(0,1fr));height:auto!important;min-height:0!important;padding:0 0 8px!important;gap:4px!important;margin:0!important;flex:none}
body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] .bag-top-tab{display:flex;align-items:center;justify-content:center;gap:6px;width:100%;height:32px!important;min-height:32px!important;padding:3px 6px!important;font-size:13px!important}
body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] .bag-top-tab .adventure-icon{width:18px;height:18px}
body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] .adventure-search{flex:none;height:36px!important;min-height:36px!important;margin-bottom:8px!important;gap:8px}
body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] .adventure-search input{height:36px!important;min-height:36px!important;max-height:36px!important;font-size:14px!important}
body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] .adventure-search>span{min-width:54px!important;font-size:12px!important}
body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] #adventure-item-grid{display:grid;grid-template-columns:repeat(8,minmax(0,1fr));grid-template-rows:none;grid-auto-rows:max-content;flex:1;min-height:0;height:auto;overflow:auto;gap:6px;align-content:start}
body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] :is(.adventure-grid-item,.adventure-grid-empty){aspect-ratio:1!important;height:auto!important;min-height:44px!important}
body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] .adventure-empty-note{margin:6px 0 0!important;font-size:12px!important}
body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] .bag-potion-disclosure{flex:none;margin:6px 0 0!important;padding:0 8px!important;max-height:160px!important;overflow:auto!important}
body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] .bag-potion-disclosure>summary{min-height:32px!important;font-size:13px!important}
body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag]>.equipment-footer{padding:4px 0 0!important;margin-top:6px!important;font-size:11px}
@container(max-width:480px){
 .pui-bag .bag-top-tab .adventure-icon{display:none!important}
 body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] #adventure-item-grid{grid-template-columns:repeat(6,minmax(0,1fr));gap:4px}
}
@container(max-width:300px){
 body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] #adventure-item-grid{grid-template-columns:repeat(4,minmax(0,1fr))}
}
@media(max-height:620px){
 body.adventure-hud #equipment-dialog.pui-module.pui-bag[data-page=bag][open]{padding:8px!important}
 body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] .equipment-header h2{font-size:19px!important}
 body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag]>.equipment-footer{display:none!important}
 body.adventure-hud :is(#game,#pui-bag-character-pair) #equipment-dialog.pui-bag[data-page=bag] .adventure-empty-note{display:none!important}
}
@media(max-width:600px) and (min-height:621px){
 body #pui-bag-character-pair{--portrait-width:calc(100vw - 24px);width:var(--portrait-width);height:calc(100dvh - 24px);overflow-y:auto;overflow-x:hidden;overscroll-behavior:contain}
 #pui-bag-character-pair[open]{flex-direction:column;align-items:center}
 body #pui-bag-character-pair #character-frame-dialog[open]{--cf-u:calc(var(--portrait-width)/1088);width:var(--portrait-width);height:calc(var(--portrait-width)*1.338235);flex:none}
 body.adventure-hud #pui-bag-character-pair #equipment-dialog.pui-module.pui-bag[data-page=bag][open]{width:var(--portrait-width);height:calc(var(--portrait-width)*1.194203);flex:none;padding:8px!important;display:flex;overflow:hidden}
 body.adventure-hud #pui-bag-character-pair #equipment-dialog>.equipment-footer{display:none!important}
 body.adventure-hud #pui-bag-character-pair .equipment-header{position:sticky!important;top:0;z-index:3;padding-bottom:3px!important;background:#281a36f5}
 body.adventure-hud #pui-bag-character-pair .adventure-inventory{display:block;overflow:visible;min-height:0}
 body.adventure-hud #pui-bag-character-pair .adventure-bag-grid{display:block;overflow:visible;min-height:0}
 body.adventure-hud #pui-bag-character-pair .adventure-search{margin-bottom:2px!important}
 body.adventure-hud #pui-bag-character-pair .adventure-grid-tabs{margin-bottom:2px!important}
 body.adventure-hud #pui-bag-character-pair #adventure-item-grid{height:auto;min-height:44px;overflow:visible;grid-template-columns:repeat(6,minmax(0,1fr));grid-template-rows:none;grid-auto-rows:44px}
}
/* 2026-10-12 pair-close: same as the character pair: a closed window keeps its size as an invisible placeholder so the
   other window stays where it is. */
#pui-bag-character-pair[open]>dialog:not([open]){display:block!important;visibility:hidden!important;opacity:0!important;pointer-events:none!important}
body #pui-bag-character-pair[open] #character-frame-dialog:not([open]){position:relative;inset:auto;margin:0;flex:none;width:calc(var(--pair-height)*.747253);height:var(--pair-height);min-width:0;min-height:0;max-width:none;max-height:none;padding:0;border:0;transform:none}
body.adventure-hud #pui-bag-character-pair[open] #equipment-dialog.pui-module.pui-bag:not([open]){position:relative;inset:auto;margin:0;flex:none;width:calc(var(--pair-height)*.837379);height:var(--pair-height);min-width:0;min-height:0;max-width:none;max-height:none;transform:none}
