/* ================================================================
   TYPEGLOBAL — PREMIUM STYLESHEET
   Aesthetic: Dark Cyberpunk Terminal × Glassmorphism
   Font Stack: Syne (display) + DM Mono (body/code)
   ================================================================ */

/* ── 1. CSS CUSTOM PROPERTIES ─────────────────────────────────── */
:root {
  /* Core palette */
  --clr-bg:           #080b14;
  --clr-surface:      #0e1525;
  --clr-glass:        rgba(14, 21, 37, 0.55);
  --clr-glass-border: rgba(255, 255, 255, 0.07);
  --clr-glass-shine:  rgba(255, 255, 255, 0.04);

  /* Accent — electric cyan/teal primary */
  --clr-accent:       #00e5c3;
  --clr-accent-dim:   rgba(0, 229, 195, 0.15);
  --clr-accent-glow:  rgba(0, 229, 195, 0.35);

  /* Secondary accent — violet */
  --clr-violet:       #8b5cf6;
  --clr-violet-dim:   rgba(139, 92, 246, 0.18);

  /* Tertiary — amber for WPM */
  --clr-amber:        #f59e0b;
  --clr-amber-dim:    rgba(245, 158, 11, 0.15);

  /* Typing feedback */
  --clr-correct:      #00e5c3;
  --clr-incorrect:    #ff4d6d;
  --clr-incorrect-bg: rgba(255, 77, 109, 0.18);
  --clr-pending:      rgba(255, 255, 255, 0.28);
  --clr-cursor:       #00e5c3;

  /* Orb colours for mesh gradient */
  --orb1: #0d3d6e;
  --orb2: #0d2a4a;
  --orb3: #1a0a3d;
  --orb4: #003d35;

  /* Typography */
  --font-display: 'Syne', sans-serif;
  --font-mono:    'DM Mono', monospace;

  /* Radii */
  --radius-sm:  6px;
  --radius-md:  14px;
  --radius-lg:  22px;
  --radius-xl:  32px;

  /* Shadows */
  --shadow-glass: 0 8px 48px rgba(0,0,0,0.55), 0 1px 0 rgba(255,255,255,0.06) inset;
  --shadow-btn:   0 4px 24px rgba(0, 229, 195, 0.22);
  --shadow-glow:  0 0 40px rgba(0, 229, 195, 0.12);

  /* Transitions */
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring:   cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Layout */
  --max-w: 820px;
  --gap:   1.5rem;
}

/* ── 2. RESET & BASE ──────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  background-color: var(--clr-bg);
  color: rgba(255,255,255,0.88);
  font-family: var(--font-mono);
  min-height: 100dvh;
  overflow-x: hidden;
  line-height: 1.6;
}

::selection {
  background: var(--clr-accent);
  color: #000;
}

/* ── 3. ANIMATED MESH BACKGROUND ─────────────────────────────── */
.bg-mesh {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.mesh-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.6;
  will-change: transform;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-direction: alternate;
}

.mesh-orb--1 {
  width: 700px; height: 700px;
  background: radial-gradient(circle, var(--orb1), transparent 70%);
  top: -200px; left: -200px;
  animation: orbDrift1 18s infinite alternate;
}
.mesh-orb--2 {
  width: 600px; height: 600px;
  background: radial-gradient(circle, var(--orb2), transparent 70%);
  bottom: -150px; right: -100px;
  animation: orbDrift2 22s infinite alternate;
}
.mesh-orb--3 {
  width: 500px; height: 500px;
  background: radial-gradient(circle, var(--orb3), transparent 70%);
  top: 40%; left: 50%;
  transform: translate(-50%, -50%);
  animation: orbDrift3 26s infinite alternate;
}
.mesh-orb--4 {
  width: 400px; height: 400px;
  background: radial-gradient(circle, var(--orb4), transparent 70%);
  bottom: 10%; left: 5%;
  animation: orbDrift4 20s infinite alternate;
}

.noise-overlay {
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.035'/%3E%3C/svg%3E");
  background-size: 200px 200px;
  opacity: 0.5;
}

