/* Shared design system for the whole site.
 *
 * One file instead of a <style> block per page: the disclaimer footer alone was
 * duplicated four times, which is how footers drift apart. No build step, so
 * this is linked directly.
 *
 * Colours come from the validated data-viz palette (validate_palette.js passes
 * both modes). Status colours always ship with a symbol or a word — hue never
 * carries the meaning on its own.
 */

:root {
  color-scheme: light;
  --bg:        #f4f3f0;
  --surface:   #fcfcfb;
  --surface-2: #f0efec;
  --line:      #e2e0da;
  --line-soft: #ebe9e4;
  --ink:       #0b0b0b;
  --ink-2:     #52514e;
  --ink-3:     #85837c;
  --accent:    #2a78d6;
  --accent-bg: #eaf2fd;
  --bar:       #cde2fb;
  --bar-fill:  #2a78d6;
  --good:      #0ca30c;
  --warning:   #fab219;
  --serious:   #ec835a;
  --critical:  #d03b3b;
  --shadow:    0 1px 2px rgba(16,15,14,.04), 0 8px 24px rgba(16,15,14,.06);
  --radius:    14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:        #0e0e0d;
    --surface:   #1a1a19;
    --surface-2: #232321;
    --line:      #343430;
    --line-soft: #2a2a27;
    --ink:       #ffffff;
    --ink-2:     #c3c2b7;
    --ink-3:     #8f8e85;
    --accent:    #3987e5;
    --accent-bg: #16283d;
    --bar:       #1c5cab;
    --bar-fill:  #3987e5;
    --shadow:    0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:#0e0e0d; --surface:#1a1a19; --surface-2:#232321; --line:#343430;
  --line-soft:#2a2a27; --ink:#fff; --ink-2:#c3c2b7; --ink-3:#8f8e85;
  --accent:#3987e5; --accent-bg:#16283d; --bar:#1c5cab; --bar-fill:#3987e5;
  --shadow:0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI",
        "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar .inner {
  max-width: 1180px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 14px;
}
.brand {
  font-weight: 700; font-size: 15px; letter-spacing: -.01em;
  color: var(--ink); text-decoration: none; white-space: nowrap;
}
.brand span { color: var(--accent); }
.tabs {
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  margin-left: auto; -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  color: var(--ink-2); text-decoration: none; font-size: 13.5px;
  padding: 6px 11px; border-radius: 999px; white-space: nowrap;
}
.tabs a:hover { background: var(--surface-2); color: var(--ink); }
.tabs a[aria-current="page"] { background: var(--accent); color: #fff; font-weight: 600; }
.icon-btn {
  flex: none; background: none; border: 1px solid var(--line);
  border-radius: 999px; width: 32px; height: 32px; cursor: pointer;
  color: var(--ink-2); font-size: 14px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ---------- page shell ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 22px 16px 72px; }
.wrap.narrow { max-width: 820px; }
.page-head { margin: 0 0 18px; }
.page-head h1 { font-size: clamp(22px, 4.4vw, 30px); margin: 0 0 6px; letter-spacing: -.02em; }
.page-head .lede { color: var(--ink-2); font-size: 14.5px; margin: 0; max-width: 62ch; }
.meta { color: var(--ink-3); font-size: 12.5px; margin: 8px 0 0; display: flex;
        flex-wrap: wrap; gap: 6px 12px; align-items: center; }

h2 { font-size: 18px; margin: 30px 0 10px; letter-spacing: -.01em; }
h3 { font-size: 15px; margin: 18px 0 6px; }
p  { margin: 10px 0; }
a  { color: var(--accent); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px; margin: 14px 0;
  box-shadow: var(--shadow);
}
.card.tight { padding: 12px 14px; }

/* ---------- callouts ---------- */
.note {
  border-radius: 10px; padding: 10px 13px; margin: 12px 0;
  font-size: 13.5px; line-height: 1.65; background: var(--surface-2);
  border-left: 3px solid var(--accent); color: var(--ink-2);
}
.note b, .note strong { color: var(--ink); }
.note.warn { border-left-color: var(--serious); }
.note.stop { border-left-color: var(--critical); }
.note.ok   { border-left-color: var(--good); }
.note .lbl { font-weight: 700; color: var(--ink); }

/* ---------- stats ---------- */
.stats { display: grid; gap: 10px; grid-template-columns: repeat(4, 1fr); margin: 0 0 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px;
}
.stat .n { font-size: clamp(18px, 3.4vw, 24px); font-weight: 660; letter-spacing: -.02em; }
.stat .l { font-size: 11.5px; color: var(--ink-3); margin-top: 1px; }
.stat .arrow { color: var(--ink-3); font-size: 11px; }

/* ---------- controls ---------- */
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 14px; }
.seg {
  display: inline-flex; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px; gap: 2px;
}
.seg button {
  border: none; background: none; color: var(--ink-2); cursor: pointer;
  font: inherit; font-size: 13px; padding: 5px 12px; border-radius: 999px;
  white-space: nowrap;
}
.seg button[aria-pressed="true"] {
  background: var(--surface); color: var(--ink); font-weight: 650;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
.chip-btn {
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  color: var(--ink-2); font: inherit; font-size: 13px; padding: 6px 12px; cursor: pointer;
}
.chip-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
select, input[type="search"] {
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px;
}
input[type="search"] { min-width: 140px; }
.grow { flex: 1 1 auto; }
.count { font-size: 12.5px; color: var(--ink-3); }

/* ---------- chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10.5px; padding: 2px 7px; border-radius: 6px;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
  border: 1px solid transparent;
}
.chip.warn { color: var(--serious); border-color: color-mix(in srgb, var(--serious) 45%, transparent); }
.chip.bad  { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 45%, transparent); }
.chip.info { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }

/* ---------- score bar ---------- */
.score { display: flex; align-items: center; gap: 8px; }
.score .v { font-weight: 650; min-width: 34px; text-align: right; }
.meter { flex: 1; min-width: 44px; height: 6px; border-radius: 3px; background: var(--bar); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--bar-fill); border-radius: 3px; }

