:root {
    /* Interaction imagery should feel magical but handmade: seals melt open */
    --plum: #5B3B76;
    --sky: #9CB7E5;
    --cream: #FFF0DA;
    --rose: #D64061;
    --gold: #C8A84E;
    --night: #24142F;
    --peach: #FFB38A;
    --ink: #2b1836;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    color: var(--cream);
    background: var(--night);
    font-family: "Nunito Sans", Inter, sans-serif;
    overflow-x: hidden;
}

body.opened .envelope-flap { transform: rotateX(178deg); }
body.opened .loose-thread { width: 42vw; opacity: 1; }
body.opened .seal { transform: scale(.92); box-shadow: 0 0 42px rgba(214,64,97,.65); }

.starscape {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(circle at 12% 14%, rgba(255,240,218,.72) 0 1px, transparent 2px),
        radial-gradient(circle at 74% 18%, rgba(156,183,229,.6) 0 1px, transparent 2px),
        radial-gradient(circle at 42% 72%, rgba(255,179,138,.5) 0 1px, transparent 2px),
        radial-gradient(circle at 90% 56%, rgba(255,240,218,.6) 0 1px, transparent 2px),
        linear-gradient(145deg, #24142F 0%, #34204a 48%, #5B3B76 100%);
}

.thread-map {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 6;
    pointer-events: none;
    opacity: .9;
}

#threadPath {
    fill: none;
    stroke: #D64061;
    stroke-width: .42;
    stroke-linecap: round;
    stroke-dasharray: 900;
    stroke-dashoffset: 900;
    filter: drop-shadow(0 0 7px rgba(214,64,97,.72));
}

main, .tableau { position: relative; z-index: 2; }

.tableau {
    min-height: 100vh;
    overflow: hidden;
    display: grid;
    align-items: center;
    padding: clamp(36px, 6vw, 86px);
    border-top: 1px solid rgba(255,240,218,.12);
}

.intro-scene {
    place-items: center;
    background:
        radial-gradient(circle at 50% 22%, rgba(156,183,229,.16), transparent 28%),
        linear-gradient(135deg, rgba(36,20,47,.98), rgba(36,20,47,.82));
}

.curtain {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 16vw;
    color: rgba(255,240,218,.08);
    font-family: "Cormorant Garamond", serif;
    font-size: clamp(42px, 8vw, 130px);
    font-style: italic;
    line-height: .72;
    writing-mode: vertical-rl;
    background: linear-gradient(90deg, rgba(91,59,118,.75), rgba(36,20,47,0));
}
.curtain-left { left: 0; transform: skewX(-7deg); }
.curtain-right { right: 0; transform: skewX(7deg) rotate(180deg); }

.moon-stamp {
    position: absolute;
    right: 16vw;
    top: 12vh;
    width: 104px;
    height: 104px;
    border: 2px solid #9CB7E5;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: #9CB7E5;
    font-size: 13px;
    letter-spacing: .22em;
    transform: rotate(15deg);
    opacity: .76;
}

.envelope {
    width: min(760px, 78vw);
    aspect-ratio: 1.62;
    position: relative;
    transform: rotate(-9deg);
    perspective: 1200px;
}

.envelope-shadow {
    position: absolute;
    inset: 14% 2% -6%;
    background: rgba(0,0,0,.34);
    filter: blur(30px);
    border-radius: 30%;
}

.envelope-back, .envelope-face, .envelope-flap {
    position: absolute;
    inset: 0;
    background: #FFF0DA;
    border: 2px solid rgba(200,168,78,.7);
    box-shadow: inset 0 0 0 12px rgba(200,168,78,.09), 0 22px 70px rgba(0,0,0,.32);
}

.envelope-back { clip-path: polygon(0 0, 100% 0, 50% 58%); }
.envelope-face { display: grid; place-items: center; padding: 8%; color: var(--ink); }
.envelope-flap {
    clip-path: polygon(0 0, 100% 0, 50% 58%);
    transform-origin: 50% 0;
    transition: transform 1100ms cubic-bezier(.2,.8,.2,1);
    z-index: 5;
}

.envelope h1 {
    margin: 0;
    font-family: "Cormorant Garamond", serif;
    font-size: clamp(58px, 11vw, 142px);
    font-style: italic;
    color: #5B3B76;
    letter-spacing: -.04em;
}

