:root {
    --vellum: #F6F0E3;
    --peach: #E8A487;
    --umber: #241C18;
    --teal: #1F6B66;
    --carmine: #B8323A;
    --milk: #DDE7DF;
    --plum: #36213A;
    --title: "Cormorant Garamond", serif;
    --copy: "DM Sans", sans-serif;
    --kr: "Noto Sans KR", sans-serif;
    --mono: "IBM Plex Mono", monospace;
}

* {
    box-sizing: border-box;
}

html {
    height: 100%;
    scroll-behavior: smooth;
}

body {
    min-height: 100%;
    margin: 0;
    color: var(--vellum);
    background:
        radial-gradient(circle at 72% 18%, rgba(232, 164, 135, 0.16), transparent 32rem),
        radial-gradient(circle at 18% 76%, rgba(31, 107, 102, 0.24), transparent 34rem),
        linear-gradient(120deg, #241C18 0%, #36213A 46%, #241C18 100%);
    font-family: var(--copy);
    overflow-x: hidden;
}

button {
    font: inherit;
}

.grain {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 40;
    opacity: 0.32;
    background-image:
        radial-gradient(circle at 10% 20%, rgba(246, 240, 227, 0.16) 0 1px, transparent 1px),
        radial-gradient(circle at 80% 30%, rgba(221, 231, 223, 0.12) 0 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.03), transparent 45%, rgba(0,0,0,0.03));
    background-size: 19px 23px, 31px 29px, 100% 100%;
    mix-blend-mode: soft-light;
}

.spine-rail {
    position: fixed;
    left: 22px;
    top: 24px;
    bottom: 24px;
    width: 118px;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 18px 10px;
    border-left: 1px solid rgba(246, 240, 227, 0.22);
    border-right: 1px solid rgba(232, 164, 135, 0.18);
    background: rgba(36, 28, 24, 0.48);
    box-shadow: inset 0 0 30px rgba(54, 33, 58, 0.66), 0 20px 70px rgba(0,0,0,0.32);
}

.rail-title {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    align-self: center;
    min-height: 160px;
    margin-bottom: 12px;
    font-family: var(--title);
    font-size: 1.2rem;
    letter-spacing: 0.11em;
    color: var(--peach);
}

.scene-tab {
    position: relative;
    min-height: 66px;
    padding: 10px 7px;
    border: 1px solid rgba(221, 231, 223, 0.2);
    border-radius: 0 12px 12px 0;
    color: rgba(246, 240, 227, 0.62);
    background: rgba(246, 240, 227, 0.05);
    text-align: left;
    cursor: pointer;
    transition: transform 500ms ease, background 500ms ease, color 500ms ease, border-color 500ms ease;
}

.scene-tab span {
    display: block;
    font-family: var(--title);
    font-weight: 700;
    font-size: 0.96rem;
    line-height: 0.95;
}

.scene-tab em {
    display: block;
    margin-top: 7px;
    font-family: var(--kr);
    font-style: normal;
    font-size: 0.72rem;
    color: var(--milk);
}

.scene-tab.active {
    transform: translateX(12px);
    color: var(--umber);
    background: var(--vellum);
    border-color: var(--peach);
    box-shadow: 0 16px 30px rgba(0,0,0,0.28), inset 4px 0 0 var(--carmine);
}

.scene-tab.active em {
    color: var(--teal);
}

.ritual {
    position: relative;
    z-index: 2;
}

.scene {
    min-height: 100vh;
    position: relative;
    display: grid;
    align-items: center;
    padding: 12vh 8vw 12vh 15vw;
}

.scene::before {
    content: "";
    position: absolute;
    inset: 8vh 5vw 8vh 10vw;
    border: 1px solid rgba(246, 240, 227, 0.08);
    border-radius: 38px;
    background: linear-gradient(135deg, rgba(221, 231, 223, 0.045), transparent 52%, rgba(232, 164, 135, 0.04));
    pointer-events: none;
}

