/* Hallmark · genre: editorial · macrostructure: Workbench · design-system: design.md · designed-as-app */

/* ============================================================
   Poetry Memorizer — стили интерфейса
   Собственная CSS-замена Tailwind CDN (без внешних зависимостей)

   ВАЖНО: все CSS-переменные (цвета, шрифты, отступы, радиусы)
   живут в tokens.css и tokens-shared.css — они подключаются ПЕРЕД этим файлом:
      <link rel="stylesheet" href="tokens-shared.css">
      <link rel="stylesheet" href="tokens.css">
      <link rel="stylesheet" href="styles.css">
   Старые имена токенов (--surface-*, --blue-*, --c-*) сохранены
   там как legacy-алиасы, поэтому правила ниже не требуют правок.
   ============================================================ */

* { box-sizing: border-box; }
html, body { height: 100%; }

/* Базовый масштаб интерфейса. 15px вместо 16px уменьшает все rem-размеры
   на ~6%: библиотека и панель настроек получают «воздух», а экран
   тренировки не меняется — он задан в px. */
html { font-size: 15px; }

body {
  margin: 0;
  background: var(--bg-body);
  color: var(--cream);
  font-family: var(--sans);
  line-height: 1.45;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; padding: 0; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; border-radius: 8px; }

/* ---------- Каркас дашборда ----------
   Две колонки: меню (ширина на самом элементе) и контент.
   Правая панель вынесена из сетки: она выезжает через transform,
   а центр меняет отступ — так переходы остаются плавными,
   а grid-template-columns не анимируется. */
.app-shell {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

/* Ширина меню живёт на элементе: колонка auto следует за ней,
   поэтому переход анимируется вместе с ней. */
.sidebar {
  width: var(--sidebar-w);
  transition: width var(--panel-anim) ease-out;
}
.app-shell.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }

/* Свёрнутое меню: только иконки с подсказками.
   На телефоне (<761px) меню горизонтальное и не сворачивается. */
@media (min-width: 761px) {
  /* Верхний отступ тот же, что у развёрнутого меню: иначе навигация
     сдвигалась бы на 4 px при переключении. */
  .app-shell.sidebar-collapsed .sidebar { padding: 24px 10px 26px; }
  /* Шапка становится колонкой: перо сверху, шеврон под ним по центру.
     Высота та же (min-height .sidebar-head), поэтому иконки не прыгают. */
  .app-shell.sidebar-collapsed .sidebar-head {
    flex-direction: column;
    justify-content: center;
    gap: 4px;
  }
  .app-shell.sidebar-collapsed .sidebar-brand {
    flex: none;
    justify-content: center;
    padding: 0;
  }
  .app-shell.sidebar-collapsed .sidebar-brand-name,
  .app-shell.sidebar-collapsed .nav-item > span,
  .app-shell.sidebar-collapsed .books,
  .app-shell.sidebar-collapsed .streak-card { display: none; }
  /* Только перо (40 px) по центру оси иконок; надпись скрыта, а не ужата. */
  .app-shell.sidebar-collapsed .brand-logo { width: 40px; height: 40px; }
  .app-shell.sidebar-collapsed .sidebar-toggle { width: 28px; height: 28px; }
  .app-shell.sidebar-collapsed .nav-item { width: 52px; padding: 0; justify-content: center; }
  .app-shell.sidebar-collapsed .sidebar-nav { align-items: center; }
  .app-shell.sidebar-collapsed .sidebar-toggle__icon { transform: rotate(180deg); }
}

/* ============================================================
   Sidebar — перенос из template-fronted/library.html (.sidebar)
   Вёрстка и стили из эталона; цвета и отступы — через токены.
   Классы .sidebar-brand / .sidebar-nav / .nav-item / .streak-*
   сохранены: на них завязан app.js (showView, dataset.view).
   ============================================================ */

.sidebar {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg-side);
  border-right: 1px solid var(--line);
  padding: 24px 17px 26px;
  overflow: hidden;
}

.sidebar-content {
  position: relative;
  z-index: 1;
}

/* Шапка меню: бренд и кнопка сворачивания в одной строке.
   Фиксированная min-height держит высоту одинаковой в обоих состояниях
   (развёрнуто: перо 62 px + шеврон в строке; свёрнуто: перо 40 + шеврон 28). */
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 72px;
  margin-bottom: 42px;
  position: relative;
  z-index: 2;
}

/* Бренд: логотип-перо + название */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 0 0 15px;
  margin-bottom: 0;
  position: relative;
  z-index: 2;
  text-decoration: none;
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

/* Кнопка сворачивания: шеврон, разворачивается в свёрнутом состоянии. */
.sidebar-toggle {
  flex: none;
  position: relative;
  /* Выше z-index бренда: иначе логотип-перо перехватывает клики. */
  z-index: 3;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid transparent;
  color: var(--muted);
  transition: color 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}
.sidebar-toggle:hover { color: var(--cream); background: var(--fill-ghost-hi); }
.sidebar-toggle:focus-visible { outline: none; box-shadow: inset 0 0 0 var(--focus-width) var(--ring); }
.sidebar-toggle__icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform var(--panel-anim) ease-out;
}
.sidebar-brand .icon {
  font-size: 30px;
  line-height: 1;
  color: var(--amber);
  flex: none;
}
/* SVG-логотип «перо + книга» (symbol #logo) */
.brand-logo {
  width: 70px;
  height: 62px;
  flex: none;
  display: block;
}
.sidebar-brand-name {
  font-family: var(--serif-display);
  font-size: 25px;
  line-height: 1.02;
  color: var(--cream);
  /* Длинное имя усекается многоточием, а не выдавливает шеврон за край. */
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  z-index: 2;
}

/* Пункт меню: 52px высоты, иконка 30px — плотность из шаблона */
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--nav-item-gap);
  height: 52px;
  padding: 0 20px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: none;
  font-family: inherit;
  font-size: 16px;
  color: var(--cream-soft);
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.nav-item .icon {
  width: var(--nav-icon);
  height: var(--nav-icon);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: currentColor;
  flex: none;
}
.nav-item:hover { background: var(--fill-ghost); color: var(--cream); }
.nav-item.active {
  background: var(--grad-nav-active);
  border-color: var(--amber-a28);
  color: var(--amber);
  font-weight: var(--fw-medium);
}
.nav-item--landing {
  margin-bottom: 10px;
  border-bottom-color: var(--line);
  border-radius: 0 0 10px 10px;
  text-decoration: none;
}

/* Книги на фоне нижней части sidebar (из template-fronted/library.html) */
.books {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 520px;
  pointer-events: none;
  z-index: 1;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 45%);
          mask-image: linear-gradient(to bottom, transparent, #000 45%);
}
.books svg { width: 100%; height: 100%; display: block; }

/* Карточка серии дней — .streak из template-fronted/library.html */
.streak-card {
  position: relative;
  z-index: 2;
  margin-top: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-card);
  background: var(--streak-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: var(--space-lg);
}
.streak-label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: var(--fs-base);
  color: var(--muted);
}
.streak-label > .icon {
  width: 22px;
  height: 22px;
  color: var(--amber);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.streak-label .streak-chevron {
  width: 16px;
  height: 16px;
  margin-left: auto;
  color: var(--muted-dim);
}
.streak-value {
  margin: 16px 0 6px;
  font-family: var(--serif-display);
  font-size: 1.375rem;
  font-weight: var(--fw-regular);
  color: var(--cream);
}
.streak-value #repertoireCount {
  font-size: 1.625rem;
}
/* Подсказка при нуле. Главное число само по себе ничего не объясняет, поэтому
   под ним появляется действие, а не констатация пустоты. */
.repertoire-hint {
  margin: 0 0 10px;
  font-size: .8125rem;
  color: var(--muted);
}
/* Статус недели — мягкая строка над кружочками: сколько дней на этой неделе
   прошло с практикой. Здесь важно, что считаются отдельные дни, а не
   непрерывная серия: пропуск посередине не обнуляет начало недели. */
.repertoire-week {
  margin: 0 0 12px;
  font-size: .8125rem;
  color: var(--muted-dim);
}
.streak-days {
  display: flex;
  justify-content: space-between;
  gap: 2px;
}
.streak-day {
  width: 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--muted-dim);
  font-size: 0.656rem;
}
.streak-day i {
  width: 13px;
  height: 13px;
  border: 1px solid #5a554d;
  border-radius: 50%;
  background: transparent;
  transition: background .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.streak-day.on i {
  border-color: var(--amber);
  background: var(--amber);
  box-shadow: 0 0 8px rgba(219, 162, 92, .5);
}

/* ---------- Main / views ---------- */
.main-panel {
  padding: 40px 24px;
  /* Тёплый near-black: карточки настроек читаются на нём как плоские
     поверхности, а не как текст на пустом чёрном поле. */
  background: #100E0C;
  min-width: 0;
  overflow-y: auto;
}
/* Единая ширина контента: заголовок и все секции выровнены по одной
   левой кромке; пустое пространство справа не заполняется.
   Режим тренировки (.practice-screen) — исключение, см. ниже:
   он позиционирован fixed с inset: 0 и должен занимать весь экран. */
.main-panel > * {
  max-width: 920px;
}
/* Библиотека занимает всю ширину центра: сетка карточек сама перестраивает
   колонки (auto-fill), поэтому фиксированный кап 920px только оставлял
   пустое поле справа на широких экранах. */
#view-library { max-width: none; }

.view { display: none; }
.view.active { display: block; }

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.view-title {
  font-family: var(--serif-display);
  font-size: 1.5rem;
  font-weight: 400;
  margin: 0;
  color: var(--cream);
}
.view-subtitle {
  font-size: 0.875rem;
  color: var(--muted);
  margin: 4px 0 0;
}

/* ============================================================
   Библиотека: шапка + тулбар
   Перенос из template-fronted/library.html (.main__head / .btn-add
   / .toolbar / .tool / .info / .tip)
   ============================================================ */
.main__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  /* Заголовок и кнопка «Добавить стихотворение» не влезали в узкий экран
     в одну строку: у кнопки white-space: nowrap, и она уезжала за правый
     край, а весь документ получал горизонтальную прокрутку. */
  flex-wrap: wrap;
}
/* Первая колонка растягивается и забирает свободное место, поэтому кнопка
   остаётся справа на широком экране и уходит под заголовок на узком. */
