/* ============================================
   MasqueradeProtocol.com - Styles
   Palette:
     Obsidian Black:    #0a0a0f
     Antique Gold:      #c9a84c
     Venetian Crimson:  #8b1a2b
     Cipher Teal:       #2a6b6e
     Parchment Ivory:   #f0e8d8
     Smoke Silver:      #6b6b7b
     Phantom Violet:    #3d2654
   Fonts:
     Display:  Playfair Display 700
     Body:     Libre Baskerville 400/700
     Mono:     IBM Plex Mono 300/500
     Accent:   Cormorant Garamond 300 italic
   ============================================ */

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

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    background-color: #0a0a0f;
    color: #f0e8d8;
    font-family: 'Libre Baskerville', serif;
    font-size: 17px;
    line-height: 1.75;
    overflow-x: hidden;
    position: relative;
}

/* --- Boot Overlay --- */
#boot-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: #0a0a0f;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.6s ease;
}

#boot-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

#boot-overlay.hidden {
    display: none;
}

#boot-text {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 13px;
    font-weight: 500;
    color: #2a6b6e;
    letter-spacing: 0.05em;
    opacity: 0;
    transition: opacity 0.4s ease;
}

#boot-text.visible {
    opacity: 1;
}

#boot-text.dissolving {
    animation: dissolveUp 0.8s ease forwards;
}

.dot {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.dot.show {
    opacity: 1;
}

@keyframes dissolveUp {
    0% { opacity: 1; transform: translateY(0); filter: blur(0); }
    100% { opacity: 0; transform: translateY(-40px); filter: blur(4px); }
}

/* --- Damask Background --- */
#damask-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    opacity: 0;
    transition: opacity 2s ease-in;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200' viewBox='0 0 200 200'%3E%3Cdefs%3E%3Cstyle%3E.d%7Bfill:none;stroke:%23c9a84c;stroke-width:0.5;opacity:0.12%7D%3C/style%3E%3C/defs%3E%3C!-- Diamond decision nodes --%3E%3Cpolygon class='d' points='100,10 120,30 100,50 80,30'/%3E%3Cpolygon class='d' points='100,150 120,170 100,190 80,170'/%3E%3C!-- Process rectangles --%3E%3Crect class='d' x='20' y='70' width='30' height='20' rx='2'/%3E%3Crect class='d' x='150' y='70' width='30' height='20' rx='2'/%3E%3C!-- Terminator circles --%3E%3Ccircle class='d' cx='100' cy='100' r='15'/%3E%3Ccircle class='d' cx='30' cy='170' r='8'/%3E%3Ccircle class='d' cx='170' cy='170' r='8'/%3E%3C!-- Arrow lines --%3E%3Cline class='d' x1='100' y1='50' x2='100' y2='85'/%3E%3Cline class='d' x1='100' y1='115' x2='100' y2='150'/%3E%3Cline class='d' x1='50' y1='80' x2='85' y2='100'/%3E%3Cline class='d' x1='115' y1='100' x2='150' y2='80'/%3E%3C!-- Scrollwork curves --%3E%3Cpath class='d' d='M0,0 Q50,20 100,0 Q150,20 200,0'/%3E%3Cpath class='d' d='M0,200 Q50,180 100,200 Q150,180 200,200'/%3E%3Cpath class='d' d='M20,30 Q40,50 20,80'/%3E%3Cpath class='d' d='M180,30 Q160,50 180,80'/%3E%3Cpath class='d' d='M20,120 Q40,140 20,170'/%3E%3Cpath class='d' d='M180,120 Q160,140 180,170'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 200px 200px;
    pointer-events: none;
}

#damask-bg.visible {
    opacity: 1;
}

/* --- HUD Layer --- */
#hud-layer {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    opacity: 0;
    transition: opacity 1.5s ease;
}

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

.hud-stream {
    position: absolute;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    font-weight: 300;
    color: #2a6b6e;
    opacity: 0.08;
    white-space: nowrap;
    overflow: hidden;
    letter-spacing: 0.05em;
}

.hud-stream-1 {
    top: 10%;
    left: 5%;
    width: 300px;
    height: 20px;
    animation: hudScroll 20s linear infinite;
}

.hud-stream-2 {
    top: 45%;
    right: 3%;
    width: 280px;
    height: 20px;
    animation: hudScroll 25s linear infinite reverse;
}

