/* ============================================
   MasqproT.com - The Masquerade Protocol
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --obsidian-velvet: #0b0a12;
    --midnight-aubergine: #1a1028;
    --parchment-ivory: #f0e8d8;
    --antique-gold: #c9a84c;
    --venetian-crimson: #8b2230;
    --champagne-haze: #d4b896;
    --tarnished-silver: #7a7568;
    --absinthe: #6b8f3c;
    --deep-purple: #241838;
    --cool-parchment: #e0dce8;

    --cursor-x: 50;
    --cursor-y: 50;
    --act-progress: 0;
}

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

html {
    scroll-behavior: smooth;
}

body {
    background: var(--obsidian-velvet);
    color: var(--parchment-ivory);
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 400;
    font-size: 18px;
    line-height: 1.75;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
}

/* --- Perspective Container --- */
#perspective-wrap {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    perspective: 1200px;
    overflow: hidden;
}

/* --- Layers --- */
.layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* --- Layer 0: Background --- */
#layer-bg {
    z-index: 0;
}

#gradient-mesh {
    position: absolute;
    top: -10%;
    left: -10%;
    width: 120%;
    height: 120%;
    background:
        radial-gradient(ellipse at 20% 30%, rgba(26, 16, 40, 0.8) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 70%, rgba(139, 34, 48, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(201, 168, 76, 0.05) 0%, transparent 40%),
        var(--obsidian-velvet);
    animation: meshDrift 30s ease-in-out infinite alternate;
}

@keyframes meshDrift {
    0% { transform: translate(0, 0); }
    25% { transform: translate(-8px, 5px); }
    50% { transform: translate(5px, -8px); }
    75% { transform: translate(-3px, -5px); }
    100% { transform: translate(6px, 3px); }
}

/* Mask Watermark */
.watermark-mask {
    position: fixed;
    width: 600px;
    height: 720px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 0;
    pointer-events: none;
    transition: transform 20s linear;
}

/* --- Layer 2: Decorations --- */
#layer-decor {
    z-index: 2;
}

/* Candle Particles */
.candle-particle {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    opacity: 0;
}

.candle-particle.gold {
    background: var(--antique-gold);
    box-shadow: 0 0 6px rgba(201, 168, 76, 0.4);
}

.candle-particle.champagne {
    background: var(--champagne-haze);
    box-shadow: 0 0 6px rgba(212, 184, 150, 0.3);
}

@keyframes candleDrift1 {
    0% { transform: translate(0, 0) scale(1); opacity: 0; }
    15% { opacity: 0.6; }
    50% { transform: translate(80px, -120px) scale(0.8); opacity: 0.4; }
    85% { opacity: 0.2; }
    100% { transform: translate(150px, -200px) scale(0.5); opacity: 0; }
}

@keyframes candleDrift2 {
    0% { transform: translate(0, 0) scale(1); opacity: 0; }
    15% { opacity: 0.5; }
    50% { transform: translate(-100px, -80px) scale(1.1); opacity: 0.35; }
    85% { opacity: 0.15; }
    100% { transform: translate(-180px, -160px) scale(0.6); opacity: 0; }
}

@keyframes candleDrift3 {
    0% { transform: translate(0, 0) scale(0.8); opacity: 0; }
    20% { opacity: 0.55; }
    60% { transform: translate(60px, -150px) scale(1); opacity: 0.3; }
    100% { transform: translate(120px, -250px) scale(0.4); opacity: 0; }
}

/* Floating Mask Particles */
.floating-mask-particle {
    position: absolute;
    pointer-events: none;
    opacity: 0;
}

.floating-mask-particle svg {
    width: 100%;
    height: 100%;
}

@keyframes floatMask {
    0% { transform: translate(0, 0) rotate(0deg); opacity: 0; }
    10% { opacity: var(--mask-opacity, 0.12); }
    50% { transform: translate(var(--drift-x, 40px), var(--drift-y, -60px)) rotate(var(--drift-rot, 5deg)); }
    90% { opacity: var(--mask-opacity, 0.12); }
    100% { transform: translate(calc(var(--drift-x, 40px) * 2), calc(var(--drift-y, -60px) * 2)) rotate(calc(var(--drift-rot, 5deg) * 2)); opacity: 0; }
}

/* --- Act Container --- */
#act-container {
    position: relative;
    z-index: 1;
    width: 100vw;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-snap-type: y mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* --- Individual Acts --- */
