/* ============================================
   archetypic.dev - Styles
   Glassmorphism scholarly observatory
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --deep-void: #0B0E17;
    --deep-void-center: #111827;
    --glass-smoke: rgba(255, 255, 255, 0.08);
    --ether-cyan: #7FDBDA;
    --neon-orchid: #C77DFF;
    --retro-tangerine: #FF8C42;
    --parchment-mist: #E8E0D4;
    --moth-wing: #9B8E82;
    --plasma-teal: #2EC4B6;
    --fade-mauve: #9D6B97;
    --frost-line: rgba(255, 255, 255, 0.12);
    --grid-line: rgba(255, 255, 255, 0.03);
    --font-display: 'Fraunces', serif;
    --font-body: 'Source Serif 4', serif;
    --font-mono: 'DM Mono', monospace;
}

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

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    background: var(--deep-void);
    background: radial-gradient(ellipse at center, var(--deep-void-center) 0%, var(--deep-void) 70%);
    color: var(--parchment-mist);
    font-family: var(--font-body);
    font-weight: 360;
    font-size: clamp(1rem, 1.15vw, 1.35rem);
    line-height: 1.72;
    min-height: 100vh;
    overflow-x: hidden;
}

/* --- Graph-Paper Substrate (deepest layer) --- */
.graph-grid {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(var(--grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
    background-size: 40px 40px;
    z-index: 0;
    pointer-events: none;
}

/* --- Organic Blobs Layer --- */
.blobs-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    overflow: hidden;
}

.blob {
    position: absolute;
    filter: blur(60px);
    mix-blend-mode: screen;
    opacity: 0;
    transition: opacity 1.5s ease;
    will-change: transform, opacity;
}

/* Chapter 0 blobs */
.blob-0a {
    width: 65vw;
    height: 65vw;
    bottom: -15%;
    right: -10%;
    background: radial-gradient(ellipse at 40% 50%, var(--plasma-teal), transparent 70%);
    border-radius: 40% 60% 65% 35% / 55% 35% 60% 40%;
    animation: blobMorph1 25s ease-in-out infinite;
}

.blob-0b {
    width: 55vw;
    height: 55vw;
    top: -10%;
    left: -10%;
    background: radial-gradient(ellipse at 60% 40%, var(--neon-orchid), transparent 70%);
    border-radius: 60% 40% 35% 65% / 35% 60% 40% 55%;
    animation: blobMorph2 22s ease-in-out infinite;
}

/* Chapter 1 blobs */
.blob-1a {
    width: 60vw;
    height: 60vw;
    top: 100vh;
    left: -5%;
    background: radial-gradient(ellipse at 50% 50%, var(--ether-cyan), transparent 70%);
    border-radius: 50% 50% 40% 60% / 60% 40% 55% 45%;
    animation: blobMorph3 28s ease-in-out infinite;
}

.blob-1b {
    width: 50vw;
    height: 50vw;
    top: 120vh;
    right: -15%;
    background: radial-gradient(ellipse at 45% 55%, var(--fade-mauve), transparent 70%);
    border-radius: 45% 55% 60% 40% / 50% 45% 55% 50%;
    animation: blobMorph1 20s ease-in-out infinite;
}

.blob-1c {
    width: 40vw;
    height: 40vw;
    top: 130vh;
    left: 40%;
    background: radial-gradient(ellipse at 50% 50%, var(--neon-orchid), transparent 65%);
    border-radius: 55% 45% 50% 50% / 45% 55% 45% 55%;
    animation: blobMorph2 24s ease-in-out infinite;
}

/* Chapter 2 blobs */
.blob-2a {
    width: 70vw;
    height: 70vw;
    top: 200vh;
    right: -20%;
    background: radial-gradient(ellipse at 40% 60%, var(--neon-orchid), transparent 70%);
    border-radius: 35% 65% 55% 45% / 60% 40% 50% 50%;
    animation: blobMorph3 26s ease-in-out infinite;
}

.blob-2b {
    width: 55vw;
    height: 55vw;
    top: 230vh;
    left: -10%;
    background: radial-gradient(ellipse at 55% 45%, var(--plasma-teal), transparent 70%);
    border-radius: 60% 40% 45% 55% / 40% 60% 55% 45%;
    animation: blobMorph1 23s ease-in-out infinite;
}

.blob-2c {
    width: 35vw;
    height: 35vw;
    top: 250vh;
    left: 50%;
    background: radial-gradient(ellipse at 50% 50%, var(--fade-mauve), transparent 65%);
    border-radius: 50% 50% 45% 55% / 55% 45% 50% 50%;
    animation: blobMorph2 21s ease-in-out infinite;
}

/* Chapter 3 blobs */
.blob-3a {
    width: 65vw;
    height: 65vw;
    top: 300vh;
    left: -15%;
    background: radial-gradient(ellipse at 45% 55%, var(--ether-cyan), transparent 70%);
    border-radius: 45% 55% 60% 40% / 55% 45% 40% 60%;
    animation: blobMorph1 27s ease-in-out infinite;
}

.blob-3b {
    width: 50vw;
    height: 50vw;
    top: 330vh;
    right: -5%;
    background: radial-gradient(ellipse at 55% 40%, var(--neon-orchid), transparent 70%);
    border-radius: 55% 45% 40% 60% / 45% 55% 60% 40%;
    animation: blobMorph3 22s ease-in-out infinite;
}

.blob-3c {
    width: 40vw;
    height: 40vw;
    top: 350vh;
    left: 30%;
    background: radial-gradient(ellipse at 50% 50%, var(--plasma-teal), transparent 65%);
    border-radius: 50% 50% 55% 45% / 50% 50% 45% 55%;
    animation: blobMorph2 25s ease-in-out infinite;
}

/* Chapter 4 blobs */
.blob-4a {
    width: 60vw;
    height: 60vw;
    top: 400vh;
    right: -10%;
    background: radial-gradient(ellipse at 40% 50%, var(--fade-mauve), transparent 70%);
    border-radius: 40% 60% 50% 50% / 60% 40% 50% 50%;
    animation: blobMorph3 24s ease-in-out infinite;
}

.blob-4b {
    width: 55vw;
    height: 55vw;
    top: 420vh;
    left: -15%;
    background: radial-gradient(ellipse at 60% 45%, var(--ether-cyan), transparent 70%);
    border-radius: 55% 45% 45% 55% / 45% 55% 55% 45%;
    animation: blobMorph1 26s ease-in-out infinite;
}

.blob-4c {
    width: 35vw;
    height: 35vw;
    top: 440vh;
    left: 45%;
    background: radial-gradient(ellipse at 50% 50%, var(--neon-orchid), transparent 65%);
    border-radius: 45% 55% 50% 50% / 55% 45% 50% 50%;
    animation: blobMorph2 20s ease-in-out infinite;
}

/* Chapter 5 blobs */
.blob-5a {
    width: 70vw;
    height: 70vw;
    top: 500vh;
    left: -10%;
    background: radial-gradient(ellipse at 50% 50%, var(--plasma-teal), transparent 70%);
    border-radius: 50% 50% 40% 60% / 60% 40% 50% 50%;
    animation: blobMorph1 28s ease-in-out infinite;
}

.blob-5b {
    width: 55vw;
    height: 55vw;
    top: 530vh;
    right: -10%;
    background: radial-gradient(ellipse at 45% 55%, var(--neon-orchid), transparent 70%);
    border-radius: 60% 40% 55% 45% / 40% 60% 45% 55%;
    animation: blobMorph3 23s ease-in-out infinite;
}

/* Blob morph keyframes */
@keyframes blobMorph1 {
    0%, 100% {
        border-radius: 40% 60% 65% 35% / 55% 35% 60% 40%;
        transform: scale(1) rotate(0deg);
    }
    25% {
        border-radius: 55% 45% 40% 60% / 40% 60% 45% 55%;
    }
    50% {
        border-radius: 60% 40% 55% 45% / 50% 50% 40% 60%;
        transform: scale(1.05) rotate(3deg);
    }
    75% {
        border-radius: 45% 55% 50% 50% / 55% 45% 55% 45%;
    }
}

@keyframes blobMorph2 {
    0%, 100% {
        border-radius: 60% 40% 35% 65% / 35% 60% 40% 55%;
        transform: scale(1) rotate(0deg);
    }
    33% {
        border-radius: 45% 55% 55% 45% / 60% 40% 55% 45%;
        transform: scale(1.03) rotate(-2deg);
    }
    66% {
        border-radius: 50% 50% 45% 55% / 45% 55% 50% 50%;
        transform: scale(0.98) rotate(2deg);
    }
}

@keyframes blobMorph3 {
    0%, 100% {
        border-radius: 50% 50% 40% 60% / 60% 40% 55% 45%;
        transform: scale(1) rotate(0deg);
    }
    20% {
        border-radius: 40% 60% 50% 50% / 50% 50% 60% 40%;
    }
    40% {
        border-radius: 55% 45% 45% 55% / 40% 60% 45% 55%;
        transform: scale(1.04) rotate(-3deg);
    }
    60% {
        border-radius: 45% 55% 55% 45% / 55% 45% 50% 50%;
    }
    80% {
        border-radius: 60% 40% 40% 60% / 45% 55% 55% 45%;
        transform: scale(0.97) rotate(2deg);
    }
}

/* --- Navigation Rail --- */
.nav-rail {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 20px 0;
    width: 48px;
    backdrop-filter: blur(12px);
    background: rgba(255, 255, 255, 0.03);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 0 12px 12px 0;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.nav-rail.visible {
    opacity: 1;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    transition: transform 0.3s ease;
}

.nav-item .sigil {
    transition: transform 0.3s ease, filter 0.3s ease;
}

.nav-item:hover .sigil {
    transform: scale(1.15);
    filter: drop-shadow(0 0 6px var(--ether-cyan));
}

.nav-item.active .sigil {
    filter: drop-shadow(0 0 4px var(--ether-cyan));
}

.nav-numeral {
    font-family: var(--font-mono);
    font-size: clamp(0.55rem, 0.7vw, 0.7rem);
    color: var(--moth-wing);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    transition: color 0.3s ease;
}

.nav-item.active .nav-numeral {
    color: var(--ether-cyan);
}

/* --- Chapters --- */
.chapter {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 80px 60px 80px 68px;
    z-index: 2;
}

/* --- Glass Panels --- */
.glass-panel {
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    background: var(--glass-smoke);
    border: 1px solid var(--frost-line);
    border-radius: 24px;
    padding: clamp(28px, 4vw, 56px);
    box-shadow:
        0 0 40px 0 rgba(127, 219, 218, 0.06),
        0 0 80px 0 rgba(199, 125, 255, 0.04);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1.0),
                backdrop-filter 0.4s ease;
    will-change: transform, opacity;
}

.glass-primary {
    width: clamp(320px, 65vw, 900px);
    max-width: 90vw;
}

.glass-secondary {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    background: rgba(255, 255, 255, 0.05);
    width: clamp(220px, 30vw, 380px);
    max-width: 85vw;
    position: absolute;
}

.glass-panel:hover {
    transform: scale(1.02);
}

.glass-secondary:hover {
    transform: scale(1.03);
}

/* --- Panel Positions --- */
.panel-hero {
    text-align: center;
}

.panel-offset-left {
    margin-right: 15%;
}

.panel-offset-right {
    margin-left: 15%;
}

.panel-centered {
    margin: 0 auto;
}

.panel-secondary-right {
    right: 5%;
    bottom: 12%;
}

.panel-secondary-left {
    left: 5%;
    bottom: 15%;
}

.panel-secondary-bottom-right {
    right: 8%;
    bottom: 8%;
}

.panel-secondary-bottom-left {
    left: 5%;
    bottom: 10%;
}

.panel-secondary-right-high {
    right: 5%;
    top: 15%;
}

/* --- Typography --- */
.hero-title {
    font-family: var(--font-display);
    font-weight: 300;
    font-size: clamp(3rem, 7vw, 6rem);
    color: var(--ether-cyan);
    letter-spacing: 0.01em;
    line-height: 1.1;
    min-height: 1.2em;
}

.hero-title .cursor {
    display: inline-block;
    width: 3px;
    height: 0.9em;
    background: var(--ether-cyan);
    margin-left: 2px;
    animation: cursorBlink 1s step-end infinite;
    vertical-align: text-bottom;
}

@keyframes cursorBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.hero-subtitle {
    font-family: var(--font-body);
    font-style: italic;
    font-weight: 360;
    font-size: clamp(1rem, 1.5vw, 1.25rem);
    color: var(--parchment-mist);
    max-width: 38em;
    margin: 1.5em auto 0;
    opacity: 0;
}

.chapter-heading {
    font-family: var(--font-display);
    font-weight: 300;
    font-size: clamp(2.2rem, 5.5vw, 5.5rem);
    color: var(--ether-cyan);
    letter-spacing: 0.01em;
    line-height: 1.15;
    margin-bottom: 0.5em;
}

.body-text {
    font-family: var(--font-body);
    font-weight: 360;
    font-size: clamp(1rem, 1.15vw, 1.35rem);
    line-height: 1.72;
    color: var(--parchment-mist);
    max-width: 38em;
    margin-bottom: 1.25em;
}

.body-text:last-child {
    margin-bottom: 0;
}

.body-text mark {
    color: var(--retro-tangerine);
    background: transparent;
    animation: tangerinePulse 3s ease-in-out infinite;
}

@keyframes tangerinePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.85; }
}

