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

:root {
    --bg-primary: #1a1714;
    --bg-secondary: #2b2419;
    --bg-tertiary: #33291e;
    --accent-primary: #c4652a;
    --accent-secondary: #8b5e3c;
    --text-primary: #b5a48a;
    --text-secondary: #6d5d4a;
    --highlight: #d4a038;
    --border: #3d3429;
    --module-gap: clamp(2rem, 4vw, 5rem);
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 300;
    font-size: clamp(1rem, 1.8vw, 1.25rem);
    line-height: 1.75;
    letter-spacing: 0.01em;
    overflow-x: hidden;
}

.svg-defs {
    position: absolute;
    width: 0;
    height: 0;
}

/* === Typography === */
h1, h2 {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 400;
    letter-spacing: 0.04em;
    line-height: 1.08;
    color: var(--accent-primary);
}

h2 {
    font-size: clamp(1.6rem, 4vw, 3rem);
    margin-bottom: 1rem;
}

p {
    margin-bottom: 1em;
}

.drop-cap {
    font-family: 'Playfair Display', Georgia, serif;
    font-style: italic;
    font-size: clamp(3rem, 6vw, 5rem);
    float: left;
    line-height: 0.8;
    margin-right: 0.15em;
    margin-top: 0.05em;
    color: var(--highlight);
}

.module-meta {
    display: block;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 400;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--text-secondary);
    margin-bottom: 1.2rem;
}

.chamber-label {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 400;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--text-secondary);
    margin-bottom: var(--module-gap);
    padding-left: 5%;
}

.chamber-label span {
    color: var(--highlight);
    margin-right: 0.8em;
}

/* === Navigation Glyph === */
#nav-glyph {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 100;
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 400ms, transform 400ms;
}

#nav-glyph:hover {
    opacity: 1;
    transform: scale(1.1);
}

#nav-glyph svg {
    filter: drop-shadow(0 0 6px rgba(212, 160, 56, 0.3));
}

/* === Navigation Overlay === */
#nav-overlay {
    position: fixed;
    inset: 0;
    z-index: 99;
    background: rgba(26, 23, 20, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 600ms;
}

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

#nav-overlay nav {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    text-align: center;
}

.nav-label {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.nav-link {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: clamp(1.4rem, 3vw, 2.2rem);
    color: var(--text-primary);
    text-decoration: none;
    letter-spacing: 0.04em;
    transition: color 400ms;
}

.nav-link:hover {
    color: var(--highlight);
}

/* === Opening Void === */
.opening-void {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2rem;
}

.site-title {
    font-size: clamp(2.8rem, 7vw, 6.5rem);
    color: var(--accent-primary);
    opacity: 0;
    transition: opacity 3s ease;
}

.site-title.visible {
    opacity: 1;
}

.scroll-line {
    opacity: 0;
    transition: opacity 1s ease;
}

.scroll-line.visible {
    opacity: 1;
}

.scroll-line-path {
    stroke-dasharray: 120;
    stroke-dashoffset: 120;
    transition: stroke-dashoffset 2s ease;
}

.scroll-line-path.drawn {
    stroke-dashoffset: 0;
}

/* === Chambers === */
.chamber {
    padding: var(--module-gap) 5%;
    min-height: 80vh;
}

/* === Modules === */
.module {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    position: relative;
    transition: border-color 400ms, transform 400ms;
    background-image:
        linear-gradient(135deg, rgba(43, 36, 25, 0.3) 0%, rgba(51, 41, 30, 0.5) 50%, rgba(43, 36, 25, 0.3) 100%);
}

.module:hover {
    border-color: var(--accent-secondary);
    transform: translateY(-2px);
}

.module:hover .glyph {
    filter: drop-shadow(0 0 12px rgba(212, 160, 56, 0.5));
}

.module-inner {
    padding: clamp(1.5rem, 3vw, 3rem);
    position: relative;
}

/* Module reveal states */
.module, .module--full {
    opacity: 0;
    transition: opacity 800ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 800ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                border-color 400ms, box-shadow 400ms;
}

.module--from-left {
    transform: translateX(-20px);
}

.module--from-right {
    transform: translateX(20px);
}

.module--from-below {
    transform: translateY(20px);
}

.module.revealed {
    opacity: 1;
    transform: translate(0, 0);
}

.module.revealed:hover {
    transform: translateY(-2px);
}

/* === Archive Hall Grid === */
.module-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--module-gap);
    align-items: start;
}

.module--tall {
    grid-row: span 2;
    min-height: 400px;
}

.module--wide {
    grid-column: span 1;
}

.module--medium {
    min-height: 280px;
}

.module--narrow {
    min-height: 200px;
}

/* === Reading Room === */
.module--full {
    max-width: 90%;
    margin: 0 auto;
}

.codex-columns {
    column-count: 2;
    column-gap: 3rem;
    column-rule: 1px solid var(--border);
}

/* === Vault Cluster === */
.vault-cluster {
    display: grid;
    grid-template-columns: 60% 35%;
    gap: var(--module-gap);
    align-items: start;
}

.module--dominant {
    min-height: 450px;
}

.module--secondary {
    margin-top: 4rem;
    min-height: 300px;
}

.module--tiny {
    grid-column: 2;
    width: 65%;
    margin-left: auto;
    margin-top: -2rem;
    min-height: 160px;
    text-align: center;
}

.tiny-verse {
    font-family: 'Playfair Display', Georgia, serif;
    font-style: italic;
    font-size: clamp(1rem, 1.5vw, 1.15rem);
    line-height: 1.9;
    color: var(--text-primary);
}

/* === Glyphs === */
.glyph {
    transition: filter 400ms;
    filter: drop-shadow(0 0 6px rgba(212, 160, 56, 0.3));
}

.glyph-margin {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
}

/* === Ember Particles === */
#ember-container {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 200px;
    pointer-events: none;
    z-index: 50;
    overflow: hidden;
}

.ember {
    position: absolute;
    bottom: -10px;
    border-radius: 50%;
    background: var(--accent-primary);
    animation: ember-rise linear infinite;
}

@keyframes ember-rise {
    0% {
        transform: translateY(0) translateX(0);
        opacity: 0;
    }
    10% {
        opacity: var(--ember-opacity, 0.6);
    }
    90% {
        opacity: var(--ember-opacity, 0.6);
    }
    100% {
        transform: translateY(-200px) translateX(var(--ember-drift, 20px));
        opacity: 0;
    }
}

/* === Responsive === */
@media (max-width: 768px) {
    .module-grid {
        grid-template-columns: 1fr;
    }

    .module--tall {
        grid-row: span 1;
    }

    .vault-cluster {
        grid-template-columns: 1fr;
    }

    .module--secondary {
        margin-top: 0;
    }

    .module--tiny {
        grid-column: 1;
        width: 80%;
        margin-top: 0;
    }

    .codex-columns {
        column-count: 1;
    }

    .module--full {
        max-width: 100%;
    }
}
