:root {
  --line: color-mix(in srgb, var(--accent) 18%, transparent);
  --shadow: 0 8px 28px color-mix(in srgb, var(--accent) 7%, transparent);
  --radius: 18px;
}
html { scrollbar-gutter: stable; scroll-padding-top: 155px; }
body { color: color-mix(in srgb, var(--accent-cool) 28%, #26313e); }
button, a, input, select, textarea, summary { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
input, textarea, select { border-color: var(--line); transition: border-color 150ms, box-shadow 150ms; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--theme-soft); }
h1, h2, h3, h4, .section-head h3, .overview-card strong { font-family: var(--sans); font-weight: 600; letter-spacing: -.015em; }
.section-head h3 { font-size: 20px; }
.auth-hero h1 { font-family: var(--serif); }
.section-head { align-items: center; flex-wrap: wrap; }
.section-head > .muted { font-size: 13px; margin-bottom: 0; }
.nav-item.is-active { background: var(--theme-soft); color: var(--accent-strong); }
.top-nav-item { flex: 0 0 auto; width: auto !important; padding: 0 16px !important; font-weight: 500 !important; transition: background 150ms, color 150ms !important; }
.top-nav-item.is-active { box-shadow: none !important; }
.view-panel { scroll-margin-top: 150px; }
.workspace-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.workspace-tabs { display: flex; padding: 4px; border: 1px solid var(--line); border-radius: 14px; background: var(--card-strong); }
.workspace-tabs button { border-radius: 10px; background: transparent; color: var(--muted); padding: 10px 20px; }
.workspace-tabs button.is-active { background: var(--theme-soft); color: var(--accent-strong); }
.workspace-hint, .draft-hint { font-size: 12px; color: var(--muted); }
.draft-hint { margin: -6px 0 0; }
.desktop-workbench { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-items: start; }
.workspace-inputs, .workspace-results { display: block; min-width: 0; }
.workspace-output { min-width: 0; display: grid; gap: 18px; }
.workspace-inactive { display: none !important; }
.workspace-assist { border: 1px solid var(--line); border-radius: 14px; background: color-mix(in srgb, var(--card) 90%, transparent); overflow: hidden; }
.workspace-assist > summary, .style-shelf > summary { padding: 14px 16px; cursor: pointer; color: var(--accent-strong); font-weight: 500; }
.workspace-assist .assist-card { margin: 0; border: 0; border-radius: 0; box-shadow: none; }
.workspace-empty { min-height: 240px; display: grid; place-items: center; padding: 32px; color: var(--muted); text-align: center; border: 1px dashed var(--line); border-radius: 14px; background: var(--theme-soft); }
.style-shelf { min-width: 0; }
.style-shelf > summary span { color: var(--muted); margin-left: 10px; font-size: 12px; font-weight: 400; }
.style-shelf #generate-style-library { border: 0; box-shadow: none; background: transparent; }
.style-shelf .style-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.desktop-dropzone { border: 1px dashed var(--line); border-radius: 14px; padding: 14px; transition: background 150ms, border-color 150ms; }
.desktop-dropzone small { color: var(--muted); }
.desktop-dropzone.is-dragging { background: var(--theme-soft); border-color: var(--accent); }
.keyboard-help { width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 40px); overflow: auto; padding: 26px; color: var(--ink); border: 1px solid var(--line); border-radius: 20px; background: var(--paper-strong); box-shadow: var(--shadow); }
.keyboard-help::backdrop { background: #16233266; }
.keyboard-help h2 { font-size: 22px; }
.keyboard-help dl { display: grid; grid-template-columns: max-content 1fr; gap: 14px 20px; font-size: 14px; }
.keyboard-help dd { margin: 0; color: var(--muted); }
.keyboard-help form { text-align: right; }
.desktop-tools { position: relative; font-size: 12px; }
.desktop-tools > summary { cursor: pointer; color: var(--accent-strong); padding: 7px 10px; border-radius: 12px; border: 1px solid var(--line); }
.desktop-tools-menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 170px; display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper-strong); box-shadow: var(--shadow); z-index: 20; }
.desktop-tools-menu a { padding: 6px 10px; }
.table-shell { overflow-x: auto; scrollbar-width: thin; border-radius: 14px; }
.table-shell table { min-width: 620px; }
#history-list { overflow: visible; gap: 16px; }
.history-record { padding: 18px; gap: 14px; background: var(--card-strong); }
.history-record > * { min-width: 0; }
.history-card-body { display: contents; }
.history-card-body > * { min-width: 0; order: 2; }
.history-card-body > header { order: 0; }
.history-record > .history-thumb { order: 1; }
.history-record header h4 { font-size: 15px; font-weight: 500; }
.history-record header .meta-line { font-size: 12px; gap: 4px 10px; }
.history-record .result-actions { gap: 7px; }
.history-record .mini-button { font-size: 12px; font-weight: 400; min-height: 38px; border-radius: 9px; padding: 7px 10px; border-color: var(--line); background: var(--theme-soft); backdrop-filter: none; }
.history-model-info { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }
.history-record .history-thumb { width: 100%; background: var(--theme-soft); border-radius: 12px; }
.history-record .history-thumb img { max-height: 240px; }
.history-record .prompt-disclosure { background: transparent; }
.history-record .prompt-disclosure summary { font-size: 13px; font-weight: 400; }
.history-record .prompt-block { font-size: 14px; line-height: 1.75; }
.history-record.has-error { border-color: color-mix(in srgb, var(--danger) 24%, var(--line)); }
.gallery-card { background: var(--card-strong); }
.gallery-card-body { padding: 16px; gap: 12px; align-content: start; }
.gallery-card .mini-button { font-size: 12px; font-weight: 400; padding: 7px 10px; border-radius: 9px; min-height: 38px; border-color: var(--line); backdrop-filter: none; }
.gallery-card .gallery-stat-row { gap: 6px; }
.gallery-card .gallery-stat-row .pill { padding: 3px 7px; font-size: 11px; font-weight: 400; background: var(--theme-soft); }
.gallery-thumb { min-height: 0; padding: 0; background: var(--theme-soft); }
.gallery-thumb img { object-fit: contain; }
.gallery-detail-body { gap: 18px; }
.gallery-detail-body .prompt-disclosure { background: var(--theme-soft); border-color: var(--line); }
.gallery-detail-body .prompt-block { color: var(--ink); }
#view-history > .section-card > .section-head { display: none; }
#gallery-list-page .section-head .eyebrow { display: none; }
#gallery-list-page .section-head h3 { font-size: 16px; font-weight: 500; }
#view-history > .section-card > .actions, #gallery-list-page > .section-card > .actions { align-items: center; justify-content: center; gap: 10px; }
#view-history > .section-card > .actions button, #gallery-list-page > .section-card > .actions button { min-height: 38px; padding: 7px 12px; border-radius: 9px; font-size: 13px; background: var(--theme-soft); color: var(--accent-strong); }
#history-page-info, #gallery-page-info { background: transparent; padding: 4px; font-size: 12px; color: var(--muted); }
@media (min-width: 761px) {
  #gallery-list, #history-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; align-items: start; }
  .gallery-card, .history-record.has-image { grid-template-columns: minmax(220px, 280px) minmax(0, 1fr); }
  .history-record.has-image { padding: 0; gap: 0; border-radius: 18px; overflow: hidden; }
  .history-record.has-image .history-card-body { display: grid; padding: 16px; gap: 12px; align-content: start; }
  .history-record.has-image .history-card-body > *, .history-record.has-image > .history-thumb { order: 0; }
  .gallery-thumb, .history-record.has-image .history-thumb { align-self: start; height: 300px; border: 0; border-radius: 18px 0 0 18px; }
  .gallery-thumb img, .history-record.has-image .history-thumb img { height: 300px; max-height: none; object-fit: contain; }
  .gallery-snippet, .history-record .prompt-block { font-size: 14px; line-height: 1.75; color: var(--ink); }
}
@media (min-width: 1700px) {
  #gallery-list, #history-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gallery-card, .history-record.has-image { grid-template-columns: minmax(180px, 220px) minmax(0, 1fr); }
}
.image-viewer-panel { display: flex; flex-direction: column; max-height: calc(100dvh - 40px); overflow: auto; background: var(--navigation-surface, var(--paper-strong)); color: var(--ink); }
.image-viewer-panel > * { flex: 0 0 auto; min-width: 0; }
.viewer-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; position: sticky; top: -18px; padding-block: 8px; margin-top: -8px; background: var(--navigation-surface, var(--paper-strong)); z-index: 3; }
.viewer-header > .viewer-close { margin-left: auto; }
.viewer-navigation[hidden] { display: none; }
.viewer-navigation { display: flex; align-items: center; gap: 8px; }
.viewer-image-stage { position: relative; min-width: 0; }
.viewer-image-stage .viewer-navigation { position: absolute; inset: 0; pointer-events: none; }
.viewer-image-stage .viewer-nav { position: absolute; top: 50%; width: 44px; min-height: 44px; height: 44px; padding: 0; display: grid; place-items: center; transform: translateY(-50%); border: 1px solid var(--line); border-radius: 50%; pointer-events: auto; font-size: 26px; font-weight: 400; line-height: 1; color: var(--accent-strong); background: var(--navigation-surface, var(--paper-strong)); box-shadow: 0 2px 8px #16233218; }
.viewer-image-stage .viewer-nav.prev { left: var(--viewer-image-inset, 10px); }
.viewer-image-stage .viewer-nav.next { right: var(--viewer-image-inset, 10px); }
.viewer-image-stage .viewer-nav:hover { transform: translateY(-50%); }
.viewer-header .viewer-nav, .viewer-header .viewer-close { position: static; min-height: 40px; padding: 8px 14px; transform: none; }
.viewer-header .viewer-nav:hover { transform: none; }
.image-viewer-panel figcaption { overflow-wrap: anywhere; max-height: 180px; }
.viewer-metadata { margin: 0 0 12px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.viewer-prompt-label { margin: 0 0 5px; font-size: 12px; color: var(--muted); }
.viewer-prompt { margin: 0; font-size: 14px; line-height: 1.75; color: var(--ink); white-space: pre-wrap; }
#viewer-viewport { position: relative; overflow: auto; min-height: 100px; max-height: calc(100dvh - 280px); overscroll-behavior: contain; border-radius: 14px; background: var(--theme-soft); }
.image-viewer.is-loading .image-viewer-panel figure::before, .image-viewer.is-broken .image-viewer-panel figure::before { display: none; }
.image-viewer.is-loading #viewer-viewport::before, .image-viewer.is-broken #viewer-viewport::before { content: '图片加载中…'; position: absolute; inset: 0; display: grid; place-items: center; z-index: 1; padding: 16px; text-align: center; font-size: 13px; color: var(--muted); background: var(--navigation-surface, var(--paper-strong)); pointer-events: none; }
.image-viewer.is-broken #viewer-viewport::before { content: '图片加载失败，请重试'; color: var(--danger); }
#viewer-image { display: block; max-width: none; max-height: none; margin-inline: auto; user-select: none; object-fit: contain; }
#viewer-image.is-zoomed { cursor: grab; }
#viewer-image.is-zoomed:active { cursor: grabbing; }
.viewer-zoom-controls { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }
.viewer-zoom-controls button { padding: 6px 12px; min-width: 38px; background: var(--theme-soft); color: var(--accent-strong); }
.viewer-zoom-controls span { color: var(--muted); font-size: 12px; }
.viewer-close, .viewer-nav { background: color-mix(in srgb, var(--accent-strong) 88%, #17212b); }
@media (min-width: 761px) {
  .prompt-disclosure { border: 0; background: transparent; overflow: visible; }
  .prompt-disclosure > summary { display: none; }
  .prompt-disclosure .prompt-block { max-height: none; overflow: visible; padding: 0; }
  .gallery-snippet { display: block; -webkit-line-clamp: unset; overflow: visible; white-space: pre-wrap; overflow-wrap: anywhere; }
}

@media (max-width: 760px) {
  #view-history > .section-card, #gallery-list-page > .section-card { padding: 16px; }
  #view-history .section-head .muted { display: none; }
  .history-toolbar, .gallery-toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .history-toolbar > label:first-child, .gallery-search { grid-column: 1 / -1; grid-row: 1; }
  .history-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .history-actions button { font-size: 12px; padding: 7px 10px; min-height: 38px; background: var(--theme-soft); color: var(--accent-strong); border-radius: 9px; }
  .history-record { padding: 12px; gap: 12px; }
  .history-record .history-thumb img { max-height: 260px; }
  .history-record .prompt-disclosure { border: 0; border-radius: 0; }
  .history-record .prompt-disclosure summary { padding: 4px 0; color: var(--accent-strong); }
  .history-record .prompt-block { padding: 8px 0 0; }
  .history-record .mini-button, .gallery-card .mini-button { min-height: 40px; padding: 8px 9px; }
  .gallery-card { display: grid; grid-template-columns: minmax(0, 1fr); }
  .gallery-thumb { width: 100%; border-radius: 16px 16px 0 0; }
  .gallery-thumb img { width: 100%; height: 230px; max-height: none; }
  .gallery-card-body { padding: 14px; }
  .image-viewer { padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); place-items: stretch; }
  .image-viewer-panel { width: 100%; height: 100%; min-height: 0; max-height: 100%; overflow: hidden; padding: 10px; gap: 8px; border-radius: 18px; }
  .image-viewer-panel > figure { flex: 1 1 auto; grid-auto-rows: max-content; overflow-y: auto; overscroll-behavior: contain; align-content: start; scrollbar-width: thin; }
  .viewer-header { position: static; gap: 8px; padding-block: 0; margin-top: 0; }
  .viewer-header .viewer-nav, .viewer-header .viewer-close { min-height: 40px; padding: 8px 10px; font-size: 12px; border-radius: 9px; background: var(--theme-soft); color: var(--accent-strong); }
  .viewer-image-stage { overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--theme-soft); }
  .viewer-image-stage .viewer-nav { width: 38px; height: 38px; min-height: 38px; font-size: 22px; background: color-mix(in srgb, var(--paper-strong) 88%, transparent); box-shadow: 0 2px 8px #16233222; }
  .viewer-image-stage .viewer-nav.prev { left: 8px; }
  .viewer-image-stage .viewer-nav.next { right: 8px; }
  #viewer-viewport { min-height: 180px; max-height: clamp(180px, 46dvh, 430px); border-radius: 0; }
  .image-viewer-panel figcaption { max-height: none; overflow: visible; }
  .viewer-zoom-controls span { display: none; }
  .viewer-zoom-controls { gap: 4px; }
  .viewer-zoom-controls button { min-height: 40px; padding: 4px 10px; font-size: 12px; border-radius: 9px; }
  .viewer-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; padding: 8px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .viewer-actions > * { display: flex; justify-content: center; align-items: center; min-height: 38px; width: 100%; font-size: 12px; font-weight: 400; line-height: 1.3; padding: 6px 8px; border: 1px solid var(--line); border-radius: 9px; color: var(--accent-strong); background: var(--theme-soft); backdrop-filter: none; }
  .viewer-actions > *:disabled, .viewer-actions > *[aria-disabled="true"] { opacity: .5; }
  .viewer-metadata { margin-bottom: 8px; font-size: 11px; }
  .viewer-prompt-label { margin-bottom: 5px; }
  .viewer-prompt { max-height: 24dvh; overflow-y: auto; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--theme-soft); font-size: 14px; line-height: 1.65; }
  .gallery-detail-body .mini-button { font-size: 12px; font-weight: 400; padding: 7px 10px; border-radius: 9px; min-height: 38px; backdrop-filter: none; }
  .gallery-detail-body .result-actions { gap: 6px; }
  .gallery-detail-body .prompt-disclosure[open] summary { display: none; }
  .gallery-detail-body .prompt-block { padding: 12px; font-size: 14px; line-height: 1.75; }
  .gallery-detail-page-card { padding: 16px; }
  .gallery-detail-page-card > .section-head .eyebrow { display: none; }
  .gallery-detail-page-card > .section-head h3 { font-size: 18px; font-weight: 500; }
  #gallery-detail-back, #gallery-comment-submit { min-height: 40px; font-size: 13px; padding: 8px 12px; border-radius: 9px; }
  .gallery-detail-preview img { max-height: clamp(180px, 45dvh, 360px); }
  .gallery-detail-body .comment-panel .empty-state { padding: 16px; }
}

@media (min-width: 900px) {
  .app-shell { grid-template-columns: 238px minmax(0, 1fr); gap: 20px; padding: 20px; max-width: 1920px; }
  .sidebar { position: sticky; top: 20px; max-height: calc(100dvh - 40px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; padding-right: 4px; grid-auto-rows: max-content; }
  .sidebar > * { padding: 16px; }
  .sidebar .brand { height: auto !important; min-height: max-content; justify-content: flex-start !important; }
  .sidebar h1 { font-size: 22px; margin-bottom: 6px; line-height: 1.4; }
  .sidebar h2 { font-size: 18px; overflow-wrap: anywhere; }
  .sidebar .muted { font-size: 12px; margin-bottom: 0; }
  #current-user-id { font-size: 10px; overflow-wrap: anywhere; margin: 6px 0 0; }
  .sidebar .eyebrow { font-size: 10px; }
  #nav-menu, .side-shortcuts { max-height: none; overflow: visible; }
  .side-shortcut { padding: 10px 12px; border-radius: 12px; }
  .side-shortcut strong { font-size: 13px; font-weight: 500; }
  .side-shortcut span { font-size: 11px; }
  .nav-item { padding: 9px 12px; min-height: 38px; border-radius: 10px; font-size: 13px; }
  .nav-menu { gap: 6px; }
  .quota-box { padding: 9px 10px; border-radius: 10px; }
  .quota-box strong { font-size: 12px; font-weight: 500; line-height: 1.6; }
  .topbar { position: sticky; top: 12px; z-index: 10; display: grid !important; grid-template-columns: minmax(0, 1fr) auto; height: auto !important; min-height: 0 !important; max-height: none !important; padding: 14px 20px !important; gap: 12px 16px; background: color-mix(in srgb, var(--paper-strong) 94%, transparent); }
  #view-title { font-size: 18px !important; white-space: normal; line-height: 1.4 !important; }
  .top-menu { grid-row: 2; grid-column: 1 / -1; justify-content: flex-start; height: auto; width: auto; overflow-x: auto; }
  .topbar-side { grid-column: 2; grid-row: 1; width: auto; flex-wrap: wrap; overflow: visible; gap: 8px; }
  .topbar .theme-select { min-width: 0; }
  .topbar .theme-select select { min-width: 90px; max-width: 130px; height: 34px; font-size: 12px; }
  .topbar #global-status { max-width: 210px; min-height: 30px; font-size: 12px; padding: 4px 10px; }
  .main-shell { gap: 18px; }
  .section-card { padding: 20px; }
  .two-column:not(.workspace-inputs):not(.workspace-results) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .desktop-workbench { grid-template-columns: minmax(360px, .95fr) minmax(0, 1.05fr); }
  .workspace-output { position: sticky; top: 146px; }
  .workspace-hint { display: none; }
  .workspace-results .result-grid { grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); }
  .workspace-results .result-grid.cols-1 { grid-template-columns: 1fr; }
  .workspace-results .result-card img { max-height: 430px; }
  .result-meta { font-size: 13px; }
  .result-actions { gap: 6px; }
  .gallery-toolbar, .history-toolbar, .admin-toolbar { grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); }
  .gallery-search { grid-column: auto; }
  .profile-overview-grid, .overview-grid { grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); }
}
@media (min-width: 1450px) {
  .app-shell { grid-template-columns: 260px minmax(0, 1fr); padding: 24px; gap: 24px; }
  .desktop-workbench { grid-template-columns: minmax(420px, .85fr) minmax(0, 1.15fr); gap: 24px; }
  .workspace-hint { display: inline; }
  .topbar #doc-link, .topbar #image-cache-clear { font-size: 12px; }
}
@media (max-width: 1100px) and (min-width: 900px) {
  .app-shell { grid-template-columns: 196px minmax(0, 1fr); padding: 14px; gap: 14px; }
  .desktop-workbench { grid-template-columns: 1fr; }
  .workspace-output { position: static; }
  .topbar #global-status { max-width: 130px; }
  .desktop-help { padding: 6px 10px; }
  .two-column:not(.workspace-inputs):not(.workspace-results) { grid-template-columns: 1fr; }
}
@media (max-width: 899px) {
  html { scroll-padding-top: 20px; }
  .workspace-hint, .draft-hint { font-size: 11px; }
  .desktop-help { display: none; }
  .keyboard-help dl { grid-template-columns: 1fr; gap: 6px; }
  .keyboard-help dd { margin-bottom: 10px; }
}
@media (hover: hover) and (pointer: fine) {
  .result-card:hover { border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
  .gallery-thumb img { transition: transform 180ms ease-out; }
  .gallery-thumb:hover img { transform: scale(1.025); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
