/* ===========================================
   gabs.wiki - Algorithmic Codex Styles
   Palette: Neon Codex (Dark-Neon + Leather)
   =========================================== */

:root {
    /* Color Palette */
    --obsidian: #0A0A0F;
    --charred-leather: #1A1410;
    --burnished-dark: #2A2018;
    --parchment-light: #E8DFD0;
    --aged-ivory: #B8A890;
    --neon-cyan: #00F0FF;
    --neon-magenta: #FF0080;
    --electric-amber: #FFB800;
    --tarnished-brass: #8B7355;
    --spectral-teal: rgba(0, 240, 255, 0.2);
    --dark-tertiary: #3A2A1A;

    /* Typography */
    --font-display: 'Cormorant Garamond', serif;
    --font-body: 'Source Serif 4', serif;
    --font-mono: 'IBM Plex Mono', monospace;

    /* Sizes */
    --hex-size: 180px;
    --hex-gap: 8px;
    --hex-border-width: 1px;
}

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

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

body {
    background-color: var(--obsidian);
    color: var(--parchment-light);
    font-family: var(--font-body);
    font-weight: 400;
    line-height: 1.72;
    letter-spacing: 0.01em;
    overflow-x: hidden;
    position: relative;
    min-height: 100vh;
}

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

/* ---- Leather Background ---- */
#leather-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--charred-leather);
    filter: url(#leather-bg);
    opacity: 0;
    z-index: 0;
    pointer-events: none;
    transition: opacity 1.2s ease;
}

#leather-background.visible {
    opacity: 1;
}

/* ---- Hex Grid Canvas ---- */
#hex-grid-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

/* ---- Connection SVG ---- */
#connection-svg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
    overflow: visible;
}

/* ---- Rosettes Layer ---- */
.rosettes-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
    overflow: visible;
}

/* ---- Phase Sections ---- */
.phase {
    position: relative;
    z-index: 3;
}

/* ---- Phase 1: The Binding ---- */
#phase-binding {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 40px;
    padding: 60px 20px;
}

/* ---- Hex Cell (General) ---- */
.hex-cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hex-border {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.hex-outline {
    width: 100%;
    height: 100%;
    overflow: visible;
}

.hex-path {
    fill: none;
    stroke: var(--neon-cyan);
    stroke-width: 1.5;
    opacity: 0;
    filter: drop-shadow(0 0 8px var(--neon-cyan));
    transition: opacity 0.3s ease;
}

.hex-path.drawn {
    opacity: 0.8;
}

.hex-content {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
}

/* ---- Apex Cell (Title) ---- */
.apex {
    width: 320px;
    height: 370px;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.apex.visible {
    opacity: 1;
    transform: scale(1);
}

.apex .hex-path {
    stroke-width: 2;
}

.site-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2.8rem, 7vw, 5.5rem);
    letter-spacing: 0.08em;
    line-height: 1.12;
    color: var(--parchment-light);
    text-transform: uppercase;
    opacity: 0;
    transition: opacity 0.8s ease 0.3s;
}

.apex.visible .site-title {
    opacity: 1;
}

.site-subtitle {
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: 0.8rem;
    letter-spacing: 0.12em;
    color: var(--neon-cyan);
    text-transform: uppercase;
    margin-top: 12px;
    min-height: 1.2em;
}

/* ---- Navigation Ring ---- */
.nav-ring {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    max-width: 700px;
    opacity: 0;
    transition: opacity 0.6s ease;
}

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

.nav-cell {
    width: 140px;
    height: 162px;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.nav-cell:hover {
    transform: scale(1.08);
}

.nav-cell:hover .hex-path {
    opacity: 1;
    stroke: var(--electric-amber);
    filter: drop-shadow(0 0 12px var(--electric-amber));
}

.nav-hex-path {
    stroke-width: 1.2;
}

.nav-label {
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--parchment-light);
    letter-spacing: 0.03em;
}