.act {
    position: relative;
    width: 100vw;
    height: 100vh;
    min-height: 100vh;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.act-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    padding: 60px 8%;
}

.act-content-centered {
    align-items: center;
}

/* --- Act Titles --- */
.act-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: clamp(3rem, 8vw, 7rem);
    color: var(--antique-gold);
    letter-spacing: 0.04em;
    text-shadow: 0 0 40px rgba(201, 168, 76, 0.3);
    margin-bottom: 30px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.act-title .act-subtitle {
    display: block;
    font-size: 0.35em;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--champagne-haze);
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    text-shadow: none;
    margin-top: 8px;
}

.act.visible .act-title {
    opacity: 1;
    transform: translateY(0);
}

/* Act IV specific title color */
.act-title-unmasking {
    color: var(--antique-gold);
}

/* --- Content Panels --- */
.content-panel {
    position: relative;
    max-width: 680px;
    background: rgba(26, 16, 40, 0.85);
    backdrop-filter: blur(12px) saturate(1.4);
    -webkit-backdrop-filter: blur(12px) saturate(1.4);
    padding: 40px 45px;
    margin: 15px 0;
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.act.visible .content-panel {
    opacity: 1;
    transform: scale(1);
}

/* Panel offset positions - never perfectly centered */
.panel-offset-right {
    align-self: flex-end;
    margin-right: 5%;
}

.panel-offset-left {
    align-self: flex-start;
    margin-left: 5%;
}

.panel-offset-center {
    align-self: center;
    margin-left: 10%;
}

/* --- Filigree Borders --- */
.filigree-border {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
}

.filigree {
    position: absolute;
    width: 100%;
    height: 20px;
    left: 0;
}

.filigree-top {
    top: -2px;
}

.filigree-bottom {
    bottom: -2px;
}

.filigree-path {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    transition: stroke-dashoffset 1.5s ease-in-out;
}

.act.visible .filigree-path {
    stroke-dashoffset: 0;
}

/* --- Epigraph / Pull Quotes --- */
.epigraph {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-style: italic;
    font-weight: 500;
    font-size: 1.4em;
    color: var(--champagne-haze);
    margin-bottom: 20px;
    padding-left: 20px;
    border-left: 2px solid rgba(201, 168, 76, 0.3);
}

/* --- Typography --- */
.content-panel p {
    margin-bottom: 16px;
    color: var(--parchment-ivory);
}

.content-panel p:last-child {
    margin-bottom: 0;
}

.content-panel h3 {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: 1.6em;
    color: var(--antique-gold);
    margin-bottom: 12px;
    letter-spacing: 0.02em;
    text-shadow: 0 0 30px rgba(201, 168, 76, 0.2);
}

.content-panel h4 {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: 1.2em;
    color: var(--antique-gold);
    margin-bottom: 10px;
    letter-spacing: 0.02em;
}

/* --- Act I: The Invitation --- */
#act-1 {
    background: var(--obsidian-velvet);
}

#act-1 .act-content {
    align-items: center;
    justify-content: center;
}

#intro-mask-container {
    position: relative;
    width: 200px;
    height: 240px;
    margin-bottom: 30px;
    opacity: 0;
    transition: opacity 0.5s ease;
}

#intro-mask-container.visible {
    opacity: 1;
}

.mask-centerpiece {
    width: 200px;
    height: 240px;
}

.mask-path {
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
    transition: stroke-dashoffset 2.5s ease-in-out;
}

#intro-mask-container.drawing .mask-path {
    stroke-dashoffset: 0;
}

#intro-mask-container.faded {
    opacity: 0.2;
    transform: translateY(-100px);
    transition: opacity 1s ease, transform 1.5s ease;
}

/* Typewriter text */
.typewriter-text {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(201, 168, 76, 0.6);
    min-height: 1.5em;
    margin-bottom: 40px;
    overflow: hidden;
    white-space: nowrap;
}

/* Act I panel */
#act-1 .content-panel {
    align-self: flex-end;
    margin-right: 8%;
    transform: translateX(60px);
    opacity: 0;
    transition: transform 0.8s ease-out, opacity 0.8s ease-out;
}

#act-1.visible .content-panel.panel-entered {
    transform: translateX(0);
    opacity: 1;
}

/* --- Act II: The Masking --- */
#act-2 {
    background: transparent;
}

