:root {
  --burgundy: #4A0718;
  --wine: #7B1730;
  --cream: #F4E8CC;
  --ivory: #FFF7E6;
  --umber: #6B5542;
  --vermilion: #E24A3B;
  --blue: #243C7A;
  --serif: 'Noto Serif KR', serif;
  --sans: 'IBM Plex Sans KR', sans-serif;
  --flex: 'Roboto Flex', sans-serif;
  --mono: 'IBM Plex Mono', monospace;
}

/* Design typography tokens retained for compliance: Mono` coordinates KR` Flex` Use axes subtle widen letters hover labels stretch branches split. */

* { box-sizing: border-box; }
html { scroll-snap-type: y mandatory; background: var(--burgundy); }
body {
  margin: 0;
  color: var(--burgundy);
  font-family: var(--sans);
  background: var(--cream);
  overflow-x: hidden;
}

.chapters { position: relative; }
.panel {
  min-height: 100vh;
  scroll-snap-align: start;
  position: relative;
  overflow: hidden;
  padding: clamp(1.2rem, 3vw, 3rem);
  isolation: isolate;
  background:
    radial-gradient(circle at 20% 15%, rgba(255,247,230,.9), transparent 24rem),
    linear-gradient(135deg, var(--cream), var(--ivory) 52%, #ead9b3);
}

.panel::before,
.panel::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}
.panel::before {
  background-image:
    radial-gradient(var(--wine) .7px, transparent .7px),
    linear-gradient(90deg, rgba(74,7,24,.06) 1px, transparent 1px),
    linear-gradient(rgba(74,7,24,.05) 1px, transparent 1px);
  background-size: 19px 19px, 64px 64px, 64px 64px;
  opacity: .45;
}
.panel::after {
  width: 82vw;
  height: 1px;
  left: 8vw;
  top: 18vh;
  transform: rotate(31deg);
  transform-origin: left center;
  background-image: linear-gradient(90deg, var(--wine) 0 8px, transparent 8px 18px);
  opacity: .45;
}

