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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  color: #e8e8e8;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

/* ─── Game Container ────────────────────────────── */
#game-container {
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: 0;
  transition: opacity 1s ease;
}

#game-container.visible {
  opacity: 1;
}

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

/* ─── Intro Screen ──────────────────────────────── */
#intro-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  transition: opacity 0.8s ease;
}

#intro-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

#intro-text {
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  font-size: clamp(1.2rem, 4vw, 2rem);
  color: #e8e8e8;
  letter-spacing: 0.08em;
  opacity: 0;
  transition: opacity 1.2s ease;
  text-align: center;
  padding: 0 2rem;
}

#intro-text.visible {
  opacity: 1;
}

/* ─── HUD ───────────────────────────────────────── */
#hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  padding: env(safe-area-inset-top, 16px) env(safe-area-inset-right, 16px) env(safe-area-inset-bottom, 16px) env(safe-area-inset-left, 16px);
  opacity: 0;
  transition: opacity 0.6s ease;
}

#hud.visible {
  opacity: 1;
}

#hud-top-left {
  position: absolute;
  top: calc(env(safe-area-inset-top, 12px) + 12px);
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.miles-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.3em;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

#miles-display {
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  font-size: clamp(2.8rem, 12vw, 6rem);
  line-height: 1;
  color: #ffeb3b;
  letter-spacing: -0.02em;
  text-shadow: 0 0 10px rgba(255, 235, 59, 0.3), 0 2px 4px rgba(0, 0, 0, 0.5);
}

.miles-row .unit {
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  font-size: clamp(1rem, 3vw, 1.4rem);
  color: rgba(255, 255, 255, 0.9);
  letter-spacing: 0.08em;
  text-transform: lowercase;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

#streak-display {
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  font-size: clamp(1rem, 3vw, 1.3rem);
  color: rgba(255, 255, 255, 0.85);
  letter-spacing: 0.04em;
  margin-top: 4px;
  text-align: center;
  text-shadow: 0 2px 6px rgba(0,0,0,0.6);
}

#hud-top-right {
  position: absolute;
  top: calc(env(safe-area-inset-top, 12px) + 18px);
  right: calc(env(safe-area-inset-right, 16px) + 16px);
}

#fps-display {
  font-family: 'Inter', monospace;
  font-weight: 400;
  font-size: clamp(0.7rem, 2vw, 0.85rem);
  color: rgba(0, 255, 100, 0.7);
  letter-spacing: 0.02em;
  text-align: right;
  margin-bottom: 4px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

#pace-display {
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  font-size: clamp(0.75rem, 2.5vw, 1rem);
  color: rgba(200, 198, 190, 0.4);
  letter-spacing: 0.04em;
}

#hud-bottom {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 12px) + 16px);
  left: 0;
  right: 0;
  text-align: center;
}

#online-display {
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  font-size: clamp(0.85rem, 2.5vw, 1.1rem);
  color: rgba(255, 255, 255, 0.65);
  letter-spacing: 0.04em;
  text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

/* ─── Stamina Bar ──────────────────────────────── */
#speed-display {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 12px) + 56px);
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Orbitron', monospace;
  font-weight: 700;
  font-size: clamp(1.3rem, 4vw, 1.8rem);
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 0 10px rgba(255,255,255,0.3), 0 2px 6px rgba(0,0,0,0.6);
  letter-spacing: 0.05em;
  text-align: center;
  transition: color 0.3s ease;
}

#stamina-bar {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 12px) + 48px);
  left: 50%;
  transform: translateX(-50%);
  width: clamp(120px, 35vw, 200px);
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  z-index: 12;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s ease;
}

#hud.visible ~ #stamina-bar {
  opacity: 1;
}

#stamina-fill {
  height: 100%;
  width: 100%;
  background: rgba(120, 200, 120, 0.7);
  border-radius: 2px;
  transition: width 0.2s ease, background-color 0.5s ease;
}

