:root {
  color-scheme: dark;
  --bg: #090014;
  --panel: #161022;
  --panel-strong: #21152f;
  --text: #fff8f0;
  --muted: #b9abc8;
  --line: #533067;
  --cyan: #23e7ff;
  --pink: #ff2f93;
  --yellow: #ffe45e;
  --green: #72ff74;
  --shadow: 0 24px 80px rgb(0 0 0 / 46%);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: var(--text);
  background:
    linear-gradient(180deg, rgb(255 47 147 / 16%), transparent 42%),
    linear-gradient(135deg, #090014 0%, #18052e 48%, #050d22 100%);
}

button {
  font: inherit;
}

.skip-link {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 10;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  background: var(--yellow);
  color: #13051f;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.arcade-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
  gap: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 0;
  overflow: hidden;
}

.race-stage,
.dashboard {
  border: 1px solid var(--line);
  border-radius: 0;
  background: rgb(16 8 28 / 84%);
  box-shadow: var(--shadow);
}

.race-stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  position: relative;
}

.cabinet-header {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: clamp(1rem, 2.5vw, 1.5rem);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgb(35 231 255 / 12%), rgb(255 47 147 / 16%));
}

.eyebrow {
  margin: 0 0 0.3rem;
  color: var(--cyan);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.02;
  letter-spacing: 0;
}

h1 {
  color: var(--yellow);
  font-size: clamp(2rem, 6vw, 4.8rem);
  text-shadow: 0 0 20px rgb(255 47 147 / 72%);
}

h2 {
  font-size: clamp(1.35rem, 3vw, 2rem);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.control-button {
  min-height: 2.7rem;
  padding: 0.65rem 1rem;
  border: 1px solid var(--cyan);
  border-radius: var(--radius);
  background: #140b24;
  color: var(--text);
  font-weight: 900;
  cursor: pointer;
}

.control-button.primary {
  border-color: var(--yellow);
  background: var(--pink);
  color: white;
}

.control-button:hover,
.control-button:focus-visible {
  outline: 3px solid rgb(35 231 255 / 36%);
  outline-offset: 2px;
}

#race-canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #12002b;
  touch-action: none;
}

.screen-layer {
  position: absolute;
  inset: clamp(5.5rem, 12vw, 8.5rem) 0 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgb(9 0 20 / 70%);
  backdrop-filter: blur(3px);
}

.screen-layer[hidden],
.flow-screen[hidden] {
  display: none;
}

.flow-screen {
  display: grid;
  gap: 1rem;
  width: min(28rem, 100%);
  padding: clamp(1rem, 4vw, 1.5rem);
  border: 1px solid var(--cyan);
  border-radius: var(--radius);
  background: rgb(20 11 36 / 92%);
  box-shadow: 0 18px 60px rgb(0 0 0 / 44%);
}

.flow-screen h2 {
  color: var(--yellow);
  font-size: clamp(1.8rem, 6vw, 3.6rem);
}

.driver-field {
  display: grid;
  gap: 0.45rem;
  color: var(--muted);
  font-weight: 900;
}

.driver-field input {
  width: 100%;
  min-height: 3rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-weight: 900;
}

.driver-field input:focus {
  border-color: var(--cyan);
  outline: 3px solid rgb(35 231 255 / 28%);
  outline-offset: 2px;
}

.countdown-screen {
  place-items: center;
  text-align: center;
}

.countdown-screen h2 {
  font-size: clamp(6rem, 24vw, 14rem);
  line-height: 0.85;
}

.dashboard {
  align-self: stretch;
  padding: clamp(1rem, 2.5vw, 1.5rem);
  overflow: auto;
  transition:
    width 180ms ease,
    padding 180ms ease,
    background 180ms ease,
    transform 180ms ease;
}

.stat-grid {
  display: grid;
  gap: 0.75rem;
  margin: 1.25rem 0;
}

.stat-grid div {
  display: grid;
  gap: 0.2rem;
  min-height: 4.7rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
}