@keyframes orbDrift1 {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(80px, 60px) scale(1.12); }
}
@keyframes orbDrift2 {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(-60px, -80px) scale(1.08); }
}
@keyframes orbDrift3 {
  from { transform: translate(-50%, -50%) scale(1); }
  to   { transform: translate(-48%, -53%) scale(1.15); }
}
@keyframes orbDrift4 {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(50px, -40px) scale(1.1); }
}

/* ── 4. PAGE WRAPPER & LAYOUT ─────────────────────────────────── */
.page-wrapper {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
  padding: 0 1rem 3rem;
}

/* ── 5. HEADER ────────────────────────────────────────────────── */
.site-header {
  width: 100%;
  max-width: var(--max-w);
  padding: 1.75rem 0 1rem;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
  color: #fff;
}

.logo-icon {
  font-size: 1.5rem;
  filter: drop-shadow(0 0 8px var(--clr-accent));
}

.header-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--clr-accent);
  background: var(--clr-accent-dim);
  border: 1px solid rgba(0, 229, 195, 0.25);
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
}

.badge-dot {
  width: 6px; height: 6px;
  background: var(--clr-accent);
  border-radius: 50%;
  animation: pulseDot 2s ease-in-out infinite;
  box-shadow: 0 0 6px var(--clr-accent);
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.7); }
}

/* ── 6. MAIN CONTENT ──────────────────────────────────────────── */
.main-content {
  width: 100%;
  max-width: var(--max-w);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ── 7. STATS BAR ─────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  background: var(--clr-glass);
  border: 1px solid var(--clr-glass-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  padding: 0.75rem 1.5rem;
  box-shadow: var(--shadow-glass);
  overflow: hidden;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.25rem 1.5rem;
  flex: 1;
}

.stat-value {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.75rem;
  line-height: 1;
  color: var(--clr-accent);
  letter-spacing: -0.03em;
  transition: color 0.2s ease;
  text-shadow: 0 0 20px var(--clr-accent-glow);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
  margin-top: 0.15rem;
}

.stat-divider {
  width: 1px;
  height: 36px;
  background: var(--clr-glass-border);
  flex-shrink: 0;
}

/* ── 8. GLASS CARD ────────────────────────────────────────────── */
.glass-card {
  background: var(--clr-glass);
  border: 1px solid var(--clr-glass-border);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(24px) saturate(1.6);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
  padding: 2.25rem 2.25rem;
  box-shadow: var(--shadow-glass);
  position: relative;
  overflow: hidden;
  animation: cardIn 0.6s var(--ease-out-expo) both;
}

/* Subtle top-edge shine */
.glass-card::before {
  content: '';
  position: absolute;
  top: 0; left: 10%; right: 10%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.12), transparent);
  pointer-events: none;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.results-card { animation-delay: 0.1s; }

/* ── 9. CARD HEADER ───────────────────────────────────────────── */
.card-header {
  margin-bottom: 1.5rem;
}

.card-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.4rem, 4vw, 2rem);
  letter-spacing: -0.03em;
  color: #fff;
  line-height: 1.1;
}

.card-subtitle {
  margin-top: 0.5rem;
  font-size: 0.83rem;
  color: rgba(255,255,255,0.45);
  line-height: 1.55;
}

.card-subtitle strong {
  color: var(--clr-accent);
  font-weight: 500;
}

/* ── 10. PASSAGE DISPLAY ──────────────────────────────────────── */
.passage-display {
  background: rgba(0,0,0,0.28);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: var(--radius-md);
  padding: 1.35rem 1.5rem;
  font-family: var(--font-mono);
  font-size: clamp(0.9rem, 2.2vw, 1.05rem);
  line-height: 1.85;
  letter-spacing: 0.01em;
  word-break: break-word;
  min-height: 130px;
  user-select: none;
  position: relative;
}

/* Individual character spans — injected by engine.js */
.passage-display .char {
  position: relative;
  transition: color 0.08s ease, background 0.08s ease;
}

.passage-display .char--pending {
  color: var(--clr-pending);
}

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

.passage-display .char--incorrect {
  color: var(--clr-incorrect);
  background: var(--clr-incorrect-bg);
  border-radius: 2px;
  animation: charShake 0.25s var(--ease-out-expo) both;
}

