/* ============================================
   mystical.quest - Design System
   Alchemist's Laboratory Journal
   ============================================ */

:root {
    --deep-umber: #1e1810;
    --aged-parchment: #3b2f1f;
    --warm-vellum: #e8d5b0;
    --burnished-gold: #c9a96e;
    --mystic-teal: #4ecdc4;
    --dried-rose: #c06c5a;
    --soft-smoke: #8a7a5a;
    --bone-white: #f5efe3;
    --dark-brown: #4a3d2e;
    --muted-parchment: #d4c4a0;

    --font-display: 'EB Garamond', Georgia, serif;
    --font-body: 'EB Garamond', Georgia, serif;
    --font-annotation: 'Caveat', cursive;
    --font-mono: 'IBM Plex Mono', monospace;

    --bounce-ease: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

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

body {
    background: var(--deep-umber);
    color: var(--muted-parchment);
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1.05rem, 1.6vw, 1.25rem);
    line-height: 1.72;
    letter-spacing: 0.005em;
    overflow-x: hidden;
}

/* ---- SVG Filters (hidden) ---- */
.svg-filters {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* ---- Grain Overlay ---- */
.grain-overlay {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.10;
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    background-size: 256px 256px;
}

/* ---- Zone Base ---- */
.zone {
    position: relative;
    clip-path: polygon(0 0, 100% 4vw, 100% 100%, 0 calc(100% - 4vw));
    margin-top: -4vw;
    padding: 8vw 6vw;
    overflow: hidden;
}

.zone:first-of-type {
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 calc(100% - 4vw));
    margin-top: 0;
}

.zone:last-of-type {
    clip-path: polygon(0 0, 100% 4vw, 100% 100%, 0 100%);
}

.zone-inner {
    position: relative;
    z-index: 2;
    max-width: 1200px;
    margin: 0 auto;
}

/* ---- Diagonal Edge Lines ---- */
.diagonal-edge-lines {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 20px;
    z-index: 3;
    pointer-events: none;
}

.diagonal-edge-lines span {
    display: block;
    width: 100%;
    height: 1px;
    background: var(--burnished-gold);
    opacity: 0.2;
    margin-bottom: 4px;
}

/* ============================================
   Zone 1: The Invocation
   ============================================ */
.zone-invocation {
    background: var(--aged-parchment);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 10vh;
    padding-bottom: 12vh;
}

.invocation-layout {
    position: relative;
    width: 100%;
    min-height: 70vh;
}

.invocation-title {
    position: relative;
    z-index: 5;
}

.title-mystical {
    display: block;
    font-family: var(--font-display);
    font-weight: 700;
    font-style: italic;
    font-size: clamp(3.5rem, 10vw, 8rem);
    color: var(--warm-vellum);
    letter-spacing: 0.03em;
    line-height: 1.12;
    margin-left: 12vw;
}

.title-quest {
    display: block;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.8rem, 5vw, 4rem);
    color: var(--burnished-gold);
    letter-spacing: 0.05em;
    line-height: 1.12;
    text-align: right;
    margin-right: 10vw;
    margin-top: 2rem;
}

.circuit-connector {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    opacity: 0.7;
}

.circuit-label {
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 300;
    fill: var(--soft-smoke);
    opacity: 0.6;
}

/* Trace draw animation */
.trace {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
}

.trace.animate-in {
    animation: traceDraw 2.5s ease-out forwards;
}

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

/* Node pulse */
.node {
    animation: nodePulse 3s ease-in-out infinite;
}

.node-teal {
    animation: nodePulseTeal 3s ease-in-out infinite;
}

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

@keyframes nodePulseTeal {
    0%, 100% { r: 3; opacity: 1; }
    50% { r: 5; opacity: 0.6; }
}

/* ============================================
   Zone 2: The Grimoire Page
   ============================================ */
.zone-grimoire {
    background: var(--deep-umber);
    padding-top: 10vw;
    padding-bottom: 10vw;
}

