:root {
  color-scheme: light;
  --paper: #f7f4ee;
  --paper-2: #ede8dd;
  --ink: #172027;
  --muted: #68747a;
  --rail: #273d43;
  --signal: #9f392c;
  --brass: #be8b2e;
  --leaf: #2f6f5f;
  --line: rgba(23, 32, 39, 0.14);
  --shadow: 0 22px 60px rgba(15, 22, 28, 0.16);
  --radius: 8px;
  --ui: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  --reader-scale: 1;
  --reader-leading: 1.74;
  margin: 0;
  background:
    linear-gradient(90deg, rgba(47, 111, 95, 0.08), transparent 18%, transparent 82%, rgba(159, 57, 44, 0.07)),
    var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  overflow-x: hidden;
}

body.theme-sepia {
  --paper: #f2eadc;
  --paper-2: #e7ddcb;
  --ink: #1f211d;
  --muted: #6f6759;
  --rail: #34413b;
  --line: rgba(31, 33, 29, 0.16);
}

a {
  color: inherit;
  text-underline-offset: 0.22em;
}

img {
  max-width: 100%;
  height: auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 12px clamp(16px, 3vw, 34px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(23, 32, 39, 0.9);
  color: #fff;
  backdrop-filter: blur(14px);
}

.reader-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-button {
  min-width: 38px;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  font: 700 0.82rem/1 var(--ui);
}

.tool-button:hover,
.tool-button:focus-visible {
  background: rgba(255, 255, 255, 0.18);
}

.brand {
  min-width: 0;
}

.brand__kicker {
  display: block;
  color: rgba(255, 255, 255, 0.68);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.brand__title {
  display: block;
  overflow: hidden;
  font-family: var(--serif);
  font-size: clamp(1.05rem, 2vw, 1.45rem);
  line-height: 1.18;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button,
.text-button,
.primary-button,
.chapter-link,
.rail-link,
.gallery-item {
  font: inherit;
}

.icon-button,
.primary-button,
.text-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
}

.icon-button {
  width: 42px;
  display: inline-grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.icon-button:hover,
.icon-button:focus-visible {
  background: rgba(255, 255, 255, 0.18);
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  background: var(--signal);
  color: #fff;
  text-decoration: none;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: #832d23;
}

.site-shell {
  display: grid;
  grid-template-columns: minmax(280px, 330px) minmax(0, 1fr);
  min-height: calc(100vh - 68px);
  transition: grid-template-columns 180ms ease;
}

.library {
  position: sticky;
  top: 65px;
  height: calc(100vh - 65px);
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow: auto;
  padding: 22px;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.64), rgba(247, 244, 238, 0.82)),
    var(--paper);
}

.library-toolbar {
  display: flex;
  justify-content: flex-end;
}

.library-content {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.library-toolbar .icon-button,
.rail-toggle {
  background: var(--rail);
  color: #fff;
}

.rail-strip {
  display: none;
}

body.nav-collapsed .site-shell {
  grid-template-columns: 64px minmax(0, 1fr);
}

body.nav-collapsed .library {
  padding: 10px 8px;
  gap: 8px;
  overflow: hidden auto;
}

body.nav-collapsed .library-toolbar,
body.nav-collapsed .library-content {
  display: none;
}

body.nav-collapsed .rail-strip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.rail-toggle,
.rail-link {
  width: 42px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.rail-toggle {
  display: inline-grid;
  place-items: center;
  margin-bottom: 4px;
}

.rail-link {
  background: rgba(255, 255, 255, 0.72);
  color: var(--rail);
  font-size: 0.76rem;
  font-weight: 800;
}

.rail-link:hover,
.rail-link:focus-visible {
  border-color: rgba(47, 111, 95, 0.42);
  background: #fff;
}

.rail-link.is-active {
  border-color: rgba(159, 57, 44, 0.36);
  background: var(--signal);
  color: #fff;
}

.cover-wrap {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 16px;
  align-items: end;
}

.cover-wrap img {
  width: 96px;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border: 1px solid rgba(23, 32, 39, 0.16);
  box-shadow: 0 12px 24px rgba(23, 32, 39, 0.18);
}

.book-title h1 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 1.56rem;
  line-height: 1.04;
}

.book-title p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.stat {
  min-height: 68px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.48);
}

.stat strong {
  display: block;
  font-size: 1.05rem;
}

.stat span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.73rem;
  line-height: 1.24;
  text-transform: uppercase;
}

.search {
  position: relative;
}

.search input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px 0 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.search svg {
  position: absolute;
  left: 12px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  color: var(--muted);
}

.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 20px;
}

.chapter-link {
  width: 100%;
  display: grid;
  gap: 3px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.chapter-link:hover,
.chapter-link:focus-visible {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.58);
}

.chapter-link.is-active {
  border-color: rgba(159, 57, 44, 0.28);
  background: #fff;
  box-shadow: 0 10px 24px rgba(23, 32, 39, 0.08);
}

