/* ============================================
   archetypic.dev - Forest Observatory HUD
   Enchanted Forest Naturalist Interface
   ============================================ */

/* Design Tokens */
:root {
    --forest-deep: #0b2618;
    --forest-core: #1a4732;
    --forest-fern: #2d5a3d;
    --forest-canopy: #4a7c59;
    --forest-glow: #7ec89a;
    --text-cream: #f0e8d8;
    --accent-gold: #d4a855;
    --accent-rose: #c8857a;
    --panel-bg: rgba(11, 38, 24, 0.85);
    --panel-border: rgba(74, 124, 89, 0.5);
    --blur-panel: blur(12px);
    --radius-panel: 16px;
    --radius-node: 50%;
    --transition-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --transition-smooth: cubic-bezier(0.4, 0, 0.2, 1);
    --font-display: 'Playfair Display', Georgia, serif;
    --font-secondary: 'Lora', 'Times New Roman', serif;
    --font-body: 'Source Sans 3', 'Segoe UI', sans-serif;
    --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
}

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

html, body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    font-family: var(--font-body);
    color: var(--text-cream);
    background: var(--forest-deep);
}

body {
    position: relative;
}

/* ============================================
   Z-Layer System
   z-index 0: Forest background
   z-index 1: Canopy frame, bg waves
   z-index 2: Floating annotation panels, mycelium
   z-index 3: Specimen Ring + content
   z-index 4: Root navigation
   z-index 5: Spore particles (pointer-events: none)
   z-index 100: Awakening overlay
   ============================================ */

/* Deep Forest Background */
#forest-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    background: linear-gradient(170deg, #0b2618 0%, #1a4732 45%, #0b2618 100%);
}

/* Subtle dappled light effect on background */
#forest-bg::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse 600px 400px at 25% 30%, rgba(74, 124, 89, 0.06), transparent),
        radial-gradient(ellipse 400px 300px at 70% 60%, rgba(126, 200, 154, 0.04), transparent),
        radial-gradient(ellipse 500px 350px at 55% 20%, rgba(45, 90, 61, 0.05), transparent);
    animation: dappled-light 20s ease-in-out infinite alternate;
}

@keyframes dappled-light {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.7; }
}

/* Background Wave Textures */
#bg-waves {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.bg-wave {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 200%;
    height: 30vh;
    opacity: 0.06;
}

.bg-wave path {
    fill: var(--forest-fern);
}

.bg-wave-1 {
    animation: wave-shift 25s linear infinite;
}

.bg-wave-2 {
    animation: wave-shift 18s linear infinite reverse;
    height: 25vh;
    opacity: 0.04;
}

.bg-wave-3 {
    animation: wave-shift 12s linear infinite;
    height: 20vh;
    opacity: 0.03;
    bottom: 5vh;
}

/* Spore Particles */
#spore-container {
    position: fixed;
    inset: 0;
    z-index: 5;
    pointer-events: none;
    overflow: hidden;
}

.spore {
    position: absolute;
    border-radius: 50%;
    background: var(--forest-glow);
    pointer-events: none;
    will-change: transform, opacity;
    box-shadow: 0 0 6px rgba(126, 200, 154, 0.3);
}

/* Mycelium Network */
#mycelium-network {
    position: fixed;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    width: 100%;
    height: 100%;
}

#mycelium-network path {
    fill: none;
    stroke: var(--forest-fern);
    stroke-opacity: 0.3;
    stroke-width: 0.15;
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-opacity 0.4s ease, stroke 0.4s ease;
}

#mycelium-network path.visible {
    animation: mycelium-grow 2s ease-out forwards;
}

#mycelium-network path.highlight {
    stroke: var(--forest-canopy);
    stroke-opacity: 0.7;
}

/* Canopy Frame */
#canopy-frame {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    will-change: transform;
}

.leaf-bracket {
    position: absolute;
    width: 100px;
    height: 100px;
    opacity: 0;
}

