.racer-page {
  max-width: 700px;
  margin-inline: auto;
  padding-block: 6px 40px;
}

body.is-racing {
  overflow: hidden;
}

.racer-intro {
  margin-bottom: 10px;
}

.racer-intro h1 {
  margin-bottom: 3px;
  font-size: clamp(30px, 7vw, 40px);
  letter-spacing: -1.8px;
  line-height: 1.1;
}

.racer-intro p,
.racer-how-to-play p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.ad-space {
  min-height: 34px;
  margin-block: 8px;
}

.race-panel {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 8px;
  border: 2px solid #342d72;
  border-radius: 14px;
  background: #e8e4c9;
  box-shadow: 0 8px 0 #b6b091;
}

.race-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
}

.race-stat {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 5px 2px;
  border: 1px solid #342d72;
  border-radius: 6px;
  background: #fffbe6;
  color: #28224f;
  text-align: center;
}

.race-stat span {
  font-size: 12px;
  font-weight: 700;
}

.race-stat strong {
  font-size: clamp(14px, 4vw, 18px);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.pitstop-progress {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 76px;
  align-items: center;
  gap: 8px;
  color: #28224f;
  font-size: 12px;
  font-weight: 700;
}

.pitstop-progress progress {
  width: 100%;
  height: 10px;
  accent-color: #e8a82b;
}

.race-screen {
  height: min(46svh, 400px);
  min-height: 280px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 3px solid #17163d;
  border-radius: 7px;
  background: #211f4e;
}

.race-road {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(90deg, #656a72, #777c84 50%, #656a72);
  isolation: isolate;
}

.race-road::before,
.race-road::after {
  position: absolute;
  z-index: 1;
  top: 0;
  bottom: 0;
  width: clamp(12px, 5%, 18px);
  background: repeating-linear-gradient(
    to bottom,
    #e94c54 0 14px,
    #fffbe6 14px 28px
  );
  animation: road-scroll var(--road-scroll-duration, 0.56s) linear infinite;
  content: "";
  pointer-events: none;
}

.race-road::before {
  left: 0;
}

.race-road::after {
  right: 0;
}

.lane-divider {
  position: absolute;
  z-index: 1;
  top: 0;
  bottom: 0;
}

.lane-divider-center {
  left: 50%;
  width: 4px;
  background: repeating-linear-gradient(
    to bottom,
    #fff 0 14px,
    transparent 14px 28px
  );
  animation: road-scroll var(--road-scroll-duration, 0.56s) linear infinite;
  opacity: 0.95;
  transform: translateX(-50%);
}

.player-car,
.traffic-car {
  position: absolute;
  z-index: 2;
  left: 50%;
  width: 11%;
  height: 8%;
  min-height: 18px;
  border: 2px solid #171a20;
  border-radius: 7px 7px 4px 4px;
  transform: translate(-50%, -50%);
}

.player-car {
  top: 84%;
  background: #f3cb45;
  box-shadow: inset 0 -3px 0 #d89225;
  transition: left 90ms steps(2, end);
}

.player-car::before,
.player-car::after,
.traffic-car::before,
.traffic-car::after {
  position: absolute;
  top: 22%;
  width: 5px;
  height: 56%;
  border-radius: 2px;
  background: #171a20;
  content: "";
}

.player-car::before,
.traffic-car::before {
  left: -4px;
}

.player-car::after,
.traffic-car::after {
  right: -4px;
}

.car-window {
  position: absolute;
  top: 15%;
  left: 22%;
  width: 56%;
  height: 32%;
  border: 1px solid #15143a;
  border-radius: 3px;
  background: #8ce2d2;
}

.car-light {
  position: absolute;
  bottom: 12%;
  width: 14%;
  height: 15%;
  border-radius: 2px;
  background: #fff4ad;
}

.car-light-left {
  left: 13%;
}

.car-light-right {
  right: 13%;
}

.traffic-car {
  background: #ed6652;
  box-shadow: inset 0 -3px 0 #b94355;
}

.traffic-car .car-window {
  top: auto;
  bottom: 18%;
  background: #8ce2d2;
}

.player-car.is-invulnerable {
  animation: repair-flash 180ms steps(2, end) infinite;
}

@keyframes repair-flash {
  50% {
    opacity: 0.35;
  }
}

.race-status {
  min-width: 0;
  min-height: 44px;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 4px 8px;
  border-radius: 5px;
  background: #28224f;
  color: #fffbe6;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
}

.race-status-row {
  min-height: 44px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.lane-controls {
  position: absolute;
  z-index: 4;
  inset-inline: 3px;
  bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.lane-button {
  width: 64px;
  height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 0;
  border: 3px solid rgb(255 251 230 / 88%);
  border-radius: 50%;
  background: rgb(23 22 61 / 56%);
  box-shadow: 0 2px 7px rgb(0 0 0 / 38%);
  color: #fffbe6;
  cursor: pointer;
  font: inherit;
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
  pointer-events: auto;
  touch-action: manipulation;
  text-shadow: 0 1px 2px rgb(21 20 58 / 90%);
  -webkit-tap-highlight-color: transparent;
}

.lane-button-label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.lane-button.is-active,
.lane-button:focus-visible {
  border-color: #fffbe6;
  background: rgb(237 102 82 / 68%);
  color: #fffbe6;
  transform: scale(0.94);
}

.lane-button:focus-visible,
.race-actions button:focus-visible,
.sound-toggle:focus-visible {
  outline: 3px solid #6b50c9;
  outline-offset: 3px;
}

.lane-button:disabled {
  cursor: default;
  opacity: 0.7;
}

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

.race-actions .button {
  min-width: 76px;
  min-height: 44px;
  padding-inline: 10px;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  touch-action: manipulation;
}

.race-actions button:disabled {
  display: none;
}

.race-actions button[hidden] {
  display: none;
}

.sound-toggle {
  width: 76px;
  min-width: 76px;
  min-height: 44px;
  padding: 0 4px;
  background: #fffbe6;
  color: #28224f;
  border: 2px solid #342d72;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  touch-action: manipulation;
}

.sound-toggle:disabled {
  cursor: default;
}

.sound-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.racer-how-to-play,
.related-games-section {
  margin-top: 24px;
}

.racer-how-to-play h2 {
  margin-bottom: 8px;
  font-size: 20px;
}

.racer-how-to-play p {
  color: #565267;
}

.related-games-section h2 {
  margin-bottom: 8px;
  font-size: 20px;
}

.ad-space-after-game {
  margin-top: 18px;
}

@media (max-height: 700px) {
  .racer-page {
    padding-top: 2px;
  }

  .racer-intro {
    margin-bottom: 6px;
  }

  .ad-space {
    min-height: 24px;
    margin-block: 5px;
  }

  .race-panel {
    gap: 5px;
    padding: 6px;
  }

  .race-screen {
    height: min(42svh, 300px);
    min-height: 220px;
  }

  .lane-controls {
    inset-inline: 3px;
    bottom: 4px;
  }

  .lane-button {
    width: 56px;
    height: 56px;
  }
}

@media (max-width: 520px) {
  .racer-page {
    padding-block: 4px 32px;
  }

  .race-panel {
    gap: 6px;
    padding: 6px;
  }

  .race-screen {
    height: min(50svh, 400px);
    min-height: 280px;
  }

  .lane-controls {
    inset-inline: 3px;
    bottom: 4px;
  }

  .lane-button {
    width: 60px;
    height: 60px;
  }
}

@media (max-width: 520px) and (max-height: 700px) {
  .race-screen {
    height: min(36svh, 260px);
    min-height: 220px;
  }
}

@media (max-height: 600px) {
  .site-header {
    height: 56px;
  }

  .ad-space:not(.ad-space-after-game) {
    display: none;
  }

  .racer-page {
    padding-top: 0;
  }

  .race-screen {
    height: min(39svh, 250px);
    min-height: 210px;
  }

  .lane-controls {
    inset-inline: 3px;
    bottom: 4px;
  }

  .lane-button {
    width: 52px;
    height: 52px;
  }
}

@media (max-width: 520px) and (max-height: 600px) {
  .racer-intro h1 {
    font-size: clamp(26px, 8vw, 30px);
    letter-spacing: -1.2px;
    white-space: nowrap;
  }

  .racer-intro p {
    display: none;
  }

  .race-screen {
    height: min(38svh, 240px);
    min-height: 205px;
  }
}

@media (max-width: 520px) and (max-height: 520px) {
  .site-header {
    height: 48px;
  }

  .racer-intro {
    margin-bottom: 4px;
  }

  .breadcrumbs {
    margin-bottom: 4px;
  }

  .race-panel {
    gap: 4px;
    padding: 5px;
  }

  .race-screen {
    height: min(36svh, 200px);
    min-height: 185px;
  }
}

@media (min-width: 521px) and (min-height: 601px) and (max-height: 840px) {
  .racer-page {
    padding-top: 2px;
  }

  .racer-intro {
    margin-bottom: 6px;
  }

  .ad-space:not(.ad-space-after-game) {
    display: none;
  }

  .race-panel {
    gap: 5px;
    padding: 6px;
  }

  .race-screen {
    height: min(40svh, 340px);
    min-height: 220px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .race-road::before,
  .race-road::after,
  .lane-divider-center {
    animation: none;
  }

  .lane-button {
    transition: none;
  }

  .player-car {
    transition: none;
  }

  .player-car.is-invulnerable {
    animation: none;
    outline: 3px solid #fffbe6;
  }

  .lane-button.is-active,
  .lane-button:focus-visible {
    transform: none;
  }
}

@keyframes road-scroll {
  to {
    background-position: 0 28px;
  }
}