.pull-quote {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 200;
    font-size: clamp(1.4rem, 2.5vw, 2.2rem);
    color: var(--neon-orchid);
    line-height: 1.45;
    margin-bottom: 0.75em;
}

.attribution {
    font-family: var(--font-mono);
    font-size: clamp(0.7rem, 0.85vw, 0.9rem);
    color: var(--moth-wing);
    letter-spacing: 0.05em;
}

.attribution em {
    font-style: italic;
}

/* --- Drop Cap --- */
.drop-cap-container {
    float: left;
    margin-right: 12px;
    margin-top: 4px;
}

.drop-cap {
    font-family: var(--font-display);
    font-weight: 300;
    font-size: 8rem;
    line-height: 0.75;
    display: block;
    color: transparent;
    background: linear-gradient(to top, var(--ether-cyan) var(--fill-pct, 0%), transparent var(--fill-pct, 0%));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-stroke: 1.5px var(--ether-cyan);
    transition: --fill-pct 0.8s ease-out;
    padding: 8px 8px 0 0;
    backdrop-filter: blur(4px);
}

@property --fill-pct {
    syntax: '<percentage>';
    inherits: false;
    initial-value: 0%;
}

.drop-cap.filled {
    --fill-pct: 100%;
}

/* --- Chapter Ornament --- */
.chapter-ornament {
    position: absolute;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.5rem;
    color: var(--neon-orchid);
    opacity: 0.7;
    z-index: 3;
}

