/* iPhone classroom refinements: preserve all whiteboard actions and accessibility. */
@media(max-width:800px){
  html,body{max-width:100%;overflow-x:hidden!important}
  #classroom.layout{min-width:0!important;max-width:100%!important;gap:7px!important}
  .board-panel,.board-area{min-width:0!important;max-width:100%!important}
  .bottom-bar{
    width:100%!important;min-width:0!important;max-width:100%!important;
    display:flex!important;flex-direction:column!important;
    align-items:stretch!important;justify-content:flex-start!important;
    gap:8px!important;overflow:visible!important;
    padding:9px 7px!important;margin:0!important;
    border-radius:12px!important;
  }
  .bottom-bar .bottom-left,
  .bottom-bar .bottom-right{
    display:flex!important;flex-direction:row!important;align-items:center!important;
    justify-content:flex-start!important;flex-wrap:nowrap!important;
    width:100%!important;min-width:0!important;max-width:100%!important;
    overflow-x:auto!important;overflow-y:hidden!important;
    -webkit-overflow-scrolling:touch;overscroll-behavior-x:contain;
    gap:6px!important;scrollbar-width:thin;
    padding:4px 2px 8px!important;
  }
  .bottom-bar .bottom-left>*,
  .bottom-bar .bottom-right>*{flex:0 0 auto!important;min-width:max-content}
  .bottom-bar button,.bottom-bar .bb-lucide-tool{
    display:inline-flex!important;align-items:center!important;
    justify-content:center!important;gap:6px!important;
    flex:0 0 auto!important;min-width:max-content!important;
    min-height:42px!important;padding:9px 11px!important;
    font-size:12px!important;white-space:nowrap!important;
    border-radius:11px!important;line-height:1.2!important;
  }
  .bottom-bar .bb-lucide-tool[hidden],
  .bottom-bar button[hidden]{display:none!important}
  .bottom-bar .bb-lucide-tool svg{width:18px!important;height:18px!important;
    flex:0 0 18px!important}
  .bottom-bar .bb-tool-label{font-size:12px!important;white-space:nowrap!important}
  .bottom-bar .shape-menu-wrap{position:relative;display:inline-flex!important}
  .bottom-bar .bottom-right label{white-space:nowrap!important;font-size:12px!important}
  .bottom-bar .bottom-right select{flex:0 0 auto!important;min-width:135px!important;
    width:auto!important;max-width:170px!important;min-height:42px!important;
    font-size:14px!important}
  #emojiReactions{display:inline-flex!important;flex-wrap:nowrap!important;
    width:auto!important;min-width:max-content!important;gap:5px!important}
  #emojiReactions button{min-width:42px!important;padding:8px!important}
  /* Dock palette to the far right above the board; never in its center. */
  #paletteToggle{
    position:fixed!important;inset:auto 10px auto auto!important;
    top:calc(222px + env(safe-area-inset-top))!important;
    z-index:2147482900!important;width:46px!important;height:46px!important;
    min-width:46px!important;min-height:46px!important;
    display:inline-flex!important;align-items:center!important;justify-content:center!important;
    padding:8px!important;border:1px solid #d6cbf3!important;
    border-radius:13px!important;background:#6040cb!important;color:#fff!important;
    box-shadow:0 8px 20px #34236b35!important;font-size:0!important;
  }
  #paletteToggle .bb-tool-label{display:none!important}
  #paletteToggle svg{width:23px!important;height:23px!important;flex:0 0 23px!important}
  #boardPalette:not([hidden]){
    position:fixed!important;left:auto!important;right:8px!important;
    width:min(190px,49vw)!important;max-width:min(190px,49vw)!important;
    top:calc(275px + env(safe-area-inset-top))!important;
    bottom:auto!important;max-height:55dvh!important;overflow-y:auto!important;
    padding:12px 9px!important;z-index:2147483000!important;
    background:#fff!important;border:1px solid #d9cdf3!important;
    border-radius:15px!important;box-shadow:0 10px 38px #291d4f3f!important;
  }
  #boardPalette[hidden]{display:none!important}
  #boardPalette .palette-control{align-items:stretch!important}
  #boardPalette label{font-size:11px!important}
  #boardPalette select{width:100%!important;max-width:100%!important;
    min-width:0!important;font-size:12px!important}
  #paletteSwatches{grid-template-columns:repeat(4,minmax(0,1fr))!important}
  .class-nav{max-width:100%!important}
  .lesson-heading{min-width:0!important;overflow-wrap:normal!important}
}
@media(max-width:390px){
  .bottom-bar .bottom-left,.bottom-bar .bottom-right{gap:5px!important}
  .bottom-bar button,.bottom-bar .bb-lucide-tool{padding:8px 9px!important}
  #paletteToggle{right:7px!important;width:43px!important;height:43px!important}
}
@media(prefers-reduced-motion:reduce){
 .bottom-bar .bottom-left,.bottom-bar .bottom-right{scroll-behavior:auto!important}
}

