:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #1a1d21;
  --text-dim: #5b6470;
  --accent: #2f6df6;
  --accent-fg: #ffffff;
  --warn-bg: #fff6e5;
  --warn-border: #f0c36d;
  --warn-text: #6b4a06;
  --error-bg: #fdecec;
  --error-border: #eba3a3;
  --error-text: #8a1f1f;
  --ok: #1f9d55;
  --stage-bg: #eceff3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171b;
    --surface: #1c2026;
    --surface-2: #23282f;
    --border: #333a43;
    --text: #e8ebef;
    --text-dim: #9aa4b1;
    --accent: #5b8cff;
    --accent-fg: #0d1117;
    --warn-bg: #322709;
    --warn-border: #7a5e12;
    --warn-text: #f0d79a;
    --error-bg: #331616;
    --error-border: #7c2c2c;
    --error-text: #f3b0b0;
    --ok: #46c07d;
    --stage-bg: #12151a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 640; letter-spacing: -.01em; }
h1 { font-size: 17px; }
h2 { font-size: 15px; margin-bottom: 14px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); margin: 26px 0 12px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ── Top bar ─────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand p { margin: 1px 0 0; font-size: 13px; color: var(--text-dim); }
.logo {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 50% 38%, var(--accent) 0 30%, transparent 31%),
              linear-gradient(160deg, var(--surface-2), var(--border));
  border: 2px solid var(--accent);
}

.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); flex: none; }
.status[data-state="ok"] .dot { background: var(--ok); }
.status[data-state="warming"] .dot { background: #e0a72b; animation: pulse 1.2s ease-in-out infinite; }
.status[data-state="down"] .dot { background: #d94b4b; }
@keyframes pulse { 50% { opacity: .3; } }

/* ── Stepper ─────────────────────────────────────────────── */
.stepper {
  display: flex; gap: 4px; padding: 12px 24px 0;
  max-width: 1240px; margin: 0 auto; width: 100%;
  overflow-x: auto;
}
.step {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border: 0; border-radius: var(--radius) var(--radius) 0 0;
  background: transparent; color: var(--text-dim);
  font: inherit; font-size: 14px; white-space: nowrap;
  cursor: not-allowed; opacity: .55;
}
.step:not([disabled]) { cursor: pointer; opacity: 1; }
.step:not([disabled]):hover { background: var(--surface-2); color: var(--text); }
.step.is-active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 -1px 0 var(--border) inset, 1px 0 0 var(--border) inset, -1px 0 0 var(--border) inset; }
.step .num {
  display: grid; place-items: center;
  width: 20px; height: 20px; border-radius: 50%; flex: none;
  background: var(--surface-2); color: var(--text-dim);
  font-size: 11px; font-weight: 700;
}
.step.is-active .num { background: var(--accent); color: var(--accent-fg); }
.step.is-done .num { background: var(--ok); color: #fff; }

/* ── Layout ──────────────────────────────────────────────── */
main { max-width: 1240px; margin: 0 auto; padding: 0 24px 40px; width: 100%; }

.panel {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.panel.is-active { display: block; }

.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 28px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

.sidebar { min-width: 0; }

/* ── Dropzone ────────────────────────────────────────────── */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 56px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); background: var(--surface); outline: none; }
.dropzone.is-over { border-color: var(--accent); background: var(--surface); border-style: solid; }
.dz-icon {
  width: 52px; height: 52px; margin: 0 auto 16px; border-radius: 50%;
  border: 3px solid var(--text-dim); opacity: .45;
  background:
    radial-gradient(circle at 50% 40%, currentColor 0 26%, transparent 27%),
    radial-gradient(ellipse at 50% 108%, currentColor 0 40%, transparent 41%);
  color: var(--text-dim);
}
.dz-title { margin: 0; font-size: 17px; font-weight: 600; }
.dz-sub { margin: 6px 0 0; color: var(--text-dim); font-size: 14px; }
.dz-formats { margin: 14px 0 0; color: var(--text-dim); font-size: 12.5px; opacity: .8; }
.privacy-note { margin: 18px auto 0; max-width: 62ch; text-align: center; font-size: 13px; color: var(--text-dim); }

/* ── Canvas stage ────────────────────────────────────────── */
.stage {
  position: relative;
  background: var(--stage-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 320px;
  display: grid; place-items: center;
  overflow: hidden;
}
.stage canvas { max-width: 100%; height: auto; display: block; }

.spinner-overlay {
  position: absolute; inset: 0;
  display: grid; place-content: center; justify-items: center; gap: 14px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  font-size: 14px; color: var(--text-dim);
  z-index: 2;
}
.spinner-overlay[hidden] { display: none; }
.spinner-overlay p { margin: 0; }
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Previews ────────────────────────────────────────────── */
.preview-pair { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.preview-pair figure { margin: 0; }
.preview-pair figcaption { margin-top: 10px; font-size: 13px; color: var(--text-dim); text-align: center; }
.preview-frame {
  position: relative;
  width: 340px; max-width: 100%; aspect-ratio: 1;
  background: var(--stage-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.preview-frame.is-round { border-radius: 50%; width: 230px; }
.preview-frame canvas, .preview-frame img { width: 100%; height: 100%; display: block; object-fit: cover; }
.preview-badge {
  position: absolute; left: 8px; bottom: 8px; z-index: 3;
  padding: 3px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--border);
  font-size: 11px; color: var(--text-dim);
}
.preview-badge[data-exact="1"] { color: var(--ok); border-color: var(--ok); }

/* ── Form controls ───────────────────────────────────────── */
.field { margin-bottom: 20px; }
.field label {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  font-size: 13.5px; font-weight: 550; margin-bottom: 7px;
}
.field .val { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 650; }
.field .sub { margin: 7px 0 0; font-size: 12.5px; color: var(--text-dim); line-height: 1.45; }

input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="text"], select {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 14px;
}
input[type="text"]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text-dim);
  font: inherit; font-size: 13px; cursor: pointer;
}
.chips button:hover { border-color: var(--accent); color: var(--text); }
.chips button.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }

