/* Phone/tablet presentation only. No model, task or wallet behavior changes. */
@media (max-width: 900px) {
  html { min-width: 0 !important; scroll-padding-top: 16px; }
  body[data-mobile-page] { min-width: 0 !important; width: 100%; }
  body[data-mobile-page] :is(input, select, textarea) { font-size: 16px !important; max-width: 100%; }
  body[data-mobile-page] :is(button, summary, input, select) { min-height: 44px; touch-action: manipulation; }
  body[data-mobile-page] :is(img, video, audio) { max-width: 100%; }
  body[data-mobile-page] :is(pre, p, h1, h2, h3, label) { overflow-wrap: anywhere; }
  body[data-mobile-page] :is(dialog, .modal, .modal-card, .modal-panel) { max-width: calc(100vw - 20px); max-height: calc(100dvh - 20px); }
  body[data-mobile-page] dialog { overflow-y: auto; overscroll-behavior: contain; }
  body[data-mobile-page] :is(.actions, .row, .toolbar, .stage-footer) { flex-wrap: wrap; }
  body[data-mobile-page] :is(.table-wrap, .table-scroll) { overflow-x: auto; }

  body.desktop-marketplace { min-width: 0 !important; }
  body.desktop-marketplace .rail { position: relative; inset: auto; width: 100%; min-width: 0; height: auto; min-height: 64px; padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
  body.desktop-marketplace .rail-nav { flex: 1 1 100%; width: 100%; gap: 6px; overflow-x: auto; overscroll-behavior-x: contain; padding-bottom: 4px; }
  body.desktop-marketplace .rail-item { flex: 0 0 auto; min-width: 72px; width: auto; height: 44px; padding: 0 10px; gap: 5px; }
  body.desktop-marketplace .rail-item span { font-size: 15px; }
  body.desktop-marketplace .rail-item svg { width: 20px; height: 20px; }
  body.desktop-marketplace .rail-bottom { margin-left: auto; }
  body.desktop-marketplace .avatar-button { min-width: 80px; height: 44px; font-size: 15px; }
  body.desktop-marketplace .stage { margin: 0; padding: 0; min-width: 0; }
  body.desktop-marketplace .view { min-height: 60dvh; }
  #view-skills .skills-page.skill-marketplace { padding: 18px 12px 32px; }
  #view-skills .skills-toolbar { flex-wrap: wrap; gap: 12px; }
  #view-skills .skill-tabs { max-width: 100%; gap: 8px; overflow-x: auto; }
  #view-skills .skill-tabs button { flex-shrink: 0; min-width: 88px; height: 44px; padding: 0 14px; font-size: 16px; }
  #view-skills .skill-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  #view-skills .skill-text-cover { height: 170px; padding: 42px 14px 18px; }
  #view-skills .skill-text-cover strong { font-size: 26px; }
  #view-skills .market-ad-slot { grid-column: 1 / -1; min-height: 180px; }
  body.desktop-marketplace :is(.workspace-layout, .chat-layout) { height: auto; min-height: 70dvh; grid-template-columns: minmax(0, 1fr); }
  body.desktop-marketplace :is(.workspace-main, .workspace-sidebar, .chat-main, .chat-sidebar) { min-width: 0; max-width: 100%; }
  .video-material-help { position: relative; right: auto; bottom: auto; }
  .video-material-panel { position: static; width: 100%; max-height: 55dvh; padding: 16px; }

  body[data-mobile-page="replay"] { height: auto; min-height: 100dvh; overflow: auto; }
  [data-mobile-page="replay"] .desktop-shell { height: auto; min-height: 100dvh; margin: 0; border-radius: 0; overflow: visible; }
  [data-mobile-page="replay"] header { height: auto; min-height: 64px; padding: 12px; flex-wrap: wrap; gap: 10px; }
  [data-mobile-page="replay"] .history { flex: 1 1 100%; width: 100%; flex-wrap: wrap; margin: 0; }
  [data-mobile-page="replay"] .history select { width: 100%; flex: 1 1 100%; }
  [data-mobile-page="replay"] #wallet { margin-left: auto; }
  [data-mobile-page="replay"] .steps { grid-template-columns: repeat(4,minmax(0,1fr)); }
  [data-mobile-page="replay"] .steps button { padding: 12px 5px; justify-content: center; gap: 4px; }
  [data-mobile-page="replay"] .steps small { display: none; }
  [data-mobile-page="replay"] main { padding: 12px; }
  [data-mobile-page="replay"] .workspace { height: auto; grid-template-columns: minmax(0,1fr); gap: 12px; }
  [data-mobile-page="replay"] :is(.settings-sidebar .panel, .settings-scroll, #output, .stage-pane, .copy-reading, #messages, #video-options) { height: auto; max-height: none; overflow: visible; }
  [data-mobile-page="replay"] .settings-sidebar .panel { padding: 16px; }
  [data-mobile-page="replay"] .copy-layout { display: flex; flex-direction: column; }
  [data-mobile-page="replay"] .empty { min-height: 280px; }
  [data-mobile-page="replay"] h1 { font-size: 24px; }
  [data-mobile-page="replay"] #video-options .row { min-width: 0; width: 100%; }
  [data-mobile-page="replay"] :is(.stage-footer, .segment-actions) { gap: 10px; }
  [data-mobile-page="replay"] .stage-footer button { flex: 1 1 140px; white-space: normal; }
  [data-mobile-page="replay"] .video-price { white-space: normal; }
  [data-mobile-page="replay"] .segment .prompt-editor { min-height: 240px; resize: vertical; }
  [data-mobile-page="replay"] .workspace-footnote { padding: 12px; }

  [data-mobile-page="product"] .shell { width: 100%; padding: 0 12px; }
  [data-mobile-page="product"] header { flex-wrap: wrap; gap: 10px; padding: 16px; }
  [data-mobile-page="product"] .layout { grid-template-columns: minmax(0,1fr); }
  [data-mobile-page="product"] .panel { min-width: 0; padding: 16px; }
  [data-mobile-page="product"] .history { width: 100%; min-width: 0; flex-wrap: wrap; }
  [data-mobile-page="product"] .history label { width: 100%; min-width: 0; }
  [data-mobile-page="product"] .editor { min-height: 300px; }
  [data-mobile-page="product"] .video-segment { padding: 12px; }
  [data-mobile-page="product"] .actions button { flex: 1 1 140px; }
  [data-mobile-page="product"] #toast { width: max-content; max-width: calc(100vw - 24px); padding: 12px; bottom: max(12px, env(safe-area-inset-bottom)); }

  [data-mobile-page="studio"] .topbar { height: auto; padding: 12px; gap: 10px; flex-wrap: wrap; }
  [data-mobile-page="studio"] :is(#promptWorkspace, #videoWorkspace) { height: auto; max-height: none; grid-template-columns: minmax(0,1fr); }
  [data-mobile-page="studio"] :is(.config-panel, .config-scroll, .results-panel) { min-width: 0; height: auto; max-height: none; overflow: visible; }
  [data-mobile-page="studio"] .config-scroll { padding: 16px; }
  [data-mobile-page="studio"] .generation-dock { position: static; padding: 16px; }
  [data-mobile-page="studio"] .project-studio[open] { width: 100%; max-width: 100%; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; overflow: auto; display: block; }
  [data-mobile-page="studio"] .project-studio .studio-shell { display: flex; flex-direction: column; overflow: visible; height: auto; }
  [data-mobile-page="studio"] .project-studio :is(.studio-topbar, .studio-automation-bar, .studio-toolbar) { flex-wrap: wrap; padding: 12px; gap: 8px; }
  [data-mobile-page="studio"] .project-studio .studio-nav { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px; border-right: 0; border-bottom: 1px solid var(--studio-border); overflow: visible; }
  [data-mobile-page="studio"] .studio-nav > :is(h2,h3,p,small,.studio-brand) { display: none; }
  [data-mobile-page="studio"] .project-studio :is(.studio-center, .studio-aside) { width: 100%; overflow: visible; padding: 12px; }
  [data-mobile-page="studio"] :is(.studio-tabs, .episode-tabs) { display: flex; max-width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  [data-mobile-page="studio"] :is(.studio-tabs, .episode-tabs) button { flex-shrink: 0; }
  [data-mobile-page="studio"] :is(.studio-match-row, .studio-shell, .studio-video-batch-settings, .video-controls, .project-editor-grid, .studio-settings-grid, .reference-grid) { grid-template-columns: minmax(0,1fr) !important; }
  [data-mobile-page="studio"] :is(.studio-single-frame, .project-studio iframe) { width: 100%; min-width: 0; min-height: 75dvh; }
  [data-mobile-page="studio"] :is(.studio-video-editor-host, .video-task-list, .project-home-card) { min-width: 0; max-width: 100%; }
  body[data-mobile-page] { padding-bottom: env(safe-area-inset-bottom); }
}
@media (max-width: 540px) {
  #view-skills .skill-grid { grid-template-columns: minmax(0,1fr); }
  #view-skills .skill-text-cover { height: 158px; }
  #view-skills .skill-card-body h3 { font-size: 20px; }
  [data-mobile-page="replay"] .steps b { display: none; }
  [data-mobile-page="replay"] .steps span { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  body[data-mobile-page] { scroll-behavior: auto; }
}
@media (max-width: 900px) {
  [data-mobile-page="home"] :is(.skill-modal-content, .story-studio-shell) { width: 100%; max-width: 100%; height: 100dvh; max-height: 100dvh; border-radius: 0; overflow-y: auto; }
  [data-mobile-page="home"] .skill-modal-content { grid-template-columns: minmax(0,1fr); }
  [data-mobile-page="home"] .skill-modal-visual { display: none; }
  [data-mobile-page="home"] .skill-modal-panel { height: auto; min-height: 100dvh; max-height: none; overflow: visible; padding: 52px 16px 20px; }
  [data-mobile-page="home"] :is(.bjd-workflow-panel, .story-studio-main, .story-source-guide) { overflow: visible; max-height: none; }
  [data-mobile-page="home"] :is(.story-studio-header, .story-studio-head-actions, .story-studio-footer) { flex-wrap: wrap; gap: 8px; padding: 12px; }
  [data-mobile-page="home"] :is(.story-source-workspace, .story-generation-layout, .story-video-layout, .story-character-layout) { grid-template-columns: minmax(0,1fr); }
  [data-mobile-page="home"] .story-history-layer { grid-template-columns: minmax(0,1fr); }
  [data-mobile-page="home"] .story-history-layer > .story-history-shade { display: none; }
}
/* The module's existing light theme uses important layered rules. */
@layer light-ui {
  @media (max-width: 900px) {
    body[data-mobile-page="studio"] :is(button, summary, input, select) { min-height: 44px !important; }
    body[data-mobile-page="studio"] :is(input, textarea, select) { font-size: 16px !important; }
    body[data-mobile-page="studio"] .project-studio .studio-topbar { display: flex !important; flex-wrap: wrap !important; height: auto !important; min-height: 64px !important; padding: 12px !important; }
    body[data-mobile-page="studio"] .project-studio[open] { display: block !important; width: 100% !important; height: 100dvh !important; max-height: 100dvh !important; margin: 0 !important; overflow-y: auto !important; }
    body[data-mobile-page="studio"] .project-studio .studio-shell { display: flex !important; flex-direction: column !important; height: auto !important; overflow: visible !important; }
    body[data-mobile-page="studio"] .project-studio .studio-nav { display: flex !important; flex-wrap: wrap !important; width: 100% !important; padding: 8px !important; overflow: visible !important; }
    body[data-mobile-page="studio"] .project-studio .studio-nav .studio-phase { width: auto !important; flex: 1 1 110px; min-height: 44px !important; padding: 8px !important; }
    body[data-mobile-page="studio"] .project-studio :is(.studio-center, .studio-aside) { width: 100% !important; max-height: none !important; overflow: visible !important; padding: 12px !important; }
    body[data-mobile-page="studio"] .project-studio :is(.studio-script-layout, .studio-create-layout, .studio-imports-row) { grid-template-columns: minmax(0,1fr) !important; margin: 0 !important; }
    body[data-mobile-page="studio"] .project-studio .studio-nav > :is(.studio-brand, .studio-nav-label) { display: none !important; }
  }
}
