:root {
  --bg: #0a0a0f;
  --bg-elevated: #111118;
  --bg-card: #16161e;
  --bg-hover: #1c1c26;
  --border: rgba(255, 255, 255, 0.06);
  --border-subtle: rgba(255, 255, 255, 0.04);
  --ink: #e8e8ed;
  --ink-secondary: #a0a0b0;
  --muted: #6b6b80;
  --accent: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.15);
  --accent-2: #8b5cf6;
  --accent-warm: #f97316;
  --accent-green: #22c55e;
  --accent-red: #ef4444;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.bg-veil {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 0% 0%, rgba(99, 102, 241, 0.08), transparent),
    radial-gradient(ellipse 50% 40% at 100% 0%, rgba(139, 92, 246, 0.06), transparent);
  z-index: -1;
  pointer-events: none;
}

/* ---- Hero ---- */
.hero {
  padding: 48px 5vw 24px;
  border-bottom: 1px solid var(--border);
}

.hero-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: grid;
  gap: 32px;
  grid-template-columns: 1fr auto;
  align-items: center;
}

.kicker {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  margin: 0 0 8px;
}

h1, h2, h3 {
  font-family: "Space Grotesk", -apple-system, sans-serif;
  margin: 0;
  letter-spacing: -0.02em;
}

h1 {
  font-size: clamp(24px, 3vw, 36px);
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

h2 {
  font-size: 17px;
  font-weight: 600;
  color: #fff;
}

.sub {
  max-width: 480px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  margin: 8px 0 0;
}

/* ---- Metric Cards (hero) ---- */
.hero-metrics {
  display: flex;
  gap: 12px;
}

.metric-card {
  background: var(--bg-card);
  padding: 16px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  min-width: 150px;
}

.metric-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 10px;
  color: var(--muted);
  margin: 0;
  font-weight: 500;
}

.metric-value {
  font-size: 28px;
  margin: 6px 0 0;
  font-weight: 700;
  font-family: "Space Grotesk", sans-serif;
  color: #fff;
}

.metric-note {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--muted);
  display: none;
}

/* ---- Main Content ---- */
.content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 5vw 48px;
  display: grid;
  gap: 20px;
}

.grid-2 {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
}

/* ---- Panel Cards ---- */
.panel {
  background: var(--bg-card);
  padding: 24px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.3), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}

.panel:hover::before {
  opacity: 1;
}

.panel-header {
  margin-bottom: 16px;
  position: relative;
}

.panel-header h2 {
  margin-bottom: 4px;
}

.panel-header p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.panel-header[data-help]::after {
  content: "?";
  position: absolute;
  top: 0;
  right: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  display: grid;
  place-items: center;
  cursor: help;
  transition: background 0.2s;
}

.panel-header[data-help]:hover::after {
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
}

/* ---- Toggles / Pill buttons ---- */
.toggle {
  display: inline-flex;
  gap: 2px;
  margin: 8px 0 16px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.toggle button {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: var(--radius-xs);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.toggle button:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.04);
}

.toggle button.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 4px rgba(99, 102, 241, 0.3);
}

/* ---- Search ---- */
.search {
  display: grid;
  gap: 12px;
}

.search-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.search-controls input {
  flex: 1;
  min-width: 220px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--ink);
  font-size: 14px;
  transition: border-color 0.15s;
}

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

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

