/* ============================================
   ethica.dev - Fairycore Digital Grimoire
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --obsidian-void: #0D0D12;
    --midnight-vellum: #1A1824;
    --candle-gold: #E8B84C;
    --ethereal-violet: #7B68AE;
    --parchment: #E8E0D4;
    --faded-sage: #8BA888;
    --ember-crimson: #C44B4F;
    --phosphor-teal: #4ECDC4;
}

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

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

body {
    background: var(--obsidian-void);
    color: var(--parchment);
    font-family: 'Crimson Pro', Georgia, serif;
    font-weight: 400;
    font-size: 1.125rem;
    line-height: 1.8;
    overflow: hidden;
    cursor: none;
}

/* --- Scroll Container --- */
.scroll-container {
    height: 100vh;
    overflow-y: scroll;
    scroll-snap-type: y mandatory;
    scroll-behavior: smooth;
}

/* --- Page Base --- */
.page {
    height: 100vh;
    width: 100vw;
    scroll-snap-align: start;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Stardust Particles --- */
.stardust-particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.stardust-particles::before,
.stardust-particles::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(1px 1px at 10% 20%, rgba(232, 184, 76, 0.3) 0%, transparent 100%),
        radial-gradient(1px 1px at 30% 60%, rgba(78, 205, 196, 0.2) 0%, transparent 100%),
        radial-gradient(1px 1px at 50% 40%, rgba(232, 184, 76, 0.25) 0%, transparent 100%),
        radial-gradient(1px 1px at 70% 80%, rgba(123, 104, 174, 0.2) 0%, transparent 100%),
        radial-gradient(1px 1px at 90% 30%, rgba(232, 184, 76, 0.3) 0%, transparent 100%),
        radial-gradient(1px 1px at 15% 85%, rgba(78, 205, 196, 0.15) 0%, transparent 100%),
        radial-gradient(1px 1px at 60% 15%, rgba(232, 184, 76, 0.2) 0%, transparent 100%),
        radial-gradient(1px 1px at 85% 55%, rgba(123, 104, 174, 0.15) 0%, transparent 100%);
    animation: stardustDrift 30s linear infinite;
}

.stardust-particles::after {
    background-image:
        radial-gradient(1.5px 1.5px at 20% 45%, rgba(232, 184, 76, 0.2) 0%, transparent 100%),
        radial-gradient(1px 1px at 40% 75%, rgba(78, 205, 196, 0.15) 0%, transparent 100%),
        radial-gradient(1px 1px at 65% 25%, rgba(232, 184, 76, 0.2) 0%, transparent 100%),
        radial-gradient(1.5px 1.5px at 80% 65%, rgba(123, 104, 174, 0.18) 0%, transparent 100%),
        radial-gradient(1px 1px at 45% 90%, rgba(232, 184, 76, 0.25) 0%, transparent 100%);
    animation: stardustDrift 45s linear infinite reverse;
}

@keyframes stardustDrift {
    0% { transform: translate(0, 0); }
    50% { transform: translate(-15px, -10px); }
    100% { transform: translate(0, 0); }
}

/* ============================================
   PAGE 1: THE SCRIPTORIUM
   ============================================ */
.page-scriptorium {
    background: var(--obsidian-void);
    flex-direction: column;
}

.darkness-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--obsidian-void);
    z-index: 10;
    pointer-events: none;
    animation: darknessLift 2s ease-out 0.6s forwards;
}

@keyframes darknessLift {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

/* Vine Borders */
.vine-border {
    position: absolute;
    z-index: 5;
    opacity: 0;
    animation: vineFadeIn 1.5s ease-out 2s forwards;
}

.vine-border-top,
.vine-border-bottom {
    left: 5%;
    width: 90%;
    height: 30px;
    background: repeating-linear-gradient(
        90deg,
        transparent 0px,
        transparent 20px,
        rgba(139, 168, 136, 0.15) 20px,
        rgba(139, 168, 136, 0.15) 21px
    );
    border: 1px solid rgba(139, 168, 136, 0.2);
    border-radius: 2px;
}

.vine-border-top { top: 20px; }
.vine-border-bottom { bottom: 100px; }

.vine-border-left,
.vine-border-right {
    top: 5%;
    height: 85%;
    width: 20px;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        transparent 20px,
        rgba(139, 168, 136, 0.15) 20px,
        rgba(139, 168, 136, 0.15) 21px
    );
    border: 1px solid rgba(139, 168, 136, 0.2);
    border-radius: 2px;
}

