/* ===========================================================
   TypeFlow — design system
   =========================================================== */
:root {
  --accent: #4dd0c4;
  --bg: #08080b;
  --bg-soft: #0d0d12;
  --surface: #111118;
  --surface-2: #16161f;
  --border: rgba(255, 255, 255, .07);
  --border-strong: rgba(255, 255, 255, .13);
  --text: #e7e7ee;
  --text-dim: #9a9aa8;
  --text-faint: #4a4a57;
  --bad: #ff6b6b;
  --extra: #b85c5c;
  --radius: 14px;
  --radius-sm: 9px;
  --mono: 'JetBrains Mono', 'SF Mono', 'Cascadia Code', 'Roboto Mono', ui-monospace, Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --shadow: 0 24px 60px -20px rgba(0, 0, 0, .7);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(1100px 600px at 50% -10%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 60%),
    radial-gradient(900px 500px at 90% 110%, rgba(91, 157, 249, .05), transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  letter-spacing: .1px;
}
.hidden { display: none !important; }
.muted { color: var(--text-dim); }
.small { font-size: 12.5px; }
kbd {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  color: var(--text-dim);
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 15px;
  color: var(--bg);
  background: var(--accent);
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 9px;
  box-shadow: 0 6px 18px -6px color-mix(in srgb, var(--accent) 70%, transparent);
}
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -.2px; color: var(--text); }
.nav { display: flex; gap: 6px; margin-right: auto; }
.nav-link {
  text-decoration: none;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 8px;
  transition: .16s;
}
.nav-link:hover { color: var(--text); background: rgba(255, 255, 255, .04); }
.nav-link.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 36px; height: 36px;
  border-radius: 9px;
  cursor: pointer;
  display: grid; place-items: center;
  transition: .16s;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); background: rgba(255, 255, 255, .03); }

/* ---------- Layout ---------- */
main { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 40px 28px 60px; }
.view { animation: fade .35s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.page-head { margin-bottom: 26px; }
.page-head h1 { font-size: 26px; font-weight: 700; letter-spacing: -.5px; margin: 0 0 6px; }
.page-head p { margin: 0; font-size: 14.5px; }
.ad-slot {
  width: 100%;
  max-width: 970px;
  margin: 32px auto;
  overflow: hidden;
}
.ad-slot:first-child { margin-top: 0; }
.ad-slot:last-child { margin-bottom: 0; }
.ad-slot .adsbygoogle { width: 100%; }
/* ---------- Config bar ---------- */
.config {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  width: fit-content;
  margin: 0 auto 30px;
  box-shadow: 0 10px 30px -20px rgba(0, 0, 0, .8);
}
.mode-tabs { display: flex; gap: 4px; padding-right: 10px; border-right: 1px solid var(--border); }
.mode-tab, .opt {
  font-family: var(--mono);
  font-size: 13px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  padding: 6px 13px;
  border-radius: 8px;
  cursor: pointer;
  transition: .15s;
}
.mode-tab:hover, .opt:hover { color: var(--text-dim); }
.mode-tab.active, .opt.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 13%, transparent); }
.opts { display: flex; gap: 2px; }
.lesson-tag {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  padding: 6px 12px;
  border-left: 1px solid var(--border);
}
.custom-panel {
  max-width: 760px;
  margin: -12px auto 28px;
  display: grid;
  gap: 12px;
}
.practice-meta {
  display: grid;
  grid-template-columns: 1fr 150px;
  gap: 12px;
}
.field {
  display: grid;
  gap: 6px;
}
.field span {
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.field input,
.field select {
  width: 100%;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font: 13.5px var(--sans);
  outline: none;
}
.field select { cursor: pointer; }
.field input:focus,
.field select:focus { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.mini-field {
  display: grid;
  gap: 5px;
  min-width: 86px;
}
.mini-field span {
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .8px;
  text-transform: uppercase;
}
.mini-field input {
  width: 100%;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  font: 13px var(--mono);
}
.goal-settings { align-items: end; }
.upload-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.upload-row input[type="file"] {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}
.upload-btn {
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 34%, var(--border));
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: .16s;
}
.upload-btn:hover {
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  transform: translateY(-1px);
}
.upload-status {
  color: var(--text-dim);
  font-size: 12.5px;
}
.upload-status.bad { color: var(--bad); }
.custom-panel textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  outline: none;
}
.custom-panel textarea:focus { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.custom-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; }
.practice-library {
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.library-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.library-title { color: var(--text); font-size: 14px; font-weight: 700; }
.library-sub { color: var(--text-faint); font-size: 12px; margin-top: 2px; }
.library-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.library-actions input[type="file"] {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}
.import-btn { margin: 0; }
.danger-text { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--border)); }
.library-tools {
  display: grid;
  grid-template-columns: 1fr 150px 170px;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-2) 42%, transparent);
}
.library-search,
.library-select {
  width: 100%;
  min-width: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px;
  font: 13px var(--sans);
}
.library-search::placeholder { color: var(--text-faint); }
.practice-list { display: grid; }
.practice-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}
.practice-row:last-child { border-bottom: 0; }
.practice-info { min-width: 0; }
.practice-title {
  color: var(--text);
  font-size: 13.5px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.practice-sub { color: var(--text-faint); font-size: 12px; margin-top: 4px; }
.practice-trend { color: var(--text-dim); font-size: 12px; margin-top: 6px; }
.practice-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.practice-tag {
  color: var(--text-dim);
  background: color-mix(in srgb, var(--surface-2) 78%, transparent);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 7px;
  font-size: 11px;
  line-height: 1.2;
}
.practice-actions { display: flex; gap: 7px; flex-shrink: 0; }
.mini-btn {
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 12px;
  cursor: pointer;
}
.mini-btn:hover { color: var(--text); border-color: var(--border-strong); }
.mini-btn:disabled { opacity: .5; cursor: not-allowed; }
.primary-mini { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 36%, var(--border)); }
.danger-mini { color: var(--bad); }
.library-empty {
  color: var(--text-faint);
  font-size: 12.5px;
  padding: 16px;
}
.practice-history {
  width: 100%;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: grid;
  gap: 6px;
}
.history-line {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 12px;
}

