:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --border: #dfe2e7;
  --text: #1c2127;
  --text-dim: #626a76;
  --accent: #4f46e5;
  --accent-dim: #eceafe;
  --danger: #e0245e;
  --ok: #1f7a3f;
  --ok-dim: #e3f3e8;
  --warn: #a15c00;
  --warn-dim: #fff4e0;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --card-bg: #1c1f25;
    --border: #2c313a;
    --text: #eceef1;
    --text-dim: #99a1ac;
    --accent: #8b80ff;
    --accent-dim: #262244;
    --ok: #5fd08a;
    --ok-dim: #16301f;
    --warn: #ffb54d;
    --warn-dim: #33260f;
  }
}

:root[data-theme="dark"] {
  --bg: #14161a;
  --card-bg: #1c1f25;
  --border: #2c313a;
  --text: #eceef1;
  --text-dim: #99a1ac;
  --accent: #8b80ff;
  --accent-dim: #262244;
  --ok: #5fd08a;
  --ok-dim: #16301f;
  --warn: #ffb54d;
  --warn-dim: #33260f;
}

* { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding: 24px 28px 56px;
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0 0 20px;
  color: var(--text-dim);
  font-size: 13.5px;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-weight: 600;
  font-size: 13.5px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.hint {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  margin: 4px 0 0;
}

.panels.panels-2 {
  grid-template-columns: repeat(2, 1fr);
}

@media (max-width: 700px) {
  .panels.panels-2 { grid-template-columns: 1fr; }
}

.figma-previews {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-top: 20px;
}

@media (max-width: 700px) {
  .figma-previews { grid-template-columns: 1fr; }
}

.figma-preview-col h3 {
  font-size: 13px;
  margin: 0 0 8px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.figma-preview-col h3 button {
  font-size: 11px;
  padding: 4px 10px;
}

.font-table-wrap {
  margin-top: 24px;
}

.font-table-wrap h3 {
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
}

.font-table-scroll {
  overflow-x: auto;
}

.font-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  overflow: hidden;
  font-size: 12.5px;
}

.font-table th, .font-table td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.font-table th.col-check, .font-table td.col-check {
  width: 32px;
  padding-right: 0;
}

.font-table td:nth-child(3) {
  max-width: 340px;
  overflow-wrap: break-word;
}

.font-table td:nth-child(4), .font-table td:nth-child(5) {
  white-space: nowrap;
}

.font-table tr.reviewed {
  opacity: 0.45;
}

.font-table tr.reviewed td:nth-child(3) {
  text-decoration: line-through;
}

.font-table-wrap h3 button {
  margin-left: auto;
}

.font-table th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: color-mix(in srgb, var(--bg) 60%, transparent);
}

.font-table tr:last-child td { border-bottom: none; }

