/* Toma Library — каталог.
   Шрифты системные: страница не обращается ни к каким сторонним серверам. */

:root {
  color-scheme: light dark;

  --blue: #17479e;            /* шапка: кобальт валенсийской азулежу */
  --primary: #17479e;         /* заливки и рамки */
  --primary-text: #17479e;    /* текст кнопок и ссылок на фоне страницы */
  --on-primary: #ffffff;
  --ground: #f4f6f9;
  --surface: #ffffff;
  --ink: #17202a;
  --muted: #53606d;
  --line: #d3dae3;
  --free-bg: #d6efe2;
  --free-ink: #0a5a3d;
  --busy-bg: #f2e2cb;
  --busy-ink: #6a3f08;
  --soon-bg: #e9e1f7;
  --soon-ink: #4a2a86;
  --focus: #e07b16;           /* апельсин: единственный тёплый акцент, только для фокуса */

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 4px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --blue: #10347a;
    --primary: #3b69d1;
    --primary-text: #9bb8ff;
    --ground: #11161d;
    --surface: #19212b;
    --ink: #e9edf2;
    --muted: #a3afbc;
    --line: #2d3947;
    --free-bg: #123a2b;
    --free-ink: #8fdcb8;
    --busy-bg: #3b2a12;
    --busy-ink: #f0c98a;
    --soon-bg: #2d2247;
    --soon-ink: #cdb9f4;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 1rem/1.55 var(--sans);
}
body:has(dialog[open]) { overflow: hidden; }
img { display: block; max-width: 100%; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: -999px; top: 0;
  padding: 8px 12px; background: #fff; color: #000; z-index: 10;
}
.skip:focus { left: 12px; top: 12px; }

.wrap { max-width: 1120px; margin: 0 auto; padding-left: 20px; padding-right: 20px; }

/* ---------- Шапка с инструкцией ---------- */

.top { background: var(--blue); color: #fff; padding: 32px 0 36px; }
.top h1 {
  margin: 0 0 14px;
  font: 600 clamp(1.9rem, 5vw, 2.7rem)/1.1 var(--serif);
  letter-spacing: -0.01em;
}
.top a { color: #fff; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.lead { margin: 0 0 18px; max-width: 60ch; font-size: 1.0625rem; }

.steps {
  list-style: none; counter-reset: step;
  margin: 0 0 20px; padding: 0;
  display: grid; gap: 14px; grid-template-columns: 1fr;
}
.steps li {
  counter-increment: step;
  display: grid; grid-template-columns: 1.6rem 1fr; column-gap: 10px;
  border-top: 2px solid rgba(255, 255, 255, 0.4);
  padding-top: 10px; max-width: 36ch;
}
.steps li::before {
  content: counter(step);
  font: 600 1.5rem/1 var(--serif);
}
@media (min-width: 820px) {
  .steps { grid-template-columns: repeat(4, 1fr); gap: 24px; }
  .steps li { display: block; }
  .steps li::before { display: block; font-size: 1.9rem; margin-bottom: 8px; }
}
.return { margin: 0; max-width: 62ch; color: rgba(255, 255, 255, 0.92); }

/* ---------- Поиск и теги ---------- */

main { padding-top: 24px; padding-bottom: 32px; }

.search input {
  width: 100%; max-width: 520px; height: 46px; padding: 0 14px;
  font: inherit; color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line); border-radius: var(--radius);
}
.search input::placeholder { color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 0; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 0 12px;
  font: inherit; font-size: 0.9375rem; line-height: 1;
  color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--line); border-radius: var(--radius);
  cursor: pointer;
}
.chip:hover { border-color: var(--primary-text); }
.chip[aria-pressed="true"] {
  background: var(--primary); border-color: var(--primary); color: var(--on-primary);
}
.chip-count { color: var(--muted); font-size: 0.8125rem; }
.chip[aria-pressed="true"] .chip-count { color: rgba(255, 255, 255, 0.82); }
.chip-more { border-style: dashed; color: var(--primary-text); }
.chips-small .chip { min-height: 34px; font-size: 0.875rem; }

.count { margin: 16px 0 22px; color: var(--muted); font-size: 0.9375rem; }

.status { padding: 24px 0; color: var(--muted); }
.status.is-error { color: var(--ink); }
.status button {
  margin-left: 8px; padding: 6px 12px;
  font: inherit; color: var(--primary-text); background: transparent;
  border: 1.5px solid var(--primary-text); border-radius: var(--radius); cursor: pointer;
}

