/* ==========================================================================
   GGIGGL.com - Warm Editorial Blog Styles
   Fonts: Playfair Display, Lora, Source Sans 3
   Palette: Parchment, Walnut, Terracotta, Honeyed Amber, Sage, Buttercream
   ========================================================================== */

/* ---------- CSS Custom Properties ---------- */
:root {
    --bg-primary: #FAF6F0;
    --bg-alternate: #F2EDE4;
    --text-primary: #2C2420;
    --text-secondary: #6B5E54;
    --accent-primary: #C4654A;
    --accent-secondary: #D4A24E;
    --accent-tertiary: #8B9E7E;
    --highlight: #F5E6C8;
    --divider: #D5CABC;
    --dark-bg: #1E1814;

    --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
    --font-body: 'Lora', Georgia, 'Times New Roman', serif;
    --font-ui: 'Source Sans 3', system-ui, -apple-system, sans-serif;

    --spring-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
    --spring-smooth: cubic-bezier(0.25, 0.46, 0.45, 0.94);

    --reading-width: 680px;
    --margin-col-width: 200px;

    --scroll-progress: 0;
}

/* ---------- Dark Mode Variables ---------- */
body.dark-mode {
    --bg-primary: #1E1814;
    --bg-alternate: #2C2420;
    --text-primary: #FAF6F0;
    --text-secondary: #D5CABC;
    --accent-primary: #C4654A;
    --accent-secondary: #D4A24E;
    --accent-tertiary: #8B9E7E;
    --highlight: #3A3028;
    --divider: #4A3F36;
}

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

html {
    font-size: 18px;
    scroll-behavior: smooth;
    scroll-snap-type: y proximity;
}

body {
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.7;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    overflow-x: hidden;
    transition: background-color 0.5s var(--spring-smooth), color 0.5s var(--spring-smooth);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

@media (max-width: 768px) {
    html {
        font-size: 17px;
    }
    body {
        line-height: 1.65;
    }
}

/* ---------- Paper Texture Overlay ---------- */
#paper-texture {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.03;
    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='100%25' height='100%25' filter='url(%23noise)' opacity='1'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
}

/* ---------- Scroll Progress Bar ---------- */
#scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 2px;
    width: calc(var(--scroll-progress) * 100%);
    background-color: var(--accent-primary);
    z-index: 10001;
    transition: width 0.1s linear;
}

/* ---------- Header / Navigation ---------- */
#site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2.5rem;
    pointer-events: none;
}

#site-header > * {
    pointer-events: auto;
}

.logo-text {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--text-primary);
    text-decoration: none;
    transition: color 0.3s var(--spring-smooth);
}

.logo-text:hover {
    color: var(--accent-primary);
}

#nav-toggle {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 8px;
}

.nav-stroke {
    display: block;
    width: 24px;
    height: 2px;
    background-color: var(--text-primary);
    border-radius: 2px;
    transition: transform 0.3s var(--spring-bounce), opacity 0.3s ease, background-color 0.3s ease;
}

.nav-stroke:nth-child(1) {
    width: 20px;
}

.nav-stroke:nth-child(3) {
    width: 16px;
}

/* Nav toggle active state */
body.nav-open .nav-stroke:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
    width: 24px;
}

body.nav-open .nav-stroke:nth-child(2) {
    opacity: 0;
}

body.nav-open .nav-stroke:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
    width: 24px;
}

/* ---------- Navigation Overlay ---------- */
#nav-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-primary);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s var(--spring-smooth), visibility 0.3s;
}

body.nav-open #nav-overlay {
    opacity: 1;
    visibility: visible;
}

body.nav-open #main-content,
body.nav-open #colophon {
    filter: blur(6px);
    transition: filter 0.3s var(--spring-smooth);
}

.nav-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2.5rem;
}

.nav-link {
    font-family: var(--font-display);
    font-size: clamp(2rem, 5vw, 3.5rem);
    color: var(--text-primary);
    text-decoration: none;
    letter-spacing: -0.01em;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s var(--spring-smooth), transform 0.4s var(--spring-bounce), color 0.2s ease;
}

body.nav-open .nav-link {
    opacity: 1;
    transform: translateY(0);
}

body.nav-open .nav-link:nth-child(1) { transition-delay: 0.05s; }
body.nav-open .nav-link:nth-child(2) { transition-delay: 0.1s; }
body.nav-open .nav-link:nth-child(3) { transition-delay: 0.15s; }
body.nav-open .nav-link:nth-child(4) { transition-delay: 0.2s; }
body.nav-open .nav-link:nth-child(5) { transition-delay: 0.25s; }

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

/* ---------- Main Content ---------- */
#main-content {
    transition: filter 0.3s var(--spring-smooth);
}

/* ---------- Hero Section ---------- */
#hero {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
    scroll-snap-align: start;
}

.hero-title-container {
    position: relative;
}

