/* ===== Reset & Variables ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

:root {
  --bg:           #1a1b26;
  --bg-secondary: #24283b;
  --bg-tertiary:  #2f334d;
  --border:       #3b4261;
  --text:         #c0caf5;
  --text-dim:     #7b84a8;
  --text-muted:   #636b8a;
  --accent:       #7aa2f7;
  --accent-hover: #89b4fa;
  --correct:      #9ece6a;
  --incorrect:    #f7768e;
  --warning:      #e0af68;
  --cursor-color: #c0caf5;
  --radius:       8px;
  --radius-sm:    5px;
  --transition:   0.15s ease;
  --font-ui:      'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:    'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

/* Scales from 15px (mobile) → 20px (1700px+ screens) */
html { font-size: clamp(15px, 1vw + 3px, 20px); }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ===== Layout ===== */
#app { display: flex; flex-direction: column; min-height: 100vh; }

header {
  position: sticky; top: 0; z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1100px; margin: 0 auto;
  padding: 0 clamp(12px, 3vw, 28px);
  height: 3.75rem;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}

.logo { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); cursor: pointer; border-radius: var(--radius-sm); padding: 4px 6px; transition: opacity var(--transition); }
.logo:hover { opacity: 0.75; }
.logo-mark { font-size: 1.25rem; }
.logo-text { font-size: 1.125rem; font-weight: 400; letter-spacing: -0.3px; }
.logo-text strong { font-weight: 600; color: var(--accent); }

.main-nav { display: flex; gap: 4px; }
.nav-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-dim); font-family: var(--font-ui);
  font-size: 0.875rem; font-weight: 500;
  padding: 6px 0.875rem; border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
  white-space: nowrap;
}
.nav-btn:hover { color: var(--text); background: var(--bg-tertiary); }
.nav-btn.active { color: var(--accent); background: var(--bg-secondary); }

#main-content { flex: 1; max-width: 1100px; width: 100%; margin: 0 auto; padding: clamp(20px, 3vw, 36px) clamp(14px, 3vw, 28px) clamp(48px, 6vw, 72px); }

.screen { display: block; }
.screen.hidden { display: none !important; }

.section-title { font-size: 1.375rem; font-weight: 600; margin-bottom: 1.5rem; }

/* ===== Config Panel ===== */
.config-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.75rem;
  display: flex; flex-direction: column; gap: 1rem;
}
.config-row { display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: flex-start; }
.config-group { display: flex; flex-direction: column; gap: 0.5rem; }
.config-label { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-dim); }

.toggle-group { display: flex; gap: 4px; flex-wrap: wrap; }
.toggle-btn {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer;
  font-family: var(--font-ui); font-size: 0.875rem; font-weight: 500;
  padding: 7px 0.875rem; border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.toggle-btn:hover { color: var(--text); border-color: var(--accent); }
.toggle-btn.active {
  background: var(--accent); border-color: var(--accent);
  color: #1a1b26; font-weight: 600;
}

/* ===== Quick Stats ===== */
.quick-stats {
  display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1.75rem;
}
.stat-card {
  flex: 1; min-width: 6rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem; text-align: center;
}
.stat-card.large { min-width: 8.5rem; padding: 1.25rem; }
.stat-value {
  font-size: 1.75rem; font-weight: 600;
  color: var(--accent); font-family: var(--font-mono);
  line-height: 1;
}
.stat-card.large .stat-value { font-size: 2.25rem; }
.stat-label { font-size: 0.8125rem; color: var(--text-dim); margin-top: 6px; font-weight: 500; }
.level-badge { color: var(--correct) !important; }

.start-area { text-align: center; padding: 12px 0; }
.start-hint { color: var(--text-dim); font-size: 0.8125rem; }
.start-hint kbd {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 7px; font-family: var(--font-mono);
  font-size: 0.75rem; color: var(--text);
}

/* ===== Test Screen ===== */
.test-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem; gap: 1rem;
}
.live-metrics { display: flex; gap: 1.5rem; }
.metric-item { display: flex; flex-direction: column; align-items: center; min-width: 3.25rem; }
.metric-value { font-size: 1.75rem; font-weight: 600; font-family: var(--font-mono); color: var(--text); line-height: 1; }
.metric-label { font-size: 0.75rem; color: var(--text-dim); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.6px; }

