:root {
  --brand-primary: #3A3530;
  --brand-secondary: #8FA28E;
  --brand-accent: #C97550;
  --brand-body: #2A2A2A;
  --brand-muted: #7D7470;
  --brand-bg: #FBF6F1;
  --stone-50: #F5F1ED;
  --stone-100: #E8E0D8;
  --stone-200: #D4C7B9;
  --stone-600: #5C4F44;
  --stone-800: #3A3530;
  --stone-900: #241F1B;
  --sage-50: #F0F3EE;
  --sage-100: #D9E1D5;
  --sage-200: #BFCDBC;
  --sage-800: #3F5747;
  --terra-50: #FAEBE2;
  --terra-400: #C97550;
  --terra-600: #9E5532;
  --neutral-50: #FBF6F1;
  --neutral-100: #F0EAE3;
  --neutral-200: #DDD3C7;
  --neutral-600: #7D7470;
  --neutral-800: #42393A;
  --neutral-900: #2A2A2A;
  --font-serif: "Fraunces", Georgia, "Times New Roman", serif;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--brand-bg);
  color: var(--brand-body);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.7;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.is-hidden {
  display: none !important;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--terra-600);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.55px;
  line-height: 1.4;
  text-transform: uppercase;
}

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  background:
    linear-gradient(90deg, rgba(143, 162, 142, 0.15), transparent 54%),
    var(--brand-bg);
}

.gate-publication {
  width: min(1040px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, 0.75fr);
  align-items: stretch;
  border: 1px solid var(--stone-200);
  background: var(--neutral-50);
  box-shadow: 0 24px 80px rgba(58, 53, 48, 0.13);
}

.gate-cover {
  min-height: 660px;
  display: flex;
  flex-direction: column;
  padding: 56px;
  background:
    linear-gradient(180deg, rgba(240, 243, 238, 0.92), rgba(251, 246, 241, 0.72)),
    var(--sage-50);
  border-right: 1px solid var(--stone-200);
}

.gate-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 42px;
  background: var(--neutral-50);
}

.gate-panel h2 {
  max-width: 340px;
  margin: 0 0 14px;
  color: var(--stone-800);
  font-family: var(--font-serif);
  font-size: 32px;
  font-weight: 500;
  line-height: 1.15;
}

.gate-panel > p {
  margin: 0 0 22px;
  color: var(--neutral-600);
  font-size: 15px;
  line-height: 1.65;
}

.subscription-points {
  display: grid;
  gap: 8px;
  margin-bottom: 28px;
}

.subscription-points span {
  border-left: 3px solid var(--sage-800);
  background: var(--sage-50);
  color: var(--stone-800);
  padding: 8px 11px;
  font-size: 13px;
  font-weight: 500;
}

.cover-rule {
  width: 96px;
  height: 3px;
  margin-top: auto;
  background: var(--terra-600);
}

.cover-note {
  margin: 16px 0 0;
  color: var(--stone-600);
  font-size: 14px;
  font-weight: 500;
}

.gate-wordmark {
  width: 190px;
  margin-bottom: 78px;
}

.gate-cover h1 {
  max-width: 620px;
  margin: 0;
  color: var(--stone-800);
  font-family: var(--font-serif);
  font-size: 58px;
  font-weight: 500;
  line-height: 1.05;
}

.gate-lede {
  max-width: 520px;
  margin: 22px 0 34px;
  color: var(--stone-600);
  font-family: var(--font-serif);
  font-size: 22px;
  line-height: 1.5;
}

.gate-panel {
  min-width: 0;
}

.access-form label {
  display: block;
  margin-bottom: 8px;
  color: var(--stone-800);
  font-weight: 500;
}

.access-row {
  display: flex;
  gap: 10px;
}

.access-row input {
  min-width: 0;
  flex: 1;
  height: 48px;
  border: 1px solid var(--stone-200);
  background: var(--stone-50);
  color: var(--neutral-900);
  padding: 0 14px;
}

.access-row button,
.search-button {
  border: 0;
  background: var(--terra-600);
  color: var(--neutral-50);
  padding: 0 18px;
  font-weight: 500;
}

.access-error {
  min-height: 22px;
  margin: 10px 0 0;
  color: var(--terra-600);
  font-size: 14px;
}

.hint {
  margin: 4px 0 0;
  color: var(--neutral-600);
  font-size: 13px;
}

.reader {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 300px minmax(0, 780px) 280px;
  column-gap: 36px;
  padding: 76px 34px 56px;
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--neutral-200);
  background: rgba(251, 246, 241, 0.94);
  padding: 0 24px;
  backdrop-filter: blur(10px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--stone-600);
  font-size: 13px;
  font-weight: 500;
}

