/* ============================================================
   scriptswirl.com — Frosted-glass calligraphy in a botanical conservatory
   ----------------------------------------------------------------------
   Color palette (from DESIGN.md):
     Espresso Bark    #2C1A0A   deep background
     Burnt Umber      #5C4012   headings
     Antique Gold     #8B6914   accent / spine
     Sienna           #A0522D   drop capitals / hover
     Parchment Cream  #FFF8EB   glass tint
     Dark Walnut      #4A3520   body text
     Warm Parchment   #F5E6CC   light surface text
     Pressed Fern     #4A6741   botanical strokes
     Honey Amber      #D4A24E   highlights
   ============================================================ */

:root {
    --color-espresso: #2C1A0A;
    --color-umber: #5C4012;
    --color-gold: #8B6914;
    --color-sienna: #A0522D;
    --color-parchment-cream: #FFF8EB;
    --color-walnut: #4A3520;
    --color-parchment-warm: #F5E6CC;
    --color-fern: #4A6741;
    --color-amber: #D4A24E;
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #2C1A0A;
    color: #4A3520;
    font-family: 'Lora', Georgia, serif;
    font-size: 16px;
    line-height: 1.75;
    letter-spacing: 0.01em;
}

body {
    position: relative;
    background:
        radial-gradient(ellipse at 20% 30%, rgba(139, 105, 20, 0.18), transparent 55%),
        radial-gradient(ellipse at 80% 70%, rgba(74, 103, 65, 0.14), transparent 60%),
        radial-gradient(ellipse at 50% 100%, rgba(212, 162, 78, 0.10), transparent 50%),
        linear-gradient(135deg, #2C1A0A 0%, #3a2410 50%, #2C1A0A 100%);
    background-attachment: fixed;
}

/* ============================================================
   Grain Overlay
   ============================================================ */
#grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.06;
    mix-blend-mode: multiply;
}

#grain-overlay rect {
    fill: #D4A24E;
}

/* ============================================================
   Margin Garden — extreme edges
   ============================================================ */
.margin-garden {
    position: fixed;
    top: 0;
    width: 48px;
    height: 100vh;
    pointer-events: none;
    z-index: 5;
}

#margin-garden-left { left: 0; }
#margin-garden-right { right: 0; }

.margin-garden svg {
    width: 100%;
    height: 200%;
    display: block;
    transition: transform 0.1s linear;
}

.garden-layer {
    transition: opacity 1.4s ease-in-out;
}

/* ============================================================
   Manuscript Container — Split-screen Grid
   ============================================================ */
#manuscript-container {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1px 1fr;
    width: 100vw;
    height: 100vh;
    padding: 0 48px;
    z-index: 10;
}

/* ============================================================
   The Spine
   ============================================================ */
#spine {
    position: relative;
    width: 1px;
    height: 100vh;
    overflow: visible;
}

#spine-line {
    position: absolute;
    top: 0;
    left: -0.5px;
    width: 2px;
    height: 100%;
    overflow: visible;
}

#spine::before {
    content: '';
    position: absolute;
    top: 0;
    left: -3px;
    width: 7px;
    height: 100%;
    background: linear-gradient(to bottom, transparent, rgba(139, 105, 20, 0.30), transparent);
    opacity: 0;
    transition: opacity 1.2s ease-in-out;
    pointer-events: none;
}

#manuscript-container:hover #spine::before,
.spine-pulse #spine::before {
    opacity: 1;
    box-shadow: 0 0 12px rgba(139, 105, 20, 0.15);
}

/* ============================================================
   Panes — Independent scroll containers
   ============================================================ */
.pane {
    position: relative;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-behavior: smooth;
}

.pane::-webkit-scrollbar {
    display: none;
}

#pane-left {
    padding: 24px 24px 24px 24px;
}

#pane-right {
    padding: 24px 24px 24px 24px;
}

.pane-scroll-content {
    width: 100%;
    will-change: transform;
}

/* ============================================================
   Sections — each ~100vh
   ============================================================ */
