/* ============================================================
   Тема: тёмная по умолчанию, светлая по переключателю.
   У каждого раздела свой акцентный цвет — так по цвету видно,
   где ты находишься, и интерфейс перестаёт быть одноцветным.
   ============================================================ */
:root,
:root[data-theme="dark"] {
  --bg: #12141a;
  --bg-glow: radial-gradient(1200px 600px at 15% -10%, rgba(224, 97, 79, 0.06), transparent 60%),
             radial-gradient(900px 500px at 90% 0%, rgba(122, 167, 232, 0.05), transparent 55%);
  --surface: #1a1d26;
  --surface-2: #222633;
  --surface-3: #2b3040;
  --ink: #dde1ea;
  --ink-soft: #a3abbd;
  --ink-faint: #737c91;
  --line: #2c3140;
  --line-strong: #3a4053;

  --accent: #d9584a;
  --accent-ink: #ffffff;
  --accent-soft: rgba(217, 88, 74, 0.16);
  /* Акцент для мелкого текста (пиньинь). На тёмном фоне обычного акцента хватает. */
  --accent-text: #ec7a6b;
  /* Пиньинь — спокойный холодный цвет: его на странице много, красным он рябит. */
  --pinyin: #9db3d9;

  --ok: #6cc48a;
  --ok-soft: rgba(74, 222, 128, 0.15);
  --warn: #e0b955;
  --warn-soft: rgba(251, 191, 36, 0.15);
  --err: #e98080;
  --err-soft: rgba(248, 113, 113, 0.15);

  --c-course: #d9a24a;
  --c-review: #e0705f;
  --c-words: #6bb8e0;
  --c-reading: #7aa7e8;
  --c-chars: #a99be6;
  --c-tones: #5cc2b0;
  --c-grammar: #6cc48a;
  --c-listening: #e08ab3;
  --c-progress: #e0b955;


  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 28px rgba(0, 0, 0, 0.28);
  --radius: 16px;
  --radius-lg: 22px;
}

