/**
 * GRIDRUNNER WPM Game Styles - Two-Column Layout
 * Left: Race Progress (always visible) | Right: Typing Area
 */

:root {
  /* Brighter, Higher-Energy Cyberpunk Palette */
  /* Base: Richer deep cyber-indigo/navy surfaces */
  --bg-primary: #0b1120; /* Deep cyber base (lifted from #090d16) */
  --bg-secondary: #131c33; /* Rich cyber panel (lifted from #0f172a) */
  --bg-tertiary: #1a2644; /* Darker cyber (lifted from #1a1f3a) */
  --bg-card: #151f38; /* Interactive card background (elevated) */
  --bg-modal: #11182c; /* Modal/results panel (luminous dark) */

  /* Vibrant Multi-Accent Palette */
  --primary: #00f5ff; /* Electric Cyan (brighter than #00f0ff) */
  --primary-dark: #00d4ff; /* Brighter cyan variant */
  --secondary: #ff2e97; /* Hot Neon Magenta (brighter than #ff2a6d) */
  --accent: #9d4edd; /* Luminous Violet */
  --accent-gold: #ffbe0b; /* Solar Gold */
  --danger: #ff2e97; /* Magenta as danger */
  --success: #00f5ff; /* Cyan as success */
  --warning: #ffbe0b; /* Gold as warning */

  /* Text Colors */
  --text-primary: #f8fafc; /* Brighter text (nearly white, slightly blue-tinted) */
  --text-secondary: #94a3b8; /* Brighter muted (not #a0aec0) */
  --text-muted: #64748b; /* Even more muted for subtle labels */

  /* Borders & Glows */
  --border: #00f5ff; /* Cyan borders */
  --border-secondary: #2d3748; /* Subtle dark border */
  --border-magenta: #ff2e97; /* Magenta borders */
  --neon-glow: 0 0 20px rgba(0, 245, 255, 0.5);
  --neon-glow-magenta: 0 0 20px rgba(255, 46, 151, 0.5);
  --neon-glow-gold: 0 0 20px rgba(255, 190, 11, 0.4);
}

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

html,
body {
  width: 100%;
  height: 100%;
  font-family: "Courier New", "Monaco", "Menlo", "Inconsolata", monospace;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  letter-spacing: 0.05em;
  font-weight: 500;
}

body {
  overflow-x: hidden;
}

/* ============================================================
 * SCREENS
 * ============================================================ */

.screen {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

.screen.overlay {
  position: fixed;
  background: rgba(0, 0, 0, 0.7);
  align-items: center;
  justify-content: center;
  z-index: 100;
}

/* ============================================================
 * LOADING SCREEN
 * ============================================================ */

#loading-screen {
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
  align-items: center;
  justify-content: center;
  border-top: 2px solid var(--primary);
}

#loading-screen h1 {
  color: var(--primary);
  text-shadow: 0 0 20px rgba(0, 240, 255, 0.6);
  font-size: 2.5rem;
  margin-bottom: 1rem;
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.1em;
}

#loading-screen p {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 2rem;
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.3);
}

.spinner {
  border: 3px solid var(--border-secondary);
  border-top: 3px solid var(--primary);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 0.8s linear infinite;
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.5);
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* ============================================================
 * START SCREEN
 * ============================================================ */

#start-screen {
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
  overflow-y: auto;
  overflow-x: hidden;
  border-top: 2px solid var(--primary);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: 0.75rem;
}

.start-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.75rem;
  padding: 0.75rem;
  align-items: start;
  justify-items: center;
  flex: 1;
}

.start-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 560px;
  padding: 0;
}

.start-content {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 1.25rem 1.5rem 1.5rem 1.5rem;
  width: 100%;
  border: 2px solid var(--primary);
  box-shadow: 0 0 40px rgba(0, 240, 255, 0.3), 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.portal-return {
  align-self: flex-start;
  color: #bffeff;
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 1rem;
  padding: 0.5rem 0;
  text-decoration: none;
}

.portal-return:hover,
.portal-return:focus-visible {
  color: #fff;
  text-decoration: underline;
}

/* Title Banner Slot */
.title-banner-slot {
  position: relative;
  width: 100%;
  max-width: 100%;
  height: 130px;
  margin: 0 0 1.25rem 0;
  border-radius: 8px;
  overflow: hidden;
  background: #090d1a;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Subtle dark border/glow for natural integration */
  border: 1px solid rgba(0, 240, 255, 0.15);
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.1);
}

/* Hide broken image icon when image fails to load */
.title-banner-slot:not(.has-banner-image) .title-banner-img {
  display: none;
}

/* Show fallback text when image is missing */
.title-banner-slot:not(.has-banner-image) .title-banner-fallback {
  display: flex;
}

/* Hide fallback text when image loads successfully */
.title-banner-slot.has-banner-image .title-banner-fallback {
  display: none;
}

.title-banner-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  /* Smooth edge-fading mask - ellipse 92% 88% fades cleanly to transparent at edges */
  mask-image: radial-gradient(
    ellipse 92% 88% at 50% 50%,
    rgba(0, 0, 0, 1) 0%,
    rgba(0, 0, 0, 0.95) 70%,
    rgba(0, 0, 0, 0.5) 90%,
    rgba(0, 0, 0, 0) 100%
  );
  -webkit-mask-image: radial-gradient(
    ellipse 92% 88% at 50% 50%,
    rgba(0, 0, 0, 1) 0%,
    rgba(0, 0, 0, 0.95) 70%,
    rgba(0, 0, 0, 0.5) 90%,
    rgba(0, 0, 0, 0) 100%
  );
}

.title-banner-fallback {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  text-align: center;
  width: 100%;
  height: 100%;
  padding: 0.75rem;
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.05) 0%, rgba(255, 0, 150, 0.05) 100%);
}

.title-banner-fallback h1 {
  font-size: 1.3rem;
  color: var(--primary);
  text-shadow: 0 0 20px rgba(0, 240, 255, 0.6);
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1.2;
}

.title-banner-fallback .tagline {
  font-size: 0.65rem;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.3;
  max-width: 90%;
}

.start-settings {
  margin: 1.75rem 1.5rem 1.25rem 1.5rem;
  padding: 0;
}

.selector-group {
  margin-bottom: 1.25rem;
}

.selector-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
  margin-bottom: 0.6rem;
  text-align: center;
}

.button-group {
  display: grid;
  gap: 0.75rem;
}

/* 3-column grid for difficulty */
.button-group.difficulty-grid {
  grid-template-columns: repeat(3, 1fr);
}

/* 2-column grid for format */
.button-group.format-grid {
  grid-template-columns: repeat(2, 1fr);
}

.difficulty-btn,
.format-btn {
  padding: 0.9rem 0.75rem;
  border: 2px solid var(--border-secondary);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  text-align: center;
}

/* With the WPM sublabel gone each difficulty card is an icon and a name, so centre them vertically */
.difficulty-btn {
  justify-content: center;
  gap: 0.5rem;
}

.difficulty-btn .emoji,
.format-btn .emoji {
  font-size: 1.5rem;
  display: none; /* Hidden by default; shown if icon fails to load */
}

.format-icon {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 8px;
  transition: all 0.3s ease;
  filter: drop-shadow(0 0 4px rgba(0, 240, 255, 0.15));
}

.format-btn:hover .format-icon,
.format-btn.active .format-icon {
  filter: drop-shadow(0 0 10px rgba(0, 245, 255, 0.4)) brightness(1.08);
}

/* Show emoji fallback if image fails to load */
.format-btn .format-icon.failed,
.format-btn .format-icon[data-failed="true"] {
  display: none;
}

.format-btn .format-icon.failed ~ .emoji,
.format-btn .format-icon[data-failed="true"] ~ .emoji {
  display: block;
}

.difficulty-icon {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 10px;
  transition: all 0.3s ease;
  filter: drop-shadow(0 0 5px rgba(0, 240, 255, 0.2));
}

.difficulty-btn:hover .difficulty-icon,
.difficulty-btn.active .difficulty-icon {
  filter: drop-shadow(0 0 12px rgba(0, 245, 255, 0.5)) brightness(1.1);
}

/* Show emoji fallback if image fails to load */
.difficulty-btn .difficulty-icon.failed,
.difficulty-btn .difficulty-icon[data-failed="true"] {
  display: none;
}

.difficulty-btn .difficulty-icon.failed ~ .emoji,
.difficulty-btn .difficulty-icon[data-failed="true"] ~ .emoji {
  display: block;
}

.difficulty-btn .name,
.format-btn .name {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.difficulty-btn:hover,
.format-btn:hover {
  border-color: var(--primary);
  background: var(--bg-secondary);
  box-shadow: 0 0 20px rgba(0, 245, 255, 0.3);
}

.difficulty-btn.active,
.format-btn.active {
  border-color: var(--primary);
  background: rgba(0, 245, 255, 0.1);
  color: var(--primary);
  box-shadow: 0 0 30px rgba(0, 245, 255, 0.5);
}

/* Arcade-style flashing START GAME button animation */
@keyframes arcade-start-flash {
  0% {
    /* Full brightness, cyan neon glow */
    opacity: 1;
    text-shadow: 0 0 10px rgba(0, 245, 255, 1);
    box-shadow: 0 0 20px rgba(0, 245, 255, 0.8), 0 0 40px rgba(0, 245, 255, 0.4);
  }
  25% {
    /* Bright magenta accent */
    opacity: 1;
    text-shadow: 0 0 15px rgba(255, 0, 127, 0.8);
    box-shadow: 0 0 25px rgba(255, 0, 127, 0.6), 0 0 45px rgba(0, 245, 255, 0.3);
  }
  50% {
    /* Back to full cyan */
    opacity: 1;
    text-shadow: 0 0 10px rgba(0, 245, 255, 1);
    box-shadow: 0 0 20px rgba(0, 245, 255, 0.8), 0 0 40px rgba(0, 245, 255, 0.4);
  }
  75% {
    /* Dim pulse (but not off) */
    opacity: 0.7;
    text-shadow: 0 0 5px rgba(0, 245, 255, 0.5);
    box-shadow: 0 0 10px rgba(0, 245, 255, 0.4), 0 0 25px rgba(0, 245, 255, 0.2);
  }
  100% {
    /* Back to full brightness */
    opacity: 1;
    text-shadow: 0 0 10px rgba(0, 245, 255, 1);
    box-shadow: 0 0 20px rgba(0, 245, 255, 0.8), 0 0 40px rgba(0, 245, 255, 0.4);
  }
}

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .btn-start {
    animation: none;
  }
}