.main__head > div { min-width: 0; flex: 1 1 240px; }

/* Доступный скринридер-текст без визуального отображения */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.view-title {
  margin: 0;
  font-family: var(--serif-display);
  font-weight: var(--fw-regular);
  font-size: 2.75rem;
  line-height: 1.1;
  letter-spacing: -0.005em;
  color: var(--cream);
}
.sub {
  margin: 8px 0 0;
  font-size: 0.9375rem;
  color: var(--muted);
}

.btn-add {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  height: 44px;
  padding: 0 30px 0 26px;
  margin-top: 4px;
  border-radius: var(--radius-pill);
  border: 0;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: var(--fw-medium);
  color: var(--amber-on);
  white-space: nowrap;
  background: var(--grad-amber);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.btn-add:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-add .icon { font-size: 18px; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0 30px;
  position: relative;
  /* Четыре кнопки плюс подсказка не помещались в 320-480 px: «Удалить данные»
     и кнопка информации уезжали за экран. Перенос по строкам убирает
     горизонтальную прокрутку всего документа. */
  flex-wrap: wrap;
}
.tool {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  height: 40px;
  padding: 0 20px 0 18px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.03);
  color: var(--cream);
  font-family: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}
.tool:hover { border-color: rgba(219, 162, 92, 0.5); background: rgba(219, 162, 92, 0.06); }
.tool .icon { font-size: 20px; }
.info {
  /* Зона нажатия 26 px была меньше рекомендованных 44 px, и на телефоне
     в кнопку «О формате экспорта» попасть было трудно. */
  width: 40px;
  height: 40px;
  flex: none;
  color: var(--muted);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  cursor: pointer;
}
.info:hover { color: var(--cream); }
.info .icon { font-size: 22px; }
.tip {
  position: absolute;
  left: 0;
  /* Отступ от низа всего тулбара, а не фиксированные 50 px от его верха:
     после переноса на узком экране кнопка информации съезжает на вторую
     строку, и подсказка с постоянным отступом накрывала её саму. */
  top: calc(100% + 8px);
  max-width: 340px;
  z-index: 5;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 0.8125rem;
  color: var(--cream);
  background: var(--popover);
  border: 1px solid rgba(219, 162, 92, 0.35);
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.tip.show { opacity: 1; transform: none; pointer-events: auto; }

.storage-note { text-align: left; max-width: 900px; line-height: 1.6; }

/* ============================================================
   Библиотека: карточки
   Перенос из template-fronted/library.html (.grid / .card / .badge
   / .ring / .kebab / .menu-pop / .card-new). Данные — из PoemStore.
   ============================================================ */
.poem-grid {
  display: grid;
  /* auto-fill: карточки сами перестраиваются при изменении ширины
     центра — когда выезжает правая панель, справа не остаётся пустоты. */
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
  align-items: stretch;
}

.poem-card {
  position: relative;
  text-align: left;
  width: 100%;
  min-height: 262px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  padding: 16px 20px 20px;
  background: var(--grad-card);
  color: var(--cream);
  font-family: var(--sans);
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.poem-card:hover { border-color: rgba(255, 255, 255, 0.2); }
.poem-card:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}
.poem-card.active-poem {
  border-color: var(--amber);
  box-shadow: 0 0 0 1px var(--amber-a28), 0 12px 40px rgba(219, 162, 92, 0.07);
  background: linear-gradient(180deg, #17130e, #100f0d);
}

/* Верх карточки: badge + «⋮» */
.card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}

.poem-card-badge {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  font-size: 0.8125rem;
  white-space: nowrap;
}
.poem-card-badge.progress { background: var(--badge-progress-bg); color: var(--badge-progress-fg); }
.poem-card-badge.done { background: var(--badge-done-bg); color: var(--badge-done-fg); }
.poem-card-badge.new { background: var(--badge-new-bg); color: var(--badge-new-fg); }

.kebab {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: #d8cfc1;
  background: none;
  border: 0;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.kebab:hover { background: var(--fill-ghost-hi); }
.kebab[aria-expanded="true"] { background: var(--fill-ghost-hi); color: var(--cream); }
.kebab .icon { font-size: 20px; line-height: 1; }

.poem-card-title {
  margin: 14px 0 0;
  font-family: var(--serif-display);
  font-weight: var(--fw-regular);
  font-size: 1.75rem;
  line-height: 1.2;
  color: var(--cream);
  overflow-wrap: anywhere;
}
.poem-card-author {
  margin-top: 6px;
  font-size: 0.875rem;
  color: var(--muted);
}
.poem-card-quote {
  margin: 22px 0 0;
  min-height: 56px;
  font-family: var(--serif-text);
  font-style: italic;
  font-size: 0.969rem;
  line-height: 1.65;
  color: var(--quote-fg);
}
.poem-card-quote span { display: block; }

/* Статистика: кольцо + подпись */
.poem-card-stat {
  display: flex;
  align-items: center;
  gap: var(--space-xl);
  margin-top: 22px;
}

/* Radial progress: SVG из template-fronted/library.html. */
.ring {
  position: relative;
  width: 76px;
  height: 76px;
  flex: none;
}
.ring svg {
  width: 100%;
  height: 100%;
  display: block;
  transform: rotate(-90deg);
}
.ring circle {
  fill: none;
  stroke-width: 5;
}
.ring .track { stroke: rgba(255, 255, 255, .1); }
.ring .bar { stroke-linecap: round; transition: stroke-dashoffset .8s cubic-bezier(.2, .8, .2, 1); }
.ring b {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1rem;
  font-weight: var(--fw-medium);
  color: var(--cream);
  font-variant-numeric: tabular-nums;
}
.poem-card.done .ring b { color: var(--green); }

.poem-card-lines {
  display: block;
  font-size: 0.8125rem;
  color: var(--muted);
  line-height: 1.6;
}
.poem-card.add-card-active {
  border-color: var(--amber);
  box-shadow: 0 0 0 1px var(--amber-a28), 0 12px 40px rgba(219, 162, 92, 0.07);
}

/* Меню действий «⋮» */
.menu-pop {
  position: absolute;
  right: 14px;
  top: 54px;
  z-index: 6;
  min-width: 170px;
  background: var(--popover);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-lg);
  padding: 6px;
  box-shadow: var(--shadow-pop);
}
.menu-pop button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--cream);
  background: none;
  border: 0;
  cursor: pointer;
}
.menu-pop button:hover { background: var(--fill-ghost-hi); }
.menu-pop button.danger { color: var(--coral-soft); }

/* dashed-карточка «Новое стихотворение» */
.poem-card-add {
  min-height: 262px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: 1px dashed var(--border-polar);
  border-radius: var(--radius-card);
  padding: var(--space-xl);
  background: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.poem-card-add:hover { border-color: rgba(219, 162, 92, 0.6); background: rgba(219, 162, 92, 0.04); }
.poem-card-add .icon {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--amber);
  color: var(--amber);
  font-size: 26px;
  margin-bottom: 26px;
}
.poem-card-add span { max-width: 200px; line-height: 1.6; }

/* ---------- Тосты ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 100;
  transform: translate(-50%, 20px);
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.4);
  font-size: 0.875rem;
  max-width: 28rem;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  border: 1px solid rgba(219, 162, 92, 0.5);
  background: var(--bg-body);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok {
  background: rgba(43, 109, 78, 0.85);
  border-color: var(--green);
  color: var(--cream);
}
.toast.err {
  background: rgba(140, 45, 40, 0.85);
  border-color: var(--coral);
  color: var(--cream);
}

/* ---------- Баннер состояния движка ----------
   В потоке контента библиотеки: под подзаголовком, над сеткой карточек.
   Раньше был position: fixed и перекрывал заголовок «Моя библиотека».
   Ширину ограничивает .main-panel > * (920px), поэтому баннер не шире
   заголовка и сетки. */
.engine-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 920px;
  margin: 0 0 24px;
  padding: 14px 18px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--coral);
  background: var(--bg-body);
  box-shadow: 0 18px 30px -12px rgba(0, 0, 0, 0.55);
  color: var(--cream, #f5efe6);
}
.engine-banner__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.engine-banner__title { font-size: 0.9rem; }
.engine-banner__text {
  font-size: 0.8rem;
  color: var(--color-primary);
  overflow-wrap: anywhere;
}
.engine-banner__progress { width: 100%; height: 6px; margin-top: 6px; }
.engine-banner--loading { border-color: rgba(219, 162, 92, 0.6); }
.engine-banner__retry {
  flex: none;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--coral);
  background: transparent;
  color: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}
.engine-banner__retry:hover { background: rgba(224, 122, 95, 0.16); }
.engine-banner__retry[disabled] { opacity: 0.5; cursor: default; }

/* ---------- Карточки ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-2xl);
  padding: 24px;
}
.card + .card { margin-top: 24px; }

.card-title {
  font-family: var(--serif-display);
  font-size: 1.25rem;
  font-weight: 400;
  margin: 0 0 12px;
  color: var(--cream);
}

.hint {
  font-size: 0.75rem;
  color: var(--color-primary);
  margin: 12px 0 0;
}

/* ---------- Поля ввода ---------- */
.field-row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.input,
.textarea {
  width: 100%;
  background: var(--color-bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  padding: 10px 16px;
  color: var(--color-text);
  font-size: 0.875rem;
  font-family: inherit;
}
.input:focus,
.textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--ring);
}
.input.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.textarea {
  line-height: 1.625;
  resize: vertical;
  min-height: 180px;
}

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  padding: 10px 20px;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  color: #fff;
  background: var(--color-card);
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--color-primary); }
.btn-primary:hover { background: var(--color-primary); }
.btn-primary:active { background: var(--color-primary); }