.timer-section { flex: 1; max-width: 300px; }
.timer-display {
  font-size: 1.375rem; font-weight: 700; font-family: var(--font-mono);
  color: var(--accent); text-align: center; margin-bottom: 6px;
  transition: color var(--transition);
}
.timer-display.timer-warning { color: var(--incorrect); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }

.progress-track {
  height: 4px; background: var(--bg-tertiary);
  border-radius: 2px; overflow: hidden;
}
.progress-bar {
  height: 100%; background: var(--accent);
  border-radius: 2px; width: 0%;
  transition: width 0.1s linear;
}

.test-controls { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  background: var(--bg-secondary); border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer; border-radius: var(--radius-sm);
  width: 2.25rem; height: 2.25rem; display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }

/* ===== Typing Area ===== */
.typing-area {
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem 2rem;
  min-height: 9rem; max-height: 18rem;
  overflow-y: auto;
  cursor: text;
  outline: none;
  transition: border-color var(--transition);
  position: relative;
}
.typing-area:focus { border-color: var(--accent); }

.text-display {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  line-height: 1.9;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.char { transition: color 0.05s; }
.char.correct { color: var(--correct); }
.char.incorrect { color: var(--incorrect); text-decoration: underline; text-decoration-color: var(--incorrect); }
.char.cursor {
  color: var(--bg);
  background: var(--cursor-color);
  border-radius: 2px;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

.typing-footer { text-align: center; margin-top: 0.875rem; }
.typing-hint { color: var(--text-muted); font-size: 0.75rem; }
.typing-hint kbd {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 3px; padding: 1px 5px; font-size: 0.6875rem;
  font-family: var(--font-mono); color: var(--text-dim);
}

/* ===== Results ===== */
.results-top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem;
}
.results-title { font-size: 1.375rem; font-weight: 600; }
.xp-gain {
  font-size: 1.125rem; font-weight: 700; color: var(--warning);
  font-family: var(--font-mono);
}
.xp-gain.animated { animation: xpPop 0.5s cubic-bezier(0.34,1.56,0.64,1); }
@keyframes xpPop { 0% { transform: scale(0); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

.results-metrics {
  display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1.75rem;
}
.result-metric {
  flex: 1; min-width: 5.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.125rem; text-align: center;
}
.result-metric.primary .result-value { font-size: 3.25rem; color: var(--accent); }
.result-value {
  font-size: 2rem; font-weight: 700;
  font-family: var(--font-mono); color: var(--text);
  line-height: 1;
}
.result-label { font-size: 0.8125rem; color: var(--text-dim); margin-top: 6px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }

.chart-section { margin-bottom: 1.75rem; }
.chart-title { font-size: 0.875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); margin-bottom: 0.625rem; }
.chart-wrap {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.chart-wrap canvas { display: block; width: 100%; }

/* Analysis */
.analysis-section {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem;
}
.analysis-section h4 { font-size: 0.8125rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); margin-bottom: 0.75rem; }
.insights-list { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.insights-list li { font-size: 0.875rem; color: var(--text); padding-left: 0.75rem; position: relative; }
.insights-list li::before { content: '→'; position: absolute; left: 0; color: var(--accent); }
.insights-list li kbd {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 3px; padding: 1px 5px; font-family: var(--font-mono); font-size: 0.75rem;
}

.error-keys { margin-top: 1rem; }
.error-key-list { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.5rem; }
.error-key-badge {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 4px 10px;
}
.error-key-badge kbd {
  font-family: var(--font-mono); font-size: 0.8125rem; font-weight: 600;
  color: var(--incorrect);
}
.err-count { font-size: 0.75rem; color: var(--text-dim); }

.consistency-wrap { display: flex; align-items: center; gap: 10px; margin-top: 1rem; }
.consistency-label { font-size: 0.75rem; color: var(--text-dim); white-space: nowrap; min-width: 5rem; }
.consistency-bar { flex: 1; height: 6px; background: var(--bg-tertiary); border-radius: 3px; overflow: hidden; }
.consistency-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.consistency-score { font-size: 0.8125rem; font-weight: 600; font-family: var(--font-mono); color: var(--text); min-width: 2.25rem; text-align: right; }

/* Achievements */
.new-achievements {
  display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 1.25rem;
}
.new-ach-header { width: 100%; font-size: 0.8125rem; font-weight: 600; color: var(--warning); text-transform: uppercase; letter-spacing: 0.5px; }
.ach-badge {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-secondary); border: 1px solid var(--warning);
  border-radius: var(--radius); padding: 0.625rem 1rem;
}
.ach-badge.new { animation: slideIn 0.4s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
.ach-icon { font-size: 1.25rem; }
.ach-label { font-size: 0.875rem; font-weight: 600; }

.results-actions {
  display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 0.5rem;
}

/* ===== Buttons ===== */
.btn {
  padding: 0.625rem 1.375rem; border-radius: var(--radius);
  font-family: var(--font-ui); font-size: 0.875rem; font-weight: 600;
  cursor: pointer; border: 1px solid transparent;
  transition: all var(--transition);
  display: inline-flex; align-items: center; gap: 8px;
}
.btn kbd {
  font-family: var(--font-mono); font-size: 0.6875rem;
  background: rgba(255,255,255,0.15); border-radius: 3px; padding: 1px 5px;
}
.btn-primary { background: var(--accent); color: #1a1b26; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--bg-secondary); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: none; color: var(--text-dim); border-color: transparent; }
.btn-ghost:hover { color: var(--text); background: var(--bg-secondary); }
.btn-large { padding: 0.875rem 2rem; font-size: 1rem; }

/* ===== Progress Screen ===== */
.level-bar-section {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.125rem 1.375rem; margin-bottom: 1.5rem;
}
.level-info { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.level-label { font-size: 0.9375rem; font-weight: 600; color: var(--text); }
.xp-label { font-size: 0.8125rem; color: var(--text-dim); font-family: var(--font-mono); }
.level-bar { height: 8px; background: var(--bg-tertiary); border-radius: 4px; overflow: hidden; }
.level-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--correct)); border-radius: 4px; transition: width 0.6s ease; }
.level-next { font-size: 0.75rem; color: var(--text-dim); margin-top: 6px; }

.progress-bests { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1.75rem; }

.achievements-section { margin-bottom: 1.75rem; }
.achievements-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr)); gap: 10px; margin-top: 0.75rem; }
.ach-card {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.875rem; text-align: center;
  transition: all var(--transition);
}
.ach-card.unlocked { border-color: var(--warning); background: color-mix(in srgb, var(--bg-secondary) 80%, var(--warning) 20%); }
.ach-card.locked { opacity: 0.45; filter: grayscale(0.5); }
.ach-card .ach-icon { font-size: 1.5rem; margin-bottom: 6px; }
.ach-card .ach-label { font-size: 0.75rem; font-weight: 600; color: var(--text); }
.ach-card .ach-desc { font-size: 0.6875rem; color: var(--text-dim); margin-top: 3px; }

