:root {
  color-scheme: dark;
  --ink: #211812;
  --paper: #f2d78b;
  --cream: #ffe8af;
  --amber: #f3a83b;
  --red: #d84b39;
  --cyan: #3ad2c6;
  --green: #61b85a;
  --violet: #6b5fb5;
  --shadow: rgba(10, 7, 5, 0.72);
  --line: rgba(255, 230, 171, 0.34);
  font-family: "Trebuchet MS", "Arial Narrow", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  min-height: 100%;
  background: #102a31;
  overscroll-behavior: none;
}

body {
  margin: 0;
  min-height: 100svh;
  overflow: hidden;
  background:
    radial-gradient(circle at 10% 8%, rgba(58, 210, 198, 0.2), transparent 26%),
    radial-gradient(circle at 84% 18%, rgba(216, 75, 57, 0.18), transparent 24%),
    linear-gradient(135deg, #150f0c 0%, #2a171f 42%, #102a31 100%);
  color: var(--cream);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

button {
  border: 2px solid #321d13;
  background: linear-gradient(#ffe3a0, #d78a32);
  color: #24140e;
  font: 900 0.95rem/1 "Trebuchet MS", Arial, sans-serif;
  min-height: 42px;
  cursor: pointer;
  box-shadow: 0 4px 0 #6f2e22;
  touch-action: manipulation;
  user-select: none;
}

button:hover,
button:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 2px;
}

button:active,
button.pressed {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #6f2e22;
}

.game-shell {
  width: min(1180px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(280px, 1fr) auto;
  gap: 10px;
  padding: 14px;
}

.rotate-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 24px;
  padding:
    max(24px, env(safe-area-inset-top))
    max(24px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(24px, env(safe-area-inset-left));
  background:
    linear-gradient(rgba(10, 7, 5, 0.84), rgba(10, 7, 5, 0.84)),
    linear-gradient(135deg, #150f0c, #102a31);
  text-align: center;
}

.rotate-overlay > div {
  width: min(340px, 100%);
  border: 3px solid var(--line);
  background: rgba(22, 12, 8, 0.92);
  padding: 18px;
  box-shadow: 0 10px 0 rgba(10, 7, 5, 0.42);
}

.rotate-overlay h2 {
  margin: 0 0 16px;
  color: var(--cream);
  font-size: 1.65rem;
  line-height: 1;
  text-transform: uppercase;
  text-shadow: 3px 3px 0 #64271e;
}

#fullscreenStart {
  width: 100%;
  padding: 0 12px;
}

.topbar,
.bottom-panel {
  border: 2px solid var(--line);
  background: rgba(22, 12, 8, 0.78);
  box-shadow: 0 8px 0 rgba(10, 7, 5, 0.25);
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
}

.kicker {
  margin: 0 0 2px;
  color: var(--cyan);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 2.5rem);
  letter-spacing: 0;
  line-height: 0.95;
  text-transform: uppercase;
  text-shadow: 3px 3px 0 #64271e;
}

.hud {
  display: grid;
  grid-template-columns: repeat(3, minmax(76px, 1fr));
  gap: 8px;
  width: min(390px, 48%);
}

.hud div {
  min-width: 0;
  border: 2px solid rgba(255, 230, 171, 0.24);
  background: rgba(7, 20, 24, 0.78);
  padding: 8px 9px;
  text-align: right;
}

.hud span,
.hud strong {
  display: block;
}

.hud span {
  color: rgba(255, 232, 175, 0.72);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.hud strong {
  color: var(--paper);
  font-size: clamp(1.05rem, 2.5vw, 1.6rem);
  line-height: 1.02;
}

.stage {
  position: relative;
  min-height: 280px;
  overflow: hidden;
  border: 3px solid #140b08;
  background: #090705;
  box-shadow: 0 16px 36px var(--shadow);
}

.race-canvas {
  width: 100%;
  height: 100%;
  min-height: 100%;
  display: block;
  background: #090705;
  image-rendering: auto;
}

.race-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255, 232, 175, 0.06) 50%, rgba(0, 0, 0, 0.06) 50%),
    radial-gradient(circle at 50% 44%, transparent 0 56%, rgba(6, 4, 3, 0.34) 100%);
  background-size: 100% 4px, 100% 100%;
  mix-blend-mode: screen;
}

.message {
  position: absolute;
  left: 14px;
  right: 14px;
  top: 14px;
  min-height: 0;
  padding: 0;
  color: #1d120d;
  background: transparent;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
}

