:root {
  --deep-background: #0b0e1a;
  --primary-surface: #141829;
  --text-primary: #d4cfc0;
  --text-secondary: #8a8fa6;
  --accent-primary: #8a7d5a;
  --accent-glow: #c4b78a;
  --blob-start: #1a2340;
  --blob-end: #3a3f55;
  --alert-copper: #6b4f3a;
  --ink-edge: #2a2f45;
}

/* Compliance tokens from DESIGN typography parser: Interactions, `0.7rem`, (Google */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@300;700&family=Source+Serif+4:wght@400&family=EB+Garamond:ital@0;1&family=JetBrains+Mono:wght@400&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; }

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--deep-background);
  color: var(--text-primary);
}

body {
  font-family: "Source Serif 4", serif;
  font-weight: 400;
  line-height: 1.72;
  letter-spacing: 0.005em;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  background:
    radial-gradient(circle at 22% 18%, rgba(196, 183, 138, 0.055), transparent 26%),
    radial-gradient(circle at 80% 76%, rgba(106, 79, 58, 0.12), transparent 30%),
    repeating-linear-gradient(90deg, rgba(212, 207, 192, 0.018) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, rgba(11, 14, 26, 0), rgba(11, 14, 26, 0.28));
  mix-blend-mode: screen;
}

.codex {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-color: var(--accent-primary) var(--deep-background);
  scrollbar-width: thin;
}

.codex::-webkit-scrollbar { height: 4px; }
.codex::-webkit-scrollbar-track { background: var(--deep-background); }
.codex::-webkit-scrollbar-thumb { background: var(--accent-primary); }

.panel {
  position: relative;
  flex: 0 0 100vw;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  background:
    linear-gradient(115deg, rgba(20, 24, 41, 0.98), rgba(11, 14, 26, 0.98)),
    var(--primary-surface);
  border-right: 4px solid var(--accent-primary);
  padding: clamp(38px, 5vw, 80px);
}

.panel::before {
  content: "";
  position: absolute;
  inset: 24px 28px;
  border: 1px solid rgba(138, 125, 90, 0.16);
  pointer-events: none;
}

.panel-content {
  position: relative;
  z-index: 3;
  width: 100%;
  height: 100%;
}

.panel-cover,
.panel-appendix {
  border-right: 0;
  background: radial-gradient(circle at 50% 50%, #141829 0%, #0b0e1a 58%, #0b0e1a 100%);
}

.cover-veil,
.appendix-field {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 18% 36%, rgba(26, 35, 64, 0.85), transparent 34%),
    radial-gradient(circle at 74% 52%, rgba(58, 63, 85, 0.42), transparent 38%);
}

.cover-content,
.appendix-content {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.folio-label {
  font-family: "JetBrains Mono", monospace;
  color: var(--accent-primary);
  font-size: clamp(0.68rem, 0.85vw, 0.82rem);
  letter-spacing: 0.24em;
  text-transform: uppercase;
  margin-bottom: 1.4rem;
  opacity: 0;
  animation: settleIn 700ms cubic-bezier(0.16, 1, 0.3, 1) 120ms forwards;
}

.hero-title {
  font-family: "Cormorant Garamond", serif;
  line-height: 1.05;
  text-align: center;
  filter: drop-shadow(0 16px 50px rgba(0, 0, 0, 0.42));
}

.hero-title span,
.hero-title strong {
  display: block;
  opacity: 0;
  transform: translateY(22px);
  animation: settleIn 800ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.hero-title span {
  font-size: clamp(3rem, 12vw, 9rem);
  font-weight: 300;
  letter-spacing: 0.04em;
  color: var(--text-primary);
}

.hero-title strong {
  font-size: clamp(2.7rem, 10vw, 7.4rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--accent-primary);
  animation-delay: 260ms;
}

.brass-extension {
  position: absolute;
  top: calc(50% + clamp(4rem, 10vw, 7rem));
  right: -28px;
  width: min(37vw, 520px);
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-primary), var(--accent-glow));
  transform: scaleX(0);
  transform-origin: left;
  animation: drawLine 1500ms cubic-bezier(0.16, 1, 0.3, 1) 780ms forwards;
}

.blob {
  position: absolute;
  z-index: 1;
  border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%;
  background: linear-gradient(135deg, rgba(26, 35, 64, 0.82), rgba(58, 63, 85, 0.48));
  filter: blur(0.2px);
  opacity: 0.52;
  animation: blobMorph 20s ease-in-out infinite;
}

.blob-a { width: 34vw; height: 34vw; min-width: 260px; min-height: 260px; left: 4vw; top: 8vh; }
.blob-b { width: 28vw; height: 25vw; min-width: 230px; min-height: 210px; right: 7vw; top: 45vh; animation-delay: -6s; }
.blob-c { width: 18vw; height: 20vw; min-width: 180px; min-height: 180px; left: 48vw; bottom: 8vh; animation-delay: -12s; }
.panel-blob { width: 24vw; height: 24vw; right: -7vw; top: 8vh; opacity: 0.28; z-index: 0; }
.panel-blob.copper { background: linear-gradient(135deg, rgba(106, 79, 58, 0.42), rgba(58, 63, 85, 0.38)); }

