/* ============================================================
   База DevRel — tech reading style
   v2026.04.05
   ============================================================ */

:root {
  color-scheme: only light;

  /* Тёплая бумага, чернила, один винный акцент — классическая книжная палитра */
  --bg: #f2ebd9;               /* desk / surface around the book */
  --bg-elevated: #fbf5e3;      /* paper page */
  --bg-subtle: #eee3c9;
  --text: #2a1f14;             /* dark brown ink */
  --text-muted: #6e5f47;
  --text-dim: #a0907a;
  --border: #d9cdb0;
  --border-strong: #bfae8a;

  --accent: #8b1e3f;           /* wine / oxblood — классический акцент печатных книг */
  --accent-hover: #6e1630;
  --accent-soft: #f3e0e5;
  --accent-text: #5f0f26;

  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-serif: "Charter", "Iowan Old Style", "Georgia", "Cambria", serif;
  --font-mono: "JetBrains Mono", "SF Mono", ui-monospace, "Menlo", "Consolas", monospace;

  --radius: 8px;
  --radius-sm: 4px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.05);

  --topbar-h: 60px;
  --nav-h: 64px;
  --content-max: 72ch;
}

/* Dark mode отключен: книжная бумажная палитра всегда */

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background-image:
    radial-gradient(ellipse at top, rgba(139, 30, 63, 0.04), transparent 60%),
    radial-gradient(circle at 20% 80%, rgba(110, 95, 71, 0.06), transparent 50%);
}

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}
a:hover { border-bottom-color: var(--accent); }

/* Layout */

.book-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.book-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1rem;
  height: var(--topbar-h);
  padding: 0 1.25rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(180%) blur(8px);
}

.book-home-link {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-align: left;
}
.book-mark {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  font-family: var(--font-sans);
}
.book-submark {
  margin: 0;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.book-top-nav {
  display: flex;
  gap: 0.25rem;
  margin-left: auto;
}
.top-nav-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.top-nav-btn:hover {
  background: var(--bg-subtle);
  color: var(--text);
}

.palette-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.65rem 0.45rem 0.85rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.palette-trigger:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}
.palette-trigger kbd {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.1rem 0.35rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-muted);
}

.book-version {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* Main content — книжный постраничный вид */

.folio-shell {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 1.8rem 2rem;
  overflow: hidden;
}
.folio-page {
  width: 100%;
  max-width: 820px;
  padding: 3rem 3.2rem 2rem;
  overflow-x: hidden;
  overflow-y: auto;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -ms-overflow-style: none;
  height: calc(100vh - var(--topbar-h) - var(--nav-h) - 3.6rem);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow:
    0 1px 0 rgba(42, 31, 20, 0.03),
    0 10px 40px -15px rgba(42, 31, 20, 0.25),
    inset 0 0 0 1px rgba(251, 245, 227, 1);
  position: relative;
}
.folio-page::-webkit-scrollbar { display: none; }

.folio-page .book-cover,
.folio-page .book-toc { max-width: 56ch; margin: 0 auto; }

/* Cover: вертикальный скролл если не влезает, центрирование по горизонтали */
.folio-page.is-cover {
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem;
}
.folio-page.is-cover .book-cover {
  padding: 1rem 0;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

/* Mobile: компактные отступы */
@media (max-width: 860px) {
  .folio-shell { padding: 0.8rem 0.8rem; }
  .folio-page {
    padding: 1.4rem 1.2rem 1.4rem;
    height: auto;
    min-height: calc(100vh - var(--topbar-h) - var(--nav-h) - 1.6rem);
    box-shadow: 0 2px 16px -6px rgba(42, 31, 20, 0.18);
  }
}

/* Cover */

.book-cover {
  padding: 2rem 0 1rem;
  max-width: 56ch;
}
.cover-eyebrow {
  margin: 0 0 0.8rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent);
  font-weight: 600;
  font-family: var(--font-mono);
}
.cover-title {
  margin: 0 0 0.6rem;
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  line-height: 1.02;
  font-weight: 800;
  letter-spacing: -0.035em;
  color: var(--text);
}
.cover-subtitle {
  margin: 0 0 1.2rem;
  font-size: clamp(1.1rem, 2vw, 1.35rem);
  line-height: 1.4;
  color: var(--text-muted);
  font-family: var(--font-serif);
  font-style: italic;
}
.cover-authors {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.2rem 1.6rem;
  margin: 1rem 0 0.3rem;
  padding: 0.8rem 0 0.5rem;
  border-top: 1px solid var(--border);
}
.cover-authors p {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text);
  font-weight: 500;
}
.cover-version {
  margin: 0 0 1rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}
