/**
 * Speed Type — AAA Professional Typing Speed Test Styling
 * Fluid responsive typography, glassmorphism, animated caret, and mobile virtual keyboard support.
 */

body.page-speed {
  --bg-dark: #07040d;
  --surface: rgba(18, 12, 34, 0.72);
  --surface-hover: rgba(28, 18, 52, 0.85);
  --surface-solid: #130d24;
  --border: rgba(168, 85, 247, 0.22);
  --border-soft: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(255, 45, 154, 0.4);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #645c7e;
  --text-pending: #585072;
  
  --pink: #ff2d9a;
  --pink-glow: rgba(255, 45, 154, 0.6);
  --violet: #9b30ff;
  --cyan: #00f0ff;
  --live-green: #34d399;
  --error-red: #ef4444;
  
  --font-display: "Outfit", "Sora", system-ui, -apple-system, sans-serif;
  --font-body: "Karla", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;

  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--text-main);
  background-color: var(--bg-dark);
  background-image:
    radial-gradient(ellipse 900px 500px at 15% -10%, rgba(255, 45, 154, 0.14), transparent 60%),
    radial-gradient(ellipse 800px 500px at 85% 10%, rgba(155, 48, 255, 0.12), transparent 55%),
    radial-gradient(ellipse 600px 400px at 50% 90%, rgba(0, 240, 255, 0.08), transparent 60%);
  background-attachment: fixed;
  overflow-x: hidden;
}

body.page-speed *,
body.page-speed *::before,
body.page-speed *::after {
  box-sizing: border-box;
}

/* App Container */
.st-app {
  max-width: 960px;
  margin: 0 auto;
  padding: 86px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 100vh;
}

@media (min-width: 1280px) {
  .st-app {
    max-width: min(960px, calc(100vw - 420px));
  }
}

/* Top Header Bar */
.st-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(14, 10, 26, 0.65);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  backdrop-filter: blur(16px);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.st-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s ease, transform 0.15s ease;
}

.st-back:hover {
  color: #fff;
  transform: translateX(-2px);
}

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

.st-title-wrap h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff 40%, #c084fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.st-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-soft);
  color: var(--text-dim);
}

.st-status .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
}

.st-status.is-live {
  color: var(--live-green);
  background: rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.35);
}

.st-status.is-live .dot {
  background: var(--live-green);
  box-shadow: 0 0 10px var(--live-green);
  animation: st-dot-pulse 1.6s infinite ease-in-out;
}

.st-status.is-done {
  color: #c084fc;
  background: rgba(192, 132, 252, 0.12);
  border-color: rgba(192, 132, 252, 0.35);
}

.st-status.is-done .dot {
  background: #c084fc;
}

@keyframes st-dot-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.6; }
}

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

.st-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.st-icon-btn:hover {
  color: #fff;
  background: rgba(168, 85, 247, 0.15);
  border-color: rgba(168, 85, 247, 0.4);
}

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

.st-icon-btn.is-off {
  opacity: 0.5;
  color: var(--text-dim);
}

