/* 手机适配
   - 竖屏窄屏：侧边栏改为左侧抽屉，顶部显示细顶栏
   - 横屏手机：侧边栏常驻，宽度压缩 */
.topbar, .scrim, .learn-top, .learn-scrim { display: none; }

@media (orientation: portrait) and (max-width: 900px) {
  :root { --top-h: 48px; }
  .topbar { display: flex; align-items: center; gap: 10px; position: fixed; inset: 0 0 auto 0; height: var(--top-h); padding: 0 8px; background: var(--paper); border-bottom: 1px solid var(--line); z-index: 20; }
  .topbar-btn { width: 36px; height: 36px; border: 1px solid var(--line-2); border-radius: 6px; display: flex; align-items: center; justify-content: center; }
  .topbar-btn svg { width: 16px; height: 16px; }
  .topbar-name { font-size: 15px; font-weight: 700; letter-spacing: .04em; }

  .side { width: min(82vw, 300px); transform: translateX(-100%); transition: transform .2s; z-index: 70; }
  /* 侧边栏大类标题：触屏点击区域至少 44px */
  .nav-title { min-height: 44px; font-size: 12px; }
  .nav-chev { width: 14px; height: 14px; }
  body.drawer-open .side { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 60; background: rgba(10,10,10,.45); opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.drawer-open .scrim { opacity: 1; pointer-events: auto; }

  .main { inset: var(--top-h) 0 0 0; }
  .page { padding: 20px 16px 48px; }
  h1 { font-size: 28px; }
  .lead { font-size: 14px; }

  .hero { gap: 20px; padding-bottom: 24px; }
  .hero-stats b { font-size: 22px; }
  .hero-stats div { padding: 12px; }
  .grid, .gl-grid, .gl-row, .lib-grid, .guide { grid-template-columns: 1fr; gap: 16px; }
  .gl-big .gl-img { aspect-ratio: 4 / 3; }

  .lab-head { flex-direction: column; align-items: flex-start; }
  .lab-head .actions { justify-content: flex-start; }
  .lab, .below, .rt-layout, .cp-layout { grid-template-columns: 1fr; }
  .lab-ab-grid { grid-template-columns: 1fr; }
  .lab-ab-bar { gap: 8px; }
  .lab-ab-tip { flex: 1 1 100%; }
  /* 地平线把手：触屏加大易点 */
  .hl-handle { width: 60px; height: 34px; margin: -17px 0 0 -30px; border-radius: 17px; }

  /* 学习进度：窄屏下进度环与数字上下堆叠，章节单列 */
  .prog-top { flex-direction: column; align-items: flex-start; gap: 16px; padding: 18px; }
  .prog-ch-list { grid-template-columns: 1fr; }
  .controls, .rt-right, .cp-right { position: static; max-height: none; }
  .readouts { grid-template-columns: repeat(2, 1fr); }
  .readout { border-right: none; border-top: 1px solid var(--line); }
  .stage-bar { flex-wrap: wrap; }
  .stage-tools { flex: 1 1 100%; justify-content: flex-start; }
  .loupe { display: none !important; }

  /* 手机端固定画面：#stage 被 JS 提到 .lab 顶部，这里把它钉在滚动区顶端。
     滚动下方控件时画面始终可见，调参即时看效果。高度上限由 JS 按比例设 max-width 控制。 */
  .stage.stage-pinned {
    position: sticky; top: 0; z-index: 6;
    margin: 0 auto 14px; width: 100%;
    border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
    background: #111; box-shadow: 0 2px 10px rgba(0,0,0,.18);
  }

  .learn { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .learn-top { display: flex; align-items: center; gap: 10px; height: var(--top-h); padding: 0 8px; background: var(--paper); border-bottom: 1px solid var(--line); }
  .learn-top-count { margin-left: auto; padding-right: 6px; font-size: 11px; color: var(--ink-3); font-family: var(--num); }
  .learn-side { position: fixed; inset: 0 auto 0 0; width: min(86vw, 340px); z-index: 70; border-right: 1px solid var(--line); border-bottom: none; transform: translateX(-100%); transition: transform .2s; }
  .learn.side-open .learn-side { transform: none; }
  .learn-scrim { display: block; position: fixed; inset: 0; z-index: 60; background: rgba(10,10,10,.45); opacity: 0; pointer-events: none; transition: opacity .2s; }
  .learn.side-open .learn-scrim { opacity: 1; pointer-events: auto; }
  .learn-head { padding: 18px 16px 14px; }
  .lesson { padding: 20px 16px 40px; }
  .lesson h1 { font-size: 26px; }
  .ls-variants { grid-template-columns: 1fr; }
  .ls-controls .grp { grid-template-columns: 1fr; }
  .ls-nav .btn { min-width: 0; flex: 1; }
  .ls-nav { gap: 10px; }

  .modal-box, .welcome-card { width: calc(100vw - 24px); max-height: 92vh; overflow-y: auto; }
  .welcome-card { padding: 24px 18px; }
  .welcome-options { grid-template-columns: 1fr; }
  .theme-toggle { width: 40px; height: 40px; right: 12px; bottom: 12px; }

  .lb-stage { padding: 0 8px; }
  .lb-nav { display: none; }
  .lb-meta { padding: 10px 16px 18px; }
}

@media (orientation: landscape) and (max-height: 540px) {
  :root { --side-w: 200px; }
  .nav-title { min-height: 44px; font-size: 12px; }
  .nav-chev { width: 14px; height: 14px; }
  .brand { padding: 12px 16px; }
  .page { padding: 20px 24px 40px; }
  .lb-stage { padding: 0 64px; }
  .lb-meta { padding: 6px 16px 10px; }
}
