:root {
  color-scheme: light;
  --paper: #f2efe7;
  --surface: #fbfaf6;
  --ink: #252823;
  --muted: #6d7168;
  --line: #cbc8bd;
  --accent: #47685c;
  --accent-soft: #dce6df;
  --warning: #f3e8ca;
  --shadow: 0 16px 50px rgba(47, 49, 43, 0.08);
  --highlight-yellow: #f7df78;
  --highlight-green: #a9d6b5;
  --highlight-blue: #a9cee0;
  --highlight-pink: #e8b8c5;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #171a18;
  --surface: #202421;
  --ink: #e7e7df;
  --muted: #a8ada4;
  --line: #3b423d;
  --accent: #91b7a7;
  --accent-soft: #293a33;
  --warning: #3c3527;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.24);
  --highlight-yellow: #76662d;
  --highlight-green: #365c42;
  --highlight-blue: #36566a;
  --highlight-pink: #714552;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Noto Serif SC", "Source Han Serif SC", "Songti SC", Georgia, serif;
  line-height: 1.85;
  transition: background-color 180ms ease, color 180ms ease;
}

button,
a {
  color: inherit;
}

button {
  font: inherit;
}

a {
  text-decoration: none;
}

.site-shell {
  min-height: 100vh;
}

.site-header {
  width: min(1180px, calc(100% - 40px));
  min-height: 84px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.site-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink);
  font-family: Georgia, serif;
  font-size: 21px;
}

.site-brand strong,
.site-brand small {
  display: block;
}

.site-brand strong {
  font-size: 15px;
}

.site-brand small {
  margin-top: 1px;
  color: var(--muted);
  font-family: Arial, sans-serif;
  font-size: 9px;
  letter-spacing: 0.16em;
}

.site-actions {
  display: flex;
  align-items: center;
  gap: 22px;
  font-size: 14px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
}

.site-main {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
}

.library-intro {
  min-height: 410px;
  padding: 88px 0 72px;
  border-bottom: 1px solid var(--line);
}

.eyebrow,
.book-kicker,
.book-meta {
  color: var(--accent);
  font-family: Arial, sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
}

.library-intro h1 {
  max-width: 820px;
  margin: 24px 0;
  font-size: clamp(38px, 6vw, 76px);
  font-weight: 500;
  line-height: 1.18;
  letter-spacing: 0;
  text-wrap: balance;
}

.intro-copy {
  max-width: 620px;
  color: var(--muted);
  font-size: 17px;
}

.shelf {
  padding: 56px 0 100px;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 22px;
}

.section-heading h2 {
  margin: 0;
  font-size: 25px;
  font-weight: 500;
}

.section-heading span {
  color: var(--muted);
  font-size: 13px;
}

.library-controls {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 220px;
  gap: 16px 22px;
  margin-bottom: 26px;
}

.library-controls label,
.sort-controls > span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-family: Arial, sans-serif;
  font-size: 12px;
}

