/* Math Competition — Student search (GitHub Pages) */
:root {
  color-scheme: dark;
  --bg: #0f0f12;
  --surface: #18181c;
  --border: #2a2a30;
  --text: #e4e4e7;
  --text-muted: #a1a1aa;
  --accent: #7c9ce0;
  --accent-hover: #9ab4ed;
  --rank-high: #6ee7b7;
  --rank-mid: #fcd34d;
  --filter-band-competition: rgba(172, 198, 248, 0.15);
  --filter-band-competition-border: rgba(172, 198, 248, 0.34);
  --filter-band-demographics: rgba(160, 238, 210, 0.12);
  --filter-band-demographics-border: rgba(160, 238, 210, 0.24);
  --filter-band-search: rgba(255, 255, 255, 0.09);
  --filter-band-search-border: rgba(255, 255, 255, 0.14);
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --overlay-backdrop: rgba(0, 0, 0, 0.5);
  --btn-ghost-hover: rgba(255, 255, 255, 0.06);
  --nav-toggle-hover: rgba(124, 156, 224, 0.08);
  --focus-ring: rgba(124, 156, 224, 0.2);
  --search-clear-bg: rgba(255, 255, 255, 0.08);
  --search-clear-bg-hover: rgba(255, 255, 255, 0.12);
  --contest-info-bg: rgba(255, 255, 255, 0.03);
  --table-row-hover: rgba(255, 255, 255, 0.02);
  --csv-thead-bg: rgba(60, 90, 160, 0.85);
  --csv-row-hover: rgba(124, 156, 224, 0.08);
  --error-text: #f87171;
  --error-bg: rgba(248, 113, 113, 0.1);
  --on-accent: #0f0f12;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f4f7;
  --surface: #ffffff;
  --border: #e2e2e8;
  --text: #18181b;
  --text-muted: #71717a;
  --accent: #4a67c8;
  --accent-hover: #3a54a8;
  --rank-high: #059669;
  --rank-mid: #ca8a04;
  --filter-band-competition: rgba(74, 103, 200, 0.12);
  --filter-band-competition-border: rgba(74, 103, 200, 0.28);
  --filter-band-demographics: rgba(5, 150, 105, 0.1);
  --filter-band-demographics-border: rgba(5, 150, 105, 0.22);
  --filter-band-search: rgba(0, 0, 0, 0.04);
  --filter-band-search-border: rgba(0, 0, 0, 0.1);
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.1);
  --overlay-backdrop: rgba(15, 23, 42, 0.38);
  --btn-ghost-hover: rgba(0, 0, 0, 0.06);
  --nav-toggle-hover: rgba(74, 103, 200, 0.12);
  --focus-ring: rgba(74, 103, 200, 0.28);
  --search-clear-bg: rgba(0, 0, 0, 0.06);
  --search-clear-bg-hover: rgba(0, 0, 0, 0.1);
  --contest-info-bg: rgba(74, 103, 200, 0.07);
  --table-row-hover: rgba(0, 0, 0, 0.035);
  --csv-thead-bg: rgba(55, 75, 145, 0.92);
  --csv-row-hover: rgba(74, 103, 200, 0.1);
  --error-text: #dc2626;
  --error-bg: rgba(220, 38, 38, 0.09);
  --on-accent: #ffffff;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body.site-nav-open {
  overflow: hidden;
}

