/* ============================================
   MasqueradeProtocol.com
   Art-Deco Ceremonial Theater
   ============================================ */

/* --- Custom Properties --- */
:root {
    --ritual-black: #0a0a0a;
    --midnight-charcoal: #1a1a1e;
    --antique-gold: #c9a84c;
    --burnished-bronze: #8b7335;
    --oxblood: #4a0e0e;
    --parchment: #e8e0d0;
    --faded-ivory: #a89f8f;
    --venetian-red: #8b1a1a;
    --marble-dark-1: #0d0d0d;
    --marble-dark-2: #111114;
    --marble-dark-3: #0a0a0e;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    background: var(--ritual-black);
}

body {
    font-family: 'Libre Baskerville', Georgia, serif;
    font-weight: 400;
    color: var(--parchment);
    background: var(--ritual-black);
    line-height: 1.9;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- SVG Definitions (hidden) --- */
.svg-defs {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* --- Grain Overlay (global, fixed) --- */
.grain-overlay {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-size: 256px 256px;
    animation: grain-flicker 4s steps(2) infinite;
    mix-blend-mode: soft-light;
}

@keyframes grain-flicker {
    0%, 100% { opacity: 0.03; transform: translate(0, 0); }
    25% { opacity: 0.06; transform: translate(-2px, 1px); }
    50% { opacity: 0.07; transform: translate(1px, -1px); }
    75% { opacity: 0.04; transform: translate(-1px, 2px); }
}

/* --- Progress Indicator --- */
.progress-track {
    position: fixed;
    right: 2rem;
    top: 15%;
    height: 70%;
    width: 2px;
    background: rgba(201, 168, 76, 0.15);
    z-index: 1000;
}

.progress-fill {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 0%;
    background: var(--antique-gold);
    transition: height 0.3s ease-out;
}

/* --- Main Ceremony Container --- */
.ceremony {
    scroll-snap-type: y proximity;
    overflow-y: auto;
    height: 100vh;
}

/* --- Chamber (Section Base) --- */
.chamber {
    min-height: 100vh;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    scroll-snap-align: start;
    overflow: hidden;
}

/* --- Marble texture on chambers --- */
.chamber::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse 800px 800px at 20% 30%, var(--marble-dark-1) 0%, transparent 70%),
        radial-gradient(ellipse 400px 400px at 70% 60%, var(--marble-dark-2) 0%, transparent 60%),
        radial-gradient(ellipse 600px 600px at 50% 80%, var(--marble-dark-3) 0%, transparent 65%),
        radial-gradient(ellipse 300px 300px at 85% 15%, var(--marble-dark-2) 0%, transparent 50%);
    z-index: 0;
    pointer-events: none;
}

/* ============================================
   SECTION 1: THE OPENING
   ============================================ */
.opening {
    background: var(--ritual-black);
    flex-direction: column;
}