/* ---------- Live stats ---------- */
.live {
  display: flex;
  gap: 34px;
  justify-content: center;
  margin-bottom: 18px;
  height: 30px;
}
.live-item { display: flex; align-items: baseline; gap: 7px; }
.live-val { font-family: var(--mono); font-size: 22px; font-weight: 700; color: var(--accent); }
.live-lab { font-size: 11px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--text-faint); }

/* ---------- Typing area ---------- */
#typing-area {
  position: relative;
  outline: none;
  cursor: text;
  padding: 4px 2px;
  user-select: none;
}
#words-viewport {
  height: 132px;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 14%, #000 82%, transparent);
          mask-image: linear-gradient(180deg, transparent, #000 14%, #000 82%, transparent);
}
#words {
  font-family: var(--mono);
  font-size: 27px;
  line-height: 44px;
  letter-spacing: .5px;
  display: flex;
  flex-wrap: wrap;
  gap: 0 14px;
  transition: transform .2s ease;
  will-change: transform;
}
.tw { display: inline-flex; }
.tw.line-active .tc {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 8%, transparent);
}
.tw.line-active.active .tc {
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 13%, transparent);
}
.tc { color: var(--text-faint); transition: color .05s; position: relative; }
.tc.ok { color: var(--text); }
.tc.bad { color: var(--bad); }
.tc.miss { color: color-mix(in srgb, var(--bad) 55%, var(--text-faint)); }
.tc.extra { color: var(--extra); opacity: .8; }
.tc.struct {
  color: color-mix(in srgb, var(--accent) 55%, var(--text-faint));
  font-weight: 700;
}
.tc.struct.ok { color: var(--accent); }
#caret {
  position: absolute;
  top: 0; left: 0;
  width: 2.5px;
  height: 32px;
  background: var(--accent);
  border-radius: 2px;
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 70%, transparent);
  animation: blink 1.1s step-end infinite;
}
#caret.smooth { transition: transform .09s cubic-bezier(.2, .9, .3, 1); }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .15; } }
.focus-hint {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--text-dim);
  background: color-mix(in srgb, var(--bg) 35%, transparent);
  backdrop-filter: blur(3px);
  border-radius: 12px;
}
#typing-area.blurred #words { filter: blur(4px); opacity: .55; }
#typing-area.blurred #caret { display: none; }
#typing-area.blurred .focus-hint { display: flex; }
.input-notice {
  max-width: 760px;
  margin: 14px auto 0;
  color: var(--text-dim);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 12.5px;
  line-height: 1.45;
  text-align: center;
}
.input-notice.warn {
  color: var(--bad);
  border-color: color-mix(in srgb, var(--bad) 35%, var(--border));
  background: color-mix(in srgb, var(--bad) 8%, var(--surface));
}

