/* sustaining.quest - Evolved-Minimal Library Aesthetic */

:root {
    --bg-base: #f4f0eb;
    --bg-alt: #e8e0f0;
    --text-primary: #2d2a33;
    --text-secondary: #6b6178;
    --accent-periwinkle: #a8b8e8;
    --accent-rose: #e8b0b8;
    --accent-mint: #a8d0b8;
    --accent-apricot: #f0d0a8;
    --glass-bg: rgba(255, 255, 255, 0.55);
    --glass-border: rgba(255, 255, 255, 0.3);
    --base-unit: 1.6rem;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.1vw, 1.15rem);
    letter-spacing: 0.01em;
    line-height: 1.72;
    color: var(--text-primary);
    background-color: #fff;
    overflow-x: hidden;
    position: relative;
}

body.loaded {
    background-color: var(--bg-base);
    transition: background-color 1.2s ease;
}

/* Dot grid underlay */
.dot-grid {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: radial-gradient(circle, var(--text-secondary) 0.5px, transparent 0.5px);
    background-size: 24px 24px;
    opacity: 0.06;
    pointer-events: none;
    z-index: 0;
}

/* Background gradient orbs */
.orb {
    position: fixed;
    border-radius: 50%;
    filter: blur(60px);
    opacity: 0.4;
    pointer-events: none;
    z-index: 0;
}

.orb-1 {
    width: 350px;
    height: 350px;
    background: radial-gradient(circle, var(--accent-periwinkle), transparent 70%);
    top: 10%;
    left: 5%;
    animation: orbFloat1 18s ease-in-out infinite;
}

.orb-2 {
    width: 280px;
    height: 280px;
    background: radial-gradient(circle, var(--accent-rose), transparent 70%);
    top: 35%;
    right: 8%;
    animation: orbFloat2 22s ease-in-out infinite;
}

.orb-3 {
    width: 320px;
    height: 320px;
    background: radial-gradient(circle, var(--accent-mint), transparent 70%);
    top: 60%;
    left: 15%;
    animation: orbFloat3 20s ease-in-out infinite;
}

.orb-4 {
    width: 250px;
    height: 250px;
    background: radial-gradient(circle, var(--accent-apricot), transparent 70%);
    top: 80%;
    right: 20%;
    animation: orbFloat4 25s ease-in-out infinite;
}

.orb-5 {
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, var(--bg-alt), transparent 70%);
    top: 45%;
    left: 50%;
    animation: orbFloat5 15s ease-in-out infinite;
}

@keyframes orbFloat1 {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(25px, -30px); }
}
@keyframes orbFloat2 {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(-20px, 25px); }
}
@keyframes orbFloat3 {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(30px, 20px); }
}
@keyframes orbFloat4 {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(-25px, -15px); }
}
@keyframes orbFloat5 {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(15px, 30px); }
}

/* Strata */
.stratum {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    padding: 4rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.stratum-label {
    font-family: 'Space Mono', monospace;
    font-weight: 400;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
    opacity: 0.6;
    margin-bottom: calc(var(--base-unit) * 2);
    align-self: flex-start;
}

/* Glassmorphic cards */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(16px) saturate(1.2);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    box-shadow: 0 8px 32px rgba(45, 42, 51, 0.06);
    position: relative;
    overflow: hidden;
}

/* Card glow accents */
.card-glow {
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    filter: blur(40px);
    opacity: 0.35;
    pointer-events: none;
    top: -30px;
    right: -30px;
}

.glow-periwinkle { background: var(--accent-periwinkle); }
.glow-rose { background: var(--accent-rose); }
.glow-mint { background: var(--accent-mint); }
.glow-apricot { background: var(--accent-apricot); }

/* Morph animation */
.morph {
    opacity: 0.3;
    transform: scale(0.6);
    border-radius: 50%;
    backdrop-filter: blur(40px) saturate(1.2);
    -webkit-backdrop-filter: blur(40px) saturate(1.2);
    transition: all 0.9s cubic-bezier(0.16, 1, 0.3, 1);
    transition-delay: calc(var(--card-index, 0) * 120ms);
}

