/* =========================================================================
   nanohana.stream — a standing transmission
   honeyed-neutral palette / diagonal-sections / expressive-variable / glitch
   ========================================================================= */

:root {
    --linen-honey: #f6ecd6;
    --combed-beeswax: #e8d4a4;
    --raw-amber: #c9a35a;
    --roasted-oat: #7a5a2e;
    --charred-birch: #2d2418;
    --paper-dust: #fffaee;
    --dried-marigold: #a78b54;
    --slab-margin: 120px;
    --slab-tilt: 10deg;
}

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

html {
    scroll-behavior: auto;
    background: var(--linen-honey);
}

body {
    font-family: "Fraunces", Georgia, serif;
    font-variation-settings: "SOFT" 60, "opsz" 14, "wght" 380;
    font-size: 1.0625rem;
    line-height: 1.85;
    letter-spacing: 0.005em;
    color: var(--roasted-oat);
    background: var(--linen-honey);
    overflow-x: hidden;
    min-height: 100vh;
    position: relative;
}

/* booting state — page fades in over 1800ms, scanline pulses down */
body.booting {
    opacity: 0.04;
}
body.booted {
    opacity: 1;
    transition: opacity 1800ms cubic-bezier(.2, .7, .1, 1);
}

/* =========================================================================
   Scanline overlay — breathing 0.03 -> 0.06 over 6s
   ========================================================================= */
.scanlines {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 90;
    background-image: repeating-linear-gradient(
        0deg,
        transparent 0px,
        transparent 3px,
        var(--charred-birch) 3px,
        var(--charred-birch) 4px
    );
    opacity: 0.04;
    animation: scanline-breathe 6s ease-in-out infinite;
    mix-blend-mode: multiply;
}

body.booting .scanlines {
    opacity: 0.22;
    animation: none;
}

@keyframes scanline-breathe {
    0%, 100% { opacity: 0.03; }
    50% { opacity: 0.06; }
}

/* =========================================================================
   Petal drift overlay — 12 nanohana petals crossing viewport
   ========================================================================= */
.petal-field {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 4;
    overflow: visible;
}

.petal {
    transform-origin: 0 0;
    will-change: transform, opacity;
    opacity: 0.6;
}

/* Each petal gets its own drift duration, delay, and y-baseline */
.petal.p1  { animation: petal-drift 52s linear -3s  infinite, petal-bob 11s ease-in-out infinite; }
.petal.p2  { animation: petal-drift 64s linear -10s infinite, petal-bob 13s ease-in-out infinite; }
.petal.p3  { animation: petal-drift 41s linear -20s infinite, petal-bob 9s  ease-in-out infinite; }
.petal.p4  { animation: petal-drift 58s linear -25s infinite, petal-bob 12s ease-in-out infinite; }
.petal.p5  { animation: petal-drift 72s linear -8s  infinite, petal-bob 15s ease-in-out infinite; }
.petal.p6  { animation: petal-drift 46s linear -32s infinite, petal-bob 10s ease-in-out infinite; }
.petal.p7  { animation: petal-drift 54s linear -18s infinite, petal-bob 14s ease-in-out infinite; }
.petal.p8  { animation: petal-drift 68s linear -5s  infinite, petal-bob 11s ease-in-out infinite; }
.petal.p9  { animation: petal-drift 38s linear -28s infinite, petal-bob 8s  ease-in-out infinite; }
.petal.p10 { animation: petal-drift 60s linear -14s infinite, petal-bob 12s ease-in-out infinite; }
.petal.p11 { animation: petal-drift 70s linear -22s infinite, petal-bob 16s ease-in-out infinite; }
.petal.p12 { animation: petal-drift 49s linear -38s infinite, petal-bob 10s ease-in-out infinite; }

.petal.p1  { --y: 80;  }
.petal.p2  { --y: 160; }
.petal.p3  { --y: 240; }
.petal.p4  { --y: 320; }
.petal.p5  { --y: 400; }
.petal.p6  { --y: 480; }
.petal.p7  { --y: 560; }
.petal.p8  { --y: 640; }
.petal.p9  { --y: 720; }
.petal.p10 { --y: 120; }
.petal.p11 { --y: 360; }
.petal.p12 { --y: 600; }

