:root {
  --bg: #faf7f2;
  --text: #1a1a1a;
  --muted: rgba(0,0,0,0.55);
  --accent: #6e9366;
  --accent-soft: color-mix(in srgb, #6e9366 12%, transparent);
  --sidebar-bg: #f2ede3;
  --border: #ddd6c8;
  --font: Georgia, serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --header-h: 56px;
  --nav-h: 56px;
}
[data-theme="dark"] {
  --bg: #1a1410;
  --text: #e8dcc8;
  --muted: rgba(255,255,255,0.55);
  --accent: color-mix(in srgb, #6e9366 70%, white);
  --accent-soft: color-mix(in srgb, #6e9366 18%, transparent);
  --sidebar-bg: #2a2018;
  --border: #3a2f25;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; padding: 0;
  font-family: var(--font);
  background: var(--bg); color: var(--text);
  line-height: 1.75; font-size: var(--reader-fs, 1.05rem);
  transition: background .3s, color .3s;
  padding-bottom: var(--nav-h);
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: url("/assets/textures/paper.svg");
  background-repeat: repeat;
  opacity: .5;
  mix-blend-mode: multiply;
}
[data-theme="dark"] body::before { opacity: .28; mix-blend-mode: screen; }
body > * { position: relative; z-index: 1; }

/* reading progress */
#readingProgress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 50%, white));
  z-index: 1100; transition: width .15s;
}

/* top bar */
.reader-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  display: flex; align-items: center; gap: .75rem;
  padding: 0 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.reader-header .book-title {
  flex: 1;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.control-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: .9rem; font-family: var(--font-ui);
  cursor: pointer;
  transition: background .2s, border-color .2s;
}
.control-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.home-btn { text-decoration: none; }
.controls { display: flex; gap: .35rem; }

/* sidebar */
.sidebar {
  position: fixed; top: 0; left: -340px;
  width: 320px; height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  z-index: 200;
  display: flex; flex-direction: column;
  transition: left .3s ease;
  overflow: hidden;
}
.sidebar.open { left: 0; }
.sidebar-head {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.sidebar-head h2 { font-size: 1.1rem; margin: 0 0 .25rem; font-family: var(--font); font-weight: 600; }
.sidebar-author { color: var(--accent); font-size: .85rem; font-family: var(--font-ui); }
.sidebar-close {
  position: absolute; top: .8rem; right: .8rem;
  width: 32px; height: 32px;
  background: transparent; border: 0;
  font-size: 1.4rem; color: var(--muted); cursor: pointer;
}
ol.toc {
  flex: 1; overflow-y: auto;
  list-style: none; margin: 0; padding: .5rem 0;
  font-family: var(--font-ui); font-size: .92rem;
}
ol.toc li { margin: 0; display: flex; align-items: stretch; }
ol.toc a {
  flex: 1;
  display: block;
  padding: .55rem 1rem .55rem 1.25rem;
  color: var(--text);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background .15s, border-color .15s;
}
ol.toc a:hover { background: var(--accent-soft); }
.toc-audio-btn {
  background: transparent;
  border: 0;
  color: var(--accent);
  font-size: 1rem;
  padding: 0 1rem;
  cursor: pointer;
  opacity: .5;
  transition: opacity .2s, background .2s;
}
.toc-audio-btn:hover { opacity: 1; background: var(--accent-soft); }
.toc-audio-btn.playing { opacity: 1; color: var(--accent); }
.chapter-audio-trigger {
  margin-top: 1rem;
  padding: .45rem .9rem;
  border: 1px solid var(--accent);
  border-radius: 22px;
  font-family: var(--font-ui);
  font-size: .85rem;
  display: inline-flex; align-items: center; gap: .35rem;
  color: var(--accent);
  background: transparent;
  cursor: pointer;
}
.chapter-audio-trigger:hover { background: var(--accent-soft); }
.chapter-audio-trigger.playing { background: var(--accent); color: white; }
ol.toc a.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
ol.toc .num { color: var(--muted); font-size: .85em; margin-right: .35rem; }
ol.toc .lock, ol.toc .preview { float: right; font-size: .85em; opacity: .7; }
.sidebar-footer {
  padding: .75rem 1.25rem;
  border-top: 1px solid var(--border);
  font-family: var(--font-ui); font-size: .9rem;
  display: flex; flex-direction: column; gap: .4rem;
}
.sidebar-link { color: var(--accent); text-decoration: none; padding: .25rem 0; }
.sidebar-link:hover { text-decoration: underline; }
.sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 199;
  opacity: 0; visibility: hidden;
  transition: opacity .3s, visibility .3s;
}
.sidebar-overlay.open { opacity: 1; visibility: visible; }

/* main */
.reader-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem;
}
.banner {
  width: 100%;
  max-height: 360px;
  object-fit: cover;
  border-radius: 8px;
  margin: 0 0 2rem;
}
/* iter4 drop-cap: велика декоративна перша літера */
.drop-cap::first-letter {
  float: left;
  font-family: var(--serif, Georgia, serif);
  font-size: 4.2em;
  line-height: .85;
  padding: .1em .12em 0 0;
  color: var(--accent, #8B2A2A);
  font-weight: 700;
}

.chapter-header {
  text-align: center;
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.chapter-position {
  font-family: var(--font-ui);
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: .78rem;
  color: var(--muted);
  margin-bottom: .5rem;
}
.chapter-title { font-size: 1.9rem; font-weight: normal; margin: 0; line-height: 1.2; }
.book-subtitle { font-size: 1.1rem; font-weight: normal; font-style: italic; color: var(--muted); margin: .5rem 0 0; }
.chapter-langs { margin-top: 1rem; display: flex; gap: .35rem; justify-content: center; }
/* iter6: мовний перемикач у верхньому навбарі */
.header-langs { display: inline-flex; gap: .3rem; align-items: center; }
.header-langs:empty { display: none; }
/* iter6: декоративний роздільник у кінці розділу */
.chapter-sep-mark {
  text-align: center;
  margin: 3rem 0 .5rem;
  font-size: 1.7rem;
  line-height: 1;
  color: var(--accent);
  letter-spacing: .35em;
  opacity: .65;
  user-select: none;
}
.lang-link {
  font-family: var(--font-ui);
  font-size: .82rem;
  padding: .25rem .55rem;
  border-radius: 14px;
  text-decoration: none;
  color: var(--muted);
  border: 1px solid var(--border);
}
.lang-link.active { background: var(--accent); color: white; border-color: var(--accent); }

.chapter-body p { margin: 0 0 1.4em; text-align: justify; hyphens: auto; }
.chapter-body p:first-of-type::first-letter {
  font-size: 3.2em;
  float: left; line-height: .9;
  padding-right: .15em; padding-top: .15em;
  font-weight: bold;
  color: var(--accent);
}
.chapter-body img { max-width: 100%; height: auto; display: block; margin: 1.5em auto; border-radius: 4px; }
.chapter-body blockquote {
  border-left: 3px solid var(--accent);
  padding: .25em 1em; margin: 1.5em 0;
  font-style: italic; color: var(--muted);
}
.chapter-body h2, .chapter-body h3 {
  font-family: var(--font); font-weight: normal;
  color: var(--accent); margin: 2em 0 .8em;
}
.chapter-body code { background: var(--accent-soft); padding: .1em .35em; border-radius: 3px; font-size: .9em; font-family: 'SF Mono', Menlo, Consolas, monospace; }
.chapter-body pre { background: var(--sidebar-bg); padding: 1em; border-radius: 6px; overflow-x: auto; font-family: 'SF Mono', Menlo, Consolas, monospace; font-size: .88em; }
.chapter-body pre code { background: none; padding: 0; }
.chapter-body table { border-collapse: collapse; width: 100%; margin: 1.5em 0; font-family: var(--font-ui); font-size: .92em; }
.chapter-body th, .chapter-body td { padding: .5em .75em; border: 1px solid var(--border); text-align: left; }
.chapter-body th { background: var(--sidebar-bg); }

.locked-stub, .locked-overlay {
  text-align: center;
  padding: 2rem 1rem;
  background: var(--sidebar-bg);
  border: 2px solid var(--accent);
  border-radius: 10px;
  margin-top: 2rem;
}
.locked-stub h3, .locked-overlay h3 { margin: 0 0 .6rem; color: var(--accent); }
.unlock-btn {
  display: inline-block;
  padding: .8rem 1.6rem;
  background: var(--accent);
  color: white;
  text-decoration: none;
  border-radius: 6px;
  font-family: var(--font-ui);
  font-weight: 600;
  margin-top: .8rem;
}

/* chapter nav (fixed bottom) */
.chapter-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1rem;
  background: var(--bg);
  border-top: 1px solid var(--border);
  z-index: 90;
  font-family: var(--font-ui);
  font-size: .9rem;
}
.nav-btn {
  display: inline-flex; align-items: center;
  padding: .5rem .9rem;
  border: 1px solid var(--border); border-radius: 6px;
  color: var(--accent); text-decoration: none;
  background: transparent;
  transition: background .2s, color .2s;
  max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nav-btn:hover:not(.disabled) { background: var(--accent); color: white; border-color: var(--accent); }
.nav-btn.disabled { opacity: .3; pointer-events: none; }
.chapter-pages { color: var(--muted); font-size: .85rem; }

/* audio player (fixed bottom above nav) */
.audio-player {
  position: fixed; bottom: calc(var(--nav-h) + .75rem); left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: .65rem;
  background: var(--sidebar-bg);
  border: 1px solid var(--accent);
  border-radius: 30px;
  padding: .5rem .9rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  z-index: 91;
  font-family: var(--font-ui); font-size: .85rem;
  max-width: calc(100% - 2rem);
}
.audio-player[hidden] { display: none; }
.audio-meta { display: flex; flex-direction: column; gap: .15rem; min-width: 140px; }
.audio-title { font-size: .8rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.audio-play-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent); color: white; border: 0;
  font-size: .9rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.audio-progress-container {
  width: 160px; height: 6px;
  background: var(--border); border-radius: 3px;
  cursor: pointer; overflow: hidden;
}
.audio-progress { height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.audio-time { color: var(--muted); white-space: nowrap; }
.audio-close-btn { background: transparent; border: 0; color: var(--muted); cursor: pointer; font-size: 1rem; }

/* floating donate */
.floating-donate-btn {
  position: fixed; bottom: calc(var(--nav-h) + 1rem); right: 1rem;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--accent); color: white;
  border: 0; cursor: pointer;
  font-size: 1.5rem;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
  display: flex; align-items: center; justify-content: center;
  z-index: 92;
  animation: gentleBob 3s ease-in-out infinite;
}
.donate-heart { display: inline-block; animation: heartbeat 1.6s ease-in-out infinite; }
@keyframes heartbeat { 0%,100% { transform: scale(1); } 50% { transform: scale(1.18); } }
@keyframes gentleBob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-2px); } }

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 300;
  opacity: 0; visibility: hidden;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  transition: opacity .25s, visibility .25s;
}
.modal.active { opacity: 1; visibility: visible; }
.modal-inner {
  background: var(--bg); color: var(--text);
  border-radius: 10px;
  padding: 2rem 1.75rem 1.75rem;
  max-width: 400px; width: 100%;
  text-align: center; position: relative;
  font-family: var(--font);
}
.modal-inner h3 { margin: 0 0 .8rem; color: var(--accent); }
.modal-close {
  position: absolute; top: .5rem; right: .5rem;
  width: 32px; height: 32px;
  background: transparent; border: 0;
  font-size: 1.4rem; color: var(--muted); cursor: pointer;
}
.modal-link { font-family: var(--font-ui); font-size: .8rem; color: var(--muted); word-break: break-all; margin-top: 1rem; }
.donate-qr { display: block; margin: 1rem auto; border: 8px solid white; border-radius: 6px; box-shadow: 0 0 0 1px var(--border); }
.donate-hint { font-family: var(--font-ui); font-size: .85rem; color: var(--muted); margin: .5rem 0 .8rem; }