.test-actions { display: flex; justify-content: center; margin-top: 20px; }
.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  padding: 9px 18px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: .16s;
}
.ghost-btn:hover { color: var(--text); border-color: var(--border-strong); background: rgba(255, 255, 255, .03); }
.primary-btn {
  background: var(--accent);
  color: #06110f;
  font-weight: 700;
  font-size: 14px;
  border: none;
  padding: 11px 26px;
  border-radius: 10px;
  cursor: pointer;
  transition: .16s;
  box-shadow: 0 12px 30px -12px color-mix(in srgb, var(--accent) 65%, transparent);
}
.primary-btn:link, .primary-btn:visited { color: #06110f; }
.primary-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.primary-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
  transform: none;
  filter: none;
}

/* ---------- Results ---------- */
#results { animation: fade .4s ease; }
.res-head { display: flex; align-items: center; gap: 40px; flex-wrap: wrap; margin-bottom: 26px; }
.res-hero-val {
  font-family: var(--mono);
  font-size: 84px;
  font-weight: 800;
  line-height: 1;
  color: var(--accent);
  letter-spacing: -2px;
}
.res-hero-lab { font-size: 13px; color: var(--text-dim); margin-top: 6px; }
.res-metrics { display: grid; grid-template-columns: repeat(2, auto); gap: 14px 34px; }
.rm-val { font-family: var(--mono); font-size: 24px; font-weight: 700; color: var(--text); }
.rm-lab { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-faint); margin-top: 2px; }
.coach-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 24%, var(--border));
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.coach-label { font-size: 15px; color: var(--text); font-weight: 700; margin-bottom: 5px; }
.coach-copy { color: var(--text-dim); font-size: 13.5px; line-height: 1.55; max-width: 650px; }
.coach-keys { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; min-width: 140px; }
.key-pill {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
  border-radius: 999px;
  padding: 5px 9px;
}
.scorecard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.score-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
}
.score-value {
  color: var(--text);
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 800;
}
.score-label {
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-top: 5px;
}
.score-note {
  color: var(--text-dim);
  font-size: 12.5px;
  margin-top: 8px;
}
.res-chart-wrap {
  height: 230px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 22px;
}
.res-actions { display: flex; gap: 12px; justify-content: center; }

/* ---------- Keyboard ---------- */
#keyboard-wrap { margin-top: 46px; }
.kb-toolbar { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; }
.toggle {
  font-size: 12.5px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-faint);
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  transition: .15s;
}
.toggle:hover { color: var(--text-dim); border-color: var(--border-strong); }
.toggle.on { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); background: color-mix(in srgb, var(--accent) 10%, transparent); }