.section {
    position: relative;
    width: 100%;
    min-height: calc(100vh - 48px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 0;
    opacity: 1;
    transition: opacity 600ms ease-in-out;
}

.section.page-turning {
    opacity: 0;
}

/* ============================================================
   Glass Panel — frosted glass treatment
   ============================================================ */
.glass-panel {
    position: relative;
    width: 100%;
    max-width: 560px;
    padding: 48px 40px;
    background: rgba(255, 248, 235, 0.25);
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 12px;
    box-shadow:
        0 8px 32px rgba(92, 64, 18, 0.12),
        inset 0 1px 2px rgba(255, 255, 255, 0.30);
    transition:
        transform 400ms ease-out,
        border-color 1.5s ease,
        opacity 800ms ease;
}

/* Firefox fallback for backdrop-filter */
@supports not ((backdrop-filter: blur(16px)) or (-webkit-backdrop-filter: blur(16px))) {
    .glass-panel {
        background: rgba(255, 248, 235, 0.85);
    }
}

.glass-panel.shake-error {
    animation: shake-error 400ms ease-in-out;
    border-color: rgba(160, 82, 45, 0.6) !important;
}

@keyframes shake-error {
    0%   { transform: translateX(0); }
    14%  { transform: translateX(-6px); }
    28%  { transform: translateX(6px); }
    42%  { transform: translateX(-4px); }
    56%  { transform: translateX(4px); }
    70%  { transform: translateX(-2px); }
    84%  { transform: translateX(2px); }
    100% { transform: translateX(0); }
}

/* ============================================================
   Herbarium Panel (left)
   ============================================================ */
.herbarium-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

.botanical-illustration {
    width: 100%;
    max-width: 400px;
    height: auto;
    aspect-ratio: 4 / 5;
    display: block;
}

.botanical-path {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 2s ease-in-out;
}

.draw-on-scroll.drawn .botanical-path {
    stroke-dashoffset: 0;
}

.herbarium-label {
    font-family: 'Playfair Display', Georgia, serif;
    font-style: italic;
    font-weight: 400;
    font-size: clamp(1.2rem, 1.8vw, 1.6rem);
    letter-spacing: 0.04em;
    color: #5C4012;
    text-align: center;
    margin-top: 8px;
}

/* ============================================================
   Script Panel (right)
   ============================================================ */
.script-panel {
    position: relative;
}

.section-marker {
    position: absolute;
    top: 16px;
    left: 16px;
    opacity: 0.7;
}

.section-marker svg {
    display: block;
}

.script-heading {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: clamp(2rem, 4.5vw, 3.8rem);
    letter-spacing: 0.02em;
    color: #5C4012;
    margin-bottom: 28px;
    line-height: 1.1;
}

.ruled-text-block {
    position: relative;
}

.ruled-text-block::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: repeating-linear-gradient(
        to bottom,
        transparent,
        transparent 27px,
        rgba(160, 82, 45, 0.13) 27px,
        rgba(160, 82, 45, 0.13) 28px
    );
    pointer-events: none;
    z-index: 0;
    border-radius: 4px;
}

.ruled-text-block > * {
    position: relative;
    z-index: 1;
}

.body-text {
    font-family: 'Lora', Georgia, serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    line-height: 1.75;
    letter-spacing: 0.01em;
    color: #4A3520;
    margin-bottom: 18px;
    text-align: justify;
    hyphens: auto;
}

.drop-capital {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 700;
    font-style: italic;
    font-size: 4.5em;
    line-height: 0.85;
    color: #A0522D;
    float: left;
    margin: 6px 8px 0 0;
    padding: 0;
}

.marginal-note {
    font-family: 'DM Sans', sans-serif;
    font-weight: 400;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: #8B6914;
    margin-top: 24px;
    padding-top: 12px;
    border-top: 1px solid rgba(139, 105, 20, 0.22);
    position: relative;
}