.cover-cta {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.8rem 1.5rem;
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.cover-cta:hover { background: var(--accent-hover); }
.cover-cta:active { transform: translateY(1px); }

/* TOC */

.book-toc { padding: 2rem 0 1rem; }
.book-toc h1 {
  margin: 0 0 0.6rem;
  font-size: clamp(1.9rem, 4vw, 2.4rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}
.toc-lead {
  margin: 0 0 2.5rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}
.toc-part { margin: 0 0 2.2rem; }
.toc-part h2 {
  margin: 0 0 0.8rem;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
}
.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.15rem;
}
.toc-link {
  display: flex;
  align-items: baseline;
  gap: 0.9rem;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s;
}
.toc-link:hover { background: var(--bg-subtle); }
.toc-num {
  flex: 0 0 2.2rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.toc-title { flex: 1; }

/* Chapter — постраничный book-style layout */

.chapter {
  max-width: 56ch;
  margin: 0 auto;
}
@media (max-width: 860px) {
  .chapter {
    height: auto;
    columns: auto;
    column-width: auto;
    column-count: 1;
    column-gap: 0;
    column-rule: none;
    width: 100%;
  }
}

.chapter-header {
  margin: 0 0 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  break-after: avoid;
  break-inside: avoid;
}
.chapter-eyebrow {
  margin: 0 0 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent);
  font-weight: 500;
  letter-spacing: 0.04em;
}
.chapter-title {
  margin: 0;
  font-size: clamp(2rem, 4.5vw, 2.8rem);
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: -0.025em;
}

/* Book-style body: serif, first-line indent, hyphens, no margins between paragraphs */
.chapter-body {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--text);
  hyphens: auto;
  -webkit-hyphens: auto;
  text-align: justify;
  text-justify: inter-word;
}
.chapter-body h2,
.chapter-body h3,
.chapter-body h4,
.chapter-body h5,
.chapter-body h6,
.chapter-body blockquote,
.chapter-body pre,
.chapter-body table,
.chapter-body .callout,
.chapter-body .editor-notes {
  break-inside: avoid;
}
.chapter-body h2,
.chapter-body h3,
.chapter-body h4,
.chapter-body h5,
.chapter-body h6 {
  break-after: avoid;
}
.chapter-body > p {
  margin: 0;
  text-indent: 1.6em;
}
/* Первый параграф после заголовка или блочного элемента — без отступа */
.chapter-body > h1 + p,
.chapter-body > h2 + p,
.chapter-body > h3 + p,
.chapter-body > h4 + p,
.chapter-body > h5 + p,
.chapter-body > h6 + p,
.chapter-body > blockquote + p,
.chapter-body > ul + p,
.chapter-body > ol + p,
.chapter-body > table + p,
.chapter-body > pre + p,
.chapter-body > hr + p,
.chapter-body > aside + p,
.chapter-body > details + p,
.chapter-body > .editor-notes + p,
.chapter-body > .callout + p {
  text-indent: 0;
}

