@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;600;700&family=Plus+Jakarta+Sans:wght@300;400;500;600;700&display=swap');

:root {
  --primary: #0A3D62;
  --primary-dark: #3C6382;
  --primary-light: #60A3BC;
  --primary-glow: rgba(37, 99, 235, 0.15);
  --secondary: #82CCDD;
  --accent: #F8F9FA;
  --accent-light: #22d3ee;
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.1);
  --error: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.1);
  --warning: #f59e0b;
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-elevated: #ffffff;
  --bg-input: #f1f5f9;
  --text: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-focus: #2563eb;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --mono: 'JetBrains Mono', monospace;
  --sans: 'Plus Jakarta Sans', sans-serif;
}

::selection {
  background: var(--primary);
  color: white;
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ===== APP SHELL ===== */
.app-shell {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 1rem 3rem;
  min-height: 100vh;
}

.app-header {
  padding: 2rem 0 0;
  margin-bottom: 2rem;
}

.header-content {
  text-align: center;
  margin-bottom: 1.5rem;
}

.app-title {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}

.app-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  font-weight: 400;
}

/* ===== TAB NAVIGATION ===== */
.tab-bar {
  display: flex;
  gap: 0.25rem;
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 4px;
}

.tab-btn {
  flex: 1;
  padding: 0.65rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

/* ===== TYPING TEST ===== */
.typing-test {
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  box-shadow: var(--shadow-sm);
}

.stat-value {
  font-family: var(--mono);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}

.progress-track {
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 2px;
  transition: width 0.15s ease;
}

/* ===== PARAGRAPH DISPLAY ===== */
.paragraph-display {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  font-family: var(--mono);
  font-size: 1.05rem;
  line-height: 2;
  margin-bottom: 1rem;
  cursor: text;
  user-select: none;
  box-shadow: var(--shadow-sm);
  max-height: 240px;
  overflow-y: auto;
}

.char {
  position: relative;
  letter-spacing: 0.01em;
  transition: color 0.1s;
}

.char.correct {
  color: var(--success);
}

.char.incorrect {
  color: var(--error);
  background: var(--error-bg);
  border-radius: 2px;
}

.char.cursor {
  border-left: 2px solid var(--primary);
  animation: blink 1s step-end infinite;
  margin-left: -1px;
  padding-left: 1px;
}

@keyframes blink {
  50% { border-color: transparent; }
}

.typing-input {
  width: 100%;
  min-height: 100px;
  padding: 1rem 1.25rem;
  font-family: var(--mono);
  font-size: 1rem;
  line-height: 1.8;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  resize: none;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.typing-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-glow);
}

.typing-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.typing-input::placeholder {
  color: var(--text-muted);
  font-family: var(--sans);
}

.test-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}

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

/* ===== BUTTONS ===== */
.btn {
  padding: 0.7rem 1.5rem;
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.3);
}

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

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

.btn-danger-sm {
  padding: 0.4rem 0.85rem;
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 500;
  border: 1px solid var(--error);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--error);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-danger-sm:hover {
  background: var(--error);
  color: white;
}

/* ===== RESULTS SCREEN ===== */
.results-screen {
  animation: fadeIn 0.5s ease;
}