.hud-stream-3 {
    bottom: 15%;
    left: 8%;
    width: 320px;
    height: 20px;
    animation: hudScroll 22s linear infinite;
}

@keyframes hudScroll {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50%); }
}

/* --- Mask Navigation --- */
#mask-nav {
    position: fixed;
    top: 34px;
    right: 34px;
    z-index: 9000;
}

#mask-nav-trigger {
    width: 48px;
    height: 32px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    transition: transform 0.3s ease;
}

#mask-nav-trigger:hover {
    transform: scale(1.1);
}

.nav-mask-icon {
    width: 48px;
    height: 32px;
    filter: drop-shadow(0 0 8px rgba(201, 168, 76, 0.3));
}

#mask-nav-menu {
    position: absolute;
    top: 40px;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8) translateY(-10px);
    transform-origin: top right;
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#mask-nav.open #mask-nav-menu {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1) translateY(0);
}

.nav-link {
    font-family: 'Cormorant Garamond', serif;
    font-size: 16px;
    font-weight: 300;
    font-style: italic;
    color: #f0e8d8;
    text-decoration: none;
    padding: 5px 13px;
    white-space: nowrap;
    position: relative;
    text-align: right;
    transition: color 0.3s ease;
}

.nav-link::after {
    content: '';
    position: absolute;
    bottom: 2px;
    right: 13px;
    width: 0;
    height: 1px;
    background: #c9a84c;
    transition: width 0.3s ease;
}

.nav-link:hover {
    color: #c9a84c;
}

.nav-link:hover::after {
    width: calc(100% - 26px);
}

/* --- Hero Section --- */
#hero {
    position: relative;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2;
    overflow: hidden;
}

#hero-mask-container {
    width: clamp(300px, 50vw, 600px);
    position: relative;
    opacity: 0;
    transition: opacity 0.8s ease;
}

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

#hero-mask {
    width: 100%;
    height: auto;
    will-change: transform;
}

.mask-path {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    opacity: 0;
}

.mask-path.animate {
    animation: drawMaskPath 3s cubic-bezier(0.65, 0, 0.35, 1) forwards;
}

.mask-path.protocol-node.animate,
.mask-path.protocol-line.animate {
    animation: drawMaskPath 2s cubic-bezier(0.65, 0, 0.35, 1) forwards;
    animation-delay: 1.5s;
}

@keyframes drawMaskPath {
    0% { stroke-dashoffset: 1000; opacity: 0; }
    10% { opacity: 1; }
    100% { stroke-dashoffset: 0; opacity: 1; }
}

/* Hero tagline */
#hero-tagline {
    margin-top: 55px;
    opacity: 0;
    transition: opacity 0.6s ease;
}

#hero-tagline.visible {
    opacity: 1;
}

.tagline-reveal {
    overflow: hidden;
    position: relative;
}

.tagline-text {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 300;
    font-style: italic;
    font-size: clamp(1.5rem, 4vw, 3rem);
    color: #f0e8d8;
    display: inline-block;
    letter-spacing: 0.02em;
}

.tagline-reveal::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #c9a84c;
    transform: translateX(-101%);
}

.tagline-reveal.animating::after {
    animation: slideReveal 1.2s cubic-bezier(0.77, 0, 0.175, 1) forwards;
}

@keyframes slideReveal {
    0% { transform: translateX(-101%); }
    45% { transform: translateX(0%); }
    55% { transform: translateX(0%); }
    100% { transform: translateX(101%); }
}

/* --- Timeline Spine --- */
#timeline-spine {
    position: fixed;
    left: 12%;
    top: 0;
    bottom: 0;
    width: 2px;
    z-index: 3;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.8s ease;
}

#timeline-spine.visible {
    opacity: 1;
}

