/* ============================================================
   TypeForge — Vercel-Inspired Design System
   Based on peaceful-planet/DESIGN.md (Vercel design language)
   ============================================================ */

/* ---------- Design Tokens (Vercel) ---------- */
:root {
  /* Canvas surfaces */
  --canvas: #ffffff;
  --canvas-soft: #fafafa;
  --canvas-soft-2: #f5f5f5;

  /* Text */
  --ink: #171717;
  --body: #4d4d4d;
  --mute: #888888;
  --on-primary: #ffffff;

  /* Borders */
  --hairline: #ebebeb;
  --hairline-strong: #a1a1a1;

  /* Brand */
  --primary: #171717;
  --link: #0070f3;
  --link-deep: #0761d1;
  --success: #0070f3;
  --error: #ee0000;
  --error-soft: #f7d4d6;
  --warning: #f5a623;
  --violet: #7928ca;
  --cyan: #50e3c2;
  --highlight-pink: #ff0080;

  /* Brand gradient stops */
  --grad-develop-start: #007cf0;
  --grad-develop-end: #00dfd8;
  --grad-preview-start: #7928ca;
  --grad-preview-end: #ff0080;
  --grad-ship-start: #ff4d4d;
  --grad-ship-end: #f9cb28;

  /* Typing specific */
  --correct: #0070f3;
  --incorrect: #ee0000;
  --cursor-color: #171717;

  /* Heatmap */
  --heat-0: #f5f5f5;
  --heat-1: #bbf7d0;
  --heat-2: #fef08a;
  --heat-3: #fdba74;
  --heat-4: #fca5a5;

  /* Shape */
  --radius-xs: 4px;
  --radius-sm: 6px;
  /* Vercel --geist-radius, nav buttons, inputs */
  --radius-md: 8px;
  /* Feature cards, template cards */
  --radius-lg: 12px;
  /* Pricing cards, large cards */
  --radius-xl: 16px;
  --radius-pill-sm: 64px;
  /* Ghost tab pills */
  --radius-pill: 100px;
  /* Marketing CTA pills */
  --radius-full: 9999px;

  /* Spacing (4px base) */
  --space-xxs: 4px;
  --space-xs: 8px;
  --space-sm: 12px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 40px;
  --space-3xl: 48px;
  --space-4xl: 64px;

  /* Elevation — stacked subtle shadows (Vercel style) */
  --shadow-1: 0 0 0 1px rgba(0, 0, 0, 0.08) inset;
  --shadow-2: 0px 1px 1px rgba(0, 0, 0, 0.03), 0px 2px 2px rgba(0, 0, 0, 0.04), 0 0 0 1px rgba(0, 0, 0, 0.08) inset;
  --shadow-3: 0px 2px 2px rgba(0, 0, 0, 0.04), 0px 8px 8px -8px rgba(0, 0, 0, 0.04), 0 0 0 1px rgba(0, 0, 0, 0.08) inset;
  --shadow-4: 0px 2px 2px rgba(0, 0, 0, 0.04), 0px 8px 16px -4px rgba(0, 0, 0, 0.04), 0 0 0 1px rgba(0, 0, 0, 0.08) inset;
  --shadow-5: 0px 1px 1px rgba(0, 0, 0, 0.03), 0px 8px 16px -4px rgba(0, 0, 0, 0.04), 0px 24px 32px -8px rgba(0, 0, 0, 0.06), 0 0 0 1px rgba(0, 0, 0, 0.08) inset;

  /* Typography */
  --font-body: 'Inter', 'Geist', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Transitions — explicit properties only (not "all") */
  --dur: 0.15s;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

/* Dark mode override (secondary; Vercel is light-first) */
body.dark {
  --canvas: #111111;
  --canvas-soft: #0a0a0a;
  --canvas-soft-2: #1a1a1a;
  --ink: #ededed;
  --body: #a1a1a1;
  --mute: #666666;
  --hairline: #2a2a2a;
  --hairline-strong: #4a4a4a;
  --primary: #ededed;
  --on-primary: #111111;
  --correct: #50e3c2;
  --incorrect: #ff6b6b;
  --cursor-color: #ededed;
  --heat-0: #1a1a1a;
  --shadow-1: 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
  --shadow-2: 0px 1px 1px rgba(0, 0, 0, 0.2), 0px 2px 2px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
  --shadow-3: 0px 2px 2px rgba(0, 0, 0, 0.2), 0px 8px 8px -8px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
  --shadow-4: 0px 2px 2px rgba(0, 0, 0, 0.2), 0px 8px 16px -4px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
  --shadow-5: 0px 1px 1px rgba(0, 0, 0, 0.3), 0px 8px 16px -4px rgba(0, 0, 0, 0.3), 0px 24px 32px -8px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
}

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background: var(--canvas-soft);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- Skip Link (Accessibility) ---------- */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-md);
  z-index: 9999;
  background: var(--primary);
  color: var(--on-primary);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: top var(--dur) var(--ease);
}

