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

:root,
[data-theme="dark"] {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #232340;
  --accent: #6c63ff;
  --accent-hover: #5a52e0;
  --text: #e8e8f0;
  --text-dim: #6b6b8d;
  --correct: #4ade80;
  --incorrect: #ef4444;
  --current: #fbbf24;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --border: #2a2a45;
  --locked: #2a2a40;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --font-sans: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --transition: 0.2s ease;
}

[data-theme="light"] {
  --bg: #f5f5fa;
  --surface: #ffffff;
  --surface2: #e8e8f0;
  --accent: #6c63ff;
  --accent-hover: #5a52e0;
  --text: #1a1a2e;
  --text-dim: #8888aa;
  --correct: #22c55e;
  --incorrect: #ef4444;
  --current: #f59e0b;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --border: #d0d0e0;
  --locked: #d0d0e0;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
}

[data-theme="matrix"] {
  --bg: #000000;
  --surface: #0a1a0a;
  --surface2: #0f2a0f;
  --accent: #00ff41;
  --accent-hover: #00cc33;
  --text: #00ff41;
  --text-dim: #005a1a;
  --correct: #00ff41;
  --incorrect: #ff0033;
  --current: #ffff00;
  --danger: #ff0033;
  --danger-hover: #cc0022;
  --border: #003300;
  --locked: #001a00;
  --shadow: 0 0 20px rgba(0, 255, 65, 0.15);
}

[data-theme="ocean"] {
  --bg: #0a1628;
  --surface: #0f1f3a;
  --surface2: #162a4a;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --text: #e0f2fe;
  --text-dim: #5f8ab0;
  --correct: #2dd4bf;
  --incorrect: #fb7185;
  --current: #fbbf24;
  --danger: #fb7185;
  --danger-hover: #f43f5e;
  --border: #1e3a5f;
  --locked: #0f2440;
  --shadow: 0 4px 24px rgba(56, 189, 248, 0.1);
}

[data-theme="retro"] {
  --bg: #1a140e;
  --surface: #2a1f14;
  --surface2: #3a2a1a;
  --accent: #ff9832;
  --accent-hover: #e07f20;
  --text: #ffd8a8;
  --text-dim: #8a6a4a;
  --correct: #8bc34a;
  --incorrect: #ff5252;
  --current: #ffd740;
  --danger: #ff5252;
  --danger-hover: #d32f2f;
  --border: #4a3520;
  --locked: #2a1f14;
  --shadow: 0 4px 24px rgba(255, 152, 50, 0.1);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  transition: background 0.3s, color 0.3s;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  line-height: 1.6;
}

#app {
  width: 100%;
  max-width: 960px;
  padding: 20px;
  margin: 0 auto;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 12px;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 110px;
}

.stat-icon {
  font-size: 1.2rem;
  opacity: 0.6;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text);
  line-height: 1.3;
}

.stat-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1.2;
}

.target-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.lang-select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  min-width: 90px;
}

.lang-select:focus {
  border-color: var(--accent);
}

.lang-select option {
  background: var(--surface2);
  color: var(--text);
}

.target-item {
  color: var(--text);
  font-weight: 500;
}

.target-item span {
  color: var(--accent);
  font-weight: 700;
  font-family: var(--font-mono);
}

.target-sep {
  opacity: 0.3;
}

.main-layout {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.content-area {
  flex: 1;
  min-width: 0;
}

.side-panel {
  width: 200px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 16px;
}

.side-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.side-card-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.side-card-sub {
  font-size: 0.8rem;
  text-transform: none;
  color: var(--text-dim);
  letter-spacing: 0;
}

.side-card-sub strong {
  color: var(--accent);
  font-family: var(--font-mono);
}

.last-result-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lr-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}

.lr-icon {
  font-size: 0.9rem;
  opacity: 0.6;
  width: 18px;
  text-align: center;
}

.lr-value {
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text);
  font-size: 0.95rem;
}

.lr-delta {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  font-weight: 600;
  margin-left: auto;
}

