:root {
  --paper: #f4efe6;
  --paper-deep: #e9e0d3;
  --ink: #241f1a;
  --muted: #746c62;
  --line: #d7cec1;
  --accent: #9f4f38;
  --card: #faf7f1;
  --reader-font-size: 20px;
  color-scheme: light;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

:root[data-theme="dark"] {
  --paper: #1b1a18;
  --paper-deep: #24221f;
  --ink: #e9e2d8;
  --muted: #aaa095;
  --line: #3b3732;
  --accent: #dc8a6b;
  --card: #24221f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: var(--paper); }
a { color: inherit; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 10px;
  left: 10px;
  padding: 10px 14px;
  background: var(--ink);
  color: var(--paper);
  transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.site-header,
.site-footer,
.hero,
.library-section {
  width: min(1180px, calc(100% - 48px));
  margin-inline: auto;
}

.site-header {
  min-height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 750; text-decoration: none; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  font-family: Georgia, serif;
  font-style: italic;
}
.header-note { color: var(--muted); font-size: 13px; letter-spacing: .12em; }

.hero { padding: clamp(80px, 12vw, 160px) 0 clamp(90px, 13vw, 170px); }
.eyebrow { margin: 0 0 18px; color: var(--accent); font-size: 11px; font-weight: 750; letter-spacing: .19em; }
.hero h1 {
  max-width: 850px;
  margin: 0;
  font-family: "Songti SC", SimSun, Georgia, serif;
  font-size: clamp(46px, 8vw, 92px);
  font-weight: 500;
  line-height: 1.16;
  letter-spacing: -.055em;
}
.hero-copy { max-width: 530px; margin: 34px 0 0; color: var(--muted); font-size: 17px; line-height: 1.9; }
.hero-meta { display: flex; gap: 30px; margin-top: 42px; color: var(--muted); font-size: 13px; }
.hero-meta strong { color: var(--ink); font-family: Georgia, serif; font-size: 22px; font-weight: 500; }

.library-section { padding-bottom: 120px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 30px; margin-bottom: 42px; }
.section-heading h2 { margin: 0; font-family: "Songti SC", SimSun, serif; font-size: clamp(34px, 5vw, 54px); font-weight: 500; }
.search-box { width: min(280px, 100%); display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.search-box svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.search-box input { width: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; }
.search-box input::placeholder { color: var(--muted); }

.book-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 68px 34px; }
.book-card { min-width: 0; }
.cover-link { display: block; text-decoration: none; }
.book-cover,
.reader-cover {
  --cover-a: #8e6756;
  --cover-b: #3c302c;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 72% 24%, rgb(255 255 255 / 20%), transparent 24%),
    linear-gradient(145deg, var(--cover-a), var(--cover-b));
}
.book-cover::before,
.reader-cover::before { content: ""; position: absolute; inset: 5% 7%; border: 1px solid rgb(255 255 255 / 25%); }
.book-cover::after,
.reader-cover::after { content: ""; position: absolute; inset: 0 auto 0 8%; width: 1px; background: rgb(0 0 0 / 12%); box-shadow: 2px 0 rgb(255 255 255 / 8%); }
.book-cover { aspect-ratio: 3 / 4.15; border-radius: 2px 7px 7px 2px; box-shadow: 0 22px 44px rgb(58 43 33 / 18%); transition: transform .35s ease, box-shadow .35s ease; }
.cover-link:hover .book-cover { transform: translateY(-7px) rotate(.4deg); box-shadow: 0 30px 55px rgb(58 43 33 / 24%); }
.cover-placeholder { position: absolute; left: 14%; bottom: 13%; color: rgb(255 255 255 / 72%); font-family: "Songti SC", SimSun, serif; font-size: 13px; letter-spacing: .18em; }
.book-info { padding-top: 23px; }
.book-labels { display: flex; gap: 8px; margin-bottom: 11px; color: var(--muted); font-size: 11px; }
.book-labels span { padding: 4px 7px; border: 1px solid var(--line); border-radius: 20px; }
.book-labels .adult-label { color: var(--accent); border-color: color-mix(in srgb, var(--accent), transparent 55%); }
.book-info h3 { margin: 0; font-family: "Songti SC", SimSun, serif; font-size: 24px; font-weight: 600; line-height: 1.35; }
.book-info h3 a { text-decoration: none; }
.book-info h3 a:hover { color: var(--accent); }
.book-description { min-height: 4.8em; margin: 13px 0 16px; color: var(--muted); font-size: 13px; line-height: 1.75; display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 3; }
.book-details { display: flex; gap: 18px; color: var(--muted); font-family: Georgia, serif; font-size: 12px; }
.card-progress { height: 2px; margin-top: 17px; overflow: hidden; background: var(--line); }
.card-progress span { display: block; height: 100%; background: var(--accent); }
.loading-message, .empty-state { grid-column: 1 / -1; padding: 70px 0; color: var(--muted); text-align: center; }

.site-footer { display: flex; justify-content: space-between; padding: 30px 0 42px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
noscript { display: block; padding: 20px; text-align: center; }

/* Reader */
.reader-page { transition: color .2s ease, background .2s ease; }
.reading-progress { position: fixed; z-index: 50; inset: 0 0 auto; height: 3px; background: transparent; }
.reading-progress span { display: block; width: 0; height: 100%; background: var(--accent); }
.reader-header {
  position: sticky;
  z-index: 40;
  top: 0;
  height: 66px;
  display: grid;
  grid-template-columns: 1fr minmax(0, 2fr) 1fr;
  align-items: center;
  padding: 0 26px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper), transparent 8%);
  backdrop-filter: blur(14px);
}
.reader-back { justify-self: start; display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; text-decoration: none; }
.reader-back svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.reader-current-title { overflow: hidden; margin: 0; font-family: "Songti SC", SimSun, serif; font-size: 14px; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.reader-tools { justify-self: end; display: flex; gap: 5px; }
.reader-tools button, .icon-button { min-height: 34px; padding: 0 9px; border: 0; border-radius: 5px; color: var(--muted); background: transparent; cursor: pointer; }
.reader-tools button:hover, .icon-button:hover { color: var(--ink); background: var(--paper-deep); }
.reader-main { width: min(100% - 40px, 940px); margin: 0 auto; }
.reader-loading, .reader-error { padding: 30vh 0; color: var(--muted); text-align: center; }
.reader-error h1 { color: var(--ink); font-family: "Songti SC", SimSun, serif; font-weight: 500; }
.book-title-page { min-height: min(760px, calc(100vh - 66px)); display: grid; grid-template-columns: 260px 1fr; align-items: center; gap: clamp(50px, 8vw, 100px); padding: 80px 0; border-bottom: 1px solid var(--line); }
.reader-cover { width: 100%; aspect-ratio: 3 / 4.15; border-radius: 2px 7px 7px 2px; box-shadow: 0 24px 55px rgb(41 33 27 / 24%); }
.reader-cover span { position: absolute; left: 16%; bottom: 14%; color: rgb(255 255 255 / 72%); font-size: 12px; letter-spacing: .17em; }
.title-details h1 { margin: 0; font-family: "Songti SC", SimSun, serif; font-size: clamp(42px, 7vw, 76px); font-weight: 500; line-height: 1.18; letter-spacing: -.05em; }
.book-meta { margin-top: 25px; color: var(--muted); font-size: 13px; }
.book-text { width: min(100%, 730px); margin: 0 auto; padding: clamp(80px, 12vw, 150px) 0; font-family: "Songti SC", STSong, SimSun, Georgia, serif; font-size: var(--reader-font-size); line-height: 2.08; letter-spacing: .025em; }
.book-text p { margin: 0 0 1.5em; text-align: justify; text-wrap: pretty; }
.book-text h2 { margin: 4em 0 1.7em; font-size: 1.5em; font-weight: 600; line-height: 1.5; text-align: center; }
.book-text h2:first-child { margin-top: 0; }
.reading-end { padding: 40px 0 150px; border-top: 1px solid var(--line); text-align: center; }
.reading-end > span { display: inline-grid; place-items: center; width: 50px; height: 50px; border: 1px solid var(--line); border-radius: 50%; font-family: "Songti SC", SimSun, serif; }
.reading-end p { color: var(--muted); }
.end-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; margin-top: 34px; }
.end-actions a, .button { padding: 11px 17px; border: 1px solid var(--line); border-radius: 4px; text-decoration: none; }

.modal { width: min(520px, calc(100% - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--card); box-shadow: 0 25px 90px rgb(0 0 0 / 28%); }
.modal::backdrop { background: rgb(20 17 14 / 68%); backdrop-filter: blur(4px); }
.modal-inner { padding: clamp(28px, 6vw, 48px); }
.modal h2 { margin: 0 0 18px; font-family: "Songti SC", SimSun, serif; font-size: 32px; font-weight: 500; }
.modal p:not(.eyebrow) { color: var(--muted); line-height: 1.8; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 30px; }
.button { cursor: pointer; }
.button.primary { border-color: var(--ink); color: var(--paper); background: var(--ink); }
.button.secondary { color: var(--muted); background: transparent; }
.modal-title-row { display: flex; align-items: start; justify-content: space-between; }
.icon-button { font-size: 28px; line-height: 1; }
.reader-library { max-height: min(55vh, 520px); overflow-y: auto; border-top: 1px solid var(--line); }
.reader-library a { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; padding: 14px 2px; border-bottom: 1px solid var(--line); text-decoration: none; }
.reader-library a[aria-current="page"] { color: var(--accent); }
.reader-library small { flex: none; color: var(--muted); }
.toast { position: fixed; z-index: 60; left: 50%; bottom: 28px; padding: 10px 16px; border-radius: 30px; color: var(--paper); background: var(--ink); font-size: 13px; transform: translateX(-50%); }

.palette-0 { --cover-a: #806858; --cover-b: #332c28; }
.palette-1 { --cover-a: #a85c45; --cover-b: #542f2d; }
.palette-2 { --cover-a: #667690; --cover-b: #273447; }
.palette-3 { --cover-a: #807151; --cover-b: #373123; }
.palette-4 { --cover-a: #7f555d; --cover-b: #37252c; }
.palette-5 { --cover-a: #657b68; --cover-b: #2f3f35; }
.palette-6 { --cover-a: #966d4a; --cover-b: #493424; }
.palette-7 { --cover-a: #5d7181; --cover-b: #293640; }
.palette-8 { --cover-a: #638077; --cover-b: #293d38; }

@media (max-width: 850px) {
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .book-title-page { grid-template-columns: 210px 1fr; gap: 45px; }
}

@media (max-width: 600px) {
  .site-header, .site-footer, .hero, .library-section { width: min(100% - 28px, 1180px); }
  .site-header { min-height: 68px; }
  .hero { padding: 80px 0 100px; }
  .hero h1 { font-size: 47px; }
  .hero-copy { font-size: 15px; }
  .section-heading { align-items: stretch; flex-direction: column; }
  .search-box { width: 100%; }
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 48px 16px; }
  .book-info h3 { font-size: 19px; }
  .book-description { min-height: 0; -webkit-line-clamp: 2; }
  .book-details { flex-direction: column; gap: 4px; }
  .site-footer { gap: 20px; }
  .reader-header { height: 58px; grid-template-columns: auto 1fr auto; padding: 0 10px; }
  .reader-back span, .reader-current-title, #font-down { display: none; }
  .reader-tools { gap: 0; }
  .reader-tools button { padding-inline: 8px; font-size: 13px; }
  .reader-main { width: min(100% - 30px, 940px); }
  .book-title-page { min-height: auto; grid-template-columns: 120px 1fr; gap: 25px; padding: 62px 0; }
  .title-details h1 { font-size: clamp(31px, 10vw, 46px); }
  .title-details .eyebrow { margin-bottom: 11px; font-size: 9px; }
  .book-meta { margin-top: 14px; font-size: 11px; line-height: 1.6; }
  .book-text { padding: 76px 0 100px; line-height: 2; }
  .book-text p { text-align: left; }
  .reading-end { padding-bottom: 100px; }
  .modal-actions { align-items: stretch; flex-direction: column-reverse; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .book-cover { transition: none; }
}