.leaf-bracket.revealed {
    opacity: 1;
}

.leaf-tl {
    top: 10px;
    left: 10px;
    animation: leaf-unfurl 1.2s var(--transition-spring) forwards;
}

.leaf-tr {
    top: 10px;
    right: 10px;
    animation: leaf-unfurl 1.2s 0.1s var(--transition-spring) forwards;
}

.leaf-bl {
    bottom: 10px;
    left: 10px;
    animation: leaf-unfurl 1.2s 0.2s var(--transition-spring) forwards;
}

.leaf-br {
    bottom: 10px;
    right: 10px;
    animation: leaf-unfurl 1.2s 0.3s var(--transition-spring) forwards;
}

.leaf-main {
    fill: none;
    stroke: var(--forest-fern);
    stroke-width: 1.5;
    stroke-opacity: 0.4;
}

.leaf-vein {
    fill: none;
    stroke: var(--forest-canopy);
    stroke-width: 1;
    stroke-opacity: 0.3;
}

.leaf-accent {
    fill: rgba(126, 200, 154, 0.05);
    stroke: none;
}

/* Vine Tendrils along edges */
.vine-tendril {
    position: absolute;
    pointer-events: none;
    opacity: 0;
    transition: opacity 1.2s ease;
}

.vine-tendril.revealed {
    opacity: 1;
}

.vine-tendril path {
    fill: none;
    stroke: var(--forest-fern);
    stroke-width: 1;
    stroke-opacity: 0.25;
    stroke-linecap: round;
}

.vine-top {
    top: 4px;
    left: 100px;
    right: 100px;
    height: 20px;
}

.vine-bottom {
    bottom: 4px;
    left: 100px;
    right: 100px;
    height: 20px;
}

.vine-left {
    top: 100px;
    bottom: 100px;
    left: 4px;
    width: 20px;
}

.vine-right {
    top: 100px;
    bottom: 100px;
    right: 4px;
    width: 20px;
}

/* Annotation Panels */
#annotation-panels {
    position: fixed;
    inset: 0;
    z-index: 2;
    pointer-events: none;
}

.annotation-panel {
    --push-x: 0px;
    --push-y: 0px;
    position: absolute;
    background: var(--panel-bg);
    backdrop-filter: var(--blur-panel);
    -webkit-backdrop-filter: var(--blur-panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-panel);
    padding: 16px 20px;
    max-width: 210px;
    opacity: 0;
    transition: transform 0.6s var(--transition-spring), opacity 0.4s ease;
    pointer-events: auto;
    will-change: transform;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(126, 200, 154, 0.05);
}

.annotation-panel.visible {
    opacity: 1;
}

.panel-leaf-ornament {
    position: absolute;
    top: -6px;
    left: -6px;
    width: 20px;
    height: 20px;
    opacity: 0.4;
}

.panel-leaf-ornament svg {
    width: 100%;
    height: 100%;
}

.panel-leaf-ornament svg path {
    fill: none;
    stroke: var(--forest-canopy);
    stroke-width: 1.5;
}

.panel-tl {
    top: 12%;
    left: 4%;
    transform: translate(calc(-40px + var(--push-x)), var(--push-y));
}

.panel-tl.visible {
    transform: translate(var(--push-x), var(--push-y));
}

.panel-tr {
    top: 12%;
    right: 4%;
    transform: translate(calc(40px + var(--push-x)), var(--push-y));
}

.panel-tr.visible {
    transform: translate(var(--push-x), var(--push-y));
}

.panel-ml {
    top: 50%;
    left: 3%;
    transform: translate(calc(-40px + var(--push-x)), calc(-50% + var(--push-y)));
}

.panel-ml.visible {
    transform: translate(var(--push-x), calc(-50% + var(--push-y)));
}

.panel-mr {
    top: 50%;
    right: 3%;
    transform: translate(calc(40px + var(--push-x)), calc(-50% + var(--push-y)));
}

.panel-mr.visible {
    transform: translate(var(--push-x), calc(-50% + var(--push-y)));
}

