/* PromptShrink v4: calm, professional UI. 8px spacing scale, one accent colour. */

:root {
  --s1: 4px; --s2: 8px; --s3: 16px; --s4: 24px; --s5: 32px; --s6: 48px;
  --radius: 12px; --radius-sm: 8px; --radius-xs: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --nav-w: 236px;

  --bg: #f6f7f9;
  --nav-bg: #fbfbfc;
  --surface: #ffffff;
  --surface-2: #f3f4f7;
  --surface-3: #e8ebf0;
  --border: #e4e7ec;
  --border-strong: #cfd4dc;
  --text: #121620;
  --text-2: #434a58;
  --muted: #697181;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --accent-line: #c7cbff;
  --on-accent: #ffffff;
  --good: #137a3c;
  --good-soft: #e8f6ee;
  --good-bar: #22a55a;
  --warn: #9a5b00;
  --warn-soft: #fff6e3;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --removed: #b42318;
  --removed-bg: #fde8e6;
  --protected-bg: #fff1c7;
  --protected-line: #a85b00;
  --chart-line: #4f46e5;
  --chart-grid: #eceef2;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 4px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14), 0 2px 6px rgba(16, 24, 40, .06);
  --focus: 0 0 0 3px rgba(79, 70, 229, .35);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f13; --nav-bg: #111318; --surface: #161920; --surface-2: #1c2028; --surface-3: #262b36;
    --border: #272c37; --border-strong: #3a4150;
    --text: #e8eaef; --text-2: #b9bfcb; --muted: #8b93a3;
    --accent: #8b85ff; --accent-hover: #a29dff; --accent-soft: #22213f; --accent-line: #3d3a7a; --on-accent: #0e1014;
    --good: #4ade80; --good-soft: #12251a; --good-bar: #34c76f;
    --warn: #fbbf47; --warn-soft: #2b2310;
    --danger: #f97066; --danger-soft: #3a1714;
    --removed: #f97066; --removed-bg: #3a1714;
    --protected-bg: #3a2c0c; --protected-line: #fdb022;
    --chart-line: #7c74f5; --chart-grid: #232833;
    --shadow-sm: none; --shadow: 0 1px 2px rgba(0,0,0,.35); --shadow-lg: 0 16px 40px rgba(0,0,0,.5);
    --focus: 0 0 0 3px rgba(139, 133, 255, .45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0f13; --nav-bg: #111318; --surface: #161920; --surface-2: #1c2028; --surface-3: #262b36;
  --border: #272c37; --border-strong: #3a4150;
  --text: #e8eaef; --text-2: #b9bfcb; --muted: #8b93a3;
  --accent: #8b85ff; --accent-hover: #a29dff; --accent-soft: #22213f; --accent-line: #3d3a7a; --on-accent: #0e1014;
  --good: #4ade80; --good-soft: #12251a; --good-bar: #34c76f;
  --warn: #fbbf47; --warn-soft: #2b2310;
  --danger: #f97066; --danger-soft: #3a1714;
  --removed: #f97066; --removed-bg: #3a1714;
  --protected-bg: #3a2c0c; --protected-line: #fdb022;
  --chart-line: #7c74f5; --chart-grid: #232833;
  --shadow-sm: none; --shadow: 0 1px 2px rgba(0,0,0,.35); --shadow-lg: 0 16px 40px rgba(0,0,0,.5);
  --focus: 0 0 0 3px rgba(139, 133, 255, .45);
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 24px; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14.5px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd, pre { font-family: var(--mono); }
code { font-size: .88em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--border); overflow-wrap: anywhere; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.fw-normal { font-weight: 400; }
.good { color: var(--good); }
.warn { color: var(--warn); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 8px; top: -40px; background: var(--accent); color: var(--on-accent); padding: 8px 12px; border-radius: 6px; z-index: 100; }
.skip-link:focus { top: 8px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.ic-sm { width: 15px; height: 15px; }
.ic-xl { width: 36px; height: 36px; stroke-width: 1.5; color: var(--muted); }
:focus-visible { outline: none; box-shadow: var(--focus); }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); min-height: 100vh;
  /* paint the sidebar column full height, also on pages taller than the window */
  background: linear-gradient(to right, var(--nav-bg) calc(var(--nav-w) - 1px), var(--border) calc(var(--nav-w) - 1px) var(--nav-w), transparent var(--nav-w)); }
.nav {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: var(--s4);
  padding: 18px 12px 14px; background: var(--nav-bg); border-right: 1px solid var(--border); z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); padding: 0 8px; }