/* Header */
.header {
  position: relative;
  padding: 2rem 1.5rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

/* Room for theme toggle + menu (index only); symmetric so title stays viewport-centered */
.header:has(#site-nav-toggle) {
  padding-left: 7rem;
  padding-right: 7rem;
}

@media (max-width: 540px) {
  .header:has(#site-nav-toggle) {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }

  /* Drop below fixed theme + menu controls so centered title does not sit under them */
  .header:has(#site-nav-toggle) .header-brand {
    padding-top: 3rem;
  }
}

.header-brand {
  text-align: center;
}

.header:has(#site-nav-toggle) .header-brand {
  max-width: 72rem;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

.header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Light / dark theme (index header) */
.theme-toggle {
  position: absolute;
  top: 1.25rem;
  right: 4.25rem;
  z-index: 2;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent-hover);
  background: var(--nav-toggle-hover);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.theme-toggle-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.theme-toggle-icon svg {
  display: block;
}

/* Hamburger menu */
.site-nav-toggle {
  position: absolute;
  top: 1.25rem;
  right: 1rem;
  z-index: 2;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.site-nav-toggle:hover {
  border-color: var(--accent);
  background: var(--nav-toggle-hover);
}

.site-nav-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.site-nav-toggle-bars,
.site-nav-toggle-bars::before,
.site-nav-toggle-bars::after {
  display: block;
  width: 1.25rem;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
}

.site-nav-toggle-bars {
  position: relative;
}

.site-nav-toggle-bars::before,
.site-nav-toggle-bars::after {
  content: "";
  position: absolute;
  left: 0;
}

.site-nav-toggle-bars::before {
  top: -6px;
}

.site-nav-toggle-bars::after {
  top: 6px;
}

/* Slide-out site menu */
#site-nav-drawer[hidden] {
  display: none !important;
  pointer-events: none !important;
}

.site-nav-drawer {
  position: fixed;
  inset: 0;
  z-index: 1100;
}

.site-nav-drawer-backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay-backdrop);
}

.site-nav-drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(20rem, 92vw);
  max-width: 100%;
  overflow-y: auto;
  padding: 1rem 1.25rem 1.5rem;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.site-nav-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.site-nav-drawer-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
}

