/* ==========================================================================
   diplomacy.quest - Styles
   A 1960s diplomatic salon meets generative art meets candy-bright confections
   ========================================================================== */

/* --- CSS Custom Properties --- */
:root {
    /* Palette */
    --diplomatic-rose: #D94F7A;
    --treaty-teal: #4AAFB5;
    --summit-gold: #F4C542;
    --protocol-violet: #8B5FBF;
    --parchment: #F5F0E8;
    --parchment-alt: #F2EDE6;
    --midnight-study: #1E1A2E;
    --ink: #2B2520;
    --noise-wash: #C8BFB0;
    --dark-grain: #3A3548;

    /* Typography */
    --font-display: 'Cormorant Garamond', 'Georgia', serif;
    --font-body: 'EB Garamond', 'Georgia', serif;
    --font-accent: 'Inconsolata', 'Courier New', monospace;

    /* Spacing (Fibonacci) */
    --space-sm: 34px;
    --space-md: 55px;
    --space-lg: 89px;
    --space-xl: 144px;

    /* Easing */
    --ease-general: cubic-bezier(0.25, 0.1, 0.25, 1.0);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Guide Rails */
    --rail-left: 15%;
    --rail-center: 42%;
    --rail-right: 73%;
}

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 1.15vw, 1.2rem);
    line-height: 1.72;
    color: var(--ink);
    background-color: var(--parchment);
    overflow-x: hidden;
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='24' viewBox='0 0 16 24'%3E%3Cpath d='M8 0C8 0 6 4 6 8L2 22C2 23 3 24 4 23L8 12L12 23C13 24 14 23 14 22L10 8C10 4 8 0 8 0Z' fill='%232B2520'/%3E%3Ccircle cx='8' cy='22' r='2' fill='%23D94F7A'/%3E%3C/svg%3E") 8 22, auto;
}

/* --- Grain Overlay --- */
.grain-overlay::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    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.9' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
    opacity: 0;
    mix-blend-mode: multiply;
    z-index: 9999;
    transition: opacity 2s var(--ease-general);
}

.grain-overlay.grain-visible::after {
    opacity: 0.06;
}

/* --- Navigation Sidebar --- */
#sidebar {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    z-index: 1000;
    padding: 20px 0;
}

#sidebar::before {
    content: '';
    position: absolute;
    inset: -10px -4px -10px -4px;
    background: rgba(245, 240, 232, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 24px 0 0 24px;
    z-index: -1;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 128 128' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.2' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.08'/%3E%3C/svg%3E");
    background-size: 128px 128px;
}

