/* Running Buddies — календарь стартов: сцена с бегуном и список забегов */

/* ---------- Arena: тёмная сцена с бегуном ---------- */

.arena {
  --heat: 1;                 /* 0…4, ставит racestage.js: чем длиннее дистанция, тем жарче */
  position: relative;
  display: flex;
  min-height: max(660px, min(96vh, 940px));
  overflow: hidden;
  color: #fff;
}
@supports (height: 100svh) {
  .arena { min-height: max(660px, min(96svh, 940px)); }
}
.arena__canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}
/* тень под текстом слева: сцена светится, а текст читается */
.arena::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    linear-gradient(90deg, rgba(18, 17, 16, 0.86) 0, rgba(18, 17, 16, 0.62) 30%, rgba(18, 17, 16, 0) 58%),
    linear-gradient(180deg, rgba(18, 17, 16, 0.7) 0, rgba(18, 17, 16, 0) 26%);
  pointer-events: none;
}
/* без JS — просто ночное небо с заревом */
.arena {
  background:
    radial-gradient(70% 55% at 70% 85%, rgba(226, 73, 43, 0.35), rgba(226, 73, 43, 0) 70%),
    linear-gradient(180deg, #0d0c10 0, #1b1714 100%);
}

.arena__inner {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 620px) minmax(0, 1fr);
  grid-template-rows: auto 1fr auto;
  gap: 0 32px;
  padding-top: calc(var(--header-h) + clamp(28px, 5vh, 64px));
  padding-bottom: clamp(28px, 4vw, 56px);
}
.arena__head { grid-column: 1; grid-row: 1; }
.arena__controls { grid-column: 1; grid-row: 3; }
.arena__controls[hidden] { display: none; }
.arena__found {
  grid-column: 2;
  grid-row: 3;
  align-self: end;
  justify-self: end;
}

.arena__title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.18em;
  margin-top: clamp(14px, 2vw, 24px);
  font-size: clamp(56px, 8.6vw, 148px);
  font-weight: 800;
  line-height: 0.86;
  letter-spacing: -0.05em;
  text-transform: uppercase;
  animation: rise 1s var(--ease) 0.15s both;
}
.arena__year {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  /* год раскаляется вместе со сценой */
  text-shadow:
    0 0 calc(var(--heat) * 7px) rgba(255, 120, 40, calc(var(--heat) * 0.18)),
    0 0 calc(var(--heat) * 22px) rgba(255, 70, 20, calc(var(--heat) * 0.14));
  transition: text-shadow 0.8s var(--ease);
}
.arena__lead {
  max-width: 27em;
  margin-top: clamp(18px, 2.4vw, 30px);
  font-size: clamp(17px, 1.35vw, 20px);
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.86);
  text-wrap: pretty;
  animation: rise 1s var(--ease) 0.3s both;
}
.arena__years { margin-top: 22px; }
.arena__years[hidden] { display: none; }

/* ---------- Pickers: тип забега и дистанция ---------- */

.arena__controls { animation: rise 1s var(--ease) 0.45s both; }
.pick + .pick { margin-top: clamp(18px, 2.2vw, 26px); }
.pick__label {
  margin-bottom: 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
}
.pick__heat {
  margin-left: 6px;
  color: #ffb066;
  letter-spacing: 0.1em;
  text-transform: none;
}
.pick__row { display: flex; gap: 8px; }

