:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #15181e;
  --muted: #5d6675;
  --line: #dde1e7;
  --accent: #1f4fd1;
  --accent-ink: #ffffff;
  --accent-soft: #e9effd;
  --warn-bg: #fff6df;
  --warn-ink: #6b4a00;
  --warn-line: #f0d48a;
  --error-bg: #fdecec;
  --error-ink: #8f1d1d;
  --error-line: #f1b5b5;
  --check-a: #ffffff;
  --check-b: #e6e9ee;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1a1d24;
    --ink: #eceef2;
    --muted: #9aa3b2;
    --line: #2c313b;
    --accent: #7ea2ff;
    --accent-ink: #0c1020;
    --accent-soft: #1d2740;
    --warn-bg: #2e2610;
    --warn-ink: #f1d58b;
    --warn-line: #5a4a17;
    --error-bg: #331818;
    --error-ink: #f3b4b4;
    --error-line: #6b2a2a;
    --check-a: #2a2e37;
    --check-b: #20242c;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 22px; line-height: 1.25; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 10px; }
p { margin: 0 0 12px; }
code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--muted); }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 16px; }
.brand svg { color: var(--accent); }
.tagline { color: var(--muted); font-size: 13px; }

.page { max-width: 1180px; margin: 0 auto; padding: 24px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.card.narrow { max-width: 520px; margin: 40px auto; }
.card-quiet { background: transparent; border-style: dashed; }
.card-quiet p { margin: 0; }

.alert { padding: 10px 14px; border-radius: 8px; border: 1px solid; margin-bottom: 12px; }
.alert-error { background: var(--error-bg); color: var(--error-ink); border-color: var(--error-line); }
.alert-warn { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); }

