:root {
  color-scheme: dark;
  --bg: #05070a;
  --panel: rgba(12, 18, 24, 0.9);
  --line: rgba(124, 242, 255, 0.32);
  --text: #edf7f8;
  --muted: #8ba4aa;
  --cyan: #4df5ff;
  --green: #72ff83;
  --yellow: #ffd057;
  --red: #ff4d5d;
}

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

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background:
    radial-gradient(circle at 18% 20%, rgba(77, 245, 255, 0.13), transparent 28%),
    radial-gradient(circle at 82% 42%, rgba(255, 77, 93, 0.11), transparent 25%),
    linear-gradient(180deg, #081118 0%, #05070a 58%, #020304 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) 132px;
  gap: 10px;
  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));
}

.hud {
  display: grid;
  grid-template-columns: repeat(6, minmax(82px, 1fr));
  gap: 8px;
  z-index: 2;
}

.hud-card {
  min-width: 0;
  border: 1px solid var(--line);
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.035) 0 2px, transparent 2px 9px),
    linear-gradient(180deg, rgba(18, 28, 34, 0.94), rgba(8, 13, 17, 0.94));
  border-radius: 8px;
  padding: 8px 10px;
  box-shadow: 0 0 18px rgba(77, 245, 255, 0.08);
}

.hud-card.flash {
  animation: hudFlash 260ms ease;
}

.hud-card span,
.control span,
.control b,
.control em {
  letter-spacing: 0;
}

.hud-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
}

.hud-card strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(17px, 3vh, 28px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.angle-card strong {
  color: var(--cyan);
}

.stage-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(124, 242, 255, 0.25);
  border-radius: 8px;
  background: #070c10;
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.5);
  touch-action: none;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

.banner {
  display: none;
  position: absolute;
  left: clamp(32px, 12vw, 190px);
  bottom: 92px;
  transform: scale(0.92) rotate(-1deg);
  min-width: 172px;
  max-width: min(320px, calc(100% - 28px));
  padding: 10px 18px;
  border: 2px solid rgba(255, 208, 87, 0.9);
  border-radius: 8px;
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 208, 87, 0.42), transparent 38%),
    linear-gradient(135deg, rgba(255, 77, 93, 0.9), rgba(40, 8, 10, 0.92) 62%, rgba(5, 7, 10, 0.9));
  color: var(--yellow);
  font-size: clamp(14px, 2.4vh, 24px);
  font-weight: 900;
  line-height: 1;
  text-align: center;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.55), 0 0 18px rgba(255, 208, 87, 0.7);
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease;
  box-shadow: 0 0 22px rgba(255, 77, 93, 0.38), 0 0 34px rgba(255, 208, 87, 0.18);
  z-index: 3;
}

.banner.show {
  opacity: 1;
  transform: scale(1) rotate(-1deg);
}

.action-bar {
  position: absolute;
  right: 14px;
  top: 14px;
  display: flex;
  gap: 8px;
  z-index: 2;
}

.action-bar button,
.action-link {
  min-width: 54px;
  min-height: 34px;
  border: 1px solid rgba(124, 242, 255, 0.35);
  border-radius: 8px;
  background: rgba(5, 7, 10, 0.68);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  display: grid;
  place-items: center;
  text-decoration: none;
  padding: 0 10px;
}

.action-bar button:active,
.action-link:active {
  transform: translateY(1px);
}

.sound-button {
  border-color: rgba(255, 83, 93, 0.74) !important;
  background: rgba(120, 9, 19, 0.72) !important;
  color: #ffe5e8 !important;
}

.sound-button.sound-on {
  border-color: rgba(114, 255, 131, 0.72) !important;
  background: rgba(114, 255, 131, 0.26) !important;
  color: #dfffe6 !important;
  box-shadow: 0 0 18px rgba(114, 255, 131, 0.24);
}

.sound-button.sound-off {
  border-color: rgba(255, 83, 93, 0.82) !important;
  background: rgba(120, 9, 19, 0.78) !important;
  box-shadow: 0 0 16px rgba(255, 83, 93, 0.2);
}

.tutorial {
  position: absolute;
  left: 16px;
  bottom: 40px;
  max-width: min(460px, calc(100% - 32px));
  padding: 10px 12px;
  border: 1px solid rgba(77, 245, 255, 0.35);
  border-radius: 8px;
  background: rgba(5, 7, 10, 0.72);
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.25;
  opacity: 0;
  transition: opacity 160ms ease;
  pointer-events: none;
}

.tutorial.show {
  opacity: 1;
}

