/* ===========================================================
   mosoon.org -- The Midnight Library
   Palette: violet-shifted midnight (220-270deg hues only)
   Typography: Commissioner (variable-axis, monastic discipline)
     -- sole typeface family; Inter / Space Grotesk are NOT used
     -- Interactive labels / spine-index text: "Commissioner"
        at weight 500 (medium lavender)
   Layout: ma (negative space) -- 12-col grid, content in cols 3-9
   =========================================================== */

:root {
    /* Palette ----------------------------------------------- */
    --abyssal-indigo:   #0C0E1A;   /* primary background, the void */
    --midnight-ink:     #151829;   /* elevated surfaces, interstitials */
    --night-shelf:      #1C1F35;   /* hover state, ghost folio numbers */
    --lavender-frost:   #C4B5FD;   /* primary headings */
    --dusk-violet:      #8B7EC8;   /* rubrics, section labels */
    --muted-lilac:      #B8B0D4;   /* body text */
    --shadow-violet:    #5A5380;   /* marginalia, decorative text */
    --monsoon-silver:   #D6D0E8;   /* selection, rare emphasis */
    --phosphor-indigo:  #7B68AE;   /* glow accents */
    --medium-lavender:  #9B8EC6;   /* spine label hover */

    /* Typography ------------------------------------------- */
    --font-stack: "Commissioner", "Inter", "Helvetica Neue", system-ui, sans-serif;

    /* Geometry --------------------------------------------- */
    --margin-side: 12vw;
    --col-width: calc((100vw - (var(--margin-side) * 2)) / 12);

    /* Easing & timings ------------------------------------- */
    --ease-nocturnal: cubic-bezier(0.25, 0.1, 0.25, 1.0);
    --reveal-duration: 1100ms;
    --margin-fade-in: 800ms;
    --margin-fade-out: 1200ms;
}

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

html {
    scroll-behavior: smooth;
    background: var(--abyssal-indigo);
    /* No scroll-snap. Folios are suggestions. */
}

body {
    font-family: var(--font-stack);
    font-weight: 400;
    color: var(--muted-lilac);
    background: var(--abyssal-indigo);
    overflow-x: hidden;
    line-height: 1.85;
    font-feature-settings: "liga" 1, "kern" 1;
    font-variation-settings: "wdth" 100;
    min-height: 100vh;
    position: relative;
}

::selection {
    background: var(--monsoon-silver);
    color: var(--abyssal-indigo);
}
::-moz-selection {
    background: var(--monsoon-silver);
    color: var(--abyssal-indigo);
}

/* Custom scrollbar ----------------------------------------- */
html::-webkit-scrollbar,
body::-webkit-scrollbar {
    width: 6px;
}
html::-webkit-scrollbar-track,
body::-webkit-scrollbar-track {
    background: var(--abyssal-indigo);
}
html::-webkit-scrollbar-thumb,
body::-webkit-scrollbar-thumb {
    background: var(--shadow-violet);
    border-radius: 3px;
    transition: background 600ms var(--ease-nocturnal);
}
html::-webkit-scrollbar-thumb:hover,
body::-webkit-scrollbar-thumb:hover {
    background: var(--dusk-violet);
}
html {
    scrollbar-width: thin;
    scrollbar-color: var(--shadow-violet) var(--abyssal-indigo);
}

.svg-defs {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
    pointer-events: none;
}

/* ===========================================================
   ATMOSPHERE -- noise, rain, vignette
   =========================================================== */
.atmosphere {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1;
}

.noise-layer {
    position: absolute;
    inset: -10%;
    pointer-events: none;
    mix-blend-mode: screen;
}

.noise-global {
    background-color: transparent;
    filter: url(#noise);
    opacity: 0.035;
    animation: noise-breathe 30s var(--ease-nocturnal) infinite alternate;
}
.noise-global::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--phosphor-indigo);
    filter: url(#noise);
    opacity: 1;
    mix-blend-mode: normal;
}

.rain-layer {
    filter: url(#rain);
    opacity: 0.02;
}
.rain-layer::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--phosphor-indigo);
    filter: url(#rain);
    animation: rain-drift 24s linear infinite;
}

.vignette {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(
            ellipse at center,
            transparent 30%,
            rgba(12, 14, 26, 0.55) 80%,
            rgba(12, 14, 26, 0.85) 100%
        );
}

