/* ============================================
   diplomacy.boo - Spectral Parlor Stylesheet
   ============================================ */

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

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

body {
    background-color: #0d0805;
    color: #c8b898;
    font-family: 'Crimson Pro', Georgia, serif;
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    line-height: 1.85;
    overflow-x: hidden;
    min-height: 100vh;
    cursor: default;
}

/* --- Background: Wood Grain Table Surface --- */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        repeating-linear-gradient(
            175deg,
            #1a0e08 0px,
            #1a0e08 2px,
            #1c1009 2px,
            #1c1009 4px,
            #1a0e08 4px,
            #1a0e08 8px,
            #19100a 8px,
            #19100a 9px,
            #1a0e08 9px,
            #1a0e08 15px,
            #1b0f09 15px,
            #1b0f09 16px
        );
    z-index: -2;
    pointer-events: none;
}

/* --- Grain/Noise Overlay --- */
#grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.03;
    z-index: 1000;
    pointer-events: none;
    background-image: 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.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    background-repeat: repeat;
}

/* --- Vignette Frame (Circular Table Edge) --- */
#vignette {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(
        ellipse at 50% 50%,
        transparent 35%,
        rgba(26, 14, 8, 0.4) 55%,
        rgba(26, 14, 8, 0.75) 70%,
        #1a0e08 90%
    );
    z-index: 100;
    pointer-events: none;
}

/* --- Opening Overlay (Darkness) --- */
#opening-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #0d0805;
    z-index: 9999;
    transition: opacity 1.5s ease-out;
    pointer-events: none;
}

#opening-overlay.fading {
    opacity: 0;
}

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

/* --- Candle Glow Layer --- */
#candle-glow {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(
        ellipse at 50% 40%,
        rgba(232, 168, 50, 0.12) 0%,
        rgba(232, 168, 50, 0.06) 20%,
        rgba(232, 168, 50, 0.02) 35%,
        transparent 50%
    );
    z-index: 99;
    pointer-events: none;
    opacity: 0;
    transition: opacity 2s ease-in;
    animation: candleFlicker1 3s ease-in-out infinite,
               candleFlicker2 5s ease-in-out infinite,
               candleFlicker3 7s ease-in-out infinite;
}

#candle-glow.visible {
    opacity: 1;
}

@keyframes candleFlicker1 {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

@keyframes candleFlicker2 {
    0%, 100% { opacity: 0.85; }
    33% { opacity: 1; }
    66% { opacity: 0.92; }
}

@keyframes candleFlicker3 {
    0%, 100% { transform: scale(0.98); }
    50% { transform: scale(1.03); }
}

/* --- Compass Rose --- */
#compass-rose-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 200px;
    height: 200px;
    z-index: 500;
    opacity: 0;
    pointer-events: none;
    transition: all 1.5s ease-in-out;
}

#compass-rose-container.visible {
    opacity: 1;
}

#compass-rose-container.resting {
    top: 15%;
    width: 120px;
    height: 120px;
    opacity: 0.7;
}

#compass-rose {
    width: 100%;
    height: 100%;
}

/* Compass spoke draw animation */
.compass-spoke {
    stroke-dasharray: 90;
    stroke-dashoffset: 90;
    transition: stroke-dashoffset 2.5s ease-out;
}

.compass-spoke.drawn {
    stroke-dashoffset: 0;
}

.compass-point {
    opacity: 0;
    transition: opacity 1s ease-in 2s;
}

.compass-point.visible {
    opacity: 0.8;
}

/* Compass needle slow searching rotation */
#compass-needle {
    animation: needleSearch 20s ease-in-out infinite;
    transform-origin: center center;
}

