/* ============================================================
   TypeMaster - Main Stylesheet
   A modern, responsive typing practice website
   ============================================================ */

/* ---- CSS Custom Properties (Theme Variables) ---- */
:root {
  /* Colors - Light Theme (default) */
  --bg-primary: #f0f4f8;
  --bg-secondary: #ffffff;
  --bg-tertiary: #e2e8f0;
  --bg-card: #ffffff;
  --text-primary: #1a202c;
  --text-secondary: #4a5568;
  --text-muted: #a0aec0;
  --accent-primary: #6366f1;
  --accent-secondary: #818cf8;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a78bfa 100%);
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --border-color: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.12);
  --shadow-glow: 0 0 20px rgba(99,102,241,0.3);

  /* Typography */
  --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --font-display: 'Inter', sans-serif;

  /* Spacing */
  --nav-height: 70px;
  --container-max: 1200px;
  --border-radius: 12px;
  --border-radius-sm: 8px;
  --border-radius-lg: 16px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;
  --transition-slow: 0.5s ease;
}

/* Dark Theme */
[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-card: #1e293b;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --accent-primary: #818cf8;
  --accent-secondary: #a78bfa;
  --border-color: #334155;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 25px rgba(129,140,248,0.4);
}

/* ---- Reset & Base ---- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font-primary);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background-color var(--transition-normal), color var(--transition-normal);
  overflow-x: hidden;
}

a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--accent-secondary);
}

img {
  max-width: 100%;
  height: auto;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
}

input, textarea, select {
  font-family: inherit;
  outline: none;
}

/* ---- Utility Classes ---- */
.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 24px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

/* ---- Navigation ---- */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  z-index: 1000;
  transition: all var(--transition-normal);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.navbar.scrolled {
  box-shadow: var(--shadow-md);
}

.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
  text-decoration: none;
}

.nav-logo .logo-icon {
  width: 36px;
  height: 36px;
  background: var(--accent-gradient);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.1rem;
  font-weight: 700;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
}

.nav-links a {
  padding: 8px 16px;
  border-radius: var(--border-radius-sm);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.95rem;
  transition: all var(--transition-fast);
  position: relative;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--accent-primary);
  background: rgba(99,102,241,0.08);
}

.nav-links a.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 3px;
  background: var(--accent-primary);
  border-radius: 3px;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Theme Toggle */
.theme-toggle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 1.2rem;
  transition: all var(--transition-fast);
  border: none;
  cursor: pointer;
}

.theme-toggle:hover {
  background: var(--accent-primary);
  color: white;
  transform: rotate(180deg);
}

/* Sound Toggle */
.sound-toggle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 1.1rem;
  transition: all var(--transition-fast);
  border: none;
  cursor: pointer;
}

.sound-toggle:hover {
  background: var(--accent-primary);
  color: white;
}

.sound-toggle.muted {
  opacity: 0.5;
}

/* Mobile Menu */
.mobile-menu-btn {
  display: none;
  width: 42px;
  height: 42px;
  border-radius: var(--border-radius-sm);
  background: transparent;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: none;
  cursor: pointer;
}

.mobile-menu-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: all var(--transition-fast);
}

.mobile-menu-btn.active span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.mobile-menu-btn.active span:nth-child(2) {
  opacity: 0;
}

.mobile-menu-btn.active span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

/* ---- Main Content ---- */
main {
  padding-top: var(--nav-height);
  min-height: calc(100vh - var(--nav-height));
}

/* ---- Hero Section ---- */
.hero {
  padding: 80px 0 60px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 30% 50%, rgba(99,102,241,0.08) 0%, transparent 50%),
              radial-gradient(circle at 70% 50%, rgba(139,92,246,0.06) 0%, transparent 50%);
  animation: heroGlow 8s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes heroGlow {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(-2%, 2%) scale(1.05); }
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: rgba(99,102,241,0.1);
  border: 1px solid rgba(99,102,241,0.2);
  border-radius: 50px;
  font-size: 0.85rem;
  color: var(--accent-primary);
  font-weight: 600;
  margin-bottom: 24px;
  animation: fadeInDown 0.6s ease;
}