.history-section { margin-bottom: 1.75rem; }
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); margin-top: 0.75rem; }
.history-table { width: 100%; border-collapse: collapse; }
.history-table th {
  background: var(--bg-tertiary); color: var(--text-dim);
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 0.625rem 1rem; text-align: left; white-space: nowrap;
}
.history-table td { padding: 0.625rem 1rem; font-size: 0.875rem; border-top: 1px solid var(--border); }
.history-table td svg { width: 13px; height: 13px; vertical-align: middle; margin-right: 4px; }
.history-table tr:hover td { background: var(--bg-tertiary); }
.wpm-cell { font-weight: 700; color: var(--accent); font-family: var(--font-mono); }
.empty-row { text-align: center; color: var(--text-dim); padding: 1.5rem !important; }

/* ===== Practice Screen ===== */
.weak-keys-section { margin: 1.25rem 0; }
.weak-key-list { display: flex; flex-direction: column; gap: 0.625rem; }
.weak-key-item { display: flex; align-items: center; gap: 0.75rem; }
.weak-key {
  font-family: var(--font-mono); font-size: 0.875rem; font-weight: 600;
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 4px; padding: 4px 10px;
  color: var(--incorrect); min-width: 3.25rem; text-align: center;
}
.weak-key-bar-wrap { flex: 1; height: 8px; background: var(--bg-tertiary); border-radius: 4px; overflow: hidden; }
.weak-key-bar { height: 100%; background: var(--incorrect); border-radius: 4px; }
.weak-key-count { font-size: 0.75rem; color: var(--text-dim); font-family: var(--font-mono); min-width: 4.375rem; text-align: right; }

