/* ============ keypress — design tokens ============ */
:root {
  /* surfaces */
  --bg: #131418;
  --surface: #191a1f;
  --surface-active: #1e1f26;
  --key-bg: #212228;

  /* text */
  --text: #e8e6df;
  --text-secondary: #a4a7b0;
  --text-muted: #7a7d86;
  --text-faint: #54565e;
  --char-pending: #4d4f57;
  --key-text: #8f929b;
  --key-text-tinted: #c9ccd3;

  /* brand */
  --accent: #e2b04a;
  --accent-hover: #efc879;
  --on-accent: #131418;
  --accent-glow: rgba(226, 176, 74, .22);
  --accent-soft: rgba(226, 176, 74, .14);

  /* semantic */
  --error: #e0685b;
  --error-soft: rgba(224, 104, 91, .14);
  --error-border: rgba(224, 104, 91, .4);
  --error-ws: rgba(224, 104, 91, .28);
  --success: #74c48a;
  --success-border: rgba(116, 196, 138, .4);
  --warn: #c9995a;

  /* borders */
  --border-subtle: rgba(255, 255, 255, .06);
  --border-soft: rgba(255, 255, 255, .08);
  --border-strong: rgba(255, 255, 255, .14);
  --border-stronger: rgba(255, 255, 255, .16);
  --border-hover: rgba(255, 255, 255, .28);

  /* type */
  --font-sans: 'Space Grotesk', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  /* shape & motion */
  --radius-btn: 11px;
  --radius-card: 16px;
  --radius-tile: 14px;
  --radius-key: 8px;
  --speed-ui: .15s;
  --speed-key: .08s;
}

/* ============ base ============ */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

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

button { font-family: inherit; cursor: pointer; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@keyframes caretBlink { 0%, 45% { opacity: 1; } 55%, 100% { opacity: 0; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.app { min-height: 100vh; display: flex; flex-direction: column; }
.main { flex: 1; display: flex; flex-direction: column; }

/* ============ top bar ============ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 40px;
  border-bottom: 1px solid var(--border-subtle);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  background: none;
  border: none;
  padding: 0;
  color: inherit;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--on-accent);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 17px;
}

.brand-name { font-weight: 600; font-size: 18px; letter-spacing: -.01em; }

.nav { display: flex; align-items: center; gap: 26px; }

.nav-link {
  background: none;
  border: none;
  padding: 0;
  font-size: 14px;
  color: var(--text-secondary);
  transition: color var(--speed-ui);
}
.nav-link:hover { color: var(--text); }

/* ============ buttons ============ */
.btn {
  border-radius: var(--radius-btn);
  font-weight: 500;
  transition: background var(--speed-ui), border-color var(--speed-ui), color var(--speed-ui);
}

.btn-primary {
  background: var(--accent);
  border: none;
  color: var(--on-accent);
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-stronger);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--border-hover); }

.btn-sm { padding: 8px 16px; border-radius: 8px; font-size: 14px; border-color: var(--border-strong); }
.btn-md { padding: 14px 27px; font-size: 15px; }
.btn-lg { padding: 15px 29px; font-size: 16px; }

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  color: var(--accent);
}
.link-btn:hover { color: var(--accent-hover); }

/* ============ screens ============ */
.screen { display: none; }
.screen.active { display: block; }

.kicker {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--accent);
}

/* ============ landing ============ */
.screen-landing.active {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 64px 24px;
  animation: fadeUp .4s ease both;
}

.screen-landing .kicker { margin-bottom: 22px; }

.hero-title {
  font-size: clamp(42px, 8vw, 72px);
  line-height: 1.02;
  letter-spacing: -.03em;
  font-weight: 700;
  margin: 0 0 22px;
  max-width: 14ch;
}

.hero-sub {
  font-size: 19px;
  line-height: 1.55;
  color: var(--text-secondary);
  max-width: 52ch;
  margin: 0 0 40px;
}

.hero-actions { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }

.hero-stats { display: flex; gap: 44px; margin-top: 64px; flex-wrap: wrap; justify-content: center; }
.hero-stat { text-align: left; }
.hero-stat-value { font-family: var(--font-mono); font-size: 30px; font-weight: 700; color: var(--text); }
.hero-stat-label { font-size: 13px; color: var(--text-muted); }

/* ============ level select ============ */
.screen-levels.active {
  flex: 1;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
  padding: 52px 40px 64px;
  animation: fadeUp .35s ease both;
}

.section-title { font-size: 36px; letter-spacing: -.02em; font-weight: 700; margin: 0 0 8px; }
.section-sub { font-size: 16px; color: var(--text-secondary); margin: 0 0 34px; }

.level-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }

.level-card {
  cursor: pointer;
  border-radius: var(--radius-card);
  padding: 22px;
  background: var(--surface);
  border: 1.5px solid var(--border-soft);
  transition: border-color var(--speed-ui), background var(--speed-ui);
  min-height: 200px;
  display: flex;
  flex-direction: column;
}
.level-card:hover { border-color: var(--border-hover); }
.level-card.active { background: var(--surface-active); border-color: var(--accent); }
.level-card.active:hover { border-color: var(--accent); }

.level-card-top { display: flex; align-items: center; justify-content: space-between; }
.level-num { font-family: var(--font-mono); font-size: 12px; color: var(--accent); }

.level-check {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}
.level-card.active .level-check { display: flex; }

.level-name { font-size: 22px; font-weight: 600; margin: 14px 0 6px; }
.level-desc { font-size: 14px; line-height: 1.5; color: var(--text-secondary); margin: 0 0 16px; }
.level-sample { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }

.levels-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 32px;
  align-items: flex-end;
  justify-content: space-between;
  margin-top: 34px;
  padding-top: 30px;
  border-top: 1px solid var(--border-subtle);
}

.footer-label {
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .1em;
  margin-bottom: 12px;
}

.mode-row { display: flex; gap: 10px; }

.mode-btn {
  text-align: left;
  border-radius: var(--radius-btn);
  padding: 12px 18px;
  background: transparent;
  border: 1.5px solid var(--border-strong);
  color: var(--text);
  transition: background var(--speed-ui), border-color var(--speed-ui), color var(--speed-ui);
}
.mode-btn:hover { border-color: var(--border-hover); }
.mode-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-hover);
}

.mode-title { display: block; font-weight: 600; font-size: 15px; }
.mode-sub { display: block; font-size: 12px; opacity: .7; margin-top: 2px; }

.targets { display: flex; gap: 28px; }
.target-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.target-value { font-family: var(--font-mono); font-size: 26px; font-weight: 700; }
.target-unit { font-size: 13px; color: var(--text-muted); font-weight: 400; }

/* ============ typing ============ */
.screen-typing.active {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
  padding: 26px 40px 40px;
}

.typing-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.typing-status-left { display: flex; align-items: center; gap: 10px; }

.btn-back {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  font-size: 16px;
  transition: border-color var(--speed-ui), color var(--speed-ui);
}
.btn-back:hover { border-color: var(--border-hover); color: var(--text); }

.typing-level { font-family: var(--font-mono); font-size: 13px; color: var(--accent); }
.typing-mode { font-size: 13px; color: var(--text-muted); }

.typing-stats { display: flex; gap: 30px; align-items: baseline; }
.stat { text-align: right; }
.stat-value { font-family: var(--font-mono); font-size: 30px; font-weight: 700; }
.stat-accent { color: var(--accent); }
.stat-unit { font-size: 12px; color: var(--text-muted); margin-left: 5px; }

.progress {
  height: 4px;
  background: rgba(255, 255, 255, .07);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 30px;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 3px;
  transition: width .12s linear;
}

.passage-wrap { flex: 1; display: flex; align-items: center; min-height: 180px; }

.passage {
  font-family: var(--font-mono);
  font-size: clamp(20px, 4vw, 30px);
  line-height: 1.85;
  letter-spacing: .01em;
  white-space: pre-wrap;
  word-break: break-word;
  width: 100%;
}

