:root {
  color-scheme: light;
  --page-bg: #f6f7fb;
  --page-gradient: radial-gradient(circle at top right, rgba(88, 166, 255, 0.12), transparent 45%),
    radial-gradient(circle at 20% 80%, rgba(255, 201, 134, 0.15), transparent 45%);
  --panel: rgba(255, 255, 255, 0.9);
  --panel-solid: #ffffff;
  --surface: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(238, 243, 255, 0.9));
  --surface-hover: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(231, 239, 255, 0.95));
  --card-border: rgba(15, 23, 42, 0.2);
  --card-shadow: 0 3px 12px rgba(15, 23, 42, 0.12);
  --text: #101530;
  --text-muted: rgba(16, 21, 48, 0.65);
  --accent: #0b7bff;
  --accent-strong: #0b7bff;
  --chart-dark: #0b5c99;
  --chart-mid: #4eb1ff;
  --chart-light: #d7ebff;
  --border-radius: 1.25rem;
  --row-height: 56px;
  font-family: 'Inter', 'SF Pro Display', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --page-bg: #04060a;
  --page-gradient: radial-gradient(circle at top, #1a274a 0%, rgba(4, 6, 10, 0) 40%),
    radial-gradient(circle at 20% 80%, rgba(94, 246, 255, 0.08), transparent 45%);
  --panel: rgba(11, 16, 27, 0.94);
  --panel-solid: #0b101b;
  --surface: linear-gradient(135deg, rgba(25, 38, 80, 0.7), rgba(12, 20, 35, 0.7));
  --surface-hover: linear-gradient(135deg, rgba(58, 86, 173, 0.9), rgba(25, 38, 80, 0.9));
  --card-border: rgba(255, 255, 255, 0.2);
  --card-shadow: 0 4px 16px rgba(7, 14, 30, 0.4);
  --text: #f2f5ff;
  --text-muted: rgba(242, 245, 255, 0.65);
  --accent: #5ef6ff;
  --accent-strong: #67b8ff;
  --chart-dark: #67b8ff;
  --chart-mid: #9fd8ff;
  --chart-light: rgba(111, 189, 255, 0.25);
}
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page-gradient), var(--page-bg);
  color: var(--text);
  font-family: inherit;
  transition: background 250ms ease, color 250ms ease;
}

.app-shell {
  padding: clamp(1.5rem, 3vw, 3rem);
  width: min(1400px, 100%);
  margin: 0 auto;
}

.app-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
  position: relative;
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.brand-logo {
  width: clamp(48px, 8vw, 72px);
  height: clamp(48px, 8vw, 72px);
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(5, 9, 18, 0.2));
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.24em;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin: 0 0 0.35rem;
}

.app-bar h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 2.8rem);
}

.brand-meta {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.theme-toggle {
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.25rem 0;
  justify-self: end;
  position: relative;
}

.toggle-track {
  width: 60px;
  height: 30px;
  border-radius: 999px;
  background: linear-gradient(135deg, #fcd35e, #f6a81a);
  padding: 3px;
  display: inline-flex;
  align-items: center;
  transition: background 200ms ease;
}

.toggle-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transform: translateX(0);
  transition: transform 200ms ease;
}

.toggle-icon {
  font-size: 0.9rem;
}

.theme-toggle[data-mode='dark'] .toggle-track {
  background: linear-gradient(135deg, #4f6bff, #272f92);
}

.theme-toggle[data-mode='dark'] .toggle-thumb {
  transform: translateX(28px);
}

.view-root {
  min-height: 70vh;
}

.view-root.home-view {
  background: var(--page-gradient), var(--page-bg);
  border-radius: 2rem;
  padding: clamp(1rem, 3vw, 2rem);
}

.hero {
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
  padding: clamp(1.25rem, 4vw, 2.5rem);
  box-shadow: var(--card-shadow);
  margin-bottom: 2rem;
  position: relative;
  overflow: hidden;
}

.hero::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 80% 20%, rgba(94, 246, 255, 0.12), transparent 50%);
  pointer-events: none;
}

.hero h2 {
  margin: 0 0 0.6rem;
  font-size: clamp(1.7rem, 4vw, 2.4rem);
}