/* ---- Phase 2: The Expansion ---- */
#phase-expansion {
    padding: 80px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 120px;
}

/* ---- Content Clusters ---- */
.content-cluster {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease, transform 0.6s ease;
    width: 100%;
    max-width: 900px;
}

.content-cluster.visible {
    opacity: 1;
    transform: translateY(0);
}

.cluster-header {
    display: flex;
    align-items: baseline;
    gap: 20px;
    margin-bottom: 30px;
    padding-left: 20px;
}

.cluster-number {
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: 1.2rem;
    color: var(--neon-cyan);
    letter-spacing: 0.12em;
    min-width: 3.5ch;
}

.cluster-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.8rem, 4vw, 3rem);
    letter-spacing: 0.05em;
    line-height: 1.12;
    color: var(--parchment-light);
    text-transform: uppercase;
    opacity: 0;
    transition: opacity 0.6s ease 0.4s;
}

.content-cluster.visible .cluster-title {
    opacity: 1;
}

/* ---- Hex Cluster Layout ---- */
.hex-cluster {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--hex-gap);
    align-items: flex-start;
}

.content-cell {
    position: relative;
}

.primary-cell {
    width: 320px;
    height: 370px;
}

.side-cell {
    width: 180px;
    height: 208px;
    align-self: center;
}

.content-hex {
    stroke-width: 1;
    stroke: var(--tarnished-brass);
    opacity: 0;
}

.content-cell.drawn .content-hex {
    opacity: 0.7;
}

.content-cell .hex-content {
    padding: 30px 24px;
}

.cell-text {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 1rem;
    line-height: 1.72;
    letter-spacing: 0.01em;
    color: var(--parchment-light);
    max-width: 58ch;
}

/* ---- Metadata Labels ---- */
.meta-label {
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: 0.8rem;
    letter-spacing: 0.12em;
    color: var(--aged-ivory);
    text-transform: uppercase;
    margin-bottom: 6px;
    display: block;
}

.counter-value {
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: 1.2rem;
    color: var(--neon-cyan);
    letter-spacing: 0.05em;
}

.meta-value {
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: 0.9rem;
    color: var(--neon-cyan);
    letter-spacing: 0.08em;
}

/* ---- Margin Cells ---- */
#margin-cells {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 4;
    pointer-events: none;
}

.margin-cell {
    position: absolute;
    width: 100px;
    height: 116px;
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: auto;
}

.margin-cell.visible {
    opacity: 0.6;
}

.margin-cell:hover {
    opacity: 1;
}

.margin-cell.left {
    left: 20px;
}

.margin-cell.right {
    right: 20px;
}

.margin-cell[data-position="1"] {
    top: 30%;
}

.margin-cell[data-position="2"] {
    top: 40%;
}

.margin-cell[data-position="3"] {
    top: 55%;
}

.margin-cell[data-position="4"] {
    top: 65%;
}

.margin-hex {
    stroke: var(--tarnished-brass);
    stroke-width: 0.8;
    opacity: 0.4;
}

.margin-cell .hex-content {
    padding: 10px;
}

.margin-cell .meta-label {
    font-size: 0.65rem;
    margin-bottom: 3px;
}

.margin-cell .counter-value,
.margin-cell .meta-value {
    font-size: 0.8rem;
}

/* ---- Phase 4: The Substrate ---- */
#phase-substrate {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding: 80px 20px 60px;
    position: relative;
}