.site-nav-drawer-close {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.site-nav-drawer-close:hover {
  color: var(--text);
  background: var(--btn-ghost-hover);
}

.site-nav-subheading {
  margin: 1.25rem 0 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.site-nav-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.site-nav-list--articles {
  margin-top: 0;
}

.site-nav-list li {
  margin: 0;
  border-bottom: 1px solid var(--border);
}

.site-nav-list li:last-child {
  border-bottom: none;
}

.site-nav-item {
  display: block;
  width: 100%;
  padding: 0.65rem 0;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  color: var(--accent);
  text-decoration: none;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  line-height: 1.4;
}

.site-nav-item:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.site-nav-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.site-nav-item--button {
  font-weight: 500;
}

/* Contest list popover */
#contest-list-popover[hidden] {
  display: none !important;
  pointer-events: none !important;
}

.contest-list-popover {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.contest-list-popover-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: var(--overlay-backdrop);
}

.contest-list-popover-inner {
  position: relative;
  z-index: 1;
  max-width: 32rem;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.contest-list-popover-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 4px;
}

.contest-list-popover-close:hover {
  color: var(--text);
  background: var(--btn-ghost-hover);
}

.contest-list-popover-title {
  margin: 0 2rem 0.5rem 0;
  font-size: 1.125rem;
  font-weight: 600;
}

.contest-list {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
  font-size: 0.9rem;
  line-height: 1.7;
}

.contest-list-sep {
  color: var(--text-muted);
  margin: 0 0.25em;
}

.contest-list-link {
  color: var(--accent);
  text-decoration: none;
}

.contest-list-link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.contest-list-item {
  color: var(--text);
}

.contest-list-block {
  margin-bottom: 0.75rem;
}

.contest-list-block:last-child {
  margin-bottom: 0;
}

.contest-list-years {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-left: 0.25rem;
}

.contest-list-year-link {
  color: var(--accent);
  text-decoration: none;
}

.contest-list-year-link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* Contest filter (top students controls) */
.contest-filter-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.competition-year-filter-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.competition-year-filter-caption {
  white-space: nowrap;
}

.competition-year-filter-select {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  max-width: 8rem;
}

.contest-filter-trigger {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.contest-filter-summary {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.contest-filter-trigger:hover {
  border-color: var(--accent);
  color: var(--accent-hover);
}

#contest-filter-popover[hidden] {
  display: none !important;
  pointer-events: none !important;
}

.contest-filter-popover {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.contest-filter-popover-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: var(--overlay-backdrop);
}

.contest-filter-popover-inner {
  position: relative;
  z-index: 1;
  max-width: 30rem;
  width: 100%;
  max-height: 75vh;
  overflow-y: auto;
  padding: 1.25rem 1.5rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}

@media (min-width: 768px) {
  .contest-filter-popover-inner {
    max-width: 38rem;
  }
}

.contest-filter-popover-title {
  margin: 0 2rem 0.75rem 0;
  font-size: 1rem;
  font-weight: 600;
}

.contest-filter-popover-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 2;
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 4px;
}

.contest-filter-popover-close:hover {
  color: var(--text);
  background: var(--btn-ghost-hover);
}

.contest-filter-options {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

/* One first-level competition per row (no shared grid with neighbors). */
.contest-filter-first-level {
  margin: 0;
  width: 100%;
  box-sizing: border-box;
}

.contest-filter-first-level--single {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.5rem;
  background: var(--surface-elevated, var(--surface));
}

/* Bold short name (contest_name) + long title from description */
.contest-filter-first-level--single .contest-filter-option--single {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.contest-filter-first-level-label {
  min-width: 0;
}

.contest-filter-short-name {
  font-weight: 700;
  color: var(--text-muted);
}

.contest-filter-long-name {
  font-weight: 400;
  color: var(--text-muted);
  opacity: 0.92;
}

.contest-filter-group {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.5rem 0.5rem;
  background: var(--surface-elevated, var(--surface));
}

.contest-filter-group-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 1.75rem;
  min-width: 0;
}

.contest-filter-group-toggle {
  flex: 1;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.35rem;
  margin: 0;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.contest-filter-group-toggle:hover {
  color: var(--text);
  background: var(--btn-ghost-hover);
}

.contest-filter-group-chevron {
  display: inline-block;
  flex-shrink: 0;
  font-size: 0.65rem;
  line-height: 1;
  transition: transform 0.15s ease;
  color: var(--text-muted);
}

.contest-filter-group--collapsed .contest-filter-group-chevron {
  transform: rotate(-90deg);
}

.contest-filter-group-heading-text {
  flex: 1;
  min-width: 0;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contest-filter-group-heading-text .contest-filter-short-name {
  font-weight: 700;
}

/* Second-level groups: full title on its own row under the name + All row */
.contest-filter-group-long {
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.4;
  color: var(--text-muted);
  opacity: 0.92;
  padding: 0 0.35rem 0.35rem 1.5rem;
  margin: 0;
  min-width: 0;
  white-space: normal;
}

.contest-filter-group-all-label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}

.contest-filter-group--collapsed .contest-filter-group-leaves,
.contest-filter-group--collapsed .contest-filter-group-long {
  display: none;
}

.contest-filter-group-leaves {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
  gap: 0.35rem 0.75rem;
  padding: 0.35rem 0 0 0.35rem;
  margin-top: 0.35rem;
  border-left: 2px solid var(--border);
}

.contest-filter-option {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text);
}

.contest-filter-option--all {
  font-weight: 500;
}

/* MCP % explanation popover */
#mcp-pct-popover[hidden] {
  display: none !important;
  pointer-events: none !important;
}

.mcp-pct-popover {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.mcp-pct-popover-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: var(--overlay-backdrop);
}

.mcp-pct-popover-inner {
  position: relative;
  z-index: 1;
  max-width: 22rem;
  width: 100%;
  padding: 1.25rem 1.5rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}

.mcp-pct-popover-title {
  margin: 0 2rem 0.5rem 0;
  font-size: 1rem;
  font-weight: 600;
}

.mcp-pct-popover-body {
  margin: 0 0 0.75rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.mcp-pct-popover-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 4px;
}

.mcp-pct-popover-close:hover {
  color: var(--text);
  background: var(--btn-ghost-hover);
}

.mcp-pct-trigger {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
  padding: 0.1em 0.15em;
  margin: -0.1em -0.15em;
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  -webkit-tap-highlight-color: transparent;
}

.mcp-pct-trigger:hover {
  color: var(--accent);
}

/* CSV popover */
#csv-popover[hidden] {
  display: none !important;
  pointer-events: none !important;
}

.csv-popover {
  position: fixed;
  inset: 0;
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.csv-popover-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: var(--overlay-backdrop);
}

.csv-popover-inner {
  position: relative;
  z-index: 1;
  max-width: 56rem;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.csv-popover-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 4px;
}

.csv-popover-close:hover {
  color: var(--text);
  background: var(--btn-ghost-hover);
}

.csv-popover-title {
  margin: 0 2rem 0.5rem 0;
  font-size: 1.125rem;
  font-weight: 600;
}

.csv-popover-loading {
  padding: 2rem;
  color: var(--text-muted);
  text-align: center;
}

