/* =============================================
   BBATTL.com - Styles
   Bento-box grid / Grainy field manual aesthetic
   ============================================= */

/* --- Custom Properties --- */
:root {
    --chalk-ivory: #F5F0E8;
    --fog-lavender: #E8E0F0;
    --blush-peach: #F2DDD4;
    --sage-mist: #D8E8DC;
    --charcoal-slate: #2E2E38;
    --warm-graphite: #6B6570;
    --deep-plum: #5C3D6E;
    --dusty-rose: #C8929A;
    --ink-teal: #3A7D7E;
    --parchment-shadow: #D8D0C4;
    --sepia-dust: #B8A898;

    --font-primary: 'Space Grotesk', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'DM Mono', monospace;

    --gutter: 4px;
    --cell-radius: 6px;
    --base-unit: 8px;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background-color: var(--chalk-ivory);
    color: var(--charcoal-slate);
    font-family: var(--font-body);
    overflow-x: hidden;
}

/* --- Grain Canvas --- */
#grain-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 9999;
    mix-blend-mode: multiply;
    opacity: 0.05;
    image-rendering: pixelated;
}

/* --- Scroll Container --- */
#scroll-container {
    scroll-snap-type: y mandatory;
    overflow-y: auto;
    height: 100vh;
    scroll-behavior: smooth;
}

/* --- Bento Section --- */
.bento-section {
    scroll-snap-align: start;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(var(--base-unit) * 3);
    position: relative;
}

/* --- Section Dividers --- */
.section-divider {
    scroll-snap-align: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 48px;
    padding: 24px 0;
    background: var(--chalk-ivory);
}

.divider-glyph {
    width: 12px;
    height: 12px;
    opacity: 0;
    transition: opacity 0.6s ease;
}

.divider-glyph.visible {
    opacity: 1;
}

.divider-glyph .draw-path {
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    transition: stroke-dashoffset 1s cubic-bezier(0.65, 0, 0.35, 1);
}

.divider-glyph.visible .draw-path {
    stroke-dashoffset: 0;
}

/* --- Bento Grid (shared) --- */
.bento-grid {
    display: grid;
    gap: var(--gutter);
    width: 100%;
    max-width: 1200px;
    height: calc(100vh - calc(var(--base-unit) * 6));
    background: var(--parchment-shadow);
    border-radius: var(--cell-radius);
    padding: var(--gutter);
}

/* --- Bento Cell (shared) --- */
.bento-cell {
    border-radius: var(--cell-radius);
    padding: calc(var(--base-unit) * 3);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
    clip-path: polygon(0 0, 0 0, 0 100%, 0 100%);
    transition: clip-path 0.6s cubic-bezier(0.65, 0, 0.35, 1),
                box-shadow 0.3s ease;
}

.bento-cell.revealed {
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
}

.bento-cell:hover {
    box-shadow: inset 0 0 0 1px var(--dusty-rose);
}

/* --- Background variants --- */
.bg-ivory { background-color: var(--chalk-ivory); }
.bg-lavender { background-color: var(--fog-lavender); }
.bg-peach { background-color: var(--blush-peach); }
.bg-sage { background-color: var(--sage-mist); }

/* --- Pattern Backgrounds --- */
.pattern-hex {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='52'%3E%3Cpath d='M30 0 L60 15 L60 37 L30 52 L0 37 L0 15 Z' fill='none' stroke='%23D8D0C4' stroke-width='0.5'/%3E%3C/svg%3E");
    background-size: 60px 52px;
}

.pattern-circles {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Ccircle cx='20' cy='20' r='15' fill='none' stroke='%23D8D0C4' stroke-width='0.5'/%3E%3C/svg%3E");
    background-size: 40px 40px;
}

.pattern-iso {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48'%3E%3Cpath d='M24 4 L44 16 L44 32 L24 44 L4 32 L4 16 Z' fill='none' stroke='%23D8D0C4' stroke-width='0.5'/%3E%3Cpath d='M24 16 L34 22 L34 30 L24 36 L14 30 L14 22 Z' fill='none' stroke='%23D8D0C4' stroke-width='0.3'/%3E%3C/svg%3E");
    background-size: 48px 48px;
}