#dense-grid-area {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* ---- Colophon Cell ---- */
.colophon-cell {
    width: 280px;
    height: 324px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.colophon-cell.visible {
    opacity: 1;
    transform: translateY(0);
}

.colophon-hex {
    stroke: var(--tarnished-brass);
    stroke-width: 1;
    opacity: 0;
}

.colophon-cell.visible .colophon-hex {
    opacity: 0.5;
}

.colophon-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.colophon-content .meta-label {
    font-size: 0.65rem;
    color: var(--aged-ivory);
    margin-bottom: 2px;
}

.colophon-content .counter-value {
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.colophon-text {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--aged-ivory);
    letter-spacing: 0.03em;
    margin-top: 8px;
    margin-bottom: 4px;
}

.spiral-ornament {
    width: 60px;
    height: 60px;
    margin: 4px 0;
}

.spiral-path {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
    transition: stroke-dashoffset 3s ease;
}

.colophon-cell.visible .spiral-path {
    stroke-dashoffset: 0;
}

/* ---- Flowing Curve Connections ---- */
.flow-connection {
    fill: none;
    stroke: var(--neon-magenta);
    stroke-width: 1.5;
    opacity: 0.3;
    stroke-dasharray: 8 4;
    animation: flowDash 4s linear infinite;
}

@keyframes flowDash {
    to {
        stroke-dashoffset: -48px;
    }
}

.connection-drawing {
    fill: none;
    stroke: var(--neon-magenta);
    stroke-width: 1.5;
    opacity: 0;
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    transition: stroke-dashoffset 2s ease, opacity 0.5s ease;
}

.connection-drawing.visible {
    opacity: 0.3;
    stroke-dashoffset: 0;
}

/* ---- Hex Cell Backgrounds (pseudo leather) ---- */
.apex .hex-content::before,
.primary-cell .hex-content::before,
.colophon-cell .hex-content::before {
    content: '';
    position: absolute;
    top: 10%;
    left: 10%;
    width: 80%;
    height: 80%;
    background-color: var(--charred-leather);
    border-radius: 4px;
    z-index: -1;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}

.side-cell .hex-content::before {
    content: '';
    position: absolute;
    top: 15%;
    left: 15%;
    width: 70%;
    height: 70%;
    background-color: var(--charred-leather);
    border-radius: 4px;
    z-index: -1;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* ---- Rosette Decorations ---- */
.rosette {
    opacity: 0.25;
}

/* ---- Animations ---- */
@keyframes hexEdgeDraw {
    from {
        stroke-dashoffset: 100%;
    }
    to {
        stroke-dashoffset: 0;
    }
}

/* Cell assembly animation */
.hex-cell.assembling .hex-path {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    opacity: 0.8;
}

.hex-cell.assembled .hex-path {
    stroke-dasharray: none;
    stroke-dashoffset: 0;
    opacity: 0.8;
    transition: opacity 0.3s ease;
}

/* Glow pulse for apex */
@keyframes glowPulse {
    0%, 100% {
        filter: drop-shadow(0 0 6px var(--neon-cyan));
    }
    50% {
        filter: drop-shadow(0 0 16px var(--neon-cyan));
    }
}

.apex.visible .hex-path.drawn {
    animation: glowPulse 3s ease-in-out infinite;
}

/* Will-change hints for animated elements */
.hex-cell {
    will-change: opacity, transform;
}

#hex-grid-canvas {
    will-change: transform;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .apex {
        width: 240px;
        height: 278px;
    }

    .nav-cell {
        width: 110px;
        height: 128px;
    }

    .nav-label {
        font-size: 0.85rem;
    }

    .primary-cell {
        width: 260px;
        height: 300px;
    }

    .side-cell {
        width: 140px;
        height: 162px;
    }

    .content-cell .hex-content {
        padding: 20px 16px;
    }

    .cell-text {
        font-size: 0.9rem;
    }

    .margin-cell {
        display: none;
    }

    .cluster-header {
        flex-direction: column;
        gap: 8px;
    }

    .colophon-cell {
        width: 220px;
        height: 255px;
    }
}

@media (max-width: 480px) {
    .nav-ring {
        gap: 8px;
    }

    .nav-cell {
        width: 90px;
        height: 104px;
    }

    .nav-label {
        font-size: 0.7rem;
    }

    .primary-cell {
        width: 220px;
        height: 254px;
    }

    .cell-text {
        font-size: 0.82rem;
        line-height: 1.6;
    }

    .side-cell {
        width: 120px;
        height: 139px;
    }
}