.panel-bc {
    bottom: 12vh;
    left: 50%;
    transform: translate(calc(-50% + var(--push-x)), calc(20px + var(--push-y)));
    max-width: 240px;
    text-align: center;
}

.panel-bc.visible {
    transform: translate(calc(-50% + var(--push-x)), var(--push-y));
}

.panel-label {
    display: block;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--forest-glow);
    margin-bottom: 8px;
}

.panel-data {
    font-family: var(--font-secondary);
    font-size: clamp(0.8rem, 1.4vw, 0.95rem);
    font-weight: 400;
    line-height: 1.55;
    color: var(--text-cream);
    opacity: 0.85;
    white-space: pre-line;
}

/* Specimen Ring */
#specimen-ring {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(55vw, 680px);
    height: min(55vw, 680px);
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ring-border {
    position: absolute;
    inset: 0;
    border: 2px dashed var(--forest-canopy);
    border-radius: 50%;
    opacity: 0;
    background: radial-gradient(ellipse at center, rgba(26, 71, 42, 0.08), transparent 70%);
}

.ring-border.visible {
    opacity: 1;
}

.ring-pulse {
    position: absolute;
    inset: 0;
    border: 2px solid var(--forest-canopy);
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
    animation: ring-pulse 2.5s ease-out infinite;
    animation-delay: 8s;
}

.ring-pulse-delayed {
    animation-delay: 12s;
}

#specimen-content {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 40px;
    max-width: 85%;
    opacity: 0;
    transition: opacity 0.6s ease;
}

#specimen-content.visible {
    opacity: 1;
}

/* Specimen Glyph */
.specimen-glyph {
    width: 72px;
    height: 72px;
    margin: 0 auto 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.specimen-glyph svg {
    width: 100%;
    height: 100%;
}

.specimen-glyph svg path,
.specimen-glyph svg circle,
.specimen-glyph svg ellipse {
    fill: none;
    stroke: var(--forest-canopy);
    stroke-width: 1.5;
}

.specimen-glyph svg .glyph-fill {
    fill: url(#glyphGradient);
    stroke: none;
    opacity: 0;
    transition: opacity 0.6s ease;
}

.specimen-glyph.animate svg path,
.specimen-glyph.animate svg circle,
.specimen-glyph.animate svg ellipse {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
    animation: glyph-draw 0.6s ease-out forwards;
}

.specimen-glyph.animate svg .glyph-fill {
    animation: glyph-fill-in 0.5s 0.4s ease forwards;
}

/* Specimen Title */
.specimen-title {
    font-family: var(--font-display);
    font-weight: 400;
    font-style: italic;
    font-size: clamp(2.2rem, 5vw, 4.8rem);
    letter-spacing: 0.01em;
    color: var(--text-cream);
    margin-bottom: 8px;
    line-height: 1.15;
}

.specimen-title .char {
    display: inline-block;
    opacity: 0;
    transform: translateY(4px);
    transition: none;
}

.specimen-title .char.typed {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.12s ease, transform 0.12s ease;
}

/* Specimen Classification Code */
.specimen-code {
    display: block;
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--forest-glow);
    margin-bottom: 16px;
    opacity: 0;
    transition: opacity 0.5s 0.2s ease;
}

.specimen-code.visible {
    opacity: 0.8;
}

/* Specimen Description */
.specimen-description {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.875rem, 1.6vw, 1.125rem);
    line-height: 1.65;
    color: var(--text-cream);
    opacity: 0;
    transition: opacity 0.5s 0.3s ease;
    max-width: 460px;
    margin: 0 auto;
}

.specimen-description.visible {
    opacity: 0.9;
}

/* Specimen Interactive Wave */
.specimen-interactive {
    margin-top: 20px;
    height: 60px;
    position: relative;
    opacity: 0;
    transition: opacity 0.5s 0.5s ease;
}

.specimen-interactive.visible {
    opacity: 1;
}

