/* Palette follows the dataviz reference instance: blue accent, sequential blue ramp,
   neutral ink. Light and dark are both selected, not auto-flipped. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --hair: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #cde2fb;
  --ramp-250: #86b6ef;
  --ramp-450: #2a78d6;
  --ramp-600: #184f95;
  --tier-s: #7a3fc2;
  --tier-a: #23845b;
  --tier-b: #2a78d6;
  --tier-c: #b56a16;
  --tier-d: #77736b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05), 0 8px 24px -16px rgba(11, 11, 11, 0.25);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #262625;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --hair: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --accent-soft: #184f95;
  --ramp-250: #6da7ec;
  --ramp-450: #3987e5;
  --ramp-600: #86b6ef;
  --tier-s: #ba8cf0;
  --tier-a: #65c99b;
  --tier-b: #6da7ec;
  --tier-c: #e3a354;
  --tier-d: #aaa69d;
  --shadow: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262625;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --hair: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --accent-soft: #184f95;
    --ramp-250: #6da7ec;
    --ramp-450: #3987e5;
    --ramp-600: #86b6ef;
    --tier-s: #ba8cf0;
    --tier-a: #65c99b;
    --tier-b: #6da7ec;
    --tier-c: #e3a354;
    --tier-d: #aaa69d;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--page);
  padding-bottom: 96px;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }
button { font: inherit; color: inherit; }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--ink-2); }

/* Header */
.top { padding: 20px 0 8px; }
.top .wrap { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.top h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.tag { color: var(--ink-2); font-size: 14px; margin-top: 4px; }
.icon-btn {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); }

/* Sorter */
.sorter {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding-top: 8px; padding-bottom: 10px;
  border-bottom: 1px solid var(--hair);
}
.row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.row-label { flex: 0 0 64px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; flex: 1; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: 7px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-2);
  font-size: 13px; font-weight: 500; white-space: nowrap; min-height: 34px;
  display: inline-flex; align-items: center; gap: 5px;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-checked="true"], .chip[aria-pressed="true"] {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}
.chip .dir { font-size: 11px; opacity: 0.85; }
.row-tools { gap: 8px; }
.search {
  flex: 1; display: flex; align-items: center; gap: 8px; padding: 0 12px; min-height: 38px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--muted);
}
.search input { flex: 1; border: 0; background: transparent; color: var(--ink); font: inherit; min-width: 0; outline: none; }
.btn {
  min-height: 38px; padding: 0 14px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }

/* Cards */
.count { font-size: 13px; color: var(--muted); margin: 12px 0 8px; }
.cards { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .cards { grid-template-columns: 1fr 1fr; } }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card.selected { outline: 2px solid var(--accent); outline-offset: -1px; }
.card-head { padding: 14px 14px 10px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.pill {
  font-size: 11.5px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); letter-spacing: 0.01em;
}
.pill.age { background: var(--accent-soft); color: var(--ink); }
.pill.imp { margin-left: auto; }
.pill.status { border: 1px solid var(--border); background: var(--surface); }
.pill.status.routine { border-color: var(--accent); color: var(--accent); }
.card h3 { font-size: 17px; font-weight: 700; }
.diseases { font-size: 13px; color: var(--ink-2); margin-top: 2px; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 14px; }
.tile { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.tile .label { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.tile .value { font-size: 20px; font-weight: 650; line-height: 1.15; margin-top: 2px; overflow-wrap: anywhere; }
.tile .value.long { font-size: 14.5px; font-weight: 600; line-height: 1.3; }
.tile .sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; overflow-wrap: anywhere; }

.score-strip { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px 14px 0; }
.score-item { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.score-item .score-k { display: block; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.score-item b { display: block; margin-top: 2px; font-size: 14px; line-height: 1.25; }
.score-item.tier-s { border-color: var(--tier-s); }
.score-item.tier-a { border-color: var(--tier-a); }
.score-item.tier-b { border-color: var(--tier-b); }
.score-item.tier-c { border-color: var(--tier-c); }
.score-item.tier-d { border-color: var(--tier-d); }
.score-item.tier-s b { color: var(--tier-s); }
.score-item.tier-a b { color: var(--tier-a); }
.score-item.tier-b b { color: var(--tier-b); }
.score-item.tier-c b { color: var(--tier-c); }
.score-item.tier-d b { color: var(--tier-d); }

.meter { padding: 10px 14px 0; }
.meter .label { display: block; font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.meter .label b { display: block; color: var(--ink); font-weight: 600; font-size: 14px; text-transform: none; letter-spacing: 0; line-height: 1.35; margin-top: 2px; }
.meter .track { height: 8px; border-radius: 4px; background: var(--accent-soft); overflow: hidden; }
.meter .fill { height: 100%; border-radius: 4px; background: var(--ramp-450); }

.se-line { padding: 10px 14px 0; font-size: 13px; color: var(--ink-2); display: grid; gap: 3px; }
.se-line b { color: var(--ink); font-weight: 600; }

.card-actions { display: flex; gap: 8px; padding: 12px 14px 14px; }
.card-actions .btn { flex: 1; justify-content: center; text-decoration: none; }
.card-actions .chev { transition: transform 0.2s; }
.card.open .card-actions .chev { transform: rotate(180deg); }

.details { display: none; border-top: 1px solid var(--hair); padding: 4px 14px 14px; }
.card.open .details { display: block; }
.stat { padding: 12px 0; border-bottom: 1px solid var(--hair); }
.stat:last-child { border-bottom: 0; }
.stat .k { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat .v { font-size: 16px; font-weight: 650; margin-top: 2px; overflow-wrap: anywhere; }
.stat .d { font-size: 14px; color: var(--ink-2); margin-top: 3px; }
.stat .calc { font-size: 12.5px; color: var(--muted); margin-top: 3px; font-style: italic; }
.orig { margin-top: 6px; font-size: 13px; color: var(--ink-2); background: var(--surface-2); border-radius: 8px; padding: 7px 10px; }
.orig b { font-weight: 600; color: var(--ink); }
.src { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.src a {
  font-size: 12px; font-weight: 600; text-decoration: none; padding: 4px 9px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--accent); background: var(--surface); display: inline-flex; align-items: center; gap: 4px;
  max-width: 100%;
}
.src a:hover { background: var(--accent-soft); }
.src a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src svg { flex: 0 0 auto; }
.sub-h { font-size: 15px; font-weight: 700; margin: 14px 0 2px; }
.sub-h.first { margin-top: 10px; }
.se-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 4px; }
.se-table td { padding: 6px 0; border-bottom: 1px solid var(--hair); vertical-align: top; }
.se-table tr:last-child td { border-bottom: 0; }
.se-table td.rate { text-align: right; font-weight: 650; white-space: nowrap; padding-left: 10px; }
.se-table .src { margin-top: 3px; }
.disease-block { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }
.disease-block .sub-h { margin-top: 0; }
.disease-block .stat { border-color: var(--border); }
.disease-block .orig { background: var(--surface); }
.disease-block .src a { background: var(--surface); }
.notes { font-size: 13px; color: var(--ink-2); margin-top: 8px; }
.notes dt { font-weight: 600; color: var(--ink); margin-top: 6px; }
.notes dd { margin: 0; }

/* Compare */
.compare-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 10px 0 max(10px, env(safe-area-inset-bottom));
  box-shadow: 0 -8px 24px -16px rgba(0,0,0,0.3);
}
.compare-bar .wrap { display: flex; align-items: center; gap: 8px; }
.compare-bar span { flex: 1; font-size: 14px; font-weight: 600; }
.compare { border: 0; padding: 0; width: min(100vw, 1100px); max-width: 100vw; height: 100dvh; max-height: 100dvh; overflow: auto; background: var(--surface); color: var(--ink); }
.compare::backdrop { background: rgba(0,0,0,0.45); }
@media (min-width: 900px) { .compare { height: auto; max-height: 92dvh; border-radius: 16px; } }
.compare-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--hair); background: var(--surface); }
.compare-head h2 { font-size: 18px; }
.compare-scroll { overflow: visible; max-height: none; }
.ctable { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 600px; font-size: 12.5px; line-height: 1.5; }
.ctable th, .ctable td { padding: 13px 14px; border-bottom: 1px solid var(--hair); vertical-align: top; text-align: left; }
.ctable th { font-size: 11px; line-height: 1.35; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 650; }
.ctable thead th { position: static; background: var(--surface); font-size: 13px; line-height: 1.4; text-transform: none; letter-spacing: 0; color: var(--ink); font-weight: 700; }
.ctable th.rowh { position: sticky; left: 0; background: var(--surface); z-index: 2; min-width: 96px; max-width: 112px; }
.ctable thead th.rowh { z-index: 2; }
.ctable td { min-width: 168px; }
.ctable td .v { font-weight: 650; }
.ctable td .d { color: var(--ink-2); font-size: 11.5px; margin-top: 4px; }
.ctable td > * + * { margin-top: 8px; }
.ctable .src { margin-top: 5px; }

/* Scoring method */
.method { margin-top: 34px; padding-top: 20px; padding-bottom: 20px; border-top: 1px solid var(--hair); border-bottom: 1px solid var(--hair); }
.method h2 { font-size: 20px; }
.method > p { margin-top: 8px; color: var(--ink-2); }
.method-grid { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 10px; }
.method-grid p { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; color: var(--ink-2); font-size: 14px; }
.method .method-warning { color: var(--ink); font-weight: 600; }
@media (min-width: 720px) { .method-grid { grid-template-columns: 1fr 1fr; } }

/* Sources */
.sources { margin-top: 36px; }
.sources h2 { font-size: 20px; margin-bottom: 4px; }
.sources ol { padding-left: 22px; margin: 12px 0 0; font-size: 14px; display: grid; gap: 8px; }
.sources li::marker { color: var(--muted); }
.sources .pub { font-weight: 600; }
.sources .used { color: var(--muted); font-size: 12.5px; }
.foot { margin-top: 28px; font-size: 12.5px; color: var(--muted); }

.empty { padding: 40px 0; text-align: center; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