.brand:hover { text-decoration: none; }
.logo { color: var(--accent); display: inline-flex; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: 16px; letter-spacing: -.01em; }
.brand-text small { font-size: 11.5px; color: var(--muted); }
.nav-list { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 550; font-size: 14px; white-space: nowrap; position: relative;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav-item .ic { width: 18px; height: 18px; }
.nav-badge { margin-left: auto; font-size: 11px; font-weight: 650; min-width: 20px; line-height: 18px; padding: 0 6px; text-align: center; border-radius: 999px; background: var(--surface-3); color: var(--text-2); }
.nav-item[aria-current="page"] .nav-badge { background: var(--surface); color: var(--accent); }
.nav-sep { height: 1px; background: var(--border); margin: 8px 10px; }
.nav-foot { margin-top: auto; display: grid; gap: var(--s2); }
.status-card {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 10px; cursor: pointer;
}
.status-card:hover { border-color: var(--border-strong); }
.status-card .dot, .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.status-card[data-state="ready"] .dot { background: var(--good-bar); box-shadow: 0 0 0 3px var(--good-soft); }
.status-card[data-state="loading"] .dot { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.status-card[data-state="error"] .dot { background: var(--danger); }
.status-lines { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.status-lines strong { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-lines small { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-foot-row { display: flex; align-items: center; gap: 2px; }
.privacy-tag { margin-left: auto; display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; color: var(--good); padding: 3px 8px; border-radius: 999px; background: var(--good-soft); white-space: nowrap; }
@keyframes pulse { 50% { opacity: .35; } }

.main { min-width: 0; padding: 28px 32px 48px; }
.view { max-width: 1440px; margin: 0 auto; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--s3); margin-bottom: 20px; flex-wrap: wrap; }
.page-head > div { min-width: 0; }
.page-head p { margin-top: 4px; max-width: 78ch; }
.uses-settings { font-size: 13px; color: var(--muted); margin: -8px 0 var(--s3); }
.uses-settings strong { color: var(--text-2); font-weight: 600; }
.uses-settings a { font-weight: 600; }
.empty { display: flex; flex-direction: column; align-items: center; gap: var(--s2); text-align: center; padding: var(--s6) var(--s4); color: var(--text-2); }

/* ---------- Buttons & controls ---------- */
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius-sm); border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn-bordered { border-color: var(--border-strong); height: 36px; width: 38px; background: var(--surface); }
.btn { font: inherit; font-size: 13.5px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid transparent; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, color .15s, box-shadow .15s; color: var(--text); background: none; text-decoration: none; }
.btn:hover { text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-sm); }
.btn-primary:not(:disabled):hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); }
.btn-secondary:not(:disabled):hover { background: var(--surface-2); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:not(:disabled):hover { background: var(--surface-2); color: var(--text); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; gap: 5px; }
.btn-lg { height: 46px; padding: 0 22px; font-size: 15px; }
.btn.done { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, var(--border)); }
.btn-row { display: flex; gap: var(--s2); flex-wrap: wrap; }
.btn[aria-busy="true"] .ic { animation: spin 1s linear infinite; }
.kbd { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: rgba(255,255,255,.2); font-weight: 500; font-family: var(--mono); }
kbd.key { display: inline-block; min-width: 24px; text-align: center; font-size: 12px; padding: 2px 7px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--border-strong); border-bottom-width: 2px; color: var(--text); }

.label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
select, input[type="text"], input[type="number"], input[type="search"] {
  font: inherit; font-size: 13.5px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 7px 10px; height: 36px; width: 100%;
}
select:focus-visible, input:focus-visible, textarea:focus-visible { border-color: var(--accent); }
input#force { font-family: var(--mono); font-size: 12.5px; }
select { appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%23697181' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
.field-hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.input-suffix { display: flex; align-items: center; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); }
.input-suffix:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
.input-suffix input { border: 0; box-shadow: none !important; font-size: 16px; font-weight: 650; height: 38px; min-width: 0; }
.input-suffix span { padding: 0 12px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.input-with-btn { display: flex; gap: var(--s2); }

/* Segmented control */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; gap: 2px; }
.seg-btn { font: 600 13px var(--font); color: var(--text-2); background: transparent; border: 0; border-radius: 6px; padding: 5px 12px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.seg-sm .seg-btn { font-size: 12.5px; padding: 4px 10px; }
.seg-xs .seg-btn { font-size: 11.5px; padding: 2px 8px; }
.seg-btn:hover:not(:disabled) { color: var(--text); }
.seg-btn[aria-checked="true"], .seg-btn[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }
.seg-btn:disabled { opacity: .45; cursor: not-allowed; }
.seg-full { display: flex; width: 100%; }
.seg-full .seg-btn { flex: 1; padding: 7px 10px; }
.seg-btn .dot { width: 7px; height: 7px; background: var(--border-strong); }
.dot.ready { background: var(--good-bar); }
.dot.loading { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.dot.error { background: var(--danger); }

/* Checkbox rows */
.check { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; cursor: pointer; }
.check + .check { border-top: 1px solid var(--border); }
.check input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--accent); flex: none; cursor: pointer; }
.check span { display: flex; flex-direction: column; min-width: 0; }
.check strong { font-size: 13.5px; font-weight: 600; }
.check small { font-size: 12px; color: var(--muted); }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 12.5px; font-weight: 550; color: var(--text-2); position: relative; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 34px; height: 20px; margin: 0; cursor: pointer; }
.switch-ui { width: 34px; height: 20px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border-strong); position: relative; flex: none; transition: background .15s, border-color .15s; }
.switch-ui::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + .switch-ui { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-ui::after { transform: translateX(14px); }
.switch input:focus-visible + .switch-ui { box-shadow: var(--focus); }

/* Range */
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 24px; background: transparent; margin: 0; --pct: 50%; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 999px; background: linear-gradient(to right, var(--accent) var(--pct), var(--surface-3) var(--pct)); }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 999px; background: var(--surface-3); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 999px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -7px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); box-shadow: var(--shadow); cursor: grab; }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); cursor: grab; }
input[type="range"]:focus-visible { box-shadow: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: var(--focus); }
input[type="range"]:focus-visible::-moz-range-thumb { box-shadow: var(--focus); }