.hero h1 {
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 20px;
  animation: fadeInUp 0.6s ease 0.1s both;
}

.hero h1 .gradient-text {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero p {
  font-size: 1.2rem;
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto 36px;
  animation: fadeInUp 0.6s ease 0.2s both;
}

.hero-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  animation: fadeInUp 0.6s ease 0.3s both;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  border-radius: var(--border-radius);
  font-weight: 600;
  font-size: 1rem;
  transition: all var(--transition-fast);
  cursor: pointer;
  border: none;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
  box-shadow: 0 4px 15px rgba(99,102,241,0.4);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(99,102,241,0.5);
  color: white;
}

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

.btn-secondary:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  transform: translateY(-2px);
}

.btn-ghost {
  background: transparent;
  color: var(--accent-primary);
  padding: 14px 20px;
}

.btn-ghost:hover {
  background: rgba(99,102,241,0.08);
}

.btn-sm {
  padding: 8px 16px;
  font-size: 0.875rem;
  border-radius: var(--border-radius-sm);
}

.btn-lg {
  padding: 16px 36px;
  font-size: 1.1rem;
}

.btn-icon {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
}

/* ---- Feature Cards ---- */
.features-section {
  padding: 60px 0 80px;
}

.section-header {
  text-align: center;
  margin-bottom: 48px;
}

.section-header h2 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.section-header p {
  color: var(--text-secondary);
  font-size: 1.05rem;
  max-width: 500px;
  margin: 0 auto;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 24px;
}

.feature-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 32px 24px;
  transition: all var(--transition-normal);
  position: relative;
  overflow: hidden;
}

.feature-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent-gradient);
  opacity: 0;
  transition: opacity var(--transition-normal);
}

.feature-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent-primary);
}

.feature-card:hover::before {
  opacity: 1;
}

.feature-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--border-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin-bottom: 16px;
  background: rgba(99,102,241,0.1);
  color: var(--accent-primary);
}

.feature-card h3 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.feature-card p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
}

/* ---- Stats Bar ---- */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 20px;
  padding: 40px 0;
}

.stat-item {
  text-align: center;
  padding: 20px;
  background: var(--bg-card);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 500;
}

/* ---- Typing Area ---- */
.typing-area {
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 32px;
  margin: 24px 0;
  position: relative;
}

.typing-text-display {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  line-height: 2;
  letter-spacing: 0.02em;
  padding: 24px;
  background: var(--bg-tertiary);
  border-radius: var(--border-radius);
  margin-bottom: 20px;
  min-height: 120px;
  position: relative;
  user-select: none;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.typing-text-display .char {
  position: relative;
  transition: color 0.1s ease;
}

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

.typing-text-display .char.incorrect {
  color: var(--error);
  background: rgba(239,68,68,0.15);
  border-radius: 2px;
}

.typing-text-display .char.current {
  background: rgba(99,102,241,0.2);
  border-radius: 2px;
}

.typing-text-display .char.current::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 2px;
  width: 100%;
  height: 2px;
  background: var(--accent-primary);
  animation: cursorBlink 1s ease-in-out infinite;
}

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

.typing-text-display .char.untyped {
  color: var(--text-muted);
}

.typing-input {
  width: 100%;
  padding: 16px 20px;
  font-family: var(--font-mono);
  font-size: 1.1rem;
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  transition: border-color var(--transition-fast);
  resize: none;
}

.typing-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}

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

/* ---- Progress Bar ---- */
.progress-container {
  margin: 20px 0;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.85rem;
  font-weight: 600;
}

.progress-bar {
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent-gradient);
  border-radius: 4px;
  transition: width 0.3s ease;
  position: relative;
}