.custom-text-section { margin: 1.25rem 0; display: flex; flex-direction: column; gap: 0.75rem; }
#custom-text-input {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-family: var(--font-mono); font-size: 0.875rem;
  padding: 0.875rem; resize: vertical; min-height: 6.25rem;
  outline: none; width: 100%;
  transition: border-color var(--transition);
}
#custom-text-input:focus { border-color: var(--accent); }
#custom-text-input::placeholder { color: var(--text-muted); }

.dim-text { color: var(--text-dim); font-size: 0.875rem; padding: 0.5rem 0; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 1.25rem;
  animation: fadeOverlay 0.15s ease;
}
@keyframes fadeOverlay { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 1.5);
  width: 100%; max-width: 680px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
  animation: slideModal 0.18s cubic-bezier(0.34, 1.4, 0.64, 1);
}
@keyframes slideModal { from { opacity: 0; transform: translateY(-16px) scale(0.97); } to { opacity: 1; transform: none; } }

.modal-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
}
.modal-mode-title { display: flex; align-items: center; gap: 0.875rem; }
.modal-mode-icon { display: flex; align-items: center; color: var(--accent); }
.modal-mode-icon svg { width: 32px; height: 32px; }
.modal-mode-name { font-size: 1.25rem; font-weight: 700; color: var(--text); }
.modal-mode-desc { font-size: 0.8125rem; color: var(--text-dim); margin-top: 3px; }

.modal-close-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-dim); font-size: 1.25rem; line-height: 1;
  padding: 4px 8px; border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
  flex-shrink: 0;
}
.modal-close-btn:hover { color: var(--text); background: var(--bg-tertiary); }

.modal-body { padding: 1.25rem 1.5rem 1.5rem; display: flex; flex-direction: column; gap: 1.25rem; }
.modal-body .config-panel { margin-bottom: 0; }
.modal-body .config-row { justify-content: center; }
.modal-body .config-group { align-items: center; }
.modal-body .quick-stats { justify-content: center; }

.modal-actions { display: flex; flex-direction: column; align-items: center; gap: 0.625rem; flex-wrap: wrap; }
.modal-hint { font-size: 0.75rem; color: var(--text-muted); }
.modal-hint kbd {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 3px; padding: 1px 5px; font-family: var(--font-mono); font-size: 0.6875rem; color: var(--text-dim);
}

