:root {
  color-scheme: dark;
  --bg: #0b1017;
  --panel: #141e2a;
  --line: #2a394b;
  --muted: #aab8c8;
  --yellow: #eaff75;
  --green: #8cffc1;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background:
    radial-gradient(ellipse at 80% 0, #21343a 0, transparent 45%), var(--bg);
  color: #f5f7fa;
  font-family: Arial, Helvetica, sans-serif;
}
button,
select,
a {
  -webkit-tap-highlight-color: transparent;
}
button,
select {
  font: inherit;
}
button {
  cursor: pointer;
}
button:focus-visible,
a:focus-visible,
select:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 4px;
}
button:disabled {
  opacity: 0.4;
  cursor: default;
}
.topbar {
  max-width: 1160px;
  margin: auto;
  padding: 24px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
}
a {
  color: inherit;
  text-decoration: none;
}
.brand {
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 1px;
}
.brand span {
  display: block;
  font-size: 9px;
  letter-spacing: 3px;
  margin-top: 5px;
  color: var(--muted);
}
.back {
  font-size: 13px;
  color: var(--muted);
}
main {
  max-width: 1100px;
  margin: auto;
  padding: 36px 24px;
}
.intro {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
  gap: 15px;
}
.eyebrow {
  font-size: 10px;
  letter-spacing: 2.5px;
  color: var(--green);
  font-weight: bold;
}
h1 {
  font-size: clamp(28px, 5vw, 54px);
  letter-spacing: -2px;
  line-height: 1;
  margin: 12px 0;
}
h1 em {
  font-style: normal;
  color: var(--yellow);
}
.subtitle {
  color: var(--muted);
  font-size: 14px;
}
.badge {
  font-size: 45px;
  font-weight: 900;
  text-align: center;
  border: 1px solid var(--line);
  padding: 12px 18px;
  transform: rotate(4deg);
  border-radius: 12px;
}
.badge span {
  display: block;
  font-size: 8px;
  letter-spacing: 2px;
}
.game {
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: 0 25px 70px #0004;
}
.hud {
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 17px 22px;
  background: #111923;
}
.hud div span {
  display: block;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 1.5px;
}
.hud strong {
  font-size: 24px;
  display: block;
  margin-top: 5px;
  font-variant-numeric: tabular-nums;
}
.hud button {
  margin-left: auto;
}
.hud button,
.game__footer button {
  background: #223244;
  border: 1px solid #405369;
  color: white;
  border-radius: 8px;
  padding: 9px 13px;
  font-size: 12px;
}
.viewport {
  height: 440px;
  position: relative;
  background: radial-gradient(ellipse at center, #2b4146, #15212e);
  overflow: hidden;
}
.viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
  padding: 20px;
  background: #0c1728dd;
  backdrop-filter: blur(6px);
}
[hidden] {
  display: none !important;
}
.overlay h2 {
  font-size: clamp(28px, 5vw, 48px);
  margin: 12px 0;
  letter-spacing: -1.5px;
}
.overlay p:not(.eyebrow) {
  max-width: 420px;
  font-size: 14px;
  line-height: 1.7;
  color: #c3d0df;
}
.primary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 50px;
  background: var(--yellow);
  color: #142021;
  font-size: 17px;
  font-weight: 800;
  padding: 17px 24px;
  border: 0;
  border-radius: 10px;
  min-width: 230px;
  margin: 12px 0;
}
.overlay .hint {
  font-size: 11px !important;
  color: #94a6b9 !important;
}
.game__status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  border-top: 1px solid var(--line);
}
.game__status p {
  font-size: 12px;
  color: var(--green);
  margin: 5px 0;
}
.game__status label {
  font-size: 11px;
  white-space: nowrap;
  color: var(--muted);
}
select {
  background: #15212e;
  color: white;
  border: 1px solid #43566a;
  border-radius: 4px;
  padding: 4px;
  margin-left: 5px;
}
.controls {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 20px 14px;
}
.controls__steer,
.controls__pedals {
  display: flex;
  gap: 8px;
}
.controls button {
  background: #28394c;
  color: white;
  border: 1px solid #465d77;
  border-bottom-width: 4px;
  border-radius: 12px;
  width: 74px;
  height: 64px;
  font-size: 22px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.controls button small {
  display: block;
  font-size: 8px;
  font-weight: bold;
  margin-top: 5px;
  letter-spacing: 0.3px;
}
.controls button.is-held {
  transform: translateY(2px);
  border-bottom-width: 2px;
  background: #526780;
}
.controls .accelerate {
  background: #b3ee84;
  color: #162b20;
  border-color: #8dbc66;
}
.controls .brake {
  background: #69474a;
  border-color: #a96c70;
}
.game__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  gap: 15px;
}
.game__footer span {
  font-size: 9px;
  color: var(--muted);
  line-height: 1.7;
}
.parking {
  position: absolute;
  bottom: 15px;
  left: 50%;
  transform: translateX(-50%);
  background: #11271eea;
  border: 1px solid var(--green);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 12px;
  text-align: center;
  min-width: 190px;
}
progress {
  display: block;
  accent-color: var(--green);
  height: 8px;
  width: 100%;
  margin-top: 8px;
}
.instructions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 30px;
  margin: 30px 0;
}
.instructions b {
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--yellow);
}
.instructions p,
.disclaimer {
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
}
.disclaimer {
  font-size: 10px;
  max-width: 800px;
}
footer {
  border-top: 1px solid var(--line);
  padding: 24px;
  text-align: center;
  color: #6c839b;
  font-size: 9px;
  letter-spacing: 1.5px;
}
footer span {
  margin: 0 15px;
}
@media (max-width: 600px) {
  .topbar {
    padding: 17px 16px;
  }
  .brand {
    font-size: 16px;
  }
  .back {
    font-size: 11px;
  }
  main {
    padding: 25px 12px;
  }
  .intro {
    margin-bottom: 18px;
  }
  .badge {
    font-size: 28px;
    padding: 10px;
  }
  .badge span {
    font-size: 6px;
  }
  .subtitle {
    font-size: 12px;
    line-height: 1.6;
  }
  .hud {
    gap: 18px;
    padding: 12px;
  }
  .hud strong {
    font-size: 20px;
  }
  .hud div span {
    font-size: 7px;
    letter-spacing: 1px;
  }
  .hud button {
    padding: 8px;
    font-size: 11px;
  }
  .viewport {
    height: min(390px, 50svh);
  }
  .game__status {
    padding: 8px 12px;
    align-items: flex-start;
  }
  .game__status p {
    font-size: 11px;
  }
  .game__status label {
    font-size: 0;
  }
  .game__status select {
    font-size: 11px;
  }
  .controls {
    padding: 8px 10px 12px;
    gap: 6px;
  }
  .controls__steer,
  .controls__pedals {
    gap: 5px;
  }
  .controls button {
    width: 56px;
    height: 62px;
  }
  .controls button small {
    font-size: 7px;
  }
  .game__footer {
    padding: 10px 12px;
  }
  .instructions {
    gap: 16px;
    grid-template-columns: 1fr;
  }
  .instructions p {
    margin: 6px 0;
  }
  .overlay h2 {
    font-size: 32px;
  }
}
@media (max-width: 350px) {
  .controls button {
    width: 49px;
  }
  .hud {
    gap: 12px;
  }
  .badge {
    display: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto;
  }
}
/* Keep the complete track and touch controls together on short landscape screens. */
@media (orientation: landscape) and (max-height: 540px) and (max-width: 1100px) {
  main { padding: 16px 12px; }
  .game { display: grid; grid-template-columns: minmax(0, 1fr) 270px; grid-template-rows: 54px auto 1fr auto; height: calc(100svh - 8px); }
  .hud { grid-column: 1 / -1; grid-row: 1; padding: 5px 12px; gap: 20px; }
  .hud strong { font-size: 18px; margin-top: 2px; }
  .viewport { grid-column: 1; grid-row: 2 / 5; height: 100%; min-height: 0; }
  .game__status { grid-column: 2; grid-row: 2; padding: 6px 10px; font-size: 10px; gap: 6px; }
  .game__status p { font-size: 10px; }
  .game__status label { font-size: 0; }
  .game__status select { font-size: 10px; }
  .controls { grid-column: 2; grid-row: 3; flex-direction: column; align-items: center; justify-content: center; padding: 4px 8px; gap: 8px; }
  .controls button { width: 64px; height: 54px; }
  .controls button small { font-size: 7px; }
  .game__footer { grid-column: 2; grid-row: 4; padding: 5px 8px; }
  .game__footer span { display: none; }
  .game__footer button { margin-left: auto; min-height: 40px; }
  .overlay { padding: 10px; }
  .overlay .eyebrow, .overlay .hint { display: none; }
  .overlay h2 { font-size: 24px; margin: 5px 0; }
  .overlay p:not(.eyebrow) { font-size: 12px; line-height: 1.4; }
}