.opening-stage {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

/* Horizontal gold line */
.opening-line {
    position: absolute;
    top: 50%;
    left: 10%;
    width: 80%;
    height: 2px;
    transform: translateY(-50%);
    opacity: 0;
}

.opening-line .line-draw {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
}

.opening.entered .opening-line {
    opacity: 1;
}

.opening.entered .opening-line .line-draw {
    animation: draw-line 1.2s ease-out 1.5s forwards;
}

@keyframes draw-line {
    to { stroke-dashoffset: 0; }
}

/* Fan radiant expansion */
.opening-fan {
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    width: 60vw;
    max-width: 600px;
    height: 300px;
    opacity: 0;
    pointer-events: none;
}

.fan-ray {
    stroke: var(--antique-gold);
    stroke-width: 0.5;
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
}

.opening.entered .opening-fan {
    opacity: 1;
}

.opening.entered .fan-ray {
    animation: draw-ray 0.8s ease-out forwards;
}

.opening.entered .fan-ray:nth-child(1)  { animation-delay: 2.8s; }
.opening.entered .fan-ray:nth-child(2)  { animation-delay: 2.83s; }
.opening.entered .fan-ray:nth-child(3)  { animation-delay: 2.86s; }
.opening.entered .fan-ray:nth-child(4)  { animation-delay: 2.89s; }
.opening.entered .fan-ray:nth-child(5)  { animation-delay: 2.92s; }
.opening.entered .fan-ray:nth-child(6)  { animation-delay: 2.95s; }
.opening.entered .fan-ray:nth-child(7)  { animation-delay: 2.98s; }
.opening.entered .fan-ray:nth-child(8)  { animation-delay: 3.01s; }
.opening.entered .fan-ray:nth-child(9)  { animation-delay: 3.04s; }
.opening.entered .fan-ray:nth-child(10) { animation-delay: 3.07s; }
.opening.entered .fan-ray:nth-child(11) { animation-delay: 3.10s; }
.opening.entered .fan-ray:nth-child(12) { animation-delay: 3.13s; }
.opening.entered .fan-ray:nth-child(13) { animation-delay: 3.16s; }
.opening.entered .fan-ray:nth-child(14) { animation-delay: 3.19s; }
.opening.entered .fan-ray:nth-child(15) { animation-delay: 3.22s; }
.opening.entered .fan-ray:nth-child(16) { animation-delay: 3.25s; }
.opening.entered .fan-ray:nth-child(17) { animation-delay: 3.28s; }

@keyframes draw-ray {
    to { stroke-dashoffset: 0; }
}

/* Site Title */
.opening-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: clamp(2.5rem, 6vw, 5rem);
    letter-spacing: 0.15em;
    color: var(--antique-gold);
    text-align: center;
    position: relative;
    z-index: 2;
    line-height: 1.2;
    margin-top: 2rem;
}

.title-word {
    display: block;
    opacity: 0;
    transform: translateY(10px);
}

.opening.entered .title-word {
    animation: title-reveal 1s ease-out forwards;
}

.opening.entered .title-word:nth-child(1) {
    animation-delay: 3.5s;
}

.opening.entered .title-word:nth-child(2) {
    animation-delay: 3.8s;
}

@keyframes title-reveal {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Entry prompt */
.entry-prompt {
    position: absolute;
    bottom: 8vh;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    z-index: 2;
}

.prompt-text {
    font-family: 'Cormorant SC', serif;
    font-weight: 600;
    font-size: 0.85rem;
    letter-spacing: 0.25em;
    color: var(--faded-ivory);
    cursor: pointer;
    position: relative;
    padding-bottom: 4px;
}

.prompt-text::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 1px;
    background: var(--antique-gold);
    transition: width 0.3s ease-out;
}

.prompt-text:hover::after {
    width: 100%;
}

.opening.entered .entry-prompt {
    animation: prompt-fade 1s ease-out 4.4s forwards;
}

@keyframes prompt-fade {
    to { opacity: 1; }
}

/* Corner fans */
.corner-fan {
    position: absolute;
    width: 120px;
    height: 60px;
    opacity: 0;
    z-index: 1;
}

.corner-fan--tl {
    top: 2rem;
    left: 2rem;
    transform: rotate(90deg);
}

.corner-fan--tr {
    top: 2rem;
    right: 2rem;
    transform: rotate(180deg);
}

.corner-fan--bl {
    bottom: 2rem;
    left: 2rem;
    transform: rotate(0deg);
}

.corner-fan--br {
    bottom: 2rem;
    right: 2rem;
    transform: rotate(-90deg);
}

.corner-fan line,
.corner-fan use line {
    stroke: var(--burnished-bronze);
    stroke-width: 0.3;
}

.opening.entered .corner-fan {
    animation: corner-appear 1s ease-out 4s forwards;
}

@keyframes corner-appear {
    to { opacity: 0.4; }
}

/* ============================================
   SECTION 2: THE ANTECHAMBER
   ============================================ */
.antechamber {
    background: var(--ritual-black);
    padding: 8rem 0;
}

.antechamber-layout {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: 1fr 0.8fr;
    gap: 4rem;
    max-width: 1200px;
    width: 90%;
    margin: 0 auto;
    align-items: center;
}