.hero p {
  margin: 0;
  color: var(--text-muted);
  max-width: 60ch;
  line-height: 1.6;
}

.race-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
}

.race-card {
  background: var(--panel);
  border-radius: var(--border-radius);
  padding: 1.25rem;
  border: 1px solid var(--card-border);
  backdrop-filter: blur(12px);
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 220ms ease, border-color 220ms ease, background 220ms ease;
}

.race-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top right, rgba(94, 246, 255, 0.15), transparent 45%);
  opacity: 0;
  transition: opacity 220ms ease;
}

.race-card:hover {
  transform: translateY(-6px);
  border-color: rgba(94, 246, 255, 0.5);
}

.race-card:hover::after {
  opacity: 1;
}

.race-card h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-muted);
}

.race-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.race-title {
  font-size: 1.25rem;
  color: var(--text);
  font-weight: 600;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  background: rgba(94, 246, 255, 0.1);
  color: var(--accent);
}

.race-view {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  width: 100%;
}

.race-view > .back-link {
  align-self: flex-start;
}

.race-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.race-header h2 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2.3rem);
}

.race-meta-line {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.back-link {
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: border-color 200ms ease;
}

.back-link:hover {
  border-color: rgba(255, 255, 255, 0.3);
}

.controls-panel {
  background: var(--panel);
  border-radius: var(--border-radius);
  border: 1px solid var(--card-border);
  padding: 0;
}

.controls-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border: none;
  background: transparent;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  width: 100%;
  text-align: left;
}

.controls-panel-body {
  padding: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.results-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.filter-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(11, 123, 255, 0.15);
  font-size: 0.85rem;
  transition: transform 200ms ease;
}

.controls-panel.collapsed .controls-panel-body {
  display: none;
}

.controls-panel.collapsed .filter-toggle-icon {
  transform: rotate(180deg);
}
.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.control-group label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.column-filter {
  display: flex;
  gap: 0.5rem;
}

.column-filter select {
  flex: 1 1 45%;
}

.column-filter input {
  flex: 2 1 55%;
}

.control-group input,
.control-group select {
  border: 1px solid rgba(15, 23, 42, 0.2);
  border-radius: 0.9rem;
  padding: 0.55rem 0.85rem;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  font: inherit;
  width: 100%;
}

.clear-btn {
  border: none;
  border-radius: 0.9rem;
  padding: 0.55rem 0.85rem;
  background: rgba(15, 23, 42, 0.08);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: background 200ms ease;
}

.clear-btn:hover {
  background: rgba(11, 123, 255, 0.12);
}

:root[data-theme='dark'] .control-group input,
:root[data-theme='dark'] .control-group select {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(4, 4, 10, 0.35);
  color: var(--text);
}

:root[data-theme='dark'] .clear-btn {
  background: rgba(255, 255, 255, 0.08);
}

:root[data-theme='dark'] .clear-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

 .table-shell {
   background: var(--panel);
   border-radius: var(--border-radius);
   border: 1px solid var(--card-border);
   padding: 0;
   overflow: hidden;
 }
 
 .table-body-wrapper {
   overflow: auto;
   width: 100%;
   max-height: min(70vh, 620px);
   -webkit-overflow-scrolling: touch;
 }
 
 .data-table {
   width: 100%;
   border-collapse: separate;
   border-spacing: 0;
   min-width: 720px;
 }
 
 .data-table th,
 .data-table td {
   padding: 0.75rem 0.9rem;
   border-bottom: 1px solid var(--card-border);
   border-right: 1px solid var(--card-border);
   white-space: nowrap;
   text-overflow: ellipsis;
   overflow: hidden;
 }
 
.data-table th {
  position: sticky;
  top: 0;
  background: var(--panel-solid);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  z-index: 1;
  text-align: left;
}
 
 .data-table th:last-child,
 .data-table td:last-child {
   border-right: none;
 }
 
 .data-table tbody tr {
   background: rgba(255, 255, 255, 0.9);
 }
 
 .data-table tbody tr:nth-child(odd) {
   background: rgba(255, 255, 255, 0.8);
 }
 