@keyframes needleSearch {
    0% { transform: translate(100px, 100px) rotate(0deg) translate(-100px, -100px); }
    15% { transform: translate(100px, 100px) rotate(12deg) translate(-100px, -100px); }
    20% { transform: translate(100px, 100px) rotate(10deg) translate(-100px, -100px); }
    35% { transform: translate(100px, 100px) rotate(-8deg) translate(-100px, -100px); }
    40% { transform: translate(100px, 100px) rotate(-5deg) translate(-100px, -100px); }
    55% { transform: translate(100px, 100px) rotate(15deg) translate(-100px, -100px); }
    65% { transform: translate(100px, 100px) rotate(5deg) translate(-100px, -100px); }
    80% { transform: translate(100px, 100px) rotate(-10deg) translate(-100px, -100px); }
    90% { transform: translate(100px, 100px) rotate(-3deg) translate(-100px, -100px); }
    100% { transform: translate(100px, 100px) rotate(0deg) translate(-100px, -100px); }
}

/* --- Main Table Surface --- */
#table-surface {
    position: relative;
    z-index: 50;
    padding: 20vh 0 10vh;
    max-width: 100vw;
}

/* --- Table Sections (Scattered Layout) --- */
.table-section {
    position: relative;
    min-height: 80vh;
    padding: 5vh 0;
}

/* --- Envelope Container --- */
.envelope-container {
    position: relative;
    width: clamp(320px, 55vw, 700px);
    margin-left: 15%;
    padding: 3rem 2.5rem 2.5rem;
    background: linear-gradient(
        170deg,
        rgba(26, 14, 8, 0.85) 0%,
        rgba(26, 14, 8, 0.7) 100%
    );
    border: 1px solid rgba(138, 122, 90, 0.15);
    clip-path: polygon(0 6%, 50% 0, 100% 6%, 100% 100%, 0 100%);
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 1s ease-out, transform 1s ease-out;
}

.envelope-container.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* Alternate positioning for scattered layout */
.table-section:nth-child(odd) .envelope-container {
    margin-left: auto;
    margin-right: 10%;
}

.table-section:nth-child(even) .envelope-container {
    margin-left: 10%;
    margin-right: auto;
}

/* Envelope flap */
.envelope-flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 6%;
    background: rgba(26, 14, 8, 0.9);
    clip-path: polygon(0 0, 50% 100%, 100% 0);
    transform-origin: top center;
    transition: transform 0.8s ease-in-out;
    z-index: 2;
}

.envelope-container.revealed .envelope-flap {
    transform: rotateX(180deg);
    opacity: 0.3;
}

/* --- Wax Seals --- */
.wax-seal {
    position: absolute;
    z-index: 5;
    border-radius: 50%;
    box-shadow:
        inset 0 2px 4px rgba(107, 26, 26, 0.6),
        0 3px 8px rgba(107, 26, 26, 0.4),
        0 0 15px rgba(107, 26, 26, 0.2);
    transition: transform 0.5s ease-out, opacity 0.5s ease-out;
}

.seal-large svg {
    width: 120px;
    height: 120px;
}

.seal-medium {
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
}

.seal-medium svg {
    width: 60px;
    height: 60px;
}

.seal-small svg {
    width: 24px;
    height: 24px;
}

.envelope-container.revealed .wax-seal.seal-medium {
    transform: translateX(-50%) scale(1.1);
    opacity: 0.7;
}

/* --- Envelope Content --- */
.envelope-content {
    opacity: 0;
    transition: opacity 0.8s ease-in 0.8s;
}

.envelope-container.revealed .envelope-content {
    opacity: 1;
}

/* --- Typography --- */
.section-title {
    font-family: 'Cinzel Decorative', 'Cinzel', serif;
    font-size: clamp(2rem, 5vw, 4.5rem);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: #d4a04a;
    margin-bottom: 2rem;
    line-height: 1.2;
}