/* ─── Pickup Text ─────────────────────────────── */
#pickup-text {
  position: fixed;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 15;
  pointer-events: none;
  white-space: nowrap;
  font-family: 'Orbitron', 'Inter', sans-serif;
  font-weight: 700;
  font-size: clamp(1.6rem, 5.5vw, 3.5rem);
  color: rgba(255, 255, 255, 0);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow: none;
  opacity: 0;
  -webkit-text-stroke: 1px rgba(0,0,0,0.3);
  transition: color 0.3s ease, transform 0.3s ease, opacity 0.3s ease, text-shadow 0.3s ease;
}

#pickup-text.visible {
  color: #fff;
  text-shadow: 
    0 0 20px rgba(255, 255, 255, 0.8),
    0 0 40px rgba(255, 235, 59, 0.6),
    0 0 60px rgba(255, 235, 59, 0.3),
    0 4px 12px rgba(0,0,0,0.8);
  opacity: 1;
  transform: translate(-50%, -55%) scale(1.05);
}

#pickup-text.fade-out {
  color: rgba(255, 255, 255, 0);
  text-shadow: none;
  opacity: 0;
  transform: translate(-50%, -65%) scale(0.95);
  transition: color 1s ease, transform 1s ease, opacity 1s ease, text-shadow 1s ease;
}

/* ─── Runner's High Indicator ────────────────── */
#high-indicator {
  position: fixed;
  top: calc(env(safe-area-inset-top, 12px) + 80px);
  left: 0;
  right: 0;
  text-align: center;
  z-index: 12;
  pointer-events: none;
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  font-size: clamp(1rem, 3.5vw, 1.4rem);
  letter-spacing: 0.3em;
  color: rgba(255, 220, 150, 0);
  text-shadow: 0 0 12px rgba(255, 180, 50, 0.6), 0 2px 4px rgba(0,0,0,0.8);
  transition: color 1.5s ease;
}

#high-indicator.visible {
  color: rgba(255, 230, 100, 0.95);
}

/* ─── Quote Display ────────────────────────────── */
#quote-display {
  position: fixed;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  pointer-events: none;
  text-align: center;
  width: 90%;
  max-width: 600px;
  font-family: 'Caveat', cursive;
  font-size: clamp(1.8rem, 6vw, 3.2rem);
  font-weight: 700;
  color: rgba(255, 255, 255, 0);
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8), 0 0 10px rgba(255, 255, 255, 0.3);
  letter-spacing: 0.02em;
  line-height: 1.3;
  word-wrap: break-word;
  overflow-wrap: break-word;
  transition: all 1s ease;
}

#quote-display.visible {
  color: rgba(255, 255, 255, 0.9);
}

#quote-display.fade-out {
  color: rgba(255, 255, 255, 0);
  opacity: 0;
  transition: all 1.5s ease;
}

/* ─── Echo Display ──────────────────────────────── */
#echo-display {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 15;
  pointer-events: none;
  text-align: center;
  width: 85%;
  max-width: 500px;
  font-family: 'Caveat', cursive;
  font-size: clamp(1.3rem, 5vw, 2rem);
  font-weight: 400;
  color: rgba(210, 208, 200, 0);
  letter-spacing: 0.02em;
  line-height: 1.4;
  transition: color 1s ease;
}

#echo-display.visible {
  color: rgba(210, 208, 200, 0.7);
}

#echo-display.fade-out {
  color: rgba(210, 208, 200, 0);
  transition: color 1.5s ease;
}

/* ─── Echo Input Overlay ────────────────────────── */
#echo-input-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

#echo-input-overlay.active {
  opacity: 1;
  pointer-events: all;
}

#echo-input-box {
  text-align: center;
  max-width: 400px;
  width: 85%;
}

#echo-input-prompt {
  font-family: 'Caveat', cursive;
  font-size: clamp(1.3rem, 5vw, 1.8rem);
  color: rgba(200, 198, 190, 0.7);
  margin-bottom: 1.5rem;
  letter-spacing: 0.02em;
  font-weight: 400;
}

#echo-mile-num {
  font-weight: 600;
}

#echo-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  color: #e8e8e8;
  font-family: 'Caveat', cursive;
  font-size: 1.3rem;
  padding: 0.8rem 0;
  text-align: center;
  outline: none;
  transition: border-color 0.3s ease;
}

