/* ===================================
   namu.works - Surreal Data Mineralogy
   Jewel-Tones | Layered-Depth | Crystalline
   =================================== */

/* --- CSS Custom Properties --- */
:root {
    --obsidian-void: #0d0221;
    --sapphire-deep: #1a1a4e;
    --amethyst-blaze: #6a1b9a;
    --ruby-vein: #9b1b5e;
    --emerald-core: #0b6e4f;
    --topaz-flare: #e6a817;
    --crystal-white: #e8e0f0;
    --soft-quartz: #c4b8d9;
    --smoky-glass: #7b6f8e;
    --tourmaline-line: #3d1f5c;

    --accent-primary: #6a1b9a;
    --accent-glow: rgba(106, 27, 154, 0.4);

    --font-display: 'Nunito', sans-serif;
    --font-body: 'Varela Round', sans-serif;
    --font-data: 'Space Grotesk', sans-serif;
}

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

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

body {
    background: var(--obsidian-void);
    color: var(--soft-quartz);
    font-family: var(--font-body);
    font-size: clamp(0.95rem, 1.8vw, 1.15rem);
    line-height: 1.72;
    overflow-x: hidden;
    min-height: 100vh;
}

/* --- Geode Entrance Overlay --- */
#geode-entrance {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    pointer-events: none;
}

#geode-top,
#geode-bottom {
    position: absolute;
    left: 0;
    width: 100%;
    height: 50%;
    background: var(--obsidian-void);
    z-index: 2;
    will-change: transform;
}

#geode-top {
    top: 0;
}

#geode-bottom {
    bottom: 0;
}

#geode-crack {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 0;
    height: 1px;
    background: linear-gradient(90deg, #6a1b9a, #9b1b5e, #0b6e4f, #e6a817, #6a1b9a);
    z-index: 3;
    will-change: width;
}

#geode-entrance.crack-expand #geode-crack {
    animation: crackExpand 800ms cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

#geode-entrance.geode-open #geode-top {
    animation: slideUp 600ms cubic-bezier(0.33, 1, 0.68, 1) forwards;
}

#geode-entrance.geode-open #geode-bottom {
    animation: slideDown 600ms cubic-bezier(0.33, 1, 0.68, 1) forwards;
}

#geode-entrance.geode-hidden {
    display: none;
}

@keyframes crackExpand {
    from { width: 0; }
    to { width: 100%; }
}

@keyframes slideUp {
    from { transform: translateY(0); }
    to { transform: translateY(-100%); }
}

@keyframes slideDown {
    from { transform: translateY(0); }
    to { transform: translateY(100%); }
}

/* --- Navigation --- */
#site-nav {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    padding: 24px;
    display: flex;
    align-items: flex-start;
    gap: 0;
    flex-direction: column;
}

.nav-brand {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(1rem, 2vw, 1.3rem);
    color: var(--crystal-white);
    text-decoration: none;
    letter-spacing: 0.02em;
    opacity: 0;
    transition: opacity 600ms ease;
}

.nav-brand.visible {
    opacity: 1;
}

.nav-line {
    position: fixed;
    top: 60px;
    left: 36px;
    width: 1px;
    height: 0;
    background: linear-gradient(to bottom, var(--ruby-vein), transparent);
    transition: height 1200ms ease;
}

.nav-line.visible {
    height: calc(100vh - 80px);
}

/* --- Perspective Container --- */
#perspective-container {
    position: relative;
    perspective: 1200px;
    min-height: 100vh;
    overflow: visible;
}

/* --- Depth Layers --- */
.depth-layer {
    will-change: transform;
}

/* Layer 0: Background */
.layer-0 {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(ellipse at center, var(--sapphire-deep) 0%, var(--obsidian-void) 70%),
        repeating-linear-gradient(60deg, rgba(106, 27, 154, 0.06) 0px, transparent 1px, transparent 40px),
        repeating-linear-gradient(120deg, rgba(106, 27, 154, 0.06) 0px, transparent 1px, transparent 40px);
    z-index: 0;
    transform: translateZ(-120px) scale(1.1);
}

/* Layer 1: Data Substrate */
.layer-1 {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50vh;
    opacity: 0.15;
    z-index: 1;
    transform: translateZ(-80px);
    pointer-events: none;
}

.substrate-bars {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    height: 100%;
    padding: 0 10%;
}

.substrate-bars .bar {
    width: 4%;
    height: var(--h, 50%);
    background: linear-gradient(to top, var(--emerald-core), transparent);
    border-radius: 2px 2px 0 0;
    animation: substratePulse 4s ease-in-out infinite;
    animation-delay: var(--d, 0s);
}

@keyframes substratePulse {
    0%, 100% { opacity: 0.4; transform: scaleY(1); }
    50% { opacity: 0.8; transform: scaleY(1.15); }
}

