:root {
  --ink: #11100D;
  --paper: #F4EAD6;
  --shadow: #C9B68E;
  --desk: #070706;
  --seal: #A53322;
  --indigo: #263B59;
  --rice: #FFF8E8;
  --display: "Fraunces", Georgia, serif;
  --serif: "Source Serif 4", Georgia, serif;
  --mono: "IBM Plex Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  background: var(--desk);
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--serif);
  background:
    radial-gradient(circle at 50% 38%, rgba(255, 248, 232, 0.11), transparent 31rem),
    linear-gradient(135deg, #070706 0%, #11100D 48%, #070706 100%);
}

.desk-grain,
.lamplight,
.dust-field {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.desk-grain {
  opacity: .2;
  background-image:
    repeating-linear-gradient(88deg, rgba(255, 248, 232, .03) 0 1px, transparent 1px 9px),
    radial-gradient(circle at 24% 28%, rgba(201, 182, 142, .08), transparent 18rem),
    radial-gradient(circle at 76% 68%, rgba(38, 59, 89, .12), transparent 22rem);
}

.lamplight {
  background: radial-gradient(ellipse at 50% 46%, rgba(244, 234, 214, .28), rgba(244, 234, 214, .05) 28rem, transparent 43rem);
  mix-blend-mode: screen;
}

.dust-field span {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(255, 248, 232, .42);
  animation: drift 13s linear infinite;
}
.dust-field span:nth-child(1) { left: 18%; top: 72%; animation-duration: 18s; }
.dust-field span:nth-child(2) { left: 31%; top: 24%; animation-duration: 14s; animation-delay: -5s; }
.dust-field span:nth-child(3) { left: 57%; top: 61%; animation-duration: 20s; animation-delay: -9s; }
.dust-field span:nth-child(4) { left: 72%; top: 32%; animation-duration: 16s; animation-delay: -3s; }
.dust-field span:nth-child(5) { left: 84%; top: 78%; animation-duration: 22s; animation-delay: -12s; }
.dust-field span:nth-child(6) { left: 45%; top: 12%; animation-duration: 15s; animation-delay: -7s; }

.toc-bookmark {
  position: fixed;
  z-index: 10;
  top: 24px;
  left: 50%;
  display: flex;
  gap: 18px;
  padding: 9px 18px 12px;
  transform: translateX(-50%);
  border: 1px solid rgba(201, 182, 142, .45);
  border-top: 0;
  background: rgba(244, 234, 214, .08);
  backdrop-filter: blur(8px);
  font: 500 11px/1 var(--mono);
  letter-spacing: .12em;
}
.toc-bookmark a {
  color: rgba(255, 248, 232, .72);
  text-decoration: none;
  transition: color .45s ease;
}
.toc-bookmark a.is-current { color: var(--seal); }

.folio-reader {
  position: relative;
  height: 100vh;
  width: 100vw;
}

.chamber {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(72px, 10vw, 128px) clamp(24px, 7vw, 96px);
  opacity: 0;
  visibility: hidden;
  transform: perspective(1200px) rotateY(5deg) translateX(38px);
  transition: opacity .9s ease, transform 1s cubic-bezier(.22,.68,.22,1), visibility .9s;
}
.chamber.is-active {
  opacity: 1;
  visibility: visible;
  transform: perspective(1200px) rotateY(0deg) translateX(0);
}
.chamber.is-leaving { transform: perspective(1200px) rotateY(-7deg) translateX(-52px); }

.paper {
  position: relative;
  width: min(620px, 86vw);
  min-height: min(650px, 72vh);
  padding: clamp(34px, 6vw, 72px);
  background:
    radial-gradient(circle at 24% 18%, rgba(165, 51, 34, .075), transparent 9rem),
    radial-gradient(circle at 76% 78%, rgba(38, 59, 89, .08), transparent 12rem),
    repeating-linear-gradient(0deg, rgba(17, 16, 13, .018) 0 1px, transparent 1px 5px),
    linear-gradient(135deg, var(--rice), var(--paper) 38%, #EAD9B7 100%);
  box-shadow: 0 40px 90px rgba(0, 0, 0, .56), inset 0 0 0 1px rgba(17, 16, 13, .16), inset 0 0 48px rgba(201, 182, 142, .44);
  isolation: isolate;
}
.paper::before,
.paper::after {
  content: "";
  position: absolute;
  inset: 12px;
  pointer-events: none;
  border: 1px solid rgba(17, 16, 13, .18);
}
.paper::after {
  inset: 0;
  border: 0;
  opacity: .34;
  background-image:
    radial-gradient(circle, rgba(17, 16, 13, .12) 0 1px, transparent 1px),
    linear-gradient(92deg, transparent 0 49%, rgba(17, 16, 13, .055) 50%, transparent 51%);
  background-size: 19px 23px, 100% 100%;
  mix-blend-mode: multiply;
}

.paper-bookplate { display: grid; align-content: center; text-align: center; }
.paper-receipt { width: min(430px, 82vw); min-height: 72vh; }
.paper-card { width: min(720px, 88vw); min-height: 590px; }
.paper-letter { width: min(640px, 86vw); min-height: 520px; transform: rotate(-1deg); }
.paper-colophon { width: min(540px, 84vw); min-height: 540px; text-align: center; }

.bookplate-frame {
  position: relative;
  z-index: 1;
  padding: clamp(42px, 7vw, 74px) 24px;
  border: 1px solid var(--ink);
  outline: 8px solid rgba(201, 182, 142, .2);
}
.ex-libris,
.shelfmark,
.chapter,
.mono,
.page-controls,
.archive-label,
.diagram-labels {
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: .12em;
}
.ex-libris { margin: 0 0 22px; color: var(--indigo); font-size: 11px; }
.shelfmark, .chapter { margin: 0 0 34px; color: var(--indigo); font-size: 11px; }

h1, h2 {
  margin: 0;
  font-family: var(--display);
  color: var(--ink);
  font-variation-settings: "SOFT" 45, "WONK" 1;
}
h1 {
  min-height: 1.15em;
  font-size: clamp(3.1rem, 10vw, 7.8rem);
  font-weight: 620;
  letter-spacing: -.08em;
}
h2 {
  max-width: 12ch;
  font-size: clamp(2.2rem, 6vw, 4.8rem);
  font-weight: 560;
  line-height: .94;
  letter-spacing: -.055em;
}
.paper-colophon h2 { max-width: none; color: var(--seal); }

.serif,
.subtitle,
.typed-note {
  position: relative;
  z-index: 1;
  font-family: var(--serif);
  font-size: clamp(1.05rem, 1.9vw, 1.35rem);
  line-height: 1.55;
  color: rgba(17, 16, 13, .84);
}
.subtitle { max-width: 34ch; margin: 20px auto 0; font-style: italic; }
.cursor {
  display: inline-block;
  width: .08em;
  height: .82em;
  margin-left: .08em;
  background: var(--seal);
  animation: blink .86s steps(1) infinite;
  vertical-align: -.08em;
}

.seal {
  position: absolute;
  right: clamp(42px, 7vw, 86px);
  bottom: clamp(42px, 7vw, 80px);
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
  border: 3px double rgba(165, 51, 34, .9);
  border-radius: 50%;
  color: var(--seal);
  font: 500 13px/1 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  opacity: 0;
  transform: scale(1.7) rotate(-12deg);
  filter: blur(4px);
}
.seal.is-stamped {
  opacity: .92;
  transform: scale(1) rotate(-12deg);
  filter: blur(.2px);
  transition: opacity .7s ease, transform .7s cubic-bezier(.16,1.2,.25,1), filter 1.1s ease;
  box-shadow: 0 0 0 15px rgba(165, 51, 34, .06), inset 0 0 18px rgba(165, 51, 34, .13);
}

.registration { position: absolute; color: var(--indigo); font: 18px var(--mono); opacity: .55; }
.top-left { top: 25px; left: 25px; }
.bottom-right { right: 25px; bottom: 25px; }
.moon-ticks { position: absolute; left: 30px; bottom: 46px; display: flex; gap: 6px; opacity: .6; }
.moon-ticks i { width: 11px; height: 11px; border: 1px solid var(--indigo); border-radius: 50%; }
.moon-ticks i:nth-child(2), .moon-ticks i:nth-child(4) { background: linear-gradient(90deg, var(--indigo) 50%, transparent 50%); }
.moon-ticks i:nth-child(3) { background: var(--indigo); }

.spirit-mark {
  position: absolute;
  top: 28%;
  right: 38px;
  width: 54px;
  height: 68px;
  border-radius: 50% 50% 46% 46%;
  background: rgba(255, 248, 232, .28);
  border-left: 1px solid rgba(38, 59, 89, .28);
  transform: rotate(4deg);
}
.spirit-mark b { position: absolute; top: 24px; width: 7px; height: 7px; border-radius: 50%; background: var(--ink); }
.spirit-mark b:first-child { left: 17px; }
.spirit-mark b:nth-child(2) { right: 16px; }
.spirit-mark em { position: absolute; left: 30px; top: 36px; width: 10px; height: 18px; border-left: 2px solid var(--ink); border-bottom: 2px solid var(--ink); border-radius: 0 0 0 10px; }

.footnote-ladder {
  position: relative;
  z-index: 1;
  margin: 38px 0 0;
  padding-left: 22px;
  color: var(--indigo);
  font-size: .95rem;
  line-height: 2.1;
  border-left: 1px solid rgba(38, 59, 89, .34);
}

.diagram { position: relative; z-index: 1; margin: 34px 0 22px; border-top: 1px solid rgba(17,16,13,.22); border-bottom: 1px solid rgba(17,16,13,.22); }
.diagram svg { width: 100%; display: block; padding: 16px 20px; }
.draw-line {
  fill: none;
  stroke: var(--indigo);
  stroke-width: 1.4;
  stroke-dasharray: 900;
  stroke-dashoffset: 900;
}
.is-active .draw-line { animation: draw 2.6s ease forwards .4s; }
.is-active .draw-line.slow { animation-duration: 3.6s; animation-delay: .8s; }
.diagram-labels { display: flex; justify-content: space-between; color: var(--indigo); font-size: 10px; padding: 0 24px 14px; }

.fold { position: absolute; inset: 0; pointer-events: none; }
.fold-a { background: linear-gradient(101deg, transparent 0 48%, rgba(17,16,13,.07) 49%, rgba(255,248,232,.18) 51%, transparent 52%); }
.fold-b { background: linear-gradient(6deg, transparent 0 46%, rgba(38,59,89,.08) 47%, transparent 49%); }
.archive-label {
  display: inline-block;
  margin-top: 28px;
  padding: 8px 12px;
  border: 1px solid var(--seal);
  color: var(--seal);
  font-size: 10px;
  transform: rotate(.8deg);
}
.tab-button {
  position: absolute;
  right: -39px;
  top: 45%;
  padding: 13px 10px;
  border: 1px solid rgba(17,16,13,.22);
  background: var(--shadow);
  color: var(--ink);
  font: 500 10px/1 var(--mono);
  letter-spacing: .12em;
  text-transform: uppercase;
  writing-mode: vertical-rl;
  cursor: pointer;
}

.colophon-grid {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 14px;
  margin-top: 44px;
  color: var(--indigo);
  font: 11px/1.5 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
}

.page-controls {
  position: fixed;
  z-index: 12;
  left: 50%;
  bottom: 26px;
  display: flex;
  align-items: center;
  gap: 18px;
  transform: translateX(-50%);
  color: rgba(255, 248, 232, .78);
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.page-controls button {
  border: 1px solid rgba(201, 182, 142, .44);
  background: rgba(17, 16, 13, .28);
  color: rgba(255, 248, 232, .78);
  padding: 9px 12px;
  font: inherit;
  text-transform: inherit;
  cursor: pointer;
  transition: color .3s ease, border-color .3s ease;
}
.page-controls button:hover { color: var(--rice); border-color: var(--seal); }

.typed-note::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1em;
  margin-left: 4px;
  background: rgba(165, 51, 34, .85);
  vertical-align: -.15em;
  animation: blink .86s steps(1) infinite;
}
.typed-note.is-complete::after { opacity: 0; }

@keyframes blink { 50% { opacity: 0; } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes drift {
  from { transform: translate3d(0, 24px, 0); opacity: 0; }
  18% { opacity: .72; }
  to { transform: translate3d(10px, -90vh, 0); opacity: 0; }
}

@media (max-width: 680px) {
  body { overflow: hidden; }
  .paper { width: 90vw; min-height: 66vh; padding: 38px 28px; }
  .paper-receipt, .paper-card, .paper-letter, .paper-colophon { width: 90vw; }
  h1 { font-size: clamp(2.65rem, 16vw, 4.8rem); }
  h2 { font-size: clamp(2rem, 12vw, 3.4rem); }
  .toc-bookmark { top: 12px; gap: 12px; }
  .page-controls { bottom: 12px; gap: 10px; }
  .page-controls button { padding: 8px 9px; }
  .tab-button { right: 8px; top: auto; bottom: 18px; writing-mode: horizontal-tb; }
  .seal { width: 68px; height: 68px; right: 30px; bottom: 30px; }
}
