:root {
    --umber: #1E1710;
    --parchment: #F2E8D5;
    --tallow: #C4954A;
    --seal: #8B3A2A;
    --ink: #3B2F1E;
    --dust: #8B7D6B;
    --char: #12100B;
    --flame: #D4A84B;
    --seal-dark: #6B2A1A;
    --candle-gold: #8B6914;
    --envelope: #E8DCC8;
}

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--umber);
    color: var(--ink);
    font-family: 'Source Serif 4', Georgia, 'Times New Roman', serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.15vw, 1.2rem);
    line-height: 1.72;
    letter-spacing: 0.005em;
    overflow-x: hidden;
}

/* ========== CANDLE FLICKER ========== */
@keyframes candleFlicker {
    0%   { opacity: 0.03; }
    25%  { opacity: 0.07; }
    50%  { opacity: 0.04; }
    75%  { opacity: 0.08; }
    100% { opacity: 0.03; }
}

@keyframes flameSway {
    0%   { d: path("M16 4 C16 4 20 9 20 12 C20 14.2 18.2 16 16 16 C13.8 16 12 14.2 12 12 C12 9 16 4 16 4Z"); }
    50%  { d: path("M16 3 C16 3 21 8 20 11 C19.5 13.8 18 15.5 16 15.5 C14 15.5 12.5 13 12 11 C11 8 16 3 16 3Z"); }
    100% { d: path("M16 4 C16 4 20 9 20 12 C20 14.2 18.2 16 16 16 C13.8 16 12 14.2 12 12 C12 9 16 4 16 4Z"); }
}

/* ========== NAV CANDLE ========== */
#nav-candle {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 1000;
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#nav-candle:hover {
    opacity: 1;
}

#nav-candle .candle-flame {
    animation: flameSway 3s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

/* ========== SIDE PANEL ========== */
#side-panel {
    position: fixed;
    top: 0;
    right: -320px;
    width: 320px;
    height: 100vh;
    background: var(--umber);
    border-left: 1px solid rgba(196, 149, 74, 0.2);
    z-index: 999;
    padding: 4rem 2rem 2rem;
    transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
}

#side-panel.open {
    right: 0;
}

#panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(18, 16, 11, 0.6);
    z-index: 998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

#panel-overlay.visible {
    opacity: 1;
    pointer-events: all;
}

.panel-title {
    font-family: 'Commissioner', 'Segoe UI', Tahoma, sans-serif;
    font-weight: 300;
    font-variant: small-caps;
    font-size: 0.85rem;
    letter-spacing: 0.12em;
    color: var(--dust);
    margin-bottom: 1.5rem;
}

#dispatch-list {
    list-style: none;
}

#dispatch-list li {
    padding: 0.75rem 0;
    border-bottom: 1px solid rgba(139, 125, 107, 0.15);
}

#dispatch-list li a {
    color: var(--tallow);
    text-decoration: none;
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    font-size: 0.85rem;
    letter-spacing: 0.02em;
    transition: color 0.3s;
}

#dispatch-list li a:hover {
    color: var(--flame);
}

#dispatch-list li .toc-date {
    display: block;
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    font-variant: small-caps;
    font-size: 0.75rem;
    letter-spacing: 0.12em;
    color: var(--dust);
    margin-top: 0.25rem;
}

/* ========== THE SEAL ========== */
#the-seal {
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--umber);
    position: relative;
    overflow: hidden;
}

#the-seal::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 50%, rgba(196, 149, 74, 0.08) 0%, transparent 70%);
    animation: candleFlicker 4s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    pointer-events: none;
}

.seal-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

#wax-seal {
    opacity: 0;
    transition: opacity 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

#wax-seal.visible {
    opacity: 1;
}

.site-title {
    font-family: 'Commissioner', 'Segoe UI', Tahoma, sans-serif;
    font-weight: 300;
    font-variant: small-caps;
    color: var(--tallow);
    letter-spacing: 0.2em;
    font-size: 0.9rem;
    opacity: 0;
    transition: opacity 1.2s cubic-bezier(0.4, 0, 0.2, 1) 0.4s;
}

#wax-seal.visible ~ .site-title {
    opacity: 1;
}

.scroll-hint {
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    font-size: 0.7rem;
    letter-spacing: 0.15em;
    color: var(--dust);
    opacity: 0;
    transition: opacity 1.2s cubic-bezier(0.4, 0, 0.2, 1) 0.8s;
    text-transform: lowercase;
}

#wax-seal.visible ~ .scroll-hint {
    opacity: 0.6;
}

/* Seal crack animation */
.seal-cracking #wax-seal {
    opacity: 1;
}

.seal-cracking .seal-piece {
    transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.seal-cracked .seal-container {
    opacity: 0;
    transition: opacity 0.4s;
    pointer-events: none;
}

/* ========== READING ROOM ========== */
#reading-room {
    max-width: 1200px;
    margin: 0 auto;
    padding: 4rem 1.5rem;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 1.5rem;
    background: var(--parchment);
    position: relative;
}

#reading-room::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 20%, rgba(196, 149, 74, 0.08) 0%, transparent 70%);
    animation: candleFlicker 4s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    pointer-events: none;
    z-index: 0;
}

/* ========== DISPATCH ========== */
.dispatch {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 1.5rem;
    position: relative;
    z-index: 1;
    opacity: 0;
    clip-path: inset(5% 5% 5% 5%);
    transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1), clip-path 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 3rem 0;
}

.dispatch.revealed {
    opacity: 1;
    clip-path: inset(0);
}