.toggles { display: grid; gap: 9px; }
.toggles label { display: flex; align-items: center; gap: 9px; font-size: 13.5px; cursor: pointer; }
.toggles input { accent-color: var(--accent); margin: 0; }
.sw { width: 14px; height: 3px; border-radius: 2px; flex: none; }
.sw-white { background: #f2f2f2; box-shadow: 0 0 0 1px var(--border); }
.sw-yellow { background: #f5d90a; }
.sw-cyan { background: #22d3ee; }
.sw-red { background: #f43f5e; }
.sw-green { background: #22c55e; }
.sw-green-dash { background: repeating-linear-gradient(90deg, #22c55e 0 4px, transparent 4px 7px); }

.hint { font-size: 12.5px; color: var(--text-dim); line-height: 1.5; margin: 18px 0 0; padding-top: 16px; border-top: 1px solid var(--border); }

/* ── Facts list ──────────────────────────────────────────── */
.facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; font-size: 13.5px; }
.facts dt { color: var(--text-dim); }
.facts dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.facts dd.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

/* ── Buttons ─────────────────────────────────────────────── */
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--border); }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 9px 16px; border: 1px solid transparent; border-radius: 7px;
  font: inherit; font-size: 14px; font-weight: 560;
  cursor: pointer; text-decoration: none;
}
.btn-primary { background: var(--accent); color: var(--accent-fg); margin-left: auto; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-block { width: 100%; margin: 4px 0 0; }
.btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }

/* ── Alerts ──────────────────────────────────────────────── */
.alert { margin-top: 16px; padding: 11px 14px; border-radius: 8px; border: 1px solid; font-size: 13.5px; line-height: 1.5; }
.alert[hidden] { display: none; }
.alert-warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }
.alert-error { background: var(--error-bg); border-color: var(--error-border); color: var(--error-text); }
.alert strong { font-weight: 680; }

footer { max-width: 1240px; margin: 0 auto; padding: 20px 24px 40px; }
footer p { margin: 0; font-size: 12.5px; color: var(--text-dim); text-align: center; }
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

.privacy-badge {
  display: flex; align-items: flex-start; gap: 10px;
  max-width: 68ch; margin: 0 auto 14px !important;
  padding: 11px 15px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px;
  text-align: left !important; line-height: 1.5;
}
.privacy-badge .lock { flex: none; font-size: 14px; line-height: 1.4; }
.privacy-badge strong { color: var(--text); font-weight: 640; }