:root[data-theme="light"] {
  --bg: #f6f7fb;
  --bg-glow: radial-gradient(1200px 600px at 15% -10%, rgba(224, 61, 38, 0.05), transparent 60%),
             radial-gradient(900px 500px at 90% 0%, rgba(56, 189, 248, 0.05), transparent 55%);
  --surface: #ffffff;
  --surface-2: #f2f4f9;
  --surface-3: #e7eaf2;
  --ink: #171a21;
  --ink-soft: #5a6274;
  --ink-faint: #8b93a5;
  --line: #e2e6ef;
  --line-strong: #cfd5e2;

  --accent: #e03d26;
  --accent-ink: #ffffff;
  --accent-soft: rgba(224, 61, 38, 0.10);
  /* На белом фоне #e03d26 даёт 4,3:1 — для мелкого пиньиня мало, берём темнее. */
  --accent-text: #c02d18;
  --pinyin: #3b5a8c;

  --ok: #16a34a;
  --ok-soft: rgba(22, 163, 74, 0.12);
  --warn: #b45309;
  --warn-soft: rgba(180, 83, 9, 0.12);
  --err: #dc2626;
  --err-soft: rgba(220, 38, 38, 0.12);

  --c-course: #c2740a;
  --c-review: #e03d26;
  --c-words: #0284c7;
  --c-reading: #1d6fd8;
  --c-chars: #7c3aed;
  --c-tones: #0d9488;
  --c-grammar: #15803d;
  --c-listening: #db2777;
  --c-progress: #b45309;


  --shadow: 0 1px 2px rgba(23, 26, 33, 0.05), 0 8px 24px rgba(23, 26, 33, 0.07);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  background-image: var(--bg-glow);
  background-attachment: fixed;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

/* Китайский шрифт задаём явно. Без этого браузер берёт первый попавшийся CJK-шрифт
   в системе, и если стоит японский, часть знаков рисуется в японском начертании
   (直, 骨, 今 отличаются) — учить по ним написание нельзя. */
:lang(zh), :lang(zh-Hans),
.hanzi-text, .hanzi-font, .flashcard-hanzi, .ex-hanzi, .char-tile .hanzi,
.tone-hanzi, .word-chips span, .wl-hanzi, .w-hanzi, .quiz-options-hanzi button,
.brand-mark, .tile-icon, .drill-answer button, .drill-bank button {
  font-family: "Noto Sans SC", "Source Han Sans SC", "PingFang SC",
    "Microsoft YaHei", "Hiragino Sans GB", "Heiti SC", sans-serif;
}

a { color: var(--accent); }

h1 { font-size: 1.9rem; margin: 0 0 6px; letter-spacing: -0.02em; }
h2 { font-size: 1.25rem; margin: 32px 0 14px; letter-spacing: -0.01em; }
h3 { font-size: 1.02rem; margin: 0 0 8px; }

.subtitle { color: var(--ink-soft); margin: 0 0 22px; max-width: 62ch; }
.muted { color: var(--ink-soft); }
.small { font-size: 0.87rem; }
.hanzi-font { font-size: 1.5rem; }

/* ---------------- Шапка ---------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.site-header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  text-decoration: none;
  color: var(--ink);
  font-size: 1.02rem;
  white-space: nowrap;
}
/* Значок — прозрачная иконка без подложки: своя форма у неё выразительнее
   любого квадрата, а на обеих темах она читается одинаково. */
.brand-mark {
  width: 36px; height: 36px;
  display: grid;
  place-items: center;
}
.brand-mark .mascot { width: 36px; }
.brand:hover .mascot { transform: translateY(-1px); transition: transform 0.15s; }

.site-nav { display: flex; gap: 3px; flex: 1; }

.site-nav a {
  color: var(--ink-soft);
  text-decoration: none;
  padding: 8px 13px;
  border-radius: 10px;
  font-size: 0.94rem;
  font-weight: 500;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.site-nav a:hover { background: var(--surface-2); color: var(--ink); }
.site-nav a.active { background: var(--accent-soft); color: var(--accent); }

.nav-badge {
  min-width: 21px;
  padding: 1px 7px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  text-align: center;
}

.header-tools { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px;
  padding: 0;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink-soft);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 1rem;
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
/* Переключатель скорости: подпись «0,75×» в квадрат 36px не влезает. */
.speed-btn {
  width: auto;
  min-width: 46px;
  padding: 0 9px;
  font-size: 0.82rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.speed-btn.is-slow {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.user-name { color: var(--ink-soft); font-size: 0.9rem; white-space: nowrap; }

.content { max-width: 1120px; margin: 0 auto; padding: 30px 20px 70px; }
.content-narrow { max-width: 760px; }

/* ---------------- Кнопки ---------------- */
button, .btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 20px;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.08s, filter 0.15s, background 0.15s;
}
button:hover, .btn:hover { filter: brightness(1.08); }
button:active, .btn:active { transform: translateY(1px); }

.btn-secondary {
  background: var(--surface-2);
  color: var(--ink);
  border-color: var(--line-strong);
}
.btn-secondary:hover { background: var(--surface-3); }

.btn-ghost { background: transparent; color: var(--ink-soft); border-color: transparent; font-weight: 500; }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }

.btn-lg { padding: 15px 30px; font-size: 1.06rem; border-radius: 14px; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 13px; font-size: 0.85rem; border-radius: 9px; }

button:disabled, .btn:disabled { opacity: 0.5; cursor: default; }

/* ---------------- Карточки и сетки ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.card-link { display: block; text-decoration: none; color: inherit; transition: border-color 0.15s, transform 0.12s; }
.card-link:hover { border-color: var(--line-strong); transform: translateY(-2px); }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); }

/* ---------------- Главная: «Сегодня» ---------------- */
.today {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 860px) { .today { grid-template-columns: 1fr; } }

.today-main {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.today-main::after {
  content: "";
  position: absolute;
  inset: auto -60px -90px auto;
  width: 260px; height: 260px;
  background: radial-gradient(circle, var(--accent-soft), transparent 70%);
  pointer-events: none;
}
.today-eyebrow {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 8px;
}
.today-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; position: relative; }

.word-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; position: relative; }
.word-chips span {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 7px 13px;
  font-size: 1.45rem;
  line-height: 1.2;
}

.today-side { display: flex; flex-direction: column; gap: 14px; }

.goal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 18px;
}
.ring { position: relative; width: 92px; height: 92px; flex-shrink: 0; }
.ring svg { transform: rotate(-90deg); }
.ring-track { stroke: var(--surface-3); }
.ring-fill { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 0.5s; }
.ring-label {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-weight: 700; font-size: 1.05rem;
}

