:root {
  color-scheme: dark;
  --bg: #10110f;
  --bg-soft: #181814;
  --paper: #f3ead7;
  --paper-soft: #e6d8bf;
  --ink: #f6eddf;
  --muted: #b9ae9f;
  --line: rgba(246, 237, 223, 0.16);
  --line-strong: rgba(246, 237, 223, 0.28);
  --gold: #d0a94d;
  --verdigris: #4fa48c;
  --wine: #a44955;
  --indigo: #6072c4;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  --font-serif: Georgia, "Times New Roman", serif;
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --content-width: 780px;
  --nav-width: 318px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6efe2;
  --bg-soft: #fffaf0;
  --paper: #fff9ec;
  --paper-soft: #ecddc4;
  --ink: #1d1a15;
  --muted: #746957;
  --line: rgba(29, 26, 21, 0.14);
  --line-strong: rgba(29, 26, 21, 0.26);
  --shadow: 0 24px 70px rgba(74, 48, 20, 0.15);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 16% 8%, rgba(79, 164, 140, 0.22), transparent 28rem),
    radial-gradient(circle at 82% 18%, rgba(164, 73, 85, 0.16), transparent 28rem),
    linear-gradient(180deg, var(--bg), var(--bg-soft) 42rem, var(--bg));
  color: var(--ink);
  font-family: var(--font-sans);
  line-height: 1.65;
  text-rendering: optimizeLegibility;
}

body.is-focused .contents {
  display: none;
}

body.is-focused .layout {
  grid-template-columns: minmax(0, var(--content-width));
  justify-content: center;
}

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

button,
input {
  font: inherit;
}

.progress {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 50;
  width: 100%;
  height: 4px;
  background: transparent;
}

.progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--verdigris), var(--wine));
}

.hero {
  position: relative;
  min-height: min(720px, 86vh);
  display: grid;
  align-items: center;
  overflow: hidden;
  padding: clamp(32px, 6vw, 88px);
  isolation: isolate;
  border-bottom: 1px solid var(--line);
}

#cosmos-canvas,
.hero__veil {
  position: absolute;
  inset: 0;
}

#cosmos-canvas {
  z-index: -3;
  width: 100%;
  height: 100%;
  background: #0b0b0a;
}

.hero__veil {
  z-index: -2;
  background:
    linear-gradient(90deg, rgba(16, 17, 15, 0.88), rgba(16, 17, 15, 0.52) 58%, rgba(16, 17, 15, 0.18)),
    linear-gradient(0deg, var(--bg), transparent 40%);
}

:root[data-theme="light"] .hero__veil {
  background:
    linear-gradient(90deg, rgba(23, 20, 15, 0.82), rgba(23, 20, 15, 0.46) 58%, rgba(23, 20, 15, 0.12)),
    linear-gradient(0deg, var(--bg), transparent 40%);
}

.hero__content {
  width: min(790px, 100%);
  padding: clamp(42px, 8vh, 96px) 0 clamp(28px, 5vh, 68px);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: 0;
}

h1 {
  max-width: 790px;
  color: #fff8ec;
  font-size: clamp(2.8rem, 6.2vw, 6.2rem);
  overflow-wrap: anywhere;
  hyphens: auto;
}

.hero__subtitle {
  max-width: 760px;
  margin: 22px 0 0;
  color: rgba(255, 248, 236, 0.86);
  font-family: var(--font-serif);
  font-size: clamp(1.15rem, 2vw, 1.7rem);
}

.hero__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-top: 22px;
  color: rgba(255, 248, 236, 0.72);
}

.hero__meta span:not(:empty) + span:not(:empty)::before {
  content: "/";
  margin-right: 18px;
  color: var(--gold);
}

.hero__description {
  max-width: 720px;
  margin: 28px 0 0;
  color: rgba(255, 248, 236, 0.76);
  font-size: 1.04rem;
}

.hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 34px;
}

.button,
.tool-button {
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  font-weight: 700;
}