.chapter-body > p:first-of-type { text-indent: 0; }
.chapter-body > * + * { margin-top: 0; }
.chapter-body h2,
.chapter-body h3,
.chapter-body h4,
.chapter-body h5,
.chapter-body h6 {
  font-family: var(--font-sans);
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text);
  line-height: 1.3;
  text-align: left;
  text-indent: 0;
}
.chapter-body h2 {
  margin-top: 2.4em;
  margin-bottom: 0.6em;
  font-size: 1.55rem;
}
.chapter-body h3 {
  margin-top: 2em;
  margin-bottom: 0.5em;
  font-size: 1.28rem;
}
.chapter-body h4 {
  margin-top: 1.7em;
  margin-bottom: 0.45em;
  font-size: 1.12rem;
}
.chapter-body h5 {
  margin-top: 1.5em;
  margin-bottom: 0.4em;
  font-size: 1rem;
}
.chapter-body h6 {
  margin-top: 1.3em;
  margin-bottom: 0.35em;
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
}
.chapter-body > p + p { margin-top: 0.35em; }
/* «Ярлык»-параграф: `**Формат:**`, `**Цели:**` — выступает как подзаголовок
   перед списком. Без text-indent, с небольшим верхним отступом. */
.chapter-body p.label {
  text-indent: 0 !important;
  margin-top: 1em;
  margin-bottom: 0.25em;
  color: var(--text);
}
.chapter-body p.label + ul,
.chapter-body p.label + ol { margin-top: 0.25em; }
.chapter-body blockquote,
.chapter-body pre,
.chapter-body table,
.chapter-body hr,
.chapter-body .callout {
  margin-top: 1.2em;
  margin-bottom: 1.2em;
  text-align: left;
  text-indent: 0;
}
.chapter-body ul,
.chapter-body ol {
  padding-left: 1.4em;
  margin: 0.9em 0;
  text-align: left;
  text-indent: 0;
}
/* Склеенные соседние списки (единый смысловой блок) */
.chapter-body ul + ul,
.chapter-body ol + ol,
.chapter-body ul + ol,
.chapter-body ol + ul {
  margin-top: 0.2em;
}
.chapter-body li { margin: 0.25em 0; line-height: 1.55; }
.chapter-body li > p { margin: 0; text-indent: 0; display: inline; }
.chapter-body blockquote ul,
.chapter-body blockquote ol {
  margin: 0.4em 0;
  padding-left: 1.2em;
}
.chapter-body blockquote > p { margin: 0.3em 0; text-indent: 0; }
.chapter-body blockquote > p:first-child { margin-top: 0; }
.chapter-body blockquote > p:last-child { margin-bottom: 0; }
.chapter-body li::marker { color: var(--text-dim); }
.chapter-body strong { font-weight: 700; color: var(--text); }
.chapter-body em { font-style: italic; }

.chapter-body pre {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.55;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 1.4em 0;
}
.chapter-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-subtle);
  padding: 0.15em 0.4em;
  border-radius: 3px;
  color: var(--accent-text);
  border: 1px solid var(--border);
}
.chapter-body pre code {
  background: transparent;
  padding: 0;
  border: none;
  color: inherit;
}

.chapter-body blockquote {
  margin: 1.5em 0;
  padding: 0.2em 0 0.2em 1.2em;
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
  font-style: italic;
}

.chapter-body table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  margin: 1.5em 0;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.chapter-body table thead,
.chapter-body table tbody {
  display: table;
  width: 100%;
  table-layout: auto;
}
.chapter-body th,
.chapter-body td {
  text-align: left;
  padding: 0.65em 0.8em;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  line-height: 1.5;
}
.chapter-body th {
  background: var(--bg-subtle);
  font-weight: 600;
  color: var(--text);
  border-bottom-color: var(--border-strong);
}
.chapter-body tbody tr:hover { background: var(--bg-subtle); }

.chapter-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5em 0;
}

.chapter-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

/* Callouts */

.chapter-body .callout {
  margin: 1.5em 0;
  padding: 1em 1.2em;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-family: var(--font-sans);
  font-size: 0.98rem;
  font-style: normal;
}
.chapter-body .callout--tip { border-color: var(--success); background: rgba(5, 150, 105, 0.08); }
.chapter-body .callout--warning { border-color: var(--warning); background: rgba(217, 119, 6, 0.1); }
.chapter-body .callout--important { border-color: var(--danger); background: rgba(220, 38, 38, 0.08); }
.chapter-body .callout--note { border-color: var(--accent); }

/* Editor notes */