.specimen-interactive svg {
    width: 100%;
    height: 100%;
}

.specimen-interactive svg path {
    fill: none;
    stroke: var(--forest-glow);
    stroke-width: 1.5;
    stroke-opacity: 0.5;
    stroke-linecap: round;
}

/* Wave Divider inside ring */
#wave-divider {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, 80px);
    width: min(40vw, 500px);
    height: 40px;
    z-index: 3;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease;
}

#wave-divider.visible {
    opacity: 0.6;
}

.wave-line {
    fill: none;
    stroke-width: 1.5;
    stroke-linecap: round;
}

.wave-line-1 {
    stroke: var(--forest-canopy);
    stroke-opacity: 0.5;
}

.wave-line-2 {
    stroke: var(--forest-glow);
    stroke-opacity: 0.3;
}

.wave-line-3 {
    stroke: var(--accent-gold);
    stroke-opacity: 0.15;
    stroke-width: 1;
}

/* Root Navigation */
#root-navigation {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 10vh;
    min-height: 80px;
    z-index: 4;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 10px;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease, transform 0.6s var(--transition-spring);
}

#root-navigation.visible {
    opacity: 1;
    transform: translateY(0);
}

#root-line {
    position: absolute;
    bottom: 35px;
    left: 5%;
    width: 90%;
    height: 30px;
    pointer-events: none;
}

.root-path {
    fill: none;
    stroke: var(--forest-fern);
    stroke-width: 2;
    stroke-linecap: round;
}

.root-path-glow {
    fill: none;
    stroke: var(--forest-glow);
    stroke-width: 1;
    stroke-linecap: round;
    stroke-opacity: 0.15;
    filter: blur(2px);
}

#nav-nodes {
    display: flex;
    gap: clamp(24px, 5vw, 64px);
    align-items: flex-end;
    position: relative;
    z-index: 1;
    padding-bottom: 2px;
}

.nav-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: none;
    border: none;
    cursor: pointer;
    position: relative;
    padding: 0;
    transition: transform 0.3s var(--transition-spring);
}

.node-stem {
    display: block;
    width: 1px;
    height: 16px;
    background: var(--forest-fern);
    transition: height 0.3s var(--transition-spring), background 0.3s ease;
    margin-bottom: 2px;
}

.node-circle {
    display: block;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--forest-canopy);
    background: var(--forest-deep);
    transition: box-shadow 0.3s ease, background 0.3s ease, border-color 0.3s ease;
}

.nav-node:hover .node-stem {
    height: 22px;
    background: var(--forest-canopy);
}

.nav-node:hover .node-circle {
    box-shadow: 0 0 16px rgba(126, 200, 154, 0.6);
    border-color: var(--forest-glow);
}

.nav-node.active .node-circle {
    background: var(--forest-canopy);
    border-color: var(--forest-glow);
    box-shadow: 0 0 20px rgba(126, 200, 154, 0.4);
}

.nav-node.active .node-stem {
    background: var(--forest-canopy);
}

.node-label {
    display: block;
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-cream);
    opacity: 0.6;
    letter-spacing: 0.05em;
    margin-top: 6px;
    transition: opacity 0.3s ease;
    white-space: nowrap;
}

.nav-node:hover .node-label,
.nav-node.active .node-label {
    opacity: 1;
}

/* Awakening Overlay */
#awakening-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.8s ease;
}

#awakening-overlay.fading {
    opacity: 0;
    pointer-events: none;
}

#awakening-overlay.hidden {
    display: none;
}

#awakening-wave {
    width: 60%;
    height: 60px;
    opacity: 0;
}

#awakening-wave path {
    fill: none;
    stroke: var(--forest-glow);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
}

#awakening-wave.drawing {
    opacity: 1;
}

#awakening-wave.drawing path {
    animation: wave-draw 0.8s ease-out forwards;
}

/* ============================================
   KEYFRAMES
   ============================================ */