.chapter-link__label {
  color: var(--signal);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chapter-link__title {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.25;
}

.reader {
  min-width: 0;
}

.reader-hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 340px);
  gap: clamp(22px, 4vw, 54px);
  align-items: center;
  min-height: clamp(420px, 60vh, 620px);
  padding: clamp(28px, 5vw, 70px);
  overflow: hidden;
  background:
    linear-gradient(100deg, rgba(23, 32, 39, 0.92) 0%, rgba(39, 61, 67, 0.88) 48%, rgba(23, 32, 39, 0.54) 100%),
    var(--hero-image) center / cover no-repeat;
  color: #fff;
}

.reader-hero::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 7px;
  background: linear-gradient(90deg, var(--leaf), var(--brass), var(--signal));
}

.hero-copy {
  position: relative;
  z-index: 1;
  min-width: 0;
  max-width: 760px;
}

.hero-copy p {
  margin: 0;
  max-width: 42rem;
  color: rgba(255, 255, 255, 0.78);
  font-size: clamp(1rem, 1.7vw, 1.22rem);
  line-height: 1.66;
  overflow-wrap: break-word;
}

.hero-copy p span {
  display: inline;
}

.hero-copy p span + span::before {
  content: " ";
}

.hero-copy h2 {
  max-width: 780px;
  margin: 0 0 18px;
  font-family: var(--serif);
  font-size: clamp(2.4rem, 5vw, 4.45rem);
  line-height: 0.96;
  font-weight: 700;
  overflow-wrap: break-word;
}

.hero-copy h2 span {
  display: block;
}

.hero-cover {
  position: relative;
  z-index: 1;
  justify-self: center;
  max-height: min(64vh, 520px);
  border: 1px solid rgba(255, 255, 255, 0.36);
  box-shadow: var(--shadow);
}

.gallery-band {
  padding: 20px clamp(18px, 4vw, 54px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.46);
}

.gallery {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
}

.gallery-item {
  min-width: 0;
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  text-align: left;
}

.gallery-item:hover,
.gallery-item:focus-visible {
  border-color: rgba(47, 111, 95, 0.42);
  box-shadow: 0 10px 22px rgba(23, 32, 39, 0.08);
}

.gallery-item img {
  width: 56px;
  height: 48px;
  object-fit: cover;
  border-radius: 5px;
}

.gallery-item span {
  display: -webkit-box;
  overflow: hidden;
  color: var(--rail);
  font-size: 0.82rem;
  line-height: 1.23;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.reader-body {
  max-width: 980px;
  margin: 0 auto;
  padding: clamp(26px, 5vw, 66px) clamp(18px, 4vw, 42px) 80px;
}

.chapter-panel {
  display: none;
}

.chapter-panel.is-active {
  display: block;
}

.chapter-head {
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--signal);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.chapter-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2rem, 4vw, 3.6rem);
  line-height: 1.04;
}

.chapter-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.chapter-meta a {
  color: var(--leaf);
  font-weight: 700;
}

.chapter-summary {
  max-width: 760px;
  margin: 18px 0 0;
  color: #3f4a4f;
  font-family: var(--serif);
  font-size: 1.1rem;
  line-height: 1.68;
}

.chapter-copy {
  margin-top: 30px;
  color: #202a30;
  font-family: var(--serif);
  font-size: calc(clamp(1.04rem, 1.3vw, 1.2rem) * var(--reader-scale));
  line-height: var(--reader-leading);
}

.chapter-copy p {
  margin: 0 0 1.04em;
  text-align: justify;
  text-align-last: auto;
  hyphens: auto;
}

.chapter-copy mark {
  background: transparent;
  color: inherit;
  padding: 0;
}

.chapter-copy h1,
.chapter-copy h2,
.chapter-copy h3 {
  margin: 1.8em 0 0.6em;
  color: var(--rail);
  font-family: var(--serif);
  line-height: 1.12;
}

.chapter-copy h1 {
  font-size: 2rem;
}

.chapter-copy h2 {
  font-size: 1.7rem;
}

.chapter-copy h3 {
  font-size: 1.38rem;
}

.chapter-copy blockquote {
  margin: 0;
  padding: 0;
  border: 0;
}

.chapter-copy img {
  display: block;
  width: auto !important;
  height: auto !important;
  max-height: 72vh;
  max-width: min(100%, 900px);
  object-fit: contain;
  margin: 24px auto;
  border: 1px solid rgba(23, 32, 39, 0.12);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 16px 38px rgba(23, 32, 39, 0.14);
  cursor: zoom-in;
}

.contents-overview {
  display: grid;
  gap: 10px;
  font-family: var(--ui);
}