.brand-lockup img {
  width: 142px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ghost-button,
.icon-button {
  min-height: 38px;
  border: 1px solid var(--stone-200);
  background: transparent;
  color: var(--stone-800);
  padding: 0 14px;
  font-weight: 500;
}

.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.mobile-only {
  display: none;
}

.toc,
.reference-rail {
  position: sticky;
  top: 82px;
  align-self: start;
  max-height: calc(100vh - 110px);
  overflow: auto;
}

.edition-card,
.rail-section {
  border: 1px solid var(--stone-200);
  background: var(--stone-50);
  padding: 18px;
}

.edition-card h2 {
  margin: 0 0 8px;
  color: var(--stone-800);
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 500;
  line-height: 1.2;
}

.edition-card p,
.rail-section p {
  margin: 0;
  color: var(--neutral-600);
  font-size: 13px;
  line-height: 1.55;
}

#chapter-list {
  display: grid;
  gap: 4px;
  margin-top: 18px;
}

.chapter-link {
  width: 100%;
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: start;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  color: var(--stone-800);
  padding: 10px 8px;
  text-align: left;
  font-size: 14px;
  line-height: 1.35;
}

.chapter-link span {
  color: var(--neutral-600);
  font-size: 12px;
}

.chapter-link strong {
  font-weight: 400;
}

.chapter-link em {
  grid-column: 2;
  color: var(--neutral-600);
  font-size: 12px;
  font-style: normal;
}

.chapter-link.is-active {
  border-left-color: var(--terra-600);
  background: var(--terra-50);
}

.book-page {
  min-width: 0;
  border-left: 1px solid var(--stone-200);
  border-right: 1px solid var(--stone-200);
  background: rgba(255, 255, 255, 0.16);
  padding: 52px min(7vw, 70px);
}

.chapter-kicker {
  margin-bottom: 18px;
  color: var(--terra-600);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.chapter-content h1 {
  margin: 0 0 24px;
  color: var(--stone-800);
  font-family: var(--font-serif);
  font-size: 42px;
  font-weight: 500;
  line-height: 1.12;
}

.chapter-content h2 {
  margin: 52px 0 14px;
  color: var(--stone-800);
  font-family: var(--font-serif);
  font-size: 27px;
  font-weight: 500;
  line-height: 1.2;
}

.chapter-content h3 {
  margin: 34px 0 10px;
  color: var(--stone-800);
  font-family: var(--font-serif);
  font-size: 21px;
  font-weight: 500;
  line-height: 1.3;
}

.chapter-content h4 {
  margin: 28px 0 8px;
  color: var(--stone-800);
  font-size: 17px;
  font-weight: 500;
}

.chapter-content p {
  margin: 0 0 18px;
}

.chapter-content a {
  color: var(--terra-600);
  text-decoration-color: rgba(158, 85, 50, 0.4);
  text-underline-offset: 3px;
}

.chapter-content blockquote {
  margin: 30px 0;
  border-left: 4px solid var(--sage-800);
  background: var(--sage-50);
  padding: 18px 22px;
  color: var(--stone-800);
}

.chapter-content blockquote p {
  margin-bottom: 12px;
}

.chapter-content blockquote p:last-child {
  margin-bottom: 0;
}

.chapter-content ul,
.chapter-content ol {
  margin: 0 0 22px;
  padding-left: 24px;
}

.chapter-content li {
  margin-bottom: 8px;
}

.chapter-content code {
  border: 1px solid var(--neutral-200);
  background: var(--stone-50);
  padding: 2px 5px;
  color: var(--neutral-800);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.reader-toc {
  display: grid;
  gap: 9px;
  margin: 22px 0 38px;
}

.reader-toc-item {
  display: grid;
  grid-template-columns: 98px 1fr;
  gap: 14px;
  align-items: baseline;
  border: 1px solid var(--neutral-200);
  background: var(--stone-50);
  color: var(--stone-800);
  padding: 13px 15px;
  text-decoration: none;
}

.reader-toc-index {
  color: var(--terra-600);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.35px;
  text-transform: uppercase;
}

.reader-toc-item strong {
  font-weight: 500;
  line-height: 1.35;
}

.chapter-content hr {
  margin: 34px 0;
  border: 0;
  border-top: 1px solid var(--neutral-200);
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  margin: 24px 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.45;
}

th,
td {
  border: 1px solid var(--neutral-200);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--stone-50);
  color: var(--stone-800);
  font-weight: 500;
}

.page-turn {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 56px;
  padding-top: 26px;
  border-top: 1px solid var(--neutral-200);
}

.reference-rail {
  display: grid;
  gap: 16px;
}

.icon-key {
  display: grid;
  gap: 7px;
  color: var(--stone-800);
  font-size: 13px;
  line-height: 1.35;
}

.icon-key span {
  cursor: default;
}

.rail-button {
  width: 100%;
  display: block;
  margin-top: 10px;
  border: 1px solid var(--stone-200);
  background: var(--neutral-50);
  color: var(--stone-800);
  padding: 10px 12px;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  box-sizing: border-box;
  cursor: pointer;
}

.tool-status {
  min-height: 18px;
  margin: 8px 0 4px;
  color: var(--neutral-600);
  font-size: 12px;
  line-height: 1.4;
}

body[data-access-mode="review"] #rebuild-reader,
body[data-access-mode="review"] #rebuild-status {
  display: none;
}