.search-tabs {
  display: inline-flex;
  gap: 2px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.search-tabs button {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: var(--radius-xs);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.search-tabs button:hover {
  color: var(--ink);
}

.search-tabs button.active {
  background: var(--accent);
  color: #fff;
}

.search-results {
  display: grid;
  gap: 4px;
}

.search-card {
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid var(--border-subtle);
  transition: border-color 0.15s, background 0.15s;
}

.search-card:hover {
  border-color: var(--border);
  background: var(--bg-hover);
}

.search-card:not(.expandable) {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.search-card .meta {
  color: var(--muted);
  font-size: 12px;
}

.search-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.profile-toggle {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 0;
  opacity: 0.8;
}

.profile-toggle:hover {
  opacity: 1;
}

.profile-detail {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.profile-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.profile-stat {
  font-size: 12px;
  color: var(--ink-secondary);
}

.profile-badge {
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.04em;
}

.profile-prelims {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.profile-section {
  margin-top: 10px;
}

.profile-section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}

.profile-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.profile-table th {
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
}

.profile-table td {
  padding: 5px 6px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--ink-secondary);
}

.profile-judges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.profile-judge {
  background: rgba(255, 255, 255, 0.05);
  padding: 4px 8px;
  border-radius: var(--radius-xs);
  font-size: 12px;
  color: var(--ink-secondary);
}

/* ---- Judge Controls ---- */
.judge-controls {
  margin-bottom: 12px;
}

.judge-controls input {
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--ink);
  font-size: 13px;
  width: 240px;
  transition: border-color 0.15s;
}

.judge-controls input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.judge-controls input::placeholder {
  color: var(--muted);
}

/* ---- Power Year Controls ---- */
.power-year-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.power-year-controls .toggle {
  margin: 0;
}

.power-year-controls input {
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--ink);
  font-size: 13px;
  width: 180px;
  transition: border-color 0.15s;
}

.power-year-controls input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.power-year-controls input::placeholder {
  color: var(--muted);
}

/* ---- Map Stats ---- */
.map-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--ink-secondary);
  margin-bottom: 12px;
}

.map-stats span {
  background: rgba(255, 255, 255, 0.05);
  padding: 5px 10px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

/* ---- Charts ---- */
.chart {
  min-height: 220px;
}

.chart.compact {
  max-width: 640px;
}

.chart.map {
  min-height: 360px;
}

.chart.box {
  min-height: 260px;
}

/* ---- Totals Grid ---- */
.totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
}

.total-card {
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  border: 1px solid var(--border-subtle);
}

.total-card .label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 500;
}

.total-card .value {
  font-size: 22px;
  font-weight: 700;
  font-family: "Space Grotesk", sans-serif;
  color: #fff;
  margin-top: 4px;
}

/* ---- Data Tables ---- */
.table {
  overflow-x: auto;
}

.table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

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

.table th {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 500;
  border-bottom-color: var(--border);
}

.table td {
  color: var(--ink-secondary);
  font-variant-numeric: tabular-nums;
}

.table tbody tr:hover {
  background: var(--bg-hover);
}

/* ---- SVG / D3 Axes ---- */
.axis text {
  font-size: 11px;
  fill: var(--muted);
}

#chart-judge-f1 .axis text {
  fill: var(--ink-secondary);
}

.axis path,
.axis line {
  stroke: var(--border);
}

.bar {
  fill: var(--accent);
}

.bar.alt {
  fill: var(--accent-2);
}

.dot {
  fill: var(--accent-warm);
  opacity: 0.9;
}

.pct-line {
  stroke: var(--accent-green);
  stroke-width: 2;
  fill: none;
  opacity: 0.8;
}

.pct-dot {
  fill: var(--accent-green);
  stroke: var(--bg-card);
  stroke-width: 1.5;
}

.note {
  color: var(--muted);
  font-size: 13px;
}

/* ---- Tooltip ---- */
.tooltip {
  z-index: 10;
  max-width: 360px;
  line-height: 1.4;
  box-shadow: var(--shadow-lg);
}

/* ---- Footer ---- */
.footer {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 5vw 48px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--border-subtle);
}

/* ---- Responsive ---- */
@media (max-width: 960px) {
  .hero-inner {
    grid-template-columns: 1fr;
  }

  .hero-metrics {
    flex-wrap: wrap;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .hero {
    padding: 32px 5vw 20px;
  }

  .panel {
    padding: 16px;
    border-radius: var(--radius-sm);
  }

  .metric-card {
    min-width: 120px;
  }

  .metric-value {
    font-size: 22px;
  }
}