.editor-notes {
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.7rem 1rem;
  margin: 0 0 2rem;
  font-family: var(--font-sans);
  font-size: 0.88rem;
}
.editor-notes summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent-text);
  list-style: none;
}
.editor-notes summary::before { content: "✎ "; opacity: 0.7; }
.editor-notes ul {
  margin: 0.7rem 0 0;
  padding-left: 1.2rem;
  list-style: disc;
}
.editor-notes li { margin: 0.4rem 0; color: var(--text-muted); }
.editor-notes li strong { color: var(--text); }

/* Page number footer в главе */
.chapter-footer {
  margin-top: 4rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}
.chapter-footer-title {
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.chapter-footer-num {
  font-variant-numeric: tabular-nums;
}

/* Bottom nav */

.book-nav {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1rem;
  height: var(--nav-h);
  padding: 0 1.25rem;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  backdrop-filter: saturate(180%) blur(8px);
}
.nav-button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.nav-button:hover:not(:disabled) {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}
.nav-button:disabled { opacity: 0.4; cursor: default; }

.book-progress {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  max-width: 480px;
  margin: 0 auto;
}
.book-progress progress {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  border: none;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.book-progress progress::-webkit-progress-bar { background: var(--border); border-radius: 2px; }
.book-progress progress::-webkit-progress-value { background: var(--accent); border-radius: 2px; }
.book-progress progress::-moz-progress-bar { background: var(--accent); }
.book-progress-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* Command palette */

.palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.55);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 1rem 1rem;
  z-index: 100;
}
.palette-overlay[hidden] { display: none; }
.palette {
  width: 100%;
  max-width: 560px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 70vh;
}
.palette-input {
  width: 100%;
  padding: 1rem 1.2rem;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  outline: none;
}
.palette-input::placeholder { color: var(--text-dim); }
.palette-results {
  list-style: none;
  padding: 0.5rem;
  margin: 0;
  overflow-y: auto;
  flex: 1;
}
.palette-item {
  display: flex;
  align-items: baseline;
  gap: 0.9rem;
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: transparent;
  border: none;
  text-align: left;
  font: inherit;
  font-size: 0.94rem;
  color: var(--text);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.palette-item.is-active,
.palette-item:hover { background: var(--bg-subtle); }
.palette-item-num {
  flex: 0 0 2.4rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-dim);
}
.palette-item-title { flex: 1; }
.palette-item-part {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}
.palette-empty {
  padding: 2rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
}
.palette-footer {
  padding: 0.55rem 1rem;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  display: flex;
  gap: 1rem;
  justify-content: space-between;
}
.palette-footer kbd {
  padding: 0.1rem 0.35rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 3px;
}

/* Floating selection bubble (comment trigger) */

.selection-bubble {
  position: absolute;
  z-index: 60;
  display: flex;
  gap: 0.35rem;
  padding: 0.35rem 0.45rem;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 500;
  transform: translate(-50%, calc(-100% - 8px));
  animation: bubbleIn 0.12s ease-out;
  white-space: nowrap;
}
.selection-bubble::after {
  content: "";
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: var(--text);
}
.selection-bubble[hidden] { display: none; }
.selection-bubble button {
  background: transparent;
  color: var(--bg);
  border: none;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
}
.selection-bubble button:hover { background: rgba(255,255,255,0.15); }

@keyframes bubbleIn {
  from { opacity: 0; transform: translate(-50%, calc(-100% - 2px)); }
  to { opacity: 1; transform: translate(-50%, calc(-100% - 8px)); }
}

/* Feedback / comment modal */

.feedback-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.55);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 110;
}
.feedback-overlay[hidden] { display: none; }
.feedback-modal {
  width: 100%;
  max-width: 480px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 1.5rem;
  position: relative;
}
.feedback-close {
  position: absolute;
  top: 0.6rem;
  right: 0.8rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}