.btn-success { background: var(--color-success); font-weight: 600; padding: 11px 24px; }
.btn-success:hover { background: var(--color-success); }
.btn-success:active { background: var(--color-success); }

.btn-ghost {
  background: var(--color-card);
  border-color: var(--line-strong);
  color: var(--color-soft);
  padding: 8px 16px;
}
.btn-ghost:hover { background: var(--line-strong); }

/* Кнопка записи: круглая, как .mic в template-fronted/practice.html.
   #btnRec и .recording сохранены — на них завязаны applyFeedbackUI/setLiveText. */
.btn-mic {
  position: relative;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  border: 3px solid var(--green);
  color: var(--green);
  background: radial-gradient(circle, rgba(47, 191, 116, 0.22), rgba(20, 60, 40, 0.4));
  box-shadow: 0 0 26px rgba(102, 232, 163, 0.35), inset 0 0 18px rgba(102, 232, 163, 0.12);
  transition: transform 0.2s, border-color 0.3s, color 0.3s, box-shadow 0.3s, opacity 0.3s;
  padding: 0;
}
.btn-mic .icon { font-size: 42px; line-height: 1; }
/* Подпись «Записать/Стоп»: визуально скрыта, но доступна скринридерам.
   Текст обновляет app.js (btnRec.textContent), поэтому скрываем контейнер. */
.btn-mic__label {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
/* Мягкое «кольцо» вокруг кнопки в покое (как .mic::before в шаблоне) */
.btn-mic::before {
  content: "";
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  border: 1px solid rgba(102, 232, 163, 0.22);
  background: rgba(102, 232, 163, 0.04);
  z-index: -1;
  pointer-events: none;
}
.btn-mic:hover { transform: scale(1.03); }
.btn-mic:active { transform: scale(0.97); }
.btn-mic.recording {
  border-color: var(--amber);
  color: var(--amber);
  background: radial-gradient(circle, rgba(219, 162, 92, 0.3), rgba(219, 162, 92, 0.15));
  box-shadow: 0 0 30px rgba(219, 162, 92, 0.5), inset 0 0 20px rgba(219, 162, 92, 0.2);
}
.btn-mic.recording::before {
  content: "";
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  border: 1px solid rgba(219, 162, 92, 0.4);
  background: rgba(219, 162, 92, 0.04);
  z-index: -1;
}
.btn-mic.recording::after {
  content: "";
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  border: 1px solid rgba(219, 162, 92, 0.5);
  animation: ping 2.2s ease-out infinite;
  z-index: -1;
}
@keyframes ping {
  0% { transform: scale(0.9); opacity: 0.9; }
  100% { transform: scale(1.35); opacity: 0; }
}

.btn-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}

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

/* ============================================================
   Тренировка — полный экран по template-fronted/practice.html.
   Сохраняются ID, на которых завязаны app.js и регрессионные тесты.
   ============================================================ */