.data-table tbody tr.is-selected-row {
  background: rgba(11, 123, 255, 0.15);
}

 :root[data-theme='dark'] .data-table tbody tr {
   background: rgba(7, 12, 24, 0.6);
 }
 
 :root[data-theme='dark'] .data-table tbody tr.is-selected-row {
   background: rgba(103, 184, 255, 0.2);
 }
 
 .cell-primary {
   font-weight: 600;
 }

 .name-button {
   background: none;
   border: none;
   padding: 0;
   font: inherit;
   color: var(--accent);
   cursor: pointer;
   display: inline-flex;
   min-width: 0;
 }
 
 .name-button:hover {
   text-decoration: underline;
 }

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

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem 1.25rem;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pagination button {
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.2);
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: background 200ms ease, border-color 200ms ease;
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

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

.pagination-size select {
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  background: rgba(255, 255, 255, 0.2);
  color: var(--text);
}

.empty-state {
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
}

.loader {
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: var(--text-muted);
}

.loader-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.inline-loader {
  min-height: auto;
  flex-direction: row;
}

.inline-loader p {
  margin: 0 0 0 0.5rem;
  color: var(--text);
}

.page-loader {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.page-loader-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: #fff;
}

.page-loader.is-visible {
  display: flex;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.detail-modal {
  position: fixed;
  inset: 0;
  background: rgba(3, 5, 12, 0.65);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
  backdrop-filter: blur(6px);
  z-index: 20;
  overscroll-behavior: contain;
}

.detail-modal[hidden] {
  display: none;
}

.detail-card {
  width: min(600px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--panel);
  border-radius: var(--border-radius);
  border: 1px solid var(--card-border);
  padding: 1.25rem;
  box-shadow: var(--card-shadow);
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.detail-header h3 {
  margin: 0;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.detail-item {
  padding: 0.75rem;
  border-radius: 0.85rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--card-border);
}

.detail-item span {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.detail-item strong {
  font-size: 1rem;
}

.detail-close {
  border: none;
  background: rgba(11, 123, 255, 0.12);
  color: var(--text);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  cursor: pointer;
}

.inline-count {
  color: var(--text-muted);
  font-size: 0.9rem;
}

@media (max-width: 720px) {
  .app-shell {
    padding: 1.25rem;
  }

  .app-bar {
    flex-direction: column;
    align-items: flex-start;
    position: relative;
  }

  .theme-toggle {
    display: inline-flex;
    align-self: flex-end;
    margin-left: auto;
    padding: 0.1rem;
  }

  .theme-toggle .toggle-text {
    display: none;
  }

  .toggle-track {
    width: 44px;
    height: 24px;
    padding: 2px;
  }

  .toggle-thumb {
    width: 20px;
    height: 20px;
  }

  .theme-toggle[data-mode='dark'] .toggle-thumb {
    transform: translateX(20px);
  }

  .controls-panel-body {
    grid-template-columns: 1fr;
  }

  .table-body-wrapper {
    max-height: none;
  }

  .data-table {
    min-width: 600px;
  }

  .pagination {
    flex-direction: column;
    align-items: stretch;
  }

  .pagination-controls {
    justify-content: space-between;
  }

  .race-grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    max-width: none;
  }
}
 
.home-section {
  margin-bottom: 2rem;
}

.section-label {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.race-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 2rem;
}

.race-list-title {
  margin: 0;
  font-size: 0.85rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.2rem;
  margin-top: 0.75rem;
  justify-items: stretch;
  grid-auto-flow: row;
}

@media (min-width: 1200px) {
  .analysis-grid {
    grid-template-columns: repeat(3, minmax(260px, 1fr));
  }
}

.blog-card {
  display: flex;
  gap: 0.9rem;
  background: var(--panel);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
  padding: 0.9rem;
  box-shadow: var(--card-shadow);
}

.blog-card img {
  width: 120px;
  height: 90px;
  object-fit: cover;
  border-radius: 0.8rem;
  flex-shrink: 0;
}

.blog-card h3 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}

.blog-card .blog-source {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.blog-card a {
  text-decoration: none;
  font-weight: 600;
  color: var(--accent);
  font-size: 0.9rem;
}

.app-footer {
  margin-top: 2rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

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