.chapter-ornament::before,
.chapter-ornament::after {
    content: '';
    display: inline-block;
    width: 60px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--frost-line), transparent);
    vertical-align: middle;
    margin: 0 16px;
}

/* --- Reveal Text Animation --- */
.reveal-text {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

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

/* --- Hero panel opening animation --- */
.panel-hero {
    opacity: 0;
    transform: scaleY(0.01);
    transform-origin: center center;
}

.panel-hero.expanding {
    animation: panelExpand 0.8s ease-out forwards;
}

@keyframes panelExpand {
    0% {
        opacity: 1;
        transform: scaleY(0.01);
        backdrop-filter: blur(0px);
        -webkit-backdrop-filter: blur(0px);
    }
    100% {
        opacity: 1;
        transform: scaleY(1);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }
}

/* --- Scrollbar styling --- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--deep-void);
}

::-webkit-scrollbar-thumb {
    background: rgba(127, 219, 218, 0.2);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(127, 219, 218, 0.4);
}

/* --- Responsive adjustments --- */
@media (max-width: 768px) {
    .chapter {
        padding: 60px 20px 60px 20px;
        flex-direction: column;
    }

    .nav-rail {
        display: none;
    }

    .glass-primary {
        width: 95vw;
    }

    .glass-secondary {
        position: relative;
        width: 90vw;
        margin-top: 20px;
        right: auto;
        left: auto;
        bottom: auto;
        top: auto;
    }

    .panel-offset-left,
    .panel-offset-right {
        margin-left: 0;
        margin-right: 0;
    }

    .drop-cap {
        font-size: 5rem;
    }

    .chapter-ornament::before,
    .chapter-ornament::after {
        width: 30px;
    }
}

@media (max-width: 480px) {
    .hero-title {
        font-size: clamp(2rem, 10vw, 3rem);
    }

    .chapter-heading {
        font-size: clamp(1.8rem, 8vw, 2.5rem);
    }

    .drop-cap {
        font-size: 4rem;
    }

    .glass-panel {
        padding: 20px;
        border-radius: 16px;
    }
}