/* Stats Dashboard */
.st-hero {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.st-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border-soft);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  backdrop-filter: blur(20px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

.st-stat {
  background: var(--surface);
  padding: 16px 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: background 0.2s ease;
}

.st-stat:hover {
  background: var(--surface-hover);
}

.st-stat .st-k {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.st-stat .st-v {
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.st-stat:first-child .st-v {
  background: linear-gradient(135deg, var(--pink), #c084fc, #60a5fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Progress Bar */
.st-progress-wrap {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 999px;
  overflow: hidden;
}

.st-progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--pink), var(--violet), var(--cyan));
  box-shadow: 0 0 12px var(--pink-glow);
  transition: width 0.3s linear;
}

/* Mode Switcher Pills */
.st-modes {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(14, 10, 26, 0.65);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 4px;
  width: fit-content;
  margin: 0 auto;
}

.st-pill {
  min-width: 58px;
  min-height: 36px;
  padding: 6px 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.st-pill:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
}

.st-pill.is-active {
  color: #fff;
  background: linear-gradient(135deg, var(--pink), var(--violet));
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: 0 4px 18px var(--pink-glow);
}

/* Typing Arena */
.st-board {
  position: relative;
  background: rgba(14, 10, 28, 0.75);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 32px 28px;
  min-height: 220px;
  max-height: 280px;
  overflow: hidden;
  backdrop-filter: blur(24px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  cursor: text;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.st-board:focus-within {
  border-color: rgba(168, 85, 247, 0.5);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6), 0 0 24px rgba(168, 85, 247, 0.2);
}

/* Input Catcher (Transparent overlay over board so mobile keyboard triggers instantly) */
.st-input-catcher {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  z-index: 5;
  cursor: text;
  border: none;
  background: transparent;
  color: transparent;
  outline: none;
  font-size: 16px; /* Prevents auto-zoom on iOS */
  padding: 0;
  margin: 0;
}

/* Word Stream */
.st-words {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 10px 14px;
  font-family: var(--font-mono);
  font-size: clamp(1.2rem, 2.3vw, 1.55rem);
  line-height: 1.8;
  letter-spacing: 0.02em;
  user-select: none;
  pointer-events: none;
}

.st-word {
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  padding: 1px 6px;
  margin: -1px -6px;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

/* Completed words (clean finished state) */
.st-word.word-correct .st-char {
  color: #736b8e;
  text-shadow: none;
}

.st-word.word-error {
  border-bottom: 2px solid rgba(239, 68, 68, 0.7);
  background: rgba(239, 68, 68, 0.08);
}

.st-word.word-error .st-char.char-correct {
  color: #9b90b5;
}

/* ACTIVE TARGET WORD FOCUS — Highlights the exact target capsule */
.st-word.word-active {
  background: rgba(168, 85, 247, 0.14);
  border: 1px solid rgba(168, 85, 247, 0.45);
  box-shadow: 0 0 16px rgba(168, 85, 247, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  position: relative;
}

.st-word.word-active .st-char.char-pending {
  color: #c4b5fd; /* Distinct high-contrast readable violet-white */
}

/* Next Upcoming Word (Queue Preview) */
.st-word.word-next .st-char {
  color: #8c82a8; /* Slightly brighter than distant words to guide eye */
  transition: color 0.15s ease;
}

/* Distant upcoming pending words */
.st-char {
  display: inline-block;
  transition: color 0.1s ease, text-shadow 0.1s ease;
}

.st-char.char-pending {
  color: var(--text-pending); /* #585072 */
}

/* Correctly typed characters in current word */
.st-char.char-correct {
  color: #ffffff;
  font-weight: 600;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

/* Immediate active character targeted under the caret */
.st-char.char-current-target {
  color: #ffffff;
  font-weight: 700;
  text-shadow: 0 0 10px rgba(255, 45, 154, 0.8), 0 0 18px rgba(168, 85, 247, 0.5);
}

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

.st-char.char-extra {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.32);
  border-radius: 2px;
  opacity: 0.95;
}

/* Animated Neon Caret */
.st-caret {
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  background: linear-gradient(180deg, #ff2d9a, #c084fc);
  border-radius: 3px;
  box-shadow: 0 0 10px #ff2d9a, 0 0 20px rgba(255, 45, 154, 0.8), 0 0 30px rgba(168, 85, 247, 0.5);
  pointer-events: none;
  z-index: 10;
  transition: transform 0.075s cubic-bezier(0.2, 0.9, 0.3, 1.0);
  animation: st-caret-glow 1.0s ease-in-out infinite alternate;
}

@keyframes st-caret-glow {
  0% {
    opacity: 0.85;
    box-shadow: 0 0 8px #ff2d9a, 0 0 16px rgba(255, 45, 154, 0.6);
  }
  100% {
    opacity: 1;
    box-shadow: 0 0 14px #ff2d9a, 0 0 26px rgba(255, 45, 154, 0.9), 0 0 36px rgba(168, 85, 247, 0.6);
  }
}

/* Focus Lost Overlay */
.st-focus-overlay {
  position: absolute;
  inset: 0;
  background: rgba(7, 4, 15, 0.82);
  backdrop-filter: blur(10px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 25;
  border-radius: 20px;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

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

.st-focus-msg {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 24px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.st-focus-icon {
  font-size: 1.2rem;
}

/* Bottom Footer Bar */
.st-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-top: 4px;
}

.st-shortcut-tip {
  font-size: 0.86rem;
  color: var(--text-dim);
}

.st-shortcut-tip kbd {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
}

.st-restart {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 18px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.st-restart:hover {
  color: #fff;
  background: rgba(168, 85, 247, 0.15);
  border-color: rgba(168, 85, 247, 0.5);
  transform: translateY(-1px);
  box-shadow: 0 4px 18px rgba(168, 85, 247, 0.25);
}

/* Detailed Results Modal */
.st-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 2, 10, 0.82);
  backdrop-filter: blur(16px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

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

.st-modal-card {
  width: min(520px, 100%);
  background: linear-gradient(165deg, rgba(26, 16, 48, 0.96), rgba(12, 8, 24, 0.98));
  border: 1px solid rgba(168, 85, 247, 0.4);
  border-radius: 24px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.8), 0 0 32px rgba(168, 85, 247, 0.2);
  animation: st-modal-pop 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes st-modal-pop {
  from { opacity: 0; transform: scale(0.92) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.st-res-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.st-res-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 800;
  color: #fff;
}

.st-res-tier {
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
}

.tier-master { color: #ff2d9a; border-color: rgba(255, 45, 154, 0.4); background: rgba(255, 45, 154, 0.12); }
.tier-advanced { color: #38bdf8; border-color: rgba(56, 189, 248, 0.4); background: rgba(56, 189, 248, 0.12); }
.tier-intermediate { color: #facc15; border-color: rgba(250, 204, 21, 0.4); background: rgba(250, 204, 21, 0.12); }
.tier-beginner { color: #a3e635; border-color: rgba(163, 230, 53, 0.4); background: rgba(163, 230, 53, 0.12); }

/* Hero WPM Box */
.st-res-hero {
  text-align: center;
  padding: 18px 0;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
}

.st-res-wpm-num {
  display: block;
  font-family: var(--font-display);
  font-size: 4.2rem;
  font-weight: 900;
  line-height: 1;
  background: linear-gradient(135deg, #ffffff 20%, var(--pink) 70%, var(--violet) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.st-res-wpm-label {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: 6px;
  display: block;
}

/* Breakdown Grid */
.st-res-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.st-res-cell {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.st-res-k {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.st-res-v {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-main);
}

.st-res-chars {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--text-muted);
}

/* Action Buttons */
.st-res-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}

.st-res-actions .btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--pink), var(--violet));
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.96rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px var(--pink-glow);
  transition: all 0.2s ease;
}

.st-res-actions .btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px var(--pink-glow);
}

.st-res-actions .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 11px;
  border-radius: 12px;
  background: transparent;
  border: 1px solid var(--border-soft);
  color: var(--text-muted);
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.st-res-actions .btn-ghost:hover {
  color: #fff;
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.04);
}

/* ================================================================
   RESPONSIVE MOBILE RULES
   ================================================================ */
@media (max-width: 640px) {
  .st-app {
    padding: 72px 14px 32px;
    gap: 16px;
  }

  .st-top {
    padding: 10px 14px;
  }

  .st-title-wrap h1 {
    font-size: 1.1rem;
  }

  .st-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .st-stat {
    padding: 12px 8px;
  }

  .st-stat .st-v {
    font-size: 1.35rem;
  }

  .st-board {
    padding: 20px 16px 16px;
    min-height: 180px;
    max-height: 240px;
  }

  .st-words {
    font-size: 1.15rem;
    line-height: 1.65;
    gap: 6px 10px;
  }

  .st-res-wpm-num {
    font-size: 3.2rem;
  }

  .st-res-grid {
    grid-template-columns: 1fr;
  }
}
