/* =====================================================================
 * 手机适配。全部在 max-width 媒体查询里，桌面端不受影响。
 *
 * 模拟编辑器在手机上不硬挤：main.js 给它们保留桌面版宽度，整体 transform 缩小到
 * 屏幕宽（body 上会挂 .fit-mode）。所以这里分三块：
 *   A. 页面级的排版，任何时候都生效；
 *   B. 编辑器内部的"挤一挤"规则，只在没有 JS 缩放（没有 .fit-mode）时兜底；
 *   C. 有 .fit-mode 时，把 styles.css / styles-2.css 里的窄屏规则拨回桌面值。
 * =================================================================== */

/* ---- A. 页面级 ------------------------------------------------------ */
@media (max-width: 860px) {
  .pad { width: min(80rem, 100% - 1.75rem); }
  .sec { padding: clamp(3rem, 8vh, 4.5rem) 0; }
  .sec-head { margin-bottom: 1.6rem; gap: 0.7rem; }
  h2 { font-size: clamp(1.6rem, 6.6vw, 2.3rem); }
  .sub { max-width: none; font-size: 0.98rem; line-height: 1.7; }
  .kicker { font-size: 0.66rem; letter-spacing: 0.18em; }

  .nav-in { gap: 0.8rem; }
  .btn { padding: 0.55rem 0.9rem; font-size: 0.86rem; }
  .btn.soon { padding: 0.55rem 0.6rem; font-size: 0; gap: 0; }
  .btn.soon svg { width: 18px; height: 18px; margin: 0; }

  .hero { padding-top: 2.2rem; padding-bottom: 2rem; }
  .hero-grid { background-size: 40px 40px; }
  .hero-copy { gap: 0.9rem; }
  .kicker.pill { max-width: 100%; white-space: normal; text-align: center; line-height: 1.4; font-size: 0.74rem; }
  .hero h1 { font-size: clamp(2.3rem, 10.5vw, 3.4rem); }
  .hero .sub { font-size: 0.98rem; }
  .hero-row { gap: 1.2rem; }
  .hero-actions { width: 100%; }
  .hero-actions .btn.lg { flex: 1 1 auto; justify-content: center; padding: 0.8rem 1rem; font-size: 0.95rem; }
  .hero-note { text-align: center; line-height: 1.5; font-size: 0.8rem; }
  .hero-note i { flex: none; }
  .hero-ed { margin-top: 0.6rem; }
  .js .hero-ed .ed { animation: none; }
  .hero-ed::after { display: none; }

  .proof { padding: 1.6rem 0; }
  .proof-in { grid-template-columns: 1fr 1fr; gap: 1rem 0.8rem; }
  .proof-it .big { font-size: 1.5rem; }
  .proof-it .lbl { font-size: 0.8rem; line-height: 1.5; }

  .vs-row { padding: 0.9rem 1rem; font-size: 0.92rem; }
  .callout { padding: 1.1rem 1.1rem 1.1rem 1.4rem; }
  .callout p { font-size: 0.92rem; }

  .seg { flex-wrap: wrap; }
  .seg button { flex: 1 1 auto; padding: 0.4rem 0.6rem; font-size: 0.8rem; }
  .lay-hint { gap: 0.5rem 1rem; font-size: 0.78rem; }
  .clips { gap: 0.8rem; }
  .clip-fig figcaption { font-size: 0.78rem; }

  .two .copy { gap: 0.8rem; }
  .feat-list { gap: 0.6rem; }
  .feat-list li { font-size: 0.9rem; }

  .tri { gap: 0.7rem; margin-top: 1.4rem; }
  .tri-it, .how-it, .bg-card, .plug, .ext-src, .ext-vm, .mode { padding: 1rem 1.05rem; }
  .tri-it p, .how-it ul { font-size: 0.88rem; }
  .kbd-list { margin-top: 1.4rem; gap: 0.2rem; }
  .kbd-it { grid-template-columns: 1fr auto; align-items: start; gap: 0.4rem 0.8rem; font-size: 0.86rem; }
  .kbd-it > span:first-child { display: block; white-space: normal; text-align: left; line-height: 1.55; }
  .kbd-it > span:last-child:not(:first-child) { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.25rem; white-space: nowrap; font-size: 0.8rem; max-width: 40%; }

  .blocks-grid { gap: 0.8rem; }
  .bg-card p { font-size: 0.9rem; }
  .bg-stage { min-height: 150px; --bs: 0.6; padding: 0.8rem; }

  .paint-tools { gap: 0.35rem; }
  .chip { font-size: 0.74rem; padding: 0.22rem 0.55rem; }
  .frames { gap: 4px; }
  .tl-bar { flex-wrap: wrap; gap: 6px; }

  .four { gap: 0.6rem; margin-top: 1rem; }
  .mode canvas { height: 84px; }
  .mode span { font-size: 0.8rem; }

  .stage-box { aspect-ratio: 4 / 3; }

  .ext-flow { grid-template-columns: 1fr; gap: 0.6rem; margin-bottom: 1.2rem; }
  .code-card { padding: 1rem 1.1rem; }
  .code-card pre { font-size: 11px; }
  .code-card .cap { position: static; display: block; margin-bottom: 0.6rem; }
  .api-table { font-size: 0.82rem; }
  .api-table th, .api-table td { padding: 0.45rem 0.5rem; }
  .plugins { gap: 0.6rem; margin-top: 1.2rem; }

  .vs-head { gap: 0.6rem; flex-direction: column; align-items: stretch; margin-bottom: 1.4rem; }
  .ct { padding: 0.7rem 1rem 0.7rem 0.8rem; }
  .vs-x { font-size: 1.1rem; text-align: center; }
  .perf-hero { gap: 0.7rem; margin-bottom: 1.6rem; }
  .perf-big { padding: 1.1rem 1.2rem; }
  .perf-big .n { font-size: clamp(2.2rem, 12vw, 3.2rem); }
  .duel { flex-wrap: wrap; gap: 0.4rem 1rem; font-size: 0.84rem; }
  .perf-live { padding: 12px 12px 14px; margin-bottom: 1.4rem; }
  .pl-head { flex-direction: column; gap: 0.3rem; }
  .pl-lane { grid-template-columns: 1fr; gap: 6px; }
  .pl-meta { grid-template-columns: auto auto auto; gap: 0.6rem; align-items: baseline; }
  .pl-fps { font-size: 1.2rem; }
  .ledger { gap: 1.8rem; }
  .bar-row { grid-template-columns: 1fr 4rem; gap: 0.35rem 0.7rem; }
  .bar-row .lb { grid-column: 1 / -1; font-size: 0.86rem; }
  .bar-row .x { font-size: 0.9rem; }
  .how { margin-top: 1.4rem; gap: 0.7rem; }

  .start { gap: 1.6rem; }
  .go-card { position: static; padding: 1.3rem 1.2rem 1.1rem; }
  .go-card .hero-actions .btn.lg { flex: 1 1 100%; }
  .step { gap: 0.7rem; padding: 0.8rem 0; }
  .compat { gap: 0.6rem; }

  .fin { padding: 3.5rem 0; }
  .fin .moo { height: 90px; }
  .fin h2 { font-size: clamp(1.9rem, 8.5vw, 2.8rem); }
  .fin .hero-actions .btn.lg { flex: 1 1 100%; }
  .site-foot { padding: 1.8rem 0 2.2rem; }
  .site-foot-in { gap: 0.6rem 1.2rem; font-size: 0.8rem; }
  .site-foot-in .sp { display: none; }

  /* 缩放容器：编辑器保持桌面宽度，整体缩到这一格里 */
  .fit-wrap { position: relative; overflow: hidden; border-radius: 12px; contain: inline-size; min-width: 0; width: 100%; }
  body.fit-mode .hero-ed, body.fit-mode .two > *, body.fit-mode .hero-in > * { min-width: 0; }
  body.fit-mode .ed { transform-origin: 0 0; box-shadow: none; }
  body.fit-mode .tilt { perspective: none; }
}

