:root {
  color-scheme: light;
  --ink: #241e1b;
  --muted: #8a7870;
  --line: #e8ddd5;
  --paper: #fffaf6;
  --ground: #f5eee8;
  --accent: #e54738;
  --accent-dark: #b92b25;
  --coral-soft: #f7d4ca;
  --mustard: #d9a73d;
  --teal: #3e756e;
  --danger: #b82f2a;
  --shadow: 0 20px 55px rgba(95, 53, 39, .10);
  font-family: "Noto Sans SC", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--ground); color: var(--ink); }
button, textarea, input, select { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: wait; opacity: .6; }
button:focus-visible, textarea:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

.app-shell { display: grid; grid-template-columns: minmax(370px, 430px) minmax(0, 1fr); min-height: 100vh; }
.control-panel { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--paper); border-right: 1px solid var(--line); }
.brand-row { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; gap: 12px; align-items: center; min-height: 78px; padding: 16px 25px; border-bottom: 1px solid var(--line); }
.brand-mark { display: grid; width: 42px; height: 42px; place-items: center; background: var(--accent); color: #fffaf6; border-radius: 12px 12px 12px 3px; font: 800 24px/1 "DM Mono", monospace; transform: rotate(-5deg); }
.brand-copy strong { display: block; font: 800 15px/1.1 "DM Mono", monospace; letter-spacing: .08em; }
.brand-copy span { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
.api-state { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font: 500 10px/1 "DM Mono", monospace; white-space: nowrap; }
.api-state i { width: 7px; height: 7px; border-radius: 50%; background: var(--mustard); }
.api-state.ready i { background: var(--teal); box-shadow: 0 0 0 4px rgba(62, 117, 110, .12); }
.api-state.error i { background: var(--danger); }
.controls { padding: 22px 25px 18px; }
.intro-line, .section-label, .gallery-header, .gallery-actions, .panel-footer, .dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.eyebrow { color: var(--muted); font: 500 10px/1.2 "DM Mono", monospace; letter-spacing: .11em; text-transform: uppercase; }
.size-badge { padding: 5px 8px; border: 1px solid var(--line); color: var(--accent-dark); background: #fff3ee; font: 500 10px/1 "DM Mono", monospace; }
h1 { max-width: 340px; margin: 18px 0 7px; font-size: clamp(28px, 3vw, 38px); line-height: 1.18; letter-spacing: 0; }
h1 em { color: var(--accent); font-style: normal; }
.lede { max-width: 335px; margin: 0 0 24px; color: var(--muted); font-size: 13px; line-height: 1.8; }
.panel-section { padding: 20px 0; border-top: 1px solid var(--line); }
.section-label { margin-bottom: 12px; color: var(--ink); font-size: 12px; font-weight: 700; }
.section-label > span:last-child { color: var(--muted); font: 400 10px/1.2 "DM Mono", monospace; }
.mode-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.mode-tabs button { min-height: 84px; padding: 11px 9px; text-align: left; border: 1px solid var(--line); border-radius: 4px; background: #fffdfb; transition: border-color .18s, background .18s, transform .18s; }
.mode-tabs button:hover { transform: translateY(-2px); border-color: var(--accent); }
.mode-tabs button.active { border-color: var(--accent); background: var(--accent); color: #fffaf6; box-shadow: 0 8px 20px rgba(229, 71, 56, .16); }
.mode-tabs span, .mode-tabs small { display: block; font: 500 9px/1.2 "DM Mono", monospace; color: var(--muted); }
.mode-tabs button.active span, .mode-tabs button.active small { color: #ffd9d0; }
.mode-tabs strong { display: block; margin: 8px 0 5px; font-size: 13px; }
.reference-slots { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.reference-slot { display: block; min-height: 104px; padding: 13px; border: 1px dashed #d9c5ba; border-radius: 4px; background: #fffdfb; transition: background .18s, border-color .18s; }
.reference-slot:hover { border-color: var(--accent); background: #fff2ed; }
.slot-icon { display: grid; width: 24px; height: 24px; margin-bottom: 13px; place-items: center; border: 1px solid currentColor; color: var(--accent); font-size: 15px; }
.reference-slot strong, .reference-slot small { display: block; }
.reference-slot strong { font-size: 12px; }
.reference-slot small { margin-top: 5px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.reference-list { display: grid; gap: 6px; margin-top: 8px; }
.reference-card { display: grid; grid-template-columns: 36px minmax(0, 1fr) 25px; align-items: center; gap: 8px; padding: 6px; border: 1px solid var(--line); background: #fff; }
.reference-card img { width: 36px; height: 46px; object-fit: cover; }
.reference-card strong, .reference-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reference-card strong { font-size: 11px; }
.reference-card small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.reference-card button, .dialog-close { width: 25px; height: 25px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 20px; line-height: 1; }
.field-label { display: block; margin-top: 10px; color: var(--muted); font-size: 10px; }
.field-label input, .field-label textarea, .select-control, .channel-fields input { display: block; width: 100%; margin-top: 6px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 3px; outline: 0; background: #fff; color: var(--ink); font-size: 13px; resize: vertical; }
.field-label input:focus, .field-label textarea:focus, .select-control:focus, .channel-fields input:focus { border-color: var(--accent); }
.text-button { padding: 0; border: 0; background: transparent; color: var(--accent-dark); font-size: 10px; }
.upload-text-button { width: 100%; margin-top: 8px; padding: 9px; border: 1px solid var(--line); background: #fff; color: var(--accent-dark); font-size: 11px; }
.page-plan { display: grid; gap: 5px; margin-top: 10px; }
.page-chip { display: grid; grid-template-columns: 25px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 7px 8px; border-left: 3px solid var(--coral-soft); background: #fffaf6; }
.page-chip b { color: var(--accent); font: 500 10px/1 "DM Mono", monospace; }
.page-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.page-chip small, .plan-empty { color: var(--muted); font-size: 9px; }
.plan-empty { margin: 8px 0 0; line-height: 1.5; }
.style-section .select-control { margin-top: 0; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; background: #f0e7e0; }
.segmented button { padding: 8px; border: 0; background: transparent; font: 500 11px/1 "DM Mono", monospace; }
.segmented button.active { background: var(--ink); color: #fffaf6; }
.ratio-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-top: 8px; }
.ratio-grid button { padding: 8px 4px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: 600 11px/1.1 "DM Mono", monospace; }
.ratio-grid button.active { border-color: var(--accent); color: var(--accent-dark); background: #fff1ec; }
.ratio-grid small { display: block; margin-top: 4px; color: var(--muted); font: 400 8px/1 "DM Mono", monospace; }
.check-row { display: grid; grid-template-columns: 16px auto; align-items: center; column-gap: 8px; margin-top: 10px; font-size: 11px; }
.check-row input { accent-color: var(--accent); }
.check-row small { grid-column: 2; margin-top: 3px; color: var(--muted); font-size: 9px; }
.generate-button { display: flex; width: 100%; align-items: center; justify-content: space-between; margin-top: 18px; padding: 15px 16px; border: 0; border-radius: 4px; background: var(--accent); color: #fffaf6; font-size: 13px; font-weight: 800; box-shadow: 0 10px 24px rgba(229, 71, 56, .22); }
.generate-button:hover { background: var(--accent-dark); }
.generate-button b { color: #ffd5cc; font: 500 10px/1 "DM Mono", monospace; }
.form-error { margin: 10px 0 0; color: var(--danger); font-size: 11px; line-height: 1.5; }
.privacy-note { margin: 14px 0 0; color: var(--muted); font-size: 9px; line-height: 1.5; }
.panel-footer { position: sticky; bottom: 0; padding: 13px 25px; border-top: 1px solid var(--line); background: rgba(255,250,246,.96); color: var(--muted); font: 500 9px/1 "DM Mono", monospace; }
.settings-link { padding: 0; border: 0; background: transparent; color: var(--accent-dark); font-size: 10px; }

.gallery-area { min-width: 0; padding: 38px clamp(22px, 5vw, 76px) 55px; }
.gallery-header { align-items: end; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.gallery-header h2 { margin: 8px 0 0; font-size: 26px; }
.gallery-actions { color: var(--muted); font: 500 10px/1 "DM Mono", monospace; }
.clear-button { padding: 7px 10px; border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 10px; }
.status-strip { display: grid; grid-template-columns: auto minmax(80px, 1fr) auto; gap: 16px; align-items: center; margin: 20px 0; padding: 13px 16px; border: 1px solid var(--line); background: #fffaf6; }
.status-strip strong, .status-strip span { display: block; }
.status-strip strong { font-size: 11px; }
.status-strip span, .status-strip time { color: var(--muted); font: 500 10px/1.4 "DM Mono", monospace; }
.progress-track { height: 5px; overflow: hidden; background: #eaded6; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .25s; }
.empty-state { display: grid; min-height: 55vh; place-items: center; align-content: center; padding: 50px 18px; text-align: center; }
.empty-mark { display: grid; width: 100px; height: 130px; margin-bottom: 24px; place-items: center; border: 1px solid #d9beb2; border-radius: 50px 50px 14px 14px; color: var(--accent); font: 500 15px/1 "DM Mono", monospace; transform: rotate(-7deg); }
.empty-state h3 { margin: 14px 0 8px; font-size: 25px; }
.empty-state p { max-width: 400px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.8; }
.empty-steps { display: flex; flex-wrap: wrap; justify-content: center; gap: 18px; margin-top: 24px; color: var(--muted); font-size: 10px; }
.empty-steps b { margin-right: 4px; color: var(--accent); font: 500 10px/1 "DM Mono", monospace; }
.result-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(205px, 1fr)); gap: 18px; }
.batch-header { grid-column: 1 / -1; display: flex; align-items: end; justify-content: space-between; gap: 15px; padding: 16px 0 2px; border-bottom: 1px solid var(--line); }
.batch-header strong, .batch-header p { display: block; margin: 7px 0 0; }
.batch-header strong { font-size: 12px; }
.batch-header p { max-width: 480px; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.result-card { overflow: hidden; border: 1px solid var(--line); background: #fffaf6; box-shadow: var(--shadow); }
.result-media { position: relative; aspect-ratio: var(--ratio); overflow: hidden; background: #eee4dd; }
.result-media img { display: block; width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.result-number { position: absolute; z-index: 1; top: 10px; left: 10px; padding: 4px 6px; background: rgba(36,30,27,.72); color: #fffaf6; font: 500 9px/1 "DM Mono", monospace; }
.result-info { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 7px; align-items: center; padding: 10px; }
.result-info strong, .result-info small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-info strong { font-size: 11px; }
.result-info small { margin-top: 4px; color: var(--muted); font: 400 9px/1 "DM Mono", monospace; }
.time-tag { color: var(--accent-dark); font: 500 9px/1 "DM Mono", monospace; white-space: nowrap; }
.result-actions { display: flex; gap: 3px; }
.result-actions button { width: 22px; height: 22px; padding: 0; border: 1px solid var(--line); background: #fff; color: var(--muted); font-size: 14px; }
.loading-mark, .error-mark { display: grid; height: 100%; place-items: center; align-content: center; color: var(--muted); }
.loading-mark i { width: 26px; height: 26px; border: 2px solid #d2c2ba; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.loading-mark span { margin-top: 12px; font: 500 9px/1 "DM Mono", monospace; }
.error-mark { padding: 18px; text-align: center; }
.error-mark strong { color: var(--danger); font-size: 12px; }
.error-mark p { margin: 8px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
@keyframes spin { to { transform: rotate(360deg); } }

dialog { color: var(--ink); }
.preview-dialog { width: min(86vw, 520px); padding: 18px; border: 1px solid var(--line); background: var(--paper); box-shadow: var(--shadow); }
.preview-dialog::backdrop, .channel-dialog::backdrop { background: rgba(36,30,27,.42); }
.preview-dialog img { display: block; max-width: 100%; max-height: 74vh; margin: 0 auto; object-fit: contain; }
.preview-dialog p { margin: 10px 0 0; color: var(--muted); font: 500 10px/1.4 "DM Mono", monospace; }
.preview-dialog .dialog-close { position: absolute; top: 8px; right: 8px; }
.channel-dialog { width: min(720px, calc(100vw - 30px)); max-height: 88vh; overflow: auto; padding: 25px; border: 1px solid var(--line); background: var(--paper); }
.dialog-heading h2 { margin: 7px 0 0; font-size: 22px; }
.dialog-note { margin: 15px 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.saved-channels { display: grid; gap: 7px; margin-bottom: 22px; }
.saved-channel { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 7px; align-items: center; padding: 10px; border: 1px solid var(--line); background: #fff; }
.saved-channel.active { border-color: var(--accent); }
.saved-channel strong, .saved-channel small { display: block; }
.saved-channel strong { font-size: 12px; }
.saved-channel small { margin-top: 4px; color: var(--muted); font: 400 9px/1 "DM Mono", monospace; }
.saved-channel button, .secondary-button { padding: 7px 10px; border: 1px solid var(--line); background: #fffaf6; color: var(--accent-dark); font-size: 10px; }
.channel-dialog h3 { margin: 0 0 12px; font-size: 13px; }
.channel-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.channel-fields label { color: var(--muted); font-size: 10px; }
.channel-fields input { margin-top: 5px; }
.channel-dialog .secondary-button { margin-top: 14px; background: var(--accent); color: #fff; }

@media (max-width: 900px) {
  .app-shell { display: block; }
  .control-panel { position: relative; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .panel-footer { position: relative; }
  .gallery-area { padding-top: 28px; }
}
@media (max-width: 540px) {
  .brand-row, .controls { padding-left: 17px; padding-right: 17px; }
  .gallery-area { padding: 24px 15px 38px; }
  .brand-row { grid-template-columns: 38px minmax(0, 1fr) auto; }
  .brand-mark { width: 38px; height: 38px; font-size: 21px; }
  h1 { font-size: 29px; }
  .mode-tabs button { min-height: 76px; padding: 9px 6px; }
  .mode-tabs strong { font-size: 11px; }
  .reference-slots { grid-template-columns: 1fr; }
  .status-strip { grid-template-columns: 1fr auto; }
  .progress-track { grid-column: 1 / -1; grid-row: 2; }
  .batch-header { display: block; }
  .result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .result-info { grid-template-columns: 1fr auto; }
  .result-info .result-actions { grid-column: 1 / -1; }
  .channel-fields { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; } }