/* Layer 3: Floating Facets */
.layer-3 {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 4;
    pointer-events: none;
    transform: translateZ(40px);
    overflow: hidden;
}

.facet {
    position: absolute;
    left: var(--x, 50%);
    top: var(--y, 50%);
    opacity: 0.08;
    animation: facetDrift var(--dur, 20s) ease-in-out infinite;
    animation-delay: var(--delay, 0s);
    will-change: transform, opacity;
}

.facet-hex {
    width: 40px;
    height: 40px;
    background: var(--amethyst-blaze);
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}

.facet-diamond {
    width: 30px;
    height: 42px;
    background: var(--ruby-vein);
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}

.facet-triangle {
    width: 36px;
    height: 32px;
    background: var(--topaz-flare);
    clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
}

@keyframes facetDrift {
    0%, 100% {
        transform: translate(0, 0) rotate(0deg);
        opacity: 0.08;
    }
    25% {
        transform: translate(30px, -20px) rotate(45deg);
        opacity: 0.12;
    }
    50% {
        transform: translate(-15px, -40px) rotate(90deg);
        opacity: 0.06;
    }
    75% {
        transform: translate(20px, -10px) rotate(135deg);
        opacity: 0.10;
    }
}

/* Layer 2: Content Plane */
.layer-2 {
    position: relative;
    z-index: 3;
    transform: translateZ(0);
}

/* --- Crystal Plates (Content Containers) --- */
.crystal-plate {
    max-width: 1100px;
    margin: 0 auto;
    padding: 60px 48px;
    background: rgba(13, 2, 33, 0.85);
    border: 1px solid rgba(168, 50, 121, 0.25);
    clip-path: polygon(4% 0%, 96% 0%, 100% 4%, 100% 96%, 96% 100%, 4% 100%, 0% 96%, 0% 4%);
    position: relative;
}

.crystal-plate + .prismatic-divider {
    margin: 0 auto;
}

.content-section {
    margin-bottom: 0;
}

