/* ============================================
   bada.coffee — Dark Academia Styles
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    /* Palette */
    --obsidian-night: #0D0D12;
    --library-mahogany: #1A1019;
    --aged-gold: #C9A96E;
    --twilight-violet: #6B4E8B;
    --manuscript-emerald: #3D6B5E;
    --parchment-cream: #E8DCC8;
    --faded-copper: #A0826D;
    --mist-silver: #8B9DAF;
    --neon-amber: #FFB347;
    --void-black: #05050A;

    /* Fluid Type Scale — Perfect Fourth (1.333) */
    --step-0: clamp(1rem, 1.2vw + 0.5rem, 1.25rem);
    --step-1: clamp(1.33rem, 1.6vw + 0.65rem, 1.666rem);
    --step-2: clamp(1.777rem, 2.1vw + 0.85rem, 2.221rem);
    --step-3: clamp(2.369rem, 2.8vw + 1.1rem, 2.96rem);
    --step-4: clamp(2.5rem, 5vw + 1rem, 5rem);
    --step-sm: clamp(0.75rem, 0.9vw + 0.3rem, 0.95rem);
    --step-mono: clamp(0.7rem, 0.8vw + 0.3rem, 0.85rem);
}

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
    overflow-x: hidden;
}

body {
    font-family: 'Lora', Georgia, serif;
    font-weight: 400;
    font-size: var(--step-0);
    line-height: 1.75;
    color: var(--parchment-cream);
    background-color: var(--obsidian-night);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Mountain Background Layers --- */
.mountain-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.mountain-layer {
    position: absolute;
    bottom: 0;
    left: -5%;
    width: 110%;
    height: 100%;
}

.mountain-layer-1 {
    z-index: 1;
    background:
        linear-gradient(180deg, transparent 55%, var(--void-black) 55%, var(--void-black) 100%);
    clip-path: polygon(
        0% 100%, 0% 72%, 5% 68%, 12% 63%, 18% 58%, 25% 55%, 32% 60%, 38% 56%, 44% 52%, 50% 48%, 55% 53%, 60% 50%, 66% 46%, 72% 50%, 78% 54%, 84% 49%, 90% 45%, 95% 50%, 100% 47%, 100% 100%
    );
    opacity: 1;
    animation: mountainBreathe1 8s ease-in-out infinite;
}

.mountain-layer-2 {
    z-index: 2;
    background: linear-gradient(180deg, transparent 55%, #0F0D18 55%, #0F0D18 100%);
    clip-path: polygon(
        0% 100%, 0% 68%, 8% 65%, 15% 60%, 22% 63%, 28% 58%, 35% 55%, 42% 60%, 48% 57%, 55% 62%, 62% 58%, 68% 55%, 75% 59%, 82% 62%, 88% 57%, 94% 54%, 100% 58%, 100% 100%
    );
    opacity: 0.85;
    animation: mountainBreathe2 8s ease-in-out infinite;
}

.mountain-layer-3 {
    z-index: 3;
    background: linear-gradient(180deg, transparent 60%, #1A1325 60%, #1A1325 100%);
    clip-path: polygon(
        0% 100%, 0% 75%, 6% 71%, 14% 68%, 20% 72%, 26% 68%, 34% 65%, 40% 70%, 46% 67%, 54% 72%, 60% 68%, 67% 65%, 74% 69%, 80% 73%, 86% 68%, 92% 65%, 100% 70%, 100% 100%
    );
    opacity: 0.7;
    animation: mountainBreathe3 8s ease-in-out infinite;
}

.mountain-layer-4 {
    z-index: 4;
    background: linear-gradient(180deg, transparent 65%, #2A1F3A 65%, #2A1F3A 100%);
    clip-path: polygon(
        0% 100%, 0% 80%, 7% 77%, 16% 74%, 23% 78%, 30% 75%, 37% 72%, 45% 76%, 52% 73%, 58% 77%, 65% 74%, 72% 71%, 79% 75%, 85% 78%, 92% 74%, 100% 76%, 100% 100%
    );
    opacity: 0.5;
    animation: mountainBreathe4 8s ease-in-out infinite;
}

.mountain-layer-5 {
    z-index: 5;
    background: linear-gradient(180deg, transparent 70%, rgba(107, 78, 139, 0.3) 70%, rgba(107, 78, 139, 0.2) 100%);
    clip-path: polygon(
        0% 100%, 0% 83%, 10% 81%, 18% 79%, 27% 82%, 35% 80%, 43% 78%, 52% 81%, 60% 79%, 68% 82%, 76% 80%, 84% 78%, 92% 81%, 100% 79%, 100% 100%
    );
    opacity: 0.35;
    animation: mountainBreathe5 8s ease-in-out infinite;
}

@keyframes mountainBreathe1 {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}
@keyframes mountainBreathe2 {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-2px); }
}
@keyframes mountainBreathe3 {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(2px); }
}
@keyframes mountainBreathe4 {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(1px); }
}
@keyframes mountainBreathe5 {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-1px); }
}

