/* ============================================================
   bada.city — Anti-Design Hexagonal City
   Palette: Honeyed-Neutral (no cool tones)
   Typography: Sans-Grotesk System
   ============================================================ */

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

:root {
    --bg-primary: #F5E6C8;
    --bg-secondary: #D4A855;
    --bg-tertiary: #8B6F47;
    --text-primary: #2B2520;
    --text-secondary: #5C3D2E;
    --accent-hot: #C75B2A;
    --accent-muted: #A68A64;
    --void: #EDE0CC;
    --hex-size: 180px;
    --hex-clip: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Instrument Sans', sans-serif;
    font-weight: 400;
    font-size: 16px;
    line-height: 1.65;
    overflow-x: hidden;
    position: relative;
}

/* --- Grid Overlays (3-scale system) --- */
.grid-overlay {
    pointer-events: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.grid-overlay.macro {
    position: fixed;
    z-index: 0;
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 299px,
            #D4A855 299px,
            #D4A855 300px
        ),
        repeating-linear-gradient(
            60deg,
            transparent,
            transparent 399px,
            #D4A855 399px,
            #D4A855 400px
        ),
        repeating-linear-gradient(
            120deg,
            transparent,
            transparent 349px,
            #D4A855 349px,
            #D4A855 350px
        );
    opacity: 0.15;
}

.grid-overlay.meso {
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 179px,
            #A68A64 179px,
            #A68A64 180px
        ),
        repeating-linear-gradient(
            60deg,
            transparent,
            transparent 179px,
            #A68A64 179px,
            #A68A64 180px
        ),
        repeating-linear-gradient(
            -60deg,
            transparent,
            transparent 179px,
            #A68A64 179px,
            #A68A64 180px
        );
    opacity: 0.08;
    z-index: 1;
}

/* --- Typography --- */
.display-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 800;
    font-size: clamp(60px, 12vw, 140px);
    letter-spacing: -0.08em;
    color: var(--text-primary);
    line-height: 0.9;
    position: relative;
    z-index: 5;
    mix-blend-mode: difference;
}

.secondary-heading {
    font-family: 'Albert Sans', sans-serif;
    font-weight: 500;
    font-size: clamp(20px, 3vw, 36px);
    letter-spacing: 0.15em;
    color: var(--text-secondary);
    text-transform: uppercase;
    line-height: 1.2;
}

.body-text {
    font-family: 'Instrument Sans', sans-serif;
    font-weight: 400;
    font-size: 15px;
    line-height: 1.65;
    color: #3D3028;
    max-width: 380px;
}

.mono-fragment {
    font-family: 'Space Mono', monospace;
    font-weight: 400;
    font-size: 11px;
    color: var(--accent-muted);
    letter-spacing: 0.05em;
    display: block;
    line-height: 1.8;
}

.display-number {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 800;
    font-size: clamp(48px, 8vw, 100px);
    color: var(--accent-hot);
    letter-spacing: -0.06em;
    line-height: 1;
}

/* --- Hex Nav Cluster --- */
.hex-nav-cluster {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: grid;
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: repeat(2, 44px);
    gap: 4px;
    backdrop-filter: blur(2px);
    animation: navPulse 4s ease-in-out infinite;
}

@keyframes navPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

.hex-nav-cell {
    width: 48px;
    height: 44px;
    clip-path: var(--hex-clip);
    background: var(--bg-tertiary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.4s cubic-bezier(0.23, 1, 0.32, 1), background-color 0.3s;
    position: relative;
    overflow: hidden;
}

.hex-nav-cell:hover {
    transform: rotate(60deg);
    background: var(--accent-hot);
}

.hex-nav-text {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 800;
    font-size: 11px;
    color: var(--bg-primary);
    letter-spacing: 0.02em;
    line-height: 1;
    transition: opacity 0.3s;
}

.hex-nav-sub {
    font-family: 'Space Mono', monospace;
    font-size: 7px;
    color: var(--accent-muted);
    position: absolute;
    bottom: 6px;
    opacity: 0;
    transition: opacity 0.3s;
}

.hex-nav-cell:hover .hex-nav-text {
    opacity: 0;
}

.hex-nav-cell:hover .hex-nav-sub {
    opacity: 1;
    color: var(--bg-primary);
}

/* --- Districts (Sections) --- */
.district {
    position: relative;
    padding: 80px 40px;
    min-height: 100vh;
    overflow: hidden;
}

.district-label {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 10;
}

/* --- Dense Pack Zone --- */
.dense-pack {
    background: var(--bg-primary);
}

.dense-pack .display-title {
    margin-bottom: 40px;
    padding-left: 5%;
}

/* --- Hex Grid (Dense Pack) --- */
.hex-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 4px;
    position: relative;
    z-index: 3;
    padding: 20px;
}