.lr-delta.up { color: var(--correct); }
.lr-delta.down { color: var(--incorrect); }
.lr-delta.neutral { color: var(--text-dim); }

.lr-empty {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-align: center;
  padding: 8px 0;
}

.next-letter-hint {
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

.nl-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--accent);
  color: #fff;
  border-radius: 5px;
  font-weight: 700;
  font-size: 0.8rem;
  font-family: var(--font-mono);
}

.practice-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.text-display {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  line-height: 2;
  letter-spacing: 0.05em;
  word-break: normal;
  overflow-wrap: normal;
  min-height: 3.2em;
  margin-bottom: 16px;
  user-select: none;
  cursor: default;
}

.text-display span {
  transition: color var(--transition), background var(--transition);
  border-radius: 2px;
  padding: 1px 0;
}

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

.text-display .char-incorrect {
  color: var(--incorrect);
  background: rgba(239, 68, 68, 0.15);
  border-radius: 3px;
}

.text-display .char-current {
  color: var(--text);
  background: rgba(108, 99, 255, 0.25);
  border-radius: 3px;
  padding: 1px 4px;
  margin: 0 -2px;
  animation: pulse 1.2s ease-in-out infinite;
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.progress-bar-container {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #a78bfa);
  border-radius: 2px;
  width: 0%;
  transition: width 0.3s ease;
}

.hint {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-top: 12px;
  min-height: 1.4em;
}

.letters-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.letters-grid.compact {
  gap: 2px;
}

.letters-grid.compact .letter-tile {
  width: 24px;
  height: 24px;
  font-size: 0.65rem;
  border-width: 1px;
}

.letter-tile {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
  border: 2px solid transparent;
}

.letter-tile.unlocked {
  background: var(--accent);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.1);
}

.letter-tile.locked {
  background: var(--locked);
  color: var(--text-dim);
  opacity: 0.4;
  border-color: var(--border);
}

.letter-tile.current-stage {
  border-color: var(--current);
  box-shadow: 0 0 12px rgba(251, 191, 36, 0.2);
  background: var(--surface2);
  color: var(--current);
  opacity: 1;
}

.keyboard-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.keyboard-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-dim);
  cursor: pointer;
  margin-bottom: 8px;
  user-select: none;
}

.keyboard-section.hidden .keyboard {
  display: none;
}
.keyboard-section.hidden {
  padding: 8px 16px;
}

.key-press-counter {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 8px;
  padding: 6px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
}

.key-press-counter .kpc-label {
  font-weight: 600;
}

.key-press-counter .kpc-value {
  color: var(--accent);
  font-weight: 700;
}

.key-press-counter .kpc-lang {
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
}

.key-presses-by-lang {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.key-presses-title {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-weight: 600;
}

.key-press-lang-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.key-press-lang-row:last-child {
  border-bottom: none;
}

.key-press-lang-row .kl-name {
  color: var(--text);
}

.key-press-lang-row .kl-value {
  color: var(--accent);
  font-weight: 700;
  font-family: var(--font-mono);
}

.keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.keyboard-row {
  display: flex;
  gap: 4px;
}

.key {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 500;
  background: var(--surface2);
  border: 1px solid var(--border);
  transition: all var(--transition);
  user-select: none;
}

.key.unlocked {
  color: var(--text);
  border-color: rgba(108, 99, 255, 0.3);
}

.key.unlocked.current-key {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  transform: scale(1.05);
  box-shadow: 0 0 16px rgba(108, 99, 255, 0.3);
}

.key.locked {
  color: var(--text-dim);
  opacity: 0.3;
  background: transparent;
}

.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

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

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(108, 99, 255, 0.3);
}

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

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

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--danger);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 40px;
  text-align: center;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  animation: modalIn 0.25s ease;
}

@keyframes modalIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal h2 {
  font-size: 1.5rem;
  margin-bottom: 12px;
}

.modal#modal h2 {
  background: linear-gradient(135deg, var(--correct), #4ade80);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.modal p {
  color: var(--text-dim);
  margin-bottom: 24px;
  line-height: 1.7;
  font-size: 0.95rem;
}

