/* ============================================================
   «Ньиэдьиипэлэк уөрпэҥин» — HTML-версия книги
   Стили: тёплая бумага, золото, киноварь; тонкая навигация
   ============================================================ */

:root {
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "PT Serif", Georgia, "Times New Roman", serif;
  --sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;

  --bg: #efe4cd;
  --bg-2: #e4d6b9;
  --paper: #fbf6ea;
  --paper-2: #f3ead7;
  --ink: #2b251d;
  --ink-2: #6a5c48;
  --ink-3: #94846b;
  --red: #b03527;
  --red-2: #8b2a1e;
  --gold: #b08a44;
  --gold-2: #d8bf8c;
  --line: rgba(97, 74, 38, .16);
  --line-strong: rgba(97, 74, 38, .30);
  --book-edge: #f7eeda;
  --book-border: rgba(150, 118, 66, .40);
  --shadow-deep: 0 34px 70px -34px rgba(70, 48, 15, .50);
  --page-filter: none;
  --dash: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='7'%3E%3Cpath d='M7 .8 13 3.5 7 6.2 1 3.5Z' fill='none' stroke='%23b08a44' stroke-width='.7'/%3E%3C/svg%3E");
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.86' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E");
}

[data-theme="dark"] {
  --bg: #131110;
  --bg-2: #1d1915;
  --paper: #221e18;
  --paper-2: #2a251d;
  --ink: #efe6d4;
  --ink-2: #c0b198;
  --ink-3: #8f8069;
  --red: #d4624f;
  --red-2: #e5806d;
  --gold: #c9a45c;
  --gold-2: #7d6840;
  --line: rgba(232, 214, 180, .14);
  --line-strong: rgba(232, 214, 180, .28);
  --book-edge: #2a251d;
  --book-border: rgba(201, 164, 92, .32);
  --shadow-deep: 0 34px 80px -30px rgba(0, 0, 0, .85);
  --page-filter: brightness(.94) contrast(1.01);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--sans);
  background:
    radial-gradient(1100px 640px at 50% -10%, rgba(255, 252, 243, .88), transparent 62%),
    radial-gradient(900px 700px at 106% 110%, rgba(210, 189, 150, .62), transparent 58%),
    radial-gradient(760px 620px at -8% 104%, rgba(222, 203, 166, .52), transparent 60%),
    linear-gradient(158deg, var(--bg), var(--bg-2));
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[data-theme="dark"] body {
  background:
    radial-gradient(1000px 600px at 50% -8%, rgba(120, 92, 48, .20), transparent 60%),
    radial-gradient(900px 700px at 106% 110%, rgba(90, 66, 30, .28), transparent 58%),
    linear-gradient(158deg, var(--bg), var(--bg-2));
}

::selection { background: rgba(176, 53, 39, .22); }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: .045;
  background-image: var(--grain);
  mix-blend-mode: multiply;
}
[data-theme="dark"] .grain { opacity: .07; mix-blend-mode: screen; }