.streak-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
}
.streak-flame { font-size: 1.9rem; }
.streak-num { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 14px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 17px 19px;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 1.8rem; font-weight: 700; line-height: 1.15; }
.stat-label { color: var(--ink-soft); font-size: 0.86rem; }

.progress-bar {
  height: 9px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 11px;
}
.progress-bar > div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #ff9a3c);
  border-radius: 999px;
  transition: width 0.4s;
}
/* Полоса из двух сегментов: выученное и начатое. Одна цифра «выучено» в первые недели
   всегда ноль, и полоса выглядела мёртвой, хотя занятия шли. */
.progress-bar.stacked { display: flex; }
.progress-bar.stacked > div { border-radius: 0; }
.progress-bar.stacked > .seg-learned { background: var(--ok); }
.progress-bar.stacked > .seg-learning {
  background: color-mix(in srgb, var(--accent) 55%, transparent);
}
.progress-bar.stacked > div:first-child { border-radius: 999px 0 0 999px; }
.progress-bar.stacked > div:last-child { border-radius: 0 999px 999px 0; }

/* ---------------- Плитки разделов ---------------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 14px; }

.tile {
  --tile: var(--accent);
  position: relative;
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.12s, border-color 0.15s;
}
.tile::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--tile);
}
.tile:hover { transform: translateY(-3px); border-color: var(--tile); }
.tile-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 1.25rem;
  background: color-mix(in srgb, var(--tile) 18%, transparent);
  color: var(--tile);
  margin-bottom: 12px;
}
.tile h3 { color: var(--tile); margin-bottom: 5px; }
.tile p { margin: 0; color: var(--ink-soft); font-size: 0.89rem; }
.tile-meta { margin-top: 10px; font-size: 0.82rem; color: var(--ink-faint); }

.t-course { --tile: var(--c-course); }
.t-review { --tile: var(--c-review); }
.t-words { --tile: var(--c-words); }
.t-reading { --tile: var(--c-reading); }
.t-chars { --tile: var(--c-chars); }
.t-tones { --tile: var(--c-tones); }
.t-grammar { --tile: var(--c-grammar); }
.t-listening { --tile: var(--c-listening); }
.t-progress { --tile: var(--c-progress); }

/* ---------------- Списки ---------------- */
.list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.list > li > a, .list > li > .list-row {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 15px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, transform 0.12s;
}
.list > li > a:hover { border-color: var(--line-strong); transform: translateX(2px); }
.list .title { font-weight: 600; }
.list .spacer { flex: 1; }

.tag {
  font-size: 0.76rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-soft);
  white-space: nowrap;
  border: 1px solid var(--line);
}
.tag-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.tag-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

/* ---------------- Вкладки уровней ---------------- */
.level-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.level-tabs a {
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
}
.level-tabs a:hover { border-color: var(--line-strong); color: var(--ink); }
.level-tabs a.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------------- Карточки слов ---------------- */
.review-header {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 520px;
  margin: 0 auto 18px;
}
.review-header .progress-bar { flex: 1; margin: 0; }

