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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3345;
  --text: #e2e8f0;
  --text-dim: #64748b;
  --text-faint: #475569;
  --primary: #6366f1;
  --primary-glow: rgba(99,102,241,0.15);
  --success: #22c55e;
  --error: #ef4444;
  --warning: #f59e0b;
  --correct-bg: rgba(34,197,94,0.08);
  --error-bg: rgba(239,68,68,0.12);
  --key-bg: #252a3a;
  --key-border: #353b50;
  --key-active: #6366f1;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
  --finger-lpinky: #ef4444;
  --finger-lring: #f97316;
  --finger-lmid: #eab308;
  --finger-lindex: #22c55e;
  --finger-rindex: #06b6d4;
  --finger-rmid: #3b82f6;
  --finger-rring: #8b5cf6;
  --finger-rpinky: #ec4899;
  --finger-thumb: #64748b;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* Hidden input for capturing keyboard */
#hidden-input {
  position: fixed;
  top: -100px;
  left: -100px;
  width: 1px;
  height: 1px;
  opacity: 0;
  font-size: 16px;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 100;
}
.logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--primary);
  cursor: pointer;
}
.logo span { color: var(--text); }
nav { display: flex; gap: 4px; }
nav button {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.875rem;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
nav button:hover, nav button.active {
  background: var(--surface2);
  color: var(--text);
}

/* Main content */
main {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
}

/* Screen visibility */
.screen { display: none; }
.screen.active { display: block; }

/* Menu Screen */
/* Launch screen (shown while Firebase loads) */
.launch-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  gap: 16px;
}
.launch-logo {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.02em;
}
.launch-logo span { color: var(--text); }
.launch-sub {
  color: var(--text-dim);
  font-size: 0.95rem;
}

/* Menu hero */
.menu-hero {
  text-align: center;
  padding: 36px 24px 28px;
  margin-bottom: 8px;
}
.menu-hero h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 12px;
}
.menu-hero p {
  color: var(--text-dim);
  font-size: 1rem;
  max-width: 520px;
  margin: 0 auto 20px;
  line-height: 1.6;
}
.menu-hero-returning {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 24px;
  text-align: left;
}
.menu-hero-returning .hero-greeting { flex: 1; min-width: 200px; }
.menu-hero-returning .hero-greeting h1 { margin-bottom: 4px; font-size: 1.5rem; }
.menu-hero-returning .hero-greeting p { margin: 0; font-size: 0.9rem; }
.hero-stats {
  display: flex;
  gap: 24px;
}
.hero-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.hero-num {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}
.hero-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.btn-hero {
  margin-top: 16px;
  padding: 12px 32px;
  font-size: 1rem;
}
.menu-hero-returning .btn-hero {
  width: 100%;
  margin-top: 0;
}

/* Progress bar */
.menu-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 4px;
  margin-bottom: 20px;
}
.menu-progress-bar {
  flex: 1;
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}
.menu-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s ease;
}
.menu-progress-text {
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: nowrap;
}

/* Next lesson highlight */
.lesson-card.next-lesson {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary), 0 0 12px var(--primary-glow);
}

.category-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin: 24px 0 12px;
  padding-left: 4px;
}

.lesson-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.lesson-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  overflow: hidden;
}
.lesson-card:hover {
  border-color: var(--primary);
  background: var(--surface2);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}
.lesson-card .number {
  font-size: 0.7rem;
  color: var(--text-faint);
  margin-bottom: 6px;
}
.lesson-card h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 4px;
}
.lesson-card .desc {
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.4;
}
.lesson-card .best {
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--primary);
  display: flex;
  gap: 12px;
}
.lesson-card .checkmark {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 20px;
  height: 20px;
  background: var(--success);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: white;
}

/* Practice Screen */
.practice-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.practice-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}
.back-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  transition: all 0.15s;
}
.back-btn:hover { color: var(--text); border-color: var(--text-dim); }

/* Stats Bar */
.stats-bar {
  display: flex;
  gap: 24px;
  padding: 14px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}
.stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.stat-value.wpm { color: var(--primary); }
.stat-value.accuracy { color: var(--success); }
.stat-value.errors { color: var(--error); }