.panels-diagonal {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    margin-top: 20px;
}

.panel-mask-type {
    opacity: 0;
    transform: scale(0.9);
    transition: opacity 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.act.visible .panel-mask-type {
    opacity: 1;
    transform: scale(1);
}

.inline-mask-icon {
    width: 60px;
    height: auto;
    margin-bottom: 12px;
    display: block;
}

.inline-mask-icon path {
    transition: fill 0.3s ease;
}

.panel-mask-type:hover .inline-mask-icon path {
    fill: rgba(139, 34, 48, 0.6);
}

/* --- Curtain Divider --- */
.curtain-divider {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    display: flex;
}

.curtain {
    width: 50%;
    height: 100%;
    background: var(--midnight-aubergine);
    position: relative;
    transition: transform 1.2s ease-in-out;
}

.curtain::after {
    content: '';
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 40px;
    background: radial-gradient(ellipse at 50% 0%, transparent 60%, var(--midnight-aubergine) 60%);
    background-size: 40px 40px;
    background-repeat: repeat-x;
}

.curtain-left {
    transform-origin: left center;
}

.curtain-right {
    transform-origin: right center;
}

/* SVG noise texture overlay on curtains */
.curtain::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.08'/%3E%3C/svg%3E");
    opacity: 0.15;
}

.act.visible .curtain-left {
    transform: translateX(-105%);
}

.act.visible .curtain-right {
    transform: translateX(105%);
}

/* --- Act III: The Dance --- */
#act-3 {
    background: transparent;
}

.protocols-grid {
    display: flex;
    flex-direction: column;
    gap: 25px;
    width: 100%;
    margin-top: 20px;
    max-width: 900px;
}

.protocol-panel {
    position: relative;
}

.protocol-numeral {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: 2.5em;
    color: var(--antique-gold);
    text-shadow: 0 0 40px rgba(201, 168, 76, 0.3);
    margin-bottom: 5px;
    letter-spacing: 0.06em;
}

/* Elastic panel cursor-follow effect */
.elastic-panel {
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94), opacity 0.8s ease;
}

/* Continuous filigree animation for Act III */
#act-3.visible .filigree-path {
    animation: filigreeDrawLoop 8s ease-in-out infinite;
}

@keyframes filigreeDrawLoop {
    0% { stroke-dashoffset: 0; }
    45% { stroke-dashoffset: 1200; }
    55% { stroke-dashoffset: 1200; }
    100% { stroke-dashoffset: 0; }
}

/* --- Act IV: The Unmasking --- */
#act-4 {
    background: var(--deep-purple);
}

#act-4 .content-panel {
    background: rgba(36, 24, 56, 0.85);
}

#act-4 .content-panel p {
    color: var(--cool-parchment);
}

#act-4 .content-panel h4 {
    color: var(--absinthe);
}

/* Reveal panels with green accent */
.reveal-panel {
    position: relative;
    overflow: hidden;
    border-left: 3px solid var(--absinthe);
}

/* Slide reveal cover */
.slide-reveal-cover {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--venetian-crimson);
    z-index: 5;
    transform: translateX(0);
    transition: transform 1s ease-in-out;
}

.act.visible .slide-reveal-cover {
    transform: translateX(101%);
}

.reveal-panels {
    display: flex;
    flex-direction: column;
    gap: 25px;
    width: 100%;
    margin-top: 30px;
}

/* Morph Mask */
#mask-morph-container {
    width: 200px;
    height: 240px;
    margin-bottom: 20px;
    align-self: center;
}

.morph-mask-svg {
    width: 200px;
    height: 240px;
}

#morph-path-outer,
#morph-path-left-eye,
#morph-path-right-eye {
    transition: stroke 2s ease;
}

#act-4.visible #morph-path-outer,
#act-4.visible #morph-path-left-eye,
#act-4.visible #morph-path-right-eye {
    animation: morphColor 6s ease-in-out infinite;
}

@keyframes morphColor {
    0%, 100% { stroke: var(--antique-gold); }
    33% { stroke: var(--venetian-crimson); }
    66% { stroke: var(--absinthe); }
}

/* --- Act V: The Protocol --- */
#act-5 {
    background: var(--obsidian-velvet);
}

.panel-final {
    max-width: 680px;
    text-align: center;
    align-self: center;
    margin-top: 20px;
}

