:root {
  color-scheme: light;
  --bg: #f5efe5;
  --surface: #fffaf2;
  --surface-strong: #efe2ce;
  --text: #2f261d;
  --muted: #7d6d5e;
  --border: #ddceb7;
  --accent: #8a4d2f;
  --accent-strong: #69361f;
  --accent-soft: #ead2bb;
  --shadow: 0 22px 48px rgba(72, 48, 28, 0.12);
  --reader-size: 18px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #181411;
  --surface: #211b17;
  --surface-strong: #2e251f;
  --text: #f1e4d3;
  --muted: #b9aa9b;
  --border: #46382e;
  --accent: #d69a6c;
  --accent-strong: #f1bc8f;
  --accent-soft: #392b22;
  --shadow: 0 22px 48px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background: radial-gradient(circle at top left, var(--accent-soft), transparent 35rem), var(--bg);
  color: var(--text);
  font-family: ui-serif, "Noto Serif SC", "Songti SC", STSong, Georgia, serif;
  line-height: 1.72;
}

a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
h1, h2, h3, p { margin-top: 0; }

.skip-link {
  position: fixed;
  top: -4rem;
  left: 1rem;
  z-index: 20;
  padding: .65rem 1rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
}
.skip-link:focus { top: 1rem; }

.shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 1rem 4rem;
}

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

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .8rem;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.2;
}

.brand small,
.eyebrow,
.section-note,
.reader-meta,
.meta-list,
#bookCount,
#chapterCount {
  color: var(--muted);
  font-size: .88rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: .8rem;
  flex-wrap: wrap;
}

button,
.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: .72rem 1rem;
  cursor: pointer;
  transition: transform .18s ease, background .18s ease, border-color .18s ease;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 3px;
}

button:hover,
.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.primary-button { background: var(--accent); color: #fff; box-shadow: 0 10px 22px rgba(138, 77, 47, .2); }
.secondary-button,
.ghost-button,
.icon-button {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 1.5rem;
  align-items: stretch;
  padding: 2.5rem 0 1.5rem;
}

.hero-copy,
.hero-card,
.panel-card,
.reader-panel,
.about {
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
}

.hero-copy {
  border-radius: 30px;
  padding: clamp(1.25rem, 3vw, 2rem);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.hero h1 {
  font-size: clamp(2.5rem, 7vw, 5rem);
  line-height: .96;
  letter-spacing: -.08em;
  margin: .35rem 0 1rem;
}

.summary {
  max-width: 48rem;
  color: var(--muted);
  font-size: 1.08rem;
}

.hero-actions,
.reader-controls,
.reader-nav {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
}

.hero-card {
  border-radius: 30px;
  padding: 1rem;
}

.hero-cover {
  min-height: 340px;
  border-radius: 24px;
  padding: 1.25rem;
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(145deg, #2f241d, #8a4d2f 52%, #d69a6c);
}

.hero-cover span {
  letter-spacing: .34em;
  opacity: .74;
}

.hero-cover strong {
  font-size: 2.5rem;
  line-height: 1.04;
  writing-mode: vertical-rl;
  letter-spacing: .16em;
  align-self: center;
}

.hero-cover em {
  font-style: normal;
  opacity: .9;
}

.hero-stats {
  display: grid;
  gap: .9rem;
  margin: 1rem 0 0;
}

.hero-stats div {
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: .75rem;
  padding: .65rem .1rem;
  border-bottom: 1px solid var(--border);
}

.hero-stats dt { color: var(--muted); }
.hero-stats dd { margin: 0; }

.library-strip {
  padding: 1rem 0 1.5rem;
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.section-heading h2,
.section-heading h3 {
  margin-bottom: .1rem;
}

.library-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: .85rem;
}

.library-tab {
  padding: 1rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: left;
}

.library-tab[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 36%, var(--border));
}

.library-tab strong,
.library-tab small {
  display: block;
}

.library-tab small {
  margin-top: .25rem;
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.sidebar {
  display: grid;
  gap: 1rem;
  position: sticky;
  top: 92px;
}

.panel-card,
.reader-panel,
.about {
  border-radius: 28px;
}

.panel-card {
  padding: 1rem;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.search-field {
  display: grid;
  gap: .4rem;
  margin: 1rem 0;
}

.search-field span {
  color: var(--muted);
  font-size: .9rem;
}

.search-field input {
  width: 100%;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: .82rem .9rem;
}

.book-grid {
  display: grid;
  gap: .85rem;
}

.book-card-btn {
  width: 100%;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: .95rem;
  text-align: left;
  display: grid;
  gap: .55rem;
}

.book-card-btn[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent-soft) 76%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 34%, var(--border));
}

.book-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
}

.book-tag {
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent-soft) 75%, transparent);
  color: var(--accent-strong);
  font-size: .78rem;
  padding: .2rem .5rem;
  white-space: nowrap;
}

