:root {
  --bg: #f4f0e8;
  --paper: #fffdf8;
  --paper-strong: #ffffff;
  --ink: #1f2933;
  --muted: #657282;
  --line: rgba(31, 41, 51, 0.14);
  --accent: #0d7c86;
  --accent-2: #b3532a;
  --shelf: #8d5b3b;
  --shelf-dark: #503221;
  --shelf-light: #c09469;
  --shelf-back: #efe4d3;
  --wood-texture: url("./bookshelf-wood.png");
  --shadow: 0 22px 70px rgba(31, 41, 51, 0.12);
  --radius: 8px;
}

:root[data-theme="dark"] {
  --bg: #111416;
  --paper: #191e20;
  --paper-strong: #20272a;
  --ink: #ecf0ef;
  --muted: #a8b2b0;
  --line: rgba(236, 240, 239, 0.14);
  --accent: #54c6be;
  --accent-2: #ffb27a;
  --shelf: #7a5640;
  --shelf-dark: #1d1714;
  --shelf-light: #a98360;
  --shelf-back: #211a16;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(13, 124, 134, 0.06), transparent 22%, transparent 78%, rgba(179, 83, 42, 0.07)),
    linear-gradient(180deg, rgba(255, 253, 248, 0.88), rgba(232, 225, 211, 0.86)),
    var(--bg);
  color: var(--ink);
  font: 16px/1.75 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
}

.site-shell {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(18px);
}

.topbar {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand span {
  color: var(--accent);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-actions a,
.icon-button {
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.nav-actions a:hover,
.nav-actions a.active,
.icon-button:hover {
  border-color: var(--line);
  color: var(--ink);
  background: var(--paper);
}

.library {
  max-width: 1240px;
  margin: 0 auto 64px;
  padding: 44px 24px 0;
}

.toc-card {
  position: sticky;
  top: 84px;
  align-self: start;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  box-shadow: var(--shadow);
}

.pagination a,
.pagination span {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
  color: var(--muted);
  background: var(--paper-strong);
}

.pagination a.active {
  border-color: transparent;
  color: #fff;
  background: var(--accent);
}

.shelf-stage {
  position: relative;
  padding: clamp(12px, 2vw, 22px);
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--shelf-dark) 78%, transparent);
  border-radius: 6px;
  background:
    radial-gradient(circle at 18% 8%, rgba(255, 246, 229, 0.2), transparent 28%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.13), transparent 25%, transparent 72%, rgba(25, 11, 5, 0.22)),
    var(--wood-texture);
  background-size:
    auto,
    auto,
    760px 760px;
  background-position:
    center,
    center,
    center top;
  box-shadow:
    0 34px 90px rgba(31, 41, 51, 0.2),
    0 7px 0 color-mix(in srgb, var(--shelf-dark) 74%, #000),
    inset 0 1px rgba(255, 255, 255, 0.48),
    inset 0 0 0 10px color-mix(in srgb, var(--shelf-dark) 80%, #000),
    inset 0 0 0 18px color-mix(in srgb, var(--shelf-light) 54%, #fff);
}

.shelf-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: inherit;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.14), transparent 22%, transparent 78%, rgba(0, 0, 0, 0.18)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent 18%, transparent 82%, rgba(0, 0, 0, 0.18));
  box-shadow:
    inset 24px 0 24px rgba(24, 13, 8, 0.18),
    inset -24px 0 24px rgba(24, 13, 8, 0.22);
  pointer-events: none;
}

.shelf-stage::after {
  display: none;
}

.book-grid {
  position: relative;
  z-index: 2;
  display: block;
  overflow: hidden;
  border: clamp(10px, 1.3vw, 16px) solid color-mix(in srgb, var(--shelf-dark) 90%, #000);
  border-radius: 4px;
  padding: clamp(16px, 2vw, 26px) clamp(16px, 2.2vw, 30px) 0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.1), transparent 18%, transparent 82%, rgba(0, 0, 0, 0.18)),
    linear-gradient(180deg, rgba(255, 244, 225, 0.18), rgba(48, 24, 12, 0.2)),
    var(--wood-texture);
  background-size:
    auto,
    auto,
    720px 720px;
  background-position:
    center,
    center,
    center top;
  box-shadow:
    0 22px 46px rgba(22, 11, 6, 0.34),
    inset 18px 0 28px rgba(30, 13, 6, 0.24),
    inset -18px 0 28px rgba(30, 13, 6, 0.26),
    inset 0 1px rgba(255, 255, 255, 0.24),
    inset 0 -2px rgba(0, 0, 0, 0.38);
}

