/* ============================================================
   GGOGGL.com — Documentation Clean Slate
   A love letter to the printed page, rendered in CSS.
   ============================================================ */

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background-color: #FAFAF8;
    color: #2B2B2B;
    font-family: 'Source Serif 4', 'Georgia', serif;
    font-weight: 400;
    font-size: 1.1rem;
    line-height: 1.85;
    overflow-x: hidden;
    position: relative;
}

/* --- Paper Grain Texture Overlay --- */
.paper-grain {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.02;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4'%3E%3Crect width='1' height='1' x='0' y='0' fill='%232B2B2B' opacity='0.5'/%3E%3Crect width='1' height='1' x='2' y='2' fill='%232B2B2B' opacity='0.3'/%3E%3C/svg%3E");
    background-repeat: repeat;
}

/* --- Rule Lines (3-tier hierarchy) --- */
.rule {
    display: block;
    border: none;
    background-color: #C5C5C5;
}

.rule-hairline {
    height: 0.5px;
}

.rule-standard {
    height: 1px;
    width: 100%;
}

.rule-heavy {
    height: 3px;
    width: 100%;
}

.rule-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
}

.rule-bottom {
    margin-top: 10vh;
}

/* --- Index Bar (Top Progress Navigation) --- */
.index-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 40px;
    background-color: #F7F6F3;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid #C5C5C5;
}

.index-bar-inner {
    display: flex;
    align-items: center;
    gap: 24px;
}

.index-dot {
    display: block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #C5C5C5;
    background: transparent;
    transition: none;
    position: relative;
    overflow: hidden;
}

.index-dot::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background-color: #2B2B2B;
    transform: translate(-50%, -50%);
    transition: width 0.6s ease, height 0.6s ease;
}

.index-dot.filled {
    border-color: #2B2B2B;
}

.index-dot.filled::after {
    width: 100%;
    height: 100%;
}

/* --- Margin Rail (Left Annotation Column) --- */
.margin-rail {
    position: fixed;
    top: 40px;
    left: 0;
    width: 25vw;
    height: calc(100vh - 40px);
    background-color: #F0EFE8;
    border-right: 1px solid #C5C5C5;
    z-index: 100;
    overflow: hidden;
    padding: 3rem 1.5rem;
}

.margin-content {
    will-change: transform;
}

.margin-group {
    margin-bottom: 6rem;
    opacity: 0.4;
    transition: opacity 0.5s ease;
}

.margin-group.active {
    opacity: 1;
}

.margin-number {
    display: block;
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 300;
    font-size: 2.8rem;
    color: #2B2B2B;
    font-feature-settings: 'onum' 1;
    line-height: 1;
    margin-bottom: 0.5rem;
}

.margin-symbol {
    display: block;
    font-family: 'DM Mono', monospace;
    font-size: 0.85rem;
    color: #A8A89E;
    letter-spacing: 0.03em;
    margin-bottom: 0.25rem;
}

.margin-label {
    display: block;
    font-family: 'DM Mono', monospace;
    font-size: 0.75rem;
    color: #6B6B65;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.margin-ref {
    display: block;
    font-family: 'DM Mono', monospace;
    font-size: 0.7rem;
    color: #A8A89E;
    letter-spacing: 0.03em;
    margin-top: 0.5rem;
}

/* --- Mobile Margin Toggle --- */
.margin-toggle {
    display: none;
    position: fixed;
    top: 50px;
    left: 10px;
    z-index: 200;
    width: 36px;
    height: 28px;
    background: #F0EFE8;
    border: 1px solid #C5C5C5;
    cursor: pointer;
    padding: 5px;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
}

.margin-toggle-bar {
    display: block;
    width: 18px;
    height: 2px;
    background-color: #2B2B2B;
}

/* --- Main Column --- */
.main-column {
    margin-left: 25vw;
    padding-top: 40px;
    position: relative;
}

/* --- Chapter Sections --- */
.chapter-section {
    position: relative;
    padding: 8vh 6vw 8vh 4vw;
    min-height: 80vh;
}

.chapter-number {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 300;
    font-size: 1.4rem;
    color: #A8A89E;
    font-feature-settings: 'onum' 1;
    margin-bottom: 1rem;
    letter-spacing: 0.05em;
}

.section-rule {
    margin-bottom: 3rem;
}

/* --- Section Headings --- */
.section-heading {
    font-family: 'Instrument Serif', 'Georgia', serif;
    font-weight: 400;
    font-size: 2.4rem;
    color: #2B2B2B;
    margin-bottom: 3rem;
    line-height: 1.2;
}

/* --- Section Dividers with Lens Circles --- */
.section-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15vh 0;
    position: relative;
}

.section-divider::before {
    content: '';
    position: absolute;
    left: 10%;
    right: 10%;
    top: 50%;
    height: 1px;
    background-color: #C5C5C5;
}

.lens-medium {
    width: 120px;
    height: 120px;
    position: relative;
    z-index: 1;
    background-color: #FAFAF8;
    padding: 10px;
}

/* --- Title Plate (Section 0) --- */
.title-plate {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
    overflow: hidden;
    padding-top: 40px;
}

