/**
 * WPMType - Typing Engine Stylesheet
 * High precision, zero-lag character styling, caret animation, and results screen.
 */

/* ===================================================
   TYPING TEST WRAPPER & CONTROLS
   =================================================== */
.typing-test-container {
  width: min(94vw, 1250px);
  max-width: 1250px;
  margin: 1.5rem auto 3rem auto;
  position: relative;
  scroll-margin-top: 85px;
}

/* Controls Toolbar (Language, Difficulty, Duration) */
.test-controls-bar {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 0.65rem 1.25rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 40;
  overflow: visible;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.control-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-right: 0.4rem;
}

/* Control Pills / Buttons */
.ctrl-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-size: 0.825rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.ctrl-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.ctrl-btn.active {
  background: var(--bg-elevated);
  color: var(--accent-cyan);
  border-color: rgba(0, 240, 255, 0.35);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.15);
}

/* Separator between control groups */
.ctrl-divider {
  width: 1px;
  height: 24px;
  background: var(--border-subtle);
  margin: 0 0.5rem;
}

/* ===================================================
   SELECTED TEST CONFIGURATION BADGES (READ-ONLY)
   =================================================== */
.test-config-badges {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.85rem;
  margin-bottom: 1.25rem;
}

.config-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.config-pill .pill-icon {
  font-size: 0.9rem;
}

.config-pill strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* ===================================================
   LIVE STATS HUD
   =================================================== */
.typing-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.5rem 1rem 0.5rem;
  margin-bottom: 0.25rem;
}

.hud-timer-wrap {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.hud-timer {
  font-family: var(--font-mono);
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--accent-cyan);
  line-height: 1;
  text-shadow: 0 0 16px var(--accent-cyan-glow);
}

.hud-timer-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
}

.hud-metrics {
  display: flex;
  align-items: center;
  gap: 1.75rem;
}

.hud-stat-item {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

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

.hud-stat-name {
  font-size: 0.725rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.05em;
}

/* ===================================================
   TYPING WORDS DISPLAY BOX
   =================================================== */
.typing-area-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: clamp(2rem, 3.5vw, 3.25rem);
  min-height: 280px;
  position: relative;
  box-shadow: var(--shadow-md);
  cursor: text;
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
  user-select: none;
  -webkit-user-select: none;
  scroll-margin-top: 100px;
}

.typing-area-card:focus-within,
.typing-area-card.focused {
  border-color: rgba(0, 240, 255, 0.4);
  box-shadow: var(--shadow-md), 0 0 25px rgba(0, 240, 255, 0.12);
}

/* Container for all words with generous height (~200px-240px) */
.words-container {
  height: 260px;
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: clamp(32px, 3.3vw, 44px);
  font-weight: 650;
  line-height: 2.15;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  position: relative;
  white-space: normal;
  word-break: break-word;
}

/* Individual Word & Char Elements */
.word {
  display: inline-block;
  margin-right: 0.8em;
  margin-bottom: 0.15em;
  position: relative;
  vertical-align: baseline;
}

.word.error {
  border-bottom: none;
}

.char {
  display: inline-block;
  vertical-align: baseline;
  color: var(--text-dim);
  transition: color 0.04s linear;
  position: relative;
  line-height: inherit;
}

/* Correct Character: clear, bold, high-contrast bright text */
.char.correct {
  color: #f8fafc;
  font-weight: 700;
}

/* Incorrect Character: prominent crimson red with subtle background tint */
.char.incorrect {
  color: #f87171;
  background: rgba(239, 68, 68, 0.28);
  border-radius: 3px;
  font-weight: 700;
}

/* Extra Character typed by user */
.char.extra {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.38);
  border-radius: 3px;
  font-weight: 700;
  opacity: 0.95;
}

/* Current Active Character: clean cyan highlight + Inline Animated Caret */
.char.current {
  color: var(--accent-cyan);
  text-decoration: none;
  text-shadow: 0 0 12px var(--accent-cyan-glow);
  position: relative;
}

.char.incorrect.current {
  color: #f87171;
  background: rgba(239, 68, 68, 0.28);
  border-radius: 3px;
}

/* Active Caret: sits immediately BEFORE the current character */
.char.current::before {
  content: '';
  position: absolute;
  left: -2.5px;
  top: 10%;
  height: 80%;
  width: 3.5px;
  background: var(--accent-cyan);
  border-radius: 2px;
  box-shadow: 0 0 10px var(--accent-cyan);
  animation: caret-blink 1s ease-in-out infinite;
  pointer-events: none;
  z-index: 2;
}

