/* ==========================================================================
   Speed Type Arena & DOM Engine Styles
   Precision, high-legibility, distraction-free typing engine
   ========================================================================== */

.st-app {
  width: 100%;
}

/* Arena Top Controls & Status */
.st-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.st-back {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color var(--trans-fast);
}

.st-back:hover {
  color: #ffffff;
}

.st-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.st-title-wrap h1 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  color: #ffffff;
  margin: 0;
}

.st-status {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.st-status.is-idle {
  background: rgba(148, 163, 184, 0.1);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.st-status.is-live {
  background: rgba(16, 185, 129, 0.12);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.st-status.is-paused {
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.st-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.st-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--trans-fast);
}

.st-icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.st-icon-btn svg {
  width: 18px;
  height: 18px;
}

/* Dashboard HUD Stats */
.st-hero {
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-md);
}

.st-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

@media (max-width: 600px) {
  .st-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
}

.st-stat {
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 16px;
}

.st-k {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.st-v {
  font-family: var(--font-mono);
  font-size: clamp(1.4rem, 2.8vw, 1.9rem);
  font-weight: 700;
  color: #ffffff;
  line-height: 1.1;
}

/* Progress Bar */
.st-progress-wrap {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-pill);
  overflow: hidden;
  position: relative;
  margin-bottom: 16px;
}

.st-progress-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  background: var(--grad-primary);
  border-radius: var(--radius-pill);
  transition: width 0.25s linear;
}

/* Duration Selector Bar */
.st-controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.st-duration-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.st-dur-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-right: 6px;
}

.st-dur-btn {
  padding: 5px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--trans-fast);
}

.st-dur-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.st-dur-btn.is-active {
  background: rgba(99, 102, 241, 0.25);
  border-color: var(--accent-primary);
  color: #ffffff;
}

.st-restart-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--trans-fast);
}

.st-restart-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

/* ==========================================================================
   Typing Board Arena & Word Stream
   ========================================================================== */
.st-arena {
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  padding: 28px;
  position: relative;
  box-shadow: var(--shadow-lg);
  min-height: 220px;
  cursor: text;
  margin-bottom: 24px;
}

.st-input-catcher {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  z-index: 2;
  cursor: default;
  font-size: 16px; /* Prevents auto-zoom on iOS */
  border: none;
  background: transparent;
}

.st-board {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 10px 14px;
  max-height: 160px;
  overflow-y: hidden;
  position: relative;
  font-family: var(--font-body);
  font-size: clamp(1.25rem, 2.5vw, 1.6rem);
  line-height: 1.5;
  user-select: none;
  -webkit-user-select: none;
}

/* Word States */
.st-word {
  display: inline-flex;
  align-items: baseline;
  padding: 2px 6px;
  border-radius: 6px;
  position: relative;
  transition: background 0.15s ease, opacity 0.15s ease;
  color: var(--text-muted);
}

.word-active {
  background: rgba(99, 102, 241, 0.18);
  border: 1px solid rgba(99, 102, 241, 0.35);
  color: #ffffff;
}

.word-next {
  color: var(--text-secondary);
}

.word-correct {
  color: rgba(255, 255, 255, 0.28);
}

.word-error {
  color: rgba(244, 63, 94, 0.65);
  border-bottom: 2px solid #f43f5e;
}

/* Character States */
.st-char {
  position: relative;
}

.char-correct {
  color: #ffffff;
}

.char-incorrect {
  color: #f43f5e;
  background: rgba(244, 63, 94, 0.15);
  border-radius: 2px;
}

.char-extra {
  color: #f87171;
  background: rgba(239, 68, 68, 0.25);
  border-radius: 2px;
}

.char-current-target {
  color: #ffffff;
}

/* Caret */
.st-caret {
  position: absolute;
  width: 2.5px;
  background: var(--accent-cyan);
  border-radius: 2px;
  box-shadow: 0 0 8px rgba(6, 182, 212, 0.8);
  pointer-events: none;
  z-index: 5;
  transition: left 0.08s linear, top 0.08s linear;
  animation: caretBlink 1s infinite ease-in-out;
}

@keyframes caretBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Focus Recovery Warning */
.st-focus-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 18, 0.85);
  backdrop-filter: blur(4px);
  z-index: 10;
  border-radius: var(--radius-lg);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
}

.st-focus-overlay.is-visible {
  display: flex;
}

.st-focus-text {
  font-size: 0.95rem;
  font-weight: 600;
  color: #ffffff;
}

/* ==========================================================================
   Results Modal Dialog
   ========================================================================== */
.st-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(8px);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.st-modal-backdrop.is-open {
  display: flex;
}

.st-modal {
  width: 100%;
  max-width: 520px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
}

.st-modal-tier {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 4px 14px;
  border-radius: var(--radius-pill);
  margin-bottom: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tier-master { background: rgba(239, 68, 68, 0.15); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.4); }
.tier-advanced { background: rgba(99, 102, 241, 0.15); color: #818cf8; border: 1px solid rgba(99, 102, 241, 0.4); }
.tier-intermediate { background: rgba(6, 182, 212, 0.15); color: #38bdf8; border: 1px solid rgba(6, 182, 212, 0.4); }
.tier-beginner { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.4); }

.st-modal-wpm-hero {
  font-family: var(--font-mono);
  font-size: 3.6rem;
  font-weight: 800;
  line-height: 1;
  color: #ffffff;
  margin-bottom: 4px;
}

.st-modal-wpm-lbl {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 24px;
}

.st-modal-metrics {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 28px;
}

.st-modal-metric {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 8px;
}

.st-modal-metric-val {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: #ffffff;
}

.st-modal-metric-lbl {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.st-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.st-btn-try-again {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--grad-primary);
  color: #ffffff;
  font-size: 0.95rem;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.16);
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
}

.st-btn-try-again:hover {
  filter: brightness(1.08);
}

.st-btn-secondary {
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.st-btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}