.dispatch-text {
    font-family: 'Crimson Pro', Georgia, serif;
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    line-height: 1.85;
    color: #c8b898;
    margin-bottom: 1.5rem;
    max-width: 60ch;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.envelope-container.revealed .dispatch-text {
    opacity: 1;
    transform: translateY(0);
}

.envelope-container.revealed .dispatch-text:nth-child(2) {
    transition-delay: 1s;
}

.envelope-container.revealed .dispatch-text:nth-child(3) {
    transition-delay: 1.2s;
}

.annotation {
    font-family: 'IM Fell English', Georgia, serif;
    font-style: italic;
    font-size: 0.85rem;
    color: #8a7a5a;
    opacity: 0;
    display: block;
    margin-top: 1.5rem;
    transition: opacity 0.8s ease-in 1.5s;
    border-left: 2px solid #4a6b5a;
    padding-left: 0.8rem;
}

.envelope-container.revealed .annotation {
    opacity: 0.8;
}

/* --- Ritual Silence Gaps --- */
.ritual-gap {
    position: relative;
    min-height: 45vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gap-seal {
    position: relative;
    opacity: 0.5;
}

/* --- Margin Decorative Objects --- */
.margin-object {
    position: absolute;
    opacity: 0;
    transition: opacity 1.5s ease-out;
    pointer-events: none;
}

.margin-object.visible {
    opacity: 0.6;
}

/* Wax drip shapes */
.wax-drip {
    width: 12px;
    height: 18px;
    background: radial-gradient(ellipse at 50% 30%, #d4a04a, #6b1a1a);
    border-radius: 50% 50% 50% 50% / 30% 30% 70% 70%;
}

.wax-drip:nth-child(even) {
    width: 10px;
    height: 15px;
    transform: rotate(15deg);
}

.wax-drip:nth-child(3n) {
    width: 14px;
    height: 20px;
    transform: rotate(-10deg);
}

/* Ring stain - verdigris patina on old bronze */
.ring-stain {
    width: 40px;
    height: 40px;
    border: 1px solid rgba(74, 107, 90, 0.3);
    border-radius: 50%;
    background: radial-gradient(
        circle,
        transparent 60%,
        rgba(74, 107, 90, 0.08) 100%
    );
    /* #4a6b5a verdigris patina */
}

/* Quill nib */
.quill-nib {
    width: 3px;
    height: 25px;
    background: linear-gradient(to bottom, #d4a04a, #8a7a5a);
    transform: rotate(-30deg);
    border-radius: 0 0 50% 50%;
}

.quill-nib::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: -2px;
    width: 7px;
    height: 5px;
    background: #d4a04a;
    clip-path: polygon(50% 100%, 0 0, 100% 0);
}

/* --- Section Terminus --- */
.section-terminus {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 15vh 0 10vh;
    gap: 2rem;
}

.terminus-text {
    text-align: center;
    display: block;
    margin-top: 1rem;
}

/* --- Planchette Navigation Trigger --- */
#planchette {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 60px;
    z-index: 2000;
    cursor: pointer;
    opacity: 0;
    transition: opacity 1s ease-in 4s, transform 0.2s ease-out;
    filter: drop-shadow(0 0 10px rgba(232, 168, 50, 0.2));
}

#planchette.visible {
    opacity: 0.8;
}

#planchette:hover {
    opacity: 1;
    filter: drop-shadow(0 0 20px rgba(232, 168, 50, 0.4));
}

#planchette:hover #planchette-lens {
    opacity: 0.6;
}

/* --- Spirit Board Radial Navigation --- */
#spirit-board-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease-out;
}

#spirit-board-nav.active {
    pointer-events: all;
    opacity: 1;
}

#spirit-board-nav.hidden {
    pointer-events: none;
}

.spirit-board-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(
        circle at center,
        rgba(13, 8, 5, 0.85) 0%,
        rgba(13, 8, 5, 0.95) 100%
    );
}

.spirit-board-letters {
    position: relative;
    width: 300px;
    height: 300px;
}

.spirit-letter {
    position: absolute;
    top: 50%;
    left: 50%;
    font-family: 'Uncial Antiqua', 'Cinzel', serif;
    font-size: 1.1rem;
    letter-spacing: 0.15em;
    color: #c8b898;
    text-decoration: none;
    white-space: nowrap;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.3s ease-out, transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), color 0.3s ease;
}