.antechamber-text {
    padding-left: 2rem;
}

.section-marker {
    font-family: 'Cormorant SC', serif;
    font-weight: 600;
    font-size: 0.85rem;
    letter-spacing: 0.25em;
    color: var(--burnished-bronze);
    display: block;
    margin-bottom: 1.5rem;
}

.section-heading {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: clamp(2rem, 4vw, 3.5rem);
    letter-spacing: 0.15em;
    color: var(--antique-gold);
    margin-bottom: 2.5rem;
    line-height: 1.2;
}

.premise-text {
    font-size: clamp(1rem, 1.1vw, 1.15rem);
    color: var(--parchment);
    margin-bottom: 1.5rem;
    line-height: 1.9;
    max-width: 520px;
}

.antechamber-mask {
    display: flex;
    align-items: center;
    justify-content: center;
}

.geometric-mask {
    width: 100%;
    max-width: 280px;
    height: auto;
    opacity: 0;
    transition: opacity 1s ease-out;
}

.geometric-mask line,
.geometric-mask polygon,
.geometric-mask path,
.geometric-mask circle,
.geometric-mask ellipse,
.geometric-mask rect,
.geometric-mask polyline {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    transition: stroke-dashoffset 1.2s ease-out;
}

.mask-container.revealed .geometric-mask {
    opacity: 1;
}

.mask-container.revealed .geometric-mask line,
.mask-container.revealed .geometric-mask polygon,
.mask-container.revealed .geometric-mask path,
.mask-container.revealed .geometric-mask circle,
.mask-container.revealed .geometric-mask ellipse,
.mask-container.revealed .geometric-mask rect,
.mask-container.revealed .geometric-mask polyline {
    stroke-dashoffset: 0;
}

/* Section divider fan */
.section-divider {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    width: 160px;
    height: 80px;
    opacity: 0.3;
    z-index: 1;
}

.divider-fan {
    width: 100%;
    height: 100%;
}

/* ============================================
   PROTOCOL CHAMBERS (Sections 3-5)
   ============================================ */
.protocol-chamber {
    background: var(--ritual-black);
    padding: 6rem 0;
}

.protocol-split {
    position: relative;
    z-index: 1;
    display: grid;
    gap: 2rem;
    max-width: 1200px;
    width: 90%;
    margin: 0 auto;
    align-items: center;
    min-height: 70vh;
}

/* Progressive bisection: left, center, right */
.protocol-split--left {
    grid-template-columns: 1.3fr 0.7fr;
}

.protocol-split--center {
    grid-template-columns: 0.8fr 1.2fr;
}

.protocol-split--right {
    grid-template-columns: 1.3fr 0.7fr;
}

.protocol-content {
    padding: 2rem;
}

.protocol-number {
    font-family: 'Cormorant SC', serif;
    font-weight: 600;
    font-size: 0.85rem;
    letter-spacing: 0.25em;
    color: var(--antique-gold);
    display: block;
    margin-bottom: 1rem;
}

.protocol-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.8rem, 3.5vw, 2.8rem);
    letter-spacing: 0.08em;
    color: var(--antique-gold);
    margin-bottom: 2rem;
    line-height: 1.3;
}

.protocol-body p {
    font-size: clamp(1rem, 1.1vw, 1.15rem);
    color: var(--parchment);
    margin-bottom: 1.5rem;
    line-height: 1.9;
    max-width: 540px;
}