.hero-title {
    font-family: var(--font-display);
    font-size: clamp(4rem, 12vw, 10rem);
    font-weight: 900;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    line-height: 1;
    transition: opacity 1s var(--spring-smooth), transform 1s var(--spring-smooth);
}

.hero-title .letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(30px) scale(0.9);
    transition: opacity 0.6s var(--spring-smooth), transform 0.6s var(--spring-bounce);
}

.hero-title .letter.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.hero-title.faded {
    opacity: 0.2;
    transform: translateY(-40px);
}

.hero-subtitle {
    font-family: var(--font-ui);
    font-size: clamp(0.85rem, 1.5vw, 1.1rem);
    color: var(--text-secondary);
    letter-spacing: 0.05em;
    text-transform: lowercase;
    margin-top: 1.5rem;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.8s var(--spring-smooth) 0.3s, transform 0.8s var(--spring-smooth) 0.3s;
}

.hero-subtitle.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ---------- Chapters ---------- */
.chapter {
    min-height: 80vh;
    padding: 6rem 2rem;
    scroll-snap-align: start;
}

.chapter-inner {
    position: relative;
    max-width: calc(var(--reading-width) + var(--margin-col-width) * 2 + 4rem);
    margin: 0 auto;
    display: grid;
    grid-template-columns: var(--margin-col-width) 1fr var(--margin-col-width);
    gap: 2rem;
}

.chapter-content {
    grid-column: 2;
    max-width: var(--reading-width);
}

@media (max-width: 1200px) {
    .chapter-inner {
        display: block;
        max-width: var(--reading-width);
    }
}

/* ---------- Chapter Titles ---------- */
.chapter-title {
    font-family: var(--font-display);
    font-size: clamp(2.5rem, 5vw, 5rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    line-height: 1.1;
    margin-bottom: 1.25rem;
}

.chapter-title.fade-reveal {
    opacity: 0;
    transform: translateY(25px);
    transition: opacity 0.8s var(--spring-smooth), transform 0.8s var(--spring-bounce);
}

.chapter-title.fade-reveal.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* ---------- Category Tags ---------- */
.category-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.tag {
    font-family: var(--font-ui);
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
    border: 1px solid var(--divider);
    border-radius: 20px;
    padding: 0.25rem 0.75rem;
    transition: background-color 0.3s var(--spring-bounce), color 0.3s ease;
    cursor: default;
}

.tag:hover {
    background-color: var(--highlight);
    color: var(--text-primary);
}

/* ---------- Body Text ---------- */
.chapter-lede {
    font-family: var(--font-body);
    font-size: 1.15rem;
    line-height: 1.75;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    font-weight: 500;
}

.body-text {
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.7;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
}

.body-text em {
    font-style: italic;
    color: var(--accent-primary);
}

/* ---------- Pull Quotes ---------- */
.pull-quote-container {
    position: relative;
    margin: 3rem 0;
    padding: 2rem 0 2rem 2rem;
    border-left: 3px solid var(--accent-primary);
}

.pull-quote-mark {
    position: absolute;
    font-family: var(--font-display);
    font-size: 6rem;
    color: var(--accent-secondary);
    opacity: 0.3;
    line-height: 1;
    pointer-events: none;
    user-select: none;
}

.pull-quote-mark.open {
    top: -1rem;
    left: -0.5rem;
}

.pull-quote-mark.close {
    bottom: -2.5rem;
    right: 0;
}

.pull-quote {
    font-family: var(--font-display);
    font-style: italic;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    line-height: 1.4;
    color: var(--accent-primary);
    position: relative;
    z-index: 1;
}

/* ---------- Continue Reading Link ---------- */
.continue-reading {
    display: inline-block;
    font-family: var(--font-ui);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-secondary);
    text-decoration: none;
    position: relative;
    margin-top: 1rem;
    padding-bottom: 2px;
}

.continue-reading::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 1.5px;
    background-color: var(--accent-primary);
    transition: width 0.3s ease-out;
}

.continue-reading:hover::after {
    width: 100%;
}

.continue-reading:hover {
    color: var(--accent-primary);
}

/* ---------- Marginal Notes ---------- */
.marginal-note {
    margin-top: 2rem;
    padding: 1rem;
    border-top: 1px solid var(--divider);
}