.vine-border-left { left: 20px; }
.vine-border-right { right: 20px; }

@keyframes vineFadeIn {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

/* Scriptorium Content */
.scriptorium-content {
    position: relative;
    z-index: 8;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* Ignition Candle */
.ignition-candle {
    position: relative;
    margin-bottom: 2rem;
}

.candle-svg-large {
    width: 60px;
    height: 120px;
    opacity: 0;
    animation: candleIgnite 1.2s ease-out 0.8s forwards;
}

@keyframes candleIgnite {
    0% { opacity: 0; transform: scale(0.5); }
    50% { opacity: 0.8; transform: scale(1.1); }
    100% { opacity: 1; transform: scale(1); }
}

.candle-glow {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(232, 184, 76, 0.15) 0%, transparent 70%);
    pointer-events: none;
    opacity: 0;
    animation: glowAppear 1.5s ease-out 1.2s forwards;
}

@keyframes glowAppear {
    0% { opacity: 0; width: 50px; height: 50px; }
    100% { opacity: 1; width: 300px; height: 300px; }
}

/* Flame animations */
.flame-outer {
    animation: flameOuter 2.1s ease-in-out infinite;
    transform-origin: center bottom;
}

.flame-mid {
    animation: flameMid 2.7s ease-in-out infinite;
    transform-origin: center bottom;
}

.flame-inner {
    animation: flameInner 3.3s ease-in-out infinite;
    transform-origin: center bottom;
}

@keyframes flameOuter {
    0%, 100% { transform: scaleX(1) scaleY(1); opacity: 0.5; }
    25% { transform: scaleX(0.85) scaleY(1.08); opacity: 0.6; }
    50% { transform: scaleX(1.1) scaleY(0.92); opacity: 0.45; }
    75% { transform: scaleX(0.9) scaleY(1.05); opacity: 0.55; }
}

@keyframes flameMid {
    0%, 100% { transform: scaleX(1) scaleY(1); opacity: 0.7; }
    33% { transform: scaleX(1.12) scaleY(0.9); opacity: 0.75; }
    66% { transform: scaleX(0.88) scaleY(1.1); opacity: 0.65; }
}

@keyframes flameInner {
    0%, 100% { transform: scaleX(1) scaleY(1); opacity: 0.85; }
    20% { transform: scaleX(0.9) scaleY(1.1); opacity: 0.9; }
    40% { transform: scaleX(1.1) scaleY(0.9); opacity: 0.8; }
    60% { transform: scaleX(0.95) scaleY(1.05); opacity: 0.88; }
    80% { transform: scaleX(1.05) scaleY(0.95); opacity: 0.82; }
}

/* Site Title - Kinetic Typography */
.site-title {
    font-family: 'Cinzel Decorative', 'Georgia', serif;
    font-weight: 700;
    font-size: 3.6rem;
    letter-spacing: 0.15em;
    font-variant: small-caps;
    color: var(--candle-gold);
    text-shadow: 0 0 20px rgba(232, 184, 76, 0.3);
    margin-bottom: 1.5rem;
}

.kinetic-char {
    display: inline-block;
    opacity: 0;
    transform: translateY(8px);
    animation: charReveal 120ms ease-out forwards;
    animation-delay: calc(1.8s + var(--char-index) * 60ms);
    position: relative;
}

.kinetic-char::after {
    content: '';
    position: absolute;
    top: -4px;
    left: 50%;
    width: 3px;
    height: 3px;
    background: var(--candle-gold);
    border-radius: 50%;
    opacity: 0;
    animation: sparkEmit 400ms ease-out forwards;
    animation-delay: calc(1.85s + var(--char-index) * 60ms);
}

@keyframes charReveal {
    0% { opacity: 0; transform: translateY(8px); }
    100% { opacity: 1; transform: translateY(0); }
}

@keyframes sparkEmit {
    0% { opacity: 0.8; transform: translate(-50%, 0) scale(1); }
    50% { opacity: 0.5; transform: translate(-50%, -15px) scale(0.6); }
    100% { opacity: 0; transform: translate(-50%, -30px) scale(0.2); }
}

/* Subtitle */
.subtitle {
    font-family: 'Crimson Pro', Georgia, serif;
    font-style: italic;
    font-size: 1.3rem;
    color: var(--parchment);
    opacity: 0;
    animation: subtitleFade 1s ease-out 3s forwards;
}

@keyframes subtitleFade {
    0% { opacity: 0; transform: translateY(5px); }
    100% { opacity: 0.8; transform: translateY(0); }
}

/* ============================================
   SPREAD LAYOUT (Pages 2, 3)
   ============================================ */
.spread {
    display: flex;
    width: 100%;
    height: 100%;
    position: relative;
    z-index: 2;
}

.spread-reversed {
    flex-direction: row;
}

.illumination-column {
    width: 35%;
    padding: 4rem 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

.text-column {
    width: 65%;
    padding: 4rem 3rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
}

.spread-reversed .text-column {
    width: 65%;
}

.spread-reversed .illumination-column {
    width: 35%;
}

/* Gutter Seam */
.gutter-seam {
    width: 10px;
    position: relative;
    flex-shrink: 0;
    background: linear-gradient(
        180deg,
        var(--candle-gold) 0%,
        var(--ethereal-violet) 50%,
        var(--candle-gold) 100%
    );
    opacity: 0.4;
    animation: gutterPulse 4s ease-in-out infinite;
}

@keyframes gutterPulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.6; }
}

