:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --sidebar-bg: #ffffff;
  --surface: #ffffff;
  --surface-strong: #eef4ff;
  --ink: #172033;
  --muted: #667085;
  --line: #dfe5ef;
  --accent: #2563eb;
  --accent-soft: #e8f0ff;
  --accent-strong: #1d4ed8;
  --accent-text: #1e3a8a;
  --button-text: #ffffff;
  --amber: #d97706;
  --rose: #e11d48;
  --match-home: #2563eb;
  --match-draw: #f59e0b;
  --match-away: #e11d48;
  --brand-bg: #ffffff;
  --brand-border: #d7e0ef;
  --brand-ring: #e8f0ff;
  --brand-shadow: rgba(37, 99, 235, 0.13);
  --nav-active-border: #bfd2ff;
  --status-border: #bdd0ff;
  --status-text: #1e3a8a;
  --bar-track: #e8edf5;
  --row-line: #edf1f7;
  --input-bg: #ffffff;
  --input-border: #ccd6e4;
  --positive-bg: #dcfce7;
  --positive-text: #166534;
  --negative-bg: #ffe4e6;
  --negative-text: #be123c;
  --error-bg: #fff1f2;
  --error-border: #fecdd3;
  --error-text: #be123c;
  --shadow: 0 18px 44px rgba(23, 32, 51, 0.08);
  --knob-shadow: rgba(23, 32, 51, 0.22);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101214;
  --sidebar-bg: #14181f;
  --surface: #1a2029;
  --surface-strong: #202938;
  --ink: #f3f7fb;
  --muted: #a7b0bf;
  --line: #2e3847;
  --accent: #60a5fa;
  --accent-soft: #17263f;
  --accent-strong: #93c5fd;
  --accent-text: #bfdbfe;
  --button-text: #07111f;
  --amber: #fbbf24;
  --rose: #fb7185;
  --match-home: #60a5fa;
  --match-draw: #fbbf24;
  --match-away: #fb7185;
  --brand-bg: #1a2029;
  --brand-border: #354154;
  --brand-ring: #253148;
  --brand-shadow: rgba(96, 165, 250, 0.18);
  --nav-active-border: #315987;
  --status-border: #315987;
  --status-text: #bfdbfe;
  --bar-track: #263142;
  --row-line: #263142;
  --input-bg: #121820;
  --input-border: #364456;
  --positive-bg: #123322;
  --positive-text: #bbf7d0;
  --negative-bg: #3f1825;
  --negative-text: #fecdd3;
  --error-bg: #3b1824;
  --error-border: #8b2d45;
  --error-text: #fecdd8;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.38);
  --knob-shadow: rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, var(--surface-strong) 0, var(--bg) 280px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 28px;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(180deg, var(--sidebar-bg) 0, var(--bg) 100%),
    var(--sidebar-bg);
  padding: 28px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--brand-border);
  border-radius: 50%;
  background: var(--brand-bg);
  box-shadow: inset 0 0 0 5px var(--brand-ring), 0 8px 18px var(--brand-shadow);
  color: var(--ink);
  font-size: 25px;
  font-weight: 800;
  line-height: 1;
}

.brand-title {
  font-size: 18px;
  font-weight: 800;
}

.brand-subtitle,
.sidebar-note,
.small-label,
.panel-heading span,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.small-label,
.eyebrow {
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-button {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 12px 14px;
  text-align: left;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.nav-button:hover,
.nav-button.is-active {
  border-color: var(--nav-active-border);
  background: var(--accent-soft);
  color: var(--accent-text);
}

.nav-button:hover {
  transform: translateX(2px);
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  padding: 12px;
  text-align: left;
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.theme-toggle:hover {
  border-color: var(--nav-active-border);
  box-shadow: 0 10px 24px var(--brand-shadow);
}

.theme-toggle-copy {
  display: grid;
  gap: 2px;
}

.theme-toggle-label {
  font-weight: 800;
}

.theme-toggle-value {
  color: var(--muted);
  font-size: 12px;
}

.theme-switch {
  position: relative;
  display: inline-flex;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
  align-items: center;
  border-radius: 999px;
  background: var(--bar-track);
  box-shadow: inset 0 0 0 1px var(--line);
  transition: background 180ms ease;
}

.theme-knob {
  width: 22px;
  height: 22px;
  margin-left: 3px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 2px 8px var(--knob-shadow);
  transition: transform 180ms ease, background 180ms ease;
}

[data-theme="dark"] .theme-switch {
  background: var(--accent);
}

[data-theme="dark"] .theme-knob {
  background: #06231f;
  transform: translateX(20px);
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.main-panel {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  margin-top: 4px;
  font-size: 32px;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
  line-height: 1.25;
}

h3 {
  margin-bottom: 10px;
  font-size: 13px;
  text-transform: uppercase;
  color: var(--muted);
}

.status-pill {
  border: 1px solid var(--status-border);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--status-text);
  font-size: 13px;
  font-weight: 700;
  padding: 8px 12px;
  white-space: nowrap;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: stretch;
  gap: 14px;
  margin-bottom: 18px;
}

.metric-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  display: flex;
  min-height: 118px;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric-value {
  margin-top: 8px;
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
}

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

.split-layout,
.matchup-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 18px;
}

.matchup-layout {
  grid-template-columns: minmax(300px, 0.8fr) minmax(0, 1.2fr);
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-heading span {
  flex-shrink: 0;
  max-width: 45%;
  text-align: right;
}

.bar-stack {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 170px) 1fr 62px;
  align-items: center;
  gap: 12px;
}

.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.bar-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--bar-track);
}