/* Menus (details/summary) */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-pop { position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; min-width: 250px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 4px; display: grid; }
.menu-right .menu-pop { left: auto; right: 0; }
.menu-pop > button { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; text-align: left; font: inherit; color: var(--text); background: none; border: 0; border-radius: 6px; padding: 8px 10px; cursor: pointer; }
.menu-pop > button:hover, .menu-pop > button:focus-visible { background: var(--surface-2); }
.menu-pop strong { font-size: 13px; font-weight: 600; }
.menu-pop small { font-size: 12px; color: var(--muted); }
.menu-form { padding: 10px 14px 12px; min-width: 280px; }
.menu-title { font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 2px; }
.btn-select { width: 100%; justify-content: space-between; font-weight: 550; }
.btn-select span { overflow: hidden; text-overflow: ellipsis; }
.menu[open] > .btn-select { border-color: var(--accent); }

/* Spinner */
.spinner { width: 16px; height: 16px; flex: none; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } .dot { animation: none !important; } * { scroll-behavior: auto !important; } }

/* ---------- Compress: toolbar (one compact row) ---------- */
.toolbar {
  display: grid; grid-template-columns: minmax(320px, 1.9fr) minmax(170px, .8fr) minmax(170px, .8fr) auto;
  align-items: end; padding: 10px 16px 12px; gap: 0;
}
.tb-group { padding: 0 16px; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.tb-strength { container-type: inline-size; }
/* Only show the level hint when there is room for it; otherwise it's the tooltip on the value. */
@container (max-width: 640px) { #level-hint { display: none; } }
.tb-group:first-child { padding-left: 0; }
.tb-group + .tb-group { border-left: 1px solid var(--border); }
.tb-label-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; min-height: 22px; min-width: 0; }
.tb-label { font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); min-height: 22px; display: flex; align-items: center; flex: none; }
.tb-label-row .seg { margin-left: auto; flex: none; }
.tb-hint { font-size: 12px; color: var(--muted); line-height: 1.4; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-hint[data-tone="warn"] { color: var(--warn); }
.rate-out { font-size: 12.5px; color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; flex: none; }
.rate-out strong { color: var(--accent); font-size: 13px; }
.rate-out[data-tone="warn"] strong { color: var(--warn); }
.tb-control { display: flex; align-items: center; gap: 10px; height: 34px; }
.range-end { font-size: 11px; color: var(--muted); white-space: nowrap; flex: none; }
.tb-control input[type="range"] { flex: 1; min-width: 80px; }
.tb-control .input-suffix { width: 100%; }
.tb-control .input-suffix input { height: 32px; font-size: 14px; }
.tb-model .seg-full { min-height: 34px; }
.tb-model .seg-full .seg-btn { padding: 5px 10px; }
.tb-keep .btn-select { height: 34px; }
.tb-action { padding-left: 16px; border-left: 1px solid var(--border); display: flex; align-items: center; gap: 14px; }
.tb-action .btn { height: 38px; padding: 0 16px; font-size: 14px; }

/* Slider: larger handle and hit area, smooth feedback */
input#rate { height: 28px; }
input#rate::-webkit-slider-thumb { width: 22px; height: 22px; margin-top: -8px; transition: transform .12s, box-shadow .12s; }
input#rate::-moz-range-thumb { width: 18px; height: 18px; transition: transform .12s; }
input#rate:hover::-webkit-slider-thumb { transform: scale(1.1); }
input#rate:active::-webkit-slider-thumb { cursor: grabbing; transform: scale(1.15); box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 18%, transparent); }
input#rate:active::-moz-range-thumb { cursor: grabbing; transform: scale(1.15); }

.status-line { display: flex; align-items: center; gap: 10px; color: var(--text-2); font-size: 13px; min-height: 22px; margin: 12px 2px; }
.status-line[data-tone="busy"] { color: var(--accent); }
.status-line[data-tone="error"] { color: var(--danger); }
.status-line[data-tone="good"] { color: var(--good); }
.status-line[data-tone="stale"] { color: var(--warn); }

/* ---------- Compress: editors ---------- */
.editors { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s3); }
.panel { display: flex; flex-direction: column; min-width: 0; container-type: inline-size; }
/* Narrow panels: tool buttons show icons only (names stay in title and aria-label). */
@container (max-width: 560px) { .tool-text { display: none; } }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--border); min-height: 50px; }
#output-panel .panel-head { padding-left: 8px; }
.panel-title { font-weight: 650; font-size: 14px; }
.panel-tools { display: flex; align-items: center; gap: 2px; }
.panel-foot { display: flex; justify-content: space-between; align-items: center; gap: var(--s2); flex-wrap: wrap; padding: 8px 16px; border-top: 1px solid var(--border); font-size: 12.5px; background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); min-height: 40px; }
.counts { color: var(--text-2); font-variant-numeric: tabular-nums; }
.counts.over { color: var(--danger); font-weight: 600; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text-2); white-space: nowrap; }
.chip.protected { background: var(--protected-bg); border-color: transparent; color: var(--protected-line); }
.drop-wrap, .out-wrap { position: relative; display: flex; flex: 1; min-height: 0; }
textarea, .diff { font-family: var(--mono); font-size: 13px; line-height: 1.7; color: var(--text); background: var(--surface); border: 0; padding: var(--s3); margin: 0; width: 100%; height: clamp(340px, 52vh, 640px); resize: vertical; overflow: auto; }
textarea::placeholder { color: var(--muted); }
textarea:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.diff { white-space: pre-wrap; word-break: break-word; resize: none; }
.diff del { color: var(--removed); background: var(--removed-bg); text-decoration: line-through; text-decoration-thickness: 1px; border-radius: 3px; }
mark.protected { background: var(--protected-bg); color: inherit; border-radius: 3px; text-decoration: underline dotted var(--protected-line); text-underline-offset: 3px; }
.legend { display: flex; gap: 10px; font-size: 12px; }
.legend del { color: var(--removed); background: var(--removed-bg); padding: 0 4px; border-radius: 3px; }
.legend mark { padding: 0 4px; }
.drop-overlay { position: absolute; inset: 8px; display: grid; place-content: center; justify-items: center; gap: 6px; border: 2px dashed var(--accent); border-radius: var(--radius-sm); background: color-mix(in srgb, var(--accent-soft) 94%, transparent); color: var(--accent); font-weight: 600; pointer-events: none; z-index: 3; }
.busy-veil { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--surface) 55%, transparent); color: var(--accent); z-index: 2; border-radius: 0; }
.busy-veil .spinner { width: 26px; height: 26px; border-width: 3px; }