.message.visible {
  opacity: 1;
  padding: 10px 12px;
  border: 2px solid #321d13;
  background: #ffe4a1;
}

.touch-controls {
  position: absolute;
  inset: auto 14px 14px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  pointer-events: none;
  z-index: 3;
}

.pedals,
.steering {
  display: grid;
  gap: 12px;
  pointer-events: auto;
}

.pedals {
  grid-template-columns: 1fr;
}

.steering {
  grid-template-columns: repeat(2, 1fr);
}

.touch-controls button {
  width: clamp(58px, 15vw, 76px);
  height: clamp(58px, 15vw, 76px);
  min-height: 0;
  border-radius: 50%;
  border-color: rgba(255, 232, 175, 0.86);
  background: rgba(16, 42, 49, 0.74);
  color: var(--cream);
  font-size: clamp(1.2rem, 6vw, 1.8rem);
  box-shadow: 0 5px 0 rgba(6, 4, 3, 0.72);
  -webkit-tap-highlight-color: transparent;
}

.touch-controls button.pressed {
  background: rgba(58, 210, 198, 0.84);
  color: #102a31;
}

.bottom-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
}

.radio-line {
  display: grid;
  grid-template-columns: 54px 1fr;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.portrait {
  width: 46px;
  height: 46px;
  border: 2px solid #0b0705;
  background:
    linear-gradient(135deg, transparent 0 46%, #211812 47% 52%, transparent 53%),
    radial-gradient(circle at 52% 36%, #ffe0a1 0 24%, transparent 25%),
    linear-gradient(160deg, var(--red), var(--violet));
}

#radioText {
  margin: 0;
  min-width: 0;
  color: var(--cream);
  font-size: clamp(0.95rem, 2vw, 1.08rem);
  font-weight: 800;
  line-height: 1.35;
}

.actions {
  display: flex;
  justify-content: end;
}

#restart {
  width: 98px;
  padding: 0 12px;
}

@media (pointer: fine) and (min-width: 761px) {
  .touch-controls {
    display: none;
  }
}

@media (pointer: coarse) {
  body {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
  }

  .touch-controls {
    display: flex;
  }
}

@media (max-width: 760px) {
  .game-shell {
    padding: 8px;
    gap: 8px;
    grid-template-rows: auto minmax(360px, 1fr) auto;
  }

  .topbar {
    align-items: start;
  }

  .hud {
    width: min(100%, 330px);
    grid-template-columns: repeat(3, minmax(58px, 1fr));
  }

  .hud div {
    padding: 6px 7px;
  }

  .stage {
    min-height: 360px;
  }

  .bottom-panel {
    grid-template-columns: 1fr;
  }

  .actions {
    justify-content: stretch;
  }

  #restart {
    width: 100%;
  }
}

@media (pointer: coarse) and (orientation: portrait), (orientation: portrait) and (max-width: 520px) {
  .rotate-overlay {
    display: grid;
  }
}

@media (pointer: coarse) and (orientation: landscape), (orientation: landscape) and (max-height: 520px) {
  body {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
  }

  .game-shell {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr);
    padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
      max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  .topbar {
    align-items: center;
    padding: 6px 8px;
  }

  .kicker {
    font-size: 0.62rem;
  }

  h1 {
    font-size: clamp(1rem, 4vw, 1.45rem);
  }

  .hud {
    width: min(420px, 56%);
    grid-template-columns: repeat(3, minmax(54px, 1fr));
    gap: 6px;
  }

  .hud div {
    padding: 5px 7px;
  }

  .hud span {
    font-size: 0.58rem;
  }

  .hud strong {
    font-size: clamp(0.92rem, 3vw, 1.22rem);
  }

  .stage {
    min-height: 0;
  }

  .bottom-panel {
    display: none;
  }

  .touch-controls {
    display: flex;
    inset: auto 14px max(12px, env(safe-area-inset-bottom));
  }

  .touch-controls button {
    width: clamp(52px, 11vw, 68px);
    height: clamp(52px, 11vw, 68px);
  }
}

@media (max-width: 520px) {
  .topbar {
    display: block;
  }

  .hud {
    width: 100%;
    margin-top: 10px;
  }

  .radio-line {
    grid-template-columns: 44px 1fr;
  }

  .portrait {
    width: 38px;
    height: 38px;
  }

  .touch-controls {
    inset: auto 10px 10px;
  }

  .pedals,
  .steering {
    gap: 8px;
  }
}