.bar-fill {
  height: 100%;
  min-width: 2px;
  border-radius: inherit;
  background: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent), transparent 78%);
}

.bar-value {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.compact-bars {
  gap: 8px;
}

.compact-bars .bar-track {
  height: 8px;
}

.table-wrap {
  overflow: auto;
  max-height: 680px;
}

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

th,
td {
  border-bottom: 1px solid var(--row-line);
  padding: 10px 8px;
  text-align: right;
  white-space: nowrap;
}

th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr:hover {
  background: color-mix(in srgb, var(--accent-soft), transparent 42%);
}

.control-row {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  margin-bottom: 18px;
}

.control-row.two-up {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.control-row.single {
  display: block;
  margin-bottom: 16px;
}

.control-field {
  flex: 1;
  min-width: min(320px, 100%);
  max-width: 380px;
}

.control-row.two-up .control-field,
.control-row.single .control-field {
  min-width: 0;
  max-width: none;
}

label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--ink);
  padding: 0 12px;
  vertical-align: middle;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent), transparent 78%);
  outline: none;
}

.primary-button {
  min-height: 42px;
  border: 1px solid var(--accent-strong);
  border-radius: 8px;
  background: var(--accent);
  color: var(--button-text);
  cursor: pointer;
  font-weight: 800;
  line-height: 1;
  padding: 0 16px;
  box-shadow: 0 10px 24px var(--brand-shadow);
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.primary-button:hover {
  background: var(--accent-strong);
  color: var(--button-text);
  transform: translateY(-1px);
}

.driver-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.driver-list {
  display: grid;
  gap: 8px;
}

.driver-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-radius: 8px;
  padding: 10px 12px;
}

.driver-item.positive {
  background: var(--positive-bg);
  color: var(--positive-text);
}

.driver-item.negative {
  background: var(--negative-bg);
  color: var(--negative-text);
}

.empty-note {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 12px;
}

.donut-wrap {
  display: grid;
  grid-template-columns: 220px 1fr;
  align-items: center;
  gap: 20px;
}

.donut {
  width: 220px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(var(--accent) 0deg, var(--accent) 120deg, var(--amber) 120deg, var(--amber) 220deg, var(--rose) 220deg);
  position: relative;
}

.donut::after {
  content: "";
  position: absolute;
  inset: 54px;
  border-radius: 50%;
  background: var(--surface);
}

.donut-legend {
  display: grid;
  gap: 10px;
}

.legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--row-line);
  padding-bottom: 8px;
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.legend-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.standings-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 22px;
}

.standings-list li {
  border-bottom: 1px solid var(--row-line);
  padding: 0 0 10px 4px;
}

.standings-main {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 800;
}

.standings-sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.subsection {
  margin-top: 20px;
}

.error-box {
  border: 1px solid var(--error-border);
  border-radius: 8px;
  background: var(--error-bg);
  color: var(--error-text);
  padding: 14px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-grid,
  .split-layout,
  .matchup-layout,
  .driver-columns,
  .control-row.two-up {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .main-panel,
  .sidebar {
    padding: 18px;
  }

  .topbar,
  .control-row,
  .donut-wrap {
    display: grid;
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 26px;
  }

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

  .bar-row {
    grid-template-columns: 1fr 54px;
  }

  .bar-label {
    grid-column: 1 / -1;
  }
}
