/* Light and dark both defined on tokens; nothing gets its only definition
   inside a media query, so a themed browser never renders unstyled. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #d9dee5;
  --text: #16191d;
  --muted: #5d6672;
  --accent: #1c5fa8;
  --accent-soft: #e6eefa;
  --good: #1a7f4b;
  --warn: #8a5a00;
  --warn-soft: #fdf3dc;
  --bad: #a3323b;
  --shadow: 0 1px 2px rgba(16, 20, 27, 0.08), 0 4px 12px rgba(16, 20, 27, 0.06);
  --radius: 10px;
}

/* The dark palette is defined TWICE, on purpose, because the theme has three states:
   an explicit choice stamps data-theme on <html>, and the default "system" setting
   stamps nothing, leaving only prefers-color-scheme to separate light from dark.
     - the media block guards on :not([data-theme="light"]) so choosing light wins
       over a dark OS;
     - the [data-theme="dark"] block makes choosing dark win over a light OS.
   Defining it in only one of the two would leave the toggle working in one direction. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151a;
    --surface: #1a1f26;
    --surface-2: #222933;
    --border: #2f3742;
    --text: #e8ecf1;
    --muted: #9aa5b3;
    --accent: #74a9e8;
    --accent-soft: #1d2c3f;
    --good: #5fc98d;
    --warn: #e0b25c;
    --warn-soft: #2b2413;
    --bad: #e88a92;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.25);
  }
}

:root[data-theme="dark"] {
  --bg: #12151a;
  --surface: #1a1f26;
  --surface-2: #222933;
  --border: #2f3742;
  --text: #e8ecf1;
  --muted: #9aa5b3;
  --accent: #74a9e8;
  --accent-soft: #1d2c3f;
  --good: #5fc98d;
  --warn: #e0b25c;
  --warn-soft: #2b2413;
  --bad: #e88a92;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.25);
}

/* Badge colours that were only defined inside the dark media query would be wrong
   under an explicit dark choice on a light OS, so they get the same treatment. */
:root[data-theme="dark"] .badge.charter { background: #2c2340; color: #c4a8ee; }
:root[data-theme="dark"] .badge.deadline { background: #16301f; color: var(--good); }

* { box-sizing: border-box; }

/* The `hidden` attribute is how this app shows and hides the gate, the tabs, the
   filter bar and the drawer. A class selector that sets `display` outranks the UA
   stylesheet's `[hidden] { display: none }`, so any flex container we hide would
   otherwise stay visible -- which is how the drawer ended up overlaying the page on
   first load. Making it !important means adding a display rule to something later
   can never silently un-hide it. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }

/* --- Gate ------------------------------------------------------------------ */
.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 36px 32px;
  max-width: 460px;
  text-align: center;
}

.gate-card h1 { margin: 0 0 8px; font-size: 24px; }
.gate-sub { color: var(--muted); margin: 0 0 24px; }

.primary {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 11px 20px;
  font-weight: 600;
}
.primary:hover { filter: brightness(1.08); }

.link {
  background: none;
  border: 0;
  color: var(--accent);
  padding: 4px;
  text-decoration: underline;
}

.theme-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  padding: 4px 11px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--text); }

.error { color: var(--bad); margin-top: 16px; }

/* --- Chrome ---------------------------------------------------------------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; flex-direction: column; }
.brand strong { font-size: 16px; }
.who { display: flex; align-items: center; gap: 10px; }
.muted { color: var(--muted); font-size: 13px; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 12px 20px 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  overflow-x: auto;
}

.tab {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 8px 14px;
  font-weight: 600;
  white-space: nowrap;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.pill {
  display: inline-block;
  margin-left: 6px;
  background: var(--warn);
  color: #fff;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 6px;
  vertical-align: 1px;
}

.change {
  border: 1px solid var(--border);
  border-left: 3px solid var(--warn);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.change h3 { margin: 0 0 4px; font-size: 14.5px; }
.change h3 a { color: var(--accent); }
.change .when { color: var(--muted); font-size: 12px; }
.change ul { margin: 6px 0 0; padding-left: 20px; font-size: 13.5px; }
.change code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* Category sub-tabs. Visually subordinate to the sector tabs above them -- pills
   rather than underlines -- so the hierarchy (sector, then grade band) reads at a
   glance instead of looking like two competing tab rows. */
.subtabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 14px 20px 0;
}

