:root {
  color-scheme: dark;
  --ink: #f7fbff;
  --muted: #92a0b8;
  --panel: rgba(7, 10, 24, 0.72);
  --pink: #ff347f;
  --cyan: #23e4ff;
  --yellow: #ffe066;
  --edge: rgba(255, 255, 255, 0.16);
  font-family: "Arial Narrow", "Roboto Condensed", Impact, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #070915;
  color: var(--ink);
}

body {
  min-height: 100dvh;
  touch-action: none;
  user-select: none;
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  width: 100%;
  height: 100dvh;
  min-height: 430px;
  overflow: hidden;
  isolation: isolate;
  background: #080a16;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.game-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255, 20, 90, 0.06), transparent 35%, transparent 65%, rgba(0, 220, 255, 0.05)),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 3px);
  mix-blend-mode: screen;
}

.topbar {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: max(18px, env(safe-area-inset-left));
  right: max(18px, env(safe-area-inset-right));
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 900;
  letter-spacing: 0.11em;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.8);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 49px;
  height: 28px;
  color: #07111c;
  font-size: 0.78rem;
  line-height: 1;
  letter-spacing: -0.04em;
  transform: skew(-9deg);
  background: var(--cyan);
  box-shadow: 4px 4px 0 var(--pink);
}

.brand-name {
  font-size: clamp(0.75rem, 1.8vw, 1rem);
}

.sound-button {
  width: 44px;
  height: 44px;
  padding: 10px;
  border: 1px solid var(--edge);
  border-radius: 50%;
  color: var(--ink);
  background: rgba(4, 8, 19, 0.5);
  backdrop-filter: blur(8px);
  pointer-events: auto;
  cursor: pointer;
}

.sound-button svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.sound-button svg path:not(:first-child) {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.sound-button[aria-pressed="false"] .sound-wave,
.sound-button[aria-pressed="true"] .sound-off {
  display: none;
}

.hud {
  position: absolute;
  top: max(64px, calc(env(safe-area-inset-top) + 50px));
  left: 50%;
  z-index: 7;
  display: flex;
  align-items: stretch;
  transform: translateX(-50%);
  border: 1px solid rgba(255, 255, 255, 0.13);
  background: linear-gradient(180deg, rgba(10, 14, 31, 0.78), rgba(5, 8, 18, 0.6));
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(9px);
  opacity: 0;
  transition: opacity 240ms ease;
}

.racing .hud,
.finished .hud,
.racing .speedometer,
.finished .speedometer {
  opacity: 1;
}

.hud-block {
  min-width: 88px;
  padding: 8px 14px 9px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-right: 1px solid rgba(255, 255, 255, 0.11);
  font-variant-numeric: tabular-nums;
}

.hud-block:last-child {
  border-right: 0;
}

.hud-label {
  margin-bottom: 2px;
  color: var(--cyan);
  font-size: 0.65rem;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.hud-block b {
  font-size: 1.15rem;
  font-style: italic;
  letter-spacing: 0.035em;
}

.hud-block small {
  margin-left: 3px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.speedometer {
  position: absolute;
  z-index: 7;
  right: max(22px, env(safe-area-inset-right));
  bottom: max(26px, calc(env(safe-area-inset-bottom) + 14px));
  width: 105px;
  padding: 8px 10px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 4px 12px #000;
  opacity: 0;
  transition: opacity 240ms ease;
}

.speedometer > span {
  display: block;
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 0.9;
  font-style: italic;
  font-weight: 900;
  letter-spacing: -0.06em;
}

.speedometer small {
  color: var(--cyan);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.tach {
  height: 4px;
  margin-top: 6px;
  overflow: hidden;
  transform: skewX(-15deg);
  background: rgba(255, 255, 255, 0.18);
}

.tach i {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--yellow), var(--pink));
}

.start-card,
.finish-card {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 10;
  width: min(530px, calc(100% - 36px));
  padding: clamp(24px, 4vw, 46px);
  transform: translate(-50%, -50%);
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.17);
  background:
    linear-gradient(135deg, rgba(16, 23, 50, 0.94), rgba(5, 8, 19, 0.88)),
    rgba(7, 10, 23, 0.9);
  box-shadow:
    0 30px 90px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px);
  clip-path: polygon(16px 0, 100% 0, 100% calc(100% - 16px), calc(100% - 16px) 100%, 0 100%, 0 16px);
}