.flashcard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 48px 26px 30px;
  text-align: center;
  max-width: 520px;
  margin: 0 auto;
}
.flashcard-hanzi { font-size: 5.2rem; line-height: 1.05; margin-bottom: 10px; letter-spacing: 0.05em; }
.flashcard-pinyin { color: var(--pinyin); font-size: 1.3rem; font-weight: 600; }
.flashcard-translation { font-size: 1.45rem; margin: 16px 0 6px; }
.flashcard-hint { color: var(--ink-faint); font-size: 0.84rem; margin: 22px 0 0; }
/* Подпись направления карточки: узнавание, припоминание или на слух. */
.flashcard-mode {
  color: var(--ink-faint);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: -24px 0 22px;
}
/* Вопрос по-русски — крупный, но не как иероглиф: это не то, что надо разглядывать. */
.flashcard-ask { font-size: 2rem; line-height: 1.25; margin-bottom: 10px; }
.flashcard-listen { margin-bottom: 12px; }
/* Когда иероглиф уходит на оборот, он больше не заголовок карточки — уменьшаем. */
.flashcard-recall #answer .flashcard-hanzi,
.flashcard-listening #answer .flashcard-hanzi { font-size: 3.6rem; }
.flashcard-actions { display: flex; gap: 12px; justify-content: center; margin-top: 24px; }
.flashcard-actions button { flex: 1; max-width: 200px; padding: 14px; }
.btn-no { background: var(--surface-2); color: var(--warn); border-color: var(--warn); }
.btn-yes { background: var(--ok); color: #06240f; }
:root[data-theme="light"] .btn-yes { color: #fff; }

.kbd-hint {
  display: inline-block;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 0.78rem;
  color: var(--ink-faint);
  background: var(--surface-2);
}

/* ---------------- Чтение ---------------- */
.hanzi-text {
  font-size: 2rem;
  line-height: 2.05;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 28px;
  margin: 18px 0;
  box-shadow: var(--shadow);
}
.hanzi-word { cursor: pointer; border-radius: 5px; padding: 0 1px; transition: background 0.12s; }
.hanzi-word:hover, .hanzi-word.active { background: var(--accent-soft); color: var(--accent); }

.word-popover {
  position: fixed;
  z-index: 60;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  color: var(--ink);
  padding: 12px 15px;
  border-radius: 12px;
  font-size: 0.96rem;
  line-height: 1.45;
  max-width: 280px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}
.word-popover .pop-pinyin { color: var(--pinyin); font-weight: 600; }
.word-popover .pop-translation { margin-top: 2px; }
.word-popover .pop-actions {
  display: flex; gap: 8px; align-items: center;
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--line);
}
.word-popover .pop-add { background: var(--surface); color: var(--ink-soft); border: 1px solid var(--line-strong); }
.word-popover .pop-add:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.word-popover .pop-add:disabled { opacity: 0.65; cursor: default; }

/* ---------------- Читалка: текст по предложениям ---------------- */
.reader-toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 18px 0 6px;
}
.reader-toolbar .spacer { flex: 1; }
.reader-hint { margin: 0 0 16px; }

.switch { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; color: var(--ink-soft); font-size: 0.9rem; }
.switch input { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }

.reader { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.reader-line {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.reader-line:hover { border-color: var(--line-strong); }
.reader-body { flex: 1; min-width: 0; }
.reader-play { flex-shrink: 0; margin-top: 4px; }
/* Внутри строки иероглифы уже в карточке — своя рамка и фон не нужны. */
.reader .sentence-hanzi {
  background: none; border: none; box-shadow: none;
  padding: 0; margin: 0;
  font-size: 1.7rem; line-height: 1.75;
}
.reader .sentence-pinyin { color: var(--pinyin); margin: 8px 0 0; font-size: 0.95rem; }
.reader .sentence-translation { color: var(--ink-soft); margin: 4px 0 0; }


.reveal-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 16px 0;
}
.reveal-block summary { cursor: pointer; font-weight: 600; }
.reveal-block .pinyin-line { color: var(--pinyin); margin: 14px 0 10px; }
.reveal-block .translation-line { margin: 0; color: var(--ink-soft); }

/* ---------------- Упражнения ---------------- */
.quiz-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.quiz-options { display: flex; flex-direction: column; gap: 9px; margin-top: 15px; }
.quiz-options button {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
  text-align: left;
  justify-content: flex-start;
  padding: 13px 17px;
  font-weight: 500;
}
.quiz-options button:hover:not(:disabled) { border-color: var(--line-strong); background: var(--surface-3); }
.quiz-options button.correct { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); font-weight: 700; }
.quiz-options button.wrong { background: var(--err-soft); border-color: var(--err); color: var(--err); }
.quiz-options button:disabled { opacity: 1; }
.quiz-feedback { margin-top: 14px; font-size: 0.97rem; color: var(--ink-soft); }
.quiz-feedback .hanzi { font-size: 1.35rem; color: var(--ink); }
.quiz-next { margin-top: 16px; }