/* ---------- Плитки ---------- */

.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 28px 16px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
@media (min-width: 640px) {
  .grid { gap: 36px 24px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

.tile { display: flex; flex-direction: column; min-width: 0; }
.tile-open {
  display: flex; flex-direction: column; gap: 10px; flex: 1;
  color: inherit; text-decoration: none;
}
.tile-title {
  font: 600 1.0625rem/1.25 var(--serif);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.tile-open:hover .tile-title { text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
.tile-authors {
  color: var(--muted); font-size: 0.9rem; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.cover-frame { position: relative; display: block; }
.cover {
  display: block; aspect-ratio: 2 / 3; container-type: inline-size;
  overflow: hidden; border-radius: 3px; background: var(--line);
  outline: 1px solid rgba(0, 0, 0, 0.14); outline-offset: -1px;
}
.cover img { width: 100%; height: 100%; object-fit: cover; }

/* Обложки нет: рисуем корешок с названием. Цвет зависит от id книги. */
.cover[data-tone="0"] { --tone: #17479e; }
.cover[data-tone="1"] { --tone: #0f6464; }
.cover[data-tone="2"] { --tone: #86375a; }
.cover[data-tone="3"] { --tone: #96600f; }
.cover[data-tone="4"] { --tone: #3b5a37; }
.cover[data-tone="5"] { --tone: #54479a; }
.cover.is-placeholder { background: var(--tone); color: #fff; }
.ph {
  position: relative; height: 100%;
  display: flex; flex-direction: column; justify-content: space-between; gap: 8px;
  padding: 12cqi 9cqi 9cqi 15cqi;
}
.ph::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 5cqi;
  background: rgba(0, 0, 0, 0.22);
}
.ph-title {
  font: 600 clamp(0.85rem, 10cqi, 1.7rem)/1.15 var(--serif);
  display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.ph-author { font-size: clamp(0.7rem, 6.5cqi, 1rem); opacity: 0.88; }

.badge {
  display: inline-block; padding: 3px 8px; border-radius: 3px;
  font-size: 0.8125rem; font-weight: 600; line-height: 1.3;
}
.badge.free { background: var(--free-bg); color: var(--free-ink); }
.badge.busy { background: var(--busy-bg); color: var(--busy-ink); }
.badge.soon { background: var(--soon-bg); color: var(--soon-ink); }
.tile-badge { align-self: flex-start; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 14px; margin-top: 14px;
  font: 600 0.9375rem/1.2 var(--sans); text-align: center; text-decoration: none;
  color: var(--primary-text); background: transparent;
  border: 1.5px solid var(--primary-text); border-radius: var(--radius);
}
.btn:hover { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { filter: brightness(1.12); }

/* ---------- Карточка книги ---------- */

.card {
  width: min(860px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 0; border-radius: 8px; overflow: auto;
  background: var(--surface); color: var(--ink);
}
.card::backdrop { background: rgba(8, 14, 24, 0.64); }

.card-bar {
  position: sticky; top: 0; z-index: 1;
  display: flex; justify-content: flex-end; padding: 8px 8px 0;
  background: var(--surface);
}
.close {
  display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
  color: var(--muted); background: transparent; border: 0; border-radius: var(--radius); cursor: pointer;
}
.close:hover { background: var(--line); color: var(--ink); }

.sheet {
  display: grid; grid-template-columns: 250px 1fr; gap: 28px;
  padding: 0 28px 30px;
}
.sheet-body { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.sheet-body p { margin: 0; }
.sheet-body h2 {
  margin: 0; overflow-wrap: anywhere;
  font: 600 clamp(1.5rem, 4vw, 2rem)/1.15 var(--serif);
}
.card-authors { color: var(--muted); font-size: 1.0625rem; }
.annotation { white-space: pre-line; max-width: 62ch; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.sheet-body .btn { align-self: flex-start; min-width: 220px; margin-top: 6px; }

@media (max-width: 679px) {
  .card { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .sheet { grid-template-columns: 1fr; gap: 20px; padding: 0 20px 28px; }
  .sheet-cover { max-width: 200px; }
  .sheet-body .btn { align-self: stretch; }
}

@media (prefers-reduced-motion: no-preference) {
  .card[open] { animation: card-in 0.18s ease-out; }
  @keyframes card-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
  }
}

.foot { padding-bottom: 40px; color: var(--muted); font-size: 0.875rem; }
.foot p { margin: 0; }