/* Wax Seal */
.wax-seal {
    margin-bottom: 2rem;
}

.seal-svg {
    width: 48px;
    height: 48px;
    filter: drop-shadow(0 2px 4px rgba(196, 75, 79, 0.3)) drop-shadow(0 0 8px rgba(196, 75, 79, 0.15));
}

/* Illustrations */
.illumination-art {
    width: 100%;
    max-width: 300px;
    margin-bottom: 2rem;
}

.illustration-svg {
    width: 100%;
    height: auto;
}

.vine-path {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
}

.page.active .vine-path {
    animation: vineGrow 2s ease-out forwards;
}

@keyframes vineGrow {
    0% { stroke-dashoffset: 400; }
    100% { stroke-dashoffset: 0; }
}

/* Marginalia */
.marginalia {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
}

.margin-note {
    font-family: 'Caveat', cursive;
    font-size: 0.85rem;
    color: var(--faded-sage);
    opacity: 0.7;
    display: block;
    animation: marginDrift 8s ease-in-out infinite;
    transform: translate(var(--drift-x, 0), var(--drift-y, 0));
}

@keyframes marginDrift {
    0%, 100% { transform: translate(var(--drift-x, 0), var(--drift-y, 0)); }
    50% { transform: translate(calc(var(--drift-x, 0) * -1), calc(var(--drift-y, 0) * -1)); }
}

/* Section Headings */
.section-heading {
    font-family: 'Cinzel Decorative', 'Georgia', serif;
    font-weight: 700;
    font-size: 2.4rem;
    letter-spacing: 0.15em;
    font-variant: small-caps;
    color: var(--candle-gold);
    text-shadow: 0 0 20px rgba(232, 184, 76, 0.3);
    margin-bottom: 2rem;
}

/* Kinetic heading animation */
.kinetic-heading {
    opacity: 0;
    transition: opacity 0.3s;
}

.kinetic-heading.animate {
    opacity: 1;
}

.kinetic-heading .kchar {
    display: inline-block;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 120ms ease-out, transform 120ms ease-out;
    position: relative;
}

.kinetic-heading .kchar.visible {
    opacity: 1;
    transform: translateY(0);
}

.kinetic-heading .kchar::after {
    content: '';
    position: absolute;
    top: -4px;
    left: 50%;
    width: 3px;
    height: 3px;
    background: var(--candle-gold);
    border-radius: 50%;
    opacity: 0;
}

.kinetic-heading .kchar.visible::after {
    animation: sparkEmit 400ms ease-out forwards;
}

/* Body Text */
.body-text {
    max-width: 600px;
}

.body-text p {
    margin-bottom: 1.5rem;
    color: var(--parchment);
}

.body-text em {
    color: var(--ember-crimson);
    font-style: italic;
    font-weight: 600;
}

/* Line reveal animation */
.reveal-line {
    opacity: 0;
    transform: translateX(-12px);
    transition: opacity 400ms ease-out, transform 400ms ease-out;
}

.reveal-line.visible {
    opacity: 1;
    transform: translateX(0);
}

