:root {
  --bg: #f4efe6;
  --panel: #ffffff;
  --ink: #1a1712;
  --muted: #7a7266;
  --line: #e3dccf;
  --gold: #c9922a;
  --pink: #e0447d;
  --teal: #1f9c8f;
  --accent-grad: linear-gradient(120deg, #c9922a, #e0447d, #7d3fbf);
  --glow: 0 8px 30px rgba(0,0,0,0.08);
}
body[data-theme="dark"] {
  --bg: #0e0c14;
  --panel: #17141f;
  --ink: #f3eee6;
  --muted: #9990a8;
  --line: #2a2436;
  --gold: #f5c542;
  --pink: #ff5d8f;
  --teal: #54d6c7;
  --glow: 0 8px 40px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Bricolage Grotesque', sans-serif;
  background:
    radial-gradient(circle at 12% 8%, rgba(201,146,42,0.10), transparent 45%),
    radial-gradient(circle at 88% 92%, rgba(224,68,125,0.10), transparent 45%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  min-height: 100vh;
  transition: background .4s, color .4s;
}

.app-shell { max-width: 1240px; margin: 0 auto; padding: 0 16px 60px; }

/* Header */
.alch-header {
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: blur(14px);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  border-bottom: 1px solid var(--line);
  margin: 0 -16px 24px;
}
.alch-header-inner {
  max-width: 1240px; margin: 0 auto; padding: 14px 20px;
  display: flex; justify-content: space-between; align-items: center;
}
.alch-logo {
  font-size: 30px; width: 52px; height: 52px;
  display: grid; place-items: center; border-radius: 14px;
  background: var(--accent-grad); color: #fff;
  box-shadow: var(--glow);
  animation: float 4s ease-in-out infinite;
}
@keyframes float { 50% { transform: translateY(-5px) rotate(-3deg); } }
.alch-title {
  margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -0.03em;
  background: var(--accent-grad); -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.alch-tagline { margin: 0; font-size: 12px; color: var(--muted); letter-spacing: 0.01em; }
.theme-btn {
  font-size: 20px; background: var(--panel); border: 1px solid var(--line);
  width: 44px; height: 44px; border-radius: 12px; cursor: pointer; color: var(--ink);
  transition: transform .2s;
}
.theme-btn:hover { transform: rotate(20deg); }

/* Layout */
.main-grid { display: grid; grid-template-columns: 400px 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .main-grid { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 22px; box-shadow: var(--glow);
}
.controls { position: sticky; top: 96px; }
@media (max-width: 900px) { .controls { position: static; } }

.field { margin-bottom: 22px; }
.field-label {
  font-family: 'JetBrains Mono', monospace; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted);
  display: block; margin-bottom: 8px;
}
.label-row { display: flex; justify-content: space-between; align-items: center; }
.mini-btn {
  font-family: 'JetBrains Mono', monospace; font-size: 10px;
  background: none; border: 1px solid var(--line); color: var(--pink);
  padding: 4px 9px; border-radius: 8px; cursor: pointer; letter-spacing: .05em;
  transition: all .15s;
}
.mini-btn:hover { background: var(--pink); color: #fff; border-color: var(--pink); }

/* Dropzone */
.dropzone {
  border: 2px dashed var(--line); border-radius: 16px; padding: 22px 16px;
  text-align: center; cursor: pointer; transition: all .2s; background: color-mix(in srgb, var(--bg) 50%, transparent);
}
.dropzone:hover, .dropzone.drag { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 8%, transparent); }
.dz-icon { font-size: 28px; color: var(--gold); }
.dz-main { font-weight: 700; margin-top: 6px; font-size: 15px; }
.dz-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.example-row { display: flex; gap: 8px; justify-content: center; margin-top: 14px; }
.example-thumb {
  width: 46px; height: 46px; border-radius: 10px; object-fit: cover;
  border: 1px solid var(--line); cursor: pointer; transition: transform .15s;
}
.example-thumb:hover { transform: scale(1.12); border-color: var(--pink); }

.source-preview { position: relative; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); }
.source-preview img { width: 100%; display: block; max-height: 260px; object-fit: contain; background: #000; }
.clear-x {
  position: absolute; top: 8px; right: 8px; width: 30px; height: 30px;
  border-radius: 50%; border: none; background: rgba(0,0,0,.6); color: #fff;
  cursor: pointer; font-size: 14px;
}
.source-label {
  position: absolute; bottom: 8px; left: 8px; font-family: 'JetBrains Mono', monospace;
  font-size: 10px; background: rgba(0,0,0,.55); color: #fff; padding: 3px 8px; border-radius: 6px;
  letter-spacing: .1em; text-transform: uppercase;
}

/* Prompt */
.prompt-input {
  width: 100%; min-height: 84px; resize: vertical; border-radius: 12px;
  border: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 50%, transparent);
  color: var(--ink); padding: 12px 14px; font-family: inherit; font-size: 14px; line-height: 1.4;
}
.prompt-input:focus { outline: none; border-color: var(--pink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--pink) 20%, transparent); }
.char-count { text-align: right; font-family: 'JetBrains Mono', monospace; font-size: 10px; color: var(--muted); margin-top: 4px; }

/* Model chips */
.model-chips { display: flex; flex-direction: column; gap: 8px; }
.model-chip {
  display: flex; align-items: center; gap: 12px; text-align: left;
  border: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 50%, transparent);
  border-radius: 12px; padding: 10px 14px; cursor: pointer; color: var(--ink);
  transition: all .18s; opacity: .6;
}
.model-chip.on { opacity: 1; }
.model-chip:hover { opacity: 1; }
.chip-glyph { font-size: 22px; width: 26px; text-align: center; }
.chip-body { display: flex; flex-direction: column; }
.chip-name { font-weight: 700; font-size: 14px; }
.chip-tag { font-family: 'JetBrains Mono', monospace; font-size: 10px; color: var(--muted); letter-spacing: .05em; }