#echo-input:focus {
  border-bottom-color: rgba(255, 255, 255, 0.4);
}

#echo-input::placeholder {
  color: rgba(255, 255, 255, 0.2);
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  font-size: 0.85rem;
}

#echo-input-buttons {
  margin-top: 2rem;
  display: flex;
  gap: 1.2rem;
  justify-content: center;
}

#echo-input-buttons button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(180, 178, 170, 0.8);
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  font-size: 0.8rem;
  padding: 0.55rem 1.4rem;
  cursor: pointer;
  letter-spacing: 0.06em;
  border-radius: 2px;
  transition: all 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}

#echo-input-buttons button:active {
  background: rgba(255, 255, 255, 0.04);
}

#echo-submit {
  border-color: rgba(255, 255, 255, 0.25) !important;
  color: rgba(210, 208, 200, 0.9) !important;
}

/* ─── Account Button (HUD) ─────────────────────── */
#account-btn {
  position: absolute;
  top: calc(env(safe-area-inset-top, 12px) + 14px);
  left: calc(env(safe-area-inset-left, 16px) + 16px);
  z-index: 11;
  pointer-events: auto;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.9);
  transition: all 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

#account-btn svg {
  width: 24px;
  height: 24px;
}

#account-btn:hover {
  background: rgba(0, 0, 0, 0.8);
  border-color: rgba(255, 255, 255, 0.5);
  color: #ffffff;
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.7);
}

#account-btn:active {
  background: rgba(0, 0, 0, 0.9);
  transform: scale(0.95);
}

#account-btn.logged-in {
  color: rgba(120, 220, 120, 1);
  border-color: rgba(120, 220, 120, 0.4);
  box-shadow: 0 2px 8px rgba(120, 220, 120, 0.3);
}

/* ─── Login Screen ─────────────────────────────── */
#login-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

#login-screen.active {
  opacity: 1;
  pointer-events: all;
}

#login-box {
  text-align: center;
  max-width: 360px;
  width: 85%;
  position: relative;
}

#login-close {
  position: absolute;
  top: -10px;
  right: -10px;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  font-size: 28px;
  cursor: pointer;
  padding: 8px 12px;
  line-height: 1;
  transition: color 0.2s;
}
#login-close:hover {
  color: #fff;
}

#login-title {
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  color: rgba(255, 255, 255, 0.9);
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}

#login-subtitle {
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  font-size: clamp(1rem, 3vw, 1.2rem);
  color: rgba(255, 255, 255, 0.8);
  letter-spacing: 0.04em;
  margin-bottom: 2rem;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 0;
}

#login-form input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  color: #e8e8e8;
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  font-size: 0.95rem;
  padding: 0.9rem 0;
  text-align: center;
  outline: none;
  transition: border-color 0.3s ease;
}

#login-form input:focus {
  border-bottom-color: rgba(255, 255, 255, 0.35);
}

#login-form input::placeholder {
  color: rgba(255, 255, 255, 0.2);
}

#login-buttons {
  margin-top: 1.5rem;
  display: flex;
  gap: 1rem;
  justify-content: center;
}

#login-buttons button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(200, 198, 190, 0.8);
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  font-size: 1rem;
  padding: 0.7rem 1.8rem;
  cursor: pointer;
  letter-spacing: 0.06em;
  border-radius: 2px;
  transition: all 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}

#login-buttons button:active {
  background: rgba(255, 255, 255, 0.04);
}

#login-signin {
  border-color: rgba(255, 255, 255, 0.25) !important;
  color: rgba(210, 208, 200, 0.9) !important;
}

#login-error {
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  font-size: 1rem;
  color: rgba(220, 80, 60, 0.9);
  margin-top: 1rem;
  min-height: 1.2em;
  letter-spacing: 0.02em;
}

#login-divider {
  display: flex;
  align-items: center;
  margin: 1.5rem 0;
  gap: 1rem;
}

#login-divider::before,
#login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
}

#login-divider span {
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.25);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

#login-social {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.social-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  width: 100%;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: rgba(200, 198, 190, 0.7);
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  font-size: 1rem;
  padding: 0.8rem 1rem;
  cursor: pointer;
  letter-spacing: 0.04em;
  border-radius: 2px;
  transition: all 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}