.ic {
  width: 18px;
  height: 18px;
  display: block;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

button { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

/* Декоративная пунктирная орнаментная линия */
.ornament {
  height: 7px;
  background-image: var(--dash);
  background-size: 14px 7px;
  background-repeat: repeat-x;
  background-position: center;
  opacity: .75;
}
.ornament--tiny { width: 86px; margin: 0 auto 5px; opacity: .6; }

/* ============================ Верхняя панель ============================ */

.topbar {
  position: relative;
  z-index: 20;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  height: 66px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(251, 246, 234, .72), rgba(251, 246, 234, .18));
  backdrop-filter: blur(10px);
}
[data-theme="dark"] .topbar {
  background: linear-gradient(180deg, rgba(34, 30, 24, .82), rgba(34, 30, 24, .25));
}

.brand {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 4px 4px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.brand:hover { background: rgba(176, 138, 68, .10); }

.brand__monogram {
  width: 36px;
  height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid var(--gold);
  border-radius: 50%;
  color: var(--red);
  font-family: var(--serif);
  font-size: 12.5px;
  letter-spacing: .04em;
  box-shadow: 0 0 0 3px rgba(176, 138, 68, .07) inset;
}
.brand__text { display: flex; flex-direction: column; line-height: 1.15; }
.brand__name {
  font-family: var(--serif);
  font-size: 13.5px;
  letter-spacing: .02em;
  color: var(--ink);
}
.brand__year {
  font-size: 9px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-top: 2px;
}

.masthead { text-align: center; min-width: 0; padding: 0 4px; }
.masthead__title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(16px, 1.75vw, 21px);
  letter-spacing: .02em;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.masthead__sub {
  margin: 3px 0 0;
  font-size: 9.5px;
  letter-spacing: .24em;
  text-transform: uppercase;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.masthead__sub .dot { color: var(--gold); margin: 0 2px; }

.tools { justify-self: end; display: flex; align-items: center; gap: 2px; }

.tool {
  position: relative;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  transition: color .18s, background .18s, border-color .18s, transform .18s;
}
.tool:hover {
  color: var(--ink);
  background: rgba(176, 138, 68, .12);
  border-color: var(--line);
}
.tool[aria-pressed="true"] {
  color: var(--red);
  border-color: var(--line-strong);
  background: rgba(176, 53, 39, .08);
}
.tool:disabled { opacity: .3; cursor: default; }
.tool.is-active { color: var(--red); }

.tool .ic--sun, .tool .ic--moon { position: absolute; transition: opacity .2s, transform .3s; }
.tool .ic--moon { opacity: 0; transform: rotate(-35deg) scale(.8); }
[data-theme="dark"] .tool .ic--sun { opacity: 0; transform: rotate(35deg) scale(.8); }
[data-theme="dark"] .tool .ic--moon { opacity: 1; transform: none; }

.tool--fs .ic--contract { display: none; }
:fullscreen .tool--fs .ic--expand { display: none; }
:fullscreen .tool--fs .ic--contract { display: block; }

.tool__badge {
  position: absolute;
  bottom: -3px;
  right: -3px;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: .02em;
  background: var(--red);
  color: #fff6e8;
  border-radius: 999px;
  padding: 1px 4px;
  line-height: 1.2;
}

/* ============================ Сцена ============================ */

.stage {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 88px 8px;
  overflow: auto;
  scrollbar-width: thin;
}
.stage::-webkit-scrollbar { width: 10px; height: 10px; }
.stage::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; }

.chipbar {
  position: absolute;
  z-index: 6;
  top: 7px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 28px);
  display: flex;
  justify-content: center;
  pointer-events: none;
}
.chipbar:empty { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(251, 246, 234, .78);
  backdrop-filter: blur(12px);
  box-shadow: 0 12px 30px -20px rgba(60, 40, 10, .55);
  font-size: 13px;
  pointer-events: auto;
  max-width: 100%;
  animation: chipIn .35s ease both;
}
[data-theme="dark"] .chip { background: rgba(38, 33, 26, .82); }

@keyframes chipIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

.chip__kicker {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .17em;
  text-transform: uppercase;
  color: var(--ink-3);
  white-space: nowrap;
}
.chip__title {
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 44ch;
}
.chip__sep {
  width: 4px;
  height: 4px;
  flex: none;
  background: var(--gold);
  transform: rotate(45deg);
  opacity: .75;
}
.chip__actions { display: flex; align-items: center; gap: 2px; }
.chip__link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0;
  border-radius: 999px;
  padding: 7px 10px;
  background: transparent;
  color: var(--red);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .01em;
  cursor: pointer;
  white-space: nowrap;
}
.chip__link:hover { background: rgba(176, 53, 39, .09); }
.chip__play {
  width: 29px;
  height: 29px;
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--red);
  color: #fff7ea;
  cursor: pointer;
  transition: background .18s, transform .18s;
}
.chip__play:hover { background: var(--red-2); transform: scale(1.05); }
.chip__play .ic { width: 13px; height: 13px; margin-left: 1px; }

