/* ==========================================================
   concurrengine.com - Light Academia / Retro-Futuristic
   Color Palette:
     #F5EDE3 - Aged Linen (primary bg)
     #2C1810 - Dark Walnut (sidebar bg)
     #EDE4D4 - Parchment (accent bg)
     #3D2E22 - Espresso (primary text)
     #A89080 - Worn Leather (secondary text)
     #D4A574 - Tarnished Copper (warm accent)
     #7EBCB5 - Patina Green (cool accent)
     #B85C38 - Rust (hot accent)
     #5A4A3A - Oxidized Bronze (deep accent)
     #D4C8B8 - Muted Sand (dividers)
   Fonts: Playfair Display, Source Serif 4, DM Mono
   ========================================================== */

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Source Serif 4', serif;
    background-color: #F5EDE3;
    color: #3D2E22;
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
    /* Dot grid background - engineering paper feel */
    background-image: radial-gradient(circle, #D4C8B8 1px, transparent 1px);
    background-size: 20px 20px;
    background-position: 0 0;
}

/* Reduce dot grid opacity via overlay on main content */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(245, 237, 227, 0.90);
    pointer-events: none;
    z-index: 0;
}

/* ---- Mobile Top Bar ---- */
#mobile-topbar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px;
    background-color: #2C1810;
    z-index: 200;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
}

.mobile-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: 18px;
    color: #D4A574;
    letter-spacing: 0.05em;
}

#hamburger-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: 32px;
}

#hamburger-btn span {
    display: block;
    height: 2px;
    width: 100%;
    background-color: #D4A574;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

#hamburger-btn.open span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

#hamburger-btn.open span:nth-child(2) {
    opacity: 0;
}

#hamburger-btn.open span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* ---- Sidebar / Card Catalog ---- */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    background-color: #2C1810;
    display: flex;
    flex-direction: column;
    padding: 0;
    z-index: 100;
    overflow-y: auto;
}

/* Rotated vertical site title */
#sidebar-title-wrap {
    padding: 40px 28px 0;
    height: 120px;
    position: relative;
}

#site-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: 18px;
    color: #D4A574;
    letter-spacing: 0.15em;
    text-transform: lowercase;
    transform: rotate(-90deg);
    transform-origin: left top;
    position: absolute;
    top: 110px;
    left: 38px;
    white-space: nowrap;
}

/* Navigation */
#sidebar-nav {
    flex: 1;
    padding: 48px 28px 0;
}

#sidebar-nav ul {
    list-style: none;
}

#sidebar-nav li {
    margin-bottom: 2px;
}

.nav-link {
    display: inline-block;
    position: relative;
    padding: 8px 0;
    font-family: 'DM Mono', monospace;
    font-size: 13px;
    font-weight: 400;
    color: #A89080;
    text-decoration: none;
    letter-spacing: 0.06em;
    transition: color 0.3s ease;
}

.nav-num {
    color: #5A4A3A;
    margin-right: 8px;
}

/* Underline-draw animation for nav links */
.nav-link::after {
    content: '';
    position: absolute;
    bottom: 4px;
    left: 0;
    width: 100%;
    height: 2px;
    background: #D4A574;
    transform-origin: left center;
    transform: scaleX(0);
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.nav-link:hover::after,
.nav-link.active::after {
    transform: scaleX(1);
}

.nav-link:hover {
    color: #D4C8B8;
}

.nav-link.active {
    color: #F5EDE3;
}

.nav-link.active .nav-num {
    color: #D4A574;
}

/* Sidebar Orrery */
#sidebar-orrery {
    width: 120px;
    height: 120px;
    margin: 20px auto 16px;
    opacity: 0.8;
}

#orrery-svg {
    width: 100%;
    height: 100%;
}

.orbit-group {
    transform-origin: 60px 60px;
}

#orbit-1 {
    animation: orbitSpin 8s linear infinite;
}

#orbit-2 {
    animation: orbitSpin 13s linear infinite reverse;
}

#orbit-3 {
    animation: orbitSpin 20s linear infinite;
}