/* Empty-state guidance laid over the text boxes */
.start { position: absolute; inset: 0; display: grid; place-items: center; padding: var(--s4); pointer-events: none; overflow: auto; }
.start-inner { max-width: 440px; width: 100%; text-align: center; display: grid; gap: 10px; justify-items: center; }
.start-title { font-size: 16px; font-weight: 650; color: var(--text); }
.start-inner .muted { font-size: 13px; }
.start-actions { display: flex; gap: var(--s2); flex-wrap: wrap; justify-content: center; margin-top: 6px; }
.start-actions .btn, .sample-card, .start a { pointer-events: auto; }
.start-or { font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 10px; display: flex; align-items: center; gap: 10px; width: 100%; }
.start-or::before, .start-or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.sample-cards { display: grid; gap: 6px; width: 100%; }
.sample-card { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 10px; align-items: center; text-align: left; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 12px; cursor: pointer; transition: border-color .15s, background .15s; }
.sample-card:hover { border-color: var(--accent-line); background: var(--accent-soft); }
.sample-card .ic { color: var(--muted); grid-row: span 2; }
.sample-card strong { font-size: 13px; font-weight: 600; }
.sample-card small { font-size: 12px; color: var(--muted); grid-column: 2; }
.sample-card .go { grid-row: 1 / span 2; grid-column: 3; color: var(--accent); }
.steps { list-style: none; padding: 0; margin: 6px 0 0; display: grid; gap: 10px; text-align: left; width: 100%; max-width: 340px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; }
.steps li > span:last-child { display: flex; flex-direction: column; }
.steps strong { font-size: 13.5px; font-weight: 600; }
.steps small { font-size: 12.5px; color: var(--muted); }
.step-n { width: 24px; height: 24px; flex: none; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.start-note { margin-top: 8px; }

/* ---------- Compress: results ---------- */
.results { display: grid; gap: var(--s3); margin-top: var(--s3); grid-template-columns: minmax(0, 1fr); }
.eyebrow { font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.kpis { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr) repeat(3, minmax(0, 1fr)); padding: 10px 0; margin-bottom: var(--s3); }
.kpi { padding: 0 18px; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.kpi + .kpi { border-left: 1px solid var(--border); }
.kpi .eyebrow { font-size: 10.5px; }
.kpi-big { font-size: 24px; font-weight: 750; line-height: 1.2; letter-spacing: -.02em; color: var(--good); font-variant-numeric: tabular-nums; }
.kpi-big.neutral { color: var(--text); }
.kpi-val { font-size: 17px; font-weight: 650; line-height: 1.2; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 6px; letter-spacing: -.01em; min-height: 29px; white-space: nowrap; }
.kpi-arrow { color: var(--muted); }
.kpi-sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub code { font-size: 10.5px; padding: 0 4px; }
.kpi-bar { flex: 1; min-width: 40px; height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin-left: 6px; }
.kpi-bar span { display: block; height: 100%; width: 0; background: var(--good-bar); border-radius: 999px; transition: width .5s ease; }

.details { overflow: hidden; }
.details-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 12px; overflow-x: auto; scrollbar-width: none; }
.details-tabs::-webkit-scrollbar { display: none; }
.dtab { font: 600 13.5px var(--font); color: var(--text-2); background: none; border: 0; padding: 13px 10px 11px; border-bottom: 2px solid transparent; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; margin-bottom: -1px; }
.dtab:hover { color: var(--text); }
.dtab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.dtab:focus-visible { box-shadow: inset var(--focus); border-radius: 6px 6px 0 0; }
.dtab-badge { font-size: 11px; font-weight: 700; min-width: 18px; line-height: 18px; padding: 0 5px; text-align: center; border-radius: 999px; background: var(--warn-soft); color: var(--warn); }
.dpanel { padding: 18px 20px 20px; }
.dpanel-title { font-size: 13px; color: var(--text-2); margin-bottom: 10px; }
.overview { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(260px, 1fr); gap: var(--s4); align-items: start; }
.insights { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr); }
.insight { display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 13.5px; }
.insight .ic { margin-top: 1px; }
.insight.tone-good { background: var(--good-soft); }
.insight.tone-good .ic { color: var(--good); }
.insight.tone-warn { background: var(--warn-soft); }
.insight.tone-warn .ic { color: var(--warn); }
.insight.tone-info .ic { color: var(--accent); }
.insight .insight-action { margin-top: 8px; }
.insight .btn { white-space: normal; height: auto; min-height: 30px; padding-top: 4px; padding-bottom: 4px; text-align: left; }
.mini-stats { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.mini-stats > div { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; min-width: 0; }
.mini-stats dt { font-size: 12px; color: var(--muted); }
.mini-stats dd { margin: 0; font-weight: 650; font-size: 15px; font-variant-numeric: tabular-nums; }
.mini-stats dd.sub { font-weight: 400; font-size: 12px; color: var(--muted); }

.cost-layout { display: grid; grid-template-columns: minmax(220px, 300px) minmax(0, 1fr); gap: var(--s4); align-items: start; }
.cost-controls { display: grid; gap: 12px; }
.cost-table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.cost-table th, .cost-table td { padding: 8px 8px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.cost-table thead th { font-size: 12px; color: var(--muted); font-weight: 600; }
.cost-table tbody th { text-align: left; font-weight: 500; color: var(--text-2); }
.cost-table td.good { font-weight: 650; }
.cost-table tr:last-child th, .cost-table tr:last-child td { border-bottom: 0; }

.quality-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s3); margin-bottom: 14px; }
.quality-head p { max-width: 80ch; font-size: 13.5px; }
.quality-controls { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(260px, 2fr) auto; gap: var(--s3); align-items: start; }
.field-grow { min-width: 0; }
.quality-run { margin-top: 25px; }
.task-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.task-chip { font: 500 12px var(--font); padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); cursor: pointer; }
.task-chip:hover { border-color: var(--accent); color: var(--accent); }
.callout { margin-top: var(--s3); padding: 10px 14px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--text); font-size: 13px; border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); }
.callout code { background: var(--surface); }
.quality-status { margin: var(--s3) 0 0; }
.similarity { display: grid; grid-template-columns: auto 1fr; gap: var(--s5); align-items: center; margin: var(--s3) 0; padding: 14px var(--s3); border-radius: var(--radius-sm); background: var(--surface-2); }
.sim-value { font-size: 40px; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.meter { height: 10px; border-radius: 999px; background: var(--surface); overflow: hidden; border: 1px solid var(--border); }
.meter span { display: block; height: 100%; width: 0; background: var(--good-bar); transition: width .5s ease; }
.meter span.mid { background: var(--warn); }
.meter span.low { background: var(--danger); }
.sim-verdict { display: flex; gap: 8px; align-items: center; font-weight: 600; margin-top: 10px; }
.answers { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.answer { display: flex; flex-direction: column; min-width: 0; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.answer header { padding: 12px var(--s3); border-bottom: 1px solid var(--border); background: var(--surface-2); }
.answer h4 { font-size: 13.5px; }
.answer-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.answer-text { padding: var(--s3); font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 560px; overflow: auto; }

.badge { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); align-self: center; white-space: nowrap; }
.badge.ready { background: var(--good-soft); color: var(--good); }
.badge.loading { background: var(--warn-soft); color: var(--warn); }
.badge.error { background: var(--danger-soft); color: var(--danger); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s2); margin-bottom: 12px; flex-wrap: wrap; }

/* ---------- Compare rates ---------- */
.sweep-card { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: var(--s4); padding: var(--s4); align-items: start; margin-bottom: var(--s3); }
.sweep-figure { margin: 0; min-width: 0; }
.chart-caption { font-size: 12.5px; color: var(--muted); margin-bottom: var(--s2); }
.chart-box { position: relative; height: 320px; }
.table-wrap { overflow-x: auto; position: relative; min-width: 0; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.data-table th { text-align: right; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { text-align: right; padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
#sweep-table tbody tr { cursor: pointer; }
#sweep-table tbody tr:hover td { background: var(--surface-2); }
.data-table tr.current td { background: var(--accent-soft) !important; }
.data-table tr.current td:first-child { font-weight: 650; color: var(--accent); }
.data-table tfoot td { font-weight: 650; border-bottom: 0; border-top: 2px solid var(--border); }
.preview-card { padding: var(--s3) var(--s4); }
.preview { font-size: 12.5px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; background: var(--surface-2); border-radius: var(--radius-sm); padding: var(--s3); margin: 0; max-height: 280px; overflow: auto; }

/* ---------- Batch ---------- */
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: var(--s5) var(--s4); border: 2px dashed var(--border-strong); background: var(--surface); cursor: pointer; margin-bottom: var(--s3); box-shadow: none; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone:focus-within { box-shadow: var(--focus); }
.table-card { padding: 4px var(--s3); overflow: hidden; position: relative; }
.batch-progress { position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--surface-3); }
.batch-progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }
.batch-table td:first-child { max-width: 320px; overflow: hidden; text-overflow: ellipsis; font-weight: 550; }
.status-tag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); }
.status-tag.done { background: var(--good-soft); color: var(--good); }
.status-tag.working { background: var(--accent-soft); color: var(--accent); }
.status-tag.error { background: var(--danger-soft); color: var(--danger); }
.row-actions { display: inline-flex; gap: 2px; }

