/* =========================================================================
   Тренажёр когортных упражнений — дизайн-система
   Белый/серый фон, пользовательский зелёный акцент, минимализм.
   Inter — интерфейс/текст; моноширинный — алгоритмические метки (T01,
   P1, D+2): это структурные идентификаторы, а не проза, и выделяются как
   единственная предметная типографическая пара (см. frontend-design).
   Фирменный элемент — сегментный индикатор этапов P1→P2→P3: он не
   декоративен, а буквально то, как устроен весь алгоритм.
   ========================================================================= */

:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --surface-2: #f1f2ee;
  --ink: #1b1d19;
  --ink-soft: #62685c;
  --ink-faint: #9aa094;
  --border: #e3e5de;
  --border-strong: #cdd0c7;

  --accent: #2f9e5c;
  --accent-ink: #ffffff;
  --accent-soft: color-mix(in srgb, var(--accent) 13%, white);
  --accent-line: color-mix(in srgb, var(--accent) 42%, white);
  --accent-dark: color-mix(in srgb, var(--accent) 78%, black);

  --err: #c13b2e;
  --err-bg: #fbebe8;
  --warn: #a9740f;
  --warn-bg: #fbf1de;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --shadow-card: 0 1px 2px rgba(27, 29, 25, 0.04), 0 4px 16px rgba(27, 29, 25, 0.05);
  --nav-h: 60px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { font-size: 16px; } /* якорь масштаба — переопределяется JS из сохранённого предпочтения размера */
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }
button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 16px; } /* 16px буквально, не rem — не даёт iOS зумить при фокусе независимо от выбранного пользователем размера */
a { color: var(--accent-dark); }
::selection { background: var(--accent-soft); }

body.has-bg-image { background-size: cover; background-position: center; background-repeat: no-repeat; }

.mono { font-family: var(--font-mono); letter-spacing: 0.01em; }

/* ---------- shell / layout ---------- */

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}

.screen {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px calc(var(--nav-h) + 28px);
}

.topbar {
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
  padding: 4px 16px 8px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.topbar h1 { font-size: 1.25rem; }
.topbar .sub { color: var(--ink-soft); font-size: 0.8125rem; }

.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  max-width: 640px;
  margin: 0 auto;
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--ink-faint);
  font-size: 0.75rem;
  font-weight: 600;
}
.bottom-nav a.active { color: var(--accent-dark); }
.bottom-nav svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; }

/* ---------- buttons ---------- */

.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.06s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--surface-2); color: var(--ink); }
.btn-ghost { background: transparent; color: var(--ink-soft); padding: 10px 12px; }
.btn-danger { background: var(--err-bg); color: var(--err); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 0.8125rem; border-radius: 7px; }

/* ---------- forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 0.8125rem; font-weight: 600; color: var(--ink-soft); }
.field input[type=text], .field input[type=password], .field input[type=number], .field textarea, .field select {
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  background: var(--surface);
  color: var(--ink);
  outline-offset: 2px;
}
.field input:focus-visible, .field textarea:focus-visible, .field select:focus-visible {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
}
.field textarea { resize: vertical; min-height: 90px; }
.hint { font-size: 0.75rem; color: var(--ink-faint); }
.error-text { font-size: 0.8125rem; color: var(--err); }

.choice-group { display: flex; gap: 8px; flex-wrap: wrap; }
.choice-chip {
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}
.choice-chip.selected { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-card);
}
.card + .card { margin-top: 12px; }
.card-title { font-size: 0.9375rem; font-weight: 700; margin-bottom: 2px; }
.card-sub { font-size: 0.8125rem; color: var(--ink-soft); }

.banner { border-radius: var(--radius-sm); padding: 12px 14px; font-size: 0.875rem; margin-bottom: 14px; }
.banner-err { background: var(--err-bg); color: var(--err); }
.banner-warn { background: var(--warn-bg); color: var(--warn); }
.banner-ok { background: var(--accent-soft); color: var(--accent-dark); }

.empty-state { text-align: center; padding: 48px 20px; color: var(--ink-soft); }
.empty-state .big { font-size: 2rem; margin-bottom: 8px; }

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- signature element: этап-трек P1 → P2 → P3 ---------- */