.progress-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.3) 50%, transparent 100%);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ---- Live Stats ---- */
.live-stats {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  margin: 16px 0;
}

.live-stat {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--border-radius-sm);
}

.live-stat-icon {
  font-size: 1.2rem;
}

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

.live-stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ---- Virtual Keyboard ---- */
.keyboard-container {
  margin: 24px 0;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-bottom: 4px;
}

.key {
  min-width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all 0.1s ease;
  user-select: none;
}

.key.wide {
  min-width: 60px;
  font-size: 0.65rem;
}

.key.extra-wide {
  min-width: 80px;
}

.key.space-bar {
  min-width: 280px;
}

.key.active {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
  transform: scale(0.95);
  box-shadow: 0 0 12px rgba(99,102,241,0.4);
}

.key.correct-press {
  background: var(--success);
  color: white;
  border-color: var(--success);
}

.key.wrong-press {
  background: var(--error);
  color: white;
  border-color: var(--error);
}

/* ---- Lesson Cards ---- */
.lessons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  margin: 24px 0;
}

.lesson-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 24px;
  transition: all var(--transition-normal);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.lesson-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent-primary);
}

.lesson-card.completed {
  border-color: var(--success);
}

.lesson-card.completed::after {
  content: '\2713';
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  background: var(--success);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
}

.lesson-level {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.lesson-level.beginner {
  background: rgba(16,185,129,0.15);
  color: var(--success);
}

.lesson-level.intermediate {
  background: rgba(245,158,11,0.15);
  color: var(--warning);
}

.lesson-level.advanced {
  background: rgba(239,68,68,0.15);
  color: var(--error);
}

.lesson-card h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.lesson-card p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.lesson-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.lesson-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ---- Level Tabs ---- */
.level-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.level-tab {
  padding: 10px 20px;
  border-radius: var(--border-radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.level-tab:hover {
  background: rgba(99,102,241,0.1);
  color: var(--accent-primary);
}

.level-tab.active {
  background: var(--accent-primary);
  color: white;
}

/* ---- Test Mode ---- */
.test-config {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 32px;
  margin: 24px 0;
}

.test-config h3 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 20px;
}

.config-group {
  margin-bottom: 20px;
}

.config-group label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.config-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.config-option {
  padding: 8px 16px;
  border-radius: var(--border-radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.9rem;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.config-option:hover {
  border-color: var(--accent-primary);
}

.config-option.active {
  border-color: var(--accent-primary);
  background: rgba(99,102,241,0.1);
  color: var(--accent-primary);
}

/* Timer display */
.timer-display {
  text-align: center;
  padding: 16px;
}

.timer-value {
  font-size: 3rem;
  font-weight: 800;
  font-family: var(--font-mono);
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

/* ---- Results Modal ---- */
.results-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

.results-overlay.active {
  opacity: 1;
  visibility: visible;
}

.results-modal {
  background: var(--bg-card);
  border-radius: var(--border-radius-lg);
  padding: 40px;
  max-width: 520px;
  width: 90%;
  transform: scale(0.9) translateY(20px);
  transition: transform var(--transition-normal);
  text-align: center;
}

.results-overlay.active .results-modal {
  transform: scale(1) translateY(0);
}

.results-modal h2 {
  font-size: 1.8rem;
  margin-bottom: 8px;
}

.results-modal .results-subtitle {
  color: var(--text-secondary);
  margin-bottom: 28px;
}

.results-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.result-stat {
  padding: 16px;
  background: var(--bg-tertiary);
  border-radius: var(--border-radius);
}

.result-stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--accent-primary);
}

.result-stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.results-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ---- Profile Page ---- */
.profile-header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 32px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  margin: 24px 0;
}

.profile-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 2rem;
  font-weight: 700;
  flex-shrink: 0;
}

.profile-info h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.profile-info p {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.profile-level {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: rgba(99,102,241,0.1);
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-primary);
  margin-top: 8px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 24px;
  text-align: center;
  transition: all var(--transition-fast);
}

.stat-card:hover {
  border-color: var(--accent-primary);
  transform: translateY(-2px);
}

.stat-card-icon {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.stat-card-value {
  font-size: 2rem;
  font-weight: 800;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-card-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* History Table */
.history-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 24px;
  margin: 24px 0;
}

.history-section h3 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 16px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
}

.history-table th,
.history-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.history-table th {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.history-table td {
  font-size: 0.95rem;
}

.history-table tr:last-child td {
  border-bottom: none;
}

/* ---- Badges / Achievements ---- */
.badges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.badge-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 20px 16px;
  text-align: center;
  transition: all var(--transition-fast);
}

.badge-card.locked {
  opacity: 0.4;
  filter: grayscale(1);
}

.badge-card:hover:not(.locked) {
  border-color: var(--accent-primary);
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.badge-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
}

.badge-name {
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 4px;
}

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

/* ---- Settings Page ---- */
.settings-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 28px;
  margin: 20px 0;
}

