:root {
  --bg: #f3f1ec;
  --panel: #ffffff;
  --ink: #171816;
  --muted: #686d68;
  --line: #ddd9d1;
  --accent: #2f6651;
  --accent-2: #e6efe9;
  --warn: #8a2c2c;
  --shadow: 0 12px 30px rgba(25, 30, 27, .08);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--bg); }
button, textarea, input { font: inherit; }
button { cursor: pointer; }
.topbar { min-height: 92px; padding: 20px clamp(18px, 4vw, 52px); display: flex; align-items: center; justify-content: space-between; gap: 18px; background: #151a17; color: white; }
.topbar h1 { margin: 2px 0 0; font-size: clamp(24px, 3vw, 38px); letter-spacing: -.03em; }
.eyebrow { font-size: 11px; letter-spacing: .18em; color: #bcd0c5; font-weight: 800; }
.layout { width: min(1500px, calc(100% - 28px)); margin: 22px auto; display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.panel-title { min-height: 58px; padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.step { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; margin-right: 9px; color: white; background: var(--accent); font-size: 13px; }
.muted { color: var(--muted); font-size: 12px; }
.ghost { border: 1px solid rgba(255,255,255,.25); background: transparent; color: inherit; border-radius: 10px; padding: 8px 12px; text-decoration: none; }
.panel .ghost { border-color: var(--line); color: var(--ink); }
.source-picker-bar { padding: 14px 16px 0; }
.source-mode-tabs { display: inline-flex; padding: 4px; gap: 4px; background: #f5f4f0; border: 1px solid var(--line); border-radius: 999px; }
.mode-tab { border: 0; background: transparent; color: var(--muted); padding: 9px 14px; border-radius: 999px; font-weight: 700; }
.mode-tab.active { background: white; color: var(--ink); box-shadow: 0 3px 10px rgba(0,0,0,.06); }
.source-tip { margin-top: 9px; color: var(--muted); font-size: 12px; }
.source-body { padding: 14px 16px 0; }
.source-mode-panel { display: none; }
.source-mode-panel.active { display: block; }
.dropzone { position: relative; display: grid; min-height: 380px; background: #e8e5de; overflow: hidden; cursor: pointer; border-radius: 14px; }
.dropzone img { width: 100%; height: 100%; max-height: 580px; object-fit: contain; display: none; background: #161816; }
.drop-prompt { place-self: center; display: grid; gap: 6px; text-align: center; color: #40433f; padding: 20px; }
.drop-prompt span { font-size: 12px; color: var(--muted); }
.upload-icon { width: 58px; height: 58px; margin: 0 auto 6px; display: grid; place-items: center; border-radius: 50%; background: white; font-size: 28px; box-shadow: var(--shadow); }
.style-area { padding: 15px 16px 18px; }
.label { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: white; padding: 8px 10px; border-radius: 999px; }
.chip.active { background: var(--accent-2); border-color: #a8c2b6; color: #153d2e; font-weight: 700; }
.library-controls { margin-bottom: 14px; }
.library-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; max-height: 520px; overflow: auto; padding-right: 4px; }
.library-card { border: 1px solid var(--line); background: white; border-radius: 14px; padding: 0; text-align: left; overflow: hidden; transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease; }
.library-card:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.library-card.selected { border-color: #6fa088; box-shadow: 0 0 0 3px rgba(47,102,81,.12); }
.library-card img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; display: block; background: #ece9e2; }
.library-card-body { padding: 10px 11px 12px; }
.library-card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.library-card-top strong { font-size: 13px; line-height: 1.3; }
.library-card-body p { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.library-area { flex: 0 0 auto; font-size: 11px; font-weight: 800; color: var(--accent); background: var(--accent-2); padding: 4px 7px; border-radius: 999px; }
.library-empty { padding: 24px; border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); text-align: center; }
.chat-panel { display: flex; flex-direction: column; }
.ai-badge { font-size: 10px; letter-spacing: .1em; font-weight: 800; color: var(--accent); background: var(--accent-2); padding: 6px 8px; border-radius: 999px; }
.chat { padding: 15px; min-height: 320px; max-height: 470px; overflow: auto; display: flex; flex-direction: column; gap: 10px; background: #faf9f6; }
.bubble { max-width: 88%; padding: 11px 13px; border-radius: 14px; line-height: 1.42; white-space: pre-wrap; font-size: 14px; }
.bubble.assistant { align-self: flex-start; background: white; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.user { align-self: flex-end; background: #183f30; color: white; border-bottom-right-radius: 4px; }
.chat-form { display: grid; grid-template-columns: 1fr auto; gap: 9px; padding: 12px 14px; border-top: 1px solid var(--line); }
textarea, input { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 11px; background: white; color: var(--ink); outline: none; }
textarea:focus, input:focus { border-color: #83aa98; box-shadow: 0 0 0 3px rgba(47,102,81,.10); }
.primary { border: 0; background: var(--accent); color: white; border-radius: 10px; padding: 10px 16px; font-weight: 800; }
.primary:disabled, .render-btn:disabled { opacity: .5; cursor: not-allowed; }
.notes-box { margin: 0 14px 10px; border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; }
.notes-box summary { cursor: pointer; font-size: 13px; font-weight: 700; }
.notes-box textarea { margin-top: 9px; }
.render-row { padding: 12px 14px 15px; margin-top: auto; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.render-btn { flex: 0 0 auto; border: 0; background: #171816; color: white; border-radius: 12px; padding: 13px 18px; font-weight: 850; }
.result-panel { grid-column: 1 / -1; }
.result-stage { min-height: 520px; background: #181a18; position: relative; display: grid; place-items: center; }
.result-stage img { width: 100%; max-height: 820px; object-fit: contain; display: none; }
.result-empty, .spinner-wrap { color: #e9eee9; text-align: center; display: grid; gap: 7px; place-items: center; padding: 30px; }
.result-empty span, .spinner-wrap span { color: #aab3ad; font-size: 13px; }
.result-icon { font-size: 52px; color: #88a898; }
.spinner { width: 48px; height: 48px; border-radius: 50%; border: 4px solid rgba(255,255,255,.2); border-top-color: white; animation: spin 1s linear infinite; margin-bottom: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
.error { margin: 12px 14px 16px; padding: 12px; border-radius: 10px; background: #fff0f0; border: 1px solid #e2b7b7; color: var(--warn); font-size: 13px; }
.hidden { display: none !important; }
footer { padding: 10px 20px 30px; color: var(--muted); text-align: center; font-size: 11px; }
dialog { border: 0; border-radius: 16px; padding: 0; box-shadow: 0 20px 80px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog-card { width: min(420px, 90vw); padding: 22px; }
.dialog-card h2 { margin: 0 0 6px; }
.dialog-card p { color: var(--muted); line-height: 1.45; font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 13px; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .result-panel { grid-column: auto; }
  .dropzone { min-height: 300px; }
  .result-stage { min-height: 380px; }
  .panel-title { align-items: flex-start; }
  .library-grid { grid-template-columns: 1fr; max-height: 420px; }
}

.version-badge { display:inline-block; vertical-align:middle; margin-left:10px; padding:5px 8px; border-radius:999px; font-size:11px; letter-spacing:.04em; background:#e6efe9; color:#153d2e; font-weight:800; }
