:root {
  color-scheme: dark;
  font-family: Inter, ui-rounded, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #08090a;
  --paper: #fff8e8;
  --cyan: #38d9ff;
  --pink: #ff4fa3;
  --yellow: #ffd43b;
  --lime: #8ce99a;
  --app-width: 100vw;
  --app-height: 100vh;
}

@supports (height: 100dvh) {
  :root {
    --app-width: 100dvw;
    --app-height: 100dvh;
  }
}

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: var(--cyan);
}

body {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--app-width);
  min-width: 100vw;
  height: var(--app-height);
  min-height: 100vh;
  font-weight: 800;
}

@supports (height: 100lvh) {
  body {
    min-height: 100lvh;
  }
}

canvas { display: block; }

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#game canvas {
  width: 100% !important;
  height: 100% !important;
}

button {
  appearance: none;
  border: 3px solid var(--ink);
  border-radius: 16px;
  font: inherit;
  color: var(--ink);
  box-shadow: 5px 5px 0 var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

button:active,
button.is-down {
  transform: translate(3px, 3px);
  box-shadow: 2px 2px 0 var(--ink);
}

[hidden] { display: none !important; }

.panel,
.rotate-panel {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 18% 18%, #ff8fab 0 10%, transparent 10.5%),
    radial-gradient(circle at 80% 23%, #ffd43b 0 13%, transparent 13.5%),
    linear-gradient(135deg, #38d9ff, #74c0fc 58%, #9775fa);
}

.start-card {
  width: min(760px, 94vw);
  padding: clamp(22px, 5vw, 48px);
  border: 5px solid var(--ink);
  border-radius: 28px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 12px 12px 0 var(--ink);
  transform: rotate(-1deg);
}

h1 {
  margin: 0;
  font-size: clamp(4rem, 15vw, 9rem);
  line-height: 0.75;
  letter-spacing: -0.09em;
  font-weight: 1000;
}

.start-logo-heading {
  font-size: 0;
  line-height: 1;
  letter-spacing: 0;
}

.start-logo {
  display: block;
  width: clamp(104px, 27vh, 210px);
  max-width: 40vw;
  height: auto;
  border-radius: 22%;
}

.kicker {
  display: inline-block;
  margin-bottom: 16px;
  padding: 6px 10px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--yellow);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transform: rotate(2deg);
}

.tagline {
  max-width: 52rem;
  margin: 20px 0 24px;
  font-size: clamp(0.95rem, 2.5vw, 1.3rem);
  line-height: 1.25;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.actions button {
  min-height: 58px;
  padding: 12px 18px;
  background: var(--pink);
}

.actions .secondary { background: var(--cyan); }

.status {
  min-height: 1.4em;
  margin: 18px 0 0;
  font-size: 0.84rem;
  line-height: 1.35;
  opacity: 0.72;
}

.rotate-panel {
  z-index: 80;
  text-align: center;
}

.rotate-card {
  padding: 28px;
  border: 5px solid var(--ink);
  border-radius: 24px;
  background: var(--yellow);
  color: var(--ink);
  box-shadow: 10px 10px 0 var(--ink);
}

.rotate-phone {
  width: 96px;
  height: 54px;
  margin: 0 auto 16px;
  border: 5px solid var(--ink);
  border-radius: 14px;
  background: var(--paper);
  transform: rotate(-10deg);
}

.hud {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  padding:
    max(10px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip,
.map-wrap,
.tilt-drive {
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: rgb(255 248 232 / 0.9);
  color: var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
}

.chip {
  min-width: 82px;
  padding: 7px 10px 8px;
  font-size: 0.62rem;
  line-height: 1;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.chip strong {
  display: block;
  margin-top: 3px;
  font-size: clamp(0.95rem, 2.5vw, 1.4rem);
  letter-spacing: -0.04em;
}

.chip.is-invalid-lap {
  background: #ff6b6b;
}

.chip.is-invalid-lap strong {
  white-space: nowrap;
  font-size: clamp(0.82rem, 2.2vw, 1.2rem);
  letter-spacing: -0.025em;
}

.map-wrap {
  width: min(24vw, 184px);
  aspect-ratio: 1.45;
  padding: 5px;
  background: rgb(255 255 255 / 0.82);
}

#map {
  width: 100%;
  height: 100%;
  border-radius: 8px;
}

.message {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%) rotate(-2deg);
  padding: 7px 13px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--yellow);
  color: var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  font-size: clamp(0.75rem, 2vw, 1rem);
  opacity: 0;
  transition: opacity 140ms ease;
}

.message.show { opacity: 1; }

.tilt-drive {
  position: absolute;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  width: min(38vw, 280px);
  padding: 6px 9px 7px;
  transform: translateX(-50%);
  background: rgb(255 248 232 / 0.82);
  text-align: center;
}

.tilt-drive > span {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  font-size: 0.55rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.tilt-track {
  position: relative;
  height: 14px;
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: linear-gradient(90deg, var(--pink) 0 47%, var(--paper) 47% 53%, var(--lime) 53% 100%);
}

.tilt-track::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--ink);
  transform: translateX(-50%);
}

.tilt-needle {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  width: 13px;
  height: 22px;
  border: 3px solid var(--ink);
  border-radius: 7px;
  background: var(--yellow);
  transform: translate(-50%, -50%);
  transition: left 45ms linear;
}

.tilt-value {
  display: block;
  margin-top: 3px;
  font-size: 0.55rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.controls {
  position: absolute;
  z-index: 20;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  pointer-events: none;
}

.controls button { pointer-events: auto; }

.utility-group {
  display: flex;
  gap: 9px;
  align-items: end;
}

.utility {
  min-height: 42px;
  padding: 7px 10px;
  border-radius: 12px;
  background: var(--paper);
  font-size: 0.66rem;
  text-transform: uppercase;
}

.pedals {
  display: flex;
  align-items: end;
  gap: 12px;
}

.pedal {
  width: clamp(68px, 11vw, 104px);
  height: clamp(68px, 11vw, 104px);
  border-radius: 50%;
  font-size: clamp(0.68rem, 1.8vw, 0.95rem);
  text-transform: uppercase;
}

.brake { background: var(--pink); }
.gas {
  width: clamp(78px, 13vw, 118px);
  height: clamp(78px, 13vw, 118px);
  background: var(--lime);
}

.manual-steer {
  position: absolute;
  left: 22%;
  right: 38%;
  top: 0;
  bottom: 0;
  z-index: 15;
  touch-action: none;
}

@media (orientation: portrait) {
  .rotate-panel { display: grid; }
}

@media (orientation: landscape) {
  .rotate-panel { display: none; }
}

@media (max-height: 430px) {
  .chip { min-width: 70px; padding: 5px 7px 6px; }
  .chip strong { font-size: 0.95rem; }
  .chip.is-invalid-lap strong { font-size: 0.82rem; }
  .map-wrap { width: min(21vw, 142px); }
  .message { top: 17%; }
  .tilt-drive { width: min(34vw, 240px); bottom: 8px; }
  .utility { font-size: 0.59rem; min-height: 38px; }
}
