:root {
  --ink: #1c2733;
  --ink-soft: #55636f;
  --paper: #f7f8f6;
  --panel: #ffffff;
  --line: #e2e6e3;
  --accent: #1f6f6b;      /* deep teal */
  --accent-soft: #e4f0ef;
  --gold: #b98a2e;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 16px/1.55 "Avenir Next", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
.wrap { max-width: 1380px; margin: 0 auto; padding: 0 20px; }

/* header */
.site-head { background: var(--panel); border-bottom: 3px solid var(--accent); }
.site-head .wrap { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; padding-top: 14px; padding-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 52px; height: 52px; border-radius: 10px;
  background: var(--accent); color: #fff;
  font-size: 24px; font-weight: 700; letter-spacing: 1px;
}
.site-head h1 { margin: 0; font-size: 22px; }
.tagline { margin: 2px 0 0; color: var(--ink-soft); font-size: 13.5px; }
.stamp { color: var(--accent); font-weight: 600; }
nav a {
  margin-left: 18px; text-decoration: none; color: var(--ink-soft);
  font-weight: 600; font-size: 14.5px; padding-bottom: 4px;
}
nav a.active, nav a:hover { color: var(--accent); border-bottom: 2px solid var(--gold); }

/* layout */
.layout { display: grid; grid-template-columns: 230px 1fr; gap: 22px; padding: 26px 0 12px; }


/* filters */
.filters { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 16px 8px; align-self: start; position: sticky; top: 12px; }
#filter-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; margin: 0 0 10px; padding: 0;
  background: none; border: 0; cursor: default; font: inherit;
  font-size: 15px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .8px; color: var(--accent);
}
#filter-toggle .chev { display: none; }
fieldset { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 12px 0; }
legend { font-weight: 700; font-size: 13.5px; padding-right: 8px; }
fieldset label { display: block; font-size: 14.5px; margin: 3px 0; cursor: pointer; }
fieldset input { accent-color: var(--accent); margin-right: 6px; }
select { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 14px; color: var(--ink); }
.years-row { display: flex; align-items: center; gap: 8px; }
.years-row select { width: auto; flex: 1; }
.hint { font-size: 12.5px; color: var(--gold); margin: 6px 0 0; }
label.disabled { color: #b6bec5; }

/* results */
.results { min-width: 0; }
.results-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.results-head h2 { margin: 0; font-size: 20px; }
.muted { color: var(--ink-soft); font-size: 13.5px; }
.table-scroll { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 7px 10px; text-align: left; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
thead th {
  background: var(--accent); color: #fff; font-size: 12.5px;
  text-transform: uppercase; letter-spacing: .6px; position: sticky; top: 0;
}
tbody tr:nth-child(even) { background: #fafbf9; }
tbody tr:hover { background: var(--accent-soft); }
td.rank { color: var(--ink-soft); width: 5.2em; white-space: nowrap; }
.mv { font-size: 11.5px; font-weight: 600; margin-left: 5px; letter-spacing: -.2px; }
.mv.up { color: #1f7a45; }
.mv.down { color: #a8452f; }
.mv.flat { color: #b6bec5; font-weight: 400; }
.mv.new {
  color: var(--gold); font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .3px;
}
.legend { font-size: 12.5px; color: var(--ink-soft); margin: 0 4px 10px; line-height: 1.5; }
.legend .mv { margin-left: 0; }
td.name { white-space: normal; max-width: 190px; line-height: 1.3; }
td.inst { white-space: normal; max-width: 260px; line-height: 1.3; font-size: 13px; color: var(--ink-soft); }
td.metric-lead { font-weight: 700; color: var(--accent); }
.region-chip {
  font-size: 11.5px; padding: 1px 8px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
}
.corrections { font-size: 13px; color: var(--ink-soft); margin: 10px 4px; }

/* prose sections */
.prose { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px 26px; margin: 26px 0; }
.prose h2 { margin-top: 0; color: var(--accent); }
.prose li { margin: 6px 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin: 16px 0; }
.card { border: 1px solid var(--line); border-left: 4px solid var(--gold); border-radius: 8px; padding: 12px 16px; background: #fcfdfc; }
.card h3 { margin: 0 0 6px; font-size: 15.5px; }
.card p { margin: 0; font-size: 14px; color: var(--ink-soft); }

footer { border-top: 1px solid var(--line); margin-top: 30px; }
footer p { color: var(--ink-soft); font-size: 13px; padding: 14px 0 0; }
footer p.copyright { padding: 6px 0 14px; font-size: 12.5px; }
a { color: var(--accent); }

/* back to top */
#f-search {
  width: 100%; padding: 8px 8px; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; font-size: 14px; color: var(--ink);
  background: #fff;
}
#f-search:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.no-match { padding: 16px 4px; color: var(--ink-soft); font-size: 14.5px; }
#show-results { display: none; }
#to-top {
  position: fixed; right: 22px; bottom: 22px;
  width: 44px; height: 44px; border-radius: 50%;
  border: 0; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
#to-top.show { opacity: 1; pointer-events: auto; }
#to-top:hover { background: #185a57; }

/* ---- narrow screens (must stay last) ---- */
@media (max-width: 820px) {
  .wrap { padding: 0 14px; }
  .layout { grid-template-columns: 1fr; gap: 16px; padding-top: 16px; }

  /* filters become a tappable, collapsible panel above the table */
  .filters#filters { position: static !important; top: auto; padding: 12px 14px; align-self: stretch; }
  #filter-toggle {
    cursor: pointer; margin: 0; padding: 4px 0;
    font-size: 16px; letter-spacing: .5px;
  }
  #filter-toggle .chev { display: inline; transition: transform .2s; }
  .filters.collapsed #filter-toggle .chev { transform: rotate(-90deg); }
  .filters.collapsed .filter-body { display: none; }
  .filters:not(.collapsed) .filter-body { padding-top: 6px; }

  /* two-up the short option lists so the open panel stays short */
  fieldset { padding: 10px 0; }
  fieldset label { display: inline-block; width: 48%; margin: 4px 0; font-size: 15px; }
  #f-region, #f-type, #f-top, .years-row select, #f-search { font-size: 16px; padding: 10px; }

  /* header */
  .site-head .wrap { flex-direction: column; align-items: flex-start; gap: 8px; }
  .site-head h1 { font-size: 18px; line-height: 1.25; }
  .tagline { font-size: 12.5px; }
  nav { display: flex; flex-wrap: wrap; gap: 4px 16px; }
  nav a { margin-left: 0; font-size: 14px; }

  /* table: keep it scrollable rather than squeezed */
  table { font-size: 13.5px; }
  th, td { padding: 7px 8px; }
  td.name { max-width: 150px; }
  td.inst { max-width: 170px; font-size: 12.5px; }
  .results-head h2 { font-size: 18px; }
  .prose { padding: 18px 16px; }
  #to-top { right: 14px; bottom: 14px; }

  /* explicit exit from the filter panel */
  #show-results {
    display: block; width: 100%; margin: 10px 0 4px; padding: 12px;
    background: var(--accent); color: #fff; border: 0; border-radius: 8px;
    font: inherit; font-size: 15.5px; font-weight: 600; cursor: pointer;
  }
  #show-results:active { background: #185a57; }
}
