:root {
  --bg: #0a0d14;
  --surface: #121620;
  --surface-raised: #1a202e;
  --surface-border: #242c3d;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.35);
  --accent-light: #60a5fa;
  --good: #10b981;
  --good-glow: rgba(16, 185, 129, 0.4);
  --bad: #ef4444;
  --bad-glow: rgba(239, 68, 68, 0.4);
  --warn: #f59e0b;
  --warn-glow: rgba(245, 158, 11, 0.4);
  --cyan: #06b6d4;

  --f0: #ec4899;
  --f1: #f97316;
  --f2: #eab308;
  --f3: #10b981;
  --f4: #06b6d4;
  --f5: #3b82f6;
  --f6: #8b5cf6;
  --f7: #d946ef;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', Consolas, Monaco, monospace;
}

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

body {
  background-color: var(--bg);
  color: var(--text-main);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  user-select: none;
}

/* ==================== ONEWORDLY MASTER HEADER ==================== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background-color: var(--surface);
  border-bottom: 1px solid var(--surface-border);
  flex-shrink: 0;
  z-index: 120;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
  padding: 4px 8px;
  margin: -4px -8px;
  border-radius: 10px;
  text-decoration: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.logo-group:hover {
  opacity: 0.88;
  transform: translateY(-1px);
}

.logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #3b82f6, #ec4899);
  color: #fff;
  border-radius: 9px;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.logo-text {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.logo-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.logo-badge {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 9999px;
  background-color: var(--surface-raised);
  color: var(--text-muted);
  border: 1px solid var(--surface-border);
}

.header-mode-nav {
  display: flex;
  align-items: center;
  background-color: #0b0e14;
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--surface-border);
  gap: 3px;
}

.mode-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

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

.mode-tab.active {
  background-color: var(--surface-raised);
  color: var(--text-main);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.tab-label-short {
  display: none;
}

/* ==================== TYPE TRAINER SUBNAV ==================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 28px;
  background-color: var(--bg);
  border-bottom: 1px solid var(--surface-border);
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.trainer-tagline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-accent {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.tagline-text {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-raised);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--surface-border);
}

.tabs button {
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tabs button:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.tabs button.active {
  color: #fff;
  background: var(--accent);
  box-shadow: 0 2px 10px var(--accent-glow);
}

.caps-warning {
  background: #7f1d1d;
  color: #fecaca;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: 1px solid #b91c1c;
  animation: pulse 1.5s infinite;
}

/* Layout */
main {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.hidden {
  display: none !important;
}

.view-head {
  margin-bottom: 4px;
}
.view-head h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.view-head p {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

/* Common Components */
kbd {
  font-family: var(--font-mono);
  background: var(--surface-raised);
  border: 1px solid var(--surface-border);
  box-shadow: 0 2px 0 var(--surface-border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.85em;
  color: var(--text-main);
  font-weight: 600;
}

.muted { color: var(--text-muted); }
.small { font-size: 0.82rem; }
.good { color: var(--good); }
.bad { color: var(--bad); }

.btn {
  background: var(--surface-raised);
  color: var(--text-main);
  border: 1px solid var(--surface-border);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:hover {
  background: #28303e;
  border-color: #444c56;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 2px 10px var(--accent-glow);
}
.btn.primary:hover {
  background: #7c3aed;
}
.btn.danger {
  background: #451a1a;
  border-color: #7f1d1d;
  color: #fca5a5;
}
.btn.danger:hover {
  background: #7f1d1d;
  color: #fff;
}
.btn.small {
  padding: 4px 10px;
  font-size: 0.78rem;
}

.seg {
  display: inline-flex;
  background: var(--surface-raised);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  padding: 2px;
}
.seg button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.seg button:hover {
  color: var(--text-main);
}
.seg button.active {
  background: var(--surface-border);
  color: var(--text-main);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.toggles {
  display: flex;
  align-items: center;
  gap: 16px;
  transition: opacity 0.2s ease;
}
.toggles.dim {
  opacity: 0.35;
  pointer-events: none;
}
.chk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.84rem;
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 500;
}
.chk input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

.focus-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 28px;
}
.focus-row.invisible {
  visibility: hidden;
}
.focus-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  background: var(--surface-raised);
  border: 1px solid var(--surface-border);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.chip small {
  color: var(--text-muted);
  font-weight: 400;
}
.chip.bad {
  border-color: #7f1d1d;
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
}

/* Typing Surface */
.typing-box {
  position: relative;
  background: #090d13;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 24px;
  min-height: 140px;
  overflow: hidden;
}

.ta {
  line-height: 38px;
  font-family: var(--font-mono);
  font-size: 1.35rem;
  height: 114px;
  overflow: hidden;
  position: relative;
  letter-spacing: -0.01em;
}

.typing-inner {
  transition: transform 0.15s cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: transform;
  word-break: break-word;
}

.ch {
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  transition: color 0.05s ease, background-color 0.05s ease;
  padding: 0 1px;
  position: relative;
}
.ch.sp {
  padding: 0 4px;
}
.ch.ok {
  color: var(--text-main);
}
.ch.fixed {
  color: var(--warn);
}
.ch.err {
  color: var(--bad);
  background: rgba(239, 68, 68, 0.2);
  border-radius: 3px;
}
.ch.cur {
  color: #fff;
  border-bottom-color: var(--accent);
  background: rgba(139, 92, 246, 0.2);
  border-radius: 3px;
  animation: cursorBlink 1s infinite alternate;
}
@keyframes cursorBlink {
  0% { border-bottom-color: var(--accent); }
  100% { border-bottom-color: transparent; }
}
.ch.flash {
  animation: flashRed 0.3s ease-out;
}
@keyframes flashRed {
  0% { background: rgba(239, 68, 68, 0.6); }
  100% { background: rgba(239, 68, 68, 0.2); }
}

/* Results Overlay inside Typing Box */
.result {
  position: absolute;
  inset: 0;
  background: rgba(9, 13, 19, 0.94);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px;
  text-align: center;
  z-index: 10;
}

.res-stats {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  justify-content: center;
}
.res-stats .stat b {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1;
}
.res-stats .stat span {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  display: block;
  margin-top: 4px;
}

.res-line {
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.pb-badge {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #000;
  font-weight: 800;
  font-size: 0.8rem;
  padding: 4px 14px;
  border-radius: 999px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  box-shadow: 0 2px 10px var(--warn-glow);
}

/* Live Stats Strip */
.live {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  padding: 8px 4px;
}
.live .stat {
  display: flex;
  flex-direction: column;
}
.live .stat b {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.1;
  font-family: var(--font-mono);
}
.live .stat span {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hint {
  margin-left: auto;
  font-size: 0.88rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.hint .finger {
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.82rem;
}
.hint .finger.f0 { color: var(--f0); background: rgba(236, 72, 153, 0.15); }
.hint .finger.f1 { color: var(--f1); background: rgba(249, 115, 22, 0.15); }
.hint .finger.f2 { color: var(--f2); background: rgba(234, 179, 8, 0.15); }
.hint .finger.f3 { color: var(--f3); background: rgba(16, 185, 129, 0.15); }
.hint .finger.f4 { color: var(--f4); background: rgba(6, 182, 212, 0.15); }
.hint .finger.f5 { color: var(--f5); background: rgba(59, 130, 246, 0.15); }
.hint .finger.f6 { color: var(--f6); background: rgba(139, 92, 246, 0.15); }
.hint .finger.f7 { color: var(--f7); background: rgba(217, 70, 239, 0.15); }

.tip {
  font-size: 0.82rem;
  color: var(--text-dim);
  text-align: center;
}

/* Timed Test View */
.test-head {
  display: flex;
  align-items: center;
  gap: 28px;
  flex-wrap: wrap;
}
.timer-big {
  font-size: 2.8rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--cyan);
  line-height: 1;
  min-width: 75px;
}
.pace {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 260px;
}
.pace-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.pace-row span {
  width: 40px;
}
.pace-row .bar {
  flex: 1;
  height: 6px;
  background: var(--surface-raised);
  border-radius: 999px;
  overflow: hidden;
}
.pace-row .bar i {
  display: block;
  height: 100%;
  border-radius: 999px;
  width: 0%;
  transition: width 0.15s ease;
}
.pace-row .bar i.you { background: var(--accent); }
.pace-row .bar i.ghost { background: var(--cyan); }
.pace-diff {
  font-size: 0.78rem;
  font-weight: 600;
  text-align: right;
}

/* Key Strike (Blackout) Game */
.strike-hud {
  justify-content: flex-start;
}
.lives {
  margin-left: auto;
  display: flex;
  gap: 4px;
}
.heart {
  color: #ef4444;
  font-size: 1.4rem;
  transition: all 0.2s ease;
}
.heart.lost {
  color: #3f3f46;
  opacity: 0.4;
  transform: scale(0.85);
}

.stage {
  position: relative;
  background: #06090e;
  border: 2px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 40px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  text-align: center;
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.stage.good {
  border-color: var(--good);
  box-shadow: 0 0 25px var(--good-glow);
}
.stage.bad {
  border-color: var(--bad);
  box-shadow: 0 0 25px var(--bad-glow);
}

.stage-char {
  font-size: 5rem;
  font-family: var(--font-mono);
  font-weight: 800;
  color: var(--text-main);
  line-height: 1;
  margin-bottom: 8px;
}
.stage-char.pop {
  animation: popKey 0.18s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes popKey {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.stage-char.count {
  color: var(--cyan);
}

.stage-sub {
  font-size: 1rem;
  color: var(--text-muted);
  min-height: 24px;
}

.stage-summary {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.timer-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 6px;
  background: var(--surface-raised);
}
.timer-bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.05s linear;
}

/* Live Race View */
.profile-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface-raised);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  margin-bottom: 6px;
  gap: 16px;
  flex-wrap: wrap;
}

.profile-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.avatar-select-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: #0d1117;
  border: 1px solid var(--surface-border);
  border-radius: 50%;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.avatar-select-wrap:hover {
  border-color: var(--accent);
}

.profile-avatar-badge {
  font-size: 1.5rem;
  line-height: 1;
}

.avatar-dropdown {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.profile-identity {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.name-edit-wrap input {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 2px 6px;
  width: 160px;
  transition: all 0.15s ease;
}
.name-edit-wrap input:hover {
  border-color: var(--surface-border);
  background: #0d1117;
}
.name-edit-wrap input:focus {
  border-color: var(--accent);
  background: #0d1117;
  outline: none;
}

.profile-stats {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}
.profile-stats b {
  color: var(--text-main);
}

.online-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  background: #0d1117;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--surface-border);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 8px var(--good-glow);
  display: inline-block;
  animation: pulse 2s infinite;
}

/* Matchmaking Grid */
.matchmaking-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.action-card {
  background: var(--surface-raised);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
}

.action-card.quick-match-card {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(139, 92, 246, 0.12) 0%, var(--surface-raised) 100%);
}

.action-card-info h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 4px;
}
.action-card-info p {
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.btn-group-row {
  display: flex;
  gap: 8px;
}
.btn-group-row .btn {
  flex: 1;
  padding: 8px 10px;
  font-size: 0.82rem;
}

.full-width {
  width: 100%;
}

.code-join-group {
  display: flex;
  align-items: stretch;
  gap: 8px;
  height: 38px;
}

.code-join-group .code-input {
  flex: 1;
  height: 38px;
  background: #0d1117;
  border: 1px solid var(--surface-border);
  color: var(--text-main);
  padding: 0 10px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 0.15em;
  text-align: center;
  font-size: 1rem;
}
.code-join-group .code-input:focus {
  border-color: var(--accent);
  outline: none;
}

.code-join-group .btn {
  height: 38px;
  padding: 0 18px;
}

.race-error {
  color: var(--bad);
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 18px;
}

/* Public Rooms Directory */
.lobby-browser {
  background: #0d1117;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lobby-browser-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.lobby-browser-head h3 {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.public-rooms-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 70px;
}

.lobby-room-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface-raised);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  gap: 12px;
}

.room-main-info {
  display: flex;
  align-items: center;
  gap: 12px;
}
.room-avatar {
  font-size: 1.5rem;
  line-height: 1;
}
.room-host {
  font-weight: 700;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 6px;
}
.room-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.status-badge.waiting {
  background: rgba(16, 185, 129, 0.15);
  color: var(--good);
  border: 1px solid rgba(16, 185, 129, 0.3);
}
.status-badge.racing {
  background: rgba(6, 182, 212, 0.15);
  color: var(--cyan);
  border: 1px solid rgba(6, 182, 212, 0.3);
}

.empty-lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 24px;
  color: var(--text-muted);
  text-align: center;
}

.room-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--surface-border);
}
.room-code {
  font-family: var(--font-mono);
  letter-spacing: 0.1em;
  color: var(--accent-light);
  font-size: 1.1rem;
}
.bot-wpm {
  background: var(--surface-raised);
  border: 1px solid var(--surface-border);
  color: var(--text-main);
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.82rem;
}

