/* ============================================================
   KNS Books — «Полуночная библиотека»
   Глубокий тёплый мрак, золото, serif-типографика, свечение.
   ============================================================ */

:root {
  --bg: #0d0a07;
  --bg-2: #14100b;
  --card: rgba(28, 22, 15, .72);
  --card-solid: #1c1610;
  --line: rgba(217, 168, 78, .14);
  --line-strong: rgba(217, 168, 78, .32);
  --ink: #f0e7d3;
  --ink-soft: #a89a80;
  --ink-faint: #6e6350;
  --gold: #d9a84e;
  --gold-2: #f2d98c;
  --gold-dim: #8a6a2f;
  --danger: #e0685a;
  --ok: #6fbf8f;
  --blue: #7aa7e0;
  --radius: 18px;
  --serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --shadow: 0 2px 6px rgba(0, 0, 0, .35), 0 18px 48px rgba(0, 0, 0, .45);
  --glow: 0 0 42px rgba(217, 168, 78, .16);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 500px at 85% -10%, rgba(217, 168, 78, .09), transparent 60%),
    radial-gradient(900px 600px at -15% 110%, rgba(120, 74, 20, .12), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .serif { font-family: var(--serif); }

::selection { background: rgba(217, 168, 78, .35); }

/* ---------- кнопки и поля ---------- */

button {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: none;
  border-radius: 12px;
  padding: 12px 22px;
  color: #191204;
  background: linear-gradient(135deg, var(--gold-2), var(--gold) 55%, #b9832c);
  box-shadow: 0 2px 10px rgba(217, 168, 78, .25), inset 0 1px 0 rgba(255, 255, 255, .35);
  transition: transform .16s ease, box-shadow .16s ease, opacity .16s;
}
button:hover { transform: translateY(-1px); box-shadow: 0 6px 22px rgba(217, 168, 78, .35), inset 0 1px 0 rgba(255,255,255,.35); }
button:active { transform: translateY(0); }
button:disabled { opacity: .45; cursor: default; transform: none; box-shadow: none; }

button.ghost {
  background: rgba(217, 168, 78, .07);
  color: var(--gold-2);
  border: 1px solid var(--line-strong);
  box-shadow: none;
}
button.ghost:hover { background: rgba(217, 168, 78, .14); box-shadow: none; }
button.danger {
  background: transparent; color: var(--danger);
  border: 1px solid rgba(224, 104, 90, .4); box-shadow: none;
  padding: 7px 13px; font-size: 13px;
}
button.danger:hover { background: rgba(224, 104, 90, .1); }

input, textarea, select {
  font: inherit;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 250, 240, .045);
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input::placeholder, textarea::placeholder { color: var(--ink-faint); }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(217, 168, 78, .18);
  background: rgba(255, 250, 240, .07);
}
select option { background: var(--card-solid); color: var(--ink); }
textarea { resize: vertical; min-height: 96px; }

/* ============================================================
   ЛЕНДИНГ
   ============================================================ */

.landing { overflow-x: hidden; }

.l-nav {
  max-width: 1180px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 24px;
}
.l-logo { font-family: var(--serif); font-size: 24px; font-weight: 800; letter-spacing: .3px; }
.l-logo em { font-style: normal; color: var(--gold); }
.l-nav .actions { display: flex; gap: 10px; align-items: center; }
.l-nav .actions button { padding: 10px 18px; }

.l-hero {
  max-width: 1180px; margin: 0 auto;
  display: grid; grid-template-columns: 1.15fr .85fr; gap: 40px;
  padding: 60px 24px 90px; align-items: center;
}
.l-hero h1 {
  font-size: clamp(38px, 5.2vw, 62px);
  line-height: 1.08; margin: 0 0 22px; font-weight: 800;
}
.l-hero h1 .gold {
  background: linear-gradient(120deg, var(--gold-2) 10%, var(--gold) 50%, #b9832c 90%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.l-hero .sub { font-size: 18px; color: var(--ink-soft); max-width: 520px; margin: 0 0 32px; }
.l-hero .cta { display: flex; gap: 14px; flex-wrap: wrap; }
.l-hero .cta button { padding: 15px 30px; font-size: 16px; border-radius: 14px; }
.l-hero .note { margin-top: 16px; font-size: 13px; color: var(--ink-faint); }

/* плавающие обложки в герое */
.l-books { position: relative; height: 440px; perspective: 900px; }
.l-book {
  position: absolute; width: 170px; height: 250px;
  border-radius: 6px 14px 14px 6px;
  box-shadow: var(--shadow), inset 4px 0 10px rgba(0, 0, 0, .35);
  padding: 18px 14px;
  display: flex; flex-direction: column; justify-content: space-between;
  animation: float 7s ease-in-out infinite;
  border: 1px solid rgba(255, 255, 255, .09);
}
.l-book::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
  background: rgba(0, 0, 0, .3); border-radius: 6px 0 0 6px;
}
.l-book .bt { font-family: var(--serif); font-weight: 700; font-size: 17px; line-height: 1.25; color: #fff8ea; }
.l-book .ba { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: rgba(255, 248, 234, .65); }
.l-book:nth-child(1) { left: 4%; top: 12%; transform: rotate(-8deg); animation-delay: 0s; }
.l-book:nth-child(2) { left: 34%; top: 34%; transform: rotate(3deg); animation-delay: 1.4s; z-index: 2; }
.l-book:nth-child(3) { left: 62%; top: 6%; transform: rotate(9deg); animation-delay: 2.8s; }
.l-book:nth-child(4) { left: 70%; top: 52%; transform: rotate(-4deg); animation-delay: 4.1s; opacity: .85; }
@keyframes float {
  0%, 100% { margin-top: 0; }
  50% { margin-top: -16px; }
}

/* секции */
.l-section { max-width: 1080px; margin: 0 auto; padding: 70px 24px; }
.l-section h2 { font-size: clamp(28px, 3.4vw, 42px); text-align: center; margin: 0 0 14px; font-weight: 800; }
.l-section .lead { text-align: center; color: var(--ink-soft); max-width: 620px; margin: 0 auto 48px; font-size: 17px; }

.l-features { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 18px; }
.l-feature {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 26px 22px;
  backdrop-filter: blur(8px);
  transition: transform .2s ease, border-color .2s;
}
.l-feature:hover { transform: translateY(-4px); border-color: var(--line-strong); }
.l-feature .ico { font-size: 30px; margin-bottom: 14px; }
.l-feature h3 { margin: 0 0 8px; font-size: 20px; }
.l-feature p { margin: 0; color: var(--ink-soft); font-size: 14.5px; }

.l-steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; counter-reset: step; }
.l-step { position: relative; padding: 26px 22px 22px 74px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.l-step::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 20px; top: 24px;
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--serif); font-size: 19px; font-weight: 700; color: #191204;
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
}
.l-step h3 { margin: 0 0 6px; font-size: 18px; }
.l-step p { margin: 0; color: var(--ink-soft); font-size: 14.5px; }

/* тарифы */
.l-pricing { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 22px; max-width: 760px; margin: 0 auto; }
.l-price {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 22px; padding: 32px 28px; position: relative;
  backdrop-filter: blur(8px);
}
.l-price.pro {
  border-color: var(--gold);
  background: linear-gradient(160deg, rgba(217, 168, 78, .12), rgba(28, 22, 15, .8) 45%);
  box-shadow: var(--glow);
}
.l-price .tag {
  position: absolute; top: -13px; left: 50%; transform: translateX(-50%);
  background: linear-gradient(135deg, var(--gold-2), var(--gold)); color: #191204;
  font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  padding: 5px 16px; border-radius: 999px; white-space: nowrap;
}
.l-price h3 { margin: 0 0 4px; font-size: 22px; }
.l-price .amount { font-family: var(--serif); font-size: 44px; font-weight: 800; margin: 12px 0 4px; }
.l-price .amount small { font-family: var(--sans); font-size: 15px; font-weight: 400; color: var(--ink-soft); }
.l-price ul { list-style: none; margin: 20px 0 26px; padding: 0; display: grid; gap: 10px; }
.l-price li { color: var(--ink-soft); font-size: 14.5px; padding-left: 26px; position: relative; }
.l-price li::before { content: "✦"; position: absolute; left: 0; color: var(--gold); }
.l-price li.no { color: var(--ink-faint); }
.l-price li.no::before { content: "—"; color: var(--ink-faint); }
.l-price button { width: 100%; }

.l-footer {
  border-top: 1px solid var(--line);
  padding: 30px 24px; text-align: center;
  color: var(--ink-faint); font-size: 13px;
}
.l-footer a { color: var(--gold-dim); text-decoration: none; }

/* ============================================================
   АВТОРИЗАЦИЯ
   ============================================================ */

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 24px; padding: 40px 36px;
  box-shadow: var(--shadow); backdrop-filter: blur(12px);
  animation: rise .5s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
.auth-card .logo { text-align: center; font-size: 44px; }
.auth-card h1 { text-align: center; font-size: 30px; margin: 10px 0 4px; font-weight: 800; }
.auth-card h1 em { font-style: normal; color: var(--gold); }
.auth-card .sub { text-align: center; color: var(--ink-soft); font-size: 14px; margin-bottom: 28px; }
.auth-card form { display: grid; gap: 12px; }
.auth-switch { text-align: center; margin-top: 18px; font-size: 14px; color: var(--ink-soft); }
.auth-switch a { color: var(--gold); cursor: pointer; text-decoration: none; font-weight: 600; }
.auth-back { text-align: center; margin-top: 12px; font-size: 13px; }
.auth-back a { color: var(--ink-faint); cursor: pointer; text-decoration: none; }
.form-error {
  background: rgba(224, 104, 90, .12); color: var(--danger);
  border: 1px solid rgba(224, 104, 90, .3);
  border-radius: 12px; padding: 11px 14px; font-size: 14px;
}

/* ============================================================
   ПРИЛОЖЕНИЕ
   ============================================================ */

.shell { max-width: 1060px; margin: 0 auto; padding: 0 20px 90px; animation: rise .35s ease; }

header.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 0 14px; gap: 12px;
}
header.top .brand { font-family: var(--serif); font-size: 24px; font-weight: 800; }
header.top .brand em { font-style: normal; color: var(--gold); }
header.top .right { display: flex; gap: 10px; align-items: center; }

