/* Mobile generation flow: references → prompt/controls → results. */
@media (max-width: 600px), (max-width: 1024px) and (max-height: 500px) and (orientation: landscape) {
  body:has(#ai-image.panel.active) { --ai-image-narrow-width: 100%; --task-bar-width: 100vw; }
  #ai-image .task-tabs-shell { top: calc(56px + env(safe-area-inset-top, 0px)); }
  #ai-image:has(> .task-tabs-shell) { padding-top: 58px; }
  #ai-image .task-list { gap: 4px; }
  /* Scale only normal-flow cards. Native zoom preserves their layout and flow height;
     task tabs, body-mounted editors/pickers and the arrangement canvas stay unscaled. */
  body:not(.arrange-mode) #ai-image .task-shell { --mobile-card-scale: .88; zoom: var(--mobile-card-scale); width: calc(100% * var(--mobile-card-scale)); margin-inline: auto; }
  body:not(.arrange-mode) #ai-image .task-shell { padding-top: 0; scroll-margin-top: calc(128px + env(safe-area-inset-top, 0px)); }
  #ai-image .task-list .task-shell:not(:first-child) { margin-top: 0; }
  #ai-image .task-card { height: auto; min-height: 0; max-height: none; padding: 12px; overflow: visible; border-radius: 18px; }
  #ai-image .task-layout { display: flex; flex-direction: column; flex-wrap: nowrap; gap: 12px; overflow: visible; }
  #ai-image .task-layout .upload-panel, #ai-image .task-layout .prompt-panel, #ai-image .task-layout .result-panel {
    position: static; inset: auto; width: 100%; min-width: 0; max-width: none; max-height: none;
    margin: 0; flex: none; overflow: visible; align-self: stretch;
  }
  #ai-image .independent-task-tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  #ai-image .independent-task-tab { flex-shrink: 0; }
  #ai-image .upload-grid { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 68px; justify-content: start; gap: 8px; margin: 0; padding: 2px 0 6px; overflow-x: auto; overscroll-behavior-x: contain; }
  #ai-image .upload-slot { width: 100%; height: auto; min-width: 0; aspect-ratio: 1; }
  #ai-image .prompt-panel .prompt-box { min-height: 0; height: auto; max-height: none; padding: 10px 10px 44px; position: relative; }
  #ai-image .prompt-box .prompt-textarea { width: 100%; min-height: 76px; height: 76px; max-height: 45dvh; font-size: 16px; line-height: 1.6; resize: vertical; }
  #ai-image .prompt-controls-wrap { width: 100%; margin: 10px 0 0; gap: 8px; align-items: stretch; }
  #ai-image .prompt-controls-wrap .field-row { width: 100%; min-width: 0; flex-direction: row; flex-wrap: wrap; gap: 8px; }
  #ai-image .prompt-controls-wrap .field-group { flex: 1 1 100px; width: auto; min-width: 0; max-width: none; }
  #ai-image .prompt-controls-wrap .field-group select { min-height: 44px; font-size: 16px; }
  #ai-image .prompt-controls-wrap .action-row { width: 100%; gap: 10px; }
  #ai-image .prompt-controls-wrap .generate-btn-wrap { flex: 1; min-width: 0; }
  #ai-image .prompt-controls-wrap .generate-btn-wrap .generate-task-btn { width: 100%; }
  #ai-image .prompt-controls-wrap .action-btn { flex: 1; width: auto; min-width: 0; max-width: none; min-height: 44px; font-size: 15px; }
  #ai-image .result-stack { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding-bottom: 8px; }
  #ai-image .result-item, #ai-image .result-item:not(:has(.result-frame)) { width: 100%; max-width: none; min-width: 0; height: auto; }
  #ai-image .result-item .result-frame { width: 100%; max-width: none; aspect-ratio: 4 / 3; }
  #ai-image .result-item img { max-width: 100%; max-height: 100%; }
  #ai-image .result-upload-btn { opacity: 1; }
  #ai-image .result-close-btn, #ai-image .result-download-btn, #ai-image .result-select-btn { opacity: 1; visibility: visible; pointer-events: auto; }
  #ai-image .task-index-tag-bg, #ai-image .task-index-tag-text { left: 12px; top: 12px; width: 26px; height: 20px; transform: none; border-radius: 7px; }
  #ai-image .task-index-tag-bg { z-index: 3; }
  #ai-image .task-index-tag-text { z-index: 4; }
  body:not(.arrange-mode) #ai-image .task-close-btn { top: 12px; right: 8px; }
  body:not(.arrange-mode) #ai-image .task-add-btn { position: relative; left: auto; bottom: auto; display: flex; width: calc(44px / var(--mobile-card-scale)); height: calc(44px / var(--mobile-card-scale)); min-width: 0; min-height: 0; margin: calc(4px / var(--mobile-card-scale)) auto 0; transform: none; opacity: 1; border: 0; background: transparent; color: var(--muted); }
  body:not(.arrange-mode) #ai-image .task-add-btn:disabled { opacity: .35; }
  #ai-image .task-add-btn::after { display: none; }
  #ai-image .upload-panel h3 { padding-left: 34px; min-height: 20px; line-height: 20px; padding-right: 20px; }
  .sb-editor-overlay { padding: 0; top: var(--mobile-visible-top, 0px); bottom: auto; height: var(--mobile-visible-height, 100dvh); align-items: flex-start; }
  .sb-editor-dialog, .sb-region-dialog, .sb-detail-dialog, .sb-product-size-pro-dialog, .sb-composer-dialog, .sb-crop-dialog {
    width: 100%; max-width: 100%; height: var(--mobile-visible-height, 100dvh); max-height: var(--mobile-visible-height, 100dvh);
    min-height: 0; border-radius: 0; padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .sb-editor-toolbar, .sb-region-toolbar { overflow-y: auto; }
  .sb-detail-ratio-modes, .sb-detail-mosaic-toolbar { max-width: 100%; overflow-x: auto; }
  .sb-composer-toolbar, .sb-composer-footer { flex-wrap: wrap; }
  #ai-image .sb-select-trigger { min-height: 44px; }
  .sb-select-menu { max-width: calc(100vw - 24px); max-height: 60dvh; overflow-y: auto; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .sb-model-option, .sb-ratio-option { min-height: 44px; }
  #ai-image .prompt-toolbar { position: absolute; inset: auto 6px 2px; flex-direction: row; justify-content: flex-end; margin: 0; opacity: 1; pointer-events: auto; }
  #ai-image .prompt-toolbar .icon-btn { width: 40px; height: 40px; }
  #ai-image .prompt-toolbar .icon-btn svg { width: 18px; height: 18px; }
  #ai-image .upload-panel h3, #ai-image .prompt-panel h3, #ai-image .result-panel h3 { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; }
  #ai-image .result-close-btn, #ai-image .result-select-btn, #ai-image .result-download-btn { width: 36px; height: 36px; }
  #ai-image .upload-grid:has(.has-image) { grid-auto-columns: 88px; }
  #ai-image .upload-slot.has-image { height: 100px; aspect-ratio: auto; touch-action: pan-x pan-y; background: var(--surface); }
  #ai-image .upload-slot.has-image img { height: 68px; border-radius: 10px 10px 0 0; }
  #ai-image .slot-tool { opacity: 1; visibility: visible; pointer-events: auto; top: auto; bottom: 0; width: 50%; height: 32px; padding: 0; border-radius: 0; background: var(--soft); color: var(--text); box-shadow: none; transform: none; }
  #ai-image .slot-tool.annotate { left: 0; }
  #ai-image .slot-tool.crop { left: 50%; }
  #ai-image .task-card .slot-remove { opacity: 1; visibility: visible; pointer-events: auto; transform: none; }
}