.morph.revealed {
    opacity: 1;
    transform: scale(1);
    border-radius: 1rem;
    backdrop-filter: blur(16px) saturate(1.2);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
}

/* SVG motifs */
.motif-svg {
    color: var(--text-secondary);
    display: block;
    margin: 0 auto var(--base-unit);
}

.motif-svg path,
.motif-svg circle,
.motif-svg rect {
    stroke-dasharray: var(--path-length, 500);
    stroke-dashoffset: var(--path-length, 500);
    transition: stroke-dashoffset 1.5s ease-out;
    transition-delay: calc(var(--card-index, 0) * 120ms + 0.4s);
}

.revealed .motif-svg path,
.revealed .motif-svg circle,
.revealed .motif-svg rect {
    stroke-dashoffset: 0;
}

/* ==================== */
/* STRATUM I - Hero     */
/* ==================== */

.stratum-i {
    background: transparent;
}

.glass-card-hero {
    max-width: 680px;
    width: 100%;
    padding: calc(var(--base-unit) * 3) calc(var(--base-unit) * 2.5);
    text-align: center;
}

.hero-title {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: clamp(2rem, 4.5vw, 3.8rem);
    letter-spacing: -0.02em;
    line-height: 1.12;
    color: var(--text-primary);
    margin-bottom: var(--base-unit);
}

.hero-dot {
    color: var(--accent-periwinkle);
}

.hero-epigraph {
    font-family: 'Caveat', cursive;
    font-weight: 400;
    font-size: clamp(1rem, 1.4vw, 1.3rem);
    line-height: 1.5;
    color: var(--text-secondary);
    max-width: 520px;
    margin: 0 auto;
}

/* Typewriter effect */
.typewriter {
    overflow: hidden;
    white-space: nowrap;
    border-right: 2px solid var(--accent-periwinkle);
    width: 0;
    animation: typewriter 2.5s steps(90, end) 1.5s forwards, blinkCaret 0.75s step-end infinite;
}

@keyframes typewriter {
    from { width: 0; }
    to { width: 100%; }
}

@keyframes blinkCaret {
    from, to { border-color: transparent; }
    50% { border-color: var(--accent-periwinkle); }
}

/* ========================= */
/* STRATUM II - Archive Grid */
/* ========================= */

.stratum-ii {
    padding-top: calc(var(--base-unit) * 4);
    padding-bottom: calc(var(--base-unit) * 4);
    min-height: auto;
}

.masonry-grid {
    columns: 3;
    column-gap: 2.4rem;
    max-width: 1200px;
    width: 100%;
}

.masonry-card {
    break-inside: avoid;
    margin-bottom: 2.4rem;
    padding: calc(var(--base-unit) * 1.5);
    display: inline-block;
    width: 100%;
}

.masonry-card:nth-child(odd) {
    transform: rotate(-0.8deg);
}

.masonry-card:nth-child(even) {
    transform: rotate(0.8deg);
}

.masonry-card.revealed:nth-child(odd) {
    transform: scale(1) rotate(-0.8deg);
}

.masonry-card.revealed:nth-child(even) {
    transform: scale(1) rotate(0.8deg);
}

.card-heading {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: clamp(1.1rem, 1.6vw, 1.4rem);
    letter-spacing: -0.02em;
    line-height: 1.2;
    color: var(--text-primary);
    margin-bottom: calc(var(--base-unit) * 0.75);
}

.card-body {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.85rem, 1vw, 1rem);
    line-height: 1.72;
    color: var(--text-primary);
}

.card-aside {
    font-family: 'Caveat', cursive;
    font-size: clamp(0.9rem, 1.2vw, 1.1rem);
    color: var(--text-secondary);
    margin-top: calc(var(--base-unit) * 0.5);
    line-height: 1.5;
}

.card-annotation {
    font-family: 'Caveat', cursive;
    font-size: clamp(0.85rem, 1.2vw, 1.1rem);
    color: var(--text-secondary);
    line-height: 1.5;
    text-align: center;
}