/* ============================================
   PAGE 3: THE PARADOX - Glitch Effects
   ============================================ */
.page-paradox {
    background: var(--obsidian-void);
}

.glitch-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    pointer-events: none;
    opacity: 0;
}

.glitch-overlay.active {
    animation: glitchSequence 300ms ease-out forwards;
}

@keyframes glitchSequence {
    0% { opacity: 1; filter: hue-rotate(0deg); }
    25% { filter: hue-rotate(30deg); transform: translateX(3px); }
    50% { filter: hue-rotate(15deg); transform: translateX(-2px); }
    75% { filter: hue-rotate(30deg); transform: translateX(4px); }
    100% { opacity: 0; filter: hue-rotate(0deg); transform: translateX(0); }
}

.scanlines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 21;
    pointer-events: none;
    opacity: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        transparent 2px,
        rgba(78, 205, 196, 0.15) 2px,
        rgba(78, 205, 196, 0.15) 3px
    );
}

.scanlines.active {
    animation: scanlineFlicker 300ms ease-out forwards;
}

@keyframes scanlineFlicker {
    0% { opacity: 0; }
    30% { opacity: 0.8; }
    60% { opacity: 0.3; }
    80% { opacity: 0.6; }
    100% { opacity: 0; }
}

/* Channel split effect on text during glitch */
.page-paradox.glitching .text-column {
    text-shadow:
        -2px 0 rgba(196, 75, 79, 0.7),
        2px 0 rgba(78, 205, 196, 0.7);
    animation: channelShift 300ms ease-out;
}

@keyframes channelShift {
    0% { text-shadow: -2px 0 rgba(196, 75, 79, 0.7), 2px 0 rgba(78, 205, 196, 0.7); }
    50% { text-shadow: -4px 0 rgba(196, 75, 79, 0.5), 4px 0 rgba(78, 205, 196, 0.5); }
    100% { text-shadow: none; }
}

/* ============================================
   PAGE 4: THE GARDEN
   ============================================ */
.page-garden {
    background: var(--obsidian-void);
}

.garden-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.garden-svg {
    width: 90%;
    max-width: 1200px;
    height: auto;
    position: absolute;
}

.firefly {
    animation: fireflyPulse 3s ease-in-out infinite;
}

.firefly:nth-child(odd) {
    animation-duration: 4s;
    animation-delay: 1s;
}

@keyframes fireflyPulse {
    0%, 100% { opacity: 0.2; }
    50% { opacity: 0.7; }
}

/* Garden text fragments */
.garden-text {
    position: absolute;
    font-family: 'Caveat', cursive;
    font-size: 0.95rem;
    color: var(--faded-sage);
    opacity: 0;
    transition: opacity 0.5s ease-out;
    pointer-events: none;
    max-width: 250px;
    text-align: center;
    z-index: 5;
}

.garden-text.illuminated {
    opacity: 1;
}

.garden-seal {
    position: absolute;
    top: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
}

/* ============================================
   PAGE 5: THE CLOSING
   ============================================ */
.page-closing {
    background: var(--obsidian-void);
    flex-direction: column;
}

.closing-content {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    max-width: 700px;
    padding: 2rem;
}

.vine-frame-full {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    border: 2px solid rgba(139, 168, 136, 0.2);
    border-radius: 4px;
    margin: 20px;
    pointer-events: none;
    box-shadow:
        inset 0 0 40px rgba(139, 168, 136, 0.05),
        0 0 40px rgba(139, 168, 136, 0.05);
}

.central-candle {
    position: relative;
    cursor: pointer;
    margin-bottom: 2rem;
}

.candle-svg-hero {
    width: 80px;
    height: 160px;
    transition: transform 0.3s;
}

.central-candle:hover .candle-svg-hero {
    transform: scale(1.05);
}

.hero-flame-outer {
    animation: flameOuter 2.1s ease-in-out infinite;
    transform-origin: center bottom;
}

.hero-flame-mid {
    animation: flameMid 2.7s ease-in-out infinite;
    transform-origin: center bottom;
}

.hero-flame-inner {
    animation: flameInner 3.3s ease-in-out infinite;
    transform-origin: center bottom;
}

.hero-candle-glow {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(232, 184, 76, 0.12) 0%, transparent 70%);
    pointer-events: none;
    transition: all 1.5s ease-out;
}