.feedback-heading {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 700;
}
.feedback-label {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0.8rem 0 0.3rem;
}
.feedback-quote {
  margin: 0;
  padding: 0.7rem 0.9rem;
  background: var(--bg-subtle);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  font-family: var(--font-serif);
  font-style: italic;
  color: var(--text);
  max-height: 140px;
  overflow-y: auto;
  font-size: 0.95rem;
}
.feedback-textarea {
  width: 100%;
  min-height: 80px;
  padding: 0.7rem 0.9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-family: var(--font-sans);
  font-size: 0.92rem;
  color: var(--text);
  resize: vertical;
  outline: none;
}
.feedback-textarea:focus { border-color: var(--accent); }
.feedback-send {
  margin-top: 0.8rem;
  padding: 0.65rem 1.2rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.feedback-send:hover:not(:disabled) { background: var(--accent-hover); }
.feedback-send:disabled { opacity: 0.6; cursor: default; }
.feedback-hint {
  margin: 0.6rem 0 0;
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* Existing comments sidebar (на полях) */
.chapter-body mark.has-comment {
  background: rgba(139, 30, 63, 0.12);
  border-bottom: 2px solid var(--accent);
  padding: 0 1px;
  cursor: pointer;
  color: inherit;
}
.chapter-body mark.has-comment:hover {
  background: rgba(139, 30, 63, 0.22);
}

/* Popup с текстом комментария (клик по mark.has-comment) */
.comment-popup {
  position: absolute;
  z-index: 1000;
  max-width: 360px;
  min-width: 220px;
  background: var(--bg-elevated, #fbf5e3);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 32px -8px rgba(42, 31, 20, 0.35);
  padding: 0.7rem 0.9rem 0.8rem;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
}
.comment-popup-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  padding-bottom: 0.4rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.comment-popup-author {
  font-weight: 600;
  color: var(--accent);
}
.comment-popup-time { color: var(--text-dim); }
.comment-popup-close {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0 0.2rem;
}
.comment-popup-close:hover { color: var(--accent); }
.comment-popup-body {
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.comment-popup-reply-item {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}
.comment-popup-reply {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}
.comment-popup-input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  font: inherit;
  font-size: 0.85rem;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
}
.comment-popup-input:focus {
  outline: none;
  border-color: var(--accent);
}
.comment-popup-send {
  margin-top: 0.4rem;
  padding: 0.35rem 0.9rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.comment-popup-send:hover { background: var(--accent-hover); }
.comment-popup-send:disabled { opacity: 0.6; cursor: default; }

/* Responsive */

@media (max-width: 860px) {
  body { font-size: 16px; }
  .book-topbar { padding: 0 0.8rem; gap: 0.5rem; }
  .book-submark { display: none; }
  .book-version { display: none; }
  .palette-trigger .palette-trigger-label { display: none; }
  .book-top-nav { gap: 0; }
  .top-nav-btn { padding: 0.4rem 0.55rem; font-size: 0.8rem; }
  .folio-shell { padding: 1.5rem 1rem 5rem; }
  .chapter-body { font-size: 1.02rem; line-height: 1.7; }
  .book-nav { padding: 0 0.9rem; gap: 0.5rem; }
  .nav-button { padding: 0.5rem 0.7rem; font-size: 0.82rem; }
  .book-progress { max-width: none; }
}

/* Narrow phones: max simplification */
@media (max-width: 560px) {
  .book-topbar {
    padding: 0 0.7rem;
    gap: 0.4rem;
  }
  .book-mark {
    font-size: 0.9rem;
    white-space: nowrap;
  }
  /* Убираем кнопки top-nav — их функции доступны через палитру */
  .book-top-nav { display: none; }
  .palette-trigger {
    margin-left: auto;
    padding: 0.4rem 0.55rem;
    gap: 0.3rem;
  }
  .palette-trigger kbd {
    font-size: 0.68rem;
    padding: 0.08rem 0.3rem;
  }
  .folio-shell { padding: 1.25rem 0.9rem 5rem; }
  .chapter-body { font-size: 1rem; }
  .chapter-body > p { text-indent: 1.2em; }
  .cover-title { font-size: 2.2rem; }
  .chapter-title { font-size: 1.7rem; }
  .book-nav {
    padding: 0 0.7rem;
    gap: 0.4rem;
  }
  .nav-button {
    padding: 0.45rem 0.6rem;
    font-size: 0.78rem;
  }
  .palette-overlay { padding: 6vh 0.8rem 0.8rem; }
}

.error {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--text-muted);
}

/* Карточки ролей (Введение: «Выберите свою роль») */
.chapter-body .role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.8rem;
  margin: 1.2rem 0 1.6rem;
}
.chapter-body .role-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.2rem 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chapter-body .role-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 12px -4px rgba(139, 30, 63, 0.18);
}
.chapter-body .role-card h3 {
  margin: 0 0 0.4rem !important;
  font-size: 1.15rem !important;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0;
}
.chapter-body .role-card .role-chapters {
  margin: 0 0 0.3rem;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--text);
  text-indent: 0;
}
.chapter-body .role-card .role-time {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-dim);
  text-indent: 0;
}
@media (max-width: 500px) {
  .chapter-body .role-grid { grid-template-columns: 1fr; }
}