@keyframes noise-breathe {
    0%   { opacity: 0.030; transform: translate3d(0, 0, 0); }
    50%  { opacity: 0.040; transform: translate3d(-0.5%, 0.3%, 0); }
    100% { opacity: 0.032; transform: translate3d(0.4%, -0.2%, 0); }
}
@keyframes rain-drift {
    0%   { transform: translate3d(0, 0, 0); }
    100% { transform: translate3d(0, 4%, 0); }
}

/* ===========================================================
   SPINE INDEX -- left edge progressive navigation
   =========================================================== */
.spine-index {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 4vw;
    min-width: 60px;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--reveal-duration) var(--ease-nocturnal);
}

.spine-index.visible {
    opacity: 1;
}

.spine-line {
    position: absolute;
    top: 12vh;
    bottom: 12vh;
    left: 50%;
    width: 1px;
    background: linear-gradient(
        to bottom,
        transparent 0%,
        var(--shadow-violet) 8%,
        var(--shadow-violet) 92%,
        transparent 100%
    );
    opacity: 0.55;
    transform: translateX(-50%);
}

.spine-nodes {
    list-style: none;
    position: absolute;
    top: 12vh;
    bottom: 12vh;
    left: 50%;
    width: 1px;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    pointer-events: auto;
}

.spine-item {
    position: relative;
    display: flex;
    align-items: center;
    pointer-events: auto;
}

.spine-node {
    appearance: none;
    border: none;
    background: var(--shadow-violet);
    width: 0;
    height: 0;
    border-radius: 50%;
    cursor: pointer;
    padding: 0;
    transition:
        width 400ms var(--ease-nocturnal),
        height 400ms var(--ease-nocturnal),
        background 600ms var(--ease-nocturnal),
        box-shadow 800ms var(--ease-nocturnal);
    position: relative;
    display: block;
}

.spine-item.materialized .spine-node {
    width: 6px;
    height: 6px;
}

.spine-item.active .spine-node {
    background: var(--lavender-frost);
    box-shadow:
        0 0 8px var(--phosphor-indigo),
        0 0 18px rgba(123, 104, 174, 0.45);
    animation: spine-pulse 3.2s var(--ease-nocturnal) infinite;
}

@keyframes spine-pulse {
    0%, 100% {
        box-shadow:
            0 0 6px var(--phosphor-indigo),
            0 0 14px rgba(123, 104, 174, 0.35);
    }
    50% {
        box-shadow:
            0 0 12px var(--phosphor-indigo),
            0 0 24px rgba(123, 104, 174, 0.65);
    }
}

.spine-label {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%) translateX(-6px);
    font-family: var(--font-stack);
    font-weight: 500;
    font-size: 0.7rem;
    color: var(--medium-lavender);
    white-space: nowrap;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    opacity: 0;
    transition:
        opacity 600ms var(--ease-nocturnal),
        transform 600ms var(--ease-nocturnal);
    pointer-events: none;
    font-variation-settings: "wdth" 100;
}

.spine-item:hover .spine-label,
.spine-item.active .spine-label {
    opacity: 0.85;
    transform: translateY(-50%) translateX(0);
}

/* ===========================================================
   MARGIN HOVER ZONES (for marginalia activation)
   =========================================================== */
.margin-zone {
    position: fixed;
    top: 0;
    bottom: 0;
    width: var(--margin-side);
    z-index: 5;
    pointer-events: auto;
    /* invisible -- only used for hover detection */
}
.margin-zone-left  { left: 0; }
.margin-zone-right { right: 0; }

/* On touch devices, marginalia is always softly visible */
@media (hover: none) {
    .margin-glyphs {
        opacity: 0.3 !important;
    }
}

/* ===========================================================
   MANUSCRIPT (main container)
   =========================================================== */
.manuscript {
    position: relative;
    z-index: 10;
    width: 100%;
}

/* ===========================================================
   FOLIO -- a single section, 80-100vh, with margin glyphs
   =========================================================== */
.folio {
    position: relative;
    min-height: 100vh;
    width: 100%;
    padding: 14vh var(--margin-side) 14vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
}

.folio-threshold   { min-height: 100vh; }
.folio-reading-room { min-height: 90vh; }
.folio-marginalia  { min-height: 95vh; }
.folio-compartment { min-height: 100vh; }
.folio-annotations { min-height: 110vh; }
.folio-shelf       { min-height: 120vh; }
.folio-colophon    { min-height: 80vh; }

