:root {
  color-scheme: dark;
  --yellow: #ffdc25;
  --panel: rgba(9, 20, 17, .78);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #163d25;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
  user-select: none;
}

.game-shell { position: fixed; inset: 0; overflow: hidden; }

#race-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.topbar {
  position: fixed;
  z-index: 5;
  top: 18px;
  left: 20px;
  right: 20px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  pointer-events: none;
}

.home-button,
.reset-button {
  width: max-content;
  min-height: 42px;
  padding: 0 15px;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 99px;
  color: white;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(0,0,0,.24);
  font: inherit;
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .025em;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  backdrop-filter: blur(10px);
  pointer-events: auto;
}

.home-button:hover,
.reset-button:hover { background: rgba(17, 36, 31, .95); }

.reset-button { justify-self: end; cursor: pointer; }
.reset-button kbd { color: #182b25; background: var(--yellow); }

.game-title {
  padding: 10px 17px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 99px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  font-size: .85rem;
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
  backdrop-filter: blur(10px);
}

.race-hud {
  position: fixed;
  z-index: 5;
  top: 76px;
  left: 50%;
  display: flex;
  align-items: stretch;
  gap: 21px;
  padding: 12px 19px;
  border: 1px solid rgba(255,255,255,.19);
  border-radius: 18px;
  color: white;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  transform: translateX(-50%);
  backdrop-filter: blur(10px);
}

.hud-block {
  min-width: 48px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}

.hud-block span {
  color: rgba(255,255,255,.57);
  font-size: .59rem;
  font-weight: 800;
  letter-spacing: .11em;
  text-transform: uppercase;
}

.hud-block strong { font-variant-numeric: tabular-nums; font-size: .91rem; }
.speed-block { min-width: 62px; align-items: flex-end; }
.speed-block strong { color: var(--yellow); font-size: 1.6rem; line-height: .9; }
.speed-block span { font-size: .52rem; }
.hud-divider { width: 1px; background: rgba(255,255,255,.17); }
.timer-block { min-width: 87px; }
.best-block { min-width: 87px; }

.countdown {
  position: fixed;
  z-index: 4;
  top: 50%;
  left: 50%;
  color: white;
  font-size: clamp(5rem, 14vw, 10rem);
  font-weight: 1000;
  line-height: 1;
  text-shadow: 0 9px 0 rgba(0,0,0,.18), 0 0 48px rgba(255, 220, 37, .45);
  transform: translate(-50%, -50%);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}

.countdown.go { color: var(--yellow); }
.countdown.hidden { opacity: 0; transform: translate(-50%, -50%) scale(1.35); }

.track-message {
  position: fixed;
  z-index: 4;
  left: 50%;
  bottom: 31px;
  padding: 9px 15px;
  border-radius: 99px;
  color: #203128;
  background: var(--yellow);
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  font-size: .75rem;
  font-weight: 900;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: .25s ease;
  pointer-events: none;
}

.track-message.visible { opacity: 1; transform: translate(-50%, 0); }
.track-message.drifting { color: #102b31; background: #d8f8ff; }

.controls-card {
  position: fixed;
  z-index: 5;
  left: 20px;
  bottom: 20px;
  display: grid;
  grid-template-columns: auto auto;
  gap: 8px 14px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 17px;
  color: white;
  background: var(--panel);
  box-shadow: 0 9px 28px rgba(0,0,0,.22);
  backdrop-filter: blur(10px);
}

.controls-label {
  grid-column: 1 / -1;
  color: rgba(255,255,255,.56);
  font-size: .6rem;
  font-weight: 900;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.key-layout { display: grid; gap: 4px; justify-items: center; }
.key-layout > div { display: flex; gap: 4px; }

kbd {
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border: 1px solid rgba(255,255,255,.35);
  border-bottom-width: 3px;
  border-radius: 6px;
  color: white;
  background: rgba(255,255,255,.12);
  font: inherit;
  font-size: .68rem;
  font-weight: 900;
  display: inline-grid;
  place-items: center;
}

kbd.active { color: #172a23; border-color: #fff3a8; background: var(--yellow); transform: translateY(2px); border-bottom-width: 1px; }

.controls-card p { margin: 0; color: rgba(255,255,255,.66); font-size: .63rem; line-height: 1.65; }
.controls-card p b { color: white; }
.controls-card p kbd { min-width: 41px; height: 19px; margin-top: 3px; border-bottom-width: 2px; font-size: .55rem; vertical-align: middle; }

.touch-controls { display: none; }

@media (max-width: 680px), (pointer: coarse) {
  .topbar { top: 12px; left: 12px; right: 12px; grid-template-columns: 1fr 1fr; }
  .game-title { display: none; }
  .home-button, .reset-button { min-height: 38px; padding: 0 12px; font-size: .7rem; }
  .race-hud { top: 62px; gap: 13px; padding: 10px 13px; border-radius: 15px; }
  .hud-block { min-width: 37px; }
  .speed-block { min-width: 52px; }
  .speed-block strong { font-size: 1.35rem; }
  .timer-block { min-width: 77px; }
  .best-block { display: none; }
  .controls-card { display: none; }
  .track-message { bottom: 132px; }
  .touch-controls { position: fixed; z-index: 6; left: 16px; right: 16px; bottom: 18px; display: flex; justify-content: space-between; pointer-events: none; }
  .touch-controls > div { display: flex; gap: 10px; }
  .touch-controls button {
    width: 62px;
    height: 62px;
    border: 1px solid rgba(255,255,255,.3);
    border-bottom-width: 4px;
    border-radius: 19px;
    color: white;
    background: rgba(9, 20, 17, .73);
    font-size: 1.6rem;
    font-weight: 900;
    box-shadow: 0 8px 24px rgba(0,0,0,.25);
    backdrop-filter: blur(8px);
    pointer-events: auto;
  }
  .touch-controls button.active { color: #172a23; border-color: #fff3a8; background: var(--yellow); transform: translateY(2px); }
}

@media (max-width: 390px) {
  .race-hud { gap: 9px; }
  .hud-divider { display: none; }
  .touch-controls button { width: 56px; height: 56px; }
}