/* --- Hero Section --- */
.hero-plate {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: linear-gradient(135deg, #0d0221 0%, #1a1a4e 30%, rgba(106, 27, 154, 0.15) 60%, rgba(155, 27, 94, 0.1) 85%, #0d0221 100%);
    border: none;
    clip-path: none;
    padding-top: 0;
    padding-bottom: 40px;
}

.hero-title {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(3rem, 8vw, 6rem);
    color: var(--crystal-white);
    letter-spacing: 0.02em;
    opacity: 0;
    margin-bottom: 24px;
}

.hero-title.revealed .hero-letter {
    display: inline-block;
    text-shadow: 0 0 20px rgba(106, 27, 154, 0.6);
    opacity: 0;
    animation: letterGlow 500ms ease forwards;
}

.hero-tagline {
    font-family: var(--font-body);
    font-size: clamp(1rem, 2vw, 1.2rem);
    color: var(--soft-quartz);
    max-width: 600px;
    margin: 0 auto;
    opacity: 0;
    transition: opacity 800ms ease;
    line-height: 1.72;
}

.hero-tagline.visible {
    opacity: 1;
}

@keyframes letterGlow {
    from {
        opacity: 0;
        text-shadow: 0 0 0 rgba(106, 27, 154, 0);
    }
    to {
        opacity: 1;
        text-shadow: 0 0 20px rgba(106, 27, 154, 0.6);
    }
}

/* Scroll Indicator */
.scroll-indicator {
    margin-top: 60px;
    opacity: 0;
    transition: opacity 600ms ease;
}

.scroll-indicator.visible {
    opacity: 1;
}

.chevron-down {
    width: 20px;
    height: 20px;
    border-right: 2px solid var(--topaz-flare);
    border-bottom: 2px solid var(--topaz-flare);
    transform: rotate(45deg);
    animation: chevronPulse 2s ease-in-out infinite;
}

@keyframes chevronPulse {
    0%, 100% { opacity: 0.3; transform: rotate(45deg) translateY(0); }
    50% { opacity: 0.8; transform: rotate(45deg) translateY(6px); }
}

/* --- Prismatic Divider --- */
.prismatic-divider {
    width: 80%;
    max-width: 900px;
    height: 3px;
    margin: 120px auto;
    background: linear-gradient(90deg, #6a1b9a, #9b1b5e, #0b6e4f, #e6a817, #6a1b9a);
    background-size: 200% 100%;
    animation: prismaticShift 20s linear infinite;
    border-radius: 2px;
}

@keyframes prismaticShift {
    from { background-position: 0% 50%; }
    to { background-position: 200% 50%; }
}

/* --- Section Headings --- */
.section-heading {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.6rem, 3.5vw, 2.8rem);
    color: var(--crystal-white);
    letter-spacing: 0.02em;
    margin-bottom: 20px;
}

.section-body {
    font-family: var(--font-body);
    color: var(--soft-quartz);
    max-width: 700px;
    margin-bottom: 48px;
    line-height: 1.72;
}

/* --- Scroll-triggered Entrance --- */
.content-section {
    opacity: 0;
    transform: translateY(30px) scale(0.97);
    transition: opacity 500ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 500ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.content-section.in-view {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.content-section .section-heading,
.content-section .section-body,
.content-section .hex-cluster,
.content-section .constellation-map,
.content-section .hex-cluster-alt,
.content-section .data-numbers,
.content-section .area-viz-container,
.content-section .faceted-cards,
.content-section .closing-text,
.content-section .closing-domain {
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 400ms ease, transform 400ms ease;
}

.content-section.in-view .section-heading {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 0ms;
}

.content-section.in-view .section-body {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 80ms;
}

.content-section.in-view .hex-cluster,
.content-section.in-view .constellation-map,
.content-section.in-view .hex-cluster-alt,
.content-section.in-view .area-viz-container {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 160ms;
}

.content-section.in-view .data-numbers,
.content-section.in-view .faceted-cards {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 240ms;
}

.content-section.in-view .closing-text,
.content-section.in-view .closing-domain {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 80ms;
}

/* --- Hexagonal Data Cells --- */
.hex-cluster {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
    margin: 40px 0;
}

.hex-cell {
    width: 140px;
    height: 140px;
    position: relative;
    transition: transform 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
    filter: drop-shadow(0 0 6px var(--accent-glow));
    cursor: pointer;
}

.hex-cell:hover {
    transform: scale(1.04);
    filter: drop-shadow(0 0 12px rgba(106, 27, 154, 0.6));
}

.hex-cell:active {
    transform: scale(0.97);
}

.hex-frame {
    width: 100%;
    height: 100%;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    background: rgba(26, 26, 78, 0.8);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 20px;
}

/* Viz: Bar Chart */
.viz-bars {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 80%;
    width: 80%;
}

.viz-bars span {
    flex: 1;
    height: var(--h, 50%);
    background: linear-gradient(to top, var(--accent-primary), rgba(106, 27, 154, 0.3));
    border-radius: 2px 2px 0 0;
    transition: height 800ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.hex-cell:hover .viz-bars span {
    height: calc(var(--h, 50%) + 10%);
}

/* Viz: Ring Gauge */
.viz-ring {
    width: 80%;
    height: 80%;
}

.ring-bg {
    fill: none;
    stroke: rgba(106, 27, 154, 0.2);
    stroke-width: 6;
}

.ring-fill {
    fill: none;
    stroke: var(--accent-primary);
    stroke-width: 6;
    stroke-linecap: round;
    stroke-dasharray: 239;
    stroke-dashoffset: 239;
    transition: stroke-dashoffset 1200ms cubic-bezier(0.34, 1.56, 0.64, 1);
    transform: rotate(-90deg);
    transform-origin: center;
}

.hex-cell:hover .ring-fill,
.in-view .ring-fill {
    stroke-dashoffset: 67;
}

/* Viz: Sparkline */
.viz-sparkline {
    width: 80%;
    height: 60%;
}

.sparkline-path {
    fill: none;
    stroke: var(--accent-primary);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
    transition: stroke-dashoffset 1500ms ease;
}

.in-view .sparkline-path {
    stroke-dashoffset: 0;
}

/* Hex neighbor expansion on hover */
.hex-cluster .hex-cell.neighbor-shift-left {
    transform: translateX(-2px);
}

.hex-cluster .hex-cell.neighbor-shift-right {
    transform: translateX(2px);
}

/* --- Data Streamline --- */
.data-streamline {
    position: relative;
    width: 4px;
    height: 200px;
    margin: 40px auto;
}

.streamline-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.vein-path {
    fill: none;
    stroke: var(--emerald-core);
    stroke-width: 0.5;
    opacity: 0.3;
}

.data-point {
    position: absolute;
    width: 4px;
    height: 4px;
    background: var(--emerald-core);
    border-radius: 50%;
    left: 0;
    top: 0;
    animation: dataFlow 4s linear infinite;
    animation-delay: var(--delay, 0s);
}

@keyframes dataFlow {
    0% { top: 0; opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { top: 100%; opacity: 0; }
}

/* --- Constellation Map --- */
.constellation-map {
    width: 100%;
    max-width: 600px;
    margin: 40px auto;
}

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

.constellation-line {
    stroke: var(--soft-quartz);
    stroke-width: 0.5;
    opacity: 0.2;
}

.constellation-node {
    fill: var(--topaz-flare);
}

.node-pulse {
    animation: nodePulse 3s ease-in-out infinite;
    animation-delay: var(--delay, 0s);
}

@keyframes nodePulse {
    0%, 100% { transform-origin: center; r: inherit; opacity: 0.7; }
    50% { opacity: 1; }
}

/* --- Data Numbers --- */
.data-numbers {
    display: flex;
    gap: 40px;
    justify-content: center;
    flex-wrap: wrap;
    margin: 48px 0 16px;
}

.data-stat {
    text-align: center;
}

.stat-value {
    display: block;
    font-family: var(--font-data);
    font-weight: 500;
    font-size: clamp(1.8rem, 4vw, 2.6rem);
    color: var(--crystal-white);
    letter-spacing: 0.04em;
}

.stat-label {
    display: block;
    font-family: var(--font-body);
    font-size: clamp(0.75rem, 1.4vw, 0.95rem);
    color: var(--smoky-glass);
    margin-top: 4px;
}

/* --- Area Visualization --- */
.area-viz-container {
    width: 100%;
    margin: 40px 0;
    border-radius: 4px;
    overflow: hidden;
}

.area-viz {
    width: 100%;
    height: auto;
    display: block;
}

.area-path {
    opacity: 0.8;
}

/* --- Faceted Cards --- */
.faceted-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin: 48px 0;
}

.faceted-card {
    position: relative;
    padding: 32px 28px;
    background: rgba(26, 26, 78, 0.6);
    clip-path: polygon(4% 0%, 96% 0%, 100% 4%, 100% 96%, 96% 100%, 4% 100%, 0% 96%, 0% 4%);
    overflow: hidden;
    cursor: pointer;
    transition: transform 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.faceted-card:hover {
    transform: scale(1.04);
}

.faceted-card:active {
    transform: scale(0.97);
}

.card-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 120%;
    height: 120%;
    transform: translate(-50%, -50%);
    background: radial-gradient(ellipse at center, var(--accent-glow) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 400ms ease;
    pointer-events: none;
}

.faceted-card:hover .card-glow {
    opacity: 0.3;
}

.card-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.1rem, 2vw, 1.4rem);
    color: var(--crystal-white);
    letter-spacing: 0.02em;
    margin-bottom: 12px;
}

.card-text {
    font-family: var(--font-body);
    color: var(--soft-quartz);
    font-size: clamp(0.85rem, 1.5vw, 1rem);
    line-height: 1.65;
}

/* --- Final Section --- */
.final-section {
    text-align: center;
    min-height: 60vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.closing-text {
    font-family: var(--font-body);
    font-size: clamp(1.1rem, 2.5vw, 1.5rem);
    color: var(--soft-quartz);
    font-style: italic;
    margin-bottom: 32px;
}

.closing-domain {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(2rem, 5vw, 3.5rem);
    color: var(--crystal-white);
    text-shadow: 0 0 30px rgba(106, 27, 154, 0.5);
    letter-spacing: 0.02em;
}

/* --- Accent Color per Section --- */
[data-accent="amethyst"] {
    --accent-primary: #6a1b9a;
    --accent-glow: rgba(106, 27, 154, 0.4);
}

[data-accent="ruby"] {
    --accent-primary: #9b1b5e;
    --accent-glow: rgba(155, 27, 94, 0.4);
}

[data-accent="emerald"] {
    --accent-primary: #0b6e4f;
    --accent-glow: rgba(11, 110, 79, 0.4);
}

[data-accent="topaz"] {
    --accent-primary: #e6a817;
    --accent-glow: rgba(230, 168, 23, 0.4);
}

/* --- Data Glow Effect --- */
.data-glow {
    filter: drop-shadow(0 0 6px var(--accent-glow));
}

/* --- Responsive: Mobile --- */
@media (max-width: 768px) {
    .layer-0 {
        transform: none;
    }

    .layer-1 {
        transform: none;
        opacity: 0.08;
    }

    .layer-3 {
        transform: none;
    }

    .layer-3 .facet:nth-child(n+4) {
        display: none;
    }

    .crystal-plate {
        padding: 40px 16px;
        clip-path: polygon(2% 0%, 98% 0%, 100% 2%, 100% 98%, 98% 100%, 2% 100%, 0% 98%, 0% 2%);
    }

    .hex-cluster {
        gap: 10px;
    }

    .hex-cell {
        width: 100px;
        height: 100px;
    }

    .faceted-cards {
        grid-template-columns: 1fr;
    }

    .data-numbers {
        gap: 24px;
    }

    #site-nav {
        padding: 16px;
    }

    .nav-line {
        display: none;
    }

    .prismatic-divider {
        margin: 60px auto;
    }

    .constellation-map {
        max-width: 100%;
    }
}

@media (max-width: 480px) {
    .hero-title {
        font-size: clamp(2.2rem, 10vw, 3rem);
    }

    .crystal-plate {
        padding: 32px 12px;
    }

    .hex-cell {
        width: 80px;
        height: 80px;
    }
}
