:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --up: #006300;
  --down: #d03b3b;
  /* Achievement levels: diverging blue (at/above) <-> red (below) */
  --lv-adv: #1c5cab;
  --lv-prof: #86b6ef;
  --lv-dev: #f0a19c;
  --lv-min: #c93a3a;
  --area-above: #2a78d6;
  --area-near: #d6d4cc;
  --area-below: #e34948;
  --bar: #2a78d6;
  /* Race/ethnicity groups (categorical) */
  --e-his: #e08a2e; --e-asi: #2a78d6; --e-whi: #7cb342; --e-two: #9b59b6;
  --e-bla: #d64f6b; --e-fil: #f2c94c; --e-pac: #26a69a; --e-ami: #8d6e63;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
    --border: rgba(255, 255, 255, 0.10); --accent: #5598e7; --up: #0ca30c; --down: #e66767;
    --lv-adv: #5598e7; --lv-prof: #1c5cab; --lv-dev: #a83232; --lv-min: #e66767;
    --area-above: #3987e5; --area-near: #4a4a46; --area-below: #e66767; --bar: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --border: rgba(255, 255, 255, 0.10); --accent: #5598e7; --up: #0ca30c; --down: #e66767;
  --lv-adv: #5598e7; --lv-prof: #1c5cab; --lv-dev: #a83232; --lv-min: #e66767;
  --area-above: #3987e5; --area-near: #4a4a46; --area-below: #e66767; --bar: #3987e5;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page); color: var(--ink); font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* ---- header ---- */
.top { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border); }
.top-inner { max-width: 1440px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.brand { color: var(--ink); display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 14px; height: 14px; border-radius: 3px; background: linear-gradient(135deg, var(--lv-adv) 50%, var(--lv-min) 50%); }
nav { display: flex; gap: 4px; }
nav a { color: var(--ink-2); padding: 6px 10px; border-radius: 6px; }
nav a.on { background: var(--surface-2); color: var(--ink); }
nav a:hover { text-decoration: none; background: var(--surface-2); }
.search { position: relative; flex: 1; min-width: 200px; max-width: 420px; margin-left: auto; }
.search input {
  width: 100%; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--page); color: var(--ink); font: inherit;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 60vh; overflow: auto;
}
#results li a { display: block; padding: 7px 10px; border-radius: 6px; color: var(--ink); }
#results li a:hover, #results li a.active { background: var(--surface-2); text-decoration: none; }
#results small { display: block; color: var(--muted); }
.icon-btn { background: none; border: 1px solid var(--border); color: var(--ink-2); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 16px; }

main { max-width: 1440px; margin: 0 auto; padding: 24px 16px 48px; }
footer { max-width: 1440px; margin: 0 auto; padding: 16px 16px 40px; color: var(--muted); font-size: 12.5px; border-top: 1px solid var(--border); }
.loading { color: var(--muted); }

/* ---- type ---- */
h1 { font: 600 34px/1.15 var(--serif); margin: 4px 0 6px; letter-spacing: -0.01em; }
h2 { font: 600 21px/1.25 var(--serif); margin: 0 0 4px; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.lede { color: var(--ink-2); max-width: 70ch; margin: 0 0 20px; }
.crumbs { font-size: 13px; color: var(--muted); }
.crumbs a { color: var(--ink-2); }

/* ---- cards / sections ---- */
.section { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-top: 18px; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.section-head p { margin: 0; color: var(--ink-2); font-size: 13.5px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-top: 18px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; }
.tile .label { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.tile .hero { font: 600 46px/1.05 var(--serif); margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.tile .hero small { font-size: 20px; color: var(--ink-2); }
.tile .sub { font-size: 13px; color: var(--ink-2); }
.tile .bench { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--grid); display: grid; gap: 4px; font-size: 13px; }
.tile .bench div { display: flex; justify-content: space-between; gap: 8px; }

.delta { font-size: 13px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.flat { color: var(--muted); }
.delta.neu { color: var(--ink-2); }

/* ---- controls ---- */
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.controls label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
select, .controls input {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--page);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; max-width: min(340px, 100%);
}
.controls, .controls label { min-width: 0; max-width: 100%; }
.controls label { grid-template-columns: minmax(0, 1fr); }
.controls label select { width: 100%; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; font-size: 13px; padding: 6px 12px; border: 0; background: var(--page); color: var(--ink-2); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--ink); color: var(--surface); }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 7px 8px; text-align: left; border-bottom: 1px solid var(--grid); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; user-select: none; }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--ink); }
th.sorted::after { content: " ↓"; }
th.sorted.asc::after { content: " ↑"; }
td.r, th.r { text-align: right; }
tbody tr:hover { background: var(--surface-2); }
tr.cat td { background: var(--page); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding-top: 12px; }
td .sub { display: block; font-size: 12px; color: var(--muted); }
.rank { color: var(--muted); width: 1%; }
td.wide, th.wide { min-width: 200px; }

