/* ========================================================================
   FANFIC CHAPTER PAGE — mobile-first, tiny screens ready (280px+)
   - safe-area padding
   - no overflow on long titles/urls
   - buttons stack on narrow
   - pager becomes vertical on tiny
   - jump dots become grid
   - Firefox-safe fallbacks for color-mix backgrounds
   ======================================================================== */

/* ===================== Global safety ===================== */
html{
  -webkit-text-size-adjust:100%;
  text-size-adjust:100%;
}

:root{
  /* Layout tokens (local, safe) */
  --ch-max: 960px;

  --ch-pad-x: clamp(10px, 3.4vw, 18px);
  --ch-pad-y: clamp(10px, 2.8vw, 16px);

  --ch-card-r: clamp(12px, 2.2vw, 16px);
  --ch-card-pad-x: clamp(12px, 3.6vw, 20px);
  --ch-card-pad-y: clamp(12px, 3.2vw, 18px);

  --ch-gap: clamp(10px, 2.6vw, 14px);

  --ch-shadow: 0 10px 28px rgba(0,0,0,.06);

  /* Reader typography */
  --ch-font: clamp(1rem, .96rem + .25vw, 1.06rem);
  --ch-lh: 1.75;

  /* Controls */
  --ch-btn-minh: 40px;
}

/* ensure long strings never break layout */
main, .chapter-card, .chapter-hero, .chapter-text, .review-card, .review-body{
  overflow-wrap:anywhere;
  word-break:break-word;
}

/* Better hyphens (works mostly on Safari/Firefox with lang=ru) */
@supports (hyphens:auto){
  .chapter-text, .review-body{
    hyphens:auto;
  }
}

/* ===================== Layout ===================== */
main{
  max-width: var(--ch-max);
  margin: 0 auto;

  /* safe-area friendly */
  padding:
    var(--ch-pad-y)
    calc(var(--ch-pad-x) + env(safe-area-inset-right, 0px))
    calc(var(--ch-pad-y) + env(safe-area-inset-bottom, 0px))
    calc(var(--ch-pad-x) + env(safe-area-inset-left, 0px));
}

/* ===================== Breadcrumbs ===================== */
.breadcrumbs{
  margin: 10px 0;
  font-size: .95rem;
  line-height: 1.3;
}
.breadcrumbs a{
  text-decoration:none;
  color:var(--link);
  text-underline-offset:2px;
}
.breadcrumbs a:hover{
  text-decoration:underline;
}

/* ===================== Chapter card ===================== */
.chapter-card{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--ch-card-r);
  padding: var(--ch-card-pad-y) var(--ch-card-pad-x);
  margin: 12px 0;
  box-shadow: var(--ch-shadow);
}

/* ===================== Header ===================== */
.chapter-hero{
  text-align:center;

  /* Firefox страховка: если color-mix/фон сломается — не проваливаемся в body */
  background-color: var(--surface-2);
  background: var(--surface-2);

  border: 1px solid var(--border);
  color: var(--text);
  border-radius: clamp(10px, 2vw, 12px);
  padding: clamp(12px, 2.8vw, 14px) clamp(12px, 3vw, 16px);
  margin-bottom: 12px;
}

.chapter-hero-title{
  margin: 0;
  line-height: 1.22;
  font-weight: 800;
  letter-spacing: .2px;

  /* long titles */
  overflow-wrap:anywhere;
}

/* subtitle row */
.chapter-hero-sub{
  display:flex;
  gap: 10px;
  align-items:center;
  justify-content:center;
  flex-wrap:wrap;

  margin-top: 8px;
  font-size: .95rem;
  color: var(--muted);
}

/* Make meta items feel tappable but not huge */
.chapter-hero-sub > *{
  max-width: 100%;
}

/* Secondary buttons (общие) */
.button.button-secondary{
  background:var(--btn-bg);
  color:var(--btn-fg);
  border:1px solid var(--btn-brd);
}
.button.button-secondary:hover{ filter:brightness(1.02); }

/* ===================== Chapter text ===================== */
.chapter-text{
  /* Firefox-safe fallback */
  background-color: var(--surface);
  background: var(--surface);

  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: clamp(12px, 3.2vw, 16px);
  margin-top: 12px;

  line-height: var(--ch-lh);
  font-size: var(--ch-font);

  overflow-wrap:anywhere;
  word-break:break-word;
}