.font-table .status-pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.status-pill.match { background: #1f7a3f22; color: #1f7a3f; }
.status-pill.mismatch { background: #e6193822; color: #e61938; }
.status-pill.missing { background: #99999922; color: var(--text-dim); }

.checks-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  white-space: nowrap;
}

.check-chip {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 20px;
  font-size: 10.5px;
  font-weight: 600;
}

.check-chip.ok { background: #1f7a3f1a; color: #1f7a3f; }
.check-chip.bad { background: #e619381a; color: #e61938; }
.check-chip.off { background: #99999918; color: var(--text-dim); }

.check-toggle-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-bottom: none;
  padding: 10px 12px;
  font-size: 12px;
  border-radius: 8px 8px 0 0;
}

.check-toggle-bar .checkbox {
  margin-bottom: 0;
}

.check-toggle-label {
  color: var(--text-dim);
  font-weight: 600;
}

.sync-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.sync-bar .checkbox { margin-bottom: 0; }

.scroll-pct {
  margin-left: auto;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 2px 8px;
  border-radius: 20px;
}

.diff-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-top: none;
  padding: 8px 12px;
  font-size: 11.5px;
  color: var(--text-dim);
}

.diff-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.swatch-red { background: #e61938; }
.swatch-gray { background: #b7b7bd; }
.swatch-amber { background: #ffb020; }
.swatch-blue { background: #5a8cff; }

.panels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

@media (max-width: 900px) {
  .panels { grid-template-columns: 1fr; }
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-height: 260px;
}

.card h2 {
  font-size: 14px;
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11.5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dropzone {
  flex: 1;
  border: 1.5px dashed var(--border);
  border-radius: 8px;
  display: flex;
  text-align: center;
  padding: 12px;
  cursor: pointer;
  min-height: 160px;
  max-height: 340px;
  overflow-y: auto;
  overflow-x: hidden;
  background: color-mix(in srgb, var(--bg) 40%, transparent);
}

.dropzone.static { cursor: default; }

.dropzone.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}

/* Auto margins self-center the placeholder without forcing the same
   alignment on a loaded (possibly very tall, full-page) preview image. */
.placeholder {
  margin: auto;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
  padding: 0 8px;
}

.preview {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 4px;
  align-self: flex-start;
}

.preview.hidden, .hidden { display: none !important; }

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.field.small { flex: 1; }

.field-row {
  display: flex;
  gap: 10px;
}

input, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
}

input:disabled { opacity: 0.55; }

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 14px;
  cursor: pointer;
}

.checkbox input { width: auto; }

.btn {
  border: none;
  border-radius: 7px;
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn:not(:disabled):hover { opacity: 0.88; }

.btn.primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

.btn.accent {
  background: var(--text);
  color: var(--card-bg);
  padding: 12px 28px;
}

.status {
  font-size: 12px;
  color: var(--text-dim);
  margin: 8px 0 0;
  min-height: 16px;
}

.status.error { color: var(--danger); }

.test-bar {
  margin: 24px 0;
  text-align: center;
}

.viewer-section {
  max-width: 1100px;
  margin: 0 auto;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  padding: 8px;
}

.mode-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  cursor: pointer;
}

.mode-btn:hover { background: var(--bg); }

.mode-btn.active {
  background: var(--text);
  color: var(--card-bg);
}

.diff-stat {
  margin-left: auto;
  font-size: 12.5px;
  color: var(--text-dim);
  padding-right: 6px;
}

.align-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-top: none;
  padding: 10px 12px;
  font-size: 12px;
}

.align-field {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
}

.align-field.small { gap: 6px; }

.align-field input[type="range"] {
  width: 130px;
  padding: 0;
}

.align-field input[type="number"] {
  width: 70px;
  padding: 5px 8px;
  font-size: 12px;
}

.align-val {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  min-width: 38px;
}

.small-btn {
  padding: 7px 14px;
  font-size: 12px;
}

.small-btn.ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.report-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-top: none;
  padding: 10px 12px;
  font-size: 12px;
}

.report-bar .checkbox {
  margin-bottom: 0;
}

#downloadImageBtn {
  margin-left: auto;
}

.viewer {
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: 75vh;
  background: #0d0f12;
}

.scrubber-stage {
  position: relative;
  width: 100%;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

.stage-img {
  /* Natural aspect ratio, scaled to the stage width and top-aligned —
     never stretched to fill a shared height, since the reference and the
     live capture are rarely the exact same pixel height. */
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: auto;
  display: block;
  pointer-events: none;
}

.stage-clip {
  position: absolute;
  inset: 0;
  overflow: hidden;
  width: 50%;
}

#stageOverlay {
  transform-origin: top left;
}

.scrubber-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 0;
  cursor: ew-resize;
}

.handle-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -1px;
  width: 2px;
  background: #e63954;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.25);
}

.handle-grip {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #e63954;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}

#diffCanvas {
  display: block;
  width: 100%;
  height: auto;
}

/* ================= Figma & Site Match (interactive workflow) ================= */

.fm-intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}