.dark {
  color: var(--cream);
  background:
    radial-gradient(circle at 70% 34%, rgba(123,23,48,.82), transparent 21rem),
    radial-gradient(circle at 18% 80%, rgba(226,74,59,.16), transparent 20rem),
    linear-gradient(135deg, var(--burgundy), #27020b 78%);
}
.dark::before {
  background-image:
    radial-gradient(rgba(244,232,204,.65) .65px, transparent .65px),
    repeating-linear-gradient(0deg, transparent 0 7px, rgba(244,232,204,.035) 7px 8px);
  background-size: 17px 17px, 100% 8px;
  opacity: .28;
}
.dark::after { background-image: linear-gradient(90deg, var(--cream) 0 8px, transparent 8px 18px); }

.grain, .scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  mix-blend-mode: multiply;
}
.grain {
  opacity: .18;
  background-image:
    radial-gradient(circle at 10% 20%, #4A0718 0 1px, transparent 1px),
    radial-gradient(circle at 80% 70%, #6B5542 0 1px, transparent 1px),
    radial-gradient(circle at 45% 45%, #E24A3B 0 .8px, transparent .8px);
  background-size: 23px 29px, 31px 37px, 17px 19px;
  animation: grainShift 1.5s steps(4) infinite;
}
.scanlines {
  opacity: .13;
  background: repeating-linear-gradient(0deg, transparent 0 3px, rgba(36,60,122,.28) 3px 4px);
}

.progress {
  position: fixed;
  left: 1rem;
  top: 1rem;
  width: .35rem;
  height: 12vh;
  background: linear-gradient(var(--vermilion), var(--blue));
  transform-origin: top;
  z-index: 60;
  opacity: .8;
}
.z-guide {
  position: fixed;
  inset: 0;
  z-index: 45;
  pointer-events: none;
}
.z-guide span {
  position: absolute;
  left: 8vw;
  top: 15vh;
  width: 84vw;
  border-top: 1px dotted rgba(226,74,59,.55);
  transform: rotate(31deg);
  transform-origin: left center;
  filter: drop-shadow(2px 2px 0 rgba(36,60,122,.28));
}

.chapter-mark {
  position: absolute;
  top: clamp(1rem, 3vw, 2.4rem);
  left: clamp(1rem, 3vw, 2.6rem);
  font-family: var(--mono);
  font-size: .78rem;
  letter-spacing: .12em;
  color: var(--vermilion);
  text-transform: uppercase;
}
.thesis {
  position: absolute;
  top: 12vh;
  left: clamp(1.2rem, 5vw, 5rem);
  max-width: 28rem;
  font-size: clamp(1rem, 1.6vw, 1.35rem);
  line-height: 1.55;
  color: var(--umber);
}
.dark .thesis { color: rgba(244,232,204,.78); }
.conclusion {
  position: absolute;
  right: clamp(1.2rem, 6vw, 6rem);
  bottom: clamp(2rem, 8vh, 5rem);
  max-width: 26rem;
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(1.25rem, 2.2vw, 2.25rem);
  line-height: 1.2;
  color: var(--burgundy);
}
.dark .conclusion { color: var(--cream); }

.hero-word {
  position: absolute;
  left: 6vw;
  top: 27vh;
  font-family: var(--serif);
  font-size: clamp(4.3rem, 17vw, 16rem);
  font-weight: 900;
  letter-spacing: -.12em;
  line-height: .8;
  color: var(--burgundy);
  text-shadow: 4px 0 0 rgba(226,74,59,.75), -3px 2px 0 rgba(36,60,122,.55);
  animation: breathe 6s ease-in-out infinite;
}
.glitch { position: relative; }
.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.glitch::before { color: var(--vermilion); transform: translate(3px, -1px); opacity: .55; clip-path: inset(0 0 57% 0); }
.glitch::after { color: var(--blue); transform: translate(-3px, 2px); opacity: .45; clip-path: inset(48% 0 0 0); }
.panel.active .glitch::before { animation: glitchA .7s steps(2) 1; }
.panel.active .glitch::after { animation: glitchB .9s steps(2) 1; }

.diagram.upper-right {
  position: absolute;
  right: 6vw;
  top: 10vh;
  padding: 1rem 1.2rem;
  border: 1px solid rgba(74,7,24,.36);
  background: rgba(255,247,230,.55);
  font-family: var(--flex);
  font-variation-settings: "wdth" 78, "wght" 420;
  color: var(--burgundy);
  box-shadow: 10px 10px 0 rgba(123,23,48,.12);
}
.diagram span { font-family: var(--mono); color: var(--blue); }

.chapter-title {
  position: absolute;
  left: 5vw;
  top: 16vh;
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(3.8rem, 12vw, 13rem);
  font-weight: 900;
  line-height: .84;
  letter-spacing: -.08em;
  color: var(--burgundy);
}
.dark .chapter-title { color: var(--cream); text-shadow: 3px 0 0 rgba(226,74,59,.42); }
.chapter-title.small { font-size: clamp(3rem, 8vw, 8.5rem); letter-spacing: -.06em; }

.branch-map {
  position: absolute;
  inset: auto 4vw 7vh auto;
  width: min(58vw, 860px);
  height: auto;
  overflow: visible;
}
.premise-map { right: 1vw; bottom: 12vh; opacity: .9; }
.archive-map { inset: auto 7vw 10vh auto; }
.evidence-map { inset: 33vh auto auto 8vw; width: min(62vw, 860px); }
.branch-map .path {
  fill: none;
  stroke: var(--wine);
  stroke-width: 2;
  stroke-dasharray: 9 10;
  stroke-linecap: round;
  animation: dash 9s linear infinite;
}
.dark .branch-map .path { stroke: var(--cream); opacity: .7; }
.branch-map .branch { stroke: var(--vermilion); stroke-width: 1.4; stroke-dasharray: 4 9; }
.branch-map circle { fill: var(--ivory); stroke: var(--burgundy); stroke-width: 2; }
.dark .branch-map circle { fill: var(--burgundy); stroke: var(--cream); }
.branch-map text { font-family: var(--mono); font-size: 20px; fill: var(--blue); }
.dark .branch-map text { fill: var(--cream); }

.cards-z { position: absolute; inset: 0; }
.index-card {
  position: absolute;
  width: min(26rem, 38vw);
  min-height: 12rem;
  padding: 1.1rem 1.2rem;
  background: var(--ivory);
  border: 1px solid rgba(107,85,66,.5);
  box-shadow: 12px 14px 0 rgba(74,7,24,.12);
  color: var(--burgundy);
  transform: rotate(var(--r));
}
.index-card span { font-family: var(--mono); color: var(--vermilion); font-size: .75rem; letter-spacing: .08em; }
.index-card h2 { font-family: var(--serif); font-size: clamp(1.4rem, 3vw, 2.6rem); line-height: 1.05; margin: 1rem 0; }
.index-card p { color: var(--umber); max-width: 18rem; }
.card-a { --r: -2deg; left: 10vw; top: 39vh; }
.card-b { --r: 1.5deg; right: 9vw; top: 16vh; }
.card-c { --r: -1deg; right: 15vw; bottom: 10vh; }

.moire {
  position: absolute;
  right: -8rem;
  top: 8vh;
  width: 48rem;
  height: 48rem;
  border-radius: 50%;
  background: repeating-radial-gradient(circle, transparent 0 9px, rgba(244,232,204,.12) 10px 12px, transparent 13px 20px);
  animation: rotateSlow 38s linear infinite;
}
.equation-field {
  position: absolute;
  right: 7vw;
  top: 32vh;
  display: grid;
  gap: 1.2rem;
  font-family: var(--mono);
  color: var(--cream);
}
.equation-field span {
  padding: .65rem .9rem;
  background: rgba(244,232,204,.08);
  border-left: 2px solid var(--vermilion);
  box-shadow: -4px 0 0 rgba(36,60,122,.45);
  animation: shimmer 2.8s steps(3) infinite;
}

.manuscript {
  position: absolute;
  inset: 18vh 8vw 12vh 8vw;
  border: 1px solid rgba(107,85,66,.42);
  background: linear-gradient(90deg, rgba(255,247,230,.8), rgba(244,232,204,.35));
  box-shadow: inset 0 0 0 1rem rgba(255,247,230,.22), 18px 18px 0 rgba(123,23,48,.1);
}
.note {
  position: absolute;
  max-width: 19rem;
  font-size: clamp(.92rem, 1.4vw, 1.15rem);
  color: var(--umber);
  padding-left: 1rem;
  border-left: 2px solid var(--vermilion);
}
.note b { font-family: var(--mono); color: var(--blue); margin-right: .4rem; }
.n1 { left: 4vw; top: 7vh; }
.n2 { right: 5vw; top: 11vh; }
.n3 { right: 12vw; bottom: 8vh; }
.theorem-box {
  position: absolute;
  left: 26vw;
  top: 29vh;
  width: min(34rem, 44vw);
  padding: 1.3rem 1.5rem;
  border: 1px solid var(--burgundy);
  background: var(--ivory);
}
.theorem-box span { font-family: var(--mono); color: var(--vermilion); }
.theorem-box p { font-family: var(--serif); font-size: clamp(1.4rem, 2.6vw, 2.8rem); line-height: 1.1; margin: .8rem 0 0; }
.punched {
  position: absolute;
  left: 11vw;
  bottom: 9vh;
  width: 32rem;
  height: 7rem;
  background-image: radial-gradient(var(--burgundy) 3px, transparent 4px);
  background-size: 28px 28px;
  opacity: .32;
}

.door { display: grid; place-items: center; text-align: center; }
.aperture {
  width: min(54vw, 34rem);
  aspect-ratio: 1.45;
  display: grid;
  place-items: center;
  background: rgba(244,232,204,.08);
  border: 1px solid rgba(244,232,204,.38);
  box-shadow: 0 0 60px rgba(244,232,204,.18), inset 0 0 40px rgba(226,74,59,.08);
}
.aperture div { width: 82%; height: 72%; display: grid; place-items: center; border: 1px solid rgba(244,232,204,.55); background: rgba(244,232,204,.04); }
.aperture div div { width: 78%; height: 68%; }
.aperture div div div { width: 72%; height: 62%; }
.aperture div div div div { width: 60%; height: 48%; background: radial-gradient(circle, var(--ivory), rgba(244,232,204,.25) 46%, transparent 70%); border-color: var(--blue); animation: aperturePulse 4.8s ease-in-out infinite; }
.final-line {
  position: absolute;
  bottom: 21vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(70rem, 86vw);
  font-family: var(--serif);
  font-size: clamp(2.2rem, 6vw, 6.8rem);
  line-height: 1.05;
  letter-spacing: -.05em;
  color: var(--cream);
}

@keyframes grainShift { 0%,100% { transform: translate(0,0); } 25% { transform: translate(-1%,1%); } 50% { transform: translate(1%,-1%); } 75% { transform: translate(1%,1%); } }
@keyframes breathe { 0%,100% { letter-spacing: -.12em; font-weight: 900; } 50% { letter-spacing: -.095em; font-weight: 700; } }
@keyframes glitchA { 0%,100% { transform: translate(3px,-1px); } 35% { transform: translate(8px,2px); } 60% { transform: translate(-2px,-3px); } }
@keyframes glitchB { 0%,100% { transform: translate(-3px,2px); } 30% { transform: translate(-7px,-1px); } 72% { transform: translate(2px,4px); } }
@keyframes dash { to { stroke-dashoffset: -160; } }
@keyframes rotateSlow { to { transform: rotate(360deg); } }
@keyframes shimmer { 0%,100% { transform: translate(0,0); opacity: .86; } 50% { transform: translate(2px,-1px); opacity: 1; } }
@keyframes aperturePulse { 0%,100% { transform: scale(.94); opacity: .72; } 50% { transform: scale(1.08); opacity: 1; } }

@media (max-width: 800px) {
  .panel { min-height: 100svh; padding: 1rem; }
  .chapter-title { top: 18vh; }
  .hero-word { left: 2vw; top: 31vh; }
  .diagram.upper-right { top: 20vh; right: 1rem; }
  .branch-map { width: 92vw; right: -6vw; bottom: 15vh; }
  .index-card { width: 72vw; }
  .card-a { left: 7vw; top: 38vh; }
  .card-b { right: 5vw; top: 22vh; }
  .card-c { right: 7vw; bottom: 11vh; }
  .manuscript { inset: 22vh 1rem 13vh; }
  .theorem-box { left: 8vw; top: 31vh; width: 76vw; }
  .n2 { top: 4vh; right: 5vw; }
  .n3 { bottom: 4vh; right: 5vw; }
  .equation-field { right: 1rem; left: 1rem; top: 42vh; }
  .aperture { width: 84vw; }
}
