/* ============================================================
   archaic.works — Iron Gall & Gold Leaf
   A dark-academia scriptorium manuscript scroll
   ============================================================ */

/* --- Color Palette: Iron Gall & Gold Leaf --- */

:root {
    --lamp-black: #0D0B08;
    --dark-umber: #1A1510;
    --raw-umber: #3D2B1F;
    --aged-parchment: #D4C8B0;
    --aged-gold: #C8A96E;
    --tarnished-brass: #A89274;
    --faded-ink: #8B7355;
    --dark-sienna: #6B5B4A;
    --verdigris: #4A8B6F;
    --warm-candlelight: #F5DEB3;
}

/* --- Reset & Base --- */

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

html {
    scroll-behavior: smooth;
    background-color: #0D0B08;
    color: #D4C8B0;
    font-size: 16px;
}

body {
    font-family: 'Source Serif 4', 'Georgia', serif;
    font-weight: 400;
    line-height: 1.75;
    background-color: #0D0B08;
    overflow-x: hidden;
    position: relative;
}

/* --- Grain Texture Overlay --- */

#grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.05;
    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%3C/filter%3E%3Crect width='256' height='256' filter='url(%23noise)' opacity='1'/%3E%3C/svg%3E");
    background-size: 256px 256px;
}

/* --- Candlelight Vignette --- */

#vignette-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
    background: radial-gradient(ellipse 70% 60% at 50% 35%, transparent 0%, rgba(13,11,8,0.3) 50%, rgba(13,11,8,0.85) 100%);
    transition: opacity 1.5s ease;
}

#vignette-overlay.guttering {
    background: radial-gradient(ellipse 40% 30% at 50% 35%, transparent 0%, rgba(13,11,8,0.5) 40%, rgba(13,11,8,0.95) 100%);
}

/* --- Fixed Folio Indicator --- */

#folio-indicator {
    position: fixed;
    left: 2vw;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1001;
    font-family: 'Cinzel', serif;
    font-weight: 400;
    font-size: 0.75rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #6B5B4A;
    mix-blend-mode: difference;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 1s ease 3s;
}

#folio-indicator.visible {
    opacity: 1;
}

.folio-separator {
    font-size: 0.6rem;
    opacity: 0.6;
}

/* --- Folio Sections (General) --- */

.folio {
    min-height: 100vh;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.folio-content,
.artifact-container,
.artifact-caption,
.artifact-subcaption,
.colophon-content {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 600ms ease, transform 600ms ease;
}

.folio.in-view .folio-content,
.folio.in-view .artifact-container,
.folio.in-view .artifact-caption,
.folio.in-view .artifact-subcaption,
.folio.in-view .colophon-content {
    opacity: 1;
    transform: translateY(0);
}

/* --- FOLIO I: Title --- */

.folio-title {
    flex-direction: column;
    background-color: #0D0B08;
}

.folio-title .folio-inner {
    text-align: center;
    opacity: 0;
}

.folio-title.loaded .folio-inner {
    opacity: 1;
}

.site-title {
    font-family: 'Cinzel', serif;
    font-weight: 700;
    font-size: clamp(3rem, 8vw, 6rem);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: #C8A96E;
    opacity: 0;
    transition: opacity 1.5s ease;
    margin-bottom: 0.5em;
}

.folio-title.loaded .site-title {
    opacity: 1;
}

.site-subtitle {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1rem, 2.5vw, 1.5rem);
    color: #A89274;
    letter-spacing: 0.06em;
    opacity: 0;
    transition: opacity 1.2s ease;
}

.folio-title.loaded .site-subtitle {
    opacity: 1;
    transition-delay: 0.8s;
}

.scroll-invite {
    font-family: 'Cinzel', serif;
    font-size: 1.5rem;
    color: #6B5B4A;
    position: absolute;
    bottom: 8vh;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    animation: none;
}

.folio-title.loaded .scroll-invite {
    opacity: 1;
    animation: pulse-glow 2.5s ease-in-out infinite;
    animation-delay: 3s;
    transition: opacity 1s ease 3s;
}