.social-btn:active {
  background: rgba(255, 255, 255, 0.04);
}

.social-btn svg {
  opacity: 0.7;
  flex-shrink: 0;
}

/* ─── Account Panel ────────────────────────────── */
#account-panel {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.88);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

#account-panel.active {
  opacity: 1;
  pointer-events: all;
}

#account-box {
  text-align: center;
  max-width: 320px;
  width: 85%;
}

#account-email {
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.6);
  letter-spacing: 0.04em;
  margin-bottom: 2rem;
  word-break: break-all;
}

#account-box button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(200, 198, 190, 0.8);
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  font-size: 0.8rem;
  padding: 0.55rem 1.6rem;
  cursor: pointer;
  letter-spacing: 0.06em;
  border-radius: 2px;
  transition: all 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  margin: 0.4rem 0.5rem;
}

#account-change-char {
  display: block;
  margin: 0 auto 1.2rem auto !important;
}

#account-box button:active {
  background: rgba(255, 255, 255, 0.04);
}

/* ─── One Mile Prompt ──────────────────────────────── */
#one-mile-prompt {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.5s ease;
}

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

#one-mile-prompt-box {
  background: rgba(20, 20, 20, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 2rem;
  text-align: center;
  min-width: 320px;
  max-width: 90vw;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

#one-mile-prompt-box h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: #f0f0f0;
}

#one-mile-prompt-box p {
  font-size: 1.1rem;
  color: #b0b0b0;
  margin-bottom: 1.5rem;
  line-height: 1.4;
}

#one-mile-prompt-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

#one-mile-prompt-buttons button {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 100px;
}

#one-mile-signup {
  background: linear-gradient(135deg, #4CAF50, #45a049);
  color: white;
}

#one-mile-signup:hover {
  background: linear-gradient(135deg, #45a049, #3d8b40);
  transform: translateY(-1px);
}

#one-mile-skip {
  background: rgba(255, 255, 255, 0.1);
  color: #e0e0e0;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

#one-mile-skip:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ─── Character Select ──────────────────────────── */
#character-select {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s ease;
}

#char-select-inner {
  text-align: center;
  max-width: 960px;
  width: 100%;
  padding: 20px;
}

#char-select-title {
  font-family: 'Caveat', cursive;
  font-size: 2rem;
  font-weight: 400;
  color: #e8e8e8;
  margin-bottom: 4px;
  letter-spacing: 0.02em;
}

#char-select-sub {
  font-size: 1rem;
  color: #aaa;
  margin-bottom: 24px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

#char-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 32px;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

.char-card {
  width: auto;
  cursor: pointer;
  border: 1px solid #222;
  border-radius: 8px;
  padding: 8px 8px 12px;
  transition: border-color 0.2s, transform 0.2s;
  background: #0a0a0a;
}

.char-card:hover:not(.locked) {
  border-color: #555;
  transform: translateY(-2px);
}

.char-card.selected {
  border-color: #fff;
}

.char-card.locked {
  opacity: 0.4;
  cursor: default;
}

.char-preview-wrap {
  width: 100%;
  aspect-ratio: 280/400;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 4px;
}

.char-preview-canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.char-preview-locked {
  width: 100%;
  aspect-ratio: 280/400;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
}

.char-lock { font-size: 2rem; }

.char-name {
  font-size: 0.85rem;
  color: #ccc;
  margin-top: 8px;
  font-weight: 500;
}

.char-desc {
  font-size: 0.9rem;
  color: #bbb;
  margin-top: 2px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

#char-start-btn {
  font-family: 'Caveat', cursive;
  font-size: 1.4rem;
  background: none;
  border: 1px solid #444;
  color: #e8e8e8;
  padding: 10px 48px;
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  letter-spacing: 0.05em;
}

#char-start-btn:hover {
  border-color: #fff;
  color: #fff;
}

@media (max-width: 600px) {
  #char-grid { gap: 10px; }
  .char-card { width: 110px; padding: 6px 6px 10px; }
  #char-select-title { font-size: 1.5rem; }
  #char-start-btn { font-size: 1.2rem; padding: 8px 36px; }
}