/* ---------- History ---------- */
.search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border-strong); background: var(--surface); border-radius: var(--radius-sm); padding: 0 12px; margin-bottom: var(--s3); max-width: 480px; color: var(--muted); }
.search:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
.search input { border: 0; box-shadow: none !important; padding-left: 0; }
.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); grid-template-columns: minmax(0, 1fr); }
.history-item { display: flex; gap: 6px; }
.history-open { flex: 1; min-width: 0; text-align: left; font: inherit; color: var(--text); cursor: pointer; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px var(--s3); display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 2px var(--s3); align-items: center; }
.history-open:hover { border-color: var(--accent-line); }
.history-red { grid-row: span 2; font-size: 22px; font-weight: 750; color: var(--good); font-variant-numeric: tabular-nums; }
.history-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--text-2); }
.history-meta strong { color: var(--text); }
.history-snippet { font-family: var(--mono); font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-del { flex: none; width: 40px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: var(--radius); cursor: pointer; display: grid; place-items: center; }
.history-del:hover { color: var(--danger); border-color: var(--danger); }

/* ---------- Settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); align-items: start; }
.set-card { padding: 18px 20px; }
.set-card > h2 { margin-bottom: 6px; }
.set-wide { grid-column: 1 / -1; }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); padding: 12px 0; border-top: 1px solid var(--border); cursor: default; }
.set-card > h2 + .set-row, .set-card > .card-head + * { border-top: 0; }
label.set-row { cursor: pointer; }
.set-row-stack { flex-direction: column; align-items: stretch; gap: 8px; }
.set-name { font-weight: 600; font-size: 13.5px; display: block; }
.set-desc { font-size: 12.5px; color: var(--muted); }
.env-table { border-collapse: collapse; width: 100%; font-size: 13px; margin-top: 10px; }
.env-table th, .env-table td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); }
.env-table th { font-family: var(--mono); font-weight: 500; font-size: 12.5px; color: var(--text-2); white-space: nowrap; width: 1%; }
.env-table td { font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }
.env-table tr:last-child th, .env-table tr:last-child td { border-bottom: 0; }
.sys-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s2); margin: 0 0 var(--s3); }
.sys-item { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; min-width: 0; }
.sys-item dt { font-size: 12px; color: var(--muted); }
.sys-item dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.model-row { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px var(--s3); align-items: center; }
.model-row + .model-row { margin-top: var(--s2); }
.model-row .path { grid-column: 1 / -1; font-family: var(--mono); font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.model-row .model-title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sys-sub { font-size: 14px; margin: 4px 0 6px; }

/* ---------- Guide ---------- */
.guide-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: var(--s3); align-items: start; }
.toc { position: sticky; top: 24px; padding: 8px; display: grid; }
.toc a { padding: 6px 10px; border-radius: 6px; color: var(--text-2); font-size: 13.5px; }
.toc a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.guide { display: grid; gap: var(--s3); min-width: 0; grid-template-columns: minmax(0, 1fr); }
.guide-sec { padding: var(--s4); }
.guide-sec > h2, .guide-sec .card-head h2 { font-size: 17px; }
.guide-sec > h2 { margin-bottom: 10px; }
.guide-sec p + p, .guide-sec p + pre, .guide-sec pre + p { margin-top: 10px; }
.guide-sec ul { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.example { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); margin: var(--s3) 0; }
.example > div { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; font-family: var(--mono); font-size: 12.5px; }
.example > div:last-child { border-color: color-mix(in srgb, var(--good) 35%, var(--border)); background: var(--good-soft); }
.example .eyebrow { font-family: var(--font); margin-bottom: 4px; }
.pros-cons { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
.pros-cons h3 { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.defs { margin: 0; display: grid; grid-template-columns: 160px 1fr; gap: 10px var(--s3); }
.defs dt { font-weight: 650; }
.defs dd { margin: 0; color: var(--text-2); }
pre.code { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 12.5px; line-height: 1.6; overflow-x: auto; margin: 0; white-space: pre; }
.code-tabs { display: flex; justify-content: space-between; align-items: center; margin: 10px 0 8px; gap: var(--s2); }
.keys-table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.keys-table td { padding: 7px 4px; border-bottom: 1px solid var(--border); }
.keys-table td:first-child { white-space: nowrap; width: 1%; padding-right: var(--s4); }
.keys-table tr:last-child td { border-bottom: 0; }

/* ---------- Toasts & dialog ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: grid; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { display: grid; grid-template-columns: 18px 1fr auto; gap: 10px; align-items: start; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 12px 10px 12px 12px; font-size: 13.5px; animation: toast-in .2s ease; }
.toast.tone-error { border-left-color: var(--danger); }
.toast.tone-error .ic { color: var(--danger); }
.toast.tone-good { border-left-color: var(--good-bar); }
.toast.tone-good .ic { color: var(--good); }
.toast .ic { color: var(--accent); margin-top: 1px; }
.toast button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 2px; border-radius: 4px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); padding: var(--s4); width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 12, 16, .45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--s2); }

/* ---------- How it works: pipeline diagram ---------- */
.arch-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); flex-wrap: wrap; margin: var(--s3) 0 var(--s2); }
.arch {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); grid-template-rows: auto 64px auto auto;
  column-gap: 30px; padding: 34px 16px 4px; margin: 0 -2px; position: relative;
}
.arch-steps { display: contents; list-style: none; }
.arch-lane { position: relative; border-radius: var(--radius); border: 1px dashed var(--border-strong); background: var(--surface-2); margin: -34px -16px -14px; z-index: 0; }
.arch-lane span { position: absolute; top: 9px; left: 14px; font-size: 11.5px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.arch-lane-browser { grid-row: 1; grid-column: 1 / -1; }
.arch-lane-server { grid-row: 3; grid-column: 1 / -1; background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface-2)); border-color: var(--accent-line); }
.arch-lane-server span { color: var(--accent); left: 50%; transform: translateX(-50%); white-space: nowrap; }
.arch-note { grid-row: 1; grid-column: 2 / 5; align-self: center; justify-self: center; z-index: 1; display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; }
.arch-step {
  position: relative; z-index: 1; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 4px; min-width: 0; cursor: pointer;
  transition: border-color .25s, box-shadow .25s, opacity .25s, transform .25s;
}
.arch-step:hover { border-color: var(--accent-line); }
.arch-step h3 { font-size: 13.5px; }
.arch-step > p { font-size: 12px; color: var(--muted); }
.arch-title { display: flex; align-items: center; gap: 8px; }
.stage-n { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.arch-where { display: none; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.s1 { grid-row: 1; grid-column: 1; } .s7 { grid-row: 1; grid-column: 5; }
.s2 { grid-row: 3; grid-column: 1; } .s3 { grid-row: 3; grid-column: 2; } .s4 { grid-row: 3; grid-column: 3; }
.s5 { grid-row: 3; grid-column: 4; } .s6 { grid-row: 3; grid-column: 5; }
.s3::before, .s4::before, .s5::before, .s6::before { content: ""; position: absolute; left: -26px; top: 50%; width: 22px; height: 2px; background: var(--accent); }
.s3::after, .s4::after, .s5::after, .s6::after { content: ""; position: absolute; left: -10px; top: calc(50% - 4px); border: 5px solid transparent; border-left: 6px solid var(--accent); border-right: 0; }
.arch-link { grid-row: 2; position: relative; display: grid; place-items: center; z-index: 1; }
.arch-link::before { content: ""; position: absolute; top: 4px; bottom: 4px; left: 50%; width: 2px; background: var(--accent); }
.arch-link::after { content: ""; position: absolute; left: calc(50% - 5px); border: 6px solid transparent; }
.arch-link-down { grid-column: 1; }
.arch-link-down::after { bottom: -6px; border-top: 7px solid var(--accent); border-bottom: 0; }
.arch-link-up { grid-column: 5; }
.arch-link-up::after { top: -6px; border-bottom: 7px solid var(--accent); border-top: 0; }
.arch-link span { position: relative; background: var(--surface); padding: 1px 8px; border-radius: 999px; border: 1px solid var(--accent-line); font-size: 11.5px; font-weight: 600; color: var(--accent); }
.arch-ext { grid-row: 4; margin-top: 30px; position: relative; display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; color: var(--text-2); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface); }
.arch-ext .ic { margin-top: 1px; color: var(--muted); }
.arch-ext::before { content: ""; position: absolute; top: -30px; height: 28px; left: 50%; border-left: 2px dashed var(--border-strong); }
.arch-ext-hf { grid-column: 2 / 4; }
.arch-ext-hf::before { left: calc(25% - 7px); }
.arch-ext-ollama { grid-column: 4 / 6; }
.arch-ext-ollama::before { left: calc(75% + 7px); }
.viz { margin-top: 6px; border-radius: 6px; background: var(--surface-2); padding: 8px; font-family: var(--mono); font-size: 11.5px; line-height: 1.6; overflow-wrap: anywhere; }
.viz del { color: var(--removed); background: var(--removed-bg); border-radius: 3px; text-decoration: line-through; }
.viz mark.protected { padding: 0 2px; }
.viz-result { background: var(--good-soft); }
.viz-stats { font-family: var(--font); font-size: 13px; }
.viz-bars { display: flex; align-items: flex-end; gap: 3px; height: 92px; padding: 8px 6px 22px; position: relative; font-family: var(--font); }
.viz-bars .bar-col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.viz-bars .b { width: 100%; max-width: 12px; border-radius: 2px 2px 0 0; background: var(--border-strong); }
.viz-bars .b.keep { background: var(--good-bar); }
.viz-bars .b.lock { background: repeating-linear-gradient(135deg, var(--protected-line) 0 3px, var(--protected-bg) 3px 6px); }
.viz-bars .w { position: absolute; bottom: -16px; font-size: 9px; color: var(--muted); white-space: nowrap; transform: rotate(-35deg); transform-origin: top center; }
.viz-bars .cut { position: absolute; left: 4px; right: 4px; border-top: 1px dashed var(--danger); }
.viz-bars .cut span { position: absolute; top: -15px; left: 0; font-size: 9px; color: var(--danger); background: var(--surface-2); padding: 0 3px; border-radius: 3px; line-height: 1.3; }
.arch.playing .arch-step { opacity: .45; }
.arch .arch-step.active { opacity: 1; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent), var(--shadow); transform: translateY(-2px); }
.arch.playing .arch-step.done { opacity: .85; }
.arch-caption { margin: var(--s3) 0; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--text); font-size: 13.5px; min-height: 42px; }
@media (prefers-reduced-motion: reduce) { .arch-step { transition: none; } .arch .arch-step.active { transform: none; } }

