.courses {
  background: linear-gradient(180deg, var(--night-950), var(--night-900) 30%, var(--night-900));
}

.courses__tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.course-tab {
  position: relative;
  display: grid;
  gap: 10px;
  padding: 18px 18px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--night-850);
  text-align: left;
  overflow: hidden;
  transition: background 0.4s var(--ease-out), color 0.4s, border-color 0.3s, transform 0.4s var(--ease-out);
}

@media (hover: hover) {
  .course-tab:hover {
    border-color: var(--lamp);
    transform: translateY(-2px);
  }
}

.course-tab:active {
  transform: scale(0.97);
  transition-duration: 0.12s;
}

.course-tab[aria-selected="true"] {
  background: var(--bone);
  border-color: var(--bone);
  color: var(--night-950);
}

.course-tab__km {
  font-stretch: 62%;
  font-weight: 900;
  font-size: clamp(2.8rem, 6vw, 5.2rem);
  line-height: 0.82;
}

.course-tab__km small {
  font-size: 0.32em;
  margin-left: 4px;
  letter-spacing: 0.04em;
}

.course-tab__name {
  display: grid;
  font-weight: 700;
  font-size: clamp(0.85rem, 1.2vw, 1.05rem);
  line-height: 1.2;
}

.course-tab__name small {
  font-family: var(--mono);
  font-weight: 400;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.6;
  margin-top: 4px;
}

.courses__stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "map" "profile" "panel";
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--night-850);
  overflow: hidden;
}

.courses__map {
  grid-area: map;
  position: relative;
  aspect-ratio: 3 / 2;
  background: radial-gradient(70% 90% at 70% 40%, rgba(255, 193, 90, 0.06), transparent 70%), var(--night-950);
}

.courses__topo,
.topo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.topo {
  fill: none;
  stroke: var(--bone);
  stroke-linecap: round;
}

.topo__line {
  stroke-width: 1;
  opacity: 0.06;
}

.topo__index {
  stroke-width: 1.6;
  opacity: 0.12;
}

.map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.map--overlay {
  pointer-events: none;
  will-change: transform;
}

.map__grid line {
  stroke: var(--bone);
  stroke-opacity: 0.035;
}

.map__north path {
  fill: var(--bone);
  opacity: 0.6;
}

.map__north text,
.map__scale text,
.map__start-label {
  fill: var(--mute);
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: 0.1em;
}

.map__scale path {
  fill: none;
  stroke: var(--mute);
  stroke-width: 1.5;
}

.map__ghost {
  fill: none;
  stroke: var(--bone);
  stroke-opacity: 0.16;
  stroke-width: 2;
  stroke-dasharray: 2 6;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke-opacity 0.4s;
}

.map__ghost.is-current {
  stroke-opacity: 0;
}

.map__halo,
.map__track {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke-dashoffset 1.6s var(--ease-io);
}

.map__halo {
  stroke: var(--lamp);
  stroke-width: 12;
  stroke-opacity: 0.35;
}

.map__track {
  stroke: var(--lamp);
  stroke-width: 3.5;
}

.map__start-ring {
  fill: none;
  stroke: var(--ember);
  stroke-width: 2;
  transform-box: fill-box;
  transform-origin: center;
  animation: pulse 2.4s var(--ease-out) infinite;
}

.map__start-dot {
  fill: var(--ember);
  stroke: var(--night-950);
  stroke-width: 3;
}

.map__start-label {
  fill: var(--bone-dim);
}

.map__runner-dot {
  fill: #fff;
  filter: drop-shadow(0 0 6px var(--lamp));
}

.courses__panel {
  grid-area: panel;
  display: grid;
  align-content: start;
  gap: 14px;
  padding: clamp(24px, 3vw, 40px);
  border-top: 1px solid var(--line);
}

.courses__panel.is-swapping > * {
  animation: swap-in 0.7s var(--ease-out) both;
}