.lanes {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 10px 0;
}
.lane {
  display: grid;
  grid-template-columns: 140px 1fr 70px 30px;
  align-items: center;
  gap: 12px;
  background: var(--surface-raised);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--surface-border);
}
.lane.me {
  border-color: var(--accent);
  background: rgba(139, 92, 246, 0.08);
}
.lane-name {
  font-size: 0.88rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tag {
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-border);
  color: var(--text-muted);
  text-transform: uppercase;
}
.tag.you {
  background: var(--accent);
  color: #fff;
}
.button.x, button.x {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.track {
  position: relative;
  height: 14px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 999px;
  overflow: visible;
}
.runner {
  position: absolute;
  top: 50%;
  left: calc(var(--p, 0) * (100% - 22px));
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text-muted);
  color: #000;
  font-size: 0.72rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  transition: left 0.1s linear;
}
.lane.me .runner {
  background: var(--accent-light);
  box-shadow: 0 0 10px var(--accent-glow);
}
.lane.bot .runner {
  background: var(--cyan);
}
.lane-wpm {
  font-size: 0.82rem;
  font-family: var(--font-mono);
  text-align: right;
  color: var(--text-muted);
}
.place {
  font-size: 1.1rem;
  text-align: center;
}

.countdown {
  position: absolute;
  inset: 0;
  background: rgba(9, 13, 19, 0.9);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4.5rem;
  font-weight: 800;
  color: var(--cyan);
  font-family: var(--font-mono);
  z-index: 20;
  text-align: center;
  line-height: 1.3;
}
.countdown.go {
  color: var(--good);
  animation: pulse 0.5s ease-out;
}
.countdown.small {
  font-size: 1.1rem;
  font-family: var(--font-sans);
  color: var(--text-muted);
  font-weight: 500;
}

