/* QA focused mobile activity containment: no global scroll locking, no data or auth changes. */
@media (max-width:720px), (max-height:520px) and (orientation: landscape) {
  #fun.saQaActivityOpen:not(.sa78ReadActive) #funGrid,
  #fun.saQaActivityOpen:not(.sa78ReadActive) #v25FunSummary {display:none!important}
  #fun.saQaActivityOpen:not(.sa78ReadActive) .kidActivityTop {display:none!important}
  #fun.saQaActivityOpen:not(.sa78ReadActive) {padding:7px 9px 105px!important;max-width:100%!important;min-width:0!important}
  #fun.saQaActivityOpen:not(.sa78ReadActive)>.head {margin:0 0 7px!important;min-height:0!important}
  #fun.saQaActivityOpen:not(.sa78ReadActive)>.head h2 {font-size:19px!important;line-height:1.3!important}
  #fun.saQaActivityOpen:not(.sa78ReadActive) #activityArea>.activitypanel {
      max-height:var(--sa-qa-available,65dvh)!important;overflow-y:auto!important;
      overflow-x:hidden!important;overscroll-behavior:contain;min-width:0!important;
      padding:10px!important;margin:0!important;
  }
  #fun.saQaActivityOpen:not(.sa78ReadActive) .activitypanel>.head {margin:0 0 6px!important}
  #fun.saQaActivityOpen:not(.sa78ReadActive) .activitypanel canvas {max-height:min(37dvh,310px);max-width:100%!important;object-fit:contain}
  #fun.saQaActivityOpen:not(.sa78ReadActive) .activitypanel input {font-size:max(16px,1em)!important;min-width:0!important;max-width:100%!important}
  #fun.saQaActivityOpen:not(.sa78ReadActive) .activitypanel button {min-height:42px!important}
  #fun.saQaActivityOpen #activityArea .saQaBack {display:inline-flex;justify-content:center;align-items:center;gap:6px;
    margin:0 0 6px!important;min-height:42px!important;padding:6px 13px!important;background:#e8f3ee!important;
    color:#155a45!important;border:1px solid #a9d8c6!important;border-radius:12px!important;font-size:14px!important}
  /* Read-abacus: preserve the existing responsive board; avoid clipped feedback on keyboard opening. */
  #fun.sa78ReadActive:focus-within .sa78ReadFeedback {overflow:visible!important;max-height:none!important}
}
@media (max-height:520px) and (orientation:landscape) {
  #fun.saQaActivityOpen:not(.sa78ReadActive) .activitypanel canvas{max-height:28dvh!important}
}


/* 29 Oct 2026 - activity-navigation fit. Scope: student game launcher and
   conservative student/trainer page headers. Never remove a gameplay control. */