/* Folio number -- enormous, ghost-faint, in the margin */
.folio-number {
    position: absolute;
    top: 18%;
    left: 4vw;
    font-family: var(--font-stack);
    font-weight: 200;
    font-variation-settings: "wdth" 100, "wght" 200;
    font-size: 4rem;
    color: var(--night-shelf);
    letter-spacing: 0.08em;
    line-height: 1;
    pointer-events: none;
    user-select: none;
    text-transform: uppercase;
    font-style: normal;
}

.folio:nth-child(odd) .folio-number {
    left: auto;
    right: 4vw;
}

.folio-content {
    width: 100%;
    max-width: 38em;
    position: relative;
    z-index: 2;
    /* Stepped indentation: "headings align col 3, body col 4" */
    margin-left: calc(var(--col-width) * 0);
}

.folio-content-empty {
    max-width: 32em;
    text-align: left;
}

.folio-content-dense {
    max-width: 40em;
}

.folio-content-densest {
    max-width: 42em;
}

.folio-content-colophon {
    max-width: 36em;
    text-align: left;
}

/* ===========================================================
   TYPOGRAPHY -- Commissioner-Versatile System
   =========================================================== */

/* Folio title -- the single page-defining heading */
.folio-title {
    font-family: var(--font-stack);
    font-weight: 700;
    font-variation-settings: "wdth" 100, "wght" 700;
    font-size: clamp(3.2rem, 7vw, 5rem);
    line-height: 1.05;
    color: var(--lavender-frost);
    letter-spacing: 0.08em;
    margin: 0.2em 0 0.6em;
    text-transform: lowercase;
    font-style: normal;
}

/* Folio heading -- larger sub-titles inside a folio */
.folio-heading {
    font-family: var(--font-stack);
    font-weight: 700;
    font-variation-settings: "wdth" 100, "wght" 700;
    font-size: clamp(1.8rem, 3.4vw, 2.6rem);
    line-height: 1.2;
    color: var(--lavender-frost);
    letter-spacing: 0.05em;
    margin: 0 0 1.2em;
    /* Stepped offset: heading sits at column 3 (start of content area) */
    margin-left: 0;
    font-style: normal;
}

/* Rubric -- "section label" small caps */
.rubric {
    font-family: var(--font-stack);
    font-weight: 300;
    font-variation-settings: "wdth" 87.5, "wght" 300;
    font-size: 1.1rem;
    color: var(--dusk-violet);
    text-transform: uppercase;
    letter-spacing: 0.2em;
    margin: 0 0 1.4em;
    /* a tiny indent */
    padding-left: 0;
}

/* Body text -- the readable measure */
.body-text {
    font-family: var(--font-stack);
    font-weight: 400;
    font-variation-settings: "wdth" 100, "wght" 400;
    font-size: 1.05rem;
    line-height: 1.85;
    color: var(--muted-lilac);
    max-width: 38em;
    margin: 0 0 1.6em;
    /* Stepped: body indented from heading by ~1 column */
    margin-left: calc(var(--col-width) * 0.55);
}

.body-text em {
    font-style: italic;
    color: var(--dusk-violet);
    font-variation-settings: "wdth" 100, "wght" 400;
}

.incipit {
    font-family: var(--font-stack);
    font-weight: 300;
    font-style: italic;
    font-variation-settings: "wdth" 100, "wght" 300;
    font-size: clamp(1.05rem, 1.6vw, 1.25rem);
    line-height: 1.9;
    color: var(--muted-lilac);
    letter-spacing: 0.02em;
    max-width: 28em;
    margin: 0 auto;
}

/* Marginalia inline -- the whispered footer of each folio */
.marginalia-inline {
    font-family: var(--font-stack);
    font-weight: 200;
    font-style: italic;
    font-variation-settings: "wdth" 112.5, "wght" 200;
    font-size: 0.78rem;
    line-height: 1.6;
    color: var(--shadow-violet);
    letter-spacing: 0.04em;
    margin-top: 2.4em;
    margin-left: calc(var(--col-width) * 1.2);
    transform: rotate(-1deg);
    transform-origin: left center;
}