.shelf-row {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  column-gap: clamp(26px, 3vw, 44px);
  align-items: end;
  min-height: clamp(430px, 38vw, 520px);
  padding: clamp(22px, 2.4vw, 34px) clamp(8px, 1.4vw, 18px) 0;
}

.shelf-row::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 38%;
  background: linear-gradient(180deg, transparent, rgba(24, 11, 5, 0.24));
  pointer-events: none;
}

.shelf-divider {
  position: relative;
  height: clamp(34px, 3vw, 46px);
  margin: 0 calc(clamp(16px, 2.2vw, 30px) * -1);
  background:
    linear-gradient(180deg, rgba(255, 246, 229, 0.32), transparent 22%, rgba(34, 15, 7, 0.24) 72%, rgba(12, 5, 2, 0.42)),
    linear-gradient(90deg, rgba(255, 255, 255, 0.12), transparent 18%, transparent 82%, rgba(0, 0, 0, 0.24)),
    var(--wood-texture);
  background-size:
    auto,
    auto,
    760px 760px;
  background-position:
    center,
    center,
    center 42%;
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.5),
    inset 0 -10px 14px rgba(18, 8, 3, 0.4),
    0 -14px 22px rgba(13, 6, 3, 0.24),
    0 14px 26px rgba(13, 6, 3, 0.28);
}

.shelf-divider::before,
.shelf-divider::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
}

.shelf-divider::before {
  top: 0;
  height: 7px;
  background: linear-gradient(180deg, rgba(255, 242, 218, 0.56), rgba(255, 242, 218, 0));
}

.shelf-divider::after {
  bottom: -8px;
  height: 8px;
  background: rgba(18, 8, 3, 0.42);
  filter: blur(6px);
}

.book-card {
  position: relative;
  min-height: 0;
  padding: 0 0 clamp(2px, 0.6vw, 8px);
  perspective: 1200px;
}

.book-card:nth-child(4n) {
  border-right: 0;
}

.book-card::before {
  display: none;
}

.book-card::after {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: -4px;
  height: 20px;
  z-index: 0;
  border-radius: 999px;
  background: rgba(12, 7, 4, 0.34);
  filter: blur(12px);
}

.book-card[hidden] {
  display: none;
}

.book-card-link {
  position: relative;
  z-index: 2;
  height: 100%;
  padding: 0;
  display: flex;
  flex-direction: column;
  justify-content: end;
  border-radius: var(--radius);
  transition: transform 180ms ease;
}

.book-card-link:hover {
  transform: translateY(-7px);
}

.book-cover {
  position: relative;
  margin: 0;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--line) 78%, #000);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow:
    0 22px 36px rgba(23, 12, 7, 0.28),
    0 8px 0 rgba(58, 35, 22, 0.18),
    inset 12px 0 18px rgba(0, 0, 0, 0.18);
  transform-origin: 24% 50%;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.book-cover::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 12%;
  z-index: 2;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.35), rgba(255, 255, 255, 0.08), transparent);
  mix-blend-mode: soft-light;
  pointer-events: none;
}

.book-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  background:
    linear-gradient(120deg, transparent 18%, rgba(255, 255, 255, 0.28) 38%, transparent 54%),
    linear-gradient(180deg, transparent 58%, rgba(0, 0, 0, 0.32));
  opacity: 0.68;
  pointer-events: none;
}

.book-cover img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform 220ms ease, filter 220ms ease;
}

.book-cover figcaption {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 4;
  min-height: 96px;
  padding: 12px;
  display: grid;
  align-items: end;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius);
  color: #fff;
  background: rgba(10, 14, 18, 0.56);
  backdrop-filter: blur(16px);
  font-size: 13px;
  line-height: 1.55;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.book-card-link:hover .book-cover {
  box-shadow:
    0 24px 58px rgba(31, 41, 51, 0.25),
    inset 12px 0 18px rgba(0, 0, 0, 0.2);
  transform: rotateY(-5deg) rotateX(2deg);
}