.timeline-line {
    width: 2px;
    height: 100%;
    background: linear-gradient(to bottom, transparent 0%, #c9a84c 15%, #c9a84c 85%, transparent 100%);
    opacity: 0.3;
}

/* --- Protocol Phase (common) --- */
.protocol-phase {
    position: relative;
    min-height: 80vh;
    padding: 89px 55px 89px 0;
    margin-left: calc(12% + 55px);
    margin-right: 8%;
    z-index: 5;
    display: flex;
    align-items: flex-start;
    gap: 34px;
}

.phase-marker {
    position: absolute;
    left: -55px;
    top: 89px;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 10;
}

.marker-mask {
    width: 40px;
    height: 28px;
    filter: drop-shadow(0 0 6px rgba(201, 168, 76, 0.3));
}

.phase-number {
    font-family: 'Playfair Display', serif;
    font-size: 14px;
    font-weight: 700;
    color: #c9a84c;
    letter-spacing: 0.15em;
}

.phase-content {
    flex: 1;
    position: relative;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.protocol-phase.revealed .phase-content {
    opacity: 1;
    transform: translateY(0);
}

/* Phase border frame */
.phase-border-frame {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

.border-draw {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.draw-path {
    stroke-dasharray: 2400;
    stroke-dashoffset: 2400;
    transition: stroke-dashoffset 0s;
}

.protocol-phase.revealed .draw-path {
    animation: borderDraw 1.2s cubic-bezier(0.65, 0, 0.35, 1) forwards;
}

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

/* Phase inner content */
.phase-inner {
    position: relative;
    z-index: 2;
    padding: 55px;
    background: linear-gradient(135deg, rgba(10, 10, 15, 0.85) 0%, rgba(61, 38, 84, 0.15) 100%);
    border-left: 3px solid rgba(201, 168, 76, 0.4);
}

.phase-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(3rem, 8vw, 7rem);
    color: #f0e8d8;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin-bottom: 34px;
    line-height: 1.1;
}

.phase-body {
    max-width: 680px;
    margin-bottom: 34px;
}

.phase-body p {
    margin-bottom: 21px;
    color: #f0e8d8;
    font-family: 'Libre Baskerville', serif;
    font-size: 17px;
    line-height: 1.75;
    font-weight: 400;
}

.phase-body p:last-child {
    margin-bottom: 0;
}

/* --- Phase-specific animations --- */

/* Phase 1: Invitation - border draws, content fades */
#phase-invitation .phase-content {
    transform: translateY(30px);
}

#phase-invitation.revealed .phase-content {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 0.4s;
}

/* Phase 2: Encryption - decrypt animation */
#phase-encryption .decrypt-target .decrypt-word {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 13px;
    color: #2a6b6e;
    display: inline;
    transition: color 0.3s ease, font-family 0.01s;
}

#phase-encryption .decrypt-target .decrypt-word.decrypted {
    font-family: 'Libre Baskerville', serif;
    font-size: 17px;
    color: #f0e8d8;
}

#phase-encryption .decrypt-target .decrypt-word.flash {
    color: #2a6b6e;
}

/* Phase 3: The Ball - slide from right */
#phase-ball .phase-content {
    transform: translateX(80px) rotate(2deg);
    opacity: 0;
}

#phase-ball.revealed .phase-content {
    transform: translateX(0) rotate(0deg);
    opacity: 1;
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.5s ease;
}

#phase-ball.revealed .phase-inner {
    animation: bounceScale 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.4s both;
}

@keyframes bounceScale {
    0% { transform: scale(0.85); }
    60% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

/* Phase 4: Unmasking - mask lift reveal */
.mask-reveal-overlay {
    position: absolute;
    inset: 0;
    background: #0a0a0f;
    z-index: 50;
    clip-path: inset(0 0 0 0);
    transition: clip-path 1.2s cubic-bezier(0.22, 1, 0.36, 1);
}

#phase-unmasking.revealed .mask-reveal-overlay {
    clip-path: inset(0 0 100% 0);
}

#phase-unmasking .phase-inner {
    position: relative;
    z-index: 51;
}

/* --- Wax Seal --- */
.wax-seal {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    margin-top: 21px;
}