.btn-start {
  width: calc(100% - 3rem);
  padding: 0.9rem;
  background: linear-gradient(135deg, var(--primary) 0%, #00d4ff 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  margin: 0.9rem 1.5rem 0.5rem 1.5rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.5);
  /* Apply arcade flashing animation */
  animation: arcade-start-flash 1.1s ease-in-out infinite;
}

.btn-start:hover,
.btn-start:focus-visible {
  /* Lock animation to full brightness on hover/focus */
  animation: none;
  opacity: 1;
  text-shadow: 0 0 15px rgba(0, 245, 255, 1), 0 0 30px rgba(255, 0, 127, 0.5);
  box-shadow: 0 0 30px rgba(0, 240, 255, 0.8), 0 0 50px rgba(255, 0, 127, 0.4);
  transform: scale(1.02);
}

.btn-start:active {
  transform: scale(0.98);
}

.start-info {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: center;
  margin: 0.5rem 1.5rem 1.5rem 1.5rem;
  padding: 0;
}

.start-info p {
  margin: 0.2rem 0;
}

 * ============================================================ */

#main-screen {
  position: static !important;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* tracks the visible area when a phone's keyboard or toolbar changes it */
  background: var(--bg-primary);
}

.game-header {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
  color: var(--primary);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  border-bottom: 2px solid var(--primary);
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.2);
}

.game-header h1 {
  font-size: 1.5rem;
  margin: 0;
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.5);
  font-weight: 700;
  letter-spacing: 0.1em;
}

/* Header logo image */
.header-logo {
  max-height: 46px;
  max-width: 240px;
  object-fit: contain;
  border-radius: 6px;
  margin-right: 0.75rem;
  display: block;
  /* Smooth edge blending */
  mask-image: radial-gradient(
    ellipse 95% 90% at 50% 50%,
    rgba(0, 0, 0, 1) 0%,
    rgba(0, 0, 0, 0.98) 70%,
    rgba(0, 0, 0, 0.6) 90%,
    rgba(0, 0, 0, 0) 100%
  );
  -webkit-mask-image: radial-gradient(
    ellipse 95% 90% at 50% 50%,
    rgba(0, 0, 0, 1) 0%,
    rgba(0, 0, 0, 0.98) 70%,
    rgba(0, 0, 0, 0.6) 90%,
    rgba(0, 0, 0, 0) 100%
  );
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.1);
}

/* Header left section: logo + fallback text */
.header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.header-left h1 {
  font-size: 1.5rem;
  margin: 0;
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.5);
  font-weight: 700;
  letter-spacing: 0.1em;
  white-space: nowrap;
}

/* Progression Badge: Shows current round, complexity level, pace scaling */
.progression-badge {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-left: auto;
  margin-right: auto;
  padding: 0.4rem 0.8rem;
  background: linear-gradient(135deg, rgba(157, 78, 221, 0.15), rgba(0, 245, 255, 0.1));
  border: 1px solid rgba(0, 245, 255, 0.4);
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--primary);
  box-shadow: 0 0 8px rgba(0, 245, 255, 0.2);
  white-space: nowrap;
}

.badge-round,
.badge-complexity,
.badge-pace {
  font-weight: 700;
  color: var(--primary);
}

.badge-sep {
  color: rgba(0, 245, 255, 0.5);
  margin: 0 0.1rem;
}

.badge-pace {
  color: var(--accent-gold);
}

#badge-pace-value {
  font-weight: 700;
  color: var(--accent-gold);
}

/* Header right section: buttons */
.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.btn-back {
  background: rgba(0, 240, 255, 0.1);
  color: var(--primary);
  border: 1px solid var(--primary);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.3s ease;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.btn-back:hover {
  background: rgba(0, 240, 255, 0.2);
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.4);
}

/* Sound Toggle Button */
.btn-sound-toggle {
  background: rgba(157, 78, 221, 0.15); /* Violet background */
  color: var(--accent); /* Violet text */
  border: 1px solid var(--accent);
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.3s ease;
  font-weight: 600;
  letter-spacing: 0.05em;
  margin-right: 1rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 44px; /* Touch target minimum */
  justify-content: center;
}

.btn-sound-toggle:hover {
  background: rgba(157, 78, 221, 0.25);
  box-shadow: 0 0 15px rgba(157, 78, 221, 0.4);
}

.btn-sound-toggle[aria-pressed="true"] {
  background: rgba(0, 245, 255, 0.15);
  color: var(--primary);
  border-color: var(--primary);
}

.btn-sound-toggle[aria-pressed="true"]:hover {
  background: rgba(0, 245, 255, 0.25);
  box-shadow: 0 0 15px rgba(0, 245, 255, 0.4);
}

.sound-icon,
.sound-muted-icon {
  display: inline-block;
  font-size: 1.1em;
  line-height: 1;
}

/* Mobile adjustments */
@media (max-width: 640px) {
  .btn-sound-toggle {
    padding: 0.4rem 0.6rem;
    margin-right: 0.5rem;
    font-size: 0.9rem;
  }
}}

/**
 * Persistent Audio Controls Header
 * Fixed position control bar accessible on all screens
 */
.audio-controls-header {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 150; /* Above all screens but below modals */
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(11, 17, 32, 0.95); /* Match game background with slight transparency */
  border: 1px solid var(--accent, #9d4edd);
  border-radius: 8px;
  padding: 0.5rem;
  box-shadow: 0 4px 20px rgba(0, 245, 255, 0.1); /* Subtle glow */
  backdrop-filter: blur(10px);
}

.btn-sound-toggle-persistent {
  background: rgba(157, 78, 221, 0.15); /* Violet background */
  color: var(--accent); /* Violet text */
  border: 1px solid var(--accent);
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.1rem;
  transition: all 0.3s ease;
  font-weight: 600;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 44px; /* Touch target minimum */
  justify-content: center;
  margin: 0;
}

.btn-sound-toggle-persistent:hover {
  background: rgba(157, 78, 221, 0.25);
  box-shadow: 0 0 15px rgba(157, 78, 221, 0.4);
}

.btn-sound-toggle-persistent[aria-pressed="true"] {
  background: rgba(0, 245, 255, 0.15);
  color: var(--primary);
  border-color: var(--primary);
}

.btn-sound-toggle-persistent[aria-pressed="true"]:hover {
  background: rgba(0, 245, 255, 0.25);
  box-shadow: 0 0 15px rgba(0, 245, 255, 0.4);
}

/* Mobile adjustments for persistent audio header */
@media (max-width: 640px) {
  .audio-controls-header {
    top: 0.75rem;
    right: 0.75rem;
    padding: 0.4rem;
  }
  
  .btn-sound-toggle-persistent {
    padding: 0.5rem 0.7rem;
    font-size: 1rem;
  }
}

/* Single-line progress track layout */
.game-layout {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  flex: 1;
  overflow: hidden;
  padding: 0.65rem 1rem;
  background: var(--bg-primary);
}

/* Top panel: Standings bar */
.standings-bar {
  flex-shrink: 0;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border-radius: 8px;
  border: 1px solid var(--border-secondary);
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-family: "Monaco", "Menlo", monospace;
  font-weight: 600;
  overflow-x: auto;
  white-space: nowrap;
}

.standings-item {
  display: inline-block;
  margin-right: 1.5rem;
  font-size: 0.75rem;
}

.standings-item .position {
  font-weight: 700;
  color: var(--primary);
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.5);
}

.standings-item .wpm-value {
  color: var(--text-secondary);
  font-size: 0.75rem;
}

/* Top panel: Single-line race progress track */
.race-panel {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  flex-shrink: 0;
  padding: 0.65rem 0.85rem;
  background: var(--bg-secondary);
  border-radius: 8px;
  border: 2px solid var(--border-secondary);
  perspective: 650px; /* depth for the over-the-shoulder track */
  perspective-origin: 50% 40%;
}

.race-panel h3 {
  font-size: 0.85rem;
  color: var(--primary);
  margin: 0;
  padding: 0;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.4);
}

.race-container {
  flex: 1;
  overflow-y: auto;
  transition: transform 600ms ease-out;
}

/* TRUE SINGLE-LINE HORIZONTAL TRACK: All racers share one track container */
.race-track {
  position: relative;
  height: 195px;
  background: url('../images/track-bg.png') !important;
  background-color: #0d1528;
  background-size: 100% 100% !important;
  background-repeat: no-repeat !important;
  background-position: center center !important;
  background-attachment: fixed;
  border: 2px solid var(--primary);
  border-radius: 8px;
  margin: 0.5rem 0;
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.3), inset 0 0 20px rgba(0, 240, 255, 0.1);
  overflow: hidden;
}

/* Track labels: 0% START | 100% FINISH */
.race-track::before {
  content: "0%";
  position: absolute;
  left: 0.5rem;
  top: -1.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.race-track::after {
  content: "100% FINISH";
  position: absolute;
  right: 0.5rem;
  top: -1.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Individual racer positioned horizontally (left: calc(progress * 100%)) */
.lane {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  width: auto;
  /* Dynamic positioning: left will be set by JavaScript */
  /* Vertical centering: translateY(-50%) centers lane at its top position */
  transform: translateX(0) translateY(-50%); /* Exact center anchor */
  transition: left 75ms linear; /* Smooth glide on per-character progress updates */
  z-index: 10;
}

/* Respect motion accessibility preferences */
@media (prefers-reduced-motion: reduce) {
  .lane {
    transition: none; /* Disable animation for motion-sensitive users */
  }
}

.lane.player-lane {
  z-index: 20; /* Player appears above others */
}

/* Vertical offset for clean overtaking - aligned to brighter track lane bands */
/* Brighter track has ~11% top/bottom margins; lanes centered at 20.5%, 40.0%, 59.5%, 79.0% */
/* With translateY(-50%), top value = vertical center; use percentage for exact alignment */
.lane:nth-child(1) {
  top: 22%;
} /* Lane 1 center (centered on glowing chevrons) */
.lane:nth-child(2) {
  top: 41%;
} /* Lane 2 center (centered on glowing chevrons) */
.lane:nth-child(3) {
  top: 60%;
} /* Lane 3 center (centered on glowing chevrons) */
.lane:nth-child(4) {
  top: 79%;
} /* Lane 4 center (centered on glowing chevrons) */

/* Racer info (compact: avatar, name, WPM stacked vertically) */
.racer {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.65rem;
  color: var(--text-primary);
  white-space: nowrap;
}

.racer-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  align-items: flex-start;
  background: rgba(11, 17, 32, 0.75); /* Dark translucent pill backdrop */
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  backdrop-filter: blur(4px);
}

.racer-avatar {
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 60px;
  height: 40px;
}

.racer-sprite {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  transition: opacity 0.3s ease;
}

.lane.surging .racer-sprite {
  filter: drop-shadow(0 0 8px var(--secondary)) brightness(1.25);
}

.lane.surging .racer-wpm {
  color: var(--secondary);
  text-shadow: 0 0 8px rgba(255, 46, 151, 0.6);
}

.racer-sprite:not([src]) {
  display: none;
}

.racer-name {
  font-weight: 600;
  font-size: 0.6rem;
  color: var(--text-primary);
  white-space: nowrap;
}

.racer-wpm {
  font-size: 0.55rem;
  color: var(--text-secondary);
  font-family: "Monaco", "Menlo", monospace;
  font-weight: 600;
  white-space: nowrap;
}

.racer-placement {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
  transition: all 0.1s ease;
}

.racer-placement.finished {
  color: var(--success);
  text-shadow: 0 0 10px rgba(0, 245, 155, 0.6);
  font-weight: 800;
}

/* Right panel: Typing area */
.typing-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow: hidden;
}