/* Hidden annotation -- the inline scholarly footnote */
.hidden-annotation {
    position: relative;
    color: inherit;
    cursor: help;
    background-image: linear-gradient(
        to right,
        var(--phosphor-indigo),
        var(--phosphor-indigo)
    );
    background-repeat: no-repeat;
    background-position: 0 100%;
    background-size: 0% 1px;
    transition: background-size 700ms var(--ease-nocturnal);
    padding-bottom: 2px;
}

.hidden-annotation:hover {
    background-size: 100% 1px;
}

.hidden-annotation::after {
    content: attr(data-annotation);
    position: absolute;
    left: 0;
    top: calc(100% + 8px);
    width: clamp(18em, 24em, 30em);
    max-width: 30em;
    padding: 0.85em 1.1em;
    background: var(--midnight-ink);
    color: var(--muted-lilac);
    font-family: var(--font-stack);
    font-weight: 300;
    font-variation-settings: "wdth" 100, "wght" 300;
    font-style: italic;
    font-size: 0.86rem;
    line-height: 1.6;
    letter-spacing: 0.01em;
    border-left: 1px solid var(--phosphor-indigo);
    box-shadow:
        0 8px 24px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(123, 104, 174, 0.15);
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
    transition:
        opacity 800ms var(--ease-nocturnal),
        transform 800ms var(--ease-nocturnal);
    z-index: 50;
    border-radius: 1px;
}

.hidden-annotation:hover::after {
    opacity: 1;
    transform: translateY(0);
}

/* ===========================================================
   MARGIN GLYPHS -- decorative marginalia
   =========================================================== */
.margin-glyphs {
    position: absolute;
    top: 0;
    bottom: 0;
    width: var(--margin-side);
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--margin-fade-out) var(--ease-nocturnal);
    z-index: 1;
}

.margin-glyphs.visible {
    opacity: 1;
    transition: opacity var(--margin-fade-in) var(--ease-nocturnal);
}

.margin-glyphs-left  { left: 0; }
.margin-glyphs-right { right: 0; }

.glyph {
    position: absolute;
    font-family: var(--font-stack);
    font-weight: 200;
    font-variation-settings: "wdth" 112.5, "wght" 200;
    font-size: 0.85rem;
    color: var(--shadow-violet);
    opacity: 0.45;
    letter-spacing: 0.04em;
    white-space: nowrap;
    transform-origin: center;
    user-select: none;
    line-height: 1;
}

.margin-glyphs-left .glyph  { left: 28%; }
.margin-glyphs-right .glyph { right: 28%; }

.glyph.annotation {
    font-size: 0.65rem;
    font-style: italic;
    opacity: 0.55;
    color: var(--shadow-violet);
    max-width: 9em;
    white-space: normal;
    line-height: 1.4;
}

.margin-glyphs-left .glyph.annotation  { left: 12%; }
.margin-glyphs-right .glyph.annotation { right: 12%; }

/* ===========================================================
   INTERSTITIAL -- the page-turn between folios
   =========================================================== */
.interstitial {
    position: relative;
    width: 100%;
    min-height: 60vh;
    background: var(--midnight-ink);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6vh var(--margin-side);
    z-index: 8;
    overflow: hidden;
}

.interstitial::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: radial-gradient(
        ellipse at center,
        rgba(123, 104, 174, 0.04) 0%,
        transparent 70%
    );
    pointer-events: none;
}

.interstitial-mark {
    position: relative;
    color: var(--dusk-violet);
    opacity: 0;
    transform: translateY(20px);
    transition:
        opacity 1200ms var(--ease-nocturnal),
        transform 1500ms var(--ease-nocturnal);
}

.interstitial.revealed .interstitial-mark {
    opacity: 1;
    transform: translateY(0);
}

.cryptic-notation {
    font-family: var(--font-stack);
    font-weight: 200;
    font-style: italic;
    font-variation-settings: "wdth" 112.5, "wght" 200;
    font-size: 0.95rem;
    color: var(--shadow-violet);
    letter-spacing: 0.3em;
    text-transform: lowercase;
    opacity: 0.7;
}

.spine-divider {
    width: 18vw;
    max-width: 360px;
    height: 1px;
    background: var(--dusk-violet);
    opacity: 0.4;
    position: relative;
}
.spine-divider::before,
.spine-divider::after {
    content: "";
    position: absolute;
    top: 50%;
    width: 6px;
    height: 6px;
    border: 1px solid var(--dusk-violet);
    border-radius: 50%;
    background: transparent;
    transform: translateY(-50%);
    opacity: 0.7;
}
.spine-divider::before { left: -16px; }
.spine-divider::after  { right: -16px; }