/* Quill align */
.chapter-text .ql-align-center{ text-align:center; }
.chapter-text .ql-align-right{ text-align:right; }
.chapter-text .ql-align-justify{ text-align:justify; }

.chapter-text img{
  max-width:100%;
  height:auto;
  display:block;
}

/* Typography */
.chapter-text p{ margin:.6em 0; }
.chapter-text h1,.chapter-text h2,.chapter-text h3{
  line-height:1.25;
  margin:.9em 0 .5em;
}
.chapter-text h1{ font-size:clamp(1.35rem, 1.15rem + 1vw, 1.65rem); }
.chapter-text h2{ font-size:clamp(1.18rem, 1.05rem + .7vw, 1.35rem); }
.chapter-text h3{ font-size:clamp(1.08rem, 1.01rem + .45vw, 1.2rem); }

.chapter-text ul,.chapter-text ol{
  padding-left:1.25em;
  margin:.6em 0;
}
.chapter-text li{ margin:.3em 0; }

/* Blockquote — with background-color fallback for Firefox */
.chapter-text blockquote{
  margin:.8em 0;
  padding:.6em .9em;

  background-color: var(--surface-2);
  background: color-mix(in srgb, var(--surface) 85%, var(--background));

  border-left:4px solid var(--border);
  border-radius:10px;
  color:var(--text);
}

.chapter-text code{
  background-color: var(--surface-2);
  background: color-mix(in srgb, var(--surface) 70%, var(--background));
  padding:.1em .35em;
  border-radius:4px;
}

.chapter-text pre{
  background-color: var(--surface-2);
  background: color-mix(in srgb, var(--surface) 70%, var(--background));
  padding:.8em 1em;
  border-radius:10px;
  overflow:auto;
  -webkit-overflow-scrolling: touch;
  border:1px solid var(--border);
}
.chapter-text pre code{ background:transparent; padding:0; }

/* ===================== Pager ===================== */
.chapter-pager{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  margin-top:16px;
}
.chapter-pager .button[aria-disabled="true"]{
  opacity:.5;
  pointer-events:none;
}

/* Make pager buttons sane on narrow */
.chapter-pager .button{
  min-height: var(--ch-btn-minh);
}

/* ===================== Jump ===================== */
.jump{ margin-top:12px; }
.jump-title{
  font-size:.95rem;
  color:var(--muted);
  margin-bottom:8px;
}

/* Use grid for stability on tiny screens */
.jump-list{
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap:10px;
  align-items:stretch;
}
.jump-dot{
  width: 100%;
  aspect-ratio: 1 / 1;

  border-radius:999px;
  display:inline-flex;
  align-items:center;
  justify-content:center;

  text-decoration:none;
  font-weight:700;

  border:1px solid var(--border);
  background:var(--surface);
  box-shadow:0 4px 12px rgba(0,0,0,.06);

  transition:transform .15s, border-color .15s, box-shadow .15s;
}
.jump-dot span{ line-height:1; }
.jump-dot:hover{
  transform:translateY(-1px);
  border-color:color-mix(in srgb, var(--border) 60%, var(--text));
  box-shadow:0 8px 20px rgba(0,0,0,.08);
}
.jump-dot:focus-visible{ outline:3px solid var(--focus); outline-offset:2px; }
.jump-dot.active{
  border-color:var(--accent);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent), 0 8px 20px rgba(0,0,0,.10);
}

/* ===================== Reader settings blocks (generic safety) ===================== */
/* Если внутри главы есть панель "Настройки чтения" — не даём ей развалиться */
.chapter-card select,
.chapter-card input[type="text"],
.chapter-card input[type="number"],
.chapter-card input[type="range"],
.chapter-card input[type="color"],
.chapter-card button{
  max-width:100%;
}

.chapter-card select,
.chapter-card input[type="text"],
.chapter-card input[type="number"]{
  width:100%;
}