.scene-copy {
    width: min(35rem, 42vw);
    position: relative;
    z-index: 3;
    padding: 30px 28px;
    border: 1px solid rgba(221, 231, 223, 0.16);
    border-radius: 30px 30px 30px 6px;
    background: rgba(36, 28, 24, 0.48);
    box-shadow: 0 22px 70px rgba(0,0,0,0.28), inset 0 1px 0 rgba(246,240,227,0.12);
    backdrop-filter: blur(12px);
    transform: translateY(38px);
    opacity: 0.24;
    transition: opacity 800ms ease, transform 800ms ease;
}

.scene.active .scene-copy {
    opacity: 1;
    transform: translateY(0);
}

.right-copy {
    justify-self: end;
    margin-right: 2vw;
}

.chapter {
    margin: 0 0 14px;
    color: var(--peach);
    font-family: var(--mono);
    font-size: 0.72rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.chapter span,
.watermark,
.inspection-pane span,
.witness-fold span,
.seal span {
    font-family: var(--kr);
}

h1,
h2 {
    margin: 0;
    max-width: 12em;
    color: var(--vellum);
    font-family: var(--title);
    font-weight: 600;
    letter-spacing: -0.035em;
    line-height: 0.9;
}

h1 {
    font-size: clamp(3.6rem, 7.2vw, 8.6rem);
}

h2 {
    font-size: clamp(3rem, 5vw, 6.4rem);
}

.scene-copy p:not(.chapter) {
    width: min(33rem, 100%);
    margin: 22px 0 0;
    color: rgba(246, 240, 227, 0.78);
    font-size: clamp(1rem, 1.25vw, 1.2rem);
    line-height: 1.72;
}

.ritual-action {
    margin-top: 28px;
    padding: 13px 18px 15px;
    border: 1px solid rgba(232, 164, 135, 0.62);
    border-radius: 999px;
    color: var(--vellum);
    background: linear-gradient(135deg, rgba(184, 50, 58, 0.42), rgba(31, 107, 102, 0.24));
    font-family: var(--title);
    font-size: 1.18rem;
    cursor: pointer;
    box-shadow: 0 14px 38px rgba(0,0,0,0.22);
    transition: transform 380ms ease, box-shadow 380ms ease, background 380ms ease;
}

.ritual-action:hover {
    transform: translateY(-3px);
    box-shadow: 0 22px 48px rgba(0,0,0,0.32);
    background: linear-gradient(135deg, rgba(184, 50, 58, 0.62), rgba(31, 107, 102, 0.34));
}

.pass-stage {
    position: fixed;
    inset: 0;
    z-index: 1;
    display: grid;
    place-items: center;
    pointer-events: none;
    perspective: 1400px;
}

.table-shadow {
    position: absolute;
    width: 54vw;
    height: 44vw;
    max-height: 650px;
    border-radius: 50%;
    transform: translate(13vw, 13vh) rotate(-10deg);
    background: radial-gradient(ellipse, rgba(0,0,0,0.42), transparent 68%);
    filter: blur(12px);
}

.living-pass {
    --rx: 0deg;
    --ry: 0deg;
    position: fixed;
    right: 8vw;
    top: 50%;
    width: min(58vw, 820px);
    height: min(62vh, 540px);
    transform: translateY(-50%) rotate(-5deg) rotateX(var(--rx)) rotateY(var(--ry));
    transform-style: preserve-3d;
    border-radius: 32px;
    color: var(--umber);
    background:
        radial-gradient(circle at 25% 18%, rgba(232, 164, 135, 0.34), transparent 15%),
        radial-gradient(circle at 76% 75%, rgba(31, 107, 102, 0.14), transparent 18%),
        linear-gradient(108deg, rgba(246, 240, 227, 0.98), rgba(221, 231, 223, 0.92));
    box-shadow: 0 52px 110px rgba(0,0,0,0.44), inset 0 0 0 1px rgba(36, 28, 24, 0.1), inset 0 -28px 80px rgba(36, 28, 24, 0.09);
    overflow: hidden;
    transition: right 800ms ease, width 800ms ease, height 800ms ease, transform 100ms linear;
}

.pass-half {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 50%;
    opacity: 0;
    background: linear-gradient(120deg, rgba(246,240,227,0.34), rgba(221,231,223,0.18));
    transition: transform 1200ms cubic-bezier(.2,.8,.2,1), opacity 400ms ease;
    z-index: 8;
}

.left-half { left: 0; transform-origin: left center; }
.right-half { right: 0; transform-origin: right center; }

.paper-fibers {
    position: absolute;
    inset: 0;
    opacity: 0.48;
    background-image:
        repeating-linear-gradient(7deg, rgba(36, 28, 24, 0.055) 0 1px, transparent 1px 11px),
        repeating-linear-gradient(93deg, rgba(31, 107, 102, 0.035) 0 1px, transparent 1px 17px),
        radial-gradient(circle at 60% 10%, rgba(255,255,255,0.56), transparent 28%);
}

.passport-gutter {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 74px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 26px 0;
    color: var(--vellum);
    background: linear-gradient(180deg, var(--umber), var(--plum));
    box-shadow: 9px 0 26px rgba(36, 28, 24, 0.2);
}

.passport-gutter span,
.passport-gutter i {
    writing-mode: vertical-rl;
    font-family: var(--title);
    letter-spacing: 0.12em;
}

.passport-gutter i {
    font-family: var(--mono);
    font-size: 0.7rem;
    font-style: normal;
    color: var(--peach);
}

.watermark {
    position: absolute;
    left: 18%;
    top: 22%;
    color: rgba(36, 28, 24, 0.07);
    font-size: clamp(4.5rem, 9vw, 9rem);
    font-weight: 700;
    transform: rotate(-11deg);
    transition: color 700ms ease, text-shadow 700ms ease;
}

.moving-light {
    position: absolute;
    inset: -40%;
    background: radial-gradient(circle at var(--mx, 58%) var(--my, 42%), rgba(255,255,255,0.62), rgba(232,164,135,0.18) 10%, transparent 28%);
    mix-blend-mode: soft-light;
    transition: opacity 400ms ease;
}

.inspection-pane {
    position: absolute;
    right: 12%;
    top: 14%;
    width: 210px;
    height: 154px;
    border: 1px solid rgba(31, 107, 102, 0.46);
    border-radius: 34px 34px 34px 6px;
    background: rgba(221, 231, 223, 0.58);
    box-shadow: inset 0 0 34px rgba(255,255,255,0.45), 0 24px 60px rgba(36,28,24,0.16);
    overflow: hidden;
}

.inspection-pane span {
    position: absolute;
    left: 15px;
    top: 12px;
    color: var(--teal);
    font-size: 0.74rem;
    letter-spacing: 0.14em;
}

.breath-cloud {
    position: absolute;
    inset: 12px;
    border-radius: 50%;
    opacity: 0;
    filter: blur(13px);
    background: radial-gradient(circle, rgba(246,240,227,0.88), rgba(221,231,223,0.48) 42%, transparent 70%);
    transform: scale(0.3) translateY(30px);
}

.guilloche,
.palm-ledger {
    position: absolute;
    inset: 0 0 0 74px;
    width: calc(100% - 74px);
    height: 100%;
    pointer-events: none;
}

.guilloche path {
    fill: none;
    stroke: rgba(31, 107, 102, 0.22);
    stroke-width: 1.2;
    stroke-dasharray: 2 8;
}

.palm-ledger path {
    fill: none;
    stroke: var(--teal);
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    opacity: 0.76;
}

.magnifier {
    position: absolute;
    left: 50%;
    top: 46%;
    width: 128px;
    height: 128px;
    border: 1px solid rgba(221, 231, 223, 0.72);
    border-radius: 50%;
    opacity: 0;
    background: rgba(221, 231, 223, 0.34);
    box-shadow: inset 0 0 24px rgba(246,240,227,0.58), 0 18px 42px rgba(36,28,24,0.18);
    transform: translate(-50%, -50%) scale(0.72);
    transition: opacity 700ms ease, transform 900ms ease;
}

.magnifier::after {
    content: "";
    position: absolute;
    right: -48px;
    bottom: 7px;
    width: 64px;
    height: 10px;
    border-radius: 20px;
    background: var(--umber);
    transform: rotate(37deg);
}

.magnifier span {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: rgba(36,28,24,0.38);
    font-family: var(--kr);
}

.witness-fold {
    position: absolute;
    left: 74px;
    bottom: 0;
    width: 280px;
    height: 170px;
    padding: 28px 28px 20px;
    color: var(--umber);
    background: linear-gradient(135deg, rgba(221,231,223,0.94), rgba(246,240,227,0.7));
    border-top: 1px solid rgba(36,28,24,0.12);
    border-right: 1px solid rgba(36,28,24,0.08);
    transform-origin: left bottom;
    transform: rotateX(77deg) rotateZ(-1deg);
    opacity: 0.34;
    transition: transform 900ms cubic-bezier(.2,.9,.2,1), opacity 700ms ease, box-shadow 700ms ease;
}

.witness-fold b {
    display: block;
    font-family: var(--title);
    font-size: 2.1rem;
    font-weight: 700;
}

.witness-fold span {
    color: var(--teal);
    font-weight: 700;
}

.witness-fold i {
    position: relative;
    display: inline-block;
    width: 8px;
    height: 8px;
    margin: 32px 11px 0 0;
    border-radius: 50%;
    background: var(--carmine);
    box-shadow: 0 0 0 0 rgba(184,50,58,0.0);
}

.seal {
    position: absolute;
    right: 16%;
    bottom: 14%;
    width: 138px;
    height: 138px;
    display: grid;
    place-items: center;
    border: 7px double var(--carmine);
    border-radius: 50%;
    color: var(--carmine);
    opacity: 0;
    transform: translateY(-90px) scale(1.8) rotate(-16deg);
    filter: blur(2px);
    background: radial-gradient(circle, rgba(184,50,58,0.08), transparent 66%);
    box-shadow: 0 0 0 0 rgba(184,50,58,0.0);
    transition: opacity 250ms ease, transform 650ms cubic-bezier(.15,1.4,.3,1), filter 300ms ease, box-shadow 500ms ease;
}

.seal span {
    margin-top: -12px;
    font-size: 2.2rem;
    font-weight: 700;
}

.seal small {
    position: absolute;
    bottom: 28px;
    font-family: var(--mono);
    font-size: 0.67rem;
    letter-spacing: 0.2em;
}

.perforation {
    position: absolute;
    right: 18px;
    bottom: 18px;
    color: rgba(36, 28, 24, 0.42);
    font-family: var(--mono);
    font-size: 0.62rem;
    letter-spacing: 0.12em;
}

.perforation::before {
    content: "tiny doses · pass codes · perforation labels";
    position: absolute;
    right: 0;
    bottom: 13px;
    color: rgba(36, 28, 24, 0.22);
    white-space: nowrap;
}

.gate-light {
    position: absolute;
    inset: 0;
    opacity: 0;
    background: linear-gradient(90deg, transparent 46%, rgba(246, 240, 227, 0.86) 50%, transparent 54%);
    transition: opacity 800ms ease;
}

.instruction-card {
    position: fixed;
    right: 32px;
    bottom: 26px;
    z-index: 18;
    width: 270px;
    padding: 17px 18px;
    border: 1px solid rgba(232, 164, 135, 0.28);
    border-radius: 18px;
    color: rgba(246, 240, 227, 0.76);
    background: rgba(36, 28, 24, 0.58);
    backdrop-filter: blur(10px);
}

.instruction-card p {
    margin: 8px 0 0;
    font-size: 0.86rem;
    line-height: 1.45;
}

.mono {
    color: var(--peach);
    font-family: var(--mono);
    font-size: 0.66rem;
    letter-spacing: 0.16em;
}

body.presence .watermark,
body.scene-1 .watermark,
body.scene-2 .watermark,
body.scene-3 .watermark,
body.scene-4 .watermark,
body.scene-5 .watermark {
    color: rgba(36, 28, 24, 0.16);
    text-shadow: 0 0 22px rgba(232, 164, 135, 0.34);
}

body.scene-1 .breath-cloud,
body.breathing .breath-cloud {
    animation: breathBloom 4.8s ease-in-out infinite;
}

body.scene-2 .palm-ledger path,
body.ledger .palm-ledger path {
    animation: drawLine 1900ms ease forwards;
}

body.scene-2 .palm-ledger path:nth-child(2) { animation-delay: 120ms; }
body.scene-2 .palm-ledger path:nth-child(3) { animation-delay: 260ms; }
body.scene-2 .palm-ledger path:nth-child(4) { animation-delay: 390ms; }
body.scene-2 .palm-ledger path:nth-child(5) { animation-delay: 520ms; }
body.scene-2 .palm-ledger path:nth-child(6) { animation-delay: 680ms; }

body.scene-2 .magnifier,
body.ledger .magnifier {
    opacity: 1;
    transform: translate(-18%, -18%) scale(1);
}

body.scene-3 .witness-fold,
body.folded .witness-fold {
    opacity: 1;
    transform: rotateX(0deg) rotateZ(-1deg);
    box-shadow: 16px -18px 38px rgba(36,28,24,0.18);
}

body.scene-3 .witness-fold i,
body.folded .witness-fold i {
    animation: stitchPulse 1300ms ease-in-out infinite;
}

body.scene-4 .seal,
body.sealed .seal,
body.scene-5 .seal {
    opacity: 0.88;
    transform: translateY(0) scale(1) rotate(-16deg);
    filter: blur(0);
    box-shadow: 0 0 0 18px rgba(184,50,58,0.07), inset 0 0 18px rgba(184,50,58,0.08);
}

body.scene-4 .living-pass,
body.sealed .living-pass {
    box-shadow: 0 44px 100px rgba(0,0,0,0.46), inset 0 -12px 24px rgba(184,50,58,0.08), inset 0 0 0 1px rgba(36,28,24,0.1);
}

body.scene-5 .pass-half,
body.gate-open .pass-half {
    opacity: 1;
}

body.scene-5 .left-half,
body.gate-open .left-half {
    transform: rotateY(-24deg) translateX(-8px);
}

body.scene-5 .right-half,
body.gate-open .right-half {
    transform: rotateY(24deg) translateX(8px);
}

body.scene-5 .gate-light,
body.gate-open .gate-light {
    opacity: 1;
}

body.scene-0 .living-pass { right: 10vw; }
body.scene-1 .living-pass { right: 7vw; }
body.scene-2 .living-pass { right: 11vw; }
body.scene-3 .living-pass { right: 6vw; }
body.scene-4 .living-pass { right: 10vw; }
body.scene-5 .living-pass { right: 18vw; width: min(62vw, 880px); }

@keyframes breathBloom {
    0%, 100% { opacity: 0; transform: scale(0.32) translateY(32px); }
    20% { opacity: 0.72; transform: scale(1.12) translateY(4px); }
    56% { opacity: 0.28; transform: scale(1.45) translateY(-6px); }
}

@keyframes drawLine {
    to { stroke-dashoffset: 0; }
}

@keyframes stitchPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(184,50,58,0.0); transform: translateY(0); }
    50% { box-shadow: 0 0 0 7px rgba(184,50,58,0.14); transform: translateY(-2px); }
}

@media (max-width: 980px) {
    .spine-rail {
        left: 0;
        right: 0;
        top: 0;
        bottom: auto;
        width: auto;
        height: 88px;
        flex-direction: row;
        overflow-x: auto;
        padding: 10px 12px;
        border-left: 0;
    }

    .rail-title {
        min-height: auto;
        writing-mode: initial;
        margin: 0 12px 0 0;
        white-space: nowrap;
    }

    .scene-tab {
        min-width: 128px;
        min-height: 54px;
        border-radius: 14px;
    }

    .scene-tab.active {
        transform: translateY(8px);
    }

    .scene {
        padding: 22vh 5vw 46vh;
    }

    .scene::before {
        inset: 14vh 4vw 8vh;
    }

    .scene-copy,
    .right-copy {
        width: 100%;
        justify-self: start;
        margin-right: 0;
    }

    .pass-stage {
        align-items: end;
        padding-bottom: 10vh;
    }

    .living-pass {
        right: 5vw !important;
        top: auto;
        bottom: 5vh;
        width: 82vw !important;
        height: 38vh;
        transform: rotate(-3deg) rotateX(var(--rx)) rotateY(var(--ry));
    }

    .instruction-card {
        display: none;
    }
}