.skip-link:focus {
  top: var(--space-md);
}

/* ---------- Header / Nav-bar ---------- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--canvas);
  border-bottom: 1px solid var(--hairline);
  height: 64px;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-lg);
  height: 64px;
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
  flex-shrink: 0;
  letter-spacing: -0.28px;
  text-decoration: none;
}

.logo-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.logo-text {
  color: var(--ink);
}

/* Nav tabs — ghost pill style (Vercel tab-ghost) */
.nav-tabs {
  display: flex;
  gap: var(--space-xxs);
  flex: 1;
  justify-content: center;
}

.nav-tab {
  background: transparent;
  border: none;
  color: var(--body);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 400;
  letter-spacing: -0.28px;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  white-space: nowrap;
  position: relative;
}

.nav-tab:hover {
  color: var(--ink);
  background: var(--canvas-soft);
}

.nav-tab.active {
  color: var(--ink);
  background: var(--canvas-soft-2);
  font-weight: 500;
}

.nav-tab:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

/* Header action buttons — nav-cta style */
.header-actions {
  display: flex;
  gap: var(--space-xs);
  margin-left: auto;
}

.btn-icon {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  color: var(--ink);
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
  flex-shrink: 0;
}

.btn-icon:hover {
  background: var(--canvas-soft-2);
  border-color: var(--hairline-strong);
}

.btn-icon:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

/* ---------- Mesh Gradient Background ---------- */
/* The brand's only decorative element — hero scale only */
.mesh-gradient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.mesh-gradient::before {
  content: '';
  position: absolute;
  top: -40%;
  left: -20%;
  width: 140%;
  height: 100%;
  background:
    radial-gradient(ellipse 60% 50% at 20% 30%, rgba(0, 124, 240, 0.07) 0%, transparent 70%),
    radial-gradient(ellipse 50% 60% at 80% 20%, rgba(121, 40, 202, 0.06) 0%, transparent 70%),
    radial-gradient(ellipse 40% 50% at 60% 70%, rgba(255, 0, 128, 0.05) 0%, transparent 70%),
    radial-gradient(ellipse 50% 40% at 10% 80%, rgba(0, 223, 216, 0.06) 0%, transparent 70%),
    radial-gradient(ellipse 30% 40% at 90% 60%, rgba(249, 203, 40, 0.05) 0%, transparent 70%);
  animation: mesh-drift 20s ease-in-out infinite alternate;
}

@keyframes mesh-drift {
  0% {
    transform: translate(0, 0) scale(1);
  }

  100% {
    transform: translate(20px, -15px) scale(1.03);
  }
}

@media (prefers-reduced-motion: reduce) {
  .mesh-gradient::before {
    animation: none;
  }
}

body.dark .mesh-gradient::before {
  background:
    radial-gradient(ellipse 60% 50% at 20% 30%, rgba(0, 124, 240, 0.12) 0%, transparent 70%),
    radial-gradient(ellipse 50% 60% at 80% 20%, rgba(121, 40, 202, 0.10) 0%, transparent 70%),
    radial-gradient(ellipse 40% 50% at 60% 70%, rgba(255, 0, 128, 0.08) 0%, transparent 70%),
    radial-gradient(ellipse 50% 40% at 10% 80%, rgba(0, 223, 216, 0.10) 0%, transparent 70%),
    radial-gradient(ellipse 30% 40% at 90% 60%, rgba(249, 203, 40, 0.07) 0%, transparent 70%);
}

/* ---------- Main ---------- */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg) var(--space-4xl);
  position: relative;
  z-index: 1;
}

/* ---------- Tab System ---------- */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: tab-in 0.2s var(--ease);
}