.book-card-link:hover .book-cover img {
  filter: saturate(1.08) contrast(1.04);
  transform: scale(1.035);
}

.book-card-link:hover figcaption {
  opacity: 1;
  transform: translateY(0);
}

.book-meta {
  margin-top: 12px;
  padding: 8px 12px 10px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid rgba(101, 68, 44, 0.18);
  border-radius: 6px;
  color: #68727a;
  background: rgba(255, 253, 247, 0.78);
  font-size: 12px;
  box-shadow: 0 12px 24px rgba(39, 21, 12, 0.1);
}

.pagination {
  position: relative;
  z-index: 2;
  margin-top: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.pagination div {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: center;
}

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 50;
  width: 100%;
  height: 3px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: 0 50%;
}

.reader-hero {
  max-width: 1000px;
  margin: 0 auto;
  padding: 56px 24px 34px;
}

.back-link {
  display: inline-block;
  margin-bottom: 24px;
  color: var(--muted);
}

.reader-hero h1 {
  margin: 0 0 14px;
  font-size: clamp(34px, 5vw, 60px);
  line-height: 1.08;
}

.reader-stats {
  display: flex;
  gap: 14px;
  color: var(--muted);
}

.reader-layout {
  max-width: 1240px;
  margin: 0 auto 80px;
  padding: 0 24px;
  display: grid;
  grid-template-columns: minmax(0, 780px) 320px;
  justify-content: center;
  gap: 44px;
}

.article-content {
  padding: 34px 44px 56px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.article-content h1,
.article-content h2,
.article-content h3,
.article-content h4 {
  scroll-margin-top: 92px;
  line-height: 1.35;
}

.article-content h1 {
  margin: 44px 0 18px;
  font-size: 30px;
}

.article-content h2 {
  margin: 38px 0 16px;
  font-size: 24px;
}

.article-content h3 {
  margin: 30px 0 12px;
  font-size: 19px;
}

.article-content p,
.article-content li {
  color: color-mix(in srgb, var(--ink) 86%, var(--muted));
}

.article-content p {
  margin: 0 0 18px;
}

.article-content blockquote {
  margin: 24px 0;
  padding: 16px 18px;
  border-left: 4px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--paper));
  color: var(--muted);
}

.article-content img {
  max-width: 100%;
  border-radius: var(--radius);
}

.toc-shell {
  min-width: 0;
}

.toc-card {
  max-height: calc(100vh - 104px);
  overflow: auto;
  padding: 16px 14px;
}

.toc-title {
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 800;
}

.toc-list,
.toc-list ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

.toc-list ol {
  display: none;
  padding-left: 13px;
}

.toc-item.is-current-section > ol,
.toc-item.is-active > ol {
  display: block;
}

.toc-list a {
  display: block;
  padding: 6px 8px;
  border-left: 2px solid transparent;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.toc-list ol a {
  font-size: 12px;
}

.toc-list a:hover,
.toc-list .is-active > a {
  border-left-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

@media (max-width: 980px) {
  .library,
  .reader-layout {
    display: block;
  }

  .toc-shell {
    display: none;
  }

  .shelf-row {
    column-gap: 18px;
    min-height: clamp(340px, 52vw, 460px);
    padding-left: 6px;
    padding-right: 6px;
  }

  .article-content {
    padding: 28px 24px 42px;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 14px 16px;
  }

  .nav-actions a {
    display: none;
  }

  .library,
  .reader-hero,
  .reader-layout {
    padding-left: 16px;
    padding-right: 16px;
  }

  .shelf-stage {
    padding: 12px;
  }

  .shelf-stage::after {
    display: none;
  }

  .book-grid {
    padding: 12px 12px 0;
  }

  .shelf-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 16px;
    min-height: auto;
    padding: 18px 4px 0;
  }

  .shelf-divider {
    height: 30px;
    margin-left: -12px;
    margin-right: -12px;
  }

  .book-card {
    padding: 0 0 6px;
    border-right: 0;
  }

  .book-card:nth-child(2n),
  .book-card:nth-child(4n) {
    border-right: 0;
  }

}