.modal-settings {
  text-align: left;
  max-width: 460px;
}

.modal-settings h2 {
  background: none;
  -webkit-background-clip: unset;
  background-clip: unset;
  color: var(--text);
  margin-bottom: 20px;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 24px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
}

.setting-row input {
  width: 80px;
  padding: 8px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  outline: none;
  transition: border var(--transition);
}

.setting-row input:focus {
  border-color: var(--accent);
}

.setting-row input::-webkit-inner-spin-button {
  opacity: 0.5;
}

.settings-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.modal-stats {
  text-align: left;
  max-width: 400px;
}
.modal-stats.modal-lb {
  max-width: 680px;
}

.modal-stats h2 {
  background: none;
  -webkit-background-clip: unset;
  background-clip: unset;
  color: var(--text);
  margin-bottom: 20px;
  font-size: 1.3rem;
}

.modal-stats .btn {
  margin-top: 8px;
}

.stats-table {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 16px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--surface2);
  font-size: 0.9rem;
}

.stats-row:nth-child(even) {
  background: var(--surface);
}

.stats-row span:first-child {
  color: var(--text-dim);
}

.stats-row span:last-child {
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent);
}

.stats-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.stats-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.stat-tab {
  flex: 1;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-xs);
  transition: all 0.2s;
}

.stat-tab:hover {
  color: var(--text);
}

.stat-tab.active {
  background: var(--accent);
  color: #fff;
}

.stats-content {
  position: relative;
  min-height: 200px;
}

.stat-panel {
  display: none;
}

.stat-panel.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.history-list {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.history-item:last-child {
  border-bottom: none;
}

.history-item.failed {
  opacity: 0.7;
}

.history-date {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  white-space: nowrap;
}

.history-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  text-align: right;
  margin: 0 16px;
}

.history-speed {
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-mono);
}

.history-accuracy {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.history-met {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  font-size: 0.7rem;
  font-weight: 600;
}

.history-met.success {
  background: rgba(74, 222, 128, 0.2);
  color: var(--correct);
}

.history-met.fail {
  background: rgba(239, 68, 68, 0.2);
  color: var(--incorrect);
}

.chart-row {
  margin-bottom: 20px;
}

.chart-row canvas {
  width: 100%;
  height: 200px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.modal-stats {
  max-width: 500px;
}

.stat-panel-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 20px;
  font-size: 0.9rem;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.2s, background 0.2s;
}
.modal-close:hover {
  color: var(--text);
  background: var(--surface2);
}

.hidden { display: none !important; }

.user-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  max-height: 300px;
  overflow-y: auto;
}

.user-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.user-entry-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.user-entry .btn { padding: 6px 14px; font-size: 0.8rem; }

/* User area */
.user-area {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px auto;
}
.user-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.user-name {
  font-size: 0.85rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}
.btn-small {
  padding: 4px 12px;
  font-size: 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  font-family: inherit;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn-accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-accent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* Auth overlay */
.modal-auth {
  max-width: 420px;
  text-align: center;
  padding: 32px 28px;
}
.auth-subtitle {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 24px;
  line-height: 1.4;
}
.auth-phrase-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
  padding: 16px;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--surface2);
}
.auth-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--surface2);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  resize: vertical;
}
.auth-input:focus {
  border-color: var(--accent);
}
.auth-phrase {
  min-height: 56px;
  line-height: 1.4;
}
.auth-phrase-actions {
  display: flex;
  gap: 8px;
}
.auth-phrase-actions .btn {
  flex: 1;
}
.auth-error {
  color: #f87171;
  font-size: 0.85rem;
  padding: 8px 12px;
  background: rgba(248,113,113,0.1);
  border-radius: 6px;
}

