/* Mobile only: preserve desktop dimensions and all existing routes. */
@media screen and (max-width:720px){
 html{-webkit-text-size-adjust:100%;text-size-adjust:100%;scroll-padding-bottom:100px}
 body{min-width:0;-webkit-tap-highlight-color:transparent}
 :where(button,a,input,select,textarea){touch-action:manipulation}
 :where(input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]),select,textarea){font-size:16px!important}
 :where(button,.button,.icon-button,.tool-button,.text-button,.close,.tool-history-delete,.tool-history-refresh,.tool-history-close){min-height:44px}
 :where(.icon-button,.close,.tool-history-delete,.tool-history-refresh,.tool-history-close){min-width:44px}
 :where(button,.button,a):focus-visible{outline:2px solid var(--primary,#506590);outline-offset:2px}
 :where(.app-header,.assistant-topbar,.topbar){padding-inline:max(12px,env(safe-area-inset-left)) max(12px,env(safe-area-inset-right))}
 html body dialog{max-width:calc(100vw - 16px)!important;max-height:calc(min(100dvh,var(--mobile-visible-height,100dvh)) - 16px)!important;overscroll-behavior:contain}
 dialog[open]:has(>.dialog-body){display:flex;flex-direction:column;overflow:hidden}
 dialog>.dialog-head{flex:none;padding:16px;gap:12px}
 dialog>.dialog-body{flex:1;min-height:0;overflow:auto;overscroll-behavior:contain;padding:16px}
 dialog>.dialog-actions{flex:none;display:flex;flex-wrap:wrap;gap:8px;padding:12px 16px max(12px,env(safe-area-inset-bottom));background:var(--surface,#fff)}
 dialog>.dialog-actions>button{flex:1 1 auto;white-space:normal}
 dialog>.dialog-head h2{font-size:20px;line-height:1.4}
 :where(.class-grade-scroll,.schedule-board-scroll,.objective-scroll-list,.table-scroll){overscroll-behavior-x:contain;-webkit-overflow-scrolling:touch}
 .dashboard .mobile-more-menu:not([hidden]){max-height:calc(var(--mobile-visible-height,100dvh) - 100px - env(safe-area-inset-bottom))}
 .dashboard .desk-nav button{min-height:48px}
 .assistant-hub-categories{scroll-padding-inline:8px}
 #assistantHubPanel .assistant-hub-categories button{min-height:44px}
 #assistantHubPanel .assistant-hub-search{min-height:48px}
 .assistant-topbar{gap:10px;flex-wrap:wrap}
 .assistant-topbar h1{font-size:19px;line-height:1.3}
 .assistant-messages,.chat-messages{overscroll-behavior-y:contain;scroll-behavior:auto}
 .assistant-composer textarea,.chat-composer textarea,.composer textarea,.composer-box textarea{max-height:28dvh}
 .tool-history-sidebar{padding-bottom:max(16px,env(safe-area-inset-bottom));max-height:var(--mobile-visible-height,100dvh)}
 .tool-history-item{min-height:54px}.tool-history-new,.tool-history-setting{min-height:44px;font-size:13px}
 .tool-history-row{grid-template-columns:minmax(0,1fr) 44px}
 .tool-history-item-title{font-size:13px}.tool-history-item-meta{font-size:11px}
 body.has-tool-history #welcome:not([hidden]){height:auto!important;min-height:0!important;display:block!important}
 body.has-tool-history #welcome .welcome-hero{min-height:0!important;margin-bottom:14px!important}
 body.has-tool-history #welcome :where(.guide-grid,.feature-grid){margin-top:10px;gap:10px}
 body.has-tool-history #welcome :where(.section-heading,.welcome-caption){margin:12px 0 8px}
 body.has-tool-history #welcome :where(.welcome-bottom,.welcome-note){margin-top:12px}
 .reader-toolbar{flex-wrap:wrap}.reader-image-tools{min-width:0}
 .reader .reader-focus-button,.reader .reader-download-toggle{min-height:44px}
 .reader-pagebar .button{min-height:44px}
 .reader-pagebar{gap:6px}.page-jump input{min-height:44px}
 .book-card .favorite-button.icon-button{width:44px;height:44px}
 .filters :where(select,input){min-height:44px}
 :where(.welcome,.welcome-hero,.library-hero,.assistant-tool-card,dialog,.mobile-more-menu){backdrop-filter:none!important;-webkit-backdrop-filter:none!important}
 .mobile-keyboard-open :where(.assistant-workstation,.chat-workstation){height:var(--mobile-visible-height);min-height:0}
 .mobile-keyboard-open .dashboard .desk-sidebar{visibility:hidden;pointer-events:none}
 .mobile-keyboard-open body.has-tool-history :where(.shell,.main,.app-main){height:var(--mobile-visible-height)!important;min-height:0!important}
 .mobile-keyboard-open .composer-wrap{padding-bottom:8px}
 .mobile-keyboard-open .tool-history-button{bottom:10px}
}
@media screen and (max-width:380px){
 .reader .reader-download-toggle,.reader .reader-focus-button{padding-inline:5px}
 .reader-image-tools output{display:none}
 .reader-toolbar{gap:4px}
 dialog>.dialog-actions{padding-inline:12px}
}
@media screen and (max-width:720px) and (prefers-reduced-motion:reduce){
 *,*::before,*::after{scroll-behavior:auto!important;animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important}
}

@media screen and (orientation:landscape) and (max-height:500px) and (max-width:980px) and (pointer:coarse){:where(button,.button,.icon-button){min-height:44px}:where(input,select,textarea){font-size:16px!important}dialog{max-height:calc(var(--mobile-visible-height,100dvh) - 8px)}}

/* Native dialogs must use the visible viewport, not the area behind the keyboard.
   Authentication has its own full-screen scroll controller; leave it intact. */
@media screen and (max-width:720px){
 .assistant-hub-categories{display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr));overflow:visible!important;white-space:normal!important;width:100%}
 .assistant-hub-categories button{min-width:0;min-height:44px;white-space:normal;justify-content:center}
 #assistantHubPanel{padding-bottom:84px}
 #assistantHubPanel #commandFloatingOpen.is-docked{position:relative!important;inset:auto!important;transform:none!important;align-self:end;width:44px;height:44px;margin-left:auto;flex:0 0 44px;touch-action:auto}
}
@media screen and (max-width:720px), screen and (max-width:980px) and (max-height:500px) and (pointer:coarse){
 html body dialog[open]:not(#loginDialog){position:fixed;inset:auto;top:calc(var(--mobile-viewport-top,0px) + var(--mobile-visible-height,100dvh)/2);left:calc(var(--mobile-viewport-left,0px) + var(--mobile-visible-width,100vw)/2);transform:translate(-50%,-50%);margin:0;box-sizing:border-box;min-width:0;max-width:calc(var(--mobile-visible-width,100vw) - 16px)!important;max-height:calc(var(--mobile-visible-height,100dvh) - 16px)!important}
 /* Auto-height flex dialogs can collapse in WebKit. Simple forms use one scroller. */
 html body dialog[open]:not(#loginDialog):not(#profileDialog):has(>.dialog-body){display:block;overflow:auto;-webkit-overflow-scrolling:touch;scroll-padding-block:16px;touch-action:auto}
 html body dialog:not(#profileDialog)>.dialog-body{height:auto;max-height:none;min-height:0;overflow:visible}
 dialog :where(.field,.control,.dialog-head>div){min-width:0;overflow-wrap:anywhere}
 dialog :where(input,select,textarea){max-width:100%;box-sizing:border-box}
 dialog>.dialog-head{align-items:flex-start;flex-wrap:wrap}
 dialog>.dialog-head h2{overflow-wrap:anywhere}
 body.has-tool-history .mask{top:var(--mobile-viewport-top,0px);left:var(--mobile-viewport-left,0px);right:auto;bottom:auto;width:var(--mobile-visible-width,100vw);height:var(--mobile-visible-height,100dvh);box-sizing:border-box;padding:12px;overflow:auto}
 body.has-tool-history .mask>.modal{max-height:calc(var(--mobile-visible-height,100dvh) - 24px);box-sizing:border-box;overscroll-behavior:contain}
 .tool-history-sidebar{top:var(--mobile-viewport-top,0px);height:var(--mobile-visible-height,100dvh);box-sizing:border-box}
 body.has-tool-history :where(#msgs,.assistant-message,.message,.bubble){min-width:0;overflow-wrap:anywhere}
 body.has-tool-history :where(#msgs,.message,.bubble) pre{max-width:100%;overflow:auto;white-space:pre}
 body.has-tool-history :where(#msgs,.message,.bubble) table{display:block;max-width:100%;overflow:auto}
 .reader .reader-image-tools .tool-button,.reader .reader-image-tools select,.reader .reader-focus-button,.reader .reader-download-toggle,.reader .reader-pagebar button,.reader .reader-export-controls .button{min-height:44px}
 .reader .reader-image-tools .tool-button{min-width:44px}
 .reader .reader-image-tools{flex-wrap:wrap}
 .reader .reader-pagebar{flex-wrap:wrap;justify-content:space-between}
 .reader .reader-pagebar .page-jump{min-width:0}
 .reader .reader-download-panel{max-height:calc(var(--mobile-visible-height,100dvh)*.43)}
 .reader .reader-heading{min-width:0}.reader .reader-heading h2{overflow-wrap:anywhere}
 .cb-wrap :where(.cb-card,.cb-preview){min-width:0;padding:14px}
 .cb-wrap .cb-row{grid-template-columns:repeat(2,minmax(0,1fr))}
 .cb-wrap .cb-advanced summary{min-height:44px;display:flex;align-items:center;flex-wrap:wrap;gap:4px}
 /* Same-origin preparation tools resize with the parent, keeping their composer
    above the keyboard instead of leaving a fixed 100dvh iframe behind it. */
 .mobile-keyboard-open #assistantView:has(#assistantLessonDesignPanel:not([hidden])),
 .mobile-keyboard-open #assistantView:has(#assistantWorksheetPanel:not([hidden])){height:var(--mobile-visible-height)!important;min-height:0!important;position:fixed;top:var(--mobile-viewport-top,0px);left:var(--mobile-viewport-left,0px);width:var(--mobile-visible-width,100vw)}
 .mobile-keyboard-open body.textbook-reading #assistantTextbookFrame{inset:auto;top:var(--mobile-viewport-top,0px);left:var(--mobile-viewport-left,0px);width:var(--mobile-visible-width,100vw);height:var(--mobile-visible-height,100dvh)}
 /* Editing page numbers needs the form and pagebar, not the reading chrome.
    Fixed-height headers must not squeeze the pagebar behind the keyboard. */
 .mobile-keyboard-open .reader .reader-header,
 .mobile-keyboard-open .reader .reader-toolbar,
 .mobile-keyboard-open .reader .reader-foot{display:none}
 .mobile-keyboard-open .reader .reader-mobile-close{display:inline-flex}
 .mobile-keyboard-open .reader #btnPrev,.mobile-keyboard-open .reader #btnNext{display:none}
 .reader .reader-export-controls input,.reader .reader-export-controls select{min-height:44px}
}
