/* ====== RESET & BASE ====== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #FAFAF8;
  --bg-card: #FFFFFF;
  --bg-card-hover: #F5F5F0;
  --text: #1A1A1A;
  --text-secondary: #6B6B6B;
  --text-muted: #9B9B9B;
  --accent: #2D5A27;
  --accent-light: #E8F0E6;
  --accent-hover: #3D7A35;
  --success: #2D8A4E;
  --success-bg: #E6F5EC;
  --error: #C53030;
  --error-bg: #FEE;
  --warning: #D69E2E;
  --border: #E8E8E3;
  --border-light: #F0F0EC;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Playfair Display', Georgia, serif;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg: #141414;
  --bg-card: #1E1E1E;
  --bg-card-hover: #282828;
  --text: #E8E8E3;
  --text-secondary: #A0A0A0;
  --text-muted: #666;
  --accent: #5CB85C;
  --accent-light: #1E2E1E;
  --accent-hover: #6ECF6E;
  --success: #48BB78;
  --success-bg: #1A2E1A;
  --error: #FC8181;
  --error-bg: #2D1B1B;
  --warning: #ECC94B;
  --border: #2D2D2D;
  --border-light: #252525;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

/* Глобальный .hidden — используется множеством карточек на главной.
   До этого правила были только локальные (.review-card.hidden,
   .next-btn.hidden и т. д.), и для остальных classList.add('hidden')
   не имел эффекта. Поэтому фантомные карточки оставались видимыми. */
.hidden { display: none !important; }

/* Kill sticky :focus outlines on mouse — keep for keyboard users */
button:focus,
.option-btn:focus,
.module-card:focus,
.nav-btn:focus,
.rule-tab:focus,
.back-btn:focus {
  outline: none;
}
button:focus-visible,
.option-btn:focus-visible,
.module-card:focus-visible,
.nav-btn:focus-visible,
.rule-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Глобально убираем тёмный «тап-флэш» на iOS, чтобы рамка не вспыхивала
   при прокрутке/скролле и не зависала. */
* { -webkit-tap-highlight-color: transparent; }
html, body { -webkit-touch-callout: none; }

/* ====== SCREENS ====== */
.screen {
  display: none;
  min-height: 100dvh;
  animation: fadeIn 0.25s ease;
  /* Сверху не лезем под Dynamic Island / notch / status bar.
     env(safe-area-inset-top) подставляет ровно столько, сколько надо
     устройству: 0 в браузере на десктопе, ~20px на старых iPhone, ~47px
     с notch (X–13), ~59px с Dynamic Island (14 Pro+). Без запаса. */
  padding-top: env(safe-area-inset-top, 0px);
}
.screen.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes popIn {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* ====== HOME ====== */
.home-container {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px 100px;
}

.home-header {
  text-align: center;
  padding: 32px 0 24px;
}

.logo-mark {
  /* «Занавес»: flex-контейнер без подложки. Кавычки крупные,
     текст между ними. align-items: baseline — главное; так глифы
     разного размера выравниваются по типографическому baseline'у,
     и оптические центры совпадают. */
  position: relative;
  height: 96px;
  padding: 0 4px;
  background: transparent;
  color: var(--accent);
  font-family: var(--font-display);
  display: inline-flex;
  align-items: stretch;
  justify-content: center;
  gap: 0;
  margin-bottom: 12px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  overflow: visible;
  transition: gap 380ms cubic-bezier(0.22, 1, 0.36, 1);
  vertical-align: middle;
}

.logo-mark.is-open { gap: 12px; }

.logo-quote {
  /* Кавычка занимает всю высоту контейнера и сама центрирует свой
     глиф через flex. Это исключает зависимость от baseline-метрик
     шрифта — глиф геометрически в центре 96px-бокса. */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 84px;
  font-weight: 800;
  line-height: 1;
}

/* logo-spacer — невидимый «толкатель», расширяется на 220px при
   открытии и раздвигает кавычки. Не содержит текста — текст рисуется
   отдельно через .logo-reveal с position: absolute. */
.logo-spacer {
  display: inline-block;
  width: 0;
  flex: 0 0 auto;
  align-self: stretch;
  transition: width 420ms cubic-bezier(0.22, 1, 0.36, 1);
}
.logo-mark.is-open .logo-spacer { width: 220px; }

.logo-reveal {
  /* HTML span (не SVG) — корректно рендерит надстрочный знак ударения
     U+0301 как настоящую диакритику над буквой. Centering через
     position:absolute top/left 50% + translate. Тонкий вертикальный
     сдвиг — через CSS-переменную --logo-text-offset, которую можно
     править в админке. */
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, calc(-50% + var(--logo-text-offset, 6px)));
  white-space: nowrap;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.2px;
  color: var(--text);
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms ease 0ms;
}
.logo-mark.is-open .logo-reveal {
  opacity: 1;
  transition: opacity 220ms ease 200ms;
}

/* Bubbles — лёгкие частицы, разлетающиеся при разъезде кавычек.
   Спавнятся JS-ом по разу на каждое открытие занавеса. */
.logo-bubble {
  position: absolute;
  top: 50%; left: 50%;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%);
  filter: blur(0.3px);
  animation: logoBubble 900ms cubic-bezier(0.2, 0.8, 0.4, 1) forwards;
}
@keyframes logoBubble {
  0%   { opacity: 0; transform: translate(calc(-50% + 0px), calc(-50% + 0px)) scale(0.4); }
  20%  { opacity: 0.65; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--bx, 0px)), calc(-50% + var(--by, 0px))) scale(1.1); }
}

@media (prefers-reduced-motion: reduce) {
  .logo-mark, .logo-quote, .logo-reveal { transition-duration: 80ms !important; }
}

.logo-text {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 4px;
}

/* (logo-accent цветом больше не выделяем — оставляем только знак ударения) */

.tagline {
  color: var(--text-secondary);
  font-size: 14px;
  font-style: italic;
}

/* User stats card */
.user-stats-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.stat-row {
  display: flex;
  justify-content: space-around;
  margin-bottom: 12px;
}

