/* lowest.dev - Dark Academia Scholarly Design */
/* Colors: #1a1410 #e8d5b7 #c4b097 #8b7355 #a67c52 #2d2318 #f0e6d3 #8c4a2f */

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

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

body {
    background: #1a1410;
    color: #c4b097;
    font-family: 'Lora', Georgia, serif;
    font-size: 18px;
    font-weight: 400;
    line-height: 1.75;
    letter-spacing: 0.005em;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Noise texture overlay */
.noise-svg {
    position: absolute;
    width: 0;
    height: 0;
}

.noise-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.04;
    filter: url(#noiseFilter);
    background: #8b7355;
}

/* Reading lamp cursor follow */
#reading-lamp {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 999;
    background: radial-gradient(circle 200px at 50% 50%, rgba(232, 213, 183, 0.08) 0%, transparent 100%);
    transition: background 0.1s ease-out;
    will-change: background;
}

#reading-lamp.expanded {
    background: radial-gradient(circle 300px at var(--lamp-x, 50%) var(--lamp-y, 50%), rgba(232, 213, 183, 0.12) 0%, transparent 100%);
}

/* Scroll progress indicator */
#scroll-progress {
    position: fixed;
    top: 0;
    right: 0;
    width: 3px;
    height: 100vh;
    background: rgba(139, 115, 85, 0.15);
    z-index: 998;
}

#scroll-progress-fill {
    width: 100%;
    height: 0%;
    background: linear-gradient(to bottom, #a67c52, #8c4a2f);
    transition: height 0.15s ease-out;
    border-radius: 0 0 2px 2px;
}

/* Compass rose navigation */
#compass-nav {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 997;
}

.compass-icon {
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.compass-icon:hover {
    opacity: 1;
    transform: rotate(15deg);
}

.compass-menu {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 140px;
    height: 140px;
    margin-top: -70px;
    margin-left: -70px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.compass-menu.open {
    opacity: 1;
    pointer-events: auto;
}

.compass-link {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    text-decoration: none;
    transition: all 0.3s ease;
}

.compass-link .numeral {
    font-family: 'Playfair Display', serif;
    font-size: 14px;
    font-weight: 700;
    color: #a67c52;
    font-variant: small-caps;
    transition: color 0.3s ease, text-shadow 0.3s ease;
}

.compass-link:hover .numeral,
.compass-link.active .numeral {
    color: #e8d5b7;
    text-shadow: 0 0 12px rgba(166, 124, 82, 0.5);
}

.compass-link:nth-child(1) { top: -10px; left: 50%; transform: translateX(-50%); }
.compass-link:nth-child(2) { top: 20px; right: -10px; }
.compass-link:nth-child(3) { top: 60px; right: -16px; }
.compass-link:nth-child(4) { top: 100px; right: -10px; }
.compass-link:nth-child(5) { bottom: -10px; left: 50%; transform: translateX(-50%); }

/* Left margin ruling line */
.margin-rule {
    position: fixed;
    top: 0;
    left: 12vw;
    width: 1px;
    height: 100vh;
    background: rgba(139, 115, 85, 0.3);
    z-index: 2;
    pointer-events: none;
}

/* Watermark symbols */
.watermark-symbols {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 500vh;
    pointer-events: none;
    z-index: 1;
}

.watermark {
    position: absolute;
    font-size: 72px;
    color: #8b7355;
    opacity: 0.05;
    font-family: 'Lora', serif;
    will-change: transform;
}

/* Canvas particles */
#candle-particles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 996;
}

/* Cartographic grid overlay */
#cartographic-grid {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 3;
    opacity: 0;
    background-image:
        repeating-linear-gradient(0deg, rgba(139, 115, 85, 0.08) 0px, rgba(139, 115, 85, 0.08) 1px, transparent 1px, transparent 120px),
        repeating-linear-gradient(90deg, rgba(139, 115, 85, 0.08) 0px, rgba(139, 115, 85, 0.08) 1px, transparent 1px, transparent 120px);
    transition: opacity 0.3s ease;
}

#cartographic-grid.flash {
    animation: gridFlash 2.6s ease forwards;
}

@keyframes gridFlash {
    0% { opacity: 0; }
    12% { opacity: 0.1; }
    70% { opacity: 0.1; }
    100% { opacity: 0; }
}

/* Main folio */
#folio {
    position: relative;
    z-index: 5;
}

/* Chapter sections */
.chapter {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    padding: 80px 0;
    transition: filter 0.3s ease, opacity 0.3s ease;
}

/* Chapter background numeral - palimpsest */
.chapter-bg-numeral {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Cormorant Garamond', serif;
    font-size: clamp(150px, 20vw, 200px);
    font-weight: 600;
    color: #a67c52;
    opacity: 0.06;
    pointer-events: none;
    z-index: 0;
    line-height: 1;
}

/* Margin labels */
.margin-label {
    position: absolute;
    top: 80px;
    left: calc(12vw - 120px);
    width: 100px;
    text-align: right;
    z-index: 6;
}

.annotation {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0.02em;
    color: #8b7355;
    font-style: italic;
    display: block;
}

.margin-tick {
    display: block;
    width: 8px;
    height: 1px;
    background: #8b7355;
    opacity: 0.5;
    margin-left: auto;
    margin-top: 8px;
}

/* Chapter content area */
.chapter-content {
    position: relative;
    width: 66%;
    max-width: 720px;
    margin-left: 17%;
    padding-left: 3%;
    padding-right: 3%;
    z-index: 6;
}

/* Odd chapters shifted slightly right, even slightly left */
.chapter:nth-child(odd) .chapter-content {
    margin-left: 18%;
}

.chapter:nth-child(even) .chapter-content {
    margin-left: 15%;
}