@keyframes petal-drift {
    0%   { transform: translate(-80px, calc(var(--y, 200) * 1px)) rotate(0deg); }
    100% { transform: translate(1320px, calc(var(--y, 200) * 1px)) rotate(720deg); }
}

@keyframes petal-bob {
    0%, 100% { translate: 0 -8px; }
    50%      { translate: 0 8px; }
}

/* =========================================================================
   Frequency dial — fixed top-right, ticks softly forever
   ========================================================================= */
.freq-dial {
    position: fixed;
    top: 20px;
    right: 22px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    font-family: "JetBrains Mono", "Consolas", monospace;
    font-size: 0.6rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--dried-marigold);
    padding: 6px 8px;
    background: rgba(255, 250, 238, 0.5);
    border: 0.5px solid var(--raw-amber);
    border-radius: 1px;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.dial-label {
    font-size: 0.55rem;
    opacity: 0.7;
}

.dial-readout {
    font-size: 0.78rem;
    color: var(--roasted-oat);
    font-variation-settings: "wght" 400;
}

.dial-tick {
    display: inline-block;
    width: 6px;
    height: 1px;
    background: var(--raw-amber);
    margin-top: 2px;
    animation: dial-tick 2s steps(20, end) infinite;
    transform-origin: left center;
}

@keyframes dial-tick {
    0%   { transform: scaleX(0.2); opacity: 0.4; }
    20%  { transform: scaleX(0.6); opacity: 0.8; }
    50%  { transform: scaleX(1.0); opacity: 1.0; }
    80%  { transform: scaleX(0.5); opacity: 0.7; }
    100% { transform: scaleX(0.2); opacity: 0.4; }
}

/* =========================================================================
   Diagonal slabs — clip-path parallelograms, alternating tilt
   ========================================================================= */
.slab {
    position: relative;
    min-height: 100vh;
    padding: 14vh 8vw;
    margin-top: calc(var(--slab-margin) * -0.6);
    background: var(--field, var(--linen-honey));
    z-index: 1;
    isolation: isolate;
}

/* The first slab has no negative margin */
.slab--hero {
    margin-top: 0;
    padding-top: 18vh;
}

/* Alternating clip-path polygons — slab--alt tilts the leading edge up on the right,
   slab--bl tilts the leading edge up on the left */
.slab--alt {
    clip-path: polygon(0 8%, 100% 0%, 100% 92%, 0 100%);
}
.slab--bl {
    clip-path: polygon(0 0%, 100% 8%, 100% 100%, 0 92%);
}

/* Hero is a flat full-bleed but with a soft trailing diagonal */
.slab--hero {
    clip-path: polygon(0 0, 100% 0, 100% 96%, 0 100%);
}

/* Coda fades up at its bottom — a softer trailing edge */
.slab--coda {
    clip-path: polygon(0 0%, 100% 8%, 100% 100%, 0 100%);
    padding-bottom: 22vh;
}

/* Fold shadows — inner thin amber line on the high edge, outer fade on the low edge */
.slab::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
}

.slab--alt::before {
    background:
        linear-gradient(180deg, rgba(201, 163, 90, 0.4) 0%, rgba(201, 163, 90, 0) 4%),
        linear-gradient(0deg, rgba(45, 36, 24, 0.06) 0%, rgba(45, 36, 24, 0) 6%);
}
.slab--bl::before {
    background:
        linear-gradient(0deg, rgba(201, 163, 90, 0.4) 0%, rgba(201, 163, 90, 0) 4%),
        linear-gradient(180deg, rgba(45, 36, 24, 0.06) 0%, rgba(45, 36, 24, 0) 6%);
}

/* Inner wrapper — the container that holds the counter-rotated content */
.slab-inner {
    position: relative;
    max-width: 1340px;
    margin: 0 auto;
    min-height: 72vh;
    z-index: 3;
}

/* Counter rotation — the slab's clip is tilted but the visible polygon is straight;
   we tilt content slightly to reinforce the "letter sliding off a desk" feeling
   while keeping text horizontal-enough to read. The slab's clip-path already creates
   the parallelogram silhouette — counter-rotate gives the slight type tilt. */