/* Word Stage: Centered Display Area (Main Focus) */
.word-stage {
  position: relative;
  flex: 0 0 auto;
  min-height: 96px;
  max-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border: 2px solid var(--primary);
  border-radius: 12px;
  padding: 1.15rem 1.5rem;
  margin-bottom: 0;
  box-shadow: 0 0 30px rgba(0, 240, 255, 0.3), inset 0 0 20px rgba(0, 240, 255, 0.1);
}

.word-stage-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  width: 100%;
}

/* Centered word display: Large, high-contrast, centered */
.words-display-centered {
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text-primary);
  font-family: "Monaco", "Menlo", monospace;
  white-space: nowrap;
  letter-spacing: 0.05em;
  text-align: center;
  min-height: 3rem;
  transition: all 0.2s ease;
  word-break: break-word;
  overflow-wrap: break-word;
}

.words-display-centered .word {
  display: inline-block;
  color: var(--text-primary);
  background: rgba(0, 240, 255, 0.1);
  padding: 0.5rem 1.2rem;
  border-radius: 6px;
  border: 1px solid var(--primary);
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.4);
  font-size: 1.5rem;
  font-weight: 700;
  animation: pulse 0.5s infinite;
}

.words-display-centered .word.typed {
  color: var(--success);
  background: rgba(0, 245, 155, 0.1);
  border-color: var(--success);
  box-shadow: 0 0 20px rgba(0, 245, 155, 0.5);
}

.words-display-centered .word.error {
  color: var(--danger);
  background: rgba(255, 42, 109, 0.1);
  border-color: var(--danger);
  box-shadow: 0 0 20px rgba(255, 42, 109, 0.5);
  animation: shake 0.3s ease-in-out;
}

/* Word progress indicator: "Word X of Y" */
.active-modifiers-badge {
  display: inline-block;
  margin-left: 0.75rem;
  padding: 0.1rem 0.6rem;
  border: 1px solid var(--secondary);
  border-radius: 999px;
  background: rgba(255, 46, 151, 0.12);
  color: var(--secondary);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
}

.emp-status {
  margin-top: 0.4rem;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-shadow: 0 0 10px rgba(157, 78, 221, 0.8);
}

/* EMP Pulse: the whole grid flashes violet, rivals are stunned, the player's prompt dims */
.race-track.emp-pulse {
  border-color: var(--accent);
  box-shadow: 0 0 28px rgba(157, 78, 221, 0.7), inset 0 0 24px rgba(157, 78, 221, 0.3);
}

.lane.stunned .racer-sprite {
  filter: grayscale(0.8) brightness(0.7) drop-shadow(0 0 8px var(--accent));
}

.lane.stunned .racer-wpm {
  color: var(--accent);
}

.words-display-centered.emp-dim {
  opacity: 0.4;
}

/* The typed prefix stays crisp; only the untyped rest fades to a ghost */
.phantom-phase .phantom-rest {
  color: rgba(0, 245, 255, 0.35);
  opacity: 0.35;
  filter: blur(3px);
  text-shadow: 0 0 14px rgba(0, 245, 255, 0.9);
  animation: phantom-flicker 0.4s steps(2, end) infinite;
}

@keyframes phantom-flicker {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.18; }
}

.next-up {
  margin-top: 0.4rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  transition: color 0.2s ease, text-shadow 0.2s ease;
}

.next-up.scrambled {
  color: var(--secondary);
  text-shadow: 0 0 10px rgba(255, 46, 151, 0.6);
}

.word-progress-indicator {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 0.5rem;
}

/* Large textarea - prominent input box */
.input-field {
  flex: 0 0 auto;
  height: 46px;
  max-width: 420px;
  margin: 0 auto;
  width: 100%;
  padding: 0.75rem 1.25rem;
  font-size: 1.1rem;
  font-family: "Monaco", "Menlo", monospace;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 2px solid var(--primary);
  border-radius: 6px;
  resize: none;
  transition: all 0.3s ease;
  line-height: 1.6;
  letter-spacing: 0.05em;
}

.input-field:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 25px rgba(0, 240, 255, 0.6);
}

.input-field::placeholder {
  color: var(--text-secondary);
}

.input-field.error {
  animation:
    shake 0.3s ease-in-out,
    error-flash 0.3s ease-out;
  border-color: var(--danger);
}

.words-display {
  /* Legacy - no longer used in single-word mode, but kept for compatibility */
  display: none;
}

.words-display .word {
  /* Legacy styles */
  display: none;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.8;
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-8px);
  }
  50% {
    transform: translateX(8px);
  }
  75% {
    transform: translateX(-8px);
  }
}

@keyframes error-flash {
  0% {
    background-color: rgba(255, 42, 109, 0.3);
    border-color: var(--danger);
  }
  100% {
    background-color: transparent;
    border-color: var(--primary);
  }
}

/* Stats at bottom */
.stats-container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--bg-secondary);
  border-radius: 8px;
  border: 1px solid var(--border-secondary);
  flex-shrink: 0;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.stat .label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat .value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  font-family: "Monaco", "Menlo", monospace;
}

/* ============================================================
 * RESULTS SCREEN
 * ============================================================ */

.results-container {
  background: var(--bg-modal); /* Luminous dark cyber-panel (#11182c) */
  border: 2px solid var(--primary); /* Glowing cyan border */
  border-radius: 12px;
  padding: 1.5rem 1.75rem;
  max-width: 650px;
  width: 95%;
  box-shadow: 0 0 40px rgba(0, 245, 255, 0.2), 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.results-container h2 {
  font-size: 1.75rem;
  color: var(--primary);
  margin: 0 0 1rem 0;
  text-align: center;
  text-shadow: 0 0 15px rgba(0, 245, 255, 0.4);
}

.results-table {
  margin-bottom: 1.25rem;
  overflow-x: auto;
  flex-shrink: 0;
}

.results-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.results-table th {
  background: var(--bg-secondary);
  padding: 0.6rem 0.5rem;
  text-align: left;
  font-weight: 600;
  color: var(--primary); /* Bright cyan headers */
  border-bottom: 2px solid var(--primary);
}

.results-table td {
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--border-secondary);
  color: var(--text-primary); /* Bright #f8fafc */
}

.results-table tr {
  background: rgba(255, 255, 255, 0.04); /* Very subtle light translucent */
}

.results-table tr:hover {
  background: rgba(0, 245, 255, 0.08); /* Subtle cyan tint on hover */
}

.results-table tr.player {
  background: rgba(0, 245, 255, 0.15); /* Brighter cyan for player row */
  border-left: 3px solid var(--primary);
  font-weight: 600;
  color: var(--primary);
}

.player-badge {
  display: inline-block;
  background: var(--primary);
  color: var(--bg-primary);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  margin-left: 0.5rem;
  letter-spacing: 0.05em;
}

.results-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-secondary);
  border-radius: 8px;
  flex-shrink: 0;
}

/* Round badge on results screen - compact version */
.round-badge-results {
  text-align: center;
  margin-bottom: 0.5rem;
  padding: 0.4rem 0.75rem;
  background: linear-gradient(135deg, rgba(0, 245, 255, 0.1), rgba(157, 78, 221, 0.1));
  border: 1px solid rgba(0, 245, 255, 0.4);
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.05em;
  text-shadow: 0 0 8px rgba(0, 245, 255, 0.3);
}

#round-badge-text {
  display: inline-block;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
}

.round-badge-results.sudden-death {
  background: rgba(255, 46, 151, 0.12);
  border-color: var(--secondary);
}

.round-badge-results.sudden-death #round-badge-text {
  color: var(--secondary);
  text-shadow: 0 0 10px rgba(255, 46, 151, 0.5);
}

/* Arcade score box now takes just 1 column (not full width) in 2-column layout */
.arcade-score-box {
  grid-column: 1;
  max-width: 100%;
}

.result-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.result-stat .label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.result-stat .value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
}

/* Cumulative Score Stat (displayed when progressionStep > 0) - sits in column 2 next to Arcade Score */
#cumulative-score-stat {
  grid-column: 2;
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 0.6rem 0.8rem;
  background: linear-gradient(135deg, rgba(255, 190, 11, 0.1), rgba(0, 245, 255, 0.1));
  border-left: 3px solid var(--accent-gold);
  border-radius: 4px;
}

#cumulative-score-stat .label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--accent-gold);
  text-transform: uppercase;
}

#cumulative-score-stat .value {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--accent-gold);
  text-shadow: 0 0 10px rgba(255, 190, 11, 0.4);
}

.share-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-shrink: 0;
}

.share-btn {
  padding: 0.6rem 0.75rem;
  background: var(--bg-card); /* Dark cyber-indigo (#151f38) */
  border: 1px solid var(--border-secondary); /* Subtle dark border */
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary); /* Bright #f8fafc */
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.share-btn:hover {
  border-color: var(--primary);
  background: rgba(0, 245, 255, 0.15);
  box-shadow: 0 0 15px rgba(0, 245, 255, 0.4);
}

.copy-btn {
  position: relative;
}

