:root {
  color-scheme: light;
  --surface-0: #f4f3f0;
  --surface-1: #fcfcfb;
  --border: #dcdad4;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6d6c67;
  --accent: #1c5cab;
  --ink-line: #0b0b0b;
  --halo: #ffffff;
  --q1: #86b6ef; --q2: #5598e7; --q3: #2a78d6; --q4: #1c5cab; --q5: #104281;
  --nodata: #d9d8d3;
  --grammar: #eb6834; --nonselective: #ffffff; --utc: #eda100; --independent: #e87ba4;
  --note-bg: #fff4e5; --note-border: #f2c48d;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #121211; --surface-1: #1a1a19; --border: #383835;
    --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #a3a29a;
    --accent: #86b6ef; --ink-line: #f0efec; --halo: #0b0b0b; --nodata: #4a4a46;
    --nonselective: #f0efec;
    --note-bg: #2b2215; --note-border: #6b4c22;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211; --surface-1: #1a1a19; --border: #383835;
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #a3a29a;
  --accent: #86b6ef; --ink-line: #f0efec; --halo: #0b0b0b; --nodata: #4a4a46;
  --nonselective: #f0efec; --note-bg: #2b2215; --note-border: #6b4c22;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--surface-0); color: var(--text-primary); }
#app { display: flex; height: 100vh; height: 100dvh; }
#panel { width: 340px; flex: none; background: var(--surface-1); border-right: 1px solid var(--border); overflow-y: auto; z-index: 500; }
#map { flex: 1; min-width: 0; background: var(--surface-0); }
.panel-head { padding: 16px 16px 8px; position: relative; }
h1 { font-size: 1.15rem; margin: 0 0 4px; line-height: 1.25; }
.sub { margin: 0; color: var(--text-secondary); font-size: .9rem; line-height: 1.4; }
.panel-toggle { display: none; }
.panel-body { padding: 0 16px 16px; }
.note { background: var(--note-bg); border: 1px solid var(--note-border); border-radius: 8px; padding: 8px 10px; font-size: .85rem; line-height: 1.4; margin: 8px 0 12px; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; }
fieldset { border: 0; padding: 0; margin: 14px 0 0; }
legend { font-weight: 600; font-size: .85rem; margin-bottom: 6px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .03em; }
fieldset label { display: flex; align-items: center; gap: 8px; font-size: .92rem; padding: 4px 0; cursor: pointer; }
input[type=radio], input[type=checkbox] { accent-color: var(--accent); margin: 0; }
.pc label { font-weight: 600; font-size: .85rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .03em; }
.pc-row { display: flex; gap: 6px; margin-top: 6px; }
.pc-row input { flex: 1; min-width: 0; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-0); color: var(--text-primary); font: inherit; }
.pc-row button, .btn { padding: 7px 12px; border-radius: 6px; border: 1px solid var(--accent); background: var(--accent); color: var(--surface-1); font: inherit; font-weight: 600; cursor: pointer; }
.btn { width: 100%; margin-top: 16px; }
.pc-msg { margin: 4px 0 0; font-size: .82rem; color: var(--text-secondary); min-height: 1em; }
.tiny { font-size: .8rem; color: var(--text-muted); line-height: 1.4; }
.legend { margin-top: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; }
.legend h4 { margin: 0 0 6px; font-size: .85rem; }
.legend .row { display: flex; align-items: center; gap: 8px; font-size: .82rem; padding: 2px 0; color: var(--text-secondary); }
.sw { width: 22px; height: 14px; border-radius: 3px; flex: none; }
.sw.nodata { background: var(--nodata); }
.legend .src { margin-top: 6px; font-size: .75rem; color: var(--text-muted); }
.legend .src a { color: var(--accent); }
.mk { display: inline-block; width: 12px; height: 12px; border: 1.5px solid #0b0b0b; flex: none; }
.mk { background: var(--surface-1); border-color: var(--text-primary); }
.mk-grammar { transform: rotate(45deg) scale(.85); }
.mk-nonselective { border-radius: 50%; }
.mk-utc { background: var(--text-primary); clip-path: polygon(50% 0, 100% 100%, 0 100%); border: 0; }
.mk-independent { border-radius: 2px; }
.mk-college { clip-path: polygon(25% 3%, 75% 3%, 100% 50%, 75% 97%, 25% 97%, 0 50%); background: var(--text-primary); border: 0; }

/* map markers */
.smk { width: 16px; height: 16px; }
.smk svg { display: block; overflow: visible; }

/* popups */
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface-1); color: var(--text-primary); }
.leaflet-popup-content { min-width: 270px; margin: 12px 14px; font-size: .88rem; line-height: 1.4; max-height: 60vh; overflow-y: auto; }
.pp h3 { margin: 0 0 2px; font-size: .98rem; }
.pp .k { color: var(--text-muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; margin-top: 10px; }
.pp table { border-collapse: collapse; width: 100%; margin-top: 4px; }
.pp td { padding: 2px 0; vertical-align: top; }
.pp td:first-child { color: var(--text-secondary); padding-right: 10px; width: 46%; }
.pp td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.pp a { color: var(--accent); }
.pp hr { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }
.qbar { display: flex; gap: 2px; height: 12px; margin: 6px 0 2px; }
.qbar span { display: block; height: 100%; }
.qbar span:first-child { border-radius: 4px 0 0 4px; }
.qbar span:last-child { border-radius: 0 4px 4px 0; }
.qlab { display: flex; justify-content: space-between; font-size: .72rem; color: var(--text-muted); }
.chip { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: .78rem; border: 1px solid var(--border); color: var(--text-secondary); }

/* dialogs */
.dlg { border: 1px solid var(--border); border-radius: 10px; background: var(--surface-1); color: var(--text-primary); padding: 0; width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
.dlg.wide { width: min(1040px, calc(100vw - 32px)); }
#compare-table td:first-child { min-width: 220px; }
.dlg::backdrop { background: rgba(0,0,0,.4); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 6px; position: sticky; top: 0; background: var(--surface-1); }
.dlg-head h2 { font-size: 1.05rem; margin: 0; }
.close { background: none; border: 0; font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--text-secondary); }
.dlg > .tiny, .prose { padding: 0 16px 16px; }
.prose { font-size: .92rem; line-height: 1.5; }
.prose h3 { font-size: .95rem; margin: 14px 0 4px; }
.prose a { color: var(--accent); }
.prose .src li { margin-bottom: 4px; }
.tbl-wrap { overflow-x: auto; padding: 0 16px 16px; }
#compare-table { border-collapse: collapse; width: 100%; font-size: .86rem; }
#compare-table th { text-align: left; font-weight: 600; color: var(--text-secondary); border-bottom: 1px solid var(--border); padding: 6px 8px; cursor: pointer; white-space: nowrap; position: sticky; top: 0; background: var(--surface-1); }
#compare-table th.num, #compare-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
#compare-table th[aria-sort]::after { content: " \2195"; color: var(--text-muted); }
#compare-table th[aria-sort="descending"]::after { content: " \2193"; }
#compare-table th[aria-sort="ascending"]::after { content: " \2191"; }
#compare-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
#compare-table tbody tr { cursor: pointer; }
#compare-table tbody tr:hover { background: var(--surface-0); }
.mini { display: flex; gap: 1px; width: 110px; height: 10px; }
.mini span { height: 100%; }

.leaflet-container { font: inherit; background: var(--surface-0); }
.leaflet-control-attribution { font-size: 10px; }

@media (max-width: 760px) {
  #app { flex-direction: column-reverse; }
  #panel { width: 100%; max-height: 52vh; border-right: 0; border-top: 1px solid var(--border); }
  #panel.collapsed { max-height: none; }
  #panel.collapsed .panel-body, #panel.collapsed .sub { display: none; }
  .panel-head { padding: 10px 16px 6px; }
  h1 { font-size: 1rem; padding-right: 110px; }
  .panel-toggle { display: block; position: absolute; right: 16px; top: 8px; padding: 5px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-0); color: var(--text-primary); font: inherit; font-size: .82rem; }
}

