/* ---------- Tokens ---------- */
:root{
  --bg:          #ffffff;
  --bg-secondary:#f3f1ec;
  --panel:       #ffffff;
  --text:        #17241d;
  --hint:        #6b7a70;
  --accent:      #8a6a2f;
  --accent-2:    #b8873c;
  --accent-text: #ffffff;
  --separator:   rgba(23,36,29,0.1);
  --header-bg:   #f8f6f0;
  --telegram:    #2a9fd8;
  --telegram-2:  #2389bd;

  --radius-section: 12px;
  --radius-cover: 12px;

  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body:    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"]{
  --bg:          #101a15;
  --bg-secondary:#0b120e;
  --panel:       #17251e;
  --text:        #ece7db;
  --hint:        #93a89b;
  --accent:      #c9a24b;
  --accent-2:    #dcb968;
  --accent-text: #10190f;
  --separator:   rgba(236,231,219,0.09);
  --header-bg:   #0d1611;
}

@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:          #101a15;
    --bg-secondary:#0b120e;
    --panel:       #17251e;
    --text:        #ece7db;
    --hint:        #93a89b;
    --accent:      #c9a24b;
    --accent-2:    #dcb968;
    --accent-text: #10190f;
    --separator:   rgba(236,231,219,0.09);
    --header-bg:   #0d1611;
  }
}

*{ box-sizing: border-box; }

html, body{
  margin: 0;
  min-height: 100%;
  background: var(--bg-secondary);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea{ font-family: inherit; }
::selection{ background: var(--accent); color: var(--accent-text); }

/* ---------- Layout ---------- */
.app{ min-height: 100vh; display: flex; flex-direction: column; }

.topbar{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--separator);
}
.topbar__title{
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  margin: 0;
  letter-spacing: 0.2px;
}
.topbar__subtitle{ margin: 2px 0 0; font-size: 0.82rem; color: var(--hint); }

.theme-toggle{
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--separator);
  background: var(--panel);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.theme-toggle svg{ width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle:active{ opacity: 0.8; }

.layout{
  flex: 1;
  display: grid;
  grid-template-columns: 360px 1fr;
  min-height: 0;
}

@media (max-width: 860px){
  .layout{ display: block; }
  .app[data-view="list"] .reader{ display: none; }
  .app[data-view="player"] .shelf{ display: none; }
}
@media (min-width: 861px){
  .backbtn{ display: none; }
}

/* ---------- Shelf ---------- */
.shelf{
  background: var(--header-bg);
  border-right: 1px solid var(--separator);
  padding: 20px 20px 28px;
  overflow-y: auto;
}

.search{
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--separator);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
}
.search__icon{ width: 17px; height: 17px; flex-shrink: 0; fill: none; stroke: var(--hint); stroke-width: 2; }
.search input{ border: none; outline: none; background: none; color: var(--text); font-size: 0.92rem; width: 100%; }
.search input::placeholder{ color: var(--hint); }

.section{ margin-bottom: 16px; }
.section__header{ font-size: 0.78rem; color: var(--hint); padding: 0 6px 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.section__body{
  background: var(--panel);
  border: 1px solid var(--separator);
  border-radius: var(--radius-section);
  overflow: hidden;
}

.row{
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--separator);
}
.row:last-child, .row--last{ border-bottom: none; }
.row__label{ font-size: 0.92rem; }
.row__label--accent{ color: var(--accent-2); font-weight: 500; }

.row--action{
  width: 100%; border: 1px solid var(--separator); cursor: pointer; justify-content: flex-start;
  border-radius: var(--radius-section);
}
.row__icon{
  width: 26px; height: 26px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; flex-shrink: 0;
}
.row__icon--accent{ background: var(--accent); color: var(--accent-text); }

.empty-hint{ margin: 0 0 16px; padding: 12px 14px; font-size: 0.84rem; color: var(--hint); line-height: 1.5; background: var(--panel); border: 1px dashed var(--separator); border-radius: var(--radius-section); }
.empty-hint code{ background: var(--bg-secondary); border-radius: 4px; padding: 1px 5px; font-size: 0.85em; }

/* ---------- Book rows ---------- */
.book{
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: var(--panel); border: none; border-bottom: 1px solid var(--separator);
  cursor: pointer; text-align: left; color: inherit;
}
.book:last-child{ border-bottom: none; }
.book:hover, .book[aria-current="true"]{ background: var(--bg-secondary); }