.copy-btn.copied::after {
  content: 'Copied!';
  position: absolute;
  top: -1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: var(--bg-primary);
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
  animation: fadeout 2s ease-out forwards;
}

@keyframes fadeout {
  0% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

.action-buttons {
  /* Buttons share the row by content width and wrap whole to the next row, never mid-label */
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border-secondary);
  flex-shrink: 0;
}

.btn {
  padding: 0.85rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: white;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px -5px rgba(8, 145, 178, 0.3);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: white;
  border-color: var(--primary);
}

/* Buttons keep every label on one line: "Continue → Round 2" never drops the digit onto a second line */
.action-buttons .btn {
  flex: 1 1 auto;
  white-space: nowrap;
  line-height: 1.3;
  padding: 0.85rem 0.9rem;
}

.action-buttons #continue-race-btn {
  flex: 2 1 auto;
}

/* Continue button text with dynamic next round number */
#continue-btn-text {
  display: inline-block;
  white-space: nowrap;
  font-weight: 700;
  letter-spacing: 0.04em;
}

/* ============================================================
 * BUTTON DISABLED STATE
 * ============================================================ */

.btn-disabled,
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--bg-secondary) !important;
  color: rgba(255, 255, 255, 0.5) !important;
  border-color: var(--border) !important;
  box-shadow: none !important;
  transform: none !important;
}

.btn-disabled:hover,
button:disabled:hover {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.btn-disabled[title]:hover::after,
.btn-disabled[title]:focus::after,
button:disabled[title]:hover::after,
button:disabled[title]:focus::after {
  /* Show disabled tooltip even when disabled */
  content: attr(title);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9);
  color: #ff6b6b;
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  font-size: 0.8rem;
  white-space: nowrap;
  z-index: 1000;
  margin-bottom: 0.5rem;
  border: 1px solid rgba(255, 107, 107, 0.3);
  animation: tooltip-fade-in 0.2s ease;
}

/* ============================================================
 * BUTTON TOOLTIPS
 * ============================================================ */

.btn[title],
.share-btn[title] {
  position: relative;
}

.btn[title]:hover::after,
.btn[title]:focus::after,
.share-btn[title]:hover::after,
.share-btn[title]:focus::after {
  content: attr(title);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9);
  color: #0ff;
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  font-size: 0.8rem;
  white-space: nowrap;
  margin-bottom: 0.5rem;
  z-index: 1000;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(0, 255, 255, 0.3);
  animation: tooltip-fade-in 0.2s ease;
}

/* Adjust tooltip for small screens - show above with smart positioning */
@media (max-width: 768px) {
  .btn[title]:hover::after,
  .btn[title]:focus::after,
  .share-btn[title]:hover::after,
  .share-btn[title]:focus::after {
    white-space: normal;
    max-width: 200px;
    width: 200px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    line-height: 1.4;
  }
}

@keyframes tooltip-fade-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* ============================================================
 * RESPONSIVE ADJUSTMENTS
 * ============================================================ */

@media (max-width: 1024px) {
  .race-panel {
    padding: 0.75rem;
  }

  .racer {
    gap: 0.1rem;
  }

  .racer-avatar {
    font-size: 1rem;
  }

  .racer-name {
    font-size: 0.55rem;
  }

  .racer-wpm {
    font-size: 0.5rem;
  }


  .words-display {
    font-size: 0.95rem;
  }
}

@media (max-width: 768px) {
  /* Header adjustments for tablet */
  .game-header {
    padding: 0.75rem 1rem;
  }

  .header-logo {
    max-height: 40px;
    max-width: 180px;
    margin-right: 0.5rem;
  }

  .game-header h1 {
    font-size: 1.2rem;
  }

  .btn-back {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
  }

  .btn-sound-toggle {
    padding: 0.4rem;
  }

  /* Single column on tablet - race track stays at top, full width */
  .game-layout {
    flex-direction: column;
  }

  .race-panel {
    padding: 0.75rem;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 180px;
  }

  .race-panel h3 {
    font-size: 0.75rem;
  }

  .race-track {
    height: 100px;
  }

  .lane:nth-child(1) {
    top: 8px;
  }
  .lane:nth-child(2) {
    top: 28px;
  }
  .lane:nth-child(3) {
    top: 48px;
  }
  .lane:nth-child(4) {
    top: 68px;
  }

  .racer-avatar {
    font-size: 0.95rem;
  }

  .racer-name {
    font-size: 0.55rem;
  }

  .racer-wpm {
    font-size: 0.5rem;
  }


  .stats-container {
    grid-template-columns: repeat(2, 1fr);
  }

  .start-content {
    padding: 2rem 1.5rem;
  }

  .results-container {
    padding: 1.5rem;
  }

  .action-buttons {
    flex-direction: column;
  }

  .action-buttons .btn,
  .action-buttons #continue-race-btn {
    flex: 0 0 auto;
    width: 100%;
  }

  .button-group {
    grid-template-columns: 1fr;
  }

  .button-group.horizontal {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .game-header {
    padding: 0.75rem 1rem;
  }

  .header-logo {
    max-height: 36px;
    max-width: 160px;
    margin-right: 0.4rem;
  }

  .game-header h1 {
    font-size: 1rem;
  }

  .btn-back {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
  }

  .game-layout {
    padding: 0.75rem;
    gap: 0.75rem;
  }

  .race-panel {
    max-height: 140px;
    padding: 0.5rem;
  }

  .race-track {
    height: 90px;
  }

  .lane:nth-child(1) {
    top: 6px;
  }
  .lane:nth-child(2) {
    top: 24px;
  }
  .lane:nth-child(3) {
    top: 42px;
  }
  .lane:nth-child(4) {
    top: 60px;
  }

  .racer {
    gap: 0.05rem;
  }

  .racer-avatar {
    font-size: 0.9rem;
  }

  .racer-name {
    font-size: 0.5rem;
  }

  .racer-placement {
    font-size: 0.7rem;
  }

  .words-display {
    font-size: 0.9rem;
  }

  .stats-container {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    padding: 0.75rem;
  }

  .stat .label {
    font-size: 0.7rem;
  }

  .stat .value {
    font-size: 1.1rem;
  }

  .start-content {
    padding: 1.5rem 1rem;
    margin: 1rem;
  }

  .start-content h1 {
    font-size: 1.8rem;
  }

  .difficulty-btn .emoji {
    font-size: 1.5rem;
  }

  .results-container {
    padding: 1rem;
    margin: 1rem;
  }

  .results-summary {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
 * PRE-RACE COUNTDOWN
 * ============================================================ */

.countdown-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  border-radius: 0.5rem;
}

.countdown-display {
  text-align: center;
}

.countdown-number {
  font-size: 7rem;
  font-weight: 900;
  color: #22d3ee;
  text-shadow: 0 0 20px rgba(34, 211, 238, 0.8);
  animation: countdown-pulse 1s ease-in-out;
  line-height: 1;
}

@keyframes countdown-pulse {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* GO! has special styling */
.countdown-number.go {
  color: #22c55e;
  text-shadow: 0 0 25px rgba(34, 197, 94, 0.9);
  animation: countdown-go 0.6s ease-out;
}

@keyframes countdown-go {
  0% {
    transform: scale(0.3);
    opacity: 0;
  }
  70% {
    transform: scale(1.3);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@media (max-width: 768px) {
  .countdown-number {
    font-size: 4rem;
  }
}

.share-btn.copy-btn {
  border-color: var(--accent-gold);
}

.share-btn.copy-btn:hover {
  border-color: var(--accent-gold);
  background: rgba(255, 190, 11, 0.15);
  box-shadow: 0 0 15px rgba(255, 190, 11, 0.4);
}

/* ============================================================ */
/* Arcade Score & Multiplier System Styles */
/* ============================================================ */

/* Arcade stats in race stats container */
.stat.arcade-stat {
  background: rgba(255, 190, 11, 0.1);
  border-left: 2px solid var(--accent-gold);
  padding-left: 0.8rem;
}

.stat.arcade-stat .label {
  color: var(--accent-gold);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

.stat.arcade-stat .value.arcade-value {
  color: var(--accent-gold);
  font-family: 'Courier New', monospace;
  font-size: 1.1rem;
  font-weight: bold;
  text-shadow: 0 0 8px rgba(255, 190, 11, 0.6);
}

/* Arcade result stat on results screen */
.result-stat.arcade-result-stat {
  background: rgba(255, 190, 11, 0.1);
  border: 1px solid rgba(255, 190, 11, 0.4);
  border-radius: 6px;
  padding: 0.8rem 1rem;
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.result-stat.arcade-result-stat .label {
  color: var(--accent-gold);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 0.5px;
  margin: 0;
}

.result-stat.arcade-result-stat .value.arcade-result-value {
  color: var(--accent-gold);
  font-family: 'Courier New', monospace;
  font-size: 1.3rem;
  font-weight: bold;
  text-shadow: 0 0 10px rgba(255, 190, 11, 0.8);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Personal best badge */
.personal-best-badge {
  display: inline-block;
  background: rgba(0, 255, 150, 0.2);
  border: 1px solid #00ff96;
  color: #00ff96;
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-left: 0.75rem;
  box-shadow: 0 0 10px rgba(0, 255, 150, 0.4);
  animation: new-best-pulse 0.6s ease-out;
}

@keyframes new-best-pulse {
  0% {
    transform: scale(0.8);
    opacity: 0;
  }
  50% {
    box-shadow: 0 0 20px rgba(0, 255, 150, 0.8);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Floating multiplier popup */
.arcade-multiplier-popup {
  font-family: 'Courier New', monospace;
  font-weight: bold;
  font-size: 24px;
  pointer-events: none;
  z-index: 1000;
  white-space: nowrap;
}

@keyframes arcade-float-popup {
  0% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translateY(-60px) scale(0.8);
    opacity: 0;
  }
}

/* Motion accessibility: Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .arcade-multiplier-popup {
    animation: none;
  }

  .personal-best-badge {
    animation: none;
  }

  .stat.arcade-stat .value.arcade-value {
    text-shadow: none;
  }

  .result-stat.arcade-result-stat .value.arcade-result-value {
    text-shadow: none;
  }
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  .stat.arcade-stat {
    flex: 0 1 auto;
    min-width: auto;
  }

  .stat.arcade-stat .label {
    font-size: 0.65rem;
  }

  .stat.arcade-stat .value.arcade-value {
    font-size: 0.9rem;
  }

  .result-stat.arcade-result-stat {
    flex-direction: column;
    align-items: flex-start;
  }

  .personal-best-badge {
    margin-left: 0;
    margin-top: 0.4rem;
  }

  .arcade-multiplier-popup {
    font-size: 18px;
  }
}

/* ===== Callsign & Challenge Banner Styling ===== */

.callsign-input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-secondary);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: 'Courier New', monospace;
  font-size: 0.95rem;
  font-weight: 600;
  transition: all 0.2s ease;
}

.callsign-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.3);
}

.callsign-input::placeholder {
  color: var(--text-secondary);
  opacity: 0.7;
}

.callsign-help {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.7rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* Challenge Banner (Ghost Challenge) */
.challenge-banner {
  margin-top: 1rem;
  padding: 1.25rem 1.5rem;
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.1), rgba(255, 0, 110, 0.1));
  border: 2px solid var(--primary);
  border-radius: 10px;
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.4), inset 0 0 10px rgba(0, 240, 255, 0.1);
  animation: challenge-pulse 2s ease-in-out infinite;
}

@keyframes challenge-pulse {
  0%, 100% {
    box-shadow: 0 0 20px rgba(0, 240, 255, 0.4), inset 0 0 10px rgba(0, 240, 255, 0.1);
  }
  50% {
    box-shadow: 0 0 30px rgba(0, 240, 255, 0.6), inset 0 0 15px rgba(0, 240, 255, 0.2);
  }
}

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

.challenge-content {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.challenge-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 2px;
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.5);
}

.challenge-opponent {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent-alt);
  font-family: 'Courier New', monospace;
}

