/* =========================================================
  Будуар — книжная лавка дамских романов
  Раскладка: липкая шапка → кнопка жанров → горизонтальные полки
  Файл подключается в templates/base.html через {% static %}.
  Все цвета заданы переменными ниже: поменяйте их, чтобы
  перекрасить весь сайт.
   ========================================================= */

:root {
  --paper: #fbf4f2;        /* фон страницы */
  --surface: #ffffff;      /* фон карточек, окон */
  --ink: #2a1320;          /* основной текст */
  --muted: #7b5c68;        /* второстепенный текст */
  --line: #ecdbe0;         /* линии и рамки */
  --chip: #f5e7eb;         /* фон плашек */
  --accent: #a3234a;       /* винно-розовый акцент */
  --accent-hover: #86183b;
  --accent-ink: #ffffff;   /* текст на акценте */
  --gold: #a5741f;         /* звёзды рейтинга */
  --overlay: rgb(30 8 18 / 0.45);
  --shadow: 0 1px 2px rgb(60 15 35 / 0.08), 0 10px 24px -14px rgb(60 15 35 / 0.35);

  --font-display: 'Yeseva One', 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-body: 'Golos Text', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --radius: 10px;
  --gutter: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1a0f14;
    --surface: #24161e;
    --ink: #f6e9ee;
    --muted: #b99ba8;
    --line: #3b2631;
    --chip: #2f1d27;
    --accent: #e86a8a;
    --accent-hover: #f28aa4;
    --accent-ink: #1a0f14;
    --gold: #e0b468;
    --overlay: rgb(0 0 0 / 0.6);
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 12px 28px -14px rgb(0 0 0 / 0.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #1a0f14;
  --surface: #24161e;
  --ink: #f6e9ee;
  --muted: #b99ba8;
  --line: #3b2631;
  --chip: #2f1d27;
  --accent: #e86a8a;
  --accent-hover: #f28aa4;
  --accent-ink: #1a0f14;
  --gold: #e0b468;
  --overlay: rgb(0 0 0 / 0.6);
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 12px 28px -14px rgb(0 0 0 / 0.7);
  color-scheme: dark;
}

/* ---------- База ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
}
img { max-width: 100%; display: block; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 400; text-wrap: balance; margin: 0; line-height: 1.15; }

.container {
  width: 100%;
  max-width: 1280px;
  margin-inline: auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter-r);
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px;
  border: 1px solid transparent; border-radius: 999px;
  font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { background: var(--accent-hover); }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn--ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn--ghost[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--chip); }
.btn--danger { background: transparent; border-color: var(--line); color: var(--accent); }
.btn--danger.is-armed { background: var(--accent); color: var(--accent-ink); }
.btn--block { width: 100%; }
.btn svg { width: 18px; height: 18px; flex: none; }

.link-btn {
  background: none; border: 0; padding: 4px 0;
  color: var(--accent); font-weight: 600; font-size: 14px; white-space: nowrap;
}
.link-btn:hover { text-decoration: underline; text-underline-offset: 3px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--chip); color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- Шапка ---------- */
.site-header {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 30;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.header__inner {
  display: flex; align-items: center; gap: 20px;
  padding-block: 12px;
}
.logo {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; flex: none;
}
.logo__mark {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  font-family: var(--font-display); font-size: 22px; line-height: 1;
}
.logo__text { font-family: var(--font-display); font-size: 24px; line-height: 1; display: flex; flex-direction: column; }
.logo__text small {
  font-family: var(--font-body); font-size: 10.5px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--muted); margin-top: 4px;
}

.search {
  flex: 1; min-width: 0; max-width: 460px;
  display: flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
}
.search:focus-within { border-color: var(--accent); }
.search svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; height: 100%;
}
.search input::placeholder { color: var(--muted); }

