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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #222633;
  --border: #2a2f3d;
  --text: #e8eaed;
  --text-muted: #8b919e;
  --accent: #6ee7b7;
  --accent-dim: rgba(110, 231, 183, 0.15);
  --correct: #6ee7b7;
  --correct-bg: rgba(110, 231, 183, 0.12);
  --error: #f87171;
  --error-bg: rgba(248, 113, 113, 0.15);
  --current: #fbbf24;
  --current-bg: rgba(251, 191, 36, 0.2);
  --pending: #4b5563;
  --font-sans: 'Outfit', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(110, 231, 183, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(99, 102, 241, 0.06), transparent);
}

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
}

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

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.logo-icon {
  font-size: 2rem;
  filter: grayscale(0.2);
}

.logo h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent), #34d399);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.control-group label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

select {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b919e' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
}

select:hover,
select:focus {
  border-color: var(--accent);
  outline: none;
}

.btn {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.55rem 1.25rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
}

.btn-primary:hover {
  background: #5dd9a8;
}

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

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

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

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 600;
}

.stat-correct {
  color: var(--correct);
}

.stat-error {
  color: var(--error);
}

.typing-area {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  min-height: 180px;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.text-display {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  line-height: 1.9;
  word-wrap: break-word;
  user-select: none;
  margin-bottom: 1rem;
  min-height: 4.5em;
}

.char {
  position: relative;
}

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

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

.char.current {
  background: var(--current-bg);
  border-bottom: 2px solid var(--current);
  border-radius: 2px;
  animation: blink 1s step-end infinite;
}

.char.pending {
  color: var(--pending);
}

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

.typing-input {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  resize: none;
  height: 52px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.typing-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

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

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

.results {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.results.hidden {
  display: none;
}

.results h2 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  color: var(--accent);
}

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

.result-card {
  background: var(--bg);
  border-radius: 10px;
  padding: 1.25rem;
  border: 1px solid var(--border);
}

.result-value {
  display: block;
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.25rem;
}

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

.error-review {
  text-align: left;
  margin-bottom: 1.5rem;
  padding: 1rem 1.25rem;
  background: var(--bg);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.error-review.hidden {
  display: none;
}

.error-review h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.error-review ul {
  list-style: none;
}

.error-review li {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
}

.error-review li:last-child {
  border-bottom: none;
}

.error-review .expected {
  color: var(--correct);
}

.error-review .typed {
  color: var(--error);
  text-decoration: line-through;
}

.error-review .context {
  color: var(--text-muted);
  font-size: 0.8rem;
}

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

.footer kbd {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.15rem 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}

@media (max-width: 640px) {
  .stats-bar {
    grid-template-columns: repeat(3, 1fr);
  }

  .stats-bar .stat:nth-child(4),
  .stats-bar .stat:nth-child(5) {
    grid-column: span 1;
  }

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

  .text-display {
    font-size: 1.05rem;
  }

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

  .control-group select {
    width: 100%;
  }
}