.candle-prompt {
    font-family: 'Caveat', cursive;
    font-size: 1.1rem;
    color: var(--faded-sage);
    opacity: 0.6;
    margin-top: 1rem;
    transition: opacity 0.5s;
}

/* Final flame burst */
.central-candle.ignited .hero-candle-glow {
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle, rgba(232, 184, 76, 0.3) 0%, rgba(232, 184, 76, 0.05) 50%, transparent 70%);
    animation: flameBurst 3s ease-out forwards;
}

.central-candle.ignited .candle-prompt {
    opacity: 0;
}

@keyframes flameBurst {
    0% { opacity: 1; }
    50% { opacity: 1; }
    100% { opacity: 0; }
}

.closing-text {
    font-family: 'Crimson Pro', Georgia, serif;
    font-size: 1.2rem;
    line-height: 1.9;
    color: var(--parchment);
    opacity: 0.85;
    margin-bottom: 3rem;
    max-width: 550px;
}

.colophon {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    opacity: 0;
    transition: opacity 1s ease-out 3s;
}

.colophon.visible {
    opacity: 1;
}

.colophon-title {
    font-family: 'Cinzel Decorative', 'Georgia', serif;
    font-size: 1.4rem;
    color: var(--candle-gold);
    letter-spacing: 0.15em;
    font-variant: small-caps;
}

.colophon-sub {
    font-family: 'Caveat', cursive;
    font-size: 1rem;
    color: var(--faded-sage);
    opacity: 0.7;
}

/* ============================================
   CANDLE SHELF NAVIGATION
   ============================================ */
.candle-shelf {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    z-index: 100;
    background: linear-gradient(to top, rgba(13, 13, 18, 0.95) 0%, transparent 100%);
}

.candle-nav {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    opacity: 0.4;
    transition: opacity 0.3s, transform 0.3s;
}

.candle-nav:hover {
    opacity: 0.8;
    transform: scale(1.1);
}

.candle-nav.active {
    opacity: 1;
}

.candle-nav-svg {
    width: 20px;
    height: 40px;
}

.nav-flame {
    animation: flameOuter 2.1s ease-in-out infinite;
    transform-origin: center bottom;
}

.nav-flame-inner {
    animation: flameInner 3.3s ease-in-out infinite;
    transform-origin: center bottom;
}

.candle-nav:not(.active) .nav-flame {
    opacity: 0.3;
}

.candle-nav:not(.active) .nav-flame-inner {
    opacity: 0.4;
}

/* ============================================
   CURSOR CANDLE TRAIL
   ============================================ */
.cursor-trail {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

.cursor-dot {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--candle-gold);
    pointer-events: none;
    transition: opacity 0.3s;
    box-shadow:
        0 0 6px rgba(232, 184, 76, 0.6),
        0 0 15px rgba(232, 184, 76, 0.3),
        0 0 30px rgba(232, 184, 76, 0.1);
}

.cursor-dot.primary {
    width: 12px;
    height: 12px;
    background: var(--candle-gold);
    box-shadow:
        0 0 10px rgba(232, 184, 76, 0.8),
        0 0 25px rgba(232, 184, 76, 0.4),
        0 0 50px rgba(232, 184, 76, 0.15);
}

/* ============================================
   PAGE TURN TRANSITION
   ============================================ */
.page-turn-flash {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--obsidian-void);
    opacity: 0;
    z-index: 50;
    pointer-events: none;
    animation: pageTurnFlicker 400ms ease-out;
}

@keyframes pageTurnFlicker {
    0% { opacity: 0; }
    30% { opacity: 0.6; }
    60% { opacity: 0.2; }
    100% { opacity: 0; }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .site-title {
        font-size: 2.2rem;
    }

    .section-heading {
        font-size: 1.6rem;
    }

    .spread {
        flex-direction: column;
    }

    .spread-reversed {
        flex-direction: column-reverse;
    }

    .illumination-column,
    .text-column {
        width: 100%;
        padding: 2rem 1.5rem;
    }

    .illumination-column {
        height: 35vh;
        padding: 1rem;
    }

    .text-column {
        height: 65vh;
        overflow-y: auto;
    }

    .gutter-seam {
        width: 100%;
        height: 6px;
    }

    .candle-shelf {
        gap: 1rem;
    }

    .body-text {
        max-width: 100%;
    }

    .garden-text {
        font-size: 0.8rem;
        max-width: 180px;
    }
}