/* ===========================================================
   BOOK MOTIF -- the recurring open-book glyph
   =========================================================== */
.book-icon {
    width: 64px;
    height: 64px;
    display: block;
    color: var(--lavender-frost);
    filter: drop-shadow(0 0 14px rgba(123, 104, 174, 0.55));
    animation: book-glow 2.4s var(--ease-nocturnal) infinite alternate;
}

.book-icon-small {
    width: 40px;
    height: 40px;
    color: var(--dusk-violet);
    filter: drop-shadow(0 0 10px rgba(123, 104, 174, 0.45));
}

.book-motif {
    margin: 2.4em 0 2em;
    margin-left: calc(var(--col-width) * 0.55);
    display: flex;
    justify-content: flex-start;
    align-items: center;
    opacity: 0.85;
}

.book-motif-large .book-icon {
    width: 88px;
    height: 88px;
}

@keyframes book-glow {
    0% {
        filter: drop-shadow(0 0 8px rgba(123, 104, 174, 0.30));
        opacity: 0.85;
    }
    100% {
        filter: drop-shadow(0 0 22px rgba(123, 104, 174, 0.70));
        opacity: 1;
    }
}

/* ===========================================================
   PAGE-CORNER FOLDS -- ghost bookmarks at content edges
   =========================================================== */
.folio-content::before {
    content: "";
    position: absolute;
    top: -8px;
    right: -8px;
    width: 28px;
    height: 28px;
    background: var(--night-shelf);
    clip-path: polygon(100% 0, 0 0, 100% 100%);
    opacity: 0.5;
    pointer-events: none;
}

.folio-content::after {
    content: "";
    position: absolute;
    bottom: -6px;
    left: -10px;
    width: 22px;
    height: 22px;
    background: var(--night-shelf);
    clip-path: polygon(0 100%, 0 0, 100% 100%);
    opacity: 0.35;
    pointer-events: none;
}

/* ===========================================================
   PROGRESSIVE-DISCLOSURE / SCROLL REVEAL
   =========================================================== */
.reveal-line {
    opacity: 0;
    transform: translateY(20px);
    transition:
        opacity var(--reveal-duration) var(--ease-nocturnal),
        transform var(--reveal-duration) var(--ease-nocturnal);
    will-change: opacity, transform;
}

.reveal-line.is-revealed {
    opacity: 1;
    transform: translateY(0);
}

/* the folio-title gets a slightly stronger reveal */
.folio-title.reveal-line {
    transition:
        opacity 1400ms var(--ease-nocturnal),
        transform 1400ms var(--ease-nocturnal);
}

/* ===========================================================
   RESPONSIVE -- preserve ma even on smaller screens
   =========================================================== */
@media (max-width: 900px) {
    :root {
        --margin-side: 9vw;
    }
    .folio {
        padding: 12vh var(--margin-side) 12vh;
    }
    .folio-number {
        font-size: 3rem;
        top: 12%;
    }
    .body-text {
        margin-left: 0;
        font-size: 1rem;
    }
    .marginalia-inline {
        margin-left: 0;
    }
    .book-motif {
        margin-left: 0;
    }
    .glyph,
    .glyph.annotation {
        font-size: 0.6rem;
    }
}

@media (max-width: 640px) {
    :root {
        --margin-side: 7vw;
    }
    .spine-index {
        width: 36px;
        min-width: 36px;
    }
    .spine-label {
        display: none;
    }
    .folio-title {
        font-size: 2.6rem;
    }
    .folio-heading {
        font-size: 1.6rem;
    }
    .hidden-annotation::after {
        width: min(80vw, 22em);
    }
    .margin-glyphs-left .glyph.annotation,
    .margin-glyphs-right .glyph.annotation {
        max-width: 6em;
    }
}

/* ===========================================================
   REDUCED MOTION fallback
   =========================================================== */
@media (prefers-reduced-motion: reduce) {
    .reveal-line {
        opacity: 1;
        transform: none;
        transition: none;
    }
    .noise-global,
    .rain-layer::before,
    .book-icon {
        animation: none;
    }
    .interstitial-mark {
        opacity: 1;
        transform: none;
    }
}
