:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --text: #1c2333;
  --muted: #667085;
  --border: #e2e6ef;
  --accent: #2f6fed;
  --accent-weak: #dbe6ff;
  --ok: #1a9d54;
  --ok-weak: #d6f4e3;
  --err: #d23c47;
  --err-weak: #fbe0e2;
  --warn: #c98a12;
  --warn-weak: #fbeecb;
  /* ревил-подсветка (§7 SPEC): оранж. подчёркивание в поле, розовая метка символа,
     тёмно-зелёный ТЕКСТ коррекции (контраст ≥4.5:1 на светлом фоне, не «зелёное на зелёном») */
  --field-bad: #e8710a;
  --field-mark: #ff2d7e;
  --field-mark-weak: rgba(255, 45, 126, .16);
  --ok-text: #0f7a3d;
  --ok-underline: #0b6b34;
  --a1: #1a9d54;
  --a2: #2f6fed;
  --b1: #8b46d6;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
:root[data-theme="dark"] {
  --bg: #0f1420;
  --surface: #171d2b;
  --surface-2: #1f2636;
  --text: #e7ebf3;
  --muted: #93a0b5;
  --border: #2a3346;
  --accent: #5b8cff;
  --accent-weak: #223052;
  --ok: #3fd07f;
  --ok-weak: #16351f;
  --err: #ff6b74;
  --err-weak: #3a1c1f;
  --warn: #e6b13f;
  --warn-weak: #3a2f12;
  --field-bad: #ffa657;
  --field-mark: #ff6fa5;
  --field-mark-weak: rgba(255, 111, 165, .22);
  --ok-text: #6ee7a0;
  --ok-underline: #8ff0b4;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

#app { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--accent), var(--b1));
  color: #fff; border-radius: 10px; font-size: 20px; font-weight: 800;
}
.brand-text { font-size: 18px; letter-spacing: .2px; }
.brand-text em { color: var(--muted); font-style: normal; font-weight: 500; }
.topnav { display: flex; align-items: center; gap: 6px; }
.topnav a {
  padding: 8px 12px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 14px;
}
.topnav a:hover { background: var(--surface-2); color: var(--text); }
.topnav a.active { color: var(--accent); background: var(--accent-weak); }
.ghost-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  width: 36px; height: 36px; border-radius: 9px; font-size: 16px;
}
.ghost-btn:hover { background: var(--surface-2); }

/* ---------- Layout ---------- */
.view { flex: 1; width: 100%; max-width: 980px; margin: 0 auto; padding: 28px 20px 60px; }
.footer {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 16px 20px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px;
}
.muted { color: var(--muted); }

/* ---------- Home ---------- */
.page-head { margin-bottom: 22px; }
.page-head h1 { margin: 0 0 6px; font-size: 26px; letter-spacing: -.3px; }
.page-head p { margin: 0; color: var(--muted); max-width: 62ch; }

.section-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px;
}
.section-card {
  display: flex; flex-direction: column; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); transition: transform .12s ease, border-color .12s ease;
}
.section-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.section-card .sc-icon { font-size: 28px; }
.section-card h3 { margin: 0; font-size: 18px; }
.section-card .sc-el { color: var(--muted); font-size: 14px; }
.section-card .sc-desc { color: var(--muted); font-size: 14px; margin: 0; }
.section-card .sc-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.level-badges { display: flex; gap: 6px; }
.lvl {
  font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; color: #fff;
}
.lvl.A1 { background: var(--a1); }
.lvl.A2 { background: var(--a2); }
.lvl.B1 { background: var(--b1); }
.lvl.outline { background: transparent; border: 1px solid var(--border); color: var(--muted); }