.stat-item {
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.xp-bar-container {
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

.xp-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: 3px;
  transition: width 0.5s ease;
}

.rank-label {
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Daily goal */
.daily-goal {
  background: var(--accent-light);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.daily-icon {
  font-size: 24px;
  line-height: 1;
}

.daily-text {
  flex: 1;
  font-size: 14px;
  color: var(--text);
}

.daily-bar-wrap {
  width: 100%;
  height: 4px;
  background: rgba(0,0,0,0.1);
  border-radius: 2px;
  overflow: hidden;
}

.daily-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.5s ease;
}

.daily-goal.completed {
  border-color: var(--success);
  background: var(--success-bg);
}
.daily-goal.completed .daily-icon::after { content: ' ✓'; }

/* Word of the day */
.word-of-day {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
  color: white;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

.word-of-day::after {
  content: '';
  position: absolute;
  top: -30px;
  right: -30px;
  width: 100px;
  height: 100px;
  background: rgba(255,255,255,0.08);
  border-radius: 50%;
}

.word-of-day:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.wod-badge {
  display: inline-block;
  background: rgba(255,255,255,0.2);
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.wod-word {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 6px;
}

.wod-tip {
  font-size: 13px;
  opacity: 0.9;
  line-height: 1.4;
}

/* Module grid */
.modules-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.module-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
  box-shadow: var(--shadow);
}

.module-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.module-card:active {
  transform: translateY(0);
}

.module-icon {
  width: 48px;
  height: 48px;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 20px;
  font-weight: 700;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.module-info {
  flex: 1;
}

.module-info h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 2px;
}

.module-info p {
  font-size: 13px;
  color: var(--text-secondary);
}

.module-progress {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}

.module-mix {
  background: linear-gradient(135deg, var(--accent-light), var(--bg-card));
  border-color: var(--accent);
}

/* ====== BOTTOM NAV ====== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 100;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 12px;
  transition: color var(--transition);
}

.nav-btn.active { color: var(--accent); font-weight: 600; }
.nav-btn:hover { color: var(--accent); }
.nav-icon { font-size: 20px; line-height: 1; }

/* ====== TRAINING SCREEN ====== */
.training-container {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.training-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.back-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.back-btn:hover { border-color: var(--accent); color: var(--accent); }

.training-title {
  flex: 1;
  font-weight: 600;
  font-size: 16px;
}

.training-counter {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

.streak-indicator {
  text-align: center;
  margin-bottom: 8px;
  font-size: 16px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.3s;
}
.streak-indicator.visible { opacity: 1; }

.progress-bar-training {
  height: 4px;
  background: var(--border-light);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 32px;
}

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

/* Question */
.question-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px 0;
}

.question-word {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 12px;
  letter-spacing: 1px;
  line-height: 1.3;
}

.question-word .stress-slot {
  display: inline-block;
  border-bottom: 3px solid var(--accent);
  min-width: 24px;
  text-align: center;
  color: var(--accent);
  font-weight: 800;
}

.question-hint {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.question-hint.flavor-hint {
  font-style: italic;
  color: var(--accent);
  opacity: 0.9;
}

.question-context {
  font-size: 14px;
  color: var(--text-muted);
  font-style: italic;
  max-width: 320px;
}

.question-sentence {
  font-size: 20px;
  line-height: 1.6;
  max-width: 360px;
  margin: 0 auto 12px;
}

.question-sentence .gap {
  display: inline-block;
  border-bottom: 2px dashed var(--accent);
  min-width: 80px;
  padding: 0 4px;
  color: var(--accent);
  font-weight: 600;
}

/* Options */
.options-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 0 20px;
}

.option-btn {
  width: 100%;
  padding: 16px 20px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 17px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  box-shadow: var(--shadow);
  /* Защита от переполнения: длинные слова без пробелов всё равно ломают
     контейнер по ширине; разрешаем перенос. */
  min-width: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* :hover on options only for real mouse pointers */
@media (hover: hover) and (pointer: fine) {
  .option-btn:hover:not(.disabled) {
    border-color: var(--accent);
    background: var(--accent-light);
  }
}
/* On touch: no hover border/bg at all — only real answer states trigger color */
.option-btn { touch-action: manipulation; user-select: none; -webkit-user-select: none; }

.option-btn.correct {
  border-color: var(--success);
  background: var(--success-bg);
  color: var(--success);
  animation: popIn 0.3s ease;
}

.option-btn.wrong {
  border-color: var(--error);
  background: var(--error-bg);
  color: var(--error);
  animation: shake 0.4s ease;
}

.option-btn.disabled {
  cursor: default;
  opacity: 0.6;
}

.option-btn.correct.disabled { opacity: 1; }

/* Two-column options for stress.
   auto-fit + minmax(150px, 1fr) — если длинные слова не помещаются в
   две колонки на узком экране, кнопки автоматически встают одна под
   другой. word-break + min-width:0 защищают от переполнения по
   ширине, когда содержимое длиннее ячейки. */
.options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  padding: 0 0 20px;
}

.options-grid .option-btn {
  text-align: center;
  font-size: 20px;
  min-width: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* Ударная гласная: вместо combining U+0301 (который в Inter/SF Pro
   плывёт вправо, а в Safari иногда рисуется с dotted-circle
   fallback'ом) рисуем acute через ::before с standalone-символом
   U+00B4 ´ и абсолютным позиционированием поверх буквы.
   Центрируем через left:50% + translateX(-50%) — это работает
   одинаково в Chrome, Firefox, Safari, iOS WebKit. */
.sv {
  position: relative;
  display: inline-block;
  /* Чуть-чуть пространства сверху для метки — чтобы она не вылезала
     за пределы строки и не обрезалась line-height'ом. */
  padding-top: 0.15em;
}
.sv::before {
  content: '\B4';
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -0.05em);
  font-size: 0.95em;
  line-height: 1;
  font-weight: 700;
  pointer-events: none;
  color: inherit;
}

/* Explanation */
.explanation-area {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  animation: slideUp 0.3s ease;
}

.explanation-area.hidden { display: none; }

.explanation-area h4 {
  font-size: 14px;
  color: var(--accent);
  margin-bottom: 6px;
  font-weight: 600;
}

.explanation-area p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.explanation-area .rule-tag {
  display: inline-block;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  margin-top: 8px;
}

/* Next button */
.next-btn {
  width: 100%;
  padding: 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 16px;
}

.next-btn:hover { background: var(--accent-hover); }
.next-btn.hidden { display: none; }

/* ====== RESULTS ====== */
.results-container {
  max-width: 480px;
  margin: 0 auto;
  padding: 40px 16px;
  text-align: center;
}

.results-icon {
  font-size: 64px;
  margin-bottom: 16px;
  animation: popIn 0.5s ease;
}

.results-title {
  font-family: var(--font-display);
  font-size: 28px;
  margin-bottom: 8px;
}

.results-subtitle {
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 15px;
}

.results-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-bottom: 32px;
}

.result-stat { text-align: center; }

.result-value {
  display: block;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
}

.result-stat:first-child .result-value { color: var(--success); }
.result-stat:nth-child(2) .result-value { color: var(--error); }
.result-stat:last-child .result-value { color: var(--accent); }

.result-label {
  font-size: 13px;
  color: var(--text-muted);
}

.mistakes-review {
  text-align: left;
  margin-bottom: 32px;
}

.mistakes-review h3 {
  font-size: 16px;
  margin-bottom: 12px;
}

.mistake-item {
  background: var(--error-bg);
  border: 1px solid var(--error);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 8px;
  font-size: 14px;
}

.mistake-item .mistake-wrong {
  text-decoration: line-through;
  color: var(--error);
  margin-right: 8px;
}

.mistake-item .mistake-correct {
  color: var(--success);
  font-weight: 600;
}

.mistake-item .mistake-rule {
  display: block;
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: 13px;
}

.results-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-primary {
  padding: 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  padding: 14px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

/* ====== STATS SCREEN ====== */
.stats-container {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px 100px;
}

.stats-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.stats-header h2 {
  font-size: 20px;
  font-weight: 700;
}

.big-stats {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.big-stat {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}

.big-stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.big-stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-top: 4px;
}

/* Activity grid */
.calendar-section {
  margin-bottom: 24px;
}

.calendar-section h3,
.module-stats-section h3,
.problem-words-section h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

.activity-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.activity-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--border-light);
}

.activity-cell.l1 { background: #c6e48b; }
.activity-cell.l2 { background: #7bc96f; }
.activity-cell.l3 { background: #239a3b; }
.activity-cell.l4 { background: #196127; }

[data-theme="dark"] .activity-cell.l1 { background: #1E3A1E; }
[data-theme="dark"] .activity-cell.l2 { background: #2D5A2D; }
[data-theme="dark"] .activity-cell.l3 { background: #3D7A3D; }
[data-theme="dark"] .activity-cell.l4 { background: #4D9A4D; }

/* Module stats */
.module-stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}

.module-stat-name {
  font-weight: 500;
  font-size: 14px;
}

.module-stat-bar-wrap {
  flex: 1;
  max-width: 120px;
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  margin: 0 12px;
  overflow: hidden;
}

.module-stat-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
}

.module-stat-pct {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  min-width: 40px;
  text-align: right;
}

/* Problem words */
.problem-word-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--error-bg);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 14px;
}

.problem-word-item .pw-word { font-weight: 600; }
.problem-word-item .pw-stat { color: var(--error); font-size: 13px; }

/* ====== RULES SCREEN ====== */
.rules-container {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px 100px;
}

.rules-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.rules-header h2 { font-size: 20px; font-weight: 700; }

/* Вводная фраза над аккордеоном */
.rules-intro {
  color: var(--text-muted);
  font-size: 13px;
  margin: -6px 0 16px;
  font-style: italic;
}

/* ========== Аккордеон правил ========== */
.rules-accordion {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.rule-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: border-color 0.2s ease, box-shadow 0.25s ease;
}
.rule-section.open {
  border-color: var(--accent);
}

.rule-section-head {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 16px;
  background: transparent;
  border: none;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  transition: background 0.18s ease;
}
.rule-section-head:active { transform: none; }

.rs-icon {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 18px;
  font-weight: 700;
  font-family: 'Playfair Display', Georgia, serif;
  letter-spacing: -0.02em;
}

.rs-title-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.rs-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.rs-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rs-chevron {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-size: 26px;
  line-height: 1;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), color 0.2s ease;
}
.rule-section.open .rs-chevron {
  transform: rotate(90deg);
  color: var(--accent);
}

.rule-section-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.32s cubic-bezier(0.4, 0, 0.2, 1);
}
.rule-section-inner {
  padding: 0 18px 18px;
  line-height: 1.7;
  font-size: 15px;
  border-top: 1px solid var(--border);
  margin-top: 0;
  padding-top: 14px;
}

/* Унаследованные стили содержимого правил */
.rule-section-inner h3 { display: none; } /* заголовок дублирует head — скрываем */
.rule-section-inner h4 {
  font-size: 14px;
  margin: 14px 0 6px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.01em;
}
.rule-section-inner p {
  margin-bottom: 8px;
  color: var(--text-secondary);
}
.rule-section-inner .example {
  background: var(--accent-light);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin: 8px 0;
  font-size: 14px;
  color: var(--text);
}
.rule-section-inner .example .correct { color: var(--success); font-weight: 600; }
.rule-section-inner .example .wrong { color: var(--error); text-decoration: line-through; }
.rule-section-inner ul {
  padding-left: 20px;
  margin-bottom: 10px;
}
.rule-section-inner li {
  margin-bottom: 4px;
  color: var(--text-secondary);
}

/* Компактный режим legacy (не используется, но оставляем пустышку на случай) */
.rules-tabs { display: none; }
.rule-tab {
  padding: 8px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}

.rule-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.rule-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  line-height: 1.7;
  font-size: 15px;
}

.rule-content h3 {
  font-size: 18px;
  margin-bottom: 12px;
  color: var(--accent);
}

.rule-content h4 {
  font-size: 15px;
  margin: 16px 0 8px;
  color: var(--text);
}

.rule-content p {
  margin-bottom: 10px;
  color: var(--text-secondary);
}

.rule-content .example {
  background: var(--accent-light);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin: 8px 0;
  font-size: 14px;
}

.rule-content .example .correct { color: var(--success); font-weight: 600; }
.rule-content .example .wrong { color: var(--error); text-decoration: line-through; }

.rule-content ul {
  padding-left: 20px;
  margin-bottom: 10px;
}

.rule-content li {
  margin-bottom: 4px;
  color: var(--text-secondary);
}

/* ====== SETTINGS ====== */
.settings-container {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px 100px;
}

.settings-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.settings-header h2 { font-size: 20px; font-weight: 700; }

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.setting-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.setting-item:last-child { border-radius: 0 0 var(--radius) var(--radius); }

.setting-item label {
  font-size: 15px;
  font-weight: 500;
}

.setting-item select,
.setting-item input[type="checkbox"] {
  font-family: inherit;
  font-size: 14px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

.setting-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.setting-item.danger {
  justify-content: center;
  margin-top: 24px;
  border-radius: var(--radius);
}

.setting-item.danger button {
  background: none;
  border: none;
  color: var(--error);
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

/* ====== TOAST ====== */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* (раньше было .toast.hidden{display:block} как хак — больше не нужно
   после добавления глобального .hidden{display:none !important}) */

/* ====== XP POPUP ====== */
.xp-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  font-size: 48px;
  font-weight: 800;
  color: var(--accent);
  opacity: 0;
  pointer-events: none;
  z-index: 200;
  animation: xpPop 0.8s ease forwards;
}

@keyframes xpPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  30% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1); }
}

/* ====== LEVEL UP OVERLAY ====== */
.levelup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  animation: fadeIn 0.3s ease;
}

.levelup-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.4s ease;
  max-width: 320px;
}

.levelup-card .lu-icon {
  font-size: 56px;
  margin-bottom: 16px;
}

.levelup-card h2 {
  font-family: var(--font-display);
  font-size: 24px;
  margin-bottom: 8px;
}