.protocol-visual {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* Fracture lines */
.fracture-lines {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    pointer-events: none;
}

.fracture-line {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    opacity: 0.5;
}

.mask-container.revealed .fracture-line {
    animation: draw-fracture 1.5s ease-out forwards;
}

.mask-container.revealed .fracture-line:nth-child(2) {
    animation-delay: 0.3s;
}

.mask-container.revealed .fracture-line:nth-child(3) {
    animation-delay: 0.6s;
}

@keyframes draw-fracture {
    to { stroke-dashoffset: 0; }
}

/* Bisection lines */
.bisection-line {
    position: absolute;
    top: 10%;
    height: 80%;
    width: 1px;
    background: var(--antique-gold);
    z-index: 2;
    opacity: 0;
    transform: scaleY(0);
    transform-origin: top;
    transition: opacity 1s ease-out, transform 1.2s ease-out;
}

.bisection-line--left {
    left: 38%;
}

.bisection-line--center {
    left: 50%;
}

.bisection-line--right {
    left: 62%;
}

.protocol-chamber.in-view .bisection-line {
    opacity: 0.4;
    transform: scaleY(1);
}

/* Chevron decorations at bottom of protocol chambers */
.chamber-chevron {
    position: absolute;
    bottom: 3rem;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 36px;
    opacity: 0;
    z-index: 1;
    transition: opacity 1.2s ease-out 0.5s;
}

.chamber-chevron svg {
    width: 100%;
    height: 100%;
}

.protocol-chamber.in-view .chamber-chevron {
    opacity: 0.25;
}

/* ============================================
   SECTION 6: THE UNMASKING
   ============================================ */
.unmasking {
    background: var(--ritual-black);
    flex-direction: column;
    position: relative;
    padding: 6rem 0;
}

.unmasking::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 50%, var(--oxblood) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 2s ease-out;
    z-index: 0;
    pointer-events: none;
}

.unmasking.in-view::after {
    opacity: 1;
}

.unmasking-convergence {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 4rem;
}

.convergence-point {
    position: absolute;
    width: 200px;
    height: 200px;
    opacity: 0;
    transition: opacity 1.5s ease-out;
}

.unmasking.in-view .convergence-point {
    opacity: 0.3;
}

.converge-line {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
}

.unmasking.in-view .converge-line {
    animation: draw-converge 1.2s ease-out forwards;
}

.unmasking.in-view .converge-line:nth-child(2) { animation-delay: 0.1s; }
.unmasking.in-view .converge-line:nth-child(3) { animation-delay: 0.2s; }
.unmasking.in-view .converge-line:nth-child(4) { animation-delay: 0.3s; }
.unmasking.in-view .converge-line:nth-child(5) { animation-delay: 0.4s; }
.unmasking.in-view .converge-line:nth-child(6) { animation-delay: 0.5s; }
.unmasking.in-view .converge-line:nth-child(7) { animation-delay: 0.6s; }
.unmasking.in-view .converge-line:nth-child(8) { animation-delay: 0.7s; }

@keyframes draw-converge {
    to { stroke-dashoffset: 0; }
}

.unmasking-mask {
    position: relative;
    z-index: 2;
}

.geometric-mask--volto {
    max-width: 200px;
}

.unmasking-text {
    position: relative;
    z-index: 1;
    text-align: center;
    max-width: 640px;
    padding: 0 2rem;
}

.unmasking-heading {
    margin-bottom: 3rem;
}

/* Hidden text reveal */
.hidden-text {
    color: var(--ritual-black);
    transition: color 0s;
    margin-bottom: 1.5rem;
    font-size: clamp(1rem, 1.1vw, 1.15rem);
    line-height: 1.9;
    text-align: center;
}

.hidden-text.text-revealed {
    color: var(--parchment);
    transition: color 2s ease-out;
}

/* Letter-by-letter reveal spans */
.hidden-text .reveal-letter {
    color: var(--ritual-black);
    transition: color 0.08s ease-out;
}

.hidden-text .reveal-letter.shown {
    color: var(--parchment);
}

/* Unmask trigger button */
.unmasking-action {
    margin-top: 3rem;
}

.unmask-trigger {
    position: relative;
    background: none;
    border: none;
    cursor: pointer;
    padding: 1rem 2.5rem;
    display: inline-block;
}

.trigger-text {
    font-family: 'Cormorant SC', serif;
    font-weight: 600;
    font-size: 0.85rem;
    letter-spacing: 0.25em;
    color: var(--antique-gold);
    position: relative;
    z-index: 1;
}