/* ===================== Reviews / Quill ===================== */
/* Токены */
.rv-scope{
  --rv-radius:12px;
  --rv-pad:10px 12px;
  --rv-editor-bg: var(--surface);
  --rv-editor-border: var(--border);
  --rv-toolbar-bg: var(--surface-2);
  --rv-text: var(--text);
  --rv-muted: var(--muted);
  --rv-avatar: 40px;
  --rv-gap: 10px;
  --rv-indent: calc(var(--rv-avatar) + var(--rv-gap));
}
.dark-theme .rv-scope,
.neon-theme .rv-scope{
  --rv-editor-bg:#141728;
  --rv-editor-border:#384056;
  --rv-toolbar-bg:#0f1324;
  --rv-text:#e8ecff;
  --rv-muted:#a3acc8;
}

/* Список/карточки */
.reviews-list{ display:grid; gap:12px; }
.review-card{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--rv-radius);
  box-shadow:var(--shadow-sm,0 4px 12px rgba(0,0,0,.06));
  padding:var(--rv-pad);
  color:var(--text);
}

/* Mobile: make review items stack cleanly */
.review-item{
  display:grid;
  grid-template-columns: var(--rv-avatar) 1fr;
  gap: var(--rv-gap);
  padding:10px 0;
  border-top:1px dashed var(--border);
}
.review-avatar{
  width:40px; height:40px;
  border-radius:50%;
  object-fit:cover;
  background:#eee;
}
.review-head{
  display:flex;
  gap:8px;
  align-items:center;
  flex-wrap:wrap;
  font-size:.95rem;
  margin-bottom:4px;
}
.review-head .name{ font-weight:700; }
.review-head .date{ color:var(--muted); margin-left:6px; font-size:.92em; }

/* actions row */
.review-actions-row{
  margin-left:auto;
  display:flex;
  gap:8px;
  align-items:center;
  flex-wrap:wrap;
}
.review-head .review-delete-form{ margin:0; }
.review-actions-row form{ margin:0; }

/* чтобы первая строка отзыва не начиналась с пунктирной линии */
.review-card > .review-item:first-child{
  border-top: 0;
  padding-top: 0;
}

/*
  Replies часто оказываются внутри 2-й колонки review-item (после аватарки),
  поэтому они “узкие”. Растягиваем их обратно на всю внутреннюю ширину карточки.
*/
.review-item .review-replies{
  /* если контейнер ответов является прямым ребёнком grid — пусть занимает обе колонки */
  grid-column: 1 / -1;

  /* визуальная “стыковка” с материнским комментом */
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);

  /* ключевое: компенсируем колонку аватарки + gap */
  margin-left: calc(-1 * var(--rv-indent));
  width: calc(100% + var(--rv-indent));
  box-sizing: border-box;
}

/* защитные сбросы от “вложенных карточек */
.review-item .review-replies .review-card,
.review-item .review-replies .review-item,
.review-item .review-replies .reply-item,
.review-item .review-replies .review-reply{
  margin-left: 0 !important;
}