.final-word-container {
    margin-top: 40px;
    text-align: center;
}

.final-word {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: clamp(3rem, 8vw, 7rem);
    color: var(--antique-gold);
    letter-spacing: 0.04em;
    display: inline-block;
    animation: candleGlow 2s ease-in-out infinite;
}

@keyframes candleGlow {
    0%, 100% { text-shadow: 0 0 40px rgba(201, 168, 76, 0.3); }
    50% { text-shadow: 0 0 80px rgba(201, 168, 76, 0.6), 0 0 120px rgba(201, 168, 76, 0.2); }
}

/* --- HUD Layer --- */
#layer-hud {
    z-index: 100;
    opacity: 0;
    transition: opacity 0.6s ease;
}

#layer-hud.visible {
    opacity: 1;
}

.hud-corner {
    position: fixed;
    pointer-events: auto;
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(201, 168, 76, 0.6);
    z-index: 101;
    opacity: 0;
    transition: opacity 0.4s ease;
}

#layer-hud.visible .hud-corner {
    opacity: 1;
}

.hud-top-left {
    top: 24px;
    left: 24px;
    transition-delay: 0s;
}

.hud-top-right {
    top: 24px;
    right: 24px;
    transition-delay: 0.2s;
}

.hud-bottom-left {
    bottom: 24px;
    left: 24px;
    transition-delay: 0.4s;
}

.hud-bottom-right {
    bottom: 24px;
    right: 24px;
    transition-delay: 0.6s;
}

.hud-mask-icon {
    width: 32px;
    height: 32px;
    cursor: pointer;
}

.hud-mask-icon path {
    fill: none;
    stroke: var(--tarnished-silver);
    stroke-width: 1;
    transition: stroke 0.3s ease;
}

.hud-mask-icon:hover path {
    stroke: var(--antique-gold);
}

#hud-act-numeral {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: 18px;
    color: var(--tarnished-silver);
    letter-spacing: 0.06em;
}

.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--tarnished-silver);
    animation: pulseDot 2s ease-in-out infinite;
}

@keyframes pulseDot {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.3); }
}

.hud-sigil {
    width: 32px;
    height: 32px;
    cursor: pointer;
}

.hud-sigil circle,
.hud-sigil line {
    transition: stroke 0.3s ease;
}

.hud-sigil:hover circle,
.hud-sigil:hover line {
    stroke: var(--antique-gold);
}

/* --- Act Timeline --- */
#act-timeline {
    position: fixed;
    left: 24px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 101;
    pointer-events: auto;
}

.timeline-dot {
    width: 16px;
    height: 16px;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.timeline-dot:hover {
    transform: scale(1.4);
}

.timeline-dot svg {
    width: 100%;
    height: 100%;
}

.timeline-dot.active svg path {
    stroke: var(--antique-gold);
    fill: rgba(201, 168, 76, 0.15);
}

/* --- Act V HUD Pulse Override --- */
#act-5.visible ~ #layer-hud .hud-corner {
    animation: hudPulse 2s ease-in-out infinite;
}

@keyframes hudPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .act-content {
        padding: 40px 5%;
    }

    .content-panel {
        max-width: 95%;
        padding: 25px 20px;
    }

    .panel-offset-right {
        margin-right: 2%;
    }

    .panel-offset-left {
        margin-left: 2%;
    }

    .panel-offset-center {
        margin-left: 2%;
    }

    .protocols-grid {
        gap: 15px;
    }

    #act-timeline {
        left: 8px;
    }

    .hud-top-left {
        top: 12px;
        left: 12px;
    }

    .hud-top-right {
        top: 12px;
        right: 12px;
    }

    .hud-bottom-left {
        bottom: 12px;
        left: 12px;
    }

    .hud-bottom-right {
        bottom: 12px;
        right: 12px;
    }
}

/* --- Prefers Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    .candle-particle,
    .floating-mask-particle {
        display: none;
    }

    .mask-path {
        stroke-dashoffset: 0;
        transition: none;
    }

    .filigree-path {
        stroke-dashoffset: 0;
        transition: none;
        animation: none;
    }

    #gradient-mesh {
        animation: none;
    }

    .curtain-left,
    .curtain-right {
        transition-duration: 0.1s;
    }

    .final-word {
        animation: none;
        text-shadow: 0 0 40px rgba(201, 168, 76, 0.3);
    }
}