.kb { display: flex; flex-direction: column; gap: 7px; align-items: center; max-width: 760px; margin: 0 auto; }
.kb.mobile-hidden { display: none; }
.kb-row { display: flex; gap: 7px; width: 100%; }
.kb-key {
  flex: 1 1 0;
  min-width: 0;
  height: 46px;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: 2px solid rgba(0, 0, 0, .4);
  border-radius: 9px;
  transition: transform .07s, background .12s, color .12s, border-color .12s;
  position: relative;
}
.kb-key.kb-spacer { background: transparent; border: none; }
.kb-home::after {
  content: ''; position: absolute; bottom: 7px; left: 50%; transform: translateX(-50%);
  width: 14px; height: 2px; border-radius: 2px; background: var(--text-faint);
}
.kb-zones .kb-key:not(.kb-spacer) {
  background: color-mix(in srgb, var(--fc) 14%, var(--surface));
  border-color: color-mix(in srgb, var(--fc) 30%, var(--border));
  color: color-mix(in srgb, var(--fc) 70%, var(--text));
}
.kb-key.kb-next {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 16px -4px color-mix(in srgb, var(--accent) 70%, transparent);
}
.kb-key.kb-hit { transform: translateY(2px); background: color-mix(in srgb, var(--accent) 24%, var(--surface)); color: var(--text); }
.kb-key.kb-bad { transform: translateY(2px); background: color-mix(in srgb, var(--bad) 28%, var(--surface)); color: #fff; }
.kb-heat {
  background: color-mix(in srgb, var(--bad) calc(var(--heat) * 85%), var(--surface)) !important;
  border-color: color-mix(in srgb, var(--bad) calc(var(--heat) * 70%), var(--border)) !important;
  color: var(--text) !important;
}

/* ---------- Lessons ---------- */
.lesson-summary {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12.5px;
  margin: -8px 0 18px;
}
.wordbook-section {
  display: grid;
  gap: 12px;
  margin: -6px 0 24px;
}
.wordbook-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: end;
}
.wordbook-sub {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 5px;
}
.wordbook-tools {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) 140px 140px;
  gap: 8px;
  min-width: min(520px, 100%);
}
.wordbook-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}
.wordbook-card {
  text-align: left;
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--border));
  border-radius: var(--radius);
  padding: 20px;
  transition: .18s;
}
.wordbook-card:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
  box-shadow: var(--shadow);
}
.wordbook-meter {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin-top: 14px;
}
.wordbook-meter span {
  display: block;
  height: 100%;
  background: var(--accent);
}
.wordbook-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}
.wordbook-preview {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.6;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.lesson-grid { display: grid; gap: 24px; }
.lesson-group { display: grid; gap: 10px; }
.lesson-group-title {
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.lesson-subgroup {
  display: grid;
  gap: 10px;
}
.lesson-subgroup-title {
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 700;
}
.lesson-group-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.lesson-card {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: .18s;
}
.lesson-card:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); box-shadow: var(--shadow); }
.lesson-card:disabled {
  cursor: not-allowed;
  opacity: .65;
  transform: none;
}
.lesson-card.done { border-color: color-mix(in srgb, var(--accent) 34%, var(--border)); background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.lesson-card.recommended { border-color: color-mix(in srgb, var(--accent) 65%, var(--border)); box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 20%, transparent); }
.lesson-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.lesson-name { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.lesson-status { font-family: var(--mono); font-size: 11px; color: var(--accent); white-space: nowrap; }
.lesson-hint { font-family: var(--mono); font-size: 12.5px; color: var(--text-dim); }
.lesson-target { color: var(--text-dim); font-size: 12px; margin-top: 12px; }
.lesson-goal { font-size: 12px; color: var(--text-faint); margin-top: 14px; }
.framed-empty {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

/* ---------- Stats ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(136px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card-value { font-family: var(--mono); font-size: 30px; font-weight: 800; color: var(--accent); letter-spacing: -1px; }
.card-label { font-size: 12.5px; color: var(--text-dim); margin-top: 6px; }
.stat-filters { display: flex; flex-wrap: wrap; gap: 8px; margin: -8px 0 18px; }
.filter-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12.5px;
  cursor: pointer;
}
.filter-chip.active {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 38%, var(--border));
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.stats-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 14px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.panel-title { font-size: 13px; font-weight: 600; color: var(--text-dim); margin-bottom: 16px; letter-spacing: .2px; }
.chart-box { position: relative; height: 240px; }
.chart-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--text-faint); font-size: 13.5px; }
.weak-list { display: flex; flex-direction: column; gap: 11px; }
.weak-trends { display: flex; flex-direction: column; gap: 10px; }
.weak-row { display: flex; align-items: center; gap: 12px; }
.trend-row { display: flex; align-items: center; gap: 10px; }
.weak-key { font-family: var(--mono); font-size: 15px; width: 22px; text-align: center; color: var(--text); }
.weak-bar { flex: 1; height: 8px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.weak-fill { display: block; height: 100%; background: linear-gradient(90deg, color-mix(in srgb, var(--bad) 55%, transparent), var(--bad)); border-radius: 5px; }
.weak-pct { font-family: var(--mono); font-size: 13px; color: var(--text-dim); width: 38px; text-align: right; }
.trend-copy { flex: 1; color: var(--text-dim); font-family: var(--mono); font-size: 13px; }
.trend-badge {
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 11px;
  padding: 4px 8px;
}
.trend-row.better .trend-badge { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.trend-row.worse .trend-badge { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--border)); }
.stats-diagnosis { display: grid; gap: 12px; }
.diagnosis-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.diagnosis-summary span {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--border));
  border-radius: 999px;
  padding: 5px 9px;
  font-family: var(--mono);
  font-size: 12px;
}
.diagnosis-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  background: color-mix(in srgb, var(--surface-2) 46%, transparent);
}
.diagnosis-label { color: var(--text); font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.diagnosis-copy { color: var(--text-dim); font-size: 12.5px; line-height: 1.55; }
.calendar-panel { grid-column: 1 / -1; }
.training-calendar { display: grid; gap: 14px; }
.calendar-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-dim);
  font-size: 12.5px;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(35, minmax(0, 1fr));
  gap: 6px;
}
.calendar-cell {
  aspect-ratio: 1;
  min-width: 0;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.calendar-cell.level-1 { background: color-mix(in srgb, var(--accent) 22%, var(--surface-2)); border-color: color-mix(in srgb, var(--accent) 20%, var(--border)); }
.calendar-cell.level-2 { background: color-mix(in srgb, var(--accent) 38%, var(--surface-2)); border-color: color-mix(in srgb, var(--accent) 32%, var(--border)); }
.calendar-cell.level-3 { background: color-mix(in srgb, var(--accent) 58%, var(--surface-2)); border-color: color-mix(in srgb, var(--accent) 48%, var(--border)); }
.calendar-cell.level-4 { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 14px -8px var(--accent); }

/* ---------- About / prose ---------- */
.prose { max-width: 680px; line-height: 1.75; color: var(--text-dim); font-size: 15px; overflow-wrap: anywhere; }
.prose h2 { color: var(--text); font-size: 18px; margin: 28px 0 8px; }
.prose h3 { color: var(--text); font-size: 15.5px; margin: 18px 0 4px; }
.prose strong { color: var(--text); }
.prose ul { padding-left: 20px; }
.prose li { margin: 6px 0; }
.prose kbd { margin: 0 1px; color: var(--text); }
.practice-link-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0 4px;
}
.practice-link-grid a {
  display: grid;
  gap: 3px;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,.025);
  color: var(--text-dim);
  text-decoration: none;
}
.practice-link-grid a:hover {
  border-color: rgba(77,208,196,.45);
  background: rgba(77,208,196,.06);
}
.practice-link-grid strong { font-size: 14px; }
.practice-link-grid span { font-size: 13px; line-height: 1.45; }