/* --- Constellation Canvas --- */
#constellation-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 6;
    pointer-events: none;
    opacity: 0.15;
}

/* --- Chapter Navigation --- */
.chapter-nav {
    position: fixed;
    right: 2rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    align-items: center;
}

.nav-numeral {
    font-family: 'Playfair Display', serif;
    font-weight: 400;
    font-size: var(--step-sm);
    color: var(--mist-silver);
    text-decoration: none;
    letter-spacing: 0.05em;
    transition: color 400ms ease, text-shadow 400ms ease, box-shadow 400ms ease;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.nav-numeral:hover {
    color: var(--aged-gold);
    text-shadow: 0 0 20px rgba(255, 179, 71, 0.4), 0 0 40px rgba(255, 179, 71, 0.15);
}

.nav-numeral.active {
    color: var(--neon-amber);
    box-shadow: 0 0 12px rgba(201, 169, 110, 0.5);
    animation: numeralPulse 3s ease-in-out infinite;
}

@keyframes numeralPulse {
    0%, 100% { box-shadow: 0 0 12px rgba(201, 169, 110, 0.3); }
    50% { box-shadow: 0 0 12px rgba(201, 169, 110, 0.6); }
}

/* --- Chapter Sections --- */
.chapter {
    position: relative;
    min-height: 100vh;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
}

.chapter-ritual {
    min-height: 120vh;
}

.chapter-return {
    min-height: 80vh;
}

.chapter-content {
    max-width: 1200px;
    width: 100%;
    position: relative;
}

.chapter-centered {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* --- Headings --- */
.chapter-heading {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: var(--step-4);
    color: var(--aged-gold);
    letter-spacing: -0.03em;
    line-height: 1.1;
    margin-bottom: 2rem;
}

.chapter-heading .char {
    display: inline-block;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

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

.chapter-heading.glow-active {
    text-shadow: 0 0 20px rgba(255, 179, 71, 0.4), 0 0 40px rgba(255, 179, 71, 0.15);
}

.chapter-subtitle {
    font-family: 'Crimson Pro', serif;
    font-weight: 300;
    font-style: italic;
    font-size: var(--step-1);
    color: var(--faded-copper);
    margin-bottom: 3rem;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.8s ease 0.6s, transform 0.8s ease 0.6s;
}

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

/* --- Fleurons --- */
.fleuron {
    font-size: var(--step-2);
    color: var(--aged-gold);
    opacity: 0.3;
    display: block;
    margin: 2rem auto;
}

.scroll-invite {
    animation: fleuronBob 2s ease-in-out infinite;
}

@keyframes fleuronBob {
    0%, 100% { transform: translateY(0); opacity: 0.3; }
    50% { transform: translateY(8px); opacity: 0.5; }
}

.fleuron-inline {
    color: var(--aged-gold);
    opacity: 0.4;
    margin-right: 0.5em;
    font-size: 1.2em;
}

.closing-fleuron {
    margin-top: 3rem;
    font-size: var(--step-3);
    opacity: 0;
    transition: opacity 1s ease;
}

.closing-fleuron.visible {
    opacity: 0.3;
}

/* --- Content Panels --- */
.chapter-asymmetric .content-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3rem;
    align-items: start;
}

.content-panel {
    position: relative;
}

.paper-texture {
    background-color: var(--library-mahogany);
    border-radius: 2px;
    padding: 3rem;
    position: relative;
    box-shadow:
        0 4px 30px rgba(5, 5, 10, 0.6),
        inset 0 0 80px rgba(5, 5, 10, 0.2);
}

.paper-texture::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='noise'%3E%3CfeTurbulence baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23noise)' opacity='1'/%3E%3C/svg%3E");
    background-size: 200px 200px;
    border-radius: 2px;
}

/* Ink stain decoration */
.paper-texture::after {
    content: '';
    position: absolute;
    bottom: -10px;
    right: -10px;
    width: 80px;
    height: 80px;
    background: radial-gradient(ellipse at 40% 50%, rgba(5, 5, 10, 0.15) 0%, transparent 70%);
    pointer-events: none;
    border-radius: 50% 30% 50% 40%;
}

.content-main {
    max-width: 65ch;
}