.bookwrap {
  position: relative;
  margin: auto;
  display: grid;
  place-items: center;
  flex: none;
}

.book {
  --ph: min(calc(100dvh - 200px), calc((100vw - 196px) * 1.41421));
  position: relative;
  display: flex;
  padding: 9px;
  border: 1px solid var(--book-border);
  border-radius: 5px;
  background: linear-gradient(180deg, var(--book-edge), var(--paper-2));
  box-shadow:
    0 1px 0 rgba(255, 255, 255, .55) inset,
    0 2px 4px rgba(70, 48, 15, .10),
    0 22px 44px -22px rgba(70, 48, 15, .42),
    0 60px 100px -55px rgba(70, 48, 15, .55);
  transform: translateZ(0);
}
[data-theme="dark"] .book {
  box-shadow:
    0 1px 0 rgba(255, 255, 255, .06) inset,
    0 2px 4px rgba(0, 0, 0, .4),
    0 22px 44px -22px rgba(0, 0, 0, .55),
    0 60px 100px -55px rgba(0, 0, 0, .8);
}

/* стопка страниц под книгой */
.bookwrap::before {
  content: "";
  position: absolute;
  inset: 5px -5px -7px -5px;
  z-index: 0;
  border-radius: 6px;
  background: var(--book-edge);
  border: 1px solid var(--book-border);
  opacity: .85;
  box-shadow: var(--shadow-deep);
}

.book.is-spread { --ph: min(calc(100dvh - 200px), calc((100vw - 240px) * 0.70711)); }

.book.is-spread::after {
  content: "";
  position: absolute;
  top: 9px;
  bottom: 9px;
  left: 50%;
  width: 46px;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 3;
  background: linear-gradient(90deg,
    transparent,
    rgba(58, 40, 12, .10) 34%,
    rgba(58, 40, 12, .24) 50%,
    rgba(58, 40, 12, .10) 66%,
    transparent);
}
[data-theme="dark"] .book.is-spread::after {
  background: linear-gradient(90deg, transparent, rgba(0, 0, 0, .35) 50%, transparent);
}

.sheet {
  position: relative;
  height: var(--ph);
  aspect-ratio: 1131 / 1600;
  overflow: hidden;
  background: var(--book-edge);
}
.sheet[hidden] { display: none; }
.sheet::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(100deg, #f4ead4 28%, #fbf6ea 48%, #f1e6cf 72%);
  background-size: 220% 100%;
  animation: shimmer 1.4s linear infinite;
  opacity: 0;
  transition: opacity .25s;
}
.sheet.is-loading::after { opacity: 1; }
@keyframes shimmer {
  from { background-position: 120% 0; }
  to { background-position: -120% 0; }
}
.sheet__img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: var(--page-filter);
  opacity: 0;
  transition: opacity .28s ease;
}
.sheet.is-ready .sheet__img { opacity: 1; }
.sheet__img[src=""] { opacity: 0; }

.book.turn-next { animation: turnNext .38s cubic-bezier(.22, .8, .3, 1); }
.book.turn-prev { animation: turnPrev .38s cubic-bezier(.22, .8, .3, 1); }
@keyframes turnNext {
  from { opacity: .25; transform: translateX(16px) scale(.995); }
  to { opacity: 1; transform: none; }
}
@keyframes turnPrev {
  from { opacity: .25; transform: translateX(-16px) scale(.995); }
  to { opacity: 1; transform: none; }
}

