/* Вынесено из includes/topnav.php (31.10.2026): общий блок оболочки — кэшируется браузером, а не
   качается заново с каждой страницей. */
  /* Full-bleed header makes the bar 100vw; clip keeps that from adding a
     horizontal scrollbar on scrollbar-OSes (clip, unlike hidden, doesn't
     break the sticky positioning below). */
  html { overflow-x: clip; }
  .topnav {
    position: sticky; top: 0; z-index: 800;
    background: #fffdfb; border-bottom: 1px solid #e7dfd6;
    box-shadow: 0 1px 0 rgba(20,20,19,0.02);
    /* Escape each page's body padding / centred container so the bar spans
       the whole window. calc adapts to whatever symmetric padding the page
       uses, so it works on every page without per-page tweaks. */
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
  }
  .topnav-inner {
    max-width: 1200px; margin: 0 auto;
    padding: 10px 16px;
    display: flex; align-items: center; gap: 22px;
  }
  .topnav-brand { display: inline-flex; align-items: center; text-decoration: none; min-width: 0; }
  .topnav-brand img { height: 42px; width: auto; max-width: 100%; display: block; }

  .topnav-links {
    display: flex; align-items: center; gap: 6px;
    flex: 1; flex-wrap: wrap;
  }
  .topnav-links a {
    text-decoration: none; color: #3d3a37;
    font-size: 0.94rem; font-weight: 500;
    padding: 7px 14px; border-radius: 8px;
    transition: background 0.15s, color 0.15s;
  }
  .topnav-links a:hover { background: #f5f0eb; color: #d97757; }
  .topnav-links a.is-active { color: #d97757; background: rgba(217,119,87,0.10); }
  .topnav-sep {
    display: inline-block;
    width: 14px; height: 1px;
    background: #c7bfb5;
    flex: 0 0 auto;
  }

  .topnav-prefs { position: relative; }
  .topnav-pref-btn {
    -webkit-appearance: none; appearance: none;
    background: transparent; border: 1px solid #e7dfd6;
    width: 38px; height: 38px; border-radius: 999px;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; color: #3d3a37;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
  }
  .topnav-pref-btn:hover { border-color: #d97757; color: #d97757; background: #fff; }
  .topnav-pref-btn svg { width: 18px; height: 18px; }

  .topnav-pref-panel {
    display: none; position: absolute; top: calc(100% + 8px); right: 0;
    min-width: 280px;
    background: #fff; border: 1px solid #e7dfd6; border-radius: 12px;
    box-shadow: 0 6px 20px rgba(20,20,19,0.10), 0 16px 40px rgba(20,20,19,0.12);
    padding: 14px 16px;
  }
  .topnav-pref-panel.is-open { display: block; }
  .topnav-pref-head {
    font-size: 0.78rem; color: #6b6560; text-transform: uppercase;
    letter-spacing: 0.06em; font-weight: 600; margin-bottom: 12px;
  }
  .pref-row { margin-bottom: 14px; }
  .pref-row:last-of-type { margin-bottom: 10px; }
  .pref-label {
    font-size: 0.86rem; color: #141413; font-weight: 500;
    display: flex; justify-content: space-between; align-items: baseline;
    margin-bottom: 4px;
  }
  .pref-val { font-size: 0.74rem; color: #6b6560; font-weight: 400; font-variant-numeric: tabular-nums; }
  .pref-slider {
    -webkit-appearance: none; appearance: none;
    width: 100%; height: 4px; background: #ede9e3; border-radius: 999px;
    outline: none; padding: 0;
  }
  .pref-slider::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 16px; height: 16px; background: #d97757; border-radius: 50%;
    cursor: pointer; border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(20,20,19,0.18);
  }
  .pref-slider::-moz-range-thumb {
    width: 16px; height: 16px; background: #d97757; border-radius: 50%;
    cursor: pointer; border: 2px solid #fff;
  }
  .pref-sample {
    margin-top: 6px; padding: 6px 10px;
    background: #f5f0eb; border-radius: 8px;
    color: #141413; line-height: 1.4;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .pref-foot {
    display: flex; gap: 8px; margin-top: 4px;
  }
  .pref-reset, .pref-save {
    -webkit-appearance: none; appearance: none;
    border-radius: 8px; padding: 8px 12px;
    font-size: 0.84rem; font-weight: 600; cursor: pointer;
    font-family: inherit; flex: 1;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
  }
  .pref-reset {
    background: transparent; border: 1px solid #e7dfd6; color: #6b6560;
    flex: 0 0 auto;
  }
  .pref-reset:hover { border-color: #d97757; color: #d97757; }
  .pref-save {
    background: #d97757; border: 1px solid #d97757; color: #fff;
  }
  .pref-save:hover { background: #c5664a; border-color: #c5664a; }

  .topnav-user { position: relative; }
  .topnav-user-btn {
    -webkit-appearance: none; appearance: none;
    background: transparent; border: 1px solid #e7dfd6;
    padding: 5px 12px 5px 5px; border-radius: 999px;
    display: inline-flex; align-items: center; gap: 8px;
    cursor: pointer; font-family: inherit; font-size: 0.92rem;
    color: #3d3a37;
    transition: border-color 0.15s, background 0.15s;
  }
  .topnav-user-btn:hover { border-color: #d97757; background: #fff; }
  .topnav-avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: linear-gradient(135deg, #d97757 0%, #e6a93b 100%);
    color: #fff; font-weight: 700; font-size: 0.92rem;
    display: inline-flex; align-items: center; justify-content: center;
    text-transform: uppercase;
  }
  .topnav-uname { font-weight: 500; }
  .topnav-chev { color: #6b6560; font-size: 0.7rem; line-height: 1; }

  .topnav-menu {
    display: none; position: absolute; top: calc(100% + 8px); right: 0;
    min-width: 220px;
    background: #fff; border: 1px solid #e7dfd6; border-radius: 12px;
    box-shadow: 0 6px 20px rgba(20,20,19,0.10), 0 16px 40px rgba(20,20,19,0.12);
    padding: 6px;
  }
  .topnav-menu.is-open { display: block; }
  .topnav-menu-head {
    padding: 10px 12px 8px; border-bottom: 1px solid #ede9e3; margin-bottom: 6px;
  }
  .topnav-menu-name { font-weight: 600; color: #141413; font-size: 0.95rem; }
  .topnav-menu-role { font-size: 0.78rem; color: #6b6560; margin-top: 1px; }
  .topnav-menu-item {
    display: block; padding: 9px 12px; border-radius: 8px;
    text-decoration: none; color: #3d3a37; font-size: 0.92rem;
    transition: background 0.15s, color 0.15s;
  }
  .topnav-menu-item:hover { background: #f5f0eb; color: #d97757; }
  .topnav-menu-item.is-active { color: #d97757; background: rgba(217,119,87,0.10); }
  .topnav-menu-item--danger { color: #a64a32; }
  .topnav-menu-item--danger:hover { background: rgba(217,119,87,0.08); }
  .topnav-menu-item { display: flex; align-items: center; gap: 10px; }   /* иконки; без :has() — Android 9 WebView */
  .topnav-menu-item .mi-ic { width: 24px; height: 24px; flex: none; margin: -3px 0; }

  /* Стрик-огонёк (P1.1): серый — сегодня ещё не занимался, оранжевый — день
     засчитан, красный пульс — вечер без активности («серия под угрозой»). */
  .topnav-streak {
    display: inline-flex; align-items: center; gap: 2px;
    font-weight: 800; font-size: 0.95rem; text-decoration: none;
    color: #b6b0a9; padding: 5px 10px; border-radius: 999px;
    transition: background 0.15s, color 0.15s;
  }
  .topnav-streak .ns-ic { width: 20px; height: 20px; filter: grayscale(1) opacity(.55); }
  .topnav-streak.on .ns-ic, .topnav-streak.warn .ns-ic { filter: none; }
  .topnav-streak.on { color: #d97757; background: rgba(217,119,87,0.10); }
  .topnav-streak.warn { color: #b53d3d; background: rgba(181,61,61,0.10);
    animation: streakPulse 1.6s ease-in-out infinite; }
  @keyframes streakPulse { 50% { transform: scale(1.12); } }

  /* Star button in the top bar — paired with the bottom-bar star but
     visible in regular browser mode too. Hidden by default; JS un-hides
     on book/podcast/video pages. */
  .topnav-star {
    -webkit-appearance: none; appearance: none;
    background: transparent; border: 1px solid #e7dfd6; border-radius: 999px;
    width: 38px; height: 38px;
    display: inline-flex; align-items: center; justify-content: center;
    color: #6b6560; cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s, transform 0.05s;
  }
  .topnav-star[hidden] { display: none; }
  .topnav-star:hover { color: #d97757; border-color: #d97757; background: rgba(217,119,87,0.06); }
  .topnav-star:active { transform: scale(0.92); }
  .topnav-star.is-active { color: #d97757; border-color: #d97757; }
  .topnav-star.is-active svg polygon { fill: currentColor; }
  .topnav-star svg { width: 18px; height: 18px; }

  /* Search magnifier — same round button as the prefs/star. */
  .topnav-search-btn {
    -webkit-appearance: none; appearance: none;
    background: transparent; border: 1px solid #e7dfd6; border-radius: 999px;
    width: 38px; height: 38px;
    display: inline-flex; align-items: center; justify-content: center;
    color: #6b6560; cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s, transform 0.05s;
  }
  .topnav-search-btn:hover { color: #d97757; border-color: #d97757; background: rgba(217,119,87,0.06); }
  .topnav-search-btn:active { transform: scale(0.92); }
  .topnav-search-btn svg { width: 18px; height: 18px; }
  /* Search dropdown — an absolute panel pinned flush to the header's bottom
     edge. .topnav is position:sticky → it's the containing block, so top:100%
     sits exactly under the bar at any header height. Closed = display:none, so
     nothing can peek at the top of the page (mobile) or leave a gap (desktop)
     the way the old position:fixed + transform + visibility hack did. */
  .topnav-search-bar {
    position: absolute; left: 0; right: 0; top: 100%; z-index: 50;
    background: #fffdfb; border-bottom: 1px solid #e7dfd6;
    box-shadow: 0 8px 18px rgba(20,20,19,0.10);
    padding: 12px;
    display: none;
  }
  .topnav-search-bar.open { display: block; animation: ts-drop 0.18s ease; }
  @keyframes ts-drop { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
  .topnav-search-bar form { display: flex; align-items: center; gap: 8px; max-width: 760px; margin: 0 auto; }
  .topnav-search-bar input { flex: 1; font: inherit; font-size: 1rem; padding: 11px 12px;
    border: 1.5px solid #e7dfd6; border-radius: 12px; background: #fff; color: #141413; }
  .topnav-search-bar input:focus { outline: none; border-color: #d97757; }
  .topnav-search-bar .ts-go { flex: 0 0 auto; width: 46px; height: 44px; border: none; border-radius: 12px;
    background: #d97757; color: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
    transition: transform 0.05s; }
  .topnav-search-bar .ts-go:active { transform: scale(0.94); }
  .topnav-search-bar .ts-go svg { width: 20px; height: 20px; }

  .topnav-burger { display: none; }


  @media (max-width: 720px) {
    .topnav-inner { gap: 7px; padding: 8px 10px; }
    .topnav-brand  { order: -1; margin-right: auto; }
    .topnav-brand img { height: 34px; }
    /* Order left→right: logo · star · font-size · search · hamburger · avatar. */
    .topnav-star   { order: 0; }
    .topnav-prefs  { order: 1; }
    .topnav-search-btn { order: 2; }
    .topnav-burger { order: 3; }
    .topnav-user   { order: 4; }
    .topnav-uname, .topnav-chev { display: none; }

    /* Make every right-hand control one tidy 36px circle so the cluster
       reads as a single even row instead of mixed pills/squares/circles. */
    .topnav-pref-btn, .topnav-search-btn, .topnav-star,
    .topnav-burger, .topnav-user-btn {
      width: 36px; height: 36px; min-width: 36px;
      border-radius: 999px; padding: 0; flex: 0 0 auto;
    }
    .topnav-pref-btn svg, .topnav-search-btn svg, .topnav-star svg { width: 17px; height: 17px; }
    .topnav-user-btn { gap: 0; justify-content: center; }
    .topnav-avatar { width: 28px; height: 28px; font-size: 0.86rem; }

    .topnav-links {
      display: none; position: absolute; top: 100%; left: 0; right: 0;
      flex-direction: column; align-items: stretch; gap: 0;
      background: #fff; border-bottom: 1px solid #e7dfd6;
      padding: 8px 12px;
    }
    .topnav-links.is-open { display: flex; }
    .topnav-links a { padding: 10px 12px; border-radius: 8px; }
    .topnav-sep { display: none; }
    .topnav-burger {
      display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
      gap: 4px; background: transparent; border: 1px solid #e7dfd6; cursor: pointer;
    }
    .topnav-burger span {
      display: block; width: 16px; height: 2px;
      background: #3d3a37; border-radius: 2px;
    }
    /* Both dropdowns: pin to viewport edges so nothing clips off-screen.
       absolute → fixed escapes the narrow .topnav-user / .topnav-prefs
       parent that would otherwise constrain width. */
    .topnav-menu, .topnav-pref-panel {
      position: fixed;
      top: 56px;
      left: 12px; right: 12px;
      min-width: 0; max-width: none; width: auto;
    }
  }
  @media (max-width: 360px) {
    .topnav-inner { gap: 5px; padding: 8px 8px; }
    .topnav-brand img { height: 30px; }
  }

  /* ===== Per-character pinyin ruby =====
     Each visible hanzi is wrapped as .rch > (.rpy syllable + .rhz char) by
     viewer.js. By default the syllable is hidden and the char renders inline,
     so nothing changes. The "Пиньинь над иероглифами" checkbox adds
     html.lt-pytop, which stacks the syllable above each char and hides the
     existing .pinyin line below. */
  .rch { display: inline; }
  .rpy { display: none; }
  html.lt-pytop .chinese .rch {
    display: inline-flex; flex-direction: column; align-items: center;
    vertical-align: bottom; line-height: 1.1; margin: 0 1px;
  }
  /* Строки с пиньинем сверху: слог уже даёт воздух над иероглифом — общий интерлиньяж
     2.8 страниц материала здесь лишний, строки разъезжались (владелец, 17.11.2026). */
  html.lt-pytop .chinese { line-height: 1.75; }
  html.lt-pytop .chinese .rpy {
    display: block; font-size: calc(var(--font-pinyin, 0.85rem) * 0.95);
    color: var(--accent, #d97757); font-style: italic; line-height: 1.15;
    white-space: nowrap;
  }
  /* keep the syllable readable over the active karaoke word (white-on-accent) */
  html.lt-pytop .char.kw-now .rpy { color: #fff; }
  html.lt-pytop .pinyin { display: none !important; }
  /* "Скрыть пиньинь" (кнопка hǎo) в режиме «сверху» должен прятать и верхние слоги. */
  html.lt-pytop.lt-nopy .chinese .rpy { display: none; }
  /* …и возвращать иероглифы в обычную строку: колонка .rch прижата к низу строки
     (vertical-align: bottom), а знаки препинания — простой текст на базовой линии,
     и при скрытом пиньине «：“ ？”» висели выше иероглифов (владелец, 17.11.2026). */
  html.lt-pytop.lt-nopy .chinese .rch { display: inline; margin: 0; vertical-align: baseline; }
  /* Английские материалы (body.lt-en-content ставят podcast/book/view при
     lang='en'): пиньиня нет, и «колонка» pytop только вредит — пустая строка
     слогов опускала слова вниз, а знаки препинания (отдельные токены) висели
     на исходной линии «в воздухе». Возвращаем обычную строку и нормальный
     интерлиньяж вместо китайского 2.8. */
  body.lt-en-content .chinese .rch { display: inline; margin: 0; vertical-align: baseline; }
  body.lt-en-content .chinese .rpy { display: none !important; }
  body.lt-en-content .chinese { line-height: 1.75; }
  .pref-toggle-row { padding-top: 2px; }
  .pref-toggle { display: flex; align-items: center; gap: 9px; cursor: pointer;
    font-size: 0.86rem; color: #141413; font-weight: 500; user-select: none; }
  .pref-toggle input { width: 16px; height: 16px; cursor: pointer;
    accent-color: var(--accent, #d97757); flex: none; }
  /* ===== Cross-page toast (e.g. "settings saved" after returning from profile) ===== */
  .lt-toast {
    position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%) translateY(12px);
    background: #2e7d3a; color: #fff; padding: 12px 22px; border-radius: 12px;
    font-size: 0.95rem; font-weight: 600; box-shadow: 0 6px 24px rgba(20,20,19,0.20);
    opacity: 0; transition: opacity .3s ease, transform .3s ease; z-index: 10000;
    pointer-events: none; max-width: 90vw; text-align: center;
  }
  .lt-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
  /* ===== "Завершить" button + rating modal (viewer pages) ===== */
  .lt-complete-bar { text-align: center; padding: 28px 0 10px; }
  .lt-finish-btn {
    background: var(--accent, #d97757); color: #fff; border: none; border-radius: 12px;
    padding: 13px 32px; font-size: 1rem; font-weight: 700; cursor: pointer; font-family: inherit;
    box-shadow: 0 2px 10px rgba(217,119,87,.30); transition: background .15s, transform .1s;
  }
  .lt-finish-btn:hover { background: var(--accent-h, #c5664a); }
  .lt-finish-btn:active { transform: translateY(1px); }
  .lt-finish-btn.is-done { background: #2e7d3a; box-shadow: none; }
  /* Secondary "Пройти тест" button, sits next to Завершить in the complete bar. */
  .lt-quiz-btn {
    display: inline-block; text-decoration: none; vertical-align: middle;
    background: var(--card, #fff); color: var(--accent, #d97757);
    border: 1.5px solid var(--accent, #d97757); border-radius: 12px;
    padding: 11px 26px; font-size: 1rem; font-weight: 700; cursor: pointer; font-family: inherit;
    margin-right: 10px; transition: background .15s, color .15s;
  }
  .lt-quiz-btn:hover { background: var(--accent, #d97757); color: #fff; }
  .lt-modal-overlay {
    position: fixed; top:0;right:0;bottom:0;left:0; background: rgba(20,20,19,.5); z-index: 10001;
    display: flex; align-items: center; justify-content: center; padding: 18px;
  }
  .lt-modal-overlay[hidden] { display: none; }
  .lt-modal {
    background: #fff; border-radius: 18px; padding: 26px 26px 22px; width: 100%; max-width: 460px;
    box-shadow: 0 12px 44px rgba(0,0,0,.26); animation: lt-modal-in .18s ease;
  }
  @keyframes lt-modal-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
  .lt-modal-title { font-size: 1.25rem; color: #141413; font-weight: 700; margin-bottom: 8px; }
  .lt-modal-sub { font-size: .9rem; color: #6b6560; line-height: 1.5; margin-bottom: 18px; }
  .lt-rate { margin-bottom: 16px; text-align: center; }
  .lt-rate-q { font-size: .95rem; color: #141413; font-weight: 600; margin-bottom: 6px; }
  .lt-stars { display: flex; gap: 4px; justify-content: center; }
  /* difficulty: 5-dot scale (Легко · · Нормально · · Трудно), like the speed control */
  .lt-scale { display: flex; justify-content: space-between; align-items: flex-start;
    position: relative; max-width: 280px; margin: 12px auto 2px; }
  .lt-scale::before { content: ''; position: absolute; left: 24px; right: 24px; top: 8px;
    height: 2px; background: #e7dfd6; }
  .lt-dot { background: none; border: none; padding: 0; cursor: pointer; font-family: inherit;
    display: flex; flex-direction: column; align-items: center; gap: 7px;
    position: relative; z-index: 1; min-width: 48px; }
  .lt-dot i { width: 16px; height: 16px; border-radius: 50%; background: #fff;
    border: 2px solid #d8cfc4; display: block; transition: transform .12s, background .12s, border-color .12s; }
  .lt-dot:hover i { border-color: var(--accent, #d97757); }
  .lt-dot.on i { background: var(--accent, #d97757); border-color: var(--accent, #d97757); transform: scale(1.2); }
  .lt-dot small { font-size: .74rem; color: #6b6560; line-height: 1; height: 1em; white-space: nowrap; }
  .lt-dot.on small { color: #141413; font-weight: 600; }
  .lt-star {
    background: none; border: none; font-size: 2rem; line-height: 1; color: #dcd5cc;
    cursor: pointer; padding: 2px 4px; font-family: inherit; transition: color .1s, transform .1s;
  }
  .lt-star:hover { transform: scale(1.14); }
  .lt-star.on { color: #f4b400; }
  .lt-modal-actions { display: flex; align-items: center; justify-content: flex-end; gap: 14px; margin-top: 22px; }
  .lt-modal-skip { background: none; border: none; color: #6b6560; font-size: .9rem; cursor: pointer; font-family: inherit; text-decoration: underline; }
  .lt-modal-submit {
    background: var(--accent, #d97757); color: #fff; border: none; border-radius: 10px;
    padding: 10px 24px; font-size: .95rem; font-weight: 700; cursor: pointer; font-family: inherit;
  }
  .lt-modal-submit:disabled { opacity: .45; cursor: not-allowed; }