.card-display-text {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: clamp(1.4rem, 2.5vw, 2.2rem);
    letter-spacing: -0.02em;
    line-height: 1.2;
    color: var(--text-primary);
    text-align: center;
    padding: calc(var(--base-unit) * 1.5) 0;
}

/* =========================== */
/* STRATUM III - Marginalia    */
/* =========================== */

.stratum-iii {
    background: var(--bg-alt);
    padding-top: calc(var(--base-unit) * 4);
    padding-bottom: calc(var(--base-unit) * 4);
}

.marginalia-panel {
    max-width: 1100px;
    width: 100%;
    min-height: 60vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
    position: relative;
}

.marginalia-body {
    padding: calc(var(--base-unit) * 2.5);
    border-right: 1px dashed var(--accent-periwinkle);
}

.marginalia-title {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: clamp(1.5rem, 2.5vw, 2.2rem);
    letter-spacing: -0.02em;
    line-height: 1.12;
    color: var(--text-primary);
    margin-bottom: calc(var(--base-unit) * 1.5);
}

.marginalia-text {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.85rem, 1vw, 1rem);
    line-height: 1.72;
    color: var(--text-primary);
    margin-bottom: var(--base-unit);
}

.marginalia-notes {
    position: relative;
    padding: calc(var(--base-unit) * 2);
}

.annotation {
    position: absolute;
    left: var(--note-x, 10%);
    top: var(--note-y, 10%);
    font-family: 'Caveat', cursive;
    font-size: clamp(0.85rem, 1.1vw, 1rem);
    color: var(--text-secondary);
    line-height: 1.4;
    max-width: 200px;
    opacity: 0;
    transition: opacity 0.6s ease 0.5s;
}

.revealed .annotation {
    opacity: 1;
}

.annotation-1 { transition-delay: 0.6s; }
.annotation-2 { transition-delay: 0.9s; }
.annotation-3 { transition-delay: 1.2s; }
.annotation-4 { transition-delay: 1.5s; }
.annotation-5 { transition-delay: 1.8s; }

.flourish {
    position: absolute;
    left: var(--fl-x, 50%);
    top: var(--fl-y, 50%);
    color: var(--accent-periwinkle);
    font-size: 1.2rem;
    pointer-events: none;
}

.flourish-asterisk {
    animation: spinSlow 20s linear infinite;
}

.flourish-dash {
    color: var(--accent-rose);
    font-size: 0.8rem;
    letter-spacing: -0.2em;
    transition: letter-spacing 0.4s ease;
}

.flourish-dash:hover {
    letter-spacing: 0.3em;
}

.flourish-dot {
    width: 6px;
    height: 6px;
    background: var(--accent-mint);
    border-radius: 50%;
    display: inline-block;
    animation: pulseDot 3s ease-in-out infinite;
}

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

@keyframes pulseDot {
    0%, 100% { transform: scale(1); opacity: 0.6; }
    50% { transform: scale(1.5); opacity: 1; }
}

/* ========================= */
/* STRATUM IV - Book Shelf   */
/* ========================= */

.stratum-iv {
    min-height: 100vh;
    padding-top: calc(var(--base-unit) * 4);
    padding-bottom: calc(var(--base-unit) * 4);
}

.book-shelf {
    display: flex;
    gap: 1.2rem;
    justify-content: center;
    align-items: center;
    height: 420px;
    max-width: 1000px;
    width: 100%;
}

.book-spine {
    background: var(--glass-bg);
    backdrop-filter: blur(16px) saturate(1.2);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    box-shadow: 0 8px 32px rgba(45, 42, 51, 0.06);
    width: 80px;
    height: 400px;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    transition: width 0.7s cubic-bezier(0.16, 1, 0.3, 1);
    flex-shrink: 0;
}

.book-spine::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--spine-tint);
    opacity: 0.15;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.book-spine.active::before {
    opacity: 0.25;
}

.book-spine.active {
    width: 360px;
}

.book-spine:not(.active) {
    width: 60px;
}

.book-spine:not(.active):not(.shrunk) {
    width: 80px;
}

.spine-label {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: 0.9rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-primary);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    white-space: nowrap;
    transition: opacity 0.3s ease;
}