/* Campaign summary stays outside the playing surface, including landscape. */
.campaign {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 22px;
  margin: 0 0 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(110deg, #1d302c, #141e2a 75%);
}
.campaign .eyebrow { margin: 0 0 7px; }
.campaign h2 { font-size: 18px; margin: 0 0 6px; }
.campaign__copy { min-width: 0; }
.campaign__copy > p:last-child { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.campaign__actions { display: flex; align-items: center; gap: 20px; flex-shrink: 0; }
.campaign__actions strong { color: var(--yellow); font-size: 18px; white-space: nowrap; }
.campaign button, .secondary, #closeLevels {
  min-height: 44px;
  min-width: 44px;
  color: #f5f7fa;
  background: #223244;
  border: 1px solid #465d77;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 12px;
}
.hud #levels { margin-left: auto; }
.hud #pause { margin-left: 0; }
.hud button { min-height: 44px; min-width: 44px; }
.overlay .secondary { margin: 3px 0; min-width: 170px; }
.overlay:has(#replay:not([hidden])) .hint,
.overlay:has(#replay:not([hidden])) > .eyebrow { display: none; }
.overlay:has(#replay:not([hidden])) h2 { margin: 6px 0; }
.overlay:has(#replay:not([hidden])) p:not(.eyebrow) { margin: 8px 0; line-height: 1.45; }
.overlay:has(#replay:not([hidden])) .primary { padding: 12px 20px; min-height: 48px; margin: 8px 0; }
.level-dialog {
  box-sizing: border-box;
  color: #f5f7fa;
  background: #101b26;
  border: 1px solid #496153;
  border-radius: 18px;
  width: min(760px, calc(100vw - 24px));
  max-width: none;
  max-height: calc(100svh - 24px);
  padding: 24px;
  overflow: auto;
  box-shadow: 0 30px 100px #000a;
}
.level-dialog::backdrop { background: #050c17d9; backdrop-filter: blur(5px); }
.level-dialog__header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.level-dialog__header .eyebrow { margin-top: 0; }
.level-dialog h2 { font-size: clamp(22px, 4vw, 30px); letter-spacing: -0.6px; margin: 8px 0 12px; }
#closeLevels { padding: 8px; flex: 0 0 44px; font-size: 18px; }
.level-dialog__help { margin: 0 0 18px; font-size: 12px; color: var(--muted); line-height: 1.6; }
.level-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.level-card {
  text-align: left;
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 180px;
  padding: 14px;
  background: #1c2a37;
  border: 1px solid #405369;
  border-radius: 12px;
  color: #f5f7fa;
}
.level-card:hover:not(:disabled) { border-color: var(--green); background: #25382f; }
.level-card[aria-current="step"] { border: 2px solid var(--green); padding: 13px; background: #21392f; }
.level-card:disabled { opacity: 0.58; }
.level-card__number { font-size: 9px; letter-spacing: 1px; color: var(--green); }
.level-card:disabled .level-card__number { color: var(--muted); }
.level-card__title { font-size: 16px; line-height: 1.15; }
.level-card__description { font-size: 11px; line-height: 1.5; color: #c0ccd8; }
.level-card__stars { font-size: 22px; letter-spacing: 2px; color: var(--yellow); margin-top: auto; }
.level-card__detail { font-size: 10px; line-height: 1.5; color: var(--muted); }
.level-dialog__rules { color: var(--yellow); font-size: 11px; line-height: 1.7; margin: 18px 0 8px; }
.level-dialog__privacy { font-size: 10px; color: var(--muted); line-height: 1.6; margin-bottom: 0; }
@media (max-width: 600px) {
  .campaign { padding: 14px; gap: 10px; align-items: flex-start; }
  .campaign h2 { font-size: 15px; line-height: 1.3; }
  .campaign__actions { flex-direction: column; gap: 6px; align-items: flex-end; }
  .campaign__actions strong { font-size: 15px; }
  .campaign__copy > p:last-child { font-size: 10px; }
  .campaign .eyebrow { font-size: 8px; }
  .hud { gap: 9px; }
  .hud button { padding: 8px; }
  .hud div span { font-size: 6px; letter-spacing: 0.7px; }
  .level-dialog { padding: 16px; }
  .level-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .level-card { padding: 11px; min-height: 190px; }
  .level-card[aria-current="step"] { padding: 10px; }
  .level-card__title { font-size: 14px; }
  .level-card__number { font-size: 8px; letter-spacing: 0.5px; }
  .overlay h2 { font-size: 28px; }
  .overlay p:not(.eyebrow) { font-size: 12px; line-height: 1.45; margin: 8px 0; }
  .overlay .primary { padding: 12px 20px; min-height: 48px; margin: 8px 0; }
}
@media (max-width: 350px) {
  .hud { gap: 6px; padding: 10px 8px; }
  .hud strong { font-size: 18px; }
  .hud button { padding: 7px; font-size: 10px; }
}
@media (orientation: landscape) and (max-height: 540px) and (max-width: 1100px) {
  .hud { gap: 20px; }
  .hud button { min-height: 44px; }
  .level-dialog { padding: 16px; }
  .level-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .level-card { min-height: 160px; }
  .overlay h2 { font-size: 24px; }
  .overlay .primary { padding: 10px 18px; min-height: 44px; margin: 4px 0; }
  .overlay .secondary { min-height: 44px; margin: 2px 0; }
}
/* Keep all persistent game actions comfortably tappable. */
.game__footer button, .game__status select { min-height: 44px; }
.game__messages { min-width: 0; flex: 1; }
#objectiveHint { display: block; color: var(--yellow); font-size: 12px; line-height: 1.4; margin: 3px 0; overflow-wrap: anywhere; }
@media (orientation: landscape) and (max-height: 540px) and (max-width: 1100px) {
  #objectiveHint { font-size: 11px; line-height: 1.25; }
  .game__messages #status { margin: 0 0 2px; }
}
/* Phase names can wrap on narrow phones without hiding the advance action. */
.overlay .primary { max-width: 100%; white-space: normal; text-align: center; justify-content: center; }

/* Let actions fit the narrow track column; minimums must not beat max-width. */
.overlay .primary, .overlay .secondary { min-width: 0; max-width: 100%; }
@media (orientation: landscape) and (max-width: 600px) and (max-height: 540px) {
  .overlay { justify-content: flex-start; overflow-y: auto; overscroll-behavior: contain; }
}

/* Audio and restart share the existing footer, leaving the compact HUD unchanged. */
.game__footer > span { min-width: 0; flex: 1; }
.game__actions { display: flex; flex: 0 0 auto; align-items: center; gap: 8px; margin-left: auto; }
.game__actions button { min-width: 44px; min-height: 44px; white-space: nowrap; margin-left: 0; }
#sound[aria-pressed="true"] { background: #172331; color: #c3cfdb; border-color: #75899d; }
@media (max-width: 600px) {
  .game__footer { gap: 8px; }
  .game__actions { gap: 6px; }
  .game__actions button { padding: 8px 10px; }
}

/* Result actions stay inside the track, with scrolling rather than clipped targets. */
.overlay:has(#replay:not([hidden])) { overflow-y: auto; overscroll-behavior: contain; justify-content: flex-start; }
.overlay > * { flex-shrink: 0; }
.overlay #advanceStatus { color: var(--yellow); font-weight: 700; font-size: 13px; margin: 6px 0; }
.overlay #cancelAdvance { min-width: 0; min-height: 44px; max-width: 100%; white-space: normal; }
@media (max-width: 600px) {
  .overlay:has(#replay:not([hidden])) h2 { font-size: 24px; }
  .overlay:has(#replay:not([hidden])) p:not(.eyebrow) { margin: 5px 0; line-height: 1.35; }
  .overlay:has(#replay:not([hidden])) .primary { margin: 5px 0; min-height: 44px; }
}
/* Keep scroll-revealed result actions away from the rounded/clipped track edge. */
.overlay { scroll-padding-block: 8px; }
.overlay button { scroll-margin-block: 8px; }

/* Controller hints stay outside the track and never cover touch targets. */
.gamepad-guide { max-width: 70rem; margin: 1rem auto; padding: .8rem 1rem; border: 1px solid #395262; border-radius: 1rem; background: #142431; color: #dcecf3; overflow-wrap: anywhere; }
.gamepad-guide p { margin: .35rem 0; line-height: 1.5; }
.gamepad-note { font-size: .85rem; color: #b5c9d4; }


/* Fixed reading slots keep pausing from changing the height of the driving HUD. */
.hud .speed-meter { flex: 0 0 auto; min-width: 64px; text-align: center; }
.hud .speed-meter .speed-meter__unit { font-size: 9px; letter-spacing: 0; white-space: nowrap; line-height: 10px; }
.hud .speed-meter #speedValue { margin: 0; line-height: 26px; color: var(--yellow); }
.hud .speed-meter .speed-meter__direction { font-size: 8px; line-height: 10px; letter-spacing: .4px; }
.hud .speed-meter__pause-slot { display: block; height: 9px; line-height: 9px; }
.hud .speed-meter #speedPaused { font-size: 7px; line-height: 9px; letter-spacing: .3px; color: var(--yellow); }
@media (max-width: 600px), (orientation: landscape) and (max-height: 540px) and (max-width: 1100px) {
  .hud { display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, .65fr) minmax(0, .9fr) 58px 44px minmax(44px, 1fr); gap: 3px; padding: 5px 8px; }
  .hud > div { min-width: 0; }
  .hud > div:not(.speed-meter) > span { font-size: 7px; letter-spacing: .2px; overflow-wrap: normal; }
  .hud strong { font-size: 18px; }
  .hud #levels, .hud #pause { margin-left: 0; width: 100%; min-width: 44px; min-height: 44px; padding: 4px 2px; font-size: 10px; overflow-wrap: normal; }
  .hud .speed-meter { min-width: 0; height: 44px; }
  .hud .speed-meter .speed-meter__unit { font-size: 7px; line-height: 9px; }
  .hud .speed-meter #speedValue { font-size: 18px; line-height: 18px; }
  .hud .speed-meter .speed-meter__direction { font-size: 7px; line-height: 9px; }
  .hud .speed-meter__pause-slot, .hud .speed-meter #speedPaused { height: 8px; line-height: 8px; }
}