.audio-btn {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid transparent;
  font-weight: 600;
}
.audio-btn:hover { background: color-mix(in srgb, var(--accent) 26%, transparent); }

/* ---------------- Иероглифы ---------------- */
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 11px; }
.char-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 8px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  position: relative;
  color: var(--ink);
  font-weight: 400;
  transition: transform 0.12s, border-color 0.15s;
}
.char-tile:hover { transform: translateY(-3px); border-color: var(--c-chars); }
.char-tile .hanzi { font-size: 2.3rem; line-height: 1.15; }
.char-tile .pinyin { font-size: 0.82rem; color: var(--c-chars); }
.char-tile .meaning {
  font-size: 0.75rem;
  line-height: 1.25;
  color: var(--ink-faint);
  text-align: center;
  max-width: 100%;
  /* Раньше здесь стояло white-space: nowrap с многоточием, и значение обрывалось
     на первом же слове: «частица побужд…». Теперь помещается до трёх строк. */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.char-tile .done { position: absolute; top: 7px; right: 9px; color: var(--ok); font-size: 0.82rem; }

/* ---------------- Модальное окно ---------------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 12, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-inner {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 420px;
  text-align: center;
  position: relative;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.modal-close {
  position: absolute; top: 12px; right: 14px;
  background: transparent; color: var(--ink-faint);
  font-size: 1.5rem; padding: 2px 9px; line-height: 1;
}
.modal-close:hover { background: var(--surface-2); color: var(--ink); }
.modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
#char-writer-target {
  display: flex; justify-content: center;
  margin: 18px 0; min-height: 232px;
  background: var(--surface-2);
  border-radius: 14px;
}

/* ---------------- Тоны и пиньинь ---------------- */
.tone-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 13px; }
.tone-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.tone-card:hover { border-color: var(--c-tones); }
.tone-num { font-weight: 700; color: var(--c-tones); }
.tone-mark { font-size: 0.82rem; color: var(--ink-faint); margin-bottom: 10px; min-height: 2.4em; }
.tone-hanzi { font-size: 2.6rem; line-height: 1.1; }
.tone-pinyin { color: var(--c-tones); font-weight: 600; }
.tone-meaning { font-size: 0.85rem; color: var(--ink-soft); margin-bottom: 12px; }
.tone-card button { margin-top: auto; }

.pinyin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 9px; }
.pinyin-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 6px 10px;
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1.25;
}
.pinyin-tile .pt-syllable { font-size: 1.15rem; }
/* Пример показывает, что именно прозвучит: инициаль отдельно не произносится. */
.pinyin-tile .pt-example { font-size: 1.05rem; font-weight: 500; color: var(--ink-soft); }
.pinyin-tile .pt-pinyin { font-size: 0.78rem; font-weight: 500; color: var(--ink-faint); }
.pinyin-tile:hover .pt-example, .pinyin-tile:hover .pt-pinyin { color: inherit; }
.pinyin-tile:hover { background: color-mix(in srgb, var(--c-tones) 16%, transparent); color: var(--c-tones); border-color: var(--c-tones); }