@keyframes tab-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tab-content.active {
    animation: none;
  }
}

/* ---------- Controls Bar ---------- */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  justify-content: center;
  margin-bottom: var(--space-lg);
}

.control-group {
  display: flex;
  align-items: center;
  gap: var(--space-xxs);
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill-sm);
  padding: 4px 6px;
  box-shadow: var(--shadow-1);
}

#mode-group {
  flex: 0 0 100%;
  justify-content: center;
}

.control-label {
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--mute);
  padding: 0 var(--space-xs);
  font-family: var(--font-mono);
}

/* Ghost tab pill buttons inside control groups */
.ctrl-btn {
  background: transparent;
  border: none;
  color: var(--body);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 400;
  letter-spacing: -0.28px;
  padding: 4px var(--space-sm);
  border-radius: var(--radius-pill-sm);
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  white-space: nowrap;
}

.ctrl-btn:hover {
  color: var(--ink);
  background: var(--canvas-soft);
}

.ctrl-btn.active {
  background: var(--canvas-soft-2);
  color: var(--ink);
  font-weight: 500;
}

.ctrl-btn:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

.custom-time-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--hairline-strong);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 14px;
  width: 52px;
  padding: 4px var(--space-xs);
  outline: none;
  text-align: center;
  font-variant-numeric: tabular-nums;
  transition: border-color var(--dur) var(--ease);
}

.custom-time-input:focus {
  border-color: var(--link);
}

.custom-time-input::-webkit-outer-spin-button,
.custom-time-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.custom-time-input[type=number] {
  -moz-appearance: textfield;
}

/* ---------- Timer Progress Bar (Monkeytype-style) ---------- */
.timer-bar {
  width: 100%;
  height: 3px;
  background: var(--hairline);
  border-radius: var(--radius-full);
  margin-bottom: var(--space-lg);
  overflow: hidden;
}

.timer-bar-fill {
  height: 100%;
  background: var(--link);
  border-radius: var(--radius-full);
  transition: width 0.3s linear;
  width: 100%;
}

/* ---------- Live Stats Bar ---------- */
.live-stats {
  display: flex;
  justify-content: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

.stat-pill {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: var(--space-xs) var(--space-lg);
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: var(--space-xxs);
  box-shadow: var(--shadow-2);
  transition: border-color var(--dur) var(--ease);
  min-width: 100px;
}

.timer-pill {
  border-color: var(--hairline-strong);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transition: color var(--dur) var(--ease);
}

.stat-unit {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--mute);
}

#live-wpm {
  color: var(--link);
}

#live-acc {
  color: var(--ink);
}

#live-timer {
  color: var(--ink);
  font-weight: 700;
}

#live-streak {
  color: var(--ink);
}

/* ---------- Typing Card ---------- */
.typing-card {
  position: relative;
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl) var(--space-3xl);
  margin-bottom: var(--space-md);
  cursor: text;
  box-shadow: var(--shadow-3);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  min-height: 180px;
  overflow: hidden;
}

/* Typing text viewport (supports multiple horizontal lines) */
.typing-card .text-display {
  display: block;
  /* keep line-height consistent; allow multi-line wrapping */
  line-height: 1.9;
  height: auto;
}


.typing-card.active-state {
  border-color: var(--hairline-strong);
  box-shadow: var(--shadow-4);
}

/* Caret */
.caret {
  display: none;
}

.caret.typing {
  animation: none;
  opacity: 1;
}

@keyframes blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .caret {
    animation: none;
    opacity: 1;
  }
}

/* Text display */
.text-display {
  font-family: var(--font-mono);
  color: var(--ink);
  font-size: 1.25rem;
  line-height: 1.9;
  color: var(--ink);


  /* Multi-line typing viewport */
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: break-word;
  text-wrap: wrap;
  tab-size: 4;
  hyphens: none;

  width: 100%;
  max-width: none;
  overflow-x: hidden;
  overflow-y: auto;
  margin: 0;

  user-select: none;
  position: relative;
  z-index: 1;
}

.char {
  position: relative;
  transition: color 0.08s ease;
}

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

.char.incorrect {
  color: var(--incorrect);
  text-decoration: underline;
  text-decoration-style: wavy;
  text-decoration-color: var(--incorrect);
}

.char.current {
  color: var(--ink);
}