.content-main p {
    margin-bottom: 1.5rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.content-main p.visible,
.scroll-reveal.visible p,
.scroll-reveal.visible {
    opacity: 1;
    transform: translateY(0);
}

/* --- Marginalia --- */
.content-marginalia {
    position: relative;
    padding-left: 2rem;
    border-left: 1px solid rgba(107, 78, 139, 0.3);
}

.pull-quote {
    font-family: 'Crimson Pro', serif;
    font-weight: 300;
    font-style: italic;
    font-size: var(--step-1);
    color: var(--faded-copper);
    line-height: 1.6;
    margin-bottom: 2rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.pull-quote.visible {
    opacity: 1;
    transform: translateY(0);
}

.annotation {
    font-family: 'Crimson Pro', serif;
    font-weight: 400;
    font-style: italic;
    font-size: var(--step-sm);
    color: var(--faded-copper);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.5s ease, transform 0.5s ease;
    margin-bottom: 0.75rem;
}

.annotation.visible {
    opacity: 0.7;
    transform: translateY(0);
}

.mono-accent {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 400;
    font-size: var(--step-mono);
    color: var(--mist-silver);
}

/* --- Coffee Ring Motif --- */
.coffee-ring-motif {
    width: 120px;
    height: 120px;
    margin: 1rem auto 2rem;
    border-radius: 50%;
    background: radial-gradient(
        ellipse at center,
        transparent 38%,
        rgba(160, 130, 109, 0.08) 40%,
        rgba(160, 130, 109, 0.12) 44%,
        rgba(160, 130, 109, 0.06) 48%,
        transparent 52%,
        rgba(160, 130, 109, 0.04) 54%,
        transparent 60%
    );
    animation: coffeeRingPulse 120s linear infinite, coffeeRingBreath 8s ease-in-out infinite;
}

@keyframes coffeeRingPulse {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes coffeeRingBreath {
    0%, 100% { opacity: 0.05; }
    50% { opacity: 0.12; }
}

/* --- Catalog / Collection --- */
.chapter-collection .chapter-content {
    max-width: 1100px;
}

.catalog-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-top: 2rem;
}

.catalog-card {
    padding: 2.5rem;
}

.catalog-name {
    font-family: 'Playfair Display', serif;
    font-weight: 600;
    font-size: var(--step-2);
    color: var(--aged-gold);
    margin-bottom: 1rem;
    letter-spacing: -0.02em;
}

.catalog-description {
    font-family: 'Lora', serif;
    font-size: var(--step-0);
    color: var(--parchment-cream);
    line-height: 1.75;
    margin-bottom: 1.5rem;
}

.catalog-params {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(107, 78, 139, 0.2);
}

.param {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.param-label {
    font-family: 'Crimson Pro', serif;
    font-weight: 400;
    font-style: italic;
    font-size: var(--step-sm);
    color: var(--faded-copper);
}

.param-value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 400;
    font-size: var(--step-mono);
    color: var(--mist-silver);
}

/* --- Scroll Reveal (base state) --- */
.scroll-reveal {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.scroll-reveal.visible {
    opacity: 1;
    transform: translateY(0);
}

/* --- Closing Text --- */
.closing-text {
    font-family: 'Playfair Display', serif;
    font-weight: 400;
    font-size: var(--step-2);
    color: var(--parchment-cream);
    max-width: 50ch;
    line-height: 1.5;
    margin-bottom: 2rem;
    text-align: center;
}

.chapter-return .chapter-heading.glow-active {
    text-shadow: 0 0 30px rgba(255, 179, 71, 0.5), 0 0 60px rgba(255, 179, 71, 0.2), 0 0 90px rgba(255, 179, 71, 0.1);
}

/* --- Link Styles --- */
a:not(.nav-numeral) {
    color: var(--parchment-cream);
    text-decoration: none;
    border-bottom: 1px solid var(--manuscript-emerald);
    transition: border-bottom-width 200ms ease, box-shadow 200ms ease;
}

a:not(.nav-numeral):hover {
    border-bottom-width: 3px;
    box-shadow: 0 2px 8px rgba(61, 107, 94, 0.3);
}

/* --- Section Dividers --- */
.chapter + .chapter::before {
    content: '❧';
    position: absolute;
    top: -1rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.5rem;
    color: var(--aged-gold);
    opacity: 0;
    transition: opacity 0.6s ease;
    z-index: 20;
}

.chapter + .chapter.in-view::before {
    opacity: 0.3;
}

/* --- Responsive --- */
@media (max-width: 900px) {
    .chapter-asymmetric .content-panel {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .content-marginalia {
        padding-left: 0;
        border-left: none;
        border-top: 1px solid rgba(107, 78, 139, 0.3);
        padding-top: 2rem;
    }

    .catalog-grid {
        grid-template-columns: 1fr;
    }

    .chapter-nav {
        right: 1rem;
        gap: 1rem;
    }

    .paper-texture {
        padding: 2rem;
    }
}

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

    .chapter-nav {
        right: 0.5rem;
        gap: 0.75rem;
    }

    .nav-numeral {
        width: 2rem;
        height: 2rem;
        font-size: 0.7rem;
    }
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }

    .mountain-layer {
        animation: none;
    }

    .coffee-ring-motif {
        animation: none;
    }

    .scroll-reveal,
    .content-main p,
    .pull-quote,
    .annotation,
    .chapter-heading .char,
    .chapter-subtitle {
        opacity: 1;
        transform: none;
    }
}