.settings-section h3 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-color);
}

.setting-row:last-child {
  border-bottom: none;
}

.setting-label {
  display: flex;
  flex-direction: column;
}

.setting-label span:first-child {
  font-weight: 600;
  font-size: 0.95rem;
}

.setting-label span:last-child {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  width: 48px;
  height: 26px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-tertiary);
  border-radius: 26px;
  transition: all var(--transition-fast);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: all var(--transition-fast);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent-primary);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(22px);
}

/* Select Dropdown */
.setting-select {
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  cursor: pointer;
}

/* Range Slider */
.setting-range {
  display: flex;
  align-items: center;
  gap: 12px;
}

.setting-range input[type="range"] {
  -webkit-appearance: none;
  width: 120px;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
}

.setting-range input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-primary);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.setting-range-value {
  font-weight: 600;
  font-size: 0.9rem;
  min-width: 30px;
  text-align: center;
}

/* ---- Leaderboard ---- */
.leaderboard-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 6px;
}

.leaderboard-table th {
  padding: 10px 16px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: left;
}

.leaderboard-table td {
  padding: 14px 16px;
  background: var(--bg-tertiary);
  font-size: 0.95rem;
}

.leaderboard-table tr td:first-child {
  border-radius: var(--border-radius-sm) 0 0 var(--border-radius-sm);
}

.leaderboard-table tr td:last-child {
  border-radius: 0 var(--border-radius-sm) var(--border-radius-sm) 0;
}

.leaderboard-table tr.highlight td {
  background: rgba(99,102,241,0.1);
  border-top: 2px solid var(--accent-primary);
  border-bottom: 2px solid var(--accent-primary);
}

.leaderboard-table tr.highlight td:first-child {
  border-left: 2px solid var(--accent-primary);
}

.leaderboard-table tr.highlight td:last-child {
  border-right: 2px solid var(--accent-primary);
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.8rem;
}

.rank-1 {
  background: linear-gradient(135deg, #ffd700, #ffb700);
  color: #1a1a1a;
}

.rank-2 {
  background: linear-gradient(135deg, #c0c0c0, #a0a0a0);
  color: #1a1a1a;
}

.rank-3 {
  background: linear-gradient(135deg, #cd7f32, #b06c2a);
  color: white;
}

/* ---- Footer ---- */
.footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 48px 0 24px;
  margin-top: 60px;
}

.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 32px;
  margin-bottom: 32px;
}

.footer-brand {
  max-width: 280px;
}

.footer-brand .nav-logo {
  margin-bottom: 12px;
}

.footer-brand p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.6;
}