.fm-intro h2 { margin: 0 0 4px; font-size: 18px; }
.fm-intro p { margin: 0; color: var(--text-dim); font-size: 13px; max-width: 640px; line-height: 1.5; }

.fm-progress {
  display: flex;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: fmstep;
  flex-wrap: wrap;
}

.fm-progress li {
  counter-increment: fmstep;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  padding: 5px 10px 5px 6px;
  border-radius: 20px;
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.fm-progress li::before {
  content: counter(fmstep);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

.fm-progress li.done { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.fm-progress li.done::before { content: "✓"; background: var(--ok-dim); }
.fm-progress li.current { color: var(--accent); border-color: var(--accent); }
.fm-progress li.current::before { background: var(--accent); color: #fff; }

.step-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  margin-bottom: 16px;
  min-width: 0;
}

.step-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.step-head .badge { width: 24px; height: 24px; font-size: 12.5px; margin-top: 1px; }
.step-head .badge.alt { background: var(--text-dim); }
.step-head h3 { margin: 0 0 3px; font-size: 15px; }
.step-head p { margin: 0; color: var(--text-dim); font-size: 12.5px; line-height: 1.5; }

.inline-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.inline-form .field { margin-bottom: 0; }
.field.grow { flex: 1 1 320px; min-width: 0; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; margin-bottom: 0; }
.field-row.wrap { flex-wrap: wrap; align-items: flex-end; }
.field-row.wrap .field { margin-bottom: 0; }
.align-end { align-self: flex-end; }

.btn.primary.auto { width: auto; }
.status.center { text-align: center; }
.push-right { margin-left: auto !important; }

.hint.inline { display: inline; margin: 0; }
.hint code {
  font-size: 11.5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
}

/* ---- step 1: detection ---- */

.detect-result, .detect-fallback, .plugin-banner {
  margin-top: 14px;
  border-radius: 8px;
  padding: 14px;
}

.detect-result {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  background: var(--ok-dim);
  border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent);
}

.detect-thumb {
  width: 180px;
  max-height: 140px;
  object-fit: contain;
  object-position: top left;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  flex-shrink: 0;
}

.detect-body { min-width: 0; flex: 1; }
.detect-title { font-weight: 700; font-size: 13.5px; color: var(--ok); margin-bottom: 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ok-mark { font-size: 15px; }

.source-chip {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--card-bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 14px;
  margin: 0;
  font-size: 12.5px;
}

.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.detect-fallback {
  background: var(--warn-dim);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
}

.warn-title { font-weight: 700; color: var(--warn); font-size: 13.5px; margin-bottom: 4px; }
.detect-fallback .hint { margin-bottom: 10px; }

.plugin-wait {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  margin-bottom: 10px;
}

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: fm-spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes fm-spin { to { transform: rotate(360deg); } }

.plugin-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--accent-dim);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  font-size: 13px;
}

.advanced {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.advanced summary {
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
}

.advanced-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-top: 12px;
}

@media (max-width: 900px) {
  .advanced-grid { grid-template-columns: 1fr; }
}

.advanced h4 { font-size: 12.5px; margin: 0 0 6px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.advanced input[type="password"] { width: 100%; }
.advanced .checkbox { margin: 8px 0; }
.btn-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.tag-opt {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  display: inline-block;
}

.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-dim); }

/* ---- step 2: live site ---- */

.viewport-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
  background: color-mix(in srgb, var(--bg) 50%, transparent);
}