.levelup-card p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.levelup-card button {
  padding: 12px 32px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* ====== ACHIEVEMENT TOAST ====== */
.achievement-toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: white;
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 280px;
  max-width: 90vw;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s;
  opacity: 0;
}
.achievement-toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.achievement-toast .ach-icon {
  font-size: 36px;
  line-height: 1;
  flex-shrink: 0;
}
.achievement-toast .ach-content { flex: 1; }
.achievement-toast .ach-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.8;
  margin-bottom: 2px;
}
.achievement-toast .ach-name {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
}
.achievement-toast .ach-desc {
  font-size: 12px;
  opacity: 0.9;
  margin-top: 2px;
}

/* ====== LITERARY QUOTE ====== */
.result-quote {
  background: var(--bg-card);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin: 0 0 24px 0;
  text-align: left;
  font-family: var(--font-display);
  animation: slideUp 0.5s ease;
}
.quote-text {
  font-size: 15px;
  line-height: 1.5;
  font-style: italic;
  color: var(--text);
  margin-bottom: 6px;
}
.quote-author {
  font-size: 13px;
  color: var(--text-secondary);
  font-style: normal;
  text-align: right;
}

/* ====== ACHIEVEMENTS SECTION (in stats) ====== */
.achievements-section { margin-bottom: 24px; }
.achievements-section h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}
.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 10px;
}
.ach-badge {
  aspect-ratio: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  cursor: help;
  transition: transform var(--transition);
  position: relative;
}
.ach-badge.locked {
  opacity: 0.25;
  filter: grayscale(1);
}
.ach-badge:hover { transform: scale(1.1); }
.ach-badge .ach-tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 11px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
  z-index: 10;
}
.ach-badge:hover .ach-tooltip { opacity: 1; }

/* ====== RESPONSIVE ====== */
@media (max-width: 400px) {
  .question-word { font-size: 28px; }
  .options-grid .option-btn { font-size: 17px; padding: 14px; }
  .big-stats { flex-direction: column; }
}


/* ========================================================== */
/* ====== ANIMATIONS & MICRO-INTERACTIONS ================= */
/* ========================================================== */

