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

:root {
  --bg: #0d0d0d;
  --surface: #161616;
  --surface2: #1e1e1e;
  --border: #2a2a2a;
  --accent: #22d3ee;
  --accent-dim: rgba(34,211,238,0.15);
  --correct: #4ade80;
  --wrong: #f87171;
  --pending: #6b7280;
  --white: #f5f5f5;
  --font-mono: 'JetBrains Mono', monospace;
  --font-sans: 'Inter', sans-serif;
}

body {
  background: var(--bg);
  color: var(--white);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 900px;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
}
.logo-icon { font-size: 1.5rem; }
.accent { color: var(--accent); }

.nav { display: flex; gap: 6px; }
.nav-btn {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--pending);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}
.nav-btn:hover { color: var(--white); border-color: #444; }
.nav-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* Stats bar */
.stats-bar {
  display: flex;
  gap: 4px;
  justify-content: center;
}
.stat {
  flex: 1;
  max-width: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}
.stat-label {
  font-size: 0.65rem;
  color: var(--pending);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Progress bar */
.progress-container {
  height: 3px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #818cf8);
  transition: width 1s linear;
  border-radius: 2px;
}

/* Main typing area */
.main {
  position: relative;
  min-height: 260px;
}

.typing-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 32px;
  min-height: 260px;
  cursor: text;
  position: relative;
  overflow: hidden;
}

.code-snippet {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  line-height: 1.9;
  letter-spacing: 0.02em;
  user-select: none;
  white-space: pre-wrap;
  word-break: break-all;
}

.char { position: relative; }
.char.correct { color: var(--correct); }
.char.wrong {
  color: var(--wrong);
  background: rgba(248,113,113,0.15);
  border-radius: 2px;
}
.char.current {
  color: var(--white);
  border-left: 2px solid var(--accent);
  animation: cursorBlink 1s step-end infinite;
}
.char.pending { color: var(--pending); }

@keyframes cursorBlink {
  0%, 100% { border-left-color: var(--accent); }
  50% { border-left-color: transparent; }
}

.hidden-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  top: 0;
  left: 0;
}

/* Overlay */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(13,13,13,0.85);
  backdrop-filter: blur(4px);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s;
}
.overlay.hidden { display: none; }

.overlay-content { text-align: center; }
.overlay-content h2 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 8px;
}
.overlay-content p {
  color: var(--pending);
  font-size: 0.9rem;
  margin-bottom: 20px;
}

.start-btn {
  padding: 12px 32px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 8px;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.start-btn:hover { background: rgba(34,211,238,0.85); transform: translateY(-1px); }

/* Result screen */
.result-screen {
  position: absolute;
  inset: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.result-screen.hidden { display: none; }

.result-content { text-align: center; padding: 24px; }
.result-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 24px;
}
.result-emoji { font-size: 2rem; }
.result-title { font-size: 1.5rem; font-weight: 700; }

.result-stats {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.result-stat {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 20px;
  min-width: 90px;
}
.result-stat.highlight {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.result-value {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
}
.result-stat.highlight .result-value { color: var(--accent); }
.result-label {
  display: block;
  font-size: 0.65rem;
  color: var(--pending);
  margin-top: 4px;
  text-transform: uppercase;
}

.result-rank {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 20px;
  min-height: 24px;
}

.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.btn-primary {
  padding: 10px 24px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary:hover { opacity: 0.9; }
.btn-secondary {
  padding: 10px 24px;
  background: transparent;
  color: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover { border-color: #444; }

/* Footer hint */
.footer-hint {
  text-align: center;
  font-size: 0.75rem;
  color: var(--pending);
}
.footer-hint span {
  font-family: var(--font-mono);
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
}

@media (max-width: 600px) {
  .code-snippet { font-size: 0.9rem; }
  .stat-value { font-size: 1.2rem; }
  .typing-container { padding: 16px 14px; }
}
