/* ============================================
   TypeGauge — design tokens
   ============================================ */
:root {
  --bg: #F7F8FA;
  --paper: #FFFFFF;
  --ink: #1A1D23;
  --muted: #8B93A1;
  --muted-light: #C3C9D2;
  --border: #E4E7EC;
  --accent: #0F766E;
  --accent-dark: #0B5B54;
  --accent-soft: #E3F3F1;
  --accent-2: #4F46E5;
  --accent-2-soft: #EBEAFB;
  --correct: #16A34A;
  --correct-soft: #E7F7ED;
  --incorrect: #DC2626;
  --incorrect-soft: #FDEAEA;
  --shadow-sm: 0 1px 2px rgba(20, 24, 33, 0.05);
  --shadow-md: 0 8px 24px rgba(20, 24, 33, 0.07);
  --radius: 14px;
  --font-display: 'Space Grotesk', 'Segoe UI', sans-serif;
  --font-body: 'Inter', 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(20,24,33,0.045) 1px, transparent 0);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 920px;
  margin: 0 auto;
  padding: 40px 24px 64px;
}

/* ============================================
   Header
   ============================================ */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark { flex-shrink: 0; }

.brand-text h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}

.tagline {
  margin: 2px 0 0;
  font-size: 0.86rem;
  color: var(--muted);
}

.duration-picker {
  display: inline-flex;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
  box-shadow: var(--shadow-sm);
}

.duration-btn {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.duration-btn:hover { color: var(--ink); }

.duration-btn.is-active {
  background: var(--accent);
  color: #fff;
}

/* ============================================
   Main card
   ============================================ */
.app-card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 28px;
}

/* ---- HUD: split-flap style stat blocks ---- */
.hud {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 0;
  margin-bottom: 26px;
  background: var(--ink);
  border-radius: 12px;
  padding: 18px 10px;
}

.hud-cell {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
}

.hud-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #9AA3B2;
  font-weight: 600;
}

.hud-value {
  font-family: var(--font-mono);
  font-size: 2.1rem;
  font-weight: 600;
  color: #F4F6F8;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.hud-value--accent { color: #5EEAD4; }

.hud-unit {
  font-size: 1.1rem;
  color: #9AA3B2;
  margin-left: 2px;
}

.hud-divider {
  width: 1px;
  background: rgba(255,255,255,0.12);
  margin: 2px 0;
}

/* ---- Typing paper ---- */
.type-area { margin-bottom: 22px; }

.type-paper {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 26px 28px;
  min-height: 130px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.type-paper:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.type-text {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 1.28rem;
  line-height: 1.9;
  letter-spacing: 0.01em;
  color: var(--muted-light);
  word-wrap: break-word;
}

.type-text .char {
  position: relative;
  white-space: pre-wrap;
}

.type-text .char--correct { color: var(--correct); }
.type-text .char--incorrect {
  color: var(--incorrect);
  background: var(--incorrect-soft);
  border-radius: 2px;
}
.type-text .char--pending { color: var(--muted-light); }

.type-text .char--current::before {
  content: "";
  position: absolute;
  left: -1px;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--accent);
  animation: caret-blink 1s step-end infinite;
}

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

.type-hint {
  margin: 10px 2px 0;
  font-size: 0.82rem;
  color: var(--muted);
}

/* Loader */
.loader {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 1rem;
}

.loader-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  animation: loader-pulse 1s ease-in-out infinite;
}
.loader-dot:nth-child(2) { animation-delay: 0.15s; }
.loader-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes loader-pulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ---- Controls / buttons ---- */
.controls {
  display: flex;
  justify-content: center;
}

.btn {
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: 10px;
  padding: 11px 22px;
  cursor: pointer;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--accent-dark);
  box-shadow: var(--shadow-md);
}

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

/* ============================================
   Results
   ============================================ */
.results {
  margin-top: 28px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 28px;
  animation: results-in 0.4s ease both;
}

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

.results-header { text-align: center; margin-bottom: 22px; }

.results-header h2 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  margin: 0 0 6px;
}

.results-header p {
  margin: 0;
  color: var(--muted);
}

.results-header strong { color: var(--ink); }

.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 22px;
}

.chart-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px 10px;
  background: #FCFCFD;
}

.chart-card h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 600;
}

.chart-wrap { width: 100%; }
.chart-wrap svg { width: 100%; height: auto; display: block; }

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

.stat-pill {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  text-align: center;
}

.stat-pill span {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat-pill strong {
  font-family: var(--font-mono);
  font-size: 1.2rem;
}

#stat-correct { color: var(--correct); }
#stat-incorrect { color: var(--incorrect); }

/* ============================================
   Footer
   ============================================ */
.site-footer {
  text-align: center;
  margin-top: 30px;
  color: var(--muted);
  font-size: 0.78rem;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 640px) {
  .page { padding: 24px 16px 48px; }
  .app-card, .results { padding: 20px; }
  .hud-value { font-size: 1.5rem; }
  .type-text { font-size: 1.05rem; line-height: 1.8; }
  .results-grid { grid-template-columns: 1fr; }
  .results-stats { grid-template-columns: repeat(2, 1fr); }
  .site-header { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