.hex-cell {
    width: 100%;
    aspect-ratio: 1 / 1.15;
    clip-path: var(--hex-clip);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
    transform: rotate(var(--chaos, 0deg));
    transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

.hex-cell:nth-child(even) {
    transform: translateY(50%) rotate(var(--chaos, 0deg));
}

.content-cell {
    background: var(--bg-primary);
    border: 1px solid var(--accent-muted);
}

.content-cell .body-text {
    text-align: left;
    padding: 0 4px;
}

.reading-cell {
    background: var(--void);
    border: 2px solid var(--accent-muted);
    box-shadow: inset 0 0 0 4px var(--bg-primary);
}

.reading-cell .secondary-heading {
    margin-bottom: 8px;
}

.decorative-cell {
    background: var(--bg-secondary);
    opacity: 0.85;
}

.accent-cell {
    background: var(--accent-hot);
    display: flex;
    align-items: center;
    justify-content: center;
}

.accent-cell .display-number {
    color: var(--bg-primary);
}

/* --- Hex Fragment Fields (SVG decoration inside cells) --- */
.hex-fragment-field {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

.hex-fragment-field::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(0deg, transparent 48%, #A68A64 48%, #A68A64 49%, transparent 49%),
        linear-gradient(60deg, transparent 48%, #A68A64 48%, #A68A64 49%, transparent 49%),
        linear-gradient(120deg, transparent 48%, #A68A64 48%, #A68A64 49%, transparent 49%);
    background-size: 30px 30px;
    opacity: 0.5;
}

.hex-fragment-field.large::before {
    background-size: 50px 50px;
    opacity: 0.7;
}

.hex-fragment-field.fading::before {
    opacity: 0.2;
}

/* --- Disruption Markers --- */
.disruption-marker {
    width: 100%;
    height: 100%;
    position: relative;
}

.disruption-marker::before {
    content: '';
    position: absolute;
    top: 10%;
    left: 10%;
    width: 120%;
    height: 6px;
    background: var(--text-primary);
    transform: rotate(-35deg);
    transform-origin: left center;
}

.disruption-marker::after {
    content: '';
    position: absolute;
    bottom: 20%;
    right: 0;
    width: 80%;
    height: 4px;
    background: var(--text-primary);
    transform: rotate(20deg);
    transform-origin: right center;
}

.disruption-marker.large::before {
    height: 8px;
}

.disruption-marker.large::after {
    height: 6px;
}

/* --- Shatter Field Zone --- */
.shatter-field {
    background: var(--void);
    min-height: 100vh;
    position: relative;
}

.shatter-field .display-title {
    text-align: center;
    margin-bottom: 60px;
}

.hex-scatter {
    position: relative;
    width: 100%;
    min-height: 600px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 20px;
    z-index: 3;
}

.scatter-cell {
    width: clamp(120px, 20vw, 200px);
    flex-shrink: 0;
}

.scatter-cell.scattered {
    transform:
        translate(var(--scatter-x, 0), var(--scatter-y, 0))
        rotate(var(--scatter-rot, 0deg))
        scale(var(--scatter-scale, 1));
}

/* --- Void Corridors --- */
.void-corridor {
    background: var(--void);
    height: 0;
    overflow: hidden;
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: height 0.5s cubic-bezier(0.23, 1, 0.32, 1);
}

.void-corridor.expanded {
    height: 200px;
}

.void-wide.expanded {
    height: 300px;
}

.void-terminal.expanded {
    height: 400px;
}

.void-diagonal {
    transform: skewY(-2deg);
}

.void-label {
    opacity: 0;
    transition: opacity 0.8s 0.3s;
    text-align: center;
    white-space: nowrap;
}

.void-corridor.expanded .void-label {
    opacity: 1;
}

/* --- Grid Draw SVG --- */
.grid-draw-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
}

.grid-draw-line {
    stroke: var(--bg-secondary);
    stroke-width: 0.5;
    fill: none;
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    transition: stroke-dashoffset 1.2s ease-out;
}

.grid-draw-line.drawn {
    stroke-dashoffset: 0;
}

.grid-node {
    fill: var(--accent-hot);
    opacity: 0;
    transition: opacity 0.6s 0.8s;
}

.grid-node.visible {
    opacity: 1;
}

/* --- Type Crash Animation Setup --- */
.type-crash .char {
    display: inline-block;
    opacity: 0;
    transform: translateY(-30px);
    transition: opacity 0.4s, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.type-crash.animated .char {
    opacity: 1;
    transform: translateY(0);
}

/* --- Hex Assembly Animation Setup --- */
.hex-assembly .hex-cell {
    opacity: 0;
    transform: scale(0) rotate(calc(var(--chaos, 0deg) - 30deg));
}

.hex-assembly.animated .hex-cell {
    opacity: 1;
    transform: translateY(0) rotate(var(--chaos, 0deg));
    transition: opacity 0.6s cubic-bezier(0.23, 1, 0.32, 1),
                transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

.hex-assembly.animated .hex-cell:nth-child(even) {
    transform: translateY(50%) rotate(var(--chaos, 0deg));
}

/* --- Shatter Scatter Animation --- */
.hex-scatter .scatter-cell {
    transition: transform 0.8s cubic-bezier(0.68, -0.55, 0.27, 1.55);
}

/* --- Moire Interference (via overlapping grids) --- */
.dense-pack::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        repeating-linear-gradient(
            30deg,
            transparent,
            transparent 59px,
            #A68A64 59px,
            #A68A64 60px
        ),
        repeating-linear-gradient(
            -30deg,
            transparent,
            transparent 67px,
            #A68A64 67px,
            #A68A64 68px
        );
    opacity: 0.04;
    pointer-events: none;
    z-index: 0;
}

.shatter-field::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        repeating-linear-gradient(
            45deg,
            transparent,
            transparent 79px,
            #D4A855 79px,
            #D4A855 80px
        ),
        repeating-linear-gradient(
            -15deg,
            transparent,
            transparent 93px,
            #D4A855 93px,
            #D4A855 94px
        );
    opacity: 0.06;
    pointer-events: none;
    z-index: 0;
}

/* --- Micro Grid (inside cells) --- */
.reading-cell::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 19px,
            #EDE0CC 19px,
            #EDE0CC 20px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 19px,
            #EDE0CC 19px,
            #EDE0CC 20px
        );
    opacity: 0.5;
    pointer-events: none;
    z-index: 0;
}

/* --- Responsive / Mobile --- */
@media (max-width: 768px) {
    :root {
        --hex-size: 100%;
    }

    .district {
        padding: 60px 16px;
    }

    .hex-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .hex-cell {
        clip-path: polygon(5% 0%, 95% 0%, 100% 50%, 95% 100%, 5% 100%, 0% 50%);
        aspect-ratio: auto;
        min-height: 120px;
        padding: 16px;
    }

    .hex-cell:nth-child(even) {
        transform: rotate(var(--chaos, 0deg));
    }

    .hex-assembly.animated .hex-cell:nth-child(even) {
        transform: rotate(var(--chaos, 0deg));
    }

    .display-title {
        font-size: clamp(40px, 14vw, 80px);
    }

    .hex-scatter {
        flex-direction: column;
        min-height: auto;
        gap: 12px;
    }

    .scatter-cell {
        width: 90%;
    }

    .scatter-cell.scattered {
        transform: rotate(calc(var(--scatter-rot, 0deg) * 0.3)) scale(1);
    }

    .hex-nav-cluster {
        top: 10px;
        right: 10px;
        grid-template-columns: repeat(3, 36px);
        grid-template-rows: repeat(2, 33px);
    }

    .hex-nav-cell {
        width: 36px;
        height: 33px;
    }

    .hex-nav-text {
        font-size: 8px;
    }

    .void-corridor.expanded {
        height: 120px;
    }

    .void-wide.expanded {
        height: 180px;
    }

    .void-terminal.expanded {
        height: 250px;
    }

    .grid-overlay.meso {
        display: none;
    }

    .body-text {
        max-width: 100%;
    }
}

@media (max-width: 480px) {
    .display-title {
        font-size: clamp(32px, 16vw, 60px);
    }

    .district {
        padding: 40px 12px;
    }
}

/* --- Selection Color --- */
::selection {
    background: var(--accent-hot);
    color: var(--bg-primary);
}