.nav-badge {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: var(--diplomatic-rose);
    cursor: pointer;
    transition: transform 280ms var(--ease-spring), box-shadow 280ms var(--ease-general);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-badge:nth-child(1) { background-color: #D94F7A; }
.nav-badge:nth-child(2) { background-color: #4AAFB5; }
.nav-badge:nth-child(3) { background-color: #F4C542; }
.nav-badge:nth-child(4) { background-color: #8B5FBF; }
.nav-badge:nth-child(5) { background-color: #D94F7A; }

.nav-badge:hover {
    transform: scale(1.08) rotate(1deg);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.nav-badge.active {
    transform: scale(1.15);
    box-shadow: 0 0 0 3px var(--parchment), 0 0 0 5px currentColor;
}

.badge-label {
    position: absolute;
    right: 40px;
    white-space: nowrap;
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--ink);
    background: rgba(245, 240, 232, 0.9);
    padding: 4px 12px;
    border-radius: 4px;
    opacity: 0;
    transform: translateX(8px);
    transition: opacity 280ms var(--ease-general), transform 280ms var(--ease-spring);
    pointer-events: none;
}

.nav-badge:hover .badge-label {
    opacity: 1;
    transform: translateX(0);
}

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

.chamber canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

.chamber-content {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 1200px;
    padding: var(--space-lg) 80px;
    opacity: 0;
    transform: translateY(40px) rotate(0.8deg);
    transition: opacity 1200ms var(--ease-general), transform 1200ms var(--ease-general);
}

.chamber-content.in-view {
    opacity: 1;
    transform: translateY(0) rotate(0deg);
}

/* --- Chamber: Dark Variant --- */
.chamber-dark {
    background-color: var(--midnight-study);
    color: var(--parchment-alt);
}

.chamber-dark .section-heading {
    color: var(--parchment-alt);
}

/* --- Opening: The Arrival --- */
#chamber-arrival {
    background-color: var(--midnight-study);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-end;
}

#hero-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.arrival-content {
    padding-bottom: var(--space-xl) !important;
    padding-left: var(--space-lg) !important;
    z-index: 2;
    /* Keep arrival content always visible after animation */
    opacity: 1 !important;
    transform: none !important;
}

.display-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(2.4rem, 6vw, 5rem);
    letter-spacing: 0.12em;
    color: var(--parchment-alt);
    line-height: 1.15;
    margin-bottom: 20px;
}

.letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(20px);
    animation: letterReveal 600ms var(--ease-general) forwards;
    animation-delay: calc(var(--delay) * 80ms + 800ms);
}

.letter.dot {
    color: var(--diplomatic-rose);
}

@keyframes letterReveal {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.subtitle {
    font-family: var(--font-body);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(1.1rem, 2vw, 1.6rem);
    color: var(--parchment);
    opacity: 0;
    animation: subtitleFade 1000ms var(--ease-general) forwards;
    animation-delay: 2.4s;
    letter-spacing: 0.04em;
}

@keyframes subtitleFade {
    to {
        opacity: 0.85;
    }
}

/* Scroll Indicator */
.scroll-indicator {
    position: absolute;
    bottom: var(--space-sm);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 2;
    opacity: 0;
    animation: subtitleFade 800ms var(--ease-general) forwards;
    animation-delay: 3.5s;
}

.scroll-label {
    font-family: var(--font-accent);
    font-weight: 500;
    font-size: 0.7rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--treaty-teal);
}

.scroll-line {
    width: 1px;
    height: 40px;
    background: linear-gradient(to bottom, var(--treaty-teal), transparent);
    animation: scrollPulse 2s var(--ease-general) infinite;
    animation-delay: 4s;
}

@keyframes scrollPulse {
    0%, 100% { opacity: 0.4; transform: scaleY(1); }
    50% { opacity: 1; transform: scaleY(1.3); }
}

/* --- Typography --- */
.section-heading {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(2.4rem, 6vw, 5rem);
    letter-spacing: 0.03em;
    line-height: 1.15;
    color: var(--ink);
    margin-bottom: var(--space-sm);
}

.section-counter {
    font-family: var(--font-display);
    font-weight: 300;
    font-size: clamp(4rem, 12vw, 9rem);
    color: var(--diplomatic-rose);
    text-shadow: 0 0 8px rgba(217, 79, 122, 0.3);
    line-height: 1;
    display: block;
    margin-bottom: var(--space-sm);
    opacity: 0.7;
}

.large-counter {
    font-size: clamp(5rem, 14vw, 11rem);
    color: var(--summit-gold);
    text-shadow: 0 0 12px rgba(244, 197, 66, 0.4);
}

.body-text {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 1.15vw, 1.2rem);
    line-height: 1.72;
    color: var(--ink);
    max-width: 600px;
}

.light-text, .chamber-dark .body-text {
    color: var(--parchment-alt);
}

.pull-quote {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 500;
    font-size: clamp(1.4rem, 3vw, 2.2rem);
    line-height: 1.4;
    color: var(--protocol-violet);
    padding: var(--space-md) 0;
    position: relative;
    max-width: 540px;
}

.quote-mark {
    font-size: 1.6em;
    color: var(--diplomatic-rose);
    opacity: 0.5;
    vertical-align: -0.15em;
}

/* --- Content Blocks (Organic Layout) --- */
.content-block {
    position: relative;
    margin-bottom: var(--space-lg);
}

.block-left {
    margin-left: var(--rail-left);
    transform: translate(-2%, 1.5%) rotate(-0.3deg);
}

.block-right {
    margin-left: var(--rail-right);
    transform: translate(2%, -1%) rotate(0.5deg);
    max-width: 480px;
}

.block-center {
    margin-left: var(--rail-center);
    transform: translate(-1%, 0.5%) rotate(0.2deg);
}

/* --- Ribbon Divider --- */
.ribbon-divider {
    width: 120px;
    height: 3px;
    background: var(--ribbon-color, var(--diplomatic-rose));
    border-radius: 2px;
    margin-bottom: var(--space-sm);
    position: relative;
}

.ribbon-divider::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 0;
    width: 100%;
    height: 5px;
    background: inherit;
    border-radius: 50%;
    opacity: 0.3;
    transform: scaleY(0.4);
}