/* Shake animation */
@keyframes shake {

  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-3px);
  }

  75% {
    transform: translateX(3px);
  }
}

.typing-card.shake {
  animation: shake 0.15s ease;
}

@media (prefers-reduced-motion: reduce) {
  .typing-card.shake {
    animation: none;
  }
}

/* Hidden textarea */
.hidden-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  top: 0;
  left: 0;
  pointer-events: none;
}

/* ---------- Hint Bar ---------- */
.hint-bar {
  text-align: center;
  margin-bottom: var(--space-lg);
}

.hint {
  font-size: 12px;
  color: var(--mute);
  font-family: var(--font-mono);
}

kbd {
  background: var(--canvas-soft-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-xs);
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--body);
}

/* ---------- Live Chart ---------- */
.chart-container {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-md) var(--space-lg);
  margin-bottom: var(--space-md);
  box-shadow: var(--shadow-2);
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-sm);
}

.chart-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  color: var(--mute);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.chart-subtitle {
  font-size: 12px;
  color: var(--link);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

#wpm-chart,
#results-chart,
#history-chart {
  width: 100%;
  display: block;
}

/* ---------- Results Overlay ---------- */
.results-overlay {
  position: fixed;
  inset: 0;
  background: rgba(250, 250, 250, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  animation: fade-in 0.2s var(--ease);
}

body.dark .results-overlay {
  background: rgba(10, 10, 10, 0.85);
}

@keyframes fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .results-overlay {
    animation: none;
  }
}

.results-card {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  max-width: 680px;
  width: 100%;
  box-shadow: var(--shadow-5);
  animation: slide-up 0.25s var(--ease);
  position: relative;
  overflow: hidden;
}

/* Brand gradient top accent strip */
.results-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg,
      var(--grad-develop-start),
      var(--grad-develop-end),
      var(--grad-preview-start),
      var(--grad-preview-end),
      var(--grad-ship-start),
      var(--grad-ship-end));
}

@keyframes slide-up {
  from {
    transform: translateY(16px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .results-card {
    animation: none;
  }
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.results-grade {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--on-primary);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.96px;
}

.results-title {
  font-size: 24px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.96px;
  text-wrap: balance;
  text-align: center;
  width: 100%;
}

.results-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

.res-stat {
  background: var(--canvas-soft);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: var(--space-sm);
  text-align: center;
}

.res-val {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 2px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}

.res-label {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--mute);
}

.results-chart-wrap {
  margin-bottom: var(--space-lg);
  background: var(--canvas-soft);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: var(--space-sm);
}

/* ---------- CTA Buttons — Vercel pill style ---------- */
.results-actions {
  display: flex;
  gap: var(--space-sm);
}

.btn-primary,
.btn-secondary {
  flex: 1;
  padding: 0 var(--space-sm);
  height: 40px;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
}

.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
  border: 1px solid var(--primary);
}

.btn-primary:hover {
  opacity: 0.85;
  transform: translateY(-1px);
}

.btn-primary:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

.btn-secondary {
  background: var(--canvas);
  color: var(--ink);
  border: 1px solid var(--hairline);
}

.btn-secondary:hover {
  background: var(--canvas-soft);
  transform: translateY(-1px);
}

.btn-secondary:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {

  .btn-primary:hover,
  .btn-secondary:hover {
    transform: none;
  }
}

/* Achievement toast */
.achievement-toast {
  margin-top: var(--space-md);
  background: var(--canvas-soft);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  animation: toast-in 0.3s var(--ease) 0.2s both;
}

@keyframes toast-in {
  from {
    transform: translateY(8px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .achievement-toast {
    animation: none;
  }
}

.toast-icon {
  font-size: 1rem;
}

.toast-text {
  font-size: 14px;
  color: var(--body);
  font-weight: 500;
  letter-spacing: -0.28px;
}

/* ---------- Page Header ---------- */
.page-header {
  margin-bottom: var(--space-xl);
  text-align: center;
}

.page-title {
  font-size: 32px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -1.28px;
  margin-bottom: var(--space-xs);
  text-wrap: balance;
  text-align: center;
}

.page-sub {
  color: var(--body);
  font-size: 16px;
  line-height: 24px;
}

/* ---------- Stats Overview ---------- */
.stats-overview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-sm);
  margin-bottom: var(--space-xl);
}