@keyframes wave-shift {
    from { transform: translateX(0); }
    to { transform: translateX(-50%); }
}

@keyframes ring-pulse {
    0% {
        transform: scale(1);
        opacity: 0.5;
    }
    100% {
        transform: scale(1.8);
        opacity: 0;
    }
}

@keyframes leaf-unfurl {
    0% {
        transform: rotate(-15deg) scale(0.8);
        opacity: 0;
    }
    100% {
        transform: rotate(0deg) scale(1);
        opacity: 1;
    }
}

@keyframes glow-breathe {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.8; }
}

@keyframes spore-drift {
    0% {
        transform: translateY(0) translateX(0);
        opacity: var(--spore-opacity, 0.4);
    }
    25% {
        transform: translateY(-25vh) translateX(8px);
    }
    50% {
        transform: translateY(-50vh) translateX(-5px);
        opacity: var(--spore-opacity, 0.4);
    }
    75% {
        transform: translateY(-75vh) translateX(10px);
    }
    100% {
        transform: translateY(-110vh) translateX(3px);
        opacity: 0;
    }
}

@keyframes mycelium-grow {
    from { stroke-dashoffset: 200; }
    to { stroke-dashoffset: 0; }
}

@keyframes wave-draw {
    from { stroke-dashoffset: 1200; }
    to { stroke-dashoffset: 0; }
}

@keyframes glyph-draw {
    from { stroke-dashoffset: 300; }
    to { stroke-dashoffset: 0; }
}

@keyframes glyph-fill-in {
    from { opacity: 0; }
    to { opacity: 0.3; }
}

@keyframes content-radial-in {
    0% {
        clip-path: circle(0% at 50% 50%);
        opacity: 0;
    }
    100% {
        clip-path: circle(75% at 50% 50%);
        opacity: 1;
    }
}

@keyframes vine-sway {
    0%, 100% { transform: scaleX(1); }
    50% { transform: scaleX(1.01); }
}

@keyframes panel-glow-pulse {
    0%, 100% { box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(126, 200, 154, 0.05); }
    50% { box-shadow: 0 4px 28px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(126, 200, 154, 0.1); }
}

/* Content transition */
#specimen-content.entering {
    animation: content-radial-in 0.9s var(--transition-spring) forwards;
}

/* Text highlight wave underline */
.wave-underline {
    position: relative;
    display: inline;
}

.wave-underline::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, transparent 0%, rgba(126,200,154,0.3) 50%, transparent 100%);
    border-radius: 2px;
}

/* Gold accent for spark specimen */
.specimen-glyph.spark-glyph svg path,
.specimen-glyph.spark-glyph svg circle {
    stroke: var(--accent-gold);
}

/* Text highlight glow effect */
.text-glow {
    background: linear-gradient(90deg, transparent 0%, rgba(126,200,154,0.15) 50%, transparent 100%);
    padding: 0 4px;
    border-radius: 2px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    #specimen-ring {
        width: min(80vw, 400px);
        height: min(80vw, 400px);
    }

    .annotation-panel {
        max-width: 150px;
        padding: 10px 14px;
        font-size: 0.85rem;
    }

    .panel-tl, .panel-tr {
        top: 6%;
    }

    .panel-ml {
        left: 1%;
    }

    .panel-mr {
        right: 1%;
    }

    .panel-bc {
        display: none;
    }

    .leaf-bracket {
        width: 60px;
        height: 60px;
    }

    .vine-tendril {
        display: none;
    }

    #nav-nodes {
        gap: 16px;
    }

    .node-circle {
        width: 24px;
        height: 24px;
    }

    .node-label {
        font-size: 10px;
    }

    #specimen-content {
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .annotation-panel {
        display: none;
    }

    #specimen-ring {
        width: min(90vw, 320px);
        height: min(90vw, 320px);
    }

    .specimen-title {
        font-size: clamp(1.6rem, 8vw, 2.4rem);
    }

    .leaf-bracket {
        width: 40px;
        height: 40px;
    }
}
