*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0a0a0a;
  --accent: #00ffaa;
  --danger: #ff3355;
  --text: #e0e0e0;
  --font-d: Helvetica, Arial, sans-serif;
  --font-m: Helvetica, Arial, sans-serif;
  --sai-t: env(safe-area-inset-top, 0px);
  --sai-b: env(safe-area-inset-bottom, 0px);
  --sai-l: env(safe-area-inset-left, 0px);
  --sai-r: env(safe-area-inset-right, 0px);
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-m);
  line-height: 1.5;
  touch-action: auto;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#game-canvas {
  touch-action: none;
  display: block;
  width: 100vw;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
}
#game-canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* D-Pad */
.dpad {
  position: fixed;
  z-index: 50;
  width: 120px;
  height: 120px;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 50%;
  border: 1px solid rgba(0, 255, 170, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
}

.dpad.hidden {
  display: none;
}

/* Diagonal area/directional indicators */
.dpad::before {
  content: '';
  position: absolute;
  inset: 15px;
  border-radius: 50%;
  border: 1px dashed rgba(0, 255, 170, 0.15);
  pointer-events: none;
}

.dpad-btn {
  display: none; /* Hide old discrete buttons */
}

.dpad-center {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(0, 255, 170, 0.2);
  border: 1px solid rgba(0, 255, 170, 0.5);
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.05s linear;
}

.dpad-center::after {
  content: '';
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.8;
}

.dpad.active .dpad-center {
  background: rgba(0, 255, 170, 0.3);
  border-color: var(--accent);
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 72px 0 0;
  max-height: calc(100dvh - 72px);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background: rgba(10, 10, 10, 0.93);
  padding: 20px max(20px, var(--sai-r)) max(20px, var(--sai-b)) max(20px, var(--sai-l));
  overflow-y: auto;
  overscroll-behavior: contain;
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  text-align: center;
  max-width: 440px;
  width: 100%;
  margin: auto;
  flex-shrink: 0;
  padding: 24px 20px;
}

.title-text {
  font-family: var(--font-d);
  font-weight: 500;
  font-size: clamp(2rem, 6vw, 3rem);
  letter-spacing: normal;
  color: #fff;
  margin-bottom: 8px;
  line-height: 1.1;
}

.title-text .accent {
  color: var(--accent);
}

.subtitle {
  font-family: var(--font-m);
  font-size: .875rem;
  color: #b5bbb8;
  letter-spacing: normal;
  margin-bottom: 28px;
}

.instructions {
  margin-bottom: 28px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.instruction-row {
  font-size: .875rem;
  color: #b5bbb8;
  letter-spacing: normal;
}

.key {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid rgba(0, 255, 170, 0.3);
  border-radius: 0;
  color: var(--accent);
  font-size: inherit;
}

.neon-btn {
  display: block;
  width: 100%;
  font-family: var(--font-d);
  font-weight: 500;
  font-size: 1rem;
  letter-spacing: normal;
  min-height: 44px;
  appearance: none;
  -webkit-appearance: none;
  padding: 13px 28px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 0;
  cursor: pointer;
  transition: background-color .15s, color .15s, border-color .15s;
  margin-bottom: 10px;
}

.neon-btn:hover,
.neon-btn:active {
  background: rgba(0, 255, 170, 0.12);
}

.neon-btn.secondary {
  color: #b5bbb8;
  border-color: #6f7773;
  font-size: 1rem;
  padding: 10px 20px;
}

.neon-btn.secondary:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 20px 0;
}

.stat-item {
  text-align: center;
}

.stat-value {
  font-family: var(--font-d);
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--accent);
  display: block;
}

.stat-label {
  font-size: .8125rem;
  color: #b5bbb8;
  letter-spacing: normal;
  text-transform: uppercase;
  margin-top: 2px;
}

/* Name Entry */
.name-entry {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.name-entry input {
  flex: 1;
  min-width: 0;
  background: #111;
  color: var(--accent);
  border: 1px solid #6f7773;
  border-radius: 0;
  min-height: 44px;
  appearance: none;
  -webkit-appearance: none;
  padding: 10px 14px;
  font-family: var(--font-m);
  font-size: 1rem;
  letter-spacing: normal;
  text-transform: uppercase;
  outline: none;
  -webkit-user-select: auto;
  user-select: auto;
  touch-action: auto;
}

.name-entry input:focus {
  border-color: var(--accent);
}

.name-entry .neon-btn {
  width: auto;
  margin: 0;
  padding: 10px 18px;
  font-size: .85rem;
}

/* Leaderboard */
.lb-results {
  text-align: left;
}

.lb-results.hidden {
  display: none;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: .82rem;
}

.lb-rank {
  font-family: var(--font-d);
  color: #b5bbb8;
  width: 26px;
  font-size: .75rem;
}

.lb-name {
  flex: 1;
  color: #fff;
  letter-spacing: normal;
  text-transform: uppercase;
}

.lb-score {
  color: var(--accent);
  font-family: var(--font-d);
  font-size: .9rem;
}

.lb-speed {
  color: #b5bbb8;
  font-size: .8125rem;
}

.lb-empty {
  text-align: center;
  color: #b5bbb8;
  padding: 20px;
  font-size: .875rem;
}

@media (max-width: 768px) {
  .overlay { inset-block-start: 64px; max-height: calc(100dvh - 64px); }
}