/* Final iPhone classroom layout: compact header, one-row modes & toolbar, usable board. */
@media(max-width:800px){
 html,body{height:auto!important;min-height:100%!important;overflow-x:hidden!important;overflow-y:auto!important}
 body{display:block!important;min-height:100dvh!important}
 body>header{
   display:grid!important;grid-template-columns:minmax(0,1fr) auto!important;
   gap:7px 10px!important;align-items:center!important;
   height:auto!important;min-height:0!important;padding:12px 14px!important;
   position:relative!important;z-index:2!important;
 }
 body>header .brand{grid-column:1;grid-row:1;min-width:0!important}
 body>header .brand img{max-width:210px!important;width:100%!important;height:auto!important}
 body>header>a[href*="portal"]{grid-column:2;grid-row:1;white-space:nowrap!important;
   font-size:12px!important;text-decoration:none!important}
 body>header>.pill{grid-column:1/-1;grid-row:2;justify-self:start;
   max-width:100%!important;padding:6px 9px!important;font-size:11px!important;
   white-space:normal!important;line-height:1.25!important}
 main{height:auto!important;min-height:0!important;display:block!important;
   padding:0 8px 18px!important;width:100%!important;max-width:100%!important}
 .lesson-heading{display:flex!important;align-items:center!important;justify-content:space-between!important;
   gap:8px!important;flex-wrap:nowrap!important;padding:8px 2px!important;min-height:46px!important;
   margin:0!important;width:100%!important}
 .lesson-heading h1{font-size:clamp(14px,4vw,17px)!important;line-height:1.25!important;
   min-width:0!important;max-width:calc(100% - 95px)!important;white-space:normal!important;
   overflow-wrap:normal!important}
 #classTimerWrap{position:static!important;flex:0 0 auto!important;white-space:nowrap!important;
   font-size:16px!important;margin:0!important}
 #bbHeaderTimer{font-size:18px!important}
 #status{display:block!important;position:static!important;max-width:100%!important;
   min-height:0!important;margin:2px 0 7px!important;padding:5px 7px!important;
   white-space:normal!important;overflow-wrap:break-word!important;
   font-size:12px!important;line-height:1.35!important}
 #classroom.layout,#classroom.layout.whiteboard-focus{
   display:grid!important;grid-template-columns:minmax(0,1fr)!important;
   grid-template-rows:auto auto auto auto!important;
   height:auto!important;min-height:0!important;max-height:none!important;
   align-items:stretch!important;gap:7px!important;padding:7px!important;
   margin:0!important;
 }
 #classroom.layout.hide{display:none!important}
 #classroom .class-nav{grid-column:1!important;grid-row:1!important;
   display:flex!important;flex-direction:row!important;flex-wrap:nowrap!important;
   min-width:0!important;width:100%!important;max-width:100%!important;
   gap:5px!important;overflow-x:auto!important;overflow-y:hidden!important;
   padding:4px 0 8px!important;scrollbar-width:thin!important;
   -webkit-overflow-scrolling:touch!important}
 #classroom .class-nav .nav-item{display:inline-flex!important;align-items:center!important;
   justify-content:center!important;flex:0 0 auto!important;min-width:max-content!important;
   min-height:40px!important;white-space:nowrap!important;font-size:12px!important;
   padding:8px 11px!important;line-height:1.2!important}
 #classroom .class-nav .nav-heading,#classroom .class-nav .nav-note{display:none!important}
 #classroom .bottom-bar{grid-column:1!important;grid-row:2!important;
   order:initial!important;z-index:3!important}
 #classroom .board-panel{grid-column:1!important;grid-row:3!important;display:flex!important;
   flex-direction:column!important;min-width:0!important;
   width:100%!important;min-height:0!important;height:auto!important;
   padding:5px!important;border:1px solid #dddaf1!important;border-radius:13px!important;
   background:#fff!important}
 #classroom .board-panel .board-heading{min-height:0!important;height:auto!important;
   margin:0 0 3px!important}
 #classroom .board-panel .board-heading h2{font-size:12px!important;line-height:1.25!important}
 #classroom .board-panel .tools{display:flex!important;flex-wrap:nowrap!important;
   gap:5px!important;overflow-x:auto!important;overflow-y:hidden!important;
   min-width:0!important;width:100%!important;max-width:100%!important;
   max-height:45px!important;padding:3px 2px 6px!important}
 #classroom .board-panel .tools button:not([hidden]){flex:0 0 auto!important;white-space:nowrap!important}
 #classroom .board-panel #pages{max-height:40px!important;
   min-height:31px!important;overflow-x:auto!important;overflow-y:hidden!important;
   width:100%!important;flex-wrap:nowrap!important;display:flex!important}
 #classroom .board-area{position:relative!important;flex:0 0 auto!important;
   display:block!important;width:100%!important;min-width:0!important;
   height:clamp(300px,43dvh,450px)!important;
   min-height:300px!important;max-height:450px!important;overflow:hidden!important;
   background:#fff!important;border:1px solid #e2def2!important;
   border-radius:11px!important}
 #classroom .board-area #board{display:block!important;width:100%!important;
   height:100%!important;min-height:0!important;max-height:100%!important;
   border:0!important;border-radius:11px!important;
   object-fit:fill!important;touch-action:none}
 #classroom .right-rail{grid-column:1!important;grid-row:4!important;min-width:0!important;
   width:100%!important;max-width:100%!important;display:flex!important;
   flex-direction:column!important;gap:8px!important;overflow:visible!important}
 #paletteToggle{position:absolute!important;top:9px!important;right:9px!important;
   bottom:auto!important;left:auto!important;z-index:20!important;
   width:42px!important;height:42px!important;min-width:42px!important;min-height:42px!important}
 #boardPalette:not([hidden]){top:auto;left:auto!important;right:8px!important;
   width:min(190px,49vw)!important;max-width:min(190px,49vw)!important}
}