/* --- Typography --- */
.hero-title {
    font-family: var(--font-primary);
    font-weight: 700;
    font-size: clamp(48px, 8vw, 96px);
    letter-spacing: -0.02em;
    color: var(--charcoal-slate);
    margin-top: 24px;
    text-align: center;
}

.section-heading {
    font-family: var(--font-primary);
    font-weight: 700;
    font-size: clamp(32px, 4vw, 56px);
    letter-spacing: -0.02em;
    color: var(--charcoal-slate);
    text-align: center;
    line-height: 1.1;
}

.cell-body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(14px, 1.2vw, 18px);
    line-height: 1.65;
    color: var(--charcoal-slate);
    text-align: center;
    max-width: 380px;
}

.cell-caption {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 14px;
    line-height: 1.65;
    color: var(--warm-graphite);
    text-align: center;
    font-style: italic;
}

.mono-label {
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--warm-graphite);
    display: block;
    margin-bottom: 8px;
}

.display-number {
    font-family: var(--font-primary);
    font-weight: 700;
    font-size: clamp(40px, 5vw, 72px);
    letter-spacing: -0.02em;
    color: var(--deep-plum);
    line-height: 1;
    margin-bottom: 8px;
}

/* --- SVG Path Draw --- */
.svg-draw .draw-path {
    stroke-dasharray: var(--path-length, 1000);
    stroke-dashoffset: var(--path-length, 1000);
    transition: stroke-dashoffset 2.5s cubic-bezier(0.65, 0, 0.35, 1);
}

.svg-draw.animated .draw-path {
    stroke-dashoffset: 0;
}

/* --- Hero Grid --- */
.hero-grid {
    grid-template-columns: 2fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    grid-template-areas:
        "main side1"
        "main side2"
        "main side3";
}

.cell-hero-main {
    grid-area: main;
    gap: 8px;
}

.cell-hero-side-1 {
    grid-area: side1;
    gap: 8px;
}

.cell-hero-side-2 {
    grid-area: side2;
}

.cell-hero-side-3 {
    grid-area: side3;
    gap: 8px;
}

/* --- Manifesto Grid --- */
.manifesto-grid {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
        "title title visual"
        "body body visual"
        "accent stat note";
}

.cell-manifesto-title { grid-area: title; }
.cell-manifesto-body { grid-area: body; }
.cell-manifesto-visual { grid-area: visual; }
.cell-manifesto-accent { grid-area: accent; }
.cell-manifesto-stat { grid-area: stat; }
.cell-manifesto-note { grid-area: note; }

/* --- Systems Grid --- */
.systems-grid {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
        "header header diagram"
        "text1 text2 diagram"
        "pattern pattern meta";
}

.cell-systems-header { grid-area: header; }
.cell-systems-diagram { grid-area: diagram; }
.cell-systems-text-1 { grid-area: text1; }
.cell-systems-text-2 { grid-area: text2; }
.cell-systems-pattern { grid-area: pattern; }
.cell-systems-meta { grid-area: meta; }

/* --- Doctrine Grid --- */
.doctrine-grid {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto 1fr 1fr;
    grid-template-areas:
        "wide wide wide"
        "d1 d2 visual"
        "d3 aside visual";
}

.cell-doctrine-wide { grid-area: wide; }
.cell-doctrine-1 { grid-area: d1; }
.cell-doctrine-2 { grid-area: d2; }
.cell-doctrine-3 { grid-area: d3; }
.cell-doctrine-visual { grid-area: visual; }
.cell-doctrine-aside { grid-area: aside; }

/* --- Signal Grid --- */
.signal-grid {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
        "header header visual"
        "block1 block2 visual"
        "data note note";
}

.cell-signal-header { grid-area: header; }
.cell-signal-block-1 { grid-area: block1; }
.cell-signal-block-2 { grid-area: block2; }
.cell-signal-visual { grid-area: visual; }
.cell-signal-data { grid-area: data; }
.cell-signal-note { grid-area: note; }

/* --- Terminal Grid --- */
.terminal-grid {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    grid-template-areas: "full";
}

.cell-terminal-full {
    grid-area: full;
    gap: 24px;
}