/* ===== Game Modes ===== */
.mode-selector-section { margin-bottom: 1.25rem; }
.mode-selector-section > .config-label {
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--text-dim);
  margin-bottom: 0.625rem; display: block;
}
.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: 0.625rem;
}
.mode-card {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.875rem;
  text-align: left; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px;
  transition: border-color var(--transition), background var(--transition);
  font-family: var(--font-ui);
}
.mode-card:hover { border-color: var(--accent); background: var(--bg-tertiary); }
.mode-card.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--bg-secondary) 70%, var(--accent) 30%);
  box-shadow: 0 0 0 1px var(--accent);
}
.mode-card-icon {
  display: flex; align-items: center; justify-content: flex-start;
  margin-bottom: 6px; color: var(--text-dim);
  transition: color var(--transition);
}
.mode-card-icon svg { width: 18px; height: 18px; flex-shrink: 0; }
.mode-card:hover .mode-card-icon { color: var(--accent); }
.mode-card.selected .mode-card-icon { color: var(--accent); }
.mode-card-label { font-size: 0.875rem; font-weight: 600; color: var(--text); }
.mode-card-desc { font-size: 0.75rem; color: var(--text-dim); line-height: 1.4; }
.mode-card-best {
  font-size: 0.6875rem; font-family: var(--font-mono);
  color: var(--correct); margin-top: 4px; font-weight: 600;
}
.mode-card.selected .mode-card-label { color: var(--accent); }

.mode-description {
  font-size: 0.8125rem; color: var(--text-dim);
  margin-top: 0.625rem; min-height: 1.125rem;
}

/* Mode badge in test header */
.mode-badge {
  font-size: 0.75rem; font-weight: 600;
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 20px; padding: 3px 10px;
  color: var(--accent); white-space: nowrap;
  display: inline-flex; align-items: center; gap: 5px;
}
.mode-badge svg { width: 13px; height: 13px; flex-shrink: 0; }

/* Locked config options */
.toggle-btn.locked {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* Health bar */
.health-wrap {
  display: flex; justify-content: center; align-items: center;
  padding: 6px 0 2px;
}
.health-hearts { display: flex; gap: 6px; }
.heart {
  font-size: 1.375rem; line-height: 1;
  transition: transform var(--transition), filter var(--transition);
}
.heart.alive { color: var(--incorrect); filter: drop-shadow(0 0 4px var(--incorrect)); }
.heart.dead  { color: var(--text-muted); filter: none; }

/* Stage banner (progressive mode) */
.stage-banner {
  text-align: center; font-size: 0.75rem; font-weight: 600;
  padding: 5px 12px; border-radius: var(--radius-sm);
  margin-bottom: 4px; transition: all 0.4s ease;
}
.stage-1 { background: color-mix(in srgb, var(--bg-tertiary) 80%, var(--correct) 20%);   color: var(--correct); }
.stage-2 { background: color-mix(in srgb, var(--bg-tertiary) 80%, var(--warning) 20%);   color: var(--warning); }
.stage-3 { background: color-mix(in srgb, var(--bg-tertiary) 80%, var(--incorrect) 20%); color: var(--incorrect); }

/* Combo display */
.combo-wrap {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; padding: 8px 0;
  font-family: var(--font-mono);
  transition: all var(--transition);
}
.combo-fire { font-size: 1.125rem; }
.combo-value {
  font-size: 1.75rem; font-weight: 700; color: var(--warning);
  min-width: 2.5rem; text-align: center; line-height: 1;
}
.combo-label { font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.combo-best { font-size: 0.75rem; color: var(--text-muted); }
.combo-wrap.combo-active .combo-value { color: var(--incorrect); text-shadow: 0 0 12px var(--incorrect); }
.combo-wrap.combo-active { animation: comboGlow 1s ease infinite alternate; }
@keyframes comboGlow { from { opacity: 0.8; } to { opacity: 1; } }

/* Mode-specific results */
.mode-specific-section { margin-bottom: 1.25rem; }
.mode-result-badge {
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--accent); margin-bottom: 0.625rem;
  display: flex; align-items: center; gap: 5px;
}
.mode-result-badge svg { width: 13px; height: 13px; flex-shrink: 0; }
.mode-result-cards { display: flex; gap: 0.625rem; flex-wrap: wrap; }
.mode-result-card {
  flex: 1; min-width: 5.5rem;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.875rem; text-align: center;
}
.mode-result-value {
  font-size: 1.625rem; font-weight: 700;
  font-family: var(--font-mono); color: var(--text); line-height: 1;
}
.mode-result-label { font-size: 0.75rem; color: var(--text-dim); margin-top: 5px; }
.mode-result-card.variant-fail .mode-result-value  { color: var(--incorrect); }
.mode-result-card.variant-success .mode-result-value { color: var(--correct); }
.mode-result-card.variant-streak .mode-result-value  { color: var(--warning); }
.mode-result-card.variant-grade .mode-result-value   { color: var(--accent); font-size: 2.25rem; }
.mode-result-card.variant-stage .mode-result-value   { color: var(--warning); }

.mode-cell { font-size: 0.8125rem; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border); }