@media (max-width:720px), (max-height:520px) and (orientation:landscape) {
  /* R27 makes an activity its own page. Keep that page in the visible viewport,
     above the ordinary app, and BELOW the persistent bottom navigation. */
  body.r57-app-mode #app>section#fun.safeR27ActivityMode,
  #fun.safeR27ActivityMode,
  #fun.safeR27ActivityMode.saQaActivityOpen,
  #fun.safeR27ActivityMode.sa78ReadActive {
    position:fixed!important;
    inset:0 0 0 0!important;
    z-index:480!important;
    width:100vw!important;
    max-width:100vw!important;
    height:100dvh!important;
    max-height:100dvh!important;
    min-height:0!important;
    margin:0!important;
    padding:0!important;
    background:#f9f5ee!important;
    overflow:hidden!important;
    overscroll-behavior:contain;
  }
  #fun.safeR27ActivityMode #activityArea,
  #fun.safeR27ActivityMode.sa78ReadActive #activityArea {
    display:block!important;
    width:100%!important;
    height:100%!important;
    max-height:100%!important;
    min-height:0!important;
    padding:0 9px max(88px,calc(78px + env(safe-area-inset-bottom,0px)))!important;
    margin:0!important;
    overflow-x:hidden!important;
    overflow-y:auto!important;
    overscroll-behavior-y:contain;
    -webkit-overflow-scrolling:touch;
    box-sizing:border-box!important;
    scroll-padding-top:62px;
  }
  #fun.safeR27ActivityMode .safeR27ActivityBar {
    position:sticky!important;
    top:0!important;
    z-index:6!important;
    margin:0 -9px 7px!important;
    padding:7px 12px!important;
    min-height:50px!important;
    box-sizing:border-box!important;
  }
  /* Remove the historic contradictory 'min-height:100dvh' vs 'max-height:65dvh'
     that trapped the exercise in a separately scrolling card. */
  #fun.safeR27ActivityMode #activityArea>.activitypanel,
  #fun.safeR27ActivityMode.saQaActivityOpen:not(.sa78ReadActive) #activityArea>.activitypanel,
  #fun.safeR27ActivityMode.sa78ReadActive #activityArea>.activitypanel {
    position:relative!important;
    min-height:0!important;
    height:auto!important;
    max-height:none!important;
    padding:10px!important;
    margin:0!important;
    overflow:visible!important;
    box-sizing:border-box!important;
    border-radius:16px!important;
  }
  #fun.safeR27ActivityMode .activitypanel>.head {margin-bottom:6px!important;gap:6px!important;flex-wrap:wrap!important}
  #fun.safeR27ActivityMode .activitypanel>.head h3 {font-size:clamp(16px,4.7vw,19px)!important}
  #fun.safeR27ActivityMode .activitypanel>.note {margin:5px 0!important;padding:7px 9px!important;font-size:12px!important;line-height:1.42!important}
  #fun.safeR27ActivityMode .activitypanel .feedback {min-height:24px!important;margin-top:5px!important}
  #fun.safeR27ActivityMode .activitypanel button {touch-action:manipulation;min-height:44px!important}
  #fun.safeR27ActivityMode .activitypanel .choices {display:flex;flex-wrap:wrap;gap:7px!important}
  #fun.safeR27ActivityMode .activitypanel .choices button {flex:1 1 95px!important;min-width:0!important}
  /* Keep the read-abacus SVG, form and status in normal flow: nothing clipped. */
  #fun.safeR27ActivityMode.sa78ReadActive .sa78ReadLayout {min-height:0!important;height:auto!important}
  #fun.safeR27ActivityMode.sa78ReadActive .sa78ReadBoard {min-height:150px!important;height:min(42dvh,300px)!important;flex:0 0 auto!important}
  #fun.safeR27ActivityMode.sa78ReadActive .sa78ReadFeedback {max-height:none!important;overflow:visible!important}
  /* Differences: both trainer-supplied images visible immediately, not stacked
     two screens apart. Hit detection and trainer-defined points remain unchanged. */
  #fun.safeR27ActivityMode .diffImageGrid {
    display:grid!important;
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    align-items:start!important;
    gap:6px!important;
    margin:8px 0!important;
  }
  #fun.safeR27ActivityMode .diffImageWrap {min-width:0!important;min-height:0!important;border-radius:10px!important;overflow:hidden!important}
  #fun.safeR27ActivityMode .diffImageWrap img {width:100%!important;height:auto!important;max-height:42dvh!important;object-fit:contain!important;display:block!important}
  /* Make drawing surfaces proportional. Do not crop/reposition a Canvas whose
     pointer code maps CSS coordinates back to intrinsic drawing coordinates. */
  #fun.safeR27ActivityMode .canvasPaint,
  #fun.safeR27ActivityMode #paintCanvas {
    display:block!important;
    width:min(100%,calc(40dvh * 600 / 340))!important;
    max-width:100%!important;
    height:auto!important;
    max-height:none!important;
    object-fit:fill!important;
    margin:5px auto!important;
  }
  #fun.safeR27ActivityMode .palette {gap:5px!important;margin-top:5px!important}
  #fun.safeR27ActivityMode .palette .swatch {width:42px!important;height:42px!important;min-width:42px!important;min-height:42px!important}
  #fun.safeR27ActivityMode .mazeCanvas {width:auto!important;height:auto!important;max-width:100%!important;max-height:42dvh!important;object-fit:fill!important;margin:6px auto!important}
  #fun.safeR27ActivityMode .mazeShell {margin:6px auto!important;max-height:none!important;overflow:visible!important}
  #fun.safeR27ActivityMode .pathBoard {max-height:none!important;overflow:hidden!important}
  #fun.safeR27ActivityMode .flashstage,
  #fun.safeR27ActivityMode .v17FlashStage {
    min-height:clamp(110px,25dvh,230px)!important;
    padding:7px!important;
    margin:6px 0!important;
  }
  #fun.safeR27ActivityMode .ab-mini {max-height:none!important;overflow-x:auto!important;overflow-y:visible!important}
  #fun.safeR27ActivityMode textarea {max-height:none!important;resize:vertical!important}
  /* Other student/trainer routes: don't lose content under bottom dock; keep
     the title and first action near the top, without hiding fields or panels. */
  #app>section.wrap:not(.hidden):not(#fun):not(#game):not(#abacus) {
    overflow-x:clip!important;
    overflow-y:visible!important;
    padding-bottom:max(92px,calc(85px + env(safe-area-inset-bottom,0px)))!important;
  }
  #app>section.wrap:not(.hidden):not(#fun):not(#game):not(#abacus)>.head {
    margin-bottom:9px!important;
    gap:8px!important;
    flex-wrap:wrap!important;
  }
  #app>section.wrap:not(.hidden):not(#fun):not(#game):not(#abacus)>.head h2 {font-size:clamp(18px,5vw,23px)!important;line-height:1.25!important}
  #app>section.wrap .card,#app>section.wrap .sectionbox {min-width:0;max-width:100%;box-sizing:border-box}
}
@media (max-width:355px) {
  #fun.safeR27ActivityMode .diffImageGrid{gap:4px!important}
  #fun.safeR27ActivityMode .diffImageWrap{border-width:1px!important}
  #fun.safeR27ActivityMode .activitypanel{padding:7px!important}
}
