:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --ink: #181b22;
  --muted: #5d6673;
  --quiet: #7a8492;
  --line: #d9dee7;
  --line-strong: #b9c1ce;
  --accent: #e1251b;
  --accent-dark: #b91912;
  --oval: #d71920;
  --sports: #087f5b;
  --formula: #1c6dd0;
  --dirt-oval: #9a5a1f;
  --dirt-road: #6d5bd0;
  --unranked: #65707d;
  --shadow: 0 18px 50px rgba(22, 28, 38, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(24, 27, 34, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(24, 27, 34, 0.035) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.season-notice {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 0 0 16px;
  padding: 12px 16px;
  background: #fff8e6;
  border: 1px solid #e6d4a5;
  border-radius: 8px;
  color: #62480a;
  font-size: 0.85rem;
}

.week-navigation {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

a {
  color: inherit;
}

.app-shell {
  width: min(1520px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 72px;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111318;
  box-shadow: var(--shadow);
  flex: 0 0 auto;
}

.brand-mark svg {
  width: 58px;
  height: 34px;
}

.brand-mark path {
  fill: none;
  stroke: #f8fafc;
  stroke-width: 4;
  stroke-linecap: round;
}

.brand-mark circle {
  fill: var(--accent);
  stroke: #fff;
  stroke-width: 1.5;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent-dark);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(1.45rem, 2.4vw, 2.3rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ghost-link,
.ghost-button,
.toggle-button,
.view-button,
.chip,
.star-button,
.detail-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  text-decoration: none;
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease, transform 150ms ease;
}

.ghost-link,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
  font-weight: 700;
}

.ghost-link:hover,
.ghost-button:hover,
.toggle-button:hover,
.view-button:hover,
.chip:hover,
.star-button:hover,
.detail-button:hover {
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.control-panel {
  display: grid;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.primary-controls {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(170px, 0.72fr) minmax(220px, 1.3fr) auto;
  gap: 12px;
  align-items: end;
}

.input-wrap {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.input-wrap span,
.filter-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

input,
select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

input:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(225, 37, 27, 0.14);
  outline: none;
}

.toggle-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 14px;
  font-weight: 800;
  white-space: nowrap;
}

.toggle-button[aria-pressed="true"],
.view-button.is-active,
.chip.is-active {
  border-color: #191b21;
  background: #191b21;
  color: #fff;
}

.star {
  color: #f2b600;
  line-height: 1;
}

.filter-block {
  display: grid;
  grid-template-columns: 1.2fr 0.64fr 1.16fr;
  gap: 14px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 7px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 10px;
  color: var(--ink);
  font-weight: 800;
  font-size: 0.9rem;
}

.chip-count {
  color: var(--quiet);
  font-size: 0.78rem;
  font-weight: 800;
}

.chip.is-active .chip-count {
  color: rgba(255, 255, 255, 0.75);
}

.category-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--unranked);
  flex: 0 0 auto;
}

.cat-OVAL { --cat: var(--oval); }
.cat-SPORTS-CAR { --cat: var(--sports); }
.cat-FORMULA-CAR { --cat: var(--formula); }
.cat-DIRT-OVAL { --cat: var(--dirt-oval); }
.cat-DIRT-ROAD { --cat: var(--dirt-road); }
.cat-UNRANKED { --cat: var(--unranked); }

.cat-OVAL .category-dot,
.cat-SPORTS-CAR .category-dot,
.cat-FORMULA-CAR .category-dot,
.cat-DIRT-OVAL .category-dot,
.cat-DIRT-ROAD .category-dot,
.cat-UNRANKED .category-dot {
  background: var(--cat);
}

.view-toggle {
  display: inline-flex;
  gap: 8px;
  margin: 18px 0 14px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.view-button {
  min-width: 90px;
  padding: 0 12px;
  font-weight: 800;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.stat {
  min-height: 76px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.stat strong {
  display: block;
  margin-top: 5px;
  font-size: 1.45rem;
  line-height: 1;
}

.view-panel {
  min-height: 260px;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 0 12px;
}

.section-head h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.15;
}

.section-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.race-list {
  display: grid;
  gap: 10px;
}

.race-card {
  display: grid;
  grid-template-columns: 44px 1.1fr minmax(260px, 0.9fr) auto;
  gap: 14px;
  align-items: center;
  min-height: 108px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--cat, var(--unranked));
  border-radius: 8px;
  background: var(--panel);
}

.star-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  color: #9aa3af;
  font-size: 1.12rem;
}

.star-button.is-favorite {
  color: #f2b600;
  border-color: #e5bd26;
  background: #fff8d8;
}

.race-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.race-title h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.25;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.badge.category {
  border-color: color-mix(in srgb, var(--cat, var(--unranked)) 36%, var(--line));
  color: var(--cat, var(--unranked));
  background: color-mix(in srgb, var(--cat, var(--unranked)) 10%, #fff);
}

.track-block {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.track-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 850;
  line-height: 1.25;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.race-actions {
  display: flex;
  justify-content: flex-end;
}

.detail-button {
  min-width: 84px;
  padding: 0 12px;
  font-weight: 800;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 220px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.matrix-wrap,
.detail-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.matrix-table,
.detail-table {
  width: 100%;
  border-collapse: collapse;
}

.matrix-table th,
.matrix-table td,
.detail-table th,
.detail-table td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

.matrix-table th:last-child,
.matrix-table td:last-child,
.detail-table th:last-child,
.detail-table td:last-child {
  border-right: 0;
}

.matrix-table tr:last-child td,
.detail-table tr:last-child td {
  border-bottom: 0;
}

.matrix-table th,
.detail-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #111318;
  color: #fff;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

.matrix-series {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 260px;
  max-width: 320px;
  background: var(--panel);
  border-left: 5px solid var(--cat, var(--unranked));
}

.matrix-table th.matrix-series {
  z-index: 3;
  background: #111318;
}

.matrix-cell {
  min-width: 190px;
}

.matrix-track {
  display: block;
  color: var(--ink);
  font-weight: 800;
  line-height: 1.25;
}

.matrix-meta {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.82rem;
}

.series-layout {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
  gap: 14px;
}

.series-list {
  display: grid;
  gap: 8px;
  align-content: start;
}

.series-row {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-left: 5px solid var(--cat, var(--unranked));
  border-radius: 8px;
  background: var(--panel);
  padding: 10px;
  text-align: left;
}

.series-row.is-selected {
  border-color: #111318;
  box-shadow: 0 0 0 2px rgba(17, 19, 24, 0.08);
}

.series-row-title {
  display: block;
  font-size: 0.94rem;
  font-weight: 850;
  line-height: 1.25;
}

.series-row p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.series-detail {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.series-detail-head {
  display: grid;
  gap: 8px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.series-detail-head h2 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.2;
}

.series-detail-head p {
  margin: 0;
  color: var(--muted);
}

.detail-table td:first-child {
  white-space: nowrap;
  font-weight: 800;
}

.details-text {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.rain-hot {
  color: #a54900;
  font-weight: 850;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #111318;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1080px) {
  .primary-controls,
  .filter-block,
  .stats-strip,
  .series-layout {
    grid-template-columns: 1fr 1fr;
  }

  .input-wide,
  .filter-block > div:last-child,
  .series-detail {
    grid-column: 1 / -1;
  }

  .race-card {
    grid-template-columns: 44px 1fr;
  }

  .track-block,
  .race-actions {
    grid-column: 2;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100vw - 20px, 680px);
    padding-top: 10px;
  }

  .topbar,
  .brand,
  .section-head {
    align-items: flex-start;
  }

  .topbar,
  .primary-controls,
  .filter-block,
  .stats-strip,
  .series-layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .brand-mark {
    width: 60px;
    height: 46px;
  }

  .view-toggle {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
  }

  .view-button {
    min-width: 0;
  }

  .race-card {
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 10px;
    padding: 12px;
  }

  .star-button {
    width: 34px;
    height: 34px;
    min-height: 34px;
  }

  .race-actions {
    justify-content: stretch;
  }

  .detail-button {
    width: 100%;
  }
}