.csv-popover-error {
  padding: 1rem;
  color: var(--error-text);
  background: var(--error-bg);
  border-radius: var(--radius);
}

.csv-popover-table-wrap {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.csv-popover-table-scroll {
  overflow: auto;
  max-height: 70vh;
}

.csv-popover-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.csv-popover-table th,
.csv-popover-table td {
  padding: 0.4rem 0.6rem;
  text-align: left;
  border: 1px solid var(--border);
}

.csv-popover-table th {
  background: var(--csv-thead-bg);
  font-weight: 600;
  position: sticky;
  top: 0;
  color: #f4f4f8;
  border-bottom: 2px solid var(--border);
}

.csv-popover-table tr:hover td {
  background: var(--csv-row-hover);
}

.csv-popover-table .num {
  text-align: right;
}

.csv-popover-open-tab {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--accent);
  text-decoration: none;
}

.csv-popover-open-tab:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.csv-row-year-link {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
}

.csv-row-year-link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* Main */
.main {
  max-width: 72rem;
  margin: 0 auto;
  padding: 1.5rem;
}

.search-wrap {
  margin-bottom: 0.75rem;
}

.search-performance-trigger-wrap {
  margin-bottom: 0.5rem;
  text-align: center;
}

#search-performance-trigger-wrap[hidden] {
  display: none !important;
}

.performance-by-year-btn,
.mcp-timeline-add-action-btn,
.chart-png-download {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.chart-png-download--compact {
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.35rem 0.65rem;
}

.chart-png-download--icon {
  padding: 0.45rem 0.55rem;
  min-width: auto;
}

.chart-png-download__svg {
  display: block;
  pointer-events: none;
  flex-shrink: 0;
}

:root[data-theme="light"] .performance-by-year-btn,
:root[data-theme="light"] .mcp-timeline-add-action-btn,
:root[data-theme="light"] .chart-png-download {
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.performance-by-year-btn:hover,
.mcp-timeline-add-action-btn:hover:not(:disabled),
.chart-png-download:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-hover);
  background: var(--nav-toggle-hover);
}

.performance-by-year-btn:focus-visible,
.mcp-timeline-add-action-btn:focus-visible,
.chart-png-download:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.mcp-timeline-add-action-btn {
  font-weight: 400;
}

.mcp-timeline-add-action-btn:disabled,
.chart-png-download:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.mcp-timeline-chart-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

/* [hidden] must win over .chart-png-download’s display: inline-flex */
.mcp-timeline-chart-toolbar[hidden],
.chart-png-download[hidden] {
  display: none !important;
}

/* Competition ranking (crank.html): tab pair matches Performance by year control */
.ranking-toggle {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin: 1.5rem 0 2rem;
}

.ranking-toggle .performance-by-year-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--filter-band-competition);
}

.ranking-toggle .performance-by-year-btn.active:hover {
  color: var(--accent-hover);
  border-color: var(--accent-hover);
  background: var(--nav-toggle-hover);
}

.student-card-back {
  display: inline-block;
  font-size: 0.95rem;
  color: var(--accent);
  text-decoration: none;
  margin-bottom: 0.5rem;
}

.student-card-back[hidden] {
  display: none;
}

.student-card-back:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.search-input-wrap {
  position: relative;
  display: block;
}

.search-input-wrap[hidden] {
  display: none;
}

.search-input {
  width: 100%;
  padding: 0.75rem 3rem 0.75rem 1rem;
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.search-clear {
  position: absolute;
  top: 50%;
  right: 0.5rem;
  transform: translateY(-50%);
  width: 2rem;
  height: 2rem;
  min-width: 2rem;
  min-height: 2rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--search-clear-bg);
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 400;
  line-height: 1;
}

.search-clear:hover {
  color: var(--text);
  background: var(--search-clear-bg-hover);
}

.search-clear[hidden] {
  display: none;
}

