.race-game {
  max-width: 760px;
  margin: auto;
  --aqua: #8cf1da;
  color: #f3f7e8;
}
.race-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  padding: 13px 16px;
  background:
    linear-gradient(95deg, #122f37eb, #16333db0),
    url('./assets/world-panoramas.webp') center 66.67%/100% 400%;
  border: 1px solid #497676;
  border-radius: 10px;
}
.race-top h2 {
  margin: 2px 0;
  font-size: clamp(19px, 4.5vw, 30px);
}
.race-top small {
  color: #baf1df;
  font-weight: bold;
}
.race-clock {
  font:
    700 clamp(16px, 3vw, 24px) ui-monospace,
    monospace;
  white-space: nowrap;
}
.race-ribbon {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 9px 2px;
  font-size: 0.84rem;
}
.race-driver {
  color: #ffdfa7;
  font-weight: bold;
}
.race-ghost {
  color: #a7dce3;
}
.race-track {
  width: 100%;
  height: auto;
  display: block;
  background: #164d60;
  border: 1px solid #588991;
  border-radius: 10px;
}
.race-status {
  color: var(--aqua);
  font-weight: 700;
  margin: 8px 0;
  min-height: 1.4em;
}
.race-controls {
  display: grid;
  grid-template-columns: 1fr 0.8fr 1fr;
  gap: 7px;
}
.race-game button {
  border: 1px solid #6a9490;
  border-radius: 9px;
  background: #25464e;
  color: inherit;
  min-height: 46px;
  font-weight: 700;
  touch-action: none;
  user-select: none;
}
.race-game button.held,
.race-game button:active {
  background: #416d70;
}
.race-game .race-go {
  width: 100%;
  margin-top: 8px;
  color: #143238;
  background: #a7ebca;
}
.race-help {
  font-size: 0.86rem;
  color: #c7d6cf;
  line-height: 1.4;
}

.race-driver {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.race-driver .face {
  display: inline-block;
  width: 34px;
  height: 26px;
}

.race-course {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}
.race-course select {
  max-width: 100%;
  color: inherit;
  background: #25464e;
  border: 1px solid #6a9490;
  border-radius: 4px;
  padding: 6px;
  font: inherit;
}
.race-course:has(select:disabled) {
  display: none;
}

/* Phone held sideways: the track takes the full height, the controls sit beside it.
   The side column has a fixed height and the status line gives way first,
   so the steering buttons and «Старт» stay on screen whatever the font. */
@media (orientation: landscape) and (max-height: 540px) {
  .race-game {
    display: grid;
    grid-template-columns: auto minmax(200px, 1fr);
    grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
    column-gap: 10px;
    height: calc(100svh - 62px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
  .race-game > * { grid-column: 2; min-width: 0; }
  .race-game > .race-track {
    grid-column: 1;
    grid-row: 1 / -1;
    align-self: start;
    width: min(calc(100vw - 250px - env(safe-area-inset-left) - env(safe-area-inset-right)),
      calc((100svh - 66px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 1.712));
    height: auto;
  }
  .race-game .race-top { padding: 4px 6px; min-height: 0; }
  .race-game .race-top h2 { font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .race-game .race-course { flex-wrap: wrap; height: auto; }
  .race-game .race-course select { flex: 1; min-width: 0; }
  .race-game .race-ribbon { flex-wrap: wrap; gap: 2px 8px; }
  .race-game .race-status { grid-row: 4; overflow: hidden; margin: 4px 0; font-size: 0.8rem; }
  .race-game .race-controls { grid-row: 5; }
  .race-game .race-controls button { min-height: 40px; }
  .race-game .race-go { grid-row: 6; min-height: 40px; margin-top: 6px; }
  .race-game .race-help { display: none; }
}