.contents-entry {
  width: 100%;
  display: grid;
  gap: 5px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.contents-entry:hover,
.contents-entry:focus-visible {
  border-color: rgba(47, 111, 95, 0.42);
  background: #fff;
  box-shadow: 0 12px 26px rgba(23, 32, 39, 0.08);
}

.contents-entry__label {
  color: var(--signal);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.contents-entry__title {
  color: var(--rail);
  font-family: var(--serif);
  font-size: 1.18rem;
  font-weight: 700;
  line-height: 1.2;
}

.contents-entry__summary {
  color: #4d585d;
  font-size: 0.92rem;
  line-height: 1.45;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  grid-template-rows: 1fr auto;
  align-items: center;
  justify-items: center;
  gap: 14px;
  padding: 58px 24px 26px;
  background: rgba(15, 22, 28, 0.88);
}

.lightbox[hidden] {
  display: none;
}

.lightbox img {
  max-width: min(1100px, 94vw);
  max-height: 82vh;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.38);
}

.lightbox p {
  max-width: min(900px, 92vw);
  margin: 0;
  color: rgba(255, 255, 255, 0.78);
  font-family: var(--ui);
  font-size: 0.92rem;
  line-height: 1.45;
  text-align: center;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 18px;
  min-width: 42px;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  font: 700 1.25rem/1 var(--ui);
}

.lightbox-close:hover,
.lightbox-close:focus-visible {
  background: rgba(255, 255, 255, 0.22);
}

.chapter-copy table {
  width: 100%;
  margin: 22px 0;
  border-collapse: collapse;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #fff;
  font-family: var(--ui);
  font-size: 0.94rem;
  line-height: 1.45;
}

.chapter-copy th,
.chapter-copy td {
  padding: 10px 12px;
  border: 1px solid var(--line);
  vertical-align: top;
}

.chapter-copy th {
  background: rgba(47, 111, 95, 0.1);
  color: var(--rail);
  text-align: left;
}

.chapter-copy ol,
.chapter-copy ul {
  padding-left: 1.35em;
}

.chapter-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 40px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.text-button {
  min-width: 118px;
  padding: 0 14px;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.text-button:hover,
.text-button:focus-visible {
  border-color: rgba(159, 57, 44, 0.36);
  color: var(--signal);
}

.text-button:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.mobile-drawer-backdrop {
  display: none;
}

@media (max-width: 1120px) {
  .site-shell {
    grid-template-columns: minmax(250px, 290px) minmax(0, 1fr);
  }

  .gallery {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .brand__title {
    font-size: 1rem;
  }

  .reader-tools {
    gap: 4px;
  }

  .tool-button {
    min-width: 34px;
    min-height: 34px;
    padding: 0 8px;
    font-size: 0.76rem;
  }

  .site-shell {
    display: block;
  }

  .library {
    position: fixed;
    inset: 63px auto 0 0;
    z-index: 40;
    width: min(86vw, 360px);
    height: calc(100vh - 63px);
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: 28px 0 54px rgba(15, 22, 28, 0.24);
  }

  .library-toolbar,
  .rail-strip,
  body.nav-collapsed .rail-strip {
    display: none;
  }

  body.nav-collapsed .site-shell {
    display: block;
  }

  body.nav-collapsed .library {
    padding: 22px;
    gap: 18px;
    overflow: auto;
  }

  body.nav-collapsed .library-content {
    display: flex;
  }

  body.drawer-open .library {
    transform: translateX(0);
  }

  body.drawer-open .mobile-drawer-backdrop {
    display: block;
    position: fixed;
    inset: 63px 0 0;
    z-index: 30;
    background: rgba(15, 22, 28, 0.38);
    border: 0;
  }

  .reader-hero {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .hero-copy h2 {
    font-size: clamp(1.72rem, 7vw, 2.2rem);
    line-height: 1.08;
    max-width: 100%;
  }

  .hero-cover {
    max-width: 240px;
    max-height: none;
  }

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

@media (min-width: 821px) {
  .menu-toggle {
    display: none;
  }
}

@media (max-width: 560px) {
  .topbar {
    gap: 8px;
    padding-left: 8px;
    padding-right: 8px;
  }

  .reader-tools {
    position: fixed;
    top: 14px;
    right: 8px;
    z-index: 60;
  }

  .brand__kicker {
    font-size: 0.66rem;
  }

  .brand__title {
    max-width: clamp(106px, 32vw, 150px);
    font-size: 0.84rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .hero-copy p {
    max-width: 100%;
    font-size: 0.96rem;
  }

  .hero-copy p span {
    display: block;
  }

  .hero-copy p span + span::before {
    content: "";
  }

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

  .cover-wrap {
    grid-template-columns: 74px 1fr;
  }

  .cover-wrap img {
    width: 74px;
  }

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

  .chapter-head h2 {
    font-size: 2rem;
  }

  .chapter-copy {
    font-size: calc(1.03rem * var(--reader-scale));
  }

  .tool-button[data-control="line"],
  .tool-button[data-control="theme"] {
    display: none;
  }
}