/* ─── Character Switch Modal ────────────────────────── */
#character-switch-modal {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

#character-switch-modal.show {
  opacity: 1;
}

#char-switch-inner {
  background: #111;
  border: 1px solid #333;
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  max-width: 640px;
  width: calc(100% - 32px);
  max-height: calc(100vh - 64px);
  overflow-y: auto;
}

#char-switch-title {
  font-family: 'Caveat', cursive;
  font-size: 1.8rem;
  color: #e8e8e8;
  margin-bottom: 20px;
  letter-spacing: 0.02em;
}

#char-switch-grid {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

#char-switch-grid .char-card {
  width: 120px;
  padding: 6px 6px 8px;
}

#char-switch-grid .char-preview-wrap {
  aspect-ratio: 1;
}

#char-switch-grid .char-name {
  font-size: 0.75rem;
  margin-top: 4px;
}

#char-switch-grid .char-desc {
  font-size: 0.7rem;
  margin-top: 1px;
}

#char-switch-buttons {
  display: flex;
  justify-content: center;
  gap: 12px;
}

#char-switch-confirm,
#char-switch-cancel {
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  background: none;
  border: 1px solid #444;
  color: #e8e8e8;
  padding: 8px 24px;
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}

#char-switch-confirm:hover {
  border-color: #fff;
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
}

#char-switch-cancel:hover {
  border-color: #888;
  color: #ccc;
}

@media (max-width: 600px) {
  #char-switch-inner { padding: 16px; }
  #char-switch-title { font-size: 1.5rem; }
  #char-switch-grid { gap: 8px; }
  #char-switch-grid .char-card { width: 80px; }
  #char-switch-buttons { gap: 8px; }
  #char-switch-confirm, #char-switch-cancel { 
    font-size: 0.8rem; 
    padding: 6px 16px; 
  }
}

/* ─── Music Control ─────────────────────────────── */
#music-control {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 12px) + 16px);
  left: calc(env(safe-area-inset-left, 16px) + 16px);
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
}

#hud.visible ~ #music-control {
  opacity: 1;
  pointer-events: auto;
}

#music-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: rgba(255, 255, 255, 0.9);
  font-size: 24px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  pointer-events: auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

#music-btn:hover {
  background: rgba(0, 0, 0, 0.8);
  border-color: rgba(255, 255, 255, 0.5);
  color: #ffffff;
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.7);
}

#music-btn.playing {
  color: rgba(180, 220, 255, 0.8);
  border-color: rgba(180, 220, 255, 0.25);
  animation: music-pulse 2s ease-in-out infinite;
}

@keyframes music-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(180, 220, 255, 0); }
  50% { box-shadow: 0 0 8px 2px rgba(180, 220, 255, 0.15); }
}

#music-track-name {
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0);
  letter-spacing: 0.04em;
  white-space: nowrap;
  transition: color 0.8s ease;
  pointer-events: none;
}

#music-track-name.visible {
  color: rgba(255, 255, 255, 0.45);
}

#music-list {
  position: absolute;
  bottom: 44px;
  left: 0;
  background: rgba(0, 0, 0, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 6px 0;
  min-width: 160px;
  display: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#music-list.open {
  display: block;
}

#music-list .track-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: rgba(200, 198, 190, 0.7);
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  font-size: 0.75rem;
  padding: 8px 14px;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  letter-spacing: 0.03em;
}

#music-list .track-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.9);
}

#music-list .track-item.active {
  color: rgba(180, 220, 255, 0.9);
}

#music-list .track-toggle {
  color: rgba(255, 255, 255, 0.9);
  font-weight: 500;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 2px;
}

/* ─── Scrollbar removal ─────────────────────────── */
::-webkit-scrollbar {
  display: none;
}

html {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

/* ─── Login Tabs ────────────────────────────────── */
#login-tabs {
  display: flex;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.4);
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  font-size: 0.9rem;
  padding: 0.8rem 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  border-bottom: 2px solid transparent;
}

.tab-btn.active {
  color: rgba(255, 255, 255, 0.9);
  border-bottom-color: rgba(255, 255, 255, 0.3);
}