/* Leaderboard */
.leaderboard-content {
  max-height: 400px;
  overflow-y: auto;
  overflow-x: auto;
  margin: 16px 0;
  border-radius: 8px;
  background: var(--bg);
  -webkit-overflow-scrolling: touch;
}
.lb-table {
  width: 100%;
  min-width: 580px;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.lb-row {
  display: grid;
  grid-template-columns: 40px 1fr 80px 90px 80px 36px;
  padding: 10px 16px;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--surface);
}
.lb-row:last-child {
  border-bottom: none;
}
.lb-header {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  position: sticky;
  top: 0;
  background: var(--bg);
  border-bottom: 2px solid var(--surface2);
}
.lb-rank {
  text-align: center;
  font-weight: 600;
  font-size: 0.95rem;
}
.lb-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-lang {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-align: center;
}
.lb-speed {
  text-align: right;
  font-weight: 600;
  color: var(--accent);
}
.lb-acc {
  text-align: right;
  color: var(--correct);
}
.lb-diff {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.75rem;
  width: 30px;
}
.lb-top {
  background: rgba(108,99,255,0.06);
}
.lb-top-1 .lb-rank { font-size: 1.2rem; }
.lb-top-2 .lb-rank { font-size: 1.1rem; }
.lb-top-3 .lb-rank { font-size: 1rem; }
.leaderboard-empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-dim);
  font-size: 0.95rem;
}

@media (max-width: 850px) {
  .main-layout { flex-direction: column; }
  .side-panel { width: 100%; flex-direction: row; flex-wrap: wrap; position: static; }
  .side-card { flex: 1; min-width: 180px; }
}

@media (max-width: 700px) {
  #app { padding: 12px; }
  header { flex-direction: column; align-items: stretch; text-align: center; }
  .stats { justify-content: center; }
  .stat { min-width: 90px; padding: 6px 10px; }
  .stat-value { font-size: 0.95rem; }
  .stat-icon { font-size: 1rem; }
  .text-display { font-size: 1.1rem; padding: 0; }
  .practice-area { padding: 16px; }
  .key { width: 36px; height: 36px; font-size: 0.7rem; }
  .keyboard-section { padding: 10px; }
  .keyboard-row { gap: 3px; }
  .letter-tile { width: 32px; height: 32px; font-size: 0.85rem; }
  .controls { flex-wrap: wrap; }
  .btn { flex: 1; min-width: 100px; padding: 10px 14px; font-size: 0.85rem; }
  .target-bar { font-size: 0.75rem; gap: 6px; padding: 6px 12px; flex-wrap: wrap; }
  .lang-select { font-size: 0.7rem; min-width: 70px; padding: 3px 6px; }
  .modal { padding: 24px; }
  .modal-settings { max-width: 320px; }
}

@media (max-width: 480px) {
  .stat { min-width: 75px; padding: 5px 8px; }
  .stat-value { font-size: 0.85rem; }
  .text-display { font-size: 0.95rem; line-height: 1.8; }
  .key { width: 28px; height: 32px; font-size: 0.6rem; }
  .keyboard-row { gap: 2px; }
  .keyboard { gap: 2px; }
  .letter-tile { width: 28px; height: 28px; font-size: 0.75rem; }
  .modal { padding: 20px; }
  .setting-row input { width: 60px; }
}

.scale-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  max-width: 180px;
}

.scale-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

.scale-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--accent);
}

.theme-select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  cursor: pointer;
}
.theme-select:focus {
  border-color: var(--accent);
}

.scale-label {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text);
  min-width: 40px;
  text-align: right;
}

.mode-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.mode-toggle:hover {
  border-color: var(--accent);
  color: var(--text);
}