.ch { color: var(--char-pending); }
.ch.ok { color: var(--text); font-weight: 500; }
.ch.bad { color: var(--error); }
.ch.bad.ws { background: var(--error-ws); border-radius: 3px; padding: 0 1px; }
.ch.cur {
  color: var(--text);
  border-left: 2px solid var(--accent);
  margin-left: -2px;
  animation: caretBlink 1s step-end infinite;
}

.typing-lower { margin-top: 24px; }

.finger-hint {
  text-align: center;
  height: 22px;
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--text-secondary);
}

/* on-screen keyboard */
.keyboard { max-width: 760px; margin: 0 auto; }
.kb-row { display: flex; gap: 6px; justify-content: center; margin-bottom: 6px; }

.key {
  flex: 0 0 40px;
  height: 42px;
  border-radius: var(--radius-key);
  background: var(--key-bg);
  color: var(--key-text);
  border: 1px solid rgba(255, 255, 255, .05);
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 0 8px 6px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-mono);
  position: relative;
  transition: background var(--speed-key), box-shadow var(--speed-key);
}

.key.tinted {
  background: var(--tint-bg);
  color: var(--key-text-tinted);
  border-color: var(--tint-border);
}

.key.active {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
}

.key-bump {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 9px;
  height: 2px;
  border-radius: 2px;
  background: #666;
}
.key.active .key-bump { background: var(--on-accent); }

.typing-help { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-faint); }
.help-key { color: var(--text-muted); }

/* ============ results ============ */
.screen-results.active {
  flex: 1;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
  padding: 48px 40px 64px;
  animation: fadeUp .4s ease both;
}

.screen-results .kicker { letter-spacing: .14em; margin-bottom: 8px; }

.results-headline { font-size: 38px; letter-spacing: -.02em; font-weight: 700; margin: 0 0 30px; }

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

.tile {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-tile);
  padding: 22px;
  background: var(--surface);
}
.tile.pass { border-color: var(--success-border); }

.tile-label { font-size: 13px; color: var(--text-muted); margin-bottom: 8px; }
.tile-value { font-family: var(--font-mono); font-size: 46px; font-weight: 700; line-height: 1; }
.tile-unit { font-size: 15px; color: var(--text-muted); font-weight: 400; }

.tile-tag { font-size: 12px; margin-top: 8px; color: var(--warn); }
.tile-tag.pass { color: var(--success); }
.tile-tag-muted { color: var(--text-muted); }

.trouble {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-tile);
  padding: 24px;
  background: var(--surface);
  margin-bottom: 28px;
}

.trouble-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.trouble-sub { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }

.trouble-keys { display: flex; flex-wrap: wrap; gap: 12px; }
.trouble-keys[hidden] { display: none; }

.trouble-key { display: flex; flex-direction: column; align-items: center; gap: 6px; }

.trouble-key-cap {
  font-family: var(--font-mono);
  min-width: 44px;
  height: 44px;
  padding: 0 10px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  background: var(--error-soft);
  border: 1px solid var(--error-border);
  color: var(--error);
}

.trouble-key-count { font-size: 11px; color: var(--text-muted); }

.clean-run { font-size: 14px; color: var(--success); }

.results-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* ============ responsive ============ */
@media (max-width: 900px) {
  .topbar { padding: 16px 20px; }
  .nav { gap: 18px; }

  .screen-levels.active,
  .screen-results.active,
  .screen-typing.active { padding-left: 20px; padding-right: 20px; }

  .level-grid { grid-template-columns: 1fr; }
  .level-card { min-height: 0; }
  .levels-footer { align-items: flex-start; flex-direction: column; }

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

  .typing-stats { gap: 18px; }
  .stat-value { font-size: 24px; }
}

@media (max-width: 720px) {
  .key { flex: 0 1 40px; min-width: 0; height: 38px; padding: 0 5px 5px; font-size: 11px; }
  .kb-row { gap: 4px; margin-bottom: 4px; }
}

@media (max-width: 560px) {
  .keyboard { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .screen.active { animation: none; }
  .key, .progress-fill, .btn, .mode-btn, .level-card { transition: none; }
}