/* Live demo */
.demo-text { height: auto; min-height: 84px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); margin-top: var(--s2); font-size: 13px; resize: vertical; }
.demo-controls { display: flex; align-items: center; gap: var(--s3); margin: var(--s2) 0; flex-wrap: wrap; }
.demo-controls .label { margin: 0; white-space: nowrap; }
.demo-controls input[type="range"] { flex: 1; min-width: 160px; max-width: 360px; }
.demo-check { padding: 0; }
.demo-out { height: auto; min-height: 84px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); resize: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
  .toolbar { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; row-gap: 12px; }
  .tb-strength { grid-column: 1 / -1; padding-right: 0; }
  .tb-group:nth-child(2) { border-left: 0; padding-left: 0; }
  .kpi { padding: 0 14px; }
  .overview { grid-template-columns: minmax(0, 1fr); }
  .mini-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  :root { --nav-w: 68px; }
  .nav { padding: 18px 10px 14px; align-items: center; }
  .brand { padding: 0; }
  .brand-text, .nav-item span:not(.nav-badge), .status-lines, .privacy-tag { display: none; }
  .nav-list { width: 100%; }
  .nav-item { justify-content: center; padding: 10px; }
  .nav-badge { position: absolute; top: 2px; right: 2px; min-width: 16px; line-height: 16px; padding: 0 4px; font-size: 10px; }
  .status-card { justify-content: center; padding: 12px; }
  .nav-foot-row { flex-direction: column; }
  .main { padding: 24px 24px 40px; }
  .cost-layout { grid-template-columns: minmax(0, 1fr); }
  .guide-layout { grid-template-columns: minmax(0, 1fr); }
  .toc { position: static; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}