.lens-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40vw;
    height: 40vw;
    opacity: 0.03;
    pointer-events: none;
}

.lens-watermark svg {
    width: 100%;
    height: 100%;
}

.title-plate-content {
    position: relative;
    z-index: 2;
}

.title-text {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 300;
    font-size: 12vw;
    letter-spacing: 0.15em;
    color: #2B2B2B;
    line-height: 1;
    margin-bottom: 1.5rem;
}

.title-subtitle {
    font-family: 'Instrument Serif', 'Georgia', serif;
    font-weight: 400;
    font-style: normal;
    font-size: 1.2rem;
    color: #6B6B65;
    letter-spacing: 0.05em;
    opacity: 0;
    transition: opacity 1s ease;
}

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

/* --- Preamble Section --- */
.preamble-section {
    display: flex;
    flex-direction: column;
}

.preamble-text {
    max-width: 38em;
}

.preamble-text p {
    margin-bottom: 2em;
    font-feature-settings: 'onum' 1, 'liga' 1;
}

/* Drop Cap */
.drop-cap {
    float: left;
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 300;
    font-size: 4.5em;
    line-height: 0.75;
    padding-right: 0.08em;
    padding-top: 0.07em;
    color: #B8453A;
}

/* --- Reference Grid (Section 2) --- */
.reference-section {
    display: flex;
    flex-direction: column;
}

.reference-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 3rem 4rem;
    max-width: 60rem;
}

.ref-card {
    position: relative;
    padding-top: 0.5rem;
}

.ref-number {
    position: absolute;
    top: 0;
    right: 0;
    font-family: 'DM Mono', monospace;
    font-size: 0.75rem;
    color: #A8A89E;
    letter-spacing: 0.03em;
}

.ref-title {
    font-family: 'Instrument Serif', 'Georgia', serif;
    font-weight: 400;
    font-size: 1.6rem;
    color: #2B2B2B;
    margin-bottom: 0.75rem;
    line-height: 1.2;
}

.ref-definition {
    font-family: 'Source Serif 4', 'Georgia', serif;
    font-weight: 400;
    font-size: 0.95rem;
    color: #6B6B65;
    line-height: 1.7;
}

.ref-definition em {
    font-weight: 600;
    color: #2B2B2B;
    font-style: italic;
}

/* --- Diagram Section --- */
.diagram-section {
    display: flex;
    flex-direction: column;
}

.diagram-container {
    width: 100%;
    padding: 4vh 0;
    overflow: visible;
}

#diagramSvg {
    width: 100%;
    height: auto;
    display: block;
}

.diagram-path {
    stroke-dasharray: var(--path-length, 1000);
    stroke-dashoffset: var(--path-length, 1000);
    transition: none;
}

.diagram-node {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.diagram-node.visible {
    opacity: 1;
}

/* --- Appendix Section (Vanishing) --- */
.appendix-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: left;
}

.appendix-section .chapter-number,
.appendix-section .section-rule,
.appendix-section .section-heading {
    align-self: flex-start;
}

.appendix-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.appendix-paragraph {
    transition: max-width 0.8s ease;
}

.appendix-p1 {
    max-width: 38em;
    margin-bottom: 2em;
}

.appendix-p2 {
    max-width: 38em;
    margin-bottom: 2em;
}

.appendix-p3 {
    max-width: 38em;
    margin-bottom: 2em;
}

.appendix-p4 {
    max-width: 38em;
    margin-bottom: 2em;
}

/* Active vanishing states (applied via JS) */
.appendix-p1.narrow { max-width: 38em; }
.appendix-p2.narrow { max-width: 20em; }
.appendix-p3.narrow { max-width: 10em; }
.appendix-p4.narrow { max-width: 5em; }

/* --- Final Period --- */
.final-period-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20vh 0 15vh;
}

.final-period {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 300;
    font-size: 6rem;
    color: #B8453A;
    line-height: 1;
}

/* --- Focus Lens Effect (cursor hover on headings) --- */
.section-heading {
    cursor: default;
    position: relative;
}

/* --- Responsive / Mobile --- */
@media (max-width: 900px) {
    .margin-rail {
        transform: translateX(-100%);
        transition: transform 0.4s ease;
        width: 70vw;
        max-width: 300px;
        z-index: 500;
    }

    .margin-rail.open {
        transform: translateX(0);
    }

    .margin-toggle {
        display: flex;
    }

    .main-column {
        margin-left: 0;
        padding: 0;
    }

    .chapter-section {
        padding: 6vh 5vw;
    }

    .title-text {
        font-size: 16vw;
    }

    .reference-grid {
        grid-template-columns: 1fr;
        gap: 2.5rem 0;
    }

    .section-divider {
        padding: 8vh 0;
    }

    .lens-medium {
        width: 80px;
        height: 80px;
    }
}

@media (max-width: 600px) {
    .title-text {
        font-size: 18vw;
        letter-spacing: 0.08em;
    }

    .section-heading {
        font-size: 1.8rem;
    }

    .index-bar-inner {
        gap: 14px;
    }

    .index-dot {
        width: 12px;
        height: 12px;
    }
}