/* Живой диалог в тексте — реплики визуально разделены */
.chapter-body .dialog {
  margin: 1.4rem 0;
  padding: 0.2rem 0 0.2rem 1.4rem;
  border-left: 3px solid var(--accent);
  background: rgba(139, 30, 63, 0.03);
  border-radius: 0 6px 6px 0;
}
.chapter-body .dialog .dialog-line {
  margin: 0.5rem 0 !important;
  text-indent: 0 !important;
  padding-left: 0;
  line-height: 1.55;
}
.chapter-body .dialog .dialog-line:first-child { margin-top: 0.6rem !important; }
.chapter-body .dialog .dialog-line:last-child { margin-bottom: 0.6rem !important; }
.chapter-body .dialog .dialog-who {
  display: inline-block;
  min-width: 3.5em;
  font-weight: 700;
  color: var(--accent);
  font-size: 0.82em;
  letter-spacing: 0.02em;
  margin-right: 0.5em;
  text-transform: uppercase;
}

/* Стилизация переписки Telegram-чата */
.chapter-body .tg-chat {
  background: rgba(139, 30, 63, 0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1rem 1rem;
  margin: 1.2rem 0;
  font-family: var(--font-sans);
  font-size: 0.92rem;
}
.chapter-body .tg-chat .tg-msg {
  background: var(--bg-elevated);
  border-radius: 10px;
  padding: 0.55rem 0.8rem;
  margin: 0 0 0.5rem;
  max-width: 85%;
  box-shadow: 0 1px 2px rgba(42, 31, 20, 0.08);
  line-height: 1.4;
}
.chapter-body .tg-chat .tg-msg:last-child { margin-bottom: 0; }
.chapter-body .tg-chat .tg-from {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.15rem;
}
.chapter-body .tg-chat .tg-admin {
  background: rgba(139, 30, 63, 0.08);
  border-left: 3px solid var(--accent);
}

/* Cross-references (внутренние ссылки на главы/приложения) */
.xref {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
  padding-bottom: 1px;
  cursor: pointer;
  font-weight: 500;
}
.xref:hover {
  border-bottom-style: solid;
  background: rgba(139, 30, 63, 0.06);
}

/* 3D книжная обложка */
.book-3d {
  position: relative;
  width: clamp(220px, 28vw, 300px);
  height: clamp(320px, 42vw, 440px);
  margin: 0 auto 1.5rem;
  perspective: 1800px;
  transform-style: preserve-3d;
  transform: rotateY(-22deg) rotateX(4deg);
  transition: transform 0.5s ease;
}
.book-3d:hover { transform: rotateY(-8deg) rotateX(2deg); }
.book-3d-front {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #8b1e3f 0%, #6b1530 100%);
  color: #fbf5e3;
  padding: 1.8rem 1.6rem 1.4rem;
  border-radius: 2px 6px 6px 2px;
  box-shadow:
    inset 2px 0 0 rgba(42, 31, 20, 0.2),
    inset -1px 0 0 rgba(251, 245, 227, 0.1),
    6px 14px 40px -8px rgba(42, 31, 20, 0.5);
  display: flex;
  flex-direction: column;
  transform: translateZ(22px);
}
.book-3d-eyebrow {
  margin: 0 0 1rem;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: rgba(251, 245, 227, 0.7);
}
.book-3d-title {
  margin: 0 0 0.8rem;
  font-size: clamp(2rem, 3.5vw, 2.8rem);
  line-height: 0.95;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: #fbf5e3;
}
.book-3d-accent {
  width: 48px;
  height: 3px;
  background: #fbf5e3;
  margin: 0 0 1rem;
}
.book-3d-subtitle {
  margin: 0 0 auto;
  font-family: var(--font-serif);
  font-size: 0.82rem;
  line-height: 1.35;
  font-style: italic;
  color: rgba(251, 245, 227, 0.85);
}
.book-3d-authors {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding-top: 0.8rem;
  margin-top: auto;
  border-top: 1px solid rgba(251, 245, 227, 0.25);
  font-size: 0.72rem;
  font-weight: 500;
  color: #fbf5e3;
}
.book-3d-version {
  margin: 0.5rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: rgba(251, 245, 227, 0.55);
  letter-spacing: 0.05em;
}
.book-3d-spine {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 44px;
  background: linear-gradient(to right, #4a0d1f, #6b1530);
  transform: rotateY(-90deg) translateZ(22px);
  transform-origin: left center;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px 0 0 2px;
}
.book-3d-spine span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  color: rgba(251, 245, 227, 0.75);
  font-weight: 500;
}
.book-3d-pages {
  position: absolute;
  top: 4px;
  right: 0;
  bottom: 4px;
  width: 44px;
  background:
    repeating-linear-gradient(to bottom, #fbf5e3 0px, #fbf5e3 1px, #e8dfc4 1px, #e8dfc4 2px);
  transform: rotateY(90deg) translateZ(22px);
  transform-origin: right center;
  box-shadow: inset -1px 0 0 rgba(42, 31, 20, 0.15);
}
@media (max-width: 720px) {
  .book-3d {
    transform: rotateY(-16deg) rotateX(3deg);
    width: 200px;
    height: 290px;
  }
}
.cover-illustration img {
  width: 100%;
  height: auto;
  display: block;
}
.cover-illustration figcaption {
  margin: 0.6rem 0 0;
  padding: 0.5rem 0 0;
  border-top: 1px solid var(--border);
  font-family: var(--font-serif);
  font-size: 0.82rem;
  font-style: italic;
  color: var(--text-muted);
  text-align: center;
}
@media (max-width: 720px) {
  .cover-illustration { max-width: 100%; padding: 0.8rem 0.6rem 0.4rem; }
}

/* Chapter header illustration */
.chapter-illustration {
  margin: 0 0 1.5rem;
  max-width: 260px;
}
.chapter-illustration img {
  width: 100%;
  height: auto;
  display: block;
}
@media (max-width: 720px) {
  .chapter-illustration { max-width: 180px; }
}

/* ============================================================
   Interactive elements: checklists, Q&A accordion, quizzes, jokes
   ============================================================ */

.checklist-progress {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent);
  letter-spacing: 0.03em;
  margin: 0.8em 0 0.3em;
  text-transform: uppercase;
}

ul.checklist {
  list-style: none;
  padding-left: 0;
  margin: 0.8em 0;
}
ul.checklist li.checklist-item {
  margin: 0.3em 0;
  text-indent: 0;
}
ul.checklist li.checklist-item label {
  display: flex;
  align-items: flex-start;
  gap: 0.6em;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  line-height: 1.5;
}
ul.checklist li.checklist-item input[type="checkbox"] {
  margin-top: 0.25em;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
ul.checklist li.checklist-item input:checked + span {
  color: var(--text-muted);
}

/* Q&A accordion */
details.qa-item {
  margin: 1em 0;
  padding: 0.7em 1em;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  text-indent: 0;
}
details.qa-item summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--accent-text);
  list-style: none;
  font-family: var(--font-sans);
  font-size: 1rem;
  padding: 0.3em 0;
  position: relative;
  padding-left: 1.6em;
}
details.qa-item summary::-webkit-details-marker { display: none; }
details.qa-item summary::before {
  content: "▸";
  position: absolute;
  left: 0;
  top: 0.3em;
  transition: transform 0.15s;
  color: var(--accent);
}
details.qa-item[open] summary::before {
  transform: rotate(90deg);
}
details.qa-item[open] summary {
  margin-bottom: 0.6em;
}