.seal-face {
    width: 55px;
    height: 55px;
    background: radial-gradient(circle at 40% 35%, #a62035, #8b1a2b 60%, #6b1220);
    clip-path: polygon(50% 0%, 63% 5%, 78% 3%, 85% 15%, 97% 22%, 95% 38%, 100% 50%, 95% 63%, 97% 78%, 85% 85%, 78% 97%, 63% 95%, 50% 100%, 37% 95%, 22% 97%, 15% 85%, 3% 78%, 5% 63%, 0% 50%, 5% 37%, 3% 22%, 15% 15%, 22% 3%, 37% 5%);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease-out;
    will-change: transform;
}

.seal-glyph {
    font-size: 20px;
    color: #f0e8d8;
    line-height: 1;
}

.wax-seal:hover .seal-face {
    box-shadow: 0 0 12px rgba(139, 26, 43, 0.4);
}

.wax-seal.pressed .seal-face {
    transform: scale(0.95);
}

.wax-seal.cracked .seal-face {
    transform: scale(1);
}

.seal-content {
    display: none;
    margin-top: 13px;
    padding: 21px;
    font-family: 'Cormorant Garamond', serif;
    font-weight: 300;
    font-style: italic;
    font-size: clamp(1rem, 2vw, 1.3rem);
    color: #c9a84c;
    border-left: 2px solid rgba(201, 168, 76, 0.3);
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.wax-seal.cracked + .seal-content,
.wax-seal.cracked .seal-content-inner {
    display: block;
}

.seal-content.show {
    opacity: 1;
    transform: translateY(0);
}

/* --- Particle trails (right-side border dissolution) --- */
.phase-particles {
    position: absolute;
    right: -8px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 13px;
    pointer-events: none;
}

.particle {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #c9a84c;
    opacity: 0;
}

.protocol-phase.revealed .particle:nth-child(1) { opacity: 0.5; animation: particleDrift 3s ease-in-out infinite; }
.protocol-phase.revealed .particle:nth-child(2) { opacity: 0.35; animation: particleDrift 3.5s ease-in-out 0.3s infinite; }
.protocol-phase.revealed .particle:nth-child(3) { opacity: 0.25; animation: particleDrift 4s ease-in-out 0.6s infinite; }
.protocol-phase.revealed .particle:nth-child(4) { opacity: 0.15; animation: particleDrift 4.5s ease-in-out 0.9s infinite; }
.protocol-phase.revealed .particle:nth-child(5) { opacity: 0.08; animation: particleDrift 5s ease-in-out 1.2s infinite; }

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

/* --- Ribbon Cipher Streams --- */
.ribbon-stream {
    position: fixed;
    top: 0;
    width: 120px;
    height: 100vh;
    z-index: 1;
    pointer-events: none;
    opacity: 0;
    transition: opacity 2s ease;
}

.ribbon-stream.visible {
    opacity: 1;
}

#ribbon-stream-1 {
    left: 3%;
}

#ribbon-stream-2 {
    right: 3%;
}

/* --- Filigree glow on hover --- */
.filigree-hover {
    transition: opacity 0.3s ease, filter 0.3s ease;
}

.filigree-hover:hover {
    opacity: 0.6 !important;
    filter: drop-shadow(0 0 20px rgba(201, 168, 76, 0.3));
}

/* --- Footer --- */
#site-footer {
    position: relative;
    z-index: 5;
    text-align: center;
    padding: 89px 34px 55px;
    margin-top: 55px;
}

.footer-filigree {
    margin-bottom: 34px;
}

.filigree-line {
    width: min(400px, 80%);
    height: auto;
}

.footer-text {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 300;
    font-style: italic;
    font-size: clamp(1.2rem, 3vw, 2rem);
    color: #f0e8d8;
    margin-bottom: 13px;
}

.footer-meta {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    font-weight: 300;
    color: #6b6b7b;
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: #0a0a0f;
}

::-webkit-scrollbar-thumb {
    background: rgba(201, 168, 76, 0.3);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(201, 168, 76, 0.5);
}

/* --- Responsive --- */
@media (max-width: 900px) {
    .protocol-phase {
        margin-left: 55px;
        margin-right: 21px;
        padding: 55px 21px;
    }

    #timeline-spine {
        left: 21px;
    }

    .phase-marker {
        left: -34px;
    }

    .phase-inner {
        padding: 34px;
    }

    .phase-title {
        font-size: clamp(2rem, 6vw, 4rem);
    }
}

@media (max-width: 600px) {
    .protocol-phase {
        margin-left: 34px;
        margin-right: 13px;
        padding: 34px 13px;
    }

    #timeline-spine {
        left: 13px;
    }

    .phase-marker {
        left: -21px;
    }

    .phase-inner {
        padding: 21px;
    }

    #mask-nav {
        top: 21px;
        right: 21px;
    }
}