.button--primary {
  border-color: rgba(208, 169, 77, 0.62);
  background: var(--gold);
  color: #17130a;
}

.button--quiet {
  background: rgba(255, 248, 236, 0.08);
  color: #fff8ec;
}

.button:hover,
.tool-button:hover {
  transform: translateY(-1px);
  border-color: var(--gold);
}

.opening-quote {
  padding: clamp(34px, 7vw, 78px) 24px;
  border-bottom: 1px solid var(--line);
}

.opening-quote__inner {
  width: min(100%, 1040px);
  margin: 0 auto;
}

.opening-quote p {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(1.35rem, 3vw, 2.8rem);
  line-height: 1.22;
}

.opening-quote span {
  display: block;
  margin-top: 18px;
  color: var(--muted);
}

.reader-tools {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px clamp(16px, 4vw, 46px);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(18px);
}

.reader-tools__brand {
  color: var(--gold);
  font-family: var(--font-serif);
  font-size: 1.08rem;
}

.reader-tools__group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
}

.search__control {
  position: relative;
}

.search__label {
  color: var(--muted);
  font-size: 0.86rem;
}

.search input {
  width: min(34vw, 360px);
  min-width: 210px;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  outline: none;
}

.search input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(208, 169, 77, 0.18);
}

.search-popover {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 45;
  display: none;
  width: min(520px, calc(100vw - 32px));
  max-height: min(520px, calc(100vh - 96px));
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px;
  background: color-mix(in srgb, var(--bg) 94%, #000);
  box-shadow: var(--shadow);
}

.search-popover.is-open {
  display: grid;
  gap: 8px;
}

.tool-button {
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
}

.layout {
  display: grid;
  grid-template-columns: var(--nav-width) minmax(0, var(--content-width));
  gap: clamp(26px, 5vw, 74px);
  justify-content: center;
  align-items: start;
  width: min(100% - 32px, 1280px);
  margin: 0 auto;
  padding: clamp(38px, 8vw, 94px) 0;
}

.contents {
  position: sticky;
  top: 86px;
  max-height: calc(100vh - 110px);
  overflow: auto;
  padding-right: 8px;
}

.contents__header {
  padding: 0 0 18px;
  border-bottom: 1px solid var(--line);
}

.contents__header p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.toc-list {
  display: grid;
  gap: 4px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

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

.toc-list a:hover,
.toc-list a.is-active {
  border-left-color: var(--gold);
  color: var(--ink);
  background: rgba(208, 169, 77, 0.08);
}

.toc-list .toc-section a {
  padding-left: 22px;
  font-size: 0.84rem;
}

.search-results {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.search-result {
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: rgba(255, 255, 255, 0.035);
}

.search-popover .search-result {
  background: rgba(255, 255, 255, 0.055);
}

.search-result strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.88rem;
}

.search-result span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

mark {
  border-radius: 4px;
  padding: 0 2px;
  background: rgba(208, 169, 77, 0.34);
  color: inherit;
}

.book mark.search-term {
  background: rgba(208, 169, 77, 0.72);
  color: #17130a;
  box-shadow: 0 0 0 2px rgba(208, 169, 77, 0.16);
}

.book {
  min-width: 0;
}

.chapter {
  scroll-margin-top: 92px;
  padding-bottom: clamp(52px, 10vw, 108px);
}

.chapter + .chapter {
  border-top: 1px solid var(--line);
  padding-top: clamp(52px, 10vw, 108px);
}

.chapter__kicker {
  color: var(--gold);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.chapter h2 {
  margin-top: 12px;
  font-size: clamp(2.2rem, 5vw, 4.9rem);
}

.chapter__title-note {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: clamp(1rem, 1.6vw, 1.18rem);
  font-weight: 500;
  line-height: 1.4;
}

.book p {
  margin: 20px 0 0;
  color: color-mix(in srgb, var(--ink) 88%, var(--muted));
  font-size: 1.07rem;
}

.book .lead {
  margin-top: 26px;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: clamp(1.22rem, 2.15vw, 1.62rem);
  line-height: 1.52;
}

.section-heading {
  scroll-margin-top: 92px;
}

.search-anchor {
  scroll-margin-top: 112px;
}

.search-anchor:target,
.is-search-hit {
  animation: targetPulse 1800ms ease;
}

@keyframes targetPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(208, 169, 77, 0);
  }

  22% {
    box-shadow: 0 0 0 8px rgba(208, 169, 77, 0.2);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(208, 169, 77, 0);
  }
}

.section-heading--2 {
  margin-top: 56px;
  color: var(--ink);
  font-size: clamp(1.55rem, 3vw, 2.35rem);
}

.section-heading--3 {
  margin-top: 34px;
  color: var(--gold);
  font-family: var(--font-sans);
  font-size: 1.05rem;
  font-weight: 800;
}

.formal-card {
  margin-top: 22px;
  border: 1px solid var(--line-strong);
  border-left: 4px solid var(--gold);
  border-radius: 8px;
  padding: clamp(16px, 3vw, 24px);
  background:
    linear-gradient(135deg, rgba(208, 169, 77, 0.11), transparent 46%),
    rgba(255, 255, 255, 0.035);
  box-shadow: var(--shadow);
}

.formal-card__label {
  display: block;
  margin-bottom: 8px;
  color: var(--gold);
  font-size: 0.84rem;
  font-weight: 800;
  text-transform: uppercase;
}

.formal-card p {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 1.12rem;
  line-height: 1.58;
}

.plate {
  margin: clamp(18px, 5vw, 46px) 0 clamp(54px, 9vw, 96px);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
  background: var(--paper);
  color: #1c1811;
  box-shadow: var(--shadow);
}

.plate__visual {
  position: relative;
  min-height: 330px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(79, 164, 140, 0.84), rgba(208, 169, 77, 0.74) 46%, rgba(164, 73, 85, 0.82)),
    repeating-linear-gradient(90deg, transparent 0 18px, rgba(255, 255, 255, 0.18) 18px 19px);
}