@keyframes orbitSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Gear teeth border at sidebar bottom */
#sidebar-gear-border {
    height: 12px;
    width: 100%;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 12' width='24' height='12'%3E%3Cpath d='M0,12 L4,12 L4,4 L8,4 L8,12 L16,12 L16,4 L20,4 L20,12 L24,12' fill='none' stroke='%235A4A3A' stroke-width='1' opacity='0.3'/%3E%3C/svg%3E");
    background-repeat: repeat-x;
    background-position: bottom;
    flex-shrink: 0;
}

/* ---- Main Content ---- */
#main-content {
    margin-left: 280px;
    flex: 1;
    padding: 0;
    position: relative;
    z-index: 1;
}

/* ---- Hero Section ---- */
#hero {
    padding: 120px 80px 80px;
    max-width: 840px;
    margin-left: 80px;
}

#hero-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: 48px;
    color: #2C1810;
    line-height: 1.15;
    letter-spacing: -0.01em;
    margin-bottom: 12px;
}

#hero-subtitle {
    font-family: 'Source Serif 4', serif;
    font-size: 20px;
    font-style: italic;
    color: #A89080;
    margin-bottom: 32px;
}

#hero-loom {
    opacity: 0;
    transition: opacity 1.2s ease;
}

#hero-loom.fade-in {
    opacity: 1;
}

/* ---- Section Dividers ---- */
.section-divider {
    padding: 20px 80px;
    max-width: 840px;
    margin-left: 80px;
}

.divider-svg {
    width: 100%;
    max-width: 400px;
    height: 12px;
    display: block;
    margin: 0 auto;
}

/* ---- Chapters ---- */
.chapter {
    padding: 60px 80px 80px;
    max-width: 840px;
    margin-left: 80px;
}

/* Section heading with left border */
.chapter-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: 32px;
    color: #2C1810;
    line-height: 1.15;
    letter-spacing: -0.01em;
    margin-bottom: 12px;
    border-left: 4px solid #7EBCB5;
    padding-left: 16px;
    position: relative;
}

/* Underline-draw on chapter titles when in view */
.chapter-title::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 16px;
    width: calc(100% - 16px);
    height: 2px;
    background: #D4A574;
    transform-origin: left center;
    transform: scaleX(0);
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.chapter.in-view .chapter-title::after {
    transform: scaleX(1);
}

/* Epigraph */
.epigraph {
    font-family: 'Source Serif 4', serif;
    font-size: 16px;
    font-style: italic;
    color: #A89080;
    padding-left: 24px;
    margin-bottom: 32px;
}

/* Body text - Source Serif 4 at 18px Regular */
.chapter-body p {
    font-family: 'Source Serif 4', serif;
    font-size: 18px;
    font-weight: 400;
    line-height: 1.7;
    color: #3D2E22;
    margin-bottom: 24px;
    max-width: 65ch;
}

/* Pull quotes */
.pull-quote {
    font-family: 'Source Serif 4', serif;
    font-weight: 400;
    font-style: italic;
    font-size: 20px;
    line-height: 1.5;
    color: #B85C38;
    border-left: 4px solid #7EBCB5;
    padding: 16px 0 16px 28px;
    margin: 36px 0;
    max-width: 560px;
    position: relative;
    /* Cross-hatch fill background */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath d='M0,8 L8,0 M-1,1 L1,-1 M7,9 L9,7' stroke='%23D4C8B8' stroke-width='0.5'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 8px 8px;
}

.pull-quote::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(245, 237, 227, 0.94);
    z-index: -1;
}

/* ---- Illustrations ---- */
.illustration-panel {
    margin: 32px 0;
    padding: 30px;
    background-color: #EDE4D4;
    border: 1px solid #D4A574;
    border-radius: 4px;
    position: relative;
}

.chapter-illustration {
    width: 100%;
    max-width: 700px;
    display: block;
    margin: 0 auto;
}

.illustration-caption {
    font-family: 'DM Mono', monospace;
    font-size: 12px;
    font-weight: 400;
    color: #A89080;
    text-align: center;
    margin-top: 16px;
    margin-bottom: 0;
    font-style: italic;
    letter-spacing: 0.02em;
}