/* ---------------- Прогресс ---------------- */
.activity-chart { display: flex; align-items: flex-end; gap: 6px; height: 110px; margin-top: 14px; }
.activity-chart .bar-wrap { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.activity-chart .bar {
  background: linear-gradient(180deg, var(--accent), #ff9a3c);
  border-radius: 5px 5px 0 0;
  min-height: 4px;
}
.activity-chart .bar.empty { background: var(--surface-3); }
.activity-labels { display: flex; gap: 6px; margin-top: 7px; }
.activity-labels span { flex: 1; text-align: center; font-size: 0.7rem; color: var(--ink-faint); }

.level-progress { display: flex; flex-direction: column; gap: 16px; }
.level-progress .row-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }

/* ---------------- Формы ---------------- */
.auth-wrap { max-width: 400px; margin: 8vh auto; }
.auth-logo { text-align: center; margin-bottom: 26px; }
.auth-logo .brand-mark { width: 56px; height: 56px; margin: 0 auto 14px; font-size: 1.6rem; border-radius: 16px; }

.form { display: flex; flex-direction: column; gap: 15px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.89rem; color: var(--ink-soft); font-weight: 500; }
.form input, .search-form input {
  font: inherit;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--ink);
}
.form input:focus, .search-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.search-form { display: flex; gap: 9px; margin-bottom: 18px; flex-wrap: wrap; }
.search-form input { flex: 1; min-width: 210px; }

.alert { padding: 13px 16px; border-radius: 12px; margin-bottom: 16px; font-size: 0.93rem; }
.alert-error { background: var(--err-soft); color: var(--err); }
.alert-info { background: var(--surface-2); color: var(--ink-soft); border: 1px solid var(--line); }

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  padding: 40px 26px;
  text-align: center;
  color: var(--ink-soft);
}
.empty-state .btn { margin: 6px 4px 0; }

.pagination { display: flex; gap: 10px; justify-content: center; align-items: center; margin-top: 24px; flex-wrap: wrap; }

.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  margin-bottom: 14px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.9rem;
}
.back-link:hover { color: var(--ink); }

/* ---------------- Слова в списке ---------------- */
.word-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.word-row:hover { border-color: var(--line-strong); }
.word-row .w-hanzi { font-size: 1.75rem; min-width: 84px; }
.word-row .w-pinyin { color: var(--c-words); min-width: 118px; font-size: 0.93rem; font-weight: 600; }
.word-row .w-translation { flex: 1; }
.word-row .w-actions { display: flex; gap: 7px; align-items: center; }

/* ---------------- Урок ---------------- */
.lesson-step { margin-bottom: 30px; }
.lesson-step-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.step-num {
  width: 30px; height: 30px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid; place-items: center;
  font-size: 0.9rem; font-weight: 700;
  flex-shrink: 0;
}
.lesson-step-head h2 { margin: 0; font-size: 1.15rem; }

.word-line {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}
.word-line:first-of-type { border-top: none; padding-top: 0; }
.word-line .wl-hanzi { min-width: 80px; font-size: 1.85rem; line-height: 1.2; }
.word-line .wl-pinyin { color: var(--pinyin); font-size: 0.92rem; font-weight: 600; }

.example { padding: 14px 0; border-top: 1px solid var(--line); }
.example:first-of-type { border-top: none; padding-top: 0; }
.example .ex-hanzi { font-size: 1.4rem; line-height: 1.5; }
.example .ex-pinyin { color: var(--pinyin); font-size: 0.92rem; }
.example .ex-translation { color: var(--ink-soft); font-size: 0.94rem; }