.practice-screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  min-width: 0;
  /* Режим тренировки — всегда на весь экран. Общее правило
     .main-panel > * ограничивает ширину контента 920 px, и без сброса
     экран тренировки сжимался до этой ширины вместо всего вьюпорта. */
  max-width: none;
  padding: 0;
  overflow: hidden;
  background: var(--bg-body);
  background-image: radial-gradient(60% 40% at 90% 100%, rgba(140, 90, 40, .10), transparent 70%);
}
.practice-screen.active { display: flex; flex-direction: column; }

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.practice-top {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  flex: none;
  min-height: 126px;
  padding: 0 44px;
  border-bottom: 1px solid var(--line);
}
.practice-back {
  display: inline-flex;
  align-items: center;
  gap: 16px;
  justify-self: start;
  padding-bottom: 32px;
  color: var(--amber);
  font-size: 16px;
}
.practice-back:hover { opacity: .8; }
.practice-back svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.practice-title { min-width: min(620px, 58vw); text-align: center; padding-top: 4px; }
.practice-title h1 {
  margin: 0;
  font-family: var(--serif-text);
  font-weight: 400;
  font-size: 26px;
  line-height: 1.25;
  letter-spacing: .005em;
}
.practice-by { margin-top: 4px; min-height: 20px; color: var(--muted); font-size: 14px; }
.practice-progress { display: flex; align-items: center; justify-content: center; gap: 18px; margin-top: 10px; }
.practice-progress__bar { width: min(356px, 38vw); height: 4px; border-radius: 4px; background: #2a2a27; overflow: hidden; }
.practice-progress__fill {
  display: block;
  width: 0;
  height: 100%;
  background: var(--amber);
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(226, 169, 94, .5);
  transition: width .5s ease;
}
.practice-progress__label { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.practice-progress__label span { color: var(--cream); font-weight: 500; }

.practice-tools { justify-self: end; display: flex; align-items: center; gap: 22px; padding-bottom: 32px; }
.hint-switch {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  height: 38px;
  padding: 0 20px 0 4px;
  border: 1px solid rgba(226, 169, 94, .5);
  border-radius: 999px;
  background: rgba(255, 255, 255, .02);
  font-size: 13px;
}
.hint-switch__track { position: relative; width: 56px; height: 30px; border-radius: 999px; background: #17150f; border: 1px solid rgba(226, 169, 94, .35); }
.hint-switch__knob { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #55534d; transition: transform .25s, background .25s; }
.hint-switch[aria-checked="true"] .hint-switch__knob { transform: translateX(26px); background: var(--amber); box-shadow: 0 0 10px rgba(226, 169, 94, .5); }
.practice-tools__sep { width: 1px; height: 30px; background: var(--line); }
.sound-switch { display: inline-flex; align-items: center; gap: 10px; color: var(--amber); font-size: 14px; }
.sound-switch svg { width: 26px; height: 26px; fill: currentColor; stroke: currentColor; stroke-width: 1.2; }
.sound-switch .sound-waves { fill: none; transition: opacity .2s; }
.sound-switch[aria-pressed="false"] { color: var(--muted); }
.sound-switch[aria-pressed="false"] .sound-waves { opacity: 0; }

.practice-stage { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; padding: 28px 24px; overflow: auto; }
.practice-stage-label { min-height: 18px; color: var(--amber); font-size: 12px; letter-spacing: .04em; }
.line-feedback { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); color: var(--amber); font-size: 13px; }
/* Состояния ответа: ошибка распознавания не выглядит как ошибка памяти. */
.line-feedback[data-kind="mismatch"] { color: var(--coral); }
.line-feedback[data-kind="near"] { color: var(--green); }
.line-feedback[data-kind="revealed"] { color: var(--green); }
.line-feedback[data-kind="skipped"] { color: #8d8577; }
.practice-poem { width: fit-content; max-width: 100%; transition: opacity .35s; }
.practice-poem.fade { opacity: 0; }
.poem-view {
  width: fit-content;
  max-width: 100%;
  font-family: var(--serif-text);
  font-size: clamp(26px, 2.75vw, 42px);
  line-height: 1.48;
  word-spacing: .14em;
  letter-spacing: .015em;
  color: var(--muted);
  white-space: normal;
}
.poem-line, .poem-line:last-child { margin-bottom: .22em; }
.practice-preview { margin-top: 44px; font-family: var(--serif-text); font-size: clamp(22px, 2.4vw, 36px); line-height: 1.72; color: #4d4c47; word-spacing: .1em; text-shadow: 0 0 20px rgba(255,255,255,.05); }
.practice-preview span { display: block; }
.practice-preview span:first-child { color: #55544e; }
.practice-a11y-feedback { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* Ручной ввод ответа: та же строка dock, что и микрофон, но без микрофона. */
.practice-answer { flex: 1 1 100%; display: flex; align-items: center; gap: 12px; margin: 4px 0 2px; }
.practice-answer__input {
  flex: 1 1 auto;
  min-width: 0;
  height: 52px;
  padding: 0 22px;
  border: 1.5px solid rgba(255,255,255,.2);
  border-radius: 999px;
  background: rgba(255,255,255,.04);
  color: var(--cream);
  font: inherit;
  font-size: 16px;
}
.practice-answer__input::placeholder { color: #8d8577; }
.practice-answer__input:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; border-color: var(--green); }
.practice-answer__hint { color: #8d8577; font-size: 12px; white-space: nowrap; }
.act--submit { height: 52px; border-color: rgba(110,231,168,.5); color: var(--green); }
.act--submit:hover { background: rgba(110,231,168,.1); }

.practice-dock {
  display: flex;
  align-items: center;
  gap: 28px;
  flex: none;
  flex-wrap: wrap;
  margin: 0 65px 60px;
  padding: 22px 20px 22px 24px;
  min-height: 140px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 70px;
  background: linear-gradient(180deg, rgba(20,20,18,.85), rgba(14,14,13,.9));
}
.practice-mic {
  position: relative;
  display: grid;
  place-items: center;
  width: 100px;
  height: 100px;
  flex: none;
  border: 3px solid var(--green);
  border-radius: 50%;
  color: var(--green);
  background: radial-gradient(circle, rgba(47,191,116,.22), rgba(20,60,40,.4));
  box-shadow: 0 0 26px rgba(110,231,168,.35), inset 0 0 18px rgba(110,231,168,.12);
  transition: transform .2s, border-color .3s, color .3s, box-shadow .3s;
}
.practice-mic:hover { transform: scale(1.03); }
.practice-mic svg { width: 42px; height: 42px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.practice-mic::before { content: ""; position: absolute; inset: -14px; z-index: -1; border: 1px solid rgba(110,231,168,.22); border-radius: 50%; background: rgba(110,231,168,.04); }
.practice-mic::after { content: ""; position: absolute; inset: -14px; border: 1px solid rgba(110,231,168,.3); border-radius: 50%; animation: practice-ping 2.2s ease-out infinite; }
.practice-dock.paused .practice-mic { border-color: #55534d; color: #8a877f; background: rgba(255,255,255,.03); box-shadow: none; }
.practice-dock.paused .practice-mic::before, .practice-dock.paused .practice-mic::after { display: none; }
@keyframes practice-ping { 0% { transform: scale(.9); opacity: .9; } 100% { transform: scale(1.35); opacity: 0; } }

.practice-wave { display: flex; align-items: center; gap: 4px; width: 140px; height: 60px; flex: none; }
.practice-wave i { width: 3px; height: 4px; border-radius: 2px; background: var(--green); opacity: .85; transition: height .12s; }
.practice-dock.paused .practice-wave i { height: 4px !important; background: #55534d; }
.rec-panel-heard { display: flex; flex-direction: column; justify-content: center; min-width: 200px; min-height: 92px; padding-left: 28px; border-left: 1px solid var(--line); }
.rec-panel-heard > small:first-child { color: #9a988f; font-size: 14px; }
.rec-panel-heard > b { min-height: 30px; margin-top: 6px; color: var(--green); font-family: var(--serif-text); font-size: 20px; font-weight: 400; }
.rec-indicator { display: flex; align-items: center; gap: 8px; color: var(--green); font-size: 12px; }
.rec-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); animation: blink 1s infinite; }
.listening-text { color: var(--muted); font-size: 12px; }
.live-text { display: block; max-width: 220px; color: var(--green) !important; font-size: 14px !important; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-text.voice { color: var(--amber) !important; }
.rec-indicator.voice .rec-dot { box-shadow: 0 0 0 6px rgba(102,232,163,.25); transform: scale(1.25); }

.practice-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; flex-wrap: wrap; }
.act--stage { border-color: rgba(226,169,94,.55); color: var(--amber); }
.act { display: inline-flex; align-items: center; gap: 16px; height: 62px; padding: 0 28px 0 26px; border: 1.5px solid rgba(255,255,255,.2); border-radius: 999px; color: var(--cream); font-size: 14px; transition: background .2s, border-color .2s, transform .2s; }
.act:hover { transform: translateY(-1px); }
.act-icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.act--hint { border-color: rgba(226,169,94,.8); background: rgba(226,169,94,.05); }
.act--hint:hover { background: rgba(226,169,94,.12); }
.act--hint .act-icon { color: var(--amber); }
.act--hint span { display: flex; flex-direction: column; text-align: left; font-size: 15px; line-height: 1.25; }
.act--hint small { color: var(--muted); font-size: 12px; }
.act--repeat:hover, .act--reset:hover, .act--target:hover,
.act--skip:hover, .act--mark:hover { background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.35); }
/* Пропуск — не успех: слово остаётся читаемым, но помечается отдельно. */
.act--skip { color: #e7ded0; }
.act--mark { color: var(--amber); border-color: rgba(226,169,94,.45); }
.act--target { border-color: rgba(255,255,255,.28); }
.act--reset { border-color: rgba(255,255,255,.22); }
/* Служебные действия компактнее основных: dock не должен перерастать в два ряда. */
.act--skip, .act--mark, .act--target, .act--reset, .act--repeat, .act--retry { height: 46px; padding: 0 16px; gap: 8px; font-size: 13px; }
.act--retry { border-color: rgba(234,107,85,.6); color: #f0d5cd; }
.act--retry:hover { background: rgba(234,107,85,.12); }
.act[disabled] { opacity: .5; cursor: default; transform: none; }
.act--reset .act-icon, .act--repeat .act-icon { width: 18px; height: 18px; }
.practice-progress__extra { color: #8d8577; }
.act--stop { height: 60px; border-color: rgba(234,107,85,.8); background: rgba(234,107,85,.05); color: #f5d8d1; }
.act--stop:hover { background: rgba(234,107,85,.14); }
.act--stop i { width: 20px; height: 20px; flex: none; border-radius: 4px; background: var(--coral); }
.fineprint { margin: 0; color: var(--color-text-muted); font-size: .875rem; line-height: 1.5; text-align: left; }
.settings-note { color: var(--color-text-muted); }
.word-token.hint-reveal { color: #fff !important; text-shadow: 0 0 18px rgba(255,255,255,.25); }
.practice-screen.hints-off .word-token.focus { color: transparent; text-shadow: none; }
.practice-screen.hints-off .word-token.focus::after { display: none; }

/* ---------- Экран завершения ---------- */
.modal.done { max-width: 460px; padding: 0; border-radius: 18px; }
.modal.done .res { padding: 36px 32px 30px; text-align: center; }
.modal.done .done-title { margin: 0; color: var(--cream); font-family: var(--serif-display); font-size: 32px; font-weight: 400; }
.modal.done .done-text { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 26px 0; }
.result-stats div { padding: 14px 6px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.02); }
.result-stats dt { color: var(--muted); font-size: 12px; }
.result-stats dd { margin: 4px 0 0; color: var(--amber); font-family: var(--serif-display); font-size: 28px; }
.modal.done .res-row { justify-content: center; }
.modal.done .res-row button { height: 44px; border-radius: 999px; font-weight: 500; }
.modal.done .res-row .ghost { border: 1px solid rgba(255,255,255,.22); }
.modal.done .res-row .primary { padding: 0 24px; border: 0; color: var(--amber-on); background: linear-gradient(180deg,#e2aa64,#d29a52); }

/* ---------- Токены слов ---------- */
.word-token {
  display: inline-block;
  padding: 0;
  color: var(--muted);
  transition: color .3s, text-shadow .3s, opacity .2s;
  white-space: nowrap;
  font-family: inherit;
}
/* Скрытое слово: невидимый текст сохраняет ширину слова,
   снизу — пунктирная линия (приём .w.blank из template-fronted/practice.html). */
.word-token.buried { color: transparent; user-select: none; border-bottom: 2px dotted rgba(255,255,255,.28); }
.word-token.buried::after { content: none; }
.word-token.focus { color: #fff; border-bottom: 2px solid var(--green); padding-bottom: 1px; margin-right: 4px; }
.word-token.focus::after { content: ""; display: inline-block; width: 2px; height: .85em; margin-left: 2px; vertical-align: -.05em; background: var(--green); animation: practice-caret 1s steps(1) infinite; }
/* «Первые буквы» на сложном уровне: слово скрыто целиком, и фокус не должен
   его раскрывать — иначе режим показывал бы именно тот ответ, который просит
   вспомнить. Правило специфичнее .focus и потому перебивает его цвет. */
.practice-screen[data-mode="first-letters"] .word-token.buried.focus { color: transparent; text-shadow: none; }
.word-token.revealed { color: var(--green); text-shadow: 0 0 22px rgba(110,231,168,.45); animation: pop .4s ease; }
/* Предварительное раскрытие по interim: слово уже узнано, но результат движок
   ещё не подтвердил. Зелёный цвет без свечения и без анимации pop — раскрытие
   выглядит сразу, однако обещание пока не засчитано. */
.word-token.provisional:not(.revealed) {
  color: var(--green);
  opacity: .75;
  text-shadow: none;
  animation: none;
  transition: opacity .15s ease;
}
/* Пропущенная цель: раскрыта, но не засчитана как самостоятельный ответ. */
.word-token.skipped { color: #b9ae9c; text-shadow: none; border-bottom: 2px dashed rgba(234,107,85,.75); }
/* Отметка сложного места сохраняется между попытками. */
.word-token.difficult { box-shadow: inset 0 -2px 0 rgba(226,169,94,.9); }
.word-token.difficult.buried { border-bottom: 2px dotted var(--amber); }
@keyframes practice-caret { 50% { opacity: 0; } }
/* Огненная вспышка после pop (по animationend добавляется JS-классом) */
.word-token.flash {
  animation: revealFlash 0.5s ease;
}
@keyframes revealFlash {
  0% { box-shadow: 0 0 0 0 rgba(102, 232, 163, 0.9) inset, 0 0 20px 6px rgba(102, 232, 163, 0.55); }
  100% { box-shadow: 0 0 0 0 rgba(102, 232, 163, 0) inset, 0 0 0 0 rgba(102, 232, 163, 0); }
}
/* «Слушаю этот токен»: оптимистичная подсветка целевого слова при записи */
.word-token.listening:not(.revealed) {
  animation: listeningGlow 1.2s infinite;
  border-radius: 0.375rem;
}
.poem-line.listening {
  border-radius: 0.375rem;
  animation: listeningGlow 1.2s infinite;
}

/* ---------- Новые состояния токенов и режимах заучивания ---------- */
/* «Первые буквы»: видимы первые буквы + хвост-плашка скрытой части */
.word-token.hinted {
  color: var(--muted);
  user-select: none;
}
.word-token.hinted {
  border-bottom: 2px dotted rgba(255, 255, 255, 0.28);
}
.word-token.hinted::after { content: none; }

/* «Пропавшее слово»: видимое контекстное слово, приглушённый цвет, без плашки */
.word-token.context {
  color: var(--muted);
}

/* «Через строку»: контейнер строки */
.poem-line {
  display: block;
  border-radius: 6px;
  transition: background 0.25s ease;
}
.poem-line.hidden-line {
  background: rgba(43, 37, 30, 0.35);
  border-radius: 6px;
}
.poem-line.hidden-line .word-token {
  color: transparent;
  user-select: none;
}
.poem-line.hidden-line .word-token.revealed {
  color: var(--green);
  text-shadow: 0 0 22px rgba(110,231,168,.45);
}
.poem-line.shown-line .word-token {
  color: var(--cream);
}

/* ---------- Утилиты ---------- */
.hidden { display: none !important; }

/* Нативный [hidden] должен побеждать авторские display.
   Браузерная таблица стилей задаёт [hidden] { display: none } с весом 0,
   поэтому любое правило компонента с тем же весом (например
   .act-menu { display: grid }) перебивало его: элемент с атрибутом hidden
   оставался на экране. Именно так меню «Ещё» висело поверх формы ответа
   сразу при входе в тренировку. Правило с !important ставит атрибут выше
   компонентных стилей — скрытие снова работает. */
[hidden] { display: none !important; }
.text-muted { color: var(--color-primary); font-size: 0.75rem; }
.stat { font-size: 0.75rem; color: var(--color-primary); }

/* ---------- Анимации ---------- */
@keyframes pulseFocus {
  0%, 100% { box-shadow: 0 0 0 3px rgba(102, 232, 163, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(102, 232, 163, 0.15); }
}
@keyframes pop {
  0% { transform: scale(0.9); background: rgba(102, 232, 163, 0.35); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}
@keyframes blink { 50% { opacity: 0.2; } }

/* CSS-класс для span-ов с white-space: pre-wrap (вместо inline-стилей) */
.poem-text-plain { white-space: pre-wrap; }

/* ============================================================
   Правая панель — перенос из template-fronted/library.html (.panel)
   Заголовок, «лист бумаги» (.sheet) и сетка режимов (.modes/.mode).
   ============================================================ */
.right-panel-close {
  position: absolute;
  top: 22px;
  right: 22px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.right-panel-close:hover { color: var(--cream); background: var(--fill-ghost-hi); }
.right-panel-close .icon { font-size: 24px; }
/* Панель — колонка из двух частей: прокручиваемое содержимое и
   неподвижный подвал с кнопкой запуска. Кнопка не уезжает за скролл
   при любой высоте настроек. */
/* Панель вынесена из сетки и прикреплена справа: открытие — это
   смена ширины центра (отступ справа) и выезд transform-ом — без переключения display. */
.right-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 45;
  width: var(--panel-w);
  max-width: 100%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 0;
  overflow: hidden;
  min-width: 0;
  transform: translateX(100%);
  visibility: hidden;
  transition: transform var(--panel-anim) ease-out, visibility 0s linear var(--panel-anim);
}
.app-shell.panel-open .right-panel {
  transform: translateX(0);
  visibility: visible;
  transition: transform var(--panel-anim) ease-out, visibility 0s;
}
/* Центр отдаёт панели место плавным отступом. */
.main-panel { transition: padding-right var(--panel-anim) ease-out; }
.app-shell.panel-open .main-panel { padding-right: calc(var(--panel-w) + 24px); }
.right-panel__scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 26px 30px 18px 30px;
}
.right-panel__foot {
  flex: none;
  padding: 12px 30px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
/* Затемнение под панелью — только когда панель оверлей (<1100px). */
.panel-scrim {
  position: fixed;
  inset: 0;
  z-index: 44;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--panel-anim) ease-out, visibility 0s linear var(--panel-anim);
}
.app-shell.panel-open .panel-scrim {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--panel-anim) ease-out, visibility 0s;
}
.right-panel .lbl {
  margin: 0;
  font-size: 1.0625rem;
  color: var(--cream);
}
.right-panel-title {
  margin: 8px 0 0;
  font-family: var(--serif-display);
  font-weight: var(--fw-regular);
  font-size: 1.75rem;
  line-height: 1.15;
  color: var(--cream);
  overflow-wrap: break-word;
}
.right-panel-author {
  margin: 6px 0 0;
  font-size: 0.875rem;
  color: var(--muted);
  min-height: 1.4em;
}

/* «Лист бумаги» со стопкой: превью стиха */
.sheet {
  position: relative;
  margin-top: 12px;
  padding: 16px 20px 14px 22px;
  border-radius: 6px;
  background: linear-gradient(180deg, var(--paper-a), var(--paper-b));
  border: 1px solid rgba(219, 162, 92, 0.22);
  box-shadow: 3px 3px 0 -0.5px var(--paper-edge-1), 6px 6px 0 -1px var(--paper-edge-2), 0 20px 40px rgba(0, 0, 0, 0.4);
  font-family: var(--serif-text);
  font-style: italic;
  font-size: 1.0625rem;
  line-height: 1.5;
  color: var(--sheet-fg);
  white-space: pre-wrap;
  word-break: break-word;
}
/* Превью стиха: высота по содержимому (height: auto), но не выше 160 px.
   Длинный текст не растягивает панель и не вытесняет настройки — он
   прокручивается внутри листа. Пустое состояние не обрезается. */
.sheet:not(:has(.practice-preview-empty)) {
  height: auto;
  min-height: 96px;
  max-height: 160px;
  overflow-y: auto;
  overflow-x: hidden;
}
/* Затухание снизу: липкая полоса поверх нижнего края видимой области.
   Появляется только когда текст доходит до низа листа. */
.sheet:not(:has(.practice-preview-empty))::after {
  content: '';
  position: sticky;
  bottom: 0;
  display: block;
  height: 20px;
  background: linear-gradient(to bottom, rgba(30, 24, 18, 0), var(--paper-b));
  pointer-events: none;
}
.sheet p { margin: 0; }
.sheet p + p { margin-top: 18px; }
.practice-preview-empty {
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.5;
  text-align: center;
  white-space: normal;
  font-family: var(--sans);
  font-style: normal;
  margin: 0;
}
.practice-preview-library {
  display: block;
  margin: 16px auto 0;
  padding: 9px 14px;
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-lg);
  background: transparent;
  color: var(--color-text);
  font-size: 0.875rem;
}
.practice-preview-library:hover { background: var(--fill-ghost-hi); }
.sheet .blank {
  background: var(--bg-highlight);
  border-radius: 3px;
  padding: 0 4px;
  color: transparent;
  user-select: none;
}
.sheet .context-line { color: var(--muted); }

/* Заголовок группы режимов */
.right-panel h4 {
  margin: 16px 0 8px;
  font-weight: var(--fw-regular);
  font-size: 0.9375rem;
  color: var(--cream);
}
/* Отступ от превью до «Выберите режим тренировки» — не меньше 20 px. */
.sheet + h4 { margin-top: 24px; }

/* Список режимов: одна колонка, строка «иконка — название — пояснение».
   Плоский список вместо сетки высоких плиток: пять режимов помещаются
   в панель без вертикального скролла, а иконка остаётся ориентиром. */
.modes {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}
.mode {
  display: grid;
  grid-template-columns: 30px auto minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 10px;
  text-align: left;
  padding: 7px 12px;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.11);
  background: rgba(255, 255, 255, 0.02);
  color: var(--cream);
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.mode:hover { border-color: rgba(255, 255, 255, 0.24); }
.mode.selected {
  border-color: var(--amber);
  background: linear-gradient(180deg, rgba(219, 162, 92, 0.16), rgba(219, 162, 92, 0.05));
}
.mode .ic {
  grid-column: 1;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.04);
  display: grid;
  place-items: center;
  font-family: var(--serif-display);
  font-size: 0.875rem;
  color: #dcd2c2;
}
.mode.selected .ic { border-color: rgba(219, 162, 92, 0.6); color: var(--amber); }
.mode .ic .mode-icon {
  width: 17px;
  height: 17px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mode .ic .mode-icon--fill { fill: currentColor; stroke: none; }
.panel-go {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  height: 52px;
  border: 0;
  border-radius: 999px;
  color: #1c130a;
  background: linear-gradient(180deg, #e2aa64, #d29a52);
  box-shadow: 0 8px 28px rgba(219, 162, 92, 0.2);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}
.panel-go:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 10px 32px rgba(219, 162, 92, 0.32); }
.panel-go:disabled { opacity: 0.45; cursor: not-allowed; }
.panel-go .icon { font-size: 16px; }
.mode strong {
  grid-column: 2;
  font-family: var(--serif-display);
  font-weight: var(--fw-regular);
  font-size: 0.9375rem;
  line-height: 1.2;
  color: var(--cream);
  white-space: nowrap;
}
.mode span {
  grid-column: 3;
  min-width: 0;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Режим в разработке: пункт виден, но выбрать его нельзя. Приглушён он
   целиком, а не только рамкой: иначе он выглядит активным, и нажатие
   «ничего не делает» читается как поломка интерфейса. */
.mode--soon {
  cursor: not-allowed;
  opacity: 0.42;
  border-style: dashed;
}
.mode--soon:hover { border-color: rgba(255, 255, 255, 0.11); }
.mode--soon .ic { color: var(--muted); }
.mode--soon .mode-soon {
  grid-column: 4;
  justify-self: end;
  padding: 1px 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  font-size: 0.625rem;
  font-style: normal;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Сложность в правой панели: свойство режима, поэтому стоит сразу под
   сеткой режимов. Три чипа в ряд: один тап вместо ухода в «Настройки». */
.panel-level {
  margin-top: 14px;
}
.panel-level__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.panel-level__label {
  font-size: 0.9375rem;
  color: var(--cream);
}
.panel-level__mode {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: right;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.panel-level__options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.panel-level__chip {
  min-height: 40px;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.02);
  color: var(--cream);
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.2;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}
.panel-level__chip:hover { border-color: rgba(255, 255, 255, 0.24); }
.panel-level__chip.selected {
  border-color: var(--amber);
  background: linear-gradient(180deg, rgba(219, 162, 92, 0.16), rgba(219, 162, 92, 0.05));
  color: var(--amber);
}
.panel-level__chip:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 var(--focus-width) var(--ring);
}
.panel-level__detail {
  margin: 10px 0 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--muted);
}

/* ---------- Прогресс ---------- */
.progress-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.progress-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 12px 14px;
}
.progress-row-title {
  font-size: 0.875rem;
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.progress-row-author {
  font-size: 0.75rem;
  color: var(--color-muted);
  white-space: nowrap;
}
.progress-row-track {
  flex: 1;
  height: 6px;
  background: var(--bg-panel);
  border-radius: 4px;
  overflow: hidden;
  min-width: 60px;
}
.progress-row-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 4px;
  transition: width 0.5s ease;
}
.progress-row.done .progress-row-fill { background: var(--color-success); }
.progress-row-date {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}
/* Этап 6: строка прогресса объясняет, что именно нужно повторить. */
.progress-row {
  flex-wrap: wrap;
  row-gap: 6px;
}
.progress-row__summary {
  display: flex;
  flex-direction: column;
  min-width: 140px;
  flex: 1 1 40%;
}
.progress-row__details {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  flex: 1 1 100%;
  order: 3;
}
.progress-row-status {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--amber);
}
.progress-row.due .progress-row-status { color: var(--amber); }
.progress-row-metric {
  font-size: 0.75rem;
  color: var(--color-muted);
}
.progress-row-advice {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}
.progress-due {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--amber);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
.progress-due__title {
  margin: 0 0 8px;
  font-family: var(--serif-display);
  font-weight: var(--fw-regular);
  font-size: 1rem;
  color: var(--cream);
}
.progress-due__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.progress-due__item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--color-muted);
  font-size: 0.8125rem;
  cursor: pointer;
}
.progress-due__item:hover,
.progress-due__item:focus-visible {
  background: var(--bg-panel);
  color: var(--cream);
}
.poem-card-review {
  display: block;
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}
.result-review {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.result-review:empty { display: none; }
.result-review p {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--color-muted);
}
.result-review__status {
  font-weight: 500;
  color: var(--cream) !important;
}
/* Этап 7: кнопка прослушивания эталона в режиме «Слушай и повторяй». */
.act--echo[aria-pressed="true"] {
  border-color: var(--amber);
  color: var(--amber);
}
.act--echo[aria-pressed="true"] .act-icon {
  animation: echoPulse 1.1s ease-in-out infinite;
}
.act--echo:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
@keyframes echoPulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .act--echo[aria-pressed="true"] .act-icon { animation: none; opacity: 1; }
}
.line-feedback[data-kind="echo-playing"],
.line-feedback[data-kind="echo-ready"] {
  color: var(--amber);
}

/* ============================================================
   Оверлеи и модальные окна
   Перенос из template-fronted/library.html (.modal-overlay / .modal
   / .dlg-actions / .hint) и template-fronted/practice.html (.res).
   ID (#overlayPoem, #overlayDone, #btnPoemSave…) не переименованы:
   на них завязаны openPoemModal(), savePoemFromModal() и тесты.
   ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
body.modal-open { overflow: hidden; }

.modal {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
  color: var(--cream);
  background: var(--modal-bg);
  border: 1px solid rgba(219, 162, 92, 0.35);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.2s ease-out;
}
@keyframes modal-in {
  0% { opacity: 0; transform: scale(0.95); }
  100% { opacity: 1; transform: scale(1); }
}

/* Заголовок модалки — serif (в шаблоне .modal h5) */
.modal .card-title {
  margin: 0 0 12px;
  font-family: var(--serif-display);
  font-weight: var(--fw-regular);
  font-size: 1.75rem;
  color: var(--cream);
}

/* Поля ввода в модалке (в шаблоне .modal input/textarea) */
.modal .input,
.modal .textarea {
  width: 100%;
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--cream);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
}
.modal .input:focus,
.modal .textarea:focus {
  outline: none;
  border-color: var(--amber);
  box-shadow: none;
}
.modal .textarea {
  min-height: 190px;
  resize: vertical;
  font-family: var(--serif-text);
  line-height: 1.6;
}

/* Действия диалога: pill-кнопки (в шаблоне .dlg-actions) */
.confirm-modal { max-width: 420px; }
.confirm-modal__icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  margin-bottom: 16px;
  border: 1px solid rgba(219, 162, 92, 0.35);
  border-radius: 50%;
  color: var(--amber);
  background: rgba(219, 162, 92, 0.1);
  font-size: 20px;
}
.confirm-modal .hint { margin-bottom: 22px; line-height: 1.6; }

.dlg-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
}
.dlg-actions button {
  height: 42px;
  padding: 0 24px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
}
.dlg-actions .ghost {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--cream);
}
.dlg-actions .ghost:hover { background: var(--fill-ghost-hi); }
.dlg-actions .main-btn {
  background: var(--grad-amber);
  color: var(--amber-on);
  border: 0;
}
.dlg-actions .main-btn:hover { box-shadow: var(--shadow-sm); }

/* Подсказка под полями (в шаблоне .hint) */
.modal .hint {
  font-size: 0.75rem;
  color: #857d71;
  margin: -6px 0 0;
  text-align: left;
}

/* Экран завершения — из template-fronted/practice.html (.res):
   селектор ограничен .modal, чтобы не протекать на .poem-card.done.
   padding/фон задаёт .res, здесь только рамка акцента и габарит. */
.modal.done {
  max-width: 460px;
  padding: 0;
  text-align: center;
  background: var(--modal-bg);
  border-color: rgba(219, 162, 92, 0.35);
}
/* «Выучено» — успех, поэтому заголовок зелёный (не amber) */
.modal.done .done-title { color: var(--green); }

/* Поле с подписью в модалке (в шаблоне .modal label) */
.dlg-field {
  display: grid;
  gap: 8px;
  font-size: 0.8125rem;
  color: var(--muted);
  margin-bottom: 16px;
}
.modal .card-title + .dlg-field { margin-top: 4px; }

/* Блок итогов тренировки (в шаблоне .res) */
.res { padding: 36px 32px 30px; }
.res h2,
.res .done-title {
  margin: 0;
  font-family: var(--serif-display);
  font-weight: var(--fw-regular);
  font-size: 2rem;
  color: var(--amber);
}
.res dl {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
  margin: 26px 0;
}
.res dl > div {
  padding: 14px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: rgba(255, 255, 255, 0.02);
}
.res dt { font-size: 0.75rem; color: var(--muted); }
.res dd {
  margin: 4px 0 0;
  font-family: var(--serif-display);
  font-size: 1.75rem;
  color: var(--amber);
}

/* Кнопки модалки завершения: .done-actions = .dlg-actions, но по центру */
.done-actions {
  justify-content: center;
  margin-top: 24px;
}

/* ---------- Иконки ---------- */
.icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  font-size: 16px;
  vertical-align: -2px;
}
.icon-lg { width: 20px; height: 20px; font-size: 20px; }

/* ---------- Настройки: заголовки секций ---------- */
.settings-title {
  font-size: 0.875rem;
  font-weight: 600;
  margin: 0 0 12px;
}
.radio-inline {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
  cursor: pointer;
}
.radio-inline input { margin-top: 2px; }
.radio-title { font-weight: 500; }

/* ============================================================
   Настройки: три компактные карточки на тёплом фоне.
   Поверхности плоские: фон #1B1814, граница #342D24, радиус 14px.
   ============================================================ */
.settings-list {
  display: grid;
  gap: 22px;
}

/* ---------- Правый блок обратной связи (plans/feedback-right-panel.md) ----------
   Кап 920px (правило .main-panel > *) снимается с вью настроек, иначе грид
   ужмётся в 920px и колонка секций просядет до ~558px. Заголовку кап
   возвращается отдельно. Математика двух колонок: 920 + 22 + 340 = 1282px
   контента; валидна от 1620px вьюпорта (289 сайдбар + 48 паддинги). */
#view-settings { max-width: none; }
#view-settings > .view-header { max-width: 920px; }
.settings-layout {
  display: grid;
  grid-template-columns: minmax(0, 920px) 340px;
  gap: 22px;
  align-items: start; /* без start grid stretch убьёт sticky у aside */
}
/* Прилипает при скролле: скролл-контейнер — .main-panel (overflow-y: auto). */
.settings-aside {
  position: sticky;
  top: 40px; /* = padding-top .main-panel */
}
/* Фолбэк: на вьюпортах < 1620px свободного места справа нет —
   форма выпадает вниз последней секцией, кап 920px сохраняется. */
@media (max-width: 1619px) {
  .settings-layout { grid-template-columns: minmax(0, 920px); }
  .settings-aside { position: static; }
}
.settings-aside .textarea { margin-top: 10px; }
.settings-aside .settings-row__actions { margin-top: 12px; }
.settings-section {
  background: #1B1814;
  border: 1px solid #342D24;
  border-radius: var(--radius-card);
  padding: 24px;
  margin-bottom: 0;
}
.settings-section + .settings-section { border-top: 1px solid #342D24; }
.settings-section__title {
  font-family: var(--sans);
  font-size: 1.0625rem;
  font-weight: var(--fw-semibold);
  letter-spacing: 0;
  text-transform: none;
  margin: 0;
  padding: 0;
  color: #EFE6D6;
}
.settings-section__title + .settings-row,
.settings-section__title + .settings-row { margin-top: 4px; }
.settings-section .settings-tech { margin-top: 12px; }

/* Строка настройки: слева текст, справа управление. */
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 0;
  min-height: 56px;
}
.settings-row + .settings-row,
.settings-row + .settings-group--levels,
.settings-group--levels + .settings-row {
  border-top: 1px solid #342D24;
  padding-top: 16px;
  margin-top: 4px;
}
.settings-row__text {
  min-width: 0;
  flex: 1 1 320px;
  display: grid;
  gap: 4px;
  /* Строки грида не растягиваются под высоту контейнера: иначе текст
     описания расползался по пустому блоку. */
  align-content: start;
}
.settings-row__text h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  margin: 0;
  padding: 0;
  text-transform: none;
  letter-spacing: 0;
  color: var(--color-text);
}
.settings-row__label { font-size: 1rem; font-weight: 600; color: #EFE6D6; }
.settings-row__desc {
  font-size: 0.875rem;
  color: #B9AE9A;
  margin: 0;
  line-height: 1.55;
}
.settings-row__desc--error { color: var(--color-danger); }
.settings-row__control {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}
/* Голосовой ввод: статус и кнопки стоят в один ряд. Раньше блок из трёх
   элементов был колонкой и растягивал строку почти на треть экрана.
   Если места в ряд не хватает, весь блок действий переносится под
   описание — текст при этом не сжимается в узкую колонку. */
.settings-row--voice {
  flex-wrap: wrap;
  row-gap: var(--space-xs);
  padding: 12px 0;
  min-height: 0;
}
.settings-row--voice .settings-row__text { flex: 1 1 300px; }
.settings-row--voice .settings-row__control {
  flex: 0 1 auto;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2xs);
  flex-wrap: wrap;
}
.settings-row--voice .settings-row__control .settings-status { margin: 0; }
.settings-row--voice .settings-row__control .tool {
  gap: 8px;
  padding: 8px 12px;
  min-height: 36px;
}
.settings-row__actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; flex-wrap: wrap; }
.settings-row__control .tool,
.settings-row__actions .tool { min-height: 38px; padding: 8px 14px; white-space: nowrap; }

/* Удаление данных: заголовок в обычном цвете, красный — только кнопка. */
.settings-row--danger {
  padding-top: 18px;
  padding-bottom: 0;
  border-top: 1px solid #342D24;
}
.settings-row--danger .settings-row__label { color: #EFE6D6; }

/* Технические детали — свёрнутый блок. */
.settings-tech { margin-top: 4px; }
.settings-tech summary {
  cursor: pointer;
  font-size: 0.8125rem;
  color: var(--muted);
  user-select: none;
}
.settings-tech summary:hover { color: var(--cream); }
.settings-tech .fineprint { margin: 8px 0 0; }

/* Компактный выбор сложности: три опции в одну строку. */
.settings-group--levels .radio-option {
  padding: 12px 14px;
  min-height: 0;
  align-items: center;
}
.settings-group--levels .radio-option strong { margin: 0; font-size: 0.9375rem; }
.settings-group--levels .radio-option small { font-size: 0.8125rem; line-height: 1.35; }
.settings-group--levels .radio-option small:empty { display: none; }

/* Статус-пилюля состояния распознавания */
.settings-status {
  flex: 0 0 auto;
  padding: 5px 9px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  color: var(--color-muted);
  font-size: 0.75rem;
  white-space: nowrap;
}
.settings-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
/* Три уровня сложности — одна равная строка на широком экране.
   Правило идёт после .settings-group, чтобы не перебивалось. */
.settings-group--levels {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
#levelOptions .radio-option:has(input:checked) {
  background: rgba(214, 164, 93, 0.12);
  border-color: var(--amber);
  box-shadow: none;
}
.radio-option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  background: #141210;
  border: 1px solid #2A251E;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.radio-option:hover {
  border-color: var(--line-strong);
}
.radio-option input[type="radio"] {
  margin: 0;
  flex: none;
  width: 17px;
  height: 17px;
  accent-color: var(--color-primary);
}
.radio-option span {
  flex: 1;
  font-size: 0.875rem;
  line-height: 1.5;
}
.radio-option strong {
  display: block;
  color: #EFE6D6;
  margin-bottom: 2px;
}
.radio-option small {
  color: #B9AE9A;
  font-size: 0.8125rem;
  line-height: 1.45;
}

/* ============================================================
   Настройки (#view-settings): readiness pill, complexity, подсказки,
   device, data on device. Expanded sections.
   ============================================================ */

/* Готовness pill (#recognizerSettingsStatus): data-state variants.
   Base styles of .settings-status remain as-is: pill without attribute
   is rendered muted, as before. */
.settings-status[data-state="ready"] {
  color: var(--color-success);
  border-color: color-mix(in srgb, var(--color-success) 55%, transparent);
}
.settings-status[data-state="loading"] {
  color: var(--amber);
  border-color: color-mix(in srgb, var(--amber) 55%, transparent);
  animation: settings-status-pulse 1.4s ease-in-out infinite;
}
.settings-status[data-state="idle"] {
  color: var(--muted);
  border-color: var(--color-border);
}
.settings-status[data-state="error"] {
  color: var(--color-danger);
  border-color: color-mix(in srgb, var(--color-danger) 55%, transparent);
}
@keyframes settings-status-pulse {
  50% { opacity: .55; }
}

/* Model loading progress (modelLoadProgress): visible during loading.
   app.js adds/removes .hidden; the rule restores block display on desktop.
   During loading the pill is also amber. */
progress.progress--model {
  display: block;
  min-width: 0;
}
progress.progress--model::-webkit-progress-value { background: var(--amber); }
progress.progress--model::-moz-progress-bar { background: var(--amber); }

/* Focus ring inset для компактных опций сложности */
.settings-group--levels .radio-option:focus-visible,
.settings-group--levels .radio-option:has(input:focus-visible) {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--ring);
}
.settings-group--levels .radio-option:has(input:checked):has(input:focus-visible) {
  box-shadow: inset 0 0 0 2px var(--color-primary);
}

/* --- подсказки toggle (#hintSwitchSettings): простой переключатель --- */
.hint-switch--settings {
  height: 44px;
  padding: 0;
  font-size: 13px;
  color: var(--cream);
}
/* Простой toggle без двойного овала: только дорожка с ползунком.
   Внешняя кнопка сохраняет зону клика 44 px и фокус-кольцо. */
.hint-switch--settings {
  border: 0;
  background: none;
  gap: 0;
  border-radius: var(--radius);
}
.hint-switch--settings .hint-switch__track {
  width: 46px;
  height: 26px;
  background: #141210;
  border-color: #342D24;
}
.hint-switch--settings .hint-switch__knob {
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: #56554f;
  box-shadow: none;
}
.hint-switch--settings[aria-checked="true"] .hint-switch__knob { transform: translateX(20px); }
.hint-switch--settings .hint-switch__label { display: none; }
.hint-switch--settings:focus-visible {
  outline: var(--focus-width) solid var(--ring);
  outline-offset: 2px;
}

/* (1–2) default + hover */
.hint-switch--settings:hover,
.hint-switch--settings.is-hover {
  border-color: var(--amber);
  background: var(--amber-a10);
}
/* (3) focus-visible: inset ring, чтобы не clip по сосед card edge */
.hint-switch--settings:focus-visible,
.hint-switch--settings.is-focus {
  outline: none;
  box-shadow: inset 0 0 0 var(--focus-width) var(--ring);
}
/* (4) active / pressed */
.hint-switch--settings:active,
.hint-switch--settings.is-active {
  background: var(--amber-a22);
  transform: translateY(1px);
}
/* (5) disabled: button looks muted, knob desaturates */
.hint-switch--settings.is-disabled,
.hint-switch--settings[disabled] {
  color: var(--muted-dim);
  border-color: var(--line);
  background: none;
}
.hint-switch--settings.is-disabled .hint-switch__label,
.hint-switch--settings[disabled] .hint-switch__label { color: var(--muted-dim); }
.hint-switch--settings.is-disabled .hint-switch__knob,
.hint-switch--settings[disabled] .hint-switch__knob { background: var(--dim); }
/* (6) loading: knob blink amber */
.hint-switch--settings[data-state="loading"] {
  border-color: color-mix(in srgb, var(--amber) 60%, transparent);
}
.hint-switch--settings[data-state="loading"] .hint-switch__knob {
  animation: settings-status-pulse 1s ease-in-out infinite;
}
/* (7) error: coral */
.hint-switch--settings[data-state="error"] {
  border-color: color-mix(in srgb, var(--color-danger) 60%, transparent);
  color: var(--color-danger);
}
.hint-switch--settings[data-state="error"] .hint-switch__knob { background: var(--color-danger); }
/* (8) success: green */
.hint-switch--settings[data-state="success"] {
  border-color: color-mix(in srgb, var(--color-success) 60%, transparent);
  color: var(--color-success);
}
.hint-switch--settings[data-state="success"] .hint-switch__knob { background: var(--color-success); }

/* Секция данных: кнопки импорта/экспорта — нейтральные. */
.settings-section--data .tool {
  border: 1px solid transparent;
  background: var(--fill-ghost);
  color: var(--color-text-muted);
}
.settings-section--data .tool:hover {
  background: var(--fill-ghost-hi);
  color: var(--cream);
}
/* Красный — только кнопка удаления, не вся секция данных. */
.settings-section--data .tool--danger {
  border-color: color-mix(in srgb, var(--color-danger) 45%, transparent);
  background: color-mix(in srgb, var(--color-danger) 8%, transparent);
  color: var(--coral-soft);
}
.settings-section--data .tool--danger:hover {
  border-color: color-mix(in srgb, var(--color-danger) 70%, transparent);
  background: color-mix(in srgb, var(--color-danger) 14%, transparent);
  color: #f5d8d1;
}

/* view-subtitle pattern for #settingsSubtitle */
#settingsSubtitle { color: var(--muted); font-size: var(--fs-base); margin: 4px 0 0; }

/* Прогресс-бар загрузки модели */
progress {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-panel);
  border: 1px solid var(--color-border);
}
progress::-webkit-progress-bar {
  background: var(--bg-panel);
  border-radius: 3px;
}
progress::-webkit-progress-value {
  background: var(--color-primary);
  border-radius: 3px;
  transition: width 0.3s ease;
}
progress::-moz-progress-bar {
  background: var(--color-primary);
  border-radius: 3px;
}

/* ---------- Адаптивность ----------
   Брейкпоинты из template-fronted/library.html (1280px / 900px)
   и template-fronted/practice.html (1180px / 860px / 560px). */

@media (max-width: 1180px) {
  .practice-dock { margin: 0 24px 32px; border-radius: 44px; gap: 20px; }
  .practice-actions { margin-left: 0; width: 100%; justify-content: center; }
}

@media (max-width: 860px) {
  .practice-top { grid-template-columns: 1fr 1fr; padding: 16px 20px; gap: 12px; }
  .practice-title { grid-column: 1 / -1; grid-row: 2; min-width: 0; padding-top: 0; }
  .practice-back, .practice-tools { padding-bottom: 0; }
  .hint-switch { gap: 0; padding: 0 4px; font-size: 0; }
  .rec-panel-heard { min-width: 0; flex: 1; }
  .practice-wave { width: 90px; }
}

/* Униксиз @media (max-width: 560px) — объединение всех правил для узких телефонов */
@media (max-width: 560px) {
  .settings-status { display: inline-block; margin-top: 10px; }
  /* В строке голосового ввода статус стоит рядом с кнопками — сдвигать его
     вниз не нужно, иначе блок действий снова разъезжается. */
  .settings-row--voice .settings-row__control .settings-status { margin-top: 0; }
  .practice-stage { place-items: start center; padding: 24px 18px; }
  .poem-view { font-size: clamp(23px, 7vw, 32px); padding: 20px 18px; }
  .practice-preview { display: none; }
  .practice-dock { margin: 0 12px 18px; padding: 16px; border-radius: 28px; gap: 12px; }
  .practice-mic { width: 78px; height: 78px; }
  .practice-mic svg { width: 34px; height: 34px; }
  .practice-wave { display: none; }
  .rec-panel-heard { flex: 1 1 calc(100% - 90px); min-width: 0; min-height: 78px; padding-left: 16px; }
  .practice-answer { flex: 1 1 100%; gap: 8px; }
  .practice-answer__input { height: 46px; padding: 0 16px; font-size: 16px; }
  .act { height: 54px; padding: 0 20px; }
  .act--submit { height: 46px; }
  .practice-answer__hint { display: none; }
  .act--skip, .act--mark, .act--target, .act--reset, .act--repeat, .act--retry { height: 42px; padding: 0 14px; font-size: 12px; }
  .act--hint span small { display: none; }
  .sound-switch span { display: none; }
  .practice-actions {
    flex: 1 1 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .practice-actions::-webkit-scrollbar { display: none; }
  .practice-actions .act { flex: 0 0 auto; }
  .wave { display: none; }
  .act-menu { right: auto; left: 0; }
  /* Строки настроек стекуются вертикально на узких экранах */
  .settings-row { flex-direction: column; align-items: stretch; gap: 10px; }
  /* В колонке flex-basis текста становится высотой: без сброса описание
     растягивалось на 320 px пустоты. */
  .settings-row__text,
  .settings-row--voice .settings-row__text { flex: 0 1 auto; }
  .settings-row__control, .settings-row__actions { justify-content: flex-start; }
  /* Голосовой ввод: действия в один ряд, по левому краю, без растягивания */
  .settings-row--voice .settings-row__control {
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    gap: 6px;
  }
  /* Кнопки голосового ввода на телефоне: плотнее, чтобы статус и действия
     занимали две строки, а не четыре. */
  .settings-row--voice .settings-row__control .tool {
    min-height: 36px;
    padding: 8px 10px;
    gap: 6px;
    font-size: 0.8125rem;
  }
  /* Карточкам немного меньше внутреннего поля */
  .settings-section { padding: 20px 16px; }
  .settings-section__title { font-size: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  .practice-screen *, .practice-screen *::before, .practice-screen *::after { transition: none !important; animation: none !important; }
  /* Панели и меню тоже: при повышенной чувствительности
     переходы выключаются полностью — интерфейс меняется мгновенно. */
  .sidebar,
  .sidebar-toggle__icon,
  .right-panel,
  .panel-scrim,
  .main-panel { transition: none !important; }
}


@media (max-width: 640px) {
  /* Компактный выбор сложности стекается в колонку */
  .settings-group--levels { grid-template-columns: 1fr; }
}

/* Правая панель — колонка только на широком экране (≥1100px):
   там затемнение не нужно, карточки остаются кликабельными.
   Ниже панель накладывается поверх контента и закрывается кликом
   по затемнению. Граница совпадает с PANEL_LAYOUT_MIN_WIDTH в app.js. */
@media (min-width: 1100px) {
  .panel-scrim { display: none !important; }
}

/* Узкий сайдбар-полоска: только иконки (как в шаблоне на 900px).
   Кнопка сворачивания здесь не нужна: ширина задана вьюпортом. */
@media (max-width: 900px) {
  .sidebar,
  /* Свёрнутое состояние не должно менять отступы полоски: иначе иконки
     навигации сдвигаются на 4 px при переключении меню. */
  .app-shell.sidebar-collapsed .sidebar { width: 76px; padding: 20px 10px; align-items: center; }
  .sidebar-head { justify-content: center; }
  .sidebar-toggle { display: none; }
  .sidebar-brand { padding: 0; }
  .sidebar-brand-name,
  .nav-item > span,
  .books,
  .streak-card { display: none; }
  .brand-logo { width: 52px; height: 46px; }
  .nav-item {
    width: 52px;
    padding: 0;
    justify-content: center;
  }
  .sidebar-nav { align-items: center; }
  .right-panel { width: min(481px, 100%); }
}

@media (max-width: 760px) {
  /* Mobile: allow normal page scrolling (base CSS sets overflow:hidden) */
  html, body { height: auto; }
  body { overflow: visible; }
  .app-shell,
  .app-shell.panel-open { grid-template-columns: 1fr; height: auto; overflow: visible; }
  .app-shell.panel-open .main-panel { padding-right: 20px; }
  .right-panel { width: min(481px, 100%); }
  .poem-grid { grid-template-columns: 1fr; }
  .main-panel { overflow: visible; padding: 28px 20px 48px; }
  .sidebar {
    flex-direction: row;
    align-items: center;
    padding: var(--space-2xs) var(--space-md);
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .sidebar-brand { margin-bottom: 0; }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; }
  .streak-card { display: none; }
}

@media (max-width: 640px) {
  .field-row { flex-direction: column; }
  .btn-row { flex-direction: column; align-items: stretch; }
  .btn-row .btn { width: 100%; }
  .settings-group,
  .modes { grid-template-columns: 1fr; }
}

/* Узкие телефоны: кнопка «Добавить стихотворение» с nowrap занимала 278 px
   и впритык упиралась в край. Уменьшаем поля и разрешаем перенос строки
   внутри, чтобы она гарантированно помещалась в 320 px. */
@media (max-width: 480px) {
  .btn-add {
    width: 100%;
    justify-content: center;
    padding: 0 16px;
    height: auto;
    min-height: 44px;
    white-space: normal;
    text-align: center;
  }
  /* Подсказка про формат экспорта: на перенесённом тулбаре она должна
     открываться под кнопкой информации, а не поверх соседних кнопок. */
  .tip { max-width: min(340px, 100%); }
}

/* Ручной ввод не выходит за пределы панели даже при увеличенном тексте. */
.practice-answer { min-width: 0; max-width: 100%; }
.practice-answer__input { min-width: 0; }
.practice-actions { min-width: 0; }

/* Прогресс загрузки модели: ширина и отступ перенесены из атрибута
   style=, который политика безопасности вырезала из документа. */
.progress--model {
    width: 100%;
    margin-top: 8px;
}

/* Спрайт с иконками вынесен из атрибута style= в класс. */
.svg-defs {
    position: absolute;
}

/* ============================================================
   Первый запуск: выбор стартового набора
   ============================================================ */
.welcome { max-width: 560px; }
.welcome-list {
    list-style: none;
    margin: 16px 0 20px;
    padding: 0;
    display: grid;
    gap: 8px;
}
.welcome-item {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: baseline;
    gap: 4px 12px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--card);
}
.welcome-item__author { color: var(--muted); font-size: .9em; }
.welcome-item__meta {
    grid-column: 1 / -1;
    color: var(--muted-dim);
    font-size: .8em;
}
.welcome-item strong { font-family: var(--serif-text); font-weight: 600; }

/* ============================================================
   Проверка микрофона
   ============================================================ */
.mic-level {
    height: 12px;
    margin: 18px 0 12px;
    border-radius: 999px;
    background: var(--line);
    overflow: hidden;
}
.mic-level__fill {
    display: block;
    height: 100%;
    width: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--amber-deep), var(--amber-light));
    transition: width .12s linear;
}
.mic-check__status { min-height: 2.6em; color: var(--muted); }

/* ============================================================
   Прогресс строфы внутри области стиха
   ============================================================ */
.stanza-progress {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 0 18px;
    font-size: .8em;
    color: var(--muted-dim);
}
.stanza-progress__track {
    flex: 1;
    height: 4px;
    border-radius: 999px;
    background: var(--line);
    overflow: hidden;
}
.stanza-progress__fill {
    display: block;
    height: 100%;
    width: 0;
    border-radius: inherit;
    background: var(--amber);
    transition: width .25s ease;
}

/* ============================================================
   Меню дополнительных действий в доке
   ============================================================ */
.act-overflow { position: relative; display: inline-flex; }
.act--more { padding: 0; width: 48px; justify-content: center; }
.act-menu {
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    z-index: 20;
    min-width: 220px;
    display: grid;
    gap: 2px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--popover);
    box-shadow: 0 18px 40px rgba(0, 0, 0, .55);
}
.act-menu__item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--cream);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.act-menu__item:hover { background: var(--amber-a10); }
.act-menu__item:focus-visible {
    outline: 2px solid var(--amber);
    outline-offset: -2px;
}
.act-menu__item .act-icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; }

/* Совет о микрофоне во время записи: тишина и «приложение зависло» должны
   выглядеть по-разному. */
.mic-advice {
    display: block;
    margin-top: 6px;
    color: var(--amber-light);
}

@media (prefers-reduced-motion: reduce) {
    .mic-level__fill,
    .stanza-progress__fill { transition: none; }
}