.arrow {
  position: absolute;
  z-index: 5;
  top: 50%;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: rgba(251, 246, 234, .62);
  backdrop-filter: blur(10px);
  color: var(--ink-2);
  cursor: pointer;
  box-shadow: 0 12px 26px -18px rgba(60, 40, 10, .55);
  transition: background .2s, color .2s, border-color .2s, transform .2s, opacity .2s;
}
[data-theme="dark"] .arrow { background: rgba(38, 33, 26, .68); }
.arrow--prev { left: clamp(8px, 3.4vw, 46px); transform: translateY(-50%); }
.arrow--next { right: clamp(8px, 3.4vw, 46px); transform: translateY(-50%); }
.arrow:hover:not(:disabled) {
  background: var(--red);
  border-color: var(--red);
  color: #fff7ea;
  transform: translateY(-50%) scale(1.06);
}
.arrow:active:not(:disabled) { transform: translateY(-50%) scale(.97); }
.arrow:disabled { opacity: .22; cursor: default; }
.arrow .ic { width: 22px; height: 22px; }

.stage__hint {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  font-size: 10.5px;
  letter-spacing: .04em;
  color: var(--ink-3);
  opacity: .8;
  pointer-events: none;
  transition: opacity .8s ease;
  white-space: nowrap;
}
.stage__hint.is-faded { opacity: 0; }

/* ============================ Нижняя панель ============================ */

.dock {
  position: relative;
  z-index: 20;
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding: 0 14px 11px;
}

.dock__inner {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(251, 246, 234, .82);
  backdrop-filter: blur(16px);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, .5) inset,
    0 20px 44px -26px rgba(60, 40, 10, .55);
}
[data-theme="dark"] .dock__inner { background: rgba(36, 31, 24, .85); }

.dockbtn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .01em;
  cursor: pointer;
  transition: background .18s, color .18s;
}
.dockbtn:hover { background: rgba(176, 138, 68, .13); color: var(--ink); }
.dockbtn .ic { width: 17px; height: 17px; }
.dockbtn--icon { width: 38px; padding: 0; justify-content: center; }
.dockbtn:disabled { opacity: .3; cursor: default; background: transparent; }

.counter {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  height: 38px;
  padding: 0 7px;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--ink);
  border-radius: 999px;
}
.counter:hover { background: rgba(176, 138, 68, .13); }
.counter__cur { font-family: var(--serif); font-size: 16.5px; font-variant-numeric: tabular-nums; }
.counter__tot { font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.dock__sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; flex: none; }
.scrub { width: 152px; padding: 0 6px; display: flex; align-items: center; }

.dock__progress {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--line);
  z-index: 30;
  pointer-events: none;
}
.dock__progress span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--gold), var(--red));
  transition: width .35s ease;
}

/* ============================ Ползунки ============================ */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 20px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--gold) var(--fill, 0%), var(--line) var(--fill, 0%));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--gold);
  box-shadow: 0 1px 4px rgba(40, 25, 5, .25);
  transition: transform .15s;
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.15); }
input[type="range"]::-moz-range-track {
  height: 3px;
  border-radius: 2px;
  background: var(--line);
}
input[type="range"]::-moz-range-progress {
  height: 3px;
  border-radius: 2px;
  background: var(--gold);
}
input[type="range"]::-moz-range-thumb {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--gold);
}

/* ============================ Шторка ============================ */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(26, 18, 6, .42);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity .3s ease;
}
.scrim.is-open { opacity: 1; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  width: min(432px, 100vw);
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line-strong);
  background:
    linear-gradient(180deg, rgba(176, 138, 68, .05), transparent 130px),
    var(--paper);
  box-shadow: -30px 0 80px -46px rgba(40, 25, 5, .6);
  transform: translateX(102%);
  transition: transform .38s cubic-bezier(.22, .85, .28, 1);
  visibility: hidden;
}
.drawer.is-open { transform: none; visibility: visible; }

.drawer__head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 14px 10px 16px;
  border-bottom: 1px solid var(--line);
}

