:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --line: #e4e4e0;
  --row-alt: #fafaf8;
  --accent: #c20e1a;
  --accent-soft: #fbe9ea;
  --hl: #fff4c2;
  --best: #1f8a43;
  --best-bg: #e3f4e8;
  --fastest: #7a2bc2;
  --fastest-bg: #f1e6fb;
  --slow: #b35c00;
  --chip: #efefeb;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416;
    --panel: #1d1d20;
    --text: #ececef;
    --muted: #9a9aa2;
    --line: #2e2e33;
    --row-alt: #212125;
    --accent: #ff4d58;
    --accent-soft: #3a1c1f;
    --hl: #4a4020;
    --best: #5fd48a;
    --best-bg: #1d3526;
    --fastest: #c79cff;
    --fastest-bg: #33254a;
    --slow: #ffae57;
    --chip: #2a2a2f;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 0 16px; height: 48px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; color: var(--accent); }
.top nav { display: flex; gap: 4px; }
.top nav a {
  text-decoration: none; padding: 6px 12px; border-radius: 6px; color: var(--muted);
}
.top nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main { padding: 16px; max-width: 1500px; margin: 0 auto; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 20px 0 8px; }
.sub { color: var(--muted); margin-bottom: 12px; }
.files { margin: -6px 0 12px; font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.files a { color: var(--accent); text-decoration: none; overflow-wrap: anywhere; }
.files a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }

/* список гонок */
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; align-items: center; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 4px 12px; cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.day { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.day:last-child { border-bottom: 0; }
.day .date { font-weight: 600; }
.day .date small { display: block; color: var(--muted); font-weight: 400; }
.day .items { display: flex; flex-direction: column; gap: 6px; }
.race-link { display: flex; gap: 10px; align-items: baseline; text-decoration: none; padding: 4px 8px; margin: -4px -8px; border-radius: 6px; }
.race-link:hover { background: var(--row-alt); }
.race-link .t { flex: 1; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .03em;
  padding: 1px 6px; border-radius: 4px; background: var(--chip); color: var(--muted); min-width: 30px; text-align: center;
}
.badge.XC { background: #e7f0ff; color: #1f55b5; }
.badge.MX { background: #fde8e8; color: #b3202a; }
.badge.SS { background: #fff1db; color: #a05a00; }
.badge.EN { background: #e8f6ea; color: #23793a; }
@media (prefers-color-scheme: dark) {
  .badge.XC { background: #1c2a44; color: #8db4ff; }
  .badge.MX { background: #3d1c1f; color: #ff8d95; }
  .badge.SS { background: #3a2b14; color: #ffc073; }
  .badge.EN { background: #1b3322; color: #7fd89a; }
}

/* страница гонки */
.race-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; align-items: start; }
.race-layout > *, .rating-layout > * { min-width: 0; }
.classes { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; padding: 6px; }
.classes button {
  display: flex; width: 100%; text-align: left; gap: 8px; justify-content: space-between;
  border: 0; background: none; padding: 7px 10px; border-radius: 6px; cursor: pointer;
}
.classes button:hover { background: var(--row-alt); }
.classes button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.classes button .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.classes .sep { height: 1px; background: var(--line); margin: 6px 4px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.search {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); min-width: 260px;
}
.tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tabs button { border: 0; background: var(--panel); padding: 6px 12px; cursor: pointer; }
.tabs button + button { border-left: 1px solid var(--line); }
.tabs button.on { background: var(--accent); color: #fff; }
.toggle { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; user-select: none; }
.class-select { display: none; }

/* таблицы */
.tbl-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 5px 8px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { font-size: 12px; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); }
tbody tr:nth-child(even) td { background: var(--row-alt); }
tbody tr.hl td { background: var(--hl); }
td.num, th.num { text-align: right; }
td.c, th.c { text-align: center; }
td.name a { text-decoration: none; font-weight: 600; }
td.name a:hover { text-decoration: underline; color: var(--accent); }
td.wrap { white-space: normal; min-width: 120px; }
td.lap { font-size: 12.5px; text-align: right; }
td.lap.best { color: var(--best); font-weight: 700; }
td.lap.fastest { background: var(--fastest-bg) !important; color: var(--fastest); font-weight: 700; }
td.lap.slow { color: var(--slow); }
td.lap.excluded { color: var(--muted); opacity: .6; }
.laps-inline span.excluded { opacity: .55; }
.top-opt { margin-left: auto; font-size: 13px; color: var(--muted); white-space: nowrap; }
.place { font-weight: 700; }
.p1 { color: #b8860b; } .p2 { color: #7d8791; } .p3 { color: #a0522d; }
.group-title { font-weight: 600; padding: 10px 8px 4px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* гонщик */
.people { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.people a { text-decoration: none; }
.stats { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
.stat { padding: 10px 14px; min-width: 120px; }
.stat b { display: block; font-size: 18px; }
.stat span { color: var(--muted); font-size: 12px; }
tr.expand td { background: var(--panel) !important; white-space: normal; }
.laps-inline { display: flex; flex-wrap: wrap; gap: 4px; font-size: 12px; }
.laps-inline span { padding: 1px 5px; border-radius: 4px; background: var(--chip); }
.laps-inline span.best { background: var(--best-bg); color: var(--best); font-weight: 700; }
button.link { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 4px; }

/* рейтинг */
.rating-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: start; }
.rating-side { padding: 14px; position: sticky; top: 64px; }
.rating-side label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.rating-side textarea, .rating-side select {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 7px 9px;
}
.rating-side textarea { min-height: 150px; resize: vertical; }
.bar { position: relative; height: 8px; background: var(--chip); border-radius: 4px; min-width: 80px; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--accent); opacity: .75; }
details.method { margin-top: 14px; font-size: 13px; color: var(--muted); }
details.method summary { cursor: pointer; color: var(--text); }
.h2h td { text-align: center; }
.h2h td.win { color: var(--best); font-weight: 700; }
.h2h td.loss { color: var(--accent); }
.h2h th.rot { writing-mode: vertical-rl; transform: rotate(180deg); text-align: left; height: 120px; }

@media (max-width: 860px) {
  .race-layout, .rating-layout { grid-template-columns: minmax(0, 1fr); }
  main { padding: 12px 16px; }
  .classes { display: none; }
  .class-select { display: block; width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
  .rating-side { position: static; }
  .day { grid-template-columns: 1fr; gap: 6px; }
  .search { min-width: 0; flex: 1; }
  .top { gap: 10px; }
  .brand { display: none; }
}
@media (max-width: 560px) {
  .top nav a { padding: 6px 8px; }
  .top-opt span { display: none; }
  .top-opt::after { content: "1-й круг"; }
}
