/* Диктант: спокойная mobile-first тема, без лишних анимаций. */

@font-face {
  font-family: 'Lora';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('libs/fonts/Lora-Cyrillic.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
  font-family: 'Lora';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('libs/fonts/Lora-Latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Lora';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('libs/fonts/Lora-Cyrillic.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
  font-family: 'Lora';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('libs/fonts/Lora-Latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Lora';
  font-style: italic;
  font-weight: 600;
  font-display: swap;
  src: url('libs/fonts/Lora-Italic-Cyrillic.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
  font-family: 'Lora';
  font-style: italic;
  font-weight: 600;
  font-display: swap;
  src: url('libs/fonts/Lora-Italic-Latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light;
  --brand-font: 'Lora', Georgia, 'Times New Roman', serif;
  --bg: #f6f4ef;
  --surface: #fffdf8;
  --surface-2: #efebe2;
  --text: #232a27;
  --muted: #5e6763;
  --border: #ddd7cb;
  --accent: #2f6f5e;
  --accent-strong: #24584b;
  --accent-soft: #e2efe9;
  --on-accent: #ffffff;
  --danger: #9a352b;
  --danger-soft: #f8e5e1;
  --highlight: #e2efe9;
  --highlight-border: #2f6f5e;
  --replace-soft: #f6ead0;
  --replace-border: #a97f28;
  --status-online: #2f9e6b;
  --status-offline: #a97f28;
  --status-neural: #6d4fe0;
  --shadow: 0 12px 34px rgba(25, 35, 30, 0.14);
  --shadow-up: 0 -8px 26px rgba(20, 30, 25, 0.07);
  --backdrop: rgba(10, 16, 13, 0.48);
  --overlay: rgba(16, 26, 21, 0.6);
  --overlay-border: rgba(255, 255, 255, 0.9);
  --on-overlay: #ffffff;
  --toast-bg: #23302a;
  --toast-text: #ffffff;
  --toast-error: #7d2f26;
  --toast-info: #2b4a3f;
  --radius: 14px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141917;
  --surface: #1d2421;
  --surface-2: #242e29;
  --text: #e8ece9;
  --muted: #a3aea9;
  --border: #2f3a35;
  --accent: #7fc7ae;
  --accent-strong: #a5dcc8;
  --accent-soft: #23352e;
  --on-accent: #10201a;
  --danger: #ff9a8c;
  --danger-soft: #3a211e;
  --highlight: #22352d;
  --highlight-border: #7fc7ae;
  --replace-soft: #3a3222;
  --replace-border: #e0b458;
  --status-online: #6fd3a0;
  --status-offline: #e0b458;
  --status-neural: #b0a3ff;
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
  --shadow-up: 0 -8px 26px rgba(0, 0, 0, 0.35);
  --backdrop: rgba(0, 0, 0, 0.6);
  --overlay: rgba(0, 0, 0, 0.65);
  --overlay-border: rgba(255, 255, 255, 0.7);
  --on-overlay: #ffffff;
  --toast-bg: #26332d;
  --toast-text: #e8ece9;
  --toast-error: #5a2a24;
  --toast-info: #244036;
}

/* Авто: следуем системной теме, если пользователь не выбрал явно. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141917;
    --surface: #1d2421;
    --surface-2: #242e29;
    --text: #e8ece9;
    --muted: #a3aea9;
    --border: #2f3a35;
    --accent: #7fc7ae;
    --accent-strong: #a5dcc8;
    --accent-soft: #23352e;
    --on-accent: #10201a;
    --danger: #ff9a8c;
    --danger-soft: #3a211e;
    --highlight: #22352d;
    --highlight-border: #7fc7ae;
    --replace-soft: #3a3222;
    --replace-border: #e0b458;
    --status-online: #6fd3a0;
    --status-offline: #e0b458;
    --status-neural: #b0a3ff;
    --shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
    --shadow-up: 0 -8px 26px rgba(0, 0, 0, 0.35);
    --backdrop: rgba(0, 0, 0, 0.6);
    --overlay: rgba(0, 0, 0, 0.65);
    --overlay-border: rgba(255, 255, 255, 0.7);
    --on-overlay: #ffffff;
    --toast-bg: #26332d;
    --toast-text: #e8ece9;
    --toast-error: #5a2a24;
    --toast-info: #244036;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

body.modal-open {
  overflow: hidden;
}

#app {
  padding-bottom: env(safe-area-inset-bottom);
}

body.reader-active #app {
  padding-bottom: calc(var(--controls-h, 128px) + 12px);
}

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

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Шапка ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 32;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.header-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px 5px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand-mark {
  width: 48px;
  height: 48px;
  flex: none;
  border-radius: 12px;
  box-shadow: 0 0 0 1px rgba(47, 111, 94, 0.14);
}

.brand-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  line-height: 1.1;
}

.brand-text {
  font-family: var(--brand-font);
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: 0.005em;
  line-height: 1.05;
  white-space: nowrap;
}

.brand-slogan {
  margin-top: 4px;
  color: var(--text);
  font-family: var(--brand-font);
  font-size: 0.98rem;
  font-style: italic;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
  white-space: nowrap;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.voice-bar {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px 8px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.voice-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 120px;
  max-width: 100%;
  min-width: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.voice-quick {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex: 0 0 auto;
}

.quick-toggle {
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-size: 0.75rem;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}

.quick-toggle[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.quick-toggle:hover {
  border-color: var(--accent);
}

.quick-toggle:focus-visible,
.quick-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.quick-select {
  max-width: 150px;
  min-height: 30px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-size: 0.75rem;
}

.voice-indicator .voice-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--muted);
}

.voice-dot.online {
  background: var(--status-online);
}

.voice-dot.offline {
  background: var(--status-offline);
}

.voice-dot.neural {
  background: var(--status-neural);
}

.voice-badge {
  flex: none;
  padding: 1px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.7rem;
  color: var(--muted);
}

/* ---------- Основная колонка ---------- */

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 18px 16px 24px;
}

h1 {
  margin: 0 0 8px;
  font-size: 1.45rem;
  line-height: 1.25;
}

h2 {
  margin: 0;
  font-size: 1.1rem;
}

h3 {
  margin: 0 0 10px;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.lead {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.55;
}

.hint {
  margin: 6px 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.banner {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
}

.banner.error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.banner.warning {
  background: var(--warning-soft, #fbeccf);
  color: var(--warning, #8a5a12);
  border: 1px solid var(--warning, #8a5a12);
}

.banner.info {
  background: var(--surface-alt, #f0ede6);
  color: var(--muted);
  border: 1px solid var(--border);
}

/* ---------- Поле текста ---------- */

.text-input {
  display: block;
  width: 100%;
  min-height: 250px;
  padding: 15px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1.03rem;
  line-height: 1.65;
  resize: vertical;
}

.text-input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.text-input:focus-visible {
  border-color: var(--accent);
}

.editor-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 14px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.drop-hint {
  color: var(--muted);
}

.pro-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  margin-top: 12px;
  padding: 10px 12px 10px 14px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: var(--accent-soft);
}

.pro-banner-text {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  min-width: 0;
  color: var(--text);
  font-size: 0.86rem;
  line-height: 1.4;
}

.pro-banner-text strong {
  color: var(--accent-strong);
  font-size: 0.94rem;
}

.pro-banner-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.range-panel {
  margin-top: 12px;
  padding: 6px 14px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.range-panel .check-row {
  margin: 0;
}

.range-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 14px;
  padding: 2px 0 4px;
}

.range-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.range-field input {
  width: 108px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
}

.range-field input:focus-visible {
  border-color: var(--accent);
}

.range-hint {
  flex-basis: 100%;
  margin: 0;
}

.import-message {
  margin: 12px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.9rem;
  line-height: 1.5;
}

.ocr-prompt {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: var(--accent-soft);
}

.ocr-text {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.5;
}

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

.field-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.field-row label {
  font-size: 0.9rem;
  font-weight: 600;
}

.field-row select {
  min-height: 40px;
  max-width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.field-row .hint {
  flex-basis: 100%;
  margin: 0;
}

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
}

.btn:hover {
  background: var(--surface-2);
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.btn.primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.btn.ghost {
  background: transparent;
}

.btn.ghost:hover {
  background: var(--surface-2);
}

.btn.small {
  min-height: 44px;
  padding: 0 13px;
  font-size: 0.88rem;
}

.btn.big {
  width: 100%;
  min-height: 54px;
  margin-top: 16px;
  padding: 0 24px;
  font-size: 1.05rem;
}

.pro-cta {
  width: 100%;
  min-height: 44px;
  margin-top: 8px;
}

.btn:disabled,
.icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
  transform: none;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  aspect-ratio: 1;
  flex: none;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
}

.icon {
  display: block;
  width: 22px;
  height: 22px;
  flex: none;
  color: currentColor;
}

.icon[hidden] {
  display: none !important;
}

.icon-sm {
  width: 18px;
  height: 18px;
}

.icon-btn:hover {
  background: var(--surface-2);
}

.icon-btn:active {
  transform: translateY(1px);
}

.icon-btn.play {
  width: 64px;
  height: 64px;
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.icon-btn.play .icon {
  width: 30px;
  height: 30px;
}

.icon-btn.play:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

/* ---------- Читалка ---------- */

.reader {
  padding-top: 2px;
}

.reader-head {
  position: sticky;
  top: var(--header-h, 72px);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -8px 0 8px;
  padding: 8px 0;
  background: var(--bg);
}

.reader-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.status {
  color: var(--accent);
  font-size: 0.88rem;
  font-weight: 600;
  text-align: right;
}

/* ---------- Панель ударений ---------- */

.stress-phrase {
  margin: 10px 0;
  font-size: 1.05rem;
  line-height: 2.1;
}

.stress-word {
  margin: 0 2px 4px 0;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.stress-word:hover {
  border-color: var(--accent);
}

.stress-word.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.stress-vowels {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}

.stress-vowel {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
  text-transform: lowercase;
  cursor: pointer;
}

.stress-vowel:hover {
  border-color: var(--accent);
}

.stress-vowel.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

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

/* ---------- Проверка диктанта ---------- */

.check-input {
  min-height: 120px;
  margin-top: 8px;
}

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

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: 0.92rem;
  cursor: pointer;
}

.check-row input {
  width: 22px;
  height: 22px;
  flex: none;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.check-summary {
  margin: 12px 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.check-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: 8px 0 12px;
  font-size: 0.82rem;
}

.check-legend span {
  padding: 2px 6px;
  border-radius: 6px;
}

.check-heading {
  margin: 16px 0 8px;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.diff-text {
  margin: 0;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  line-height: 1.75;
}

.diff-missed {
  color: var(--danger);
  text-decoration: underline wavy var(--danger);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.diff-extra {
  color: var(--danger);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

.diff-replace {
  background: var(--replace-soft);
  text-decoration: underline dotted var(--replace-border);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.diff-punct {
  color: var(--accent);
}

/* ---------- Словарь произношения ---------- */

.pron-add {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}

.text-input.pron-input {
  flex: 1 1 140px;
  height: 38px;
  min-height: 38px;
  padding: 0 10px;
  font-size: 0.9rem;
  text-align: center;
}

.pron-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0;
}

.pron-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.pron-text {
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.pron-badge {
  flex: 0 0 auto;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-transform: uppercase;
}

.pron-row .icon-btn {
  margin-left: auto;
}

/* ---------- Библиотека текстов ---------- */

.lib-save {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}

.text-input.lib-input {
  flex: 1 1 180px;
  height: 38px;
  min-height: 38px;
  padding: 0 10px;
  font-size: 0.9rem;
  text-align: center;
}

.lib-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
}

.lib-transfer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 4px;
}

.lib-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.lib-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 220px;
  min-width: 0;
}

.lib-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.lib-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

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

.btn.danger {
  color: var(--danger);
  border-color: var(--danger);
}

/* ---------- Экспорт в аудио ---------- */

.export-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.export-text {
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.phrase-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.phrase {
  padding: 12px 16px;
  border-left: 3px solid transparent;
  border-radius: 0 10px 10px 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.55;
  cursor: pointer;
}

.phrase:not(.current):hover {
  background: var(--surface-2);
}

.phrase.current {
  border-left-color: var(--highlight-border);
  background: var(--highlight);
  color: var(--text);
  font-size: 1.12rem;
  font-weight: 600;
}

.phrase-list.hide-text .phrase:not(.current) {
  display: none;
}

/* ---------- Режимы для детей и дислексии (A8) ---------- */

@font-face {
  font-family: "OpenDyslexic";
  src: url("libs/fonts/OpenDyslexic-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "OpenDyslexic";
  src: url("libs/fonts/OpenDyslexic-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

body.dyslexia-font {
  font-family: "OpenDyslexic", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  letter-spacing: 0.01em;
}

/* Крупный шрифт и увеличенные интервалы — чтобы читать с расстояния. */
body.large-text .phrase-list {
  gap: 14px;
}

body.large-text .phrase {
  padding: 16px 20px;
  font-size: 1.4rem;
  line-height: 1.85;
}

body.large-text .phrase.current {
  font-size: 1.6rem;
}

/* ---------- Нижняя панель ---------- */

.controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-up);
}

.controls-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 16px;
  position: relative;
}

.progress-track {
  height: 3px;
  margin: -8px 0 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.15s ease;
}

.controls-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.phrase.paragraph-start::before {
  content: '¶ ';
  color: var(--muted);
  font-size: 0.85em;
  opacity: 0.75;
}

.quick-settings {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px;
}

.quick-chip {
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--fg);
  font: inherit;
  font-size: 0.78rem;
  line-height: 1.1;
  cursor: pointer;
  white-space: nowrap;
}

.quick-chip:hover {
  border-color: var(--accent);
}

.quick-chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.quick-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.quick-rate,
.quick-size {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 1 1 160px;
  min-width: 0;
  min-height: 44px;
  color: var(--muted);
  font-size: 0.76rem;
}

.quick-size {
  flex: 0 1 auto;
}

.quick-size .quick-select {
  min-height: 44px;
  max-width: 150px;
}

.cleanup-panel {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}

.cleanup-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.cleanup-head > span {
  flex: 1 1 220px;
}

.cleanup-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
}

.cleanup-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--bg);
  font-size: 0.82rem;
}

.cleanup-list .cleanup-text {
  flex: 1 1 200px;
  overflow-wrap: anywhere;
}

.cleanup-list .cleanup-rule {
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
}

.estimate-line {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.quick-rate-label {
  flex: none;
  white-space: nowrap;
}

.quick-rate input[type="range"] {
  flex: 1 1 70px;
  min-width: 56px;
  height: 44px;
  margin: 0;
  accent-color: var(--accent);
}

.quick-rate output {
  min-width: 2.2em;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.controls-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.controls-group.left {
  justify-self: end;
}

.controls-group.right {
  justify-self: start;
}

.controls-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}

.progress {
  min-width: 56px;
}

.kbd-hint {
  text-align: right;
}

/* ---------- Настройки ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: var(--backdrop);
}

.settings-panel {
  position: fixed;
  z-index: 31;
  top: calc(50% + var(--header-h, 72px) / 2);
  left: 50%;
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - var(--header-h, 72px) - 24px);
  max-height: calc(100dvh - var(--header-h, 72px) - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.settings-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.settings-body {
  padding: 8px 24px 24px;
}

.license-backdrop {
  z-index: 40;
}

.license-panel {
  z-index: 41;
  width: min(480px, calc(100vw - 24px));
}

.license-status {
  margin: 8px 0 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
}

.license-status.pro {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.license-reason {
  margin: 0 0 10px;
  padding: 10px 14px;
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 0.9rem;
}

.license-line {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

.license-activate {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 14px 0 6px;
}

.license-activate label {
  flex: 0 0 100%;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
}

.text-input.license-input {
  flex: 1 1 220px;
  width: 100%;
  height: 44px;
  min-height: 44px;
  padding: 0 12px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.9rem;
  letter-spacing: 0.03em;
  text-align: center;
}

.license-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 12px;
}

.license-buy {
  margin: 4px 0 12px;
}

.license-buy a {
  color: var(--accent-strong);
  font-weight: 600;
  text-underline-offset: 3px;
}

.license-devices {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
}

.license-device {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

.license-device-info {
  min-width: 0;
  font-size: 0.84rem;
}

.license-device-name {
  display: block;
  color: var(--text);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.license-device-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.license-device.current {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.settings-group {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.settings-group:last-of-type {
  border-bottom: 0;
}

.range-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 0 2px;
  font-size: 0.92rem;
}

.range-label output {
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

input[type="range"] {
  display: block;
  width: 100%;
  height: 44px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.tempo-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 2px 0 6px;
}

.tempo-status {
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.select-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  flex-wrap: wrap;
  margin: 10px 0 2px;
  font-size: 0.92rem;
}

.select-row label {
  font-weight: 600;
}

.select-row select,
.select-row input[type="number"] {
  min-height: 40px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.select-row input[type="number"] {
  width: 76px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.select-row .hint {
  margin: 0;
}

.check-row,
.radio-row {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 44px;
  padding: 5px 0;
  font-size: 0.92rem;
  line-height: 1.4;
  cursor: pointer;
}

.check-row input,
.radio-row input {
  width: 22px;
  height: 22px;
  flex: none;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.voice-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0;
}

.voice-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}

.voice-select {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 44px;
  cursor: pointer;
}

.voice-row input[type="radio"] {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
}

.voice-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.voice-row .voice-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
  font-weight: 600;
}

.voice-meta {
  color: var(--muted);
  font-size: 0.72rem;
}

.voice-row .btn {
  min-height: 44px;
  padding: 0 11px;
  font-size: 0.78rem;
}

.voice-hint ul {
  margin: 6px 0 0;
  padding-left: 20px;
}

.piper-block {
  margin: 12px 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.piper-block .check-row {
  padding-top: 0;
}

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

#piperProgress,
#piperEnProgress {
  width: 100%;
  height: 10px;
  margin: 4px 0 2px;
  accent-color: var(--accent);
}

.install-hint {
  margin-top: 14px;
}

/* ---------- История ---------- */

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 10px 0 16px;
}

.history-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.history-info {
  flex: 1 1 240px;
  min-width: 0;
}

.history-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.94rem;
  font-weight: 600;
}

.history-meta {
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.75rem;
}

.history-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.history-actions .btn {
  min-height: 44px;
}

.icon-btn.small {
  width: 44px;
  height: 44px;
}

.icon-btn.small .icon {
  width: 18px;
  height: 18px;
}

/* ---------- Оверлеи ---------- */

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--overlay);
}

.drop-card {
  max-width: 420px;
  padding: 38px 28px;
  border: 3px dashed var(--overlay-border);
  border-radius: 20px;
  color: var(--on-overlay);
  font-size: 1.15rem;
  font-weight: 600;
  text-align: center;
}

.loading-overlay {
  position: fixed;
  top: calc(84px + env(safe-area-inset-top));
  left: 50%;
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  font-weight: 600;
  transform: translateX(-50%);
  pointer-events: none;
}

.spinner {
  width: 18px;
  height: 18px;
  flex: none;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 80;
  width: max-content;
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--toast-bg);
  color: var(--toast-text);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  line-height: 1.45;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

body.reader-active .toast {
  bottom: calc(116px + env(safe-area-inset-bottom));
}

.toast.error {
  background: var(--toast-error);
}

.toast.info {
  background: var(--toast-info);
}

/* ---------- Адаптивность ---------- */

@media (max-width: 700px) {
  .kbd-hint {
    display: none;
  }

  .controls-info {
    justify-content: center;
  }

  .header-inner {
    padding-left: 12px;
    padding-right: 12px;
  }

  .voice-bar {
    padding-left: 12px;
    padding-right: 12px;
  }

  .container {
    padding-left: 12px;
    padding-right: 12px;
  }

  .settings-panel {
    width: calc(100vw - 16px);
    max-height: calc(100vh - var(--header-h, 72px) - 16px);
    max-height: calc(100dvh - var(--header-h, 72px) - 16px);
  }

  .settings-body {
    padding-left: 14px;
    padding-right: 14px;
  }

  .voice-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .voice-row .btn {
    grid-column: 1;
    justify-self: start;
  }

  .history-actions {
    width: 100%;
    margin-left: 0;
  }
}

@media (min-width: 701px) {
  .text-input {
    min-height: 300px;
  }

  .controls-inner {
    padding-bottom: 10px;
  }
}

@media (max-width: 700px) {
  .brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 10px;
  }

  .brand-text {
    font-size: 1.45rem;
  }

  .brand-slogan {
    font-size: 0.9rem;
    margin-top: 3px;
  }
}

@media (max-width: 420px) {
  .header-inner {
    gap: 6px 8px;
  }

  .brand {
    gap: 9px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 10px;
  }

  .brand-text {
    font-size: 1.36rem;
  }

  .brand-slogan {
    font-size: 0.88rem;
  }

  .header-actions {
    margin-left: auto;
  }
}

@media (max-width: 380px) {
  .header-inner {
    padding: 10px 10px 4px;
    gap: 6px 6px;
  }

  .brand-text {
    font-size: 1.28rem;
  }

  .brand-slogan {
    font-size: 0.84rem;
  }

  .header-actions {
    gap: 6px;
  }

  .header-actions .btn.small {
    padding: 0 10px;
    font-size: 0.8rem;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
  }

  .quick-select {
    max-width: 146px;
  }

  .voice-indicator {
    flex-basis: 60px;
  }
}

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