/* Manuscript ruling lines behind text */
.manuscript-ruling {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 30px,
        rgba(139, 115, 85, 0.04) 30px,
        rgba(139, 115, 85, 0.04) 31px
    );
    clip-path: inset(0 100% 0 0);
    transition: clip-path 0.8s ease-out;
}

.manuscript-ruling.revealed {
    clip-path: inset(0 0 0 0);
}

/* Drop cap */
.drop-cap-line {
    position: relative;
    margin-bottom: 32px;
}

.drop-cap {
    font-family: 'Cormorant Garamond', serif;
    font-size: clamp(100px, 10vw, 140px);
    font-weight: 600;
    color: #a67c52;
    float: left;
    line-height: 0.8;
    margin-right: 12px;
    margin-top: 8px;
    text-shadow: 0 2px 8px rgba(166, 124, 82, 0.3);
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease-out 0.2s, transform 0.6s ease-out 0.2s, text-shadow 0.6s ease-out 0.2s;
}

.drop-cap.visible {
    opacity: 1;
    transform: translateY(0);
    text-shadow: 0 4px 16px rgba(166, 124, 82, 0.5);
}

/* Chapter titles */
.chapter-title {
    font-family: 'Playfair Display', serif;
    font-size: clamp(36px, 5vw, 64px);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.15;
    color: #e8d5b7;
    margin-bottom: 0;
    padding-top: 24px;
}

/* Body prose */
.body-prose {
    font-family: 'Lora', Georgia, serif;
    font-size: 18px;
    font-weight: 400;
    line-height: 1.75;
    letter-spacing: 0.005em;
    color: #c4b097;
    margin-bottom: 28px;
    position: relative;
}

.body-prose em {
    font-style: italic;
    color: #e8d5b7;
}

.body-prose.last-line {
    font-style: italic;
    color: #e8d5b7;
    font-size: 20px;
    margin-top: 40px;
    text-align: center;
}

/* Pull quotes */
.pull-quote {
    position: relative;
    margin: 48px 0;
    padding: 24px 48px;
    text-align: center;
}

.quote-mark {
    font-family: 'Playfair Display', serif;
    font-size: 96px;
    color: #a67c52;
    opacity: 0.2;
    line-height: 1;
    position: absolute;
}

.quote-mark.open {
    top: -20px;
    left: 0;
}

.quote-mark.close {
    bottom: -50px;
    right: 0;
}

.pull-quote blockquote {
    font-family: 'Playfair Display', serif;
    font-size: clamp(20px, 2.5vw, 26px);
    font-weight: 400;
    font-style: italic;
    color: #e8d5b7;
    line-height: 1.5;
    letter-spacing: -0.01em;
}

.quote-cite {
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: #8b7355;
    margin-top: 16px;
    letter-spacing: 0.02em;
}

/* Footnotes */
.footnote-marker {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: #a67c52;
    background: none;
    border: none;
    cursor: pointer;
    vertical-align: super;
    padding: 0 2px;
    transition: color 0.3s ease;
}

.footnote-marker:hover {
    color: #e8d5b7;
}

/* Marginal notes */
.marginal-note {
    position: absolute;
    left: -260px;
    width: 220px;
    background: #2d2318;
    border-left: 2px solid #a67c52;
    padding: 16px;
    opacity: 0;
    transform: translateX(-20px);
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
    z-index: 10;
}

.marginal-note.visible {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}

.note-number {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: #a67c52;
    font-weight: 500;
}

.note-content {
    font-family: 'Lora', serif;
    font-size: 13px;
    line-height: 1.6;
    color: #8b7355;
}

/* Section dividers */
.section-divider {
    text-align: center;
    font-size: 24px;
    color: #a67c52;
    opacity: 0.6;
    margin: 48px 0 0 0;
    letter-spacing: 8px;
}

/* Final flourish */
.final-flourish {
    text-align: center;
    margin-top: 64px;
    padding-bottom: 80px;
}

.flourish-symbol {
    font-size: 20px;
    color: #a67c52;
    opacity: 0.5;
    margin: 0 16px;
}

.flourish-word {
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    font-style: italic;
    color: #8b7355;
    letter-spacing: 0.15em;
    text-transform: lowercase;
}

/* Background grid lines - faint ruled paper */
#folio::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    background:
        repeating-linear-gradient(
            90deg,
            transparent 0px,
            transparent calc(100% / 12 - 1px),
            rgba(139, 115, 85, 0.03) calc(100% / 12 - 1px),
            rgba(139, 115, 85, 0.03) calc(100% / 12),
            transparent calc(100% / 12)
        );
}

/* Responsive */
@media (max-width: 1024px) {
    .chapter-content {
        width: 80%;
        margin-left: 15% !important;
    }

    .margin-label {
        display: none;
    }

    .marginal-note {
        position: relative;
        left: 0;
        width: 100%;
        margin: 16px 0;
    }

    .margin-rule {
        display: none;
    }
}

@media (max-width: 768px) {
    .chapter-content {
        width: 90%;
        margin-left: 5% !important;
        padding: 0 16px;
    }

    .chapter-title {
        font-size: 32px;
    }

    .drop-cap {
        font-size: 80px;
    }

    .chapter-bg-numeral {
        font-size: 120px;
    }

    .pull-quote {
        padding: 16px 24px;
    }

    .quote-mark {
        font-size: 64px;
    }

    #compass-nav {
        top: 12px;
        right: 12px;
    }
}

/* Selection color */
::selection {
    background: rgba(166, 124, 82, 0.3);
    color: #f0e6d3;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 0px;
}

/* Smooth chapter transitions via JS classes */
.chapter.blurring {
    filter: blur(3px);
    opacity: 0.6;
}

.chapter.sharpening {
    filter: blur(0px);
    opacity: 1;
}