/* Text Display */
.text-display-wrapper {
  position: relative;
  margin-bottom: 16px;
}
.text-display {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'JetBrains Mono', 'Consolas', monospace;
  font-size: 1.3rem;
  line-height: 2;
  min-height: 160px;
  cursor: text;
  position: relative;
  overflow-y: auto;
  max-height: 340px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-wrap: break-word;
  -webkit-user-select: none;
  user-select: none;
}
.text-display .char {
  position: relative;
  transition: color 0.05s;
}
.text-display .char.vowel-hl { color: #f0abfc; }
.text-display .char.vowel-hl.upcoming { color: #d946ef; font-weight: 600; }
.text-display .char.vowel-hl.correct { color: #a855f7; }
.text-display .char.vowel-hl.current { color: #e879f9; }
.text-display .char.correct { color: var(--text-dim); }
.text-display .char.incorrect {
  color: var(--error);
  background: var(--error-bg);
  border-radius: 2px;
}
.text-display .char.current { color: var(--text); }
.text-display .char.current::before {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 2.5px;
  background: var(--primary);
  border-radius: 2px;
  animation: blink 1s step-end infinite;
}
.text-display .char.upcoming { color: var(--text-faint); }

@keyframes blink {
  50% { opacity: 0; }
}

/* Tap to start overlay */
.tap-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15,17,23,0.8);
  border-radius: var(--radius);
  cursor: pointer;
  z-index: 10;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.tap-overlay span {
  color: var(--text-dim);
  font-size: 1rem;
  padding: 12px 24px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.tap-overlay.hidden { display: none; }

/* Visual Keyboard */
.keyboard-container { margin-top: 12px; }
.keyboard {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: 780px;
  margin: 0 auto;
}
.kb-row {
  display: flex;
  gap: 4px;
  justify-content: center;
}
.key {
  height: 42px;
  min-width: 42px;
  border: 1px solid var(--key-border);
  background: var(--key-bg);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-family: inherit;
  color: var(--text-dim);
  position: relative;
  transition: all 0.08s;
  flex-shrink: 0;
}
.key.wide-1-25 { min-width: 54px; }
.key.wide-1-5 { min-width: 65px; }
.key.wide-1-75 { min-width: 76px; }
.key.wide-2 { min-width: 86px; }
.key.wide-2-25 { min-width: 96px; }
.key.wide-2-75 { min-width: 118px; }
.key.space-bar { flex: 1; max-width: 340px; }

.key.highlight {
  border-color: var(--primary);
  background: var(--primary-glow);
  color: var(--text);
  box-shadow: 0 0 12px rgba(99,102,241,0.3);
}
.key.pressed {
  transform: scale(0.93);
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.key.error-flash {
  background: var(--error);
  border-color: var(--error);
  color: white;
}

.key .finger-dot {
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  opacity: 0.5;
}

.key.home-key::after {
  content: '';
  position: absolute;
  bottom: 6px;
  width: 8px;
  height: 2px;
  background: var(--text-faint);
  border-radius: 1px;
}

/* Results Screen */
.results-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 480px;
  margin: 40px auto;
  text-align: center;
}
.results-card h2 {
  font-size: 1.5rem;
  margin-bottom: 24px;
}
.results-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 28px;
}
.results-stat {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 16px;
}
.results-stat .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 4px;
}
.results-stat .value {
  font-size: 1.8rem;
  font-weight: 700;
}
.results-stat .value.wpm { color: var(--primary); }
.results-stat .value.acc { color: var(--success); }
.results-stat .value.err { color: var(--error); }
.results-stat .value.time { color: var(--warning); }
.results-stat .pb { font-size: 0.7rem; color: var(--warning); margin-top: 4px; }
.results-stat .xp-earned { font-size: 0.8rem; color: var(--primary); margin-top: 4px; font-weight: 600; }
.results-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* XP bar */
.xp-summary {
  margin-bottom: 24px;
  padding: 16px;
  background: var(--surface2);
  border-radius: var(--radius);
}
.xp-summary .xp-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.xp-summary .xp-label { font-size: 0.8rem; color: var(--text-dim); }
.xp-summary .xp-value { font-size: 1.2rem; font-weight: 700; color: var(--primary); }
.xp-summary .xp-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.xp-summary .xp-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.5s ease;
}
.xp-summary .xp-level { font-size: 0.7rem; color: var(--text-faint); margin-top: 4px; text-align: right; }

.btn {
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { border-color: var(--text-dim); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.btn-primary:hover { opacity: 0.9; }
.btn-danger {
  background: transparent;
  border-color: var(--error);
  color: var(--error);
}
.btn-danger:hover { background: var(--error); color: white; }
.btn-block { display: block; width: 100%; }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-google {
  background: white;
  color: #333;
  border: 1px solid #ddd;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-google:hover { background: #f5f5f5; border-color: #ccc; }

/* Stats Screen */
.stats-overview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 32px;
}
.stats-overview .stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stats-overview .stat-card .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 4px;
}
.stats-overview .stat-card .value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}

.history-table {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.history-table th, .history-table td {
  padding: 10px 14px;
  text-align: left;
  font-size: 0.85rem;
}
.history-table th {
  background: var(--surface2);
  color: var(--text-faint);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.history-table td { border-top: 1px solid var(--border); }

/* Settings Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.modal h3 {
  font-size: 1.15rem;
  margin-bottom: 20px;
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }
.setting-label { font-size: 0.9rem; }
.setting-desc { font-size: 0.75rem; color: var(--text-dim); }

/* Toggle switch */
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.toggle input { display: none; }
.toggle .slider {
  position: absolute;
  inset: 0;
  background: var(--surface2);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid var(--border);
}
.toggle .slider::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: all 0.2s;
}
.toggle input:checked + .slider {
  background: var(--primary);
  border-color: var(--primary);
}
.toggle input:checked + .slider::before {
  transform: translateX(20px);
  background: white;
}

/* Login Screen */
.login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 100px);
  padding: 20px;
}
.login-brand {
  text-align: center;
  margin-bottom: 32px;
}
.login-brand h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--primary);
}
.login-brand h1 span { color: var(--text); }
.login-brand p {
  color: var(--text-dim);
  font-size: 0.95rem;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.login-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.login-tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.9rem;
  font-family: inherit;
  padding: 10px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}
