/* ========================================
   archetypic.dev -- Styles
   Hexagonal-honeycomb mandala experience
   ======================================== */

:root {
    /* Palette */
    --parchment: #f4ede4;
    --parchment-edge: #ebe1d4;
    --ink: #2c1e1a;
    --violet: #6b4c8a;
    --gold: #c4983a;
    --rose: #a8697a;
    --indigo: #3a3560;
    --amber: #e8c17a;

    /* Tempo multiplier: adjust to speed/slow entire experience */
    --tempo: 1;

    /* Sizing */
    --hex-size: clamp(140px, 22vmin, 260px);
    --hex-gap: clamp(8px, 1.5vmin, 18px);
}

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

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

body {
    font-family: 'Libre Caslon Text', Georgia, serif;
    color: var(--ink);
    background: radial-gradient(ellipse at center, var(--parchment) 0%, var(--parchment-edge) 100%);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

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

/* ---- Noise Overlay ---- */
.noise-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.025;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    background-repeat: repeat;
}

/* ---- Act 1: The Threshold ---- */
.act-threshold {
    position: relative;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.title-container {
    text-align: center;
}

.title {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 600;
    font-style: italic;
    font-size: clamp(3rem, 10vw, 7rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink);
    display: inline-block;
}

.letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(8px);
    animation: letterReveal 0.5s ease-out forwards;
    animation-delay: calc(0.6s + var(--letter-index, 0) * 0.08s);
}

.letter:nth-child(1) { --letter-index: 0; }
.letter:nth-child(2) { --letter-index: 1; }
.letter:nth-child(3) { --letter-index: 2; }
.letter:nth-child(4) { --letter-index: 3; }
.letter:nth-child(5) { --letter-index: 4; }
.letter:nth-child(6) { --letter-index: 5; }
.letter:nth-child(7) { --letter-index: 6; }
.letter:nth-child(8) { --letter-index: 7; }
.letter:nth-child(9) { --letter-index: 8; }
.letter:nth-child(10) { --letter-index: 9; }