.subopts { margin: 2px 0 6px 26px; padding: 8px 10px; border-left: 2px solid var(--border); display: grid; gap: 6px; }
.subopts select { width: 100%; max-width: 100%; font: inherit; font-size: .88rem; padding: 5px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-0); color: var(--text-primary); }
label.chk { display: flex; gap: 8px; align-items: flex-start; font-size: .86rem; padding: 4px 0; cursor: pointer; }
label.chk input { margin-top: 3px; }
.btn-2 { background: transparent; color: var(--accent); margin-top: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.legend .dot { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--text-primary); flex: none; }
.chart-box { padding: 0 16px; position: relative; }
.chart-box svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-box .axis text, .chart-box .lab { fill: var(--text-secondary); font-size: 12px; }
.chart-box .grid { stroke: var(--border); stroke-width: 1; }
.chart-box .ref { stroke: var(--text-muted); stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart-box .pt { cursor: pointer; }
.chart-box .pt:hover, .chart-box .pt:focus { stroke-width: 3; outline: none; }
.chart-box .med { stroke: var(--text-primary); stroke-width: 2.5; }
.chart-ctl { margin: 0 0 4px; }
.chart-tip { position: fixed; z-index: 10000; pointer-events: none; background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: .82rem; line-height: 1.4; box-shadow: 0 4px 14px rgba(0,0,0,.15); max-width: 260px; }
table.plain { border-collapse: collapse; width: 100%; font-size: .84rem; }
table.plain th, table.plain td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--border); }
table.plain td.num, table.plain th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pp .band { display: inline-flex; align-items: center; gap: 6px; }
.pp .band i { width: 12px; height: 12px; border-radius: 50%; border: 1px solid #0b0b0b; display: inline-block; }
.pp ul.areas { margin: 4px 0 0; padding-left: 16px; }