.angle-meter {
  position: absolute;
  left: 34px;
  right: 10px;
  bottom: 16px;
  height: 14px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.zone {
  display: block;
  height: 100%;
  float: left;
}

.zone.low {
  width: 50%;
  background: rgba(114, 255, 131, 0.32);
}

.zone.balance {
  width: 25%;
  background: rgba(255, 208, 87, 0.38);
}

.zone.twelve {
  width: 6%;
  background: rgba(77, 245, 255, 0.82);
}

.zone.danger {
  width: 19%;
  background: rgba(255, 77, 93, 0.58);
}

.angle-meter i {
  position: absolute;
  top: -5px;
  left: 0%;
  width: 4px;
  height: 24px;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 0 14px #fff;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  min-height: 0;
  z-index: 2;
}

.control {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 104px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  box-shadow: none;
  touch-action: none;
}

.control span,
.control b {
  position: absolute;
  bottom: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.control em {
  position: absolute;
  right: 10px;
  top: 8px;
  color: var(--cyan);
  font-size: 20px;
  font-style: normal;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.clutch-control {
  justify-items: stretch;
  padding: 10px 20px 10px 10px;
}

.clutch-control::after {
  content: none;
  position: absolute;
  right: 18px;
  top: 50%;
  width: 42px;
  height: 54px;
  border-radius: 10px 20px 20px 10px;
  border: 2px solid rgba(237, 247, 248, 0.28);
  background:
    radial-gradient(circle at 72% 50%, rgba(77, 245, 255, 0.45), transparent 34%),
    linear-gradient(180deg, #17232a, #080d11);
  box-shadow: 0 0 22px rgba(77, 245, 255, 0.18);
  transform: translateY(-50%);
}

.lever {
  justify-self: end;
  width: min(46vw, 238px);
  height: 62px;
  border-radius: 999px;
  background-color: transparent;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  transform-origin: calc(100% - 24px) 50%;
  transform: rotate(18deg);
  box-shadow: none;
  z-index: 1;
}

.lever::before {
  content: none;
  position: absolute;
  right: -2px;
  top: 50%;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: #101920;
  border: 2px solid rgba(255, 255, 255, 0.24);
  transform: translateY(-50%);
}

.lever::after {
  content: none;
  position: absolute;
  left: 4px;
  top: 50%;
  width: 30px;
  height: 10px;
  border-radius: 999px;
  background: rgba(5, 7, 10, 0.34);
  transform: translateY(-50%);
}

.brake-control {
  cursor: pointer;
}

.brake-disc {
  width: 144px;
  height: 144px;
  border-radius: 50%;
  border: 0;
  background-color: transparent;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  box-shadow: none;
  transition: transform 80ms ease, box-shadow 80ms ease;
}

.brake-control.active .brake-disc {
  transform: scale(0.92) translateY(8px);
  box-shadow: none;
}

.grip {
  width: min(46vw, 210px);
  height: 62px;
  border-radius: 999px;
  background-color: transparent;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  border: 0;
  box-shadow: none;
}

.throttle-control::after {
  content: none;
  position: absolute;
  right: 14px;
  top: 50%;
  width: 44px;
  height: 22px;
  border: 1px solid rgba(255, 77, 93, 0.55);
  border-radius: 999px;
  color: rgba(255, 77, 93, 0.85);
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 900;
  transform: translateY(-50%);
}

.throttle-control.red-zone {
  box-shadow: none;
}

.throttle-control.red-zone .grip {
  box-shadow: none;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(2, 4, 6, 0.72);
}

.overlay[hidden] {
  display: none;
}

.panel {
  width: min(560px, 94vw);
  max-height: min(92dvh, 820px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  border: 1px solid rgba(124, 242, 255, 0.32);
  border-radius: 8px;
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.035) 0 2px, transparent 2px 10px),
    rgba(8, 12, 16, 0.94);
  padding: 24px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.48), 0 0 42px rgba(77, 245, 255, 0.08);
}

.result-overlay {
  place-items: stretch center;
  overflow: hidden;
}

.result-overlay .panel {
  height: calc(100dvh - 36px);
  max-height: calc(100dvh - 36px);
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.compact-panel {
  width: min(460px, 92vw);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-size: clamp(34px, 8vw, 64px);
  line-height: 0.9;
  letter-spacing: 0;
}

h2 {
  font-size: clamp(28px, 6vw, 48px);
}

.tagline {
  margin: 14px 0 0;
  color: #c9d8db;
  font-size: 16px;
  line-height: 1.45;
}

.menu-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.menu-actions button,
.menu-link {
  min-height: 44px;
  border: 1px solid rgba(124, 242, 255, 0.36);
  border-radius: 8px;
  background: rgba(77, 245, 255, 0.13);
  color: var(--text);
  cursor: pointer;
  font-weight: 900;
  padding: 10px 14px;
  display: grid;
  place-items: center;
  text-decoration: none;
}

.menu-actions button:active,
.menu-link:active {
  transform: translateY(1px);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 20px;
}

.result-grid div {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.05);
}

.result-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.result-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 26px;
  font-variant-numeric: tabular-nums;
}

.leaderboard-panel {
  margin-top: 18px;
}

.leaderboard-panel h3 {
  margin: 0 0 10px;
  color: var(--yellow);
  font-size: 18px;
}

.leaderboard-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.leaderboard-form input,
.leaderboard-form select {
  min-width: 0;
  height: 40px;
  border: 1px solid rgba(124, 242, 255, 0.3);
  border-radius: 8px;
  background: rgba(5, 7, 10, 0.72);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  padding: 0 10px;
  -webkit-user-select: text;
  user-select: text;
}

.leaderboard-form button {
  grid-column: span 2;
  min-height: 42px;
  border: 1px solid rgba(255, 208, 87, 0.55);
  border-radius: 8px;
  background: rgba(255, 208, 87, 0.16);
  color: var(--text);
  font: inherit;
  font-weight: 900;
}

.leaderboard-list {
  display: grid;
  gap: 6px;
  max-height: 180px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  overflow: auto;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  gap: 8px;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  padding: 8px 10px;
  font-size: 13px;
}

.leaderboard-list b {
  color: var(--cyan);
}

.leaderboard-list span {
  color: var(--muted);
  font-weight: 800;
}

.ig-link {
  color: var(--cyan);
  font-weight: 900;
  text-decoration: none;
}

.ig-link:active,
.ig-link:hover {
  color: var(--yellow);
}

.rotate-warning {
  display: none;
}

@keyframes hudFlash {
  0% { border-color: rgba(255, 208, 87, 0.35); transform: scale(1); }
  45% { border-color: rgba(255, 208, 87, 1); transform: scale(1.04); }
  100% { border-color: var(--line); transform: scale(1); }
}

@media (orientation: portrait) and (max-width: 760px) {
  .game-shell {
    grid-template-rows: auto minmax(0, 1fr) 34dvh;
    gap: 8px;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

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

  .hud-card {
    padding: 6px 7px;
  }

  .hud-card span {
    font-size: 9px;
  }

  .hud-card strong {
    font-size: clamp(16px, 5vw, 22px);
  }

  .stage-wrap {
    border-radius: 8px;
  }

  .controls {
    grid-template-columns: 0.95fr 1.1fr 0.95fr;
    gap: 8px;
  }

  .control {
    min-height: 0;
    height: 100%;
  }

  .control span,
  .control b {
    bottom: 8px;
    font-size: 10px;
  }

  .control em {
    top: 7px;
    right: 8px;
    font-size: 18px;
  }

  .lever {
    width: min(36vw, 174px);
    height: 58px;
  }

  .grip {
    width: min(36vw, 168px);
    height: 58px;
  }

  .brake-disc {
    width: min(31vw, 144px);
    height: min(31vw, 144px);
  }

  .action-bar {
    left: 10px;
    right: 10px;
    top: 10px;
    justify-content: flex-end;
    gap: 6px;
  }

  .action-bar button {
    min-width: 48px;
    min-height: 31px;
    padding: 0 7px;
    font-size: 11px;
  }

  .tutorial {
    left: 10px;
    right: 10px;
    bottom: 34px;
    max-width: none;
    padding: 8px 9px;
    font-size: 12px;
  }

  .banner {
    left: 46px;
    bottom: 86px;
    min-width: 178px;
    max-width: calc(100% - 112px);
    padding: 9px 13px;
    font-size: clamp(13px, 3.8vw, 17px);
  }

  .angle-meter {
    left: 32px;
    right: 10px;
    bottom: 10px;
  }

  .panel {
    width: min(390px, 94vw);
    padding: 18px;
  }

  h1 {
    font-size: clamp(36px, 14vw, 56px);
  }

  h2 {
    font-size: clamp(28px, 10vw, 42px);
  }

  .tagline {
    font-size: 14px;
  }

  .menu-actions button {
    flex: 1 1 100%;
  }
}

@media (max-height: 580px) {
  .game-shell {
    grid-template-rows: auto minmax(0, 1fr) 108px;
    gap: 7px;
  }

  .hud-card {
    padding: 6px 8px;
  }

  .hud-card span {
    font-size: 10px;
  }

  .control {
    min-height: 88px;
  }

  .panel {
    padding: 18px;
  }

  .action-bar {
    right: 10px;
    top: 10px;
  }

  .action-bar button {
    min-width: 50px;
    min-height: 30px;
  }
}

@media (max-width: 760px) {
  .hud {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .game-shell {
    grid-template-rows: auto minmax(0, 1fr) 116px;
  }
}
