/*
 * TURN is gesture-first. Prevent browser text selection and the iOS Copy /
 * Look Up / Translate callout throughout the app, then opt the deliberately
 * readable/copyable information surfaces back in below.
 */
body,
body * {
  -webkit-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
}

/*
 * Selection allowlist: How to Play + Drive By Ear help/training, visible
 * version information, About, History/Changelog, Achievements and Give
 * Feedback. Keep controls and the rest of the game gesture-only.
 */
body .m8-how-dialog .m8-guide-grid,
body .m8-how-dialog .m8-guide-grid *,
body .turn-dbe-training-dialog .m8-dialog-card,
body .turn-dbe-training-dialog .m8-dialog-card *,
body .m8-home-build,
body .m8-home-build *,
body .install-kicker,
body .install-kicker *,
body .m8-about-content,
body .m8-about-content *,
body .turn-history-panel,
body .turn-history-panel *,
body .turn-history-release,
body .turn-history-release *,
body .turn-achievements-content,
body .turn-achievements-content *,
body .m8-feedback-content,
body .m8-feedback-content * {
  -webkit-user-select: text !important;
  user-select: text !important;
  -webkit-touch-callout: default !important;
}

.pedals {
  display: block;
}

/*
 * The drive pad's look and motion, in one place. The race's pad below reads
 * these, and so does HOW TO PLAY's picture of it (ui/how-to-play-demos.js), so
 * a change here changes both. Short landscape (below) and the race layout
 * (responsive.css) still resize the race's pad for themselves.
 */
:root {
  --turn-drive-outline: 4px;
  --turn-drive-divider: 2px;
  --turn-drive-pad-radius: 22.5px;
  --turn-drive-pad-shadow-x: 5.25px;
  --turn-drive-pad-shadow-y: 6px;
  /* DRIFT and BOOST, then GAS, then BRAKE. */
  --turn-drive-pad-rows: 32% 44% 24%;
  /* The ring on a pressed zone, and on a pressed LOCK or REVERSE. */
  --turn-drive-zone-pressed: inset 0 0 0 4.5px var(--turn-control-pressed);
  --turn-drive-bubble-pressed: inset 0 0 0 3.75px var(--turn-control-pressed-bubble);
  /* LOCK, SHIFT and REVERSE wait tucked against the pad's edge, then slide out
     on the pad's curve and fade in; they change colour as they are pressed. */
  --turn-drive-bubble-radius: 749.25px;
  --turn-drive-bubble-tuck: 62%;
  --turn-drive-bubble-tuck-scale: 0.38;
  --turn-drive-bubble-slide: 140ms;
  --turn-drive-bubble-slide-easing: cubic-bezier(.2,.88,.25,1);
  --turn-drive-bubble-fade: 80ms;
  --turn-drive-bubble-colour-change: 100ms;
}