.pb-banner {
  text-align: center;
  background: linear-gradient(135deg, var(--warning), #f97316);
  color: white;
  font-weight: 700;
  font-size: 1.1rem;
  padding: 0.85rem;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  animation: bounceIn 0.6s ease;
}

@keyframes bounceIn {
  0% { transform: scale(0.8); opacity: 0; }
  60% { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

.results-hero {
  text-align: center;
  padding: 2.5rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-md);
}

.wpm-display {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.5rem;
}

.wpm-number {
  font-family: var(--mono);
  font-size: 5rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.04em;
}

.wpm-unit {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.rating-blazing .wpm-number { color: #ef4444; }
.rating-impressive .wpm-number { color: #f59e0b; }
.rating-solid .wpm-number { color: var(--primary); }
.rating-growing .wpm-number { color: var(--accent); }
.rating-beginner .wpm-number { color: var(--success); }

.wpm-rating {
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 0.75rem;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
}

.result-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.result-info {
  display: flex;
  flex-direction: column;
}

.result-value {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
}

.result-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

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

/* ===== PERSONAL BESTS ===== */
.personal-bests {
  animation: fadeIn 0.4s ease;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 0.75rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  box-shadow: var(--shadow-sm);
}

.summary-card.best {
  border-top: 3px solid var(--warning);
}

.summary-card.avg {
  border-top: 3px solid var(--primary);
}

.summary-card.acc {
  border-top: 3px solid var(--success);
}

.summary-card.avgacc {
  border-top: 3px solid var(--accent);
}

.summary-emoji {
  font-size: 1.5rem;
}

.summary-value {
  font-family: var(--mono);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
}

.summary-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}

.records-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.records-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.record-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  animation: slideIn 0.3s ease both;
}

.record-row:nth-child(1) { animation-delay: 0s; }
.record-row:nth-child(2) { animation-delay: 0.04s; }
.record-row:nth-child(3) { animation-delay: 0.08s; }
.record-row:nth-child(4) { animation-delay: 0.12s; }
.record-row:nth-child(5) { animation-delay: 0.16s; }
.record-row:nth-child(6) { animation-delay: 0.2s; }
.record-row:nth-child(7) { animation-delay: 0.24s; }
.record-row:nth-child(8) { animation-delay: 0.28s; }
.record-row:nth-child(9) { animation-delay: 0.32s; }
.record-row:nth-child(10) { animation-delay: 0.36s; }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}

.record-row:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.record-row.top-record {
  border-left: 3px solid var(--warning);
}

.record-rank {
  font-size: 1.25rem;
  min-width: 2.5rem;
  text-align: center;
  font-weight: 700;
  color: var(--text-muted);
  font-family: var(--mono);
}

.record-details {
  flex: 1;
  min-width: 0;
}

.record-main {
  display: flex;
  gap: 1rem;
  align-items: baseline;
}

.record-wpm {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary);
}

.record-accuracy {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.record-meta {
  display: flex;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.record-delete {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.record-delete:hover {
  background: var(--error-bg);
  color: var(--error);
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.empty-state h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.empty-state p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

/* ===== LOADING SKELETON ===== */
.records-loading {
  padding: 2rem 0;
}

.skeleton-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.skeleton-row {
  height: 68px;
  background: linear-gradient(90deg, var(--bg-input) 25%, var(--border) 50%, var(--bg-input) 75%);
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .app-shell {
    padding: 0 0.75rem 2rem;
  }

  .app-title {
    font-size: 1.5rem;
  }

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

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

  .paragraph-display {
    font-size: 0.92rem;
    padding: 1rem;
    line-height: 1.85;
  }

  .typing-input {
    min-height: 80px;
    font-size: 0.92rem;
  }

  .test-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .wpm-number {
    font-size: 3.5rem;
  }

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

  .results-actions {
    flex-direction: column;
  }

  .results-actions .btn {
    justify-content: center;
  }

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

  .record-main {
    flex-direction: column;
    gap: 0.15rem;
  }

  .record-meta {
    flex-wrap: wrap;
  }
}

@media (max-width: 380px) {
  .stats-bar {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

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


<!-- WALKTHROUGH_SCRIPT:
[
  {"step": 1, "narration": "Welcome to TypePulse! This is your personal typing speed test. The main screen shows a paragraph for you to type.", "view": "user", "highlight_selector": ".paragraph-display", "wait_for": "tap_to_continue"},
  {"step": 2, "narration": "Click in the text area below the paragraph and start typing. Your WPM, accuracy, and time update in real-time as you type.", "view": "user", "highlight_selector": ".typing-input", "wait_for": "user_interaction"},
  {"step": 3, "narration": "Watch the live stats bar at the top — it tracks your words per minute, accuracy percentage, elapsed time, and character progress.", "view": "user", "highlight_selector": ".stats-bar", "wait_for": "tap_to_continue"},
  {"step": 4, "narration": "Characters you type correctly turn green. Mistakes are highlighted in red. The cursor shows your current position in the paragraph.", "view": "user", "highlight_selector": ".paragraph-display", "wait_for": "tap_to_continue"},
  {"step": 5, "narration": "When you finish typing the full paragraph, you'll see a detailed results screen with your WPM, accuracy rating, and character stats.", "view": "user", "highlight_selector": ".results-hero", "wait_for": "tap_to_continue"},
  {"step": 6, "narration": "Every test result is automatically saved. Switch to the Personal Bests tab to see all your records ranked by WPM.", "view": "user", "highlight_selector": ".tab-btn:nth-child(2)", "wait_for": "user_interaction"},
  {"step": 7, "narration": "The summary cards show your best WPM, average WPM, best accuracy, and average accuracy across all tests. Track your improvement over time!", "view": "user", "highlight_selector": ".summary-cards", "wait_for": "tap_to_continue"}
]
-->

.identity-badge {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  opacity: 0.85;
}

.saving-note {
  margin-top: 0.75rem;
  font-size: 0.95rem;
  opacity: 0.8;
}

.leaderboard-panel {
  margin-bottom: 1.5rem;
}

.leaderboard-list .record-row {
  width: 100%;
}

.empty-state.compact {
  padding: 2rem 1rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
}

.sound-feedback-row {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.btn-sound {
  min-width: 180px;
}

.mode-selector {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0 0 1rem;
}

.mode-btn {
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-btn:hover {
  color: var(--text);
  border-color: var(--primary-light);
}

.mode-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}

.timed-hint {
  color: var(--accent);
}

.timed-finish-note {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.18);
  font-size: 0.92rem;
}

.race-room-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

.race-room-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.race-room-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.race-room-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.room-code-pill {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--primary);
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}

.race-room-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.room-input {
  min-width: 160px;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-family: var(--mono);
  font-weight: 600;
  outline: none;
}

.room-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-glow);
}

.race-room-message {
  margin-top: 0.75rem;
  color: var(--text-secondary);
  font-size: 0.92rem;
}

.race-roster {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-top: 0.9rem;
}

.roster-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  background: var(--bg-input);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.roster-card.connected {
  border-color: rgba(16, 185, 129, 0.3);
}

.roster-card.disconnected {
  opacity: 0.75;
}

.roster-card span {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.race-progress-panel {
  margin-top: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.race-progress-row {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 0.75rem;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.race-progress-track {
  height: 10px;
  background: var(--bg-input);
  border-radius: 999px;
  overflow: hidden;
}

.race-progress-fill {
  height: 100%;
  border-radius: inherit;
  transition: width 0.15s ease;
}

.race-progress-fill.me {
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.race-progress-fill.opponent {
  background: linear-gradient(90deg, var(--warning), #f97316);
}

@media (max-width: 640px) {
  .race-room-header {
    flex-direction: column;
  }

  .race-roster {
    grid-template-columns: 1fr;
  }

  .race-progress-row {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }
}

.lobby-presence-panel {
  margin-top: 0.9rem;
  padding: 0.85rem;
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--bg-input), rgba(255, 255, 255, 0.7));
  border: 1px solid var(--border);
}

.lobby-presence-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0.65rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.lobby-users-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.lobby-user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  font-size: 0.85rem;
}

.presence-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.12);
  flex-shrink: 0;
}

.lobby-user-name {
  font-weight: 600;
  color: var(--text);
}

.lobby-user-room {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.78rem;
}

.lobby-empty-note {
  font-size: 0.88rem;
  color: var(--text-muted);
  padding: 0.2rem 0;
}

.race-room-badges {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.room-occupancy-indicator {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 0.75rem;
}

.occupancy-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-secondary);
}

.occupancy-pill.active {
  background: var(--success-bg);
  color: var(--success);
  border-color: rgba(16, 185, 129, 0.2);
}

.occupancy-pill.subtle {
  background: transparent;
}

@media (max-width: 640px) {
  .lobby-presence-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .race-room-badges {
    justify-content: flex-start;
  }
}

.history-section {
  margin-bottom: 1.5rem;
}

.history-chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
}

.history-chart-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.history-chart-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.history-stat {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.history-stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}

.history-stat-value {
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.history-stat-value.trend-up {
  color: var(--success);
}

.history-stat-value.trend-down {
  color: var(--error);
}

.history-chart-wrap {
  min-height: 240px;
}

.history-chart-wrap canvas {
  width: 100% !important;
  height: 240px !important;
}

.mode-badge {
  margin-top: 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.race-status-pill {
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 700;
}

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

.race-input {
  min-width: 160px;
}

.race-progress-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-top: 1rem;
}

.race-progress-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  padding: 0.85rem;
}

.race-progress-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--bg-card);
  overflow: hidden;
  margin: 0.5rem 0;
  border: 1px solid var(--border);
}

.race-progress-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.race-progress-bar.opponent span {
  background: linear-gradient(90deg, var(--warning), #f97316);
}

.race-meta-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

@media (max-width: 640px) {
  .history-chart-summary,
  .race-progress-grid {
    grid-template-columns: 1fr;
  }

  .race-actions-row {
    flex-direction: column;
  }

  .race-input {
    min-width: 0;
  }
}

.records-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.share-note {
  margin-bottom: 0.9rem;
}

.record-select {
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  text-align: inherit;
  color: inherit;
}

.record-row.selected-record {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px var(--primary-glow), var(--shadow-sm);
}

.record-share {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.record-share:hover {
  background: var(--primary-glow);
  color: var(--primary);
}

@media (max-width: 640px) {
  .records-actions {
    width: 100%;
    justify-content: flex-start;
  }
}