/* Keyframes */
@keyframes ripple {
  to { transform: scale(4); opacity: 0; }
}
@keyframes correctPulse {
  0%   { box-shadow: 0 0 0 0 rgba(72, 187, 120, 0.55); }
  60%  { box-shadow: 0 0 0 14px rgba(72, 187, 120, 0); }
  100% { box-shadow: 0 0 0 0 rgba(72, 187, 120, 0); }
}
@keyframes wrongFlash {
  0%, 100% { background: var(--error-bg); }
  50%      { background: #F8B2B2; }
}
@keyframes checkPop {
  0%   { transform: scale(0) rotate(-20deg); opacity: 0; }
  60%  { transform: scale(1.25) rotate(0); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.03); }
}
@keyframes streakPulse {
  0%, 100% { transform: scale(1); }
  40%      { transform: scale(1.25); }
  60%      { transform: scale(0.95); }
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(24px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-24px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes countUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes levelUpEnter {
  0%   { transform: scale(0.6) translateY(40px); opacity: 0; }
  60%  { transform: scale(1.06) translateY(-6px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}
@keyframes trophyShine {
  0%   { filter: drop-shadow(0 0 0 rgba(255, 215, 0, 0)); transform: rotate(-8deg) scale(1); }
  30%  { filter: drop-shadow(0 0 16px rgba(255, 215, 0, 0.85)); transform: rotate(6deg) scale(1.15); }
  60%  { filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.6));  transform: rotate(-4deg) scale(1.05); }
  100% { filter: drop-shadow(0 0 0 rgba(255, 215, 0, 0)); transform: rotate(0) scale(1); }
}

/* Everything tappable — spring feel */
button,
.option-btn,
.module-card,
.nav-btn,
.rule-tab,
.back-btn {
  transition: transform 0.15s cubic-bezier(0.2, 0.8, 0.4, 1.2),
              box-shadow 0.15s ease,
              background 0.15s ease,
              border-color 0.15s ease,
              color 0.15s ease;
}
button:active,
.option-btn:not(.disabled):active,
.nav-btn:active,
.rule-tab:active,
.back-btn:active {
  transform: scale(0.96);
}
.module-card:active {
  transform: scale(0.98);
}

/* Ripple effect (adds a .ripple span via JS on click) */
.ripple-host { position: relative; overflow: hidden; }
.ripple {
  position: absolute;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.18;
  pointer-events: none;
  transform: scale(0);
  animation: ripple 0.55s ease-out forwards;
  will-change: transform, opacity;
}

/* Option buttons — correct / wrong feedback */
.option-btn.correct {
  animation: correctPulse 0.8s ease-out;
}
.option-btn.wrong {
  animation: shake 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97), wrongFlash 0.5s ease-out;
}

/* Checkmark overlay that can be placed inside a correct option */
.check-pop {
  display: inline-block;
  margin-left: 8px;
  animation: checkPop 0.45s cubic-bezier(0.2, 0.8, 0.4, 1.4) forwards;
}

/* Logo — больше не дышим. Анимация теперь — «занавес со словом». */

/* SW update bar */
.sw-update-bar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-card, #1a1a1a);
  color: var(--text, #fff);
  border: 1px solid var(--border, rgba(255,255,255,0.1));
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  font-size: 14px;
  transform: translateY(120%);
  opacity: 0;
  transition: transform 280ms ease, opacity 280ms ease;
}
.sw-update-bar.visible { transform: translateY(0); opacity: 1; }
.sw-update-bar button {
  background: var(--accent, #4f8cff);
  color: white;
  border: 0;
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  font-size: 13px;
}
.sw-update-bar button:active { transform: scale(0.96); }

/* Microlesson button (in explanation area on wrong answer) */
.microlesson-btn {
  display: inline-block;
  margin-top: 12px;
  padding: 10px 16px;
  background: var(--bg, #111);
  color: var(--text, #fff);
  border: 1px solid var(--accent, #4f8cff);
  border-radius: 12px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: transform 120ms ease, background 160ms ease;
}
.microlesson-btn:hover { background: var(--accent, #4f8cff); color: white; }
.microlesson-btn:active { transform: scale(0.97); }

/* Microlesson modal */
.micro-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 220ms ease;
}
.micro-modal.visible { opacity: 1; pointer-events: auto; }
.micro-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
}
.micro-card {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 82vh;
  overflow-y: auto;
  background: var(--bg-card, #1c1c1e);
  color: var(--text, #fff);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  padding: 22px 22px 28px;
  box-shadow: 0 -8px 30px rgba(0,0,0,0.4);
  transform: translateY(40px);
  transition: transform 280ms cubic-bezier(0.22, 1, 0.36, 1);
}
.micro-modal.visible .micro-card { transform: translateY(0); }
.micro-close {
  position: absolute; top: 8px; right: 12px;
  background: transparent; border: 0;
  color: var(--text-secondary, #888);
  font-size: 28px; line-height: 1;
  cursor: pointer; padding: 4px 10px;
}
.micro-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.micro-icon { font-size: 28px; }
.micro-title { font-weight: 800; font-size: 18px; }
.micro-subtitle { color: var(--text-secondary, #999); font-size: 13px; margin-top: 2px; }
.micro-body { font-size: 15px; line-height: 1.5; }
.micro-body p { margin: 8px 0; }
.micro-body ul { padding-left: 20px; }
.micro-cta {
  display: block;
  width: 100%;
  margin-top: 18px;
  padding: 12px;
  background: var(--accent, #4f8cff);
  color: white; border: 0; border-radius: 12px;
  font-weight: 700; font-size: 15px;
  cursor: pointer;
}
.micro-cta:active { transform: scale(0.98); }

/* Settings slider */
.setting-slider { flex-direction: column; align-items: stretch; gap: 8px; }
.setting-slider label { display: flex; flex-direction: column; gap: 2px; }
.setting-slider .setting-hint {
  font-size: 12px;
  color: var(--text-secondary, #888);
  font-weight: 500;
}
.setting-slider input[type="range"] {
  width: 100%;
  accent-color: var(--accent, #4f8cff);
}

/* Errors heat-map */
.heatmap-section { margin-top: 24px; }
.heatmap-hint {
  color: var(--text-secondary, #888);
  font-size: 13px;
  margin: 4px 0 12px;
}
.heatmap-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.heatmap-mod {
  flex: 0 0 110px;
  font-size: 13px;
  color: var(--text-secondary, #aaa);
}
.heatmap-cells {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  flex: 1;
}
.heatmap-cell {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  display: inline-block;
  cursor: help;
  transition: transform 120ms ease;
}
.heatmap-cell:hover { transform: scale(1.4); }

/* Weekly digest */
.digest-bars {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 6px;
  height: 86px;
  margin: 12px 0 4px;
  padding: 0 4px;
}
.digest-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  height: 100%;
}
.digest-bar {
  width: 100%;
  min-height: 3px;
  background: var(--accent, #4f8cff);
  border-radius: 4px 4px 0 0;
  transition: height 280ms ease;
}
.digest-bar-label {
  font-size: 11px;
  color: var(--text-secondary, #888);
}
.digest-h4 {
  margin: 14px 0 6px;
  font-size: 14px;
  color: var(--text-secondary, #aaa);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.digest-top { padding-left: 18px; margin: 0; }
.digest-top li { padding: 3px 0; font-size: 14px; }
.digest-top-empty { font-size: 14px; color: var(--text-secondary, #888); }

/* Share button */
.btn-share {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  background: transparent;
  color: var(--text, #fff);
  border: 1px solid var(--border, rgba(255,255,255,0.18));
  border-radius: 14px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: background 160ms ease;
}
.btn-share:hover { background: var(--bg-card, rgba(255,255,255,0.05)); }
.btn-share:active { transform: scale(0.98); }

/* ===== TUTOR — AI-наставник Розенталь ===== */
/* Login bar внутри tutor-screen — для web-юзеров без Telegram-сессии. */
.tutor-login {
  display: flex; align-items: center; gap: 12px;
  margin: 12px 12px 0;
  padding: 12px 14px;
  background: linear-gradient(135deg, rgba(35, 145, 224, 0.16), rgba(35, 145, 224, 0.08));
  border: 1px solid rgba(35, 145, 224, 0.35);
  border-radius: 12px;
}
.tutor-login-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tutor-login-text strong { font-size: 14px; font-weight: 700; }
.tutor-login-text span { font-size: 12px; color: var(--text-secondary); line-height: 1.35; }
.tutor-login-btn {
  flex: 0 0 auto;
  padding: 10px 14px;
  border-radius: 10px;
  border: 0;
  background: #2391e0;
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.tutor-login-btn:disabled { opacity: 0.7; cursor: default; }
.tutor-login-btn:active { transform: scale(0.98); }

.tutor-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  margin-bottom: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  color: var(--text);
}
.tutor-icon { font-size: 30px; flex: 0 0 auto; }
.tutor-info { flex: 1; min-width: 0; }
.tutor-title { font-weight: 700; font-size: 16px; margin-bottom: 2px; }
.tutor-sub { color: var(--text-secondary); font-size: 13px; }
.tutor-arrow { font-size: 24px; color: var(--text-secondary); flex: 0 0 auto; }

/* ===== Text check (резюме-чекер) ===== */
.tc-summary {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.tc-score {
  display: inline-flex; align-items: baseline; gap: 6px;
  font-size: 28px; font-weight: 800;
  margin-right: 12px;
}
.tc-score-pct { font-size: 14px; color: var(--text-secondary); font-weight: 400; }
.tc-summary-text { color: var(--text-secondary); font-size: 14px; line-height: 1.5; margin-top: 8px; }
.tc-issue {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--error);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  font-size: 14px;
}
.tc-issue.style    { border-left-color: var(--warning, #d69e2e); }
.tc-issue.gram     { border-left-color: var(--accent); }
.tc-issue.paronym  { border-left-color: var(--accent); }
.tc-issue-fragment {
  display: inline-block;
  font-family: monospace;
  background: rgba(252, 129, 129, 0.12);
  padding: 2px 6px;
  border-radius: 4px;
  margin-right: 8px;
}
.tc-issue-arrow { color: var(--accent); margin: 0 6px; }
.tc-issue-suggestion {
  display: inline-block;
  font-family: monospace;
  font-weight: 700;
  background: rgba(76, 175, 80, 0.15);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
}
.tc-issue-explanation { color: var(--text-secondary); font-size: 13px; margin-top: 6px; line-height: 1.5; }
.tc-issue-type {
  display: inline-block;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--border);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
}

/* ===== Compact home strip (заменяет 3 старые карточки) ===== */
.home-strip {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px;
}
.hs-cell {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 6px;
  background: transparent;
  border: 0;
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  min-width: 0;
  transition: background 160ms;
}
.hs-cell:hover { background: rgba(255, 255, 255, 0.04); }
.hs-cell:active { background: rgba(255, 255, 255, 0.08); }
.hs-icon { font-size: 16px; line-height: 1; }
.hs-num {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.3px;
  line-height: 1.1;
}
.hs-sep { color: var(--text-secondary); margin: 0 2px; font-weight: 400; }
.hs-label {
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: lowercase;
  letter-spacing: 0.3px;
}

/* ===== AI-помощник — главный CTA на главной ===== */
.ai-helper-card {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  padding: 16px 18px;
  margin-bottom: 14px;
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.14), rgba(59, 130, 246, 0.12));
  border: 1px solid rgba(124, 58, 237, 0.35);
  border-radius: 16px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  text-align: left;
  transition: transform 120ms, box-shadow 200ms;
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.12);
}
.ai-helper-card:active { transform: scale(0.99); }
.aih-icon {
  font-size: 28px; flex: 0 0 auto;
  filter: drop-shadow(0 0 8px rgba(168, 85, 247, 0.5));
  animation: aihSparkle 3s ease-in-out infinite;
}
@keyframes aihSparkle {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.08); opacity: 0.9; }
}
.aih-info { flex: 1; min-width: 0; }
.aih-label {
  font-weight: 700; font-size: 16px; margin-bottom: 3px;
  letter-spacing: 0.1px;
}
.aih-sub { font-size: 13px; color: var(--text-secondary); line-height: 1.35; }
.aih-arrow { font-size: 24px; color: var(--text-secondary); flex: 0 0 auto; }

/* ===== Daily Word ===== */
.daily-word-card {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 14px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  text-align: left;
  transition: transform 120ms;
}
.daily-word-card:active { transform: scale(0.99); }
.dwc-icon { font-size: 26px; flex: 0 0 auto; }
.dwc-info { flex: 1; min-width: 0; }
.dwc-label { font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.dwc-sub { font-size: 12px; color: var(--text-secondary); }
.dwc-arrow { font-size: 22px; color: var(--text-secondary); flex: 0 0 auto; }

/* Screen daily-word */
.dw-stage {
  padding: 24px 16px;
  display: flex; flex-direction: column; align-items: center;
  gap: 16px;
  text-align: center;
}
.dw-meta {
  font-size: 13px; color: var(--text-secondary);
  letter-spacing: 0.6px; text-transform: uppercase;
}
.dw-prompt {
  font-size: 20px; font-weight: 700;
  color: var(--text);
}
.dw-word {
  display: flex; gap: 2px;
  font-weight: 800;
  font-family: 'Playfair Display', Georgia, serif;
  color: var(--text);
  margin: 14px 0 8px;
  flex-wrap: nowrap;
  justify-content: center;
  width: 100%;
  max-width: 100%;
  overflow: visible;
  /* font-size задаётся JS-ом динамически после рендера, чтобы слово
     гарантированно влезло в одну строку независимо от длины и ширины
     экрана. Базовая величина — 42px, но скейлим вниз до 18px. */
  font-size: 42px;
}
.dw-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  min-width: 0;
  flex: 0 1 auto;
  background: transparent;
  border: 0;
  font: inherit;
  color: inherit;
  cursor: default;
}
.dw-vowel {
  cursor: pointer;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--bg-card);
  transition: border-color 160ms, background 160ms, transform 180ms;
}
.dw-vowel:hover { border-color: var(--accent); }
.dw-vowel:active { transform: scale(0.94); }
.dw-vowel.dw-correct {
  background: var(--success-bg);
  color: var(--success);
  border-color: var(--success);
  animation: dwCorrectBump 480ms cubic-bezier(0.22, 1, 0.36, 1);
}
.dw-vowel.dw-correct-reveal {
  background: rgba(76,175,80,0.2);
  border-color: var(--accent);
  color: var(--accent);
  animation: dwRevealPulse 1.4s infinite ease-in-out;
}
.dw-vowel.dw-wrong {
  background: var(--error-bg);
  color: var(--error);
  border-color: var(--error);
  animation: dwShakeX 360ms;
}
.dw-vowel:disabled { cursor: default; opacity: 1; }
@keyframes dwCorrectBump {
  0% { transform: scale(1); }
  50% { transform: scale(1.18); }
  100% { transform: scale(1); }
}
@keyframes dwShakeX {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}
@keyframes dwRevealPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}
.dw-hint {
  font-size: 13px;
  color: var(--text-secondary);
  max-width: 340px;
  line-height: 1.5;
}
.dw-result-emoji {
  font-size: 38px;
  letter-spacing: 6px;
  margin: 8px 0;
}
.dw-result-verdict {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
}
.dw-result-word {
  font-size: clamp(22px, 9vw, 40px);
  font-weight: 800;
  font-family: 'Playfair Display', Georgia, serif;
  color: var(--text);
  margin: 12px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.dw-result-word strong {
  color: var(--accent);
  font-weight: 800;
}
.dw-result-rule {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
  max-width: 360px;
}
.dw-result-example {
  font-style: italic;
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 6px;
  max-width: 360px;
}
.dw-result-streak {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  margin-top: 4px;
}
.dw-share-btn {
  background: var(--accent);
  color: white;
  border: 0;
  padding: 14px 28px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  font-family: inherit;
  margin-top: 14px;
}
.dw-share-btn:active { transform: scale(0.97); }
.dw-tomorrow {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-secondary);
  font-style: italic;
}
.dw-close-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 10px 22px;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  margin-top: 6px;
}

/* ===== Pending chest card (на главной) ===== */
.pending-chest-card {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  padding: 16px 18px;
  margin-bottom: 16px;
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.18), rgba(212, 175, 55, 0.04));
  border: 1px solid rgba(212, 175, 55, 0.5);
  border-radius: 14px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  text-align: left;
  position: relative;
  overflow: hidden;
  transition: transform 120ms ease;
  animation: chestPulse 2.4s ease-in-out infinite;
}
.pending-chest-card:active { transform: scale(0.99); }
@keyframes chestPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(212, 175, 55, 0); }
  50%      { box-shadow: 0 0 30px 0 rgba(212, 175, 55, 0.25); }
}
.pcc-icon { font-size: 30px; flex: 0 0 auto; }
.pcc-info { flex: 1; min-width: 0; }
.pcc-label { font-weight: 800; font-size: 15px; margin-bottom: 2px; }
.pcc-sub { font-size: 12px; color: var(--text-secondary); }
.pcc-arrow { font-size: 22px; color: var(--text-secondary); flex: 0 0 auto; }

/* ===== Chest reveal modal ===== */
.chest-modal {
  position: fixed; inset: 0; z-index: 11000;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 280ms ease;
}
.chest-modal.visible { pointer-events: auto; opacity: 1; }
.chest-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
}
.chest-stage {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center;
  gap: 18px;
  padding: 24px;
  max-width: 92vw;
}

/* Сам сундук — emoji-based, простой */
.chest-box {
  position: relative;
  width: 120px; height: 120px;
  display: flex; align-items: center; justify-content: center;
  transition: transform 600ms cubic-bezier(0.22, 1, 0.36, 1);
}
.chest-body {
  font-size: 88px; line-height: 1;
  filter: drop-shadow(0 8px 30px rgba(212, 175, 55, 0.4));
  animation: chestBoxFloat 2.2s ease-in-out infinite;
}
.chest-glow {
  position: absolute; inset: -30%;
  background: radial-gradient(circle, rgba(212, 175, 55, 0.35), transparent 60%);
  z-index: -1;
  animation: chestGlowPulse 1.8s ease-in-out infinite;
}
@keyframes chestBoxFloat {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}
@keyframes chestGlowPulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50%      { opacity: 1;   transform: scale(1.2); }
}
.chest-box.opening {
  transform: scale(1.4) rotate(8deg);
  animation: chestOpenShake 0.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes chestOpenShake {
  0%   { transform: scale(1) rotate(0); }
  20%  { transform: scale(1.15) rotate(-4deg); }
  40%  { transform: scale(1.25) rotate(5deg); }
  60%  { transform: scale(1.3) rotate(-3deg); }
  80%  { transform: scale(1.4) rotate(2deg); }
  100% { transform: scale(0.85) rotate(0); opacity: 0.4; }
}
.chest-box.opening .chest-glow {
  animation: chestGlowExplode 0.6s ease-out forwards;
}
@keyframes chestGlowExplode {
  0%   { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(3); }
}
.chest-lid { display: none; } /* зарезервировано на будущее */

/* Reward, появляющийся после открытия */
.chest-reward {
  opacity: 0;
  transform: translateY(20px) scale(0.9);
  transition: opacity 480ms ease, transform 580ms cubic-bezier(0.22, 1, 0.36, 1);
  text-align: center;
  display: flex; flex-direction: column; align-items: center;
  gap: 12px;
}
.chest-reward.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.chest-reward-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: rgba(212, 175, 55, 0.95);
  font-weight: 700;
}
.chest-xp-burst {
  font-size: 64px;
  font-weight: 900;
  background: linear-gradient(135deg, #d4af37, #f0d96b);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1;
}
.chest-xp-unit { font-size: 24px; }
.chest-xp-sub { color: var(--text-secondary); font-size: 13px; }
.chest-quote {
  font-style: italic; font-family: 'Playfair Display', Georgia, serif;
  font-size: 18px; line-height: 1.5;
  color: var(--text); max-width: 320px;
}
.chest-quote-author {
  font-size: 13px; color: var(--text-secondary);
  margin-top: 4px;
}
.chest-close {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 28px;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  margin-top: 10px;
}
.chest-close:hover { border-color: var(--accent); color: var(--accent); }

/* Trophy section: список открытых сундуков */
.chest-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.chest-history-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
}
.chest-history-icon { font-size: 20px; margin-bottom: 4px; }
.chest-history-source { font-size: 10px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.4px; }
.chest-history-reward { font-weight: 700; color: var(--text); margin-top: 4px; line-height: 1.2; }
.chest-history-date { font-size: 10px; color: var(--text-secondary); margin-top: 2px; }

/* ===== Writer Cards (типографические карточки коллекции) ===== */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.cards-completion {
  background: linear-gradient(135deg, rgba(76,175,80,0.12), rgba(76,175,80,0.04));
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 14px;
  color: var(--text);
  text-align: center;
}

/* Базовая карточка — типографическая, без портрета */
.writer-card {
  position: relative;
  aspect-ratio: 3 / 4;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-family: 'Playfair Display', 'Times New Roman', Georgia, serif;
  cursor: pointer;
  overflow: hidden;
  transition: transform 160ms ease, border-color 160ms ease;
}
.writer-card:active { transform: scale(0.97); }
.writer-card.locked {
  background: var(--bg);
  border-style: dashed;
  opacity: 0.7;
}

/* Уголки декоративные — рамка академического артефакта */
.wc-corner {
  position: absolute;
  width: 12px; height: 12px;
  border: 1px solid var(--text-secondary);
}
.wc-corner-tl { top: 4px; left: 4px; border-right: 0; border-bottom: 0; }
.wc-corner-tr { top: 4px; right: 4px; border-left: 0; border-bottom: 0; }
.wc-corner-bl { bottom: 4px; left: 4px; border-right: 0; border-top: 0; }
.wc-corner-br { bottom: 4px; right: 4px; border-left: 0; border-top: 0; }

/* Звёзды редкости */
.wc-rarity {
  font-size: 9px;
  letter-spacing: 1px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.writer-card-rare .wc-rarity { color: #d6a85a; }
.writer-card-legendary .wc-rarity { color: #d4af37; text-shadow: 0 0 8px rgba(212,175,55,0.4); }

/* Монограмма — крупная литера на карточке-thumb */
.wc-monogram {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--text);
  margin-bottom: 4px;
}
.wc-name {
  font-size: 11px;
  color: var(--text-secondary);
  font-style: italic;
}
.wc-locked-hint {
  font-size: 9px;
  color: var(--text-muted, var(--text-secondary));
  font-style: italic;
  margin-top: 4px;
  line-height: 1.2;
}

/* Цветовые рамки по редкости */
.writer-card-common { border-color: var(--border); }
.writer-card-rare { border-color: rgba(214, 168, 90, 0.5); }
.writer-card-rare:not(.locked) {
  background: linear-gradient(180deg, rgba(214, 168, 90, 0.06), var(--bg-card));
}
.writer-card-legendary { border-color: rgba(212, 175, 55, 0.7); border-width: 2px; }
.writer-card-legendary:not(.locked) {
  background: linear-gradient(180deg, rgba(212, 175, 55, 0.10), var(--bg-card));
  box-shadow: 0 0 20px rgba(212, 175, 55, 0.15);
}

/* Полная карточка в модалке */
.writer-card-full {
  aspect-ratio: 3 / 4;
  width: 100%;
  max-width: 340px;
  padding: 28px 24px;
  cursor: default;
}
.writer-card-full .wc-corner {
  width: 22px; height: 22px;
  border-width: 1px;
}
.writer-card-full .wc-corner-tl { top: 8px; left: 8px; }
.writer-card-full .wc-corner-tr { top: 8px; right: 8px; }
.writer-card-full .wc-corner-bl { bottom: 8px; left: 8px; }
.writer-card-full .wc-corner-br { bottom: 8px; right: 8px; }
.wc-rarity-label {
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 14px;
}
.wc-monogram-large {
  font-size: 56px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 10px;
  letter-spacing: 2px;
}
.wc-name-full {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.wc-years {
  font-size: 12px;
  color: var(--text-secondary);
  font-style: italic;
  margin-bottom: 18px;
}
.wc-quote {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  font-style: italic;
  margin-bottom: 14px;
  max-width: 90%;
}
.wc-work {
  font-size: 12px;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}
.wc-quote-locked {
  font-size: 13px;
  color: var(--text-secondary);
  font-style: italic;
  padding: 10px 16px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  margin-top: 10px;
  max-width: 90%;
  line-height: 1.4;
}

/* Модалка карточки */
.wc-modal {
  position: fixed; inset: 0; z-index: 10500;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 280ms ease;
}
.wc-modal.visible { pointer-events: auto; opacity: 1; }
.wc-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
}
.wc-modal-inner {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 20px;
}
.wc-modal.visible .writer-card-full {
  animation: cardReveal 580ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes cardReveal {
  0%   { transform: rotateY(180deg) scale(0.9); opacity: 0; }
  60%  { transform: rotateY(0) scale(1.05); opacity: 1; }
  100% { transform: rotateY(0) scale(1); opacity: 1; }
}
.wc-close {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 22px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
}
.wc-close:hover { border-color: var(--accent); color: var(--accent); }

/* Тост открытия карточки — уголок справа сверху */
.card-unlocked-toast {
  position: fixed;
  top: calc(20px + env(safe-area-inset-top, 0px));
  right: 16px;
  z-index: 10001;
  display: flex;
  align-items: stretch;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: 14px;
  padding: 12px;
  max-width: 360px;
  width: calc(100vw - 32px);
  box-shadow: 0 16px 40px rgba(0,0,0,0.4);
  transform: translateX(110%);
  transition: transform 380ms cubic-bezier(0.22, 1, 0.36, 1);
}
.card-unlocked-toast.visible { transform: translateX(0); }
.cut-mini-card {
  flex: 0 0 70px;
  aspect-ratio: 3 / 4;
  padding: 8px 4px;
}
.cut-mini-card .wc-monogram { font-size: 18px; margin-bottom: 2px; }
.cut-mini-card .wc-name { font-size: 9px; }
.cut-mini-card .wc-corner { width: 7px; height: 7px; }
.cut-content { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.cut-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 4px;
}
.cut-name { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 4px; line-height: 1.2; }
.cut-action {
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
}

/* ===== Trophy Room ===== */
.trophy-section {
  margin-bottom: 22px;
}
.trophy-section-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 0 0 10px;
}
.trophy-section-head h3 {
  font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--text-secondary);
  margin: 0;
}
.trophy-section-head .trophy-section-meta {
  font-size: 12px; color: var(--text-secondary);
}

/* Уровень / Speech level карточка */
.trophy-level-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 16px;
}
.trophy-level-icon {
  font-size: 40px; line-height: 1;
  flex: 0 0 auto;
}
.trophy-level-info { flex: 1; min-width: 0; }
.trophy-level-rank {
  font-size: 11px; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.4px;
  margin-bottom: 2px;
}
.trophy-level-title {
  font-size: 18px; font-weight: 800;
  color: var(--text); margin-bottom: 8px;
}
.trophy-level-bar {
  height: 6px; background: var(--border);
  border-radius: 3px; overflow: hidden;
}
.trophy-level-bar-fill {
  height: 100%; background: var(--accent);
  border-radius: 3px;
  transition: width 600ms cubic-bezier(0.22, 1, 0.36, 1);
}
.trophy-level-meta {
  font-size: 12px; color: var(--text-secondary);
  margin-top: 4px;
}

/* Streak heatmap */
.trophy-streak-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  margin-bottom: 16px;
}
.trophy-streak-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.trophy-streak-num {
  font-size: 28px; font-weight: 800; color: var(--accent);
}
.trophy-streak-label {
  font-size: 12px; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.4px;
}
.trophy-streak-freeze {
  font-size: 13px; color: var(--text-secondary);
}
.trophy-heatmap {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  margin-top: 4px;
}
.heatmap-day {
  aspect-ratio: 1;
  background: var(--border);
  border-radius: 3px;
  position: relative;
}
.heatmap-day.l1 { background: rgba(76, 175, 80, 0.25); }
.heatmap-day.l2 { background: rgba(76, 175, 80, 0.5); }
.heatmap-day.l3 { background: rgba(76, 175, 80, 0.75); }
.heatmap-day.l4 { background: var(--accent); }
.heatmap-day.today {
  outline: 2px solid var(--text);
  outline-offset: 1px;
}
.heatmap-legend {
  display: flex; align-items: center; gap: 4px;
  margin-top: 10px;
  font-size: 11px; color: var(--text-secondary);
  justify-content: flex-end;
}
.heatmap-legend .legend-cell {
  width: 10px; height: 10px; border-radius: 2px;
}

/* Achievements grid */
.trophy-achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.trophy-ach {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
  position: relative;
  transition: transform 120ms;
}
.trophy-ach.locked { opacity: 0.6; }
.trophy-ach.unlocked {
  border-color: rgba(76, 175, 80, 0.4);
  background: linear-gradient(180deg, rgba(76,175,80,0.06), var(--bg-card));
}
.trophy-ach-icon {
  font-size: 28px;
  margin-bottom: 4px;
  line-height: 1;
}
.trophy-ach.locked .trophy-ach-icon { filter: grayscale(1) opacity(0.6); }
.trophy-ach-name {
  font-weight: 700;
  font-size: 12px;
  margin-bottom: 4px;
  color: var(--text);
}
.trophy-ach-desc {
  font-size: 10px;
  color: var(--text-secondary);
  line-height: 1.3;
  margin-bottom: 6px;
}
.trophy-ach-progress {
  height: 3px; background: var(--border);
  border-radius: 2px; overflow: hidden;
  margin-top: 6px;
}
.trophy-ach-progress-fill {
  height: 100%; background: var(--accent);
}
.trophy-ach-progress-text {
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 3px;
}

/* Placeholder cards (Карточки писателей, Сундуки — coming soon) */
.trophy-placeholder {
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: 14px;
  padding: 22px 20px;
  text-align: center;
  margin-bottom: 12px;
}
.trophy-placeholder-icon {
  font-size: 32px;
  opacity: 0.5;
  margin-bottom: 8px;
}
.trophy-placeholder-title {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 4px;
  color: var(--text);
}
.trophy-placeholder-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}
.trophy-placeholder-tag {
  display: inline-block;
  margin-top: 8px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 2px 8px;
  border-radius: 6px;
}

/* ===== Cabinet (вкладка с инструментами) ===== */
.cabinet-section {
  margin-bottom: 22px;
}
.cabinet-section h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-secondary);
  margin: 0 0 10px;
}

/* ===== Активный курс на главной ===== */
.course-card-active {
  display: flex; align-items: stretch;
  margin-bottom: 16px;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: 14px;
  overflow: hidden;
  position: relative;
}
.cca-clickable {
  flex: 1;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  cursor: pointer;
  transition: transform 120ms ease;
  min-width: 0;
}
.cca-clickable:active { transform: scale(0.99); }
.cca-dismiss {
  flex: 0 0 auto;
  width: 36px;
  background: transparent;
  border: 0;
  border-left: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  align-self: stretch;
  font-family: inherit;
}
.cca-dismiss:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.cca-icon { font-size: 28px; flex: 0 0 auto; }
.cca-info { flex: 1; min-width: 0; }
.cca-label { font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.cca-day { color: var(--text-secondary); font-size: 13px; margin-bottom: 6px; }
.cca-bar {
  height: 4px; background: var(--border);
  border-radius: 2px; overflow: hidden;
}
.cca-bar-fill {
  height: 100%; background: var(--accent);
  border-radius: 2px;
  transition: width 400ms ease;
}
.cca-arrow { font-size: 22px; color: var(--text-secondary); flex: 0 0 auto; }

/* Список курсов */
.course-item {
  display: block; width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: var(--text);
  transition: border-color 160ms ease;
}
.course-item:hover { border-color: var(--accent); }
.course-item-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.course-item-icon { font-size: 26px; }
.course-item-title { font-weight: 700; font-size: 16px; }
.course-item-short { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.course-item-meta {
  display: flex; gap: 12px; font-size: 12px;
  color: var(--text-secondary); margin-top: 8px;
}
.course-item-progress {
  margin-top: 10px;
  height: 4px; background: var(--border);
  border-radius: 2px; overflow: hidden;
}
.course-item-progress-fill {
  height: 100%; background: var(--accent); border-radius: 2px;
}
.course-recommended {
  display: inline-block;
  font-size: 11px; padding: 2px 8px;
  background: rgba(76,175,80,0.12);
  color: var(--accent);
  border-radius: 10px;
  margin-left: 8px;
}

/* Детальная страница курса */
.course-detail {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 14px;
}
.course-detail h3 { margin: 0 0 8px; font-size: 18px; }
.course-detail-desc { color: var(--text-secondary); font-size: 14px; line-height: 1.5; margin-bottom: 14px; }
.course-detail-stats {
  display: flex; gap: 20px; padding: 10px 0;
  border-top: 1px solid var(--border-light, var(--border));
  border-bottom: 1px solid var(--border-light, var(--border));
  margin: 12px 0;
}
.course-detail-stat-num { font-weight: 800; font-size: 18px; }
.course-detail-stat-label { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.4px; }
.course-detail-day {
  background: linear-gradient(135deg, rgba(76,175,80,0.08), rgba(76,175,80,0.02));
  border: 1px solid rgba(76,175,80,0.3);
  border-radius: 12px;
  padding: 14px 16px;
  margin: 12px 0;
}
.course-detail-day-title { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.course-detail-day-theme { color: var(--text-secondary); font-size: 13px; margin-bottom: 8px; }
.course-detail-day-progress {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; margin-top: 8px;
}
.course-detail-cta {
  display: block; width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white; border: 0; border-radius: 12px;
  font-weight: 700; font-size: 15px;
  cursor: pointer;
  margin-top: 12px;
  font-family: inherit;
}
.course-detail-cta:active { transform: scale(0.98); }
.course-detail-cta.secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

/* ===== Speech Tip Card (на главной) ===== */
.speech-tip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 16px;
  cursor: pointer;
  transition: transform 120ms ease;
}
.speech-tip:active { transform: scale(0.99); }
.st-tag {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 6px;
}
.st-title {
  font-weight: 700; font-size: 15px;
  margin-bottom: 4px; line-height: 1.35;
}
.st-body {
  font-size: 13px; color: var(--text-secondary);
  line-height: 1.5;
}
.st-body strong { color: var(--text); font-weight: 700; }
.st-foot {
  margin-top: 8px; text-align: right;
}
.st-hint {
  font-size: 11px; color: var(--text-muted, var(--text-secondary)); opacity: 0.7;
}

/* ===== Onboarding ===== */
.onboarding {
  position: fixed; inset: 0;
  z-index: 10500;
  display: flex; align-items: center; justify-content: center;
  pointer-events: auto;
  opacity: 1;
  transition: opacity 240ms ease;
}
.onboarding.hidden { opacity: 0; pointer-events: none; visibility: hidden; }
.onb-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.onb-card {
  position: relative; z-index: 1;
  width: 92%; max-width: 560px;
  max-height: 92dvh; overflow-y: auto;
  background: var(--bg-card, #1a1a1a);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 26px 22px 18px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
  animation: onbIn 380ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes onbIn {
  from { transform: translateY(30px) scale(0.96); opacity: 0; }
  to   { transform: translateY(0) scale(1);       opacity: 1; }
}
.onb-skip {
  position: absolute; top: 14px; right: 16px;
  background: transparent; border: 0;
  color: var(--text-secondary);
  font-size: 13px; cursor: pointer;
  padding: 4px 8px; border-radius: 6px;
}
.onb-skip:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.onb-head { text-align: center; margin-bottom: 18px; }
.onb-emoji { font-size: 36px; margin-bottom: 8px; }
.onb-head h2 { margin: 0 0 6px; font-size: 22px; font-weight: 800; }
.onb-sub {
  font-size: 14px; color: var(--text-secondary);
  margin: 0; line-height: 1.45;
}
.onb-roles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 14px 0 8px;
}
/* Primary кнопка (general) — на всю ширину сетки */
.onb-role-primary {
  grid-column: 1 / -1;
  padding: 16px 18px;
  background: linear-gradient(135deg, var(--accent-light, rgba(76,175,80,0.12)), var(--bg-card));
  border-color: var(--accent);
  border-width: 2px;
}
.onb-role-primary .onb-role-icon { font-size: 32px; }
.onb-role-primary .onb-role-label { font-size: 16px; }
.onb-role-primary .onb-role-go {
  margin-left: auto;
  font-size: 22px;
  color: var(--accent);
  flex: 0 0 auto;
}
/* Разделитель между primary и сеткой ролей */
.onb-divider {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin: 6px 0 2px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.onb-divider::before,
.onb-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.onb-divider span {
  padding: 0 4px;
}
@media (max-width: 380px) {
  .onb-roles { grid-template-columns: 1fr; }
  .onb-role-primary { grid-column: 1 / -1; }
}
.onb-role {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--bg, #111);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: var(--text);
  transition: transform 120ms ease, border-color 160ms ease, background 160ms ease;
}
.onb-role:hover { border-color: var(--accent); }
.onb-role:active { transform: scale(0.98); }
.onb-role-icon { font-size: 24px; flex: 0 0 auto; }
.onb-role-info { flex: 1; min-width: 0; }
.onb-role-label { font-weight: 700; font-size: 14px; line-height: 1.25; }
.onb-role-short { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.onb-foot {
  text-align: center;
  margin-top: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.onb-diag {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-secondary);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.onb-diag:hover { color: var(--accent); border-color: var(--accent); }

/* ===== Diagnostic screen ===== */
#screen-diagnostic.active {
  display: flex !important;
  flex-direction: column;
  min-height: 100dvh;
  padding-top: 0 !important;
}
.diag-screen {
  display: flex; flex-direction: column;
  flex: 1; min-height: 100dvh;
  background: var(--bg);
}
.diag-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky; top: 0; z-index: 5;
}
.diag-head .back-btn {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
}
.diag-head-text { flex: 1; }
.diag-title { font-weight: 700; font-size: 16px; }
.diag-progress { color: var(--text-secondary); font-size: 12px; margin-top: 2px; }
.diag-body { flex: 1; padding: 24px 18px; overflow-y: auto; }
.diag-question {
  font-size: 18px; font-weight: 600; margin-bottom: 6px;
  line-height: 1.4;
}
.diag-hint {
  font-size: 13px; color: var(--text-secondary);
  margin-bottom: 18px;
}
.diag-options {
  display: grid; gap: 10px;
}
.diag-option {
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  text-align: left;
  transition: transform 120ms, border-color 160ms;
}
.diag-option:hover { border-color: var(--accent); }
.diag-option:active { transform: scale(0.98); }
.diag-result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-top: 12px;
}
.diag-result-card h3 { margin: 0 0 6px; font-size: 18px; }
.diag-result-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light, var(--border));
  font-size: 14px;
}
.diag-result-row:last-child { border-bottom: 0; }
.diag-result-row span:last-child { font-weight: 700; }
.diag-cta {
  display: block; width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white; border: 0; border-radius: 12px;
  font-weight: 700; font-size: 15px;
  cursor: pointer;
  margin-top: 16px;
  font-family: inherit;
}
.diag-cta:active { transform: scale(0.98); }

/* Persona welcome card на главной */
.persona-banner {
  background: linear-gradient(135deg, rgba(76,175,80,0.08), rgba(76,175,80,0.02));
  border: 1px solid rgba(76,175,80,0.25);
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 12px;
}
.persona-banner-icon { font-size: 24px; flex: 0 0 auto; }
.persona-banner-text { flex: 1; min-width: 0; font-size: 13px; line-height: 1.4; color: var(--text); }
.persona-banner-text .pb-label {
  font-weight: 700; color: var(--accent); margin-right: 6px;
}
.persona-banner-change {
  background: transparent; border: 0; cursor: pointer;
  color: var(--text-secondary); font-size: 11px;
  padding: 4px 8px; border-radius: 6px;
}
.persona-banner-change:hover { color: var(--text); background: rgba(255,255,255,0.05); }

/* Speech level в Stats */
.speech-level-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 16px;
  text-align: center;
}
.sl-icon { font-size: 36px; margin-bottom: 6px; }
.sl-title { font-weight: 800; font-size: 20px; margin-bottom: 4px; }
.sl-pct { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.sl-desc { font-size: 13px; color: var(--text-secondary); line-height: 1.4; }
.sl-bar {
  height: 6px; background: var(--border);
  border-radius: 3px; overflow: hidden;
  margin: 12px 0 6px;
}
.sl-bar-fill {
  height: 100%; background: var(--accent);
  border-radius: 3px;
  transition: width 600ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* Tutor — полноэкранный screen, не модалка. Заполняет весь #screen-tutor.
   Это решает проблему двойного скролла в Telegram Mini App: вместо
   sheet поверх главного экрана юзер находится в обычном screen, и
   свайп вниз корректно закрывает мини-апу, как в любом другом разделе. */
#screen-tutor.active {
  display: flex !important;
  flex-direction: column;
  min-height: 100dvh;
  /* Safe-area тут не дублируем — её закладывает .tutor-head, чтобы
     sticky-шапка корректно подкладывалась под Dynamic Island. */
  padding-top: 0 !important;
}
.tutor-screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 100dvh;
  background: var(--bg, #18181c);
  color: var(--text, #fff);
}

.tutor-screen .tutor-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  /* + safe-area под Dynamic Island, чтобы шапка не цепляла часы */
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  /* Шапка прилипает к верху экрана при скролле страницы (или окна
     Telegram Mini App). Кнопка «Назад» всегда под рукой, не нужно
     скроллить вверх ради неё. */
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg, #18181c);
  /* Лёгкая визуальная отстройка при скролле */
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.tutor-screen .tutor-head .back-btn {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
}
.tutor-head-icon { font-size: 26px; }
.tutor-head-text { flex: 1; min-width: 0; }
.tutor-head-title { font-weight: 700; font-size: 16px; }
.tutor-head-sub { color: var(--text-secondary, #888); font-size: 12px; margin-top: 2px; }
.tutor-close {
  background: transparent; border: 0;
  color: var(--text-secondary, #888);
  font-size: 28px; line-height: 1;
  padding: 4px 10px; cursor: pointer;
}

.tutor-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.tutor-msg { display: flex; }
.tutor-msg-user { justify-content: flex-end; }
.tutor-msg-bot { justify-content: flex-start; }
.tutor-bubble {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.tutor-msg-user .tutor-bubble {
  background: var(--accent, #4f8cff);
  color: white;
  border-bottom-right-radius: 6px;
}
.tutor-msg-bot .tutor-bubble {
  background: var(--bg-card, #232328);
  color: var(--text, #fff);
  border-bottom-left-radius: 6px;
}
.tutor-bubble strong { color: inherit; }
.tutor-bubble code {
  background: rgba(255,255,255,0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 90%;
}

.tutor-typing .tutor-bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.tutor-typing .tutor-bubble span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-secondary, #aaa);
  animation: tutorTypingDot 1.2s infinite ease-in-out;
}
.tutor-typing .tutor-bubble span:nth-child(2) { animation-delay: 0.18s; }
.tutor-typing .tutor-bubble span:nth-child(3) { animation-delay: 0.36s; }
@keyframes tutorTypingDot {
  0%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.tutor-suggest {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 8px 14px;
  overflow-x: auto;
  border-top: 1px solid var(--border);
  flex: 0 0 auto;
  scrollbar-width: none;
}
.tutor-suggest::-webkit-scrollbar { display: none; }
.tutor-chip {
  flex: 0 0 auto;
  padding: 6px 12px;
  background: var(--bg-card, #232328);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text-secondary, #ccc);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.tutor-chip:hover { color: var(--text); border-color: var(--accent); }

.tutor-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  flex: 0 0 auto;
}
#tutor-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 10px 14px;
  background: var(--bg-card, #232328);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.4;
  max-height: 140px;
  min-height: 40px;
  outline: none;
}
#tutor-input:focus { border-color: var(--accent); }
.tutor-send {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--accent, #4f8cff);
  color: white;
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 160ms;
}
.tutor-send:disabled { opacity: 0.4; cursor: default; }
@media (min-width: 520px) {
  .micro-modal { align-items: center; }
  .micro-card { border-radius: 18px; }
}

/* Streak indicator — pulse when it increments */
.streak-indicator.bump .streak-fire {
  display: inline-block;
  animation: streakPulse 0.5s cubic-bezier(0.2, 0.8, 0.4, 1.4);
}

/* Screen transitions — direction-aware */
.screen.slide-in-right { animation: slideInRight 0.28s ease; }
.screen.slide-in-left  { animation: slideInLeft  0.28s ease; }

/* Result counters pop in */
.result-value.counted { animation: countUp 0.4s ease; }

/* Level up overlay — upgraded */
.levelup-card {
  animation: levelUpEnter 0.55s cubic-bezier(0.2, 0.8, 0.4, 1.2) !important;
}
.levelup-card .lu-icon {
  animation: trophyShine 1.4s ease-out;
}

/* Confetti canvas — fixed overlay */
#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
}

/* Toast — slide from bottom with subtle spring */
.toast {
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.4, 1.2), opacity 0.3s ease;
}

/* Achievement badge — unlock flash */
@keyframes achUnlockGlow {
  0%   { box-shadow: 0 0 0 0 rgba(236, 201, 75, 0.7); }
  70%  { box-shadow: 0 0 0 18px rgba(236, 201, 75, 0); }
  100% { box-shadow: 0 0 0 0 rgba(236, 201, 75, 0); }
}
.ach-badge.just-unlocked { animation: achUnlockGlow 1.2s ease-out; }

/* ========================================================== */
/* ====== EXTRA ALIVE ANIMATIONS (v2)                   ====== */
/* ========================================================== */

/* Floating +XP text (Duolingo-style) */
.xp-float {
  position: fixed;
  pointer-events: none;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  color: var(--success);
  text-shadow: 0 2px 8px rgba(92, 184, 92, 0.4);
  z-index: 9998;
  animation: xpFloat 1.1s cubic-bezier(0.2, 0.8, 0.4, 1) forwards;
  will-change: transform, opacity;
}
@keyframes xpFloat {
  0%   { transform: translate(-50%, 0) scale(0.6); opacity: 0; }
  15%  { transform: translate(-50%, -8px) scale(1.2); opacity: 1; }
  80%  { transform: translate(-50%, -60px) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -90px) scale(0.85); opacity: 0; }
}

/* Floating short reaction ("Точно!" / "Мимо!" etc) */
.reaction-float {
  position: fixed;
  pointer-events: none;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.5px;
  z-index: 9998;
  animation: reactionFloat 0.9s ease-out forwards;
}
.reaction-float.good  { color: var(--success); }
.reaction-float.bad   { color: var(--error); }
@keyframes reactionFloat {
  0%   { transform: translate(-50%, 0) scale(0.8); opacity: 0; }
  20%  { transform: translate(-50%, -10px) scale(1.1); opacity: 1; }
  100% { transform: translate(-50%, -55px) scale(1); opacity: 0; }
}

/* Sparkle burst (small dots from correct-answer button) */
.sparkle {
  position: fixed;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
  pointer-events: none;
  z-index: 9997;
  animation: sparkleOut 0.7s ease-out forwards;
  will-change: transform, opacity;
}
@keyframes sparkleOut {
  0%   { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}

/* Question area — slide-in when new question appears */
.question-area.incoming {
  animation: questionIn 0.35s cubic-bezier(0.2, 0.8, 0.4, 1.1);
}
@keyframes questionIn {
  from { opacity: 0; transform: translateX(30px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Stagger-in for option buttons */
@keyframes optionIn {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.option-btn.appearing {
  animation: optionIn 0.35s cubic-bezier(0.2, 0.8, 0.4, 1.1) backwards;
}

/* Progress bar shimmer */
.progress-fill,
.xp-bar,
.daily-bar {
  position: relative;
  overflow: hidden;
  transition: width 0.6s cubic-bezier(0.2, 0.8, 0.4, 1);
}
.progress-fill::after,
.xp-bar::after,
.daily-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(255,255,255,0.25) 50%,
    transparent 100%);
  transform: translateX(-100%);
  animation: shimmer 2.4s ease-in-out infinite;
}
@keyframes shimmer {
  0%   { transform: translateX(-100%); }
  60%  { transform: translateX(200%); }
  100% { transform: translateX(200%); }
}

/* Streak fire flicker */
@keyframes flicker {
  0%, 100% { transform: scale(1) rotate(-2deg); filter: brightness(1); }
  25%      { transform: scale(1.08) rotate(2deg); filter: brightness(1.15); }
  50%      { transform: scale(1.02) rotate(-1deg); filter: brightness(0.95); }
  75%      { transform: scale(1.06) rotate(3deg); filter: brightness(1.1); }
}
.streak-indicator.visible .streak-fire {
  display: inline-block;
  animation: flicker 1.8s ease-in-out infinite;
}

/* Mistake item — stagger in on results */
@keyframes mistakeIn {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: translateX(0); }
}
.mistake-item { animation: mistakeIn 0.35s ease backwards; }

/* Module card — gentle gradient sweep on hover (desktop only) */
@media (hover: hover) and (pointer: fine) {
  .module-card {
    background-image: linear-gradient(135deg, var(--bg-card), var(--bg-card));
    transition: transform 0.2s, box-shadow 0.2s, background-image 0.5s;
  }
  .module-card:hover {
    background-image: linear-gradient(135deg, var(--bg-card), var(--accent-light));
  }
}

/* Big XP count on results — bounce when reached */
@keyframes xpBounce {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.3); }
  70%  { transform: scale(0.95); }
  100% { transform: scale(1); }
}
.result-value.bounced { animation: xpBounce 0.55s cubic-bezier(0.3, 1.5, 0.4, 1); }

/* Page transition — next question slide */
@keyframes slideOutLeft {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(-24px); }
}
.question-area.outgoing { animation: slideOutLeft 0.2s ease forwards; }

/* Special: exam module card has distinct gradient */
.module-card.module-exam {
  background: linear-gradient(135deg, #2D5A27 0%, #5CB85C 100%);
  color: white;
  border-color: transparent;
}
[data-theme="dark"] .module-card.module-exam {
  background: linear-gradient(135deg, #1A3A18 0%, #2D5A27 100%);
}
.module-card.module-exam h3,
.module-card.module-exam p,
.module-card.module-exam .module-progress {
  color: white;
}
.module-card.module-exam .module-icon {
  filter: brightness(1.3);
}

/* Neutralize :hover/:active effects on touch devices — they "stick"
   after tap and animate during scroll-touch. Стратегия:
   1) Все state-pseudo (:hover, :active, :focus, :focus-visible,
      :focus-within) принудительно совпадают с baseline — ни цвет, ни
      рамка, ни тень, ни transform не меняются.
   2) Убиваем transition'ы на background / border / transform / shadow
      для интерактивных элементов — даже если браузер на миг применит
      какое-то состояние, никакой анимации обратно не сыграет. */
@media (hover: none), (pointer: coarse) {
  /* === Module card === */
  .module-card,
  .module-card:hover,
  .module-card:active,
  .module-card:focus,
  .module-card:focus-visible,
  .module-card:focus-within {
    background: var(--bg-card) !important;
    border-color: var(--border) !important;
    box-shadow: var(--shadow) !important;
    transform: none !important;
    outline: none !important;
  }
  /* exam-карточка имеет другой фон */
  .module-card.module-exam,
  .module-card.module-exam:hover,
  .module-card.module-exam:active,
  .module-card.module-exam:focus,
  .module-card.module-exam:focus-within {
    background: linear-gradient(135deg, #2D5A27 0%, #5CB85C 100%) !important;
    border-color: transparent !important;
  }

  /* === Все остальные тапабельные === */
  .word-of-day,
  .word-of-day:hover, .word-of-day:active, .word-of-day:focus, .word-of-day:focus-within,
  .ach-badge:hover, .ach-badge:active, .ach-badge:focus,
  .rule-section-head:hover, .rule-section-head:active, .rule-section-head:focus {
    transform: none !important;
    box-shadow: var(--shadow) !important;
    outline: none !important;
  }

  /* === Кнопки (общие) === */
  .nav-btn:hover, .nav-btn:active, .nav-btn:focus, .nav-btn:focus-within,
  .back-btn:hover, .back-btn:active, .back-btn:focus, .back-btn:focus-within,
  .next-btn:hover, .next-btn:active, .next-btn:focus,
  .btn-secondary:hover, .btn-secondary:active, .btn-secondary:focus,
  .btn-share:hover, .btn-share:active, .btn-share:focus,
  .rule-tab:hover, .rule-tab:active, .rule-tab:focus,
  .microlesson-btn:hover, .microlesson-btn:active, .microlesson-btn:focus,
  button:active, button:focus, button:focus-within {
    transform: none !important;
    outline: none !important;
  }
  /* nav-btn — цвет неактивный по умолчанию, активный по .active */
  .nav-btn:hover, .nav-btn:active, .nav-btn:focus { color: var(--text-secondary) !important; }
  .nav-btn.active, .nav-btn.active:hover, .nav-btn.active:focus { color: var(--accent) !important; }
  .back-btn:hover, .back-btn:active, .back-btn:focus {
    border-color: var(--border) !important;
    color: var(--text) !important;
  }
  .btn-secondary:hover, .btn-secondary:active, .btn-secondary:focus {
    border-color: var(--border) !important;
    color: var(--text) !important;
  }
  /* btn-primary — у него фон акцент, не сбрасываем его */
  .btn-primary:hover, .btn-primary:active, .btn-primary:focus {
    background: var(--accent) !important;
    transform: none !important;
    outline: none !important;
  }
  .next-btn:hover, .next-btn:active, .next-btn:focus {
    background: var(--accent) !important;
    transform: none !important;
  }

  /* === Option buttons (варианты ответов) === */
  /* Никаких hover/active эффектов — состояние диктуется ТОЛЬКО классами. */
  .option-btn,
  .option-btn:hover,
  .option-btn:active,
  .option-btn:focus,
  .option-btn:focus-visible,
  .option-btn:hover:not(.disabled),
  .option-btn:active:not(.disabled) {
    background: var(--bg-card) !important;
    border-color: var(--border) !important;
    color: var(--text) !important;
    transform: none !important;
    outline: none !important;
  }
  .option-btn.correct, .option-btn.correct:hover, .option-btn.correct:active {
    background: var(--success-bg) !important;
    border-color: var(--success) !important;
    color: var(--success) !important;
  }
  .option-btn.wrong, .option-btn.wrong:hover, .option-btn.wrong:active {
    background: var(--error-bg) !important;
    border-color: var(--error) !important;
    color: var(--error) !important;
  }
  .option-btn.selected, .option-btn.selected:hover, .option-btn.selected:active {
    border-color: var(--accent) !important;
  }

  /* === Контрольный выстрел: убиваем transition'ы у тех свойств, на
     которых играет браузер при touch. Без transition нечего
     анимировать — даже если pseudo-class на миг применится. ===
     Прозрачность и colors-of-text оставляем для остальной UI-анимации. */
  .module-card,
  .word-of-day,
  .nav-btn,
  .back-btn,
  .next-btn,
  .btn-primary,
  .btn-secondary,
  .btn-share,
  .option-btn,
  .ach-badge,
  .rule-tab,
  .rule-section-head,
  .microlesson-btn,
  .micro-cta,
  .sw-update-bar button {
    transition: opacity 150ms ease, color 150ms ease !important;
  }
}

/* Respect user's motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  #screen-home.active .logo-mark { animation: none; }
}

/* ====== STREAK FREEZE BADGE ====== */
.freeze-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 2px 7px;
  letter-spacing: 0.2px;
}
.freeze-badge.hidden { display: none; }

/* ====== REVIEW CARD ====== */
.review-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  margin-bottom: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  text-align: left;
  color: var(--text);
  font-family: inherit;
  position: relative;
  overflow: hidden;
}
.review-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--warning);
}
.review-card:hover {
  transform: translateY(-1px);
  border-color: var(--warning);
  box-shadow: var(--shadow-md);
}
.review-card.hidden { display: none; }
.review-icon {
  font-size: 24px;
  line-height: 1;
  width: 40px;
  text-align: center;
}
.review-info { flex: 1; min-width: 0; }
.review-info h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 2px;
  color: var(--text);
}
.review-info p {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0;
}
.review-badge {
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 14px;
  background: var(--warning);
  color: #1A1A1A;
  font-weight: 700;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ====== DAILY CHALLENGE ====== */
.daily-challenge {
  display: none; /* По умолчанию скрыт. Открывается тапом на ◆ в strip. */
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color var(--transition);
}
.daily-challenge.dc-expanded { display: block; }
.daily-challenge:hover { border-color: var(--accent); }
.daily-challenge.hidden { display: none; }
.daily-challenge.dc-completed {
  background: var(--success-bg);
  border-color: var(--success);
}
.dc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.dc-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.2px;
}
.dc-title::before { content: '◆ '; color: var(--accent); font-size: 11px; vertical-align: middle; }
.dc-meta {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}
.dc-bar-wrap {
  width: 100%;
  height: 4px;
  background: rgba(0,0,0,0.08);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 10px;
}
[data-theme="dark"] .dc-bar-wrap { background: rgba(255,255,255,0.06); }
.dc-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s ease;
}
.dc-tasks {
  display: none;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}
.daily-challenge.dc-expanded .dc-tasks { display: flex; }
.dc-task {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  background: var(--bg);
}
.dc-task-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.dc-check {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.dc-task-done .dc-check {
  background: var(--accent);
  color: #fff;
}
.dc-task-title {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.dc-task-done .dc-task-title {
  color: var(--text-secondary);
  text-decoration: line-through;
  text-decoration-color: var(--text-muted);
}
.dc-task-xp {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-light);
  padding: 2px 6px;
  border-radius: 8px;
}
.dc-task-bar {
  width: 100%;
  height: 3px;
  background: rgba(0,0,0,0.06);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 3px;
}
[data-theme="dark"] .dc-task-bar { background: rgba(255,255,255,0.05); }
.dc-task-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s ease;
}
.dc-task-meta {
  font-size: 10px;
  color: var(--text-muted);
  text-align: right;
}