@keyframes pulse-glow {
    0%, 100% { opacity: 0.4; transform: translateX(-50%) translateY(0); }
    50% { opacity: 1; transform: translateX(-50%) translateY(6px); }
}

/* --- Text Folios --- */

.folio-text {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    padding: 10vh 4vw;
    background-color: #1A1510;
    position: relative;
}

/* --- Ruled Margin --- */

.ruled-margin {
    width: 15%;
    min-width: 140px;
    max-width: 200px;
    padding-right: 2rem;
    border-right: 1px solid rgba(61,43,31,0.3);
    flex-shrink: 0;
    position: relative;
    align-self: stretch;
    padding-top: 2rem;
}

.folio-number {
    font-family: 'Cinzel', serif;
    font-weight: 400;
    font-size: 0.85rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #6B5B4A;
    display: block;
    margin-bottom: 1rem;
}

.margin-date {
    font-family: 'Cinzel', serif;
    font-weight: 400;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    color: #6B5B4A;
    display: block;
    margin-bottom: 1.5rem;
}

.margin-annotation {
    font-family: 'IM Fell English', serif;
    font-weight: 400;
    font-style: italic;
    font-size: 0.75rem;
    line-height: 1.6;
    color: #8B7355;
    letter-spacing: 0.02em;
    overflow: hidden;
}

.margin-annotation em {
    font-style: normal;
    color: #A89274;
}

/* Typewriter effect for annotations */
.margin-annotation .typewriter-text {
    display: inline;
}

.margin-annotation.typing .typewriter-char {
    opacity: 0;
}

.margin-annotation.typing .typewriter-char.revealed {
    opacity: 1;
}

/* --- Reading Column --- */

.reading-column {
    max-width: 55ch;
    width: 100%;
    padding: 2rem 0 2rem 3rem;
    position: relative;
}

.ruled-lines-bg {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: repeating-linear-gradient(
        to bottom,
        transparent,
        transparent calc(1.75rem * 1 - 1px),
        rgba(61,43,31,0.08) calc(1.75rem * 1 - 1px),
        rgba(61,43,31,0.08) calc(1.75rem * 1)
    );
    pointer-events: none;
    opacity: 0;
    transition: opacity 600ms ease;
}

.folio-text.in-view .ruled-lines-bg {
    opacity: 1;
}

.folio-content p {
    font-family: 'Source Serif 4', 'Georgia', serif;
    font-weight: 400;
    font-size: 1rem;
    line-height: 1.75;
    color: #D4C8B0;
}

.folio-content p + p {
    text-indent: 1.5em;
}

.folio-content p em {
    font-style: italic;
    color: #F5DEB3;
}

/* --- Illuminated Drop Capital --- */

.drop-cap {
    float: left;
    font-family: 'Cinzel', serif;
    font-weight: 700;
    font-size: 4em;
    line-height: 0.8;
    padding-right: 0.08em;
    padding-top: 0.05em;
    background: radial-gradient(circle at 50% 50%, #C8A96E 30%, #8B7355 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 8px rgba(200,169,110,0.3));
    shape-outside: margin-box;
}

.has-drop-cap {
    text-indent: 0 !important;
}

/* --- Fleuron Dividers --- */

.fleuron-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2em;
    padding: 2rem 0;
    position: relative;
    background-color: #1A1510;
}

.fleuron-divider::before,
.fleuron-divider::after {
    content: '';
    flex: 1;
    max-width: 200px;
    height: 1px;
    background-color: rgba(61,43,31,0.4);
}

.fleuron {
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    color: #6B5B4A;
}

/* --- Exhibition Folios --- */

.folio-exhibition {
    flex-direction: column;
    background-color: #0D0B08;
    padding: 6vh 4vw;
    position: relative;
    overflow: hidden;
}

.exhibition-spotlight {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -55%);
    width: 500px;
    height: 500px;
    background: radial-gradient(ellipse at center, rgba(245,222,179,0.06) 0%, rgba(200,169,110,0.03) 30%, transparent 70%);
    pointer-events: none;
}

.artifact-container {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 3rem;
    position: relative;
    z-index: 1;
}

