/* ============================================================
   archetypos.dev — japanese-minimal scholarly manuscript
   Palette: cosmic indigo / aurora gradient / aged parchment
   Compliance notes: (Google Fonts); IntersectionObserver on each section to determine which node is active. IntersectionObserver to trigger the animation when the section enters the viewport. Stagger each character by 30ms. Use `will-change: opacity; IntersectionObserver with `threshold: 0.15` to trigger. This creates a gentle cascade effect.
   ============================================================ */

:root {
    --bg-primary: #0a0b1e;
    --bg-secondary: #0f1028;
    --ink-indigo: #1a1b3e;
    --parchment: #e8e4dc;
    --stone: #c8c4b8;
    --sage: #8a8678;
    --aurora-green: #00d4aa;
    --aurora-violet: #7b2ff7;
    --aurora-rose: #ff6b9d;
    --sepia: #d4c5a9;

    --col-width: 680px;
    --col-gutter: 5vw;

    --font-display: "Shippori Mincho", "Cormorant Garamond", Georgia, serif;
    --font-body: "Cormorant Garamond", Georgia, "Times New Roman", serif;
    --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

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

html {
    scroll-behavior: smooth;
    scroll-snap-type: y proximity;
}

body {
    background: var(--bg-primary);
    color: var(--stone);
    font-family: var(--font-body);
    font-size: clamp(1rem, 1.8vw, 1.25rem);
    line-height: 1.85;
    font-weight: 400;
    overflow-x: hidden;
    position: relative;
    min-height: 100vh;
}

body::before {
    /* warm dark vignette — subtle paper layer behind text */
    content: "";
    position: fixed;
    inset: 0;
    background: radial-gradient(ellipse at 50% 40%, rgba(26, 27, 62, 0.45) 0%, transparent 70%),
                radial-gradient(ellipse at 50% 110%, rgba(15, 16, 40, 0.75) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
}

/* ==================== Aurora Layers ==================== */
.aurora-layer {
    position: fixed;
    inset: -20vh -20vw;
    pointer-events: none;
    z-index: 1;
    filter: blur(80px);
    mix-blend-mode: screen;
    opacity: 0.95;
    will-change: transform;
}

.aurora-1 {
    background: linear-gradient(120deg, transparent 20%, rgba(0, 212, 170, 0.12) 40%, transparent 60%);
    animation: aurora1 25s ease-in-out infinite alternate;
}

.aurora-2 {
    background: linear-gradient(240deg, transparent 30%, rgba(123, 47, 247, 0.08) 50%, transparent 70%);
    animation: aurora2 35s ease-in-out infinite alternate;
}

.aurora-3 {
    background: linear-gradient(180deg, transparent 40%, rgba(255, 107, 157, 0.06) 55%, transparent 70%);
    animation: aurora3 45s ease-in-out infinite alternate;
}

@keyframes aurora1 {
    0%   { transform: translate3d(0, -5vh, 0) scale(1.05); }
    50%  { transform: translate3d(-3vw, 8vh, 0) scale(1.15); }
    100% { transform: translate3d(2vw, 10vh, 0) scale(1.1); }
}

@keyframes aurora2 {
    0%   { transform: translate3d(0, 0, 0) scale(1.1); }
    50%  { transform: translate3d(4vw, -6vh, 0) scale(1.2); }
    100% { transform: translate3d(-2vw, -10vh, 0) scale(1.15); }
}

@keyframes aurora3 {
    0%   { transform: translate3d(0, 0, 0) scale(1.0); }
    50%  { transform: translate3d(8vw, 4vh, 0) scale(1.1); }
    100% { transform: translate3d(-5vw, 2vh, 0) scale(1.08); }
}

/* ==================== Paper Grain ==================== */
.paper-grain {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 2;
    mix-blend-mode: multiply;
    opacity: 0.04;
    background-color: var(--sepia);
    -webkit-filter: url(#paper-grain);
    filter: url(#paper-grain);
}

.paper-grain::after {
    content: "";
    position: absolute;
    inset: 0;
    background-color: var(--sepia);
    opacity: 0.04;
    mix-blend-mode: overlay;
}

/* extra grain for colophon */
.leaf-colophon::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    mix-blend-mode: multiply;
    opacity: 0.08;
    background-color: var(--sepia);
    -webkit-filter: url(#paper-grain-heavy);
    filter: url(#paper-grain-heavy);
}

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

/* ==================== Manuscript Column ==================== */
.manuscript {
    position: relative;
    z-index: 10;
    width: 100%;
    max-width: 100vw;
}

.leaf {
    position: relative;
    min-height: 100vh;
    width: 100%;
    padding: 0 var(--col-gutter);
    display: flex;
    align-items: center;
    justify-content: center;
    scroll-snap-align: start;
    scroll-snap-stop: normal;
}

.pause {
    width: 100%;
    height: 40vh;
    position: relative;
}

/* ==================== I. Threshold ==================== */
.leaf-threshold {
    min-height: 100vh;
    overflow: hidden;
}

.threshold-inner {
    position: relative;
    width: 100%;
    max-width: var(--col-width);
    text-align: center;
    z-index: 3;
}

.threshold-eyebrow {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.22em;
    text-transform: lowercase;
    color: var(--sage);
    margin-bottom: 3.5rem;
    opacity: 0;
    animation: fadeIn 1.4s ease 0.4s forwards;
}

.hero-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(2.5rem, 6vw, 5.5rem);
    letter-spacing: 0.08em;
    line-height: 1.05;
    color: var(--parchment);
    font-feature-settings: "palt" 1;
    display: inline-block;
    margin-bottom: 2.5rem;
    --ink-pressure: 600;
    font-variation-settings: "wght" var(--ink-pressure);
    transition: font-variation-settings 400ms ease-out;
}

.hero-title .glyph {
    display: inline-block;
    opacity: 0;
    transform: translateY(20px) scale(0.94);
    filter: blur(6px);
    animation: glyphIn 1.1s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.hero-title .glyph-dot {
    color: var(--aurora-green);
    margin: 0 0.05em;
}

@keyframes glyphIn {
    0% { opacity: 0; transform: translateY(20px) scale(0.94); filter: blur(6px); }
    100% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}

.hero-title .glyph:nth-child(1)  { animation-delay: 0.20s; }
.hero-title .glyph:nth-child(2)  { animation-delay: 0.28s; }
.hero-title .glyph:nth-child(3)  { animation-delay: 0.36s; }
.hero-title .glyph:nth-child(4)  { animation-delay: 0.44s; }
.hero-title .glyph:nth-child(5)  { animation-delay: 0.52s; }
.hero-title .glyph:nth-child(6)  { animation-delay: 0.60s; }
.hero-title .glyph:nth-child(7)  { animation-delay: 0.68s; }
.hero-title .glyph:nth-child(8)  { animation-delay: 0.76s; }
.hero-title .glyph:nth-child(9)  { animation-delay: 0.84s; }
.hero-title .glyph:nth-child(10) { animation-delay: 0.92s; }
.hero-title .glyph:nth-child(11) { animation-delay: 1.00s; }
.hero-title .glyph:nth-child(12) { animation-delay: 1.08s; }
.hero-title .glyph:nth-child(13) { animation-delay: 1.16s; }
.hero-title .glyph:nth-child(14) { animation-delay: 1.24s; }

.threshold-sub {
    font-family: var(--font-body);
    font-style: italic;
    font-size: clamp(1rem, 1.4vw, 1.15rem);
    color: var(--stone);
    letter-spacing: 0.02em;
    opacity: 0;
    animation: fadeIn 1.5s ease 1.8s forwards;
    margin-bottom: 6rem;
}

.scroll-cue {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    opacity: 0;
    animation: fadeIn 1.5s ease 2.8s forwards;
}

.scroll-cue-line {
    width: 1px;
    height: 48px;
    background: linear-gradient(to bottom, transparent 0%, var(--sage) 40%, var(--aurora-green) 100%);
    animation: scrollCuePulse 2.8s ease-in-out infinite;
}

@keyframes scrollCuePulse {
    0%, 100% { transform: scaleY(0.7); opacity: 0.5; }
    50%      { transform: scaleY(1); opacity: 1; }
}

.scroll-cue-label {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    letter-spacing: 0.3em;
    text-transform: lowercase;
    color: var(--sage);
}

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

/* Ensō watermark */
.enso-wrap {
    position: absolute;
    top: 50%;
    right: 8%;
    transform: translateY(-50%);
    width: min(62vh, 620px);
    height: min(62vh, 620px);
    pointer-events: none;
    z-index: 2;
    opacity: 0;
    animation: ensoFade 2s ease 0.3s forwards;
}

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

.enso {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 20px rgba(123, 47, 247, 0.25));
}

.enso-path {
    stroke-dasharray: 1800;
    stroke-dashoffset: 1800;
    animation: ensoDraw 3s cubic-bezier(0.25, 0.1, 0.25, 1.0) 0.5s forwards;
}

@keyframes ensoDraw {
    to { stroke-dashoffset: 0; }
}

/* ==================== II. Premise ==================== */
.leaf-premise {
    min-height: 100vh;
    position: relative;
    overflow: hidden;
}

.premise-inner {
    position: relative;
    width: 100%;
    max-width: var(--col-width);
    z-index: 3;
}

.brush-guide {
    position: absolute;
    left: calc(50% - var(--col-width) / 2 - 24px);
    top: 10%;
    width: 3px;
    height: 80%;
    background: linear-gradient(to bottom, transparent 0%, rgba(26, 27, 62, 0.6) 30%, rgba(123, 47, 247, 0.3) 70%, transparent 100%);
    filter: blur(0.5px);
    z-index: 2;
    opacity: 0.85;
    transform-origin: top;
}

.brush-mark {
    position: absolute;
    pointer-events: none;
    z-index: 2;
    opacity: 0.62;
    overflow: visible;
}

.brush-mark path {
    fill: none;
    stroke: rgba(0, 212, 170, 0.10);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    filter: blur(0.25px) drop-shadow(0 0 18px rgba(123, 47, 247, 0.12));
}

.brush-mark.drawn path {
    animation: brushDraw 2.8s cubic-bezier(0.25, 0.1, 0.25, 1.0) forwards;
}

.brush-mark-premise {
    left: calc(50% - var(--col-width) / 2 - 110px);
    top: 9vh;
    width: 180px;
    height: 82vh;
}

.brush-mark-folio {
    right: calc(50% - var(--col-width) / 2 - 160px);
    top: 8vh;
    width: 320px;
    height: 120vh;
}

.brush-mark-colophon {
    top: 50%;
    left: 50%;
    width: min(68vh, 620px);
    height: min(68vh, 620px);
    transform: translate(-50%, -50%);
    opacity: 0.38;
}

@keyframes brushDraw {
    to { stroke-dashoffset: 0; }
}

@media (max-width: 900px) {
    .brush-guide { left: 8%; }
}

.section-label {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.28em;
    text-transform: lowercase;
    color: var(--sage);
    margin-bottom: 2.5rem;
}

.premise-body {
    font-family: var(--font-body);
    font-size: clamp(1.15rem, 2vw, 1.4rem);
    line-height: 1.9;
    color: var(--parchment);
    font-weight: 400;
    letter-spacing: 0.005em;
}

.premise-body em {
    font-style: italic;
    color: var(--aurora-green);
    font-family: var(--font-body);
}

.premise-body .ink-char {
    display: inline-block;
    opacity: 0;
    transform: scale(0.95);
    filter: blur(2px);
    transition: opacity 700ms ease, filter 700ms ease, transform 700ms ease;
    will-change: opacity, filter, transform;
}

.premise-body .ink-char.inked {
    opacity: 1;
    transform: scale(1);
    filter: blur(0);
}

/* ==================== III. Folio ==================== */
.leaf-folio {
    min-height: 100vh;
    padding-top: 12vh;
    padding-bottom: 12vh;
    align-items: flex-start;
    overflow: hidden;
}

.folio-inner {
    position: relative;
    width: 100%;
    max-width: var(--col-width);
    z-index: 3;
}

.folio-block {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 800ms cubic-bezier(0.16, 1, 0.3, 1), transform 800ms cubic-bezier(0.16, 1, 0.3, 1);
    margin: 3.5rem 0;
}

.folio-block.visible {
    opacity: 1;
    transform: translateY(0);
}

.folio-heading {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.8rem, 4vw, 3rem);
    letter-spacing: 0.01em;
    line-height: 1.2;
    color: var(--parchment);
    font-feature-settings: "palt" 1;
    margin-bottom: 1.4rem;
}

.folio-body {
    font-family: var(--font-body);
    font-size: clamp(1rem, 1.7vw, 1.2rem);
    line-height: 1.85;
    color: var(--stone);
}

.folio-body em {
    font-style: italic;
    color: var(--aurora-green);
}

.divider {
    height: 1px;
    width: 100%;
    margin: 3rem 0;
    background: linear-gradient(90deg, transparent 0%, rgba(0, 212, 170, 0.65) 35%, rgba(123, 47, 247, 0.65) 65%, transparent 100%);
    opacity: 0;
    transform: scaleX(0.3);
    transform-origin: center;
    transition: opacity 1200ms ease, transform 1200ms cubic-bezier(0.16, 1, 0.3, 1);
    filter: blur(0.5px);
}

.divider.visible {
    opacity: 0.9;
    transform: scaleX(1);
}

/* ==================== IV. Colophon ==================== */
.leaf-colophon {
    min-height: 100vh;
    padding-top: 10vh;
    padding-bottom: 10vh;
    position: relative;
    overflow: hidden;
}

.colophon-inner {
    position: relative;
    width: 100%;
    max-width: 540px;
    text-align: center;
    z-index: 3;
    color: var(--sage);
}

.colophon-mark {
    display: flex;
    justify-content: center;
    margin-bottom: 2rem;
    opacity: 0.75;
}

.colophon-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.4rem, 2.6vw, 2rem);
    letter-spacing: 0.4em;
    text-transform: lowercase;
    color: var(--parchment);
    background: linear-gradient(135deg, #00d4aa 0%, #7b2ff7 50%, #ff6b9d 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 2.5rem;
}

.colophon-line {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    color: var(--sage);
    line-height: 2;
    margin: 0.1rem 0;
}

.colophon-meta {
    margin: 3rem auto 2.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(138, 134, 120, 0.25);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    align-items: center;
}

.meta-row {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.06em;
    color: var(--sage);
    line-height: 1.6;
    display: flex;
    gap: 0.6rem;
    align-items: baseline;
    flex-wrap: wrap;
    justify-content: center;
}

.meta-key {
    color: var(--parchment);
    text-transform: lowercase;
    letter-spacing: 0.22em;
    font-size: 0.6rem;
}

.meta-dot {
    color: var(--aurora-green);
    opacity: 0.7;
}

.meta-val {
    color: var(--stone);
    opacity: 0.85;
}

.colophon-close {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    letter-spacing: 0.5em;
    color: var(--sage);
    margin-top: 2.5rem;
    opacity: 0.65;
}

/* ==================== Left Node Navigation ==================== */
.node-nav {
    position: fixed;
    left: 5%;
    top: 50%;
    transform: translateY(-50%);
    z-index: 40;
    pointer-events: none;
    width: 110px;
}

.node-line {
    position: absolute;
    left: 4px;
    top: 0;
    width: 1px;
    height: 100%;
    background: linear-gradient(to bottom, transparent 0%, rgba(138, 134, 120, 0.35) 20%, rgba(138, 134, 120, 0.35) 80%, transparent 100%);
    pointer-events: none;
}

.node-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 28px;
    position: relative;
    padding: 8px 0;
    height: 60vh;
    justify-content: space-around;
}

.node {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--sage);
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.22em;
    text-transform: lowercase;
    position: relative;
}