.drive-stack {
  --drive-pad-height: clamp(142.5px, 26vw, 201px);
  --drift-lock-bubble-width: clamp(39px, 7.2vw, 55.5px);
  --shift-bubble-width: clamp(43.5px, 7.8vw, 60px);
  --reverse-bubble-width: clamp(39px, 7.2vw, 55.5px);
  --drive-brake-color: var(--turn-control-brake, #ff7b54);
  position: relative;
  isolation: isolate;
  width: clamp(142.5px, 24vw, 195px);
  height: var(--drive-pad-height);
  display: grid;
  pointer-events: auto;
}

.drive-pad {
  --boost-charge: 100%;
  position: relative;
  z-index: 2;
  height: var(--drive-pad-height);
  overflow: hidden;
  display: grid;
  grid-template-rows: var(--turn-drive-pad-rows);
  border: var(--turn-drive-outline) solid var(--turn-outline);
  border-radius: var(--turn-drive-pad-radius);
  background: var(--lime);
  box-shadow: var(--turn-drive-pad-shadow-x) var(--turn-drive-pad-shadow-y) 0 var(--turn-shadow-color);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.drive-lock-bubble {
  position: absolute;
  z-index: 1;
  top: 0;
  right: calc(100% - 3px);
  width: var(--drift-lock-bubble-width);
  /* Grid percentages use the pad's inner height; finish on the GAS border's far edge. */
  height: calc(32% + 4.08px);
  box-sizing: border-box;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: var(--turn-drive-outline) solid var(--turn-outline);
  border-radius: var(--turn-drive-bubble-radius) 0 0 var(--turn-drive-bubble-radius);
  background: var(--turn-control-lock);
  color: var(--turn-ink);
  opacity: 0;
  transform: translateX(var(--turn-drive-bubble-tuck)) scaleX(var(--turn-drive-bubble-tuck-scale));
  transform-origin: right center;
  transition:
    opacity var(--turn-drive-bubble-fade) ease-out,
    transform var(--turn-drive-bubble-slide) var(--turn-drive-bubble-slide-easing),
    background-color var(--turn-drive-bubble-colour-change) ease;
  pointer-events: none;
}

.drive-lock-bubble span {
  display: block;
  transform: rotate(-90deg);
  font-size: max(var(--turn-text-floor, 11px), clamp(0.435rem, 1.55vw, 0.615rem));
  font-weight: 900;
  letter-spacing: 0.035em;
  line-height: 1;
}

.controls .drive-shift-bubble {
  position: absolute;
  z-index: 1;
  /* Share the GAS row's two 4px horizontal borders exactly. */
  top: calc(32% + 1.08px);
  right: calc(100% - 3px);
  width: var(--shift-bubble-width);
  height: calc(44% + 0.36px);
  min-height: 0;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: var(--turn-drive-outline) solid var(--turn-outline);
  border-radius: var(--turn-drive-bubble-radius) 0 0 var(--turn-drive-bubble-radius);
  background: var(--turn-control-gas);
  color: var(--turn-ink);
  box-shadow: none;
  opacity: 0;
  transform: translateX(var(--turn-drive-bubble-tuck)) scaleX(var(--turn-drive-bubble-tuck-scale));
  transform-origin: right center;
  transition:
    opacity var(--turn-drive-bubble-fade) ease-out,
    transform var(--turn-drive-bubble-slide) var(--turn-drive-bubble-slide-easing),
    background-color var(--turn-drive-bubble-colour-change) ease;
  pointer-events: none;
}

.drive-shift-bubble span {
  display: inline-flex;
  padding: 0;
  align-items: center;
  justify-content: center;
  gap: .32em;
  transform: rotate(-90deg);
  font-size: max(var(--turn-text-floor, 11px), clamp(0.435rem, 1.48vw, 0.6rem));
  font-weight: 950;
  letter-spacing: 0.035em;
  line-height: 1;
  white-space: nowrap;
}

.drive-shift-bubble i {
  display: inline-block;
  width: 0;
  overflow: hidden;
  opacity: 0;
  font-size: .9em;
  font-style: normal;
  line-height: 1;
  transition:
    width var(--turn-drive-bubble-colour-change) ease,
    opacity var(--turn-drive-bubble-colour-change) ease;
}

.controls .drive-reverse-bubble {
  position: absolute;
  z-index: 1;
  right: calc(100% - 3px);
  bottom: 0;
  width: var(--reverse-bubble-width);
  height: calc(24% + 1.56px);
  min-height: 0;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: var(--turn-drive-outline) solid var(--turn-outline);
  border-radius: var(--turn-drive-bubble-radius) 0 0 var(--turn-drive-bubble-radius);
  background: var(--drive-brake-color);
  color: var(--turn-ink);
  box-shadow: none;
  opacity: 0;
  transform: translateX(var(--turn-drive-bubble-tuck)) scaleX(var(--turn-drive-bubble-tuck-scale));
  transform-origin: right center;
  transition:
    opacity var(--turn-drive-bubble-fade) ease-out,
    transform var(--turn-drive-bubble-slide) var(--turn-drive-bubble-slide-easing),
    background-color var(--turn-drive-bubble-colour-change) ease;
  pointer-events: none;
  touch-action: none;
  font-size: max(var(--turn-text-floor, 11px), clamp(0.585rem, 2vw, 0.84rem));
  font-weight: 950;
  line-height: 1;
  text-transform: uppercase;
}

.drive-stack.is-brake-ready .drive-reverse-bubble,
.drive-stack.is-reversing .drive-reverse-bubble,
.drive-reverse-bubble:focus-visible {
  opacity: 1;
  transform: translateX(0) scaleX(1);
  pointer-events: auto;
}

.drive-stack.is-brake-ready .drive-pad {
  border-bottom-left-radius: 0;
}

.drive-stack.is-reversing .drive-reverse-bubble,
.drive-reverse-bubble.is-active {
  background: var(--turn-orange-200, #ffb89f);
  box-shadow: var(--turn-drive-bubble-pressed);
}

.drive-reverse-bubble:focus-visible {
  outline: 4px solid var(--paper);
  outline-offset: 2.25px;
}

.drive-stack.is-shift-available.is-gas-ready .drive-shift-bubble,
.drive-stack.is-shift-active .drive-shift-bubble,
.drive-shift-bubble:focus-visible {
  opacity: 1;
  transform: translateX(0) scaleX(1);
  pointer-events: auto;
}

.drive-stack.is-shift-active .drive-shift-bubble {
  background: var(--turn-control-shift-on);
}

.drive-stack.is-shift-active .drive-shift-bubble i {
  width: .72em;
  opacity: 1;
}

.drive-shift-bubble:focus-visible {
  outline: 4px solid var(--paper);
  outline-offset: 2.25px;
}

.drive-stack.is-drift-ready .drive-lock-bubble {
  opacity: 1;
  transform: translateX(0) scaleX(1);
}

.drive-stack.is-drift-ready .drive-pad {
  border-top-left-radius: 0;
}

.drive-stack.is-drift-locking .drive-lock-bubble {
  background: var(--turn-control-overcharge);
  box-shadow: var(--turn-drive-bubble-pressed);
}

.drive-pad-top {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.drive-zone,
.drive-pad .drive-gas-zone,
.drive-pad .drive-brake-zone {
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  transform: none;
  color: var(--turn-text);
  font-size: max(var(--turn-text-floor, 11px), clamp(0.585rem, 2vw, 0.84rem));
  letter-spacing: 0.025em;
  text-transform: uppercase;
  touch-action: none;
}

.drive-zone:active,
.drive-pad .drive-gas-zone:active,
.drive-pad .drive-brake-zone:active {
  transform: none;
  box-shadow: none;
}

.drive-drift-zone {
  border-right: var(--turn-drive-divider) solid var(--turn-outline);
  background: #54c2ef;
}

.drive-boost-zone {
  position: relative;
  overflow: hidden;
  border-left: var(--turn-drive-divider) solid var(--turn-outline);
  background:
    linear-gradient(
      to top,
      #ff6b6b 0 var(--boost-charge),
      #ffb2aa var(--boost-charge) 100%
    );
}

.drive-boost-zone::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: rgb(255 255 255 / 0);
  transition: background 100ms ease;
}

.drive-pad .drive-gas-zone {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  text-align: center;
  border-top: var(--turn-drive-outline) solid var(--turn-outline);
  background: #c8db08;
}

.drive-pad .drive-gas-zone::after {
  content: none;
}

.drive-pad .drive-brake-zone {
  display: grid;
  place-items: center;
  padding: 4.5px 9px;
  border-top: var(--turn-drive-outline) solid var(--turn-outline);
  background: var(--drive-brake-color);
  font-size: max(var(--turn-text-floor, 11px), clamp(0.45rem, 1.45vw, 0.615rem));
  letter-spacing: 0.035em;
  white-space: nowrap;
}

.drive-pad[data-drive-zone="gas"] .drive-gas-zone,
.drive-drift-zone.is-active,
.drive-boost-zone.is-active,
.drive-brake-zone.is-active {
  box-shadow: var(--turn-drive-zone-pressed);
}

.drive-pad[data-drive-zone="gas"] .drive-gas-zone {
  background: #d9eb12;
}

.drive-drift-zone.is-active {
  background: #38d9ff;
}

.drive-brake-zone.is-active {
  background: var(--drive-brake-color);
}

.drive-pad.is-boosting .drive-boost-zone {
  background:
    linear-gradient(
      to top,
      #ff3f4a 0 var(--boost-charge),
      #ff9a8e var(--boost-charge) 100%
    );
}

.drive-pad.is-boosting {
  box-shadow:
    var(--turn-drive-pad-shadow-x) var(--turn-drive-pad-shadow-y) 0 var(--turn-shadow-color),
    0 0 0 3.75px rgb(255 90 95 / 0.28);
}

:root.turn-left-handed-controls .controls {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
}

:root.turn-left-handed-controls .pedals {
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
}

:root.turn-left-handed-controls .utility-group {
  grid-column: 2;
  grid-row: 1;
  align-self: end;
  justify-self: end;
  transform: none;
}

:root.turn-left-handed-controls .drive-lock-bubble {
  right: auto;
  left: calc(100% - 3px);
  border-radius: 0 var(--turn-drive-bubble-radius) var(--turn-drive-bubble-radius) 0;
  transform: translateX(calc(-1 * var(--turn-drive-bubble-tuck))) scaleX(var(--turn-drive-bubble-tuck-scale));
  transform-origin: left center;
}

:root.turn-left-handed-controls .drive-shift-bubble {
  right: auto;
  left: calc(100% - 3px);
  border-radius: 0 var(--turn-drive-bubble-radius) var(--turn-drive-bubble-radius) 0;
  transform: translateX(calc(-1 * var(--turn-drive-bubble-tuck))) scaleX(var(--turn-drive-bubble-tuck-scale));
  transform-origin: left center;
}

:root.turn-left-handed-controls .drive-reverse-bubble {
  right: auto;
  left: calc(100% - 3px);
  border-radius: 0 var(--turn-drive-bubble-radius) var(--turn-drive-bubble-radius) 0;
  transform: translateX(calc(-1 * var(--turn-drive-bubble-tuck))) scaleX(var(--turn-drive-bubble-tuck-scale));
  transform-origin: left center;
}

:root.turn-left-handed-controls .drive-stack.is-shift-available.is-gas-ready .drive-shift-bubble,
:root.turn-left-handed-controls .drive-stack.is-shift-active .drive-shift-bubble,
:root.turn-left-handed-controls .drive-shift-bubble:focus-visible {
  transform: translateX(0) scaleX(1);
}

:root.turn-left-handed-controls .drive-stack.is-brake-ready .drive-reverse-bubble,
:root.turn-left-handed-controls .drive-stack.is-reversing .drive-reverse-bubble,
:root.turn-left-handed-controls .drive-reverse-bubble:focus-visible {
  transform: translateX(0) scaleX(1);
}

:root.turn-left-handed-controls .drive-stack.is-drift-ready .drive-lock-bubble {
  transform: translateX(0) scaleX(1);
}

:root.turn-left-handed-controls .drive-stack.is-drift-ready .drive-pad {
  border-top-left-radius: var(--turn-drive-pad-radius);
  border-top-right-radius: 0;
}

:root.turn-left-handed-controls .drive-stack.is-brake-ready .drive-pad {
  border-bottom-left-radius: var(--turn-drive-pad-radius);
  border-bottom-right-radius: 0;
}

:root.turn-left-handed-controls .drive-boost-zone {
  border-right: var(--turn-drive-divider) solid var(--turn-outline);
  border-left: 0;
}

:root.turn-left-handed-controls .drive-drift-zone {
  border-right: 0;
  border-left: var(--turn-drive-divider) solid var(--turn-outline);
}

@media (max-height: 322.5px) {
  .drive-stack {
    --drive-pad-height: clamp(130.5px, 23.5vw, 153.75px);
    --drift-lock-bubble-width: clamp(36px, 6.8vw, 48px);
    --shift-bubble-width: clamp(39px, 7.2vw, 52.5px);
    --reverse-bubble-width: clamp(36px, 6.8vw, 48px);
    width: clamp(130.5px, 23vw, 168px);
  }

  .drive-pad {
    border-width: 2.25px;
    border-radius: 18px;
    box-shadow: 3.75px 4.5px 0 var(--turn-shadow-color);
  }

  .drive-pad .drive-gas-zone,
  .drive-pad .drive-brake-zone {
    border-top-width: 2.25px;
  }

  .drive-drift-zone {
    border-right-width: 1.125px;
  }

  .drive-boost-zone {
    border-left-width: 1.125px;
  }

  .drive-lock-bubble {
    right: calc(100% - 2.25px);
    height: calc(32% + 3.06px);
    border-width: 2.25px;
  }

  .controls .drive-shift-bubble {
    right: calc(100% - 2.25px);
    top: calc(32% + 0.81px);
    height: calc(44% + 0.27px);
    border-width: 2.25px;
  }

  .controls .drive-reverse-bubble {
    right: calc(100% - 2.25px);
    height: calc(24% + 1.17px);
    border-width: 2.25px;
  }

  :root.turn-left-handed-controls .drive-lock-bubble {
    right: auto;
    left: calc(100% - 2.25px);
  }

  :root.turn-left-handed-controls .drive-shift-bubble {
    right: auto;
    left: calc(100% - 2.25px);
  }

  :root.turn-left-handed-controls .drive-reverse-bubble {
    right: auto;
    left: calc(100% - 2.25px);
  }

  :root.turn-left-handed-controls .drive-stack.is-drift-ready .drive-pad {
    border-top-left-radius: 18px;
  }

  :root.turn-left-handed-controls .drive-stack.is-brake-ready .drive-pad {
    border-bottom-left-radius: 18px;
  }

  :root.turn-left-handed-controls .drive-boost-zone {
    border-right-width: 1.125px;
  }

  :root.turn-left-handed-controls .drive-drift-zone {
    border-left-width: 1.125px;
  }
}

@media (max-width: 525px) and (max-height: 322.5px) {
  :root.turn-left-handed-controls .utility-group[data-menu-state="staged"] {
    gap: 3.75px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .drive-lock-bubble,
  .controls .drive-shift-bubble,
  .controls .drive-reverse-bubble,
  .drive-shift-bubble i {
    transition: none;
  }
}

/* RESPONSE TIME (#1247): as the kick lands, the control the player came back to
   (GAS or DRIFT) flashes cream inside a cream ring, then fades. No text to read. */
.drive-stack { --turn-response-flash: 62%; }
:root[data-theme="dark"] .drive-stack { --turn-response-flash: 26%; }

.drive-stack .is-response-kick {
  animation: turn-response-kick 900ms cubic-bezier(.2,.8,.3,1);
}

@keyframes turn-response-kick {
  0% {
    box-shadow: inset 0 0 0 0 var(--turn-paper),
      inset 0 0 0 999px color-mix(in srgb, var(--turn-paper) 0%, transparent);
  }
  14% {
    box-shadow: inset 0 0 0 var(--turn-space-2) var(--turn-paper),
      inset 0 0 0 999px color-mix(in srgb, var(--turn-paper) var(--turn-response-flash), transparent);
  }
  45% {
    box-shadow: inset 0 0 0 var(--turn-space-2) var(--turn-paper),
      inset 0 0 0 999px color-mix(in srgb, var(--turn-paper) 0%, transparent);
  }
  100% {
    box-shadow: inset 0 0 0 0 color-mix(in srgb, var(--turn-paper) 0%, transparent),
      inset 0 0 0 999px color-mix(in srgb, var(--turn-paper) 0%, transparent);
  }
}

@media (prefers-reduced-motion: reduce) {
  .drive-stack .is-response-kick {
    animation: none;
    box-shadow: inset 0 0 0 var(--turn-space-2) var(--turn-paper);
  }
}

@media (forced-colors: active) {
  .drive-stack .is-response-kick {
    animation: none;
    outline: var(--turn-border-default) solid Highlight;
    outline-offset: calc(-1 * var(--turn-border-default));
  }
}
