/* wpmflex.com — design system
   Warm-graphite typing-test aesthetic, system monospace stack (zero external font requests). */

:root {
  --bg: #14161a;
  --bg-raised: #1b1e24;
  --bg-inset: #0f1114;
  --border: #2b2f37;
  --border-soft: #21242b;
  --text: #e9e7e2;
  --text-dim: #a2a7b0;
  --text-faint: #62666f;
  --accent: #ffb454;
  --accent-dim: #b9822f;
  --accent-contrast: #201200;
  --correct: #6fd68a;
  --incorrect: #ff6b6b;
  --incorrect-bg: rgba(255, 107, 107, 0.14);
  --focus: #7cc6ff;
  --radius: 6px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Menlo", "Consolas",
    "Liberation Mono", monospace;
  --maxw: 860px;
}

:root[data-theme="light"] {
  --bg: #f7f5f1;
  --bg-raised: #ffffff;
  --bg-inset: #edeae3;
  --border: #ddd7cb;
  --border-soft: #e7e2d8;
  --text: #201c16;
  --text-dim: #5a5648;
  --text-faint: #928d7e;
  --accent: #b9722a;
  --accent-dim: #8f5a20;
  --accent-contrast: #fff8ee;
  --correct: #2f8f52;
  --incorrect: #c8362b;
  --incorrect-bg: rgba(200, 54, 43, 0.1);
  --focus: #0a6cbf;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f7f5f1;
    --bg-raised: #ffffff;
    --bg-inset: #edeae3;
    --border: #ddd7cb;
    --border-soft: #e7e2d8;
    --text: #201c16;
    --text-dim: #5a5648;
    --text-faint: #928d7e;
    --accent: #b9722a;
    --accent-dim: #8f5a20;
    --accent-contrast: #fff8ee;
    --correct: #2f8f52;
    --incorrect: #c8362b;
    --incorrect-bg: rgba(200, 54, 43, 0.1);
    --focus: #0a6cbf;
  }
}

* { box-sizing: border-box; }
html { color-scheme: dark light; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 8px 12px;
  z-index: 100;
}
.skip-link:focus { left: 8px; top: 8px; }

button, select, input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 14px;
  transition: border-color .12s ease, background .12s ease, color .12s ease;
}
button:hover { border-color: var(--accent-dim); color: var(--accent); }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}
button.primary:hover { color: var(--accent-contrast); filter: brightness(1.08); }
button.icon-btn { padding: 6px 10px; font-size: 13px; }

/* ---------- layout shell ---------- */
.site-header {
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  z-index: 20;
}
.header-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.brand-mark .bracket { color: var(--accent); }
.brand-tag { color: var(--text-faint); font-size: 12px; display: none; }
@media (min-width: 640px) { .brand-tag { display: inline; } }

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

main { max-width: var(--maxw); margin: 0 auto; padding: 24px 20px 60px; }

.container-narrow { max-width: 700px; margin: 0 auto; padding: 40px 20px 60px; }
.container-narrow h1 { font-size: 22px; }
.container-narrow h2 { font-size: 16px; margin-top: 32px; }
.container-narrow p, .container-narrow li { color: var(--text-dim); }

/* ---------- hero ---------- */
.hero { text-align: center; padding: 20px 0 24px; }
.hero h1 {
  font-size: clamp(22px, 4vw, 32px);
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}
.hero p { color: var(--text-dim); margin: 0; font-size: 14.5px; }

/* ---------- duration selector ---------- */
.duration-row {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
.segmented { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.segmented button {
  border: none; border-radius: 0; background: var(--bg-inset);
  border-right: 1px solid var(--border);
  padding: 8px 16px;
  min-width: 56px;
}
.segmented button:last-child { border-right: none; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-contrast); font-weight: 600; }

/* ---------- live stats ---------- */
.stats-row {
  display: flex;
  justify-content: center;
  gap: 28px;
  margin-bottom: 16px;
  font-variant-numeric: tabular-nums;
}
.stat { text-align: center; }
.stat .stat-value { display: block; font-size: 26px; font-weight: 700; color: var(--accent); line-height: 1.1; }
.stat .stat-label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); margin-top: 2px; }

