.racing-page {
  --race-ink: #233d3b;
  --race-line: #bacac2;
  --race-paper: #fffdf4;
  color: var(--race-ink);
  margin: 0;
  background: radial-gradient(ellipse at 15% 0%, #dceacb 0, transparent 45%),
    linear-gradient(145deg, #f5efdf, #e9f0e9);
  font-family: 'Avenir Next Rounded', 'Trebuchet MS', sans-serif;
  min-height: 100svh;
}
.racing-page * {
  box-sizing: border-box;
}
.race-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.racing-page a {
  color: #235e4a;
}
.race-page-header,
.race-page-main {
  max-width: 1220px;
  margin: auto;
  padding: 18px;
}
.race-page-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.race-page-header a {
  padding: 12px 16px;
  border: 1px solid var(--race-line);
  border-radius: 16px;
  background: var(--race-paper);
  font-weight: 800;
  text-decoration: none;
}
.race-page-header p {
  margin: 0;
}
.race-page-main h1 {
  font-size: clamp(30px, 4vw, 52px);
  letter-spacing: -1.5px;
  margin: 8px 0;
}
.race-page-main > .race-lead {
  max-width: 780px;
  line-height: 1.6;
}
.race-kicker {
  font-size: 12px;
  letter-spacing: 2px;
  font-weight: 800;
  color: #46645b;
}
.race-track-links {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin: 24px 0;
}
.race-track-card {
  padding: 20px;
  border: 1px solid var(--race-line);
  border-radius: 24px;
  background: var(--race-paper);
  text-decoration: none;
  box-shadow: 0 8px 0 #274c3f0a;
}
.race-track-card strong {
  display: block;
  font-size: 23px;
  margin: 8px 0;
}
.race-track-card p {
  font-size: 15px;
  line-height: 1.5;
}
.race-track-preview {
  display: block;
  width: 100%;
  aspect-ratio: 1000/650;
  border-radius: 16px;
  object-fit: contain;
  background: #deebd2;
}
.race-track-preview svg {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.race-note {
  font: 15px/1.6 'Trebuchet MS', sans-serif;
  max-width: 900px;
}
.race-game {
  background: #fffdf5;
  border: 1px solid #becfc5;
  border-radius: 28px;
  padding: 20px;
  box-shadow: 0 10px 28px #2846370c;
}
.race-game button {
  font: 800 15px/1.2 'Avenir Next Rounded', 'Trebuchet MS', sans-serif;
  color: #274a40;
  background: #f1f4ea;
  border: 1px solid #b9cabc;
  border-radius: 14px;
  padding: 12px 14px;
  min-height: 48px;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  cursor: pointer;
  touch-action: manipulation;
}
.race-game button:disabled {
  opacity: 0.5;
  cursor: default;
}
.race-game button[aria-pressed='true'] {
  background: #245e4b;
  color: #fff;
}
.race-game button:focus-visible,
.race-game input:focus-visible,
.racing-page a:focus-visible {
  outline: 3px solid #9d5428;
  outline-offset: 4px;
}
.race-dashboard {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.race-dashboard h2 {
  font-size: clamp(23px, 3vw, 36px);
  margin: 6px 0;
  letter-spacing: -0.8px;
}
.race-dashboard p {
  font: 15px/1.4 'Trebuchet MS', sans-serif;
  margin: 0;
  max-width: 670px;
}
.race-speed {
  background: #203e3b;
  color: #fff5db;
  min-width: 100px;
  flex-shrink: 0;
  padding: 10px;
  border-radius: 22px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.race-speed strong {
  font-size: 42px;
  line-height: 1.1;
  display: block;
}
.race-speed span {
  font-size: 10px;
  letter-spacing: 1px;
}
.race-dials {
  display: flex;
  align-items: center;
  gap: 10px;
}
.race-revs {
  min-width: 76px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.race-revs strong {
  display: block;
  font-size: 28px;
  line-height: 1;
}
.race-revs span,
.race-revs small {
  display: block;
  font-size: 9px;
  letter-spacing: 1px;
  margin-top: 4px;
}
.race-rev-meter {
  height: 5px;
  background: #d4dfd4;
  overflow: hidden;
  border-radius: 4px;
  margin-top: 6px;
}
.race-rev-meter i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #2d7960 0%, #c58735 80%, #a34732 100%);
}
.race-modes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}
.race-options-toggle {
  margin: 10px 0;
}
.race-game [hidden] {
  display: none;
}
.race-modes button {
  min-height: 44px;
  font-size: 13px;
}
.race-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 18px;
}
/* Grid/flex auto minimums must not let status copy size the whole document. */
.race-layout > *,
.race-dashboard > *,
.race-controls > *,
.race-instruments > * {
  min-width: 0;
}
.race-stage {
  position: relative;
  isolation: isolate;
  width: 100%;
  aspect-ratio: 1000/650;
  overflow: clip;
  contain: paint;
  border: 2px solid #b6c8b3;
  border-radius: 22px;
  background: var(--race-terrain, #d8e7c4);
}
.race-world {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  will-change: transform;
  pointer-events: none;
}
.race-world > svg {
  display: block;
  width: 100%;
  height: 100%;
}
.race-vehicle,
.race-ghost-car {
  position: absolute;
  width: 7.2%;
  height: 16.62%;
  object-fit: contain;
  pointer-events: none;
  will-change: transform, left, top;
}
.race-car {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(2px 4px 2px #182c2638);
}
.race-ghost-car {
  opacity: 0.34;
  filter: sepia(1) saturate(2) hue-rotate(145deg);
}
.race-brake-lights {
  position: absolute;
  left: 23%;
  right: 23%;
  bottom: 14%;
  height: 5%;
  opacity: 0;
  display: flex;
  justify-content: space-between;
}
.race-brake-lights::before,
.race-brake-lights::after {
  content: '';
  width: 25%;
  height: 100%;
  background: #ff463b;
  border-radius: 50%;
  transform: rotate(30deg);
}
.race-brake-lights::after {
  transform: rotate(-30deg);
}
[data-race-braking='true'] .race-brake-lights {
  opacity: 1;
  filter: drop-shadow(0 0 2px #ff3324);
}
.race-world > .race-skids {
  position: absolute;
  inset: 0;
}
.race-minimap {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 23%;
  aspect-ratio: 1000/650;
  border: 2px solid #fff9df;
  border-radius: 8px;
  overflow: hidden;
  background: #d8e7c4;
  box-shadow: 0 2px 7px #142e3133;
  pointer-events: none;
}
.race-minimap svg {
  width: 100%;
  height: 100%;
  display: block;
}
.race-minimap i {
  position: absolute;
  width: 7px;
  height: 7px;
  transform: translate(-50%, -50%);
  background: #c43e2c;
  border: 1px solid white;
  border-radius: 50%;
}
.race-minimap span {
  position: absolute;
  bottom: 0;
  left: 0;
  font-size: 8px;
  letter-spacing: 1px;
  padding: 2px 4px;
  background: #fff9e8df;
}
.race-minimap .race-minimap-flag {
  background: #ffe07c;
  border-color: #263d35;
  width: 6px;
  height: 6px;
}
[data-race-camera='overview'] .race-minimap {
  display: none;
}
.race-grip {
  position: absolute;
  left: 9px;
  top: 9px;
  background: #183c36df;
  color: #fff5dc;
  border-radius: 6px;
  padding: 5px 7px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1px;
  pointer-events: none;
}
.race-corner {
  position: absolute;
  left: 9px;
  right: 9px;
  bottom: 9px;
  width: fit-content;
  max-width: calc(100% - 18px);
  padding: 6px 9px;
  border-radius: 7px;
  background: #fff8e9ed;
  color: #233d3b;
  font-size: clamp(9px, 1.4vw, 13px);
  font-weight: 800;
  pointer-events: none;
}
.race-next-flag {
  position: absolute;
  transform: translate(-50%, -50%);
  border: 3px solid #fff8df;
  background: #214e42;
  color: #fff;
  min-width: 26px;
  min-height: 26px;
  border-radius: 50%;
  font-size: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  box-shadow: 0 2px 6px #162f3540;
}
.race-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  padding: 16px;
  text-align: center;
  background: #f8f8e8ee;
  overflow-y: auto;
  overscroll-behavior-y: contain;
}
.race-overlay > * {
  flex-shrink: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}
/* Auto margins centre only when there is room, keeping a long title reachable. */
.race-overlay > :first-child {
  margin-top: auto;
}
.race-overlay > :last-child {
  margin-bottom: auto;
}
.race-overlay[hidden],
.race-next-flag[hidden],
.race-instruments [hidden],
.racing-page [hidden] {
  display: none;
}
.race-overlay h3 {
  font-size: clamp(19px, 2.5vw, 30px);
  margin: 0 0 8px;
}
.race-overlay p {
  font: 15px/1.5 'Trebuchet MS', sans-serif;
  max-width: 430px;
  margin: 0 0 14px;
}
.race-overlay button {
  background: #245e4b;
  color: #fff;
  min-width: min(160px, 100%);
}
.race-instruments {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.race-status {
  min-height: 40px;
  font: 14px/1.4 'Trebuchet MS', sans-serif;
  color: #425c54;
  overflow-wrap: anywhere;
}
.race-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.race-wheel-box {
  display: grid;
  place-items: center;
  gap: 10px;
  background: linear-gradient(150deg, #334d47, #1e3532);
  color: #fff5df;
  border-radius: 24px;
  padding: 12px;
}
.race-wheel {
  position: relative;
  width: 106px;
  height: 106px;
  border: 12px solid #142824;
  border-radius: 50%;
  background: #536760;
  box-shadow: inset 0 0 0 3px #9aa59b, 0 4px 8px #071a1740;
  touch-action: none;
  cursor: ew-resize;
  user-select: none;
}
.race-wheel::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 12px;
  left: calc(50% - 4px);
  top: -12px;
  background: #e6c65d;
  border-radius: 2px;
}
.race-wheel i,
.race-wheel b {
  position: absolute;
  background: #b6c1b7;
  display: block;
}
.race-wheel i {
  height: 12px;
  left: 0;
  right: 0;
  top: 35px;
}
.race-wheel b {
  width: 12px;
  left: 35px;
  top: 35px;
  bottom: 0;
}
.race-wheel span {
  position: absolute;
  inset: 22px 13px;
  background: #29423b;
  border-radius: 50%;
  color: #fff;
  font-size: 10px;
  display: grid;
  place-items: center;
}
.race-wheel-box label {
  display: grid;
  text-align: center;
  width: 100%;
  gap: 8px;
  font-size: 12px;
}
.race-wheel-box input {
  width: 100%;
  min-height: 48px;
  accent-color: #285e4c;
  touch-action: none;
  cursor: ew-resize;
}
.race-pedals {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.race-pedals button {
  min-height: 112px;
  display: grid;
  place-items: center;
  gap: 5px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.race-pedals span {
  font-size: 27px;
}
.race-pedals small {
  font: 11px 'Trebuchet MS', sans-serif;
}
.race-pedals .race-brake {
  background: #f6dcd0;
  border-color: #d8a993;
  color: #754331;
  box-shadow: 0 5px 0 #dab7a5;
}
.race-pedals .race-accelerator {
  background: #d6e9cf;
  border-color: #9abd8e;
  color: #26543a;
  box-shadow: 0 5px 0 #afc5a2;
}
.race-pedals button[data-held='true'] {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #8ca38b;
}
.race-help {
  font: 12px/1.4 'Trebuchet MS', sans-serif;
  margin: 0;
  color: #51655d;
}
.race-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.race-actions button {
  font-size: 13px;
  min-height: 48px;
}
.race-result {
  padding: 20px;
  background: #dfecda;
  border-radius: 20px;
  margin: 18px 0;
  outline: none;
}
.race-result a {
  display: inline-block;
  padding: 12px;
}
@media (max-width: 960px) {
  .race-page-header {
    gap: 8px;
  }
  .race-page-header p {
    display: none;
  }
  .race-page-header a {
    display: flex;
    flex: 1 1 0;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 48px;
    padding: 10px 12px;
    line-height: 1.35;
    text-align: center;
    overflow-wrap: anywhere;
  }
}
@media (max-width: 800px) {
  .race-game .race-kicker {
    font-size: 10px;
    letter-spacing: 1px;
  }
  .race-dials {
    gap: 6px;
  }
  .race-revs {
    min-width: 48px;
  }
  .race-revs strong {
    font-size: 24px;
  }
  .race-stage {
    max-width: 100%;
    margin-inline: auto;
  }
  .race-page-header p,
  .race-dashboard p,
  .race-help {
    display: none;
  }
  .race-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .race-actions button {
    flex: 1 1 110px;
    min-height: 52px;
    padding: 8px 4px;
    font-size: 11px;
  }
  .race-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .race-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .race-wheel-box {
    grid-row: span 2;
  }
  .race-pedals button {
    min-height: 104px;
  }
  .race-help,
  .race-actions {
    grid-column: 1/-1;
  }
  .race-wheel {
    width: 90px;
    height: 90px;
    border-width: 10px;
  }
  .race-wheel i {
    top: 29px;
  }
  .race-wheel b {
    left: 29px;
    top: 29px;
  }
  .race-wheel span {
    inset: 18px 10px;
  }
  .race-game {
    padding: 14px;
    border-radius: 22px;
  }
  .race-page-main {
    padding: 12px;
  }
  .race-speed {
    min-width: 76px;
  }
  .race-speed strong {
    font-size: 34px;
  }
  .race-track-links {
    grid-template-columns: minmax(0, 1fr);
  }
  .race-track-card {
    display: grid;
    grid-template-columns: 100px minmax(0, 1fr);
    column-gap: 16px;
  }
  .race-track-preview {
    grid-row: span 3;
    align-self: center;
  }
  .race-track-card strong {
    font-size: 21px;
  }
  .race-track-card p {
    margin: 0;
  }
  .race-page-header {
    padding: 12px;
    font-size: 13px;
  }
  .race-dashboard p {
    font-size: 13px;
  }
  .race-overlay p {
    font-size: 12px;
    margin-bottom: 10px;
  }
  .race-overlay h3 {
    font-size: 19px;
  }
  .race-overlay button {
    min-height: 44px;
    padding: 10px;
  }
  .race-instruments {
    font-size: 12px;
  }
}
@media (max-width: 540px) {
  .race-page-header a {
    flex-basis: calc((100% - 8px) / 2);
  }
  .race-dashboard {
    flex-wrap: wrap;
    gap: 10px;
  }
  .race-dashboard > :first-child {
    flex: 1 1 140px;
  }
  .race-dials {
    margin-inline-start: auto;
  }
  .race-controls {
    grid-template-columns: minmax(0, 1fr);
  }
  .race-wheel-box {
    grid-row: auto;
    grid-template-columns: 90px minmax(0, 1fr);
  }
}
@media (max-width: 800px) and (min-height: 501px) {
  /* Only ready/paused screens grow; driving keeps the track's original ratio. */
  .race-stage:has(> .race-overlay:not([hidden])) {
    min-height: 240px;
  }
}
@media (max-width: 800px) and (max-height: 500px) {
  .race-stage {
    max-width: min(100%, max(220px, calc((100svh - 195px) * 1.53846)));
  }
}
@media (min-width: 801px) and (max-height: 960px) {
  .race-layout {
    grid-template-columns: minmax(0, 1fr) 260px;
  }
  .race-stage {
    max-width: min(100%, max(260px, calc((100svh - 380px) * 1.53846)));
    margin-inline: auto;
  }
  .race-dashboard p {
    display: none;
  }
  .race-wheel-box {
    padding: 8px;
  }
  .race-wheel {
    width: 78px;
    height: 78px;
    border-width: 9px;
  }
  .race-wheel i {
    top: 24px;
  }
  .race-wheel b {
    left: 24px;
    top: 24px;
  }
  .race-wheel span {
    inset: 14px 8px;
  }
  .race-controls {
    gap: 8px;
  }
  .race-pedals button {
    min-height: 88px;
  }
  .race-help {
    display: none;
  }
  .race-game {
    padding: 14px;
  }
  .race-modes {
    margin: 10px 0;
  }
  .race-page-main > .race-lead {
    display: none;
  }
}
@media (min-width: 700px) and (max-height: 500px) {
  .race-revs {
    display: grid;
    grid-template-columns: 18px 52px;
    min-width: 70px;
    gap: 0;
    align-items: center;
  }
  .race-revs strong {
    grid-row: span 3;
    font-size: 21px;
  }
  .race-revs span,
  .race-revs small {
    font-size: 7px;
    line-height: 9px;
    margin: 0;
    white-space: nowrap;
  }
  .race-rev-meter {
    height: 3px;
    margin: 2px 0;
  }
  .race-options-toggle {
    min-height: 44px;
    margin: 0 0 6px;
    padding: 6px 10px;
    font-size: 11px;
  }
  .race-page-header {
    padding: 6px 12px;
  }
  .race-page-header p {
    display: none;
  }
  .race-page-header a {
    padding: 8px 12px;
    font-size: 12px;
  }
  .race-page-main {
    padding: 4px 8px;
  }
  .race-game {
    padding: 8px;
  }
  .race-dashboard {
    min-height: 36px;
  }
  .race-dashboard h2 {
    font-size: 20px;
    margin: 0;
  }
  .race-dashboard .race-kicker,
  .race-dashboard p {
    display: none;
  }
  .race-speed {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 80px;
    padding: 4px 8px;
    border-radius: 12px;
  }
  .race-speed strong {
    font-size: 25px;
  }
  .race-speed span {
    font-size: 8px;
  }
  .race-modes {
    margin: 6px 0;
    gap: 4px;
  }
  .race-modes button {
    font-size: 10px;
    min-height: 48px;
    padding: 6px 8px;
  }
  .race-layout {
    grid-template-columns: minmax(0, 1fr) 260px;
    gap: 10px;
  }
  .race-stage {
    max-width: min(100%, max(190px, calc((100svh - 195px) * 1.53846)));
  }
  .race-controls {
    display: flex;
    gap: 6px;
  }
  .race-wheel-box {
    padding: 4px 8px;
    gap: 0;
  }
  .race-wheel {
    display: none;
  }
  .race-wheel-box label {
    gap: 0;
    font-size: 10px;
  }
  .race-wheel-box input {
    min-height: 48px;
  }
  .race-pedals {
    gap: 8px;
  }
  .race-pedals button {
    padding: 4px;
    min-height: 74px;
    gap: 3px;
  }
  .race-pedals span {
    font-size: 19px;
  }
  .race-pedals strong {
    font-size: 12px;
  }
  .race-pedals small {
    font-size: 9px;
  }
  .race-help {
    display: none;
  }
  .race-controls > [data-race-tap] {
    min-height: 48px;
    padding: 6px;
    font-size: 11px;
  }
  .race-actions {
    display: flex;
    gap: 4px;
  }
  .race-actions button {
    flex: 1;
    min-height: 48px;
    font-size: 10px;
    padding: 4px;
  }
  .race-instruments {
    margin-top: 6px;
    font-size: 11px;
  }
  .race-status {
    min-height: 0;
    margin: 6px 0 0;
    font-size: 11px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .race-car {
    will-change: auto;
  }
}