/* When the word is fully typed, caret sits immediately AFTER the last character */
.char.current-end {
  position: relative;
}

.char.current-end::after {
  content: '';
  position: absolute;
  right: -2.5px;
  top: 10%;
  height: 80%;
  width: 3.5px;
  background: var(--accent-cyan);
  border-radius: 2px;
  box-shadow: 0 0 10px var(--accent-cyan);
  animation: caret-blink 1s ease-in-out infinite;
  pointer-events: none;
  z-index: 2;
}

/* RTL cursor placement */
.words-container.rtl .char.current::before {
  left: auto;
  right: -2.5px;
}

.words-container.rtl .char.current-end::after {
  right: auto;
  left: -2.5px;
}

/* Start Typing Subtle Hint */
.start-typing-hint {
  position: absolute;
  top: 14px;
  right: 20px;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  opacity: 1;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  pointer-events: none;
  user-select: none;
  background: var(--bg-secondary);
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  z-index: 6;
}

.start-typing-hint.hidden {
  opacity: 0;
  visibility: hidden;
}

.hint-pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 8px var(--accent-cyan);
  animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 0.3; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.15); }
}

[dir="rtl"] .start-typing-hint {
  right: auto;
  left: 20px;
}

@keyframes caret-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Obsolete top-level caret completely removed & hidden */
.typing-caret {
  display: none !important;
}

/* Hidden Capture Input */
.typing-hidden-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  z-index: 5;
  cursor: text;
  border: none;
  outline: none;
  background: transparent;
  color: transparent;
  font-size: 16px; /* Prevents auto-zoom on iOS Safari */
}

/* Overlay prompt when unfocused */
.focus-prompt-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: var(--text-primary);
  font-size: 1.05rem;
  font-weight: 600;
  z-index: 20;
  cursor: pointer;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.focus-prompt-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.focus-prompt-icon {
  color: var(--accent-cyan);
  font-size: 1.35rem;
  animation: pulse-ring 2s infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

/* Bottom Action Bar (Restart, Passage switch, Finish early in Free Hand) */
.test-actions-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 1.25rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.test-hint {
  font-size: 0.825rem;
  color: var(--text-muted);
}

.test-actions-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.action-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 1.15rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: all var(--transition-fast);
}

.action-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.action-btn.btn-finish-freehand {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.4);
  color: var(--accent-emerald);
}

.action-btn.btn-finish-freehand:hover {
  background: var(--accent-emerald);
  color: #ffffff;
}

/* ===================================================
   RESULT MODAL SCREEN
   =================================================== */
.result-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1.5rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.result-modal-backdrop.show {
  opacity: 1;
  visibility: visible;
}

.result-modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  max-width: 880px;
  width: min(92vw, 880px);
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem 2rem;
  box-shadow: var(--shadow-lg), 0 0 25px rgba(0, 0, 0, 0.08);
  transform: translateY(16px) scale(0.98);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  text-align: center;
  position: relative;
  margin: auto;
}

.result-modal-backdrop.show .result-modal-card {
  transform: translateY(0) scale(1);
}

/* Result Modal Close Button (Top-Right) */
.result-modal-close-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  z-index: 10;
  padding: 0;
  outline: none;
}

.result-modal-close-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--text-primary);
  border-color: var(--border-hover);
  transform: scale(1.05);
}

.result-modal-close-btn:active {
  transform: scale(0.96);
}

.result-modal-close-btn:focus-visible {
  outline: 2px solid var(--accent-cyan);
  outline-offset: 2px;
}

[dir="rtl"] .result-modal-close-btn {
  right: auto;
  left: 1rem;
}

.result-badge-tier {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.85rem;
  border-radius: var(--radius-full);
  font-weight: 700;
  font-size: 0.8rem;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tier-gold-style {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #d97706;
}

.tier-platinum-style {
  background: rgba(2, 132, 199, 0.12);
  border: 1px solid rgba(2, 132, 199, 0.35);
  color: #0284c7;
}

.tier-silver-style {
  background: rgba(148, 163, 184, 0.15);
  border: 1px solid rgba(148, 163, 184, 0.35);
  color: #64748b;
}

.tier-bronze-style {
  background: rgba(217, 119, 6, 0.12);
  border: 1px solid rgba(217, 119, 6, 0.35);
  color: #b45309;
}

/* Typist & Guest ID Bar - Compact */
.result-typist-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.45rem 0.85rem;
  margin: 0.4rem 0 0.75rem 0;
  text-align: left;
}

.typist-profile-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.typist-avatar-icon {
  font-size: 1.2rem;
  line-height: 1;
  flex-shrink: 0;
}

.typist-name-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-width: 0;
}