.premium-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 700; letter-spacing: .06em;
  color: #191204; padding: 6px 14px; border-radius: 999px;
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
  box-shadow: 0 0 18px rgba(217, 168, 78, .35);
}
.usage-pill {
  font-size: 12.5px; color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; cursor: pointer; white-space: nowrap;
  background: rgba(217, 168, 78, .05);
  transition: border-color .15s;
}
.usage-pill:hover { border-color: var(--line-strong); }
.usage-pill b { color: var(--gold-2); }
header.top .user { font-size: 13px; color: var(--ink-faint); }
header.top button.logout { padding: 7px 14px; font-size: 12.5px; }

nav.tabs {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 26px;
}
nav.tabs a {
  padding: 12px 18px; text-decoration: none;
  color: var(--ink-soft); font-weight: 500; font-size: 15px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}
nav.tabs a:hover { color: var(--ink); }
nav.tabs a.active { color: var(--gold-2); border-bottom-color: var(--gold); font-weight: 600; }

/* ---------- карточки ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  padding: 22px;
  margin-bottom: 18px;
}
.card h3 { margin: 0 0 8px; font-size: 21px; font-weight: 700; }
.card .hint { font-size: 13.5px; color: var(--ink-soft); margin: -2px 0 14px; }
.card form { display: grid; gap: 12px; }
.card form button { justify-self: start; }

/* ---------- источники ---------- */