.footer-links h4 {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.footer-links ul {
  list-style: none;
}

.footer-links li {
  margin-bottom: 8px;
}

.footer-links a {
  color: var(--text-secondary);
  font-size: 0.9rem;
  transition: color var(--transition-fast);
}

.footer-links a:hover {
  color: var(--accent-primary);
}

.footer-bottom {
  padding-top: 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

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

.footer-social {
  display: flex;
  gap: 12px;
}

.footer-social a {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 1rem;
  transition: all var(--transition-fast);
}

.footer-social a:hover {
  background: var(--accent-primary);
  color: white;
  transform: translateY(-2px);
}

/* ---- Section Spacing ---- */
.page-section {
  padding: 40px 0;
}

.page-header {
  margin-bottom: 32px;
}

.page-header h1 {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.page-header p {
  color: var(--text-secondary);
  font-size: 1.05rem;
}

/* ---- Two Column Layout ---- */
.two-col {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
}

/* ---- Chart placeholder ---- */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 24px;
  margin: 20px 0;
}

.chart-container h4 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 16px;
}

.chart-area {
  height: 200px;
  background: var(--bg-tertiary);
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  padding: 16px;
  gap: 8px;
}

.chart-bar {
  flex: 1;
  background: var(--accent-gradient);
  border-radius: 4px 4px 0 0;
  transition: height 0.5s ease;
  min-width: 20px;
  max-width: 40px;
  position: relative;
}

.chart-bar:hover {
  opacity: 0.8;
}

.chart-bar::after {
  content: attr(data-label);
  position: absolute;
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ---- Mode Selector Cards ---- */
.mode-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.mode-card {
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.mode-card:hover {
  border-color: var(--accent-primary);
  transform: translateY(-2px);
}

.mode-card.active {
  border-color: var(--accent-primary);
  background: rgba(99,102,241,0.05);
}

.mode-card-icon {
  font-size: 2rem;
  margin-bottom: 8px;
}

.mode-card h4 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.mode-card p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ---- Page Transitions ---- */
.page-content {
  animation: pageIn 0.4s ease;
}

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

/* ---- Responsive Design ---- */
@media (max-width: 968px) {
  .two-col {
    grid-template-columns: 1fr;
  }

  .profile-header {
    flex-direction: column;
    text-align: center;
  }
}

@media (max-width: 768px) {
  :root {
    --nav-height: 60px;
  }

  .nav-links {
    display: none;
    position: fixed;
    top: var(--nav-height);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    flex-direction: column;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
  }

  .nav-links.mobile-open {
    display: flex;
  }

  .mobile-menu-btn {
    display: flex;
  }

  .hero h1 {
    font-size: 2rem;
  }

  .hero p {
    font-size: 1rem;
  }

  .typing-text-display {
    font-size: 1rem;
    padding: 16px;
  }

  .keyboard-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .key {
    min-width: 30px;
    height: 34px;
    font-size: 0.65rem;
  }

  .key.wide {
    min-width: 44px;
  }

  .key.extra-wide {
    min-width: 56px;
  }

  .key.space-bar {
    min-width: 160px;
  }

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

  .history-table {
    font-size: 0.85rem;
  }

  .history-table th,
  .history-table td {
    padding: 8px 10px;
  }

  .footer-grid {
    grid-template-columns: 1fr;
  }

  .live-stats {
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 0 16px;
  }

  .hero {
    padding: 40px 0 30px;
  }

  .hero-buttons {
    flex-direction: column;
    width: 100%;
  }

  .hero-buttons .btn {
    width: 100%;
  }

  .features-grid {
    grid-template-columns: 1fr;
  }

  .lessons-grid {
    grid-template-columns: 1fr;
  }

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

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

  .level-tabs {
    justify-content: center;
  }

  .badges-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .setting-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ---- Selection ---- */
::selection {
  background: rgba(99,102,241,0.3);
  color: var(--text-primary);
}

/* ---- Focus Visible ---- */
:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* ---- Print ---- */
@media print {
  .navbar, .footer, .keyboard-container, .theme-toggle, .sound-toggle {
    display: none !important;
  }

  main {
    padding-top: 0;
  }
}
