:root {
  color-scheme: light;
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-muted: #f7f8fb;
  --text: #111827;
  --text-muted: #4b5563;
  --border: #d4dae6;
  --accent: #ea580c;
  --danger: #ba2d4b;
  --shadow: 0 10px 24px rgba(15, 23, 42, 0.1);
  --shadow-soft: 0 2px 10px rgba(15, 23, 42, 0.08);
  --radius-lg: 18px;
  --radius-md: 12px;
  --ring: 0 0 0 3px rgba(234, 88, 12, 0.24);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1220;
  --surface: #131d32;
  --surface-muted: #1a2741;
  --text: #edf2ff;
  --text-muted: #b3c0de;
  --border: #2a395b;
  --accent: #fb923c;
  --danger: #ff7f9b;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --shadow-soft: 0 3px 12px rgba(0, 0, 0, 0.35);
  --ring: 0 0 0 3px rgba(132, 160, 255, 0.32);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #0f1424;
    --surface: #151c31;
    --surface-muted: #1c2540;
    --text: #e7ecff;
    --text-muted: #a7b2d9;
    --border: #2a355b;
    --accent: #84a0ff;
    --danger: #ff7f9b;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    --shadow-soft: 0 3px 12px rgba(0, 0, 0, 0.35);
    --ring: 0 0 0 3px rgba(132, 160, 255, 0.32);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background:
    radial-gradient(1100px 600px at 100% -50%, #dfe8ff, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #eef2ff, transparent 60%),
    var(--bg);
  color: var(--text);
}

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 24px 36px;
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 22px;
  position: relative;
  min-height: 300px;
  padding: 28px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(90deg, rgba(8, 13, 24, 0.86) 0%, rgba(8, 13, 24, 0.66) 42%, rgba(8, 13, 24, 0.12) 100%),
    url("./assets/hero-cyclists-stylized-road-race.webp") center right / cover no-repeat;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0;
  color: #fb923c;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.78rem;
  font-style: italic;
}

h1 {
  margin: 6px 0 10px;
  font-size: clamp(1.9rem, 4vw, 2.7rem);
  letter-spacing: -0.02em;
  color: #ffffff;
}

.subtitle {
  margin: 0;
  color: rgba(255, 255, 255, 0.82);
  max-width: 620px;
  line-height: 1.45;
}

.settings-group {
  display: grid;
  gap: 4px;
}