.subtab {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  padding: 5px 13px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.subtab:hover { border-color: var(--accent); color: var(--text); }
.subtab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.subtab .n {
  opacity: 0.7;
  font-weight: 500;
  margin-left: 5px;
}

.subtab-blurb {
  padding: 8px 20px 0;
  color: var(--muted);
  font-size: 13px;
}

.controls {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: end;
  padding: 16px 20px 4px;
}

.controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.controls .grow { flex: 1 1 220px; }
.controls .check {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  padding-bottom: 8px;
}

select, input[type="search"] {
  font: inherit;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  min-width: 130px;
}

.banner {
  margin: 12px 20px 0;
  padding: 10px 14px;
  background: var(--warn-soft);
  border: 1px solid var(--warn);
  border-radius: 8px;
  color: var(--warn);
  font-size: 13px;
}

.count { padding: 8px 20px 0; }

/* --- Groups and cards ------------------------------------------------------ */
#groups { padding: 8px 20px 48px; }

.group { margin-top: 24px; }
.group-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.group-head h2 { margin: 0; font-size: 17px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  text-align: left;
  width: 100%;
  color: inherit;
}
.card:hover { border-color: var(--accent); }

.rank {
  flex: 0 0 46px;
  text-align: center;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 8px;
  padding: 6px 0;
  font-weight: 700;
}
.rank small { display: block; font-weight: 500; font-size: 10px; opacity: 0.75; }
.rank.unranked { background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 600; }

.card-main { min-width: 0; flex: 1; }
.card-name { font-weight: 650; margin-bottom: 2px; }
.card-line { font-size: 12.5px; color: var(--muted); }
.card-stats { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; font-size: 12px; }
.card-stats span { background: var(--surface-2); border-radius: 5px; padding: 2px 7px; }

/* The GreatSchools chip, banded the way GreatSchools bands it. Deliberately styled
   unlike the rank block on the left: they are different claims from different sources
   and must not read as one number stated twice. */
.card-stats .gs { font-weight: 700; }
.gs-high { background: #e7f4ec !important; color: var(--good) !important; }
.gs-mid { background: var(--warn-soft) !important; color: var(--warn) !important; }
.gs-low { background: #fbeaec !important; color: var(--bad) !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .gs-high { background: #16301f !important; }
  :root:not([data-theme="light"]) .gs-low { background: #3a1f23 !important; }
}
:root[data-theme="dark"] .gs-high { background: #16301f !important; }
:root[data-theme="dark"] .gs-low { background: #3a1f23 !important; }

.badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.badge {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--muted);
}
.badge.magnet { background: var(--accent-soft); color: var(--accent); }
.badge.zip { background: #ece7fb; color: #5b3fa8; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge.zip { background: #2a2440; color: #bfa9f0; }
}
:root[data-theme="dark"] .badge.zip { background: #2a2440; color: #bfa9f0; }
.badge.charter { background: #efe6fa; color: #6b3fa0; }
.badge.closing { background: var(--warn-soft); color: var(--warn); }
.badge.deadline { background: #e7f4ec; color: var(--good); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge.charter { background: #2c2340; color: #c4a8ee; }
  :root:not([data-theme="light"]) .badge.deadline { background: #16301f; color: var(--good); }
}

/* --- Drawer ---------------------------------------------------------------- */
.drawer {
  position: fixed;
  inset: 0;
  background: rgba(10, 13, 18, 0.5);
  display: flex;
  justify-content: flex-end;
  z-index: 50;
}

.drawer-panel {
  background: var(--surface);
  width: min(560px, 100%);
  height: 100%;
  overflow-y: auto;
  padding: 24px 26px 60px;
  position: relative;
}

.drawer-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: 0;
  font-size: 26px;
  line-height: 1;
  color: var(--muted);
}

.drawer-panel h2 { margin: 0 8px 4px 0; font-size: 20px; padding-right: 30px; }

/* Without this the source links inherit the UA's dark blue, which is close to
   unreadable on the dark surface -- and the sources are the part of this panel a
   sceptical reader most needs to be able to follow. */
.drawer-panel a { color: var(--accent); }
.drawer-panel ul { padding-left: 20px; margin: 8px 0 0; }
.drawer-panel li { margin-bottom: 6px; font-size: 13px; }

.field-table { width: 100%; border-collapse: collapse; margin-top: 18px; }
.field-table th,
.field-table td {
  text-align: left;
  vertical-align: top;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.field-table th { width: 42%; color: var(--muted); font-weight: 600; }
.unknown { color: var(--muted); font-style: italic; }

.section-title {
  margin: 24px 0 0;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.bar {
  position: relative;
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  margin-top: 5px;
  overflow: hidden;
}
.bar i { position: absolute; inset: 0 auto 0 0; background: var(--accent); }

/* `.drawer-panel a` (0,1,1) outranks a bare `.apply` (0,1,0), so without the
   `.drawer-panel` prefix here this button renders accent-on-accent -- a blue label on a
   blue background, i.e. invisible. That is exactly what happened when the source-link
   colour rule was added. */
.drawer-panel a.apply,
.apply {
  display: inline-block;
  margin-top: 14px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
}

/* --- About ---------------------------------------------------------------- */
.about { padding: 16px 20px 60px; max-width: 820px; }
.about h2 { font-size: 17px; margin: 26px 0 8px; }
.about li { margin-bottom: 8px; }
.about a { color: var(--accent); }
.about code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

.coverage { width: 100%; border-collapse: collapse; margin-top: 8px; }
.coverage td, .coverage th { padding: 6px 8px; border-bottom: 1px solid var(--border); font-size: 13px; text-align: left; }
.coverage td:last-child { width: 130px; }
