@font-face {
  font-family: 'JetBrains Mono';
  src: url('fonts/jetbrains-mono-400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('fonts/jetbrains-mono-500.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('fonts/jetbrains-mono-700.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #050807;
  --bg-soft: #0b110e;
  --panel: #0f1714;
  --line: #1c2722;
  --text: #e9efe9;
  --muted: #6f8077;
  --dim: #46554d;
  --green: #34d17a;
  --green-soft: #1f6f47;
  --green-deep: #103726;
  --correct: #cfe9da;
  --incorrect: #e2615a;
  --incorrect-bg: #2a1614;
  --caret: #34d17a;
  --radius: 10px;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(900px 500px at 50% -10%, #0a1611 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.shell {
  max-width: 960px;
  margin: 0 auto;
  min-height: 100%;
  padding: 22px clamp(16px, 4vw, 40px) 28px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

/* topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.brand .logo { color: var(--green); }
.brand-mark { width: 22px; height: 22px; display: block; flex: none; }
.brand .name { color: var(--text); font-size: 15px; }
.brand .name-b { color: var(--green); }
.topnav { display: flex; gap: 8px; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}
.ghost {
  font-size: 13px;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}
.ghost:hover { color: var(--green); background: var(--bg-soft); }
.ghost.danger:hover { color: var(--incorrect); }

/* config */
.config {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 13px;
}
.config-group { display: flex; gap: 4px; }
.config-sep {
  width: 1px;
  align-self: stretch;
  background: var(--line);
  margin: 2px 6px;
}
.opt {
  color: var(--muted);
  padding: 6px 11px;
  border-radius: 7px;
  transition: color 0.15s, background 0.15s;
  font-size: 13px;
}
.opt:hover { color: var(--text); }
.opt.active { color: var(--green); background: var(--green-deep); }

/* stage */
.stage { flex: 1; display: flex; flex-direction: column; justify-content: center; }

.statline {
  display: flex;
  align-items: baseline;
  gap: 26px;
  color: var(--muted);
  margin-bottom: 18px;
  font-size: 14px;
  min-height: 30px;
}
.stat b { color: var(--green); font-size: 22px; font-weight: 500; margin-right: 6px; }
.stat i { font-style: normal; }
.drill-tag, #drill-tag {
  color: var(--green);
  border: 1px solid var(--green-soft);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  letter-spacing: 1px;
}

/* typer */
.typer {
  position: relative;
  outline: none;
  cursor: text;
  user-select: none;
}
.words {
  font-size: 27px;
  line-height: 1.65;
  height: calc(1.65em * 3);
  overflow: hidden;
  color: var(--dim);
  letter-spacing: 0.5px;
  white-space: pre-wrap;
  word-break: break-word;
}
.words-inner {
  transition: transform 0.18s ease;
  will-change: transform;
}
.char { position: relative; }
.char.correct { color: var(--correct); }
.char.incorrect { color: var(--incorrect); }
.char.incorrect.space { background: var(--incorrect-bg); border-radius: 2px; }

.caret {
  position: absolute;
  top: 0;
  left: 0;
  width: 2px;
  height: 1.65em;
  background: var(--caret);
  border-radius: 2px;
  transition: left 0.08s ease, top 0.08s ease;
  animation: blink 1.05s steps(1) infinite;
}
.typer.typing .caret { animation: none; }
@keyframes blink { 50% { opacity: 0.15; } }

.blur-note {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 8, 7, 0.55);
  backdrop-filter: blur(3px);
  color: var(--muted);
  font-size: 15px;
  border-radius: var(--radius);
}

.hint {
  color: var(--dim);
  font-size: 13px;
  margin-top: 22px;
}
.hint kbd {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 12px;
  color: var(--muted);
}

/* results */
.result-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 1.4fr;
  gap: 30px;
  align-items: start;
}
.result-big {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.metric b { display: block; font-size: 40px; font-weight: 500; color: var(--green); }
.metric i { font-style: normal; color: var(--muted); font-size: 13px; }

.weakspots h3 {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.5px;
}
.weak-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.weak-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
}
.weak-pair {
  font-weight: 500;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 9px;
  min-width: 74px;
  text-align: center;
}
.weak-bar { flex: 1; height: 6px; background: var(--bg-soft); border-radius: 4px; overflow: hidden; }
.weak-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--green-soft), var(--green)); }
.weak-meta { color: var(--muted); font-size: 12px; min-width: 96px; text-align: right; }
.dwell-note { color: var(--dim); font-size: 12.5px; margin-top: 14px; }

.result-actions { display: flex; gap: 12px; margin-top: 28px; flex-wrap: wrap; }
.primary, .accent {
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.primary { background: var(--bg-soft); border: 1px solid var(--line); color: var(--text); }
.primary:hover { border-color: var(--green-soft); color: var(--green); }
.accent { background: var(--green); color: #04140c; }
.accent:hover { background: #44e389; }
.accent:disabled { background: var(--bg-soft); color: var(--dim); cursor: not-allowed; border: 1px solid var(--line); }
.primary kbd, .accent kbd { font-size: 11px; opacity: 0.7; margin-left: 6px; }

/* raw stats tables */
.raw-stats { margin-top: 30px; border-top: 1px solid var(--line); padding-top: 14px; }
.raw-stats summary { color: var(--muted); cursor: pointer; font-size: 13px; }
.raw-stats summary:hover { color: var(--green); }
.tables { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; margin-top: 16px; }
.table-block h4 { margin: 0 0 8px; font-size: 12px; color: var(--dim); font-weight: 500; }
.table-block table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table-block th { text-align: left; color: var(--dim); font-weight: 500; padding: 3px 6px; border-bottom: 1px solid var(--line); }
.table-block td { padding: 3px 6px; color: var(--muted); }
.table-block tr td:first-child { color: var(--text); }
.flag-cv { color: var(--incorrect); }

/* feedback */
.feedback-title { font-size: 16px; color: var(--green); font-weight: 500; margin: 0 0 18px; }
.feedback-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.feedback-list li { display: flex; align-items: center; gap: 14px; font-size: 15px; }
.fb-pair { min-width: 74px; text-align: center; padding: 3px 9px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg-soft); }
.fb-state { font-size: 13px; min-width: 120px; }
.fb-up { color: var(--green); }
.fb-down { color: var(--incorrect); }
.fb-flat { color: var(--muted); }
.fb-mastered { color: var(--green); font-weight: 500; }
.fb-meta { color: var(--muted); font-size: 12.5px; }
.feedback-progress { color: var(--muted); font-size: 13px; margin-top: 20px; }

.footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  text-align: center;
}
.footer-tag { color: var(--dim); }
.footer-credit {
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 2px;
  text-transform: lowercase;
  opacity: 0.8;
}
.footer-credit::before { content: '— '; opacity: 0.6; }

.hidden { display: none !important; }

@media (max-width: 680px) {
  .result-grid { grid-template-columns: 1fr; }
  .tables { grid-template-columns: 1fr; }
  .words { font-size: 22px; }
  .statline { gap: 16px; }
}
