:root {
  --bg: #f8fafc;
  --card-bg: #fff;
  --text: #1e293b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --correct: #16a34a;
  --incorrect: #ef4444;
  --current: #2563eb;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --radius: 16px;
}
[data-bs-theme="dark"] {
  --bg: #0f172a;
  --card-bg: #1e293b;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --border: #334155;
  --shadow: 0 1px 3px rgba(0,0,0,0.2);
}

body { background: var(--bg); color: var(--text); font-family: 'Inter', sans-serif; transition: background 0.3s, color 0.3s; min-height: 100vh; }
.navbar { background: var(--card-bg); box-shadow: var(--shadow); }
.navbar-brand { font-weight: 800; font-size: 1.2rem; }

.stats-bar {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px;
}
.stat-item {
  background: var(--card-bg); border-radius: var(--radius); padding: 16px;
  text-align: center; box-shadow: var(--shadow); border: 1px solid var(--border);
}
.stat-value { font-size: 1.6rem; font-weight: 800; font-family: 'JetBrains Mono', monospace; display: block; color: var(--text); }
.stat-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
#wpmDisplay { color: #2563eb; }
#accuracyDisplay { color: #16a34a; }

.text-card {
  background: var(--card-bg); border-radius: var(--radius); padding: 24px;
  box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 16px;
}
.text-display {
  font-family: 'JetBrains Mono', monospace; font-size: 1.15rem; line-height: 1.8;
  max-height: 180px; overflow-y: auto; padding: 8px; border-radius: 8px;
  user-select: none; cursor: default; word-wrap: break-word;
}
.text-display::-webkit-scrollbar { width: 4px; }
.text-display::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.char {
  padding: 2px 1px; border-radius: 2px; transition: all 0.05s;
}
.char.correct { color: var(--correct); }
.char.incorrect { color: var(--incorrect); background: rgba(239,68,68,0.15); text-decoration: underline; text-decoration-color: var(--incorrect); }
.char.current { background: var(--current); color: #fff; border-radius: 2px; animation: blink 0.8s infinite; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

.input-card {
  background: var(--card-bg); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 16px;
}
.input-wrapper textarea {
  background: var(--bg); border: 2px solid var(--border); border-radius: 12px;
  font-family: 'JetBrains Mono', monospace; font-size: 1rem; resize: none;
  transition: border-color 0.2s;
}
.input-wrapper textarea:focus { border-color: var(--current); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.input-wrapper textarea:disabled { opacity: 0.5; cursor: not-allowed; }

.keyboard-tips {
  background: var(--card-bg); border-radius: var(--radius); padding: 16px 20px;
  box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 20px;
}
.keyboard-tips kbd {
  background: var(--border); border: 1px solid var(--text-muted); border-radius: 4px;
  padding: 2px 6px; font-family: 'JetBrains Mono', monospace; font-size: 0.75rem;
  color: var(--text);
}
.kbd-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 12px; border-radius: 20px;
  background: var(--card-bg); border: 1px solid var(--border);
  color: var(--text); font-size: 0.85rem;
}

.history-card {
  background: var(--card-bg); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.history-table { width: 100%; font-size: 0.85rem; }
.history-table th { color: var(--text-muted); font-weight: 600; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.5px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.history-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.history-table tr:last-child td { border-bottom: none; }
.history-table .badge { font-size: 0.7rem; }
.hist-wpm { font-weight: 700; color: var(--current); }
.hist-accuracy { font-weight: 600; }
.hist-time { color: var(--text-muted); font-family: 'JetBrains Mono', monospace; }
.hist-date { color: var(--text-muted); font-size: 0.8rem; }

.result-icon { animation: pulse 1s ease infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.1); } }
.result-stat { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.result-value { font-size: 1.5rem; font-weight: 800; font-family: 'JetBrains Mono', monospace; }
.result-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.modal-content { background: var(--card-bg); color: var(--text); border: 1px solid var(--border); }
.modal-header, .modal-footer { border-color: var(--border); }

@media (max-width: 576px) {
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 1.2rem; }
  .text-display { font-size: 1rem; max-height: 140px; }
}

.mode-switcher { margin: 0 12px; }
.mode-switcher .btn { border-radius: 25px !important; padding: 0.55rem 1.5rem; font-size: 1rem; font-weight: 600; }
.mode-tab.active { cursor: default; }

.ad-slot {
  background: var(--card-bg);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  user-select: none;
  flex-direction: column;
  gap: 4px;
}
.ad-slot-full { margin: 20px 0; min-height: 100px; }
.ad-slot .ad-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.4;
}
.ad-slot .ad-placeholder { font-size: 0.85rem; opacity: 0.5; }
.ad-slot-inline { margin-top: 16px; min-height: 80px; }
@media (max-width: 768px) {
  .ad-slot-full { margin: 14px 0; }
  .ad-slot { min-height: 70px; padding: 14px; }
}
@media print {
  .ad-slot { display: none !important; }
}