.counter-rotate {
    position: relative;
    padding: 4vh 0;
}
.counter-rotate--neg {
    transform: rotate(-1.2deg);
    transform-origin: 12% 50%;
}
.counter-rotate--pos {
    transform: rotate(1.2deg);
    transform-origin: 88% 50%;
}

/* =========================================================================
   Hero / wordmark
   ========================================================================= */
.slab--hero .slab-inner {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    padding-top: 6vh;
}

.prelude {
    font-family: "JetBrains Mono", monospace;
    font-weight: 300;
    font-size: 0.72rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--dried-marigold);
    margin-bottom: 2.6vh;
}

.wordmark {
    font-family: "Recursive", "Inter", sans-serif;
    font-variation-settings: "MONO" 0, "CASL" 1, "wght" 480, "slnt" -3;
    font-size: clamp(2.6rem, 11vw, 9.2rem);
    line-height: 0.92;
    color: var(--roasted-oat);
    letter-spacing: -0.04em;
    max-width: 88vw;
    margin-bottom: 4vh;
    text-transform: lowercase;
    word-break: keep-all;
}

.subwordmark {
    font-family: "Fraunces", serif;
    font-variation-settings: "SOFT" 80, "opsz" 14, "wght" 380;
    font-style: italic;
    font-size: clamp(1rem, 1.4vw, 1.18rem);
    color: var(--dried-marigold);
    max-width: 48ch;
    line-height: 1.6;
}

.seal--hero {
    position: absolute !important;
    top: 6vh;
    right: 4vw;
}

.anchor--hero {
    position: absolute;
    top: 8vh;
    right: 6vw;
    width: clamp(120px, 16vw, 220px);
    height: clamp(120px, 16vw, 220px);
    opacity: 0.92;
}

/* =========================================================================
   Transmission sections
   ========================================================================= */
.transmission-head {
    max-width: 64ch;
    margin-bottom: 3vh;
    position: relative;
}

.signal-label {
    font-family: "JetBrains Mono", monospace;
    font-weight: 300;
    font-size: 0.72rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--dried-marigold);
    margin-bottom: 1.8vh;
    display: inline-block;
}

.trans-title {
    font-family: "Recursive", "Inter", sans-serif;
    font-variation-settings: "MONO" 0, "CASL" 0, "wght" 460, "slnt" 0;
    font-size: clamp(1.8rem, 4.6vw, 3.8rem);
    line-height: 1.08;
    color: var(--roasted-oat);
    letter-spacing: -0.02em;
    max-width: 24ch;
    transition: font-variation-settings 800ms cubic-bezier(.2, .7, .1, 1);
}

/* Activated state — set by IntersectionObserver — "warms up" the type */
.trans-title.warmed {
    font-variation-settings: "MONO" 0, "CASL" 1, "wght" 500, "slnt" -4;
}

/* Anchor the prose to the LOW corner of each diagonal */
.prose-anchor {
    max-width: 56ch;
    margin-top: 6vh;
}

.slab--alt .prose-anchor {
    /* Slab--alt tilts down on the right, so low corner is bottom-left */
    margin-left: 4vw;
    margin-top: auto;
    align-self: flex-end;
}
.slab--bl .prose-anchor {
    /* Slab--bl tilts down on the left, so low corner is bottom-right */
    margin-left: auto;
    margin-right: 4vw;
    text-align: right;
}

.slab--bl .transmission-head {
    margin-left: auto;
    text-align: right;
}

.slab--bl .trans-title {
    margin-left: auto;
}

.prose-anchor p {
    margin-bottom: 1.4em;
}

.prose-anchor p::first-letter {
    color: var(--raw-amber);
    font-variation-settings: "SOFT" 100, "opsz" 24, "wght" 500;
}

/* =========================================================================
   Section seals — tiny circular markers, upper-left of each section
   ========================================================================= */