.button {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 14px; min-height: 38px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.button:hover { border-color: var(--muted); }
.button-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.button-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.button[disabled] { opacity: 0.6; cursor: progress; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- home ---------- */
.home { display: grid; grid-template-columns: minmax(320px, 420px) 1fr; gap: 28px; align-items: start; }
.form { display: grid; gap: 12px; margin-top: 16px; }
.field { display: grid; gap: 4px; flex: 1; min-width: 0; }
.field > span:first-child { font-size: 13px; font-weight: 600; }
.field em { font-style: normal; font-weight: 400; color: var(--muted); }
.field-row { display: flex; gap: 12px; }
.field-small { flex: 0 0 130px; }
input[type="text"], input[type="number"] {
  width: 100%; min-height: 38px; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink); font: inherit;
}
.input-unit { position: relative; display: block; }
.input-unit input { padding-right: 40px; }
.input-unit b { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-weight: 500; color: var(--muted); font-size: 13px; }
.hint { margin: -6px 0 0; font-size: 13px; color: var(--muted); }

.dropzone {
  display: grid; justify-items: center; gap: 4px;
  padding: 24px 16px; text-align: center;
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  color: var(--muted); cursor: pointer; position: relative;
}
.dropzone strong { color: var(--ink); overflow-wrap: anywhere; }
.dropzone span { font-size: 13px; }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.has-file { border-style: solid; border-color: var(--accent); }
.dropzone:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.form-error { margin: 0; color: var(--error-ink); font-size: 13px; }

.empty { color: var(--muted); padding: 28px; border: 1px dashed var(--line); border-radius: var(--radius); text-align: center; }
.project-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.project-tile { display: grid; gap: 4px; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); text-decoration: none; }
.project-tile:hover { border-color: var(--accent); }
.thumb { display: grid; place-items: center; aspect-ratio: 4 / 3; border-radius: 6px; overflow: hidden; padding: 10px; }
.thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.thumb-failed { font-size: 12px; color: var(--error-ink); }
.tile-name { font-weight: 600; padding: 2px 4px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-meta { font-size: 12px; color: var(--muted); padding: 0 4px 4px; }

.checker {
  background-color: var(--check-a);
  background-image:
    linear-gradient(45deg, var(--check-b) 25%, transparent 25%, transparent 75%, var(--check-b) 75%),
    linear-gradient(45deg, var(--check-b) 25%, transparent 25%, transparent 75%, var(--check-b) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
}

/* ---------- project ---------- */
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.crumbs span { margin: 0 4px; }
.project-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.project-head p { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.workspace { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }
.stage {
  display: grid; place-items: center;
  min-height: 460px; padding: 32px;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.stage img { max-width: 100%; max-height: 640px; object-fit: contain; }
.side { display: grid; gap: 14px; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--line); vertical-align: -1px; margin: 0 4px 0 2px; }
.choice { display: flex; gap: 10px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin-top: 3px; accent-color: var(--accent); }
.choice strong { display: block; font-size: 14px; }
.choice small { color: var(--muted); font-size: 12.5px; }

@media (max-width: 860px) {
  .page { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .tagline { display: none; }
  .home, .workspace { grid-template-columns: 1fr; }
  .stage { min-height: 280px; padding: 20px; }
}

/* ---------- phase 2: analysis ---------- */
:root {
  --ok-bg: #e6f4ea; --ok-ink: #1c5b30;
  --danger: #b42318;
  --highlight: #ff00aa;
}
@media (prefers-color-scheme: dark) {
  :root { --ok-bg: #16301f; --ok-ink: #9ad8ae; --danger: #ff8a80; }
}
.alert-success { background: var(--ok-bg); color: var(--ok-ink); border-color: transparent; }
.button-danger { color: var(--danger); }
.button-danger:hover { border-color: var(--danger); }
.actions form { margin: 0; }

.stage { align-content: center; gap: 12px; }
.stage-frame { position: relative; display: inline-block; line-height: 0; }
.stage-frame img:first-child { max-width: 100%; max-height: 640px; }
.stage-overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage-caption {
  margin: 0; padding: 6px 10px; border-radius: 6px; font-size: 13px; max-width: 640px;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--highlight);
}

.count { display: inline-block; min-width: 22px; padding: 0 6px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; text-align: center; }
.palette { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.palette li { display: grid; grid-template-columns: 18px 64px 38px 1fr; align-items: center; gap: 8px; }
.chip { width: 18px; height: 18px; border-radius: 4px; border: 1px solid var(--line); }
.palette-share { text-align: right; font-variant-numeric: tabular-nums; }
.palette-size { color: var(--muted); text-align: right; }

.checks { margin-top: 28px; }
.checks-head p { max-width: 760px; }
.check-grid { list-style: none; margin: 14px 0 12px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.check-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.check-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 4px; }
.check-title h3 { margin: 0; font-size: 15px; }
.check-card > p { font-size: 13px; margin-bottom: 0; }
.badge { flex: none; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok-ink); }
.badge-caution { background: var(--warn-bg); color: var(--warn-ink); }
.badge-limit { background: var(--error-bg); color: var(--error-ink); }
.findings { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; font-size: 13.5px; }
.finding { padding-left: 10px; border-left: 3px solid var(--line); }
.finding-limit { border-left-color: var(--error-line); }
.finding-caution { border-left-color: var(--warn-line); }
.finding span { display: block; }
.link-button { margin-top: 2px; padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: underline; }
.link-button[aria-pressed="true"] { color: var(--highlight); }

/* ---------- phase 3: previews ---------- */
.checks-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; }
.checks-head p { margin-bottom: 0; }
.preview-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.fabric-form { display: flex; align-items: center; gap: 8px; margin: 0; }
.fabric-form label { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.fabric-form input[type="color"] { width: 38px; height: 38px; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; }
.fabric-note { font-size: 13px; }

.check-card { display: flex; flex-direction: column; }
.preview {
  display: grid; place-items: center;
  margin: -16px -16px 14px; aspect-ratio: 3 / 2; overflow: hidden;
  border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0;
  background: var(--bg);
}
.preview a { display: block; width: 100%; height: 100%; }
.preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.preview-empty { margin: 0; padding: 0 16px; color: var(--muted); font-size: 13px; text-align: center; }
.preview-none { aspect-ratio: auto; padding: 14px 0; border-bottom-style: dashed; background: transparent; }
.preview.is-busy .preview-empty::before {
  content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 8px; vertical-align: -1px;
  border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .preview.is-busy .preview-empty::before { animation: none; } }
.preview-actions { margin: auto 0 0; padding-top: 12px; font-size: 13px; font-weight: 600; }

/* ---------- phase 5: compare ---------- */
.preview-actions { display: flex; gap: 16px; flex-wrap: wrap; }
.compare-bar { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.compare-pick { display: grid; gap: 4px; font-size: 13px; font-weight: 600; }
.compare-pick select {
  min-height: 38px; min-width: 210px; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit;
}
.compare-swap { font-size: 16px; }
.segmented { display: inline-flex; margin-left: auto; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented button { min-height: 38px; padding: 6px 14px; border: 0; background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.compare-stage { position: relative; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--bg); }
.compare-pane { margin: 0; position: relative; }
.compare-pane img { display: block; width: 100%; height: 100%; object-fit: contain; }
.compare-pane figcaption {
  position: absolute; bottom: 10px; padding: 3px 10px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.62); color: #fff; font-size: 12.5px; font-weight: 600; pointer-events: none;
}
.compare-left figcaption { left: 10px; }
.compare-right figcaption { right: 10px; }

[data-mode="slider"] .compare-stage { aspect-ratio: var(--ratio); }
[data-mode="slider"] .compare-pane { position: absolute; inset: 0; }
[data-mode="slider"] .compare-right { clip-path: inset(0 0 0 var(--pos)); }
[data-mode="slider"] .compare-handle {
  position: absolute; top: 0; bottom: 0; left: var(--pos); width: 2px; margin-left: -1px;
  background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45); pointer-events: none;
}
[data-mode="slider"] .compare-handle::after {
  content: "‹ ›"; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: #fff; color: #15181e; font-weight: 700; letter-spacing: 2px; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
}
.compare-range { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: ew-resize; }
.compare-stage:has(.compare-range:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

[data-mode="side"] .compare-stage { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
[data-mode="side"] .compare-handle, [data-mode="side"] .compare-range { display: none; }

.compare-notes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.compare-notes .card { padding: 16px; }
.compare-notes h3 { margin: 0; font-size: 15px; }
.compare-notes p { margin: 8px 0 0; font-size: 13.5px; }
@media (max-width: 700px) {
  [data-mode="side"] .compare-stage, .compare-notes { grid-template-columns: 1fr; }
  .segmented { margin-left: 0; }
}

/* ---------- phase 6: accounts, admin, AI ---------- */
.account { margin-left: auto; display: flex; align-items: center; gap: 16px; font-size: 14px; }
.account a { color: var(--ink); text-decoration: none; font-weight: 600; }
.account a:hover { color: var(--accent); }
.account-name { color: var(--muted); }
.account form { margin: 0; }
.account .link-button { margin: 0; font-size: 14px; }
.auth { margin-top: 60px; }

.stat-row { list-style: none; margin: 0 0 20px; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 2px; }
.stat span { font-size: 13px; color: var(--muted); }
.stat strong { font-size: 26px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat small { font-size: 12.5px; color: var(--muted); }

.admin-ai { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: center; margin-bottom: 26px; }
.admin-ai p:last-child { margin-bottom: 0; }
.admin-ai-form { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin: 0; }
.switch { display: flex; gap: 10px; align-items: flex-start; max-width: 280px; cursor: pointer; }
.switch input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); }
.switch strong { display: block; font-size: 14px; }
.switch small { color: var(--muted); font-size: 12.5px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
select, input[type="email"], input[type="password"] {
  width: 100%; min-height: 38px; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit;
}

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: 14px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.table th { font-size: 12.5px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.table th small { font-weight: 400; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; margin: 0; align-items: center; }
.row-actions input[type="password"] { width: 150px; min-height: 30px; padding: 4px 8px; font-size: 13px; }
.button-small { min-height: 30px; padding: 3px 10px; font-size: 13px; }
.row-more { margin-top: 6px; font-size: 13px; }
.row-more summary { cursor: pointer; color: var(--accent); }
.row-more form { margin-top: 6px; }
.add-user { margin-bottom: 26px; padding: 14px 16px; }
.add-user summary { cursor: pointer; }
.add-user-form { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: end; }

.preview { position: relative; }
.preview-switch { position: absolute; top: 8px; left: 8px; z-index: 1; margin: 0; font-size: 12.5px; }
.preview-switch button { min-height: 28px; padding: 2px 10px; font-size: 12.5px; }
.ai-status { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.ai-status-ok { color: var(--ok-ink); }
.ai-status-bad { color: var(--error-ink); }
@media (max-width: 860px) {
  .admin-ai { grid-template-columns: 1fr; }
  .account-name { display: none; }
}
.key-field { flex: 1 1 280px; min-width: 240px; }
.key-field > label { font-size: 13px; font-weight: 600; }
.check-inline { display: inline-flex; align-items: center; gap: 5px; margin-left: 8px; }
.admin-ai { grid-template-columns: 1fr; }
.ai-off { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px; }
.preview-actions { align-items: center; }

/* An element marked hidden stays hidden, whatever display its class gives it. */
[hidden] { display: none !important; }

/* ---------- preview viewer ---------- */
.preview a { cursor: zoom-in; }
.preview a:focus-visible { outline-offset: -3px; }
.lightbox {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: rgba(10, 12, 16, 0.94); color: #f2f3f5;
  display: none; grid-template-rows: auto 1fr;
}
.lightbox[open] { display: grid; }
.lightbox::backdrop { background: rgba(10, 12, 16, 0.94); }
.lightbox-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; flex-wrap: wrap; }
.lightbox-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.lightbox-title strong { font-size: 15px; }
.lightbox-title .muted { color: #a9b0bc; font-size: 13px; }
.lightbox-tools { display: flex; gap: 8px; }
.lightbox .button { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.22); color: #f2f3f5; }
.lightbox .button:hover { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.4); }
.lightbox :focus-visible { outline-color: #fff; }
.lightbox-stage { position: relative; min-height: 0; display: grid; place-items: center; padding: 0 16px 16px; overflow: hidden; }
.lightbox-stage img { max-width: 100%; max-height: 100%; min-height: 0; object-fit: contain; border-radius: 6px; cursor: zoom-in; }
.lightbox-stage.is-zoomed { overflow: auto; place-items: start; }
.lightbox-stage.is-zoomed img { max-width: none; max-height: none; cursor: zoom-out; }
.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 1;
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(10, 12, 16, 0.6); color: #fff; font-size: 26px; line-height: 1; cursor: pointer;
}
.lightbox-nav:hover { background: rgba(255, 255, 255, 0.18); }
.lightbox-prev { left: 20px; }
.lightbox-next { right: 20px; }
.lightbox-stage.is-zoomed .lightbox-nav { position: fixed; }
.lightbox.is-single .lightbox-nav { display: none; }
body:has(.lightbox[open]) { overflow: hidden; }