/* ---------- typing surface ---------- */
.type-wrap { position: relative; }
.type-input-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.type-surface {
  background: var(--bg-raised);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 22px 26px;
  cursor: text;
  max-height: 4.8em;
  overflow: hidden;
  position: relative;
}
.type-surface:focus-within { border-color: var(--accent-dim); }
.passage {
  font-size: 21px;
  line-height: 1.6em;
  letter-spacing: .01em;
  color: var(--text-faint);
  word-break: break-word;
}
.char { position: relative; white-space: pre-wrap; }
.char.correct { color: var(--text); }
.char.incorrect { color: var(--incorrect); background: var(--incorrect-bg); border-radius: 2px; }
.char.current::before {
  content: "";
  position: absolute;
  left: -1px; top: 1px; bottom: 1px;
  width: 2px;
  background: var(--accent);
  animation: caret-blink 1s step-end infinite;
}
@keyframes caret-blink { 50% { opacity: 0; } }

.type-hint {
  text-align: center;
  color: var(--text-faint);
  font-size: 12.5px;
  margin: 10px 0 0;
}

.controls-row {
  display: flex;
  justify-content: center;
  margin-top: 18px;
}

/* ---------- results screen ---------- */
.results-panel {
  background: var(--bg-raised);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 28px;
  text-align: center;
}
.results-headline { display: flex; justify-content: center; gap: 40px; flex-wrap: wrap; margin-bottom: 10px; }
.results-headline .stat-value { font-size: 44px; }
.results-headline .stat-label { font-size: 12px; }

.rating-badge {
  display: inline-block;
  font-weight: 700;
  font-size: 14px;
  padding: 4px 14px;
  border-radius: 999px;
  margin-top: 6px;
  border: 1px solid var(--accent-dim);
  color: var(--accent);
}
.rating-message { color: var(--text-dim); font-size: 13px; margin: 8px 0 0; }

.results-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 24px 0;
  text-align: left;
}
@media (min-width: 520px) { .results-grid { grid-template-columns: repeat(4, 1fr); } }
.results-grid .cell {
  background: var(--bg-inset);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 10px 12px;
}
.results-grid .cell .k { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); }
.results-grid .cell .v { display: block; font-size: 18px; font-weight: 700; margin-top: 2px; }
.results-grid .cell.correct .v { color: var(--correct); }
.results-grid .cell.incorrect .v { color: var(--incorrect); }

.best-line { color: var(--text-dim); font-size: 13px; margin: 4px 0 20px; }
.best-line strong { color: var(--accent); }

/* ---------- history ---------- */
.history-section { margin-top: 24px; text-align: left; }
.history-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-faint);
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#sparkline { color: var(--accent); width: 140px; height: 30px; }
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.history-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-inset);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
}
.history-list .h-wpm { font-weight: 700; color: var(--text); }
.history-list .h-meta { color: var(--text-faint); }
.history-empty { justify-content: center; color: var(--text-faint); }

/* ---------- about section ---------- */
.about-section { margin-top: 40px; }
.about-section h2 { font-size: 16px; }
.about-section p { color: var(--text-dim); }

/* ---------- faq / article list items ---------- */
.faq-item { margin-bottom: 18px; }
.faq-item h3 { font-size: 15px; margin: 0 0 6px; }
.faq-item p { margin: 0; color: var(--text-dim); }

/* ---------- footer ---------- */
.site-footer {
  border-top: 1px solid var(--border-soft);
  margin-top: 40px;
}
.footer-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 24px 20px 40px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: space-between;
  color: var(--text-faint);
  font-size: 12.5px;
}
.footer-links { display: flex; gap: 16px; flex-wrap: wrap; }
.footer-links a { color: var(--text-dim); }

/* ---------- misc ---------- */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

::selection { background: var(--accent); color: var(--accent-contrast); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-inset); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
