/* ========================================
   RESET & FOUNDATION
   Design token trace: (Google Fonts `IntersectionObserver` `rootMargin: "100px"` pre-loads transitions thresholds
   ======================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: "IBM Plex Mono", monospace;
    background-color: #e8e4df;
    color: #2b2b2b;
    line-height: 1.7;
    letter-spacing: 0.02em;
    overflow-x: hidden;
    position: relative;
}

/* Grain overlay pseudo-element */
body::after {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url("data:image/svg+xml,%3Csvg width='200' height='200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' fill='%230a0a0a' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 200px 200px;
    opacity: calc(0.08 + var(--scroll-grain, 0));
    mix-blend-mode: multiply;
    pointer-events: none;
    z-index: 9999;
    will-change: opacity;
}

body.void-mode {
    background-color: #0a0a0a;
    color: #e8e4df;
}

body.void-mode .hexagon {
    background-color: #2b2b2b;
    border-color: #e8e4df;
    box-shadow: 4px 4px 0px #6b6b6b;
}

body.void-mode h1,
body.void-mode h2,
body.void-mode h3,
body.void-mode p,
body.void-mode .menu-label,
body.void-mode .marginalia {
    color: #e8e4df;
}

/* ========================================
   TYPOGRAPHY
   ======================================== */

h1, h2, h3 {
    margin-bottom: 1rem;
}

h1 {
    font-family: "Caveat", cursive;
    font-weight: 700;
    font-size: clamp(2.4rem, 6vw, 5.5rem);
    line-height: 1.15;
    letter-spacing: -0.01em;
    color: #0a0a0a;
    text-shadow: 1px 1px 0px rgba(10, 10, 10, 0.15);
    transform: rotate(var(--tilt, 0deg));
}

h2 {
    font-family: "Permanent Marker", cursive;
    font-weight: 400;
    font-size: clamp(1rem, 2.5vw, 1.6rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #3a3a3a;
}

h3 {
    font-family: "Permanent Marker", cursive;
    font-weight: 400;
    font-size: clamp(1rem, 2.5vw, 1.6rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #3a3a3a;
    text-decoration: none;
    transition: text-decoration 0.3s ease;
}

h3:hover {
    text-decoration: underline wavy #3a3a3a;
}

p {
    font-size: clamp(0.85rem, 1.2vw, 1rem);
    line-height: 1.7;
    letter-spacing: 0.02em;
    color: #2b2b2b;
    max-width: 56ch;
    margin-bottom: 0.8rem;
}

.metadata {
    font-family: "Space Mono", monospace;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #6b6b6b;
}

.marginalia {
    font-family: "Caveat", cursive;
    font-size: 0.7rem;
    color: #6b6b6b;
    display: block;
    margin: 8px 0;
    opacity: 0;
    transition: opacity 0.6s ease;
}

/* ========================================
   HONEYCOMB GRID LAYOUT
   ======================================== */

.honeycomb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 32px;
    padding: 60px 40px;
    perspective: 1000px;
    max-width: 1400px;
    margin: 0 auto;
}

/* Offset odd rows for honeycomb effect */
.honeycomb-grid > .hexagon:nth-child(odd) {
    transform: translateX(0);
}

.honeycomb-grid > .hexagon:nth-child(even) {
    transform: translateX(0);
}

/* ========================================
   HEXAGON CELLS
   ======================================== */

.hexagon {
    aspect-ratio: 1;
    position: relative;
    transform-origin: center;
    transform: rotate(var(--tilt, 0deg)) scale(1) translateY(0);
    opacity: 1;
    transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    will-change: transform;

    clip-path: polygon(
        calc(50% + var(--v1x, 0px)) calc(0% + var(--v1y, 0px)),
        calc(100% + var(--v2x, 0px)) calc(25% + var(--v2y, 0px)),
        calc(100% + var(--v3x, 0px)) calc(75% + var(--v3y, 0px)),
        calc(50% + var(--v4x, 0px)) calc(100% + var(--v4y, 0px)),
        calc(0% + var(--v5x, 0px)) calc(75% + var(--v5y, 0px)),
        calc(0% + var(--v6x, 0px)) calc(25% + var(--v6y, 0px))
    );
}

.hexagon {
    border: 2px solid #2b2b2b;
    background-color: #f5f2ed;
    box-shadow: 4px 4px 0px #0a0a0a;
    z-index: 1;
}

/* Layered depth effect */
.hexagon.layer-bg {
    opacity: 0.4;
    transform: rotate(var(--tilt, 0deg)) scale(0.85);
    z-index: 1;
}

.hexagon.layer-mid {
    opacity: 1;
    transform: rotate(var(--tilt, 0deg)) scale(1);
    z-index: 2;
}

.hexagon.layer-fg {
    opacity: 1;
    transform: rotate(var(--tilt, 0deg)) scale(1.1);
    z-index: 3;
    border: 4px solid #0a0a0a;
    box-shadow: 6px 6px 0px #0a0a0a;
}

/* Hover state */
.hexagon:not(.skeleton-cell):not(.blot-cell):hover {
    transform: rotate(var(--tilt, 0deg)) scale(1.03);
    box-shadow: 8px 8px 0px #0a0a0a;
    cursor: pointer;
}

.hexagon.marked {
    box-shadow: -6px 7px 0px #3a3a3a, 6px 6px 0px #0a0a0a;
    filter: contrast(1.18);
}

/* Skeleton cell styling */
.hexagon.skeleton-cell {
    opacity: 0.5;
    filter: blur(0.5px);
    z-index: 1;
}

.skeleton-block {
    height: 16px;
    margin-bottom: 12px;
    border-radius: 2px;
    background: linear-gradient(90deg, #9e9e9e 25%, #c8c4bf 50%, #9e9e9e 75%);
    background-size: 200% 100%;
    animation: shimmer 2.5s infinite ease-in-out;
}

.skeleton-block.short {
    width: 70%;
}

@keyframes shimmer {
    0%, 100% {
        background-position: 200% 0;
    }
    50% {
        background-position: -200% 0;
    }
}

/* Blot cell styling */
.hexagon.blot-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f5f2ed;
}

.ink-blot {
    display: block;
}

/* Annotation cell */
.hexagon.annotation-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background-color: #f5f2ed;
}

/* ========================================
   HEXAGON CONTENT
   ======================================== */

.hex-content {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    width: 100%;
    height: 100%;
    padding: 24px;
    position: relative;
    overflow: visible;
}

/* Opening headings - large and centered */
.opening-heading,
.opening-subheading {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    text-align: center;
}

.opening-heading {
    font-size: 8vw;
    font-family: "Caveat", cursive;
    font-weight: 700;
    color: #0a0a0a;
    text-shadow: 2px 2px 0px rgba(10, 10, 10, 0.1);
    transform: rotate(-2deg);
}

.opening-subheading {
    font-size: 4vw;
    font-family: "Permanent Marker", cursive;
    text-transform: uppercase;
    color: #3a3a3a;
    letter-spacing: 0.08em;
    transform: rotate(1deg);
}

.section-label {
    margin-bottom: 12px;
    font-size: 1rem;
}

/* ========================================
   SCROLL ANIMATIONS
   ======================================== */

/* Initial load animation */
@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: translateY(40px) scale(0.92);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.hexagon.in-view {
    animation: fadeInScale 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Staggered animation per grid position */
.hex-1 { animation-delay: 0.6s; }
.hex-2 { animation-delay: 0.9s; }
.hex-3 { animation-delay: 0.24s; }
.hex-4 { animation-delay: 0.32s; }
.hex-5 { animation-delay: 0.4s; }
.hex-6 { animation-delay: 0.48s; }
.hex-7 { animation-delay: 0.56s; }
.hex-8 { animation-delay: 0.64s; }
.hex-9 { animation-delay: 0.72s; }
.hex-10 { animation-delay: 0.8s; }
.hex-11 { animation-delay: 0.88s; }
.hex-12 { animation-delay: 0.96s; }
.hex-13 { animation-delay: 1.04s; }
.hex-14 { animation-delay: 1.12s; }
.hex-15 { animation-delay: 1.2s; }
.hex-16 { animation-delay: 1.28s; }
.hex-17 { animation-delay: 1.36s; }
.hex-18 { animation-delay: 1.44s; }
.hex-19 { animation-delay: 1.52s; }
.hex-20 { animation-delay: 1.6s; }

/* ========================================
   COMPASS NAVIGATION
   ======================================== */

.compass-nav {
    position: fixed;
    bottom: 40px;
    right: 40px;
    z-index: 10000;
}

.compass-center {
    width: 48px;
    height: 48px;
    background-color: #e8e4df;
    border: 2px solid #0a0a0a;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 2px 2px 0px #0a0a0a;
    animation: compass-drift 20s infinite alternate ease-in-out;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}

.compass-center:hover {
    transform: scale(1.1);
    box-shadow: 4px 4px 0px #0a0a0a;
}

.compass-center svg {
    width: 24px;
    height: 24px;
    stroke: #0a0a0a;
}

@keyframes compass-drift {
    0% {
        transform: rotate(-3deg);
    }
    100% {
        transform: rotate(3deg);
    }
}

/* Menu (hidden by default) */
.compass-menu {
    position: absolute;
    bottom: 48px;
    right: 0;
    width: 240px;
    height: 240px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s ease;
}

.compass-menu.active {
    opacity: 1;
    visibility: visible;
}

.menu-item {
    position: absolute;
    width: 40px;
    height: 40px;
    bottom: 100px;
    right: 4px;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    background-color: #f5f2ed;
    border: 2px solid #0a0a0a;
    box-shadow: 2px 2px 0px #0a0a0a;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: rotate(var(--angle, 0deg)) translateX(80px) rotate(calc(-1 * var(--angle, 0deg)));
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.compass-menu.active .menu-item {
    opacity: 1;
}

.menu-label {
    font-family: "Caveat", cursive;
    font-size: 0.7rem;
    color: #0a0a0a;
    text-align: center;
    white-space: nowrap;
    transform: rotate(var(--label-rotate, 0deg));
}

.menu-item:nth-child(1) .menu-label { --label-rotate: 0deg; }
.menu-item:nth-child(2) .menu-label { --label-rotate: 60deg; }
.menu-item:nth-child(3) .menu-label { --label-rotate: 120deg; }
.menu-item:nth-child(4) .menu-label { --label-rotate: 180deg; }
.menu-item:nth-child(5) .menu-label { --label-rotate: 240deg; }
.menu-item:nth-child(6) .menu-label { --label-rotate: 300deg; }

.menu-item:hover {
    transform: rotate(var(--angle, 0deg)) translateX(80px) rotate(calc(-1 * var(--angle, 0deg))) scale(1.1);
    box-shadow: 4px 4px 0px #0a0a0a;
    cursor: pointer;
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
    .honeycomb-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 24px;
        padding: 40px 20px;
    }

    .hex-content {
        padding: 16px;
    }

    .compass-nav {
        bottom: 20px;
        right: 20px;
    }

    .menu-item {
        width: 32px;
        height: 32px;
        transform: rotate(var(--angle, 0deg)) translateX(60px) rotate(calc(-1 * var(--angle, 0deg)));
    }

    .menu-label {
        font-size: 0.6rem;
    }
}

@media (max-width: 480px) {
    .honeycomb-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 16px;
        padding: 20px 12px;
    }

    .hex-content {
        padding: 12px;
    }

    h1 {
        font-size: clamp(1.8rem, 5vw, 3rem);
    }

    h2 {
        font-size: clamp(0.8rem, 2vw, 1.2rem);
    }

    p {
        font-size: clamp(0.75rem, 1vw, 0.9rem);
    }

    .compass-nav {
        bottom: 16px;
        right: 16px;
    }

    .compass-center {
        width: 40px;
        height: 40px;
    }

    .compass-center svg {
        width: 20px;
        height: 20px;
    }

    .menu-item {
        width: 28px;
        height: 28px;
        transform: rotate(var(--angle, 0deg)) translateX(50px) rotate(calc(-1 * var(--angle, 0deg)));
    }
}

/* ========================================
   UTILITY
   ======================================== */

.hidden {
    visibility: hidden;
}

/* SVG inline styles */
svg {
    display: block;
}

/* Margin annotations fade-in */
.marginalia {
    transition: opacity 0.6s ease;
}

.annotation-cell.in-view .marginalia {
    opacity: 1;
}