.tile {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 2px 10px;
  flex: 1 1 0;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 14px;
  background: rgba(18, 17, 16, 0.42);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #fff;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.3s var(--ease), color 0.3s var(--ease), border-color 0.3s var(--ease), transform 0.3s var(--ease);
}
.tile:hover { border-color: #fff; transform: translateY(-2px); }
.tile[aria-pressed="true"] {
  border-color: #fff;
  background: #fff;
  color: var(--ink);
}
.tile__icon {
  grid-row: 1 / 3;
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tile[aria-pressed="true"] .tile__icon { stroke: var(--accent); }
.tile__name {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}
.tile__count {
  min-height: 1.3em;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  font-variant-numeric: tabular-nums;
}
.tile[aria-pressed="true"] .tile__count { color: var(--muted); }

/* дистанции — «шкала жара»: от спокойной пятёрки до ультры в огне */
.pick__row--dist { gap: 0; }
.heat {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  flex: 1 1 0;
  min-width: 0;
  padding: 11px 12px 10px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-right-width: 0;
  background: rgba(18, 17, 16, 0.42);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #fff;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.3s var(--ease), color 0.3s var(--ease), box-shadow 0.4s var(--ease);
}
.heat:first-child { border-radius: 14px 0 0 14px; }
.heat:last-child { border-right-width: 1px; border-radius: 0 14px 14px 0; }
.heat:hover { background: rgba(255, 255, 255, 0.12); }
.heat__name {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.heat[aria-pressed="true"] {
  z-index: 1;
  border-color: transparent;
  background: linear-gradient(160deg, #ffd27a 0%, #ff7a2f 45%, #e2492b 100%);
  color: #1a0d06;
  box-shadow: 0 0 calc(4px + var(--heat) * 9px) rgba(255, 110, 40, calc(0.2 + var(--heat) * 0.12));
}
.heat[data-dist="10"][aria-pressed="true"] { background: linear-gradient(160deg, #ffffff 0%, #d9e2e8 100%); box-shadow: none; }

/* значок огня; горящие — цветные, остальные — тусклые */
.flames { display: inline-flex; gap: 2px; line-height: 0; }
.flame {
  width: 10px;
  height: 13px;
  fill: currentColor;
  opacity: 0.22;
}
.flame.is-lit { opacity: 1; color: #ff7a2f; }
.heat[aria-pressed="true"] .flame.is-lit { color: #7a1a06; }
.heat[aria-pressed="true"] .flame { opacity: 0.3; }
.heat[aria-pressed="true"] .flame.is-lit { opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
  .heat[aria-pressed="true"] .flame.is-lit { animation: flicker 0.9s ease-in-out infinite alternate; transform-origin: 50% 100%; }
  .heat[aria-pressed="true"] .flame.is-lit:nth-child(2) { animation-delay: -0.3s; }
  .heat[aria-pressed="true"] .flame.is-lit:nth-child(3) { animation-delay: -0.6s; }
  .heat[aria-pressed="true"] .flame.is-lit:nth-child(4) { animation-delay: -0.15s; }
}
@keyframes flicker {
  0% { transform: scale(1, 1); }
  50% { transform: scale(0.92, 1.12); }
  100% { transform: scale(1.06, 0.94); }
}

/* «57 стартов ↓» — к списку */
.arena__found {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  animation: rise 1s var(--ease) 0.6s both;
}
.arena__found[hidden] { display: none; }
.arena__found b {
  font-size: clamp(56px, 7vw, 112px);
  font-weight: 800;
  line-height: 0.9;
  letter-spacing: -0.05em;
  font-variant-numeric: tabular-nums;
}
.arena__found span {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.75);
}
.arena__found span::after {
  content: "";
  width: 7px;
  height: 7px;
  margin-top: -4px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.3s var(--ease);
}
.arena__found:hover span { color: #fff; }
.arena__found:hover span::after { transform: translateY(3px) rotate(45deg); }

/* ---------- Calendar: список стартов ---------- */

.calendar { padding: clamp(64px, 8vw, 120px) 0 clamp(72px, 9vw, 140px); }
.calendar__head { margin-bottom: clamp(28px, 3.6vw, 48px); }

.calendar__filters[hidden] { display: none; }
.calendar__months { margin-bottom: 12px; }
.calendar__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 24px;
  margin-bottom: clamp(20px, 2.6vw, 36px);
}
.calendar__summary {
  margin-left: auto;
  font-size: 14px;
  color: var(--muted);
}
.calendar__summary b { color: var(--ink); font-variant-numeric: tabular-nums; }
.calendar__reset {
  margin-left: 10px;
  padding: 0;
  border: 0;
  background: none;
  font-size: 14px;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.select { position: relative; display: inline-flex; }
.select::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 18px;
  width: 6px;
  height: 6px;
  margin-top: -5px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  pointer-events: none;
}
.select select {
  -webkit-appearance: none;
  appearance: none;
  min-height: 38px;
  max-width: 260px;
  padding: 0 42px 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.3s var(--ease);
}
.select select:hover { border-color: var(--ink); }
.select.is-set select { border-color: var(--ink); background: var(--ink); color: #fff; }
.select.is-set::after { color: #fff; }

.calendar__month + .calendar__month { margin-top: clamp(36px, 4vw, 60px); }
.calendar__mhead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--ink);
}
.calendar__mname {
  font-size: clamp(30px, 3.4vw, 52px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
}
.calendar__mcount {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.race {
  position: relative;
  display: grid;
  grid-template-columns: 5.6em minmax(0, 2.2fr) 6.5em minmax(0, 1.5fr) 4.6em auto;
  align-items: center;
  gap: 8px 24px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}
.race::before {
  content: "";
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 100%;
  height: 1px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.6s var(--ease);
}
.race:hover::before { transform: scaleX(1); }

.race__date {
  display: flex;
  flex-direction: column;
  line-height: 1;
}
.race__day {
  font-size: clamp(28px, 2.6vw, 40px);
  font-weight: 800;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.race__wd {
  margin-top: 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.race__main { display: flex; flex-direction: column; min-width: 0; }
.race__title {
  margin: 0;
  font-size: clamp(17px, 1.45vw, 21px);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.005em;
  text-wrap: pretty;
  overflow-wrap: anywhere;
}
.race__city {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-top: 4px;
  font-size: 14px;
  color: var(--muted);
}
.race__abroad {
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.race__type {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.race__type::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink);
}
.race__type--road::before { background: var(--ink); }
.race__type--trail::before { border-radius: 0; background: #3f7a4b; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.race__type--other::before { border-radius: 2px; background: var(--accent); }

.race__km {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.race__km span {
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(13, 13, 13, 0.06);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.race__km span.is-long { background: rgba(226, 73, 43, 0.12); color: #a8321a; }
.race__km .race__more { background: none; color: var(--muted); }
.race__km .race__unknown { background: none; color: var(--muted); font-weight: 500; }

.race .flames { color: var(--ink); }
.race .flame { width: 11px; height: 14px; }
.race .flame.is-lit { color: var(--accent); }
@media (prefers-reduced-motion: no-preference) {
  .race:hover .flame.is-lit { animation: flicker 0.7s ease-in-out infinite alternate; transform-origin: 50% 100%; }
  .race:hover .flame.is-lit:nth-child(2n) { animation-delay: -0.35s; }
}

.race__go {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 20px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  transition: background-color 0.3s var(--ease), color 0.3s var(--ease), border-color 0.3s var(--ease);
}
.race__go::after {
  content: "";
  width: 6px;
  height: 6px;
  border-top: 1.5px solid currentColor;
  border-right: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.3s var(--ease);
}
.race__go:hover {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}
.race__go:hover::after { transform: translateX(3px) rotate(45deg); }

.calendar__loading,
.calendar__empty {
  padding: clamp(28px, 4vw, 48px) 0;
  border-top: 1px solid var(--ink);
  font-size: clamp(17px, 1.35vw, 20px);
  color: #3b3a37;
}
.calendar__loading { color: var(--muted); }
@media (scripting: none) {
  .calendar__loading { display: none; }
}
.calendar__empty p { max-width: 32em; text-wrap: pretty; }
.calendar__empty .btn { margin-top: 24px; }
.calendar__empty a:not(.btn) { text-decoration: underline; text-underline-offset: 3px; }

.calendar__source {
  margin-top: clamp(24px, 3vw, 40px);
  font-size: 13px;
  color: var(--muted);
}
.calendar__source[hidden] { display: none; }
.calendar__source a { text-decoration: underline; text-underline-offset: 3px; }
.calendar__source a:hover { color: var(--accent); }

/* ---------- Tablet ---------- */

@media (max-width: 1100px) {
  .race { grid-template-columns: 5em minmax(0, 1fr) auto auto; }
  .race__type { grid-column: 2; grid-row: 2; }
  .race__km { grid-column: 2 / 4; grid-row: 3; }
  .race .flames { grid-column: 3; grid-row: 1; }
  .race__go { grid-column: 4; grid-row: 1 / 4; }
  .race__date { grid-row: 1 / 4; align-self: start; }
}

@media (max-width: 960px) {
  .arena__inner { grid-template-columns: minmax(0, 1fr); }
  .arena__found { grid-column: 1; grid-row: 2; align-self: start; margin-top: 18px; justify-self: start; align-items: flex-start; text-align: left; }
}

/* ---------- Mobile: сверху заголовок, в середине бегун, снизу выбор ---------- */

@media (max-width: 760px) {
  .arena { min-height: 0; }
  /* затемняем только под заголовком и под выбором — бегун в середине остаётся ярким */
  .arena::before {
    background:
      linear-gradient(180deg, rgba(18, 17, 16, 0.75) 0, rgba(18, 17, 16, 0) 210px),
      linear-gradient(0deg, rgba(18, 17, 16, 0.9) 0, rgba(18, 17, 16, 0.55) 190px, rgba(18, 17, 16, 0) 240px);
  }
  .arena__inner {
    grid-template-rows: auto auto auto;
    padding-top: calc(var(--header-h) + 18px);
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }
  .arena__title { margin-top: 10px; font-size: clamp(48px, 15vw, 76px); }
  .arena__lead { display: none; }
  .arena__years { margin-top: 12px; }
  .arena__years .chip { min-height: 34px; }
  /* место под бегуна: его рисует racestage.js между заголовком и выбором */
  .arena__found {
    grid-row: 2;
    min-height: clamp(220px, 36vh, 340px);
    margin-top: 0;
    padding-top: 10px;
    justify-self: end;
    align-items: flex-end;
    text-align: right;
  }
  .arena__found b { font-size: 44px; }
  .arena__found span { font-size: 10px; }

  .pick__row--type { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .tile {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    justify-items: center;
    padding: 10px 4px 8px;
    text-align: center;
  }
  .tile__icon { grid-row: auto; width: 26px; height: 26px; }
  .tile__name { font-size: 12px; letter-spacing: 0.04em; }
  .tile__count { font-size: 11px; }
  .heat { padding: 10px 6px 9px; align-items: center; text-align: center; }
  .heat__name { font-size: 11px; white-space: normal; line-height: 1.15; }
  .flame { width: 8px; height: 11px; }

  .calendar__months {
    flex-wrap: nowrap;
    margin: 0 calc(var(--pad) * -1) 12px;
    padding: 0 var(--pad);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .calendar__months::-webkit-scrollbar { display: none; }
  .calendar__summary { margin-left: 0; width: 100%; }

  .race {
    grid-template-columns: 3.6em minmax(0, 1fr) auto;
    gap: 6px 14px;
    padding: 16px 0;
  }
  .race__date { grid-row: 1 / 5; }
  .race__day { font-size: 26px; }
  .race__main { grid-column: 2 / 4; grid-row: 1; }
  .race__type { grid-column: 2; grid-row: 2; }
  .race .flames { grid-column: 3; grid-row: 2; justify-self: end; }
  .race__km { grid-column: 2 / 4; grid-row: 3; }
  .race__go { grid-column: 2 / 4; grid-row: 4; justify-self: start; min-height: 38px; margin-top: 4px; }
}