.terminal-trace {
    width: 80%;
    max-width: 800px;
    height: auto;
}

.terminal-text {
    margin-top: 16px;
    max-width: 500px;
}

.terminal-sig {
    margin-top: 8px;
    opacity: 0.6;
}

/* --- Floating Diamond Navigation --- */
.nav-diamond {
    position: fixed;
    bottom: 32px;
    right: 32px;
    z-index: 10000;
}

.diamond-glyph {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.4s cubic-bezier(0.65, 0, 0.35, 1);
    background: var(--chalk-ivory);
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(46, 46, 56, 0.12);
}

.diamond-glyph:hover {
    transform: rotate(45deg);
}

.nav-diamond.open .diamond-glyph {
    transform: rotate(45deg);
}

.radial-menu {
    position: absolute;
    bottom: 56px;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.nav-diamond.open .radial-menu {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.radial-item {
    display: block;
    text-decoration: none;
    padding: 8px 16px;
    background: var(--chalk-ivory);
    border-radius: 4px;
    box-shadow: 0 1px 4px rgba(46, 46, 56, 0.1);
    transition: background 0.2s ease, transform 0.2s ease;
    white-space: nowrap;
}

.radial-item:hover {
    background: var(--fog-lavender);
    transform: translateX(-4px);
}

.radial-label {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--deep-plum);
}

/* --- Stagger Delay Utility (set via JS) --- */
.bento-cell[data-stagger="0"] { transition-delay: 0ms; }
.bento-cell[data-stagger="1"] { transition-delay: 80ms; }
.bento-cell[data-stagger="2"] { transition-delay: 160ms; }
.bento-cell[data-stagger="3"] { transition-delay: 240ms; }
.bento-cell[data-stagger="4"] { transition-delay: 320ms; }
.bento-cell[data-stagger="5"] { transition-delay: 400ms; }

/* --- Clip-path fallback --- */
@supports not (clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%)) {
    .bento-cell {
        clip-path: none;
        opacity: 0;
        transition: opacity 0.6s ease;
    }
    .bento-cell.revealed {
        opacity: 1;
    }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .hero-grid {
        grid-template-columns: 1fr;
        grid-template-rows: 2fr 1fr 1fr 1fr;
        grid-template-areas:
            "main"
            "side1"
            "side2"
            "side3";
    }

    .manifesto-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto 1fr auto;
        grid-template-areas:
            "title title"
            "visual visual"
            "body body"
            "accent stat";
    }

    .cell-manifesto-note { display: none; }

    .systems-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto 1fr auto auto;
        grid-template-areas:
            "header header"
            "diagram diagram"
            "text1 text2"
            "pattern meta";
    }

    .doctrine-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto auto auto;
        grid-template-areas:
            "wide wide"
            "d1 d2"
            "d3 visual"
            "aside aside";
    }

    .signal-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto 1fr auto;
        grid-template-areas:
            "header header"
            "visual visual"
            "block1 block2"
            "data note";
    }

    .bento-section {
        padding: calc(var(--base-unit) * 2);
    }

    .bento-grid {
        height: calc(100vh - calc(var(--base-unit) * 4));
    }

    .section-divider {
        gap: 24px;
    }

    .hero-title {
        font-size: clamp(36px, 10vw, 64px);
    }
}

@media (max-width: 480px) {
    .manifesto-grid,
    .systems-grid,
    .doctrine-grid,
    .signal-grid {
        grid-template-columns: 1fr;
    }

    .manifesto-grid {
        grid-template-areas:
            "title"
            "visual"
            "body"
            "accent";
    }

    .cell-manifesto-stat { display: none; }

    .systems-grid {
        grid-template-areas:
            "header"
            "diagram"
            "text1"
            "text2";
    }

    .cell-systems-pattern,
    .cell-systems-meta { display: none; }

    .doctrine-grid {
        grid-template-areas:
            "wide"
            "d1"
            "d2"
            "d3";
    }

    .cell-doctrine-visual,
    .cell-doctrine-aside { display: none; }

    .signal-grid {
        grid-template-areas:
            "header"
            "visual"
            "block1"
            "block2";
    }

    .cell-signal-data,
    .cell-signal-note { display: none; }
}