.typist-name-val {
  font-weight: 700;
  font-size: 0.925rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.typist-guest-badge {
  font-family: var(--font-mono);
  font-size: 0.725rem;
  color: #0284c7;
  background: #e0f2fe;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  border: 1px solid #bae6fd;
  display: inline-block;
  white-space: nowrap;
}

.btn-copy-guest-id {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.775rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-copy-guest-id:hover {
  background: var(--bg-elevated);
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

/* WPM Number & Label - Compact & Prominent */
.result-hero-metric {
  margin: 0.4rem 0 0.85rem 0;
}

.result-wpm-number {
  font-family: var(--font-mono);
  font-size: clamp(64px, 6.5vw, 76px);
  font-weight: 850;
  line-height: 1;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.result-wpm-label {
  font-size: 0.95rem; /* ~15px */
  font-weight: 700;
  color: var(--accent-cyan);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 0.2rem;
}

/* Secondary stats grid - Compact 3x2 on desktop */
.result-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem 0.85rem;
  margin-bottom: 0.85rem;
  background: var(--bg-secondary);
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.res-stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.3rem 0.25rem;
}

.res-stat-val {
  font-family: var(--font-mono);
  font-size: clamp(20px, 2.2vw, 24px);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.15;
}

.res-stat-name {
  font-size: 0.75rem; /* 12px */
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-top: 0.15rem;
}

/* Standard sized result buttons */
.result-buttons-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-top: 0.4rem;
}

.result-buttons-row .btn {
  min-height: 42px;
  height: 44px;
  padding: 0.5rem 1.25rem;
  font-size: 0.925rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border-radius: var(--radius-full);
}

/* ===================================================
   RESPONSIVE ADJUSTMENTS
   =================================================== */
@media (max-width: 768px) {
  .test-controls-bar {
    flex-direction: column;
    align-items: stretch;
    padding: 0.85rem 1rem;
    gap: 0.75rem;
  }

  .ctrl-divider {
    display: none;
  }

  .control-group {
    width: 100%;
    margin-bottom: 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .font-control-group {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
  }

  .font-dropdown-menu {
    left: 0;
    right: auto;
    width: 100%;
    max-width: 100%;
  }

  .words-container {
    font-size: clamp(28px, 3.5vw, 36px);
    line-height: 2.1;
    height: 230px;
  }

  .typing-area-card {
    padding: clamp(1.5rem, 3vw, 2.25rem);
    min-height: 250px;
  }

  .result-modal-card {
    max-width: calc(100% - 32px);
    width: calc(100% - 32px);
    padding: 1.25rem 1.25rem;
  }

  .result-wpm-number {
    font-size: clamp(56px, 7vw, 68px);
  }

  .result-stats-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    padding: 0.65rem 0.5rem;
  }
}

@media (max-width: 480px) {
  .test-controls-bar {
    padding: 0.75rem 0.85rem;
    gap: 0.65rem;
  }

  .ctrl-btn {
    padding: 0.25rem 0.55rem;
    font-size: 0.775rem;
  }

  .control-label {
    font-size: 0.7rem;
    min-width: 65px;
  }

  .font-select-btn {
    padding: 0.3rem 0.7rem;
    font-size: 0.775rem;
    max-width: 100%;
  }

  .font-select-wrap {
    max-width: calc(100% - 75px);
  }

  #current-font-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .hud-metrics {
    gap: 0.75rem;
  }

  .hud-stat-value {
    font-size: 1.1rem;
  }

  .hud-timer {
    font-size: 1.75rem;
  }

  .words-container {
    font-size: clamp(22px, 5.5vw, 30px);
    line-height: 2.0;
    height: 200px;
  }

  .typing-area-card {
    padding: 1.25rem 0.85rem;
    min-height: 220px;
  }

  .result-modal-backdrop {
    padding: 0.5rem;
  }

  .result-modal-card {
    width: calc(100% - 24px);
    max-width: calc(100% - 24px);
    padding: 1.15rem 0.85rem;
    border-radius: var(--radius-lg);
  }

  .result-modal-close-btn {
    top: 0.65rem;
    right: 0.65rem;
    width: 30px;
    height: 30px;
  }

  [dir="rtl"] .result-modal-close-btn {
    right: auto;
    left: 0.65rem;
  }

  .result-typist-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
    padding: 0.45rem 0.65rem;
  }

  .typist-profile-info {
    justify-content: space-between;
  }

  .btn-copy-guest-id {
    justify-content: center;
    width: 100%;
  }

  .result-wpm-number {
    font-size: clamp(48px, 12vw, 58px);
  }

  .result-wpm-label {
    font-size: 0.875rem;
  }

  .result-stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.45rem;
    padding: 0.55rem 0.4rem;
  }

  .res-stat-val {
    font-size: 1.2rem;
  }

  .res-stat-name {
    font-size: 0.7rem;
  }

  .result-buttons-row {
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
  }

  .result-buttons-row .btn {
    width: 100%;
    height: 46px;
    min-height: 46px;
  }
}