.source-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 0; border-bottom: 1px solid var(--line);
}
.source-item:last-child { border-bottom: none; }
.source-item .icon {
  width: 42px; height: 42px; border-radius: 12px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 18px;
  background: rgba(217, 168, 78, .1); border: 1px solid var(--line);
}
.source-item .body { flex: 1; min-width: 0; }
.source-item .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14.5px; }
.source-item .meta { font-size: 12.5px; color: var(--ink-faint); margin-top: 2px; }
.source-item .acts { display: flex; gap: 8px; align-items: center; }
.source-item .acts .ghost { padding: 7px 12px; font-size: 13px; }

.badge {
  display: inline-block; font-size: 12px; font-weight: 600;
  padding: 4px 12px; border-radius: 999px; white-space: nowrap;
}
.badge.pending    { background: rgba(217, 168, 78, .14); color: var(--gold-2); }
.badge.processing { background: rgba(122, 167, 224, .14); color: var(--blue); }
.badge.done       { background: rgba(111, 191, 143, .13); color: var(--ok); }
.badge.failed     { background: rgba(224, 104, 90, .13); color: var(--danger); }
.badge.want       { background: rgba(217, 168, 78, .14); color: var(--gold-2); }
.badge.reading    { background: rgba(122, 167, 224, .14); color: var(--blue); }
.badge.read       { background: rgba(111, 191, 143, .13); color: var(--ok); }

