/* Touch controls (#122), placed after the ergonomics research: low in the screen's
   corners, steering for one thumb and the pedals for the other. A phone held upright
   docks them in their own bar under the field, 72 × 76 px, unless the player puts them on
   the track; elsewhere they lie over the field's bottom corners, 64 px in landscape and
   72 px on larger screens. The player's settings scale them (0.85, 1, 1.2), set their
   background and mirror them. */
.touch-controls {
  --pad-w: 72px;
  --pad-h: 72px;
  --pad-scale: 1;
  /* The fill behind each button and how much of it shows: dark over the track, light on the
     bar's own dark surface, so « Fond des boutons » shows in both. Until 2026-11-12 the bar
     took the dark fill too, and its three settings looked alike (Sébastien). */
  --pad-fill: 20 36 60;
  --pad-alpha: 0.32;
  grid-area: field;
  align-self: end;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--space-3);
  /* 16 px from the screen's sides at least: the edges belong to the system's back gesture. */
  padding: 0 max(var(--space-4), env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom))
    max(var(--space-4), env(safe-area-inset-left));
  pointer-events: none;
}
.touch-controls[data-size='small'] {
  --pad-scale: 0.85;
}
.touch-controls[data-size='large'] {
  --pad-scale: 1.2;
}
.touch-controls[data-opacity='light'] {
  --pad-alpha: 0.12;
}
.touch-controls[data-opacity='strong'] {
  --pad-alpha: 0.62;
}
/* Left-handed: steering on the right, pedals on the left, gas still on the outside. */
.touch-controls[data-hand='left'] {
  flex-direction: row-reverse;
}
.touch-controls[data-hand='left'] .touch-pedals {
  flex-direction: row-reverse;
}
.touch-steering,
.touch-pedals {
  display: flex;
  gap: 10px;
  pointer-events: auto;
}
.touch-controls button {
  width: calc(var(--pad-w) * var(--pad-scale));
  height: calc(var(--pad-h) * var(--pad-scale));
  padding: 0;
  border: 1.5px solid rgb(220 232 255 / 0.75);
  border-radius: 14px;
  background: rgb(var(--pad-fill) / var(--pad-alpha));
  color: #fff;
  font-size: var(--fs-15);
  font-weight: 600;
  text-shadow: 0 1px 2px #000;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.touch-controls .accelerator {
  border-color: #e8ffc3;
  background: rgb(215 248 121 / calc(var(--pad-alpha) + 0.1));
  color: #f2ffd9;
}
/* The site's press style (site.css, `:active`) stays off these buttons: a gliding thumb keeps
   `:active` on the button it first touched, while `.held` follows the finger. */
.touch-controls button:active {
  filter: none;
  transform: none;
}
/* Held: an outer ring the thumb does not hide. */
.touch-controls button.held {
  background: rgb(111 169 198 / 0.55);
  outline: 3px solid #effaff;
  outline-offset: 2px;
}
.touch-controls .accelerator.held {
  background: rgb(185 239 64 / 0.6);
  outline-color: #efffc8;
}
/* Automatic acceleration needs no gas pedal. */
.touch-controls[data-auto='on'] .accelerator {
  display: none;
}
/* CSS arrowheads, not platform emoji tiles. */
.touch-controls [data-drive='left']::before,
.touch-controls [data-drive='right']::before {
  content: '';
  display: block;
  width: 0;
  height: 0;
  margin: 0 auto;
  border-top: 11px solid transparent;
  border-bottom: 11px solid transparent;
  filter: drop-shadow(0 1px 2px #000);
}
.touch-controls [data-drive='left']::before {
  border-right: 18px solid currentColor;
}
.touch-controls [data-drive='right']::before {
  border-left: 18px solid currentColor;
}
/* Upright phone: a bar of its own under the field, the buttons at the screen's bottom; or, if
   the player chooses, over the track's bottom corners as in landscape. */
@media (max-width: 750px) and (orientation: portrait) {
  .touch-controls[data-placement='bar'] {
    --pad-h: 76px;
    --pad-fill: 168 190 228;
    grid-area: pad;
    align-self: stretch;
    padding: 6px max(var(--space-4), env(safe-area-inset-right))
      max(6px, env(safe-area-inset-bottom)) max(var(--space-4), env(safe-area-inset-left));
    border-top: 1px solid var(--line-2);
    background: var(--surface);
  }
  /* Four buttons, two inner gaps of 10 px, 12 px between the groups, 16 px margins. */
  .touch-controls button {
    width: min(calc(var(--pad-w) * var(--pad-scale)), calc((100vw - 68px) / 4));
  }
}
@media (max-height: 520px) and (orientation: landscape) {
  .touch-controls {
    --pad-w: 64px;
    --pad-h: 64px;
  }
}
/* While « Commandes tactiles » is open over a pause, the buttons show above the dimmed panel,
   so each setting can be seen as it changes; the panel keeps clear of them. Without `:has()`
   the buttons stay under the panel until the race resumes. */
.race:has(#control-settings[open]) .touch-controls {
  z-index: 4;
}
.touch-enabled .race:has(#control-settings[open]) .overlay {
  padding-bottom: 112px;
}