/* --- Seal Stamps --- */
.seal-stamp {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--seal-color, var(--diplomatic-rose));
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.2rem;
    color: var(--parchment);
    cursor: pointer;
    transition: transform 280ms var(--ease-spring), box-shadow 280ms var(--ease-general);
    margin-bottom: var(--space-sm);
}

.seal-stamp:hover {
    transform: scale(1.08) rotate(1deg);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
}

.floating-seal {
    display: inline-flex;
    margin: 0 12px;
    animation: sealFloat 4s ease-in-out infinite;
    animation-delay: var(--float-delay, 0s);
}

@keyframes sealFloat {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    33% { transform: translateY(-10px) rotate(2deg); }
    66% { transform: translateY(-6px) rotate(-1.5deg); }
}

/* --- Section Divider SVGs --- */
.section-divider {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 24px;
    z-index: 2;
    opacity: 0.5;
}

/* --- Treaty Document Panel --- */
.treaty-document {
    background: var(--parchment);
    border: 2px solid var(--noise-wash);
    border-radius: 4px;
    padding: 0;
    position: relative;
    max-width: 800px;
    margin: 0 auto;
    box-shadow: 0 8px 40px rgba(43, 37, 32, 0.15),
                inset 0 0 0 8px var(--parchment),
                inset 0 0 0 9px var(--noise-wash);
    transform: rotate(-0.4deg);
}

.treaty-inner {
    padding: var(--space-lg);
}

.treaty-heading {
    color: var(--ink) !important;
}

.treaty-articles {
    margin-top: var(--space-md);
}

.treaty-article {
    margin-bottom: var(--space-md);
    padding-left: var(--space-sm);
    border-left: 2px solid var(--summit-gold);
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 800ms var(--ease-general), transform 800ms var(--ease-general);
}

.treaty-article.visible {
    opacity: 1;
    transform: translateY(0);
}

.article-num {
    font-family: var(--font-accent);
    font-weight: 500;
    font-size: 0.8rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--summit-gold);
    display: block;
    margin-bottom: 8px;
}

.treaty-seals {
    display: flex;
    gap: 24px;
    justify-content: center;
    margin-top: var(--space-lg);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--noise-wash);
}

/* --- Wax Seals --- */
.wax-seal {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.3), var(--seal-color, var(--diplomatic-rose)) 50%, rgba(0,0,0,0.2));
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.4rem;
    color: var(--parchment);
    cursor: pointer;
    transition: transform 280ms var(--ease-spring), box-shadow 280ms var(--ease-general);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.2), inset 0 -2px 4px rgba(0, 0, 0, 0.15);
}

.wax-seal:hover {
    transform: scale(1.08) rotate(1deg);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25), inset 0 -2px 4px rgba(0, 0, 0, 0.15);
}

/* --- Corner Folds --- */
.corner-fold {
    position: absolute;
    width: 40px;
    height: 40px;
}

.corner-top-right {
    top: 0;
    right: 0;
    background: linear-gradient(225deg, var(--noise-wash) 50%, transparent 50%);
    clip-path: polygon(0 0, 100% 0, 100% 100%);
}

.corner-bottom-left {
    bottom: 0;
    left: 0;
    background: linear-gradient(45deg, var(--noise-wash) 50%, transparent 50%);
    clip-path: polygon(0 0, 100% 100%, 0 100%);
}

/* --- Postmark Watermark --- */
.postmark-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-15deg);
    font-family: var(--font-accent);
    font-weight: 500;
    font-size: 3.5rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--diplomatic-rose);
    opacity: 0.08;
    pointer-events: none;
    white-space: nowrap;
    border: 3px solid;
    border-radius: 50%;
    padding: 20px 40px;
    border-color: var(--diplomatic-rose);
}

