:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #e2e8f0;
  --text: #172033;
  --text-muted: #64748b;
  --text-soft: #94a3b8;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #eff6ff;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 42px 0 30px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

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

.brand-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid #bfdbfe;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2rem);
  letter-spacing: -0.035em;
  line-height: 1.1;
}

.brand p {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.test-config {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.04);
  white-space: nowrap;
}

.config-label {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.test-config strong {
  font-size: 0.88rem;
}

.test-card,
.results-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.test-card {
  padding: 28px;
}

.hud {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}

.hud-item {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  text-align: center;
}

.hud-label {
  display: block;
  margin-bottom: 4px;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.hud-value {
  font-size: clamp(1.45rem, 4vw, 2rem);
  letter-spacing: -0.03em;
}

.loading-state {
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #dbeafe;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.quote-display {
  min-height: 220px;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fbfdff;
  font-size: clamp(1.15rem, 2.7vw, 1.5rem);
  font-weight: 500;
  line-height: 2;
  letter-spacing: 0.005em;
  outline: none;
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease,
    background 180ms ease;
}

.quote-display:focus,
.quote-display.is-active {
  border-color: #93c5fd;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08);
  background: #ffffff;
}

.char {
  transition:
    color 80ms ease,
    background-color 80ms ease;
}

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

.char.incorrect {
  color: var(--danger);
  text-decoration: underline wavy currentColor;
  text-underline-offset: 5px;
}

.char.current {
  background: #dbeafe;
  border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.12);
}

.char.untyped {
  color: #334155;
}

.test-status {
  min-height: 52px;
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.status-message {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 700;
  transition:
    transform 160ms ease,
    background-color 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
}

.button-secondary {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.button-secondary:hover {
  border-color: #cbd5e1;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.07);
}

.results-card {
  margin-top: 24px;
  padding: 28px;
}

.results-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.eyebrow {
  display: inline-block;
  margin-bottom: 7px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.results-header h2 {
  margin: 0;
  font-size: clamp(1.55rem, 3vw, 2rem);
  letter-spacing: -0.035em;
}

.final-score {
  text-align: right;
}

.final-score span {
  display: block;
  margin-bottom: 2px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.final-score strong {
  color: var(--accent);
  font-size: clamp(2rem, 5vw, 3.1rem);
  letter-spacing: -0.05em;
  line-height: 1;
}

.result-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 24px 0;
}

.metric-card {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
}

.metric-card span {
  display: block;
  margin-bottom: 5px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.metric-card strong {
  font-size: 1.5rem;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.chart-card {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
}

.chart-heading {
  margin-bottom: 14px;
}

.chart-heading h3 {
  margin: 0;
  font-size: 1rem;
}

.chart-heading p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.chart-wrapper {
  width: 100%;
  aspect-ratio: 2 / 1;
  min-height: 250px;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: #fbfdff;
}

.chart {
  display: block;
  width: 100%;
  height: 100%;
}

.chart text {
  fill: #64748b;
  font-size: 12px;
  font-family: inherit;
}

.chart .axis {
  stroke: #cbd5e1;
  stroke-width: 1.5;
}

.chart .grid-line {
  stroke: #e2e8f0;
  stroke-width: 1;
}

.chart .line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart .point {
  fill: #ffffff;
  stroke: var(--accent);
  stroke-width: 3;
}

.chart .bar-correct {
  fill: #22c55e;
}

.chart .bar-incorrect {
  fill: #ef4444;
}

.chart .bar-value {
  fill: #1e293b;
  font-size: 13px;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.app-footer {
  margin-top: 22px;
  text-align: center;
  color: var(--text-soft);
  font-size: 0.8rem;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 820px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .test-config {
    width: 100%;
    justify-content: space-between;
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 600px) {
  .app-shell {
    width: min(100% - 20px, 1120px);
    padding-top: 20px;
  }

  .test-card,
  .results-card {
    padding: 16px;
    border-radius: 16px;
  }

  .hud {
    gap: 8px;
    margin-bottom: 16px;
  }

  .hud-item {
    padding: 12px 8px;
  }

  .hud-value {
    font-size: 1.4rem;
  }

  .quote-display {
    min-height: 280px;
    padding: 20px;
    font-size: 1.05rem;
    line-height: 1.9;
  }

  .test-status,
  .results-header {
    align-items: stretch;
    flex-direction: column;
  }

  .final-score {
    text-align: left;
  }

  .result-metrics {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 430px) {
  .brand p {
    font-size: 0.82rem;
  }

  .result-metrics {
    grid-template-columns: 1fr;
  }

  .button {
    width: 100%;
  }

  .test-status {
    gap: 12px;
  }
}