.book-card-btn h3 {
  margin-bottom: .15rem;
  font-size: 1.02rem;
}

.book-card-btn p {
  color: var(--muted);
  font-size: .92rem;
}

.book-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  color: var(--muted);
  font-size: .82rem;
}

.meta-list {
  list-style: none;
  padding: 0;
  margin: .75rem 0 0;
  display: grid;
  gap: .65rem;
}

.meta-list li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px dashed var(--border);
  padding-bottom: .4rem;
}

.reader-panel {
  padding: clamp(1rem, 2.5vw, 1.6rem);
}

.reader-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
}

.reader-top h2 {
  margin-bottom: 0;
  font-size: clamp(1.6rem, 3vw, 2.4rem);
}

.book-summary {
  display: grid;
  gap: .75rem;
  padding: 1rem 0 1.1rem;
  border-bottom: 1px solid var(--border);
}

.summary-row {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  justify-content: space-between;
}

.summary-row strong {
  font-size: 1rem;
}

.summary-row span {
  color: var(--muted);
}

.chapter-strip {
  padding-top: 1rem;
}

.chapter-list {
  display: flex;
  gap: .6rem;
  overflow-x: auto;
  padding-bottom: .25rem;
  scroll-snap-type: x proximity;
}

.chapter-pill {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: .65rem .9rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  min-width: 150px;
  scroll-snap-align: start;
}

.chapter-pill[aria-current="true"] {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.chapter-pill strong,
.chapter-pill small {
  display: block;
}

.chapter-pill small {
  margin-top: .2rem;
  color: var(--muted);
}

.reader-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 1rem 0 1.3rem;
}

.chapter-content {
  font-size: var(--reader-size);
  max-width: 42em;
  margin: 0 auto;
}

.chapter-content p {
  margin: 0 0 1.02em;
  text-indent: 2em;
}

.empty-state {
  padding: 1.6rem;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 20px;
  background: var(--surface);
}

.reader-nav {
  justify-content: space-between;
  border-top: 1px solid var(--border);
  margin-top: 1.6rem;
  padding-top: 1rem;
}

.about {
  margin-top: 1.25rem;
  padding: clamp(1rem, 2.5vw, 1.6rem);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.feature-grid article {
  border-radius: 22px;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
}

@media (max-width: 1024px) {
  .hero,
  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }
}

@media (max-width: 720px) {
  .shell {
    padding-inline: .75rem;
  }

  .topbar {
    align-items: flex-start;
    padding: .8rem 0;
  }

  .topbar-actions {
    justify-content: flex-end;
    gap: .5rem;
  }

  .topbar-actions a {
    display: none;
  }

  .hero-cover {
    min-height: 280px;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .feature-grid {
    grid-template-columns: 1fr;
  }

  .reader-top {
    flex-direction: column;
  }

  .reader-nav button,
  .hero-actions a {
    width: 100%;
  }
}
