:root {
  --bg: #0d1017;
  --bg-soft: #141924;
  --panel: #171d2a;
  --panel-2: #1d2433;
  --line: #2a3346;
  --text: #e7ecf5;
  --muted: #93a0b8;
  --accent: #5ad1a0;
  --accent-ink: #06251a;
  --warn: #ffb454;
  --error: #ff7a7a;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --bg-soft: #eaeef6;
    --panel: #ffffff;
    --panel-2: #f2f5fa;
    --line: #d9e0ec;
    --text: #18202f;
    --muted: #5d6b83;
    --accent: #14876a;
    --accent-ink: #ffffff;
    --warn: #a4630b;
    --error: #b3261e;
    --shadow: 0 8px 24px rgba(30, 50, 90, .10);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 70% -10%, var(--bg-soft), var(--bg)) fixed;
  color: var(--text);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 20px clamp(16px, 4vw, 40px);
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 42px; height: 42px; display: grid; place-items: center;
  border-radius: 12px; background: var(--accent); color: var(--accent-ink);
  font-size: 22px; font-weight: 700;
}
.topbar h1 { margin: 0; font-size: 19px; letter-spacing: -.01em; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.chip {
  display: inline-block; padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel);
  font-size: 12px; font-weight: 600; letter-spacing: .02em;
}
.chip-ok { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.chip-muted { color: var(--muted); }

main { flex: 1; padding: 0 clamp(16px, 4vw, 40px) 40px; }

/* ---------------- dropzone ---------------- */
.dropzone {
  max-width: 760px; margin: 4vh auto 0; padding: clamp(32px, 7vw, 72px) 24px;
  border: 2px dashed var(--line); border-radius: 20px;
  background: var(--panel); text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s, transform .15s;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); outline: none; }
.dropzone.dragging { border-color: var(--accent); background: var(--panel-2); transform: scale(1.01); }
.dz-icon { font-size: 34px; color: var(--accent); }
.dz-title { margin: 10px 0 6px; font-size: 21px; font-weight: 650; }
.dz-sub { margin: 0; color: var(--muted); }
.dz-note { margin: 18px 0 0; color: var(--muted); font-size: 13px; }

kbd {
  font: inherit; font-size: 12px; padding: 2px 7px; margin: 0 2px;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px;
  background: var(--panel-2);
}

.linkbtn {
  background: none; border: none; padding: 0; font: inherit;
  color: var(--accent); cursor: pointer; text-decoration: underline;
}

/* ---------------- workspace ---------------- */
.workspace {
  display: grid; grid-template-columns: minmax(300px, 360px) 1fr;
  gap: 20px; align-items: start; max-width: 1400px; margin: 8px auto 0;
}
@media (max-width: 900px) { .workspace { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.controls { padding: 18px; display: flex; flex-direction: column; gap: 14px; }

.source-summary { display: flex; gap: 12px; align-items: center; }
.thumb {
  width: 64px; height: 64px; border-radius: 10px; object-fit: cover;
  border: 1px solid var(--line); background: var(--panel-2);
}
.source-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.source-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }

select, input[type="range"] {
  width: 100%; font: inherit; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 10px;
}
input[type="range"]:disabled { opacity: .45; cursor: not-allowed; }
input[type="range"] { padding: 0; accent-color: var(--accent); }
select:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.blurb { margin: -4px 0 0; color: var(--muted); font-size: 13px; }
.model-meta { margin: -6px 0 -2px; font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge {
  padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700;
  letter-spacing: .03em; text-transform: uppercase;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
}
.estimate { color: var(--text); }
.estimate.slow { color: var(--warn); }

.advanced { border-top: 1px solid var(--line); padding-top: 12px; }
.advanced summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.advanced > *:not(summary) { margin-top: 12px; }

.actions { display: flex; gap: 10px; }
button.primary, button.ghost {
  font: inherit; font-weight: 600; border-radius: 10px; padding: 11px 16px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
button.primary { flex: 1; background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.primary:disabled, button.ghost:disabled { opacity: .5; cursor: not-allowed; }
button.primary:not(:disabled):hover { filter: brightness(1.08); }

.progress .bar {
  height: 8px; border-radius: 999px; background: var(--panel-2);
  border: 1px solid var(--line); overflow: hidden;
}
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .18s ease; }
.status { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.status.warn { color: var(--warn); }
.error {
  margin: 0; padding: 10px 12px; border-radius: 10px; font-size: 13px;
  color: var(--error); border: 1px solid color-mix(in srgb, var(--error) 40%, var(--line));
  background: color-mix(in srgb, var(--error) 8%, transparent);
}

/* ---------------- preview ---------------- */
.preview { padding: 14px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.preview-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.tabs { display: flex; gap: 4px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tab {
  font: inherit; font-size: 13px; font-weight: 600; border: none; background: none;
  color: var(--muted); padding: 6px 14px; border-radius: 8px; cursor: pointer;
}
.tab.active { background: var(--panel); color: var(--text); }
.preview-tools { display: flex; align-items: center; gap: 8px; }
.preview-tools button { padding: 8px 12px; font-size: 13px; }

.stage {
  position: relative; border-radius: 12px; overflow: auto;
  background:
    conic-gradient(from 45deg, var(--panel-2) 25%, transparent 0 50%, var(--panel-2) 0 75%, transparent 0) 0 0 / 20px 20px;
  border: 1px solid var(--line); min-height: 300px;
  display: grid; place-items: center;
}
.compare {
  position: relative; line-height: 0; max-width: 100%;
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.compare canvas { display: block; max-width: 100%; height: auto; image-rendering: auto; }
/*
 * "Fit" mode (default) scales the canvas down to the panel width — which
 * also scales down the very detail an upscale just added, so two runs can
 * look deceptively similar at a glance. "100%" drops the constraint so the
 * stage's own scrollbars take over and every pixel is shown 1:1.
 */
.compare.native canvas { max-width: none; }
.compare.native { max-width: none; }
.layer { }
.clip { position: absolute; inset: 0; clip-path: inset(0 50% 0 0); }
.clip canvas { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; }
.handle {
  position: absolute; top: 0; bottom: 0; left: 50%; width: 2px;
  background: var(--accent); cursor: ew-resize; transform: translateX(-1px);
}
.handle span {
  position: absolute; top: 50%; left: 50%; width: 30px; height: 30px;
  transform: translate(-50%, -50%); border-radius: 50%;
  background: var(--accent); box-shadow: 0 2px 10px rgba(0, 0, 0, .4);
}
.handle span::after {
  content: "⇔"; position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--accent-ink); font-size: 14px; line-height: 1;
}
.compare.result-only .clip { clip-path: none !important; }
.compare.result-only .handle, .compare.result-only .tag { display: none; }
.tag {
  position: absolute; bottom: 8px; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  background: rgba(0, 0, 0, .55); color: #fff; line-height: 1.6;
}
.tag-left { left: 8px; }
.tag-right { right: 8px; }
.hint { margin: 0; color: var(--muted); font-size: 12.5px; }

.footer {
  padding: 22px clamp(16px, 4vw, 40px) 30px; color: var(--muted); font-size: 12.5px;
  border-top: 1px solid var(--line); max-width: 1400px; margin: 0 auto; width: 100%;
}
.footer p { margin: 0; }