/* Like */
.c-like-btn{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:6px 10px;
  min-height:32px;
  border:1px solid var(--border);
  background:var(--surface);
  color:var(--text);
  border-radius:999px;
  cursor:pointer;
  font-weight:700;
  transition:transform .1s ease, background-color .15s ease;
}
.c-like-btn:hover{ transform:translateY(-1px); }
.c-like-btn.liked{
  background:color-mix(in srgb, var(--accent,#7c82ff) 12%, transparent);
  border-color:var(--accent,#7c82ff);
}
.c-like-btn .count{
  font-variant-numeric:tabular-nums;
  min-width:1.4em;
  text-align:right;
}

/* Buttons */
.review-edit-btn,
.review-save-btn,
.review-cancel-btn,
.rv-scope .review-delete-form .button{
  height:32px;
  padding:6px 10px;
  box-sizing:border-box;
  border-radius:10px;
  border:1px solid var(--btn-secondary-border, var(--rv-editor-border));
  background:var(--btn-secondary-bg, var(--rv-editor-bg));
  color:var(--rv-text);
  cursor:pointer;
  display:inline-flex;
  align-items:center;
  justify-content:center;
}
.review-edit-btn:hover,
.rv-scope .review-delete-form .button:hover{ filter:brightness(1.02); }

/* Content */
.review-body{
  color:var(--text);
  line-height:1.65;
  overflow-wrap:anywhere;
}
.review-body a{ color:var(--link); text-underline-offset:2px; }
.review-body .ql-align-center{text-align:center;}
.review-body .ql-align-right{text-align:right;}
.review-body .ql-align-justify{text-align:justify;}
.review-body img{
  max-width:100% !important;
  height:auto !important;
  display:block !important;
  margin:8px 0 !important;
}
.review-body audio{
  display:block !important;
  width:100% !important;
  margin:8px 0 !important;
}

/* Hints/counters */
.review-hint{ margin-top:6px; font-size:.9rem; color:var(--rv-muted); }
.review-counter{ font-size:.9rem; margin-top:4px; }
.review-counter.over{ color:#ef4444; font-weight:700; }

/* ---------- Quill: toolbar ---------- */
#q-toolbar{ display:flex; flex-wrap:wrap; gap:6px; align-items:center; }
#q-toolbar .ql-formats{ margin:0; display:flex; gap:4px; align-items:center; }
#q-toolbar button, #q-toolbar .ql-picker-label, #q-toolbar .ql-picker-item{
  height:24px; line-height:24px;
}

/* toolbar/container */
.rv-scope .ql-toolbar.ql-snow{
  background:var(--rv-toolbar-bg);
  border:1px solid var(--rv-editor-border);
  border-radius:12px 12px 0 0;
  padding:6px;
  margin-bottom:6px;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,.04);
}
.rv-scope .ql-toolbar .ql-stroke{ stroke:var(--rv-text) !important; }
.rv-scope .ql-toolbar .ql-fill,
.rv-scope .ql-toolbar .ql-stroke.ql-fill{ fill:var(--rv-text) !important; }
.rv-scope .ql-toolbar .ql-picker,
.rv-scope .ql-toolbar .ql-picker-label,
.rv-scope .ql-toolbar .ql-picker-item{ color:var(--rv-text) !important; }

.rv-scope .ql-container.ql-snow{
  background:var(--rv-editor-bg);
  border:1px solid var(--rv-editor-border);
  border-top:0;
  border-radius:0 0 12px 12px;
  position:relative;
  z-index:0;
  outline:none;
}

/* hide built-in toolbar for main editor — use #q-toolbar */
#q-editor .ql-toolbar{ display:none !important; }

/* ---------- Resets for inherited flex/grid ---------- */
#q-editor .ql-container, #q-editor .ql-editor,
.rv-scope .ql-container, .rv-scope .ql-editor,
.review-edit-area .ql-container, .review-edit-area .ql-editor,
.reply-form .ql-container, .reply-form .ql-editor{
  display:block !important;
  position:static !important;
  float:none !important;
  clear:none !important;
  align-items:initial !important;
  justify-content:flex-start !important;
  width:100% !important;
  box-sizing:border-box !important;
  margin:0 !important;
  text-align:left !important;
}

/* main editor container */
#q-editor.ql-container.ql-snow{
  border:1px solid var(--rv-editor-border);
  border-radius:12px;
  background:var(--rv-editor-bg);
  min-height:180px;
  max-height:320px;
  overflow:visible;
  position:relative;
  z-index:1;
}

/* editor body */
#q-editor .ql-editor,
.rv-scope .ql-editor,
.review-edit-area .ql-editor{
  min-height:160px;
  max-height:360px;
  overflow-y:auto;
  -webkit-overflow-scrolling: touch;
  line-height:1.6;
  font-size:1rem;
  background:var(--rv-editor-bg);
  color:var(--rv-text) !important;
  caret-color:currentColor !important;
  padding:12px 14px;
  text-align:left !important;
}

/* placeholder */
#q-editor .ql-editor.ql-blank::before,
.rv-scope .ql-editor.ql-blank::before,
.review-edit-area .ql-editor.ql-blank::before{
  color:var(--rv-muted);
  left:14px;
  right:14px;
  pointer-events:none;
}

/* inline editor */
.review-edit-area{ margin-top:8px; }
.review-edit-area[hidden]{ display:none !important; }
.review-edit-area .ql-container.ql-snow{
  border:1px solid var(--rv-editor-border);
  border-radius:10px;
  background:var(--rv-editor-bg);
}
.review-edit-area .ql-editor{
  min-height:120px;
  max-height:280px;
  padding:10px 12px;
}

/* dark/neon reinforce */
.dark-theme  .review-edit-area .ql-editor,
.neon-theme  .review-edit-area .ql-editor,
.dark-theme  #q-editor .ql-editor,
.neon-theme  #q-editor .ql-editor{
  background:var(--rv-editor-bg) !important;
  color:var(--rv-text) !important;
}