@media (max-width: 900px) {
  .editors, .sweep-card, .answers, .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .quality-controls { grid-template-columns: minmax(0, 1fr); }
  .quality-run { margin-top: 0; justify-self: start; }
  textarea, .diff { height: 360px; }
  .mini-stats { grid-template-columns: 1fr 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; padding: 10px 0; row-gap: 10px; }
  .kpi { padding: 0 14px; }
  .kpi-main { grid-column: 1 / -1; }
  .kpi:nth-child(2), .kpi:nth-child(4) { border-left: 0; }
}

/* Phones and narrow windows: the side navigation becomes a top bar. */
@media (max-width: 760px) {
  .app { display: block; background: none; }
  .nav { position: sticky; top: 0; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 8px 12px 6px; border-right: 0; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--nav-bg) 92%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
  .brand-text { display: flex; }
  .brand-text small { display: none; }
  .nav-list { order: 3; flex-basis: 100%; flex-direction: row; overflow-x: auto; scrollbar-width: none; gap: 2px; }
  .nav-list::-webkit-scrollbar { display: none; }
  .nav-item { padding: 7px 10px; font-size: 13px; gap: 6px; }
  .nav-item[aria-current="page"] span:not(.nav-badge) { display: inline; }
  .nav-sep { display: none; }
  .nav-foot { margin: 0 0 0 auto; display: flex; gap: 2px; align-items: center; }
  .nav-foot-row { flex-direction: row; }
  .status-card { width: 34px; height: 34px; padding: 0; border-color: transparent; background: transparent; }
  .main { padding: 18px 16px 40px; }
  h1 { font-size: 21px; }
  .toolbar { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); padding: 10px 14px 12px; }
  .tb-group, .tb-group:first-child { padding: 0; border-left: 0 !important; }
  .tb-group:nth-child(3) { padding-left: 10px; }
  .tb-action { grid-column: 1 / -1; padding: 10px 0 0; border-left: 0; border-top: 1px solid var(--border); justify-content: space-between; }
  .tb-action .btn { flex: 1; }
  #level-hint { display: none; }
  .panel-head { flex-wrap: wrap; }
  .tool-text { display: none; }
  .dpanel { padding: 14px; }
  .similarity { grid-template-columns: 1fr; gap: var(--s2); }
  .col-time { display: none; }
  .data-table th, .data-table td { padding: 8px 5px; }
  .history-open { grid-template-columns: 1fr; }
  .history-red { grid-row: auto; font-size: 18px; }
  .guide-sec, .set-card { padding: var(--s3); }
  .example, .pros-cons { grid-template-columns: minmax(0, 1fr); }
  .defs { grid-template-columns: 1fr; gap: 2px; }
  .defs dd { margin-bottom: 8px; }
  .set-row { flex-wrap: wrap; }
  .cost-table th, .cost-table td { padding: 6px 4px; font-size: 12.5px; }
  .cost-table thead th { font-size: 11px; }
  .start { padding: var(--s3); place-items: start center; }
  .kbd { display: none; }
}
@media (max-width: 420px) {
  .mini-stats { grid-template-columns: 1fr 1fr; }
  .range-end { display: none; }
  .tb-strength .tb-label { display: none; }
}

/* Diagram on narrow screens: one vertical flow */
@media (max-width: 900px) {
  .arch { display: block; padding: 0; margin: 0; }
  .arch-lane, .arch-link, .arch-note { display: none; }
  .arch-steps { display: flex; flex-direction: column; gap: 26px; padding: 0; margin: 0; }
  .arch-where { display: block; }
  .arch-step::before, .arch-step::after { display: none; }
  .arch-step + .arch-step::before { display: block; content: ""; position: absolute; left: 22px; top: -24px; width: 2px; height: 20px; background: var(--accent); }
  .arch-step + .arch-step::after { display: block; content: ""; position: absolute; left: 18px; top: -8px; border: 5px solid transparent; border-top: 6px solid var(--accent); border-bottom: 0; }
  .arch-ext { margin-top: var(--s2); }
  .arch-ext::before { display: none; }
  .viz-bars { height: 110px; }
}
