/* Bound functional panels by the viewport; large scene artwork is the sole canvas exception. */
:root{--viewport-panel-width:calc(100vw - 24px);--viewport-panel-height:calc(100dvh - 24px)}
html,body{max-width:100%;overscroll-behavior:none}
dialog{box-sizing:border-box!important;min-width:0!important;max-width:var(--viewport-panel-width)!important;max-height:var(--viewport-panel-height)!important;overflow-y:auto;overflow-x:hidden}
dialog input,dialog select,dialog textarea{min-width:0;max-width:100%;box-sizing:border-box}
dialog .settings-footer-actions,dialog .buddy-dialog-actions{flex-wrap:wrap}
dialog .settings-footer-actions>*,dialog .buddy-dialog-actions>*{min-width:0;max-width:100%}
dialog :is(h1,h2,h3,p,label,.settings-hint,.settings-warning){overflow-wrap:anywhere}
.game-category-dialog{overflow:hidden!important}
.game-category-header,.game-category-footer,.game-category-options,.game-category-shell{min-width:0;max-width:100%}
.worlds-header{min-width:0;max-width:100%;box-sizing:border-box}
.worlds-header h1{min-width:0;overflow-wrap:anywhere}
#screen-theme-editor .worlds-header{display:grid;grid-template-columns:44px minmax(0,1fr) 44px;gap:6px}
#learning-world-title{min-width:0;max-width:100%;font-size:18px;padding:6px;gap:4px;overflow-wrap:anywhere}
#learning-world-title img{width:32px;height:32px;flex:none}
#learning-world-title>span{min-width:0}
#navigation-theme-world-home{grid-column:3;grid-row:2;justify-self:end;margin:0}
.worlds-tray-panel,.learning-world-controls{box-sizing:border-box;max-width:calc(100% - 24px)}
.learning-world-controls{left:12px;right:12px;min-width:0}
.learning-world-tools,#learning-world-tray,.worlds-tray{min-width:0;max-width:100%}
#screen-word-library .worlds-header h1,#screen-word-study .worlds-header h1{flex:1;font-size:26px}
/* Expanded tablet scene: keep all controls at phone dimensions while the scene uses the tablet. */
html[data-preview-device=ipad] :is(#screen-worlds-editor,#screen-theme-editor) .worlds-header{width:min(440px,100%);max-width:440px;left:50%;right:auto;transform:translateX(-50%);margin:0}
html[data-preview-device=ipad] .learning-world-controls{width:min(416px,calc(100% - 24px));left:50%;right:auto;transform:translateX(-50%);height:155px}
html[data-preview-device=ipad] #screen-theme-editor .learning-world-main{inset:0}
html[data-preview-device=ipad] #learning-world-title{font-size:18px}
html[data-preview-device=ipad] #learning-world-title img{width:32px;height:32px}
#screen-voice-preview{min-width:0;min-height:0}
#screen-voice-preview .voice-return-bar{position:relative;flex:0 0 68px;max-width:100%;padding:12px;box-sizing:border-box}
#voice-preview-frame{flex:1;min-width:0;min-height:0;width:100%!important;height:auto!important}
/* Pause uses an overlay rather than <dialog>, so it needs its own viewport bounds. */
.overlay{padding:12px;box-sizing:border-box}
.overlay-card{box-sizing:border-box;min-width:0;max-width:min(416px,calc(100vw - 24px));max-height:calc(100dvh - 24px);padding:24px clamp(16px,5vw,28px);overflow:auto;overflow-wrap:anywhere}
.overlay-card button{min-width:0;max-width:100%;white-space:normal}
.sw-shell,.sw-header,.sw-lesson,.sw-library,.study-reader,.study-reader-nav{min-width:0;max-width:100%}
.sw-header #sw-title{min-width:0}
/* Tablet theme tools can be collapsed so every saved canvas position stays reachable. */
#viewport-theme-tools-toggle{position:absolute;z-index:30;right:max(12px,calc((100% - 416px)/2));bottom:167px;pointer-events:auto}
#screen-theme-editor.viewport-tools-hidden .learning-world-controls{display:none}
#screen-theme-editor.viewport-tools-hidden #viewport-theme-tools-toggle{bottom:max(12px,env(safe-area-inset-bottom))}
#viewport-theme-tools-toggle[aria-expanded=true]{background:#FFE8A6!important}
html[data-preview-device=ipad] dialog{max-width:min(416px,calc(100vw - 24px))!important}
html[data-preview-device=ipad] #learning-world-title small{font-size:10px}