.overview-card {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  text-align: center;
  box-shadow: var(--shadow-2);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.overview-card:hover {
  border-color: var(--hairline-strong);
  box-shadow: var(--shadow-3);
}

.ov-icon {
  font-size: 1.4rem;
  margin-bottom: var(--space-xs);
}

.ov-val {
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 2px;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
}

.ov-label {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--mute);
}

/* ---------- Chart Section ---------- */
.chart-section {
  margin-bottom: var(--space-xl);
}

.chart-card {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-2);
}

.chart-card-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--body);
  margin-bottom: var(--space-md);
  letter-spacing: -0.28px;
  text-align: center;
}

/* ---------- History Filters ---------- */
.history-filters {
  display: flex;
  justify-content: center;
  gap: var(--space-xxs);
  margin-bottom: var(--space-md);
}

.history-filters .ctrl-btn {
  font-size: 12px;
  padding: 3px var(--space-sm);
}

/* ---------- History Table ---------- */
.history-section {
  margin-bottom: var(--space-xl);
}

.section-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.6px;
  margin-bottom: var(--space-xs);
  text-wrap: balance;
  text-align: center;
}

.section-sub {
  color: var(--body);
  font-size: 14px;
  margin-bottom: var(--space-md);
  text-align: center;
}

.history-table-wrap {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-2);
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.history-table th {
  background: var(--canvas-soft);
  color: var(--mute);
  font-family: var(--font-mono);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  border-bottom: 1px solid var(--hairline);
}

.history-table td {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--hairline);
  color: var(--body);
  font-family: var(--font-mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  transition: background var(--dur) var(--ease);
}

.history-table tr:last-child td {
  border-bottom: none;
}

.history-table tr:hover td {
  background: var(--canvas-soft);
}

.no-data {
  text-align: center;
  color: var(--mute);
  padding: 40px !important;
  font-family: var(--font-body) !important;
  font-size: 14px !important;
  letter-spacing: -0.28px;
}

