*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f7f9fc; --bg2: #ffffff; --bg3: #ffffff;
  --border: #e3e8f0; --text: #0f172a; --text2: #5b6878; --text3: #64748b;
  --accent: #2563eb; --green: #059669; --red: #dc2626; --yellow: #b45309;
  --correct: #059669; --wrong: #dc2626; --cursor: #b45309;
  --radius: 12px;
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; font-size: 15px; user-select: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
nav { background: var(--bg2); border-bottom: 1px solid var(--border); }
.nav-inner { max-width: 900px; margin: 0 auto; padding: 0 20px; height: 52px; display: flex; align-items: center; justify-content: space-between; }
.logo { font-weight: 700; font-size: 18px; color: var(--accent); }
.btn-ghost { background: none; border: none; color: var(--text2); font-size: 13px; cursor: pointer; padding: 6px 12px; border-radius: 8px; }
.btn-ghost:hover { background: var(--bg3); color: var(--text); }

/* CONFIG BAR */
.config-bar { background: var(--bg2); border-bottom: 1px solid var(--border); padding: 10px 0; }
.config-inner { max-width: 900px; margin: 0 auto; padding: 0 20px; display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.config-group { display: flex; align-items: center; gap: 10px; }
.config-label { font-size: 12px; color: var(--text3); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap; }
.btn-group { display: flex; gap: 4px; }
.cfg-btn { background: none; border: 1px solid var(--border); color: var(--text3); padding: 5px 12px; border-radius: 6px; font-size: 13px; cursor: pointer; transition: all 0.15s; }
.cfg-btn:hover { border-color: var(--accent); color: var(--text); }
.cfg-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.container { max-width: 900px; margin: 0 auto; padding: 28px 20px; }

/* LIVE STATS */
.live-stats { display: flex; gap: 32px; justify-content: center; margin-bottom: 20px; }
.live-stat { text-align: center; }
.live-val { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1; }
.live-lbl { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 4px; }
.timer-stat .live-val { color: var(--yellow); font-size: 32px; }
.accent-red { color: var(--red) !important; }
.accent-yellow { color: var(--yellow) !important; }
.accent-green { color: var(--green) !important; }

/* TEST CARD */
.test-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 36px;
  position: relative;
  min-height: 140px;
  cursor: text;
  margin-bottom: 16px;
  transition: border-color 0.2s;
}
.test-card:focus-within { border-color: var(--accent); }
.test-card.blur-active { filter: blur(3px); opacity: 0.4; }

.words-display {
  font-size: 22px;
  line-height: 1.85;
  font-family: 'Courier New', Courier, monospace;
  letter-spacing: 0.02em;
  overflow: hidden;
  max-height: 3.7em; /* show ~2 lines */
}

.word { display: inline-block; margin-right: 0.4em; position: relative; }
.word .letter { display: inline; }
.letter.correct { color: var(--correct); }
.letter.wrong   { color: var(--wrong); text-decoration: underline; text-decoration-color: var(--wrong); }
.letter.pending { color: var(--text3); }
.word.wrong-word > .letter { color: var(--wrong); }

.word-cursor { position: relative; }
.word-cursor::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.1em;
  bottom: 0.1em;
  width: 2px;
  background: var(--cursor);
  border-radius: 1px;
  animation: blink 1s step-end infinite;
}
.letter-cursor { position: relative; }
.letter-cursor::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.05em;
  bottom: 0.05em;
  width: 2px;
  background: var(--cursor);
  border-radius: 1px;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

.click-to-start {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--text3);
  pointer-events: none;
  background: rgba(22,27,39,0.85);
  border-radius: var(--radius);
  transition: opacity 0.2s;
}
.click-to-start.hidden { opacity: 0; pointer-events: none; }

.typing-input {
  position: fixed;
  top: -9999px;
  left: -9999px;
  opacity: 0;
  width: 1px;
  height: 1px;
}

/* CONTROLS */
.test-controls { display: flex; justify-content: center; gap: 12px; margin-bottom: 20px; }
.btn-restart {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 9px 22px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-restart:hover { border-color: var(--accent); color: var(--text); }
.btn-primary { background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 10px 24px; font-size: 14px; font-weight: 600; cursor: pointer; transition: background 0.15s; }
.btn-primary:hover { background: #3a7ae0; }
.btn-secondary { background: var(--bg3); border: 1px solid var(--border); color: var(--text2); border-radius: 8px; padding: 10px 20px; font-size: 14px; cursor: pointer; transition: all 0.15s; }
.btn-secondary:hover { border-color: var(--accent); color: var(--text); }

/* RESULTS */
.results-panel { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; margin-bottom: 20px; }
.results-header { display: flex; gap: 32px; align-items: flex-start; margin-bottom: 24px; flex-wrap: wrap; }
.result-big { text-align: center; }
.result-big-val { font-size: 72px; font-weight: 800; color: var(--accent); line-height: 1; }
.result-big-lbl { font-size: 14px; color: var(--text2); margin-top: 6px; text-transform: uppercase; letter-spacing: 1px; }
.results-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; flex: 1; }
.result-item { background: var(--bg3); border-radius: 10px; padding: 14px; text-align: center; }
.result-val { font-size: 22px; font-weight: 700; }
.result-lbl { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 4px; }

.wpm-chart-wrap { margin-bottom: 20px; }
.wpm-chart-wrap h3 { font-size: 14px; color: var(--text2); margin-bottom: 12px; }
#wpm-chart { width: 100%; background: var(--bg3); border-radius: 8px; display: block; }
.results-actions { display: flex; gap: 12px; }

/* HISTORY */
.history-panel { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.history-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.history-header h2 { font-size: 18px; }
.history-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.history-table th { background: var(--bg3); color: var(--text2); padding: 9px 12px; text-align: center; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; border-bottom: 1px solid var(--border); }
.history-table td { padding: 10px 12px; text-align: center; border-bottom: 1px solid rgba(42,51,71,0.4); color: var(--text2); }
.history-table tr:last-child td { border-bottom: none; }
.history-empty { text-align: center; color: var(--text3); padding: 40px; font-size: 15px; }
.pb-badge { background: var(--yellow); color: #000; font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px; margin-left: 4px; }

/* Progress bar */
.progress-wrap { width: 100%; height: 3px; background: var(--bg3); border-radius: 2px; margin-bottom: 8px; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.3s; }

@media(max-width:600px){
  .live-stats{gap:16px}
  .live-val{font-size:22px}
  .words-display{font-size:18px}
  .test-card{padding:20px}
  .result-big-val{font-size:56px}
  .results-grid{grid-template-columns:repeat(2,1fr)}
  .results-header{flex-direction:column;align-items:center}
}