@media (max-width: 700px) {
  .reader-main { padding: 1rem 1rem 2rem; }
  .chapter-title { font-size: 1.5rem; }
  .reader-header .book-title { font-size: .92rem; }
  .audio-progress-container { width: 100px; }
  .audio-time { display: none; }
}
@media (max-width: 460px) {
  .nav-btn { font-size: .82rem; padding: .4rem .65rem; }
  .audio-progress-container { width: 70px; }
}
@media print {
  .reader-header, .sidebar, .sidebar-overlay, .chapter-nav, .audio-player, .floating-donate-btn, .modal, #readingProgress { display: none !important; }
  body { padding: 0; }
}

/* iter6 крок 2 — атмосферні ефекти */
.fx-layer {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 90;
  overflow: hidden;
  opacity: 1;
  transition: opacity .6s ease;
}
.fx-layer.fx-off { opacity: 0; }
.fx-particle { position: absolute; top: -8%; will-change: transform; }
/* сніг */
.fx-snow .fx-particle { color: rgba(255,255,255,.85); animation: fxFall linear infinite; }
[data-theme="light"] .fx-snow .fx-particle { color: rgba(120,150,190,.6); }
@keyframes fxFall {
  0%   { transform: translateY(-10vh) translateX(0) rotate(0deg); }
  100% { transform: translateY(112vh) translateX(40px) rotate(360deg); }
}
/* дощ */
.fx-rain .fx-particle {
  width: 1px; height: 38px;
  background: linear-gradient(transparent, rgba(150,180,220,.55));
  animation: fxRain linear infinite;
}
@keyframes fxRain {
  0% { transform: translateY(-14vh); } 100% { transform: translateY(114vh); }
}
/* листя */
.fx-leaves .fx-particle { animation: fxLeaf linear infinite; }
@keyframes fxLeaf {
  0%   { transform: translateY(-10vh) translateX(0) rotate(0deg); }
  50%  { transform: translateY(52vh) translateX(-32px) rotate(140deg); }
  100% { transform: translateY(112vh) translateX(26px) rotate(280deg); }
}
/* іскри — рух угору */
.fx-embers .fx-particle {
  top: auto; bottom: -5%;
  color: rgba(255,150,60,.85);
  animation: fxRise linear infinite;
}
@keyframes fxRise {
  0%   { transform: translateY(0) translateX(0); opacity: 0; }
  15%  { opacity: .9; }
  100% { transform: translateY(-118vh) translateX(35px); opacity: 0; }
}
/* зорі — мерехтіння на місці */
.fx-stars .fx-particle { color: rgba(255,255,255,.9); animation: fxTwinkle ease-in-out infinite; }
[data-theme="light"] .fx-stars .fx-particle { color: rgba(90,110,160,.7); }
@keyframes fxTwinkle {
  0%, 100% { opacity: .12; transform: scale(.8); }
  50%      { opacity: 1; transform: scale(1.25); }
}
@media (prefers-reduced-motion: reduce) { .fx-layer { display: none; } }