.mode-toggle.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.modal-suggestions {
  max-width: 640px;
  text-align: left;
}
.modal-suggestions h2 {
  background: none;
  -webkit-background-clip: unset;
  background-clip: unset;
  color: var(--text);
  font-size: 1.3rem;
  margin: 0;
}
.suggestions-content {
  max-height: 450px;
  overflow-y: auto;
  margin: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.suggestion-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  transition: border-color 0.2s;
}
.suggestion-card:hover {
  border-color: var(--accent);
}
.suggestion-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 6px;
}
.suggestion-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  word-break: break-word;
}
.suggestion-author {
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: nowrap;
}
.suggestion-desc {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 10px;
  line-height: 1.4;
  word-break: break-word;
}
.suggestion-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.suggestion-vote-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.suggestion-vote-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.suggestion-vote-btn.voted {
  background: rgba(108,99,255,0.15);
  border-color: var(--accent);
  color: var(--accent);
}
.suggestion-comment-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 2px 6px;
  font-family: inherit;
  transition: color 0.2s;
}
.suggestion-comment-toggle:hover {
  color: var(--text);
}
.suggestion-comments {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.suggestion-comments.hidden {
  display: none;
}
.comment-item {
  font-size: 0.8rem;
  padding: 8px 10px;
  background: var(--surface);
  border-radius: 6px;
  border: 1px solid var(--border);
}
.comment-author {
  font-weight: 600;
  color: var(--accent);
  margin-right: 6px;
}
.comment-text {
  color: var(--text);
}
.comment-date {
  display: block;
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-top: 4px;
}
.comment-form {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}
.comment-form input {
  flex: 1;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.8rem;
  font-family: inherit;
  outline: none;
}
.comment-form input:focus {
  border-color: var(--accent);
}
.comment-form .btn {
  padding: 6px 14px;
  font-size: 0.8rem;
}

.app-version {
  position: fixed;
  bottom: 6px;
  right: 10px;
  font-size: 0.7rem;
  opacity: 0.3;
  color: var(--text);
  pointer-events: none;
}
.site-footer {
  position: fixed;
  bottom: 6px;
  left: 10px;
  font-size: 0.7rem;
  opacity: 0.45;
  color: var(--text-dim);
  pointer-events: none;
  z-index: 1000;
}









.btn-sm {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text-dim);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.btn-sm:hover {
  border-color: var(--accent);
  color: var(--text);
}
.btn-sm.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Speed test panel */
.speedtest-panel {
  margin-top: 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 12px;
}
.speedtest-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.speedtest-header h3 {
  font-size: 1rem;
  color: var(--text);
}
.speedtest-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.speedtest-row label {
  color: var(--text-dim);
  font-size: 0.85rem;
}
.speedtest-row select,
.speedtest-row textarea {
  background: var(--surface2);
  border: 1px solid transparent;
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.85rem;
}
.speedtest-row select:focus,
.speedtest-row textarea:focus {
  border-color: var(--accent);
  outline: none;
}
.speedtest-custom-text {
  width: 100%;
  margin-bottom: 10px;
  background: var(--surface2);
  border: 1px solid transparent;
  color: var(--text);
  padding: 8px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.85rem;
  resize: vertical;
}
.speedtest-custom-text:focus {
  border-color: var(--accent);
  outline: none;
}
.speedtest-stats {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: var(--text-dim);
}
.speedtest-stats span {
  background: var(--surface2);
  padding: 4px 10px;
  border-radius: 6px;
}
.speedtest-stats strong {
  color: var(--accent);
}
.speedtest-text {
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.1rem;
  line-height: 1.6;
  padding: 12px;
  word-break: break-word;
  color: var(--text-dim);
  user-select: none;
  transition: transform 0.12s ease;
}
.speedtest-scroll-wrap {
  background: var(--surface2);
  border-radius: 8px;
  margin-bottom: 10px;
  height: calc(3 * 1.6em + 24px);
  overflow: hidden;
  position: relative;
}
.speedtest-text .st-correct {
  color: var(--correct);
}
.speedtest-text .st-incorrect {
  color: var(--incorrect);
  background: rgba(239,68,68,0.2);
  border-radius: 2px;
}
.speedtest-text .st-current {
  background: var(--accent);
  color: #fff;
  border-radius: 2px;
}
.speedtest-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--text);
  font-family: 'Courier New', Courier, monospace;
  font-size: 1rem;
  outline: none;
  margin-bottom: 10px;
  resize: none;
  box-sizing: border-box;
  min-height: 60px;
}
.speedtest-input:focus {
  box-shadow: 0 0 0 2px rgba(108,99,255,0.3);
}
.speedtest-result-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 1rem;
  color: var(--text);
}
.speedtest-result-stats strong {
  color: var(--accent);
  font-size: 1.2rem;
}