/* ---------- Footer ---------- */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 22px 28px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  max-width: 1040px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4, 4, 7, .72);
  backdrop-filter: blur(6px);
  animation: fade .2s ease;
}
.modal-card {
  width: min(480px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 8px 22px 22px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 0; border-bottom: 1px solid var(--border); }
.set-row:last-child { border-bottom: none; }
.set-label { font-size: 14.5px; font-weight: 600; color: var(--text); }
.set-desc { font-size: 12.5px; color: var(--text-dim); margin-top: 3px; }
.set-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.set-actions input[type="file"] {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}
.danger-actions .danger-btn { padding-inline: 12px; }
.accent-picker { display: flex; gap: 8px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; transition: .15s; }
.swatch:hover { transform: scale(1.12); }
.swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px currentColor; }
.danger-btn { background: color-mix(in srgb, var(--bad) 14%, transparent); border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent); color: var(--bad); font-size: 13px; padding: 8px 16px; border-radius: 9px; cursor: pointer; transition: .15s; }
.danger-btn:hover { background: color-mix(in srgb, var(--bad) 22%, transparent); }

/* switch */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 20px; cursor: pointer; transition: .2s; }
.slider::before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: var(--text-dim); border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: color-mix(in srgb, var(--accent) 30%, transparent); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); background: var(--accent); }