.start-card::before,
.finish-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  width: 88px;
  height: 3px;
  background: linear-gradient(90deg, var(--cyan), var(--pink));
  box-shadow: 0 0 18px var(--pink);
}

.start-card.is-leaving,
.finish-card.is-leaving {
  animation: cardOut 350ms ease forwards;
}

@keyframes cardOut {
  to { opacity: 0; transform: translate(-50%, -46%) scale(0.96); }
}

.eyebrow {
  color: var(--cyan);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.24em;
}

h1,
h2 {
  margin: 12px 0;
  line-height: 0.88;
  font-style: italic;
  font-weight: 900;
  letter-spacing: -0.055em;
  text-shadow: 4px 5px 0 rgba(255, 52, 127, 0.22);
}

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

h2 {
  font-size: clamp(2.4rem, 7vw, 4.6rem);
}

h1 em {
  display: inline-block;
  color: var(--pink);
  font-style: inherit;
  text-shadow: 3px 3px 0 rgba(35, 228, 255, 0.28);
}

.intro {
  margin: 18px auto 20px;
  color: #b8c2d5;
  font-family: system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.45;
}

.control-hints {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin: 20px 0 24px;
  color: #b6c0d4;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.control-hints span {
  display: flex;
  align-items: center;
  gap: 5px;
}

kbd {
  min-width: 25px;
  padding: 5px 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-bottom-color: rgba(255, 255, 255, 0.36);
  border-radius: 4px;
  color: white;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
}

.start-button {
  min-width: 210px;
  min-height: 56px;
  padding: 0 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  color: #07111a;
  background: var(--cyan);
  box-shadow: 7px 7px 0 var(--pink), 0 0 32px rgba(35, 228, 255, 0.2);
  cursor: pointer;
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.08em;
  clip-path: polygon(9px 0, 100% 0, 100% calc(100% - 9px), calc(100% - 9px) 100%, 0 100%, 0 9px);
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.start-button:hover {
  transform: translate(-2px, -2px);
  background: #78efff;
  box-shadow: 9px 9px 0 var(--pink), 0 0 40px rgba(35, 228, 255, 0.28);
}

.start-button:active {
  transform: translate(4px, 4px);
  box-shadow: 2px 2px 0 var(--pink);
}

.start-button svg {
  width: 22px;
  fill: currentColor;
}

.phone-hint {
  margin: 18px 0 0;
  color: #68758e;
  font-family: system-ui, sans-serif;
  font-size: 0.78rem;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin: 24px 0 28px;
  background: rgba(255, 255, 255, 0.13);
}

.result-grid div {
  padding: 13px 8px;
  background: rgba(8, 12, 27, 0.9);
}

.result-grid span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.result-grid b {
  color: var(--cyan);
  font-size: clamp(0.85rem, 3vw, 1.25rem);
  font-style: italic;
  font-variant-numeric: tabular-nums;
}

.race-message {
  position: absolute;
  top: 42%;
  left: 50%;
  z-index: 9;
  width: 100%;
  transform: translate(-50%, -50%);
  text-align: center;
  font-size: clamp(4rem, 15vw, 9rem);
  line-height: 1;
  font-weight: 900;
  font-style: italic;
  letter-spacing: -0.06em;
  text-shadow: 6px 7px 0 var(--pink), 0 0 50px rgba(35, 228, 255, 0.5);
  pointer-events: none;
}

.race-message.flash {
  animation: messageFlash 850ms ease both;
}

@keyframes messageFlash {
  0% { opacity: 0; transform: translate(-50%, -44%) scale(1.35); }
  18%, 70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -54%) scale(0.92); }
}

