:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #dedcd6;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #75736d;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e3eefb;
  --series-1: #2a78d6;
  --good: #0ca30c;
  --good-ink: #066e06;
  --warn: #fab219;
  --warn-ink: #8a5a00;
  --serious: #ec835a;
  --bad: #d03b3b;
  --bad-ink: #b02a2a;
  --info: #75736d;
  --code-bg: #f0efec;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #383835;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #9b9a92;
    --accent: #3987e5;
    --accent-soft: #1d2e44;
    --series-1: #3987e5;
    --good-ink: #4cc44c;
    --warn-ink: #fab219;
    --bad-ink: #ef7272;
    --info: #9b9a92;
    --code-bg: #232321;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #383835;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #9b9a92; --accent: #3987e5; --accent-soft: #1d2e44;
  --series-1: #3987e5; --good-ink: #4cc44c; --warn-ink: #fab219; --bad-ink: #ef7272; --info: #9b9a92;
  --code-bg: #232321; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
code, pre, .mono { font-family: var(--mono); font-size: 13px; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 28px; font-weight: 650; }
h2 { font-size: 20px; font-weight: 600; }
h3 { font-size: 16px; font-weight: 600; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* Layout */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .inner { display: flex; align-items: center; gap: 16px; height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; color: var(--text); text-decoration: none; }
.brand svg { width: 26px; height: 26px; }
.topbar nav { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a { color: var(--text-2); text-decoration: none; padding: 6px 10px; border-radius: 6px; font-size: 14px; }
.topbar nav a:hover, .topbar nav a.active { background: var(--surface-2); color: var(--text); }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.wide { max-width: 1320px; }
main { padding: 28px 0 64px; }
footer { color: var(--text-3); font-size: 13px; text-align: center; padding: 24px 16px 40px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-size: 14px; cursor: pointer; text-decoration: none;
  min-height: 38px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.big { padding: 12px 22px; font-size: 16px; min-height: 48px; }
.btn.danger { color: var(--bad-ink); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.icon { padding: 8px 10px; }
input[type=text], input[type=search], input[type=date], input[type=number], input[type=password], select {
  font: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); min-height: 38px; width: 100%;
}
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); font-weight: 500; }
.check-label { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }

/* Landing */
.hero { text-align: center; padding: 28px 0 8px; }
.hero h1 { font-size: 34px; }
.hero p.lead { font-size: 17px; color: var(--text-2); max-width: 620px; margin: 0 auto 26px; }
.address-box {
  display: flex; max-width: 620px; margin: 0 auto; border: 2px solid var(--accent); border-radius: 12px;
  background: var(--surface); overflow: hidden;
}
.address-box .addr {
  flex: 1; padding: 14px 16px; font-family: var(--mono); font-size: 17px; text-align: center;
  overflow-wrap: anywhere; user-select: all; min-width: 0;
}
.address-box button { border: 0; border-left: 1px solid var(--border); background: var(--surface-2); color: var(--text); padding: 0 18px; cursor: pointer; font: inherit; font-size: 14px; }
.address-box button:hover { background: var(--accent-soft); }
.hero .actions { margin-top: 18px; display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; align-items: center; }
.steps { counter-reset: step; list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.steps li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 16px 16px 52px; position: relative; }
.steps li::before {
  counter-increment: step; content: counter(step); position: absolute; left: 16px; top: 16px;
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px;
}
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.features div { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.features b { display: block; margin-bottom: 4px; }
.features span { color: var(--text-2); font-size: 14px; }
.notice { font-size: 13px; color: var(--text-3); text-align: center; margin-top: 18px; }

/* Waiting */
.waiting { text-align: center; padding: 40px 20px; }
.spinner { width: 42px; height: 42px; border: 4px solid var(--surface-2); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 18px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* Score header */
.score-head { display: flex; gap: 28px; align-items: center; flex-wrap: wrap; }
.dial { width: 150px; height: 150px; flex: none; }
.dial .track { stroke: var(--surface-2); }
.dial .num { font-size: 34px; font-weight: 700; fill: var(--text); }
.dial .den { font-size: 13px; fill: var(--text-3); }
.dial.excellent .arc { stroke: var(--good); }
.dial.good .arc { stroke: var(--good); }
.dial.fair .arc { stroke: var(--warn); }
.dial.poor .arc { stroke: var(--serious); }
.dial.bad .arc { stroke: var(--bad); }
.score-meta { flex: 1; min-width: 260px; }
.score-meta h1 { font-size: 24px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
.toolbar.share { display: flex; flex-wrap: nowrap; gap: 0; max-width: 560px; }
.share input { flex: 1; width: auto; border-radius: 8px 0 0 8px; font-family: var(--mono); font-size: 13px; min-width: 0; }
.share button { border-radius: 0 8px 8px 0; border-left: 0; }

/* Identity card */
.identity { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.idbox { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; background: var(--surface); }
.idbox .lbl { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.idbox .val { font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; margin-top: 2px; }
.chain { font-family: var(--mono); font-size: 13px; background: var(--code-bg); border-radius: 8px; padding: 10px 12px; margin-top: 10px; overflow-x: auto; white-space: pre; }

/* Status badges */
.st { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; border: 1px solid transparent; }
.st::before { font-size: 12px; line-height: 1; }
.st.pass { color: var(--good-ink); border-color: var(--good); }
.st.pass::before { content: "✓"; }
.st.warn { color: var(--warn-ink); border-color: var(--warn); }
.st.warn::before { content: "!"; }
.st.fail { color: var(--bad-ink); border-color: var(--bad); }
.st.fail::before { content: "✕"; }
.st.info { color: var(--text-2); border-color: var(--border); }
.st.info::before { content: "i"; font-style: italic; font-family: Georgia, serif; }
.st.error { color: var(--text-2); border-color: var(--text-3); border-style: dashed; }
.st.error::before { content: "?"; }
.pen { font-weight: 700; font-size: 13px; color: var(--bad-ink); white-space: nowrap; font-variant-numeric: tabular-nums; }
.pen.zero { color: var(--text-3); font-weight: 500; }

/* Groups & checks */
details.group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; box-shadow: var(--shadow); }
details.group > summary {
  list-style: none; cursor: pointer; padding: 14px 18px; display: flex; align-items: center; gap: 12px; font-size: 17px; font-weight: 600;
}
details.group > summary::-webkit-details-marker, details.check > summary::-webkit-details-marker { display: none; }
details.group > summary .title { flex: 1; }
details.group > summary::after, details.check > summary::after { content: "▸"; color: var(--text-3); transition: transform .15s; }
details[open].group > summary::after, details[open].check > summary::after { transform: rotate(90deg); }
.group-body { padding: 0 18px 14px; }
details.check { border-top: 1px solid var(--border); }
details.check > summary { list-style: none; cursor: pointer; padding: 11px 2px; display: flex; gap: 10px; align-items: flex-start; }
details.check > summary .title { flex: 1; overflow-wrap: anywhere; }
.check-body { padding: 0 2px 14px 2px; }
.check-body p { margin: 0 0 10px; color: var(--text-2); }
.check-body pre, pre.block {
  background: var(--code-bg); border-radius: 8px; padding: 10px 12px; overflow-x: auto; margin: 0 0 10px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.fix { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: 8px 12px; border-radius: 0 8px 8px 0; margin: 0 0 10px; font-size: 14px; }
.fix b { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); margin-bottom: 2px; }
.refs { font-size: 12px; color: var(--text-3); }
.topfix { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.topfix:first-of-type { border-top: 0; }
.topfix .pen { min-width: 44px; }
.bl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 16px; padding: 8px 0 12px; font-size: 14px; }
.bl-grid .ok { color: var(--good-ink); font-weight: 600; }
.bl-grid .err { color: var(--text-3); font-weight: 600; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 9px 14px; font: inherit; font-size: 14px; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
iframe.preview { width: 100%; height: 560px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
pre.source { max-height: 560px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: var(--surface-2); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
.score-pill { display: inline-block; min-width: 40px; text-align: center; font-weight: 700; border-radius: 6px; padding: 1px 6px; font-variant-numeric: tabular-nums; border: 1px solid; }
.score-pill.excellent, .score-pill.good { color: var(--good-ink); border-color: var(--good); }
.score-pill.fair { color: var(--warn-ink); border-color: var(--warn); }
.score-pill.poor, .score-pill.bad { color: var(--bad-ink); border-color: var(--bad); }
.score-pill.none { color: var(--text-3); border-color: var(--border); }

/* Admin */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.stat .k { font-size: 12px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 13px; color: var(--text-3); }
.bars { width: 100%; height: 180px; display: block; }
.bars .bar { fill: var(--series-1); }
.bars .bar:hover, .bars .bar.hl { opacity: .8; }
.bars .axis { fill: var(--text-3); font-size: 11px; }
.bars .grid-line { stroke: var(--border); stroke-width: 1; }
.chart-wrap { position: relative; }
.tooltip { position: absolute; pointer-events: none; background: var(--text); color: var(--surface); font-size: 12px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -110%); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }
.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 12px; background: var(--surface-2); border-radius: 6px; padding: 2px 8px; color: var(--text-2); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 10; }

@media (max-width: 640px) {
  .hero h1 { font-size: 26px; }
  .address-box { flex-direction: column; }
  .address-box button { border-left: 0; border-top: 1px solid var(--border); padding: 12px; }
  .score-head { gap: 16px; }
  .dial { width: 120px; height: 120px; }
  .card { padding: 16px; }
  details.group > summary { padding: 12px 14px; font-size: 16px; }
  .group-body { padding: 0 14px 12px; }
  .topbar nav a { padding: 6px 7px; }
}
@media print {
  .topbar, .toolbar, .tabs, footer, iframe.preview { display: none !important; }
  details.group, details.check { break-inside: avoid; }
  body { background: #fff; }
}