.marginal-note::after {
    content: attr(data-note);
    display: block;
    margin-top: 4px;
    font-style: italic;
    text-transform: none;
    letter-spacing: 0.04em;
    color: rgba(139, 105, 20, 0.7);
    font-size: 0.72rem;
}

/* ============================================================
   Opening / Closing — site title
   ============================================================ */
#site-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 900;
    font-style: italic;
    font-size: clamp(3rem, 7vw, 5.5rem);
    color: #5C4012;
    line-height: 1;
    margin-bottom: 24px;
    letter-spacing: 0;
    transition: letter-spacing 1s ease-out, opacity 1s ease-out;
    opacity: 0;
}

#site-title.revealed {
    letter-spacing: 0.06em;
    opacity: 1;
}

.tagline {
    font-family: 'Lora', Georgia, serif;
    font-style: italic;
    font-weight: 400;
    font-size: clamp(1rem, 1.4vw, 1.25rem);
    color: #8B6914;
    margin-bottom: 32px;
    opacity: 0;
    transition: opacity 1.2s ease-in-out;
    transition-delay: 0.6s;
}

.tagline.revealed {
    opacity: 1;
}

/* ============================================================
   Calligraphic Swirls
   ============================================================ */
.calligraphic-swirl {
    width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    animation: swirl-breathe 4s ease-in-out infinite;
}

.calligraphic-swirl .swirl-path {
    stroke-dasharray: 1500;
    stroke-dashoffset: 1500;
    transition: stroke-dashoffset 3s ease-in-out;
}

.calligraphic-swirl.drawn .swirl-path {
    stroke-dashoffset: 0;
}

@keyframes swirl-breathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.03); }
}

.opening-swirl {
    margin-top: 32px;
    max-width: 300px;
}

.closing-swirl {
    max-width: 400px;
    margin: 0 auto 32px;
}

.closing-text {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 700;
    font-style: italic;
    font-size: clamp(1.4rem, 2.4vw, 2rem);
    color: #5C4012;
    line-height: 1.5;
    text-align: center;
    margin-top: 24px;
}

/* ============================================================
   Closing folio convergence
   ============================================================ */
.closing-panel {
    text-align: center;
}

#manuscript-container.closing-converging #pane-left .closing-panel,
#manuscript-container.closing-converging #pane-right .closing-panel {
    transform: scale(1.02);
}

/* ============================================================
   TOC Pill
   ============================================================ */
#toc-toggle {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 56px;
    height: 56px;
    border-radius: 28px;
    background: rgba(255, 248, 235, 0.40);
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    border: 1px solid rgba(255, 255, 255, 0.25);
    box-shadow: 0 8px 24px rgba(92, 64, 18, 0.20);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    transition: transform 300ms ease, box-shadow 300ms ease, background 300ms ease;
}

#toc-toggle:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 12px 32px rgba(92, 64, 18, 0.28);
    background: rgba(255, 248, 235, 0.55);
}

#toc-toggle.active {
    background: rgba(212, 162, 78, 0.35);
}

#toc-toggle svg {
    width: 22px;
    height: 22px;
    display: block;
}

@supports not ((backdrop-filter: blur(16px)) or (-webkit-backdrop-filter: blur(16px))) {
    #toc-toggle {
        background: rgba(255, 248, 235, 0.92);
    }
}

/* ============================================================
   TOC Panel
   ============================================================ */
#toc-panel {
    position: fixed;
    bottom: 100px;
    right: 28px;
    min-width: 240px;
    padding: 24px 28px;
    background: rgba(255, 248, 235, 0.40);
    backdrop-filter: blur(24px) saturate(140%);
    -webkit-backdrop-filter: blur(24px) saturate(140%);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 12px;
    box-shadow: 0 12px 36px rgba(92, 64, 18, 0.20);
    z-index: 199;
    opacity: 0;
    transform: translateY(20px) scale(0.96);
    pointer-events: none;
    transition: opacity 300ms ease, transform 300ms ease;
}

@supports not ((backdrop-filter: blur(16px)) or (-webkit-backdrop-filter: blur(16px))) {
    #toc-panel {
        background: rgba(255, 248, 235, 0.95);
    }
}