.courses__panel.is-swapping > *:nth-child(2) { animation-delay: 0.05s; }
.courses__panel.is-swapping > *:nth-child(3) { animation-delay: 0.1s; }
.courses__panel.is-swapping > *:nth-child(4) { animation-delay: 0.15s; }
.courses__panel.is-swapping > *:nth-child(5) { animation-delay: 0.2s; }
.courses__panel.is-swapping > *:nth-child(6) { animation-delay: 0.25s; }

@keyframes swap-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}

.courses__title {
  font-size: clamp(5rem, 9vw, 8rem);
  color: var(--lamp);
}

.courses__title small {
  font-size: 0.3em;
  margin-left: 6px;
  color: var(--bone);
}

.courses__name {
  font-stretch: 75%;
  font-weight: 800;
  font-size: 1.5rem;
  text-transform: uppercase;
  line-height: 1;
}

.courses__tagline {
  color: var(--bone-dim);
  max-width: 34ch;
}

.courses__stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-block: 10px 8px;
  border-top: 1px solid var(--line);
}

.courses__stats div {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.courses__stats div:nth-child(odd) {
  padding-right: 12px;
}

.courses__stats dt {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mute);
  margin-bottom: 4px;
}

.courses__stats dd {
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.25;
}

.courses__stats dd small {
  display: block;
  font-family: var(--mono);
  font-weight: 400;
  font-size: 0.7rem;
  color: var(--mute);
  letter-spacing: 0.06em;
}

.courses__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.courses__profile {
  grid-area: profile;
  padding: 18px clamp(12px, 2vw, 24px) 10px;
  border-top: 1px solid var(--line);
  background: var(--night-900);
}

.profile__head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 12px;
  color: var(--mute);
  padding-inline: 8px;
}

.profile__readout {
  flex-shrink: 0;
  white-space: nowrap;
  color: var(--lamp);
  font-variant-numeric: tabular-nums;
}

.profile {
  width: 100%;
  height: clamp(150px, 16vw, 210px);
  cursor: ew-resize;
  touch-action: pan-y;
}

.profile__axes line {
  stroke: var(--bone);
  stroke-opacity: 0.08;
}

.profile__axes text {
  fill: var(--mute);
  font-family: var(--mono);
  font-size: 11px;
}

.profile__area {
  fill: url(#profile-fill);
}

.profile__line {
  fill: none;
  stroke: var(--lamp);
  stroke-width: 2.5;
  stroke-linejoin: round;
}

.profile__marker line {
  stroke: var(--bone);
  stroke-opacity: 0.4;
  stroke-dasharray: 3 4;
}

.profile__marker circle {
  fill: #fff;
  stroke: var(--lamp);
  stroke-width: 3;
}

@media (min-width: 1000px) {
  .courses__stage {
    grid-template-columns: minmax(0, 1.75fr) minmax(320px, 1fr);
    grid-template-areas: "map panel" "profile panel";
  }

  .courses__map {
    aspect-ratio: 2 / 1;
  }

  .courses__panel {
    border-top: 0;
    border-left: 1px solid var(--line);
  }
}

@media (max-width: 560px) {
  .courses__tabs {
    gap: 8px;
  }

  .course-tab {
    gap: 8px;
    padding: 14px 12px;
  }

  .course-tab__name small {
    display: none;
  }

  .courses__actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  }

  .courses__actions .btn {
    padding-inline: 1em;
  }
}

@media (max-width: 380px) {
  .course-tab__km {
    font-size: 2.4rem;
  }

  .course-tab__name {
    font-size: 0.8rem;
  }
}

@media (max-width: 700px) {
  .map__mark {
    transform: scale(2.2);
  }

  .map__scale text {
    font-size: 32px;
  }

  .map__scale path {
    stroke-width: 3;
  }

  .map__ghost {
    stroke-width: 4;
    stroke-dasharray: 4 12;
  }

  .map__track {
    stroke-width: 7;
  }

  .map__halo {
    stroke-width: 22;
  }

  .profile__head {
    padding-inline: 4px;
  }
}