.dispatch-header {
    grid-column: 2 / 7;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.dispatch-seal svg {
    display: block;
    flex-shrink: 0;
}

.dispatch-date {
    font-family: 'Commissioner', 'Segoe UI', Tahoma, sans-serif;
    font-weight: 300;
    font-variant: small-caps;
    font-size: 0.85rem;
    letter-spacing: 0.12em;
    color: var(--dust);
}

.dispatch-title {
    grid-column: 1 / 9;
    font-family: 'Commissioner', 'Segoe UI', Tahoma, sans-serif;
    font-weight: 700;
    font-size: clamp(1.8rem, 3.5vw, 3rem);
    letter-spacing: 0.02em;
    line-height: 1.15;
    color: var(--ink);
    padding: 0.5rem 0;
}

.dispatch-body {
    grid-column: 2 / 7;
    color: #4A3F2F;
}

.dispatch-body p {
    margin-bottom: 1.25rem;
}

.dispatch-body p:first-child::first-letter {
    font-family: 'Commissioner', sans-serif;
    font-weight: 800;
    font-size: 4.5em;
    float: left;
    line-height: 0.8;
    margin-right: 0.08em;
    color: var(--candle-gold);
}

.dispatch-margin {
    grid-column: 7 / 9;
    align-self: start;
    padding-top: 1rem;
}

.dispatch:nth-child(odd) .dispatch-margin {
    grid-column: 7 / 9;
}

.dispatch:nth-child(even) .dispatch-margin {
    grid-column: 1 / 3;
    grid-row: 3 / 4;
}

.pull-quote {
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    font-style: italic;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--seal);
    border-left: 2px solid var(--tallow);
    padding-left: 1rem;
}

/* ========== INTERSTITIAL COLLAGE ========== */
.interstitial-collage {
    grid-column: 1 / -1;
    position: relative;
    height: 120px;
    z-index: 1;
    overflow: hidden;
}

.collage-postmark {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) rotate(-3deg);
    width: 80px;
    height: 80px;
    opacity: 0.4;
}

.collage-torn {
    position: absolute;
    left: 10%;
    top: 20%;
    width: 200px;
    height: 60px;
    background: var(--parchment);
    clip-path: polygon(0 0, 95% 5%, 100% 40%, 92% 100%, 5% 95%, 0 50%);
    opacity: 0.15;
    transform: rotate(-2deg);
}

.collage-torn.torn-right {
    left: auto;
    right: 10%;
    transform: rotate(2deg);
    clip-path: polygon(5% 0, 100% 10%, 95% 50%, 100% 100%, 8% 95%, 0 40%);
}

.collage-stamps {
    position: absolute;
    right: 20%;
    top: 30%;
    width: 100px;
    height: 80px;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 4px,
        rgba(196, 149, 74, 0.12) 4px,
        rgba(196, 149, 74, 0.12) 5px
    );
    transform: rotate(3deg);
}

.collage-stamps.stamps-alt {
    right: auto;
    left: 15%;
    transform: rotate(-1deg);
}

/* ========== ARCHIVE DRAWER ========== */
#archive-drawer {
    background: var(--char);
    padding: 5rem 2rem;
    position: relative;
}

#archive-drawer::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 20%, rgba(196, 149, 74, 0.06) 0%, transparent 60%);
    animation: candleFlicker 4s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    pointer-events: none;
}

.archive-title {
    font-family: 'Commissioner', 'Segoe UI', Tahoma, sans-serif;
    font-weight: 300;
    font-variant: small-caps;
    font-size: 0.85rem;
    letter-spacing: 0.12em;
    color: var(--dust);
    text-align: center;
    margin-bottom: 3rem;
    position: relative;
    z-index: 1;
}

.archive-envelopes {
    display: flex;
    justify-content: center;
    gap: 2.5rem;
    flex-wrap: wrap;
    max-width: 900px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.envelope {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    cursor: default;
}

.envelope-svg {
    width: 180px;
    height: 120px;
    display: block;
}

.envelope-flap {
    transform-origin: top center;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.envelope:hover .envelope-flap {
    transform: rotateX(180deg);
}

.envelope-headline {
    font-family: 'Commissioner', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.02em;
    color: transparent;
    text-align: center;
    max-width: 180px;
    transition: color 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.envelope:hover .envelope-headline {
    color: var(--tallow);
}

/* ========== COLOPHON ========== */
#colophon {
    background: var(--char);
    padding: 3rem 2rem;
    text-align: center;
    border-top: 1px solid rgba(139, 125, 107, 0.15);
}

.colophon-text {
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    font-variant: small-caps;
    font-size: 0.75rem;
    letter-spacing: 0.12em;
    color: var(--dust);
    margin-bottom: 0.5rem;
}

/* ========== REDUCED MOTION ========== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition-duration: 0.01s !important;
    }

    .dispatch {
        opacity: 1;
        clip-path: none;
    }
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    #reading-room {
        grid-template-columns: 1fr;
        padding: 2rem 1rem;
    }

    .dispatch {
        display: block;
        padding: 2rem 0;
    }

    .dispatch-header {
        margin-bottom: 0.75rem;
    }

    .dispatch-title {
        margin-bottom: 1rem;
    }

    .dispatch-margin {
        margin-top: 1.5rem;
    }

    .dispatch-body {
        grid-column: 1;
    }

    .archive-envelopes {
        gap: 1.5rem;
    }

    .envelope-svg {
        width: 140px;
        height: 93px;
    }

    #side-panel {
        width: 280px;
        right: -280px;
    }
}