@media (max-width: 560px) {
  body { font-size: 15px; }
  .nav-cta .btn.pri { padding: 0.5rem 0.8rem; }
  .brand .ver { display: none; }
  .vs-row { padding: 0.8rem 0.9rem; }
  .thumbs { grid-template-columns: repeat(auto-fill, minmax(50px, 1fr)); }
  .compat { grid-template-columns: 1fr; }
  .go-url { font-size: clamp(1.4rem, 8vw, 2rem); }
}

/* ---- B. 没有 JS 缩放时，编辑器内部挤一挤 ------------------------------ */
@media (max-width: 860px) {
  body:not(.fit-mode) .hero-ed .ed { aspect-ratio: auto; height: 520px; max-height: none; --bs: 0.5; border-radius: 10px; }
  body:not(.fit-mode) .hero-ed .ed-body { grid-template-columns: 132px 1fr; grid-template-rows: 1fr; }
  body:not(.fit-mode) .hero-ed .p-sprites { display: none; }
  body:not(.fit-mode) .hero-ed .p-fly { display: flex; }
  body:not(.fit-mode) .hero-ed .fly { grid-template-columns: 1fr; }
  body:not(.fit-mode) .hero-ed .cats { display: none; }
  body:not(.fit-mode) .hero-ed .fly-list { padding: 8px; gap: 8px; }
  body:not(.fit-mode) .hero-ed .stage-win { width: 52%; right: 8px; top: 8px; }
  body:not(.fit-mode) .hero-ed .stage-bar { height: 24px; }
  body:not(.fit-mode) .hero-ed .stage-bar .go, body:not(.fit-mode) .hero-ed .stage-bar .pause, body:not(.fit-mode) .hero-ed .stage-bar .stop { width: 26px; height: 16px; }
  body:not(.fit-mode) .hero-ed .stage-bar .ic { display: none; }
  body:not(.fit-mode) .hero-ed .tabs .tab:not(.on) { display: none; }
  body:not(.fit-mode) .ed-top .mi, body:not(.fit-mode) .ed-top .search { display: none; }
  body:not(.fit-mode) .ed-top .ed-tools i:nth-child(n+9) { display: none; }
  body:not(.fit-mode) .hero-cap { left: 8px; right: 8px; bottom: 8px; font-size: 10.5px; padding: 5px 9px; }
  body:not(.fit-mode) .ws-zoom { display: none; }
  body:not(.fit-mode) .lay-ed { aspect-ratio: 4 / 3.4; }
  body:not(.fit-mode) .lay-ed .pn-b { font-size: 9px; }
  body:not(.fit-mode) .lay-ed .sp-row { display: none; }
  body:not(.fit-mode) .xws { aspect-ratio: 4 / 3.2; --bs: 0.5; }
  body:not(.fit-mode) .xws .tabs .tab { padding: 0 8px; font-size: 10px; }
  body:not(.fit-mode) .scene-demo .ed-body { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 6px; }
  body:not(.fit-mode) .sd-stage .pn-b { padding: 0; }
  body:not(.fit-mode) .sd-script .pn-b { min-height: 300px; }
  body:not(.fit-mode) .sd-script .ws { --bs: 0.52; }
  body:not(.fit-mode) .scene-demo .sd-caption { position: relative; height: auto; min-height: 34px; padding: 8px 12px; line-height: 1.4; font-size: 11px; }
  body:not(.fit-mode) .lib-ed { aspect-ratio: auto; height: 440px; }
  body:not(.fit-mode) .lib-ed .assets { grid-template-columns: 1fr; }
  body:not(.fit-mode) .lib-ed .tree { display: none; }
  body:not(.fit-mode) .lib-ed .thumbs { grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); grid-auto-rows: 58px; gap: 6px; padding: 8px; align-content: start; }
  body:not(.fit-mode) .lib-ed .thumbs i { aspect-ratio: auto; height: 58px; }
  body:not(.fit-mode) .dlg { inset: 34px 0 0; }
  body:not(.fit-mode) .dlg-box { width: min(300px, 88%); }
  body:not(.fit-mode) .daw { aspect-ratio: auto; height: 420px; }
  body:not(.fit-mode) .daw .ed-body { grid-template-columns: 96px 1fr; }
  body:not(.fit-mode) .daw .tr { padding: 0 6px; font-size: 9.5px; }
  body:not(.fit-mode) .daw .tr .ms { display: none; }
  body:not(.fit-mode) .daw .transport { font-size: 10px; gap: 6px; }
  body:not(.fit-mode) .daw .transport > span:nth-child(n+5):not(.btn2) { display: none; }
  body:not(.fit-mode) .code-ed { aspect-ratio: auto; height: 520px; }
  body:not(.fit-mode) .code-ed .ed-body { grid-template-columns: 1fr; grid-template-rows: 1fr 150px; }
  body:not(.fit-mode) .code-ed .p-files { display: none; }
  body:not(.fit-mode) .code { font-size: 10.5px; padding: 8px 10px; }
  body:not(.fit-mode) .code .ln::before { width: 16px; margin-right: 8px; }
  body:not(.fit-mode) .minimap { display: none; }
  body:not(.fit-mode) .code-ed .code { right: 0; }
  body:not(.fit-mode) .statusbar { gap: 8px; font-size: 9.5px; padding: 0 8px; }
  body:not(.fit-mode) .term { font-size: 10px; }
}
@media (max-width: 560px) {
  body:not(.fit-mode) .hero-ed .ed { height: 480px; }
  body:not(.fit-mode) .hero-ed .ed-body { grid-template-columns: 118px 1fr; }
  body:not(.fit-mode) .hero-ed .stage-win { width: 56%; }
  body:not(.fit-mode) .xws .ed-body { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  body:not(.fit-mode) .xws { aspect-ratio: 3 / 4; }
  body:not(.fit-mode) .lay-ed { aspect-ratio: 3 / 3.2; }
}

/* ---- C. 有 JS 缩放时，把 styles.css / styles-2.css 的窄屏规则拨回桌面值 ------- */
@media (max-width: 860px) {
  body.fit-mode .hero-ed .ed { aspect-ratio: 16 / 9.2; max-height: none; }
  body.fit-mode .hero-ed .ed-body { grid-template-columns: 180px 230px 1fr; }
  body.fit-mode .hero-ed .p-sprites, body.fit-mode .hero-ed .p-fly { display: flex; }
  body.fit-mode .float-ws { display: flex; }
  body.fit-mode .code-ed { aspect-ratio: 16 / 10; }
  body.fit-mode .code-ed .ed-body { grid-template-columns: 170px 1fr; grid-template-rows: 1fr 140px; }
  body.fit-mode .code-ed .p-files { display: flex; }
  body.fit-mode .lib-ed { aspect-ratio: 16 / 7.6; }
  body.fit-mode .lib-ed .assets { grid-template-columns: 180px minmax(0, 1fr) 260px; }
  body.fit-mode .lib-ed .detail { display: grid; }
  body.fit-mode .daw { aspect-ratio: 16 / 7.2; }
  body.fit-mode .daw .ed-body { grid-template-columns: 150px 1fr; }
  body.fit-mode .scene-demo { aspect-ratio: 16 / 6.9; }
  body.fit-mode .scene-demo .ed-body { position: absolute; inset: 34px 0 34px; grid-template-columns: 43% 22% 1fr; margin-bottom: 0; }
}
