:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --card: #1a1a3e;
  --char-correct: #e2e8f0;
  --char-current: #fbbf24;
  --char-incorrect: #ef4444;
  --char-untyped: #4a5568;
  --primary: #fbbf24;
  --secondary: #818cf8;
  --success: #34d399;
  --error: #ef4444;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #2d3748;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Outfit', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

.view {
  display: none;
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.view.active {
  display: block;
}

/* Navbar */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: var(--text-primary);
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 1.25rem;
}

.logo-bolt {
  font-size: 1.3em;
}

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

.nav-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  border-radius: 8px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.nav-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(251, 191, 36, 0.08);
}

/* Home Hero */
.home-hero {
  text-align: center;
  padding: 3rem 0 2rem;
}

.home-title {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 3rem;
  color: var(--text-primary);
}

.home-tagline {
  font-size: 1.15rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

/* Mode Grid */
.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
  max-width: 900px;
  margin: 0 auto;
}

.mode-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  animation: fadeSlideUp 0.4s ease backwards;
}

.mode-card:nth-child(1) { animation-delay: 0s; }
.mode-card:nth-child(2) { animation-delay: 0.1s; }
.mode-card:nth-child(3) { animation-delay: 0.2s; }
.mode-card:nth-child(4) { animation-delay: 0.3s; }

.mode-card:hover {
  transform: translateY(-4px);
  border-color: var(--primary);
  box-shadow: 0 8px 30px rgba(251, 191, 36, 0.1);
}

.mode-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.mode-name {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 1.25rem;
  margin-bottom: 0.25rem;
}

.mode-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1rem;
  line-height: 1.4;
}

.mode-options,
.time-options,
.word-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.mode-option {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  font-family: 'Outfit', sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

.mode-option.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #1a1a2e;
  font-weight: 600;
}

.custom-textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 0.75rem;
  border-radius: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  resize: vertical;
  margin-top: 0.5rem;
  margin-bottom: 0.75rem;
  line-height: 1.5;
}

.custom-textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-family: 'Outfit', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--primary);
  color: #1a1a2e;
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

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

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

.btn-save {
  background: var(--success);
  color: #1a1a2e;
}

.btn-danger {
  background: transparent;
  color: var(--error);
  border: 1px solid var(--error);
  margin-top: 1.5rem;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

.btn-back {
  background: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 0.4rem 0;
}

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

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

.pulse {
  animation: pulse 1.5s ease infinite;
}

/* Sub-view header */
.sub-view-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.sub-view-title {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 1.5rem;
}

/* Toast */
.toast-container {
  position: fixed;
  top: 70px;
  right: 1rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--card);
  border: 1px solid var(--primary);
  color: var(--text-primary);
  padding: 0.75rem 1.25rem;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  transform: translateX(120%);
  transition: transform 0.3s ease;
  max-width: 350px;
}

.toast.show {
  transform: translateX(0);
}

/* Leaderboard */
.lb-filters {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.lb-filter {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  font-family: 'Outfit', sans-serif;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.lb-filter.active {
  background: var(--primary);
  color: #1a1a2e;
  border-color: var(--primary);
}

.lb-sort {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.lb-sort-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: 'Outfit', sans-serif;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.lb-sort-btn.active {
  color: var(--primary);
  font-weight: 600;
}

.lb-table {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lb-header,
.lb-row {
  display: grid;
  grid-template-columns: 50px 80px 80px 1fr 80px 100px;
  align-items: center;
  padding: 0.6rem 0.75rem;
  font-size: 0.85rem;
  border-radius: 8px;
}

.lb-header {
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

.lb-row {
  background: var(--card);
  color: var(--text-secondary);
  animation: fadeSlideUp 0.3s ease backwards;
}

.lb-row .lb-wpm {
  color: var(--primary);
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
}

.lb-best {
  border: 1px solid rgba(251, 191, 36, 0.3);
  background: rgba(251, 191, 36, 0.05);
}

.lb-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 0;
}

/* Achievements */
.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.75rem;
}

.achievement-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.achievement-card.locked {
  opacity: 0.4;
}

.achievement-card.unlocked {
  border-color: rgba(251, 191, 36, 0.3);
}

.achievement-icon {
  font-size: 1.75rem;
  flex-shrink: 0;
}

.achievement-title {
  font-weight: 600;
  font-size: 0.95rem;
  display: block;
}

.achievement-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: block;
}

/* Animations */
@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(251, 191, 36, 0); }
}

/* Responsive */
@media (max-width: 1024px) {
  .mode-grid {
    grid-template-columns: 1fr;
    max-width: 500px;
  }
}

@media (max-width: 768px) {
  .home-title { font-size: 2rem; }
  .home-hero { padding: 2rem 0 1.5rem; }

  .lb-header, .lb-row {
    grid-template-columns: 40px 60px 60px 1fr 60px;
    font-size: 0.8rem;
  }

  .lb-date { display: none; }
}
