/* Mobile display: preserve the black/gold identity with readable midtones.
   Scoped to the user workspace; media pixels and desktop styles stay intact. */
@media (max-width: 767px) {
  .dark :is(.app-user-workspace.zhimeng-v4, body.zhimeng-v4-overlays),
  html .app-user-workspace.zhimeng-v4.zm-home {
    --weave-gold: #f2d49b;
    --weave-gold-bright: #ffe5b8;
    --user-page-bg: #141c28;
    --user-surface: #1d2837;
    --user-surface-raised: #263345;
    --user-surface-muted: #202c3c;
    --user-surface-hover: #2b3b4e;
    --user-control-pressed: #34465a;
    --user-ink: #f8f3e9;
    --user-ink-muted: #c5ced9;
    --user-ink-soft: #acb9c9;
    --user-border: #f2d49b40;
    --user-border-strong: #f2d49b70;
    --background: var(--user-page-bg);
    --foreground: var(--user-ink);
    --muted-foreground: var(--user-ink-muted);
    --border: var(--user-border);
    --input: var(--user-border-strong);
    --card: var(--user-surface);
    --card-foreground: var(--user-ink);
    --popover: var(--user-surface-raised);
    --popover-foreground: var(--user-ink);
    --workspace-page: var(--user-page-bg);
    --workspace-sidebar: var(--user-page-bg);
    --workspace-content: var(--user-page-bg);
    --workspace-surface: var(--user-surface);
    --workspace-border: var(--user-border);
    --zm-bg: #141c28;
    --zm-text: #f8f3e9;
    --zm-muted: #c5ced9;
    --zm-soft: #acb9c9;
    --zm-gold: #f2d49b;
    --zm-ember: #ff936e;
    --zm-ice: #89cbff;
    --zm-jade: #70e4c5;
    --zm-magenta: #ed91c2;
    --zm-line: #dbe6f133;
    --zm-line2: #dbe6f152;
  }
  .dark .app-user-workspace.zhimeng-v4 {
    background-color: var(--user-page-bg) !important;
    color: var(--user-ink);
  }
  html .app-user-workspace.zhimeng-v4.zm-home {
    background: radial-gradient(700px 500px at 90% 0%, #f28d5b18, transparent 70%),
      radial-gradient(700px 600px at 0% 45%, #70e4c514, transparent 70%),
      radial-gradient(700px 600px at 100% 90%, #89cbff14, transparent 70%), #141c28 !important;
  }
  .dark .zhimeng-v4 :is(.app-workspace-sidebar, .app-workspace-topbar),
  html .zhimeng-v4.zm-home :is(.app-workspace-sidebar, .app-workspace-topbar) {
    --zm-text: #f8f3e9;
    --zm-muted: #c5ced9;
    --zm-soft: #acb9c9;
    --zm-gold: #f2d49b;
    --zm-ember: #ff936e;
    --zm-ice: #89cbff;
    --zm-jade: #70e4c5;
    --zm-magenta: #ed91c2;
    --zm-line: #dbe6f133;
    --zm-line2: #dbe6f152;
  }
  .dark .app-user-workspace.zhimeng-v4 .app-workspace-topbar,
  html .app-user-workspace.zhimeng-v4.zm-home .app-workspace-topbar {
    background: linear-gradient(180deg, #182231f5, #182231d9) !important;
    border-bottom: 1px solid var(--user-border);
  }
  .dark .app-user-workspace.zhimeng-v4 .app-workspace-sidebar,
  html .app-user-workspace.zhimeng-v4.zm-home .app-workspace-sidebar {
    background: linear-gradient(180deg, #202b3b, #151e2b) !important;
  }
  html .app-user-workspace.zhimeng-v4.zm-home .creation-launchpad .creation-chat-composer {
    background: linear-gradient(180deg, #263244f5, #1c2737fa) !important;
  }
  html .app-user-workspace.zhimeng-v4.zm-home .creation-composer-stage.is-home-mode > .creation-mode-tabs {
    background: #202c3be8;
    border-color: var(--zm-line2);
  }
  html .app-user-workspace.zhimeng-v4.zm-home :is(.creation-chat-control, .creation-model-picker, .creation-attachments-button) {
    color: var(--zm-muted);
    border-color: var(--zm-line2);
    background-color: #273548b3;
  }
  html .app-user-workspace.zhimeng-v4.zm-home .creation-launchpad .creation-model-picker {
    color: var(--zm-muted) !important;
    background: #273548 !important;
    border-color: var(--zm-line2) !important;
  }
  html .app-user-workspace.zhimeng-v4.zm-home .creation-model-picker :is(span, svg) {
    color: var(--zm-muted) !important;
  }
  html .app-user-workspace.zhimeng-v4.zm-home .app-workspace-topbar-icon-button {
    color: var(--zm-muted) !important;
    background: var(--user-surface) !important;
    border-color: var(--zm-line2) !important;
  }
  .dark .app-user-workspace.zhimeng-v4 :is(textarea, input)::placeholder,
  html .app-user-workspace.zhimeng-v4.zm-home :is(textarea, input)::placeholder,
  .dark .app-user-workspace.zhimeng-v4 [contenteditable][data-placeholder]:empty::before {
    color: #acb9c9 !important;
    opacity: 1;
  }
  html .app-user-workspace.zhimeng-v4.zm-home .creation-composer-stage.is-home-mode .creation-mode-button[aria-pressed="true"] {
    color: #f8f3e9;
    background-color: color-mix(in srgb, var(--zm-mode) 22%, #202c3b);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--zm-mode) 65%, transparent);
  }
  html .app-user-workspace.zhimeng-v4.zm-home .zm-capability {
    background: linear-gradient(160deg, color-mix(in srgb, var(--k) 10%, #202c3b), #1b2533);
    border-color: color-mix(in srgb, var(--k) 36%, #344355);
  }
  html .app-user-workspace.zhimeng-v4.zm-home .zm-grain { opacity: .035; }
  html .app-user-workspace.zhimeng-v4.zm-home .inspiration-card-open::after {
    background: linear-gradient(180deg, transparent 55%, #080d16ed);
  }
  .dark .zhimeng-v4 :is(.story-genre-chips button, .zm-canvas-tips article, .zm-task-stat, .zm-project-empty) {
    border-color: var(--user-border-strong);
  }
  .dark .zhimeng-v4 :is(.zm-task-stat, .zm-canvas-tips article, .zm-project-empty, .zm-task-empty) {
    background-color: var(--user-surface);
  }
  /* Keep the light theme readable; its existing cream/gold colors are retained. */
  html:not(.dark) .app-user-workspace.zhimeng-v4:not(.zm-home) {
    --user-ink-muted: #5e574b;
    --user-ink-soft: #6b6254;
  }
}

/* One bounded viewport, one scrolling asset list. The action bar never scrolls away. */
@media (max-width: 767px), (max-height: 500px) {
  body.zhimeng-v4-overlays .asset-library-picker-modal {
    --picker-height: min(720px, calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)));
    width: min(960px, calc(100vw - 16px)) !important;
    max-width: calc(100vw - 16px) !important;
    padding-bottom: 0;
  }
  body.zhimeng-v4-overlays .asset-library-picker-modal .ant-modal-body {
    height: var(--picker-height);
    max-height: none;
    overflow: hidden;
  }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-shell {
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-toolbar {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: 36px 44px;
    gap: 8px 6px;
    min-height: 0;
    padding: 8px 48px 8px 12px;
  }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-search {
    grid-column: 1 / -1;
    grid-row: 2;
    height: 44px;
    margin-right: -36px;
    max-width: none;
  }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-search input { font-size: 16px; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-count { grid-column: 2; grid-row: 1; white-space: nowrap; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .ant-modal-close { top: 8px; right: 4px; width: 44px; height: 44px; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    gap: 0;
    padding: 0 12px;
  }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-categories {
    display: flex;
    flex: 0 0 auto;
    height: 56px;
    min-height: 56px;
    max-height: 56px;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 0 8px;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-categories::-webkit-scrollbar { display: none; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-nav-label { display: none; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-categories .assets-filter-item {
    width: auto;
    min-width: max-content;
    height: 44px;
    flex: 0 0 auto;
    white-space: nowrap;
  }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-grid-wrap {
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 4px 0 12px;
    scroll-padding-block: 8px;
  }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-card-check { opacity: 1; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-empty { min-height: 120px; padding: 16px 0; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-footer {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    flex: 0 0 auto;
    min-height: 0;
    gap: 8px;
    padding: 8px 12px 12px;
    border-top: 1px solid var(--border);
    background: var(--popover);
  }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-upload { min-width: 0; min-height: 48px; padding: 6px 12px; gap: 8px; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-upload > svg { flex-shrink: 0; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-upload span { min-width: 0; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-upload small { overflow-wrap: anywhere; line-height: 1.4; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-actions .ant-btn { min-height: 44px; height: auto; flex: 1 1 auto; padding: 8px 12px; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-footer-error { max-width: none; max-height: 44px; overflow-y: auto; }
}
@media (min-width: 600px) and (max-height: 500px) {
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-toolbar { grid-template-columns: auto minmax(100px, 1fr) auto; grid-template-rows: 44px; gap: 8px; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-search { grid-column: 2; grid-row: 1; margin-right: 0; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-count { grid-column: 3; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-footer { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-upload small { display: none; }
  body.zhimeng-v4-overlays .asset-library-picker-modal .asset-picker-footer-error { grid-column: 1 / -1; }
}
