:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f1f4f7; --border: #dfe4ea; --text: #0f172a; --muted: #526072;
  --accent: #0f766e; --accent-ink: #ffffff; --accent-soft: #ccfbf1; --warn: #b45309; --warn-soft: #fef3c7;
  --bad: #b91c1c; --bad-soft: #fee2e2; --good: #15803d; --good-soft: #dcfce7; --focus: #2563eb;
  --c-rules: #64748b; --c-api: #d97706; --c-small: #0f766e; --c-small2: #7c3aed; --c-small3: #2563eb;
  --radius: 12px; --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1016; --surface: #121a23; --surface-2: #17212c; --border: #263342; --text: #e6edf3; --muted: #9aa8b8;
    --accent: #2dd4bf; --accent-ink: #042f2e; --accent-soft: #134e4a; --warn: #fbbf24; --warn-soft: #422006;
    --bad: #f87171; --bad-soft: #450a0a; --good: #4ade80; --good-soft: #052e16; --focus: #60a5fa;
    --c-rules: #94a3b8; --c-api: #fbbf24; --c-small: #2dd4bf; --c-small2: #a78bfa; --c-small3: #60a5fa;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 var(--sans); padding-bottom: 76px; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }
h1 { font-size: 1.65rem; line-height: 1.2; margin: 0 0 8px; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; margin: 0 0 4px; }
h3 { font-size: 1rem; margin: 0 0 6px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
code, pre { font-family: var(--mono); font-size: .85rem; }
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow-x: auto; margin: 0; }

/* top bar + navigation: bottom tab bar on phones, inline on desktop */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 10px 16px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.05rem; }
.nav { position: fixed; bottom: 0; left: 0; right: 0; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); z-index: 30; }
.nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 52px; justify-content: center;
  color: var(--muted); text-decoration: none; font-size: .72rem; border-radius: 10px; touch-action: manipulation; }
.nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
@media (min-width: 860px) {
  body { padding-bottom: 0; }
  .nav { position: static; display: flex; gap: 4px; background: none; border: 0; padding: 0; margin-left: auto; }
  .nav a { flex-direction: row; min-height: 40px; padding: 0 12px; font-size: .9rem; gap: 6px; }
  .nav svg { width: 18px; height: 18px; }
}

