/* Full-game phone layout. The catalog's live demos keep their original styling. */
@media (max-width: 720px) {
  body:not(.preview) { min-width: 0; padding-bottom: env(safe-area-inset-bottom); }
  body:not(.preview) :is(.arcade-toolbar, header) { gap: 4px 6px; padding: 6px 8px; flex-wrap: wrap; }
  body:not(.preview) :is(.arcade-toolbar, header) a { width: auto; min-height: 44px; display: inline-flex; align-items: center; }
  body:not(.preview) :is(.arcade-toolbar, header) button { flex: 0 1 auto; min-height: 44px; padding: 4px 8px; font-size: .76rem; }
  body:not(.preview) .arcade-toolbar label { font-size: .75rem; }
  body:not(.preview) .journey-strip { padding: 4px 8px; gap: 4px 8px; font-size: .75rem; }
  body:not(.preview) .journey-strip label { width: auto; }
  body:not(.preview) #hud { gap: 5px 8px; padding: 4px 8px; }
  body:not(.preview) :is(#mission, main) { min-width: 0; }
  body:not(.preview) :is(.mission-intro, .dojo-intro, .challenge, .question-panel) { padding: 10px; margin-block: 6px; }
  body:not(.preview) :is(.mission-intro, .dojo-intro) h1 { font-size: clamp(1.25rem, 5vw, 1.65rem); margin-block: 3px; }
  body:not(.preview) :is(.mission-intro, .dojo-intro) p { margin-block: 5px; }
  body:not(.preview) :is(.mission-hud, .fight-hud) { padding: 5px 8px; gap: 5px; }
  body:not(.preview) #arena { min-height: 0; padding: 8px; }
  body:not(.preview) .board-grid { width: min(100%, 230px); margin-inline: auto; }
  body:not(.preview) :is(#choices, #dojo-answers, .answers-container) { gap: 6px; }
  body:not(.preview) :is(#choices, #dojo-answers) button { min-height: 44px; padding: 6px 8px; }
  body:not(.preview) #game-container #start-screen { order: -1; padding: 10px !important; }
  body:not(.preview) #start-screen .game-title { font-size: 25px !important; }
  body:not(.preview) #start-screen .subtitle { font-size: 14px !important; margin-block: 5px !important; }
  body:not(.preview) #start-screen .difficulty-panel { padding: 4px; margin-block: 5px; }
  body:not(.preview) #start-screen .diff-btn { min-height: 44px; padding: 5px 7px; }
  body:not(.preview) #start-screen .primary-btn { min-height: 48px; padding: 7px 16px !important; font-size: 1rem !important; }
  body:not(.preview) #mobile-controls { padding: 4px 8px; }
  body:not(.preview) .action-btn { min-height: 48px; min-width: 48px; }
  body:not(.preview) :is(.code-panel, #question) { overflow-wrap: anywhere; }
}
@media (max-height: 500px) and (orientation: landscape) and (max-width: 980px) {
  body:not(.preview) #game-container > canvas { max-height: 57svh; object-fit: contain; }
}

/* Math Panda keeps the course at its current scroll position during questions and stage transitions. */
@media (max-width: 720px), (max-width: 980px) and (max-height: 500px) {
  body:not(.preview):has(#course-status) :is(#math-screen, #stage-complete):not(.hidden) {
    position: fixed !important;
    inset: 0 !important;
    z-index: 300;
    width: 100%;
    height: 100%;
    max-height: 100dvh;
    box-sizing: border-box;
    display: flex;
    align-items: safe center;
    justify-content: safe center;
    overflow: auto !important;
    overscroll-behavior: contain;
    padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom)) !important;
    background: #07182fe8 !important;
  }
  body:not(.preview):has(#course-status) #math-ui {
    flex: 0 1 560px;
    min-width: 0;
    margin-block: auto;
    max-height: none;
    overflow: visible;
  }
  body:not(.preview):has(#course-status) #math-screen #question {
    margin: 0 0 8px;
    padding: 4px !important;
    font-size: clamp(20px, 6vw, 28px) !important;
  }
  body:not(.preview):has(#course-status) #math-screen .answer-btn {
    min-height: 46px;
    padding: 5px 10px !important;
  }
}

@media (max-width: 720px), (max-width: 980px) and (max-height: 500px) {
  body:not(.preview):has(#course-status) #stage-complete:not(.hidden) {
    flex-direction: column;
    gap: 12px;
  }
  body:not(.preview) #stage-complete > * { flex-shrink: 0; max-width: 100%; }
  body:not(.preview) #next-course-stage {
    min-height: 48px;
    white-space: normal;
    touch-action: manipulation;
  }
}