:root {
    --porcelain: #F7F3EA;
    --ink: #101214;
    --proof-blue: #2359D7;
    --lemma-green: #2F7D57;
    --contradiction-red: #D64242;
    --graphite: #8C8A82;
    --lavender: #C8D8FF;
    --display: "Cormorant Garamond", serif;
    --body: "Atkinson Hyperlegible", sans-serif;
    --mono: "IBM Plex Mono", monospace;
    --kr: "Noto Sans KR", sans-serif;
}

/* Typography compliance note: IBM Plex Mono restricted to symbolic accents rather than an overused mono-heavy tech identity. IBM Plex Mono only for symbolic expressions. Interaction should feel like solving rather than shopping: hovering a lemma can align its supporting assumptions. */

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at 20% 8%, rgba(200, 216, 255, 0.42), transparent 28%),
        radial-gradient(circle at 80% 55%, rgba(35, 89, 215, 0.08), transparent 26%),
        linear-gradient(180deg, #F7F3EA 0%, #F4F0E6 42%, #ECE9E2 72%, #101214 100%);
    font-family: var(--body);
    overflow-x: hidden;
}

.paper-grain {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 5;
    opacity: 0.35;
    background-image:
        linear-gradient(rgba(16, 18, 20, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(16, 18, 20, 0.025) 1px, transparent 1px),
        radial-gradient(circle, rgba(140, 138, 130, 0.18) 1px, transparent 1.5px);
    background-size: 100% 29px, 31px 100%, 18px 18px;
    mix-blend-mode: multiply;
}

.reasoning-thread {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 500vh;
    z-index: 2;
    pointer-events: none;
}

.reasoning-thread path {
    fill: none;
    stroke: var(--contradiction-red);
    stroke-width: 3.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    marker-end: url(#arrowhead);
    filter: drop-shadow(0 2px 0 rgba(214, 66, 66, 0.16));
}

.reasoning-thread marker path { fill: var(--contradiction-red); }

.proof-manuscript { position: relative; z-index: 3; }

.chapter {
    min-height: 100vh;
    position: relative;
    display: grid;
    grid-template-columns: minmax(92px, 13vw) 1fr minmax(92px, 14vw);
    align-items: stretch;
    padding: clamp(20px, 3vw, 44px);
    overflow: hidden;
    isolation: isolate;
}

.chapter::before {
    content: attr(data-phase);
    position: absolute;
    right: 4vw;
    top: 3vh;
    font-family: var(--mono);
    color: rgba(140, 138, 130, 0.42);
    letter-spacing: 0.16em;
    font-size: 0.72rem;
}

.chapter::after {
    content: "";
    position: absolute;
    inset: 8vh 9vw;
    border: 1px solid rgba(140, 138, 130, 0.22);
    transform: skewY(-1.5deg);
    z-index: -1;
}

.dawn { background: linear-gradient(115deg, rgba(247, 243, 234, 0.94), rgba(200, 216, 255, 0.28)); }
.morning { background: linear-gradient(160deg, rgba(247, 243, 234, 0.72), rgba(47, 125, 87, 0.09)); }
.noon { background: radial-gradient(circle at 72% 22%, rgba(35, 89, 215, 0.16), transparent 24%), rgba(247, 243, 234, 0.74); }
.dusk { background: linear-gradient(150deg, rgba(247, 243, 234, 0.82), rgba(214, 66, 66, 0.13), rgba(16, 18, 20, 0.05)); }
.midnight { background: radial-gradient(circle at 54% 48%, rgba(200, 216, 255, 0.18), transparent 30%), #101214; color: var(--porcelain); }

.margin {
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    color: var(--graphite);
    font-family: var(--mono);
    font-size: clamp(0.68rem, 1vw, 0.84rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding-top: 18vh;
}

.margin.right { align-items: flex-end; text-align: right; padding-top: 34vh; }
.midnight .margin { color: rgba(247, 243, 234, 0.58); }
.kr { font-family: var(--kr); letter-spacing: 0.02em; text-transform: none; }

.stamp {
    display: inline-block;
    width: max-content;
    padding: 0.38rem 0.62rem;
    border: 1px solid currentColor;
    transform: rotate(-6deg);
    color: var(--proof-blue);
    background: rgba(247, 243, 234, 0.62);
}
.stamp.thus { color: var(--lemma-green); transform: rotate(4deg); }
.stamp.else { color: var(--contradiction-red); transform: rotate(-9deg); }
.stamp.qed-stamp { color: var(--lavender); background: rgba(200, 216, 255, 0.08); transform: rotate(3deg); }

.chapter-field {
    position: relative;
    align-self: center;
    width: min(980px, 100%);
    min-height: 62vh;
    margin: 0 auto;
    padding: clamp(22px, 5vw, 72px);
}

.folio {
    margin: 0 0 0.8rem;
    font-family: var(--mono);
    color: var(--proof-blue);
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 0.75rem;
}

h1, h2 {
    font-family: var(--display);
    font-weight: 500;
    line-height: 0.92;
    margin: 0;
}

.wordmark { font-size: clamp(5.2rem, 15vw, 14rem); letter-spacing: -0.075em; }
h2 { font-size: clamp(3.8rem, 9vw, 9.6rem); letter-spacing: -0.05em; max-width: 850px; }

.theorem-copy {
    max-width: 610px;
    margin: 2rem 0 0;
    color: rgba(16, 18, 20, 0.76);
    font-size: clamp(1rem, 1.7vw, 1.42rem);
    line-height: 1.55;
}
.midnight .theorem-copy { color: rgba(247, 243, 234, 0.72); }

code, .proof-label, .time { font-family: var(--mono); }
code { color: var(--ink); font-size: clamp(0.9rem, 1.4vw, 1.15rem); }
.midnight code { color: var(--porcelain); }

.vellum {
    background: rgba(247, 243, 234, 0.74);
    border: 1px solid rgba(140, 138, 130, 0.38);
    box-shadow: 0 24px 70px rgba(16, 18, 20, 0.08), inset 0 0 35px rgba(200, 216, 255, 0.18);
    backdrop-filter: blur(5px);
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 10px, #000 calc(100% - 10px), transparent 100%);
    mask-image: linear-gradient(90deg, transparent 0, #000 10px, #000 calc(100% - 10px), transparent 100%);
}

.premise-slip {
    width: min(520px, 86vw);
    padding: 1.15rem 1.35rem;
    margin: 2rem 0 0 clamp(18px, 16vw, 210px);
    transform: rotate(-2.2deg);
}

.proof-label {
    display: block;
    margin-bottom: 0.55rem;
    color: var(--graphite);
    font-size: 0.68rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.typewrite::after {
    content: "";
    display: inline-block;
    width: 0.62em;
    height: 1.1em;
    margin-left: 0.12em;
    vertical-align: -0.16em;
    background: var(--ink);
    animation: blink 0.82s steps(1) infinite;
}

.paper-moon {
    position: absolute;
    width: 72px;
    height: 72px;
    border-radius: 50%;
    right: 10%;
    top: 18%;
    background: var(--lavender);
    box-shadow: inset -18px 2px 0 rgba(247, 243, 234, 0.72), 0 0 60px rgba(200, 216, 255, 0.72);
}

.bracket-notes span { display: block; position: relative; padding-right: 1.4rem; }
.bracket-notes span::after { content: ")"; position: absolute; right: 0; color: var(--proof-blue); font-size: 2rem; line-height: 0.5; }

.split-field, .inference-grid { display: grid; grid-template-columns: 1fr minmax(280px, 0.72fr); gap: clamp(24px, 5vw, 74px); align-items: center; }
.lemma-stack { position: relative; min-height: 320px; }

.lemma {
    position: absolute;
    width: min(390px, 72vw);
    padding: 1rem 1.2rem;
    text-align: left;
    color: var(--ink);
    font: inherit;
    cursor: pointer;
    transition: transform 500ms cubic-bezier(.2,.8,.2,1), border-color 500ms, box-shadow 500ms;
}
.lemma:nth-child(1) { top: 0; left: 4%; transform: rotate(-5deg); }
.lemma:nth-child(2) { top: 105px; left: 16%; transform: rotate(3deg); }
.lemma:nth-child(3) { top: 210px; left: 1%; transform: rotate(-1deg); }
.lemma.active, .lemma:hover { transform: translateX(-28px) rotate(0deg); border-color: var(--lemma-green); box-shadow: 0 18px 50px rgba(47, 125, 87, 0.18); }

.proof-tree {
    position: absolute;
    left: 7%;
    bottom: 4%;
    width: min(360px, 42vw);
    opacity: 0.62;
}
.proof-tree path, .proof-tree circle { fill: none; stroke: var(--lemma-green); stroke-width: 2; }
.proof-tree circle { fill: rgba(247, 243, 234, 0.9); }

.quantifier-beads { display: flex; flex-direction: column; gap: 0.56rem; align-items: center; }
.quantifier-beads i { width: 13px; height: 13px; border-radius: 50%; border: 1px solid var(--lemma-green); background: rgba(47, 125, 87, 0.12); }

.sunbeam-symbols {
    position: absolute;
    top: 14%;
    right: 18%;
    font-family: var(--mono);
    color: rgba(35, 89, 215, 0.18);
    font-size: clamp(3rem, 8vw, 8rem);
    letter-spacing: -0.2em;
    transform: rotate(-16deg);
}

.truth-fragment { padding: 1.3rem; transform: rotate(2.5deg); }
.truth-table {
    display: grid;
    grid-template-columns: repeat(3, minmax(54px, 1fr));
    border-top: 1px solid rgba(140, 138, 130, 0.45);
    border-left: 1px solid rgba(140, 138, 130, 0.45);
    font-family: var(--mono);
}
.truth-table span { padding: 0.74rem; border-right: 1px solid rgba(140, 138, 130, 0.45); border-bottom: 1px solid rgba(140, 138, 130, 0.45); }
.truth-table span:nth-child(-n+3) { color: var(--proof-blue); background: rgba(200, 216, 255, 0.18); }
.truth-table.compact { grid-template-columns: repeat(3, minmax(46px, 1fr)); }
.green { color: var(--lemma-green); }
.red { color: var(--contradiction-red); }

.foldout {
    position: absolute;
    left: 9%;
    bottom: 12%;
    padding: 0.9rem 1.1rem;
    border-left: 4px solid var(--proof-blue);
    background: rgba(200, 216, 255, 0.24);
    transform-origin: left center;
    transform: perspective(900px) rotateY(-18deg);
    transition: transform 700ms cubic-bezier(.2,.8,.2,1);
}
.chapter.is-visible .foldout { transform: perspective(900px) rotateY(0deg); }
.foldout span { display: block; color: var(--proof-blue); font-family: var(--mono); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.12em; margin-bottom: 0.4rem; }

.contradiction-stage { text-align: center; }
.contradiction-stage .theorem-copy { margin-left: auto; margin-right: auto; }
.contradiction-seal {
    width: clamp(120px, 18vw, 210px);
    height: clamp(120px, 18vw, 210px);
    margin: 2.2rem auto;
    border-radius: 50%;
    border: 1px solid var(--contradiction-red);
    background: radial-gradient(circle, rgba(214, 66, 66, 0.2), rgba(214, 66, 66, 0.04) 62%, transparent 63%);
    color: var(--contradiction-red);
    font-family: var(--display);
    font-size: clamp(5rem, 12vw, 11rem);
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 0 0 rgba(214, 66, 66, 0.0);
    transition: transform 400ms, box-shadow 400ms, background 400ms;
}
.contradiction-seal:hover, .contradiction-seal.flare { transform: scale(1.06) rotate(7deg); box-shadow: 0 0 80px rgba(214, 66, 66, 0.35); background: radial-gradient(circle, rgba(214, 66, 66, 0.34), rgba(214, 66, 66, 0.08) 62%, transparent 63%); }

.invertible-table { width: min(430px, 88vw); padding: 1.1rem; margin: 0 auto; transition: filter 450ms, transform 450ms; }
.invertible-table.inverted { filter: invert(1) hue-rotate(160deg); transform: rotate(2deg) scale(1.03); }
.venn-eclipse { position: absolute; right: 9%; top: 22%; width: 190px; height: 120px; opacity: 0.28; }
.venn-eclipse i { position: absolute; width: 116px; height: 116px; border-radius: 50%; border: 2px solid var(--contradiction-red); }
.venn-eclipse i:nth-child(2) { left: 70px; border-color: var(--ink); }

.final-field { text-align: center; }
.final-field .theorem-copy { margin-left: auto; margin-right: auto; }
.theorem-diagram {
    position: relative;
    width: min(620px, 82vw);
    height: min(620px, 82vw);
    margin: 5vh auto 0;
    border-radius: 50%;
    border: 1px solid rgba(200, 216, 255, 0.46);
    background: radial-gradient(circle, rgba(200, 216, 255, 0.18), rgba(200, 216, 255, 0.04) 44%, transparent 45%);
    box-shadow: inset 0 0 80px rgba(200, 216, 255, 0.12), 0 0 90px rgba(200, 216, 255, 0.12);
}
.theorem-diagram::before, .theorem-diagram::after { content: ""; position: absolute; inset: 18%; border: 1px solid rgba(200, 216, 255, 0.28); transform: rotate(45deg); }
.theorem-diagram::after { inset: 31%; transform: rotate(-18deg); border-color: rgba(47, 125, 87, 0.45); }
.midnight-seal {
    position: absolute;
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    font-family: var(--display);
    font-size: clamp(2rem, 5vw, 4.6rem);
    color: var(--lavender);
    white-space: nowrap;
}
.orbit {
    position: absolute;
    font-family: var(--mono);
    color: var(--porcelain);
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(200, 216, 255, 0.42);
    border-radius: 50%;
    background: rgba(16, 18, 20, 0.8);
    transition: transform 900ms cubic-bezier(.2,.8,.2,1), color 900ms;
}
.symbol-one { left: 15%; top: 22%; }
.symbol-two { right: 12%; top: 34%; }
.symbol-three { left: 27%; bottom: 17%; }
.symbol-four { right: 26%; bottom: 16%; }
.chapter.is-visible .orbit { color: var(--lavender); transform: translate(0, 0) scale(1.12); }

.chapter .folio, .chapter h1, .chapter h2, .chapter .theorem-copy, .chapter .vellum, .chapter .proof-tree, .chapter .contradiction-seal, .chapter .theorem-diagram {
    opacity: 0;
    transform: translateY(28px);
    transition: opacity 900ms ease, transform 900ms cubic-bezier(.2,.8,.2,1);
}
.chapter.is-visible .folio, .chapter.is-visible h1, .chapter.is-visible h2, .chapter.is-visible .theorem-copy, .chapter.is-visible .vellum, .chapter.is-visible .proof-tree, .chapter.is-visible .contradiction-seal, .chapter.is-visible .theorem-diagram {
    opacity: 1;
    transform: translateY(0);
}
.chapter.is-visible .premise-slip { transform: rotate(-2.2deg); }
.chapter.is-visible .truth-fragment { transform: rotate(2.5deg); }

@keyframes blink { 50% { opacity: 0; } }

@media (max-width: 820px) {
    .chapter { grid-template-columns: 1fr; padding: 22px; }
    .margin { position: absolute; padding-top: 0; top: 24px; left: 22px; flex-direction: row; gap: 0.7rem; z-index: 4; }
    .margin.right { display: none; }
    .chapter-field { padding: 18vh 0 8vh; }
    .split-field, .inference-grid { grid-template-columns: 1fr; }
    .premise-slip { margin-left: 0; }
    .lemma-stack { min-height: 350px; }
    .proof-tree, .venn-eclipse { display: none; }
}