.address { margin: 0; color: #5B3B76; font-size: clamp(15px, 2vw, 22px); }
.hand-note, .final-note { font-family: "Homemade Apple", cursive; color: #D64061; transform: rotate(-3deg); }

.seal {
    position: absolute;
    right: 13%;
    bottom: 18%;
    width: 88px;
    height: 88px;
    border: 0;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #FFB38A, #D64061 48%, #8d2345 100%);
    color: #FFF0DA;
    font-family: "Cormorant Garamond", serif;
    font-size: 22px;
    font-style: italic;
    cursor: pointer;
    animation: sealPulse 2.6s ease 1 .5s;
    z-index: 8;
}

.loose-thread {
    position: absolute;
    right: 17%;
    bottom: 28%;
    height: 4px;
    width: 0;
    background: #D64061;
    border-radius: 999px;
    transform: rotate(22deg);
    transform-origin: left;
    opacity: 0;
    transition: width 1.3s ease, opacity .4s ease;
}

.scroll-note {
    position: absolute;
    bottom: 34px;
    font-family: "Homemade Apple", cursive;
    color: #FFB38A;
}

.chapter { max-width: 560px; position: relative; z-index: 4; }
.chapter-left { margin-left: 5vw; }
.chapter-right { margin-left: auto; margin-right: 5vw; }
.chapter-kicker {
    display: inline-block;
    color: #C8A84E;
    text-transform: uppercase;
    letter-spacing: .34em;
    font-size: 13px;
    font-weight: 800;
}
.chapter h2 {
    margin: 12px 0 18px;
    font-family: "Cormorant Garamond", serif;
    font-size: clamp(48px, 8vw, 104px);
    font-style: italic;
    line-height: .88;
    color: #FFF0DA;
}
.chapter p, .paper-island p { font-size: clamp(18px, 2vw, 24px); line-height: 1.55; color: rgba(255,240,218,.86); }

.quest-button, .final-link, .drift-controls button {
    border: 1px solid rgba(255,240,218,.42);
    background: rgba(255,240,218,.12);
    color: #FFF0DA;
    border-radius: 999px;
    padding: 13px 22px;
    font-family: "Nunito Sans", sans-serif;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    transition: transform .25s ease, background .25s ease;
}
.quest-button:hover, .final-link:hover, .drift-controls button:hover { transform: translateY(-3px); background: rgba(214,64,97,.35); }

.atlas-scene { background: linear-gradient(145deg, #5B3B76, #24142F 74%); }
.paper-sun { position: absolute; width: 34vw; height: 34vw; right: -9vw; top: -8vw; background: #FFF0DA; opacity: .12; border-radius: 50%; }
.diagonal-panel { position: absolute; inset: 16vh -8vw auto auto; width: 70vw; height: 42vh; background: rgba(255,240,218,.12); transform: rotate(-16deg); border: 1px solid rgba(200,168,78,.35); }
.envelope-mountains { position: absolute; right: 5vw; bottom: 4vh; width: 54vw; height: 48vh; }
.mountain { position: absolute; bottom: 0; background: #FFF0DA; border: 2px solid rgba(200,168,78,.65); clip-path: polygon(50% 0, 100% 100%, 0 100%); opacity: .93; }
.m1 { width: 42%; height: 72%; left: 0; transform: rotate(-8deg); }
.m2 { width: 50%; height: 92%; left: 24%; background: #ffe7c2; }
.m3 { width: 35%; height: 62%; right: 0; transform: rotate(9deg); }
.label { position: absolute; padding: 7px 14px; background: #9CB7E5; color: #24142F; font-family: "Homemade Apple", cursive; transform: rotate(-7deg); }
.label-one { left: 16%; top: 34%; } .label-two { right: 12%; top: 22%; }

.secret-note {
    position: absolute;
    left: 50%;
    bottom: 12%;
    max-width: 330px;
    padding: 22px;
    background: #FFF0DA;
    color: #5B3B76;
    font-family: "Homemade Apple", cursive;
    transform: rotate(4deg) translateY(20px);
    opacity: 0;
    transition: opacity .45s ease, transform .45s ease;
    z-index: 7;
}
.secret-note.show { opacity: 1; transform: rotate(-2deg) translateY(0); }

.fog-scene { background: linear-gradient(180deg, #24142F 0%, #5B3B76 56%, #9CB7E5 160%); }
.fog { position: absolute; height: 28vh; width: 80vw; border-radius: 50%; background: rgba(156,183,229,.18); filter: blur(22px); animation: fogDrift 14s ease-in-out infinite alternate; }
.fog-a { top: 18vh; left: -14vw; } .fog-b { top: 42vh; right: -22vw; animation-duration: 18s; } .fog-c { bottom: 8vh; left: 10vw; animation-duration: 22s; }
.moth-field { position: absolute; inset: 0; pointer-events: none; }
.moth { position: absolute; width: 18px; height: 28px; background: #FFB38A; border-radius: 60% 60% 45% 45%; box-shadow: 0 0 22px #FFB38A; opacity: .42; animation: mothFloat 8s ease-in-out infinite; }
.moth::before, .moth::after { content: ""; position: absolute; top: 4px; width: 18px; height: 14px; background: rgba(255,240,218,.58); border-radius: 80% 20%; }
.moth::before { right: 12px; transform: rotate(-28deg); } .moth::after { left: 12px; transform: rotate(28deg) scaleX(-1); }
.moth:nth-child(1){ left:18%; top:28%; } .moth:nth-child(2){ left:42%; top:68%; animation-delay: -2s; } .moth:nth-child(3){ left:72%; top:24%; animation-delay: -4s; } .moth:nth-child(4){ left:62%; top:52%; animation-delay: -1s; } .moth:nth-child(5){ left:28%; top:78%; animation-delay: -5s; }
.moth-field.lit .moth { opacity: 1; }

.horizontal-scene { min-height: 100vh; background: #FFF0DA; color: #24142F; display: block; padding-top: 12vh; }
.sideways-title { font-family: "Cormorant Garamond", serif; font-size: clamp(58px, 10vw, 132px); font-style: italic; color: #5B3B76; white-space: nowrap; }
.island-track { display: flex; gap: 7vw; width: max-content; padding: 7vh 10vw 4vh; transform: translateX(0); transition: transform .75s cubic-bezier(.2,.8,.2,1); }
.paper-island { width: min(70vw, 560px); min-height: 380px; padding: 42px; background: linear-gradient(135deg, #fff8ea, #ffdcb7); border: 2px solid #C8A84E; color: #24142F; transform: rotate(-3deg); box-shadow: 0 26px 45px rgba(36,20,47,.18); }
.paper-island:nth-child(2) { transform: rotate(4deg); background: #9CB7E5; }
.paper-island:nth-child(3) { transform: rotate(-1deg); }
.paper-island h3 { font-family: "Cormorant Garamond", serif; font-size: clamp(38px, 5vw, 70px); color: #5B3B76; margin: 14px 0; line-height: .92; }
.paper-island p { color: #24142F; }
.stamp { display: grid; place-items: center; width: 60px; height: 60px; border: 2px dashed #D64061; border-radius: 50%; color: #D64061; font-family: "Homemade Apple", cursive; }
.drift-controls { position: absolute; right: 8vw; bottom: 8vh; display: flex; gap: 14px; }
.drift-controls button { color: #5B3B76; border-color: #5B3B76; background: rgba(91,59,118,.08); }

.constellation-scene { background: radial-gradient(circle at 72% 28%, rgba(156,183,229,.22), transparent 35%), linear-gradient(155deg, #24142F, #5B3B76); }
.constellation { position: absolute; right: 6vw; top: 18vh; width: min(58vw, 720px); height: 56vh; overflow: visible; }
.constellation path { fill: none; stroke: #C8A84E; stroke-width: 2; stroke-dasharray: 8 12; }
.constellation circle { fill: #FFF0DA; filter: drop-shadow(0 0 10px #9CB7E5); }
.compass-heart { position: absolute; right: 24vw; bottom: 16vh; width: 120px; height: 120px; transform: rotate(45deg); background: #D64061; box-shadow: 0 0 0 12px rgba(255,240,218,.12), 0 0 38px rgba(214,64,97,.62); transition: transform .8s ease; }
.compass-heart::before, .compass-heart::after { content: ""; position: absolute; width: 120px; height: 120px; border-radius: 50%; background: #D64061; }
.compass-heart::before { left: -60px; } .compass-heart::after { top: -60px; }
.compass-heart.turn { transform: rotate(405deg) scale(1.08); }

.vow-scene { place-items: center; text-align: center; background: linear-gradient(180deg, #5B3B76, #24142F); }
.stage-letters { position: absolute; inset: 6vh 0 auto; color: rgba(255,240,218,.07); font-family: "Cormorant Garamond", serif; font-size: 22vw; letter-spacing: .08em; }
.final-chapter { margin: 0 auto; }
.wax-moons { display: flex; gap: 24px; margin-top: 30px; }
.wax-moons span { width: 58px; height: 58px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #FFB38A, #D64061 62%); box-shadow: 0 0 24px rgba(214,64,97,.52); }
.final-note { position: absolute; bottom: 8vh; }

.floating-confession {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(.94);
    max-width: 420px;
    padding: 26px 30px;
    background: #FFF0DA;
    color: #5B3B76;
    font-family: "Homemade Apple", cursive;
    z-index: 20;
    opacity: 0;
    pointer-events: none;
    box-shadow: 0 30px 90px rgba(0,0,0,.35);
    transition: opacity .35s ease, transform .35s ease;
}
.floating-confession.show { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-2deg); }

@keyframes sealPulse { 0%,100% { transform: scale(1); } 45% { transform: scale(1.1); box-shadow: 0 0 46px rgba(214,64,97,.8); } }
@keyframes fogDrift { to { transform: translateX(18vw) translateY(-4vh); } }
@keyframes mothFloat { 0%,100% { transform: translateY(0) rotate(-8deg); } 50% { transform: translateY(-38px) rotate(12deg); } }

@media (max-width: 760px) {
    .tableau { padding: 34px 22px; }
    .envelope { width: 92vw; }
    .curtain { width: 10vw; }
    .envelope-mountains, .constellation { opacity: .46; width: 96vw; right: -14vw; }
    .chapter-left, .chapter-right { margin: 0; }
    .secret-note { left: 8vw; right: 8vw; bottom: 8vh; }
    .island-track { padding-left: 2vw; gap: 4vw; }
    .paper-island { width: 86vw; }
}