/* Settings */
.settings-row { display: flex; gap: 20px; margin-bottom: 22px; }
.setting { flex: 1; }
.setting input[type=range] { width: 100%; accent-color: var(--pink); }
.ratio-tabs { display: flex; gap: 6px; }
.ratio-tab {
  flex: 1; border: 1px solid var(--line); background: transparent; color: var(--muted);
  border-radius: 8px; padding: 6px 0; cursor: pointer; font-weight: 700; font-family: 'JetBrains Mono', monospace;
}
.ratio-tab.on { background: var(--teal); color: #06231f; border-color: var(--teal); }

/* Run */
.run-row { display: flex; gap: 10px; }
.run-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px;
  border: none; border-radius: 14px; padding: 15px; cursor: pointer;
  font-family: inherit; font-weight: 800; font-size: 16px; color: #fff;
  background: var(--accent-grad); background-size: 200% 200%;
  animation: shift 5s ease infinite; box-shadow: var(--glow);
  transition: transform .12s;
}
@keyframes shift { 50% { background-position: 100% 50%; } }
.run-btn:hover:not(:disabled) { transform: translateY(-2px); }
.run-btn:disabled { opacity: .4; cursor: not-allowed; animation: none; }
.run-spin { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.remix-btn {
  width: 54px; border: 1px solid var(--line); background: var(--panel);
  color: var(--gold); font-size: 22px; border-radius: 14px; cursor: pointer; transition: transform .3s;
}
.remix-btn:hover { transform: rotate(180deg); }

/* Results */
.results-panel { min-height: 400px; }
.results-empty { text-align: center; padding: 80px 20px; color: var(--muted); }
.empty-glyph { font-size: 60px; opacity: .4; animation: float 4s ease-in-out infinite; }
.empty-title { font-weight: 800; font-size: 22px; margin-top: 12px; color: var(--ink); }
.empty-sub { max-width: 340px; margin: 8px auto 0; font-size: 14px; line-height: 1.5; }

.results-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.result-card { border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: color-mix(in srgb, var(--bg) 40%, transparent); animation: pop .4s ease; }
@keyframes pop { from { opacity: 0; transform: scale(.96); } }
.rc-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.rc-glyph { font-size: 18px; }
.rc-name { font-weight: 700; font-size: 13px; }
.rc-tag { margin-left: auto; font-family: 'JetBrains Mono', monospace; font-size: 9px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.rc-body { aspect-ratio: 1; display: grid; place-items: center; background: #0a0810; position: relative; }
.rc-img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.rc-idle { color: var(--muted); font-family: 'JetBrains Mono', monospace; font-size: 11px; }
.rc-loading { text-align: center; color: #b9a6ff; }
.rc-loading-txt { font-family: 'JetBrains Mono', monospace; font-size: 11px; margin-top: 10px; letter-spacing: .1em; }
.rc-error { text-align: center; color: #ff7a90; padding: 20px; font-size: 12px; }
.rc-error-face { font-size: 34px; }
.rc-actions { display: flex; gap: 4px; padding: 8px; }
.rc-actions button {
  flex: 1; font-family: 'JetBrains Mono', monospace; font-size: 10px; letter-spacing: .03em;
  border: 1px solid var(--line); background: transparent; color: var(--ink);
  padding: 7px 4px; border-radius: 8px; cursor: pointer; transition: all .15s;
}
.rc-actions button:hover { background: var(--accent); color: #000; border-color: var(--accent); }

/* Beaker animation */
.beaker { width: 40px; height: 50px; margin: 0 auto; position: relative; border: 2px solid #8a7bff; border-top: none; border-radius: 0 0 12px 12px; overflow: hidden; }
.bubble { position: absolute; bottom: 4px; border-radius: 50%; background: #b9a6ff; animation: rise 1.6s infinite ease-in; }
.b1 { width: 8px; height: 8px; left: 6px; animation-delay: 0s; }
.b2 { width: 6px; height: 6px; left: 18px; animation-delay: .5s; }
.b3 { width: 10px; height: 10px; left: 26px; animation-delay: 1s; }
@keyframes rise { 0% { transform: translateY(0); opacity: 1; } 100% { transform: translateY(-40px); opacity: 0; } }

/* Compare modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.8); display: grid; place-items: center; z-index: 100; padding: 20px; backdrop-filter: blur(4px); }
.compare-box { background: var(--panel); border-radius: 18px; padding: 16px; max-width: 620px; width: 100%; position: relative; }
.modal-close { position: absolute; top: -14px; right: -14px; width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--pink); color: #fff; cursor: pointer; font-size: 16px; z-index: 5; }
.compare-wrap { position: relative; border-radius: 12px; overflow: hidden; background: #000; }
.cmp-after, .cmp-before { width: 100%; display: block; }
.cmp-before-clip { position: absolute; top: 0; left: 0; height: 100%; overflow: hidden; }
.cmp-before-clip .cmp-before { position: absolute; top: 0; left: 0; }
.cmp-handle { position: absolute; top: 0; height: 100%; width: 3px; background: #fff; transform: translateX(-50%); pointer-events: none; box-shadow: 0 0 8px rgba(0,0,0,.5); }
.cmp-slider { position: absolute; bottom: 10px; left: 5%; width: 90%; accent-color: #fff; }
.compare-legend { text-align: center; font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--muted); margin-top: 10px; }

/* History */
.history { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 16px; }
.history-head { display: flex; justify-content: space-between; align-items: center; font-family: 'JetBrains Mono', monospace; font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin-bottom: 10px; }
.clear-hist { background: none; border: none; color: var(--pink); cursor: pointer; font-family: inherit; font-size: 11px; }
.history-row { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 8px; }
.hist-item { flex: 0 0 auto; width: 120px; cursor: pointer; }
.hist-item img { width: 120px; height: 90px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); transition: transform .15s; }
.hist-item:hover img { transform: scale(1.04); border-color: var(--pink); }
.hist-prompt { display: block; font-size: 11px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Footer */
.foot { text-align: center; margin-top: 40px; font-size: 13px; color: var(--muted); }
.foot a { color: var(--pink); font-weight: 700; text-decoration: none; }
.foot a:hover { text-decoration: underline; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 12px 22px; border-radius: 12px;
  font-weight: 600; z-index: 200; box-shadow: var(--glow); animation: toastin .3s ease;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 12px); } }