.book__mark{
  width: 90px; height: 130px; border-radius: 9px;
  background: linear-gradient(160deg, var(--accent-2), var(--accent));
  color: var(--accent-text);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 1.1rem; font-weight: 700; flex-shrink: 0;
  overflow: hidden;
}
.book__cover-img{ width: 100%; height: 100%; object-fit: cover; display: block; }
.book__text{ min-width: 0; flex: 1; }
.book__title{ display: block; font-size: 0.94rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book__author{ display: block; font-size: 0.8rem; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book__desc{
  display: -webkit-box; -webkit-line-clamp: 10; -webkit-box-orient: vertical; overflow: hidden;
  font-size: 0.76rem; color: var(--hint); opacity: 0.85; margin-top: 1px;
}
.book__chevron{ width: 16px; height: 16px; flex-shrink: 0; fill: none; stroke: var(--hint); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Reader ---------- */
.reader{ padding: 32px; overflow-y: auto; }

.reader__empty{ max-width: 460px; margin: 40px auto 0; text-align: left; }
.reader__empty-kicker{ color: var(--accent-2); font-size: 0.8rem; margin: 0 0 10px; }
.reader__empty h2{ font-family: var(--font-display); font-weight: 700; font-size: 1.8rem; line-height: 1.25; margin: 0 0 12px; }

.backbtn{
  display: flex; align-items: center; gap: 6px;
  background: none; border: none; color: var(--accent-2);
  font-size: 0.9rem; font-weight: 500; cursor: pointer; padding: 0 0 20px;
}
.backbtn svg{ width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Страница книги ---------- */
.bookpage{ display: flex; flex-direction: column; align-items: center; text-align: center; max-width: 480px; margin: 0 auto 20px; }

.cover{
  width: 200px; height: 300px; border-radius: var(--radius-cover);
  background: linear-gradient(155deg, var(--accent-2), var(--accent));
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 24px;
  box-shadow: 0 22px 50px -20px rgba(0,0,0,0.35);
  overflow: hidden;
}
.cover__img{ width: 100%; height: 100%; object-fit: cover; display: block; }
.cover span{ font-family: var(--font-display); font-size: 4.2rem; font-weight: 700; color: var(--accent-text); opacity: 0.9; }

.bookpage__author{ margin: 0 0 4px; font-size: 0.86rem; color: var(--accent-2); }
.bookpage__title{ font-family: var(--font-display); font-weight: 700; font-size: 1.5rem; margin: 0 0 16px; line-height: 1.3; }

/* Описание: сначала 3 строки, по «Далее» — целиком */
.about{ width: 100%; text-align: left; }
.about[hidden]{ display: none; }
.about__text{
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.65;
  color: var(--text);
  opacity: 0.85;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}
.about__text.is-open{
  display: block;
  -webkit-line-clamp: unset;
  line-clamp: unset;
  overflow: visible;
}
.about__more{
  margin-top: 8px; padding: 0;
  background: none; border: none; cursor: pointer;
  color: var(--accent-2); font-size: 0.9rem; font-weight: 600;
}
.about__more:hover{ color: var(--accent); }
.about__more[hidden]{ display: none; }

/* ---------- Кнопка Telegram ---------- */
.tg{
  max-width: 480px; margin: 0 auto 20px; width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--telegram); color: #ffffff;
  border-radius: var(--radius-section);
  padding: 14px; font-size: 0.95rem; font-weight: 600;
  text-decoration: none;
}
.tg:hover{ background: var(--telegram-2); }
.tg svg{ width: 20px; height: 20px; fill: currentColor; flex-shrink: 0; }

/* ---------- Похожие книги ---------- */
.similar{ max-width: 480px; margin: 0 auto 20px; }
.similar__header{ font-size: 0.8rem; color: var(--hint); padding: 0 2px 8px; text-transform: uppercase; letter-spacing: 0.04em; }
.similar__row{ display: flex; gap: 12px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.similar__row::-webkit-scrollbar{ display: none; }
.similar__card{ flex: 0 0 92px; display: flex; flex-direction: column; gap: 6px; background: none; border: none; padding: 0; text-align: left; color: inherit; cursor: pointer; }
.similar__cover{
  width: 92px; height: 92px; border-radius: 10px; overflow: hidden;
  background: linear-gradient(160deg, var(--accent-2), var(--accent));
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.similar__cover img{ width: 100%; height: 100%; object-fit: cover; display: block; }
.similar__cover span{ font-family: var(--font-display); font-size: 1.7rem; font-weight: 700; color: var(--accent-text); opacity: 0.9; }
.similar__title{ font-size: 0.78rem; font-weight: 500; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.similar__author{ font-size: 0.7rem; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Донат ---------- */
.donate{
  max-width: 480px; margin: 0 auto; width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: var(--accent-text);
  border: none; border-radius: var(--radius-section);
  padding: 14px; font-size: 0.95rem; font-weight: 600; cursor: pointer;
}
.donate:hover{ background: var(--accent-2); }
.donate__icon{ font-size: 1.1rem; line-height: 1; }

.reader .section{ max-width: 480px; margin-left: auto; margin-right: auto; }

/* ---------- Модальное окно ---------- */
.modal-overlay{ position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-overlay[hidden]{ display: none; }
.modal-card{
  width: 100%; max-width: 420px; background: var(--panel);
  border: 1px solid var(--separator); border-radius: 14px;
  padding: 22px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 30px 70px -30px rgba(0,0,0,0.5);
}
.modal-title{ margin: 0 0 4px; font-family: var(--font-display); font-size: 1.15rem; font-weight: 700; }
.modal-field{ display: flex; flex-direction: column; gap: 4px; }
.modal-field label{ font-size: 0.78rem; color: var(--hint); }
.modal-field input{
  background: var(--bg-secondary); border: 1px solid var(--separator); border-radius: 8px;
  padding: 10px 12px; font-size: 0.9rem; color: var(--text); outline: none;
}
.modal-field input:focus{ border-color: var(--accent); }
.modal-field input::placeholder{ color: var(--hint); }
.modal-actions{ display: flex; gap: 10px; margin-top: 6px; }
.modal-btn{ flex: 1; border: none; border-radius: 8px; padding: 11px; font-size: 0.9rem; font-weight: 600; cursor: pointer; }
.modal-btn--ghost{ background: var(--bg-secondary); color: var(--text); }
.modal-btn--accent{ background: var(--accent); color: var(--accent-text); }
.modal-btn--accent:hover{ background: var(--accent-2); }

/* ---------- Accessibility ---------- */
@media (prefers-reduced-motion: reduce){ *{ transition: none !important; } }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible{ outline: 2px solid var(--accent); outline-offset: 2px; }