main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 40px; outline: none; }
.page { display: grid; gap: 16px; animation: fade .2s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .page, .sk { animation: none !important; } * { transition: none !important; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.grid2 { display: grid; gap: 16px; }
@media (min-width: 960px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.hero p.lead { font-size: 1.05rem; color: var(--muted); max-width: 70ch; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; color: var(--accent); font-weight: 700; margin-bottom: 6px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; border-top: 4px solid var(--kc, var(--border)); }
.kpi .k-label { font-size: .8rem; color: var(--muted); display: block; min-height: 2.4em; }
.kpi .k-val { font: 700 1.5rem/1.2 var(--mono); font-variant-numeric: tabular-nums; }
.kpi .k-sub { font-size: .78rem; color: var(--muted); }
.kpi.pending .k-val { color: var(--muted); font-size: 1rem; font-family: var(--sans); font-weight: 600; }

.verdict { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.notice { display: flex; gap: 10px; align-items: flex-start; border-radius: 10px; padding: 12px 14px; background: var(--accent-soft); }
.notice.warn { background: var(--warn-soft); }
.notice.bad { background: var(--bad-soft); }
.notice button { margin-left: auto; }

/* controls */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; color: var(--muted); padding: 0 14px; min-height: 36px; border-radius: 8px; font: inherit; font-size: .9rem; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; touch-action: manipulation;
  transition: transform .12s ease-out, background .15s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .85rem; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
label.field { display: grid; gap: 6px; font-weight: 600; font-size: .9rem; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: .8rem; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%; }
textarea { min-height: 130px; resize: vertical; line-height: 1.5; }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--bad); }
.err-text { color: var(--bad); font-size: .85rem; font-weight: 500; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.row > * { flex: 1 1 160px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 999px; padding: 0 12px; min-height: 36px;
  font: inherit; font-size: .85rem; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; max-width: 100%; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
.chip:disabled { opacity: .55; cursor: not-allowed; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dc, var(--muted)); flex: none; }
.tag { display: inline-block; font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.tag.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.tag.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.tag.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; font-size: .78rem; color: var(--muted); white-space: nowrap; }
th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
th button:focus-visible { outline: 3px solid var(--focus); }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
tr.pending td { color: var(--muted); }
.best { font-weight: 700; color: var(--good); }
.heat td.cell { text-align: center; font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* charts */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid line { stroke: var(--border); }
.chart text { fill: var(--muted); font: 11px var(--sans); }
.chart .lbl { fill: var(--text); font-weight: 600; font-size: 12px; }
.chart .pt { cursor: pointer; }
.chart .pt:focus-visible circle { stroke: var(--focus); stroke-width: 3; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: .82rem; color: var(--muted); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* playground */
.results { display: grid; gap: 12px; }
@media (min-width: 720px) { .results { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); } }
.result { border-top: 4px solid var(--kc, var(--border)); }
.result .meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.fields { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; font-size: .9rem; align-items: baseline; }
.fields dt { color: var(--muted); font-size: .8rem; }
.fields dd { margin: 0; font-family: var(--mono); word-break: break-word; }
.fields .mark { font-size: .8rem; }
.ok-mark { color: var(--good); } .bad-mark { color: var(--bad); }
.example { border: 1px solid var(--border); border-radius: 10px; padding: 12px; display: grid; gap: 8px; background: var(--surface); }
.example .text { white-space: pre-wrap; word-break: break-word; }
.diff { display: grid; grid-template-columns: auto 1fr 1fr; gap: 2px 10px; font-size: .82rem; }
.diff .h { color: var(--muted); font-weight: 600; }
.diff .wrong { color: var(--bad); font-family: var(--mono); }
.diff .right { color: var(--good); font-family: var(--mono); }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; stroke: currentColor; fill: none; stroke-width: 1.5; margin-bottom: 8px; }

/* method */
.pipeline { display: grid; gap: 10px; counter-reset: step; }
@media (min-width: 860px) { .pipeline { grid-template-columns: repeat(5, 1fr); } }
.step { position: relative; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.step::before { counter-increment: step; content: counter(step); display: inline-grid; place-items: center; width: 24px; height: 24px;
  border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: .8rem; margin-bottom: 6px; }
.step p { font-size: .85rem; color: var(--muted); margin: 0; }
.copyable { position: relative; }
.copyable .btn { position: absolute; top: 6px; right: 6px; }

.skeleton-page { display: grid; gap: 14px; }
.sk { background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; border-radius: 8px; animation: sh 1.2s infinite; }
.sk-title { height: 34px; width: 70%; } .sk-line { height: 18px; width: 50%; } .sk-block { height: 220px; }
@keyframes sh { to { background-position: -200% 0; } }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); opacity: 0; background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: .9rem; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
details summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.notice button { white-space: nowrap; }
.samples { display: grid; gap: 8px; }
@media (min-width: 720px) { .samples { grid-template-columns: 1fr 1fr; } }
.sample { display: grid; gap: 4px; justify-items: start; text-align: left; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 10px; padding: 10px 12px; min-height: 44px; font: inherit; font-size: .9rem; cursor: pointer; touch-action: manipulation; }
.sample:hover { border-color: var(--accent); }
.sample-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.chip { text-align: left; }
.results-table { min-width: 760px; }
.results-table td:first-child { min-width: 200px; }
@media (max-width: 600px) { .chart text { font-size: 12px; } .chart .lbl { font-size: 13px; } }
main:focus, main:focus-visible { outline: none; }