.vp-label { font-size: 11.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.vp-dims { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 2px 0; }
.vp-note { font-size: 12.5px; color: var(--text-dim); }
.vp-note.ok { color: var(--ok); font-weight: 600; }
.vp-controls .checkbox { margin-bottom: 6px; }
.vp-controls .field-row .field { margin-bottom: 0; width: 100px; }

.option-row {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.option-row .checkbox { margin-bottom: 0; }

.radio-group {
  border: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12.5px;
}

.radio-group legend {
  float: left;
  margin-right: 4px;
  color: var(--text-dim);
  font-weight: 600;
}

.radio-group label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.radio-group input { width: auto; }

/* ---- step 3: interactive browser ---- */

.browser-shell {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.browser-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
  background: color-mix(in srgb, var(--bg) 70%, var(--card-bg));
  border-bottom: 1px solid var(--border);
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  border-radius: 6px;
  width: 32px;
  height: 32px;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn:not(:disabled):hover { background: var(--bg); }

.url-bar {
  flex: 1;
  min-width: 80px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 12.5px;
  padding: 7px 10px;
}

.browser-toolbar select { padding: 6px 8px; font-size: 12px; max-width: 180px; }

.state-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
  margin-left: 4px;
}

.state-dot.active { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-dim); }
.state-dot.busy { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-dim); }
.state-text { font-size: 12px; font-weight: 600; color: var(--text-dim); white-space: nowrap; }

.browser-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  min-height: 320px;
}

@media (max-width: 1000px) {
  .browser-main { grid-template-columns: 1fr; }
}

.browser-viewport {
  position: relative;
  background: #0d0f12;
  overflow: auto;
  max-height: 78vh;
  min-height: 320px;
}

.bv-stage {
  position: relative;
  margin: 0 auto;
  line-height: 0;
  outline: none;
}

.bv-stage.focused { box-shadow: 0 0 0 2px var(--accent) inset; }

#bvFrame {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
  cursor: default;
}

.bv-stage.zoom-1 { width: max-content; }
.bv-stage.zoom-1 #bvFrame { width: auto; max-width: none; }

/* Invisible input that receives keyboard focus, IME and paste for the remote page. */
.key-sink {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  resize: none;
  pointer-events: none;
}

.bv-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #99a1ac;
  font-size: 13px;
  padding: 24px;
  line-height: 1.6;
}

.bv-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 15, 18, 0.55);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  gap: 10px;
  text-align: center;
  padding: 20px;
  line-height: 1.5;
}

