/* Палитра «эвкалипт и слива» */
:root {
  --bg: #F5F7F3;
  --surface: #E9EEE8;
  --ink: #1E2925;
  --muted: #5D6A64;
  --line: #D3DCD5;
  --accent: #4C7A6B;
  --accent-soft: #DCE8E2;
  --plum: #8E5672;
  --plum-soft: #F2E6EC;
  --focus: #2F6F5C;
  --serif: "Literata", Georgia, "Times New Roman", serif;
  --sans: "Manrope", -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs: 17px;
  --bar-h: 52px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #131A17;
  --surface: #1C2521;
  --ink: #E5ECE8;
  --muted: #9AA9A2;
  --line: #2B3732;
  --accent: #8CC0AE;
  --accent-soft: #22322C;
  --plum: #D49AB6;
  --plum-soft: #2E2229;
  --focus: #A6D4C4;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

/* ---------- защита содержимого ---------- */
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, textarea { -webkit-user-select: text; user-select: text; }
#wm { position: fixed; inset: 0; z-index: 45; pointer-events: none; opacity: .24; background-repeat: repeat; }
:root[data-theme="dark"] #wm { opacity: .3; }
.concealed #app, .concealed #sheet { filter: blur(18px); }

.wrap { max-width: 680px; margin: 0 auto; padding: 0 18px; }

/* ---------- полоса чтения ---------- */
.progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 30; pointer-events: none; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .12s linear; }

/* ---------- главная ---------- */
.home-head { padding: 28px 0 8px; }
.home-head h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0 0 6px;
}
.home-head p { margin: 0; color: var(--muted); font-size: 15px; }

.search {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding: 14px 0 10px;
}
.search label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.search input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 12px 14px 12px 40px;
  font-size: 16px;
  outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%235D6A64' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='8' cy='8' r='6'/%3E%3Cpath d='m16.5 16.5-4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 13px center;
}
.search input:focus { border-color: var(--accent); }

.resume {
  display: block; width: 100%; text-align: left;
  margin: 8px 0 4px;
  padding: 14px 16px;
  border: 0; border-left: 3px solid var(--plum);
  background: var(--plum-soft);
  border-radius: 4px 12px 12px 4px;
}
.resume small { display: block; color: var(--muted); font-size: 13px; margin-bottom: 2px; }
.resume strong { font-family: var(--serif); font-weight: 600; font-size: 17px; }
.resume span { display: block; color: var(--muted); font-size: 14px; margin-top: 2px; }