.tabs {
  flex: 1;
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: rgba(176, 138, 68, .12);
}
.tab {
  flex: 1;
  height: 30px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .02em;
  cursor: pointer;
  transition: background .2s, color .2s, box-shadow .2s;
}
.tab:hover { color: var(--ink); }
.tab.is-active {
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(60, 40, 10, .14);
}
[data-theme="dark"] .tab.is-active { background: var(--paper-2); }
.tab:focus-visible { outline-offset: 1px; }

.drawer__close {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}
.drawer__close:hover { background: rgba(176, 138, 68, .13); color: var(--ink); }

.drawer__body { flex: 1; overflow-y: auto; padding: 14px 16px 26px; overscroll-behavior: contain; }
.drawer__body::-webkit-scrollbar { width: 10px; }
.drawer__body::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; }
.drawer__body::-webkit-scrollbar-track { background: transparent; }

.drawer__foot {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 10.5px;
  letter-spacing: .02em;
}
.linkbtn {
  border: 0;
  background: transparent;
  color: var(--red);
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 3px 4px;
  border-radius: 4px;
}
.linkbtn:hover { text-decoration: underline; }

.panel[hidden] { display: none; }
.panel__lead { margin: 2px 0 14px; color: var(--ink-3); font-size: 11.5px; line-height: 1.55; }

/* ------------------------------- поиск ------------------------------- */

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin-bottom: 4px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(176, 138, 68, .06);
  color: var(--ink-3);
  transition: border-color .2s, background .2s;
}
.search:focus-within { border-color: var(--gold); background: rgba(176, 138, 68, .10); }
.search .ic { width: 16px; height: 16px; flex: none; }
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  outline: none;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
}
.search input::placeholder { color: var(--ink-3); }
.search input::-webkit-search-cancel-button { display: none; }
.search__clear {
  width: 22px;
  height: 22px;
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
}
.search__clear[hidden] { display: none; }
.search__clear:hover { color: var(--ink); background: rgba(0, 0, 0, .06); }
.search__clear .ic { width: 13px; height: 13px; }

.results { border-bottom: 1px solid var(--line); margin: 4px 0 10px; padding-bottom: 6px; max-height: 46vh; overflow: auto; }
.results__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.result {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 8px;
  background: transparent;
  padding: 7px 8px;
  cursor: pointer;
}
.result:hover { background: rgba(176, 138, 68, .12); }
.result__n {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--red);
  margin-bottom: 2px;
}
.result__t { font-size: 12px; line-height: 1.5; color: var(--ink-2); }
.result__t mark { background: rgba(176, 53, 39, .16); color: var(--ink); border-radius: 2px; padding: 0 1px; }
.results__empty { padding: 10px 8px 14px; font-size: 12px; color: var(--ink-3); line-height: 1.5; }

/* ------------------------------- содержание ------------------------------- */

.toc h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 20px 0 4px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.toc h2:first-child { margin-top: 8px; }
.toc h2::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--line), transparent);
}
.toc__hint { margin: 0 0 6px; font-size: 11px; color: var(--ink-3); }