.bv-overlay.flash { background: rgba(255, 255, 255, 0.55); color: #1c2127; }

.select-popup {
  position: absolute;
  z-index: 5;
  background: #fff;
  color: #1c2127;
  border: 1px solid #b7bcc5;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  max-height: 280px;
  overflow-y: auto;
  min-width: 160px;
  line-height: 1.3;
  font-size: 13px;
}

.select-popup button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 7px 10px;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.select-popup button:hover, .select-popup button:focus { background: #eceafe; outline: none; }
.select-popup button.selected { font-weight: 700; }
.select-popup button:disabled { color: #9aa0a8; cursor: not-allowed; }

.history-panel {
  border-left: 1px solid var(--border);
  padding: 12px;
  overflow-y: auto;
  max-height: 78vh;
  min-width: 0;
}

@media (max-width: 1000px) {
  .history-panel { border-left: none; border-top: 1px solid var(--border); max-height: 240px; }
}

.history-panel h4, .regions-panel h4 {
  margin: 0 0 8px;
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.count {
  font-size: 11px;
  background: var(--bg);
  border-radius: 20px;
  padding: 1px 7px;
  color: var(--text-dim);
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 12px;
}

.history-list li {
  display: flex;
  gap: 7px;
  padding: 5px 0;
  border-bottom: 1px dashed var(--border);
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.history-list li:last-child { border-bottom: none; }
.history-list .h-icon { color: var(--ok); flex-shrink: 0; width: 12px; }
.history-list li.failed .h-icon { color: var(--danger); }
.history-list li.skipped .h-icon { color: var(--warn); }
.history-list li.info { color: var(--text-dim); }
.history-list li.capture { font-weight: 700; }
.history-list .h-empty { color: var(--text-dim); border: none; }

.browser-status {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  padding: 8px 12px;
  font-size: 12px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
}

.browser-status b { color: var(--text); font-weight: 600; margin-right: 4px; }
#bvCurUrl { overflow-wrap: anywhere; }

.browser-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 50%, transparent);
  flex-wrap: wrap;
}

.browser-actions .status { margin: 0; flex: 1; }

/* ---- step 4: visual test ---- */

.compare-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

@media (max-width: 700px) {
  .compare-pair { grid-template-columns: 1fr; }
}

.pair-col h4 {
  font-size: 13px;
  margin: 0 0 8px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pair-col h4 button { font-size: 11px; padding: 4px 10px; }
.pair-drop { min-height: 180px; max-height: 300px; }
.pair-meta { font-size: 12px; color: var(--text-dim); margin: 6px 0 0; line-height: 1.5; min-height: 18px; }

.test-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  flex-wrap: wrap;
  margin: 20px 0 4px;
}

.results { margin-top: 16px; }

.score-row {
  display: flex;
  gap: 16px;
  align-items: stretch;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.score-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 18px;
  min-width: 200px;
}

.score-label { font-size: 12px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.score-value { font-size: 36px; font-weight: 800; font-variant-numeric: tabular-nums; margin: 2px 0 8px; }
.score-value.good { color: var(--ok); }
.score-value.mid { color: var(--warn); }
.score-value.bad { color: var(--danger); }
.score-bar { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; }
.score-bar i { display: block; height: 100%; background: currentColor; width: 0; transition: width 0.4s ease; }
.score-value.good + .score-bar i { background: var(--ok); }
.score-value.mid + .score-bar i { background: var(--warn); }
.score-value.bad + .score-bar i { background: var(--danger); }

.stat-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin: 0;
}

.stat-grid > div {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.stat-grid dt { font-size: 11.5px; color: var(--text-dim); margin-bottom: 4px; }
.stat-grid dd { margin: 0; font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }

.warn-note {
  background: var(--warn-dim);
  color: var(--warn);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12.5px;
  margin: 0 0 12px;
}

.fm-toolbar { flex-wrap: wrap; }
.fm-toolbar .checkbox { margin-bottom: 0; }

.view-opts {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-left: 10px;
  font-size: 12px;
}

.view-opts .checkbox { margin-bottom: 0; }
.blink-label { font-weight: 700; font-size: 12px; min-width: 70px; }

.result-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  overflow: hidden;
}

@media (max-width: 1000px) {
  .result-main { grid-template-columns: 1fr; }
}

.fm-viewer {
  border: none;
  border-radius: 0;
  max-height: 78vh;
}

.fm-side {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px;
  background: #0d0f12;
}

.fm-col-label {
  position: sticky;
  top: 0;
  z-index: 2;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #eceef1;
  background: rgba(13, 15, 18, 0.85);
  padding: 5px 8px;
}

.fm-stage {
  position: relative;
  line-height: 0;
}

.fm-stage canvas {
  display: block;
  width: 100%;
  height: auto;
}

.fm-stage canvas.layer {
  position: absolute;
  top: 0;
  left: 0;
}

.fm-stage svg.regions {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.regions rect { fill: rgba(230, 25, 56, 0.08); stroke: #e61938; stroke-width: 2; vector-effect: non-scaling-stroke; }
.regions rect.selected { fill: rgba(255, 176, 32, 0.18); stroke: #ffb020; stroke-width: 3; }
.regions text { fill: #fff; font: 700 12px sans-serif; paint-order: stroke; stroke: #e61938; stroke-width: 3px; }

.regions-panel {
  border-left: 1px solid var(--border);
  padding: 12px;
  overflow-y: auto;
  max-height: 78vh;
  min-width: 0;
}

@media (max-width: 1000px) {
  .regions-panel { border-left: none; border-top: 1px solid var(--border); max-height: none; }
}

.region-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 12.5px;
}

.region-list li button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 8px;
  cursor: pointer;
  color: var(--text);
  font: inherit;
}

.region-list li button:hover { background: var(--bg); }
.region-list li button.selected { border-color: var(--accent); background: var(--accent-dim); }
.region-name { font-weight: 600; display: block; overflow-wrap: anywhere; }
.region-meta { font-size: 11.5px; color: var(--text-dim); }
.region-pct { font-weight: 700; color: var(--danger); }

.region-detail {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  font-size: 12px;
}

.region-detail .crops {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 8px 0;
}

.region-detail figure { margin: 0; }
.region-detail figcaption { font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; font-weight: 700; margin-bottom: 3px; }
.region-detail img { width: 100%; border: 1px solid var(--border); border-radius: 4px; background: #fff; display: block; }
.region-detail .kv { font-size: 11.5px; }

.results .report-bar { border-top: 1px solid var(--border); border-radius: 8px; margin-top: 12px; }

#fmStep4 .font-table-wrap { margin-top: 24px; }

/* ---- scenarios ---- */

.scenario-list { display: grid; gap: 10px; }

.scenario-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}

.scenario-info { flex: 1; min-width: 220px; }
.scenario-name { font-weight: 700; font-size: 13.5px; }
.scenario-meta { font-size: 12px; color: var(--text-dim); margin-top: 3px; line-height: 1.5; overflow-wrap: anywhere; }
.scenario-score { font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; min-width: 80px; text-align: right; }
.scenario-trend { font-size: 11px; color: var(--text-dim); display: block; font-weight: 500; }
.scenario-actions { display: flex; gap: 6px; }

.fm-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--text);
  padding: 20px;
  width: min(520px, calc(100vw - 32px));
}

.fm-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.fm-dialog h3 { margin: 0 0 14px; font-size: 16px; }
.fm-dialog .checkbox { align-items: flex-start; }
.fm-dialog .checkbox input { margin-top: 2px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

@media (max-width: 600px) {
  body { padding: 16px 16px 48px; }
  .detect-result { flex-direction: column; }
  .detect-thumb { width: 100%; }
}

/* ---- Figma & Site Match: scrubber view ---- */

.fm-scrub {
  user-select: none;
  touch-action: none;
  cursor: ew-resize;
  outline: none;
}

.fm-scrub:focus-visible { box-shadow: 0 0 0 2px var(--accent) inset; }

.fm-scrub-clip {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 50%;
  overflow: hidden;
  z-index: 1;
}

.fm-stage .fm-scrub-clip canvas { max-width: none; }
.fm-scrub svg.regions { z-index: 2; }
.fm-scrub .scrubber-handle { z-index: 3; }

.fm-scrub-tag {
  position: absolute;
  top: 8px;
  z-index: 3;
  font: 700 11px/1 sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #fff;
  background: rgba(13, 15, 18, 0.75);
  padding: 5px 8px;
  border-radius: 4px;
  pointer-events: none;
}

.fm-scrub-tag.left { left: 8px; }
.fm-scrub-tag.right { right: 8px; }

.fm-include-bar { gap: 12px; }

/* ---- Figma fallback options (view-only files etc.) ---- */

.fallback-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 10px 0 12px;
}

@media (max-width: 1000px) {
  .fallback-options { grid-template-columns: 1fr; }
}

.fallback-option {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  min-width: 0;
}

.fallback-option h4 { margin: 0 0 6px; font-size: 12.5px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.fallback-option .hint { margin-bottom: 10px; }
.fallback-option .btn-row input { flex: 1; min-width: 120px; }
.fallback-option .field { margin-bottom: 0; }
.fallback-option select { width: 100%; }
#fmManualNote { margin-top: 8px; }
.fallback-option .field.small:has(#fmManualScale) { flex: 0 0 96px; }
.plugin-wait.error { color: var(--danger); font-weight: 600; }
.fallback-options.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1000px) { .fallback-options.two { grid-template-columns: 1fr; } }
.fallback-option .field-row + .field-row { margin-top: 8px; }
.fallback-option .note-line { margin: 10px 0; }
.advanced-token { margin-top: 10px; max-width: 480px; }
.advanced-token input { width: 100%; }