.tab-btn:hover:not(.active) {
  color: rgba(255, 255, 255, 0.6);
}

/* ─── Leaderboard Control ───────────────────────── */
#leaderboard-control {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 12px) + 16px);
  right: calc(env(safe-area-inset-right, 16px) + 16px);
  z-index: 12;
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
}

#hud.visible ~ #leaderboard-control {
  opacity: 1;
  pointer-events: auto;
}

#leaderboard-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: rgba(255, 255, 255, 0.9);
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  pointer-events: auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

#leaderboard-btn:hover {
  background: rgba(0, 0, 0, 0.8);
  border-color: rgba(255, 255, 255, 0.5);
  color: #ffffff;
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.7);
}

/* ─── Leaderboard Panel ─────────────────────────── */
#leaderboard-panel {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

#leaderboard-panel.active {
  display: flex;
}

#leaderboard-box {
  background: rgba(20, 20, 20, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 2rem;
  text-align: center;
  min-width: 380px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  position: relative;
}

#leaderboard-close {
  position: absolute;
  top: 1rem;
  right: 1.2rem;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.4);
  font-size: 1.5rem;
  cursor: pointer;
  transition: color 0.3s ease;
}

#leaderboard-close:hover {
  color: rgba(255, 255, 255, 0.8);
}

#leaderboard-title {
  font-family: 'Caveat', cursive;
  font-weight: 600;
  font-size: 2rem;
  color: #f0f0f0;
  margin-bottom: 0.5rem;
}

#leaderboard-subtitle {
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.4);
  margin-bottom: 2rem;
}

#leaderboard-loading {
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  color: rgba(255, 255, 255, 0.6);
  padding: 2rem;
}

#leaderboard-list {
  text-align: left;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  padding: 0.8rem 1rem;
  margin-bottom: 0.5rem;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  transition: background 0.3s ease;
}

.leaderboard-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.leaderboard-item.current-user {
  background: rgba(100, 150, 255, 0.15);
  border: 1px solid rgba(100, 150, 255, 0.3);
}

.leaderboard-rank {
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 1.1rem;
  width: 40px;
  text-align: center;
  margin-right: 1rem;
}

.leaderboard-rank.gold { color: #ffd700; }
.leaderboard-rank.silver { color: #c0c0c0; }
.leaderboard-rank.bronze { color: #cd7f32; }
.leaderboard-rank.other { color: rgba(255, 255, 255, 0.6); }

.leaderboard-nickname {
  flex: 1;
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.9);
}

.leaderboard-miles {
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.7);
}

/* ─── Nickname Modal ────────────────────────────── */
#nickname-modal {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

#nickname-modal.active {
  display: flex;
}

#nickname-box {
  background: rgba(20, 20, 20, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 2rem;
  text-align: center;
  min-width: 350px;
  max-width: 90vw;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

#nickname-title {
  font-family: 'Caveat', cursive;
  font-weight: 600;
  font-size: 1.8rem;
  color: #f0f0f0;
  margin-bottom: 0.5rem;
}

#nickname-subtitle {
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 2rem;
  line-height: 1.4;
}

#nickname-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  color: #e8e8e8;
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  font-size: 1rem;
  padding: 0.9rem 0;
  text-align: center;
  outline: none;
  transition: border-color 0.3s ease;
  margin-bottom: 2rem;
}

#nickname-input:focus {
  border-bottom-color: rgba(255, 255, 255, 0.35);
}

#nickname-input::placeholder {
  color: rgba(255, 255, 255, 0.2);
}

#nickname-buttons {
  display: flex;
  justify-content: center;
}

#nickname-submit {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: rgba(210, 208, 200, 0.9);
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  font-size: 1rem;
  padding: 0.7rem 2rem;
  cursor: pointer;
  letter-spacing: 0.06em;
  border-radius: 2px;
  transition: all 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}

#nickname-submit:active {
  background: rgba(255, 255, 255, 0.04);
}

#nickname-error {
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  font-size: 0.9rem;
  color: rgba(220, 80, 60, 0.9);
  margin-top: 1rem;
  min-height: 1.2em;
}