.story {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 8px 8px;
  border-radius: 9px;
  transition: background .16s;
}
.story:hover { background: rgba(176, 138, 68, .09); }
.story.is-current { background: rgba(176, 53, 39, .06); }
.story__num {
  width: 21px;
  flex: none;
  padding-top: 3px;
  font-family: var(--serif);
  font-size: 12.5px;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.story.is-current .story__num { color: var(--red); }
.story__body { flex: 1; min-width: 0; }
.story__row { display: flex; align-items: baseline; gap: 8px; }
.story__title {
  border: 0;
  padding: 0;
  background: transparent;
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 1.25;
  letter-spacing: .005em;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  min-width: 0;
}
.story__title:hover { color: var(--red); }
.story__range {
  margin-left: auto;
  flex: none;
  font-size: 10px;
  letter-spacing: .04em;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  padding-top: 2px;
}
.story__ru {
  display: block;
  margin-top: 2px;
  border: 0;
  padding: 0;
  background: transparent;
  font-family: var(--serif);
  font-style: italic;
  font-size: 12.5px;
  color: var(--ink-2);
  text-align: left;
  cursor: pointer;
}
.story__ru:hover { color: var(--red); }
.story__play {
  width: 30px;
  height: 30px;
  flex: none;
  display: grid;
  place-items: center;
  margin-top: 1px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}
.story__play:hover { border-color: var(--red); color: var(--red); }
.story__play .ic { width: 12px; height: 12px; margin-left: 1px; }
.story.is-playing .story__play { background: var(--red); border-color: var(--red); color: #fff7ea; }

.toc__links { display: flex; flex-direction: column; gap: 1px; }
.toc-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-2);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}
.toc-link:hover { background: rgba(176, 138, 68, .09); color: var(--ink); }
.toc-link em { font-style: normal; color: var(--ink-3); font-size: 10px; font-variant-numeric: tabular-nums; }

.toc__about {
  margin-top: 18px;
  padding: 12px 13px;
  border: 1px dashed var(--line-strong);
  border-radius: 11px;
  color: var(--ink-3);
  font-size: 11px;
  line-height: 1.6;
}
.toc__about b { color: var(--ink-2); font-weight: 600; }

/* ------------------------------- миниатюры ------------------------------- */

.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.thumb {
  position: relative;
  display: block;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 6px 16px -13px rgba(60, 40, 10, .55);
  transition: transform .18s, box-shadow .18s, border-color .18s;
}
.thumb:hover { transform: translateY(-2px); box-shadow: 0 12px 24px -14px rgba(60, 40, 10, .55); border-color: var(--line-strong); }
.thumb.is-current { border-color: var(--red); box-shadow: 0 0 0 1px var(--red), 0 10px 22px -14px rgba(176, 53, 39, .6); }
.thumb img { display: block; width: 100%; height: auto; filter: var(--page-filter); }
.thumb__n {
  position: absolute;
  right: 4px;
  bottom: 4px;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 9.5px;
  font-weight: 600;
  color: var(--ink);
  background: rgba(251, 246, 234, .88);
  font-variant-numeric: tabular-nums;
}
[data-theme="dark"] .thumb__n { background: rgba(34, 30, 24, .85); color: var(--ink); }

/* ------------------------------- звук ------------------------------- */