.locked-chapter {
  border: 1px solid var(--stone-200);
  background: var(--stone-50);
  padding: 28px;
}

.locked-chapter h1 {
  margin-bottom: 18px;
}

.resource-callout {
  border-color: var(--sage-200);
  background: var(--sage-50);
}

.resource-item {
  display: block;
  margin-top: 12px;
  color: var(--stone-800);
  text-decoration: none;
}

.resource-item strong {
  display: block;
  font-size: 14px;
  line-height: 1.35;
}

.resource-item p {
  margin-top: 4px;
}

.search-panel {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: start center;
  background: rgba(36, 31, 27, 0.28);
  padding: 82px 18px 18px;
}

.guides-panel {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: start center;
  background: rgba(36, 31, 27, 0.28);
  padding: 82px 18px 18px;
}

.guides-shell {
  width: min(880px, 100%);
  border: 1px solid var(--stone-200);
  background: var(--neutral-50);
  box-shadow: 0 24px 80px rgba(36, 31, 27, 0.22);
  padding: 26px;
}

.guides-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.guides-head h2 {
  margin: 0;
  color: var(--stone-800);
  font-family: var(--font-serif);
  font-size: 31px;
  font-weight: 500;
  line-height: 1.15;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.guide-card {
  min-height: 170px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  border: 1px solid var(--neutral-200);
  background: var(--stone-50);
  color: var(--stone-800);
  padding: 18px;
  text-align: left;
}

.guide-card.is-current {
  border-color: var(--terra-600);
  background: var(--terra-50);
}

.guide-card:disabled {
  cursor: default;
  opacity: 0.72;
}

.guide-card span {
  color: var(--terra-600);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.45px;
  text-transform: uppercase;
}

.guide-card strong {
  margin-top: 18px;
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 500;
  line-height: 1.18;
}

.guide-card small {
  margin-top: auto;
  color: var(--neutral-600);
  font-size: 13px;
  line-height: 1.45;
}

.guides-cta {
  display: inline-block;
  margin-top: 22px;
  color: var(--terra-600);
  font-weight: 500;
  letter-spacing: 0.2px;
  text-decoration: none;
}

.guides-cta:hover {
  text-decoration: underline;
}

.search-shell {
  width: min(760px, 100%);
  max-height: calc(100vh - 110px);
  overflow: auto;
  border: 1px solid var(--stone-200);
  background: var(--neutral-50);
  box-shadow: 0 24px 80px rgba(36, 31, 27, 0.22);
  padding: 22px;
}

.search-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
}

.search-head label {
  color: var(--stone-800);
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 500;
}

#search-input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--stone-200);
  background: var(--stone-50);
  padding: 0 14px;
}

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

.search-result {
  border: 1px solid var(--neutral-200);
  background: transparent;
  padding: 14px;
  text-align: left;
}

.search-result strong {
  display: block;
  color: var(--stone-800);
  font-weight: 500;
}

.search-result span {
  display: block;
  margin-top: 6px;
  color: var(--neutral-600);
  font-size: 14px;
  line-height: 1.55;
}

mark {
  background: var(--terra-50);
  color: var(--terra-600);
}

.empty-search {
  margin: 0;
  color: var(--neutral-600);
}

@media (max-width: 1180px) {
  .reader {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .reference-rail {
    display: none;
  }
}

@media (max-width: 820px) {
  .mobile-only {
    display: inline-flex;
    align-items: center;
  }

  .reader {
    display: block;
    padding: 70px 0 0;
  }

  .toc {
    position: fixed;
    inset: 58px auto 0 0;
    z-index: 30;
    width: min(320px, 88vw);
    max-height: none;
    transform: translateX(-105%);
    border-right: 1px solid var(--neutral-200);
    background: var(--brand-bg);
    padding: 18px;
    transition: transform 180ms ease;
  }

  .toc.is-open {
    transform: translateX(0);
  }

  .book-page {
    border: 0;
    padding: 34px 22px 46px;
  }

  .chapter-content h1 {
    font-size: 32px;
  }

  .gate {
    padding: 18px;
  }

  .gate-publication {
    display: block;
  }

  .gate-cover {
    min-height: auto;
    padding: 32px 24px 38px;
    border-right: 0;
    border-bottom: 1px solid var(--stone-200);
  }

  .gate-panel {
    padding: 30px 24px;
  }

  .gate-cover h1 {
    font-size: 38px;
  }

  .access-row {
    display: grid;
  }

  .access-row button {
    height: 46px;
  }

  .brand-lockup img {
    width: 118px;
  }

  .reader-toc-item,
  .guide-grid {
    grid-template-columns: 1fr;
  }

  .guide-card {
    min-height: 140px;
  }
}
