:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #101416;
  color: #f8f5ec;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

img,
canvas {
  -webkit-user-drag: none;
  user-drag: none;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    #101416;
  background-size: 36px 36px;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  background: #2b3337;
  color: #f8f5ec;
  box-shadow: 0 3px 0 #111719;
  cursor: pointer;
  font: inherit;
  font-weight: 900;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

button:active,
button.active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #111719;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  align-content: start;
  gap: 16px;
  min-height: 100vh;
  padding: 16px;
}

.stage {
  position: relative;
  align-self: start;
  width: 100%;
  overflow: hidden;
  border: 2px solid rgba(248, 245, 236, 0.18);
  border-radius: 8px;
  aspect-ratio: 960 / 540;
  background: #92d8ec;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 960 / 540;
  touch-action: none;
}

.hud {
  position: absolute;
  top: 12px;
  left: 12px;
  display: grid;
  grid-template-columns: repeat(4, minmax(76px, 1fr));
  gap: 7px;
}

.hud > div {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 7px;
  padding: 7px 9px;
  background: rgba(15, 24, 27, 0.74);
  backdrop-filter: blur(8px);
}

.hud span {
  display: block;
  color: #9fe8d7;
  font-size: 9px;
  font-weight: 900;
  text-transform: uppercase;
}

.hud strong {
  display: block;
  overflow: hidden;
  font-size: 17px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.race-controls {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: grid;
  grid-template-columns: 92px 76px;
  gap: 9px;
}

.race-controls button {
  min-height: 58px;
  border: 2px solid rgba(255, 255, 255, 0.32);
  background: #f4c84b;
  color: #17150e;
  box-shadow: 0 4px 0 #8f6a1c;
  font-size: 17px;
  touch-action: none;
}

.finish {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 9px;
  padding: 20px;
  background: rgba(11, 16, 18, 0.78);
  text-align: center;
}

.finish p,
.finish h2 {
  margin: 0;
}

.finish p {
  color: #f4c84b;
  font-size: 15px;
  font-weight: 1000;
}

.finish h2 {
  font-size: clamp(34px, 6vw, 72px);
}

.finish strong {
  color: #9fe8d7;
  font-size: 18px;
}

.finish > div {
  display: flex;
  gap: 8px;
}

.workshop {
  display: flex;
  flex-direction: column;
  gap: 17px;
  min-height: 0;
  border: 2px solid rgba(248, 245, 236, 0.16);
  border-radius: 8px;
  padding: 20px;
  background: rgba(19, 24, 27, 0.94);
}

.title p,
.title h1 {
  margin: 0;
}

.title p {
  color: #69d8bd;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.title h1 {
  margin-top: 5px;
  color: #f4c84b;
  font-size: 31px;
  line-height: 0.96;
}

fieldset {
  min-width: 0;
  margin: 0;
  border: 0;
  border-top: 1px solid rgba(248, 245, 236, 0.14);
  padding: 13px 0 0;
}

legend {
  padding: 0 8px 0 0;
  color: #b8c3c0;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.swatches,
.options {
  display: grid;
  gap: 7px;
  margin-top: 8px;
}

.name-input {
  width: 100%;
  min-height: 42px;
  margin-top: 8px;
  border: 2px solid rgba(248, 245, 236, 0.2);
  border-radius: 7px;
  padding: 0 11px;
  outline: none;
  background: #252d31;
  color: #f8f5ec;
  font: inherit;
  font-weight: 900;
}

.name-input:focus {
  border-color: #69d8bd;
}

.swatches {
  grid-template-columns: repeat(6, 1fr);
}

.swatch {
  min-width: 0;
  min-height: 36px;
  border: 2px solid transparent;
  padding: 0;
  background: var(--swatch);
  box-shadow: none;
}

.swatch.selected {
  border-color: #fff;
  box-shadow: inset 0 0 0 3px #172024;
}

.options {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.options button {
  min-width: 0;
  min-height: 38px;
  padding: 0 5px;
  color: #cdd5d2;
  font-size: 11px;
  box-shadow: none;
}

.options button.selected {
  background: #69d8bd;
  color: #101416;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: auto;
}

.actions .primary {
  background: #f4c84b;
  color: #17150e;
  box-shadow: 0 3px 0 #8f6a1c;
}

.hidden {
  display: none;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .workshop {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
  }

  .title,
  .actions {
    grid-column: 1 / -1;
  }

  .actions {
    margin-top: 0;
  }
}

@media (max-width: 620px) {
  .hud {
    top: 5px;
    left: 5px;
    grid-template-columns: repeat(4, minmax(50px, 1fr));
    gap: 3px;
  }

  .hud > div {
    padding: 3px 5px;
  }

  .hud span {
    font-size: 6px;
  }

  .hud strong {
    font-size: 10px;
  }

  .race-controls {
    right: 6px;
    bottom: 6px;
    grid-template-columns: 62px 55px;
    gap: 5px;
  }

  .race-controls button {
    min-height: 38px;
    font-size: 12px;
  }

  .finish {
    gap: 5px;
    padding: 8px;
  }

  .finish p {
    font-size: 9px;
  }

  .finish h2 {
    font-size: 28px;
  }

  .finish strong {
    font-size: 11px;
  }

  .finish button {
    min-height: 30px;
    padding: 0 10px;
    font-size: 10px;
  }

  .workshop {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .title,
  .actions {
    grid-column: auto;
  }

  .title h1 {
    font-size: 28px;
  }
}