.search-hint {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.search-hint[hidden] {
  display: none;
}

.search-apply-filters-wrap {
  margin-top: 0.5rem;
  padding: 0.45rem 0.75rem;
  background: var(--filter-band-search);
  border: 1px solid var(--filter-band-search-border);
  border-radius: var(--radius);
}

.search-apply-filters-wrap[hidden] {
  display: none !important;
}

/* competition filters: row 1 = competition, row 2 = girls / grade / state */
.awards-ranking-filters {
  margin-bottom: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.awards-ranking-filters > .awards-ranking-controls {
  margin: 0;
}

.awards-ranking-filters .leaderboard-filters-row--competition {
  display: flex;
  align-items: center;
  background: var(--filter-band-competition);
  border: 1px solid var(--filter-band-competition-border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
}

.awards-ranking-filters .leaderboard-filters-row--demographics {
  background: var(--filter-band-demographics);
  border: 1px solid var(--filter-band-demographics-border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
}

/* Per-student header actions (MCP breakdown uses .mcp-breakdown-btn; export + performance match below) */
.export-pdf-student-btn,
.student-card-performance-btn {
  display: inline-block;
  padding: 0.4rem 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  background: transparent;
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.export-pdf-student-btn:hover:not(:disabled),
.student-card-performance-btn:hover {
  background: var(--accent);
  color: var(--on-accent);
}

.export-pdf-student-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.mcp-breakdown-wrap {
  position: relative;
}

.mcp-breakdown-btn {
  display: inline-block;
  padding: 0.4rem 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  background: transparent;
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.mcp-breakdown-btn:hover {
  background: var(--accent);
  color: var(--on-accent);
}

.mcp-breakdown-popover {
  position: fixed;
  inset: 0;
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.mcp-breakdown-popover:not([hidden]) {
  display: flex;
}

.mcp-breakdown-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay-backdrop);
}

.mcp-breakdown-popover-inner {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  max-width: 560px;
  width: 92vw;
  max-height: 85vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.mcp-breakdown-title {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
}

.mcp-breakdown-canvas {
  display: block;
  margin: 0 auto;
}

.mcp-breakdown-download-png {
  margin-top: 0.75rem;
}

.mcp-breakdown-legend {
  margin-top: 1rem;
  width: 100%;
}

.mcp-breakdown-close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

/* Results */
.results {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Awards ranking */
.awards-ranking {
  margin-bottom: 2rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.awards-ranking-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

/* Three separate distribution links (each opens its own dialog; not one combined popup). */
.awards-ranking-dist-links {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.15rem 0.35rem;
  margin-left: 0.4rem;
  vertical-align: baseline;
}

.awards-ranking-dist-links .state-dist-trigger {
  margin-left: 0;
}

.awards-ranking-dist-sep {
  color: var(--text-muted);
  font-weight: 400;
  user-select: none;
}

.awards-ranking-subtitle {
  margin: 0.35rem 0 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.awards-ranking-subtitle a {
  color: var(--accent);
  text-decoration: none;
}

.awards-ranking-subtitle a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

#awards-ranking-filters[hidden] {
  display: none !important;
}

.awards-ranking-controls {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1rem;
}

/* Sort toggle (# Records / MCP / MCP %) */
.sort-toggle-wrap {
  display: inline-flex;
  align-items: center;
}

.sort-toggle {
  display: inline-flex;
  padding: 2px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  gap: 0;
}

.sort-toggle-option {
  padding: 0.25rem 0.65rem;
  border-radius: calc(var(--radius) - 2px);
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.sort-toggle-option--active {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

/* MCP % sort direction (below filters, visible when MCP % mode) */
.mcp-pct-sort-row {
  margin: 0.5rem 0 0.75rem;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mcp-pct-sort-text {
  color: var(--text-muted);
}

.mcp-pct-sort-row[hidden] {
  display: none !important;
}

.mcp-pct-filter-link {
  color: var(--accent);
  text-decoration: none;
}

.mcp-pct-filter-link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.mcp-pct-sort-btn {
  padding: 0.25rem 0.65rem;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.mcp-pct-sort-btn:hover {
  background: var(--border);
  color: var(--text);
}

.awards-ranking-controls .girls-only-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}

.search-apply-filters-wrap .search-apply-filters-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.awards-ranking-controls .girls-only-label input[type="checkbox"],
.search-apply-filters-wrap .search-apply-filters-label input[type="checkbox"],
/* Scope to container so header "All" (.contest-filter-group-all-label) matches nested options */
.contest-filter-options input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 1rem;
  height: 1rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: inline-block;
  position: relative;
  cursor: pointer;
  margin: 0;
  flex-shrink: 0;
  box-sizing: border-box;
  vertical-align: middle;
}

.awards-ranking-controls .girls-only-label input[type="checkbox"]:focus-visible,
.search-apply-filters-wrap .search-apply-filters-label input[type="checkbox"]:focus-visible,
.contest-filter-options input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.awards-ranking-controls .girls-only-label input[type="checkbox"]:checked,
.search-apply-filters-wrap .search-apply-filters-label input[type="checkbox"]:checked,
.contest-filter-options input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.awards-ranking-controls .girls-only-label input[type="checkbox"]:checked::after,
.search-apply-filters-wrap .search-apply-filters-label input[type="checkbox"]:checked::after,
.contest-filter-options input[type="checkbox"]:checked::after {
  content: "✓";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -55%);
  font-size: 0.75rem;
  color: var(--on-accent);
}

.awards-ranking-controls .grade-filter-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.awards-ranking-controls .grade-filter-caption {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.awards-ranking-controls .grade-filter-select {
  font: inherit;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.awards-ranking-controls .state-filter-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.awards-ranking-controls .state-filter-caption {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.awards-ranking-controls .state-filter-select {
  font: inherit;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.awards-ranking-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.awards-ranking-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.9rem;
}

.awards-ranking-position {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  min-width: 2.5rem;
}

.awards-ranking-name {
  flex: 1;
}

.awards-ranking-count {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.awards-ranking-grade {
  font-size: 0.8em;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 0.35em;
}

.awards-ranking-empty {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Skeleton placeholders to prevent CLS while data loads */
.awards-ranking-item--skeleton .awards-ranking-name,
.awards-ranking-item--skeleton .awards-ranking-count {
  color: var(--text-muted);
  opacity: 0.6;
}

.student-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.student-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1rem;
}

.student-header-actions {
  margin-left: auto;
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
}

.student-name {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  cursor: pointer;
}

.awards-ranking-name {
  cursor: pointer;
}

.student-stats {
  display: flex;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.student-stat {
  background: var(--border);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  white-space: nowrap;
}

.student-aliases {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.student-contests {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.contest-section {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.student-contests .contest-section:first-child {
  border-top: none;
  padding-top: 0;
}

.contest-info {
  margin-bottom: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--contest-info-bg);
  border-radius: 6px;
  border-left: 3px solid var(--accent);
}

.contest-info-title {
  margin: 0 0 0.35em;
  font-size: 1rem;
  font-weight: 600;
}

.contest-info-description {
  margin: 0 0 0.5em;
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.contest-info-website {
  display: inline-block;
  font-size: 0.875rem;
  color: var(--accent);
  text-decoration: none;
}

.contest-info-website:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.records-table-wrap {
  overflow-x: auto;
}

.records-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.records-table th,
.records-table td {
  padding: 0.6rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.records-table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.records-table th.has-tooltip {
  cursor: help;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

.col-tooltip {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 100;
  margin-top: 4px;
  padding: 0.5rem 0.75rem;
  min-width: 200px;
  max-width: 300px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.8rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  line-height: 1.45;
  white-space: normal;
}

.records-table tr:last-child td {
  border-bottom: none;
}

.records-table tr:hover td {
  background: var(--table-row-hover);
}

.records-table .num {
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}

.records-table .rank-1 { color: var(--rank-high); }
.records-table .rank-2,
.records-table .rank-3 { color: var(--rank-mid); }

/* Empty / loading */
.empty-state,
.loading {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
}

.loading[aria-busy="false"] {
  display: none;
}

/* Footer */
.footer {
  margin-top: 3rem;
  padding: 1.5rem;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.footer .disclaimer {
  color: var(--text-muted);
  font-size: 0.85em;
  max-width: 42rem;
  margin-left: auto;
  margin-right: auto;
}

.footer code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 0.15em 0.4em;
  background: var(--surface);
  border-radius: 4px;
}

/* Back link (report page, competition ranking, etc.) */
.back-link {
  display: block;
  text-align: left;
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--accent);
  text-decoration: none;
}

.header--crank > .back-link {
  margin-top: 0;
  margin-bottom: 0.75rem;
}

.back-link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.report-form-section,
.report-stats-section {
  margin-bottom: 2rem;
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.report-section-title {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.report-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-label .required {
  color: var(--error-text);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.6rem 0.85rem;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.form-textarea {
  resize: vertical;
  min-height: 5rem;
}

.report-submit-btn {
  align-self: flex-start;
  padding: 0.6rem 1.5rem;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--on-accent);
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

.report-submit-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.report-submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.report-status {
  font-size: 0.875rem;
  min-height: 1.25em;
  margin: 0;
}

.report-status--success {
  color: var(--rank-high);
}

.report-status--error {
  color: var(--error-text);
}

.report-stats-subtitle {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.report-stats-table tbody tr:hover td {
  background: var(--table-row-hover);
}

/* State distribution popover */
.state-dist-trigger {
  display: inline;
  padding: 0;
  margin-left: 0.4rem;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  vertical-align: baseline;
}

.state-dist-trigger:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* Must win over .state-dist-popover { display: flex } so [hidden] works for every distribution dialog. */
.state-dist-popover[hidden] {
  display: none !important;
  pointer-events: none !important;
}

.state-dist-popover {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.state-dist-popover-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: var(--overlay-backdrop);
}

.state-dist-popover-inner {
  position: relative;
  z-index: 1;
  max-width: 64rem;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.state-dist-popover-title {
  margin: 0 2rem 0.5rem 0;
  font-size: 1.125rem;
  font-weight: 600;
}

.state-dist-popover-hint {
  margin: 0 2rem 0.75rem 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.state-dist-popover-toolbar {
  margin: 0 2rem 1rem 0;
}

#state-dist-download-all-png {
  display: inline-flex;
  align-items: center;
}

.state-dist-popover-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 4px;
}

.state-dist-popover-close:hover {
  color: var(--text);
  background: var(--btn-ghost-hover);
}

.state-dist-charts {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 2rem;
}

.state-dist-chart-wrap {
  text-align: center;
}

.state-dist-chart-title {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
}

.state-dist-chart-wrap canvas {
  display: block;
  margin: 0 auto 1rem;
}

.state-dist-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1rem;
  justify-content: center;
  font-size: 0.8rem;
}

.state-dist-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.state-dist-legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.state-dist-legend-label {
  color: var(--text);
}

.state-dist-legend-value {
  color: var(--text-muted);
}

.state-dist-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.state-dist-map-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.state-dist-map-note {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.state-dist-us-map-wrap {
  position: relative;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  overflow: hidden;
}

.state-dist-us-map-container {
  min-height: 200px;
}

.state-dist-us-map-container svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 360px;
}

.state-dist-us-map-state {
  stroke: var(--border);
  stroke-width: 0.5;
  cursor: pointer;
  transition: opacity 0.15s;
}

.state-dist-us-map-state:hover {
  opacity: 0.88;
}

.state-dist-us-map-state-label {
  font-size: 9px;
  font-weight: 600;
  fill: var(--text);
  stroke: var(--bg);
  stroke-width: 2px;
  paint-order: stroke fill;
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: central;
}

.state-dist-us-map-tooltip {
  position: fixed;
  z-index: 10001;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--text);
  pointer-events: none;
  box-shadow: var(--shadow);
}

/* Click/tap: show scrollable student list (stays open when pointer leaves the state) */
.state-dist-us-map-tooltip.state-dist-us-map-tooltip--names {
  pointer-events: auto;
  max-width: min(340px, calc(100vw - 16px));
  max-height: min(320px, 55vh);
  overflow-y: auto;
  padding: 0.65rem 0.85rem;
  text-align: left;
}

.state-dist-us-map-tooltip-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.state-dist-us-map-tooltip-head-row .state-dist-us-map-tooltip-empty {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding-right: 0;
}

.state-dist-us-map-tooltip-close {
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  margin: 0;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
}

.state-dist-us-map-tooltip-close:hover {
  color: var(--text);
  background: var(--btn-ghost-hover);
  border-color: var(--border);
}

.state-dist-us-map-tooltip-head {
  margin: 0 0 0.4rem;
  padding-right: 2rem;
  font-size: 0.9rem;
}

.state-dist-us-map-tooltip-namelist {
  margin: 0;
  padding-left: 1.15rem;
  line-height: 1.45;
}

.state-dist-us-map-tooltip-empty {
  margin: 0;
  max-width: 280px;
}

.state-dist-us-map-names-count {
  font-weight: 500;
  color: var(--text-muted);
}

.map-gradient-legend {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  max-width: 220px;
}

.map-gradient-bar-wrap {
  margin-bottom: 0.25rem;
}

.map-gradient-bar {
  display: block;
  border-radius: 4px;
  overflow: hidden;
  width: 100%;
}

.map-gradient-labels {
  display: flex;
  justify-content: space-between;
}

@media (max-width: 899px) {
  .state-dist-charts {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 639px) {
  .state-dist-charts {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 640px) {
  .header h1 {
    font-size: 2rem;
  }

  .records-table th,
  .records-table td {
    padding: 0.75rem 1.25rem;
  }
}

/* MCP cumulative timeline (index line chart) */
#mcp-timeline-popover[hidden] {
  display: none !important;
  pointer-events: none !important;
}

.mcp-timeline-popover {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.mcp-timeline-popover-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: var(--overlay-backdrop);
}

.mcp-timeline-popover-inner {
  position: relative;
  z-index: 1;
  max-width: 52rem;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
  padding-top: 2.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  /* Keep description and controls at a stable size after rotate (esp. iOS Safari). */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.mcp-timeline-popover-title {
  margin: 0 2rem 0.5rem 0;
  font-size: 1.125rem;
  font-weight: 600;
}

.mcp-timeline-desc {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.mcp-timeline-options {
  margin: 0 0 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
}

.mcp-timeline-filters-heading {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 0.5rem;
}

.mcp-timeline-filter-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem 1rem;
  flex-wrap: wrap;
}

.mcp-timeline-filter-row .mcp-timeline-filter-label {
  flex: 1 1 11rem;
  min-width: 0;
}

.mcp-timeline-contest-summary {
  flex: 0 1 auto;
  max-width: 100%;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.35;
  text-align: right;
  white-space: normal;
}

.mcp-timeline-filter-hint {
  margin: 0.45rem 0 0;
  padding-left: 1.45rem;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.mcp-timeline-filter-label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.mcp-timeline-filter-label input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.mcp-timeline-add-wrap {
  position: relative;
  margin-bottom: 0.75rem;
}

.mcp-timeline-popover-inner .mcp-timeline-demographics-row {
  background: var(--filter-band-demographics);
  border: 1px solid var(--filter-band-demographics-border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  margin-top: 0.75rem;
}

.mcp-timeline-add-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem 0.75rem;
  margin-bottom: 0.35rem;
}

.mcp-timeline-search-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0;
}

.mcp-timeline-add-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.mcp-timeline-student-search {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.mcp-timeline-student-search:focus {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

.mcp-timeline-search-results {
  list-style: none;
  margin: 0.25rem 0 0;
  padding: 0;
  max-height: 11rem;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.mcp-timeline-search-results[hidden] {
  display: none !important;
}

.mcp-timeline-search-results li button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  color: var(--text);
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.mcp-timeline-search-results li:last-child button {
  border-bottom: none;
}

.mcp-timeline-search-empty {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.mcp-timeline-search-results li button:hover {
  background: var(--table-row-hover);
}

.mcp-timeline-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
  min-height: 0;
}

.mcp-timeline-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.5rem 0.25rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
  background: var(--filter-band-competition);
  border: 1px solid var(--filter-band-competition-border);
  border-radius: 999px;
}

.mcp-timeline-chip-remove {
  padding: 0 0.2rem;
  font-size: 1rem;
  line-height: 1;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 4px;
}

.mcp-timeline-chip-remove:hover {
  color: var(--text);
  background: var(--btn-ghost-hover);
}

.mcp-timeline-chart-wrap {
  position: relative;
  width: 100%;
  height: min(360px, 50vh);
  min-height: 240px;
}

.mcp-timeline-chart-wrap canvas {
  display: block;
  max-width: 100%;
}

.mcp-timeline-empty {
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.mcp-timeline-disclaimer {
  margin: 1rem 0 0;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.mcp-timeline-disclaimer a {
  color: var(--accent);
  text-decoration: none;
}

.mcp-timeline-disclaimer a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.mcp-timeline-popover-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 4px;
}

.mcp-timeline-popover-close:hover {
  color: var(--text);
  background: var(--btn-ghost-hover);
}