.stage-track {
  display: flex;
  align-items: center;
  gap: 4px;
}
.stage-track .seg {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  position: relative;
}
.stage-track .seg.done { background: var(--accent); }
.stage-track .seg.skipped {
  background: repeating-linear-gradient(45deg, var(--border-strong), var(--border-strong) 3px, transparent 3px, transparent 6px);
}
.stage-track .seg.current { background: var(--accent-line); }
.stage-track .seg.current::after {
  content: '';
  position: absolute; inset: -3px;
  border-radius: 6px;
  border: 1.5px solid var(--accent);
}
.stage-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  font-size: 0.6875rem;
}
.stage-labels span { flex: 1; text-align: center; color: var(--ink-faint); font-family: var(--font-mono); }
.stage-labels span.done, .stage-labels span.current { color: var(--accent-dark); font-weight: 700; }

/* ---------- library tree ---------- */

.folder-block { margin-bottom: 18px; }
.folder-title {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  padding: 0 4px 8px;
}
.topic-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
}
.topic-row + .topic-row { margin-top: 8px; }
.topic-row .meta { flex: 1; min-width: 0; }
.topic-row .name { font-weight: 600; font-size: 0.9375rem; }
.topic-row .count { font-size: 0.7812rem; color: var(--ink-soft); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--ink-faint); }
.status-dot.in_progress { background: var(--accent); }
.status-dot.completed { background: var(--accent-dark); }

.part-row { padding: 12px 0; border-top: 1px solid var(--border); }
.part-row:first-child { border-top: none; padding-top: 4px; }
.part-row .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.part-row .label { font-family: var(--font-mono); font-weight: 700; font-size: 0.875rem; }
.part-row .next { font-size: 0.75rem; color: var(--ink-soft); }

/* ---------- exercise screen ---------- */

.exercise-progress {
  display: flex; align-items: center; gap: 10px;
  font-size: 0.8125rem; color: var(--ink-soft); margin-bottom: 16px;
}
.exercise-progress .bar { flex: 1; height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.exercise-progress .bar > div { height: 100%; background: var(--accent); transition: width 0.25s ease; }

.exercise-card { padding: 22px 18px; }
.exercise-kicker {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent-dark);
  font-weight: 700;
  margin-bottom: 10px;
}
.exercise-sentence { font-size: 1.1875rem; line-height: 1.5; margin-bottom: 6px; }
.exercise-sentence .gap {
  display: inline-block;
  min-width: 64px;
  border-bottom: 2px solid var(--accent);
  color: var(--accent-dark);
  font-weight: 700;
  text-align: center;
}
.translation-line { font-size: 0.875rem; color: var(--ink-soft); margin-top: 10px; min-height: 20px; }
.translation-toggle { font-size: 0.8125rem; color: var(--accent-dark); background: none; border: none; padding: 4px 0; cursor: pointer; font-weight: 600; }

.answer-row { display: flex; gap: 8px; margin-top: 18px; }
.answer-row input { flex: 1; }

.feedback {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}
.feedback.correct { background: var(--accent-soft); color: var(--accent-dark); }
.feedback.incorrect { background: var(--err-bg); color: var(--err); }
.feedback .correct-answer { font-weight: 700; margin-top: 2px; }

.cloze-text { font-size: 1.125rem; line-height: 1.8; }
.cloze-text input {
  width: 90px;
  border: none;
  border-bottom: 2px solid var(--accent);
  text-align: center;
  font-weight: 700;
  color: var(--accent-dark);
  background: transparent;
}
.word-bank { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.word-bank span {
  font-size: 0.8125rem; padding: 5px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-soft);
}

.session-summary { text-align: center; padding: 32px 16px; }
.session-summary .num { font-size: 3rem; font-weight: 700; color: var(--accent-dark); font-family: var(--font-mono); }

/* ---------- coverage table ---------- */

table.coverage { width: 100%; border-collapse: collapse; font-size: 0.8438rem; }
table.coverage th, table.coverage td { padding: 9px 6px; text-align: center; border-bottom: 1px solid var(--border); }
table.coverage th:first-child, table.coverage td:first-child { text-align: left; font-family: var(--font-mono); font-weight: 700; }
.cov-pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; }
.cov-full { background: var(--accent-soft); color: var(--accent-dark); }
.cov-partial { background: var(--warn-bg); color: var(--warn); }
.cov-missing { background: var(--surface-2); color: var(--ink-faint); }

/* ---------- accent swatches (settings) ---------- */

.swatch-row { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 40px; height: 40px; border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  position: relative;
}
.swatch.selected { border-color: var(--ink); }
.swatch.selected::after {
  content: '✓'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1rem; font-weight: 700;
}

/* ---------- misc ---------- */

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.text-center { text-align: center; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.muted { color: var(--ink-soft); }
.small { font-size: 0.8125rem; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

@media (min-width: 720px) {
  .bottom-nav { border-radius: var(--radius-lg) var(--radius-lg) 0 0; box-shadow: 0 -6px 24px rgba(0,0,0,0.06); }
}