/* ===== Responsive ===== */

/* Tablet */
@media (max-width: 768px) {
  .test-header { gap: 0.625rem; }
  .live-metrics { gap: 1rem; }
  .timer-section { max-width: 220px; }
  .modal { max-width: 560px; }
  .config-panel { padding: 1rem 1.125rem; }
  .results-title { font-size: 1.25rem; }
  .section-title { font-size: 1.25rem; }
}

/* Large phone / small tablet */
@media (max-width: 600px) {
  .test-header { flex-wrap: wrap; row-gap: 8px; }
  .timer-section { order: -1; flex: 1 1 100%; max-width: 100%; }
  .live-metrics { gap: 1.25rem; }

  .modal-body { padding: 1rem 1rem 1.25rem; gap: 1rem; }
  .modal-header { padding: 1rem 1rem 0.75rem; }
  .modal-mode-icon svg { width: 26px; height: 26px; }
  .modal-mode-name { font-size: 1.0625rem; }
  .modal-actions { flex-direction: column; align-items: center; gap: 0.625rem; }
  .modal-actions .btn-large { width: 100%; justify-content: center; }
}

/* Small phone */
@media (max-width: 480px) {
  #main-content { padding: 1rem 0.75rem 2.75rem; }

  .config-row { flex-direction: column; gap: 0.875rem; }
  .config-panel { padding: 0.875rem 0.875rem; gap: 0.875rem; }

  .results-metrics { gap: 0.5rem; }
  .result-metric.primary .result-value { font-size: 2.625rem; }
  .result-value { font-size: 1.625rem; }

  .text-display { font-size: 1.1rem; }
  .typing-area { padding: 1.125rem 1rem; }

  .quick-stats { gap: 0.5rem; }
  .stat-value { font-size: 1.5rem; }
  .stat-card.large .stat-value { font-size: 1.75rem; }

  .achievements-grid { grid-template-columns: repeat(auto-fill, minmax(6.25rem, 1fr)); }

  .metric-value { font-size: 1.5rem; }
  .timer-display { font-size: 1.25rem; }

  .mode-card { padding: 0.625rem 0.75rem; }

  .history-table th,
  .history-table td { padding: 0.5rem 0.625rem; font-size: 0.8125rem; }

  .results-actions { gap: 0.5rem; }
  .results-actions .btn { flex: 1 1 auto; justify-content: center; min-width: 0; }
}

/* Very small phone */
@media (max-width: 360px) {
  .main-nav { gap: 2px; }
  .nav-btn { padding: 5px 0.5rem; }
  .logo-mark { display: none; }

  .toggle-btn { font-size: 0.8125rem; padding: 6px 0.625rem; }

  .stat-value { font-size: 1.25rem; }
  .stat-card.large .stat-value { font-size: 1.5rem; }

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