/* Библиотекарь на дизайн-системе Ilya Gamburg.
   Токены и живой слой подключены в index.html (colors_and_type.css, ig-motion.css/js).
   Цвета внутри секций только через var(--ig-*), чтобы всё перекрашивалось вместе с темой вкладки. */

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ig-bg);
  color: var(--ig-fg);
  padding: env(safe-area-inset-top) 0 calc(env(safe-area-inset-bottom) + 110px);
  min-height: 100svh;
}
body.noscroll { overflow: hidden; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ── Шапка и плавающее меню-пилюля ─────────────────────────────────────── */
.top { padding: 14px 20px 0; max-width: 760px; margin: 0 auto; }
.brand { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand-name { font-family: var(--font-serif); font-weight: 700; font-size: 22px; letter-spacing: -0.01em; }
.brand-status { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ig-muted); }
.dot-idle { width: 8px; height: 8px; border-radius: 50%; background: var(--warm-300, #C9C2B0); display: inline-block; }

.tabs-wrap { position: sticky; top: calc(env(safe-area-inset-top) + 10px); z-index: 30; display: flex; justify-content: center; padding: 12px 16px 0; pointer-events: none; }
.tabs {
  pointer-events: auto; display: flex; gap: 4px; padding: 5px;
  border-radius: var(--radius-pill); background: rgba(255, 250, 235, 0.72);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  box-shadow: var(--shadow-soft);
}
.tabs button {
  border: 0; background: transparent; border-radius: var(--radius-pill);
  padding: 9px 18px; font-size: 15px; font-weight: 500; color: var(--ink-600, #3A3A37);
  transition: background var(--ig-t-micro) var(--ease-out), color var(--ig-t-micro) var(--ease-out), transform var(--dur-fast) var(--ease-press);
}
.tabs button:hover { background: var(--cream-300); }
.tabs button:active { transform: scale(0.97); }
.tabs button[aria-selected="true"] { background: var(--ink-800); color: var(--cream-50); }
.badge {
  display: inline-block; min-width: 20px; margin-left: 4px; padding: 0 6px; border-radius: var(--radius-pill);
  background: var(--yellow-500); color: var(--ink-900); font: 600 12px/20px var(--font-mono); text-align: center;
  animation: badge-in var(--dur-slow) var(--ease-soft);
}
@keyframes badge-in { from { transform: scale(0.6); opacity: 0; } }

main { max-width: 760px; margin: 0 auto; padding: 0 16px; }
.tab { min-height: 100svh; padding-top: 8px; }

/* ── Заголовки секций ───────────────────────────────────────────────────── */
.hero { padding: 28px 4px 22px; }
.eyebrow { margin: 0 0 10px; color: var(--ig-muted); font-size: 13px; font-weight: 500; letter-spacing: 0.02em; }
.title { font-size: clamp(36px, 10vw, 56px); line-height: 1.05; letter-spacing: -0.02em; }
.lead { margin-top: 14px; color: var(--ig-muted); font-size: 17px; line-height: 1.5; max-width: 34em; }
.label { margin: 0; }

/* ── Пилюли ─────────────────────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: var(--radius-pill); border: 0;
  background: var(--ig-card); color: var(--ig-fg); font-size: 15px; font-weight: 500;
  box-shadow: 0 1px 2px rgba(40, 30, 10, 0.05);
  transition: background var(--ig-t-micro) var(--ease-out), transform var(--dur-fast) var(--ease-press), opacity var(--ig-t-micro);
}
.pill:hover { background: var(--cream-300); }
.pill:active { transform: scale(0.98); }
.pill:disabled { opacity: 0.45; cursor: default; transform: none; }
.pill-accent { background: var(--yellow-500); color: var(--ink-900); font-weight: 600; }
.pill-accent:hover { background: var(--yellow-600); }
.pill-ink { background: var(--ink-800); color: var(--cream-50); font-weight: 600; }
.pill-ink:hover { background: var(--ink-700); }
.pill.wide { width: 100%; margin-top: 12px; }
.pill.on { background: var(--ink-800); color: var(--cream-50); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; flex: none;
  border: 0; border-radius: 50%; background: var(--ig-card); color: var(--ig-fg); box-shadow: var(--shadow-soft);
  transition: background var(--ig-t-micro) var(--ease-out), transform var(--dur-fast) var(--ease-press);
}
.icon-btn:hover { background: var(--cream-300); }
.icon-btn:active { transform: scale(0.94); }

/* ── Карточки ───────────────────────────────────────────────────────────── */
.card { background: var(--ig-card); border-radius: var(--radius-lg); box-shadow: var(--shadow-soft); transition: background-color var(--ig-t-theme) var(--ig-ease-io), box-shadow var(--ig-t-micro) var(--ease-out), transform var(--dur-fast) var(--ease-press); }

/* ── Файлы ──────────────────────────────────────────────────────────────── */
.drop { display: block; cursor: pointer; border-radius: var(--radius-xl); }
.drop-body {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 28px 26px 26px; border-radius: var(--radius-xl);
  background: var(--ink-800); color: var(--cream-50); box-shadow: var(--shadow-dark);
}
.drop:active .drop-body { transform: scale(0.985); }
.drop-icon { width: 52px; height: 52px; border-radius: 16px; background: var(--yellow-500); color: var(--ink-900); display: flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.drop-icon svg { width: 26px; height: 26px; }
.drop-title { font-family: var(--font-serif); font-weight: 700; font-size: 28px; line-height: 1.1; }
.drop-sub { color: var(--warm-300); font-size: 15px; }
.tips { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.tip { padding: 18px; }
.tip p:last-child { margin-top: 6px; font-size: 14px; line-height: 1.45; }
@media (max-width: 420px) { .tips { grid-template-columns: 1fr; } }
.notes { padding-left: 18px; color: var(--danger); font-size: 14px; }

/* ── Поиск ──────────────────────────────────────────────────────────────── */
.search-field {
  display: flex; align-items: center; gap: 10px; padding: 0 18px; height: 54px;
  border-radius: var(--radius-pill); background: var(--ig-card); box-shadow: var(--shadow-soft); color: var(--ig-muted);
  transition: box-shadow var(--ig-t-micro) var(--ease-out);
}
.search-field:focus-within { box-shadow: 0 0 0 3px var(--yellow-300), var(--shadow-soft); }
.search-field input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: 17px; color: var(--ig-fg); }
.search-field input::placeholder { color: var(--warm-500); }
.search-row { display: flex; gap: 10px; margin-top: 10px; align-items: center; }
.search-row .pill { margin-left: auto; padding-left: 24px; padding-right: 24px; }
.seg { display: inline-flex; padding: 4px; border-radius: var(--radius-pill); background: var(--ig-card); box-shadow: var(--shadow-soft); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 8px 16px; border-radius: var(--radius-pill); font-size: 14px; font-weight: 500; cursor: pointer; transition: background var(--ig-t-micro) var(--ease-out), color var(--ig-t-micro); }
.seg input:checked + span { background: var(--yellow-500); color: var(--ink-900); }

.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.quick-card { border: 0; text-align: left; padding: 18px; display: flex; flex-direction: column; gap: 4px; color: var(--ig-fg); }
.quick-card:hover { box-shadow: var(--shadow-card); }
.quick-card:active { transform: scale(0.98); }
.q-title { font-family: var(--font-serif); font-weight: 700; font-size: 20px; }
.q-sub { color: var(--ig-muted); font-size: 13px; }

.feed-head { display: flex; align-items: center; gap: 12px; margin: 28px 0 10px; }
.feed-title { font-size: clamp(22px, 6vw, 30px); line-height: 1.15; letter-spacing: -0.01em; }
.bulkbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 12px; }
.check-pill { cursor: pointer; }
.check-pill input { width: 18px; height: 18px; margin: 0; accent-color: var(--ink-800); }
.status-line { color: var(--ig-muted); font-size: 14px; margin: 12px 4px; }
.status-line:empty { display: none; }

/* ── Список ленты ───────────────────────────────────────────────────────── */
.entries, .jobs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.entry { background: var(--ig-card); border-radius: var(--radius-lg); box-shadow: var(--shadow-soft); transition: background-color var(--ig-t-theme) var(--ig-ease-io), box-shadow var(--ig-t-micro) var(--ease-out); }
.entry.nav > button {
  position: relative; width: 100%; text-align: left; border: 0; background: none; border-radius: var(--radius-lg);
  padding: 16px 44px 16px 18px; display: flex; flex-direction: column; gap: 2px; color: var(--ig-fg);
  transition: transform var(--dur-fast) var(--ease-press);
}
.entry.nav > button:active { transform: scale(0.985); }
.entry.nav > button::after {
  content: ""; position: absolute; right: 18px; top: 50%; width: 9px; height: 9px; margin-top: -5px;
  border-right: 2px solid var(--ig-muted); border-top: 2px solid var(--ig-muted); transform: rotate(45deg);
}
.entry:hover { box-shadow: var(--shadow-card); }
.entry-title { font-weight: 600; font-size: 16px; line-height: 1.3; overflow-wrap: anywhere; }
.entry-sub { color: var(--ig-fg); opacity: 0.75; font-size: 14px; }
.entry-info { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.entry-info:empty { display: none; }
.tag { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: var(--radius-pill); font: 500 12px/18px var(--font-mono); background: var(--cream-300); color: var(--ink-600); }
.tag-fmt { background: var(--yellow-200); color: var(--ink-900); }
.tag-series { background: transparent; box-shadow: inset 0 0 0 1px var(--ig-line); font-family: var(--font-sans); }
.entry-desc { color: var(--ig-muted); font-size: 13px; line-height: 1.45; margin-top: 6px; }

.entry.book { padding: 4px 4px 4px 0; }
.entry-pick { display: flex; align-items: flex-start; gap: 2px; }
.pick-box { padding: 16px 6px 12px 16px; cursor: pointer; flex: none; }
.pick-box input { appearance: none; -webkit-appearance: none; margin: 0; width: 24px; height: 24px; border-radius: 50%; box-shadow: inset 0 0 0 2px var(--warm-300); background: transparent; cursor: pointer; display: grid; place-items: center; transition: background var(--ig-t-micro) var(--ease-out), box-shadow var(--ig-t-micro), transform var(--dur-slow) var(--ease-soft); }
.pick-box input:checked { background: var(--yellow-500); box-shadow: none; transform: scale(1.06); }
.pick-box input:checked::after { content: ""; width: 10px; height: 6px; border-left: 2px solid var(--ink-900); border-bottom: 2px solid var(--ink-900); transform: translateY(-1px) rotate(-45deg); }
button.entry-text { flex: 1; min-width: 0; text-align: left; border: 0; background: none; border-radius: 14px; padding: 12px 12px 12px 6px; display: flex; flex-direction: column; color: var(--ig-fg); transition: background var(--ig-t-micro); }
button.entry-text:active { background: rgba(18, 18, 18, 0.04); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 12px 52px; }
.chip { border: 0; font-size: 13px; padding: 6px 12px; border-radius: var(--radius-pill); background: var(--cream-300); color: var(--ink-600); transition: background var(--ig-t-micro), transform var(--dur-fast) var(--ease-press); }
.chip:hover { background: var(--yellow-200); }
.chip:active { transform: scale(0.97); }
.entry.other { padding: 16px 18px; display: flex; flex-direction: column; opacity: 0.7; }

/* буквенный указатель плиткой */
.entries .tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(66px, 1fr)); gap: 8px; padding: 2px 0 10px; background: none; box-shadow: none; }
.tile {
  border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 12px 4px;
  border-radius: 16px; background: var(--ig-card); color: var(--ig-fg); box-shadow: var(--shadow-soft);
  transition: background var(--ig-t-micro) var(--ease-out), transform var(--dur-fast) var(--ease-press), box-shadow var(--ig-t-micro);
}
.tile:hover { background: var(--yellow-200); box-shadow: var(--shadow-card); }
.tile:active { transform: scale(0.95); }
.tile-l { font-family: var(--font-serif); font-weight: 700; font-size: 20px; line-height: 1.2; }
.tile-n { font: 500 11px/1 var(--font-mono); color: var(--ig-muted); }

/* плавающая панель подготовки */
.prepbar {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 14px); z-index: 25;
  width: min(560px, calc(100% - 24px)); transform: translateX(-50%);
  display: flex; gap: 8px; padding: 8px; border-radius: var(--radius-pill);
  background: var(--ink-800); box-shadow: var(--shadow-dark);
  animation: bar-in 700ms var(--ig-ease);
}
@keyframes bar-in { from { transform: translate(-50%, 140%); } }
.prepbar select { flex: 1; min-width: 0; border: 0; border-radius: var(--radius-pill); padding: 10px 14px; background: var(--ink-700); color: var(--cream-50); font-size: 14px; }
.prepbar .pill { flex: none; }

/* ── Готово ─────────────────────────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { padding: 16px; }
.stat .metric { font-family: var(--font-mono); font-size: clamp(30px, 9vw, 44px); margin-top: 6px; }
.progress {
  height: 12px; margin: 14px 0 18px; border-radius: var(--radius-pill); overflow: hidden;
  /* остаток: диагональная штриховка, как в дашбордах системы */
  background: repeating-linear-gradient(-45deg, var(--ig-card) 0 6px, rgba(18, 18, 18, 0.08) 6px 8px);
}
.progress > i { display: block; height: 100%; width: 0; background: var(--yellow-500); border-radius: var(--radius-pill); transition: width 900ms var(--ig-ease); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.busy { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ig-fg); }
.empty { padding: 28px 22px; text-align: center; }
.empty-title { font-family: var(--font-serif); font-weight: 700; font-size: 22px; margin-bottom: 6px; }

.job { display: flex; gap: 12px; padding: 16px; align-items: flex-start; background: var(--ig-card); border-radius: var(--radius-lg); box-shadow: var(--shadow-soft); transition: opacity var(--ig-t-micro), background-color var(--ig-t-theme) var(--ig-ease-io); }
.job.enter { animation: job-in 900ms var(--ig-ease) both; animation-delay: calc(var(--k, 0) * 70ms); }
@keyframes job-in { from { opacity: 0; transform: translate3d(0, 18px, 0); } }
.job .state-ic { width: 24px; height: 24px; flex: none; margin-top: 1px; border-radius: 50%; display: grid; place-items: center; box-shadow: inset 0 0 0 2px var(--warm-300); }
.job.fetching .state-ic, .job.converting .state-ic { box-shadow: none; }
.job.fetching .state-ic::before, .job.converting .state-ic::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--yellow-500); animation: ig-pulse 2.2s infinite; }
.job.ready .state-ic { background: var(--yellow-500); box-shadow: none; animation: badge-in var(--dur-slow) var(--ease-soft); }
.job.ready .state-ic::before { content: ""; width: 9px; height: 5px; border-left: 2px solid var(--ink-900); border-bottom: 2px solid var(--ink-900); transform: translateY(-1px) rotate(-45deg); }
.job.failed .state-ic { background: var(--danger); box-shadow: none; }
.job.failed .state-ic::before { content: "!"; color: #fff; font: 700 13px/1 var(--font-sans); }
.job input[type="checkbox"] { appearance: none; -webkit-appearance: none; margin: 0; }
.job-pick { flex: none; cursor: pointer; }
.job-pick input:not(:checked) + .state-ic { background: transparent; box-shadow: inset 0 0 0 2px var(--warm-300); }
.job-pick input:not(:checked) + .state-ic::before { display: none; }
.job-main { flex: 1; min-width: 0; }
.job-title { font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.job-sub { color: var(--ig-muted); font-size: 14px; margin-top: 2px; }
.job-state { font-size: 13px; color: var(--ig-muted); margin-top: 6px; }
.job.ready .job-state { color: var(--success); }
.job.failed .job-state { color: var(--danger); }
.job.shared { opacity: 0.55; }
.job-warn { font-size: 12px; color: var(--warning); margin-top: 4px; }
.job-actions { display: flex; gap: 6px; flex: none; }
.job-actions .icon-btn { width: 38px; height: 38px; box-shadow: none; background: var(--cream-300); }
.job-actions .icon-btn.go { background: var(--yellow-500); color: var(--ink-900); }

/* ── Карточка книги ─────────────────────────────────────────────────────── */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; background: rgba(20, 18, 12, 0); transition: background 500ms var(--ig-ease-io); }
.sheet.open { background: rgba(20, 18, 12, 0.45); }
.sheet-panel {
  position: relative; width: 100%; max-width: 760px; height: calc(100% - env(safe-area-inset-top) - 20px);
  display: flex; flex-direction: column; background: var(--cream-200); color: var(--ink-900);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0; box-shadow: var(--shadow-pop);
  transform: translate3d(0, 104%, 0); transition: transform 700ms var(--ig-ease);
}
.sheet.open .sheet-panel { transform: none; }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--warm-300); margin: 8px auto 0; }
.sheet-head { position: absolute; top: 12px; right: 14px; z-index: 2; }
.sheet-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 22px 20px 20px; }
.sheet-actions { display: flex; gap: 8px; padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px); background: var(--cream-100); border-top: 1px solid var(--line); }
.sheet-actions .pill { flex: 1; }
#sheetPick.on { background: var(--ink-800); color: var(--cream-50); }
.book-top { display: flex; gap: 16px; align-items: flex-start; padding-right: 40px; }
.book-cover { width: 120px; flex: none; border-radius: 10px; box-shadow: var(--shadow-card); background: var(--cream-100); clip-path: inset(100% 0 0 0 round 10px); transition: clip-path 1100ms var(--ig-ease) 150ms; }
.sheet.open .book-cover { clip-path: inset(0 0 0 0 round 10px); }
.book-cover.none { height: 170px; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 12px; color: var(--warm-500); }
.book-head h2 { font-size: 24px; line-height: 1.15; margin: 0 0 8px; }
.book-authors { font-weight: 600; }
.book-series { margin-top: 6px; }
.book-facts { color: var(--warm-700); font-size: 13px; margin-top: 6px; }
.book-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.book-genres { color: var(--warm-700); font-size: 13px; margin: 14px 0 0; }
.sheet-body .chips { padding: 12px 0 0; }
.sheet-body h3 { font-size: 18px; margin: 22px 0 8px; }
.book-text { margin: 0 0 10px; line-height: 1.6; }
.reviews { margin-top: 16px; background: var(--cream-100); border-radius: var(--radius-lg); padding: 4px 16px; box-shadow: var(--shadow-soft); }
.reviews summary { cursor: pointer; font-weight: 600; padding: 12px 0; }
.review { font-size: 14px; line-height: 1.5; margin: 0 0 12px; }
.review b { font-weight: 600; }
.warn { color: var(--danger); font-size: 14px; }
.hint { color: var(--warm-700); font-size: 14px; }
.book-link { display: inline-block; margin-top: 18px; border-bottom: 1px solid var(--line); }

/* ── Тост в духе системы ────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 86px); z-index: 60;
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: var(--radius-pill);
  background: var(--ink-900); color: var(--cream-50); font-size: 14px; font-weight: 500; text-align: center;
  opacity: 0; transform: translate3d(-50%, 16px, 0); pointer-events: none;
  transition: opacity .4s, transform .6s var(--ease-soft);
}
.toast.is-on { opacity: 1; transform: translate3d(-50%, 0, 0); }

@media (prefers-reduced-motion: reduce) {
  .sheet-panel, .book-cover, .progress > i { transition: none !important; }
  .book-cover { clip-path: none !important; }
  .job.enter, .prepbar, .badge { animation: none !important; }
}
