/* ============================================================
   绿幕工作台 · 独立移动端 UI（≤1024px）
   与桌面端共用 DOM 控件，布局/导航/密度单独设计
   ============================================================ */

@media (max-width: 1024px) {
  body.gsm-page {
    overflow: hidden;
    overscroll-behavior: none;
  }

  body.gsm-mobile-mode .gsm-app-wrapper > site-header {
    display: none;
  }

  body.gsm-mobile-mode .gsm-app-wrapper {
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
  }

  body.gsm-mobile-mode .gsm-embed {
    flex: 1;
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  /* ---------- 移动壳 ---------- */
  .gsm-mobile-app {
    display: none;
    flex: 1;
    min-height: 0;
    flex-direction: column;
    background: var(--void);
  }

  body.gsm-mobile-mode .gsm-mobile-app {
    display: flex;
  }

  body.gsm-mobile-mode .gsm-desktop-only {
    display: none !important;
  }

  .m-topbar {
    flex-shrink: 0;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top));
    border-bottom: 1px solid var(--stroke);
    background: var(--panel);
    z-index: 30;
  }

  .m-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 12px;
    border-radius: var(--r-sm);
    border: 1px solid var(--stroke);
    background: var(--panel-2);
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    font-family: inherit;
    cursor: pointer;
  }

  .m-back:active {
    border-color: var(--diamond);
    color: var(--text);
  }

  .m-topbar-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 800;
    letter-spacing: 0.02em;
  }

  .m-cube {
    width: 18px;
    height: 18px;
    border-radius: 3px;
    background: linear-gradient(135deg, #3ad07f, #34d3e6);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12) inset;
  }

  .m-topbar-meta {
    justify-self: end;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid var(--stroke);
    background: var(--panel);
    color: var(--text-dim);
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
  }

  .m-body {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
  }

  .m-panel {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }

  .m-panel.is-active {
    display: flex;
  }

  .m-scroll {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }

  /* ---------- 底栏 Tab ---------- */
  .m-tabbar {
    flex-shrink: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 6px 8px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--stroke);
    background: var(--panel);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    z-index: 40;
  }

  .m-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 52px;
    padding: 6px 4px;
    border: 0;
    border-radius: var(--r-md);
    background: transparent;
    color: var(--text-mute);
    font: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .m-tab-ico {
    font-size: 17px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 18px;
  }

  .m-tab-lbl {
    font-size: 11px;
    font-weight: 800;
  }

  .m-tab.is-active {
    color: var(--diamond);
    background: var(--diamond-soft);
    box-shadow: 0 0 0 1px var(--stroke-strong) inset;
  }

  /* ---------- 预览 Tab ---------- */
  body.gsm-mobile-mode #stage {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    height: 100%;
    background: var(--inset);
  }

  body.gsm-mobile-mode .stage-bar {
    flex-shrink: 0;
    padding: 10px 14px;
    flex-wrap: wrap;
  }

  body.gsm-mobile-mode .stage-bar > .title {
    width: 100%;
    font-size: 13px;
    margin-bottom: 2px;
  }

  body.gsm-mobile-mode .stage-bar > .spacer {
    display: none;
  }

  /* 隐藏「帧率」徽标（stage-bar 现在多了返回按钮，索引后移一位） */
  body.gsm-mobile-mode .stage-bar > .badge:nth-child(6) {
    display: none;
  }

  body.gsm-mobile-mode .canvas-area {
    flex: 1;
    width: 100%;
    min-height: 0;
    height: auto;
    max-height: none;
    aspect-ratio: unset;
    padding: 12px;
    margin: 0;
  }

  body.gsm-mobile-mode .transport {
    flex-shrink: 0;
    padding: 12px 14px 14px;
    border-top: 1px solid var(--stroke);
    background: var(--panel);
  }

  body.gsm-mobile-mode .transport-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  body.gsm-mobile-mode .transport-btns {
    display: grid;
    grid-template-columns: 44px 1fr 44px 44px;
    gap: 8px;
    width: 100%;
  }

  body.gsm-mobile-mode .tbtn {
    min-width: 44px;
    height: 48px;
    font-size: 18px;
  }

  body.gsm-mobile-mode .tbtn.play {
    font-size: 15px;
    font-weight: 800;
  }

  body.gsm-mobile-mode .readout {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
  }

  body.gsm-mobile-mode .chip-read {
    flex: 1;
    text-align: center;
    padding: 8px 10px;
  }

  /* ---------- 素材 Tab ---------- */
  body.gsm-mobile-mode #gsm-assets {
    display: block;
    overflow: visible;
    border: 0;
    background: transparent;
  }

  body.gsm-mobile-mode #gsm-assets .section {
    padding: 16px 14px;
    border-bottom: 1px solid var(--stroke);
    background: var(--panel);
  }

  body.gsm-mobile-mode .section-head h2 {
    font-size: 15px;
  }

  body.gsm-mobile-mode .template-grid {
    display: flex;
    flex-wrap: nowrap;
    gap: 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    padding-bottom: 4px;
    margin: 0 -2px;
  }

  body.gsm-mobile-mode .template-grid .tpl {
    flex: 0 0 min(78vw, 300px);
    scroll-snap-align: start;
    min-height: 72px;
  }

  body.gsm-mobile-mode .slots {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 12px 0;
  }

  body.gsm-mobile-mode .slot {
    min-height: 72px;
  }

  body.gsm-mobile-mode .searchbar input {
    min-height: 44px;
    font-size: 16px;
  }

  body.gsm-mobile-mode .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }

  body.gsm-mobile-mode .chip {
    flex-shrink: 0;
    min-height: 40px;
    padding: 0 16px;
  }

  body.gsm-mobile-mode .asset-grid {
    max-height: none;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  body.gsm-mobile-mode .asset-grid .asset {
    min-height: 64px;
  }

  body.gsm-mobile-mode .file-drop.upload {
    min-height: 52px;
    margin-top: 12px;
  }

  body.gsm-mobile-mode .current-asset {
    margin-bottom: 8px;
  }

  body.gsm-mobile-mode .recent-row {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
  }

  /* ---------- 调节 Tab ---------- */
  body.gsm-mobile-mode #gsm-settings {
    display: contents;
  }

  body.gsm-mobile-mode #mScrollTune .section,
  body.gsm-mobile-mode #mScrollExport .section {
    padding: 16px 14px;
    border-bottom: 1px solid var(--stroke);
    background: var(--panel);
  }

  body.gsm-mobile-mode .field select,
  body.gsm-mobile-mode .field input[type="text"] {
    min-height: 44px;
    font-size: 16px;
  }

  body.gsm-mobile-mode .segmented {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    gap: 6px;
  }

  body.gsm-mobile-mode .segmented button {
    flex: 1 0 auto;
    min-width: 72px;
    min-height: 44px;
    padding: 0 14px;
  }

  body.gsm-mobile-mode .param input[type="range"] {
    height: 32px;
  }

  body.gsm-mobile-mode .param-head label {
    font-size: 14px;
  }

  body.gsm-mobile-mode .grid-2 {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  body.gsm-mobile-mode .color-input input[type="color"] {
    width: 48px;
    height: 48px;
  }

  body.gsm-mobile-mode .btn.ghost,
  body.gsm-mobile-mode .btn {
    min-height: 44px;
  }

  /* ---------- 导出 Tab ---------- */
  body.gsm-mobile-mode .btn-record {
    min-height: 56px;
    font-size: 16px;
    margin-top: 8px;
  }

  body.gsm-mobile-mode .result .r-actions {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  body.gsm-mobile-mode .result .btn.download {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  body.gsm-mobile-mode .preset-save {
    flex-direction: column;
    gap: 10px;
  }

  body.gsm-mobile-mode .preset-save input {
    min-height: 44px;
    font-size: 16px;
  }

  body.gsm-mobile-mode .preset-save .btn {
    width: 100%;
  }

  body.gsm-mobile-mode .preset-list .preset-row {
    min-height: 48px;
  }

  /* ---------- Toast ---------- */
  body.gsm-mobile-mode .toasts {
    bottom: calc(72px + env(safe-area-inset-bottom));
    left: 12px;
    right: 12px;
  }
}

@media (max-width: 640px) {
  body.gsm-mobile-mode .asset-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body.gsm-mobile-mode .template-grid .tpl {
    flex-basis: 86vw;
  }
}

@media (max-width: 1024px) and (prefers-reduced-motion: reduce) {
  .m-tab,
  .m-back {
    transition: none !important;
  }
}