/* ---------- table (desktop) ---------- */
.tablewrap {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow);
}
table.data { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
table.data th, table.data td {
  padding: 10px 12px; text-align: right; white-space: nowrap;
  border-bottom: 1px solid var(--line-soft);
}
table.data th {
  position: sticky; top: 0; z-index: 1; background: var(--surface);
  color: var(--ink-3); font-size: 11px; font-weight: 650; cursor: pointer;
  user-select: none; letter-spacing: .02em; border-bottom-color: var(--line);
}
table.data th:hover { color: var(--ink); }
table.data th[aria-sort] { color: var(--accent); }
table.data th.l, table.data td.l { text-align: left; }
table.data tbody tr:hover { background: var(--accent-bg); }
table.data tbody tr:last-child td { border-bottom: none; }
.rank { color: var(--ink-3); }
.tk { font-weight: 650; }
.nm { color: var(--ink-2); font-size: 12px; }
.sub2 { color: var(--ink-3); font-size: 11.5px; }

/* ---------- cards (mobile list) ---------- */
.cards { display: none; }
.co {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 14px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.co-top { display: flex; align-items: flex-start; gap: 10px; }
.co-rank {
  flex: none; width: 26px; height: 26px; border-radius: 8px; background: var(--surface-2);
  color: var(--ink-3); font-size: 12px; font-weight: 650;
  display: grid; place-items: center;
}
.co-id { flex: 1; min-width: 0; }
.co-id .t { font-weight: 700; font-size: 15px; }
.co-id .n { color: var(--ink-2); font-size: 12.5px; overflow: hidden;
            text-overflow: ellipsis; white-space: nowrap; }
.co-score { flex: none; text-align: right; }
.co-score .v { font-size: 19px; font-weight: 680; letter-spacing: -.02em; }
.co-score .l { font-size: 10px; color: var(--ink-3); }
.co-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 10px; margin-top: 11px;
}
.co-grid .k { font-size: 10.5px; color: var(--ink-3); }
.co-grid .v { font-size: 14px; font-weight: 620; }
.co-foot { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin-top: 11px; }
.co-ex { font-size: 11.5px; color: var(--ink-3); margin-top: 9px; }
.co-ex b { color: var(--ink-2); }

@media (max-width: 780px) {
  .tablewrap { display: none; }
  .cards { display: block; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .wrap { padding: 18px 12px 64px; }
  .controls { gap: 6px; }
  .topbar .inner { padding: 9px 12px; gap: 10px; }
  .brand { font-size: 14px; }
}

/* ---------- note button + drawer ---------- */
.noteBtn {
  background: none; border: 1px solid var(--line); border-radius: 7px;
  color: var(--ink-3); font: inherit; font-size: 11.5px; padding: 3px 9px; cursor: pointer;
}
.noteBtn:hover { border-color: var(--accent); color: var(--accent); }
.noteBtn.has { color: var(--good); border-color: color-mix(in srgb, var(--good) 50%, transparent); }

.scrim {
  position: fixed; inset: 0; background: rgba(10,10,9,.42); z-index: 40;
  display: none; backdrop-filter: blur(2px);
}
.scrim.open { display: block; }
.sheet {
  position: fixed; z-index: 41; background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  display: none; overflow: auto;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(620px, calc(100vw - 32px)); max-height: 82vh;
  border-radius: var(--radius); padding: 18px 20px;
}
.sheet.open { display: block; }
.sheet h3 { margin: 0 0 2px; font-size: 17px; }
.sheet .close {
  position: absolute; top: 12px; right: 14px; background: none; border: none;
  color: var(--ink-3); font-size: 22px; line-height: 1; cursor: pointer;
}
.sheet textarea {
  width: 100%; min-height: 130px; background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px;
  font: inherit; font-size: 14px; line-height: 1.6; resize: vertical;
}
.sheet label.ck {
  display: flex; gap: 9px; align-items: flex-start; margin: 12px 0;
  font-size: 13.5px; color: var(--ink-2); cursor: pointer;
}
.sheet label.ck input { margin-top: 3px; flex: none; }
.hint { font-size: 12px; color: var(--ink-3); margin: 8px 0 0; }
@media (max-width: 780px) {
  .sheet {
    left: 0; right: 0; top: auto; bottom: 0; transform: none;
    width: auto; max-height: 88vh; border-radius: 18px 18px 0 0;
    border-bottom: none; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  }
}

/* ---------- prose bits reused by the static pages ---------- */
table.plain { border-collapse: collapse; width: 100%; font-size: 13.5px; margin: 12px 0; }
table.plain th, table.plain td {
  padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}
table.plain th { color: var(--ink-3); font-size: 11px; font-weight: 650; }
table.plain td.n { text-align: right; white-space: nowrap; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: 12.5px; }
pre {
  background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 10px;
  padding: 12px 14px; overflow-x: auto; font-size: 12.5px; line-height: 1.65; margin: 12px 0;
}
figure { margin: 0; }
figcaption { font-size: 12px; color: var(--ink-3); margin-bottom: 10px; }
svg.fig { width: 100%; height: auto; display: block; overflow: visible; }

/* ---------- disclaimer ---------- */
footer.disc {
  margin-top: 40px; border-top: 1px solid var(--line);
  padding-top: 16px; font-size: 11.5px; line-height: 1.7; color: var(--ink-3);
}
footer.disc summary {
  cursor: pointer; font-size: 12px; color: var(--ink-2); font-weight: 650;
  letter-spacing: .02em; margin-bottom: 8px;
}
footer.disc p { margin: 0 0 8px; max-width: 78ch; }
footer.disc b { color: var(--ink-2); }

/* ---------- method page: numbered steps ---------- */
.step {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; margin: 14px 0; box-shadow: var(--shadow);
}
.step > h2 { font-size: 17px; margin: 0 0 2px; display: flex; gap: 11px; align-items: baseline; }
.step > h2 .n {
  flex: none; color: #fff; background: var(--accent); border-radius: 999px;
  font-size: 12px; font-weight: 700; padding: 2px 10px; line-height: 1.5;
}
.step .q { color: var(--ink-2); font-size: 13.5px; margin: 4px 0 12px; }
.step ul { margin: 10px 0; padding-left: 20px; }
.step li { margin: 5px 0; }
.toc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
       padding: 14px 18px; margin: 16px 0; box-shadow: var(--shadow); }
.toc ol { margin: 8px 0 0; padding-left: 22px; }
.toc li { margin: 4px 0; }
.toc a { color: var(--ink); text-decoration: none; }
.toc a:hover { color: var(--accent); text-decoration: underline; }

/* ---------- calculator ---------- */
.fields { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.fld label { display: block; font-size: 12px; color: var(--ink-3); margin-bottom: 6px; }
.fld .val { font-variant-numeric: tabular-nums; font-weight: 650; color: var(--ink); }
input[type=range] { width: 100%; accent-color: var(--accent); }
.tiles { display: grid; gap: 10px; grid-template-columns: repeat(4, 1fr); margin: 14px 0; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
        padding: 14px 16px; box-shadow: var(--shadow); }
.tile .n { font-size: clamp(20px, 4vw, 26px); font-weight: 680; letter-spacing: -.02em;
           font-variant-numeric: tabular-nums; }
.tile .l { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.tile.hero { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.tile.hero .n { color: var(--accent); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px;
            margin-right: 6px; vertical-align: -1px; }
.grid line { stroke: var(--line-soft); stroke-width: 1; }
.axis text { fill: var(--ink-3); font-size: 11px; }
@media (max-width: 780px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