.login-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.login-form { display: flex; flex-direction: column; gap: 14px; }
.input-group { display: flex; flex-direction: column; gap: 4px; }
.input-group label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}
.input-field {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.input-field:focus { border-color: var(--primary); }
.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--text-faint);
  font-size: 0.8rem;
}
.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.form-error {
  color: var(--error);
  font-size: 0.8rem;
  margin-top: 4px;
}
.hidden { display: none !important; }

/* Profile Screen */
.profile-screen { max-width: 600px; margin: 0 auto; }
.profile-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.profile-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}
.profile-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.profile-info h2 { font-size: 1.2rem; margin-bottom: 2px; }
.profile-info p { color: var(--text-dim); font-size: 0.85rem; }
.profile-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.profile-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.profile-stat .value { font-size: 1.3rem; font-weight: 700; color: var(--primary); }
.profile-stat .label { font-size: 0.7rem; text-transform: uppercase; color: var(--text-faint); margin-top: 2px; }
.profile-section { margin-bottom: 24px; }
.profile-section h3 { font-size: 0.95rem; margin-bottom: 12px; }
.class-list { display: flex; flex-direction: column; gap: 8px; }
.class-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}
.class-item:hover { border-color: var(--primary); }
.class-item-info h4 { font-size: 0.9rem; margin-bottom: 2px; }
.class-item-info p { font-size: 0.75rem; color: var(--text-dim); }
.class-item-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface2);
  color: var(--text-faint);
  font-family: monospace;
}
.profile-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}