.touch-controls {
  position: absolute;
  z-index: 8;
  inset: auto max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  display: flex;
  justify-content: space-between;
  align-items: end;
  pointer-events: none;
  opacity: 0;
  transition: opacity 220ms ease;
}

.racing .touch-controls {
  opacity: 1;
}

.steering-controls,
.pedal-controls {
  display: flex;
  align-items: end;
  gap: 10px;
}

.touch-button {
  width: clamp(62px, 15vw, 88px);
  height: clamp(62px, 15vw, 88px);
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.23);
  border-radius: 50%;
  color: white;
  background: rgba(7, 10, 24, 0.48);
  box-shadow: inset 0 0 18px rgba(255, 255, 255, 0.04), 0 6px 24px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(8px);
  pointer-events: auto;
  touch-action: none;
}

.touch-button svg {
  width: 34px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.touch-button span {
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.touch-button.gas {
  width: clamp(72px, 18vw, 100px);
  height: clamp(72px, 18vw, 100px);
  border-color: rgba(35, 228, 255, 0.58);
  color: var(--cyan);
}

.touch-button.brake {
  width: clamp(58px, 13vw, 76px);
  height: clamp(58px, 13vw, 76px);
  border-color: rgba(255, 52, 127, 0.5);
  color: #ff80ad;
}

.touch-button.is-active {
  transform: scale(0.92);
  color: #07111a;
  background: var(--cyan);
  box-shadow: 0 0 30px rgba(35, 228, 255, 0.42);
}

.touch-button.brake.is-active {
  background: var(--pink);
}

.rotate-notice {
  display: none;
}

[hidden] {
  display: none !important;
}

@media (hover: hover) and (pointer: fine) {
  .touch-controls { display: none; }
}

@media (max-width: 650px) {
  .brand-name { display: none; }
  .hud { top: max(13px, env(safe-area-inset-top)); }
  .hud-block { min-width: 74px; padding: 7px 9px; }
  .hud-block b { font-size: 1rem; }
  .time-block { min-width: 104px; }
  .topbar { top: max(15px, env(safe-area-inset-top)); }
  .topbar .brand { visibility: hidden; }
  .speedometer { right: max(15px, env(safe-area-inset-right)); bottom: max(106px, calc(env(safe-area-inset-bottom) + 96px)); }
  .control-hints { display: none; }
  .start-card, .finish-card { padding: 26px 22px 30px; }
  .intro { margin: 15px auto 21px; }
}

@media (max-height: 480px) {
  .topbar { top: 9px; }
  .start-card, .finish-card { width: min(650px, calc(100% - 100px)); padding: 18px 30px 21px; }
  .start-card h1 { font-size: clamp(2.6rem, 11vh, 4.2rem); margin: 8px 0; }
  .finish-card h2 { font-size: clamp(2rem, 10vh, 3.4rem); margin: 8px 0; }
  .intro { margin: 8px auto 10px; }
  .control-hints { margin: 10px 0 15px; }
  .phone-hint { display: none; }
  .start-button { min-height: 48px; }
  .hud { top: 9px; }
  .speedometer { bottom: 13px; }
  .touch-controls { bottom: max(8px, env(safe-area-inset-bottom)); }
}

@media (orientation: portrait) and (max-width: 500px) {
  .game-shell:not(.racing):not(.finished) .rotate-notice {
    position: absolute;
    bottom: calc(env(safe-area-inset-bottom) + 18px);
    left: 50%;
    z-index: 12;
    display: flex;
    align-items: center;
    gap: 8px;
    transform: translateX(-50%);
    color: #8d99ae;
    font-size: 0.75rem;
    font-family: system-ui, sans-serif;
  }
  .rotate-notice svg { width: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