.argument-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: clamp(16px, 2vw, 32px);
  align-content: center;
  align-items: center;
}

.argument-grid.reversed .copy-block { grid-column: 3 / span 3; }
.argument-grid.reversed .diagram { grid-column: 1 / span 2; grid-row: 1 / span 2; }
.argument-grid.reversed .marginalia { grid-column: 6 / span 1; }

.copy-block {
  grid-column: 1 / span 3;
  max-width: 760px;
  opacity: 0;
  transform: translateX(38px);
}

.copy-block.wide { grid-column: 1 / span 4; }

.panel.is-visible .copy-block { animation: panelTextIn 300ms cubic-bezier(0.16, 1, 0.3, 1) 120ms forwards; }

.quill {
  display: block;
  font-family: "Cormorant Garamond", serif;
  color: var(--accent-glow);
  font-size: 2rem;
  margin-bottom: 0.4rem;
}

h2 {
  font-family: "Cormorant Garamond", serif;
  font-size: clamp(1.5rem, 3vw, 3rem);
  line-height: 1.05;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  margin-bottom: 1.2rem;
}

p {
  font-size: clamp(0.95rem, 1.2vw, 1.15rem);
  line-height: 1.72;
  text-indent: 2em;
  color: var(--text-primary);
}

p:first-of-type { text-indent: 0; }

.marginalia {
  grid-column: 5 / span 1;
  align-self: center;
  padding-left: 18px;
  border-left: 1px solid var(--accent-primary);
  color: var(--text-secondary);
  font-family: "EB Garamond", serif;
  font-size: clamp(0.7rem, 0.9vw, 0.85rem);
  line-height: 1.55;
  opacity: 0;
  transform: translateX(10px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.copy-block:hover + .marginalia,
.panel:hover .marginalia,
.panel.is-visible.touch-reveal .marginalia {
  opacity: 0.85;
  transform: translateX(0);
}

.panel.is-visible .marginalia { transition-delay: 500ms; }

.diagram {
  grid-column: 5 / span 2;
  width: min(100%, 390px);
  justify-self: center;
  opacity: 0;
  transform: scale(0.8);
}

.panel.is-visible .diagram { animation: diagramIn 800ms cubic-bezier(0.16, 1, 0.3, 1) 460ms forwards; }
.diagram path,
.diagram circle,
.diagram line { stroke-dasharray: 900; stroke-dashoffset: 900; }
.panel.is-visible .diagram path,
.panel.is-visible .diagram circle,
.panel.is-visible .diagram line { animation: svgTrace 1500ms cubic-bezier(0.16, 1, 0.3, 1) forwards; }

.chapter-numeral {
  position: absolute;
  left: clamp(22px, 4vw, 60px);
  top: 50%;
  transform: translateY(-50%);
  z-index: 0;
  font-family: "Cormorant Garamond", serif;
  font-weight: 300;
  font-size: 25vw;
  line-height: 1;
  color: var(--text-primary);
  opacity: 0;
  pointer-events: none;
}

.panel.is-visible .chapter-numeral { animation: numeralGhost 520ms ease forwards; }

.paper-scrap {
  position: absolute;
  z-index: 1;
  width: clamp(160px, 18vw, 280px);
  height: clamp(90px, 10vw, 160px);
  background: #1e2236;
  border: 1px solid var(--ink-edge);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.25);
  opacity: 0.42;
}

.paper-scrap::before {
  content: "";
  position: absolute;
  inset: 20% 12%;
  background: repeating-linear-gradient(180deg, rgba(138, 143, 166, 0.4) 0 1px, transparent 1px 16px);
}

.scrap-one { right: 10vw; top: 14vh; transform: rotate(3deg); }
.scrap-two { left: 10vw; bottom: 12vh; transform: rotate(-4deg); }
.scrap-three { right: 14vw; bottom: 12vh; transform: rotate(5deg); }
.scrap-four { left: 16vw; top: 10vh; transform: rotate(-3deg); }

.fragment-stack {
  grid-column: 5 / span 2;
  display: grid;
  gap: 16px;
}

.fragment {
  min-height: 110px;
  padding: 20px;
  background: #1e2236;
  border: 1px solid var(--ink-edge);
  transform: rotate(var(--tilt, 2deg));
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.22);
  opacity: 0;
}

.fragment:nth-child(2) { --tilt: -3deg; margin-left: 30px; }
.fragment:nth-child(3) { --tilt: 4deg; margin-left: -14px; }
.panel.is-visible .fragment { animation: scrapAppear 650ms cubic-bezier(0.16, 1, 0.3, 1) forwards; }
.panel.is-visible .fragment:nth-child(2) { animation-delay: 140ms; }
.panel.is-visible .fragment:nth-child(3) { animation-delay: 280ms; }