/* inline bar */
.ibar { display: flex; align-items: center; gap: 8px; min-width: 150px; }
.ibar .track { flex: 1; height: 10px; position: relative; }
.ibar .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--bar); border-radius: 0 4px 4px 0; }
.ibar .ref { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink-2); border-radius: 1px; }
.ibar .val { width: 46px; text-align: right; font-variant-numeric: tabular-nums; }

/* stacked level bars */
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.levels { display: grid; gap: 10px; margin-top: 12px; }
.lv-row { display: grid; grid-template-columns: 84px 1fr 64px; gap: 12px; align-items: center; }
.lv-row .name { font-size: 13px; color: var(--ink-2); }
.lv-row .tot { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.lv-row .tot small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.stack { display: flex; gap: 2px; height: 26px; position: relative; }
.stack > div { height: 100%; display: flex; align-items: center; justify-content: center; font-size: 11.5px; overflow: hidden; color: #fff; font-variant-numeric: tabular-nums; }
.stack > div:first-child { border-radius: 4px 0 0 4px; }
.stack > div:last-child { border-radius: 0 4px 4px 0; }
.stack .s-prof, .stack .s-dev, .stack .s-near { color: var(--ink); }
.stack .thresh { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); border-radius: 1px; }
.s-adv { background: var(--lv-adv); } .s-prof { background: var(--lv-prof); }
.s-dev { background: var(--lv-dev); } .s-min { background: var(--lv-min); }
.s-above { background: var(--area-above); } .s-near { background: var(--area-near); } .s-below { background: var(--area-below); }
.e-his { background: var(--e-his); } .e-asi { background: var(--e-asi); } .e-whi { background: var(--e-whi); } .e-two { background: var(--e-two); }
.e-bla { background: var(--e-bla); } .e-fil { background: var(--e-fil); } .e-pac { background: var(--e-pac); } .e-ami { background: var(--e-ami); }
.dstack { min-width: 160px; }
.dstack > div { white-space: nowrap; }
.dstack .e-fil, .dstack .e-whi, .dstack .e-his { color: #0b0b0b; }
.dv-row { grid-template-columns: 200px 1fr 120px; }
/* relative performance tile, info button and popup */
.rpi { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
.rpi th { font-size: 11px; color: var(--muted); font-weight: 600; text-align: right; padding: 2px 0; border: 0; }
.rpi td { padding: 3px 0; border: 0; text-align: right; font-variant-numeric: tabular-nums; }
.rpi td:first-child, .rpi th:first-child { text-align: left; color: var(--ink-2); }
.rpi tr.big td:not(:first-child) { font: 600 22px/1.1 var(--serif); padding: 2px 0 4px; white-space: nowrap; }
.rpi tr.big td small { font-size: 12px; font-family: var(--sans); font-weight: 400; color: var(--ink-2); }
.rpi td:not(:first-child) { padding-left: 8px; }
.info { display: inline-flex; align-items: center; justify-content: center; width: 17px; height: 17px; border-radius: 50%;
  border: 1px solid var(--ink-2); color: var(--ink-2); background: none; font: 600 11px/1 Georgia, serif; cursor: pointer; vertical-align: middle; margin-left: 6px; padding: 0; }
.info:hover { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 60; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow: auto; }
.modal { background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 14px; max-width: 720px; width: 100%;
  padding: 24px 28px 20px; box-shadow: 0 20px 60px rgba(0,0,0,.3); font-size: 15px; line-height: 1.55; position: relative; }
.modal h2 { margin-top: 0; }
.modal h3 { font-size: 15px; margin: 18px 0 4px; }
.modal p { margin: 0 0 10px; }
.modal .close { position: absolute; top: 12px; right: 14px; background: none; border: 0; font-size: 22px; color: var(--muted); cursor: pointer; }
.modal .close:hover { color: var(--ink); }
.modal table { font-size: 13.5px; margin: 6px 0 10px; }
tr.me td { background: var(--blue-soft, var(--surface-2)); font-weight: 600; }
tr.state td { background: var(--surface-2); font-style: italic; border-top: 2px solid var(--axis); border-bottom: 2px solid var(--axis); }
.controls label.check { display: flex; flex-direction: row; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); padding-bottom: 7px; }
.controls label.check input { width: auto; margin: 0; }
/* collapsible blocks */
.fold-btn { font: inherit; font-size: 13px; color: var(--accent); background: none; border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
.fold-btn:hover { background: var(--surface-2); }
.fold-body[hidden] { display: none; }
.fold-body { margin-top: 12px; }
/* the written analysis */
.analysis { background: var(--surface-2); border-radius: 10px; padding: 14px 18px; margin: 0 0 16px; }
.analysis p { margin: 0 0 10px; }
.analysis p:last-of-type { margin-bottom: 0; }
.analysis .credit { font-size: 12px; color: var(--muted); margin-top: 8px; }
/* contribution bars (diverging around zero) */
.cbar { display: inline-block; position: relative; width: 120px; height: 10px; vertical-align: middle; background: var(--surface-2); border-radius: 2px; }
.cbar::before { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--axis); }
.cbar i { position: absolute; top: 0; bottom: 0; background: var(--up); }
.cbar i.neg { background: var(--down); }
tr.sum td { font-weight: 600; border-top: 2px solid var(--axis); }
#drivers-sec .section-head { display: block; }
#drivers-sec .section-head .controls { margin-top: 12px; }
.drv-cat { margin-top: 18px; }
.drv-cat h3 { font-size: 14px; margin: 0 0 4px; display: flex; justify-content: space-between; gap: 12px; }
.drv-cat h3 span { font-weight: 400; color: var(--ink-2); }
.drv-sum { font-size: 15px; margin: 0 0 6px; }
/* trend charts */
.chart { width: 100%; height: auto; display: block; margin-top: 8px; }
.chart .grid { stroke: var(--grid); }
.chart .lbl { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .dash { stroke-dasharray: 5 4; stroke-width: 1.6; opacity: .7; }
.chart .line.r1 { opacity: .4; }
.chart .line.thin { stroke-width: 1.2; opacity: .35; }
.chart .line.thin:hover { opacity: 1; stroke-width: 2.5; }
.other { stroke: var(--ink-2); } .state { stroke: var(--ink); }
.chart .line.r2 { opacity: .25; stroke-dasharray: 2 4; }
.legend i.sw.r2 { opacity: .35; border-top-style: dotted; }
.ela { stroke: var(--accent); fill: var(--accent); } .math { stroke: var(--e-his); fill: var(--e-his); } .div { stroke: var(--e-two); fill: var(--e-two); }
.chart circle { stroke: var(--surface); stroke-width: 1.5; }
.legend i.sw { background: none; border-top: 3px solid var(--ink-2); height: 0; width: 18px; border-radius: 0; }
.legend i.sw.ela { border-color: var(--accent); } .legend i.sw.math { border-color: var(--e-his); } .legend i.sw.div { border-color: var(--e-two); }
.legend i.sw.dash { border-top-style: dashed; } .legend i.sw.r1 { opacity: .4; }
:root[data-theme="dark"] .stack .s-prof, :root[data-theme="dark"] .stack .s-dev { color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .stack .s-prof, :root:not([data-theme="light"]) .stack .s-dev { color: #fff; } }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.two h3 { font-size: 14px; margin: 0 0 6px; }
.area-row { grid-template-columns: 170px 1fr; }

#tip {
  position: fixed; z-index: 50; pointer-events: none; max-width: 280px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 6px 20px rgba(0,0,0,.18);
}
#tip b { display: block; margin-bottom: 4px; }
#tip .kv { display: flex; justify-content: space-between; gap: 16px; font-variant-numeric: tabular-nums; }
#tip i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; }

.empty { color: var(--muted); padding: 20px 0; }

@media (max-width: 760px) {
  h1 { font-size: 27px; }
  .two { grid-template-columns: 1fr; }
  .search { order: 5; max-width: none; flex-basis: 100%; }
  .lv-row { grid-template-columns: 64px 1fr 52px; gap: 8px; }
  .area-row { grid-template-columns: 110px 1fr; }
  .dv-row { grid-template-columns: 90px 1fr 80px; }
  .tile .hero { font-size: 38px; }
  .section { padding: 16px; }
}