.progress-mini { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.bar { --pct: 0%; height: 8px; width: 88px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; width: var(--pct); background: var(--accent); border-radius: 999px; transition: width .3s ease; }

/* ---------- Section page ---------- */
.crumbs { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.crumbs a:hover { color: var(--text); }
.level-tabs { display: flex; gap: 8px; margin: 18px 0; flex-wrap: wrap; }
.level-tab {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 999px; font-weight: 600; font-size: 14px;
}
.level-tab.active { border-color: transparent; color: #fff; background: var(--accent); }
.level-tab.active[data-level="A1"] { background: var(--a1); }
.level-tab.active[data-level="A2"] { background: var(--a2); }
.level-tab.active[data-level="B1"] { background: var(--b1); }

.lesson-list { display: flex; flex-direction: column; gap: 10px; }
.lesson-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px;
  transition: border-color .12s ease, transform .12s ease;
}
.lesson-row:hover { transform: translateX(2px); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.lesson-row .lr-num { font-variant-numeric: tabular-nums; color: var(--muted); width: 28px; font-weight: 700; }
.lesson-row .lr-main { flex: 1; min-width: 0; }
.lesson-row .lr-title { font-weight: 650; }
.lesson-row .lr-sub { color: var(--muted); font-size: 13px; }
.lesson-row .lr-status { display: flex; align-items: center; gap: 8px; }
.check-dot { width: 22px; height: 22px; border-radius: 999px; display: grid; place-items: center; font-size: 13px; color: #fff; }
.check-dot.done { background: var(--ok); }
.check-dot.partial { background: var(--warn); }
.check-dot.todo { background: var(--surface-2); color: var(--muted); }

/* ---------- Lesson / dictation ---------- */
.player { display: flex; flex-direction: column; gap: 18px; }
.player-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.player-head h1 { margin: 0; font-size: 22px; }
.player-head .ph-sub { color: var(--muted); font-size: 14px; }

.sent-progress { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.dots { display: flex; gap: 5px; flex-wrap: wrap; max-width: 320px; }
.dots > button { width: 13px; height: 13px; padding: 0; appearance: none; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; }
.dots > button.done { background: var(--ok); border-color: var(--ok); }
.dots > button.current { outline: 2px solid var(--accent); outline-offset: 1px; }

.stage {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px;
}
.audio-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.big { font-size: 16px; padding: 12px 20px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn .kbd { font: 600 11px var(--mono); opacity: .7; border: 1px solid currentColor; border-radius: 5px; padding: 0 5px; }

.speed-group { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.speed-group button { border: 0; background: var(--surface); color: var(--muted); padding: 9px 12px; font-weight: 600; font-size: 13px; }
.speed-group button.active { background: var(--accent-weak); color: var(--accent); }

/* Поле ответа = обёртка с textarea (сверху) и зеркалом (сзади). Рамка/фон — на обёртке. */
.answer-wrap {
  position: relative; background: var(--bg);
  border: 2px solid var(--border); border-radius: 12px;
}
.answer-wrap:focus-within { border-color: var(--accent); }
.answer-wrap[data-state="correct"] { border-color: var(--ok); background: var(--ok-weak); }
.answer-wrap[data-state="wrong"] { border-color: var(--err); }
/* единственный источник типографских метрик — иначе поедут переносы между textarea и зеркалом */
.answer-wrap .answer-input,
.answer-wrap .answer-mirror {
  font: 20px/1.5 var(--sans);
  letter-spacing: 0; word-spacing: 2px; tab-size: 4;
  padding: 14px 16px; border: 0; margin: 0;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: normal;
  box-sizing: border-box; width: 100%;
}
.answer-input {
  position: relative; z-index: 1; display: block; resize: none; min-height: 64px; overflow: hidden;
  background: transparent; color: var(--text); caret-color: var(--accent); outline: none;
}
.answer-mirror {
  position: absolute; inset: 0; z-index: 0;
  color: transparent; pointer-events: none; overflow: hidden; user-select: none;
}
/* декорации зеркала, видимые сквозь прозрачный textarea */
.answer-mirror .field-bad {
  text-decoration: underline; text-decoration-color: var(--field-bad);
  text-decoration-thickness: 2px; text-underline-offset: 3px;
}
.answer-mirror .field-mark {
  background: var(--field-mark-weak); border-radius: 3px;
  box-shadow: inset 0 -2px 0 0 var(--field-mark);
}
.answer-mirror .field-soft { box-shadow: inset 0 -2px 0 0 var(--warn); }
.answer-mirror .field-ins { color: var(--field-mark); font-weight: 700; }

.feedback { margin-top: 16px; display: none; }
.feedback.show { display: block; }
.diff-line { font-size: 21px; line-height: 1.7; margin-bottom: 10px; word-spacing: 2px; }
.tok { padding: 1px 3px; border-radius: 5px; }
.tok.ok { color: var(--ok-text); background: none; }
.tok.plain { color: var(--text); }
.tok.opt { color: var(--muted); font-style: italic; } /* необязательное слово (артикль/местоимение), опущено */
/* слово-коррекция: зелёный ТЕКСТ (не фон — контраст), подчёркнут точный неверный символ */
.tok.fix { color: var(--ok-text); background: none; font-weight: 650; }
.tok.fix .c-bad { text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 3px; text-decoration-color: var(--ok-underline); }
.tok.bad { color: var(--err); background: var(--err-weak); text-decoration: line-through; text-decoration-thickness: 1px; }
.tok.miss { color: var(--muted); background: var(--surface-2); border: 1px dashed var(--border); }
.tok.accent { color: var(--warn); background: none; }
.tok.fix .c-acc, .tok.accent .c-acc { text-decoration: underline dotted var(--warn); text-underline-offset: 3px; }
.diff-meta { display: flex; align-items: center; gap: 14px; font-size: 14px; color: var(--muted); flex-wrap: wrap; }
.acc-pill { font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.acc-pill.hi { color: var(--ok); background: var(--ok-weak); }
.acc-pill.mid { color: var(--warn); background: var(--warn-weak); }
.acc-pill.lo { color: var(--err); background: var(--err-weak); }
.translation { margin-top: 12px; color: var(--muted); font-size: 15px; font-style: italic; }
.translation b { color: var(--text); font-style: normal; }

.player-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.hint-note { font-size: 13px; color: var(--muted); margin-top: 8px; }
.reveal { margin-top: 12px; font-size: 20px; color: var(--text); padding: 12px 14px; background: var(--surface-2); border-radius: 10px; display: none; }
.reveal.show { display: block; }

/* ---------- Complete banner ---------- */
.complete {
  text-align: center; padding: 30px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.complete .big-emoji { font-size: 48px; }
.complete h2 { margin: 8px 0; }
.score-big { font-size: 40px; font-weight: 800; }

/* ---------- Progress page ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.stat-card .sv { font-size: 30px; font-weight: 800; }
.stat-card .sl { color: var(--muted); font-size: 13px; }

.notice { background: var(--warn-weak); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); padding: 12px 14px; border-radius: 10px; font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 40px; }

/* ---------- Progressive reveal / extras ---------- */
.tok.mask { color: var(--muted); background: var(--surface-2); letter-spacing: 2px; border-radius: 5px; padding: 1px 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.tok.err { outline: 2px solid var(--err); outline-offset: 1px; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; }
.pron { margin-top: 12px; font-size: 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pron-w { cursor: pointer; border: 0; border-bottom: 2px dotted var(--muted); background: none; color: inherit; font: inherit; padding: 2px 0; }
.pron-w:hover { color: var(--accent); border-color: var(--accent); }

/* Видимый фокус для клавиатуры + меньше движения по системной настройке */
a:focus-visible, button:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

select.speed, .modal-row select {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 9px; padding: 8px 10px; font-weight: 600; font-size: 14px;
}

.tr-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.tr-list { max-height: 60vh; overflow-y: auto; }
.tr-row.current { border-color: var(--accent); background: var(--accent-weak); }

/* ---------- Settings modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(16, 24, 40, .45); padding: 20px;
}
.modal {
  width: min(460px, 100%); max-height: 86vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 4px; border-bottom: 1px solid var(--border);
}
.modal-row:last-child { border-bottom: 0; }
.modal-row span { font-size: 14px; }

/* ---------- Подсказки-чипы, хоткеи, skip-link ---------- */
.hints-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.hints-row:empty { display: none; }
.chip { border: 1px solid var(--border); background: var(--warn-weak); color: var(--text); padding: 4px 10px; border-radius: 999px; font-size: 14px; cursor: pointer; }
.chip:hover { border-color: var(--warn); }
:root[data-hotkeys="off"] .kbd { display: none; }

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 60;
  background: var(--accent); color: #fff; padding: 10px 14px; border-radius: 10px;
  font-weight: 600; transition: top .12s ease;
}
.skip-link:focus { top: 8px; }

/* ---------- Тач-таргеты 44px на мобильных ---------- */
@media (max-width: 560px) {
  .brand-text { font-size: 16px; }
  .diff-line { font-size: 18px; }
  .answer-wrap .answer-input, .answer-wrap .answer-mirror { font-size: 18px; }
  .view { padding: 20px 14px 50px; }
  .btn, .level-tab, .ghost-btn, select.speed, .modal-row select { min-height: 44px; }
  .dots > button { width: 16px; height: 16px; }
  .lesson-row { padding: 16px; }
}