/* --- Archive Cards --- */
.archive-card {
    background: rgba(245, 240, 232, 0.08);
    border: 1px solid rgba(200, 191, 176, 0.2);
    border-radius: 4px;
    padding: var(--space-md);
    position: relative;
    max-width: 480px;
    transition: transform 280ms var(--ease-spring), box-shadow 280ms var(--ease-general);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.archive-card:hover {
    transform: scale(1.02) rotate(0.3deg);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.archive-card .corner-fold {
    background: linear-gradient(225deg, rgba(200, 191, 176, 0.3) 50%, transparent 50%);
}

.card-label {
    font-family: var(--font-accent);
    font-weight: 500;
    font-size: 0.8rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--treaty-teal);
    display: block;
    margin-bottom: 12px;
}

.card-date {
    font-family: var(--font-display);
    font-weight: 300;
    font-size: 1.8rem;
    color: var(--protocol-violet);
    opacity: 0.4;
    margin-top: 16px;
    text-shadow: 0 0 6px rgba(139, 95, 191, 0.3);
}

/* --- Departure Section --- */
.departure-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.departure-content .content-block {
    margin-left: 0;
    transform: none;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.departure-content .ribbon-divider {
    margin-left: auto;
    margin-right: auto;
}

.departure-content .body-text {
    text-align: center;
}

.closing-quote {
    text-align: center;
    margin: var(--space-md) auto 0;
}

.departure-seals {
    margin-top: var(--space-lg);
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
}

.departure-footer {
    margin-top: var(--space-xl);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    opacity: 0.5;
}

.footer-label {
    font-family: var(--font-accent);
    font-weight: 500;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--diplomatic-rose);
}

.footer-year {
    font-family: var(--font-display);
    font-weight: 300;
    font-size: 1.4rem;
    color: var(--noise-wash);
    letter-spacing: 0.1em;
}

/* --- Fade-In on Scroll --- */
.fade-in-scroll {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 800ms var(--ease-general), transform 800ms var(--ease-general);
}

.fade-in-scroll.visible {
    opacity: 1;
    transform: translateY(0);
}

/* --- Background for light chambers --- */
.chamber:not(.chamber-dark) {
    background-color: var(--parchment);
}

#chamber-treaty {
    background-color: var(--parchment-alt);
}

#chamber-departure {
    background: linear-gradient(180deg, var(--parchment) 0%, var(--parchment-alt) 100%);
}

/* --- Congress Section Specific --- */
.congress-content {
    padding-top: var(--space-xl) !important;
    padding-bottom: var(--space-xl) !important;
}

/* --- Scale-Hover on All Interactive Elements --- */
.archive-card,
.treaty-document,
.wax-seal,
.seal-stamp,
.nav-badge {
    will-change: transform;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .chamber-content {
        padding: var(--space-md) 24px;
    }

    .arrival-content {
        padding-left: var(--space-sm) !important;
        padding-bottom: var(--space-lg) !important;
    }

    .block-left,
    .block-right,
    .block-center {
        margin-left: 0;
        transform: none;
        max-width: 100%;
    }

    #sidebar {
        width: 36px;
    }

    .nav-badge {
        width: 22px;
        height: 22px;
    }

    .treaty-document {
        transform: none;
        margin: 0 8px;
    }

    .treaty-inner {
        padding: var(--space-md);
    }

    .postmark-watermark {
        font-size: 1.8rem;
        padding: 12px 20px;
    }

    .section-counter {
        font-size: clamp(3rem, 10vw, 6rem);
    }

    .display-title {
        font-size: clamp(1.8rem, 8vw, 3.5rem);
    }

    .departure-seals {
        gap: 6px;
    }

    .floating-seal {
        width: 36px;
        height: 36px;
        font-size: 1rem;
        margin: 0 4px;
    }
}

@media (max-width: 480px) {
    #sidebar {
        display: none;
    }

    .departure-seals {
        gap: 4px;
    }

    .floating-seal {
        margin: 0 2px;
    }

    .pull-quote {
        font-size: clamp(1.2rem, 4vw, 1.6rem);
    }

    .wax-seal {
        width: 44px;
        height: 44px;
        font-size: 1.1rem;
    }

    .treaty-seals {
        gap: 16px;
    }
}