.challenge-stats {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.clear-challenge-btn {
  margin-top: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-secondary);
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  align-self: flex-start;
}

.clear-challenge-btn:hover {
  background: var(--border-secondary);
  color: var(--text-primary);
  box-shadow: 0 0 8px rgba(0, 240, 255, 0.2);
}

.clear-challenge-btn:active {
  transform: scale(0.98);
}

/* ============================================================
 * COLLAPSIBLE MODIFIERS PANEL
 * ============================================================ */

.modifiers-panel {
  margin-top: 0.75rem;
  background: var(--bg-card);
  border: 1.5px solid var(--border-secondary);
  border-radius: 8px;
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.modifiers-panel[open] {
  border-color: var(--primary);
  box-shadow: 0 0 18px rgba(0, 245, 255, 0.18);
}

.modifiers-panel-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 0.95rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modifiers-panel-summary::-webkit-details-marker {
  display: none;
}

.modifiers-summary-left {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  white-space: nowrap;
}

.modifiers-active-count {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--primary);
  background: rgba(0, 245, 255, 0.12);
  border: 1px solid rgba(0, 245, 255, 0.35);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  white-space: nowrap;
}

.modifiers-chevron {
  color: var(--text-secondary);
  font-size: 0.85rem;
  flex-shrink: 0;
  transition: transform 0.2s ease, color 0.2s ease;
}

.modifiers-panel[open] .modifiers-chevron {
  transform: rotate(180deg);
  color: var(--primary);
}

.modifiers-panel-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.25rem 0.85rem 0.9rem 0.85rem;
}

.modifier-item {
  width: 100%;
}

.modifier-toggle-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  min-height: 76px;
  padding: 0.75rem 0.95rem;
  background: var(--bg-secondary);
  border: 1.5px solid var(--border-secondary);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.25s ease;
}

.modifier-toggle-label:hover {
  border-color: var(--secondary);
  box-shadow: 0 0 14px rgba(255, 46, 151, 0.25);
}

.modifier-toggle-label:has(.modifier-toggle:checked) {
  border-color: var(--secondary);
  background: rgba(255, 46, 151, 0.1);
  box-shadow: var(--neon-glow-magenta);
}

.modifier-toggle-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  text-align: left;
}

.modifier-toggle-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modifier-toggle-desc {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.modifier-switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 24px;
  flex-shrink: 0;
}

.modifier-toggle {
  opacity: 0;
  width: 0;
  height: 0;
}

.modifier-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-secondary);
  border-radius: 24px;
  transition: all 0.25s ease;
}

.modifier-slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  top: 3px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: all 0.25s ease;
}

.modifier-toggle:checked + .modifier-slider {
  background: rgba(255, 46, 151, 0.35);
  border-color: var(--secondary);
}

.modifier-toggle:checked + .modifier-slider::before {
  transform: translateX(22px);
  background: var(--secondary);
  box-shadow: 0 0 10px var(--secondary);
}
/* ============================================================
 * ARCADE JUICE
 * Everything here is cosmetic: transforms, opacity, glows, and click-through overlays only,
 * so layout and element coordinates never move.
 * ============================================================ */

/* ---- FX layer (callouts, glitch, shockwave) ---- */
#fx-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1500;
}

/* ---- Micro shake (transform only) ---- */
.fx-shake {
  animation: fx-shake 170ms ease-in-out;
}

.fx-shake-heavy {
  animation: fx-shake-heavy 260ms ease-in-out;
}

@keyframes fx-shake {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-3px, 1px); }
  50% { transform: translate(3px, -1px); }
  75% { transform: translate(-2px, 1px); }
}

@keyframes fx-shake-heavy {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  20% { transform: translate(-7px, 3px) rotate(-0.4deg); }
  40% { transform: translate(6px, -3px) rotate(0.4deg); }
  60% { transform: translate(-5px, 2px) rotate(-0.3deg); }
  80% { transform: translate(4px, -2px) rotate(0.2deg); }
}

/* ---- Chromatic glitch flash ---- */
.fx-glitch {
  position: absolute;
  inset: 0;
  mix-blend-mode: screen;
  animation: fx-glitch 220ms steps(4, end) forwards;
}

.fx-glitch-magenta {
  background:
    linear-gradient(90deg, rgba(255, 46, 151, 0.28), transparent 40%),
    linear-gradient(270deg, rgba(0, 245, 255, 0.22), transparent 40%);
}

.fx-glitch-cyan {
  background:
    linear-gradient(90deg, rgba(0, 245, 255, 0.3), transparent 45%),
    linear-gradient(270deg, rgba(157, 78, 221, 0.25), transparent 45%);
}

.fx-glitch-red {
  background:
    linear-gradient(90deg, rgba(255, 30, 30, 0.45), transparent 50%),
    linear-gradient(270deg, rgba(255, 46, 151, 0.35), transparent 50%);
}

@keyframes fx-glitch {
  0% { opacity: 1; transform: translateX(-6px); }
  25% { opacity: 0.8; transform: translateX(5px) skewX(2deg); }
  50% { opacity: 1; transform: translateX(-3px); }
  100% { opacity: 0; transform: translateX(0); }
}

/* ---- Floating arcade callouts ---- */
.arcade-callout {
  position: absolute;
  left: 50%;
  top: 26%;
  transform: translateX(-50%);
  font-family: 'Courier New', monospace;
  font-size: clamp(2rem, 7vw, 4.5rem);
  font-weight: 900;
  letter-spacing: 0.12em;
  white-space: nowrap;
  animation: arcade-callout 1s cubic-bezier(0.2, 1.4, 0.4, 1) forwards;
}

.arcade-callout-cyan { color: var(--primary); text-shadow: 0 0 18px var(--primary), 0 0 40px var(--primary); }
.arcade-callout-gold { color: var(--accent-gold); text-shadow: 0 0 18px var(--accent-gold), 0 0 40px var(--accent-gold); }
.arcade-callout-magenta { color: var(--secondary); text-shadow: 0 0 18px var(--secondary), 0 0 40px var(--secondary); }
.arcade-callout-violet { color: #d9a8ff; text-shadow: 0 0 18px var(--accent), 0 0 44px var(--accent), 0 0 70px var(--secondary); }
.arcade-callout-red { color: #ff4040; text-shadow: 0 0 18px #ff2020, 0 0 40px #ff2020; }

@keyframes arcade-callout {
  0% { opacity: 0; transform: translateX(-50%) scale(0.3); }
  25% { opacity: 1; transform: translateX(-50%) scale(1.15); }
  70% { opacity: 1; transform: translateX(-50%) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-30px) scale(1.05); }
}

/* ---- EMP shockwave ring ---- */
.fx-shockwave {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 4px solid var(--primary);
  box-shadow: 0 0 24px var(--primary), inset 0 0 24px var(--primary);
  transform: translate(-50%, -50%) scale(1);
  animation: fx-shockwave 900ms ease-out forwards;
}

.fx-shockwave-violet {
  border-color: var(--accent);
  box-shadow: 0 0 24px var(--accent), inset 0 0 24px var(--accent);
}

@keyframes fx-shockwave {
  0% { opacity: 0.95; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(34); }
}

/* ---- Scramble Core matrix flash over the prompt stage ---- */
.word-stage.fx-matrix::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 12px;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(0, 255, 150, 0.22) 0 2px, transparent 2px 6px),
    linear-gradient(90deg, rgba(0, 245, 255, 0.18), rgba(255, 46, 151, 0.18));
  mix-blend-mode: screen;
  animation: fx-matrix 500ms steps(5, end) forwards;
}

@keyframes fx-matrix {
  0% { opacity: 1; background-position: 0 0, 0 0; }
  100% { opacity: 0; background-position: 0 30px, 0 0; }
}

/* ---- Combo fever: glow, track energy, speedlines ---- */
#main-screen { --fever-rgb: 0, 245, 255; --fever-i: 0; }
#main-screen[data-fever='2'] { --fever-rgb: 0, 245, 255; --fever-i: 1; }
#main-screen[data-fever='3'] { --fever-rgb: 255, 190, 11; --fever-i: 2; }
#main-screen[data-fever='4'] { --fever-rgb: 255, 46, 151; --fever-i: 3; }
#main-screen[data-fever='5'] { --fever-rgb: 217, 168, 255; --fever-i: 4; }

#main-screen[data-fever] .race-panel {
  border-color: rgb(var(--fever-rgb));
  animation: fever-pulse 1.1s ease-in-out infinite;
}

#main-screen[data-fever] .race-track {
  border-color: rgb(var(--fever-rgb));
  box-shadow:
    0 0 calc(14px * var(--fever-i)) rgba(var(--fever-rgb), 0.75),
    inset 0 0 calc(10px * var(--fever-i)) rgba(var(--fever-rgb), 0.35);
}

