:root {
  --bg: #f4f4f5;
  --chrome: #ffffff;
  --chrome-2: #f4f4f5;
  --line: #e4e4e7;
  --text: #18181b;
  --muted: #71717a;
  --faint: #a1a1aa;
  --accent: #7c3aed;
  --hover: #f4f4f5;
  --on: #18181b;
  --on-text: #fafafa;
  --shadow: 0 12px 40px rgb(0 0 0 / 0.12), 0 2px 6px rgb(0 0 0 / 0.06);
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #09090b;
    --chrome: #111113;
    --chrome-2: #18181b;
    --line: #27272a;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --faint: #71717a;
    --accent: #a78bfa;
    --hover: #1f1f23;
    --on: #f4f4f5;
    --on-text: #18181b;
    --shadow: 0 16px 50px rgb(0 0 0 / 0.5), 0 2px 6px rgb(0 0 0 / 0.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #09090b;
  --chrome: #111113;
  --chrome-2: #18181b;
  --line: #27272a;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --faint: #71717a;
  --accent: #a78bfa;
  --hover: #1f1f23;
  --on: #f4f4f5;
  --on-text: #18181b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 13px/1.4 var(--sans); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
button:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.app { display: grid; grid-template-rows: 52px 1fr; grid-template-columns: 1fr; height: 100vh; }
.app.with-panel { grid-template-columns: 1fr 340px; }
.app > .bar { grid-column: 1 / -1; }

/* ---- Top bar ---- */
.bar { display: flex; align-items: center; gap: 12px; padding: 0 12px; background: var(--chrome); border-bottom: 1px solid var(--line); min-width: 0; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; padding-right: 4px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: linear-gradient(135deg, #a78bfa, #22d3ee); box-shadow: 0 0 12px rgb(139 92 246 / 0.6); flex: none; }
.dot.big { width: 28px; height: 28px; }
.site { letter-spacing: -0.01em; }

.versions { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1 1 auto; }
.vs { color: var(--faint); font-size: 12px; }
.picker { position: relative; display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 8px 0 10px; border: 1px solid var(--line);
  border-radius: 9px; background: var(--chrome-2); min-width: 0; max-width: 280px; cursor: pointer; }
.picker:hover { border-color: var(--faint); }
.picker .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.picker select { appearance: none; border: 0; background: transparent; color: var(--text); font: 500 13px/1 var(--sans); min-width: 0; max-width: 200px;
  text-overflow: ellipsis; cursor: pointer; padding-right: 2px; outline: none; }
.picker svg { color: var(--muted); flex: none; pointer-events: none; }
.pr { color: var(--muted); text-decoration: none; font: 500 12px var(--mono); padding: 4px 6px; border-radius: 6px; }
.pr:hover { color: var(--text); background: var(--hover); }

.flip { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--chrome-2); border: 1px solid var(--line); }
.flip button { border: 0; background: transparent; height: 26px; padding: 0 14px; border-radius: 8px; font-weight: 500; color: var(--muted); cursor: pointer; transition: background 0.12s, color 0.12s; }
.flip button.on { background: var(--on); color: var(--on-text); box-shadow: 0 1px 2px rgb(0 0 0 / 0.2); }

.stepper { display: inline-flex; align-items: center; gap: 2px; }
.stepper .count { min-width: 84px; text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }
.stepper button, .icon { display: inline-grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; color: var(--muted); }
.stepper button:hover:not(:disabled), .icon:hover { background: var(--hover); color: var(--text); }
.stepper button:disabled { opacity: 0.35; cursor: default; }
.icon.on { color: var(--text); background: var(--hover); }

.tools { display: inline-flex; align-items: center; gap: 2px; margin-left: auto; }
.toggle { display: inline-flex; align-items: center; gap: 8px; height: 30px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; color: var(--muted); }
.toggle:hover { background: var(--hover); color: var(--text); }
.toggle .sw { position: relative; width: 26px; height: 15px; border-radius: 99px; background: var(--line); transition: background 0.15s; }
.toggle .sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 11px; height: 11px; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 2px rgb(0 0 0 / 0.3); }
.toggle.on { color: var(--text); }
.toggle.on .sw { background: var(--accent); }
.toggle.on .sw::after { transform: translateX(11px); }

/* ---- Stage ---- */
.stage { position: relative; min-width: 0; min-height: 0; background: var(--bg); }
.frame { position: absolute; inset: 0; }
.frame iframe { width: 100%; height: 100%; border: 0; background: #fff; display: block; }
.stage.flip .frame { visibility: hidden; }
.stage.flip.show-head .frame.head, .stage.flip.show-base .frame.base { visibility: visible; }
.stage.split { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px; }
.stage.split .frame { position: relative; inset: auto; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); padding-top: 28px; background: var(--chrome); }
.stage.split .frame .tag { position: absolute; top: 0; left: 0; right: 0; height: 28px; display: flex; align-items: center; padding: 0 10px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
.badge { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); padding: 6px 12px; border-radius: 99px; font: 600 12px var(--sans);
  color: #fff; background: rgb(24 24 27 / 0.88); backdrop-filter: blur(8px); pointer-events: none; box-shadow: var(--shadow); }
.badge.base { background: rgb(229 72 77 / 0.92); }

/* ---- Panel ---- */
.panel { overflow: auto; background: var(--chrome); border-left: 1px solid var(--line); padding: 8px 0 0; display: flex; flex-direction: column; }
.panel section { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.panel h2 { margin: 0 0 10px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.note { margin: 8px 16px 4px; padding: 10px 12px; border-radius: 9px; background: var(--chrome-2); color: var(--muted); font-size: 12px; }
.note b { color: var(--text); }
.cats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 10px; }
.cat { display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; background: transparent; cursor: pointer; text-align: left; }
.cat:hover { background: var(--hover); }
.cat i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.cat span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.cat b { font-weight: 600; font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted); }
.cat.muted { opacity: 0.45; }
.cat.muted i { background: transparent; box-shadow: inset 0 0 0 1.5px var(--c); }
.cat.muted span { text-decoration: line-through; }

.changes, .pages, .endpoints, .files { list-style: none; margin: 0; padding: 0; }
.changes button { display: flex; gap: 10px; width: 100%; padding: 8px; border: 0; border-radius: 8px; background: transparent; text-align: left; cursor: pointer; }
.changes button:hover { background: var(--hover); }
.changes button.on { background: var(--hover); box-shadow: inset 2px 0 0 var(--c); }
.changes i { width: 8px; height: 8px; margin-top: 5px; border-radius: 50%; background: var(--c); flex: none; }
.changes .what { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.changes .label { overflow-wrap: anywhere; }
.changes .where { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.empty { padding: 10px 8px; color: var(--muted); }

.pages button { display: flex; justify-content: space-between; width: 100%; padding: 7px 8px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; font-family: var(--mono); font-size: 12px; }
.pages button:hover, .pages button.on { background: var(--hover); }
.pages b { color: var(--muted); font-weight: 500; }

.select { width: 100%; height: 32px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--chrome-2); color: var(--text); font: inherit; }
.sub { margin: 8px 0; color: var(--muted); font-size: 12px; }
.endpoints li { display: flex; flex-direction: column; gap: 3px; padding: 8px 10px; margin-top: 6px; border-radius: 8px; background: var(--chrome-2); border-left: 2px solid #3e63dd; }
.endpoints code { font: 12px var(--mono); }
.endpoints code b { color: #3e63dd; }
.endpoints .via { font: 11px var(--mono); color: var(--muted); overflow-wrap: anywhere; }
.endpoints .hit { align-self: flex-start; font-size: 11px; font-weight: 600; color: #fff; background: #3e63dd; padding: 2px 7px; border-radius: 99px; }
.hint { margin: 8px 0 0; color: var(--faint); font-size: 12px; }

.files li { display: flex; align-items: center; gap: 8px; padding: 3px 0; font: 12px var(--mono); }
.files .p { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left; }
.files .st { width: 16px; text-align: center; font-weight: 700; color: var(--muted); }
.files .st.added { color: #30a46c; } .files .st.deleted { color: #e5484d; } .files .st.modified { color: #f5a524; }
.files .d em { color: #30a46c; font-style: normal; } .files .d s { color: #e5484d; text-decoration: none; }
.keys { margin-top: auto; padding: 12px 16px; color: var(--faint); font-size: 11px; line-height: 2; }
kbd { display: inline-block; min-width: 18px; padding: 0 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; font: 11px/16px var(--mono); text-align: center; color: var(--muted); background: var(--chrome-2); }

/* ---- Settings ---- */
.popover { position: fixed; top: 58px; right: 12px; z-index: 10; width: 300px; padding: 14px 16px 12px; border-radius: 14px; background: var(--chrome); border: 1px solid var(--line); box-shadow: var(--shadow); }
.pop-head { display: flex; align-items: center; justify-content: space-between; }
.popover h2 { margin: 0; font-size: 14px; }
.popover h3 { margin: 14px 0 8px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.seg { display: flex; padding: 3px; border-radius: 10px; background: var(--chrome-2); border: 1px solid var(--line); }
.seg button { flex: 1; height: 26px; border: 0; border-radius: 7px; background: transparent; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--on); color: var(--on-text); }
.row { display: flex; align-items: center; gap: 8px; padding: 5px 0; cursor: pointer; }
.row input { accent-color: var(--accent); margin: 0; }
.row .sw { width: 8px; height: 8px; border-radius: 50%; }
.row .n { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

.empty-state { height: 100%; display: grid; place-content: center; justify-items: center; text-align: center; gap: 4px; padding: 24px; color: var(--muted); }
.empty-state h1 { margin: 12px 0 0; font-size: 18px; color: var(--text); }
.empty-state p { margin: 0; max-width: 420px; }

@media (max-width: 1100px) {
  .app.with-panel { grid-template-columns: 1fr 300px; }
  .vs, .picker .lbl, .toggle { font-size: 0; gap: 0; }
}
@media (max-width: 760px) {
  .app.with-panel { grid-template-columns: 1fr; grid-template-rows: 52px 1fr 40vh; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .bar { overflow-x: auto; }
}

/* ---- Highlight style picker ---- */
.divider { width: 1px; height: 20px; margin: 0 4px; background: var(--line); }
.style-picker { position: relative; }
.style-picker > .toggle { color: var(--text); }
.style-picker > .toggle svg { color: var(--muted); }
.style-picker .menu { position: absolute; top: calc(100% + 6px); right: 0; z-index: 20; width: 260px; padding: 6px; border-radius: 12px;
  background: var(--chrome); border: 1px solid var(--line); box-shadow: var(--shadow); }
.style-picker .menu button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px; border: 0; border-radius: 8px;
  background: transparent; cursor: pointer; text-align: left; }
.style-picker .menu button:hover { background: var(--hover); }
.style-picker .menu button.on { background: var(--hover); box-shadow: inset 2px 0 0 var(--accent); }
.style-picker .menu span { display: flex; flex-direction: column; gap: 1px; }
.style-picker .menu small { color: var(--muted); font-size: 11px; }
.style-picker .menu .hint { margin: 4px 8px 2px; }

/* Swatches mirror the in-page treatments (agent/overlay.ts). */
.preview { --c: #f5a524; position: relative; width: 22px; height: 16px; flex: none; border-radius: 3px; }
.preview.brackets { background:
  linear-gradient(var(--c),var(--c)) top left/6px 1.5px no-repeat, linear-gradient(var(--c),var(--c)) top left/1.5px 6px no-repeat,
  linear-gradient(var(--c),var(--c)) top right/6px 1.5px no-repeat, linear-gradient(var(--c),var(--c)) top right/1.5px 6px no-repeat,
  linear-gradient(var(--c),var(--c)) bottom left/6px 1.5px no-repeat, linear-gradient(var(--c),var(--c)) bottom left/1.5px 6px no-repeat,
  linear-gradient(var(--c),var(--c)) bottom right/6px 1.5px no-repeat, linear-gradient(var(--c),var(--c)) bottom right/1.5px 6px no-repeat; }
.preview.outline, .preview.labels, .preview.flash { outline: 2px solid var(--c); outline-offset: -2px; box-shadow: 0 0 6px color-mix(in srgb, var(--c) 50%, transparent); }
.preview.fill { background: color-mix(in srgb, var(--c) 30%, transparent); outline: 2px solid var(--c); outline-offset: -2px; }
.preview.labels::before { content: ""; position: absolute; left: 0; top: -2px; width: 10px; height: 5px; border-radius: 2px; background: var(--c); }
.preview.spotlight { background: rgb(9 9 11 / .7); }
.preview.spotlight::after { content: ""; position: absolute; inset: 4px 6px; border-radius: 2px; background: #fff; outline: 1.5px solid var(--c); }
.preview.flash { animation: preview-flash 1s ease-in-out infinite alternate; }
@keyframes preview-flash { to { box-shadow: 0 0 10px var(--c); background: color-mix(in srgb, var(--c) 25%, transparent); } }
@media (prefers-reduced-motion: reduce) { .preview.flash { animation: none; } }

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