:root {
  --bg: #0a0a0a;
  --bg-raised: #131313;
  --border: #262626;
  --fg: #f5f5f2;
  --fg-muted: #a3a39d;
  --yellow: #ffd500;
  --yellow-fg: #0a0a0a;
  --violet: #8b5cf6;
  --red: #ff4d4d;
  --font-display: 'Archivo Black', 'Arial Black', sans-serif;
  --font-body: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-nav {
  width: 100%;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.game-nav a {
  color: var(--fg-muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.game-nav a:hover {
  color: var(--yellow);
}

.game-nav .brand {
  color: var(--fg);
  font-family: var(--font-display);
  text-transform: uppercase;
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.game-wrap {
  width: 100%;
  max-width: 920px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.game-title {
  font-family: var(--font-display);
  text-transform: uppercase;
  font-size: clamp(1.3rem, 4vw, 1.9rem);
  text-align: center;
}

.game-title .hl {
  color: var(--yellow);
}

.hud {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.95rem;
  font-weight: 700;
}

.hud span {
  color: var(--fg-muted);
  font-weight: 500;
  margin-right: 0.35rem;
}

.hud .warn {
  color: var(--red);
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #1b1b1b;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.stage.hit::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255, 77, 77, 0.28);
  pointer-events: none;
  animation: flash 0.25s ease-out;
}

@keyframes flash {
  from { opacity: 1; }
  to { opacity: 0; }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(10, 10, 10, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.9rem;
  padding: 1.5rem;
}

.overlay[hidden] {
  display: none;
}

.overlay h2 {
  font-family: var(--font-display);
  text-transform: uppercase;
  font-size: clamp(1.3rem, 5vw, 2rem);
}

.overlay p {
  color: var(--fg-muted);
  max-width: 420px;
  font-size: 0.95rem;
}

.overlay .fee {
  color: var(--yellow);
  font-size: 1.4rem;
  font-family: var(--font-display);
}

.overlay-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  display: inline-block;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.75rem 1.5rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  background: var(--yellow);
  color: var(--yellow-fg);
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-ghost {
  border: 1px solid var(--border);
  color: var(--fg);
  background: transparent;
}

.btn-ghost:hover {
  border-color: var(--yellow);
}

.btn-p {
  width: 5.5rem;
  height: 5.5rem;
  border-radius: 50%;
  background: var(--yellow);
  color: var(--yellow-fg);
  font-family: var(--font-display);
  font-size: 2.4rem;
  line-height: 1;
  border: none;
  cursor: pointer;
  box-shadow: 0 10px 26px -8px rgba(255, 213, 0, 0.55);
  animation: btn-p-pulse 1.8s ease-in-out infinite;
}

.btn-p:active {
  transform: scale(0.94);
  animation: none;
}

@keyframes btn-p-pulse {
  0%, 100% { box-shadow: 0 10px 26px -8px rgba(255, 213, 0, 0.55); }
  50% { box-shadow: 0 10px 34px -4px rgba(255, 213, 0, 0.85); }
}

@media (prefers-reduced-motion: reduce) {
  .btn-p { animation: none; }
}

.btn-p-caption {
  color: var(--fg-muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  margin-top: -0.25rem;
}

.controls-hint {
  color: var(--fg-muted);
  font-size: 0.85rem;
  text-align: center;
}

.touch-controls {
  display: none;
  position: absolute;
  left: 0.6rem;
  right: 0.6rem;
  bottom: 0.6rem;
  z-index: 5;
  align-items: flex-end;
  gap: 0.6rem;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}

.touch-controls > * {
  pointer-events: auto;
}

@media (pointer: coarse) {
  .touch-controls {
    display: flex;
  }
}

.drive-zone {
  position: relative;
  flex: 1;
  height: 4.2rem;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(19, 19, 19, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  overflow: hidden;
  touch-action: none;
}

.drive-guide {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: var(--border);
}

.drive-indicator {
  position: absolute;
  top: 0.5rem;
  bottom: 0.5rem;
  left: 50%;
  width: 3.4rem;
  margin-left: -1.7rem;
  border-radius: 10px;
  background: rgba(255, 213, 0, 0.16);
  border: 1px solid rgba(255, 213, 0, 0.4);
  transition: background 0.1s ease;
  pointer-events: none;
}

.drive-zone.active .drive-indicator {
  background: rgba(255, 213, 0, 0.32);
}

.drive-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.75rem;
  text-align: center;
  font-size: 0.7rem;
  color: var(--fg-muted);
  pointer-events: none;
}

.touch-side {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: center;
  justify-content: flex-end;
}

.gyro-toggle {
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(19, 19, 19, 0.65);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  color: var(--fg-muted);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.35rem 0.45rem;
  white-space: nowrap;
}

.gyro-toggle.active {
  background: var(--yellow);
  color: var(--yellow-fg);
  border-color: var(--yellow);
}

.touch-brake {
  width: 3.6rem;
  height: 3.6rem;
  flex-shrink: 0;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(19, 19, 19, 0.65);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  color: var(--fg);
  font-size: 0.62rem;
  font-weight: 700;
  touch-action: none;
}

.touch-brake:active {
  background: var(--red);
  color: #fff;
}

/* ---------- mobile landscape: reclaim vertical space, fix the stage to viewport height ---------- */

@media (pointer: coarse) and (orientation: landscape) {
  .game-nav {
    padding: 0.35rem 0.75rem;
  }

  .game-title {
    display: none;
  }

  .game-wrap {
    padding: 0.5rem 0.75rem;
    gap: 0.4rem;
  }

  .hud {
    font-size: 0.8rem;
  }

  .stage {
    width: auto;
    height: min(80vh, 66.6vw);
    aspect-ratio: 3 / 2;
    max-width: 100%;
    margin: 0 auto;
  }

  .drive-zone {
    height: 3.4rem;
  }

  .touch-brake {
    width: 3rem;
    height: 3rem;
  }
}