#main-screen[data-fever] .input-field {
  border-color: rgb(var(--fever-rgb));
  box-shadow: 0 0 calc(12px * var(--fever-i)) rgba(var(--fever-rgb), 0.8);
}

#main-screen[data-fever] .stats-container {
  border-color: rgb(var(--fever-rgb));
  box-shadow: 0 0 calc(8px * var(--fever-i)) rgba(var(--fever-rgb), 0.5);
}

#main-screen[data-fever]::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: calc(var(--fever-i) * 0.22);
  background: repeating-linear-gradient(
    90deg,
    transparent 0 46px,
    rgba(var(--fever-rgb), 0.5) 46px 48px
  );
  mix-blend-mode: screen;
  animation: speedlines 0.45s linear infinite;
}

@keyframes fever-pulse {
  0%, 100% { box-shadow: 0 0 calc(6px * var(--fever-i)) rgba(var(--fever-rgb), 0.4); }
  50% { box-shadow: 0 0 calc(18px * var(--fever-i)) rgba(var(--fever-rgb), 0.9); }
}

@keyframes speedlines {
  from { background-position: 0 0; }
  to { background-position: -96px 0; }
}

/* ---- Sudden Death armed: red hazard bar and input ---- */
#main-screen[data-hazard]::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 6px;
  pointer-events: none;
  background: repeating-linear-gradient(45deg, #ff2e2e 0 12px, #1a0000 12px 24px);
  animation: hazard-pulse 0.9s ease-in-out infinite;
}

#main-screen[data-hazard] .input-field {
  border-color: #ff2e2e;
  box-shadow: 0 0 16px rgba(255, 46, 46, 0.55);
}

@keyframes hazard-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

/* EMP flash must win over the fever border */
#main-screen .race-track.emp-pulse {
  border-color: var(--accent);
  box-shadow: 0 0 28px rgba(157, 78, 221, 0.7), inset 0 0 24px rgba(157, 78, 221, 0.3);
}

/* ---- Hover-pods: thrusters, bobbing, nitro tilt, afterburners ---- */
.lane .racer-avatar::before {
  content: '';
  position: absolute;
  right: 100%;
  top: 50%;
  width: 30px;
  height: 8px;
  margin-right: -10px;
  transform: translateY(-50%);
  border-radius: 8px 0 0 8px;
  background: linear-gradient(270deg, rgba(0, 245, 255, 0.85), rgba(0, 245, 255, 0));
  filter: blur(1px);
  opacity: 0.8;
  animation: thruster-flicker 0.18s linear infinite alternate;
  pointer-events: none;
}

.lane.player-lane .racer-avatar::before {
  background: linear-gradient(270deg, rgba(255, 46, 151, 0.9), rgba(255, 190, 11, 0.5), rgba(255, 46, 151, 0));
}

.lane .racer-sprite {
  animation: pod-bob 1.8s ease-in-out infinite;
}

#lane-ai_ai2 .racer-sprite { animation-delay: -0.6s; }
#lane-ai_ai3 .racer-sprite { animation-delay: -1.2s; }

.lane.nitro .racer-sprite {
  rotate: -5deg;
  scale: 1.1;
  transition: rotate 0.15s ease, scale 0.15s ease;
}

.lane.nitro .racer-avatar::before {
  width: 62px;
  background: linear-gradient(270deg, rgba(255, 255, 255, 0.95), rgba(255, 46, 151, 0.8), rgba(255, 46, 151, 0));
}

.lane.overtake .racer-sprite {
  filter: drop-shadow(0 0 14px var(--primary)) brightness(1.5);
}

.lane.surging .racer-avatar::before {
  width: 58px;
  height: 11px;
  background: linear-gradient(270deg, rgba(255, 220, 90, 0.95), rgba(255, 90, 20, 0.85), rgba(255, 30, 0, 0));
}

.lane.stunned .racer-avatar::before {
  opacity: 0.08;
  animation: none;
}

@keyframes pod-bob {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -2px; }
}

@keyframes thruster-flicker {
  from { opacity: 0.6; }
  to { opacity: 0.95; }
}

/* ---- Spark particles on clears ---- */
.fx-spark {
  position: absolute;
  left: 58px;
  top: 40%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent-gold);
  box-shadow: 0 0 8px var(--accent-gold);
  pointer-events: none;
  animation: fx-spark 600ms ease-out forwards;
}

@keyframes fx-spark {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.2); }
}

/* ---- Tiered screen shakes (transform only; each ends back at translate(0)) ---- */
.fx-shake-firework {
  animation: fx-shake-firework 200ms ease-out;
}

.fx-screen-quake {
  animation: fx-screen-quake 300ms ease-in-out;
}

@keyframes fx-shake-firework {
  0%, 100% { transform: translate(0, 0) scale(1); }
  30% { transform: translate(0, -4px) scale(1.012); }
  60% { transform: translate(2px, 2px) scale(0.996); }
}

@keyframes fx-screen-quake {
  0%, 100% { transform: translate(0, 0) rotate(0) scale(1); }
  12% { transform: translate(-10px, 5px) rotate(-0.6deg) scale(1.015); }
  27% { transform: translate(9px, -6px) rotate(0.6deg) scale(1.015); }
  42% { transform: translate(-8px, 4px) rotate(-0.4deg) scale(1.01); }
  57% { transform: translate(6px, -3px) rotate(0.3deg) scale(1.01); }
  75% { transform: translate(-3px, 2px) rotate(-0.1deg) scale(1.004); }
}

/* ---- Fireworks: neon sparks that fly out of a burst point and fade ---- */
.fx-firework {
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
}

.fx-firework-spark {
  --spark: var(--primary);
  position: absolute;
  left: -3px;
  top: -3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--spark);
  box-shadow: 0 0 10px var(--spark), 0 0 20px var(--spark);
  animation: fx-firework-spark 800ms cubic-bezier(0.1, 0.7, 0.3, 1) forwards;
}

.fx-firework-cyan { --spark: #00f5ff; }
.fx-firework-magenta { --spark: #ff2e97; }
.fx-firework-gold { --spark: #ffbe0b; }
.fx-firework-violet { --spark: #d9a8ff; }

@keyframes fx-firework-spark {
  0% { opacity: 1; transform: translate(0, 0) scale(1.3); }
  70% { opacity: 0.9; }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.2); }
}

/* ---- Cyber scan-flare: a soft bar sweeping down the screen during high fever or surges ---- */
.fx-scanflare {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 18vh;
  opacity: 0.55;
  mix-blend-mode: screen;
  background: linear-gradient(180deg, transparent, rgba(0, 245, 255, 0.22) 50%, transparent);
  animation: fx-scanflare 1.8s linear infinite;
}

.fx-scanflare-surge {
  background: linear-gradient(180deg, transparent, rgba(255, 46, 151, 0.3) 50%, transparent);
  animation-duration: 1.1s;
}

@keyframes fx-scanflare {
  from { transform: translateY(-20vh); }
  to { transform: translateY(105vh); }
}

/* ---- Third-person chase camera (final 25%) ---- */
/* The track tilts toward the viewer, the player's pod grows, and rivals shrink into the distance.
   Lane `left`/`top` values are untouched; only transforms, outlines, and the badge change. */
.race-track.pov-third-person {
  transform: perspective(700px) rotateX(7deg);
  transform-origin: 50% 100%;
  transition: transform 600ms ease-out;
  outline: 2px solid rgba(255, 46, 151, 0.75);
  outline-offset: -6px;
}

.race-track.pov-third-person .lane {
  transition: left 75ms linear, scale 500ms ease-out;
}

.race-track.pov-third-person .lane.player-lane {
  scale: 1.18;
}

.race-track.pov-third-person .lane:not(.player-lane) {
  scale: 0.88;
}

.race-track.pov-third-person .lane.player-lane .racer-avatar::before {
  width: 56px;
  height: 10px;
  filter: blur(1.5px) brightness(1.3);
}

.pov-badge {
  position: absolute;
  left: 0.6rem;
  bottom: 0.4rem;
  padding: 0.1rem 0.5rem;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: #fff;
  background: rgba(255, 46, 151, 0.8);
  border: 1px solid #ff2e97;
  border-radius: 3px;
  text-shadow: 0 0 6px #ff2e97;
  pointer-events: none;
  z-index: 30;
  animation: pov-badge-in 500ms ease-out, badge-blink 0.8s ease-in-out 500ms infinite alternate;
}

@keyframes pov-badge-in {
  0% { opacity: 0; transform: translateX(-24px) scale(1.6); }
  100% { opacity: 1; transform: none; }
}

/* ---- Dissolve (crossfade) transitions: opacity only, so nothing moves or stops receiving clicks ---- */
#main-screen.dissolve-in {
  animation: dissolve-in 600ms ease-in-out both;
}

#start-screen.dissolve-out {
  animation: dissolve-out 600ms ease-in-out both;
  pointer-events: none;
}

/* The results wait (--dissolve-delay) for the gun strike on the race screen, then fade in over it */
#results-screen.dissolve-in {
  animation: dissolve-in var(--dissolve-ms, 1400ms) ease-in-out var(--dissolve-delay, 0ms) both;
}

@keyframes dissolve-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes dissolve-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ---- FPS HUD guns: two cannons rise from the lower corners and shoot the losing pods ---- */
.fps-gun {
  position: absolute;
  bottom: 0;
  width: 130px;
  height: 200px;
  pointer-events: none;
  transform-origin: 50% 100%;
  filter: drop-shadow(0 0 10px rgba(0, 245, 255, 0.6));
  animation: fps-gun-rise 350ms ease-out both;
}

.fps-gun-left { left: 5%; rotate: 16deg; }
.fps-gun-right { right: 5%; rotate: -16deg; }