#toc-panel.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

#toc-panel ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.toc-link {
    font-family: 'DM Sans', sans-serif;
    font-weight: 500;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: #8B6914;
    text-decoration: none;
    padding: 4px 0;
    border-bottom: 1px solid transparent;
    transition: color 250ms ease, border-color 250ms ease, padding-left 250ms ease;
    display: block;
}

.toc-link:hover {
    color: #A0522D;
    border-bottom-color: rgba(160, 82, 45, 0.4);
    padding-left: 6px;
}

.toc-link.active {
    color: #5C4012;
    border-bottom-color: rgba(139, 105, 20, 0.5);
}

/* ============================================================
   Opening sequence — initial states
   ============================================================ */
.section[data-section="0"] .glass-panel {
    opacity: 0;
    transform: scale(0.92);
}

.opening-ready .section[data-section="0"] .glass-panel {
    opacity: 1;
    transform: scale(1);
    transition: opacity 800ms cubic-bezier(0.22, 1, 0.36, 1),
                transform 800ms cubic-bezier(0.22, 1, 0.36, 1);
}

#spine-line line {
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    transition: stroke-dashoffset 1.2s ease-out;
}

.spine-drawn #spine-line line {
    stroke-dashoffset: 0;
}

/* ============================================================
   Page Turn radial gradient overlay
   ============================================================ */
.page-turn-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 50;
    opacity: 0;
    background: radial-gradient(ellipse at 50% 50%,
        rgba(255, 248, 235, 0.0) 0%,
        rgba(212, 162, 78, 0.18) 35%,
        rgba(255, 248, 235, 0.0) 70%);
    transition: opacity 300ms ease;
}

.page-turn-overlay.flashing {
    opacity: 1;
}

/* ============================================================
   Mobile — single column collapse
   ============================================================ */
@media (max-width: 768px) {
    html, body {
        overflow-x: hidden;
        overflow-y: auto;
        height: auto;
    }

    body {
        background-attachment: scroll;
    }

    .margin-garden {
        width: 28px;
    }

    #manuscript-container {
        display: block;
        grid-template-columns: 1fr;
        height: auto;
        padding: 16px 28px;
    }

    #spine {
        display: none;
    }

    .pane {
        height: auto;
        overflow: visible;
    }

    #pane-left,
    #pane-right {
        padding: 0;
    }

    .pane-scroll-content {
        transform: none !important;
    }

    .section {
        min-height: auto;
        padding: 24px 0;
    }

    .section + .section {
        border-top: 1px solid rgba(139, 105, 20, 0.18);
    }

    .glass-panel {
        max-width: 100%;
        padding: 32px 24px;
    }

    #site-title {
        font-size: clamp(2.5rem, 12vw, 4rem);
    }

    #toc-panel {
        right: 16px;
        bottom: 88px;
    }

    #toc-toggle {
        right: 16px;
        bottom: 16px;
    }
}

/* ============================================================
   Pressed Specimen Effect — second glass layer
   ============================================================ */
.herbarium-panel::after {
    content: '';
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    bottom: 12px;
    background: rgba(255, 248, 235, 0.10);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 8px;
    pointer-events: none;
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.30);
    z-index: -1;
}

/* Selection style */
::selection {
    background: rgba(212, 162, 78, 0.4);
    color: #2C1A0A;
}

/* ============================================================
   Dark surface body text — for any dark-panel content blocks
   Uses Warm Parchment (#F5E6CC) per palette spec.
   ============================================================ */
.body-text-on-dark {
    color: #F5E6CC;
    background: #2C1A0A;
}

/* Reference swatches kept active to ensure all palette tokens
   from DESIGN.md exist in the compiled stylesheet. */
.palette-fern-stroke { stroke: #4A6741; }
.palette-cream-tint { background-color: rgba(255, 248, 235, 0.25); /* #FFF8EB tint */ }
.palette-warm-parchment { color: #F5E6CC; }