.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- библиотека ---------- */

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 22px; align-items: center; }
.chips button {
  background: transparent; color: var(--ink-soft);
  border: 1px solid var(--line); padding: 8px 16px;
  font-size: 14px; font-weight: 500; border-radius: 999px;
  box-shadow: none;
}
.chips button:hover { color: var(--ink); border-color: var(--line-strong); transform: none; }
.chips button.active { background: linear-gradient(135deg, var(--gold-2), var(--gold)); color: #191204; border-color: transparent; font-weight: 600; }

.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px; }

.book-card {
  position: relative;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
  transition: transform .2s ease, border-color .2s, box-shadow .2s;
  animation: rise .4s ease backwards;
}
.book-card:hover { transform: translateY(-5px); border-color: var(--line-strong); box-shadow: var(--glow); }

/* генеративная обложка */
.book-cover {
  height: 190px; padding: 18px 16px;
  display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.book-cover::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 7px;
  background: rgba(0, 0, 0, .32);
}
.book-cover::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(120% 90% at 80% 0%, rgba(255, 255, 255, .14), transparent 55%);
}
.book-cover .bt {
  font-family: var(--serif); font-weight: 700; font-size: 17px; line-height: 1.25;
  color: #fff8ea; text-shadow: 0 1px 6px rgba(0, 0, 0, .4);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.book-cover .ba {
  font-size: 10.5px; letter-spacing: .13em; text-transform: uppercase;
  color: rgba(255, 248, 234, .7);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-cover .st { position: absolute; right: 12px; top: 12px; z-index: 1; }

.book-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; }
.book-body .genres { display: flex; gap: 6px; flex-wrap: wrap; }
.book-body .genres span {
  font-size: 11px; font-weight: 500;
  background: rgba(217, 168, 78, .1); color: var(--gold-2);
  border: 1px solid var(--line);
  padding: 3px 9px; border-radius: 999px;
}
.book-body .desc, .book-body .why { font-size: 13px; color: var(--ink-soft); }
.book-body .why { font-style: italic; color: var(--gold-2); opacity: .85; }
.book-body .why::before { content: "«"; } .book-body .why::after { content: "»"; }
.book-body .controls { margin-top: 6px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.book-body .controls select { width: auto; font-size: 13px; padding: 7px 10px; }
.book-body .readat { font-size: 12px; color: var(--ink-faint); }
.rating-stars { color: var(--gold); font-size: 13px; letter-spacing: 1px; }

.empty { text-align: center; color: var(--ink-soft); padding: 52px 20px; font-size: 15px; }
.empty .big { font-size: 52px; margin-bottom: 12px; filter: drop-shadow(0 4px 14px rgba(217, 168, 78, .35)); }

/* ---------- чат ---------- */

.chat-thread { display: flex; flex-direction: column; gap: 14px; margin-bottom: 18px; }
.msg { max-width: 78%; padding: 13px 17px; border-radius: 18px; font-size: 15px; white-space: pre-wrap; animation: rise .25s ease; }
.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
  color: #191204; border-bottom-right-radius: 6px;
  box-shadow: 0 4px 18px rgba(217, 168, 78, .22);
}
.msg.assistant {
  align-self: flex-start;
  background: var(--card); border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.msg.assistant strong { color: var(--gold-2); }
.chat-form { display: flex; gap: 10px; position: sticky; bottom: 14px; }
.chat-form input {
  flex: 1; border-radius: 14px; padding: 14px 18px;
  background: rgba(28, 22, 15, .9); backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
.chat-form button { border-radius: 14px; padding: 14px 22px; box-shadow: var(--shadow); }

.typing { display: inline-flex; gap: 5px; align-items: center; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold); animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- paywall ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(8, 6, 4, .75); backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 20px;
  animation: fadein .2s ease;
}
@keyframes fadein { from { opacity: 0; } }
.paywall {
  width: 100%; max-width: 440px;
  background: linear-gradient(165deg, rgba(217, 168, 78, .14), rgba(28, 22, 15, .97) 40%);
  border: 1px solid var(--gold);
  border-radius: 24px; padding: 36px 32px;
  box-shadow: var(--shadow), var(--glow);
  text-align: center;
  animation: rise .3s ease;
}
.paywall .crown { font-size: 46px; filter: drop-shadow(0 4px 16px rgba(217, 168, 78, .5)); }
.paywall h2 { margin: 12px 0 6px; font-size: 28px; font-weight: 800; }
.paywall .reason { color: var(--ink-soft); font-size: 14.5px; margin-bottom: 20px; }
.paywall ul { text-align: left; list-style: none; padding: 0; margin: 0 0 22px; display: grid; gap: 9px; }
.paywall li { color: var(--ink-soft); font-size: 14px; padding-left: 26px; position: relative; }
.paywall li::before { content: "✦"; position: absolute; left: 0; color: var(--gold); }
.paywall .price-line { font-family: var(--serif); font-size: 34px; font-weight: 800; margin-bottom: 18px; }
.paywall .price-line small { font-family: var(--sans); font-size: 14px; font-weight: 400; color: var(--ink-soft); }
.paywall form { display: flex; gap: 8px; margin-top: 18px; }
.paywall form input { flex: 1; text-align: center; letter-spacing: .08em; text-transform: uppercase; }
.paywall .close { margin-top: 16px; background: none; border: none; color: var(--ink-faint); font-size: 13px; font-weight: 400; box-shadow: none; padding: 6px; }
.paywall .close:hover { color: var(--ink); transform: none; box-shadow: none; }
.paywall .promo-ok { color: var(--ok); font-size: 14px; margin-top: 12px; }
.paywall .promo-err { color: var(--danger); font-size: 14px; margin-top: 12px; }

/* ---------- тост ---------- */

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: linear-gradient(135deg, rgba(38, 30, 18, .97), rgba(28, 22, 15, .97));
  color: var(--ink); border: 1px solid var(--line-strong);
  padding: 12px 22px; border-radius: 999px; font-size: 14px;
  box-shadow: var(--shadow); z-index: 60;
  animation: rise .25s ease;
}

/* ---------- адаптив ---------- */

@media (max-width: 900px) {
  .l-hero { grid-template-columns: 1fr; padding-top: 30px; }
  .l-books { display: none; }
}
@media (max-width: 560px) {
  .msg { max-width: 92%; }
  header.top .brand { font-size: 20px; }
  header.top .user { display: none; }
  .card { padding: 18px 16px; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
}
