/* =========================================================
   Inline editor styles
   Loaded only on pages that include editor.js
   ========================================================= */

.is-editing-page #article {
  /* Make hover targets feel deliberate */
}

/* Hover affordance — ONLY in edit mode, so attaching the class in view mode
   can't flash a dashed outline on load. */
body.is-edit-mode .edit-hoverable {
  position: relative;
  cursor: text;
  outline: 1px dashed transparent;
  outline-offset: 4px;
  transition: background 0.18s ease;
}

body.is-edit-mode .edit-hoverable:hover {
  outline-color: rgba(217, 184, 120, 0.45);
  background: rgba(217, 184, 120, 0.04);
}

/* In view mode: hide all editor UI completely */
body:not(.is-edit-mode) .edit-toolbar,
body:not(.is-edit-mode) .edit-add,
body:not(.is-edit-mode) .edit-delete,
body:not(.is-edit-mode) .edit-insert-zone,
body:not(.is-edit-mode) .edit-controls {
  display: none !important;
}

/* "Редактор" entry button (bottom-left, default state) */
.edit-enter-btn {
  position: fixed;
  bottom: 1.5rem;
  left: 1.5rem;
  z-index: 55;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--rule, #2a251e);
  background: rgba(28, 24, 16, 0.85);
  backdrop-filter: blur(10px) saturate(1.1);
  -webkit-backdrop-filter: blur(10px) saturate(1.1);
  color: var(--ink-soft, #b6ad97);
  font-family: var(--sans, sans-serif);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.3s, color 0.3s, transform 0.2s var(--ease-soft, ease);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.edit-enter-btn:hover {
  background: rgba(40, 35, 23, 0.95);
  color: var(--ink, #ede4d0);
  transform: translateY(-1px);
}

.edit-enter-btn svg { opacity: 0.85; }

/* In edit mode: hide the entry button (we're already in) */
body.is-edit-mode .edit-enter-btn { display: none; }

/* In reader mode: hide editor entry too */
body.is-reading .edit-enter-btn { display: none !important; }

@media (max-width: 560px) {
  .edit-enter-btn {
    bottom: 1rem;
    left: 1rem;
    padding: 0.5rem 0.85rem;
    font-size: 0.68rem;
  }
}

/* Active editing target */
.edit-active {
  outline: 1px solid var(--accent, #d9b878) !important;
  outline-offset: 4px;
  background: rgba(217, 184, 120, 0.06);
  border-radius: 1px;
}

/* Block-level container — shows × on hover for deletion */
.edit-block-host {
  position: relative;
}

.edit-block-host > .edit-delete {
  position: absolute;
  top: 0;
  right: -32px;
  -webkit-user-select: none;
  user-select: none;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: rgba(37, 32, 26, 0.95);
  border: 1px solid var(--rule, #2a251e);
  color: var(--ink-soft, #b6ad97);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1;
  padding: 0;
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: color 0.2s, transform 0.15s, background 0.2s, opacity 0.15s;
}

/* In edit mode the × is ALWAYS visible (subtle) so it's reachable without a
   hover-race — moving the cursor toward it never makes it vanish. */
body.is-edit-mode .edit-block-host > .edit-delete {
  opacity: 0.34;
  pointer-events: auto;
}
/* Brighten fully on hover of the block or the × itself, or while editing it. */
.edit-block-host:hover > .edit-delete,
.edit-block-host > .edit-delete:hover,
.edit-block-host:has(.edit-active) > .edit-delete,
.edit-block-host.edit-active > .edit-delete {
  opacity: 1;
  pointer-events: auto;
}

/* Narrower screens: put × inside top-right corner */
@media (max-width: 900px) {
  .edit-block-host > .edit-delete { right: 4px; top: 4px; }
}

.edit-delete:hover {
  color: #ff8e7a;
  transform: scale(1.12);
  background: rgba(60, 35, 30, 1);
  border-color: rgba(255, 140, 120, 0.5);
}

/* When × is hovered, frame the parent block so user sees what will be deleted */
.edit-block-host:has(.edit-delete:hover) {
  outline: 1px dashed rgba(255, 140, 120, 0.65);
  outline-offset: 4px;
  background: rgba(255, 140, 120, 0.04);
}

/* =========================================================
   Editing mode: flatten everything that shifts the browser's
   hit-testing of click coordinates. Without this the cursor
   lands one character early on contenteditable elements.

   Culprits we've seen:
   - ::first-letter + float:left (drop cap)
   - hanging-punctuation
   - font-feature-settings (kerning, ligatures, old-style nums)
   - text-rendering: optimizeLegibility
   - decorative ::before content
   ========================================================= */

/* Modal-mode editor — no contenteditable overrides needed.
   Editing happens in a textarea inside a modal. The rendered text
   stays visually identical to read mode (drop cap, hanging punctuation,
   etc. all preserved). */

/* =========================================================
   Insert zones — appear BETWEEN blocks. Click + to insert a
   new block exactly at that position.
   ========================================================= */

.edit-insert-zone {
  position: relative;
  height: 22px;
  margin: 0 auto;
  max-width: 42rem;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
  cursor: pointer;
  z-index: 5;
}

.edit-insert-zone:hover,
.edit-insert-zone:focus-within {
  opacity: 1;
}

.edit-insert-zone::before {
  content: "";
  position: absolute;
  left: 1.5rem;
  right: 1.5rem;
  top: 50%;
  height: 1px;
  background: var(--accent, #d9b878);
  opacity: 0.35;
  pointer-events: none;
}

.edit-insert-btn {
  position: relative;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: var(--bg, #0e0b07);
  border: 1px solid var(--accent, #d9b878);
  color: var(--accent, #d9b878);
  font-family: var(--sans, sans-serif);
  font-size: 16px;
  line-height: 1;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, transform 0.15s;
  z-index: 1;
}

.edit-insert-btn:hover {
  background: var(--accent, #d9b878);
  color: var(--bg, #0e0b07);
  transform: scale(1.1);
}

/* =========================================================
   Top-right editor toolbar
   ========================================================= */

.edit-toolbar {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.55rem;
  border-radius: 999px;
  background: rgba(28, 24, 16, 0.92);
  backdrop-filter: blur(12px) saturate(1.1);
  -webkit-backdrop-filter: blur(12px) saturate(1.1);
  border: 1px solid var(--rule, #2a251e);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  font-family: var(--sans, sans-serif);
}

.edit-toolbar__status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.2rem 0.7rem 0.2rem 0.5rem;
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted, #7a7160);
}

.edit-toolbar__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6e6651;
  transition: background 0.3s;
}

.edit-toolbar.is-dirty .edit-toolbar__dot { background: #d9b878; box-shadow: 0 0 8px rgba(217, 184, 120, 0.6); }
.edit-toolbar.is-saving .edit-toolbar__dot { background: #6fb4ff; animation: edit-pulse 1.2s ease-in-out infinite; }
.edit-toolbar.is-saved .edit-toolbar__dot { background: #5ec27d; }
.edit-toolbar.is-error .edit-toolbar__dot { background: #ff8e7a; }

@keyframes edit-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.edit-toolbar.is-dirty .edit-toolbar__status::after { content: " · не сохранено"; }
.edit-toolbar.is-saving .edit-toolbar__status::after { content: " · сохраняю…"; }
.edit-toolbar.is-saved .edit-toolbar__status::after { content: " · сохранено"; }
.edit-toolbar.is-error .edit-toolbar__status::after { content: " · ошибка"; }

.edit-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--ink-soft, #b6ad97);
  font-family: var(--sans, sans-serif);
  font-size: 0.74rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.edit-btn:hover {
  background: rgba(217, 184, 120, 0.1);
  color: var(--ink, #ede4d0);
}

.edit-btn--primary {
  background: var(--accent, #d9b878);
  color: var(--bg, #0e0b07);
}
.edit-btn--primary:hover { background: #ecc488; color: var(--bg, #0e0b07); }
.edit-btn--primary:disabled { opacity: 0.4; cursor: not-allowed; }

.edit-btn--danger { color: rgba(255, 140, 120, 0.85); }
.edit-btn--danger:hover { background: rgba(255, 100, 80, 0.12); color: #ff8e7a; }

/* =========================================================
   Sticky save / cancel controls (right side while editing)
   ========================================================= */

.edit-controls {
  position: fixed;
  right: 1.25rem;
  z-index: 65;
  display: none;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.edit-controls.is-open {
  display: flex;
  pointer-events: auto;
}

.edit-control-btn {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--rule, #2a251e);
  background: rgba(28, 24, 16, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--ink-soft, #b6ad97);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0;
  transition: transform 0.18s var(--ease-soft, ease), background 0.2s, color 0.2s, border-color 0.2s;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}

.edit-control-btn:hover {
  transform: scale(1.08);
}

.edit-control-btn--ok {
  background: rgba(94, 194, 125, 0.18);
  border-color: rgba(94, 194, 125, 0.5);
  color: #6fd58f;
}
.edit-control-btn--ok:hover { background: rgba(94, 194, 125, 0.3); color: #8fe2a8; }

.edit-control-btn--cancel:hover {
  background: rgba(255, 140, 120, 0.15);
  border-color: rgba(255, 140, 120, 0.4);
  color: #ff8e7a;
}

/* =========================================================
   Add block — floating "+" + dropdown menu (bottom-left)
   ========================================================= */

.edit-add {
  position: fixed;
  bottom: 1.5rem;
  left: 1.5rem;
  z-index: 60;
  font-family: var(--sans, sans-serif);
}

.edit-add__btn {
  width: 52px;
  height: 52px;
  border-radius: 999px;
  border: 1px solid var(--rule, #2a251e);
  background: rgba(28, 24, 16, 0.92);
  backdrop-filter: blur(10px) saturate(1.1);
  -webkit-backdrop-filter: blur(10px) saturate(1.1);
  color: var(--accent, #d9b878);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.3s, color 0.3s, transform 0.2s var(--ease-soft, ease);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

.edit-add__btn:hover {
  background: rgba(217, 184, 120, 0.15);
  transform: translateY(-2px);
}

.edit-add__menu {
  position: absolute;
  bottom: calc(100% + 0.6rem);
  left: 0;
  min-width: 240px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--surface, #1c1810);
  border: 1px solid var(--rule, #2a251e);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  padding: 0.35rem 0;
  opacity: 0;
  transform: translateY(8px) scale(0.97);
  transform-origin: bottom left;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s var(--ease-soft, ease);
}

.edit-add__menu.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.edit-add__group {
  padding: 0.5rem 1.1rem 0.25rem;
  font-size: 0.66rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--muted, #7a7160);
}

.edit-add__item {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  width: 100%;
  padding: 0.65rem 1.1rem;
  background: none;
  border: none;
  text-align: left;
  font-family: var(--sans, sans-serif);
  font-size: 0.92rem;
  color: var(--ink-soft, #b6ad97);
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
}

.edit-add__item:hover {
  background: rgba(217, 184, 120, 0.08);
  color: var(--ink, #ede4d0);
}

.edit-add__item kbd {
  margin-left: auto;
  font-family: var(--sans, sans-serif);
  font-size: 0.7rem;
  color: var(--muted, #7a7160);
  padding: 0.1rem 0.4rem;
  border: 1px solid var(--rule, #2a251e);
  border-radius: 4px;
}

/* =========================================================
   Auth modal (small)
   ========================================================= */

.edit-modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 7, 5, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  font-family: var(--sans, sans-serif);
}

.edit-modal.is-open { display: flex; }

.edit-modal__card {
  width: 100%;
  max-width: 26rem;
  background: var(--surface, #1c1810);
  border: 1px solid var(--rule, #2a251e);
  border-radius: 14px;
  padding: 2rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.edit-modal__title {
  font-family: var(--sans, sans-serif);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink, #ede4d0);
  margin: 0 0 0.5rem;
}

.edit-modal__hint {
  font-size: 0.85rem;
  color: var(--muted, #7a7160);
  margin: 0 0 1.5rem;
  line-height: 1.5;
}

.edit-modal__input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  margin-bottom: 1rem;
  background: var(--bg, #0e0b07);
  border: 1px solid var(--rule, #2a251e);
  border-radius: 8px;
  color: var(--ink, #ede4d0);
  font-family: var(--sans, sans-serif);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.edit-modal__input:focus {
  border-color: var(--accent, #d9b878);
}

.edit-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Text-editing modal — larger card, big textarea */
.edit-modal--text .edit-modal__card {
  max-width: 48rem;
  width: 100%;
  padding: 2rem 2rem 1.5rem;
}

.edit-modal__textarea {
  width: 100%;
  min-height: 12rem;
  padding: 1rem 1.1rem;
  margin: 0.5rem 0 0.8rem;
  background: var(--bg, #0e0b07);
  border: 1px solid var(--rule, #2a251e);
  border-radius: 8px;
  color: var(--ink, #ede4d0);
  /* Use system font for editing — easier to spot what you're typing.
     The rendered serif look returns automatically when modal closes. */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.55;
  outline: none;
  resize: vertical;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.edit-modal__textarea:focus {
  border-color: var(--accent, #d9b878);
}

@media (max-width: 720px) {
  .edit-modal--text .edit-modal__card {
    max-width: calc(100vw - 2rem);
    padding: 1.5rem 1.2rem 1.2rem;
  }
  .edit-modal__textarea { min-height: 9rem; font-size: 0.95rem; }
}

/* =========================================================
   READER MODE — focus reading with optional auto-scroll
   ========================================================= */

.read-btn {
  position: fixed;
  bottom: 4.5rem;
  right: 1.5rem;
  z-index: 55;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--rule, #2a251e);
  background: rgba(28, 24, 16, 0.85);
  backdrop-filter: blur(10px) saturate(1.1);
  -webkit-backdrop-filter: blur(10px) saturate(1.1);
  color: var(--ink-soft, #b6ad97);
  font-family: var(--sans, sans-serif);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.3s, color 0.3s, transform 0.2s var(--ease-soft, ease);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.read-btn:hover {
  background: rgba(40, 35, 23, 0.95);
  color: var(--ink, #ede4d0);
  transform: translateY(-1px);
}

.read-btn svg { opacity: 0.85; }

@media (max-width: 560px) {
  .read-btn {
    bottom: 4rem;
    right: 1rem;
    padding: 0.5rem 0.85rem;
    font-size: 0.68rem;
  }
}

/* ---- Reader mode: hide everything except the text ---- */
body.is-reading .site-header,
body.is-reading .site-footer,
body.is-reading .share,
body.is-reading .edit-toolbar,
body.is-reading .edit-add,
body.is-reading .edit-delete,
body.is-reading .edit-insert-zone,
body.is-reading .hero-story__overlay,
body.is-reading .progress,
body.is-reading .read-btn,
body.is-reading .story-footer,
body.is-reading .latest {
  display: none !important;
}

/* Reader mode hides the cinematic hero entirely — the focus is the text,
   which emerges out of the top vignette instead of a half-faded giant title. */
body.is-reading .hero-story { display: none !important; }
body.is-reading #article { padding-top: calc(16vh + env(safe-area-inset-top, 0px)); }

/* No more hover affordances on text */
body.is-reading .edit-hoverable {
  outline: none !important;
  background: transparent !important;
  cursor: default !important;
}

/* Slight emphasis on the text itself in reader mode */
body.is-reading .prose {
  max-width: 38rem;
}

body.is-reading {
  cursor: default;
}

/* Top fade in BOTH reading and listening modes (this is the key bit — the audio player
   previously had no top vignette, so text showed at the very top). The notch / Dynamic
   Island strip itself is handled by the dark theme-color + no viewport-fit (content never
   sits behind it), so these gradients only need to fade the top of the viewport.
   No transform/will-change here — a transform on a fixed element re-anchors it on iOS. */
body.is-reading::before,
body.is-reading::after,
body.is-tts-open::before {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  z-index: 70;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

/* Reading: focus is at viewport centre → the top band can be tall. */
body.is-reading::before {
  top: 0;
  height: calc(13vh + env(safe-area-inset-top, 0px));   /* top dim halved (was 26vh) */
  background: linear-gradient(180deg,
    var(--bg, #0e0b07) 0%,
    var(--bg, #0e0b07) 60%,
    transparent 100%);
}

/* Listening (TTS): the spoken line rests at ~20vh, so the band must be transparent by then. */
body.is-tts-open::before {
  top: 0;
  height: calc(19vh + env(safe-area-inset-top, 0px));
  background: linear-gradient(180deg,
    var(--bg, #0e0b07) 0%,
    var(--bg, #0e0b07) 58%,
    transparent 100%);
}

body.is-reading::after {
  bottom: 0;
  height: calc(28vh + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(0deg,
    var(--bg, #0e0b07) 0%,
    var(--bg, #0e0b07) 30%,
    rgba(14, 11, 7, 0.7) 65%,
    transparent 100%);
}

/* Dim all article text by default in reader mode; current focus is bright */
body.is-reading #article p,
body.is-reading #article h2,
body.is-reading #article h3,
body.is-reading #article h4,
body.is-reading #article blockquote,
body.is-reading #article figure {
  transition: opacity 0.5s ease, filter 0.5s ease;
  opacity: 0.3;
}

body.is-reading #article .read-focus,
body.is-reading #article .read-focus p,
body.is-reading #article .read-focus h2,
body.is-reading #article .read-focus h3 {
  opacity: 1;
}

/* Only the TEXT eases in. The vignette stays fully opaque from the start —
   animating a fixed pseudo-element's opacity left it transparent on iOS Safari,
   so the dimmed text peeked through at the top (the "light strip"). */
@keyframes readerFrameIn { from { opacity: 0; } to { opacity: 1; } }
body.is-reading #article { animation: readerFrameIn 0.55s ease both; }
@media (prefers-reduced-motion: reduce) {
  body.is-reading #article { animation: none !important; }
}

/* Player music on/off toggle — struck through when muted */
.tts-music.is-off { opacity: 0.4; position: relative; }
.tts-music.is-off::after {
  content: ""; position: absolute; left: 20%; right: 20%; top: 50%; height: 2px;
  background: currentColor; transform: rotate(-45deg); border-radius: 2px;
}

/* ---- Floating reading controls (bottom center) ---- */
.read-controls {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(140%);
  z-index: 80;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.5rem;
  background: rgba(20, 16, 10, 0.96);
  backdrop-filter: blur(12px) saturate(1.1);
  -webkit-backdrop-filter: blur(12px) saturate(1.1);
  border: 1px solid var(--rule, #2a251e);
  border-radius: 999px;
  font-family: var(--sans, sans-serif);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s var(--ease-soft, ease);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55);
}

body.is-reading .read-controls {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.read-ctrl {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--ink-soft, #b6ad97);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.2s, color 0.2s, transform 0.15s;
}

.read-ctrl:hover {
  background: rgba(217, 184, 120, 0.12);
  color: var(--accent, #d9b878);
  transform: scale(1.06);
}

.read-ctrl--play {
  background: var(--accent, #d9b878);
  color: var(--bg, #0e0b07);
}

.read-ctrl--play:hover {
  background: #ecc488;
  color: var(--bg, #0e0b07);
}

.read-ctrl--exit:hover {
  color: #ff8e7a;
  background: rgba(255, 140, 120, 0.12);
}

.read-speed {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 999px;
}

.read-speed__btn {
  padding: 0.42rem 0.85rem;
  border: none;
  background: transparent;
  color: var(--muted, #7a7160);
  font-family: var(--sans, sans-serif);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  border-radius: 999px;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}

.read-speed__btn:hover {
  color: var(--ink-soft, #b6ad97);
}

.read-speed__btn.is-active {
  background: rgba(217, 184, 120, 0.18);
  color: var(--accent, #d9b878);
}

@media (max-width: 560px) {
  .read-controls {
    bottom: 1rem;
    gap: 0.25rem;
    padding: 0.25rem 0.35rem;
    max-width: calc(100vw - 1rem);
  }
  .read-ctrl { width: 44px; height: 44px; }
  .read-speed__btn { padding: 0.32rem 0.55rem; font-size: 0.64rem; }
}

/* =========================================================
   TTS — «Слушать» button + audio player + word highlight
   ========================================================= */

.tts-btn {
  position: fixed;
  bottom: 7.5rem; /* stacked above "Читать" which is at 4.5rem */
  right: 1.5rem;
  z-index: 55;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--rule, #2a251e);
  background: rgba(28, 24, 16, 0.85);
  backdrop-filter: blur(10px) saturate(1.1);
  -webkit-backdrop-filter: blur(10px) saturate(1.1);
  color: var(--ink-soft, #b6ad97);
  font-family: var(--sans, sans-serif);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.3s, color 0.3s, transform 0.2s var(--ease-soft, ease);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.tts-btn:hover {
  background: rgba(40, 35, 23, 0.95);
  color: var(--ink, #ede4d0);
  transform: translateY(-1px);
}

.tts-btn svg { opacity: 0.85; }

body.is-tts-open .tts-btn { display: none; }
body.is-reading .tts-btn { display: none !important; }

@media (max-width: 560px) {
  .tts-btn { bottom: 7rem; right: 1rem; padding: 0.5rem 0.85rem; font-size: 0.68rem; }
}

/* ---- Player bar (bottom-center, visible when open) ---- */
.tts-player {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(140%);
  z-index: 80;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem 0.35rem 0.4rem;
  background: rgba(20, 16, 10, 0.96);
  backdrop-filter: blur(12px) saturate(1.1);
  -webkit-backdrop-filter: blur(12px) saturate(1.1);
  border: 1px solid var(--rule, #2a251e);
  border-radius: 999px;
  font-family: var(--sans, sans-serif);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s var(--ease-soft, ease);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55);
  min-width: 380px;
  max-width: calc(100vw - 2rem);
}

body.is-tts-open .tts-player {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.tts-ctrl {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--ink-soft, #b6ad97);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.2s, color 0.2s, transform 0.15s;
}

.tts-ctrl:hover {
  background: rgba(217, 184, 120, 0.12);
  color: var(--accent, #d9b878);
  transform: scale(1.06);
}

.tts-ctrl--play {
  background: var(--accent, #d9b878);
  color: var(--bg, #0e0b07);
}

.tts-ctrl--play:hover {
  background: #ecc488;
  color: var(--bg, #0e0b07);
}

.tts-player.is-loading .tts-ctrl--play {
  background: rgba(217, 184, 120, 0.4);
  cursor: progress;
}

.tts-icon-loading {
  animation: tts-spin 0.9s linear infinite;
}

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

.tts-ctrl--exit:hover {
  color: #ff8e7a;
  background: rgba(255, 140, 120, 0.12);
}

.tts-progress {
  flex: 1;
  min-width: 80px;
  height: 4px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 999px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.tts-progress__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: var(--accent, #d9b878);
  border-radius: 999px;
  transition: width 0.1s linear;
}

.tts-time {
  flex: 1;
  text-align: center;
  font-family: var(--sans, sans-serif);
  font-size: 0.8rem;
  color: var(--ink-soft, #b6ad97);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  margin: 0 0.4rem;
}

.tts-speed {
  padding: 0.4rem 0.65rem;
  border: none;
  background: rgba(0, 0, 0, 0.4);
  color: var(--ink-soft, #b6ad97);
  font-family: var(--sans, sans-serif);
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  border-radius: 999px;
  transition: background 0.2s, color 0.2s;
  font-variant-numeric: tabular-nums;
}

.tts-speed:hover {
  background: rgba(217, 184, 120, 0.18);
  color: var(--accent, #d9b878);
}

@media (max-width: 560px) {
  .tts-player {
    bottom: 1rem;
    gap: 0.3rem;
    padding: 0.3rem 0.4rem;
    min-width: 0;
    width: calc(100vw - 1.5rem);
  }
  .tts-ctrl { width: 44px; height: 44px; }
  .tts-time { font-size: 0.7rem; }
  .tts-speed { padding: 0.3rem 0.5rem; font-size: 0.68rem; }
}

/* ---- Line-level reading highlight — atmospheric & very smooth ---- */
.tts-word {
  transition: color 0.85s var(--ease-soft, cubic-bezier(0.4, 0, 0.2, 1)),
              text-shadow 0.85s ease;
}

body.is-tts-open .tts-word { cursor: pointer; }

/* While reading, the whole text sinks quietly into shadow... */
#article.tts-reading .tts-word {
  color: rgba(237, 228, 208, 0.24);   /* --ink @ 24% */
}

/* ...the lines just above & below glow faintly (a soft pool of light)... */
#article.tts-reading .tts-word.is-near {
  color: rgba(237, 228, 208, 0.5);    /* --ink @ 50% */
}

/* ...and the line being read is fully lit, with a quiet warm aura. */
#article.tts-reading .tts-word.is-current {
  color: rgba(237, 228, 208, 1);      /* --ink */
  text-shadow: 0 0 22px rgba(217, 184, 120, 0.18);
}

/* Hide other floating UI while TTS player is open */
body.is-tts-open .read-btn,
body.is-tts-open .edit-enter-btn,
body.is-tts-open .share {
  display: none !important;
}

/* ---- Toast for TTS errors ---- */
.tts-toast {
  position: fixed;
  bottom: 6rem;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  z-index: 90;
  padding: 0.7rem 1.2rem;
  border-radius: 999px;
  background: rgba(40, 25, 20, 0.95);
  border: 1px solid rgba(255, 140, 120, 0.5);
  color: #ff8e7a;
  font-family: var(--sans, sans-serif);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s var(--ease-soft, ease);
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-width: calc(100vw - 2rem);
  text-align: center;
}

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

/* =========================================================
   Toast (small bottom-center notice)
   ========================================================= */

.edit-toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  z-index: 75;
  padding: 0.7rem 1.2rem;
  border-radius: 999px;
  background: rgba(28, 24, 16, 0.95);
  border: 1px solid var(--rule, #2a251e);
  color: var(--ink, #ede4d0);
  font-family: var(--sans, sans-serif);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s var(--ease-soft, ease);
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

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

.edit-toast--err { border-color: rgba(255, 140, 120, 0.5); color: #ff8e7a; }
.edit-toast--ok  { border-color: rgba(94, 194, 125, 0.5); color: #6fd58f; }

/* Push share button left a tiny bit when toolbar visible (so they don't overlap stacked) */
.is-editing-page .share { bottom: 1.5rem; right: 1.5rem; }

/* Hide editor on print */
@media print {
  .edit-toolbar, .edit-panel, .edit-controls, .edit-add, .edit-modal, .edit-toast, .edit-delete { display: none !important; }
  .edit-active, .edit-hoverable { outline: none !important; background: none !important; }
}

/* =========================================================
   Editor panel (right sidebar) — v19
   ========================================================= */
.edit-panel {
  position: fixed; top: 0; right: 0; z-index: 80;
  width: min(340px, 92vw); height: 100vh; height: 100svh;
  display: none; flex-direction: column;
  background: #14110b; border-left: 1px solid var(--rule, #2a251e);
  box-shadow: -14px 0 44px rgba(0, 0, 0, 0.45);
  font-family: var(--sans, sans-serif);
}
body.is-edit-mode .edit-panel { display: flex; }
body.is-edit-mode { padding-right: min(340px, 92vw); }
/* keep floating buttons from colliding with the panel */
body.is-edit-mode .share,
body.is-edit-mode .read-btn,
body.is-edit-mode .tts-btn { display: none !important; }

.edit-panel__head {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.85rem 1rem; border-bottom: 1px solid var(--rule);
}
.edit-panel__title { font-weight: 600; font-size: 0.92rem; color: var(--ink); display: flex; align-items: center; gap: 0.5rem; white-space: nowrap; }
.edit-panel__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); transition: background 0.2s; }
.edit-panel.is-dirty .edit-panel__dot { background: #e0a23a; }
.edit-panel.is-saving .edit-panel__dot { background: #d9b878; }
.edit-panel.is-saved .edit-panel__dot { background: #6fd58f; }
.edit-panel.is-error .edit-panel__dot { background: #ff8e7a; }
.edit-panel__state { flex: 1; font-size: 0.7rem; color: var(--muted); }
.edit-panel__scroll { flex: 1; overflow-y: auto; padding: 0 1rem 3rem; }

.edit-sec { padding: 1rem 0; border-bottom: 1px solid var(--rule); }
.edit-sec__h { font-size: 0.72rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); margin: 0 0 0.7rem; font-weight: 600; }
.edit-sec__hint { font-size: 0.7rem; color: var(--muted); margin: -0.3rem 0 0.7rem; line-height: 1.4; }

.edit-btn--wide { display: block; width: 100%; text-align: left; margin-bottom: 0.4rem; }
.edit-btn--icon { padding: 0.35rem 0.55rem; line-height: 1; }
.edit-btn--on { color: var(--accent); border-color: var(--accent); }

.edit-pick { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.edit-pick__group { width: 100%; font-size: 0.66rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0.55rem 0 0.05rem; }
.edit-pick__item { font-family: var(--sans); font-size: 0.8rem; color: var(--ink-soft); background: rgba(255, 255, 255, 0.04); border: 1px solid var(--rule); border-radius: 8px; padding: 0.4rem 0.7rem; cursor: pointer; transition: all 0.18s; }
.edit-pick__item:hover { border-color: var(--accent); color: var(--ink); }

.edit-blocks { display: flex; flex-direction: column; gap: 0.25rem; }
.edit-blocks__empty { font-size: 0.8rem; color: var(--muted); line-height: 1.5; }
.edit-row { display: flex; align-items: center; gap: 0.35rem; padding: 0.35rem 0.45rem; border: 1px solid transparent; border-radius: 8px; background: rgba(255, 255, 255, 0.02); }
.edit-row:hover { background: rgba(255, 255, 255, 0.05); }
.edit-row.is-sel { border-color: var(--accent); background: rgba(217, 184, 120, 0.08); }
.edit-row.is-hidden { opacity: 0.55; }
.edit-row__label { flex: 1; min-width: 0; font-size: 0.8rem; color: var(--ink-soft); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.edit-row:hover .edit-row__label { color: var(--ink); }
.edit-row__ctrls { display: flex; gap: 0.1rem; flex: none; }
.edit-row__btn { font-family: var(--sans); font-size: 0.9rem; line-height: 1; color: var(--muted); background: none; border: none; cursor: pointer; padding: 0.2rem 0.32rem; border-radius: 5px; }
.edit-row__btn:hover { background: rgba(255, 255, 255, 0.1); color: var(--ink); }
.edit-row__btn:disabled { opacity: 0.25; cursor: default; }
.edit-row__btn--del:hover { color: #ff8e7a; background: rgba(255, 140, 120, 0.12); }

/* hidden blocks: invisible to visitors; dimmed + outlined while editing */
.block-hidden { display: none; }
body.is-edit-mode .block-hidden { display: block; opacity: 0.4; outline: 1px dashed var(--muted); outline-offset: 6px; }

.edit-flash { animation: editFlash 1.2s ease; border-radius: 4px; }
@keyframes editFlash { 0%, 100% { background: transparent; } 30% { background: rgba(217, 184, 120, 0.14); } }

/* mobile: panel becomes a bottom drawer */
@media (max-width: 720px) {
  .edit-panel { width: 100vw; height: 62vh; top: auto; bottom: 0; border-left: none; border-top: 1px solid var(--rule); box-shadow: 0 -14px 44px rgba(0, 0, 0, 0.5); }
  body.is-edit-mode { padding-right: 0; padding-bottom: 62vh; }
}

/* viewport-fit=cover (story pages): keep normal-mode content clear of the status
   bar. The reading bands above already extend into the safe areas via env(), so
   they reach the physical screen edges (under the Dynamic Island / home indicator). */
body.story { padding-top: 0; }