/* Blinking cursor positioned after last typed char */
.passage-display .char--cursor::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--clr-cursor);
  border-radius: 2px;
  margin-left: 1px;
  vertical-align: text-bottom;
  animation: blink 1s step-end infinite;
  box-shadow: 0 0 8px var(--clr-accent);
}

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

@keyframes charShake {
  0%   { transform: translateX(0); }
  25%  { transform: translateX(-3px); }
  50%  { transform: translateX(3px); }
  75%  { transform: translateX(-2px); }
  100% { transform: translateX(0); }
}

/* ── 11. TYPING INPUT ─────────────────────────────────────────── */
.typing-input {
  width: 100%;
  margin-top: 1rem;
  background: rgba(0,0,0,0.22);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: var(--radius-md);
  padding: 0.9rem 1.2rem;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: rgba(255,255,255,0.75);
  resize: none;
  height: 72px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  caret-color: var(--clr-accent);
  line-height: 1.6;
}

.typing-input:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.typing-input:not(:disabled):focus {
  border-color: rgba(0, 229, 195, 0.4);
  box-shadow: 0 0 0 3px rgba(0, 229, 195, 0.1), inset 0 1px 0 rgba(255,255,255,0.04);
}

.typing-input::placeholder {
  color: rgba(255,255,255,0.2);
  font-style: italic;
}

/* ── 12. ERROR FLASH ──────────────────────────────────────────── */
.error-flash {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-xl);
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center, rgba(255,77,109,0.12), transparent 70%);
  transition: opacity 0.05s ease;
  z-index: 2;
}

.error-flash.active {
  animation: flashIn 0.3s ease forwards;
}

@keyframes flashIn {
  0%   { opacity: 1; }
  100% { opacity: 0; }
}

/* ── 13. CONTROLS ─────────────────────────────────────────────── */
.controls {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.35rem;
  flex-wrap: wrap;
}

/* Base button */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1.4rem;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.88rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition:
    transform 0.15s var(--ease-spring),
    box-shadow 0.2s ease,
    background 0.2s ease,
    opacity 0.2s ease;
  position: relative;
  overflow: hidden;
  user-select: none;
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.btn:not(:disabled):active {
  transform: scale(0.96);
}

/* Ripple effect on click */
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.06);
  opacity: 0;
  transition: opacity 0.15s ease;
  border-radius: inherit;
}
.btn:not(:disabled):hover::after { opacity: 1; }

.btn-icon {
  font-size: 0.8rem;
  line-height: 1;
}

/* Start button */
.btn--start {
  background: linear-gradient(135deg, #00b89f, var(--clr-accent));
  color: #000;
  border-color: rgba(0, 229, 195, 0.4);
  box-shadow: var(--shadow-btn), 0 1px 0 rgba(255,255,255,0.2) inset;
  flex: 1;
}

.btn--start:not(:disabled):hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 6px 32px rgba(0, 229, 195, 0.38);
}

/* Stop button */
.btn--stop {
  background: rgba(255, 77, 109, 0.12);
  color: #ff4d6d;
  border-color: rgba(255, 77, 109, 0.3);
}

.btn--stop:not(:disabled):hover {
  background: rgba(255, 77, 109, 0.22);
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 6px 24px rgba(255, 77, 109, 0.25);
}

/* Reset button */
.btn--reset {
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.5);
  border-color: rgba(255, 255, 255, 0.08);
}

.btn--reset:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.8);
  transform: translateY(-1px);
}

/* ── 14. STATE BADGE ──────────────────────────────────────────── */
.state-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 1rem;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  transition: color 0.3s ease;
}

.state-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

/* States: ready / running / done */
.state-badge[data-state="running"] { color: var(--clr-accent); }
.state-badge[data-state="running"] .state-dot {
  background: var(--clr-accent);
  box-shadow: 0 0 8px var(--clr-accent);
  animation: pulseDot 1s ease-in-out infinite;
}
.state-badge[data-state="done"] { color: var(--clr-violet); }
.state-badge[data-state="done"] .state-dot {
  background: var(--clr-violet);
  box-shadow: 0 0 8px var(--clr-violet);
}