.grimoire-page {
    background: var(--aged-parchment);
    padding: clamp(2rem, 5vw, 4rem);
    border-radius: 0.3rem;
    transform: rotate(3deg);
    box-shadow: 
        0 20px 60px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(201, 169, 110, 0.1);
    position: relative;
}

.grimoire-page::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(ellipse at 30% 20%, rgba(232, 213, 176, 0.08) 0%, transparent 60%);
    pointer-events: none;
}

.section-heading {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2.2rem, 5.5vw, 4.8rem);
    color: var(--warm-vellum);
    letter-spacing: 0.03em;
    line-height: 1.12;
    margin-bottom: 2rem;
    opacity: 0;
    transform: translateY(30px);
}

.section-heading.visible {
    animation: bounceEnter 700ms var(--bounce-ease) forwards;
}

.grimoire-columns {
    columns: 2;
    column-gap: 3rem;
    column-rule: 1px solid var(--burnished-gold);
    column-rule-style: dashed;
}

.body-text {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1.05rem, 1.6vw, 1.25rem);
    line-height: 1.72;
    letter-spacing: 0.005em;
    color: var(--muted-parchment);
    margin-bottom: 1.5rem;
}

.zone-grimoire .body-text {
    color: var(--warm-vellum);
}

.annotation {
    font-family: var(--font-annotation);
    font-weight: 400;
    font-size: clamp(0.95rem, 1.4vw, 1.15rem);
    line-height: 1.5;
    color: var(--burnished-gold);
    text-shadow: 0 0 8px rgba(201, 169, 110, 0.3);
    margin-bottom: 1.5rem;
    font-style: italic;
}

/* ============================================
   Zone 3: The Enchanted Circuit
   ============================================ */
.zone-circuit {
    background: var(--deep-umber);
    min-height: 40vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6vw 2vw;
}

.circuit-mandala {
    width: 100%;
    max-height: 400px;
}

.trace-mandala {
    stroke-dasharray: 3000;
    stroke-dashoffset: 3000;
}

.trace-mandala.animate-in {
    animation: traceDraw 3s ease-out forwards;
}

/* ============================================
   Zone 4: The Riddle Garden
   ============================================ */
.zone-riddle {
    background: var(--aged-parchment);
    padding-top: 10vw;
    padding-bottom: 10vw;
}

.zone-riddle .section-heading {
    color: var(--warm-vellum);
    text-align: center;
    margin-bottom: 4rem;
}

.riddle-cards {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    padding: 0 5vw;
}

.riddle-card {
    background: var(--deep-umber);
    border-radius: 1.2rem;
    padding: clamp(1.5rem, 3vw, 2.5rem);
    position: relative;
    overflow: hidden;
    opacity: 0;
    transform: translateY(40px);
    transition: box-shadow 0.3s ease;
}

.riddle-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.03;
    pointer-events: none;
}

.riddle-card:hover {
    box-shadow: 0 0 30px rgba(78, 205, 196, 0.1);
}

.riddle-card-1 {
    margin-left: 0;
    background: #1e1810;
}

.riddle-card-2 {
    margin-left: 15%;
    background: #231d14;
}

.riddle-card-3 {
    margin-left: 30%;
    background: #282018;
}

.riddle-card.visible {
    animation: bounceEnter 700ms var(--bounce-ease) forwards;
}

.card-annotation {
    font-family: var(--font-annotation);
    font-size: clamp(0.85rem, 1.2vw, 1rem);
    color: var(--burnished-gold);
    text-shadow: 0 0 8px rgba(201, 169, 110, 0.3);
    display: block;
    margin-bottom: 0.75rem;
}

.card-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.5rem, 3vw, 2.2rem);
    color: var(--warm-vellum);
    letter-spacing: 0.03em;
    line-height: 1.12;
    margin-bottom: 1rem;
}

.card-circuit-label {
    font-family: var(--font-mono);
    font-weight: 300;
    font-size: clamp(0.7rem, 1vw, 0.85rem);
    color: var(--soft-smoke);
    opacity: 0.6;
    display: block;
    margin-top: 1rem;
}