/* ---------- Article / guides ---------- */
.article { max-width: 760px; margin: 0 auto; }
.breadcrumb { font-size: 13px; color: var(--text-faint); margin-bottom: 22px; }
.breadcrumb a { color: var(--text-dim); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }
.article h1 { font-size: 32px; line-height: 1.18; letter-spacing: -.7px; margin: 0 0 14px; }
.article .lede { font-size: 17px; line-height: 1.7; color: var(--text-dim); margin: 0 0 6px; }
.article-meta { font-size: 12.5px; color: var(--text-faint); margin-bottom: 30px; padding-bottom: 22px; border-bottom: 1px solid var(--border); }
.article-toc {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  margin: -10px 0 30px;
}
.toc-title {
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .8px;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.article-toc ol {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 18px;
  padding-left: 20px;
  margin: 0;
}
.article-toc li { color: var(--text-faint); font-size: 13.5px; line-height: 1.45; }
.article-toc a { color: var(--text-dim); text-decoration: none; }
.article-toc a:hover { color: var(--accent); }
.article-body { font-size: 16px; line-height: 1.8; color: var(--text-dim); overflow-wrap: anywhere; }
.article-body h2 { scroll-margin-top: 90px; }
.article-body h2 { color: var(--text); font-size: 22px; letter-spacing: -.3px; margin: 38px 0 12px; }
.article-body h3 { color: var(--text); font-size: 17px; margin: 26px 0 8px; }
.article-body p { margin: 0 0 16px; }
.article-body strong { color: var(--text); }
.article-body a { color: var(--accent); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.article-body a:visited { color: color-mix(in srgb, var(--accent) 84%, var(--text)); }
.article-body ul, .article-body ol { padding-left: 22px; margin: 0 0 16px; }
.article-body li { margin: 7px 0; }
.article-body kbd { margin: 0 1px; color: var(--text); }
.data-table { width: 100%; border-collapse: collapse; margin: 8px 0 22px; font-size: 14.5px; }
.data-table th, .data-table td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--text); font-weight: 600; background: var(--surface); }
.data-table td { color: var(--text-dim); }
.callout { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 10px; padding: 16px 18px; margin: 22px 0; font-size: 15px; }
.cta-card { display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap; background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 13%, var(--surface)), var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border)); border-radius: var(--radius); padding: 22px 24px; margin: 32px 0; }
.cta-card .cta-text { font-size: 15.5px; color: var(--text); font-weight: 600; }
.cta-card .cta-sub { font-size: 13px; color: var(--text-dim); margin-top: 3px; font-weight: 400; }
.cta-card .primary-btn {
  color: #06110f !important;
  background: #4dd0c4;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-shadow: none;
  -webkit-text-fill-color: #06110f;
}
.cta-card .primary-btn::selection { color: #06110f; background: rgba(255, 255, 255, .35); }
.faq-block {
  margin-top: 36px;
  display: grid;
  gap: 12px;
}
.faq-block h2 { margin-bottom: 2px; }
.faq-item {
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 15px 16px;
}
.faq-item h3 {
  margin: 0 0 6px;
  color: var(--text);
  font-size: 15px;
}
.faq-item p {
  margin: 0;
  color: var(--text-dim);
  font-size: 14.5px;
  line-height: 1.65;
}
.related { margin-top: 44px; padding-top: 26px; border-top: 1px solid var(--border); }
.related-title { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-faint); margin-bottom: 14px; }
.guide-section { margin: 34px 0; }
.guide-section h2 {
  color: var(--text);
  font-size: 18px;
  margin: 0 0 12px;
  letter-spacing: -.2px;
}
.guide-section-intro {
  max-width: 720px;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.6;
  margin: -4px 0 14px;
}
.related-grid, .guide-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.related-card { display: block; text-decoration: none; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px; transition: .16s; }
.related-card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); transform: translateY(-2px); box-shadow: var(--shadow); }
.related-card .rc-title { color: var(--text); font-size: 14.5px; font-weight: 600; margin-bottom: 5px; }
.related-card .rc-desc { color: var(--text-dim); font-size: 12.5px; line-height: 1.55; }