.part { margin-top: 26px; }
.part h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 19px;
  margin: 0 0 4px;
  color: var(--accent);
}
.part h2 small { display: block; font-family: var(--sans); font-weight: 600; font-size: 13px; color: var(--muted); }
.mod-list { list-style: none; margin: 0; padding: 0; }
.mod-link {
  display: grid; grid-template-columns: 34px 1fr; gap: 0 10px;
  width: 100%; text-align: left;
  padding: 13px 0; border: 0; background: none;
  border-bottom: 1px solid var(--line);
}
.mod-list li:last-child .mod-link { border-bottom: 0; }
.mod-link .n { font-family: var(--serif); font-size: 17px; color: var(--muted); padding-top: 1px; font-variant-numeric: lining-nums tabular-nums; }
.mod-link .t { font-weight: 600; font-size: 16px; line-height: 1.35; }
.mod-link .d {
  grid-column: 2; color: var(--muted); font-size: 14px; line-height: 1.4; margin-top: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.mod-link:active { background: var(--surface); }
.foot { color: var(--muted); font-size: 13px; padding: 28px 0 40px; }

/* ---------- поиск ---------- */
.results { list-style: none; padding: 0; margin: 4px 0 40px; }
.results li button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.results .where { font-size: 13px; color: var(--accent); font-weight: 600; }
.results .sec { font-weight: 600; margin: 2px 0; }
.results .snip { font-size: 14px; color: var(--muted); }
.results mark { background: var(--accent-soft); color: inherit; border-radius: 3px; padding: 0 2px; }
.empty { color: var(--muted); padding: 18px 0; }

/* ---------- модуль ---------- */
.bar {
  position: sticky; top: 0; z-index: 10;
  height: var(--bar-h);
  display: flex; align-items: center; gap: 6px;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.bar.scrolled { border-bottom-color: var(--line); }
.bar .bar-title {
  flex: 1; min-width: 0;
  font-weight: 600; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; transition: opacity .2s;
}
.bar.scrolled .bar-title { opacity: 1; }
.icon-btn {
  flex: none; height: 38px; min-width: 38px; padding: 0 10px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  font-weight: 600; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.icon-btn svg { width: 18px; height: 18px; }
#home-btn { color: var(--accent); }
.bar.scrolled #home-btn { font-size: 0; gap: 0; } /* при прокрутке остаётся только значок, место — заголовку */

/* ---------- нижняя панель навигации по главам ---------- */
.reading { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: 56px 1fr 56px; gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.dock button {
  height: 48px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
}
.dock button:active { background: var(--accent-soft); }
.dock button[disabled] { opacity: .35; cursor: default; }
.dock svg { width: 20px; height: 20px; flex: none; }
.dock-side { color: var(--accent); }
.dock-home { color: var(--accent); font-weight: 700; font-size: 15px; }
.dock-home span { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.dock-home small { color: var(--muted); font-weight: 600; font-size: 12px; }
@media (min-width: 720px) { .dock { padding-inline: calc(50% - 340px + 18px); } }

.mod-head { padding: 10px 0 18px; }
.mod-num {
  font-family: var(--serif);
  font-size: 72px; line-height: .9;
  font-weight: 400;
  color: var(--accent);
  opacity: .35;
  font-variant-numeric: lining-nums;
  letter-spacing: -0.03em;
}
.mod-of { color: var(--muted); font-size: 13px; font-weight: 600; margin-top: 6px; }
.mod-head h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 28px; line-height: 1.18;
  letter-spacing: -0.01em;
  margin: 6px 0 10px;
}
.mod-head .lead { color: var(--muted); font-size: 15.5px; margin: 0; }

.toc-inline { margin: 6px 0 8px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.toc-inline > summary {
  list-style: none; cursor: pointer;
  padding: 13px 0; font-weight: 600; font-size: 15px;
  display: flex; justify-content: space-between; align-items: center;
}
.toc-inline > summary::-webkit-details-marker { display: none; }
.toc-inline > summary::after { content: "+"; font-size: 20px; color: var(--accent); font-weight: 500; }
.toc-inline[open] > summary::after { content: "–"; }

.sec-list { list-style: none; margin: 0 0 10px; padding: 0; }
.sec-list button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 8px 0; font-size: 15px; line-height: 1.35; color: var(--ink);
}
.sec-list button.current { color: var(--accent); font-weight: 600; }

/* ---------- текст статьи ---------- */
.article {
  font-family: var(--serif);
  font-size: var(--fs);
  line-height: 1.68;
  padding-bottom: 12px;
  hyphens: auto; -webkit-hyphens: auto;
  overflow-wrap: break-word;
}
.article h2 {
  font-size: 1.32em; line-height: 1.25; font-weight: 600;
  margin: 2.1em 0 .6em;
  scroll-margin-top: calc(var(--bar-h) + 12px);
}
.article h3 {
  font-size: 1.1em; line-height: 1.3; font-weight: 600;
  margin: 1.7em 0 .5em;
  scroll-margin-top: calc(var(--bar-h) + 12px);
}
.article h4 { font-size: 1em; margin: 1.4em 0 .4em; }
.article p { margin: 0 0 .85em; }
.article ul, .article ol { margin: 0 0 1em; padding-left: 1.25em; }
.article li { margin: .25em 0; }
.article li::marker { color: var(--accent); }
.article strong { font-weight: 600; }
.article hr { border: 0; height: 1px; background: var(--line); margin: 2em 0; }
.article a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.article blockquote {
  margin: 1.2em 0; padding: .3em 0 .3em 1em;
  border-left: 3px solid var(--plum); color: var(--ink); font-style: italic;
}
.article pre {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px; line-height: 1.5;
  background: var(--surface); padding: 12px 14px; border-radius: 10px;
  overflow-x: auto; hyphens: none;
}
.article li.check { list-style: none; position: relative; }
.article li.check .box {
  display: inline-block; width: .9em; height: .9em; margin: 0 .5em -.1em -1.25em;
  border: 1.5px solid var(--accent); border-radius: 4px;
}
.table-wrap {
  margin: 1em -18px 1.3em; padding: 0 18px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.article table {
  border-collapse: collapse; font-family: var(--sans);
  font-size: 14px; line-height: 1.45; min-width: 100%;
  hyphens: none;
}
.article th, .article td {
  text-align: left; vertical-align: top;
  padding: 9px 10px; border-bottom: 1px solid var(--line);
  min-width: 110px; max-width: 260px;
}
.article th { font-weight: 700; background: var(--surface); }
.article th:first-child, .article td:first-child { padding-left: 0; }
.article thead th:first-child { padding-left: 10px; border-radius: 8px 0 0 0; }

/* выводы — акцентным цветом */
.article h2.takeaways { color: var(--plum); }
.article h2.takeaways + ol, .article h2.takeaways + ul {
  background: var(--plum-soft); border-radius: 12px;
  padding: 14px 16px 14px 2.2em;
}
.article h2.takeaways + ol li::marker { color: var(--plum); }

/* схемы (встроенный SVG в тексте главы) */
.article figure.fig { margin: 1.2em 0 1.4em; padding: 14px 12px 10px; background: var(--surface); border-radius: 12px; }
.article .fig svg { display: block; width: 100%; height: auto; max-width: 560px; margin: 0 auto; font-family: var(--sans); }
.article .fig figcaption { font-family: var(--sans); font-size: 13px; line-height: 1.45; color: var(--muted); text-align: center; margin-top: 8px; }
.fig .t { fill: var(--ink); font-size: 13px; }
.fig .ts { fill: var(--muted); font-size: 11px; }
.fig .tb { fill: var(--ink); font-size: 14px; font-weight: 700; }
.fig .acc { fill: var(--accent); } .fig .accs { fill: var(--accent-soft); }
.fig .plum { fill: var(--plum); } .fig .plums { fill: var(--plum-soft); }
.fig .bg { fill: var(--bg); }
.fig .ln { stroke: var(--line); fill: none; } .fig .lm { stroke: var(--muted); fill: none; }
.fig .la { stroke: var(--accent); fill: none; } .fig .lp { stroke: var(--plum); fill: none; }

/* источники и дисклеймер */
.article .note { font-family: var(--sans); font-size: 13px; color: var(--muted); line-height: 1.5; }

.pager { display: grid; gap: 10px; padding: 18px 0 44px; }
.pager button {
  text-align: left; padding: 14px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
}
.pager small { display: block; color: var(--muted); font-size: 13px; }
.pager strong { font-family: var(--serif); font-weight: 600; font-size: 16px; }

/* ---------- нижняя панель (содержание, размер текста) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 16, 14, .45); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 78vh; overflow-y: auto;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .18);
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet .grip { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { font-family: var(--serif); font-weight: 600; font-size: 20px; margin: 0 0 8px; }
.sizes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 8px 0 18px; }
.sizes button {
  height: 48px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  font-family: var(--serif);
}
.sizes button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- экраны доступа и загрузки ---------- */
.gate { min-height: 88vh; display: flex; flex-direction: column; justify-content: center; padding-block: 30px; }
.gate .mark {
  font-family: var(--serif); font-size: 64px; line-height: 1; color: var(--accent); opacity: .35; margin-bottom: 10px;
}
.gate h1 { font-family: var(--serif); font-weight: 600; font-size: 26px; line-height: 1.2; margin: 0 0 10px; }
.gate p { color: var(--muted); margin: 0 0 20px; max-width: 34em; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 50px; padding: 0 22px; border-radius: 12px; border: 0;
  background: var(--accent); color: var(--bg); font-weight: 700; font-size: 16px;
}
.btn.secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn[disabled] { opacity: .6; }
.gate .actions { display: flex; gap: 10px; flex-wrap: wrap; }

.skeleton { padding-top: 34px; padding-inline: 18px; }
.skeleton i { display: block; height: 14px; border-radius: 7px; background: var(--surface); margin: 12px 0; }
.skeleton i:nth-child(1) { width: 55%; height: 26px; }
.skeleton i:nth-child(3) { width: 85%; }
.skeleton i:nth-child(4) { width: 70%; }

.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 50;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (min-width: 720px) {
  .home-head h1 { font-size: 36px; }
  .mod-head h1 { font-size: 34px; }
}

/* ---------- пометки «!» (рецензент) ---------- */
.flag-btn[aria-pressed="true"] { background: var(--plum); color: #fff; border-radius: 10px; }
.flagging .article :is(p, li, h2, h3, h4, blockquote, table, figure, .fig) { cursor: pointer; border-radius: 6px; transition: background .15s; }
.flagging .article :is(p, li, h2, h3, h4, blockquote, table, figure, .fig):hover { background: var(--plum-soft); }
.flagging .bar { box-shadow: inset 0 -3px 0 var(--plum); }
.article .flagged { position: relative; background: var(--plum-soft); border-radius: 6px; box-shadow: -10px 0 0 var(--plum-soft), 10px 0 0 var(--plum-soft); }
.article .flagged::before {
  content: "!"; position: absolute; left: -8px; top: -9px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--plum); color: #fff; font: 800 13px/20px var(--sans); text-align: center;
}
.flag-quote { margin: 4px 0 12px; padding: 10px 12px; background: var(--surface); border-left: 3px solid var(--plum); border-radius: 8px; font-size: 14px; color: var(--muted); }
.flag-text {
  width: 100%; border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 12px;
  padding: 10px 12px; font: inherit; font-size: 16px; resize: vertical; user-select: text; -webkit-user-select: text;
}
.flag-text:focus { outline: none; border-color: var(--plum); }
.flag-actions { display: grid; gap: 8px; margin-top: 12px; }
.flag-list-btn {
  display: block; width: 100%; text-align: left; margin: 4px 0 14px; padding: 12px 14px; border-radius: 14px;
  border: 1px solid var(--plum); background: var(--plum-soft); color: var(--plum); font: 700 15px var(--sans); cursor: pointer;
}
.flag-list-btn small { display: block; font-weight: 600; font-size: 12px; color: var(--muted); margin-top: 2px; }
.flag-list { list-style: none; margin: 0; padding: 0; }
.flag-list button { display: grid; gap: 3px; width: 100%; text-align: left; padding: 10px 0; border: 0; border-bottom: 1px solid var(--line); background: none; color: inherit; font: inherit; cursor: pointer; }
.flag-list .where { font-size: 13px; color: var(--accent); font-weight: 700; }
.flag-list .quote { font-size: 14px; color: var(--muted); }
.flag-list .comment { font-size: 14px; color: var(--plum); font-weight: 600; }

/* «🎧 Слушать главу» под заголовком главы */
.listen-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  margin-top: 14px; padding: 10px 16px; border: 1px solid var(--accent); border-radius: 12px;
  background: var(--accent-soft); color: var(--accent); font: inherit; font-weight: 600; font-size: 15px; cursor: pointer;
}
.listen-btn small { font-weight: 400; font-size: 12.5px; color: var(--muted); }
.listen-btn:disabled { opacity: .75; cursor: default; }
.part-listen { margin: 6px 0 12px; padding: 7px 12px; font-size: 14px; }
