:root {
    color-scheme: light;
    --canvas: #f5f4ef;
    --paper: #fffef9;
    --ink: #222821;
    --muted: #62685f;
    --line: #dfdfd5;
    --accent: #dfed97;
    --accent-strong: #cddd76;
    --radius: 17px;
    font-family: Inter, system-ui, "Noto Sans CJK SC", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--canvas); }
a { color: inherit; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.75rem, 5vw, 2.75rem); font-weight: 700; letter-spacing: -.045em; line-height: 1.15; }
h2 { font-size: 1.08rem; font-weight: 690; }
:focus-visible { outline: 2px solid #516714; outline-offset: 3px; }

.site-header { border-bottom: 1px solid var(--line); background: var(--paper); }
.topbar { width: min(1200px, 100% - 48px); min-height: 65px; margin: auto; display: flex; align-items: center; gap: 30px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 720; text-decoration: none; white-space: nowrap; }
.brand-mark { position: relative; width: 29px; height: 29px; border-radius: 8px; background: var(--ink); }
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; background: var(--accent); border-radius: 3px; transform: rotate(-36deg); }
.brand-mark::before { left: 7px; top: 10px; width: 10px; height: 13px; }
.brand-mark::after { left: 16px; top: 6px; width: 7px; height: 8px; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { text-decoration: none; padding: 7px 13px; border-radius: 7px; color: var(--muted); font-size: .875rem; }
.topbar nav a:hover, .topbar nav a[aria-current] { color: var(--ink); background: #ecece2; }
.account { margin-inline-start: auto; display: flex; align-items: center; gap: 13px; min-width: 0; }
.account-name { max-width: 160px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .8rem; }

.container { width: min(1200px, 100% - 48px); margin: auto; padding: 47px 0 60px; }
.page-heading, .section-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.page-heading { margin-bottom: 28px; }
.workspace { display: grid; grid-template-columns: minmax(0, 1.08fr) minmax(0, 1fr); align-items: start; gap: 18px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
.settings, .output { padding: 22px; min-width: 0; }
.settings h2, .output h2 { margin-bottom: 19px; }
.field-label { display: flex; align-items: baseline; gap: 8px; margin-bottom: 7px; font-size: .87rem; font-weight: 640; }
.optional, .muted { font-size: .79rem; color: var(--muted); font-weight: 430; line-height: 1.5; }
.field, .reference-field, .settings textarea { margin-bottom: 16px; }
.settings-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
textarea, select, input[type="file"] { width: 100%; border: 1px solid var(--line); border-radius: 9px; background: #f9f9f3; color: var(--ink); font: inherit; }
textarea, select { padding: 11px 12px; font-size: .87rem; }
textarea { display: block; min-height: 110px; resize: vertical; }
select { min-height: 43px; }
textarea::placeholder { color: #72786e; }
input[type="file"] { padding: 6px; min-height: 45px; color: var(--muted); font-size: .79rem; }
input::file-selector-button { padding: 7px 9px; border: 0; border-radius: 5px; background: #ecece0; margin-right: 8px; font: inherit; color: var(--ink); cursor: pointer; }
.reference-field .muted { margin-top: 8px; }
button, .button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 39px; border: 1px solid transparent; border-radius: 8px; padding: 9px 14px; font: 650 .86rem/1.2 Inter, system-ui, "Noto Sans CJK SC", sans-serif; text-decoration: none; color: var(--ink); cursor: pointer; white-space: nowrap; }
button:disabled { cursor: default; opacity: .55; }
.primary { min-height: 45px; background: var(--accent); }
.primary:not(:disabled):hover { background: var(--accent-strong); }
.secondary { border-color: var(--line); background: var(--paper); }
.secondary:hover, .quiet:hover { background: #ecece0; }
.quiet { background: transparent; }
.generate { width: 100%; }
.htmx-indicator { display: none; }
.htmx-request.htmx-indicator { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: var(--muted); font-size: .8rem; }
.spinner { width: 13px; height: 13px; border: 2px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.notice { padding: 12px 13px; border: 1px solid #e8c9b4; background: #ffede3; color: #703a22; border-radius: 8px; font-size: .86rem; line-height: 1.5; }
.field .notice { margin-top: 9px; }

.output { display: flex; flex-direction: column; }
#result { display: flex; flex: 1; flex-direction: column; min-height: 260px; }
.output-empty, .output-image { display: grid; place-items: center; overflow: hidden; border-radius: 11px; flex: 1; background: #e9eae0; }
.output-empty {
    align-content: center; gap: 14px; color: var(--muted); font-size: .88rem;
    background-image: radial-gradient(#b5b9a9 1px, transparent 1px); background-size: 19px 19px;
}
.preview-mark { display: block; width: 42px; height: 35px; border: 1.5px solid #808973; border-radius: 6px; position: relative; background: #ebeee0; overflow: hidden; }
.preview-mark::before { content: ""; position: absolute; top: 6px; left: 8px; width: 6px; height: 6px; border: 1px solid #808973; border-radius: 50%; }
.preview-mark::after { content: ""; position: absolute; bottom: -13px; right: -3px; width: 31px; height: 31px; border: 1px solid #808973; background: #dce3c9; transform: rotate(45deg); border-radius: 4px; }
.output-image img { display: block; width: 100%; max-height: 550px; object-fit: contain; }
.result-caption { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 13px; }
.result-meta { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; font-size: .85rem; }

.history-area { margin-top: 34px; }
.history-empty { padding: 24px 0; color: var(--muted); font-size: .9rem; }
.history-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
.record { overflow: hidden; }
.record-image { display: block; aspect-ratio: 4 / 3; background: #e9eae0; }
.record-image img { display: block; width: 100%; height: 100%; object-fit: contain; }
.record-body { padding: 14px; overflow-wrap: anywhere; }
.record-model { font-weight: 660; margin-bottom: 4px; font-size: .92rem; }
.record details { margin: 10px 0; font-size: .84rem; }
.record summary { cursor: pointer; }
.saved-prompt { margin-top: 8px; white-space: pre-wrap; }
.record-links { display: flex; gap: 12px; flex-wrap: wrap; }
.text-link { color: #3e5313; font-size: .82rem; text-underline-offset: 3px; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 15px; margin-top: 22px; }

.login { width: min(1000px, 100% - 48px); margin: 0 auto; display: grid; grid-template-columns: minmax(0, .95fr) minmax(0, 1.05fr); gap: 32px; align-items: center; padding: 70px 0 45px; }
.login-intro { padding: 38px; min-height: 433px; display: flex; flex-direction: column; justify-content: flex-end; background: #242d22; color: #f5f6ed; border-radius: var(--radius); }
.login-intro p { margin-top: 13px; max-width: 285px; line-height: 1.7; color: #d2d8c8; font-size: .95rem; }
.login-art { height: 150px; width: 178px; position: relative; margin-bottom: auto; }
.login-art span { position: absolute; width: 96px; height: 112px; border-radius: 15px; border: 1.5px solid #d9e889; left: 28px; top: 10px; transform: rotate(-22deg); }
.login-art span:nth-child(2) { transform: rotate(1deg); background: #45503c; left: 39px; }
.login-art span:nth-child(3) { transform: rotate(24deg); background: var(--accent); left: 57px; }
.login-panel { padding: 24px; }
.login-panel h2, .login-panel .field-label { margin-bottom: 8px; }
.login-step { margin-bottom: 21px; }
.login-step p { margin-top: 7px; }
.login-panel button { width: 100%; }
.login-panel .notice { margin-bottom: 17px; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; padding: 11px; background: #eeefe5; border-radius: 7px; font-size: .76rem; line-height: 1.65; }

@media (max-width: 780px) {
    .workspace, .login { grid-template-columns: 1fr; }
    .container { padding-top: 30px; }
    .login { padding-top: 29px; gap: 16px; }
    .login-intro { min-height: 254px; padding: 25px; }
    .login-art { transform: scale(.62); transform-origin: top left; height: 95px; }
    .history-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 470px) {
    .topbar, .container, .login { width: calc(100% - 24px); }
    .topbar { gap: 9px; }
    .brand { gap: 6px; font-size: .85rem; }
    .topbar nav a, .quiet { padding-inline: 7px; }
    .account { gap: 2px; }
    .account-name { display: none; }
    .settings, .output { padding: 16px; }
    .history-grid { grid-template-columns: minmax(0, 1fr); }
}

.creation-column { display: grid; gap: 18px; min-width: 0; }
.discussion { padding: 22px; min-width: 0; }
.discussion-header, .settings-header { margin-bottom: 18px; }
.settings-header h2 { margin: 0; }
.model-tag { font-size: .76rem; color: #3e5313; background: #eef1dd; padding: 5px 8px; border-radius: 6px; }
.conversation-feed {
    display: flex; flex-direction: column; gap: 10px; min-height: 230px; max-height: 400px; overflow-y: auto;
    padding: 12px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 10px; background: #f8f8f1;
}
.conversation-empty { margin: auto; color: var(--muted); font-size: .9rem; text-align: center; padding: 12px; }
.message { max-width: 95%; padding: 10px 12px; border-radius: 8px; background: var(--paper); border: 1px solid var(--line); }
.message.user { align-self: flex-end; background: #e9efcf; border-color: #e5eacb; }
.message.assistant { align-self: flex-start; }
.message-author { font-size: .75rem; color: var(--muted); margin-bottom: 4px; }
.message-text, #draft-prompt { font-size: .88rem; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.draft-card { border: 1px solid #dce3bc; padding: 12px; margin-bottom: 16px; border-radius: 9px; background: #f0f3de; }
.draft-card h3 { margin: 0; font-size: .87rem; }
.draft-card button { min-height: 31px; padding: 5px 9px; }
#draft-prompt { max-height: 200px; overflow-y: auto; margin-top: 8px; }
#chat-error:not(:empty) { margin-bottom: 10px; }
.message-label { margin-top: 12px; }
.model-notice { margin-top: 5px; }
#chat-form textarea { margin-bottom: 10px; }
.chat-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.chat-actions .htmx-request.htmx-indicator { margin-top: 0; margin-right: auto; }
#image-form .notice { margin-bottom: 10px; }
.login-help { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 16px; font-size: .87rem; }
.login-help summary { cursor: pointer; color: var(--muted); }
.login-help .login-step { margin-top: 12px; margin-bottom: 0; }

@media (max-width: 470px) {
    .discussion { padding: 16px; }
}

.thread-heading { align-items: flex-start; }
.thread-heading h1 { overflow-wrap: anywhere; }
.thread-actions { display: flex; align-items: flex-start; gap: 8px; white-space: nowrap; }
.thread-switcher { position: relative; }
.thread-switcher summary { list-style: none; }
.thread-switcher summary::-webkit-details-marker { display: none; }
.thread-links {
    display: grid; gap: 4px; min-width: 245px; max-width: 310px; max-height: 300px; overflow: auto;
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 4;
    padding: 8px; background: var(--paper); border: 1px solid var(--line); border-radius: 9px;
    box-shadow: 0 6px 18px #31352718;
}
.thread-links a { padding: 8px; text-decoration: none; border-radius: 6px; font-size: .88rem; white-space: normal; overflow-wrap: anywhere; }
.thread-links a:hover, .thread-links a[aria-current] { background: #eef1dd; }
#activity:not(:empty), #form-error:not(:empty) { margin-bottom: 14px; }
.task-status { display: flex; align-items: center; gap: 9px; padding: 10px; color: var(--muted); font-size: .88rem; }
.message-attachments { margin: 8px 0 0; padding-left: 16px; overflow-wrap: anywhere; }
.message-refs { margin-top: 7px; }
.references { margin-bottom: 12px; padding: 11px; border: 1px solid var(--line); border-radius: 8px; }
.auto-reference { margin-bottom: 12px; padding: 10px 11px; background: #f7f7ef; border-radius: 8px; }
.auto-reference p { margin-top: 4px; }
.references summary, .version-entry summary { cursor: pointer; font-size: .86rem; }
.reference-note { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 8px 0; }
.reference-note label { white-space: nowrap; }
.reference-items { display: grid; gap: 6px; max-height: 300px; overflow: auto; }
.reference-item { display: flex; align-items: center; gap: 9px; background: #f7f7ef; border-radius: 6px; padding: 7px; }
.reference-thumb, .version-thumb { flex: 0 0 38px; width: 38px; height: 38px; }
.reference-thumb img, .version-thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 5px; }
.reference-info { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.reference-toggle { font-size: .78rem; white-space: nowrap; }
.image-help { margin-bottom: 10px; }
.empty-version { min-height: 240px; }
.version-entry {
    display: flex; gap: 10px; align-items: flex-start; margin-top: 10px;
    border-top: 1px solid var(--line); padding-top: 10px; font-size: .85rem;
}
.version-entry div { min-width: 0; flex: 1; }
.version-entry .button, .version-entry button { min-height: 32px; padding: 6px 9px; }
.version-source { display: block; margin-top: 4px; overflow-wrap: anywhere; }
@media (max-width: 575px) {
    .thread-heading { flex-wrap: wrap; }
    .thread-links { left: 0; right: auto; }
    .reference-item { gap: 4px; }
}

.numbered-image { position: relative; }
.numbered-image canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.annotation-legend {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    margin: 12px 0 0; padding: 0 0 0 23px; gap: 5px 16px; font-size: .82rem; color: var(--muted);
}
.annotation-legend[hidden] { display: none; }
.version-tools, .version-buttons { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.version-entry .version-buttons { flex: 0 0 auto; min-width: auto; }
.version-preview { margin: 4px 0; }
.version-preview .version-visual { margin-top: 7px; }
@media (max-width: 470px) {
    .version-tools button, .version-tools a, .version-buttons button { padding-inline: 6px; }
}

.discarded-versions { border-top: 1px solid var(--line); margin-top: 13px; padding-top: 12px; }
.discarded-versions summary { color: var(--muted); cursor: pointer; font-size: .85rem; }
.discarded-entry { display: flex; align-items: center; gap: 10px; padding-top: 8px; }
.discarded-entry button { margin-inline-start: auto; min-height: 32px; }

.embedded-review-warning { margin-bottom: 10px; }