/* undo/redo */
.rv-scope .ql-toolbar .ql-undo,
.rv-scope .ql-toolbar .ql-redo,
#q-toolbar .ql-undo,
#q-toolbar .ql-redo,
.review-edit-area .ql-toolbar .ql-undo,
.review-edit-area .ql-toolbar .ql-redo{
  appearance:none;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  height:24px;
  line-height:24px;
  padding:0 8px;
  border-radius:6px;
  border:1px solid transparent;
  color:var(--rv-text, var(--text));
  background:transparent;
  font-weight:600;
  cursor:pointer;
}
.rv-scope .ql-toolbar .ql-undo:hover,
.rv-scope .ql-toolbar .ql-redo:hover,
#q-toolbar .ql-undo:hover,
#q-toolbar .ql-redo:hover,
.review-edit-area .ql-toolbar .ql-undo:hover,
.review-edit-area .ql-toolbar .ql-redo:hover{
  background:color-mix(in srgb, var(--accent,#6366f1) 12%, transparent);
  border-color:color-mix(in srgb, var(--accent,#6366f1) 40%, var(--rv-editor-border));
}
.rv-scope .ql-toolbar .ql-undo.ql-active,
.rv-scope .ql-toolbar .ql-redo.ql-active,
#q-toolbar .ql-undo.ql-active,
#q-toolbar .ql-redo.ql-active,
.review-edit-area .ql-toolbar .ql-undo.ql-active,
.review-edit-area .ql-toolbar .ql-redo.ql-active{
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent);
}

/* focus */
.rv-scope .ql-container.ql-snow:focus-within{
  border-color:rgba(124,130,255,.55);
  box-shadow:inset 0 0 0 2px rgba(124,130,255,.35);
}

/* alignments */
#q-editor .ql-editor .ql-align-center,
.rv-scope  .ql-editor .ql-align-center,
.review-edit-area .ql-editor .ql-align-center{ text-align:center !important; }
#q-editor .ql-editor .ql-align-right,
.rv-scope  .ql-editor .ql-align-right,
.review-edit-area .ql-editor .ql-align-right{ text-align:right !important; }
#q-editor .ql-editor .ql-align-justify,
.rv-scope  .ql-editor .ql-align-justify,
.review-edit-area .ql-editor .ql-align-justify{ text-align:justify !important; }

/* Reply/Edit action buttons */
.rv-scope .review-actions-row .reply-btn,
.rv-scope .review-actions-row .review-edit-btn{
  appearance:none;
  box-sizing:border-box;
  display:inline-flex;
  align-items:center;
  gap:.4rem;
  height:32px;
  padding:6px 10px;
  border-radius:10px;
  border:1px solid var(--btn-secondary-border, rgba(0,0,0,.12));
  background:var(--btn-secondary-bg, rgba(0,0,0,.04));
  color:var(--btn-secondary-fg, inherit);
  font:600 0.95rem/1.2 inherit;
  cursor:pointer;
  transition:background .15s ease, border-color .15s ease, transform .02s ease;
}
.dark-theme .rv-scope .review-actions-row .reply-btn,
.dark-theme .rv-scope .review-actions-row .review-edit-btn{
  border-color:var(--btn-secondary-border, rgba(255,255,255,.18));
  background:var(--btn-secondary-bg, rgba(255,255,255,.06));
}
.rv-scope .review-actions-row .reply-btn:hover,
.rv-scope .review-actions-row .review-edit-btn:hover{
  background:var(--btn-secondary-bg-hover, rgba(0,0,0,.06));
}
.dark-theme .rv-scope .review-actions-row .reply-btn:hover,
.dark-theme .rv-scope .review-actions-row .review-edit-btn:hover{
  background:var(--btn-secondary-bg-hover, rgba(255,255,255,.1));
}
.rv-scope .review-actions-row .reply-btn:active,
.rv-scope .review-actions-row .review-edit-btn:active{ transform:translateY(1px); }

/* ===== keep editor left aligned ===== */
#reviewForm #q-editor .ql-editor{
  display:block !important;
  text-align:left !important;
  align-items:initial !important;
  justify-content:flex-start !important;
}
#reviewForm #q-editor .ql-editor > *:not(.ql-align-center):not(.ql-align-right):not(.ql-align-justify){
  text-align:left !important;
}

/* Reply placeholder clamp */
.rv-scope .reply-editor .ql-editor{ position:relative !important; }
.rv-scope .reply-editor .ql-editor.ql-blank::before{
  position:absolute !important;
  top:10px !important;
  left:14px !important;
  right:14px !important;
  transform:none !important;
  white-space:normal !important;
  color:var(--rv-muted) !important;
  pointer-events:none !important;
}
.review-edit-area .ql-editor{ position:relative !important; }
.review-edit-area .ql-editor.ql-blank::before{
  position:absolute !important;
  top:10px !important; left:14px !important; right:14px !important;
  transform:none !important;
}

/* ===================== Bookmark by selection — popover ===================== */
:root{
  --bm-accent: var(--accent, #7c82ff);
  --bm-accent-ink: var(--on-accent, #fff);

  --bm-bg: var(--card-bg, #111827);
  --bm-fg: var(--ink-on-primary, #fff);
  --bm-border: rgba(255,255,255,.08);
  --bm-shadow: 0 10px 30px rgba(0,0,0,.35);

  /* fallback color if gradient unsupported */
  --bm-pill-bg: var(--accent, #7c82ff);
  --bm-pill: linear-gradient(180deg, #7c82ff, #6a73ff);
}
.dark-theme{
  --bm-bg:#161823;
  --bm-border: rgba(255,255,255,.06);
}

.bmk-highlight{
  background: color-mix(in oklab, var(--bm-accent) 18%, transparent);
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--bm-accent) 35%, transparent) inset;
  border-radius: 4px;
  animation: bmkPulse .9s ease-out 1;
}
@keyframes bmkPulse{
  from{ outline:2px solid color-mix(in oklab, var(--bm-accent) 60%, transparent); }
  to  { outline:0; }
}

.bookmark-pop{
  position: fixed;
  left: 0; top: 0;
  transform: translate(-50%,-100%); /* JS positions */
  z-index: 2147483000;
  display: none;

  background-color: var(--bm-bg);
  background: var(--bm-bg);

  color: var(--bm-fg);
  border: 1px solid var(--bm-border);
  border-radius: 12px;
  box-shadow: var(--bm-shadow);

  padding: 8px 10px;
  gap: 8px;
  align-items: center;

  /* IMPORTANT: tiny screens */
  max-width: calc(100vw - 16px);
  white-space: normal;

  user-select: none;
  -webkit-user-select: none;

  transition: opacity .12s ease, transform .12s ease;
}
.bookmark-pop[data-pos="bottom"]{ transform: translate(-50%, 8px); }

.bookmark-pop::after{
  content: "";
  position: absolute;
  left: 50%;
  width: 10px; height: 10px;
  background: var(--bm-bg);
  border-left: 1px solid var(--bm-border);
  border-top: 1px solid var(--bm-border);
  transform: translate(-50%, 50%) rotate(45deg);
  bottom: -1px;
}
.bookmark-pop[data-pos="bottom"]::after{
  top: -1px; bottom: auto;
  transform: translate(-50%, -50%) rotate(225deg);
}

.bookmark-pop__btn{
  appearance: none;
  border: 0;
  cursor: pointer;

  display:inline-flex;
  align-items:center;
  gap:8px;

  padding: 8px 12px;
  border-radius: 999px;

  background-color: var(--bm-pill-bg);
  background: var(--bm-pill);

  color:#fff;
  font-weight:700;

  box-shadow: inset 0 -1px 0 rgba(0,0,0,.25);

  /* wrap safety */
  max-width: 100%;
}
.bookmark-pop__btn .ico{ font-size:16px; }

.bookmark-pop__close{
  appearance:none;
  border:0;
  background:transparent;
  cursor:pointer;
  color: var(--bm-fg);
  opacity:.75;
  padding:4px 6px;
  border-radius:8px;
  font-size:18px;
  line-height:1;
}
.bookmark-pop__close:hover{ opacity:1; }

/* ===================== Preserve tabs/indents in chapter text ===================== */
.chapter-text,
.chapter-text p,
.chapter-text li,
.chapter-text blockquote{
  white-space: pre-wrap;
}
.chapter-text pre,
.chapter-text pre code{
  white-space: pre;
}

/* ===================== Reviews: restore Quill-like formatting ===================== */
.review-body{
  line-height:1.55;
  overflow-wrap:anywhere;
}
.review-body p{ margin:0 0 .55em; }
.review-body p:last-child{ margin-bottom:0; }
.review-body strong,
.review-body b{ font-weight:800 !important; }
.review-body em,
.review-body i{ font-style:italic !important; }
.review-body u{
  text-decoration:underline !important;
  text-underline-offset:2px;
}
.review-body s,
.review-body strike,
.review-body del{ text-decoration:line-through !important; }
.review-body a{
  color:var(--brand,#7aa2ff);
  text-decoration:underline;
  text-underline-offset:2px;
}
.review-body a:hover{ filter:brightness(1.08); }
.review-body blockquote{
  margin:.6em 0;
  padding:.55em .8em;
  border-left:3px solid color-mix(in srgb, var(--brand,#7aa2ff) 55%, transparent);
  background-color: var(--surface-2);
  background:color-mix(in srgb, var(--surface-1, rgba(255,255,255,.06)) 80%, transparent);
  border-radius:14px;
}
.review-body ul,
.review-body ol{
  margin:.4em 0 .6em 1.25em;
  padding:0;
}
.review-body li{ margin:.2em 0; }

/* ===================== Mobile overrides ===================== */
@media (max-width: 560px){
  .chapter-card{
    padding: clamp(12px, 3.8vw, 16px);
    border-radius: 14px;
  }

  .chapter-hero{
    padding: 12px;
  }

  /* make meta less crowded */
  .chapter-hero-sub{
    gap: 8px;
    font-size: .93rem;
  }

  /* pager: avoid cramped horizontal */
  .chapter-pager{
    flex-direction: column;
    align-items: stretch;
  }
  .chapter-pager .button{
    width: 100%;
    justify-content: center;
  }

  /* jump dots get tighter */
  .jump-list{
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 8px;
  }
}

@media (max-width: 360px){
  :root{
    --ch-btn-minh: 38px;
  }

  .breadcrumbs{
    font-size: .92rem;
  }

  .chapter-text{
    padding: 12px;
    border-radius: 12px;
  }

  .jump-list{
    grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
    gap: 8px;
  }
}

@media (max-width: 320px){
  main{
    padding-left: calc(8px + env(safe-area-inset-left, 0px));
    padding-right: calc(8px + env(safe-area-inset-right, 0px));
  }

  .chapter-card{
    padding: 12px;
  }

  .chapter-hero-title{
    font-size: 1.18rem;
  }
}

/* Hover is useless on touch; reduce jitter */
@media (hover: none){
  .jump-dot:hover,
  .c-like-btn:hover{
    transform:none;
  }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce){
  *{ scroll-behavior:auto !important; }
  .jump-dot,
  .bookmark-pop{
    transition:none !important;
  }
  .bmk-highlight{
    animation:none !important;
  }
}

/* ===================== Quill placeholder: fix drift ===================== */

/* Quill плейсхолдер (::before) должен позиционироваться относительно .ql-editor */
#q-editor .ql-editor,
.rv-scope .ql-editor,
.review-edit-area .ql-editor,
.reply-form .ql-editor{
  position: relative !important;
}

/* жёстко фиксируем геометрию плейсхолдера под наши паддинги */
#q-editor .ql-editor.ql-blank::before,
.rv-scope .ql-editor.ql-blank::before,
.review-edit-area .ql-editor.ql-blank::before{
  position: absolute !important;
  top: 12px !important;
  left: 14px !important;
  right: 14px !important;
  transform: none !important;
  white-space: normal !important;
  pointer-events: none !important;
  color: var(--rv-muted) !important;
}

/* ===========================
   Exit prompt modal
   =========================== */
.exit-review-overlay{
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 1600;
  background: rgba(0,0,0,.55);
}

.exit-review-overlay.is-open{
  display: flex;
}

.exit-review-card{
  width: min(560px, 100%);
  border-radius: 18px;
  border: 1px solid color-mix(in srgb, var(--border, #23314a) 70%, transparent);
  background: var(--surface, #0f172a);
  color: var(--text, #e7eefc);
  box-shadow: 0 24px 70px rgba(0,0,0,.45);
  padding: 16px 16px 14px;
}

.exit-review-head{
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.exit-review-ico{
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;

  border: 1px solid color-mix(in srgb, var(--accent, #7c82ff) 45%, transparent);
  background: color-mix(in srgb, var(--accent, #7c82ff) 22%, transparent);
}

.exit-review-title{
  margin: 0;
  font-weight: 900;
  font-size: 1.15rem;
}

.exit-review-text{
  margin: 8px 0 0;
  line-height: 1.45;
  color: color-mix(in srgb, var(--text, #e7eefc) 92%, var(--muted, #9fb0c9));
}

.exit-review-actions{
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.exit-review-actions .button{
  flex: 1 1 auto;
}

.exit-review-close{
  margin-left: auto;
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 10px;
}

.exit-review-close:focus-visible{
  outline: 2px solid color-mix(in srgb, var(--accent, #7c82ff) 55%, transparent);
  outline-offset: 2px;
}

@media (max-width: 360px){
  .exit-review-card{ padding: 14px; border-radius: 16px; }
  .exit-review-ico{ width: 36px; height: 36px; border-radius: 11px; }
}

/* =========================
   Fullscreen reader (chapter)
   ========================= */

.fanfic-chapter-page.reader-fs{
  overflow: hidden;
}

/* На случай отсутствия FS API: прячем лишнее */
.fanfic-chapter-page.reader-fs #app-header,
.fanfic-chapter-page.reader-fs #app-drawer,
.fanfic-chapter-page.reader-fs .breadcrumbs,
.fanfic-chapter-page.reader-fs .chapter-hero,
.fanfic-chapter-page.reader-fs .chapter-pager,
.fanfic-chapter-page.reader-fs .reviews-card,
.fanfic-chapter-page.reader-fs .footer-actions,
.fanfic-chapter-page.reader-fs footer{
  display:none !important;
}

/* Корень читалки — строго во весь экран */
.fanfic-chapter-page.reader-fs [data-reader-root]{
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;

  margin: 0 !important;
  max-width: none !important;

  overflow: auto !important;
  -webkit-overflow-scrolling: touch;

  background: var(--surface, #ffffff);
  background-color: var(--surface, #ffffff); /* Firefox safety */
  color: var(--text, #111827);

  z-index: 2000;

  /* safe-area */
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Верхняя панель — липкая */
.fanfic-chapter-page.reader-fs [data-reader-bar]{
  position: sticky;
  top: 0;
  z-index: 5;

  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;

  padding: 10px clamp(10px, 2vw, 18px);

  background: var(--surface, #ffffff);
  background-color: var(--surface, #ffffff);

  border-bottom: 1px solid var(--border, rgba(0,0,0,.12));
  box-shadow: 0 10px 26px rgba(0,0,0,.10);
}

/* Панель настроек — тоже с нормальными кромками */
.fanfic-chapter-page.reader-fs .reader-panel{
  margin: 10px clamp(10px, 2vw, 18px) 0;
}

/* ТЕКСТ — на всю ширину экрана (кроме кромок) */
.fanfic-chapter-page.reader-fs [data-reader-target],
.fanfic-chapter-page.reader-fs .chapter-notes{
  width: 100% !important;
  max-width: none !important;
  margin: 0 !important;
}

/* Небольшие кромки по бокам */
.fanfic-chapter-page.reader-fs [data-reader-target]{
  padding: 14px clamp(12px, 2.2vw, 26px) 52px;
}