:root {
  color-scheme: light;
  --bg: #ffffff;
  --ink: #171614;
  --muted: #6f6a61;
  --line: #e4dfd6;
  --panel: #f6f4ef;
  --panel-strong: #ebe5da;
  --accent: #6c4b34;
  --accent-dark: #3e2b1f;
  --shadow: 0 22px 64px rgba(31, 27, 22, 0.15);
  --page-w: 1275;
  --page-h: 1650;
  --spread-ratio: 1.5455;
  --single-page-ratio: 0.7727;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
}

.hidden {
  display: none !important;
}

.library {
  width: min(100%, 1360px);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(24px, 4vw, 64px);
}

.site-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 340px);
  gap: 32px;
  align-items: end;
  margin-bottom: clamp(28px, 5vw, 64px);
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.site-header h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.25rem, 6vw, 5.6rem);
  font-weight: 400;
  line-height: 0.94;
  letter-spacing: 0;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.7;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: clamp(24px, 3vw, 42px);
  align-items: start;
}

.book-grid.has-featured-book {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(18px, 2.4vw, 34px);
}

.book-card {
  display: grid;
  gap: 16px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.featured-book-card {
  grid-column: 1 / -1;
  grid-template-columns: minmax(260px, 440px) minmax(0, 1fr);
  gap: clamp(28px, 5vw, 72px);
  align-items: center;
  margin-bottom: clamp(10px, 2vw, 24px);
  padding-bottom: clamp(26px, 4vw, 54px);
  border-bottom: 1px solid var(--line);
}

.book-cover {
  position: relative;
  display: block;
  aspect-ratio: var(--page-w) / var(--page-h);
  overflow: hidden;
  background: var(--panel);
  box-shadow:
    0 18px 46px rgba(31, 27, 22, 0.18),
    inset 0 0 0 1px rgba(31, 27, 22, 0.06);
  transition:
    box-shadow 180ms ease,
    transform 180ms ease;
}

.book-cover::before {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 1;
  width: 12px;
  content: "";
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.22), rgba(255, 255, 255, 0));
  pointer-events: none;
}

.book-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-card:hover .book-cover,
.book-card:focus-visible .book-cover {
  transform: translateY(-4px);
  box-shadow:
    0 26px 58px rgba(31, 27, 22, 0.22),
    inset 0 0 0 1px rgba(31, 27, 22, 0.06);
}

.featured-book-card .book-cover {
  box-shadow:
    0 30px 80px rgba(31, 27, 22, 0.22),
    inset 0 0 0 1px rgba(31, 27, 22, 0.06);
}

.featured-book-card:hover .book-cover,
.featured-book-card:focus-visible .book-cover {
  transform: translateY(-6px);
  box-shadow:
    0 38px 94px rgba(31, 27, 22, 0.25),
    inset 0 0 0 1px rgba(31, 27, 22, 0.06);
}

.book-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 8px;
}

.book-meta {
  display: grid;
  gap: 6px;
}

.book-title,
.book-subtitle,
.book-pages {
  display: block;
}

.featured-book-card .book-meta {
  align-content: center;
  max-width: 520px;
  gap: 14px;
}

.book-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.16rem;
  line-height: 1.25;
}

.featured-book-card .book-title {
  font-size: clamp(2.2rem, 5vw, 4.8rem);
  line-height: 0.96;
}