.fps-gun-barrel {
  position: absolute;
  left: 50%;
  bottom: 40px;
  width: 44px;
  height: 150px;
  margin-left: -22px;
  clip-path: polygon(24% 0, 76% 0, 100% 100%, 0 100%);
  background: linear-gradient(90deg, #0b1126, #4d6aa8 45%, #0b1126);
}

.fps-gun-body {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 100px;
  height: 56px;
  margin-left: -50px;
  border-radius: 10px 10px 0 0;
  border: 2px solid var(--primary);
  border-bottom: 0;
  background: linear-gradient(180deg, #1a2347, #0b1126);
  box-shadow: inset 0 6px 0 rgba(255, 46, 151, 0.55);
}

.fps-gun-led {
  position: absolute;
  left: 50%;
  bottom: 18px;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  border-radius: 50%;
  background: #ff2e2e;
  box-shadow: 0 0 10px #ff2e2e;
}

.fps-gun.locked .fps-gun-led {
  animation: badge-blink 0.25s steps(2, end) infinite;
}

.fps-gun-muzzle {
  position: absolute;
  left: 50%;
  top: 0;
  width: 70px;
  height: 70px;
  margin-left: -35px;
  border-radius: 50%;
  opacity: 0;
  background: radial-gradient(circle, #fff 0%, #ffe066 35%, rgba(255, 46, 151, 0) 70%);
}

.fps-gun.firing .fps-gun-muzzle {
  animation: fps-muzzle 150ms ease-out;
}

.fps-gun.recoil {
  animation: fps-gun-recoil 180ms ease-out;
}

.fps-gun.retract {
  animation: fps-gun-retract 250ms ease-in both;
}

@keyframes fps-gun-rise {
  from { translate: 0 110%; }
  to { translate: 0 0; }
}

@keyframes fps-gun-recoil {
  0% { translate: 0 0; }
  30% { translate: 0 18px; }
  100% { translate: 0 0; }
}

@keyframes fps-gun-retract {
  from { translate: 0 0; }
  to { translate: 0 110%; }
}

@keyframes fps-muzzle {
  0% { opacity: 1; transform: scale(0.4); }
  100% { opacity: 0; transform: scale(1.5); }
}

.fx-tracer {
  position: absolute;
  width: var(--len);
  height: 4px;
  margin-top: -2px;
  transform-origin: 0 50%;
  transform: rotate(var(--ang)) scaleX(0);
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.95), #ff2e97 55%, rgba(255, 46, 151, 0));
  box-shadow: 0 0 12px #ff2e97;
  animation: fx-tracer 220ms linear forwards;
}

@keyframes fx-tracer {
  0% { opacity: 1; transform: rotate(var(--ang)) scaleX(0); }
  55% { opacity: 1; transform: rotate(var(--ang)) scaleX(1); }
  100% { opacity: 0; transform: rotate(var(--ang)) scaleX(1); }
}

.fx-impact {
  position: absolute;
  width: 0;
  height: 0;
}

.fx-impact-flash {
  position: absolute;
  left: -90px;
  top: -90px;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, #fff6b0 22%, #ffbe0b 45%, rgba(255, 60, 0, 0) 72%);
  animation: fx-impact-flash 520ms ease-out forwards;
}

.fx-impact-fireball {
  position: absolute;
  left: -55px;
  top: -55px;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffe066 0%, #ff8a1f 40%, #e02a00 68%, rgba(120, 0, 0, 0) 100%);
  filter: blur(2px);
  animation: fx-impact-fireball 900ms ease-out forwards;
}

.fx-impact-ring {
  position: absolute;
  left: -30px;
  top: -30px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 4px solid #ffd166;
  box-shadow: 0 0 22px #ff8a1f, inset 0 0 14px #ff8a1f;
  animation: fx-impact-ring 800ms ease-out forwards;
}

.fx-impact-ring-late {
  border-color: #00f5ff;
  box-shadow: 0 0 22px #00f5ff, inset 0 0 14px #00f5ff;
  animation-duration: 1100ms;
  animation-delay: 120ms;
  opacity: 0;
}

.fx-impact-spark {
  position: absolute;
  left: -3px;
  top: -3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ffb347;
  box-shadow: 0 0 10px #ff5a00, 0 0 20px #ff2e00;
  animation: fx-impact-spark 1100ms cubic-bezier(0.1, 0.7, 0.3, 1) forwards;
}

.fx-impact-debris {
  position: absolute;
  left: -5px;
  top: -5px;
  width: 10px;
  height: 6px;
  background: #3a2a2a;
  border: 1px solid #ff8a1f;
  animation: fx-impact-debris 1300ms cubic-bezier(0.15, 0.6, 0.4, 1) forwards;
}

.fx-impact-smoke {
  position: absolute;
  left: -22px;
  top: -22px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(70, 70, 80, 0.85), rgba(30, 30, 40, 0));
  opacity: 0;
  animation: fx-impact-smoke 1300ms ease-out var(--delay, 0ms) forwards;
}

/* A brief whole-screen white-orange glare as the blast goes off */
.fx-impact-glare {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 55%, rgba(255, 240, 200, 0.55), rgba(255, 120, 0, 0.18) 55%, transparent 80%);
  mix-blend-mode: screen;
  animation: fx-impact-glare 320ms ease-out forwards;
}

@keyframes fx-impact-flash {
  0% { opacity: 1; transform: scale(0.25); }
  100% { opacity: 0; transform: scale(3.6); }
}

@keyframes fx-impact-fireball {
  0% { opacity: 1; transform: scale(0.3); }
  35% { opacity: 1; transform: scale(1.6); }
  100% { opacity: 0; transform: scale(2.6) translateY(-18px); }
}

@keyframes fx-impact-ring {
  0% { opacity: 0.95; transform: scale(0.4); }
  100% { opacity: 0; transform: scale(7); }
}

.fx-impact-ring-late {
  animation-name: fx-impact-ring-late;
}

@keyframes fx-impact-ring-late {
  0% { opacity: 0.9; transform: scale(0.4); }
  100% { opacity: 0; transform: scale(10); }
}

@keyframes fx-impact-spark {
  0% { opacity: 1; transform: translate(0, 0) scale(1.4); }
  70% { opacity: 0.9; }
  100% { opacity: 0; transform: translate(var(--dx), calc(var(--dy) + 34px)) scale(0.2); }
}

@keyframes fx-impact-debris {
  0% { opacity: 1; transform: translate(0, 0) rotate(0); }
  100% { opacity: 0; transform: translate(var(--dx), calc(var(--dy) + 60px)) rotate(var(--rot)); }
}

@keyframes fx-impact-smoke {
  0% { opacity: 0; transform: translate(var(--sx, 0), 0) scale(0.4); }
  25% { opacity: 0.9; }
  100% { opacity: 0; transform: translate(var(--sx, 0), -70px) scale(3); }
}

@keyframes fx-impact-glare {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

/* A shot-down pod: dimmed and tipped over. Filter and child transforms only, so the lane never moves. */
.lane.destroyed {
  filter: brightness(0.6) saturate(0.6);
}

.lane.destroyed .racer-sprite {
  rotate: 22deg;
  scale: 0.85;
  animation: none;
  filter: drop-shadow(0 0 8px #ff5a00);
  transition: rotate 0.25s ease-out, scale 0.25s ease-out;
}

.lane.destroyed .racer-avatar::before {
  opacity: 0.05;
  animation: none;
}

/* ---- Saved data panel and seed bookmarks ---- */
.save-panel {
  margin-top: 0.75rem;
  background: var(--bg-card);
  border: 1.5px solid var(--border-secondary);
  border-radius: 8px;
  overflow: hidden;
}

.save-panel[open] {
  border-color: var(--primary);
}

.save-panel-summary {
  cursor: pointer;
  padding: 0.6rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.save-panel-body {
  padding: 0.25rem 0.85rem 0.85rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.save-line {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.save-subtitle {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 0.25rem;
}

.saved-seeds-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.saved-seed {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border-secondary);
  border-radius: 6px;
  font-size: 0.75rem;
  color: var(--text-primary);
}

.saved-seed-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-seed-load,
.saved-seed-remove,
.save-action-btn {
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--primary);
  border-radius: 5px;
  background: rgba(0, 245, 255, 0.08);
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.saved-seed-remove {
  border-color: var(--border-secondary);
  color: var(--text-secondary);
}

.save-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.save-action-danger {
  border-color: #ff6b6b;
  color: #ff6b6b;
  background: rgba(255, 107, 107, 0.08);
}

.save-action-danger.armed {
  background: #ff6b6b;
  color: #11182c;
}

.save-status {
  margin: 0;
  min-height: 1em;
  font-size: 0.72rem;
  color: #ffbe0b;
}

.share-btn.bookmark-btn.saved {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

/* ---- Mobile / tablet typing ergonomics ----
   On phones and tablets (narrow, or short in landscape) the input box stays a compact single line instead of
   the old 120-150 px block, the prompt wraps and stays large enough to read, the stats are a tight 3-up grid,
   and the play area scrolls so the prompt, the input, and the stats stay reachable above a virtual keyboard. */
@media (max-width: 1024px), (max-height: 600px) {
  .game-layout {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scroll-padding-bottom: 5rem;
  }

  .typing-panel {
    flex-shrink: 0;
    overflow: visible;
    gap: 0.6rem;
  }

  .word-stage {
    min-height: 72px;
    max-height: none;
    padding: 0.75rem 1rem;
  }

  .word-stage-content {
    gap: 0.5rem;
  }

  .words-display-centered {
    min-height: 0;
    font-size: 1.6rem;
    white-space: normal;
  }

  .words-display-centered .word {
    max-width: 100%;
    padding: 0.4rem 0.8rem;
    font-size: clamp(1.05rem, 4.6vw, 1.5rem);
    line-height: 1.35;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  /* 16px or larger stops iOS from zooming the page when the box takes focus */
  .input-field {
    min-height: 0;
    height: 48px;
    max-width: 100%;
    padding: 0.5rem 0.85rem;
    font-size: 16px;
    line-height: 1.4;
    overflow: hidden;
  }

  .stats-container {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.35rem 0.5rem;
    padding: 0.4rem 0.6rem;
  }

  .stat .value {
    font-size: 1rem;
  }
}

/* Keep the race header from crowding on a phone: icon-only camera toggle, a shorter round badge */
@media (max-width: 640px) {
  .game-header {
    gap: 0.4rem;
  }

  .btn-camera-toggle {
    margin-right: 0.4rem;
    padding: 0.4rem 0.55rem;
  }

  .btn-camera-toggle .camera-toggle-label,
  .progression-badge .badge-sep,
  .progression-badge .badge-complexity,
  .progression-badge .badge-pace {
    display: none !important;
  }

  .header-left {
    min-width: 0;
    gap: 0.4rem;
  }

  .game-header .header-logo {
    max-width: 84px;
    max-height: 28px;
    margin-right: 0;
  }

  .game-header .progression-badge {
    padding: 0.2rem 0.5rem;
    font-size: 0.6rem;
    white-space: nowrap;
  }

  .game-header .btn-sound-toggle {
    margin-right: 0.15rem;
  }

  .game-header .btn-camera-toggle {
    margin-right: 0.15rem;
  }

  .game-header .btn-back {
    padding: 0.4rem 0.6rem;
  }
}

/* On the narrowest phones there is no room for the round badge beside the controls (the round shows on the results) */
@media (max-width: 380px) {
  .game-header .progression-badge {
    display: none;
  }
}

@media (max-width: 480px) {
  .game-layout {
    gap: 0.5rem;
    padding: 0.5rem 0.6rem;
  }

  .word-stage {
    padding: 0.6rem 0.75rem;
  }

  .stat .label {
    font-size: 0.62rem;
  }

  .stat .value {
    font-size: 0.95rem;
  }
}

/* ---- Camera view toggle ---- */
.button-group.camera-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.camera-btn {
  padding: 0.6rem 0.5rem;
  border: 2px solid var(--border-secondary);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  text-align: center;
}

.camera-btn:hover {
  border-color: var(--primary);
  background: var(--bg-secondary);
}

.camera-btn.active {
  border-color: var(--primary);
  background: rgba(0, 245, 255, 0.1);
  color: var(--primary);
  box-shadow: 0 0 20px rgba(0, 245, 255, 0.4);
}

.btn-camera-toggle {
  background: rgba(255, 46, 151, 0.12);
  color: #ff7ab8;
  border: 1px solid #ff2e97;
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  margin-right: 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.3s ease;
}

.btn-camera-toggle:hover,
.btn-camera-toggle[aria-pressed='true'] {
  background: rgba(255, 46, 151, 0.28);
  box-shadow: 0 0 14px rgba(255, 46, 151, 0.45);
}

/* ---- Over-the-shoulder 4-lane view ----
   The camera sits behind the field looking down the course. The race track is laid on the ground like a
   road: turned 90 degrees so progress runs away from the viewer (start gate at the bottom, finish line at
   the far end) and tilted back under the panel's perspective, so the four lanes sit side by side and
   converge toward the vanishing point. Each pod is stood back up (counter-rotated) and lifted off the road
   so it faces the camera. Only transforms and the track's own box change; lane left/top percentages,
   race progress, and every calculation are untouched. */
#main-screen[data-camera='ots'] .race-container {
  --ots-tilt: 64deg; /* how far the road is laid back */
  --ots-length: 570px; /* the course length (progress axis) */
  --ots-lanes: 660px; /* the road width (the four lanes) */
  position: relative;
  flex: 0 0 auto;
  height: 211px; /* the classic track's footprint, so the page layout never shifts */
  overflow: visible;
  transform-style: preserve-3d;
  transform-origin: 50% 100%; /* the start gate stays on the near edge */
  transform: rotateX(var(--ots-tilt));
}

#main-screen[data-camera='ots'] .race-track {
  position: absolute;
  margin: 0;
  width: var(--ots-length);
  height: var(--ots-lanes);
  left: calc(50% - var(--ots-length) / 2);
  top: calc(100% - var(--ots-length) / 2 - var(--ots-lanes) / 2);
  overflow: visible;
  transform-style: preserve-3d;
  rotate: -90deg; /* start -> finish now runs up the screen; the track's own transform stays free for shakes */
}

/* The 75% chase camera's flat-strip tilt does not apply here (the whole view is already a chase view), and
   its transform-origin would move the road's pivot, so both are pinned */
#main-screen[data-camera='ots'] .race-track,
#main-screen[data-camera='ots'] .race-track.pov-third-person {
  transform-origin: 50% 50%;
}

#main-screen[data-camera='ots'] .race-track.pov-third-person {
  transform: none;
}

/* The 0% / 100% captions and the chase badge belong to the flat strip */
#main-screen[data-camera='ots'] .race-track::before,
#main-screen[data-camera='ots'] .race-track::after,
#main-screen[data-camera='ots'] .race-track .pov-badge {
  display: none;
}

#main-screen[data-camera='ots'] .race-track .lane {
  /* Undo the road's turn and tilt so the pod stands upright facing the camera, lifted clear of the road */
  transform: translateY(-50%) rotateZ(90deg) rotateX(calc(var(--ots-tilt) * -1)) translateZ(40px);
}