/* Unified compact classroom on phones: desktop-style tools, sized for touch. */
@media(max-width:800px){
 #classroom.layout,#classroom.layout.whiteboard-focus{
   padding:6px!important;gap:6px!important;
   grid-template-columns:minmax(0,1fr)!important;
   grid-template-rows:auto auto auto auto!important;
 }
 /* Keep modes as one accessible strip, with no wrapping or off-screen overlap. */
 #classroom .class-nav{
   gap:5px!important;padding:5px 4px!important;min-height:0!important;
   scroll-padding-inline:8px;overscroll-behavior-x:contain;
 }
 #classroom .class-nav .nav-item.bb-class-nav-lucide{
   flex:0 0 auto!important;min-height:40px!important;
   padding:7px 10px!important;font-size:12px!important;
   flex-direction:row!important;text-align:center!important;
   border-radius:10px!important;
 }
 #classroom .class-nav .nav-item svg{width:17px!important;height:17px!important}
 /* One slim horizontally scrollable bottom toolbar, rather than two tall rows. */
 #classroom .bottom-bar{
   display:flex!important;flex-direction:row!important;align-items:center!important;
   justify-content:flex-start!important;flex-wrap:nowrap!important;
   gap:8px!important;padding:6px!important;
   min-height:0!important;width:100%!important;
   overflow-x:auto!important;overflow-y:hidden!important;
   -webkit-overflow-scrolling:touch;scrollbar-width:thin;
 }
 #classroom .bottom-bar .bottom-left,
 #classroom .bottom-bar .bottom-right{
   flex:0 0 auto!important;width:max-content!important;max-width:none!important;
   min-width:max-content!important;display:flex!important;
   flex-direction:row!important;flex-wrap:nowrap!important;
   overflow:visible!important;gap:5px!important;padding:0!important;
   align-items:center!important;
 }
 #classroom .bottom-bar button,
 #classroom .bottom-bar .bb-lucide-tool{
   padding:8px 10px!important;min-height:40px!important;
   border-radius:10px!important;font-size:12px!important;
 }
 #classroom .bottom-bar .bottom-right select{min-height:40px!important}
 #classroom .board-panel{
   padding:8px!important;gap:5px!important;
   border-radius:14px!important;
 }
 #classroom .board-panel .board-heading{margin:0!important}
 #classroom .board-panel .board-heading h2{
   font-size:clamp(13px,3.6vw,16px)!important;
   line-height:1.35!important;
 }
 /* MacBook-style compact secondary toolbar, independently swipeable on iPhone. */
 #classroom .board-panel .tools,
 #classroom .board-panel #pages{
   gap:5px!important;padding:4px 1px 6px!important;
   max-height:none!important;height:auto!important;
   min-height:40px!important;align-items:center!important;
   scrollbar-width:thin;-webkit-overflow-scrolling:touch;
   overflow-x:auto!important;overflow-y:hidden!important;
 }
 #classroom .board-panel .tools button,
 #classroom .board-panel #pages button{
   min-height:36px!important;padding:7px 9px!important;
   font-size:12px!important;flex-shrink:0!important;
   border-radius:9px!important;
 }
 #classroom .board-panel #pages label{flex:0 0 auto!important;white-space:nowrap!important}
 #classroom .board-panel #pageSelect{
   flex:0 0 auto!important;min-width:110px!important;
   width:115px!important;max-width:115px!important;
   min-height:36px!important;
 }
 /* Make the board the main visual element without a huge empty scroll. */
 #classroom .board-area{
   height:clamp(280px,43svh,420px)!important;
   min-height:280px!important;max-height:420px!important;
   border-radius:10px!important;
 }
 /* Mini-map remains usable but no longer takes up a large chunk of the board. */
 #classroom .board-area #navigatorStrip{
   position:absolute!important;right:6px!important;bottom:6px!important;
   left:auto!important;top:auto!important;
   width:auto!important;max-width:100px!important;
   padding:3px!important;gap:2px!important;
   border-radius:9px!important;
 }
 #classroom .board-area #miniMap{
   width:84px!important;height:51px!important;
   max-width:84px!important;max-height:51px!important;
 }
 #classroom .board-area #zoomReadout{font-size:10px!important;line-height:1.1!important}
 #classroom .board-area #navigatorStrip .muted{display:none!important}
 /* Whiteboard controls stay in their desktop order; video follows directly. */
 #classroom .right-rail{gap:7px!important}
 #classroom .right-rail .video-panel{padding:10px!important;min-width:0!important}
 #classroom .right-rail #dailyFrame{
   width:100%!important;min-height:185px!important;
   height:clamp(185px,28svh,270px)!important;
 }
}