.plate__visual::before,
.plate__visual::after {
  content: "";
  position: absolute;
  inset: 12%;
  border: 1px solid rgba(255, 255, 255, 0.42);
  transform: rotate(8deg);
}

.plate__visual::after {
  inset: 24%;
  transform: rotate(-12deg);
}

.plate__visual img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.plate__number {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 132px;
  height: 132px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 50%;
  color: #fffaf0;
  font-family: var(--font-serif);
  font-size: 2.4rem;
  background: rgba(16, 17, 15, 0.16);
  backdrop-filter: blur(6px);
}

.plate__caption {
  padding: 18px 20px 20px;
}

.plate__caption strong {
  display: block;
  font-family: var(--font-serif);
  font-size: 1.35rem;
  line-height: 1.2;
}

.plate__caption span {
  display: block;
  margin-top: 8px;
  color: #5d5345;
}

.back-to-top {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 800;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

@media (max-width: 980px) {
  .reader-tools {
    align-items: stretch;
    flex-direction: column;
  }

  .reader-tools__group,
  .search {
    width: 100%;
  }

  .search input {
    width: 100%;
    min-width: 0;
  }

  .search__control {
    flex: 1;
  }

  .search-popover {
    left: 0;
    right: auto;
    width: 100%;
  }

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

  .contents {
    position: static;
    max-height: none;
    padding: 0;
  }

  .toc-list {
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  }

  .toc-list .toc-section {
    display: none;
  }
}

@media (max-width: 620px) {
  .hero {
    min-height: 86vh;
    padding: 28px 18px;
  }

  h1 {
    font-size: clamp(2.35rem, 11.8vw, 3.1rem);
  }

  .opening-quote {
    padding-inline: 18px;
  }

  .reader-tools__group {
    flex-wrap: wrap;
  }

  .search {
    flex-basis: 100%;
  }

  .tool-button {
    flex: 1 1 120px;
  }

  .layout {
    width: min(100% - 28px, 1280px);
  }

  .book p,
  .formal-card p {
    font-size: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
  }
}