.badge-wpm {
  display: inline-block;
  padding: 2px var(--space-xs);
  border-radius: var(--radius-full);
  font-weight: 500;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.badge-wpm.fast {
  background: #d3e5ff;
  color: var(--link-deep);
}

.badge-wpm.medium {
  background: #ffefcf;
  color: #ab570a;
}

.badge-wpm.slow {
  background: var(--error-soft);
  color: #c50000;
}

/* ---------- Keyboard Heatmap ---------- */
.keyboard-section {
  margin-bottom: var(--space-xl);
}

.keyboard-heatmap {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  overflow-x: auto;
  margin-bottom: var(--space-sm);
  box-shadow: var(--shadow-2);
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-bottom: 5px;
}

.kb-key {
  background: var(--canvas-soft-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-xs);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 400;
  color: var(--body);
  cursor: default;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
  position: relative;
}

.kb-key.wide {
  width: 60px;
}

.kb-key.wider {
  width: 82px;
}

.kb-key.space {
  width: 240px;
}

.kb-key[data-heat="1"] {
  background: var(--heat-1);
  border-color: transparent;
}

.kb-key[data-heat="2"] {
  background: var(--heat-2);
  border-color: transparent;
}

.kb-key[data-heat="3"] {
  background: var(--heat-3);
  border-color: transparent;
}

.kb-key[data-heat="4"] {
  background: var(--heat-4);
  border-color: transparent;
  color: var(--on-primary);
}

.heatmap-legend {
  display: flex;
  gap: var(--space-lg);
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--mute);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.leg-item {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.leg-swatch {
  width: 14px;
  height: 14px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--hairline);
}

/* ---------- Leaderboard ---------- */
.lb-filters {
  display: flex;
  gap: var(--space-xs);
  justify-content: center;
  margin-bottom: var(--space-lg);
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.lb-entry {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  display: grid;
  grid-template-columns: 44px 1fr auto auto auto;
  gap: var(--space-sm);
  align-items: center;
  box-shadow: var(--shadow-2);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.lb-entry:hover {
  border-color: var(--hairline-strong);
  box-shadow: var(--shadow-3);
}

.lb-entry.rank-1 {
  border-left: 3px solid #f9cb28;
}

.lb-entry.rank-2 {
  border-left: 3px solid var(--hairline-strong);
}

.lb-entry.rank-3 {
  border-left: 3px solid #cd7f32;
}

.lb-rank {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  color: var(--mute);
  font-variant-numeric: tabular-nums;
}

.rank-1 .lb-rank {
  color: #b8860b;
}

.rank-2 .lb-rank {
  color: var(--hairline-strong);
}

.rank-3 .lb-rank {
  color: #cd7f32;
}

.lb-date {
  font-size: 12px;
  color: var(--mute);
  font-family: var(--font-mono);
}

.lb-wpm {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.lb-acc {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--body);
  font-variant-numeric: tabular-nums;
}

.lb-mode {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--mute);
  background: var(--canvas-soft-2);
  border: 1px solid var(--hairline);
  padding: 2px var(--space-xs);
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.lb-empty {
  text-align: center;
  color: var(--mute);
  padding: var(--space-4xl);
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  font-size: 14px;
  letter-spacing: -0.28px;
}

/* ---------- Achievements ---------- */
.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-sm);
}

.achievement-card {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  display: flex;
  gap: var(--space-sm);
  align-items: flex-start;
  box-shadow: var(--shadow-2);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  position: relative;
  overflow: hidden;
}

.achievement-card:hover {
  border-color: var(--hairline-strong);
  box-shadow: var(--shadow-3);
}

.achievement-card.unlocked {
  border-color: var(--hairline-strong);
}

.achievement-card.unlocked::after {
  content: '✓';
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  font-size: 11px;
  color: var(--link);
  font-weight: 600;
  font-family: var(--font-mono);
}

.achievement-card.locked {
  opacity: 0.5;
}

.ach-icon {
  font-size: 1.4rem;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  background: var(--canvas-soft-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.achievement-card.unlocked .ach-icon {
  background: var(--canvas-soft);
  border-color: var(--hairline-strong);
}

.ach-info {
  flex: 1;
  min-width: 0;
}

.ach-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 2px;
  color: var(--ink);
  letter-spacing: -0.28px;
}

.ach-desc {
  font-size: 12px;
  color: var(--mute);
  line-height: 1.5;
}

.ach-progress {
  font-size: 11px;
  color: var(--link);
  font-family: var(--font-mono);
  margin-top: var(--space-xs);
}

/* ---------- Typing Legal Nav (under typing box) ---------- */
.typing-legal-nav {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}

.typing-legal-nav a {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--hairline);
  background: var(--canvas-soft);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

.typing-legal-nav a:hover {
  background: var(--canvas-soft-2);
  border-color: var(--hairline-strong);
  color: var(--link);
}

body.dark .typing-legal-nav a {
  background: var(--canvas-soft-2);
}


/* ---------- Shortcuts Bar ---------- */
.shortcuts-bar {
  position: fixed;
  bottom: var(--space-lg);

  left: 50%;
  transform: translateX(-50%);
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-full);
  padding: var(--space-xs) var(--space-lg);
  display: flex;
  gap: var(--space-lg);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--mute);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  box-shadow: var(--shadow-3);
  z-index: 10;
  white-space: nowrap;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .header-inner {
    padding: 0 var(--space-md);
  }

  .nav-tabs {
    gap: 2px;
  }

  .nav-tab {
    padding: var(--space-xs);
    font-size: 13px;
  }

  .main {
    padding: var(--space-lg) var(--space-md) var(--space-4xl);
  }

  .typing-card {
    padding: var(--space-lg);
  }

  .text-display {
    font-size: 1.1rem;
  }

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

  .controls-bar {
    gap: var(--space-xs);
  }

  .live-stats {
    gap: var(--space-xs);
    flex-wrap: wrap;
  }

  .stat-pill {
    padding: var(--space-xs) var(--space-md);
  }

  .stat-value {
    font-size: 1.2rem;
  }

  .kb-key {
    width: 30px;
    height: 30px;
    font-size: 10px;
  }

  .kb-key.wide {
    width: 50px;
  }

  .kb-key.wider {
    width: 65px;
  }

  .kb-key.space {
    width: 160px;
  }

  .shortcuts-bar {
    gap: var(--space-md);
    padding: var(--space-xs) var(--space-md);
    font-size: 10px;
  }
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--canvas-soft);
}

::-webkit-scrollbar-thumb {
  background: var(--hairline-strong);
  border-radius: var(--radius-xs);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--mute);
}

/* ---------- WPM pulse animation ---------- */
@keyframes wpm-pulse {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.06);
  }

  100% {
    transform: scale(1);
  }
}