.trigger-border {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.border-trace {
    stroke-dasharray: 596;
    stroke-dashoffset: 596;
    transition: stroke-dashoffset 0.8s ease-out;
}

.unmask-trigger:hover .border-trace {
    stroke-dashoffset: 0;
}

.unmask-trigger:hover .trigger-text {
    color: var(--parchment);
    transition: color 0.4s ease-out;
}

/* Post-unmask state */
.unmask-trigger.unmasked {
    pointer-events: none;
}

.unmask-trigger.unmasked .trigger-text {
    color: var(--venetian-red);
    transition: color 1.5s ease-out;
}

.unmask-trigger.unmasked .border-trace {
    stroke: var(--venetian-red);
    stroke-dashoffset: 0;
    transition: stroke 1.5s ease-out, stroke-dashoffset 0.8s ease-out;
}

/* Closing fan */
.closing-fan {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    width: 160px;
    height: 80px;
    opacity: 0.2;
    z-index: 1;
}

/* ============================================
   REVEAL ANIMATION (scroll-triggered)
   ============================================ */
.reveal-group > * {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.9s ease-out, transform 0.9s ease-out;
}

.reveal-group.revealed > *:nth-child(1) { transition-delay: 0s; }
.reveal-group.revealed > *:nth-child(2) { transition-delay: 0.12s; }
.reveal-group.revealed > *:nth-child(3) { transition-delay: 0.24s; }
.reveal-group.revealed > *:nth-child(4) { transition-delay: 0.36s; }
.reveal-group.revealed > *:nth-child(5) { transition-delay: 0.48s; }
.reveal-group.revealed > *:nth-child(6) { transition-delay: 0.60s; }
.reveal-group.revealed > *:nth-child(7) { transition-delay: 0.72s; }

.reveal-group.revealed > * {
    opacity: 1;
    transform: translateY(0);
}

/* ============================================
   TEXT HOVER EFFECTS
   ============================================ */
.premise-text,
.protocol-body p {
    position: relative;
}

.protocol-title {
    position: relative;
    display: inline-block;
}

.protocol-title::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 0;
    height: 1px;
    background: var(--antique-gold);
    transition: width 0.3s ease-out;
}

.protocol-title:hover::after {
    width: 100%;
}

/* Hover gold underline for body text */
.premise-text::after,
.protocol-body p::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 1px;
    background: var(--burnished-bronze);
    transition: width 0.3s ease-out;
    opacity: 0.5;
}

.premise-text:hover::after,
.protocol-body p:hover::after {
    width: 100%;
}

/* ============================================
   MASK TILT-3D EFFECT (cursor-based perspective)
   ============================================ */
.mask-container {
    perspective: 800px;
}

.mask-container .geometric-mask {
    transition: opacity 1s ease-out, transform 0.15s ease-out;
    transform-style: preserve-3d;
}

/* ============================================
   IN-VIEW STATES
   ============================================ */
.chamber.in-view .section-marker,
.chamber.in-view .section-heading,
.chamber.in-view .protocol-number,
.chamber.in-view .protocol-title {
    opacity: 1;
}

/* ============================================
   SELECTION / HIGHLIGHT
   ============================================ */
::selection {
    background: var(--burnished-bronze);
    color: var(--ritual-black);
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */
@media (max-width: 900px) {
    .antechamber-layout {
        grid-template-columns: 1fr;
        gap: 3rem;
    }

    .antechamber-mask {
        order: -1;
    }

    .geometric-mask {
        max-width: 200px;
    }

    .protocol-split--left,
    .protocol-split--center,
    .protocol-split--right {
        grid-template-columns: 1fr;
    }

    .bisection-line {
        display: none;
    }

    .protocol-visual {
        order: -1;
        margin-bottom: 2rem;
    }

    .progress-track {
        right: 1rem;
    }

    .corner-fan--tr,
    .corner-fan--bl {
        display: none;
    }
}

@media (max-width: 600px) {
    .opening-title {
        font-size: clamp(2rem, 8vw, 3rem);
    }

    .opening-fan {
        width: 90vw;
    }

    .antechamber-text {
        padding-left: 0;
    }

    .protocol-content {
        padding: 1rem;
    }

    .corner-fan {
        width: 80px;
        height: 40px;
    }
}