.library-controls input,
.library-controls select {
  width: 100%;
  min-height: 46px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 0;
  outline: 0;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.library-controls input:focus,
.library-controls select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.sort-controls {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.sort-controls > span {
  margin: 0 4px 0 0;
}

.sort-controls button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.sort-controls button:hover,
.sort-controls button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.empty-books {
  padding: 42px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
}

.book-row {
  border-top: 1px solid var(--line);
}

.book-row:last-child {
  border-bottom: 1px solid var(--line);
}

.book-link {
  display: grid;
  grid-template-columns: 68px 1fr 180px;
  gap: 24px;
  align-items: center;
  padding: 30px 8px;
  transition: background-color 150ms ease, padding 150ms ease;
}

.book-link:hover {
  padding-right: 18px;
  padding-left: 18px;
  background: var(--surface);
}

.book-index {
  color: var(--muted);
  font-family: Georgia, serif;
  font-size: 20px;
}

.book-meta {
  display: flex;
  gap: 18px;
}

.book-main h3 {
  margin: 5px 0 7px;
  font-size: 25px;
  font-weight: 500;
}

.book-main p,
.book-author {
  color: var(--muted);
}

.book-main p {
  max-width: 680px;
  margin: 0;
  line-height: 1.6;
}

.book-author {
  display: grid;
  gap: 5px;
  justify-items: end;
  font-size: 13px;
}

.site-footer {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 32px 0 46px;
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.reader {
  padding: 42px 0 100px;
}

.back-link {
  color: var(--muted);
  font-size: 13px;
}

.book-header {
  max-width: 780px;
  margin: 70px auto 80px;
  text-align: center;
}

.book-kicker {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin: 24px 0;
}

.book-header h1 {
  margin: 0;
  font-size: clamp(38px, 6vw, 66px);
  font-weight: 500;
  line-height: 1.2;
}

.subtitle {
  color: var(--muted);
  font-size: 20px;
}

.book-details {
  display: flex;
  justify-content: center;
  gap: 22px;
  color: var(--muted);
  font-size: 13px;
}

.book-summary {
  margin: 30px auto 0;
  padding-top: 28px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 16px;
}

.reading-layout {
  position: relative;
  display: grid;
  grid-template-columns: 210px minmax(0, 760px);
  gap: 58px;
  justify-content: center;
}

.toc-panel {
  position: sticky;
  top: 28px;
  align-self: start;
  max-height: calc(100vh - 56px);
  overflow: auto;
  padding-right: 18px;
  border-right: 1px solid var(--line);
}

.toc-panel strong {
  font-size: 13px;
}

.toc-panel a {
  display: block;
  margin-top: 8px;
  padding: 8px 10px;
  border-left: 2px solid transparent;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  transition: color 150ms ease, background-color 150ms ease, border-color 150ms ease;
}

.toc-panel a:hover,
.toc-panel a.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.health-note,
.source-note {
  margin-bottom: 24px;
  padding: 18px 22px;
  background: var(--warning);
  border-left: 3px solid #a67c45;
  font-size: 13px;
}

.source-note {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.health-note p,
.source-note p {
  margin: 4px 0 0;
}

.annotation-guide {
  position: sticky;
  top: 0;
  z-index: 6;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 32px;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  color: var(--muted);
  font-family: Arial, sans-serif;
  font-size: 12px;
}

.annotation-guide button {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}

.guide-dot,
.selection-toolbar button[data-highlight] {
  width: 18px;
  height: 18px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 50%;
}

.yellow {
  background: var(--highlight-yellow);
}

.green {
  background: var(--highlight-green);
}

.blue {
  background: var(--highlight-blue);
}

.pink {
  background: var(--highlight-pink);
}

.book-content {
  min-height: 56vh;
  padding: 48px 58px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 17px;
}

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

.book-chapter.active {
  display: block;
  animation: chapter-in 180ms ease-out;
}

@keyframes chapter-in {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.book-content h2 {
  margin: 0 0 1.4em;
  padding: 0 0 0.75em;
  border-bottom: 1px solid var(--line);
  color: var(--accent);
  font-size: 29px;
  font-weight: 500;
  line-height: 1.35;
}

.book-content h3 {
  margin-top: 2.4em;
  font-size: 21px;
}

.book-content p,
.book-content li {
  text-align: justify;
  text-justify: inter-ideograph;
}

.book-content li {
  margin: 0.55em 0;
}

.book-content blockquote {
  margin: 2em 0;
  padding: 2px 0 2px 24px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  font-size: 18px;
}

.book-content mark.reader-highlight {
  padding: 0.08em 0;
  border-radius: 2px;
  color: inherit;
  cursor: pointer;
}

.book-content mark[data-color="yellow"] {
  background: var(--highlight-yellow);
}

.book-content mark[data-color="green"] {
  background: var(--highlight-green);
}

.book-content mark[data-color="blue"] {
  background: var(--highlight-blue);
}

.book-content mark[data-color="pink"] {
  background: var(--highlight-pink);
}

.book-content mark[data-note]:not([data-note=""]) {
  border-bottom: 2px solid var(--accent);
}

.chapter-pager {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  margin-top: 22px;
}

.chapter-pager button {
  min-height: 72px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.chapter-pager button:last-child {
  text-align: right;
}

.chapter-pager button:hover:not(:disabled) {
  border-color: var(--accent);
}

.chapter-pager button:disabled {
  opacity: 0.42;
  cursor: default;
}

.chapter-pager small,
.chapter-pager span {
  display: block;
}

.chapter-pager small,
.chapter-progress {
  color: var(--muted);
  font-family: Arial, sans-serif;
  font-size: 11px;
}

.chapter-pager button span {
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.4;
}

.chapter-progress {
  white-space: nowrap;
}

.selection-toolbar {
  position: fixed;
  z-index: 30;
  display: none;
  align-items: center;
  gap: 7px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.selection-toolbar.visible {
  display: flex;
}

.selection-toolbar button {
  cursor: pointer;
}

.selection-toolbar button[data-highlight] {
  padding: 0;
}

.selection-toolbar button[data-highlight="yellow"] {
  background: var(--highlight-yellow);
}

.selection-toolbar button[data-highlight="green"] {
  background: var(--highlight-green);
}

.selection-toolbar button[data-highlight="blue"] {
  background: var(--highlight-blue);
}

.selection-toolbar button[data-highlight="pink"] {
  background: var(--highlight-pink);
}

.note-button {
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line);
  background: transparent;
}

.annotation-panel {
  position: fixed;
  z-index: 40;
  top: 0;
  right: 0;
  width: min(390px, 92vw);
  height: 100vh;
  padding: 24px;
  overflow: auto;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(105%);
  transition: transform 180ms ease;
}

.annotation-panel.open {
  transform: translateX(0);
}

.annotation-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.annotation-storage-note {
  color: var(--muted);
  font-size: 12px;
}

.annotation-item {
  margin: 16px 0;
  padding: 14px;
  border: 1px solid var(--line);
}

.annotation-item p {
  margin: 0 0 8px;
}

.annotation-item small {
  display: block;
  color: var(--muted);
}

.annotation-item button,
.danger-button {
  margin-top: 10px;
  border: 0;
  background: transparent;
  color: #a55454;
  cursor: pointer;
  font-size: 12px;
}

.danger-button {
  padding: 10px 0;
}

@media (max-width: 900px) {
  .reading-layout {
    display: block;
  }

  .toc-panel {
    position: static;
    max-height: none;
    margin-bottom: 30px;
    padding: 20px;
    border: 1px solid var(--line);
  }

  .toc-panel nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .book-link {
    grid-template-columns: 42px 1fr;
  }

  .book-author {
    grid-column: 2;
    justify-items: start;
  }
}

@media (max-width: 620px) {
  .site-header,
  .site-main,
  .site-footer {
    width: min(100% - 24px, 1180px);
  }

  .library-intro {
    min-height: auto;
    padding: 58px 0;
  }

  .library-intro h1 {
    font-size: 39px;
  }

  .library-controls {
    grid-template-columns: 1fr;
  }

  .sort-controls {
    grid-column: 1;
  }

  .site-actions a {
    display: none;
  }

  .book-link {
    gap: 10px;
    padding: 24px 2px;
  }

  .book-main h3 {
    font-size: 21px;
  }

  .book-header {
    margin: 46px auto 54px;
  }

  .book-header h1 {
    font-size: 38px;
  }

  .book-details {
    display: grid;
    gap: 4px;
  }

  .toc-panel nav {
    grid-template-columns: 1fr;
  }

  .book-content {
    padding: 34px 23px;
    font-size: 16px;
  }

  .annotation-guide > span:first-child {
    display: none;
  }

  .chapter-pager {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .chapter-progress {
    grid-column: 1 / -1;
    grid-row: 1;
    text-align: center;
  }

  .site-footer {
    display: grid;
    gap: 3px;
  }
}