/* Joke insert */
aside.joke {
  margin: 1.2em 0;
  padding: 0.8em 1em;
  background: rgba(139, 30, 63, 0.05);
  border-left: 2px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--text-muted);
  text-indent: 0;
}
aside.joke .joke-body::before { content: "💬 "; margin-right: 0.3em; opacity: 0.6; }

/* Interactive scoring quiz (.quiz) */
.quiz {
  margin: 2em 0;
  padding: 1.8em 1.6em;
  background: var(--bg);
  border: 2px solid var(--border-strong);
  border-radius: var(--radius);
}
.quiz h3 {
  margin: 0 0 0.3em;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text);
}
.quiz-intro {
  margin: 0 0 1.5em;
  color: var(--text-muted);
  font-size: 0.92rem;
}
.quiz-question-card {
  margin: 0 0 1.2em;
  padding: 1em 1.1em;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.quiz-q {
  margin: 0 0 0.7em;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent-text);
}
.quiz-radio-option {
  display: flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.55em 0.8em;
  margin: 0.35em 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.93rem;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.quiz-radio-option:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.quiz-radio-option.is-selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.quiz-radio-option input[type="radio"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  cursor: pointer;
}
.quiz-submit {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.2em;
  padding: 0.8rem 1.5rem;
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}
.quiz-submit:hover:not(:disabled) { background: var(--accent-hover); }
.quiz-submit:active:not(:disabled) { transform: translateY(1px); }
.quiz-submit:disabled { opacity: 0.45; cursor: not-allowed; }
.quiz-result {
  margin-top: 1.2em;
  padding: 1.2em 1.3em;
  background: var(--accent-soft);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
}
.quiz-result-score {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 0.4em;
}
.quiz-result-title {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--accent-text);
  margin: 0 0 0.5em;
}
.quiz-result-description {
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.55;
}