.header__nav { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.nav-btn {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 64px; padding: 6px 8px;
  background: none; border: 0; border-radius: 8px;
  color: var(--muted); font-size: 12px; text-decoration: none;
}
.nav-btn:hover, .nav-btn[aria-current="page"] { color: var(--ink); background: var(--chip); }
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn span { max-width: 9ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  position: absolute; top: 2px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--accent); color: var(--accent-ink);
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 860px) {
  .header__inner { flex-wrap: wrap; gap: 10px 12px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .logo__text small { display: none; }
}
@media (max-width: 520px) {
  .header__nav { gap: 0; }
  .nav-btn { min-width: 40px; padding: 8px; }
  .nav-btn span { display: none; }
  .badge { top: 0; left: auto; right: 0; }
  .logo__text { font-size: 21px; }
}

/* ---------- Панель с жанрами ---------- */
.toolbar {
  display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap;
  padding-block: 20px 4px;
}
.toolbar__note { margin: 0; color: var(--muted); font-size: 14px; flex: 1; min-width: 0; }
.genre-picker { position: relative; }
.genre-picker > summary { list-style: none; }
.genre-picker > summary::-webkit-details-marker { display: none; }
.genre-toggle { cursor: pointer; user-select: none; }
.genre-toggle {
  display: inline-flex; align-items: center; gap: 10px;
  min-height: 48px; padding: 0 18px 0 20px;
  border-radius: 999px; border: 1px solid var(--ink);
  background: var(--ink); color: var(--paper);
  font-weight: 600;
}
.genre-toggle__current {
  font-weight: 400; opacity: .75;
  max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.genre-toggle svg { width: 16px; height: 16px; transition: transform .2s; }
.genre-picker[open] .genre-toggle svg { transform: rotate(180deg); }

.genre-panel {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 20;
  width: min(560px, calc(100vw - 32px));
  padding: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow);
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px;
}
.genre-option {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 10px 12px; border: 0; border-radius: 10px;
  background: transparent; text-align: left;
  color: inherit; text-decoration: none;
}
.genre-option:hover { background: var(--chip); }
.genre-option[aria-current="true"] { background: var(--chip); box-shadow: inset 0 0 0 1px var(--accent); }
.genre-option__name { font-weight: 600; display: flex; gap: 8px; align-items: baseline; }
.genre-option__count { color: var(--muted); font-weight: 400; font-size: 13px; font-variant-numeric: tabular-nums; }
.genre-option__tag { color: var(--muted); font-size: 13px; }
.genre-option--wide { grid-column: 1 / -1; }
@media (max-width: 520px) {
  .genre-panel { grid-template-columns: 1fr; }
}

/* ---------- Полки (ряды книг) ---------- */
.shelves { display: flex; flex-direction: column; gap: 40px; padding-block: 24px 64px; }
.shelf__head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  padding-bottom: 14px; margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.shelf__head > div { min-width: 0; }
.shelf__head h2 { font-size: clamp(22px, 2.6vw, 30px); }
.shelf__head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.shelf__viewport { position: relative; }
.shelf__track {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: clamp(140px, 40vw, 180px);
  gap: 22px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: 2px;
  padding: 4px 2px 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.shelf__track > * { scroll-snap-align: start; }
.shelf__track--grid {
  grid-auto-flow: row;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  overflow: visible;
  gap: 32px 22px;
}
.shelf__arrow {
  position: absolute; top: calc(50% - 50px); z-index: 2;
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  transition: opacity .15s;
}
.shelf__arrow svg { width: 20px; height: 20px; }
.shelf__arrow--prev { left: -14px; }
.shelf__arrow--next { right: -14px; }
.shelf__arrow:disabled { opacity: 0; pointer-events: none; }
@media (hover: none), (max-width: 700px) {
  .shelf__arrow { display: none; }
}

.empty {
  text-align: center; padding: 64px 16px; color: var(--muted);
}
.empty h2 { color: var(--ink); font-size: 26px; margin-bottom: 8px; }

/* ---------- Карточка книги ---------- */
.card { position: relative; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.card__link { display: flex; flex-direction: column; gap: 10px; text-decoration: none; }
.card__link:hover .cover { transform: translateY(-4px) rotate(-0.6deg); }
.card__title {
  font-weight: 600; font-size: 14.5px; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card__author { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card__meta { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-top: 6px; }
.card__rating { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.card__rating b { color: var(--gold); font-weight: 400; }
.price { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.price s { font-weight: 400; color: var(--muted); font-size: .85em; margin-right: 4px; }
.card__like-form { position: absolute; top: 8px; right: 8px; z-index: 1; margin: 0; }
.card__like {
  width: 36px; height: 36px; border-radius: 50%; border: 0;
  display: grid; place-items: center;
  background: rgb(255 255 255 / .88); color: #8a1d3f;
  box-shadow: 0 2px 8px rgb(0 0 0 / .18);
}
.card__like svg { width: 18px; height: 18px; }
.card__like[aria-pressed="true"] svg { fill: currentColor; }
.card__flag {
  position: absolute; top: 10px; left: 0; z-index: 1;
  padding: 3px 10px 3px 8px; border-radius: 0 999px 999px 0;
  background: var(--accent); color: var(--accent-ink);
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
}

/* ---------- Обложка ----------
   Рисуется из названия и цвета (переменная --h).
   Если у книги указано поле image, используется картинка. */
.cover {
  --h: 340;
  position: relative;
  width: 100%; max-width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 3px 8px 8px 3px;
  overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 25% 12% 14%;
  text-align: center;
  color: hsl(var(--h) 70% 94%);
  background: linear-gradient(165deg, hsl(var(--h) 50% 22%), hsl(calc(var(--h) + 18) 55% 42%));
  box-shadow: inset 5px 0 0 rgb(0 0 0 / .22), inset 6px 0 0 rgb(255 255 255 / .08), var(--shadow);
  container-type: inline-size;
  transition: transform .25s ease;
}
.cover::before {
  content: ""; position: absolute; inset: 6%;
  border: 1px solid hsl(42 75% 72% / .55); border-radius: 2px;
  pointer-events: none;
}
.cover__author {
  position: relative;
  font-size: 11px; font-size: 6.6cqi;
  letter-spacing: .14em; text-transform: uppercase; opacity: .85; line-height: 1.3;
}
.cover__title {
  position: relative;
  font-family: var(--font-display);
  font-size: 18px; font-size: 11.5cqi;
  line-height: 1.1; text-wrap: balance; hyphens: auto; overflow-wrap: anywhere;
  text-shadow: 0 1px 12px rgb(0 0 0 / .25);
}
.cover__orn {
  position: relative; width: 36%; height: 1px;
  background: hsl(42 75% 72% / .8);
}
.cover__orn::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 7px; height: 7px; transform: translate(-50%, -50%) rotate(45deg);
  background: hsl(42 75% 72%);
}
.cover--v1 {
  background:
    radial-gradient(circle at 50% 46%, hsl(calc(var(--h) + 10) 70% 75% / .28) 0 24%, transparent 24.5%),
    radial-gradient(circle at 50% 46%, transparent 0 27%, hsl(42 75% 72% / .35) 27.5% 28%, transparent 28.5%),
    linear-gradient(165deg, hsl(var(--h) 50% 22%), hsl(calc(var(--h) + 18) 55% 42%));
}
.cover--v2 {
  background:
    repeating-linear-gradient(125deg, transparent 0 16px, hsl(0 0% 100% / .06) 16px 17px),
    linear-gradient(165deg, hsl(var(--h) 45% 26%), hsl(calc(var(--h) - 16) 50% 46%));
}
.cover--v3::after {
  content: ""; position: absolute; left: 22%; right: 22%; top: 24%; bottom: 30%;
  border: 1px solid hsl(42 75% 72% / .45); border-radius: 999px 999px 0 0;
  background: hsl(calc(var(--h) + 20) 60% 70% / .12);
}
.cover--v3 .cover__title, .cover--v3 .cover__author, .cover--v3 .cover__orn { z-index: 1; }
.cover--image { background-size: cover; background-position: center; padding: 0; }
.cover--image::before { display: none; }
@media (prefers-reduced-motion: reduce) {
  .cover, .genre-toggle svg { transition: none; }
}

/* ---------- Страница книги ----------
   Отдельная страница book.html: обложка слева,
   справа название, аннотация и кнопки покупки. */
.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 20px; padding: 6px 0;
  color: var(--muted); font-size: 14px; text-decoration: none;
}
.back-link svg { width: 16px; height: 16px; }
.back-link:hover { color: var(--accent); }

.book {
  display: grid;
  grid-template-columns: minmax(220px, 360px) minmax(0, 1fr);
  gap: 56px;
  padding-block: 20px 72px;
  align-items: start;
}
.book__cover { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 96px); }
.book__cover .cover { box-shadow: inset 6px 0 0 rgb(0 0 0 / .22), 0 30px 50px -24px rgb(60 15 35 / .6); }
.book__info { min-width: 0; display: flex; flex-direction: column; gap: 22px; max-width: 660px; }
.book__heading { display: flex; flex-direction: column; gap: 10px; }
.book__genre {
  align-self: flex-start;
  padding: 4px 12px; border-radius: 999px;
  background: var(--chip); color: var(--accent);
  font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  text-decoration: none;
}
.book__title { font-size: clamp(32px, 4.6vw, 52px); }
.book__author { font-size: 18px; color: var(--muted); }
.book__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; color: var(--muted); font-size: 14px; }
.book__meta b { color: var(--ink); font-variant-numeric: tabular-nums; }
.book__meta .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--muted); }
.stars {
  font-size: 17px; letter-spacing: 2px;
  background: linear-gradient(90deg, var(--gold) calc(var(--r) / 5 * 100%), var(--line) 0);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.buy-box {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding: 20px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
}
.buy-box__price { flex-basis: 100%; font-size: 30px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.buy-box__price s { font-size: 17px; font-weight: 400; color: var(--muted); margin-left: 10px; }
.buy-box .btn { min-height: 50px; padding: 0 24px; font-size: 15px; }
.buy-box__note { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 13px; }

.book__desc h2 { font-size: 24px; margin-bottom: 12px; }
.book__desc p { margin: 0 0 14px; max-width: 65ch; font-size: 16.5px; line-height: 1.65; }
.book__desc p:first-of-type::first-letter {
  float: left; font-family: var(--font-display); font-size: 3.3em; line-height: .9;
  margin: 4px 10px 0 0; color: var(--accent);
}

.book__tools { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding-top: 14px; border-top: 1px dashed var(--line); }
.edited-mark { color: var(--muted); font-size: 13px; }

@media (max-width: 760px) {
  .book { grid-template-columns: 1fr; gap: 28px; padding-top: 12px; }
  .book__cover { position: static; width: min(240px, 70%); margin-inline: auto; }
  .book__heading { align-items: center; text-align: center; }
  .book__genres { justify-content: center; }
  .book__meta { justify-content: center; }
  .buy-box .btn { flex: 1 1 100%; }
}

/* ---------- Формы ---------- */
.form { display: grid; gap: 14px; }
.form__row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}
.field textarea { min-height: 140px; resize: vertical; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 0; border-color: var(--accent); }
.field input[type="range"] { padding: 0; min-height: 32px; accent-color: var(--accent); border: 0; background: transparent; }
.field__hint { font-size: 12px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.form__actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; padding-top: 6px; }
.form__actions .spacer { margin-right: auto; }
.form__error { margin: 0; color: var(--accent); font-size: 13px; font-weight: 600; }

/* ---------- Подвал ---------- */
.site-footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.site-footer .container { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px; padding-block: 24px; }

/* ---------- Плашка «Куплено» ---------- */
.card__flag--owned { background: var(--ink); color: var(--paper); }
.link-btn { text-decoration: none; }
.link-btn--muted { color: var(--muted); }
.muted { color: var(--muted); }
.toolbar__note a { color: var(--accent); }
.empty a:not(.btn) { color: var(--accent); }

/* ---------- Общие страницы (корзина, библиотека, аккаунт) ---------- */
.page { padding-block: 28px 72px; }
.page--narrow { max-width: 720px; }
.page__head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; margin-bottom: 24px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.page__head h1 { font-size: clamp(28px, 3.6vw, 40px); }
.page__head p { margin: 0; color: var(--muted); }
.page__head a { color: var(--accent); }
.back-link + .page__head { margin-top: 8px; }

/* Корзина */
.cart { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 32px; align-items: start; }
.line-list { list-style: none; margin: 0; padding: 0; }
.line-item {
  display: grid; grid-template-columns: 64px minmax(0, 1fr) auto auto; gap: 16px; align-items: center;
  padding-block: 14px; border-bottom: 1px solid var(--line);
}
.line-item:first-child { padding-top: 0; }
.line-item .cover { padding: 12%; box-shadow: inset 3px 0 0 rgb(0 0 0 / .22); }
.line-item .cover__author, .line-item .cover__orn { display: none; }
.line-item .cover__title { font-size: 9px; font-size: 13cqi; }
.line-item__title { font-weight: 600; text-decoration: none; line-height: 1.3; }
.line-item__title:hover { color: var(--accent); }
.line-item__sub { color: var(--muted); font-size: 13px; }
.line-item form { margin: 0; }
.summary {
  position: sticky; top: calc(env(safe-area-inset-top, 0px) + 96px);
  display: flex; flex-direction: column; gap: 14px;
  padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
}
.summary__row { display: flex; justify-content: space-between; align-items: baseline; font-size: 17px; }
.summary__row b { font-size: 24px; font-variant-numeric: tabular-nums; }
.summary__note { margin: 0; color: var(--muted); font-size: 13px; }
@media (max-width: 760px) {
  .cart { grid-template-columns: 1fr; }
  .summary { position: static; }
  .line-item { grid-template-columns: 52px minmax(0, 1fr) auto; }
  .line-item .price { grid-column: 2; grid-row: 2; }
  .line-item form { grid-column: 3; grid-row: 1 / span 2; }
}

/* Аккаунт */
.profile { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }
.profile h1 { font-size: 32px; }
.profile__avatar {
  width: 60px; height: 60px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  font-family: var(--font-display); font-size: 28px;
}
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 32px; }
.stats > * { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; text-decoration: none; }
.stats a:hover { border-color: var(--accent); }
.stats b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.stats span { color: var(--muted); font-size: 13px; }
.orders { margin-bottom: 32px; }
.orders h2 { font-size: 24px; margin-bottom: 12px; }
.order { padding-block: 14px; border-top: 1px solid var(--line); }
.order__head { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: baseline; }
.order__head span:not(.price) { color: var(--muted); font-size: 13px; }
.order__head .price { margin-left: auto; }
.order ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 14px; }
.order a { color: var(--ink); }
.form__actions--start { justify-content: flex-start; }
.form__actions form { margin: 0; }