/* ── 15. KPI GRID ─────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.kpi-card {
  background: rgba(0,0,0,0.22);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius-md);
  padding: 1.1rem 0.75rem;
  text-align: center;
  transition: transform 0.3s var(--ease-spring), box-shadow 0.3s ease;
}

.kpi-card:hover {
  transform: translateY(-3px);
}

.kpi-value {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.kpi-label {
  font-size: 0.65rem;
  color: rgba(255,255,255,0.38);
  margin-top: 0.4rem;
  letter-spacing: 0.04em;
}

.kpi-sublabel {
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.55;
  margin-top: 0.15rem;
}

/* KPI accent colours */
.kpi--cpm .kpi-value { color: var(--clr-accent); text-shadow: 0 0 20px var(--clr-accent-glow); }
.kpi--cpm { border-top: 2px solid rgba(0, 229, 195, 0.3); }

.kpi--cps .kpi-value { color: #38bdf8; text-shadow: 0 0 20px rgba(56,189,248,0.3); }
.kpi--cps { border-top: 2px solid rgba(56,189,248,0.3); }

.kpi--wpm .kpi-value { color: var(--clr-amber); text-shadow: 0 0 20px rgba(245,158,11,0.3); }
.kpi--wpm { border-top: 2px solid rgba(245,158,11,0.3); }

.kpi--acc .kpi-value { color: var(--clr-violet); text-shadow: 0 0 20px rgba(139,92,246,0.3); }
.kpi--acc { border-top: 2px solid rgba(139,92,246,0.3); }

/* ── 16. CHART ────────────────────────────────────────────────── */
.chart-wrapper {
  position: relative;
  width: 100%;
  height: 220px;
  background: rgba(0,0,0,0.2);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: var(--radius-md);
  padding: 1rem;
  overflow: hidden;
}

.chart-caption {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.25);
  text-align: center;
  margin-top: 0.6rem;
  letter-spacing: 0.04em;
}

/* ── 17. FOOTER ───────────────────────────────────────────────── */
.site-footer {
  width: 100%;
  max-width: var(--max-w);
  margin-top: 3rem;
  padding-bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.footer-copy {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.22);
  letter-spacing: 0.04em;
}

.footer-nav {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.footer-link {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.3);
  text-decoration: none;
  letter-spacing: 0.04em;
  transition: color 0.2s ease;
}

.footer-link:hover {
  color: var(--clr-accent);
}

.footer-sep {
  color: rgba(255,255,255,0.15);
  font-size: 0.65rem;
}

/* ── 18. UTILITY: HIDDEN ──────────────────────────────────────── */
[hidden] {
  display: none !important;
}

/* ── 19. ACCESSIBILITY: FOCUS RING ───────────────────────────── */
:focus-visible {
  outline: 2px solid var(--clr-accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ── 20. SCROLL BAR ───────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0, 229, 195, 0.3); }

/* ── 21. RESPONSIVENESS ───────────────────────────────────────── */

/* Tablet (≤ 680px) */
@media (max-width: 680px) {
  .glass-card { padding: 1.5rem 1.25rem; }

  .stats-bar { padding: 0.6rem 0.75rem; }
  .stat-item { padding: 0.25rem 0.75rem; }
  .stat-value { font-size: 1.3rem; }

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

  .controls { flex-direction: column; }
  .btn { justify-content: center; }

  .chart-wrapper { height: 190px; }
}

/* Mobile (≤ 420px) */
@media (max-width: 420px) {
  :root { --gap: 1rem; }

  .header-badge { display: none; }

  .stats-bar {
    gap: 0;
    padding: 0.5rem;
  }
  .stat-item { padding: 0.2rem 0.5rem; }
  .stat-value { font-size: 1.1rem; }
  .stat-label { font-size: 0.58rem; }

  .passage-display { font-size: 0.88rem; padding: 1rem; }

  .kpi-grid { gap: 0.5rem; }
  .kpi-value { font-size: 1.5rem; }
}

/* ── 22. REDUCED MOTION ───────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .mesh-orb,
  .badge-dot,
  .state-dot,
  .char--cursor::after {
    animation: none !important;
  }

  .btn:not(:disabled):hover {
    transform: none !important;
  }

  .glass-card {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
}