.book-subtitle {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.featured-book-card .book-subtitle {
  font-size: clamp(1rem, 1.7vw, 1.28rem);
  line-height: 1.55;
}

.book-pages {
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.book-action {
  display: inline-grid;
  place-items: center;
  width: fit-content;
  min-height: 42px;
  margin-top: 8px;
  padding: 0 18px;
  border: 1px solid var(--accent);
  background: var(--accent-dark);
  color: #fff;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition:
    background-color 180ms ease,
    border-color 180ms ease;
}

.featured-book-card:hover .book-action,
.featured-book-card:focus-visible .book-action {
  border-color: var(--accent-dark);
  background: var(--accent);
}

.empty-state {
  margin: 0;
  color: var(--muted);
}

.reader {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  background: var(--bg);
}

.reader:fullscreen {
  background: var(--bg);
}

.reader-toolbar {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(0, auto) minmax(190px, 1fr);
  align-items: center;
  gap: 16px;
  padding: 16px clamp(14px, 3vw, 36px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

.reader-title {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1rem, 2vw, 1.5rem);
  font-weight: 400;
  letter-spacing: 0;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-tools {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition:
    background-color 180ms ease,
    border-color 180ms ease,
    color 180ms ease;
}

.btn:not(.icon-btn) {
  padding: 0 14px;
}

.btn:hover:not(:disabled),
.btn:focus-visible:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.btn:disabled {
  background: #f2f0ea;
  color: #aaa49a;
  cursor: not-allowed;
}

.icon-btn {
  width: 42px;
  padding: 0;
  font-size: 1.35rem;
  line-height: 1;
}

.fullscreen-btn {
  min-width: 112px;
}

.page-indicator {
  min-width: 70px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-align: center;
}

.flipbook-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: clamp(8px, 2vw, 28px);
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0)),
    var(--panel);
}

.flipbook {
  width: min(100%, calc((100vh - 126px) * var(--spread-ratio)));
  width: min(100%, calc((100dvh - 126px) * var(--spread-ratio)));
  max-width: 1600px;
  height: auto;
  max-height: 100%;
  aspect-ratio: var(--spread-ratio);
  filter: drop-shadow(var(--shadow));
}

.stf__parent {
  margin: 0 auto;
}

.catalog-page {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 0;
  overflow: hidden;
  background: #fff;
  box-shadow: none;
}

.catalog-page img {
  display: block;
  width: 100%;
  height: 100%;
  background: #faf9f6;
  object-fit: contain;
  object-position: center;
  user-select: none;
  -webkit-user-drag: none;
}

.page-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.62), transparent),
    var(--panel-strong);
  background-size: 200% 100%;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  animation: page-sheen 1.2s linear infinite;
}

.catalog-page:not(.is-loading):not(.has-error) .page-placeholder {
  display: none;
}

.catalog-page.has-error .page-placeholder {
  background: #f7f1ee;
  color: var(--accent-dark);
  animation: none;
}

.reader-status,
.reader-hint {
  margin: 0;
  padding: 10px clamp(14px, 3vw, 36px);
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.reader-status:empty {
  display: none;
}

.reader-hint {
  border-top: 1px solid var(--line);
}

@keyframes page-sheen {
  from {
    background-position: 160% 0;
  }

  to {
    background-position: -40% 0;
  }
}

@media (max-width: 780px) {
  .library {
    padding: 24px 16px 48px;
  }

  .site-header {
    grid-template-columns: 1fr;
    gap: 14px;
    margin-bottom: 32px;
  }

  .book-grid {
    grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
    gap: 22px 16px;
  }

  .book-grid.has-featured-book {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .featured-book-card {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .featured-book-card .book-cover {
    width: min(100%, 360px);
  }

  .featured-book-card .book-title {
    font-size: clamp(2rem, 12vw, 3.3rem);
  }

  .reader-toolbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    padding: 10px 12px;
  }

  .reader-title {
    font-size: 0.94rem;
  }

  .reader-tools {
    gap: 4px;
  }

  .btn:not(.icon-btn) {
    padding: 0 10px;
  }

  .btn {
    min-height: 38px;
    font-size: 0.68rem;
  }

  .icon-btn {
    width: 34px;
    font-size: 1.1rem;
  }

  .fullscreen-btn {
    min-width: 84px;
  }

  .page-indicator {
    min-width: 54px;
    font-size: 0.68rem;
  }

  .flipbook-stage {
    padding: 8px;
  }

  .flipbook {
    width: min(100%, calc((100vh - 74px) * var(--single-page-ratio)));
    width: min(100%, calc((100dvh - 74px) * var(--single-page-ratio)));
    max-width: 800px;
    height: auto;
    max-height: 100%;
    aspect-ratio: var(--single-page-ratio);
  }

  .reader-hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
