:root {
  color-scheme: dark;
  --bar: #15151e;
  --panel: #1f1f2b;
  --line: #38384a;
  --fg: #f4f4f6;
  --muted: #9a9aad;
  --red: #e10600;
  --purple: #b138dd;
  --green: #00d26a;
  --yellow: #ffd400;
  --key-h: clamp(34px, 5.4dvh, 50px);
  --display: 'Arial Narrow', 'Helvetica Neue', 'Roboto Condensed', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

html {
  /* iOS tints the status bar area from the page background. */
  background: var(--bar);
}

body {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bar);
  color: var(--fg);
  font: italic 800 14px/1.2 var(--display);
  text-transform: uppercase;
  /* Stop the page itself bouncing, zooming or selecting like a website. */
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

button {
  font: inherit;
  color: inherit;
  text-transform: inherit;
  border: 0;
  padding: 0;
  touch-action: none;
}

/* --- A player's half ---------------------------------------------------- */

.side {
  --team: var(--red);
  flex: none;
  /* The keyboard sits against the edge of the phone, clear of the home bar. */
  padding-bottom: calc(env(safe-area-inset-bottom) + 6px);
  background: var(--bar);
}

#top {
  --team: #00d2be;
  transform: rotate(180deg);
  padding-bottom: calc(env(safe-area-inset-top) + 6px);
}

.strip {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 8px 0 0;
  background: #0d0d13;
  border-top: 2px solid var(--team);
}

.pos {
  align-self: stretch;
  display: grid;
  place-items: center;
  width: 38px;
  background: var(--fg);
  color: #0d0d13;
  font-size: 17px;
  clip-path: polygon(0 0, 100% 0, 82% 100%, 0 100%);
  padding-right: 5px;
}

.code {
  padding-left: 7px;
  border-left: 4px solid var(--team);
  font-size: 17px;
  letter-spacing: 0.04em;
}

.sectors {
  display: flex;
  gap: 3px;
  margin-left: 4px;
}

.sectors i {
  width: 18px;
  height: 7px;
  background: var(--line);
  transform: skewX(-18deg);
}

.sectors .purple {
  background: var(--purple);
}

.sectors .green {
  background: var(--green);
}

.sectors .yellow {
  background: var(--yellow);
}

.gap {
  flex: 1;
  text-align: right;
  color: var(--muted);
  font-size: 13px;
}

.speed {
  min-width: 78px;
  text-align: right;
  color: var(--muted);
  font-size: 11px;
}

.speed b {
  color: var(--fg);
  font-size: 21px;
  font-variant-numeric: tabular-nums;
}

.tape {
  position: relative;
  height: 52px;
  overflow: hidden;
  /* The letter to type sits a third of the way along. */
  padding-left: 30%;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.text {
  font: 700 24px/52px ui-monospace, Menlo, Consolas, monospace;
  text-transform: none;
  white-space: pre;
  transition: transform 90ms ease-out;
}

.done {
  color: #5c5c70;
}

.now {
  display: inline-block;
  min-width: 1ch;
  background: var(--team);
  color: #fff;
  box-shadow: 0 0 0 2px var(--team);
  border-radius: 2px;
}

.lockup .tape {
  background: #5a0d0a;
}

.lockup .now {
  background: #fff;
  color: var(--red);
}

.jump .tape::after {
  content: 'jump start · penalty';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--yellow);
  color: #111;
  font: italic 800 18px var(--display);
  letter-spacing: 0.06em;
}

.result {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--panel);
}

.result b {
  font-size: 26px;
  letter-spacing: 0.03em;
}

.result span {
  color: var(--muted);
  font-size: 13px;
}

.result.won {
  background:
    linear-gradient(90deg, var(--team) 62%, transparent),
    repeating-conic-gradient(#fff 0 25%, #111 0 50%) 0 0 / 16px 16px;
}

.result.won span {
  color: #fff;
}

.board {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 7px 3px 0;
}

.row {
  display: flex;
  justify-content: center;
  gap: 4px;
}

.key {
  flex: 0 0 calc((100% - 36px) / 10);
  height: var(--key-h);
  background: #2b2b3a;
  border-bottom: 3px solid #0d0d13;
  border-radius: 5px;
  font-size: 19px;
  font-style: normal;
}

.key.space {
  flex-basis: 62%;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.3em;
}

.key.down {
  background: var(--team);
  border-bottom-width: 1px;
  transform: translateY(2px);
}

.ready {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background:
    linear-gradient(100deg, transparent 0 8%, var(--team) 8% 11%, transparent 11% 13%, var(--team) 13% 14.5%, transparent 14.5%),
    rgba(13, 13, 19, 0.93);
}

.ready b {
  font-size: 40px;
  letter-spacing: 0.02em;
}

.ready small {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.12em;
}

.ready.set b {
  color: var(--green);
}

/* --- The circuit between them ------------------------------------------- */

#paddock {
  position: relative;
  flex: 1;
  min-height: 0;
  background:
    radial-gradient(ellipse at center, #232331, transparent 75%),
    repeating-linear-gradient(45deg, #17171f 0 3px, #1b1b25 3px 6px);
}

#circuit,
#circuit svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#circuit svg {
  padding: 6px;
}

#circuit path {
  fill: none;
  stroke-linejoin: round;
}