/* ===================================================
   CURATED TYPING FONT SCOPING
   Font styles apply STRICTLY to #words-container
   =================================================== */
#words-container {
  font-family: var(--typing-font, "JetBrains Mono", monospace);
}

.font-control-group {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.font-select-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.font-select-btn {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-full);
  font-size: 0.825rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  outline: none;
  line-height: 1.2;
  transition: all var(--transition-fast);
}

.font-select-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.font-select-btn.open,
.font-select-btn[aria-expanded="true"] {
  border-color: var(--accent-cyan);
  color: var(--text-primary);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.15);
}

.font-btn-chevron {
  transition: transform var(--transition-fast);
  color: var(--text-muted);
  flex-shrink: 0;
}

.font-select-btn.open .font-btn-chevron,
.font-select-btn[aria-expanded="true"] .font-btn-chevron {
  transform: rotate(180deg);
  color: var(--accent-cyan);
}

.font-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  min-width: 220px;
  max-width: 300px;
  max-height: 280px;
  overflow-y: auto;
  padding: 0.35rem;
  display: none;
  z-index: 250;
}

.font-dropdown-menu.show {
  display: block !important;
}

.font-option-item {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: background var(--transition-fast);
  margin-bottom: 2px;
}

.font-option-item:hover,
.font-option-item.active {
  background: var(--bg-elevated);
}

.font-option-item.active .font-option-name {
  color: var(--accent-cyan);
}

.font-option-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.font-option-preview {
  font-size: 0.775rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===================================================
   RTL TYPING ENGINE RULES
   =================================================== */
.words-container.rtl {
  direction: rtl;
  text-align: right;
}

.words-container.rtl .word {
  margin-right: 0;
  margin-left: 0.65em;
}

/* ===================================================
   PRE-TEST USER SETUP MODAL
   =================================================== */
.setup-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.setup-modal-backdrop.active {
  opacity: 1;
  visibility: visible;
}

.setup-modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 2.25rem;
  max-width: 540px;
  width: 100%;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  transform: translateY(20px) scale(0.96);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  max-height: 92vh;
  overflow-y: auto;
}

.setup-modal-backdrop.active .setup-modal-card {
  transform: translateY(0) scale(1);
}

.setup-modal-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.setup-modal-icon {
  font-size: 2.2rem;
  margin-bottom: 0.35rem;
  line-height: 1;
}

.setup-modal-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 0.4rem;
}

.setup-modal-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.setup-form-group {
  margin-bottom: 1.15rem;
}

.setup-form-label {
  display: block;
  font-size: 0.775rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.45rem;
}

.label-optional {
  font-weight: 500;
  color: var(--text-muted);
  text-transform: none;
  font-size: 0.75rem;
}

.setup-hint-text {
  color: var(--text-muted);
  font-size: 0.775rem;
  display: block;
  margin-top: 0.35rem;
}

.setup-select-wrap {
  position: relative;
  width: 100%;
}

.setup-form-input,
.setup-form-select {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.95rem;
  font-size: 0.925rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.setup-form-input:focus,
.setup-form-select:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px rgba(0, 240, 255, 0.15);
}

/* Setup Pills (Difficulty and Duration) */
.setup-pills-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.setup-durations-grid {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.setup-pill-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
  outline: none;
  user-select: none;
  line-height: 1.2;
}

.setup-pill-btn:hover {
  background: var(--bg-elevated);
  border-color: var(--accent-cyan);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.setup-pill-btn.active {
  background: linear-gradient(135deg, #0284c7 0%, #2563eb 100%);
  color: #ffffff !important;
  border-color: #0284c7;
  box-shadow: 0 3px 10px rgba(2, 132, 199, 0.35);
  font-weight: 700;
}

.setup-pill-btn.pill-freehand {
  font-weight: 700;
}

.setup-modal-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.75rem;
}

.setup-modal-actions .btn {
  flex: 1;
  padding: 0.75rem 1rem;
}

/* Result modal leaderboard status - Compact */
.result-leaderboard-notice {
  margin: 0.5rem 0 0.85rem 0;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-md);
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.25);
  font-size: 0.875rem;
  color: #065f46;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

