/* ===== Custom Property for Counter Animation ===== */
@property --counter-value {
    syntax: '<integer>';
    inherits: false;
    initial-value: 0;
}

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

html {
    scroll-behavior: smooth;
}

body {
    background: #0a1628;
    color: #b8d4e8;
    font-family: 'Outfit', sans-serif;
    font-weight: 300;
    line-height: 1.7;
    letter-spacing: 0.01em;
    overflow-x: hidden;
}

/* ===== Typography ===== */
.display-text {
    font-family: 'Dela Gothic One', cursive;
    color: #d4eaff;
    text-shadow: 0 0 40px #5ba3d9aa, 0 0 80px #3d7ab833;
    letter-spacing: -0.03em;
}

/* ===== Scenes ===== */
.scene {
    position: relative;
    width: 100%;
    overflow: hidden;
}

/* ===== Scene 1: The Membrane ===== */
#scene-membrane {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0a1628;
}

.membrane-hex {
    position: relative;
    width: 90vmin;
    height: calc(90vmin * 1.1547);
    max-width: 600px;
    max-height: 693px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hex-border-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.hex-border-path {
    fill: none;
    stroke: #5ba3d9;
    stroke-width: 2;
    stroke-dasharray: 1800;
    stroke-dashoffset: 1800;
    animation: traceHex 2s ease-out 0.3s forwards;
    filter: drop-shadow(0 0 8px #5ba3d980) drop-shadow(0 0 20px #5ba3d940);
}

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

.membrane-content {
    text-align: center;
    z-index: 1;
}

.membrane-title {
    font-family: 'Dela Gothic One', cursive;
    font-size: clamp(3rem, 8vw, 8rem);
    color: #d4eaff;
    text-shadow: 0 0 40px #5ba3d9aa, 0 0 80px #3d7ab833;
    letter-spacing: -0.03em;
    line-height: 1;
    animation: breathe 6s ease-in-out infinite;
}

@keyframes breathe {
    0%, 100% { transform: scale(1); text-shadow: 0 0 40px #5ba3d9aa, 0 0 80px #3d7ab833; }
    50% { transform: scale(1.02); text-shadow: 0 0 60px #5ba3d9cc, 0 0 100px #3d7ab855; }
}

.membrane-subtitle {
    font-family: 'Outfit', sans-serif;
    font-weight: 300;
    font-size: 0.8rem;
    color: #b8d4e8;
    opacity: 0.6;
    margin-top: 2rem;
    letter-spacing: 0.1em;
}

/* ===== Scene 2: The Hive ===== */
#scene-hive {
    min-height: 200vh;
    padding: 10vh 5vw;
    background: #0a1628;
}

.hex-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

.hex-cell {
    position: relative;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    aspect-ratio: 1 / 1.1547;
}

.hex-grid .hex-cell:nth-child(even) {
    transform: translateY(25%);
}

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

.hex-bg {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 35% 30%, #1a3358 0%, #122240 60%, #0d1a30 100%);
    box-shadow: inset 0 -20px 40px #0a162880, inset 0 10px 30px #5ba3d915;
    opacity: 0;
    transition: opacity 0.6s ease 0.4s;
}

.hex-trace {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.hex-trace polygon {
    fill: none;
    stroke: #5ba3d9;
    stroke-width: 2;
    stroke-dasharray: 1800;
    stroke-dashoffset: 1800;
    transition: none;
    filter: drop-shadow(0 0 6px #5ba3d960);
}

.hex-content {
    position: relative;
    z-index: 1;
    padding: 2rem;
    text-align: center;
    opacity: 0;
    transition: opacity 0.4s ease 0.8s;
}

/* Reveal states */
.hex-reveal.revealed .hex-bg {
    opacity: 1;
}

.hex-reveal.revealed .hex-trace polygon {
    animation: traceHex 1.2s ease-out forwards;
}

.hex-reveal.revealed .hex-content {
    opacity: 1;
}

/* Inflated cells */
.hex-inflated .hex-text-inflated {
    font-family: 'Dela Gothic One', cursive;
    font-size: clamp(1.2rem, 2vw, 2rem);
    color: #d4eaff;
    text-shadow: 0 0 30px #5ba3d988, 0 0 60px #3d7ab822;
    letter-spacing: -0.03em;
    line-height: 1.3;
}

/* Compressed cells */
.hex-compressed {
    opacity: 0.4;
    transition: opacity 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.hex-compressed:hover {
    opacity: 1;
    transform: scale(1.1) translateY(0) !important;
    z-index: 10;
}

.hex-text-compressed {
    font-family: 'Outfit', sans-serif;
    font-weight: 300;
    font-size: 0.65rem;
    color: #b8d4e8;
    line-height: 1.5;
}

.hex-label {
    display: block;
    font-family: 'Fragment Mono', monospace;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: #7eb8d4;
    margin-top: 0.5rem;
}

/* Counters */
.hex-counter {
    display: block;
    font-family: 'Fragment Mono', monospace;
    font-size: 2.5rem;
    color: #5ba3d9;
    text-shadow: 0 0 20px #5ba3d988;
    --counter-value: 0;
    counter-reset: num var(--counter-value);
}

.hex-counter.counting {
    transition: --counter-value 2s ease-out;
}

/* ===== Botanical SVGs ===== */
.botanical-svg {
    width: 80%;
    max-width: 180px;
    height: auto;
}

.botanical-line {
    stroke: #e8a0c4;
    stroke-width: 1.5;
    fill: none;
    filter: drop-shadow(0 0 4px #e8a0c480) drop-shadow(0 0 12px #e8a0c440) drop-shadow(0 0 24px #e8a0c420);
}

/* ===== Scene 3: The Mirror ===== */
#scene-mirror {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #0a1628;
    gap: 2rem;
}

.mirror-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    width: 90%;
    max-width: 900px;
}

.mirror-hex {
    flex: 1;
    max-width: 350px;
    aspect-ratio: 1 / 1.1547;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    position: relative;
}

.mirror-hex .hex-inner {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.mirror-hex .hex-bg {
    opacity: 1;
}

.mirror-hex .hex-content {
    opacity: 1;
    padding: 1rem;
}

.mirror-hex .hex-trace polygon {
    stroke-dashoffset: 0;
}

.mirror-inflated {
    opacity: 1;
}

.mirror-inflated .botanical-line {
    stroke: #e8a0c4;
    filter: drop-shadow(0 0 4px #e8a0c480) drop-shadow(0 0 12px #e8a0c440) drop-shadow(0 0 24px #e8a0c420);
}

.mirror-inflated .hex-trace polygon {
    stroke: #5ba3d9;
    filter: drop-shadow(0 0 8px #5ba3d980);
}

.mirror-compressed {
    opacity: 0.25;
    filter: saturate(0.2);
}

.mirror-compressed .hex-trace polygon {
    stroke: #2a4a6b;
    filter: none;
}

.mirror-divider {
    width: 1px;
    height: 300px;
    background: linear-gradient(to bottom, transparent, #5ba3d9, transparent);
    animation: shimmer 4s ease-in-out infinite;
    flex-shrink: 0;
    margin: 0 1rem;
}

@keyframes shimmer {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

.mirror-caption {
    font-family: 'Outfit', sans-serif;
    font-weight: 300;
    font-size: clamp(1rem, 2vw, 1.4rem);
    color: #b8d4e8;
    text-align: center;
    letter-spacing: 0.05em;
}

.botanical-mirror {
    width: 70%;
    max-width: 160px;
}

/* ===== Scene 4: The Dissolution ===== */
#scene-dissolution {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(to bottom, #0a1628, #000000);
    position: relative;
}

.dissolution-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    max-width: 600px;
    width: 80%;
    position: absolute;
}

.dissolution-cell {
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    aspect-ratio: 1 / 1.1547;
    transition: transform 0.1s linear, opacity 0.1s linear;
}

.dissolution-cell .hex-bg {
    opacity: 1;
}

.botanical-escape {
    width: 100%;
    height: 100%;
    overflow: visible;
}

.dissolution-final {
    position: relative;
    z-index: 2;
    text-align: center;
    opacity: 0;
    transition: opacity 1s ease;
}

.dissolution-final.visible {
    opacity: 1;
}

.dissolution-counter {
    display: block;
    font-family: 'Fragment Mono', monospace;
    font-size: clamp(4rem, 10vw, 8rem);
    color: #5ba3d9;
    text-shadow: 0 0 40px #5ba3d988, 0 0 80px #5ba3d944;
}

.dissolution-word {
    display: block;
    font-family: 'Fragment Mono', monospace;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: #7eb8d4;
    margin-top: 1rem;
}

/* ===== Hex Nav ===== */
#hex-nav {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100;
}

.nav-dot {
    width: 12px;
    height: 12px;
    background: #2a4a6b;
    border: 1px solid #5ba3d940;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0;
}

.nav-dot.active {
    width: 20px;
    height: 20px;
    background: #5ba3d9;
    box-shadow: 0 0 12px #5ba3d988;
}

/* ===== Mobile ===== */
@media (max-width: 768px) {
    .hex-grid {
        grid-template-columns: 1fr;
        gap: 10px;
        padding: 0 10%;
    }

    .hex-grid .hex-cell:nth-child(even) {
        transform: none;
    }

    .hex-compressed:hover {
        transform: scale(1.05) !important;
    }

    .mirror-container {
        flex-direction: column;
        gap: 1rem;
    }

    .mirror-divider {
        width: 200px;
        height: 1px;
        background: linear-gradient(to right, transparent, #5ba3d9, transparent);
    }

    .mirror-hex {
        max-width: 250px;
    }

    .dissolution-grid {
        gap: 20px;
    }
}