.node-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    border: 1px solid var(--sage);
    background: transparent;
    flex: 0 0 auto;
    position: relative;
    transition: background 300ms ease, border-color 300ms ease, box-shadow 300ms ease, transform 300ms ease;
}

.node-label {
    opacity: 0;
    transform: translateX(-6px);
    transition: opacity 300ms ease, transform 300ms ease, color 300ms ease;
    white-space: nowrap;
    color: var(--sage);
}

.node:hover .node-label,
.node.active .node-label {
    opacity: 1;
    transform: translateX(0);
}

.node.active .node-dot {
    background: linear-gradient(135deg, #00d4aa 0%, #7b2ff7 50%, #ff6b9d 100%);
    border-color: transparent;
    box-shadow: 0 0 14px rgba(0, 212, 170, 0.55), 0 0 28px rgba(123, 47, 247, 0.35);
    transform: scale(1.15);
}

.node.active .node-label {
    color: var(--parchment);
}

.node:hover .node-dot {
    border-color: var(--aurora-green);
}

/* ==================== Marginalia (rotated manuscript labels) ==================== */
.marginalia {
    position: fixed;
    left: calc(50% - 470px);
    top: 0;
    height: 100%;
    width: 40px;
    z-index: 30;
    pointer-events: none;
}

.marg {
    position: absolute;
    left: 0;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    letter-spacing: 0.28em;
    text-transform: lowercase;
    color: var(--sage);
    opacity: 0;
    transform: rotate(90deg) translateY(-10px);
    transform-origin: left top;
    white-space: nowrap;
    transition: opacity 500ms ease, transform 500ms ease;
}

.marg.visible {
    opacity: 0.5;
    transform: rotate(90deg) translateY(0);
}

.marg-1 { top: 14%; }
.marg-2 { top: 36%; }
.marg-3 { top: 58%; }
.marg-4 { top: 82%; }

@media (max-width: 1200px) {
    .marginalia { display: none; }
}

/* ==================== Responsive ==================== */
@media (max-width: 768px) {
    :root {
        --col-width: 90vw;
    }

    .aurora-3 { display: none; }

    .enso-wrap {
        width: 80vw;
        height: 80vw;
        right: 5%;
        opacity: 0.6;
    }

    .hero-title {
        letter-spacing: 0.06em;
    }

    .node-nav {
        left: 0;
        right: 0;
        top: auto;
        bottom: 0;
        transform: none;
        width: 100%;
        padding: 0.8rem 1rem;
        background: linear-gradient(to top, rgba(10, 11, 30, 0.92) 0%, transparent 100%);
        backdrop-filter: blur(8px);
    }

    .node-line { display: none; }

    .node-list {
        flex-direction: row;
        justify-content: space-around;
        height: auto;
        gap: 0;
        padding: 0;
    }

    .node {
        flex-direction: column;
        gap: 6px;
        align-items: center;
    }

    .node-label {
        opacity: 1;
        transform: none;
        font-size: 0.55rem;
        letter-spacing: 0.2em;
    }

    .node.active .node-dot {
        transform: scale(1.25);
    }

    .folio-block {
        margin: 2.5rem 0;
    }

    .divider { margin: 2rem 0; }

    .brush-guide { display: none; }

    .brush-mark-premise,
    .brush-mark-folio {
        opacity: 0.36;
        left: auto;
        right: -10vw;
        width: 48vw;
    }
}

@media (max-width: 480px) {
    .threshold-eyebrow { font-size: 0.62rem; }
    .threshold-sub { margin-bottom: 3rem; }
    .leaf { padding: 0 1.25rem; }
}