@media (max-width: 760px) {
  .site-header-inner { flex-wrap: wrap; gap: 10px; }
  .site-nav { order: 3; width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .user-name { display: none; }
  h1 { font-size: 1.5rem; }
  .content { padding: 22px 15px 60px; }
  .today-main { padding: 22px; }
  .flashcard { padding: 36px 18px 24px; }
  .flashcard-hanzi { font-size: 4rem; }
  .hanzi-text { font-size: 1.65rem; padding: 20px; }
  .word-row { flex-wrap: wrap; gap: 10px; }
  .word-row .w-pinyin, .word-row .w-hanzi { min-width: auto; }
  .word-row .w-translation { flex-basis: 100%; }
}

/* ---------------- Упражнение по грамматике ---------------- */
.drill-prompt {
  font-size: 1.05rem;
  margin: 8px 0 14px;
}
.drill-answer {
  min-height: 52px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-content: flex-start;
}
.drill-pool {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.drill-chip {
  font-family: inherit;
  font-size: 1.15rem;
  line-height: 1.2;
  padding: 7px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.12s, transform 0.08s;
}
.drill-chip:hover { border-color: var(--c-grammar, var(--accent)); }
.drill-chip:active { transform: translateY(1px); }
.drill-chip.placed { background: var(--surface); border-style: solid; }
.drill-feedback {
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 0.92rem;
}
.drill-feedback.ok { background: rgba(60, 160, 90, 0.14); }
.drill-feedback.wrong { background: rgba(200, 90, 70, 0.14); }
.drill-feedback .ex-hanzi { margin-bottom: 2px; }
.drill-feedback button { margin-top: 8px; }
.drill-actions { display: flex; gap: 8px; }

.w-pos {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--ink-faint);
  font-size: 0.72rem;
  vertical-align: middle;
}

.quiz-options-hanzi button {
  font-size: 1.15rem;
  line-height: 1.35;
}
.quiz-feedback .ex-hanzi { line-height: 1.5; }

/* ---------------- Продолжить и поиск по урокам ---------------- */
.continue-card {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--c-course);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 18px 0 10px;
  box-shadow: var(--shadow);
}
.continue-card .spacer { flex: 1; }

.search-row { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; margin: 18px 0 6px; }
.search-row input {
  flex: 1; min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  padding: 11px 14px;
  font: inherit;
}
.search-row input:focus { outline: none; border-color: var(--accent); }

/* ---------------- Меньше движения ---------------- */
/* Системная настройка «уменьшить анимацию» — её просят не для красоты:
   от плавных переходов и появлений у части людей кружится голова. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------------- Панда ---------------- */
/* Только на «пустых» экранах: всё повторено, заход закончен, страницы нет.
   На страницах с материалом её нет намеренно — там смотреть надо на иероглиф. */
.mascot { width: 128px; height: auto; display: block; }
.mascot-holder { display: flex; justify-content: center; margin-bottom: 14px; }
.mascot-holder.small .mascot { width: 92px; }
/* Лёгкое покачивание — заметно, только если специально смотреть. */
@keyframes mascot-breathe {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-3px) rotate(-1.2deg); }
}
.mascot-holder .mascot { animation: mascot-breathe 4.5s ease-in-out infinite; }
.today-main .mascot-holder { position: absolute; right: 26px; bottom: 18px; margin: 0; opacity: 0.95; }
@media (max-width: 760px) {
  .today-main .mascot-holder { display: none; }
}

