/* Grade Trends：颜色全部是 :root 上的变量；深色模式另选一组值（不是自动反色）。
   图表配色按 dataviz 参考调色板：分类色固定顺序（slot 1–6），已用 validate_palette.js 校验过浅色 / 深色两种模式。 */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6e69;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --brand: #2a78d6;
  --link: #1c5cab;
  --up: #006300;
  --down: #c62f2f;
  --wash: rgba(42, 120, 214, 0.08);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300;
  --ref: #898781;          /* 全州平均：灰色参照线 */
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242422;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #9b9a93;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --brand: #3987e5;
    --link: #86b6ef;
    --up: #0ca30c;
    --down: #e66767;
    --wash: rgba(57, 135, 229, 0.14);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300;
    --ref: #898781;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #242422;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #9b9a93;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --brand: #3987e5;
  --link: #86b6ef;
  --up: #0ca30c;
  --down: #e66767;
  --wash: rgba(57, 135, 229, 0.14);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300;
  --ref: #898781;
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.55 var(--font);
  overflow-x: hidden;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 28px; letter-spacing: -0.01em; }
h2 { font-size: 19px; }
h3 { font-size: 15px; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { max-width: 1440px; margin: 0 auto; padding: 0 24px; }
button { font: inherit; color: inherit; }

/* ------------------------------------------------------------ 页头 */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); position: relative; z-index: 20; }
.header-inner { display: flex; align-items: center; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 700; font-size: 17px; }
.brand:hover { text-decoration: none; }
.brand-mark { display: block; }
.search { position: relative; flex: 1 1 320px; max-width: 460px; display: flex; }
.search-input {
  width: 100%; height: 40px; padding: 0 44px 0 14px; border: 1px solid var(--axis); border-radius: 10px;
  background: var(--page); color: var(--ink); font: inherit; outline: none;
}
.search-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--wash); }
.search-btn { position: absolute; right: 4px; top: 4px; width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-2); cursor: pointer; }
.nav { display: flex; align-items: center; gap: 16px; margin-left: auto; white-space: nowrap; }
.nav a { color: var(--ink-2); }
.lang-switch { display: inline-flex; gap: 6px; color: var(--muted); }
.lang-switch a.on { color: var(--ink); font-weight: 600; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--brand); color: #fff; font-size: 12px; line-height: 18px; text-align: center; }

.suggest {
  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: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12);
  max-height: 360px; overflow-y: auto; z-index: 30;
}
.suggest li { display: flex; gap: 8px; align-items: baseline; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.suggest li[aria-selected="true"], .suggest li:hover { background: var(--wash); }
.suggest .s-label { font-weight: 600; }
.suggest .s-detail { color: var(--muted); font-size: 13px; margin-left: auto; text-align: right; }

.crumbs { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 14px; padding-bottom: 4px; font-size: 13px; color: var(--muted); }
.crumbs a { color: var(--ink-2); }

/* ------------------------------------------------------------ 首页 */
.hero { background: var(--surface); border-bottom: 1px solid var(--border); padding: 40px 0 36px; }
.hero h1 { font-size: 34px; max-width: 760px; }
.hero .lead { font-size: 17px; color: var(--ink-2); max-width: 720px; }
.hero-search { position: relative; display: flex; gap: 8px; max-width: 640px; margin-top: 18px; }
.hero-search .search-input { height: 48px; font-size: 16px; padding-right: 14px; }
.page-home .site-header .search { display: none; }
/* 首页：搜索框到"附近的学校"标题 37px（搜索区下边距 10 + 分隔线 1 + 卡片外边距 8 + 卡片内边距 18） */
.page-home .hero { padding-bottom: 10px; }
.page-home #nearby { margin-top: 8px; }

.section { margin: 32px 0; }
.city-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.city-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.city-grid a { display: flex; flex-direction: column; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; color: var(--ink); }
.city-grid a:hover { border-color: var(--brand); text-decoration: none; }
.city-grid .muted { font-size: 13px; }

/* ------------------------------------------------------------ 卡片、通用 */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin: 18px 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.card-head p { margin: 0; }
.page-head { margin: 18px 0 8px; }
.page-head .lead { color: var(--ink-2); }
.notice { background: var(--surface-2); border-radius: 8px; padding: 10px 14px; color: var(--ink-2); }
.footnote { font-size: 13px; margin-top: 10px; }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--surface-2); color: var(--ink-2); font-size: 12px; line-height: 18px; }
.tag-accent { background: var(--wash); color: var(--link); }
.chips-line { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip-link { padding: 2px 10px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); font-size: 13px; }
.btn, .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; height: 40px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--brand); font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn { background: var(--brand); color: #fff; }
.btn:hover { text-decoration: none; filter: brightness(1.05); }
.btn-ghost { background: transparent; color: var(--link); }
.btn-ghost[aria-pressed="true"] { background: var(--wash); }
.hero-search .btn { height: 48px; }

/* 筛选按钮：一行，放在它所控制的内容上方 */
.filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0 12px; }
.chip { height: 30px; padding: 0 12px; border: 1px solid var(--border); border-radius: 15px; background: var(--surface); color: var(--ink-2); cursor: pointer; }
.chip:hover { background: var(--wash); }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.chip:disabled { opacity: .4; cursor: default; }
.filters-count { margin-left: 6px; font-size: 13px; }
.filters-year { font-size: 13px; }
.measure-note { margin: -4px 0 8px; font-size: 13px; color: var(--ink-2); max-width: 980px; }
.filters-year::before { content: "· "; }
.filters .sep { width: 1px; height: 20px; background: var(--grid); margin: 0 6px; }