.artifact-svg {
    width: auto;
    height: 40vh;
    max-height: 300px;
}

.artifact-path {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: none;
}

.folio-exhibition.in-view .artifact-path {
    animation: draw-artifact 2s ease-in-out forwards;
}

@keyframes draw-artifact {
    to {
        stroke-dashoffset: 0;
    }
}

.artifact-caption {
    font-family: 'Cinzel', serif;
    font-weight: 400;
    font-size: 1rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #C8A96E;
    text-align: center;
    margin-bottom: 0.5rem;
    position: relative;
    z-index: 1;
}

.artifact-subcaption {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 400;
    font-style: italic;
    font-size: 0.9rem;
    color: #A89274;
    text-align: center;
    letter-spacing: 0.04em;
    position: relative;
    z-index: 1;
}

/* --- Colophon --- */

.folio-colophon {
    flex-direction: column;
    background-color: #1A1510;
    padding: 10vh 4vw;
}

.colophon-content {
    text-align: center;
    max-width: 45ch;
}

.colophon-text {
    font-family: 'IM Fell English', serif;
    font-weight: 400;
    font-style: italic;
    font-size: 0.95rem;
    line-height: 2.0;
    color: #8B7355;
    margin-bottom: 1.5rem;
}

.colophon-fleuron {
    font-family: 'Cinzel', serif;
    font-size: 1.5rem;
    color: #6B5B4A;
    margin-top: 2rem;
}

/* --- Headings (used in text folios if needed) --- */

h2, h3 {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    color: #C8A96E;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: clamp(2rem, 5vw, 4.5rem);
    margin-bottom: 1rem;
}

h3 {
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.2rem, 3vw, 2rem);
    color: #A89274;
    text-transform: none;
}

/* --- Links --- */

a {
    color: #C8A96E;
    text-decoration: none;
    border-bottom: 1px solid rgba(200,169,110,0.3);
    transition: color 0.3s ease, border-color 0.3s ease;
}

a:hover {
    color: #4A8B6F;
    border-bottom-color: #4A8B6F;
}

/* --- Selection --- */

::selection {
    background-color: rgba(74,139,111,0.3);
    color: #F5DEB3;
}

/* --- Prefers Reduced Motion --- */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .folio-content,
    .artifact-container,
    .artifact-caption,
    .artifact-subcaption,
    .colophon-content {
        opacity: 1;
        transform: none;
    }

    .folio-title .folio-inner,
    .site-title,
    .site-subtitle,
    .scroll-invite {
        opacity: 1;
    }

    .artifact-path {
        stroke-dasharray: none;
        stroke-dashoffset: 0;
    }

    .ruled-lines-bg {
        opacity: 1;
    }

    #folio-indicator {
        opacity: 1;
    }
}

/* --- Responsive: Mobile --- */

@media screen and (max-width: 768px) {
    .folio-text {
        flex-direction: column;
        padding: 6vh 5vw;
    }

    .ruled-margin {
        width: 100%;
        min-width: unset;
        max-width: unset;
        border-right: none;
        border-bottom: 1px solid rgba(61,43,31,0.3);
        padding-right: 0;
        padding-bottom: 1.5rem;
        margin-bottom: 1.5rem;
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem 1.5rem;
        align-items: baseline;
        padding-top: 0;
    }

    .margin-annotation {
        width: 100%;
        font-size: 0.7rem;
    }

    .folio-number, .margin-date {
        margin-bottom: 0;
    }

    .reading-column {
        padding: 0;
        max-width: 100%;
    }

    #folio-indicator {
        left: 3vw;
        font-size: 0.65rem;
    }

    .site-title {
        letter-spacing: 0.1em;
    }

    .drop-cap {
        font-size: 3em;
    }

    .exhibition-spotlight {
        width: 300px;
        height: 300px;
    }

    .artifact-svg {
        max-height: 220px;
    }
}

@media screen and (max-width: 480px) {
    .ruled-margin {
        display: none;
    }

    .reading-column {
        padding: 0 1vw;
    }

    #folio-indicator {
        display: none;
    }
}