.book-spine.active .spine-label {
    opacity: 0;
}

.spine-content {
    opacity: 0;
    padding: calc(var(--base-unit) * 1.5);
    position: absolute;
    top: 0;
    left: 0;
    width: 360px;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    transition: opacity 0.5s ease 0.3s;
    pointer-events: none;
}

.book-spine.active .spine-content {
    opacity: 1;
    pointer-events: auto;
}

.spine-content h3 {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: clamp(1rem, 1.4vw, 1.3rem);
    letter-spacing: -0.02em;
    line-height: 1.2;
    color: var(--text-primary);
    margin-bottom: calc(var(--base-unit) * 0.75);
}

.spine-content p {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.8rem, 0.95vw, 0.95rem);
    line-height: 1.65;
    color: var(--text-primary);
    margin-bottom: var(--base-unit);
}

.spine-motif {
    margin-top: auto;
}

/* ===================== */
/* STRATUM V - Colophon  */
/* ===================== */

.stratum-v {
    min-height: 80vh;
    background: transparent;
}

.colophon-card {
    max-width: 580px;
    width: 100%;
    padding: calc(var(--base-unit) * 3) calc(var(--base-unit) * 2.5);
    text-align: center;
}

.colophon-title {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: clamp(2rem, 4vw, 3.4rem);
    letter-spacing: -0.02em;
    line-height: 1.12;
    color: var(--text-primary);
    margin-bottom: var(--base-unit);
}

.colophon-text {
    font-family: 'Caveat', cursive;
    font-weight: 400;
    font-size: clamp(1.1rem, 1.5vw, 1.4rem);
    line-height: 1.5;
    color: var(--text-secondary);
    margin-bottom: calc(var(--base-unit) * 2);
}

/* Dashed rule between strata */
.stratum-ii::before,
.stratum-iv::before {
    content: '';
    display: block;
    width: 60%;
    max-width: 400px;
    border-top: 1px dashed var(--accent-periwinkle);
    opacity: 0.4;
    margin: 0 auto calc(var(--base-unit) * 2);
}

/* =================== */
/* Responsive          */
/* =================== */

@media (max-width: 1023px) {
    .masonry-grid {
        columns: 2;
    }

    .book-shelf {
        height: 350px;
    }

    .book-spine {
        height: 340px;
    }

    .book-spine.active {
        width: 280px;
    }

    .spine-content {
        width: 280px;
    }

    .stratum {
        padding: 3rem 2.5rem;
    }
}

@media (max-width: 767px) {
    .masonry-grid {
        columns: 1;
    }

    .masonry-card {
        margin-bottom: 3rem;
    }

    .masonry-card:nth-child(odd),
    .masonry-card:nth-child(even) {
        transform: rotate(0);
    }

    .masonry-card.revealed:nth-child(odd),
    .masonry-card.revealed:nth-child(even) {
        transform: scale(1) rotate(0);
    }

    .stratum {
        padding: 2rem 1.5rem;
    }

    .marginalia-panel {
        grid-template-columns: 1fr;
    }

    .marginalia-body {
        border-right: none;
        border-bottom: 1px dashed var(--accent-periwinkle);
    }

    .marginalia-notes {
        min-height: 300px;
    }

    .book-shelf {
        flex-direction: column;
        height: auto;
        gap: 1rem;
    }

    .book-spine {
        width: 100% !important;
        height: 60px;
        writing-mode: horizontal-tb;
    }

    .book-spine.active {
        width: 100% !important;
        height: 350px;
    }

    .spine-label {
        writing-mode: horizontal-tb;
    }

    .spine-content {
        width: 100%;
        height: 350px;
    }

    .hero-epigraph.typewriter {
        white-space: normal;
        width: auto;
        border-right: none;
        animation: fadeInText 1.5s ease 1.5s forwards;
        opacity: 0;
    }

    @keyframes fadeInText {
        to { opacity: 1; }
    }

    .orb {
        opacity: 0.2;
    }

    .orb-1, .orb-2, .orb-3, .orb-4, .orb-5 {
        width: 200px;
        height: 200px;
    }
}