:root {
  --paper: #f3f1e7;
  --paper-2: #e7e2d2;
  --ink: #1c1b17;
  --ink-soft: #4c463c;
  --forge: #b4471e;
  --ember: #7c2e1d;
  --gray: #6f685a;
  --field: #22201c;
  --line: rgba(28, 27, 23, 0.2);
  --display: "Anton", Impact, sans-serif;
  --label: "Archivo", system-ui, sans-serif;
  --body: "Spectral", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --topbar: 58px;
  --rail: 310px;
  --z-sticky: 20;
  --z-backdrop: 30;
  --z-drawer: 40;
}

* { box-sizing: border-box; }
html { color: var(--ink); background: var(--field); }
.library-body { min-height: 100vh; margin: 0; background: var(--paper); color: var(--ink); font-family: var(--body); }
.library-body a { color: inherit; }
.skip-link { position: fixed; left: 12px; top: 8px; z-index: 50; padding: 10px 14px; background: var(--ink); color: var(--paper) !important; font-family: var(--label); transform: translateY(-140%); }
.skip-link:focus { transform: translateY(0); }
a:focus-visible, button:focus-visible { outline: 3px solid var(--forge); outline-offset: 3px; }

.library-topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: var(--z-sticky);
  height: var(--topbar);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 clamp(14px, 2vw, 30px);
  border-bottom: 1px solid var(--line);
  background: rgba(243, 241, 231, 0.97);
  font-family: var(--label);
}
.topbar-title { overflow: hidden; font-weight: 700; text-decoration: none; text-overflow: ellipsis; white-space: nowrap; }
.contents-button { display: none; border: 1px solid var(--line); border-radius: 4px; padding: 8px 11px; background: transparent; color: var(--ink); font: 700 0.86rem var(--label); cursor: pointer; }
.contents-button::before { content: "☰"; margin-right: 7px; }
.utility-nav { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.utility-link { color: var(--ember) !important; font-size: 0.84rem; font-weight: 600; text-decoration: none; }
.utility-link:hover { text-decoration: underline; text-underline-offset: 3px; }

.library-rail {
  position: fixed;
  inset: var(--topbar) auto 0 0;
  z-index: 10;
  width: var(--rail);
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: #f8f7f1;
  font-family: var(--label);
}
.rail-brand { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 22px 22px 16px; border-bottom: 1px solid var(--line); }
.rail-brand a { font: 400 1.45rem var(--display); letter-spacing: 0.01em; text-decoration: none; text-transform: uppercase; }
.rail-brand span { color: var(--gray); font: 0.68rem var(--mono); text-transform: uppercase; }
.rail-collection { display: block; padding: 16px 22px; color: var(--ember) !important; font-weight: 700; text-decoration: none; }
.library-rail > nav > ol { margin: 0; padding: 0 12px 28px; list-style: none; }
.rail-group { margin-bottom: 2px; }
.rail-group-row { display: grid; grid-template-columns: minmax(0, 1fr) 38px; align-items: stretch; }
.rail-parent { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 8px; padding: 10px; border-radius: 4px; color: var(--ink-soft); font-size: 0.84rem; line-height: 1.25; text-decoration: none; }
.rail-parent:hover { background: var(--paper-2); color: var(--ink); }
.rail-parent[aria-current="page"] { background: var(--ink); color: var(--paper); }
.nav-group-toggle { display: grid; place-items: center; border: 0; background: transparent; color: var(--gray); cursor: pointer; }
.nav-group-toggle:hover { color: var(--ember); background: var(--paper-2); }
.nav-group-toggle span { display: block; font-size: 0.68rem; transition: transform 160ms cubic-bezier(.22, 1, .36, 1); }
.rail-group.open > .rail-group-row .nav-group-toggle span,
.collection-group.open > .collection-section-row .nav-group-toggle span { transform: rotate(90deg); }
.rail-children { margin: 2px 0 8px 14px; padding: 2px 0 3px 13px; border-left: 1px solid var(--line); list-style: none; }
.rail-children li a { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 7px 8px; border-radius: 3px; color: var(--ink-soft); font-size: 0.76rem; line-height: 1.3; text-decoration: none; }
.rail-children li a:hover { background: var(--paper-2); color: var(--ink); }
.rail-children li a[aria-current="location"] { background: var(--paper-2); color: var(--ember); font-weight: 700; }
.nav-enhanced .rail-group:not(.open) > .rail-children,
.nav-enhanced .collection-group:not(.open) > .collection-children { display: none; }
.nested-page { flex: none; color: var(--gray); font: 0.62rem var(--mono); white-space: nowrap; }
.current-marker { font: 0.58rem var(--mono); text-transform: uppercase; }
.rail-backdrop { position: fixed; inset: var(--topbar) 0 0; z-index: var(--z-backdrop); background: rgba(28, 27, 23, 0.55); }

.library-main { min-height: 100vh; padding-top: var(--topbar); }
.library-body:has(.library-rail) .library-main { margin-left: var(--rail); }
.section-article { min-width: 0; }
.section-masthead { padding: clamp(34px, 5vw, 72px) clamp(22px, 6vw, 92px) clamp(28px, 4vw, 56px); border-bottom: 1px solid var(--line); background: var(--paper); }
.section-context { margin: 0 0 14px; color: var(--ember); font: 700 0.72rem var(--mono); letter-spacing: 0.06em; text-transform: uppercase; }
.section-masthead h1 { max-width: 15ch; margin: 0; font: 400 clamp(2.8rem, 7vw, 5.6rem)/0.92 var(--display); letter-spacing: -0.01em; text-wrap: balance; }
.section-summary { max-width: 62ch; margin: 20px 0 0; color: var(--ink-soft); font-size: clamp(1.05rem, 2vw, 1.35rem); line-height: 1.45; text-wrap: pretty; }

.sheet-stage { min-width: 0; padding: clamp(24px, 5vw, 64px) clamp(10px, 3vw, 42px); overflow-x: auto; background: var(--field); }
.sheet-frame { position: relative; margin: 0 auto clamp(20px, 4vw, 42px); overflow: visible; }
.sheet-frame > .sheet { position: absolute !important; inset: 0 auto auto 0; margin: 0 !important; transform-origin: top left; box-shadow: 0 8px 16px rgba(0, 0, 0, 0.28) !important; }

.section-pager { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: stretch; gap: 1px; border-top: 1px solid var(--line); background: var(--line); font-family: var(--label); }
.section-pager a { display: flex; min-height: 105px; flex-direction: column; justify-content: center; padding: 22px clamp(18px, 4vw, 48px); background: var(--paper); text-decoration: none; }
.section-pager a:last-child { text-align: right; align-items: flex-end; }
.section-pager a:hover { background: var(--paper-2); }
.section-pager span { color: var(--gray); font: 0.67rem var(--mono); text-transform: uppercase; }
.section-pager strong { margin-top: 5px; font-size: 0.96rem; }
.section-pager .pager-contents { min-width: 120px; align-items: center; color: var(--ember); font-size: 0.82rem; font-weight: 700; text-align: center; }

.collection-home { min-height: calc(100vh - var(--topbar)); }
.collection-hero { padding: clamp(54px, 9vw, 120px) clamp(24px, 8vw, 112px); color: var(--paper); background-color: var(--ink); background-image: linear-gradient(rgba(255,255,255,.045) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.045) 1px, transparent 1px); background-size: 22px 22px; }
.collection-badge { display: inline-block; color: #cfc8b8; font: 0.72rem var(--mono); letter-spacing: 0.08em; text-transform: uppercase; }
.collection-hero h1 { max-width: 12ch; margin: 26px 0 20px; color: var(--paper); font: 400 clamp(4rem, 10vw, 6rem)/0.86 var(--display); letter-spacing: -0.01em; text-wrap: balance; }
.collection-hero > p { max-width: 58ch; color: #d8d2c3; font-size: clamp(1.1rem, 2vw, 1.35rem); line-height: 1.5; }
.collection-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 20px; margin-top: 34px; font-family: var(--label); }
.collection-actions a { color: var(--paper); font-weight: 700; text-underline-offset: 4px; }
.collection-actions .primary-action { padding: 12px 17px; background: var(--forge); text-decoration: none; }
.collection-index { padding: clamp(42px, 7vw, 90px) clamp(24px, 8vw, 112px); }
.collection-index h2 { margin: 0; font: 400 clamp(2.2rem, 5vw, 3.8rem) var(--display); }
.index-help { max-width: 60ch; margin: 8px 0 24px; color: var(--ink-soft); }
.collection-index > ol { margin: 0; padding: 0; border-top: 2px solid var(--ink); list-style: none; }
.collection-group { border-bottom: 1px solid var(--line); }
.collection-section-row { display: grid; grid-template-columns: minmax(0, 1fr) 56px; align-items: stretch; }
.collection-section-link { display: grid; grid-template-columns: minmax(160px, 0.65fr) minmax(220px, 1fr) auto; gap: 22px; padding: 18px 0; text-decoration: none; }
.collection-section-link:hover .index-title { color: var(--forge); }
.collection-toggle { border-left: 1px solid var(--line); }
.collection-children { margin: 0 56px 14px clamp(20px, 4vw, 48px); padding: 7px 0 0; border-top: 1px solid var(--line); list-style: none; }
.collection-children li a { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px; padding: 9px 12px; color: var(--ink-soft); font-family: var(--label); font-size: 0.86rem; text-decoration: none; }
.collection-children li a:hover { background: var(--paper-2); color: var(--ember); }
.index-title { font: 700 0.95rem var(--label); }
.index-description { color: var(--ink-soft); }
.index-page { color: var(--gray); font: 0.74rem var(--mono); white-space: nowrap; }

.library-home { min-height: calc(100vh - var(--topbar)); padding: clamp(52px, 9vw, 120px) clamp(24px, 8vw, 120px); background: var(--ink); color: var(--paper); }
.library-home header { max-width: 800px; }
.library-home h1 { margin: 28px 0 26px; font: 400 clamp(4.2rem, 12vw, 6rem)/0.82 var(--display); letter-spacing: -0.01em; }
.library-home .title-pair { display: flex; flex-wrap: wrap; column-gap: 0.13em; }
.library-home header p { max-width: 68ch; color: #d8d2c3; font-size: 1.2rem; line-height: 1.55; }
.library-home ol { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin: clamp(42px, 7vw, 84px) 0 0; padding: 0; list-style: none; }
.library-home li a { display: flex; height: 100%; flex-direction: column; padding: 26px; border: 1px solid rgba(243, 241, 231, 0.3); background: #201f1b; color: var(--paper); text-decoration: none; }
.library-home li a:hover { border-color: var(--forge); background: #29261f; }
.library-kind { color: #cfc8b8; font: 0.67rem var(--mono); text-transform: uppercase; }
.library-home li strong { margin: 18px 0 12px; font: 400 2.1rem/1 var(--display); }
.library-home .library-description { color: #d8d2c3; line-height: 1.4; }
.library-home .library-open { margin-top: 22px; color: var(--paper); font: 700 0.84rem/1.3 var(--label); }

@media (min-width: 1280px) {
  .library-home ol { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.reader-flow { max-width: 78ch; margin: 0 auto; padding: clamp(42px, 7vw, 92px) clamp(22px, 6vw, 72px); font-size: clamp(1.05rem, 1.5vw, 1.2rem); line-height: 1.68; }
.reader-flow .frontmatter, .reader-flow #TOC, .reader-flow .unit-opener, .reader-flow .level1 { width: auto; height: auto; min-height: 0; margin: 0 0 54px; padding: 0; background: none; break-before: auto; break-after: auto; }
.reader-flow .reg, .reader-flow .unit-anvil-box { display: none; }
.reader-flow .eyebrow { color: var(--ember); font: 700 0.72rem var(--mono); letter-spacing: 0.08em; text-transform: uppercase; }
.reader-flow h1, .reader-flow h2 { margin: 2.2em 0 0.55em; padding: 0; border: 0; color: var(--ink); font: 400 clamp(2.4rem, 6vw, 4.4rem)/0.94 var(--display); letter-spacing: 0; text-wrap: balance; }
.reader-flow h3 { margin: 1.8em 0 0.5em; color: var(--ember); font: 700 1.02rem/1.25 var(--label); }
.reader-flow p { margin: 0 0 1em; }
.reader-flow blockquote { margin: 1.5em 0; padding: 18px 22px; background: var(--paper-2); font-style: italic; }
.reader-flow #TOC ul { columns: 1; margin: 18px 0 0; padding: 0; list-style: none; }
.reader-flow #TOC li { margin: 0; border-bottom: 1px solid var(--line); }
.reader-flow #TOC a { display: flex; justify-content: space-between; gap: 18px; padding: 10px 0; text-decoration: none; }
.reader-flow .toc-page { font-family: var(--mono); }
.reader-flow img { max-width: 100%; height: auto; }
.sheet-frame, .reader-flow [id] { scroll-margin-top: calc(var(--topbar) + 18px); }

@media (max-width: 860px) {
  .contents-button { display: inline-block; }
  .library-rail { z-index: var(--z-drawer); width: min(88vw, 330px); transform: translateX(-105%); transition: transform 180ms cubic-bezier(.22, 1, .36, 1); box-shadow: 4px 0 8px rgba(0,0,0,.22); }
  .rail-open .library-rail { transform: translateX(0); }
  .library-body:has(.library-rail) .library-main { margin-left: 0; }
  .utility-nav .utility-link:first-child { display: none; }
  .section-masthead h1 { font-size: clamp(2.7rem, 13vw, 4.3rem); }
  .collection-section-link { grid-template-columns: 1fr auto; gap: 7px 16px; }
  .collection-section-link .index-description { grid-column: 1 / -1; }
  .section-pager { grid-template-columns: 1fr 1fr; }
  .section-pager .pager-contents { grid-column: 1 / -1; grid-row: 2; min-height: 58px; }
  .section-pager .pager-empty { display: none; }
}

@media (max-width: 520px) {
  .library-topbar { gap: 10px; }
  .topbar-title { font-size: 0.86rem; }
  .utility-nav { gap: 8px; }
  .utility-link { font-size: 0.77rem; }
  .section-masthead { padding-inline: 20px; }
  .sheet-stage { padding-inline: 0; }
  .collection-hero, .collection-index, .library-home { padding-inline: 20px; }
  .collection-section-link { padding: 16px 0; }
  .collection-section-row { grid-template-columns: minmax(0, 1fr) 48px; }
  .collection-children { margin-right: 48px; margin-left: 8px; }
  .library-home ol { grid-template-columns: 1fr; }
}

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

@media print {
  .library-topbar, .library-rail, .rail-backdrop, .section-masthead, .section-pager, .skip-link { display: none !important; }
  .library-body:has(.library-rail) .library-main { margin: 0; padding: 0; }
  .sheet-stage { padding: 0; overflow: visible; background: white; }
  .sheet-frame { width: 8.5in !important; height: 11in !important; margin: 0 !important; break-after: page; }
  .sheet-frame > .sheet { position: relative !important; transform: none !important; box-shadow: none !important; }
  .reader-flow { max-width: none; padding: 0; font-size: 11pt; }
}