/* ===================================================
   LIGHT MODE CONTRAST PASS - TYPING ENGINE
   =================================================== */
[data-theme="light"] .words-container {
  color: #94a3b8;
}

[data-theme="light"] .char {
  color: #94a3b8;
}

[data-theme="light"] .char.correct {
  color: #0f172a;
  font-weight: 700;
}

[data-theme="light"] .char.incorrect {
  color: #dc2626;
  background: rgba(220, 38, 38, 0.16);
  border-radius: 3px;
  font-weight: 700;
}

[data-theme="light"] .char.extra {
  color: #b91c1c;
  background: rgba(220, 38, 38, 0.24);
  border-radius: 3px;
  font-weight: 700;
}

[data-theme="light"] .char.current {
  color: #0284c7;
  text-decoration: none;
  text-shadow: none;
}

[data-theme="light"] .char.incorrect.current {
  color: #dc2626;
  background: rgba(220, 38, 38, 0.16);
  border-radius: 3px;
}

[data-theme="light"] .char.current::before,
[data-theme="light"] .char.current-end::after {
  background: #0284c7;
  box-shadow: 0 0 8px rgba(2, 132, 199, 0.45);
}

[data-theme="light"] .start-typing-hint {
  color: #64748b;
}

[data-theme="light"] .test-controls-bar {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .typing-area-card {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .ctrl-btn {
  color: #475569;
}

[data-theme="light"] .ctrl-btn:hover {
  background: rgba(0, 0, 0, 0.04);
  color: #0f172a;
}

[data-theme="light"] .ctrl-btn.active {
  background: #e0f2fe;
  color: #0284c7;
  border-color: #bae6fd;
  box-shadow: 0 0 10px rgba(2, 132, 199, 0.15);
}

[data-theme="light"] .hud-stat-value {
  color: #0f172a;
}

[data-theme="light"] .hud-timer {
  color: #0284c7;
  text-shadow: none;
}

[data-theme="light"] .setup-modal-card,
[data-theme="light"] .result-card {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.08);
  color: #0f172a;
}

[data-theme="light"] .setup-form-input,
[data-theme="light"] .setup-form-select {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #0f172a;
}

[data-theme="light"] .setup-pill-btn {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #475569;
}

[data-theme="light"] .setup-pill-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
  border-color: #94a3b8;
}

[data-theme="light"] .setup-pill-btn.active {
  background: linear-gradient(135deg, #0284c7 0%, #2563eb 100%);
  color: #ffffff !important;
  border-color: #0284c7;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.3);
}

[data-theme="light"] .result-stat-val {
  color: #0f172a;
}

[data-theme="light"] .result-leaderboard-notice {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
  color: #065f46;
}

[data-theme="light"] .result-modal-card {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .result-modal-close-btn {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #475569;
}

[data-theme="light"] .result-modal-close-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
  border-color: #94a3b8;
}

[data-theme="light"] .result-modal-close-btn:focus-visible {
  outline: 2px solid #0284c7;
}

[data-theme="light"] .result-wpm-number {
  color: #0f172a;
  text-shadow: none;
}

[data-theme="light"] .result-wpm-label {
  color: #0284c7;
}

[data-theme="light"] .result-stats-grid {
  background: #f8fafc;
  border-color: #e2e8f0;
}

[data-theme="light"] .result-typist-bar {
  background: #f8fafc;
  border-color: #e2e8f0;
}

[data-theme="light"] .btn-copy-guest-id {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #334155;
}

[data-theme="light"] .btn-copy-guest-id:hover {
  background: #f1f5f9;
  border-color: #0284c7;
  color: #0284c7;
}

[data-theme="light"] .font-select-btn {
  background: #f8fafc;
  border-color: rgba(0, 0, 0, 0.12);
  color: #334155;
}

[data-theme="light"] .font-select-btn:hover {
  background: #ffffff;
  border-color: rgba(2, 132, 199, 0.4);
  color: #0f172a;
}

[data-theme="light"] .font-select-btn.open,
[data-theme="light"] .font-select-btn[aria-expanded="true"] {
  border-color: #0284c7;
  color: #0284c7;
  box-shadow: 0 0 10px rgba(2, 132, 199, 0.15);
}

[data-theme="light"] .font-dropdown-menu {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.12);
  color: #0f172a;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .font-option-item:hover,
[data-theme="light"] .font-option-item.active {
  background: #f1f5f9;
}

[data-theme="light"] .font-option-item.active .font-option-name {
  color: #0284c7;
}

[data-theme="light"] .font-option-name {
  color: #0f172a;
}

[data-theme="light"] .font-option-preview {
  color: #64748b;
}