.stat-pill.pulse {
  animation: wpm-pulse 0.2s var(--ease);
}

@media (prefers-reduced-motion: reduce) {
  .stat-pill.pulse {
    animation: none;
  }
}

/* ---------- Selection ---------- */
::selection {
  background: var(--primary);
  color: var(--on-primary);
}

/* ---------- SEO Content Section ---------- */
.seo-content {
  background: var(--canvas-soft);
  border-top: 1px solid var(--hairline);
  padding: var(--space-4xl) var(--space-lg);
  margin-top: var(--space-4xl);
}

.seo-content-inner {
  max-width: 720px;
  margin: 0 auto;
}

.seo-content h2 {
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.03em;
  color: var(--ink);
  margin-bottom: var(--space-lg);
}

.seo-content h3 {
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin-top: var(--space-2xl);
  margin-bottom: var(--space-sm);
}

.seo-content p {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--body);
  margin-bottom: var(--space-md);
}

.seo-content strong {
  color: var(--ink);
  font-weight: 600;
}

/* ---------- FAQ Items ---------- */
.faq-item {
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
  overflow: hidden;
  background: var(--canvas);
  transition: border-color var(--dur) var(--ease);
}

.faq-item[open] {
  border-color: var(--hairline-strong);
}

.faq-question {
  font-size: 1rem;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.02em;
  padding: var(--space-md) var(--space-lg);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  user-select: none;
  transition: color var(--dur) var(--ease);
}

.faq-question::-webkit-details-marker {
  display: none;
}

.faq-question::after {
  content: '+';
  font-size: 1.3rem;
  font-weight: 400;
  color: var(--mute);
  flex-shrink: 0;
  transition: transform 0.2s var(--ease);
  line-height: 1;
}

.faq-item[open] .faq-question::after {
  transform: rotate(45deg);
}

.faq-question:hover {
  color: var(--link);
}

.faq-answer {
  padding: 0 var(--space-lg) var(--space-lg);
}

.faq-answer p {
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--body);
  margin: 0;
}

/* ---------- Site Footer ---------- */
.site-footer {
  background: var(--canvas);
  border-top: 1px solid var(--hairline);
  padding: var(--space-lg) var(--space-lg);
  position: relative;
  z-index: 1;
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 13px;
  color: var(--mute);
}

.footer-text {
  font-weight: 400;
  letter-spacing: -0.28px;
}

.footer-links {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.footer-links a {
  font-size: 13px;
  color: var(--body);
  text-decoration: none;
  transition: color var(--dur) var(--ease);
  letter-spacing: -0.28px;
}

.footer-links a:hover {
  color: var(--link);
}

.footer-links a:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

@media (max-width: 600px) {
  .footer-inner {
    flex-direction: column;
    text-align: center;
  }
  .footer-links {
    justify-content: center;
  }
}

/* ---------- Legal / Content Pages ---------- */
.legal-content {
  padding: var(--space-xl) 0;
}

.legal-content h2 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--ink);
  margin-top: var(--space-2xl);
  margin-bottom: var(--space-sm);
}

.legal-content p {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--body);
  margin-bottom: var(--space-md);
}

.legal-content a {
  color: var(--link);
  text-decoration: none;
}

.legal-content a:hover {
  text-decoration: underline;
}

.legal-content code {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  background: var(--canvas-soft-2);
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--hairline);
}

/* Nav tab as link */
a.nav-tab {
  text-decoration: none;
}

/* ---------- Error Pages ---------- */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-4xl) var(--space-lg);
  min-height: 50vh;
}

.error-code {
  font-family: var(--font-mono);
  font-size: 6rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--hairline-strong);
  margin-bottom: var(--space-md);
}

body.dark .error-code {
  color: var(--mute);
}

.error-title {
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--ink);
  margin-bottom: var(--space-sm);
}

.error-desc {
  font-size: 1rem;
  line-height: 1.6;
  color: var(--body);
  margin-bottom: var(--space-xl);
  max-width: 400px;
}

.error-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--space-xl);
  height: 44px;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 500;
  background: var(--primary);
  color: var(--on-primary);
  text-decoration: none;
  border: 1px solid var(--primary);
  cursor: pointer;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.error-btn:hover {
  opacity: 0.85;
  transform: translateY(-1px);
}

.error-btn:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}