.settings-group + .settings-group {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.settings-section-label {
  margin: 0 0 4px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.calendar-view-option {
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  font-weight: 500;
}

.calendar-view-option.is-active {
  background: var(--surface-muted);
  border-color: var(--border);
}

html[data-calendar-view="auto"] .calendar {
  display: grid;
}

html[data-calendar-view="auto"] .table-wrap {
  display: none;
}

@media (min-width: 741px) {
  html[data-calendar-view="auto"] .calendar {
    display: none;
  }

  html[data-calendar-view="auto"] .table-wrap {
    display: block;
  }
}

html[data-calendar-view="cards"] .calendar {
  display: grid;
}

html[data-calendar-view="cards"] .table-wrap {
  display: none;
}

html[data-calendar-view="table"] .calendar {
  display: none;
}

html[data-calendar-view="table"] .table-wrap {
  display: block;
}

.theme-menu {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 40;
  display: grid;
  justify-items: end;
}

.theme-button {
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  color: var(--text);
  border-radius: 999px;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(12px);
}

.theme-button-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  flex-shrink: 0;
  opacity: 0.78;
}

.theme-button-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

.theme-popover {
  margin-top: 8px;
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  min-width: 160px;
  padding: 6px;
  display: grid;
  gap: 4px;
  backdrop-filter: blur(14px);
}

.theme-option {
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  font-weight: 500;
}

.theme-option.is-active {
  background: var(--surface-muted);
  border-color: var(--border);
}

.error {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #ffe9ee;
  border: 1px solid #ffc6d4;
  color: var(--danger);
}

.hidden {
  display: none;
}

.calendar {
  display: grid;
  gap: 18px;
}

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

.month-title {
  margin: 0;
  padding: 16px 18px;
  background: var(--surface-muted);
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  border-left: 4px solid var(--accent);
}

.race-list {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.race-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: grid;
  gap: 8px;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.race-card:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  box-shadow: var(--shadow-soft);
}

.race-card[data-status="past"] {
  opacity: 0.74;
  background: color-mix(in srgb, var(--surface) 88%, var(--surface-muted));
  border-color: color-mix(in srgb, var(--border) 82%, transparent);
}

.race-card[data-status="past"] .race-name {
  color: var(--text-muted);
  font-weight: 500;
}

.race-card[data-status="past"] .race-date::before,
.race-card[data-status="past"] .race-organizer::before {
  opacity: 0.42;
}

.race-card[data-status="past"]:hover {
  transform: none;
  box-shadow: none;
  border-color: color-mix(in srgb, var(--border) 90%, transparent);
}

.race-date {
  color: var(--text-muted);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.race-date::before {
  content: "";
  width: 14px;
  height: 14px;
  opacity: 0.88;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23ea580c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2' ry='2'/%3E%3Cline x1='16' y1='2' x2='16' y2='6'/%3E%3Cline x1='8' y1='2' x2='8' y2='6'/%3E%3Cline x1='3' y1='10' x2='21' y2='10'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

.race-name {
  margin: 0;
  font-size: 1rem;
}

.race-organizer {
  margin: 0;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.race-organizer::before {
  content: "";
  width: 14px;
  height: 14px;
  opacity: 0.88;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23ea580c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 20c1.8-3.5 5-5 8-5s6.2 1.5 8 5'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

.race-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.status {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-past { color: #6b7280; }
.status-current { color: #0d9488; }
.status-upcoming { color: #2563eb; }
.status-approx { color: #7c3aed; }

.results-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.results-link::before {
  content: "";
  width: 14px;
  height: 14px;
  opacity: 0.95;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23ea580c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 18l6-6-6-6'/%3E%3Cpath d='M15 12H3'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

.results-link:hover {
  text-decoration: underline;
}

.empty {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
}

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.races-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.races-table th,
.races-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.races-table th {
  background: var(--surface-muted);
  font-size: 0.9rem;
  position: sticky;
  top: 0;
  z-index: 2;
  white-space: nowrap;
}

.races-table th::before {
  content: "";
  width: 14px;
  height: 14px;
  margin-right: 6px;
  display: inline-block;
  vertical-align: -2px;
  background-size: contain;
  background-repeat: no-repeat;
}

.races-table th:nth-child(1)::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23ea580c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2' ry='2'/%3E%3Cline x1='16' y1='2' x2='16' y2='6'/%3E%3Cline x1='8' y1='2' x2='8' y2='6'/%3E%3Cline x1='3' y1='10' x2='21' y2='10'/%3E%3C/svg%3E");
}

.races-table th:nth-child(2)::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23ea580c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='5' cy='19' r='2'/%3E%3Ccircle cx='19' cy='19' r='2'/%3E%3Cpath d='M5 19h14'/%3E%3Cpath d='M8 19V9l5-4 3 2'/%3E%3C/svg%3E");
}

.races-table th:nth-child(3)::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23ea580c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 20c1.8-3.5 5-5 8-5s6.2 1.5 8 5'/%3E%3C/svg%3E");
}

.races-table th:nth-child(4)::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23ea580c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 18l6-6-6-6'/%3E%3Cpath d='M15 12H3'/%3E%3C/svg%3E");
}

.races-table td {
  font-size: 0.95rem;
}

.race-row:last-child td {
  border-bottom: none;
}

.race-row:nth-child(even) td {
  background: color-mix(in srgb, var(--surface) 85%, var(--surface-muted));
}

.race-row[data-status="past"] td {
  color: color-mix(in srgb, var(--text-muted) 92%, var(--text));
  background: color-mix(in srgb, var(--surface-muted) 28%, var(--surface));
}

.race-row[data-status="past"]:nth-child(even) td {
  background: color-mix(in srgb, var(--surface-muted) 38%, var(--surface));
}

.race-row:hover td {
  background: color-mix(in srgb, var(--surface) 60%, var(--surface-muted));
}

.race-row[data-status="past"]:hover td {
  background: color-mix(in srgb, var(--surface-muted) 42%, var(--surface));
}

a:focus-visible,
input:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: 8px;
}

@media (max-width: 740px) {
  .page { padding: 16px 16px 28px; }
  .theme-menu {
    top: 22px;
    right: 22px;
  }
  .hero {
    flex-direction: column;
    align-items: stretch;
  }

  .races-table {
    min-width: 620px;
  }

  .races-table th,
  .races-table td {
    padding: 10px 10px;
    font-size: 0.88rem;
  }

  /* Скрываем организатора на очень узких экранах ради читаемости */
  .races-table th:nth-child(3),
  .races-table td:nth-child(3) {
    display: none;
  }
}