/* Shuttle animation */
#loom-shuttle {
    animation: shuttleSlide 8s linear infinite;
}

@keyframes shuttleSlide {
    0% { transform: translateX(80px); }
    100% { transform: translateX(500px); }
}

/* Large orrery process orbit animations */
.process-orbit-1 {
    transform-origin: 300px 150px;
    animation: orbitSpin 6s linear infinite;
}

.process-orbit-2 {
    transform-origin: 300px 150px;
    animation: orbitSpin 9s linear infinite;
}

.process-orbit-3 {
    transform-origin: 300px 150px;
    animation: orbitSpin 14s linear infinite reverse;
}

.process-orbit-4 {
    transform-origin: 300px 150px;
    animation: orbitSpin 20s linear infinite;
}

.process-orbit-5 {
    transform-origin: 300px 150px;
    animation: orbitSpin 28s linear infinite reverse;
}

/* ---- Body links underline-draw ---- */
.chapter-body a {
    color: #3D2E22;
    text-decoration: none;
    position: relative;
    display: inline;
}

.chapter-body a::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 2px;
    background: #7EBCB5;
    transform-origin: left center;
    transform: scaleX(0);
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.chapter-body a:hover::after {
    transform: scaleX(1);
}

/* ---- Footer / Colophon ---- */
#colophon {
    padding: 40px 80px 80px;
    max-width: 840px;
    margin-left: 80px;
}

.colophon-text {
    font-family: 'DM Mono', monospace;
    font-size: 13px;
    color: #A89080;
    letter-spacing: 0.02em;
    margin-bottom: 6px;
}

.colophon-note {
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    color: #D4C8B8;
    font-style: italic;
}

/* ---- Responsive: Tablet ---- */
@media (max-width: 1024px) {
    #hero,
    .chapter,
    .section-divider,
    #colophon {
        margin-left: 40px;
    }
}

@media (max-width: 900px) {
    #sidebar {
        width: 240px;
    }

    #main-content {
        margin-left: 240px;
    }

    #hero {
        padding: 80px 40px 60px;
        margin-left: 20px;
    }

    .chapter {
        padding: 40px 40px 60px;
        margin-left: 20px;
    }

    .section-divider {
        padding: 16px 40px;
        margin-left: 20px;
    }

    #colophon {
        padding: 30px 40px 60px;
        margin-left: 20px;
    }

    #hero-title {
        font-size: 36px;
    }

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

/* ---- Responsive: Mobile ---- */
@media (max-width: 768px) {
    #mobile-topbar {
        display: flex;
    }

    #sidebar {
        position: fixed;
        top: 60px;
        left: 0;
        width: 100%;
        height: calc(100vh - 60px);
        transform: translateX(-100%);
        transition: transform 0.35s ease;
        padding: 20px;
    }

    #sidebar.open {
        transform: translateX(0);
    }

    #sidebar-title-wrap {
        display: none;
    }

    #sidebar-nav {
        padding: 0;
    }

    .nav-link {
        padding: 12px 0;
        font-size: 15px;
    }

    #sidebar-orrery {
        margin-top: 30px;
    }

    #sidebar-gear-border {
        display: none;
    }

    #main-content {
        margin-left: 0;
        margin-top: 60px;
    }

    #hero,
    .chapter,
    .section-divider,
    #colophon {
        margin-left: 0;
        padding-left: 20px;
        padding-right: 20px;
    }

    #hero {
        padding-top: 60px;
        padding-bottom: 40px;
    }

    #hero-title {
        font-size: 32px;
    }

    #hero-subtitle {
        font-size: 17px;
    }

    .chapter {
        padding-top: 40px;
        padding-bottom: 40px;
    }

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

    .pull-quote {
        font-size: 17px;
        padding-left: 20px;
    }

    .illustration-panel {
        padding: 16px;
        margin: 24px 0;
    }

    .section-divider {
        padding-top: 12px;
        padding-bottom: 12px;
    }
}