.stat-grid dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stat-grid dd {
  margin: 0;
  color: var(--green);
  font-size: clamp(1.35rem, 4vw, 2.3rem);
  font-weight: 950;
  line-height: 1;
}

.controls-panel {
  display: grid;
  gap: 0.9rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.controls-panel p {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.key-grid {
  display: grid;
  grid-template-columns: repeat(3, 3rem);
  gap: 0.45rem;
}

.key-grid span {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border: 1px solid var(--cyan);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--cyan);
  font-weight: 950;
}

.key-grid span:first-child {
  grid-column: 2;
}

.touch-controls {
  position: absolute;
  right: max(0.75rem, env(safe-area-inset-right));
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  left: max(0.75rem, env(safe-area-inset-left));
  z-index: 3;
  display: none;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
  pointer-events: none;
}

.touch-button {
  min-height: 3.7rem;
  border: 1px solid rgb(255 255 255 / 42%);
  border-radius: var(--radius);
  background: rgb(9 0 20 / 72%);
  color: var(--text);
  font-weight: 950;
  touch-action: none;
  pointer-events: auto;
  backdrop-filter: blur(6px);
}

.touch-button.go {
  border-color: var(--yellow);
  background: rgb(255 47 147 / 78%);
}

.touch-button:active {
  transform: translateY(1px);
  background: rgb(35 231 255 / 36%);
}

.arcade-shell.is-fullscreen {
  grid-template-columns: 1fr;
}

.arcade-shell.is-fullscreen .race-stage {
  grid-column: 1;
  grid-row: 1;
}

.arcade-shell.is-fullscreen .dashboard {
  position: absolute;
  top: max(0.75rem, env(safe-area-inset-top));
  right: max(0.75rem, env(safe-area-inset-right));
  z-index: 4;
  width: min(24rem, calc(100% - 1.5rem));
  max-height: calc(100vh - 1.5rem);
  max-height: calc(100dvh - 1.5rem);
  padding: 0.75rem;
  border-radius: var(--radius);
  background: rgb(9 0 20 / 68%);
  backdrop-filter: blur(8px);
}

.arcade-shell.is-fullscreen .dashboard .eyebrow,
.arcade-shell.is-fullscreen .dashboard h2,
.arcade-shell.is-fullscreen .controls-panel {
  display: none;
}

.arcade-shell.is-fullscreen .stat-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.45rem;
  margin: 0;
}

.arcade-shell.is-fullscreen .stat-grid div {
  min-height: 0;
  padding: 0.55rem;
}

.arcade-shell.is-fullscreen .stat-grid dd {
  font-size: clamp(1rem, 2.4vw, 1.45rem);
}

@media (max-width: 920px) {
  .arcade-shell {
    grid-template-columns: 1fr;
  }

  .dashboard {
    position: absolute;
    right: max(0.5rem, env(safe-area-inset-right));
    bottom: calc(5.1rem + env(safe-area-inset-bottom));
    left: max(0.5rem, env(safe-area-inset-left));
    z-index: 4;
    align-self: auto;
    max-height: 36vh;
    padding: 0.6rem;
    border-radius: var(--radius);
    background: rgb(9 0 20 / 68%);
    backdrop-filter: blur(8px);
  }

  .dashboard .eyebrow,
  .dashboard h2,
  .controls-panel {
    display: none;
  }

  .stat-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.45rem;
    margin: 0;
  }

  .stat-grid div {
    min-height: 0;
    padding: 0.55rem;
  }

  .stat-grid dt {
    font-size: 0.64rem;
  }

  .stat-grid dd {
    font-size: clamp(0.95rem, 3.7vw, 1.35rem);
  }

  .touch-controls {
    display: grid;
  }
}

@media (max-width: 620px) {
  .cabinet-header {
    align-items: stretch;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem;
  }

  h1 {
    font-size: clamp(1.8rem, 10vw, 3rem);
  }

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

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

  .arcade-shell.is-fullscreen .stat-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .control-button,
  .touch-button {
    padding-right: 0.45rem;
    padding-left: 0.45rem;
  }
}