/* ---------- Legal and utility pages ---------- */
.legal-page {
  max-width: 760px;
  margin: 0 auto;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1.78;
}
.legal-page h1 {
  color: var(--text);
  font-size: 34px;
  line-height: 1.15;
  margin: 0 0 12px;
}
.legal-page .lede {
  font-size: 17px;
  line-height: 1.7;
  margin: 0 0 8px;
}
.legal-page h2 {
  color: var(--text);
  font-size: 20px;
  margin: 34px 0 10px;
}
.legal-page p { margin: 0 0 15px; }
.legal-page a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 42%, transparent);
}
.legal-updated {
  color: var(--text-faint);
  font-size: 13px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
}
.not-found {
  max-width: 720px;
  min-height: 48vh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.eyebrow {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  margin-bottom: 12px;
}
.not-found h1 {
  color: var(--text);
  font-size: clamp(36px, 7vw, 68px);
  line-height: 1;
  margin: 0 0 16px;
}
.not-found p {
  max-width: 560px;
  font-size: 17px;
  line-height: 1.7;
}
.not-found-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}
.analytics-page { max-width: 980px; margin: 0 auto; }
.analytics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.analytics-panels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.analytics-list { display: grid; gap: 8px; }
.analytics-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 14px;
  align-items: baseline;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  padding: 8px 0;
}
.analytics-row:last-child { border-bottom: 0; }
.analytics-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.analytics-row strong {
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
}
.analytics-row small {
  grid-column: 1 / -1;
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1.45;
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  main { padding: 26px 16px 48px; }
  .ad-slot { margin-block: 24px; }
  #words { font-size: 22px; line-height: 38px; }
  #words-viewport { height: 116px; }
  .res-head { gap: 24px; }
  .res-hero-val { font-size: 60px; }
  .practice-meta { grid-template-columns: 1fr; }
  .wordbook-head { align-items: stretch; flex-direction: column; }
  .wordbook-tools { grid-template-columns: 1fr; min-width: 0; }
  .wordbook-actions > * { flex: 1 1 calc(50% - 8px); text-align: center; justify-content: center; }
  .upload-row { align-items: stretch; flex-direction: column; }
  .upload-btn { text-align: center; }
  .custom-actions { justify-content: stretch; }
  .custom-actions > * { flex: 1 1 calc(50% - 8px); justify-content: center; }
  .library-head { align-items: stretch; flex-direction: column; }
  .library-actions { justify-content: stretch; }
  .library-actions > * { flex: 1 1 calc(50% - 8px); justify-content: center; text-align: center; }
  .library-tools { grid-template-columns: 1fr; }
  .practice-row { align-items: flex-start; flex-direction: column; }
  .practice-actions { width: 100%; flex-wrap: wrap; }
  .practice-actions .mini-btn { flex: 1; }
  .coach-panel { align-items: flex-start; flex-direction: column; }
  .coach-keys { justify-content: flex-start; }
  .scorecard { grid-template-columns: 1fr; }
  .analytics-grid, .analytics-panels { grid-template-columns: 1fr; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-grid { grid-template-columns: 1fr; }
  .calendar-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .calendar-meta { align-items: flex-start; flex-direction: column; }
  .modal-card { max-height: 88vh; overflow: auto; }
  .set-row { align-items: stretch; flex-direction: column; }
  .set-actions { justify-content: stretch; }
  .set-actions > * { flex: 1 1 100%; justify-content: center; text-align: center; }
  .data-table { display: block; overflow-x: auto; white-space: nowrap; }
  .article-toc ol { grid-template-columns: 1fr; }
  .article-toc { padding: 14px 15px; }
  .legal-page h1 { font-size: 30px; }
  .not-found { min-height: 42vh; }
  .not-found-actions > * { flex: 1 1 100%; justify-content: center; text-align: center; }
  .practice-link-grid { grid-template-columns: 1fr; }
  .nav { gap: 0; overflow-x: auto; }
  .nav-link { padding: 7px 9px; font-size: 13px; }
  .topbar { gap: 14px; padding: 14px 16px; }
  #keyboard-wrap { margin-top: 28px; }
  #keyboard.mobile-hidden { display: none !important; }
  .kb-key { height: 38px; font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