@media (min-width: 1201px) {
    .marginal-note {
        position: absolute;
        right: -240px;
        width: var(--margin-col-width);
        margin-top: 0;
        border-top: none;
        border-left: 1px solid var(--divider);
        padding: 0 0 0 1rem;
        opacity: 0;
        transform: translateX(10px);
        transition: opacity 0.6s var(--spring-smooth), transform 0.6s var(--spring-smooth);
    }

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

.marginal-note p {
    font-family: var(--font-body);
    font-style: italic;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

/* ---------- Footnote Markers ---------- */
.footnote-marker {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.2em;
    height: 1.2em;
    background-color: var(--accent-primary);
    color: #FFFFFF;
    font-family: var(--font-ui);
    font-size: 0.6rem;
    font-weight: 600;
    border-radius: 50%;
    vertical-align: super;
    margin-left: 2px;
    cursor: pointer;
    transition: transform 0.2s var(--spring-bounce), background-color 0.2s ease;
}

.footnote-marker:hover {
    transform: scale(1.2);
    background-color: var(--accent-secondary);
}

/* ---------- Marginal Illustrations ---------- */
.marginal-illustration {
    display: none;
}

@media (min-width: 1201px) {
    .marginal-illustration {
        display: flex;
        align-items: flex-start;
        justify-content: center;
        padding-top: 4rem;
        opacity: 0;
        transform: translateY(15px);
        transition: opacity 0.8s var(--spring-smooth), transform 0.8s var(--spring-smooth);
    }

    .marginal-illustration.visible {
        opacity: 1;
        transform: translateY(0);
    }

    .marginal-illustration.marginal-right {
        grid-column: 3;
        grid-row: 1;
    }

    .marginal-illustration.marginal-left {
        grid-column: 1;
        grid-row: 1;
    }
}

.margin-svg {
    width: 60px;
    height: auto;
    color: var(--text-primary);
    opacity: 0.4;
}

.margin-svg .steam {
    animation: steamRise 3s ease-in-out infinite;
}

.margin-svg .steam:nth-child(5) {
    animation-delay: 0.5s;
}

.margin-svg .steam:nth-child(6) {
    animation-delay: 1s;
}

@keyframes steamRise {
    0%, 100% { opacity: 0.4; transform: translateY(0); }
    50% { opacity: 0.15; transform: translateY(-3px); }
}

/* ---------- Section Dividers ---------- */
.section-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem 0;
}

.divider-ornament {
    opacity: 0;
    transition: opacity 0.8s var(--spring-smooth);
}

.divider-ornament.visible {
    opacity: 1;
}

.ornament-path {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 1.2s var(--spring-smooth);
}

.divider-ornament.visible .ornament-path {
    stroke-dashoffset: 0;
}

.ornament-dot {
    opacity: 0;
    transition: opacity 0.4s ease 0.8s;
}

.divider-ornament.visible .ornament-dot {
    opacity: 1;
}

/* ---------- Footer / Colophon ---------- */
#colophon {
    padding: 6rem 2rem;
    text-align: center;
    background-color: var(--bg-alternate);
    position: relative;
    transition: filter 0.3s var(--spring-smooth), background-color 0.5s var(--spring-smooth);
}

.colophon-inner {
    max-width: 400px;
    margin: 0 auto;
}

.colophon-ornament {
    display: flex;
    justify-content: center;
    margin: 1rem 0;
}

.colophon-title {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.colophon-text {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: 400;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
    line-height: 1.8;
}

.colophon-date {
    margin-top: 1rem;
    font-variant: small-caps;
    letter-spacing: 0.15em;
}

/* ---------- Dark Mode Toggle ---------- */
#dark-mode-toggle {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1000;
    background: var(--bg-alternate);
    border: 1px solid var(--divider);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, transform 0.3s var(--spring-bounce);
}

#dark-mode-toggle:hover {
    transform: scale(1.1);
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}

/* ---------- Body Link Styles ---------- */
.body-text a,
.chapter-lede a {
    color: var(--accent-primary);
    text-decoration: none;
    position: relative;
}

.body-text a::after,
.chapter-lede a::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 0;
    height: 1px;
    background-color: var(--accent-primary);
    transition: width 0.2s ease-out;
}

.body-text a:hover::after,
.chapter-lede a:hover::after {
    width: 100%;
}

/* ---------- Selection ---------- */
::selection {
    background-color: var(--highlight);
    color: var(--text-primary);
}

/* ---------- Responsive Adjustments ---------- */
@media (max-width: 768px) {
    #site-header {
        padding: 1rem 1.5rem;
    }

    .chapter {
        padding: 4rem 1.5rem;
    }

    .pull-quote-container {
        margin: 2rem 0;
        padding: 1.5rem 0 1.5rem 1.5rem;
    }

    .pull-quote-mark {
        font-size: 4rem;
    }

    .hero-title {
        font-size: clamp(3rem, 15vw, 6rem);
    }

    #colophon {
        padding: 4rem 1.5rem;
    }

    .section-divider {
        padding: 3rem 0;
    }
}

@media (max-width: 480px) {
    .chapter {
        padding: 3rem 1rem;
    }

    .chapter-title {
        font-size: clamp(2rem, 8vw, 3rem);
    }

    .pull-quote {
        font-size: clamp(1.2rem, 4vw, 1.8rem);
    }

    #site-header {
        padding: 1rem;
    }
}

/* ---------- Smooth appearance for chapters ---------- */
.chapter-content {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s var(--spring-smooth), transform 0.8s var(--spring-smooth);
}

.chapter-content.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Hero chapter content exception - controlled by JS */
#hero .hero-title-container {
    opacity: 1;
    transform: none;
}
