:root {
  --paper: #f2f1ec;
  --panel: #fbfaf7;
  --ink: #181915;
  --muted: #74746c;
  --line: #d8d7d0;
  --accent: #e95f32;
  --accent-dark: #bd3d18;
  --moss: #66715a;
  --shadow: 0 22px 60px rgba(36, 33, 24, .12);
}

.reference-group { margin-top: 18px; }
.reference-paste { margin-top: 10px; padding: 14px 10px; border: 1px dashed var(--line); border-radius: 3px; background: #fff; color: var(--muted); font-size: 12px; line-height: 1.6; text-align: center; }
.reference-paste:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.reference-title { font-size: 12px !important; font-weight: 700; color: var(--ink) !important; }
#referencePreview:not([hidden]) { margin-top: 10px; display: grid; gap: 8px; }
.reference-item { padding: 8px; border: 1px solid var(--line); display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.reference-item img { width: 52px; height: 52px; object-fit: contain; background: #fff; }
.reference-item span { font-size: 11px; overflow-wrap: anywhere; }
.stepper button:disabled { opacity: .35; cursor: default; }

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif; letter-spacing: 0; }
button, textarea, select { font: inherit; }
button { color: inherit; }
button:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app-shell { min-height: 100vh; }
.topbar { height: 64px; padding: 0 24px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; background: rgba(242, 241, 236, .92); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(14px); }
.brand { display: inline-flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; font-size: 13px; font-weight: 800; }
.brand-mark { width: 25px; height: 25px; border: 1px solid var(--ink); display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 4px; transform: rotate(-3deg); }
.brand-mark span { background: var(--ink); }
.brand-mark span:nth-child(2) { background: var(--accent); }
.topbar-actions, .api-status, .canvas-actions { display: flex; align-items: center; }
.topbar-actions { gap: 12px; }
.api-status { gap: 8px; font-size: 12px; color: var(--muted); }
.status-dot { width: 7px; height: 7px; background: #b0afa8; border-radius: 50%; }
.api-status.ready .status-dot { background: #5d8b54; box-shadow: 0 0 0 4px rgba(93, 139, 84, .12); }
.api-status.error .status-dot { background: var(--accent); }
.icon-button { width: 38px; height: 38px; padding: 0; display: inline-grid; place-items: center; border: 1px solid var(--line); background: transparent; cursor: pointer; border-radius: 4px; transition: .2s ease; }
.icon-button:hover:not(:disabled) { background: #fff; border-color: #b6b4ac; }
.icon-button:disabled { opacity: .35; cursor: default; }
.icon-button svg { width: 17px; height: 17px; stroke-width: 1.8; }
.mobile-settings, .panel-close { display: none; }

.workspace { min-height: calc(100vh - 64px); display: grid; grid-template-columns: minmax(340px, 410px) 1fr; }
.control-panel { background: var(--panel); border-right: 1px solid var(--line); padding: 34px 30px 28px; overflow-y: auto; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 30px; }
.eyebrow, .empty-kicker { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; letter-spacing: 1.6px; color: var(--accent); font-weight: 700; }
h1 { font-family: Georgia, "Songti SC", serif; font-size: 30px; line-height: 1.18; font-weight: 500; margin: 9px 0 0; }
.field-group { min-width: 0; }
.field-group label, .field-label-row label, .preset-section label { font-size: 12px; font-weight: 700; }
.api-config { margin: -8px 0 24px; border: 1px solid var(--line); background: #f5f4ef; }
.api-config .config-heading { min-height: 43px; padding: 0 11px; display: grid; grid-template-columns: auto 1fr auto; gap: 9px; align-items: center; list-style: none; font-size: 11px; font-weight: 700; }
.api-config .config-heading::-webkit-details-marker { display: none; }
.api-config .config-heading > span:first-child { display: flex; align-items: center; gap: 7px; }
.api-config .config-heading svg { width: 14px; }
.api-config .summary-chevron { transition: transform .2s; }
.api-config[open] .summary-chevron { transform: rotate(180deg); }
.config-summary { min-width: 0; overflow: hidden; color: var(--muted); font-size: 10px; font-weight: 500; text-align: right; text-overflow: ellipsis; white-space: nowrap; }
.config-body { padding: 13px 11px 12px; border-top: 1px solid var(--line); display: grid; gap: 13px; background: #fff; }
.config-body input[type="url"], .key-input-wrap input { width: 100%; height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 3px; color: var(--ink); background: #fff; font-size: 11px; }
.key-input-wrap { position: relative; }
.key-input-wrap input { padding-right: 40px; }
.key-input-wrap button { width: 38px; position: absolute; top: 1px; right: 1px; bottom: 1px; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; }
.key-input-wrap button:hover { color: var(--ink); }
.key-input-wrap svg { width: 15px; }
.remember-row { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 10px; cursor: pointer; }
.remember-row input { accent-color: var(--moss); }
.field-label-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; }
.field-label-row > span { color: var(--muted); font-size: 10px; }
.prompt-box { border: 1px solid var(--line); background: #fff; transition: border .2s; }
.prompt-box:focus-within { border-color: var(--ink); }
textarea { width: 100%; min-height: 142px; display: block; border: 0; resize: vertical; padding: 14px 15px 8px; line-height: 1.7; color: var(--ink); background: transparent; font-size: 13px; }
textarea::placeholder { color: #aaa9a1; }
textarea:focus { outline: 0; }
.prompt-tools { border-top: 1px solid #eceae4; padding: 7px 8px; display: flex; justify-content: space-between; }
.quiet-button { border: 0; background: none; padding: 6px; display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); cursor: pointer; }
.quiet-button:hover { color: var(--ink); }
.quiet-button svg { width: 13px; height: 13px; }
.preset-section { margin-top: 22px; }
.style-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.style-chips button { padding: 8px 10px; border: 1px solid var(--line); background: transparent; border-radius: 3px; font-size: 11px; cursor: pointer; }
.style-chips button:hover, .style-chips button.active { color: #fff; background: var(--moss); border-color: var(--moss); }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 12px; margin-top: 24px; }
.span-2 { grid-column: 1 / -1; }
.field-group > label { display: block; margin-bottom: 8px; }
.select-wrap { position: relative; }
select { appearance: none; width: 100%; height: 42px; padding: 0 35px 0 11px; border: 1px solid var(--line); background: #fff; border-radius: 3px; color: var(--ink); font-size: 12px; cursor: pointer; }
.select-wrap svg { pointer-events: none; position: absolute; right: 10px; top: 50%; width: 15px; transform: translateY(-50%); color: var(--muted); }
.stepper { height: 42px; display: grid; grid-template-columns: 40px 1fr 40px; border: 1px solid var(--line); background: #fff; border-radius: 3px; }
.stepper button { border: 0; background: transparent; display: grid; place-items: center; cursor: pointer; }
.stepper button:hover { background: #f2f1ec; }
.stepper svg { width: 14px; }
.stepper output { display: grid; place-items: center; border-left: 1px solid var(--line); border-right: 1px solid var(--line); font-size: 12px; font-weight: 700; }
.toggle-row { margin: 20px 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; cursor: pointer; }
.toggle-row strong { display: block; font-size: 12px; }
.toggle-row small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.toggle { width: 38px; height: 22px; position: relative; flex: 0 0 auto; }
.toggle input { opacity: 0; position: absolute; }
.toggle span { inset: 0; position: absolute; background: #c9c8c1; border-radius: 12px; transition: .2s; }
.toggle span::after { content: ""; width: 16px; height: 16px; position: absolute; top: 3px; left: 3px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px #777; transition: .2s; }
.toggle input:checked + span { background: var(--moss); }
.toggle input:checked + span::after { transform: translateX(16px); }
.generate-button { width: 100%; height: 52px; padding: 0 14px 0 17px; display: flex; align-items: center; justify-content: space-between; border: 0; border-radius: 3px; background: var(--accent); color: #fff; cursor: pointer; font-size: 13px; font-weight: 750; box-shadow: 0 8px 24px rgba(233, 95, 50, .2); transition: .2s; }
.generate-button:hover { background: var(--accent-dark); transform: translateY(-1px); }
.generate-button:disabled { cursor: wait; opacity: .7; transform: none; }
.generate-button > span { display: flex; align-items: center; gap: 9px; }
.generate-button svg { width: 17px; }
.generate-button kbd { font-family: inherit; font-size: 10px; font-weight: 500; color: rgba(255,255,255,.7); background: rgba(0,0,0,.12); padding: 4px 6px; border-radius: 3px; }

.canvas-area { min-width: 0; position: relative; display: flex; flex-direction: column; }
.canvas-toolbar { min-height: 61px; padding: 0 28px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.view-tabs { align-self: stretch; display: flex; gap: 25px; }
.view-tabs button { position: relative; border: 0; background: none; padding: 0; color: var(--muted); cursor: pointer; font-size: 12px; }
.view-tabs button.active { color: var(--ink); font-weight: 700; }
.view-tabs button.active::after { content: ""; height: 2px; position: absolute; bottom: -1px; left: 0; right: 0; background: var(--accent); }
.view-tabs span { min-width: 18px; display: inline-block; padding: 2px 5px; margin-left: 3px; border-radius: 10px; background: #dddbd4; color: var(--muted); font-size: 9px; }
.canvas-actions { gap: 8px; }
.gallery { padding: clamp(22px, 4vw, 54px); display: grid; grid-template-columns: repeat(auto-fill, min(100%, 320px)); gap: 20px; align-content: start; flex: 1; }
.empty-state { grid-column: 1 / -1; min-height: calc(100vh - 180px); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.empty-visual { width: min(330px, 70vw); aspect-ratio: 1.35; position: relative; margin-bottom: 29px; background: #d9ddd2; overflow: hidden; box-shadow: var(--shadow); }
.empty-visual::before { content: ""; position: absolute; width: 70%; height: 85%; left: -10%; bottom: -45%; background: #89977a; transform: rotate(18deg); }
.empty-visual::after { content: ""; position: absolute; width: 65%; height: 72%; right: -14%; bottom: -35%; background: #5e6d59; transform: rotate(-21deg); }
.frame { position: absolute; z-index: 2; background: #eeeae0; box-shadow: 0 8px 20px rgba(43,45,36,.18); }
.frame-one { width: 18%; height: 61%; left: 39%; bottom: 12%; transform: skewY(-8deg); }
.frame-two { width: 31%; height: 35%; left: 51%; bottom: 19%; transform: skewY(8deg); background: #c9c4b8; }
.sun { width: 42px; height: 42px; position: absolute; top: 20%; right: 23%; border-radius: 50%; background: var(--accent); }
.grain { position: absolute; inset: 0; z-index: 4; opacity: .2; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.3'/%3E%3C/svg%3E"); }
.empty-kicker { color: var(--moss); }
.empty-state h2 { margin: 8px 0 7px; font-family: Georgia, "Songti SC", serif; font-size: 26px; font-weight: 500; }
.empty-state > p:last-child { max-width: 330px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.7; }
.art-card { min-width: 0; position: relative; margin: 0; background: #e4e2db; overflow: hidden; box-shadow: 0 13px 38px rgba(32,31,27,.12); }
.art-card img { display: block; width: 100%; height: auto; min-height: 250px; object-fit: cover; }
.art-card .card-overlay { position: absolute; inset: auto 0 0; padding: 40px 13px 12px; display: flex; justify-content: flex-end; gap: 7px; opacity: 0; transform: translateY(8px); background: linear-gradient(transparent, rgba(0,0,0,.55)); transition: .2s; }
.art-card:hover .card-overlay, .art-card:focus-within .card-overlay { opacity: 1; transform: none; }
.card-overlay button { width: 37px; height: 37px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.55); border-radius: 3px; background: rgba(20,20,18,.62); color: #fff; cursor: pointer; backdrop-filter: blur(8px); }
.card-overlay button:hover { background: var(--accent); border-color: var(--accent); }
.card-overlay svg { width: 16px; }
.loading-state { position: absolute; inset: 61px 0 0; z-index: 5; align-items: center; justify-content: center; gap: 22px; background: rgba(242,241,236,.93); backdrop-filter: blur(6px); }
.loading-state:not([hidden]) { display: flex; }
.loading-state strong { font-family: Georgia, "Songti SC", serif; font-size: 20px; font-weight: 500; }
.loading-state p { margin: 6px 0 0; color: var(--muted); font-size: 11px; }
.loading-art { width: 82px; height: 82px; position: relative; }
.loading-art span { width: 52px; height: 64px; position: absolute; left: 15px; top: 9px; border: 1px solid var(--ink); animation: shuffle 2.4s infinite ease-in-out; }
.loading-art span:nth-child(2) { border-color: var(--accent); animation-delay: -.8s; }
.loading-art span:nth-child(3) { border-color: var(--moss); animation-delay: -1.6s; }
@keyframes shuffle { 0%,100% { transform: rotate(-7deg) translate(-5px,3px); } 50% { transform: rotate(8deg) translate(7px,-3px); } }
.toast { position: fixed; z-index: 50; top: max(16px, env(safe-area-inset-top)); left: 50%; width: max-content; max-width: min(390px, calc(100vw - 32px)); padding: 12px 15px; color: #fff; background: #25251f; border-left: 3px solid var(--accent); border-radius: 3px; box-shadow: var(--shadow); font-size: 12px; line-height: 1.55; text-align: center; overflow-wrap: anywhere; opacity: 0; pointer-events: none; transform: translate(-50%, -12px); transition: opacity .25s, transform .25s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 330px 1fr; }
  .control-panel { padding: 28px 22px; }
}

@media (max-width: 700px) {
  .topbar { height: 58px; padding: 0 15px; }
  .api-status { display: none; }
  .mobile-settings { display: inline-grid; }
  .workspace { min-height: calc(100vh - 58px); display: block; }
  .control-panel { width: min(92vw, 390px); position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; padding: 26px 22px; border: 0; box-shadow: var(--shadow); transform: translateX(-105%); transition: transform .25s ease; }
  .control-panel.open { transform: none; }
  .panel-close { display: inline-grid; }
  .canvas-toolbar { min-height: 56px; padding: 0 15px; }
  .gallery { padding: 18px 15px 30px; gap: 14px; }
  .empty-state { min-height: calc(100vh - 150px); }
  .empty-visual { width: min(280px, 76vw); }
  .loading-state { inset: 56px 0 0; }
  .art-card img { min-height: 200px; }
  .art-card .card-overlay { opacity: 1; transform: none; }
}

#generateForm > .generate-button { margin-top: 16px; margin-bottom: 28px; }
.detect-button { border: 1px solid var(--line); border-radius: 3px; padding: 6px 8px; background: #fff; font-size: 11px; cursor: pointer; }
.detect-button:disabled { opacity: .5; cursor: wait; }
.setting-hint { display: block; color: var(--muted); font-size: 10px; line-height: 1.6; margin-top: 7px; }

.brand-tagline { font-size: 11px; font-weight: 400; color: var(--muted); }
.panel-heading { display: none; }
@media (max-width: 700px) { .panel-heading { display: flex; justify-content: flex-end; margin-bottom: 14px; } .brand { gap: 7px; } .brand-tagline { font-size: 10px; } }

.api-config summary.config-heading { cursor: pointer; }
.api-config[open] summary.config-heading > svg { transform: rotate(180deg); }

.key-save-row { display: flex; gap: 8px; align-items: stretch; }
.key-save-row .key-input-wrap { flex: 1; min-width: 0; }
.save-key-button { flex: 0 0 auto; padding: 0 13px; border: 0; border-radius: 3px; background: var(--moss); color: #fff; font: inherit; font-size: 12px; cursor: pointer; }
.save-key-button:hover { filter: brightness(.9); }

.key-input-wrap #toggleKey { width: 48px; font-size: 10px; }
.key-input-wrap input { padding-right: 50px; }

.image-preview { width: min(1200px, 96vw); height: 92vh; height: 92dvh; max-width: 96vw; max-height: 94vh; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); color: var(--ink); }
.image-preview::backdrop { background: rgba(0,0,0,.78); }
.preview-toolbar { height: 56px; display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--line); font-size: 13px; }
.preview-toolbar > span { flex: 1; }
.preview-toolbar button { padding: 7px 12px; border: 1px solid var(--line); border-radius: 3px; background: var(--panel); cursor: pointer; }
.preview-content { height: calc(100% - 56px); overflow: auto; display: flex; padding: 12px; }
.preview-content img { display: block; margin: auto; max-width: 100%; max-height: 100%; object-fit: contain; }
.preview-content.original-size img { max-width: none; max-height: none; flex-shrink: 0; }

.storage-notice { position: sticky; top: 64px; z-index: 6; margin: 0; padding: 14px 24px; background: var(--paper); color: var(--muted); font-size: 12px; line-height: 1.7; text-align: center; overflow-wrap: anywhere; }
@media (max-width: 700px) { .storage-notice { top: 58px; padding: 12px 15px; } }
