*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #090910;
  --surface:    #0f0f18;
  --border:     #1a1a28;
  --accent:     #3effa0;
  --gold:       #FFB300;
  --danger:     #ff4455;
  --text:       #f0f0f8;
  --text-muted: #52526e;
  --font:       -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', system-ui, sans-serif;
  --font-mono:  'SF Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --radius:     10px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: clamp(12px, 4vh, 48px);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse 60% 50% at 50% 40%, rgba(62,255,160,0.07) 0%, transparent 70%);
  pointer-events: none;
}

/* ── App shell ────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  will-change: transform;
}

/* ── HUD ──────────────────────────────────────────────── */
.hud {
  width: 480px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 60px;
}

.hud-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  font-family: var(--font-mono);
  text-transform: uppercase;
}

.hud-value {
  font-size: 20px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text);
  letter-spacing: -0.02em;
  min-width: 48px;
  text-align: center;
  display: inline-block;
}

@keyframes score-pop {
  0%   { transform: scale(1);    color: var(--text); }
  40%  { transform: scale(1.22); color: var(--accent); }
  100% { transform: scale(1);    color: var(--text); }
}

.hud-value.pop {
  animation: score-pop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.hud-brand {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.28em;
  color: var(--accent);
  font-family: var(--font-mono);
  text-shadow: 0 0 24px rgba(62,255,160,0.35);
}

/* ── Game canvas ──────────────────────────────────────── */
.game-container {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow:
    0 0 0 1px rgba(62,255,160,0.1),
    0 24px 64px rgba(0,0,0,0.7);
}

canvas { display: block; }

/* ── Overlay ──────────────────────────────────────────── */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(9,9,16,0.9);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  pointer-events: auto;
  transition: opacity 0.25s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: 100%;
  padding: 0 24px;
}

.overlay-panel.hidden { display: none; }

/* ── Overlay: idle / name input ───────────────────────── */
.overlay-title {
  font-size: 60px;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--text);
  line-height: 1;
}

/* ── Name input ───────────────────────────────────────── */
.name-field {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.name-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.name-input {
  width: 220px;
  padding: 10px 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-align: center;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
}

.name-input::placeholder {
  color: var(--text-muted);
  opacity: 0.45;
}

.name-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(62,255,160,0.12);
}

.overlay-hint {
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.overlay-controls {
  display: flex;
  gap: 20px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  opacity: 0.55;
}

/* ── Overlay: game over ───────────────────────────────── */
.gameover-title {
  font-size: 40px;
  font-weight: 900;
  letter-spacing: -0.03em;
  color: var(--danger);
  text-shadow: 0 0 40px rgba(255,68,85,0.3);
}

.score-display {
  display: flex;
  align-items: center;
  gap: 10px;
}

.score-display-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.score-display-value {
  font-size: 46px;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--accent);
  letter-spacing: -0.04em;
  line-height: 1;
  text-shadow: 0 0 28px rgba(62,255,160,0.25);
}

.rank-badge {
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-muted);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  padding: 3px 8px;
  align-self: flex-end;
  margin-bottom: 6px;
}

.rank-badge--top {
  color: var(--gold);
  background: rgba(255,179,0,0.1);
  border-color: rgba(255,179,0,0.3);
  text-shadow: 0 0 12px rgba(255,179,0,0.4);
}

/* ── Leaderboard ──────────────────────────────────────── */
.leaderboard {
  width: 100%;
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: none;
}

.leaderboard::-webkit-scrollbar { display: none; }

.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 10px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  transition: background 0.1s;
}

.lb-row--current {
  background: rgba(62,255,160,0.08);
  border: 1px solid rgba(62,255,160,0.18);
}

.lb-rank {
  color: var(--text-muted);
  min-width: 18px;
  text-align: right;
  font-size: 10px;
}

.lb-rank--top { color: var(--gold); }

.lb-name {
  flex: 1;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-score {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ── Buttons ──────────────────────────────────────────── */
.gameover-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.btn-primary {
  padding: 10px 28px;
  background: var(--accent);
  color: #06100a;
  border: none;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary:hover  { opacity: 0.86; }
.btn-primary:active { transform: scale(0.95); }

.btn-ghost {
  padding: 9px 20px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-ghost:hover  { border-color: rgba(255,255,255,0.2); color: var(--text); }
.btn-ghost:active { transform: scale(0.95); }

/* ── Mobile D-pad ─────────────────────────────────────── */
.dpad {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
  user-select: none;
}

/* Show only on actual touch devices */
@media (hover: none) and (pointer: coarse) {
  .dpad { display: flex; }
}

.dpad-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
}

.dpad-btn {
  width: 60px;
  height: 60px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.08s, border-color 0.08s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.dpad-btn:active {
  background: rgba(62,255,160,0.12);
  border-color: rgba(62,255,160,0.35);
}

.dpad-center {
  width: 60px;
  height: 60px;
}