/* Leaderboard */
.leaderboard-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
}
.leaderboard-tab {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.leaderboard-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.leaderboard-list { display: flex; flex-direction: column; gap: 6px; }
.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all 0.15s;
}
.leaderboard-row--me {
  border-color: var(--primary);
  background: var(--primary-glow);
}
.leaderboard-row--top { border-color: var(--warning); }
.leaderboard-rank {
  font-size: 0.85rem;
  font-weight: 700;
  min-width: 36px;
  text-align: center;
  color: var(--text-dim);
}
.leaderboard-row--top .leaderboard-rank { color: var(--warning); }
.leaderboard-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
}
.leaderboard-avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-placeholder {
  width: 100%;
  height: 100%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 0.9rem;
}
.leaderboard-info { flex: 1; min-width: 0; }
.leaderboard-name { font-size: 0.9rem; font-weight: 600; display: block; }
.leaderboard-meta { font-size: 0.7rem; color: var(--text-dim); }
.leaderboard-xp { font-size: 0.85rem; font-weight: 700; color: var(--primary); white-space: nowrap; }

/* Class modals */
.class-modal h3 { margin-bottom: 8px; }
.class-modal p { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 14px; }
.class-modal .input-field { width: 100%; margin-bottom: 8px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.class-code-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  background: var(--surface2);
  border-radius: var(--radius);
  margin: 12px 0;
}
.class-code-display span {
  font-size: 1.8rem;
  font-weight: 700;
  font-family: monospace;
  letter-spacing: 0.15em;
  color: var(--primary);
}
.text-muted { color: var(--text-dim); }
.text-sm { font-size: 0.8rem; }

/* Class Dashboard */
.class-dashboard-header { margin-bottom: 20px; }
.class-dashboard-header h2 { font-size: 1.4rem; margin-bottom: 8px; }
.class-dashboard-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.class-code-badge {
  font-family: monospace;
  font-size: 0.85rem;
  padding: 2px 8px;
  background: var(--surface2);
  border-radius: 4px;
  color: var(--primary);
  letter-spacing: 0.05em;
}
.class-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card-sm {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}
.stat-card-sm .stat-value { font-size: 1.2rem; font-weight: 700; color: var(--primary); }
.stat-card-sm .stat-label { font-size: 0.65rem; text-transform: uppercase; color: var(--text-faint); }
.class-leaderboard h3 { font-size: 1rem; margin-bottom: 12px; }
.class-admin { margin-top: 24px; text-align: center; }
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  margin-bottom: 16px;
  padding: 4px 0;
}
.btn-back:hover { color: var(--text); }

/* Toast notifications */
#toast-container {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: inherit;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.2s ease;
  max-width: 320px;
}
.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--error); color: white; }
.toast-info { background: var(--primary); color: white; }
@keyframes toastIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Header layout */
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.back-to-landing {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 1.2rem;
  line-height: 1;
  transition: color 0.15s;
}
.back-to-landing:hover { color: var(--text); }

/* Loading spinner */

.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 768px) {
  header { padding: 10px 14px; }
  .logo { font-size: 1.1rem; }
  nav button { padding: 6px 10px; font-size: 0.8rem; }
  main { padding: 14px; }
  .text-display { font-size: 1.05rem; padding: 16px; line-height: 1.9; }
  .stats-bar { gap: 16px; padding: 10px 14px; }
  .stat-value { font-size: 1.05rem; }
  .key { height: 34px; min-width: 28px; font-size: 0.6rem; }
  .key.wide-1-25 { min-width: 36px; }
  .key.wide-1-5 { min-width: 44px; }
  .key.wide-1-75 { min-width: 52px; }
  .key.wide-2 { min-width: 58px; }
  .key.wide-2-25 { min-width: 64px; }
  .key.wide-2-75 { min-width: 78px; }
  .lesson-grid { grid-template-columns: 1fr; }
  .results-card { padding: 24px 16px; margin: 20px auto; }
  .results-stat .value { font-size: 1.4rem; }
  .profile-stats { grid-template-columns: repeat(2, 1fr); }
  .class-stats-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .key { height: 30px; min-width: 22px; font-size: 0.5rem; gap: 2px; }
  .key.wide-1-25 { min-width: 29px; }
  .key.wide-1-5 { min-width: 35px; }
  .key.wide-1-75 { min-width: 41px; }
  .key.wide-2 { min-width: 46px; }
  .key.wide-2-25 { min-width: 52px; }
  .key.wide-2-75 { min-width: 62px; }
  .kb-row { gap: 2px; }
  .keyboard { gap: 3px; }
  .profile-stats { grid-template-columns: 1fr; }
}