.card-circuit {
    width: 120px;
    height: 30px;
    margin-top: 0.5rem;
}

/* ============================================
   Zone 5: The Farewell Spell
   ============================================ */
.zone-farewell {
    background: var(--deep-umber);
    min-height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 12vw;
    padding-bottom: 12vw;
    position: relative;
}

.farewell-content {
    position: relative;
    z-index: 2;
    max-width: 700px;
    margin: 0 auto;
    text-align: center;
}

.farewell-text {
    opacity: 0;
    transform: translateY(30px);
}

.farewell-text.visible {
    animation: bounceEnter 700ms var(--bounce-ease) forwards;
}

.farewell-watermark {
    position: absolute;
    bottom: 10%;
    left: 50%;
    transform: translateX(-50%) rotate(-7deg);
    font-family: var(--font-display);
    font-weight: 700;
    font-style: italic;
    font-size: 20vw;
    color: var(--warm-vellum);
    opacity: 0.06;
    pointer-events: none;
    white-space: nowrap;
    z-index: 1;
    line-height: 1;
}

/* ---- Floating Nature Elements ---- */
.floating-elements {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
}

.float-leaf {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--burnished-gold);
    border-radius: 0 50% 50% 50%;
    transform: rotate(45deg);
    opacity: 0.15;
    animation: floatDrift 8s ease-in-out infinite;
}

.float-dot {
    position: absolute;
    width: 4px;
    height: 4px;
    background: var(--burnished-gold);
    border-radius: 50%;
    opacity: 0.2;
    animation: floatDrift 10s ease-in-out infinite;
}

.float-crescent {
    position: absolute;
    width: 14px;
    height: 14px;
    border: 2px solid var(--burnished-gold);
    border-radius: 50%;
    opacity: 0.12;
    animation: floatDrift 9s ease-in-out infinite;
}

.float-crescent::after {
    content: '';
    position: absolute;
    top: -1px;
    right: -1px;
    width: 12px;
    height: 12px;
    background: var(--deep-umber);
    border-radius: 50%;
}

.float-1 { top: 15%; left: 8%; animation-delay: 0s; }
.float-2 { top: 40%; right: 12%; animation-delay: -2s; }
.float-3 { top: 25%; left: 45%; animation-delay: -4s; }
.float-4 { top: 60%; left: 20%; animation-delay: -1s; }
.float-5 { top: 70%; right: 25%; animation-delay: -3s; }
.float-6 { top: 50%; right: 5%; animation-delay: -5s; }
.float-7 { top: 80%; left: 35%; animation-delay: -6s; }

@keyframes floatDrift {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-8px) rotate(3deg); }
}

/* ---- Bounce Enter Animation ---- */
.bounce-target {
    opacity: 0;
    transform: translateY(40px);
}

.bounce-target.visible {
    animation: bounceEnter 700ms var(--bounce-ease) forwards;
}

@keyframes bounceEnter {
    0% {
        opacity: 0;
        transform: translateY(40px);
    }
    60% {
        opacity: 1;
        transform: translateY(-5px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .zone {
        clip-path: polygon(0 0, 100% 2.5vw, 100% 100%, 0 calc(100% - 2.5vw));
        margin-top: -2.5vw;
        padding: 12vw 5vw;
    }

    .zone:first-of-type {
        clip-path: polygon(0 0, 100% 0, 100% 100%, 0 calc(100% - 2.5vw));
    }

    .zone:last-of-type {
        clip-path: polygon(0 0, 100% 2.5vw, 100% 100%, 0 100%);
    }

    .title-mystical {
        margin-left: 5vw;
    }

    .title-quest {
        margin-right: 5vw;
    }

    .grimoire-page {
        transform: rotate(1deg);
    }

    .grimoire-columns {
        columns: 1;
    }

    .riddle-card-1,
    .riddle-card-2,
    .riddle-card-3 {
        margin-left: 0;
    }

    .grain-overlay {
        opacity: 0.06;
    }

    .farewell-watermark {
        font-size: 30vw;
    }
}