.sound__group h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 20px 0 6px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.sound__group h3 span { color: var(--gold); letter-spacing: .06em; text-transform: none; font-weight: 600; }
.sound__group h3::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--line), transparent);
}
.track {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.track:hover { background: rgba(176, 138, 68, .09); }
.track.is-playing { background: rgba(176, 53, 39, .07); }
.track__btn {
  width: 31px;
  height: 31px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink-2);
  background: transparent;
}
.track.is-playing .track__btn { background: var(--red); border-color: var(--red); color: #fff7ea; }
.track__btn .ic { width: 12px; height: 12px; margin-left: 1px; }
.track__body { flex: 1; min-width: 0; display: block; }
.track__title { display: block; font-family: var(--serif); font-size: 14px; line-height: 1.3; color: var(--ink); }
.track.is-playing .track__title { color: var(--red); }
.track__sub { display: block; font-size: 10.5px; color: var(--ink-3); margin-top: 1px; }
.track__dur { flex: none; font-size: 10.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* ============================ Плеер ============================ */

.player {
  position: fixed;
  z-index: 55;
  left: 20px;
  bottom: 96px;
  width: 332px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 26px;
  grid-template-areas:
    "toggle meta close"
    "seek seek seek"
    "row row row";
  gap: 9px 10px;
  padding: 13px 14px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 28px 66px -26px rgba(60, 35, 8, .6), 0 1px 0 rgba(255, 255, 255, .4) inset;
  animation: playerIn .32s cubic-bezier(.2, .9, .3, 1);
}
[data-theme="dark"] .player { box-shadow: 0 28px 66px -20px rgba(0, 0, 0, .85); }
.player[hidden] { display: none; }
@keyframes playerIn {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.player__toggle {
  grid-area: toggle;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--red);
  color: #fff7ea;
  cursor: pointer;
  transition: background .18s, transform .18s;
}
.player__toggle:hover { background: var(--red-2); transform: scale(1.04); }
.player__toggle .ic { width: 17px; height: 17px; }
.player__toggle .ic--pause { display: none; }
.player.is-playing .player__toggle .ic--play { display: none; }
.player.is-playing .player__toggle .ic--pause { display: block; }

.player__meta { grid-area: meta; min-width: 0; align-self: center; }
.player__title {
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.25;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player__sub {
  margin-top: 2px;
  font-size: 10.5px;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player__close {
  grid-area: close;
  width: 26px;
  height: 26px;
  align-self: start;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
}
.player__close:hover { color: var(--ink); background: rgba(0, 0, 0, .06); }
.player__close .ic { width: 14px; height: 14px; }

.player__seek { grid-area: seek; display: flex; align-items: center; gap: 8px; }
.player__time { width: 33px; flex: none; text-align: center; font-size: 10px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.player__row { grid-area: row; display: flex; align-items: center; gap: 6px; }
.player__row > button {
  width: 30px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}
.player__row > button:hover { background: rgba(176, 138, 68, .12); color: var(--ink); }
.player__row .ic { width: 15px; height: 15px; }
.player__group {
  flex: 1;
  min-width: 0;
  font-size: 9.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player__list {
  width: auto !important;
  padding: 0 10px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .02em;
  border-radius: 999px !important;
}

/* ============================ Модальное окно ============================ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(24, 16, 6, .55);
  backdrop-filter: blur(7px);
  animation: fadeIn .25s ease;
}
.modal[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal__card {
  position: relative;
  width: min(660px, 100%);
  max-height: min(86dvh, 780px);
  overflow: auto;
  padding: 26px 30px 24px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 44px 100px -30px rgba(20, 10, 0, .65);
  animation: cardIn .3s cubic-bezier(.2, .9, .3, 1);
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px) scale(.985); }
  to { opacity: 1; transform: none; }
}
.modal__card::-webkit-scrollbar { width: 10px; }
.modal__card::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; }

.modal__close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}
.modal__close:hover { background: rgba(176, 138, 68, .13); }

.modal__card h2 {
  margin: 8px 0 10px;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 26px;
  letter-spacing: .01em;
  text-align: center;
}
.modal__lead {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink-2);
  text-align: center;
}
.modal__card h3 {
  margin: 24px 0 8px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.modal__card p {
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--ink-2);
}
.modal__card code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 11px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(176, 138, 68, .08);
}
.keys {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  gap: 4px 18px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.keys li { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-2); padding: 3px 0; }
.keys li span { margin-left: 4px; }
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 5px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(251, 246, 234, .8);
  font-family: var(--sans);
  font-size: 10.5px;
  font-weight: 600;
  text-align: center;
  color: var(--ink-2);
}
[data-theme="dark"] kbd { background: rgba(255, 255, 255, .04); }
.modal__credit { font-size: 11px !important; color: var(--ink-3) !important; }
.modal__credit a { color: var(--red); }
.modal__foot { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }

.btn {
  height: 38px;
  padding: 0 20px;
  border: 1px solid var(--red);
  border-radius: 999px;
  background: var(--red);
  color: #fff7ea;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: filter .18s, transform .18s;
}
.btn:hover { filter: brightness(1.06); }
.btn--ghost { background: transparent; color: var(--red); }
.btn--ghost:hover { background: rgba(176, 53, 39, .08); }

/* ============================ Тост ============================ */

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  z-index: 90;
  transform: translate(-50%, 8px);
  padding: 9px 18px;
  border-radius: 999px;
  background: rgba(38, 30, 20, .94);
  color: #f7ecd6;
  font-size: 12px;
  letter-spacing: .01em;
  box-shadow: 0 18px 40px -20px rgba(0, 0, 0, .6);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  max-width: min(90vw, 460px);
  text-align: center;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ============================ Тёмная тема: страницы ============================ */
[data-theme="dark"] .sheet,
[data-theme="dark"] .book { background: var(--book-edge); }

/* ============================ Адаптив ============================ */

@media (max-width: 1180px) {
  .dockbtn__label { display: none; }
  .dockbtn--label { width: 38px; padding: 0; justify-content: center; }
  .scrub { width: 120px; }
  .masthead__sub { display: none; }
  .stage { padding: 40px 76px 8px; }
}

@media (max-width: 900px) {
  .topbar { height: 58px; padding: 0 10px; gap: 6px; }
  .brand { padding: 4px; }
  .brand__text { display: none; }
  .brand__monogram { width: 32px; height: 32px; font-size: 11.5px; }
  .masthead__title { font-size: 15px; }
  .tools { gap: 0; }
  .tool { width: 32px; height: 32px; }
  .tool--fs, .tool[data-act="spread"] { display: none; }
  .tool .ic { width: 17px; height: 17px; }

  .stage { padding: 34px 6px 4px; overscroll-behavior: contain; }
  .book { --ph: min(calc(100dvh - 172px), calc((100vw - 36px) * 1.41421)); }
  .book.is-spread { --ph: min(calc(100dvh - 172px), calc((100vw - 36px) * 1.41421)); }
  .book.is-spread::after { display: none; }
  .arrow { display: none; }
  .stage__hint { display: none; }

  .chip { padding: 5px 6px 5px 11px; gap: 7px; }
  .chip__kicker { display: none; }
  .chip__sep { display: none; }
  .chip__title { font-size: 13px; max-width: 40vw; }
  .chip__link { padding: 6px 7px; font-size: 10.5px; }
  .chip__play { width: 26px; height: 26px; }

  .dock { padding: 0 8px 8px; }
  .dock__inner { gap: 0; padding: 5px 6px; }
  .dockbtn { padding: 0 8px; }
  .dockbtn--icon { width: 34px; }
  .counter__cur { font-size: 15px; }
  .dock__sep { margin: 0 3px; }
  .dock__sep--hide, .scrub { display: none; }
  .dockbtn--label { width: 34px; padding: 0; justify-content: center; }
  .masthead__title { letter-spacing: 0; }

  .drawer { width: 100vw; border-left: 0; }
  .player {
    left: 8px;
    right: 8px;
    bottom: 68px;
    width: auto;
    grid-template-columns: 40px minmax(0, 1fr) 24px;
    grid-template-areas: "toggle meta close" "row row row";
    gap: 7px 9px;
    padding: 10px 12px;
  }
  .player__toggle { width: 40px; height: 40px; }
  .player__seek { display: none; }
  .toast { bottom: 78px; }
}

@media (max-width: 560px) {
  .masthead { padding: 0; }
  .masthead__title { font-size: 14px; max-width: 52vw; }
  .tool[data-act="spread"] { display: none; }
  .dock__inner { padding: 5px; }
  .dockbtn--toc { padding: 0 10px; }
  .chip__link span { display: none; }
  .modal__card { padding: 22px 18px 20px; }
  .modal__card h2 { font-size: 21px; }
  .keys { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .chip__title { max-width: 34vw; }
  .dockbtn--toc { padding: 0 8px; }
}

/* ============================ Меньше движения ============================ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* ============================ Печать ============================ */

@media print {
  .topbar, .dock, .arrow, .chipbar, .drawer, .player, .scrim, .stage__hint { display: none !important; }
  body { display: block; overflow: visible; background: #fff; }
  .stage { padding: 0; display: block; }
  .book { box-shadow: none; }
}