/* ------------------------------------------------------------ 学校列表 */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; }
.schools th, .schools td, .data th, .data td { padding: 10px 10px; border-bottom: 1px solid var(--grid); text-align: left; vertical-align: top; }
.schools thead th, .data thead th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--axis); white-space: nowrap; }
.schools thead th button { border: 0; background: none; padding: 0; color: inherit; font: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer; text-align: inherit; }
.schools thead th[data-sort] button::after { content: " ↕"; color: var(--axis); }
.schools thead th[data-sort] button:hover { color: var(--link); }
.schools thead th[aria-sort] { color: var(--ink); }
.schools thead th[aria-sort] button::after { content: " ↓"; color: var(--ink); }
.schools thead th[aria-sort="ascending"] button::after { content: " ↑"; }
.sort-pick { display: none; margin-left: auto; align-items: center; gap: 6px; font-size: 13px; }
.sort-pick select { height: 30px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit; padding: 0 6px; }
.schools tbody tr:hover { background: var(--wash); }
.c-pick { width: 28px; padding-right: 0 !important; }
.c-pick input { width: 16px; height: 16px; margin-top: 3px; accent-color: var(--brand); }
.c-name { min-width: 200px; }
.school-link { font-weight: 600; }
.c-name .sub { font-size: 13px; margin-top: 2px; }
.c-num { text-align: right !important; white-space: nowrap; font-variant-numeric: tabular-nums; }
.c-group { white-space: nowrap; }
/* 总分变化：箭头 + 百分点；方向同时由箭头表示，不只靠颜色。平线是画出来的短横，免得和负号混淆 */
.chg { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chg.up { color: var(--up); }
.chg.down { color: var(--down); }
.chg.flat { color: var(--muted); font-weight: 500; }
.chg.flat .chg-icon { display: inline-block; width: 14px; height: 2px; border-radius: 1px; background: currentColor; }
.c-score { white-space: nowrap; min-width: 104px; }
.score-line { display: flex; align-items: center; gap: 8px; }
.score-line strong { min-width: 38px; font-variant-numeric: tabular-nums; }
.spark { display: block; overflow: visible; width: 56px; height: 18px; }
.spark path { fill: none; stroke: var(--ref); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.spark circle { fill: var(--s1); stroke: var(--surface); stroke-width: 1.5; }
.vs { font-size: 12px; }
.delta { font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.empty { padding: 12px; }
.pager { display: flex; gap: 6px; flex-wrap: wrap; margin: 16px 0; }
.pager a, .pager span { min-width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }
.pager span { background: var(--ink); color: var(--surface); }

.letters { columns: 4 200px; column-gap: 24px; }
.letter { break-inside: avoid; margin-bottom: 14px; }
.letter ul { list-style: none; margin: 0; padding: 0; }
.letter li { padding: 1px 0; }
.letter .muted { font-size: 12px; }

.results { list-style: none; margin: 0; padding: 0; }
.results li { display: flex; gap: 10px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--grid); flex-wrap: wrap; }

/* 对比栏：勾选学校后出现在页面底部 */
.compare-bar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -6px 20px rgba(0,0,0,.08); z-index: 25; }
.compare-bar-inner { display: flex; gap: 10px; align-items: center; min-height: 60px; padding-top: 8px; padding-bottom: 8px; }
.compare-names { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
body.has-compare-bar { padding-bottom: 72px; }

/* ------------------------------------------------------------ 学校页 */
.school-head { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; margin: 14px 0 6px; flex-wrap: wrap; }
.school-title h1 { margin-bottom: 6px; }
.school-meta { display: flex; flex-wrap: wrap; gap: 4px 0; color: var(--ink-2); margin: 0 0 2px; }
.school-meta span + span::before { content: "·"; margin: 0 8px; color: var(--muted); }
.school-addr { color: var(--muted); margin: 0; }
details.years-table { margin-top: 12px; }
details.years-table summary { cursor: pointer; color: var(--link); font-size: 14px; }
details.years-table table { margin-top: 6px; }
.school-addr a { margin-left: 8px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 16px 0; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.tiles-inline .tile { background: var(--surface-2); border: 0; }
.tile-label { font-size: 13px; color: var(--ink-2); }
.tile-value { font-size: 28px; font-weight: 650; line-height: 1.2; margin: 2px 0; }
.tile-sub { font-size: 12px; }
.table-title { margin-top: 18px; }
.data td strong { margin-right: 6px; font-variant-numeric: tabular-nums; }
.data td .muted { font-size: 12px; }
.data tbody th { font-weight: 600; white-space: nowrap; }

/* 族裔构成：100% 堆叠条，段与段之间留 2px 表面色缝隙 */
.stack { display: flex; gap: 2px; height: 18px; margin: 6px 0 10px; background: var(--surface); }
.stack .seg { display: block; min-width: 2px; }
.stack .seg:first-child { border-radius: 4px 0 0 4px; }
.stack .seg:last-child { border-radius: 0 4px 4px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; list-style: none; margin: 0 0 6px; padding: 0; font-size: 13px; }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex: none; }
.key.line { width: 14px; height: 2px; border-radius: 1px; }
.r0, .s0 { background: var(--s1); } .r1, .s1 { background: var(--s2); } .r2, .s2 { background: var(--s3); }
.r3, .s3 { background: var(--s4); } .r4, .s4 { background: var(--s5); } .r5, .s5 { background: var(--s6); }
.key.ref { background: var(--ref); }

/* ------------------------------------------------------------ 图表（charts.js） */
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px 22px; }
.chart { position: relative; min-width: 0; }
.chart h3 { margin: 4px 0 2px; }
.chart .chart-sub { font-size: 12px; color: var(--muted); margin: 0 0 4px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .axis line { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gap-label { fill: var(--muted); font-size: 10px; }
.chart .series path { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series circle { stroke: var(--surface); stroke-width: 2; }
.chart .series.ref path { stroke-width: 1.5; }
.chart .series path.bridge { stroke-width: 1.5; stroke-dasharray: 0.5 5; opacity: .75; }
.chart .gap-band { fill: var(--surface-2); }
.chart .break-line { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 4 3; }
.chart-note { display: flex; align-items: center; gap: 6px; margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.key.dotted { width: 16px; height: 0; border-radius: 0; background: none; border-top: 2px dotted var(--ink-2); }
.key.break { width: 0; height: 12px; border-radius: 0; background: none; border-left: 1px dashed var(--ink-2); }
.chart .end-label { fill: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .cross { stroke: var(--axis); stroke-width: 1; }
.chart .bar rect { stroke: none; }
.chart .legend { margin-top: 4px; }
.chart .empty-chart { color: var(--muted); font-size: 13px; padding: 30px 0; text-align: center; border: 1px dashed var(--grid); border-radius: 8px; }
.chart.loading svg { opacity: .45; }
.tip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 140px; padding: 8px 10px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: 0 6px 18px rgba(0,0,0,.14); font-size: 12px;
}
.tip .tip-title { color: var(--muted); margin-bottom: 4px; }
.tip .tip-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.tip .tip-row strong { min-width: 34px; color: var(--ink); font-variant-numeric: tabular-nums; }
.tip .tip-row span { color: var(--ink-2); }
details.table-view { margin-top: 6px; font-size: 13px; }
details.table-view summary { cursor: pointer; color: var(--link); }
details.table-view table { margin-top: 6px; }
details.table-view th, details.table-view td { padding: 4px 8px; border-bottom: 1px solid var(--grid); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
details.table-view th:first-child, details.table-view td:first-child { text-align: left; }

/* ------------------------------------------------------------ 对比页 */
.picked { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.picked li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.picked .remove { margin-left: auto; width: 28px; height: 28px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.add-school { position: relative; max-width: 460px; }
.compare-table th:first-child { min-width: 150px; }
.compare-table td, .compare-table thead th { min-width: 150px; }
.compare-table thead th { text-transform: none; font-size: 13px; color: var(--ink); white-space: normal; }

/* ------------------------------------------------------------ 说明页、页脚 */
.prose { max-width: 820px; }
.prose h1 { margin-top: 18px; }
.prose h2 { margin-top: 24px; }
.prose li { margin: 4px 0; }
.site-footer { margin-top: 40px; padding: 24px 0 32px; border-top: 1px solid var(--border); background: var(--surface); font-size: 13px; color: var(--ink-2); }
.footer-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* 中等宽度（小笔记本）表头放不下一行时才换行 */
@media (max-width: 1200px) {
  .schools thead th { white-space: normal; }
}

@media (max-width: 720px) {
  .wrap { padding: 0 16px; }
  h1, .hero h1 { font-size: 24px; }
  .header-inner { gap: 10px; padding-top: 8px; padding-bottom: 8px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .nav { gap: 12px; }
  .c-hide-sm { display: none; }
  .c-score { min-width: 0; }
  .spark { display: none; }
  .vs span:not(.delta) { display: none; } /* 手机上只留 "+38"，表格下方注明是比全州同年级 */
  .sort-pick { display: inline-flex; }
  /* 手机上只放 学校、数学、英语 + 一列：默认低收入；按距离、科学、人数排序时换成那一列（其余列横向滑动可看） */
  .c-dist { display: none; }
  .school-list[data-sorted="dist"] .c-dist, .school-list[data-sorted="sci"] .c-sci,
  .school-list[data-sorted="change"] .c-change, .school-list[data-sorted="enroll"] .c-enroll,
  .school-list[data-sorted="group"] .c-group { display: table-cell; }
  .school-list[data-sorted="dist"] .c-frl, .school-list[data-sorted="sci"] .c-frl,
  .school-list[data-sorted="change"] .c-frl, .school-list[data-sorted="enroll"] .c-frl,
  .school-list[data-sorted="group"] .c-frl { display: none; }
  .schools th, .schools td { padding: 9px 5px; }
  .schools thead th { font-size: 11px; letter-spacing: 0; white-space: normal; }
  .c-name { min-width: 120px; }
  .c-pick { width: 22px; }
  .card { padding: 14px; border-radius: 10px; }
  .tile-value { font-size: 24px; }
  .hero { padding: 26px 0 24px; }
  .page-home .hero { padding-bottom: 10px; }
  .hero-search .btn { padding: 0 14px; }
}