.kerb-white {
  stroke: #f4f4f6;
  stroke-width: 22;
}

.kerb-red {
  stroke: var(--red);
  stroke-width: 22;
  stroke-dasharray: 7 7;
}

.tarmac {
  stroke: #30303c;
  stroke-width: 17;
}

.racing-line {
  stroke: rgba(255, 255, 255, 0.16);
  stroke-width: 0.7;
  stroke-dasharray: 5 6;
}

.car0 .body {
  fill: var(--red);
}

.car1 .body {
  fill: #00d2be;
}

/* The chequered flag frames the circuit at the end of a race. */
[data-phase='flag'] #paddock::before,
[data-phase='flag'] #paddock::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 12px;
  background: repeating-conic-gradient(#fff 0 25%, #111 0 50%) 0 0 / 12px 12px;
  z-index: 1;
}

[data-phase='flag'] #paddock::after {
  bottom: 0;
}

#lights {
  position: absolute;
  top: 50%;
  left: 50%;
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: #08080c;
  border: 1px solid var(--line);
  border-radius: 10px;
  transform: translate(-50%, -50%);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
}

#lights i {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #2a1414;
}

#lights i.on {
  background: #ff1a10;
  box-shadow: 0 0 18px 4px rgba(255, 30, 16, 0.75);
}

#lobby {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(21, 21, 30, 0.72);
}

body:not([data-phase='lobby']) #lobby {
  display: none;
}

#lobby h1 {
  margin: 0;
  font-size: 42px;
  line-height: 1;
  letter-spacing: -0.01em;
  text-shadow: 3px 3px 0 var(--red);
}

#lobby .far {
  transform: rotate(180deg);
  text-shadow: 3px 3px 0 #00d2be;
}

#distance {
  display: flex;
  gap: 3px;
  transform: skewX(-12deg);
}

#distance button {
  padding: 11px 16px;
  background: #0d0d13;
  border-bottom: 3px solid var(--line);
  color: var(--muted);
  font-size: 15px;
}

#distance button.on {
  background: var(--red);
  border-color: #fff;
  color: #fff;
}

/* Sideways there is no room for two keyboards. */
#turn {
  display: none;
  position: fixed;
  inset: 0;
  margin: 0;
  place-items: center;
  padding: 24px;
  background: var(--bar);
  text-align: center;
  font-size: 20px;
  z-index: 5;
}

@media (orientation: landscape) and (max-height: 560px) {
  #turn {
    display: grid;
  }
}

.now:empty {
  display: none;
}

/* --- The notice on a desktop -------------------------------------------- */

#desktop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 6;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 32px;
  background:
    linear-gradient(100deg, transparent 0 6%, var(--red) 6% 8%, transparent 8% 9.5%, var(--red) 9.5% 10.5%, transparent 10.5%),
    var(--bar);
  text-align: center;
}

/* Anything whose main pointer is not a finger is not a phone. */
@media not all and (pointer: coarse) {
  #desktop:not(.dismissed) {
    display: flex;
  }
}

#desktop h1 {
  margin: 0;
  font-size: 64px;
  line-height: 1;
  text-shadow: 4px 4px 0 var(--red);
}

#desktop h2 {
  margin: 0;
  padding: 6px 16px;
  background: var(--yellow);
  color: #111;
  font-size: 22px;
  transform: skewX(-12deg);
}

#desktop p {
  max-width: 420px;
  margin: 0;
  color: var(--muted);
  font: 500 17px/1.5 system-ui, sans-serif;
  text-transform: none;
}

#desktop p b {
  color: var(--fg);
  font-size: 20px;
}

#anyway {
  margin-top: 10px;
  padding: 10px 18px;
  background: none;
  border-bottom: 2px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.08em;
  cursor: pointer;
}