/* ---------------- Подвал и обратная связь ---------------- */
.site-footer { border-top: 1px solid var(--line); margin-top: 20px; }
.site-footer-inner {
  max-width: 1120px; margin: 0 auto; padding: 18px 20px 28px;
  display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center;
  font-size: 0.88rem;
}
.site-footer a { color: var(--ink-soft); }
.site-footer a:hover { color: var(--ink); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.link-btn {
  background: none; border: 0; padding: 0; font: inherit; font-weight: inherit;
  color: var(--accent-text); text-decoration: underline; cursor: pointer; display: inline;
}
.link-btn:hover { filter: none; }

.feedback-inner { max-width: 480px; text-align: left; max-height: calc(100vh - 40px); overflow-y: auto; }
.feedback-inner h2 { margin: 0 0 4px; }
.feedback-lead { margin: 0; }
.feedback-kinds { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.form .feedback-kinds label {
  flex-direction: row; align-items: center; gap: 7px;
  padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 10px;
  color: var(--ink); cursor: pointer;
}
.form .feedback-kinds label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.form .feedback-kinds input { accent-color: var(--accent); margin: 0; }
.form textarea {
  font: inherit; padding: 12px 14px; resize: vertical; min-height: 110px;
  border: 1px solid var(--line-strong); border-radius: 11px;
  background: var(--surface-2); color: var(--ink);
}
.form textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.feedback-trap { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.feedback-inner .alert { margin: 0; }

.feedback-filter { display: flex; gap: 8px; margin-bottom: 18px; }
.feedback-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.feedback-item.is-done { opacity: 0.6; }
.feedback-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.feedback-meta .spacer { flex: 1; }
.feedback-meta form { margin: 0; }
.feedback-text { white-space: pre-wrap; overflow-wrap: anywhere; margin: 12px 0; }

.prose h2:first-child { margin-top: 0; }
.prose p { line-height: 1.6; color: var(--ink-soft); }

/* ---------------- Пиньинь над иероглифами в русском тексте ---------------- */
/* Подпись мелкая и приглушённая: читается при взгляде на иероглиф, но не спорит с текстом. */
.with-pinyin { line-height: 2.45; }
h1.with-pinyin { line-height: 1.75; }
.hz-annot ruby { ruby-position: over; margin: 0 2px; }
.hz-annot rt {
  /* Не мельче 12px: в уроке пояснение набрано мелким шрифтом, и доля от него давала 9px. */
  font-size: max(0.74em, 12px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--pinyin);
  font-weight: 500;
  letter-spacing: 0;
}
h1 .hz-annot rt { font-size: max(0.5em, 15px); }

.back-links { display: flex; flex-wrap: wrap; gap: 4px 18px; align-items: baseline; }
.back-link-secondary { color: var(--ink-faint); }

/* ---------------- Логин без почты: код восстановления ---------------- */
.auth-note { margin: 16px 0 0; }
.recovery-card h1 { font-size: 1.45rem; }
.recovery-code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 1.6rem; font-weight: 700; letter-spacing: 0.08em; text-align: center;
  padding: 18px 12px; margin: 18px 0 10px;
  background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: 12px;
  user-select: all; overflow-wrap: anywhere;
}
.recovery-actions { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.recovery-confirm { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; cursor: pointer; }
.recovery-confirm input { accent-color: var(--accent); width: 18px; height: 18px; margin: 0; }
.btn[aria-disabled="true"] { opacity: 0.5; cursor: default; }
a.user-name { text-decoration: none; }
a.user-name:hover { color: var(--ink); }

/* ---------- Без регистрации: вход в шапке и плашка про гостевой прогресс ---------- */
a.header-login, a.header-register { text-decoration: none; white-space: nowrap; display: inline-flex; align-items: center; }
a.header-login { color: var(--ink-soft); padding: 7px 10px; }
a.header-login:hover { color: var(--ink); }
.guest-note {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 14px 18px;
  margin: 0 0 22px;
}
.guest-note p { margin: 0 0 10px; }
.guest-note p.small { margin: 8px 0 0; }
.guest-note-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.guest-note-actions a { text-decoration: none; }
/* На телефоне в шапке только «Войти»: регистрация есть на плашке под шапкой. */
@media (max-width: 760px) {
  a.header-register { display: none; }
  /* Первая строка — название и кнопки, вторая — разделы. flex-basis 100% нужен явно:
     у .site-nav стоит flex: 1, и без этого меню втискивалось в строку с кнопками. */
  .site-header-inner { justify-content: space-between; padding: 10px 15px; }
  .site-nav { flex: 0 0 100%; }
  .header-tools { gap: 6px; }
  a.header-login { padding: 7px 6px; }
}
/* Совсем узкие телефоны: название сайта не влезает рядом с кнопками — остаётся панда. */
@media (max-width: 379px) {
  .brand > span:last-child { display: none; }
}