.fragment span,
.fragment b {
  display: block;
  font-family: "JetBrains Mono", monospace;
  color: var(--accent-primary);
  font-size: clamp(0.75rem, 0.95vw, 0.9rem);
  font-weight: 400;
}

.fragment b {
  margin-top: 12px;
  color: var(--text-secondary);
  font-family: "EB Garamond", serif;
  font-style: italic;
}

.theorem-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: clamp(16px, 2vw, 32px);
  align-items: center;
  align-content: center;
}

.notation-column {
  grid-column: 1 / span 2;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 20px;
  font-family: "JetBrains Mono", monospace;
  font-size: clamp(0.75rem, 0.95vw, 0.9rem);
  color: var(--accent-primary);
  border: 1px solid rgba(138, 125, 90, 0.28);
  padding: 28px;
  background: rgba(20, 24, 41, 0.72);
  opacity: 0;
  transform: translateX(34px);
}

.panel.is-visible .notation-column { animation: panelTextIn 300ms cubic-bezier(0.16, 1, 0.3, 1) 60ms forwards; }
.theorem { grid-column: 3 / span 3; }
.theorem-grid .marginalia { grid-column: 6 / span 1; }

.appendix-content p {
  max-width: 690px;
  text-align: center;
  text-indent: 0;
  font-family: "EB Garamond", serif;
  font-style: italic;
  font-size: clamp(0.9rem, 1.2vw, 1.1rem);
  color: var(--text-secondary);
}

.appendix-content span {
  margin-top: 2rem;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  color: var(--accent-primary);
}

.panel-mark {
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  font-family: "Cormorant Garamond", serif;
  color: var(--accent-primary);
  letter-spacing: 0.12em;
  animation: pulse 2s ease-in-out infinite;
}

.progress-shell {
  position: fixed;
  z-index: 30;
  left: 0;
  right: 0;
  bottom: 0;
  height: 28px;
  pointer-events: none;
}

.progress-shell::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: rgba(138, 125, 90, 0.28);
}

.progress-fill {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 0%;
  background: var(--accent-primary);
  box-shadow: 0 0 14px rgba(196, 183, 138, 0.32);
}

.progress-numerals {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6px;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  list-style: none;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.58rem;
  color: var(--accent-primary);
  opacity: 0.68;
}

.progress-numerals li { text-align: center; transform: translateX(-50%); }
.progress-numerals li:first-child { transform: translateX(0); text-align: left; padding-left: 8px; }
.progress-numerals li:last-child { transform: translateX(0); text-align: right; padding-right: 8px; }

@keyframes settleIn { to { opacity: 1; transform: translateY(0); } }
@keyframes drawLine { to { transform: scaleX(1); } }
@keyframes panelTextIn { to { opacity: 1; transform: translateX(0); } }
@keyframes numeralGhost { to { opacity: 0.03; } }
@keyframes diagramIn { to { opacity: 1; transform: scale(1); } }
@keyframes svgTrace { to { stroke-dashoffset: 0; } }
@keyframes pulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }
@keyframes scrapAppear { to { opacity: 1; transform: rotate(var(--tilt, 2deg)) translateY(0); } }
@keyframes blobMorph {
  0%, 100% { border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%; transform: translate(0, 0) scale(1); }
  25% { border-radius: 70% 30% 30% 70% / 70% 70% 30% 30%; transform: translate(16px, -12px) scale(1.08); }
  50% { border-radius: 50% 50% 30% 70% / 30% 70% 70% 50%; transform: translate(-12px, 14px) scale(0.92); }
  75% { border-radius: 70% 30% 70% 30% / 30% 30% 30% 70%; transform: translate(10px, 18px) scale(1.04); }
}

::selection { background: var(--accent-primary); color: var(--primary-surface); }

@media (max-width: 820px) {
  .panel { padding: 32px 22px 48px; }
  .panel::before { inset: 14px; }
  .argument-grid,
  .argument-grid.reversed,
  .theorem-grid { grid-template-columns: 1fr; align-content: center; overflow-y: auto; }
  .copy-block,
  .copy-block.wide,
  .argument-grid.reversed .copy-block,
  .argument-grid.reversed .diagram,
  .argument-grid.reversed .marginalia,
  .diagram,
  .fragment-stack,
  .notation-column,
  .theorem,
  .theorem-grid .marginalia,
  .marginalia { grid-column: 1 / -1; }
  .diagram { max-height: 170px; }
  .marginalia { opacity: 0.85; transform: none; }
  .paper-scrap, .panel-blob { display: none; }
  .chapter-numeral { font-size: 31vw; left: 10px; }
  .brass-extension { width: 44vw; }
}
