:root {
    color-scheme: light;
    --paper: #f8f7f3;
    --surface: #fffefa;
    --ink: #211f25;
    --muted: #625d69;
    --line: #e1dce3;
    --control: #c5beca;
    --violet: #51368c;
    --violet-dark: #3f286f;
    --violet-soft: #eee7f8;
    --danger: #a12b3e;
    font-family: 'Inter', 'Microsoft YaHei UI', 'PingFang SC', system-ui, sans-serif;
    background: var(--paper);
    color: var(--ink);
    line-height: 1.5;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
h1, h2, h3, p, figure, pre { margin: 0; }
a { color: var(--violet); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .58; }
:focus-visible { outline: 2px solid var(--violet); outline-offset: 3px; }
.sr-only { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.topbar { border-bottom: 1px solid var(--line); background: var(--surface); }
.topbar-inner, .workspace { width: min(100% - 88px, 1440px); margin-inline: auto; }
.topbar-inner { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--ink); font-size: 15px; font-weight: 750; text-decoration: none; white-space: nowrap; }
.brand-mark { width: 32px; height: 32px; position: relative; flex: none; border-radius: 8px; background: var(--violet); }
.brand-mark::before, .brand-mark::after { content: ''; position: absolute; width: 12px; height: 15px; border: 1px solid var(--surface); border-radius: 2px; }
.brand-mark::before { top: 7px; left: 9px; transform: rotate(-13deg); }
.brand-mark::after { top: 11px; left: 13px; background: var(--violet); transform: rotate(10deg); }
.brand-separator { width: 1px; height: 16px; background: var(--control); }
.brand-section { font-size: 14px; color: var(--muted); font-weight: 550; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.actions.right { justify-content: flex-end; }

.button, .file-button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 8px 15px;
    border: 1px solid var(--control);
    border-radius: 8px;
    color: var(--ink);
    background: var(--surface);
    font-size: 14px;
    font-weight: 620;
    text-decoration: none;
    transition: border-color 160ms, background-color 160ms, color 160ms;
}
.button:not(:disabled):hover, .file-button:hover { border-color: var(--violet); color: var(--violet); }
.button-quiet { background: transparent; border-color: transparent; color: var(--muted); }
.button-quiet:not(:disabled):hover { border-color: transparent; background: var(--violet-soft); }
.button-primary { color: white; background: var(--violet); border-color: var(--violet); }
.button-primary:not(:disabled):hover { color: white; background: var(--violet-dark); }
.button-danger { color: var(--danger); }
.button-destructive, .button-destructive:not(:disabled):hover { background: var(--danger); border-color: var(--danger); color: white; }
.plus { font-size: 21px; font-weight: 500; line-height: 1; }

.workspace { padding: 43px 0 64px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; padding-bottom: 27px; border-bottom: 1px solid var(--line); }
h1 { font-size: clamp(28px, 3.3vw, 48px); line-height: 1.2; letter-spacing: -.045em; font-weight: 780; }
.library-summary { margin-top: 10px; color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
.library-layout { display: grid; grid-template-columns: 194px minmax(0, 1fr); gap: 29px; padding-top: 23px; }
.filters { align-self: start; }
.filters h2 { padding: 10px 12px 13px; color: var(--muted); font-size: 14px; font-weight: 700; }
.tag-list { display: grid; gap: 3px; }
.tag-filter {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 44px;
    padding: 6px 11px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--ink);
    font-size: 14px;
    text-align: left;
    transition: background-color 160ms;
}
.tag-filter:hover { background: #f0edf0; }
.tag-filter[aria-pressed='true'] { background: var(--violet-soft); color: var(--violet-dark); font-weight: 720; }
.tag-filter.active-group { color: var(--violet-dark); font-weight: 720; }
.subcategory-list { display: grid; gap: 2px; margin: 0 0 5px 12px; padding-inline-start: 7px; border-inline-start: 1px solid var(--line); }
.subcategory-list .tag-filter { gap: 6px; padding-inline: 8px; font-size: 13px; }
.tag-total { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.mobile-filter { display: none; }
.catalog-bar { min-height: 46px; margin-bottom: 17px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.results-heading { display: flex; align-items: baseline; gap: 9px; }
.results-heading h2 { font-size: 20px; line-height: 1.3; }
.result-count { flex: none; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.search-control { width: min(48%, 360px); display: flex; align-items: center; position: relative; }
.search-control input { padding-inline-start: 39px; }
.search-icon { width: 12px; height: 12px; border: 1.6px solid var(--muted); border-radius: 50%; position: absolute; left: 15px; pointer-events: none; }
.search-icon::after { content: ''; position: absolute; width: 6px; height: 1.5px; background: var(--muted); transform: rotate(45deg); top: 9px; left: 8px; }
input, textarea, select { width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid var(--control); border-radius: 8px; background: var(--surface); color: var(--ink); font-size: 16px; }
input::placeholder, textarea::placeholder { color: var(--muted); }
textarea { resize: vertical; }

.gallery { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 17px; }
.gallery-card {
    display: grid;
    grid-template-rows: auto 1fr;
    width: 100%;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 11px;
    overflow: hidden;
    background: var(--surface);
    color: var(--ink);
    text-align: left;
    transition: border-color 170ms, box-shadow 170ms;
}
.gallery-card:hover { border-color: #a58cbf; box-shadow: 0 4px 14px #51368c12; }
.card-cover { position: relative; display: grid; place-items: center; width: 100%; aspect-ratio: 3 / 4; overflow: hidden; background: #eeebe8; border-bottom: 1px solid var(--line); }
.card-cover img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; }
.card-cover-missing { color: var(--muted); font-size: 14px; }
.card-meta { display: grid; align-content: start; gap: 8px; padding: 12px 13px 14px; min-width: 0; }
.card-title { font-size: 16px; font-weight: 730; line-height: 1.4; overflow-wrap: anywhere; }
.pills { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }
.pill { padding: 3px 7px; max-width: 100%; border-radius: 5px; background: #f1edf3; color: #574b64; font-size: 12px; line-height: 1.4; overflow-wrap: anywhere; }
.pill:first-child { color: var(--violet-dark); background: var(--violet-soft); }
.empty-state { padding: 48px 18px; background: var(--surface); border: 1px dashed var(--control); border-radius: 10px; text-align: center; color: var(--muted); }
.pagination { display: flex; justify-content: center; align-items: center; margin-top: 28px; gap: 16px; color: var(--muted); font-size: 14px; }

dialog { max-height: min(90dvh, 940px); max-width: calc(100% - 28px); padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); box-shadow: 0 20px 75px #241a3733; overflow: auto; }
dialog::backdrop { background: #21182f85; }
.small-dialog { width: min(530px, 100%); }
.wide-dialog { width: min(1010px, 100%); }
.dialog-header, .dialog-footer { padding: 12px 24px; display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--surface); z-index: 1; }
.dialog-header { border-bottom: 1px solid var(--line); position: sticky; top: 0; }
.dialog-header h2 { font-size: clamp(19px, 2.7vw, 24px); line-height: 1.3; overflow-wrap: anywhere; }
.dialog-header button { flex: none; }
.dialog-body { display: grid; gap: 15px; padding: 20px 24px; }
.dialog-footer { border-top: 1px solid var(--line); position: sticky; bottom: 0; }
.editor-footer { justify-content: flex-end; flex-wrap: wrap; }
.editor-footer .feedback { flex: 1 1 250px; }
.detail-layout { grid-template-columns: minmax(0, .9fr) minmax(0, 1fr); gap: 25px; }
.detail-layout:has(.detail-media[hidden]) { grid-template-columns: 1fr; }
.detail-media, .detail-text, .fields { display: grid; align-content: start; gap: 14px; min-width: 0; }
.detail-text > p { color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.detail-media figure { border: 1px solid var(--line); border-radius: 8px; background: var(--paper); overflow: hidden; }
.detail-media img { display: block; width: 100%; max-height: 440px; object-fit: contain; }
.detail-media figcaption { padding: 8px 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.image-error { display: block; padding: 14px; color: var(--muted); }
.prompt-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.prompt-heading h3 { font-size: 16px; }
.prompt-text { padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; }
.editor-layout { grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: 22px; }
.field { display: grid; align-content: start; gap: 6px; font-size: 14px; font-weight: 650; min-width: 0; }
.field :is(input, textarea) { font-weight: 400; }
.image-field { display: grid; gap: 6px; }
.file-button { position: relative; justify-self: start; cursor: pointer; }
.file-button input { cursor: pointer; position: absolute; inset: 0; opacity: 0; }
.file-button:focus-within { outline: 2px solid var(--violet); outline-offset: 2px; }
.file-button:has(input:disabled) { opacity: .58; }
.cover-preview img { display: block; max-width: 100%; max-height: 120px; border: 1px solid var(--line); border-radius: 7px; }
.feedback { color: var(--violet-dark); font-size: 14px; overflow-wrap: anywhere; }
.feedback-error { color: var(--danger); }
.toast { position: fixed; right: 18px; bottom: 18px; max-width: calc(100% - 36px); padding: 11px 16px; border-radius: 8px; background: var(--ink); color: white; box-shadow: 0 4px 14px #211f2530; font-size: 14px; }

@media (max-width: 1180px) { .gallery { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 930px) {
    .topbar-inner, .workspace { width: calc(100% - 44px); }
    .library-layout { grid-template-columns: 156px minmax(0, 1fr); gap: 16px; }
    .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 650px) {
    .topbar-inner, .workspace { width: calc(100% - 28px); }
    .topbar-inner { min-height: 62px; gap: 8px; }
    .brand { gap: 6px; }
    .brand-section, .brand-separator { display: none; }
    .topbar .button { padding-inline: 9px; }
    .workspace { padding-top: 27px; }
    .page-heading { flex-wrap: wrap; padding-bottom: 17px; }
    .library-layout { grid-template-columns: 1fr; gap: 12px; padding-top: 15px; }
    .filters h2, .tag-list { display: none; }
    .mobile-filter { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
    .mobile-filter + .mobile-filter { margin-top: 8px; }
    .catalog-bar { align-items: stretch; flex-direction: column-reverse; margin-bottom: 12px; }
    .search-control { width: 100%; }
    .results-heading h2 { font-size: 17px; }
    .gallery { gap: 9px; }
    .card-meta { padding: 9px; }
    .detail-layout, .editor-layout { grid-template-columns: 1fr; }
    .dialog-body, .dialog-header, .dialog-footer { padding-inline: 14px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }
