:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --surface-2: #f0e9da;
  --ink: #1f1b16;
  --muted: #6b6256;
  --line: #e0d6c2;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --ok: #2d6a4f;
  --ok-bg: #e3f0e8;
  --warn: #8a5a00;
  --warn-bg: #fbefd2;
  --bad: #9b2c2c;
  --bad-bg: #f8e1df;
  --idle: #5b5750;
  --idle-bg: #ebe7df;
  --focus: #1d4ed8;
  --ok-solid: #2d6a4f; --warn-solid: #b7791f; --bad-solid: #9b2c2c;
  --radius: 10px;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1814; --surface: #25211b; --surface-2: #2e2922; --ink: #f1ebdf; --muted: #b3a995;
    --line: #3b352b; --accent: #7fc4ad; --accent-ink: #11201b;
    --ok: #8fd3aa; --ok-bg: #1f3a2c; --warn: #f0c36a; --warn-bg: #3d2f12;
    --bad: #f1a5a0; --bad-bg: #432321; --idle: #cbc4b6; --idle-bg: #36312a; --focus: #7aa2ff;
    --ok-solid: #4f9d77; --warn-solid: #d99a2b; --bad-solid: #d9615b;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.55 var(--sans); min-height: 100vh; display: flex; flex-direction: column;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
a { color: var(--accent); }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 600; }
.brand-mark {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-family: var(--mono); font-weight: 500;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.lang { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.lang-btn { background: transparent; border: 0; padding: 6px 12px; cursor: pointer; }
.lang-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 32px 16px 48px; }
main:has(.wide:not([hidden])) { max-width: 980px; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); line-height: 1.2; margin: 0 0 12px; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; margin: 32px 0 12px; }
h3 { font-size: 1.05rem; margin: 0 0 6px; }
.lead { color: var(--muted); font-size: 1.05rem; margin: 0 0 24px; }
.note { color: var(--muted); font-size: 0.9rem; margin: 12px 0 0; }
.foot { max-width: 980px; margin: 0 auto; padding: 0 16px 32px; color: var(--muted); font-size: 0.85rem; }

.url-form { display: flex; gap: 10px; flex-wrap: wrap; }
.url-form input {
  flex: 1 1 260px; min-width: 0; padding: 14px 16px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface); font-size: 1.05rem;
}
button { cursor: pointer; border-radius: var(--radius); }
.primary { background: var(--accent); color: var(--accent-ink); border: 0; padding: 14px 22px; font-weight: 600; }
.primary:hover { filter: brightness(1.08); }
.ghost { background: transparent; border: 1px solid var(--line); padding: 7px 12px; }
.ghost:hover { background: var(--surface-2); }
.ghost[aria-pressed="true"] { background: var(--surface-2); border-color: var(--accent); }
.form-error { color: var(--bad); background: var(--bad-bg); padding: 10px 14px; border-radius: var(--radius); }

.bar { height: 12px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 20px 0 10px; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.4s ease; }
.stage { font-weight: 500; margin: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 12px 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 0.88em; overflow-wrap: anywhere; }
.chip {
  display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 0.8rem; font-weight: 500;
  background: var(--idle-bg); color: var(--idle); white-space: nowrap;
}
.chip.auto_accepted { background: var(--ok-bg); color: var(--ok); }
.chip.needs_confirmation { background: var(--warn-bg); color: var(--warn); }
.chip.blocked { background: var(--bad-bg); color: var(--bad); }
.chip.insufficient_evidence { background: var(--idle-bg); color: var(--idle); }
.chip.type { background: var(--surface-2); color: var(--ink); font-family: var(--mono); font-weight: 400; }

.summary { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .big { font-size: 2rem; font-weight: 600; line-height: 1.1; }
.statline { margin: 6px 0; }

.items { list-style: none; margin: 0; padding: 0; }
.items li { display: flex; gap: 10px; align-items: baseline; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.items li:first-child { border-top: 0; }
.items button.link { background: none; border: 0; padding: 0; color: var(--accent); text-align: left; text-decoration: underline; }

table.fields { width: 100%; border-collapse: collapse; }
table.fields th, table.fields td { text-align: left; vertical-align: top; padding: 10px 8px; border-top: 1px solid var(--line); }
table.fields th { font-weight: 500; width: 28%; color: var(--muted); }
.field-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.field-actions button { padding: 4px 10px; font-size: 0.85rem; }
.field-edit { display: flex; gap: 6px; flex-wrap: wrap; }
.field-edit input { flex: 1 1 200px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.ev { margin-top: 6px; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; font-size: 0.88rem; }
.ev dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; }
.ev dt { color: var(--muted); }
.ev dd { margin: 0; overflow-wrap: anywhere; }
.ev code { font-family: var(--mono); }
.src { cursor: help; border-bottom: 1px dotted var(--muted); }

.tpl-title { display: flex; align-items: flex-start; gap: 10px; }
.tpl-title input[type="checkbox"] { width: 20px; height: 20px; margin-top: 3px; accent-color: var(--accent); }
.lists { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-top: 10px; }
.lists h4 { margin: 0 0 4px; font-size: 0.85rem; color: var(--muted); font-weight: 500; }
.lists ul { margin: 0; padding-left: 18px; font-size: 0.92rem; }
details { margin-top: 10px; }
summary { cursor: pointer; font-weight: 500; }
pre.json {
  margin: 8px 0 0; padding: 12px; background: var(--surface-2); border-radius: 8px; overflow: auto;
  max-height: 360px; font: 0.82rem/1.5 var(--mono); white-space: pre; tab-size: 2;
}
.notice { border-left: 4px solid var(--warn); background: var(--warn-bg); padding: 10px 14px; border-radius: 6px; margin: 10px 0; }
.mode-opts { display: grid; gap: 8px; }
.mode-opts label { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); cursor: pointer; }
.mode-opts input { margin-top: 5px; accent-color: var(--accent); }
.comp { display: grid; grid-template-columns: 120px 1fr 60px; gap: 8px; align-items: center; margin: 4px 0; font-size: 0.9rem; }
.comp .track { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.comp .fill { height: 100%; background: var(--accent); }
.dl { display: inline-block; text-decoration: none; }

/* report: header, banner, steps, findings, glossary */
.report-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.report-head .lead { margin-bottom: 6px; max-width: 62ch; }
.report-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; max-width: 260px; }
.banner {
  display: grid; grid-template-columns: auto 1fr auto; gap: 18px; align-items: start;
  border: 2px solid var(--line); border-left-width: 10px; border-radius: var(--radius);
  background: var(--surface); padding: 20px; margin: 16px 0;
}
.banner.light-good { border-color: var(--ok-solid); background: var(--ok-bg); }
.banner.light-attention { border-color: var(--warn-solid); background: var(--warn-bg); }
.banner.light-blocked { border-color: var(--bad-solid); background: var(--bad-bg); }
.light {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center;
  font: 600 1.7rem/1 var(--sans); color: #fff; background: var(--idle);
}
.light-good .light { background: var(--ok-solid); }
.light-attention .light { background: var(--warn-solid); color: #1f1b16; }
.light-blocked .light { background: var(--bad-solid); }
.banner-title { margin: 0 0 4px; font-size: 1.35rem; }
.banner-desc { margin: 0 0 10px; font-weight: 500; }
.banner-note { margin: 0 0 10px; font-weight: 600; }
.summary-text p { margin: 0 0 8px; max-width: 70ch; }
.banner-score { text-align: right; min-width: 120px; }
.banner-score .big { font-size: 2.2rem; font-weight: 600; line-height: 1.1; white-space: nowrap; }
.steps .card-head { align-items: center; }
.steps h2, .card h2 { margin-top: 0; }
.step-list { list-style: none; margin: 14px 0 0; padding: 0; }
.step { border-top: 1px solid var(--line); padding: 12px 0; }
.step:first-child { border-top: 0; }
.step-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.step-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.step-title { font-weight: 600; flex: 1 1 260px; cursor: pointer; }
.step-n { color: var(--muted); font-family: var(--mono); font-weight: 500; }
.step.done .step-title { text-decoration: line-through; color: var(--muted); }
.chip.who { background: var(--surface-2); color: var(--ink); }
.step-more { margin: 6px 0 0 32px; }
.step-text h4 { margin: 10px 0 2px; font-size: 0.85rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.step-text p { margin: 0 0 4px; max-width: 70ch; }
.explain { background: var(--surface-2); border-radius: 8px; padding: 10px 14px; margin: 10px 0; }
.explain p { margin: 4px 0; max-width: 72ch; }
.notice.ok { border-left-color: var(--ok-solid); background: var(--ok-bg); }
.notice p { margin: 6px 0 0; }
.tpl.st-blocked { border-left: 5px solid var(--bad-solid); }
.tpl.st-needs_confirmation { border-left: 5px solid var(--warn-solid); }
.tpl.st-auto_accepted { border-left: 5px solid var(--ok-solid); }
.tpl.st-insufficient_evidence { border-left: 5px solid var(--idle); }
.fields-more summary, .tech summary, .why-know summary { font-weight: 500; color: var(--accent); }
.why-know { margin-top: 6px; }
.why-know .ev { margin: 6px 0; }
.ev p { margin: 2px 0; }
blockquote.quote { margin: 6px 0; padding: 6px 12px; border-left: 3px solid var(--accent); background: var(--surface); font-style: italic; overflow-wrap: anywhere; }
td .val { font-weight: 500; overflow-wrap: anywhere; }
.question { margin: 6px 0; }
.finding-list { list-style: none; margin: 8px 0 0; padding: 0; }
.finding { padding: 8px 0 8px 12px; border-left: 4px solid var(--idle); margin-top: 10px; }
.finding.sev-critical, .finding.sev-error { border-left-color: var(--bad-solid); }
.finding.sev-warning { border-left-color: var(--warn-solid); }
.finding p { margin: 4px 0; max-width: 72ch; }
.finding-title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sev-group { margin-top: 12px; }
.pages { margin: 6px 0 0; padding-left: 18px; }
.ok-line { color: var(--ok); font-weight: 500; }
.comp-note { margin: 0 0 8px; color: var(--muted); font-size: 0.88rem; max-width: 70ch; }
.gl { border-bottom: 1px dotted var(--accent); cursor: help; position: relative; }
.gl:hover::after, .gl:focus::after {
  content: attr(data-tip); position: absolute; left: 0; top: 1.5em; z-index: 10; width: max-content; max-width: min(300px, 80vw);
  background: var(--ink); color: var(--bg); padding: 8px 10px; border-radius: 8px; font: 400 0.85rem/1.4 var(--sans); white-space: normal;
}
.glossary dt { font-weight: 600; margin-top: 8px; }
.glossary dd { margin: 0; color: var(--muted); }

@media print {
  @page { margin: 14mm; }
  body { background: #fff; color: #000; font-size: 11pt; display: block; }
  .topbar, .foot, .no-print, #again, .field-actions, #mode-toggle, button.ghost, .lang { display: none !important; }
  main, main:has(.wide:not([hidden])) { max-width: none; padding: 0; }
  .card, .banner, .finding, .step { break-inside: avoid; box-shadow: none; }
  .banner, .light, .chip, .tpl, .explain, .notice { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .card { border-color: #bbb; background: #fff; }
  a { color: inherit; text-decoration: none; }
  .gl { border-bottom: 0; }
  pre.json { max-height: none; white-space: pre-wrap; }
  .step-more { margin-left: 0; }
}

@media (max-width: 600px) {
  .banner { grid-template-columns: 1fr; }
  .banner-score { text-align: left; }
  .report-actions { max-width: none; }
  .step-more { margin-left: 0; }
  main { padding-top: 20px; }
  table.fields th { width: auto; display: block; border-top: 1px solid var(--line); padding-bottom: 0; }
  table.fields td { display: block; border-top: 0; padding-top: 2px; }
  .comp { grid-template-columns: 90px 1fr 50px; }
  .primary { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { .bar-fill { transition: none; } }