#main-screen[data-camera='ots'] .race-track .lane.player-lane {
  scale: 1.15;
}

/* A short fade hides the snap between the two layouts */
#main-screen.camera-switching .race-panel {
  animation: camera-switch 500ms ease-out;
}

@keyframes camera-switch {
  from { opacity: 0.35; }
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .race-container,
  #main-screen.camera-switching .race-panel {
    transition: none;
    animation: none;
  }
}

/* ---- Mutator preset chips ---- */
.modifier-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.6rem 0.85rem 0.15rem 0.85rem;
}

.preset-chip {
  background: rgba(0, 245, 255, 0.08);
  border: 1px solid rgba(0, 245, 255, 0.5);
  border-radius: 999px;
  color: var(--primary);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.25rem 0.7rem;
  text-transform: uppercase;
  transition: background 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
}

.preset-chip:hover {
  background: rgba(0, 245, 255, 0.2);
}

.preset-chip.active {
  background: var(--secondary);
  border-color: var(--secondary);
  box-shadow: 0 0 12px rgba(255, 46, 151, 0.7);
  color: #fff;
}

.preset-chip.preset-clear {
  border-color: var(--border-secondary);
  color: var(--text-secondary);
}

/* ---- Results: rank medal and personal best ---- */
.arcade-rank-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 0.5rem 0;
}

.rank-medal {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 3px solid var(--primary);
  background: var(--bg-card);
  color: var(--primary);
  font-size: 1.5rem;
  font-weight: 900;
  box-shadow: 0 0 18px rgba(0, 245, 255, 0.5);
  animation: medal-pop 0.6s cubic-bezier(0.2, 1.5, 0.4, 1);
}

.rank-medal[data-rank='S+'] {
  border-color: #ffd0ff;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--secondary), var(--accent-gold));
  box-shadow: 0 0 26px rgba(255, 46, 151, 0.8), 0 0 50px rgba(255, 190, 11, 0.5);
}

.rank-medal[data-rank='S'] {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
  box-shadow: 0 0 22px rgba(255, 190, 11, 0.7);
}

.rank-medal[data-rank='B'] {
  border-color: #6b7fa8;
  color: #9fb2d8;
  box-shadow: 0 0 10px rgba(107, 127, 168, 0.5);
}

.rank-medal[data-rank='DNF'] {
  border-color: #ff4040;
  color: #ff4040;
  font-size: 1rem;
  box-shadow: 0 0 14px rgba(255, 64, 64, 0.5);
}

.pb-banner {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.pb-banner[data-status='beaten'] {
  color: #00ff96;
  text-shadow: 0 0 10px rgba(0, 255, 150, 0.7);
  animation: new-best-pulse 0.6s ease-out;
}

.pb-banner[data-status='first'] {
  color: var(--primary);
}

@keyframes medal-pop {
  0% { transform: scale(0.2) rotate(-25deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* ---- Target crosshairs: lock-on reticle and badge (absolute, so lane layout never shifts) ---- */
.lane.locked-on .racer-avatar::after {
  content: '';
  position: absolute;
  inset: -7px;
  pointer-events: none;
  --reticle: #ff4a3d;
  background:
    linear-gradient(var(--reticle), var(--reticle)) top left / 11px 2px no-repeat,
    linear-gradient(var(--reticle), var(--reticle)) top left / 2px 11px no-repeat,
    linear-gradient(var(--reticle), var(--reticle)) top right / 11px 2px no-repeat,
    linear-gradient(var(--reticle), var(--reticle)) top right / 2px 11px no-repeat,
    linear-gradient(var(--reticle), var(--reticle)) bottom left / 11px 2px no-repeat,
    linear-gradient(var(--reticle), var(--reticle)) bottom left / 2px 11px no-repeat,
    linear-gradient(var(--reticle), var(--reticle)) bottom right / 11px 2px no-repeat,
    linear-gradient(var(--reticle), var(--reticle)) bottom right / 2px 11px no-repeat;
  filter: drop-shadow(0 0 4px rgba(255, 74, 61, 0.9));
  animation:
    reticle-snap 0.35s cubic-bezier(0.2, 1.4, 0.4, 1),
    reticle-pulse 1s ease-in-out 0.35s infinite alternate;
}

.target-badge {
  position: absolute;
  left: 0;
  top: -12px;
  padding: 0 4px;
  border: 1px solid #ff4a3d;
  border-radius: 3px;
  background: rgba(40, 0, 0, 0.8);
  color: #ffb03a;
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  line-height: 1.4;
  pointer-events: none;
  animation: badge-blink 0.9s steps(2, end) infinite;
}

@keyframes reticle-snap {
  0% { opacity: 0; transform: scale(2.4) rotate(45deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

@keyframes reticle-pulse {
  from { opacity: 0.65; }
  to { opacity: 1; }
}

@keyframes badge-blink {
  0% { opacity: 1; }
  100% { opacity: 0.55; }
}

/* ---- Motion accessibility ---- */
@media (prefers-reduced-motion: reduce) {
  .fx-shake,
  .fx-shake-heavy,
  .fx-glitch,
  .fx-shockwave,
  .arcade-callout,
  .fx-spark,
  .fx-shake-firework,
  .fx-screen-quake,
  .fx-firework-spark,
  .fx-scanflare,
  .pov-badge,
  #main-screen.dissolve-in,
  #start-screen.dissolve-out,
  #results-screen.dissolve-in,
  .fx-impact-flash,
  .fx-impact-spark,
  .fx-impact-fireball,
  .fx-impact-ring,
  .fx-impact-debris,
  .fx-impact-smoke,
  .fx-impact-glare,
  .lane.locked-on .racer-avatar::after,
  .target-badge,
  .lane .racer-sprite,
  .lane .racer-avatar::before,
  .rank-medal,
  .pb-banner,
  #main-screen[data-fever] .race-panel,
  #main-screen[data-fever]::after,
  #main-screen[data-hazard]::before,
  .word-stage.fx-matrix::after {
    animation: none;
  }

  .fx-firework,
  .fx-scanflare,
  .fps-gun,
  .fx-tracer,
  .fx-impact {
    display: none;
  }

  .phantom-phase .phantom-rest {
    animation: none;
  }

  .race-track.pov-third-person,
  .race-track.pov-third-person .lane {
    transform: none;
    transition: none;
  }
}