#spirit-board-nav.active .spirit-letter {
    opacity: 1;
}

.spirit-letter:hover {
    color: #e8a832;
    text-shadow: 0 0 20px rgba(232, 168, 50, 0.4);
}

.spirit-letter.active-section {
    color: #e8a832;
}

/* Position letters in a circle */
.spirit-letter[data-angle="0"] {
    transform: translate(-50%, -50%) translateY(-130px);
}

.spirit-letter[data-angle="72"] {
    transform: translate(-50%, -50%) translate(124px, -40px);
}

.spirit-letter[data-angle="144"] {
    transform: translate(-50%, -50%) translate(76px, 105px);
}

.spirit-letter[data-angle="216"] {
    transform: translate(-50%, -50%) translate(-76px, 105px);
}

.spirit-letter[data-angle="288"] {
    transform: translate(-50%, -50%) translate(-124px, -40px);
}

/* Default state (collapsed to center) */
#spirit-board-nav:not(.active) .spirit-letter[data-angle="0"],
#spirit-board-nav:not(.active) .spirit-letter[data-angle="72"],
#spirit-board-nav:not(.active) .spirit-letter[data-angle="144"],
#spirit-board-nav:not(.active) .spirit-letter[data-angle="216"],
#spirit-board-nav:not(.active) .spirit-letter[data-angle="288"] {
    transform: translate(-50%, -50%);
    opacity: 0;
}

/* Stagger animation delays for radial expansion */
#spirit-board-nav.active .spirit-letter[data-angle="0"] { transition-delay: 0ms; }
#spirit-board-nav.active .spirit-letter[data-angle="72"] { transition-delay: 30ms; }
#spirit-board-nav.active .spirit-letter[data-angle="144"] { transition-delay: 60ms; }
#spirit-board-nav.active .spirit-letter[data-angle="216"] { transition-delay: 90ms; }
#spirit-board-nav.active .spirit-letter[data-angle="288"] { transition-delay: 120ms; }

/* --- Hover Glow Effect (replaces standard hover) --- */
a:hover,
.envelope-container:hover {
    box-shadow: 0 0 20px rgba(232, 168, 50, 0.08);
}

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

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

::-webkit-scrollbar-thumb {
    background: #8a7a5a;
    border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
    background: #d4a04a;
}

/* --- Selection Color --- */
::selection {
    background: rgba(212, 160, 74, 0.3);
    color: #e8e0d0;
}

/* --- Responsive Adjustments --- */
@media (max-width: 768px) {
    .envelope-container {
        width: 90vw;
        margin-left: 5% !important;
        margin-right: 5% !important;
        padding: 2rem 1.5rem 1.5rem;
    }

    .section-title {
        font-size: clamp(1.5rem, 8vw, 2.5rem);
        letter-spacing: 0.1em;
    }

    .margin-object {
        display: none;
    }

    .ritual-gap {
        min-height: 30vh;
    }

    #compass-rose-container {
        width: 140px;
        height: 140px;
    }

    #compass-rose-container.resting {
        width: 80px;
        height: 80px;
    }

    .spirit-board-letters {
        width: 250px;
        height: 250px;
    }

    .spirit-letter[data-angle="0"] {
        transform: translate(-50%, -50%) translateY(-100px);
    }

    .spirit-letter[data-angle="72"] {
        transform: translate(-50%, -50%) translate(95px, -31px);
    }

    .spirit-letter[data-angle="144"] {
        transform: translate(-50%, -50%) translate(59px, 81px);
    }

    .spirit-letter[data-angle="216"] {
        transform: translate(-50%, -50%) translate(-59px, 81px);
    }

    .spirit-letter[data-angle="288"] {
        transform: translate(-50%, -50%) translate(-95px, -31px);
    }

    .spirit-letter {
        font-size: 0.9rem;
    }
}