.seal {
    position: absolute;
    top: -1.2vh;
    left: 0;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.slab--bl .seal {
    left: auto;
    right: 0;
}

.seal svg {
    width: 100%;
    height: 100%;
}

.seal .seal-ring {
    stroke-dasharray: 63;
    stroke-dashoffset: 63;
    transition: stroke-dashoffset 1400ms cubic-bezier(.2, .7, .1, 1);
}

.seal.drawn .seal-ring {
    stroke-dashoffset: 0;
}

.seal-num {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: "JetBrains Mono", monospace;
    font-size: 0.5rem;
    color: var(--roasted-oat);
    letter-spacing: 0.1em;
    pointer-events: none;
}

/* =========================================================================
   Anchor glyphs — large SVG icons positioned at high (uncropped) corners
   ========================================================================= */
.anchor-glyph {
    position: absolute;
    width: clamp(96px, 14vw, 180px);
    height: clamp(96px, 14vw, 180px);
    z-index: 4;
    pointer-events: none;
}

.anchor--tr { top: 6vh;     right: 5vw;  }
.anchor--tl { top: 6vh;     left: 5vw;   }
.anchor--br { bottom: 8vh;  right: 5vw;  }
.anchor--bl { bottom: 8vh;  left: 5vw;   }

/* Path-draw on entry — all strokes draw 0->length over 1400ms */
.anchor-glyph path,
.anchor-glyph line,
.anchor-glyph rect,
.anchor-glyph circle,
.anchor-glyph ellipse {
    stroke-dasharray: 320;
    stroke-dashoffset: 320;
    transition: stroke-dashoffset 1400ms cubic-bezier(.2, .7, .1, 1);
}

.anchor-glyph.drawn path,
.anchor-glyph.drawn line,
.anchor-glyph.drawn rect,
.anchor-glyph.drawn circle,
.anchor-glyph.drawn ellipse {
    stroke-dashoffset: 0;
}

/* Stagger draw across child elements within the glyph */
.anchor-glyph g > *:nth-child(2)  { transition-delay: 60ms;  }
.anchor-glyph g > *:nth-child(3)  { transition-delay: 120ms; }
.anchor-glyph g > *:nth-child(4)  { transition-delay: 180ms; }
.anchor-glyph g > *:nth-child(5)  { transition-delay: 240ms; }
.anchor-glyph g > *:nth-child(6)  { transition-delay: 300ms; }
.anchor-glyph g > *:nth-child(7)  { transition-delay: 360ms; }
.anchor-glyph g > *:nth-child(8)  { transition-delay: 420ms; }
.anchor-glyph g > *:nth-child(9)  { transition-delay: 480ms; }
.anchor-glyph g > *:nth-child(10) { transition-delay: 540ms; }

/* Soft inner highlight — paper-dust edge on filled portions */
.anchor-glyph g {
    filter: drop-shadow(0 0 0.6px rgba(255, 250, 238, 0.6));
}

/* =========================================================================
   Footer ribbon — honey horizontal strip, no links
   ========================================================================= */
.ribbon {
    position: relative;
    background: linear-gradient(90deg, var(--raw-amber) 0%, #d4b06b 50%, var(--raw-amber) 100%);
    color: var(--paper-dust);
    padding: 18px 0;
    margin-top: 0;
    z-index: 5;
    border-top: 1px solid rgba(45, 36, 24, 0.1);
    border-bottom: 1px solid rgba(45, 36, 24, 0.1);
    overflow: hidden;
}

.ribbon-inner {
    max-width: 1340px;
    margin: 0 auto;
    padding: 0 8vw;
    font-family: "JetBrains Mono", monospace;
    font-weight: 300;
    font-size: 0.72rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    display: flex;
    flex-wrap: wrap;
    gap: 14px 22px;
    align-items: center;
}

.ribbon-piece {
    display: inline-block;
}

.ribbon-dot {
    opacity: 0.55;
}

#signalStrength,
#clockReadout {
    color: var(--charred-birch);
    font-variation-settings: "wght" 400;
}

/* =========================================================================
   Glitch — tender, not aggressive — 240ms RGB-split + horizontal slice
   ========================================================================= */
.glitch-target {
    position: relative;
}

.glitch-target.glitching {
    animation: glitch-once 240ms steps(8, end) 1;
}

@keyframes glitch-once {
    0%   { transform: translate(0, 0);   filter: none;       clip-path: inset(0 0 0 0); }
    20%  { transform: translate(2px, 0); filter: hue-rotate(8deg);  clip-path: inset(20% 0 60% 0); }
    35%  { transform: translate(-3px, 0); filter: hue-rotate(-6deg); clip-path: inset(50% 0 30% 0); }
    55%  { transform: translate(1px, 0); filter: hue-rotate(4deg);  clip-path: inset(70% 0 10% 0); }
    75%  { transform: translate(-1px, 0); filter: hue-rotate(-3deg); clip-path: inset(10% 0 80% 0); }
    100% { transform: translate(0, 0);   filter: none;       clip-path: inset(0 0 0 0); }
}

/* RGB ghost layers — created at runtime when glitch is triggered */
.glitch-ghost {
    position: absolute;
    inset: 0;
    pointer-events: none;
    mix-blend-mode: screen;
    opacity: 0.6;
}

/* Wordmark draws strokes on load */
.wordmark.draw-in {
    background-image: linear-gradient(90deg, transparent 0%, transparent 100%);
    background-size: 0% 100%;
    background-repeat: no-repeat;
    background-position: left center;
}

/* =========================================================================
   Entry reveal — sections fade and rise as they enter
   ========================================================================= */
.slab .counter-rotate,
.slab .anchor-glyph {
    opacity: 0;
    transform: translateY(28px);
    transition: opacity 1000ms ease-out, transform 1000ms cubic-bezier(.2, .7, .1, 1);
}

.slab.in-view .counter-rotate {
    opacity: 1;
    transform: translateY(0);
}

.slab.in-view .anchor-glyph {
    opacity: 0.95;
    transform: translateY(0);
    transition-delay: 200ms;
}

/* The hero has no Y translation — it's the entry point */
.slab--hero .counter-rotate,
.slab--hero .anchor-glyph {
    transform: translateY(0);
    opacity: 1;
}

/* Counter-rotate transforms must compose with the entry transform */
.slab--alt.in-view .counter-rotate.counter-rotate--neg { transform: rotate(-1.2deg); }
.slab--bl.in-view  .counter-rotate.counter-rotate--pos { transform: rotate(1.2deg); }

/* =========================================================================
   Responsive — keep diagonals, soften slab tilts on narrow viewports
   ========================================================================= */
@media (max-width: 760px) {
    .slab {
        padding: 10vh 6vw;
        min-height: 92vh;
    }
    .slab--alt { clip-path: polygon(0 4%, 100% 0%, 100% 96%, 0 100%); }
    .slab--bl  { clip-path: polygon(0 0%, 100% 4%, 100% 100%, 0 96%); }
    .wordmark {
        font-size: clamp(2.2rem, 14vw, 4.4rem);
    }
    .trans-title {
        font-size: clamp(1.5rem, 7.5vw, 2.4rem);
        max-width: 18ch;
    }
    .anchor-glyph {
        width: 110px;
        height: 110px;
    }
    .anchor--tr, .anchor--tl { top: 4vh; }
    .anchor--br, .anchor--bl { bottom: 4vh; }
    .ribbon-inner {
        font-size: 0.62rem;
        gap: 8px 14px;
    }
    .prose-anchor {
        max-width: 100%;
        margin-top: 4vh;
    }
    .slab--bl .prose-anchor {
        text-align: left;
        margin-right: 0;
    }
    .slab--bl .transmission-head {
        text-align: left;
        margin-left: 0;
    }
    .slab--bl .trans-title {
        margin-left: 0;
    }
    .freq-dial {
        top: 10px;
        right: 10px;
        font-size: 0.5rem;
        padding: 4px 6px;
    }
}

@media (max-width: 480px) {
    .slab { padding: 8vh 5vw; }
    .anchor-glyph { display: none; }
}

/* Print — strip animations, keep palette */
@media print {
    .scanlines, .petal-field, .freq-dial { display: none; }
    .slab { clip-path: none; margin-top: 0; }
    body { background: #fff; }
}