@keyframes letterReveal {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.subtitle {
    font-family: 'Alegreya Sans SC', sans-serif;
    font-weight: 500;
    font-size: 0.85rem;
    letter-spacing: 0.18em;
    color: var(--violet);
    opacity: 0;
    animation: fadeIn 0.8s ease-out forwards;
    animation-delay: 2.2s;
    margin-top: 0.5rem;
}

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

/* ---- Title fade on scroll ---- */
.title-container.fading {
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
    opacity: 0;
    transform: translateY(-40px);
}

/* ---- Act 2 & 3: The Mandala ---- */
.act-mandala {
    position: relative;
    min-height: 250vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 10vh;
    z-index: 2;
}

.mandala-container {
    position: sticky;
    top: 50%;
    transform: translateY(-50%);
    width: calc(var(--hex-size) * 3.5);
    height: calc(var(--hex-size) * 3.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ---- Connector Lines ---- */
.connector-lines {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 1s ease;
}

.connector-lines.visible {
    opacity: 1;
}

.connector {
    stroke: var(--gold);
    stroke-width: 1;
    opacity: 0.3;
    animation: connectorPulse 4s ease-in-out infinite;
}

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

/* ---- Hexagonal Cells ---- */
.hex-cell {
    position: absolute;
    width: var(--hex-size);
    height: var(--hex-size);
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--parchment);
    border: none;
    transition:
        transform calc(1.2s * var(--tempo)) cubic-bezier(0.22, 0.61, 0.36, 1),
        opacity calc(0.8s * var(--tempo)) ease;
    cursor: default;
    z-index: 1;
}

.hex-cell::before {
    content: '';
    position: absolute;
    inset: 0;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    border: 1px solid var(--gold);
    opacity: 0.5;
    pointer-events: none;
    z-index: 2;
}

.hex-content {
    padding: clamp(1rem, 3vmin, 2.5rem);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* ---- Hex positions (collapsed: all at center) ---- */
.hex-cell {
    left: 50%;
    top: 50%;
    margin-left: calc(var(--hex-size) / -2);
    margin-top: calc(var(--hex-size) / -2);
}

/* Expanded positions (set via JS with --tx, --ty) */
.hex-cell.expanded {
    transform: translate(var(--tx, 0), var(--ty, 0));
}

/* ---- Center Cell ---- */
.hex-center {
    z-index: 3;
    background: var(--parchment);
}

.hex-center::before {
    border-color: var(--violet);
    border-width: 2px;
    opacity: 0.7;
}

.hex-thesis {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 600;
    font-style: italic;
    font-size: clamp(0.85rem, 2vmin, 1.3rem);
    color: var(--violet);
    letter-spacing: 0.04em;
    line-height: 1.4;
}

/* ---- Outer Hex Cells ---- */
.hex-outer {
    opacity: 0;
}

.hex-outer.revealed {
    opacity: 1;
}

.hex-outer.dimmed {
    opacity: 0.4;
    transform: translate(var(--tx, 0), var(--ty, 0)) scale(0.92);
}

.hex-outer.active {
    opacity: 1;
    transform: translate(var(--tx, 0), var(--ty, 0)) scale(1.08);
    z-index: 5;
}

.hex-outer.active::before {
    border-color: var(--violet);
    border-width: 2px;
    opacity: 1;
}

.hex-outer:not(.active) .hex-content .archetype-name,
.hex-outer:not(.active) .hex-content .archetype-desc {
    opacity: 0;
}

.archetype-symbol {
    width: clamp(36px, 6vmin, 56px);
    height: clamp(36px, 6vmin, 56px);
    margin-bottom: 0.4rem;
    opacity: 0;
    transition: opacity 0.6s ease;
}

.hex-outer.active .archetype-symbol {
    opacity: 1;
}

/* Path draw animation for active symbols */
.hex-outer.active .archetype-symbol circle,
.hex-outer.active .archetype-symbol path,
.hex-outer.active .archetype-symbol line,
.hex-outer.active .archetype-symbol polyline,
.hex-outer.active .archetype-symbol ellipse {
    animation: pathDraw 1.5s ease-in-out forwards;
}

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

.archetype-name {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 600;
    font-style: italic;
    font-size: clamp(0.7rem, 1.8vmin, 1.1rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--violet);
    margin-bottom: 0.3rem;
    opacity: 0;
    transition: opacity 0.6s ease 0.3s;
}

.archetype-desc {
    font-family: 'Libre Caslon Text', Georgia, serif;
    font-size: clamp(0.5rem, 1.1vmin, 0.7rem);
    line-height: 1.55;
    color: var(--ink);
    opacity: 0;
    transition: opacity 0.6s ease 0.5s;
}

.hex-outer.active .archetype-name,
.hex-outer.active .archetype-desc {
    opacity: 1;
}

/* Hover tint on non-active hexagons */
.hex-outer.revealed:not(.active):hover {
    background: linear-gradient(135deg, var(--parchment), rgba(168, 105, 122, 0.08));
}

/* ---- Act 4: The Descent ---- */
.act-descent {
    position: relative;
    z-index: 2;
    padding: 20vh clamp(2rem, 8vw, 12rem);
    max-width: 100%;
}

.prose-block {
    max-width: 38em;
    margin: 0 auto 4rem;
    opacity: 0;
    filter: blur(4px);
    transition: opacity 0.8s ease-out, filter 0.8s ease-out;
}

.prose-block.visible {
    opacity: 1;
    filter: blur(0);
}

.prose-block p {
    font-family: 'Libre Caslon Text', Georgia, serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    line-height: 1.75;
    color: var(--ink);
}

/* ---- Ma-Space Glyphs ---- */
.ma-glyph {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 40vh;
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-style: italic;
    font-size: 4rem;
    color: var(--rose);
    opacity: 0.4;
    animation: glyphRotate 60s linear infinite;
    user-select: none;
}

@keyframes glyphRotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ---- Ouroboros Sigil ---- */
.sigil {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 48px;
    height: 48px;
    cursor: pointer;
    z-index: 100;
    opacity: 0.6;
    transition: opacity 0.3s ease;
}

.sigil:hover {
    opacity: 1;
}

.sigil:hover .sigil-path {
    animation: ouroborosAnimate 2s linear infinite;
}

.sigil-path {
    stroke-dasharray: 113;
    stroke-dashoffset: 0;
}

@keyframes ouroborosAnimate {
    from { stroke-dashoffset: 0; }
    to { stroke-dashoffset: -113; }
}

/* ---- Mandala fade on scroll past ---- */
.mandala-container.fading-out {
    transition: opacity 1s ease, transform 1s ease;
    opacity: 0;
    transform: translateY(-50%) scale(0.85);
}

/* ---- Reduced Motion ---- */
@media (prefers-reduced-motion: reduce) {
    .letter {
        animation: none;
        opacity: 1;
        transform: none;
    }
    .subtitle {
        animation: none;
        opacity: 1;
    }
    .hex-cell {
        transition: none;
    }
    .hex-outer {
        opacity: 1;
    }
    .hex-outer .archetype-name,
    .hex-outer .archetype-desc,
    .hex-outer .archetype-symbol {
        opacity: 1;
    }
    .archetype-symbol circle,
    .archetype-symbol path,
    .archetype-symbol line,
    .archetype-symbol polyline,
    .archetype-symbol ellipse {
        stroke-dashoffset: 0;
        animation: none;
    }
    .prose-block {
        opacity: 1;
        filter: none;
    }
    .ma-glyph {
        animation: none;
    }
    .connector {
        animation: none;
        opacity: 0.5;
    }
}

/* ---- Responsive adjustments ---- */
@media (max-width: 600px) {
    :root {
        --hex-size: clamp(100px, 35vmin, 160px);
    }

    .act-mandala {
        min-height: 300vh;
    }

    .mandala-container {
        width: calc(var(--hex-size) * 3.2);
        height: calc(var(--hex-size) * 3.2);
    }

    .archetype-desc {
        display: none;
    }

    .act-descent {
        padding: 15vh clamp(1.5rem, 5vw, 4rem);
    }
}

@media (max-width: 400px) {
    :root {
        --hex-size: clamp(90px, 30vmin, 130px);
    }
}