/* Insights Dashboard */
.insights {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card.wide {
  grid-column: 1 / -1;
}
.card h3 {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.heat-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.legend {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}
.legend i {
  display: inline-block;
  width: 90px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(to right, #10b981, #eab308, #ef4444);
}
.legend .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 3px;
}
.key-detail {
  font-family: var(--font-mono);
}
.kd-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ov-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.ov-grid .stat b {
  font-size: 1.6rem;
  font-weight: 800;
}
.ov-grid .stat span {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  display: block;
}

.mini {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.mini th, .mini td {
  padding: 6px 8px;
  text-align: left;
}
.mini th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  border-bottom: 1px solid var(--surface-border);
}
.mini td {
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.mini tr.me {
  background: rgba(139, 92, 246, 0.1);
}

.row-bar {
  display: grid;
  grid-template-columns: 140px 1fr 65px;
  align-items: center;
  gap: 10px;
  font-size: 0.84rem;
}
.row-bar .meter {
  height: 6px;
  background: var(--surface-raised);
  border-radius: 999px;
  overflow: hidden;
}
.row-bar .meter i {
  display: block;
  height: 100%;
  background: var(--bad);
  border-radius: 999px;
}

.chart {
  width: 100%;
  height: 180px;
  display: block;
}
.empty {
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 16px 0;
  text-align: center;
}
.reset-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

/* ========================================================
   ON-SCREEN KEYBOARD
   ======================================================== */
.kb-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  margin-top: auto;
}

.keyboard {
  width: 100%;
  max-width: 980px;
  background: #11151c;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

.kb-row {
  display: flex;
  gap: 6px;
  width: 100%;
}

.key {
  height: 48px;
  background: #1b212b;
  border: 1px solid #2d3543;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
  position: relative;
  transition: transform 0.05s ease, background-color 0.1s ease, border-color 0.1s ease, box-shadow 0.1s ease, opacity 0.25s ease, filter 0.25s ease;
  user-select: none;
  cursor: default;
}

.key .lbl {
  line-height: 1;
  pointer-events: none;
}
.key .lbl.top {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.key.special {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  background: #151a23;
}

/* Key States */
.key.down {
  transform: translateY(2px);
  background: #2b3342;
  border-color: #4b5563;
}

.key.target {
  border-color: var(--accent);
  background: rgba(139, 92, 246, 0.22);
  color: #fff;
  box-shadow: 0 0 14px var(--accent-glow), inset 0 0 8px var(--accent-glow);
  animation: pulseGlow 1.2s infinite alternate;
}
@keyframes pulseGlow {
  0% { box-shadow: 0 0 8px var(--accent-glow); }
  100% { box-shadow: 0 0 18px var(--accent-glow), inset 0 0 8px var(--accent-glow); }
}

.key.ok {
  background: rgba(16, 185, 129, 0.35) !important;
  border-color: var(--good) !important;
  color: #fff !important;
}

.key.bad {
  background: rgba(239, 68, 68, 0.45) !important;
  border-color: var(--bad) !important;
  color: #fff !important;
  animation: shake 0.2s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* Key Strike Game Reveal Classes */
.key.reveal-ok {
  background: var(--good) !important;
  border-color: var(--good) !important;
  color: #000 !important;
  box-shadow: 0 0 20px var(--good-glow);
  transform: scale(1.05);
}

.key.reveal-bad {
  background: var(--bad) !important;
  border-color: var(--bad) !important;
  color: #fff !important;
  box-shadow: 0 0 20px var(--bad-glow);
}

.key.reveal-want {
  background: var(--warn) !important;
  border-color: #fbbf24 !important;
  color: #000 !important;
  box-shadow: 0 0 24px var(--warn-glow);
  animation: bounceKey 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes bounceKey {
  0% { transform: scale(0.9); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* Finger Zones */
.keyboard.show-fingers .key[data-finger="0"] { border-bottom: 3px solid var(--f0); }
.keyboard.show-fingers .key[data-finger="1"] { border-bottom: 3px solid var(--f1); }
.keyboard.show-fingers .key[data-finger="2"] { border-bottom: 3px solid var(--f2); }
.keyboard.show-fingers .key[data-finger="3"] { border-bottom: 3px solid var(--f3); }
.keyboard.show-fingers .key[data-finger="4"] { border-bottom: 3px solid var(--f4); }
.keyboard.show-fingers .key[data-finger="5"] { border-bottom: 3px solid var(--f5); }
.keyboard.show-fingers .key[data-finger="6"] { border-bottom: 3px solid var(--f6); }
.keyboard.show-fingers .key[data-finger="7"] { border-bottom: 3px solid var(--f7); }

/* Heatmap Mode */
.keyboard[data-mode="heat"] .key.heat-known {
  /* color interpolate: 0 (green) -> 0.5 (yellow) -> 1 (red) */
  background: hsl(calc((1 - var(--heat, 0)) * 120), 75%, 20%);
  border-color: hsl(calc((1 - var(--heat, 0)) * 120), 80%, 40%);
  color: #fff;
}

/* Blank / Blackout Mode (for Key Strike Game) */
.keyboard[data-mode="blank"] .key {
  background: #090c10 !important;
  border-color: #171b22 !important;
  color: transparent !important;
  box-shadow: none !important;
}
.keyboard[data-mode="blank"] .key .lbl {
  opacity: 0 !important;
}
.keyboard[data-mode="blank"] .key.target {
  border-color: var(--accent) !important;
  background: rgba(139, 92, 246, 0.25) !important;
}
.keyboard[data-mode="blank"] .key.down {
  background: #1e2430 !important;
}
.keyboard[data-mode="blank"] .key.reveal-ok,
.keyboard[data-mode="blank"] .key.reveal-bad,
.keyboard[data-mode="blank"] .key.reveal-want {
  color: #000 !important;
}
.keyboard[data-mode="blank"] .key.reveal-ok .lbl,
.keyboard[data-mode="blank"] .key.reveal-bad .lbl,
.keyboard[data-mode="blank"] .key.reveal-want .lbl {
  opacity: 1 !important;
}

.kb-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 980px;
  padding: 0 4px;
}
.finger-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.74rem;
  color: var(--text-dim);
}
.finger-legend i {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
}
.finger-legend .f0 { background: var(--f0); }
.finger-legend .f1 { background: var(--f1); }
.finger-legend .f2 { background: var(--f2); }
.finger-legend .f3 { background: var(--f3); }
.finger-legend .f4 { background: var(--f4); }
.finger-legend .f5 { background: var(--f5); }
.finger-legend .f6 { background: var(--f6); }
.finger-legend .f7 { background: var(--f7); }

@media (max-width: 768px) {
  .app-header {
    padding: 10px 14px;
  }
  .tab-label-full {
    display: none;
  }
  .tab-label-short {
    display: inline;
  }
  .mode-tab {
    padding: 4px 7px;
    font-size: 0.74rem;
    gap: 4px;
  }
  .logo-group {
    gap: 8px;
  }
  .logo-icon {
    width: 30px;
    height: 30px;
  }
  .logo-title {
    font-size: 1.1rem;
  }
  .logo-badge {
    display: none;
  }
  .trainer-tagline {
    display: none;
  }
  .topbar {
    flex-direction: column;
    padding: 10px 12px;
  }
  .tabs {
    width: 100%;
    overflow-x: auto;
    justify-content: flex-start;
  }
  .tabs button {
    padding: 6px 12px;
    font-size: 0.8rem;
    white-space: nowrap;
  }
  .insights {
    grid-template-columns: 1fr;
  }
  .ov-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .matchmaking-grid {
    grid-template-columns: 1fr;
  }
  .profile-card {
    flex-direction: column;
    align-items: flex-start;
  }
  .key {
    height: 38px;
    font-size: 0.75rem;
  }
}