/* Вход и регистрация */
.auth-card {
  max-width: 440px; margin: 24px auto 0;
  padding: 28px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  display: flex; flex-direction: column; gap: 14px;
}
.auth-card h1 { font-size: 30px; }
.auth-card p { margin: 0; }
.auth-card__alt { text-align: center; color: var(--muted); font-size: 14px; }
.auth-card a { color: var(--accent); }
.field--error input, .field--error select, .field--error textarea { border-color: var(--accent); }
.field input[type="file"] { padding: 9px 12px; }
.field ul { margin: 4px 0 0; padding-left: 18px; font-size: 12px; color: var(--muted); }

/* Редактор книги */
.editor { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 32px; align-items: start; }
.editor__preview { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 96px); display: flex; flex-direction: column; gap: 10px; }
@media (max-width: 600px) {
  .editor { grid-template-columns: 1fr; }
  .editor__preview { position: static; width: 150px; margin-inline: auto; }
  .auth-card { padding: 22px 18px; }
}

/* ---------- Уведомления ---------- */
.toasts {
  position: fixed; z-index: 70;
  left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  width: max-content; max-width: calc(100% - 32px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 12px 20px; border-radius: 999px;
  background: var(--ink); color: var(--paper);
  font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow);
  transition: opacity .3s, transform .3s;
}
.toast--error { background: var(--accent); color: var(--accent-ink); }
.toast.is-leaving { opacity: 0; transform: translateY(8px); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* кнопки в блоке покупки обёрнуты в <form>: пусть ведут себя как прямые элементы ряда */
.buy-box form { display: contents; }

/* ---------- Мелочи ---------- */
.btn--small { min-height: 36px; padding: 0 14px; font-size: 13px; }
.site-footer a { color: var(--accent); }
.selectable { user-select: all; }
@media (max-width: 430px) {
  .logo__text { display: none; }   /* в шапке 6 кнопок, на узком экране оставляем только знак */
}

/* =========================================================
   СОДЕРЖАНИЕ НА СТРАНИЦЕ КНИГИ
   ========================================================= */
.book__toc h2 { font-size: 24px; margin-bottom: 10px; }
.toc { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.toc__item {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 4px; border-bottom: 1px solid var(--line);
  text-decoration: none;
}
.toc__item:hover .toc__title { color: var(--accent); }
.toc__num {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--chip); color: var(--accent);
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.toc__title { flex: 1; min-width: 0; font-weight: 500; }
.toc__tag { flex: none; display: inline-flex; color: var(--muted); font-size: 12px; }
.toc__tag svg { width: 18px; height: 18px; }
.toc__tag--free { color: var(--accent); font-weight: 600; }
.toc__item.is-locked .toc__title { color: var(--muted); }
.toc__item.is-locked .toc__num { background: transparent; border: 1px solid var(--line); color: var(--muted); }

/* Библиотека: карточка + кнопка чтения */
.library-item { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

/* =========================================================
   ЧИТАЛКА
   Настройки читателя меняют переменные ниже через атрибуты
   data-reader-theme / data-reader-font на <html>.
   ========================================================= */
:root {
  --reader-size: 19px;
  --font-reading: 'PT Serif', Georgia, 'Times New Roman', serif;
}
:root[data-reader-font="sans"] { --font-reading: var(--font-body); }

/* Фон читалки поверх темы сайта */
:root[data-reader-theme="light"] {
  --paper: #fdfaf7; --surface: #ffffff; --ink: #22161c; --muted: #75606a;
  --line: #ebe0e3; --chip: #f5ebee; --accent: #a3234a; --accent-ink: #ffffff;
  color-scheme: light;
}
:root[data-reader-theme="sepia"] {
  --paper: #f3e9d4; --surface: #f9f2e3; --ink: #3a2c1e; --muted: #7d6a52;
  --line: #e0d1b3; --chip: #eadcc0; --accent: #8e3b24; --accent-ink: #fff8ec;
  color-scheme: light;
}
:root[data-reader-theme="dark"] {
  --paper: #141012; --surface: #1d171a; --ink: #e9dfe3; --muted: #a2939a;
  --line: #2f272b; --chip: #282024; --accent: #e07f97; --accent-ink: #141012;
  color-scheme: dark;
}

.reader-bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.reader-bar__inner { position: relative; display: flex; align-items: center; gap: 8px; padding-block: 8px; }
.reader-bar__title { flex: 1; min-width: 0; display: flex; flex-direction: column; text-align: center; line-height: 1.25; }
.reader-bar__book, .reader-bar__chapter { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-bar__book { font-size: 12px; color: var(--muted); letter-spacing: .04em; }
.reader-bar__chapter { font-weight: 600; font-size: 14px; }
.reader-bar .icon-btn { color: var(--ink); flex: none; }
.reader-aa { font-family: var(--font-display); font-size: 17px; }

.reader-pop { position: static; }   /* панель выравнивается по правому краю панели читалки */
.reader-pop > summary { list-style: none; cursor: pointer; }
.reader-pop > summary::-webkit-details-marker { display: none; }
.reader-pop[open] > summary { background: var(--chip); }
.reader-pop__panel {
  position: absolute; top: calc(100% + 2px); z-index: 5;
  right: max(16px, env(safe-area-inset-right, 0px));
  width: min(340px, calc(100vw - 32px));
  max-height: min(70vh, 520px); overflow-y: auto;
  padding: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
}
.reader-pop__label {
  margin: 4px 0 0; font-size: 11.5px; font-weight: 600; color: var(--muted);
  letter-spacing: .08em; text-transform: uppercase;
}
.reader-toc { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.reader-toc a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; text-decoration: none; font-size: 14px;
}
.reader-toc a:hover { background: var(--chip); }
.reader-toc a[aria-current="page"] { background: var(--chip); color: var(--accent); font-weight: 600; }
.reader-toc a.is-locked { color: var(--muted); }
.reader-toc svg { width: 16px; height: 16px; flex: none; margin-left: auto; }
.reader-toc__num { width: 22px; flex: none; font-variant-numeric: tabular-nums; color: var(--muted); }
.reader-toc__title { min-width: 0; }

.seg { display: flex; gap: 4px; padding: 4px; background: var(--chip); border-radius: 10px; align-items: center; }
.seg--wrap { flex-wrap: wrap; }
.seg button {
  flex: 1; min-height: 36px; padding: 0 10px;
  border: 0; border-radius: 7px; background: transparent; font-size: 13px; font-weight: 500;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--accent); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.seg--wrap button { flex: 1 1 calc(50% - 4px); }
.seg output { min-width: 3ch; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

.reader-progress { height: 3px; background: transparent; overflow: hidden; }
.reader-progress span {
  display: block; height: 100%; background: var(--accent);
  transform: scaleX(0); transform-origin: left;
}

.reader { padding-block: 40px 48px; }
.reader__page { max-width: 680px; margin-inline: auto; }
.reader__kicker {
  margin: 0 0 10px; text-align: center; color: var(--muted);
  font-size: 12px; letter-spacing: .14em; text-transform: uppercase;
}
.reader__title { text-align: center; font-size: clamp(28px, 4vw, 40px); margin-bottom: 36px; }
.reader__text {
  font-family: var(--font-reading);
  font-size: var(--reader-size);
  line-height: 1.7;
  hyphens: auto; -webkit-hyphens: auto;
  overflow-wrap: break-word;
}
.reader__text p { margin: 0; text-indent: 1.6em; }
.reader__text p:first-child { text-indent: 0; }
.reader__text p:first-child::first-letter {
  float: left; font-family: var(--font-display); font-size: 3.2em; line-height: .85;
  margin: 6px 10px 0 0; color: var(--accent);
}
.reader__end { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 48px; text-align: center; color: var(--muted); }
.reader__end > span { font-size: 28px; color: var(--accent); }
.reader__end p { margin: 0; }

.paywall {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  margin-top: 8px; padding: 36px 24px; text-align: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
}
.paywall__icon { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: var(--chip); color: var(--accent); }
.paywall__icon svg { width: 24px; height: 24px; }
.paywall h2 { font-size: 26px; }
.paywall p { margin: 0; max-width: 46ch; color: var(--muted); }
.paywall__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 6px; }
.paywall__actions form { display: contents; }

.reader-nav {
  max-width: 680px; margin: 48px auto 0;
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 16px; align-items: center;
  padding-top: 20px; border-top: 1px solid var(--line);
}
.reader-nav__link {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  text-decoration: none; background: var(--surface);
}
.reader-nav__link:hover { border-color: var(--accent); }
.reader-nav__link span { font-size: 12.5px; color: var(--muted); }
.reader-nav__link b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.reader-nav__link b svg { width: 15px; height: 15px; flex: none; color: var(--muted); }
.reader-nav__link--next { text-align: right; align-items: flex-end; }
.reader-nav__link.is-empty { border: 0; background: none; }
.reader-nav__pos { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.reader-hint { text-align: center; color: var(--muted); font-size: 12.5px; margin: 16px 0 0; }
@media (hover: none) { .reader-hint { display: none; } }
@media (max-width: 560px) {
  .reader { padding-top: 28px; }
  .reader-nav { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .reader-nav__pos { grid-column: 1 / -1; grid-row: 1; text-align: center; }
}

/* =========================================================
   ПОДДЕРЖКА
   ========================================================= */
.support { display: grid; grid-template-columns: minmax(0, 380px) minmax(0, 1fr); gap: 40px; align-items: start; }
.support h2 { font-size: 22px; margin-bottom: 14px; }
.support__new { padding: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
@media (max-width: 820px) { .support { grid-template-columns: 1fr; gap: 28px; } }

.thread-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.thread-row {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 4px; border-bottom: 1px solid var(--line); text-decoration: none;
}
.thread-row:hover b { color: var(--accent); }
.thread-row__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.thread-row__main b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-row__main span { color: var(--muted); font-size: 13px; }
.thread-row.is-unread b { font-weight: 700; }

.pill {
  flex: none; display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill--open { background: var(--chip); color: var(--accent); }
.pill--closed { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.pill--new { background: var(--accent); color: var(--accent-ink); }

.tabs { display: flex; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs a {
  padding: 8px 16px; border-radius: 999px; text-decoration: none;
  font-size: 14px; font-weight: 500; color: var(--muted);
}
.tabs a:hover { color: var(--ink); background: var(--chip); }
.tabs a[aria-current="page"] { background: var(--ink); color: var(--paper); }

/* Переписка */
.page--chat { max-width: 820px; }
.chat {
  display: flex; flex-direction: column;
  margin-top: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  overflow: hidden;
}
.chat__head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.chat__head-text { flex: 1 1 260px; min-width: 0; }
.chat__head h1 { font-size: 24px; }
.chat__head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.chat__head form { margin: 0; }
.chat__log {
  display: flex; flex-direction: column; gap: 14px;
  height: min(58vh, 560px); overflow-y: auto;
  padding: 20px; background: var(--paper);
  overscroll-behavior: contain;
}
.msg { max-width: min(78%, 560px); display: flex; flex-direction: column; gap: 4px; }
.msg__meta { display: flex; gap: 8px; align-items: baseline; font-size: 12px; color: var(--muted); }
.msg__meta b { font-weight: 600; color: var(--ink); }
.msg__text {
  padding: 10px 14px; border-radius: 14px;
  line-height: 1.5; overflow-wrap: anywhere;
}
.msg--theirs { align-self: flex-start; }
.msg--theirs .msg__text { background: var(--surface); border: 1px solid var(--line); border-top-left-radius: 4px; }
.msg--mine { align-self: flex-end; align-items: flex-end; }
.msg--mine .msg__text { background: var(--accent); color: var(--accent-ink); border-top-right-radius: 4px; }
.msg--system .msg__text { background: var(--chip); border-color: transparent; color: var(--muted); font-size: 14px; }
.chat__form { display: flex; gap: 10px; align-items: flex-end; padding: 14px 16px; border-top: 1px solid var(--line); }
.chat__form textarea {
  flex: 1; min-width: 0; min-height: 48px; max-height: 200px; resize: vertical;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); line-height: 1.45;
}
.chat__form textarea:focus { outline: 0; border-color: var(--accent); }
.chat__form .btn { min-height: 48px; }
.chat__hint { margin: 0; padding: 0 20px 14px; color: var(--muted); font-size: 12px; }
@media (max-width: 560px) {
  .chat__log { padding: 14px; height: 60vh; }
  .msg { max-width: 90%; }
  .chat__head { padding: 14px 16px; }
}

/* =========================================================
   Статистика чтения (/stats/)
   ========================================================= */
.stat-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 20px; }
.stat-toolbar .tabs { margin-bottom: 0; }

.stat-tiles, .funnel {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px; margin: 0 0 28px; padding: 0; list-style: none;
}
.stat-tiles > *, .funnel > li {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px;
}
.stat-tiles b, .funnel b { display: block; font-size: 26px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-tiles span, .funnel span { color: var(--muted); font-size: 13px; }
.stat-tiles b small, .funnel b small { font-size: 14px; font-weight: 500; color: var(--muted); }
.stat-note { margin: -12px 0 20px; padding: 10px 14px; border-radius: 10px; background: var(--chip); font-size: 14px; }

.table-wrap { overflow-x: auto; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tbody tr:last-child > * { border-bottom: 0; }
.data-table thead th { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.data-table tbody th { font-weight: 500; min-width: 180px; }
.data-table tbody th a { color: var(--ink); text-decoration-color: var(--line); }
.data-table tbody th a:hover { color: var(--accent); }
.data-table small { color: var(--muted); font-size: 12px; font-weight: 400; }
.data-table tbody th small { display: block; }
.data-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.data-table tbody tr:hover > * { background: color-mix(in srgb, var(--chip) 55%, transparent); }

.data-table--chapters tbody th small { display: inline; }
.ch-num { display: inline-block; width: 26px; color: var(--muted); font-variant-numeric: tabular-nums; }
.data-table tr.paid-start { border-top: 2px dashed var(--accent); }
@media (max-width: 560px) {
  .data-table--chapters .bar-col { display: none; }   /* на телефоне только цифры */
  .data-table th, .data-table td { padding: 10px; }
}
.drop { color: var(--accent) !important; }

.bar-col { width: 34%; min-width: 140px; }
.bar { position: relative; height: 14px; }
.bar span { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; }
.bar__opened { background: color-mix(in srgb, var(--accent) 28%, var(--surface)); }
.bar__finished { background: var(--accent); top: 3px !important; bottom: 3px !important; }
.legend { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.legend i { display: inline-block; width: 12px; height: 10px; border-radius: 2px; }
.legend__finished { margin-left: 8px; }
.legend__opened { background: color-mix(in srgb, var(--accent) 28%, var(--surface)); }
.legend__finished { background: var(--accent); }

/* Код из письма */
.code-input {
  font-size: 26px !important; letter-spacing: 0.4em; text-align: center;
  font-variant-numeric: tabular-nums; padding-block: 10px !important;
}
.resend { text-align: center; }
.resend .link-btn[disabled] { color: var(--muted); cursor: default; text-decoration: none; }
.nowrap { white-space: nowrap; }

/* Жанры книги (до трёх) */
.book__genres { display: flex; flex-wrap: wrap; gap: 6px; }
.field__label { font-size: 13px; font-weight: 600; color: var(--muted); }
div.checks { display: flex; flex-wrap: wrap; gap: 6px 8px; margin-top: 2px; }
div.checks > div { display: contents; }
div.checks label {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  font-size: 14px; font-weight: 400; color: var(--ink); cursor: pointer;
}
div.checks label:has(input:checked) { border-color: var(--accent); background: var(--chip); }
div.checks input[type="checkbox"] {
  flex: none; width: 16px; height: 16px; min-height: 0; padding: 0; margin: 0;
  border: 0; border-radius: 3px; accent-color: var(--accent);
}

/* Выбор книги на странице статистики */
.book-picker { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; max-width: 560px; }
.book-picker label { font-size: 13px; font-weight: 600; color: var(--muted); }
.book-picker__row { display: flex; gap: 8px; }
.book-picker select {
  flex: 1; min-width: 0; min-height: 42px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}

.stat-h { font-size: 22px; margin: 4px 0 12px; }
.empty--small { padding: 24px 16px; }
.empty--small p { margin: 0; }

/* Неоплаченный заказ в профиле */
.order__pay { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.order__pay form { margin: 0; }