/* Quiz (multi-choice) */
.quiz-block {
  margin: 1.5em 0;
  padding: 1.1em 1.2em;
  background: var(--bg-subtle);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  text-indent: 0;
}
.quiz-question {
  font-family: var(--font-sans);
  font-weight: 700;
  color: var(--accent-text);
  margin: 0 0 0.8em;
}
.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  list-style: none;
  padding: 0;
  margin: 0;
}
.quiz-option {
  padding: 0.6em 0.9em;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  transition: background 0.15s, border-color 0.15s;
}
.quiz-option:hover { background: var(--accent-soft); border-color: var(--accent); }
.quiz-option.is-correct { background: rgba(5, 150, 105, 0.12); border-color: #059669; }
.quiz-option.is-wrong { background: rgba(220, 38, 38, 0.12); border-color: #dc2626; }
.quiz-explanation {
  margin-top: 0.8em;
  padding: 0.6em 0.8em;
  background: var(--bg);
  border-left: 2px solid var(--accent);
  font-family: var(--font-serif);
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Плюсы/минусы маркеры (вместо emoji ✅/❌) */
.chapter-body .pro,
.chapter-body .con {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.3em;
  height: 1.3em;
  border-radius: 50%;
  font-size: 0.82em;
  font-weight: 700;
  line-height: 1;
  margin-right: 0.3em;
  vertical-align: middle;
}
.chapter-body .pro {
  background: rgba(46, 125, 50, 0.12);
  color: #2e7d32;
  border: 1.5px solid rgba(46, 125, 50, 0.3);
}
.chapter-body .con {
  background: rgba(198, 40, 40, 0.1);
  color: #c62828;
  border: 1.5px solid rgba(198, 40, 40, 0.25);
}
