/* One owner for insets: native Android CSS variables (zero when the native
   WebView is already inset), falling back to WebKit/browser safe-area env().
   Do not add UA/model offsets. Artwork remains full bleed; controls do not. */
:root{
 --app-safe-top:var(--safe-area-inset-top,env(safe-area-inset-top,0px));
 --app-safe-right:var(--safe-area-inset-right,env(safe-area-inset-right,0px));
 --app-safe-bottom:var(--safe-area-inset-bottom,env(safe-area-inset-bottom,0px));
 --app-safe-left:var(--safe-area-inset-left,env(safe-area-inset-left,0px));
 --app-safe-height:calc(100vh - var(--app-safe-top) - var(--app-safe-bottom));
 --app-safe-stable-height:calc(100vh - var(--app-safe-top) - var(--app-safe-bottom));
 --app-safe-width:calc(100vw - var(--app-safe-left) - var(--app-safe-right));
}
@supports(height:100dvh){:root{--app-safe-height:calc(100dvh - var(--app-safe-top) - var(--app-safe-bottom))}}
@supports(height:100svh){:root{--app-safe-stable-height:calc(100svh - var(--app-safe-top) - var(--app-safe-bottom))}}
body{padding:var(--app-safe-top) var(--app-safe-right) var(--app-safe-bottom) var(--app-safe-left)}
#home-view .hero{height:calc(var(--app-safe-stable-height) - var(--page-header-height,120px))}
#creation-guide.creation-starry:not(.creation-has-query){height:calc(var(--app-safe-stable-height) - var(--page-header-height,120px))}
#creation-guide.creation-starry.creation-has-query{min-height:calc(var(--app-safe-stable-height) - var(--page-header-height,120px))}
/* Dialogs live in the top layer, outside body padding. Keep both their visible
   surface and scrolling content inside the same safe rectangle. */
dialog:not(#settings-dialog):not(#first-welcome){
 inset:var(--app-safe-top) var(--app-safe-right) var(--app-safe-bottom) var(--app-safe-left)!important;
 max-width:calc(var(--app-safe-width) - 32px)!important;
 max-height:min(88dvh,calc(var(--app-safe-height) - 32px))!important;
}
#settings-dialog{
 inset:var(--app-safe-top) var(--app-safe-right) var(--app-safe-bottom) var(--app-safe-left);
 width:var(--app-safe-width);height:var(--app-safe-height);max-height:var(--app-safe-height);
}
#term-reading{max-height:min(calc(88dvh - 2px),calc(var(--app-safe-height) - 34px))}
.settings-notice{bottom:calc(var(--app-safe-bottom) + 24px)}
.toast.toast-favorite{bottom:calc(var(--app-safe-bottom) + 30px)}
.local-test-launcher{left:calc(var(--app-safe-left) + 12px);bottom:calc(var(--app-safe-bottom) + 12px)}
@media(max-width:760px){
 .moon-pendant{top:calc(var(--app-safe-top) + max(0px,var(--page-header-height,90px) + var(--page-header-height,90px) - 180px))}
 /* Settings is already inset above. Do not charge the safe area twice. */
 #settings-dialog .settings-shell{padding-top:10px;padding-bottom:32px}
 #settings-dialog[data-page=account] .settings-shell{padding-top:0;padding-bottom:34px}
 dialog:not(#settings-dialog):not(#first-welcome){max-height:min(92dvh,calc(var(--app-safe-height) - 32px))!important}
 #term-reading{max-height:min(calc(92dvh - 2px),calc(var(--app-safe-height) - 34px))}
}
@media(max-width:600px){
 #profile-editor[data-field=birthday]{inset:auto var(--app-safe-right) calc(var(--app-safe-bottom) + 8px) var(--app-safe-left)!important}
}
@media(orientation:landscape) and (max-width:1000px) and (max-height:500px){
 /* Body/dialog already excludes the notch on both sides. */
 .header{padding-left:4%;padding-right:4%}
 #creation-guide.creation-starry:not(.creation-has-query){height:auto;min-height:calc(var(--app-safe-stable-height) - var(--page-header-height,120px))}
}

/* The portrait website uses a contained viewport below the browser toolbar. */
@media (display-mode:browser) and (orientation:portrait) and (max-width:760px){
 body[data-view="home"]{padding-top:0}
 body[data-view="home"]>.header{padding-top:10px;min-height:76px;align-content:flex-start}
 body[data-view="home"] #home-view .hero{height:calc(100svh - var(--app-safe-bottom) - var(--page-header-height,76px))}
 body[data-view="home"]>.moon-pendant{top:max(0px,calc(var(--page-header-height,76px) + var(--page-header-height,76px) - 180px))}
}
