/* Shared phone layout for the standalone math demonstrations. */
@media (max-width: 980px) {
  html,
  body {
    width: 100%;
    min-width: 0;
    overflow-x: hidden !important;
  }

  .nav {
    height: 72px !important;
    min-height: 72px;
    padding: 8px 12px !important;
  }

  .nav > :first-child,
  .brand {
    min-width: 0;
    max-width: 100%;
  }

  .nav h1,
  .brand h1 {
    max-width: calc(100vw - 92px);
    overflow: hidden;
    font-size: 17px !important;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .nav p,
  .brand p {
    display: none;
  }

  .layout,
  .app-grid {
    display: block !important;
    width: 100%;
    height: auto !important;
    min-width: 0;
    padding-top: 72px !important;
  }

  .sidebar {
    width: 100%;
    height: auto !important;
    max-height: none !important;
    min-width: 0;
  }

  .stage {
    position: relative !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    width: 100%;
    height: auto !important;
    min-height: 0 !important;
    padding: 16px;
    overflow: visible !important;
  }

  .stage > * {
    min-width: 0;
    max-width: 100%;
  }

  .stage .hud,
  .stage .lab,
  .stage .canvas-wrap,
  .stage .right-panel,
  .stage .math-card,
  .stage .legend,
  .stage .control,
  .stage .control-panel {
    position: relative !important;
    inset: auto !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    left: auto !important;
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    transform: none !important;
  }

  .stage .hud,
  .stage .right-panel,
  .stage .math-card,
  .stage .legend,
  .stage .control,
  .stage .control-panel {
    height: auto !important;
  }

  .stage .hud {
    padding: 14px 16px;
  }

  .stage .note {
    display: none !important;
  }

  .stage .lab,
  .stage .canvas-wrap {
    min-height: 340px;
    aspect-ratio: 5 / 4;
    overflow: hidden !important;
  }

  .stage .lab svg,
  .stage .canvas-wrap canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
  }

  .stage .right-panel {
    padding: 16px;
    overflow: visible !important;
  }

  .stage .math-card,
  .stage .legend {
    padding: 14px 16px;
  }

  .stage .control,
  .stage .control-panel {
    z-index: 12;
    padding: 14px;
  }

  .stage .control-grid {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 14px !important;
  }

  .stage .control label,
  .stage .control-panel label,
  .stage input[type="range"] {
    min-width: 0;
    width: 100%;
  }

  .stage .toast {
    position: relative !important;
    inset: auto !important;
    width: 100% !important;
    max-width: none !important;
    text-align: center;
    transform: none !important;
  }

  .stage .toast.show {
    transform: none !important;
  }

  .stage .quiz,
  .stage .quiz-panel {
    position: relative !important;
    inset: auto !important;
    width: 100% !important;
    max-width: none !important;
    max-height: none !important;
    overflow: visible !important;
    z-index: 20 !important;
    transform: none !important;
  }

  .stage .quiz.hide,
  .stage .quiz-panel.hidden-panel {
    display: none !important;
  }

  .stage .fab,
  .stage .quiz-fab {
    position: relative !important;
    inset: auto !important;
    margin: 0 0 0 auto;
    flex: 0 0 56px;
    width: 56px;
    height: 56px;
  }

  .stage .fab.show,
  .stage .quiz-fab.show {
    display: grid;
    place-items: center;
  }

  /* The train page uses two sibling layers instead of a wrapped scene. */
  .stage > #canvas-container,
  .stage > #svg-overlay {
    grid-area: 2 / 1;
    width: 100% !important;
    height: 360px !important;
    min-height: 360px;
  }

  .stage > #canvas-container {
    position: relative !important;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 24px;
  }

  .stage > #svg-overlay {
    position: relative !important;
    inset: auto !important;
    z-index: 5;
    pointer-events: none;
  }

  .stage > .absolute:not(.control-panel) {
    position: relative !important;
    inset: auto !important;
    grid-area: 1 / 1;
    width: 100% !important;
    max-width: none !important;
  }

  .stage > #canvas-container ~ .control-panel {
    grid-row: 3;
  }

  .stage > #canvas-container ~ .quiz-fab {
    grid-row: 4;
  }

  .watermark {
    display: none !important;
  }
}

@media (max-width: 420px) {
  .stage {
    padding: 12px;
  }

  .stage .lab,
  .stage .canvas-wrap,
  .stage > #canvas-container,
  .stage > #svg-overlay {
    height: 320px !important;
    min-height: 320px;
  }
}
