/**
 * ============================================================================
 * MOTION.CSS — intro, page curtain, scroll set-pieces & spider touches
 * ============================================================================
 * Loaded after main.css. Everything here animates transform / opacity /
 * clip-path only, so the browser can keep it on the compositor.
 */

:root {
    --silk: rgba(52, 56, 72, 0.42);
    --silk-strong: rgba(36, 38, 50, 0.7);
    --mini-spider: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cg fill='none' stroke='%2314151e' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M17 19 L10 13 L6 6'/%3E%3Cpath d='M23 19 L30 13 L34 6'/%3E%3Cpath d='M16.5 21 L8 18 L3 14'/%3E%3Cpath d='M23.5 21 L32 18 L37 14'/%3E%3Cpath d='M16.5 23 L8 25 L3 31'/%3E%3Cpath d='M23.5 23 L32 25 L37 31'/%3E%3Cpath d='M17 25 L11 31 L8 38'/%3E%3Cpath d='M23 25 L29 31 L32 38'/%3E%3C/g%3E%3Cellipse cx='20' cy='15' rx='5' ry='6.5' fill='%2314151e'/%3E%3Cpath d='M18 13.5 Q20 12 22 13.5 Q20 14.6 18 13.5Z M18.4 16.6 Q20 15.3 21.6 16.6 Q20 17.6 18.4 16.6Z' fill='%23d9204c'/%3E%3Cellipse cx='20' cy='23.5' rx='3.6' ry='4' fill='%231d1e26'/%3E%3Ccircle cx='18.8' cy='26' r='.8' fill='%23d9204c'/%3E%3Ccircle cx='21.2' cy='26' r='.8' fill='%23d9204c'/%3E%3Cellipse cx='18.3' cy='13.2' rx='1.2' ry='1.8' fill='%23fff' opacity='.35'/%3E%3C/svg%3E");
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-in-out-quart: cubic-bezier(0.76, 0, 0.24, 1);
}

::selection { background: var(--accent-spider); color: #fff; }

/* Lenis owns smooth scrolling — native smooth scroll would fight it */
html { scroll-behavior: auto !important; }

/* Hero elements wait (hidden) for their entrance; failsafe reveals them */
html.js:not(.motion-off) [data-hero] { visibility: hidden; }
html.motion-failsafe [data-hero] { visibility: visible !important; opacity: 1 !important; }
@media (prefers-reduced-motion: reduce) {
    html.js [data-hero] { visibility: visible !important; }
}

/* -------------------------------------------------------------------------- */
/* 1. SPIDER INTRO (home, once per session)                                    */
/* -------------------------------------------------------------------------- */
html.intro-playing, html.intro-playing body { overflow: hidden; }
html.intro-done .spider-intro { display: none; }

.spider-intro {
    position: fixed;
    inset: 0;
    z-index: 100000;
    pointer-events: auto;
    overflow: hidden;
    contain: strict;
}
.spider-intro { background: var(--bg-newsprint); }
.spider-intro.is-lifting { pointer-events: none; background: transparent; }
.spider-intro .intro-hud,
.spider-intro .intro-caption { transition: opacity 0.3s ease, transform 0.5s cubic-bezier(0.16, 1, 0.3, 1); }
.spider-intro.is-lifting .intro-hud,
.spider-intro.is-lifting .intro-caption { opacity: 0; transform: translateY(-14px); }
.intro-silk { position: absolute; inset: 0; display: block; }

.intro-paper,
.intro-shard {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse at 50% 46%, rgba(255, 255, 255, 0.55), transparent 60%),
        var(--bg-newsprint);
}
.intro-shard {
    will-change: transform;
    box-shadow: 0 0 0 1px rgba(20, 21, 30, 0.04);
}
.intro-shard::after {
    /* torn paper edge shading */
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 47%, rgba(20, 21, 30, 0.06), transparent 30%);
}

.intro-web,
.intro-shard svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
}
.web-spoke { fill: none; stroke: var(--silk-strong); stroke-width: 1.05; }
.web-spiral { fill: none; stroke: var(--silk); stroke-width: 0.85; }
.web-hub { fill: none; stroke: var(--silk-strong); stroke-width: 2.2; stroke-dasharray: 2 3; }
.web-dew .dew-body { fill: rgba(255, 255, 255, 0.75); stroke: rgba(60, 66, 84, 0.5); stroke-width: 0.6; }
.web-dew .dew-glint { fill: #fff; }
.is-static .web-dew { transform-box: fill-box; }

.intro-thread {
    position: absolute;
    top: 0;
    width: 1px;
    height: 100vh;
    background: linear-gradient(to bottom, rgba(36, 38, 50, 0.25), rgba(36, 38, 50, 0.8));
    transform-origin: 50% 0;
    transform: scaleY(0);
    will-change: transform;
}
.intro-spider {
    position: absolute;
    top: 0;
    left: 0;
    will-change: transform;
    filter: drop-shadow(10px 16px 14px rgba(20, 18, 14, 0.18));
}

.intro-hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 22px 28px;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--ink-secondary);
}
.intro-hud .intro-pct { color: var(--accent-spider); }
.intro-skip {
    font: inherit;
    letter-spacing: inherit;
    color: var(--ink-primary);
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid var(--border-ink);
    padding: 8px 14px;
    cursor: pointer;
    box-shadow: 2px 2px 0 var(--ink-primary);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.intro-skip:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--accent-spider); }
.intro-skip kbd { font: inherit; opacity: 0.55; margin-left: 8px; }
.intro-caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 34px;
    text-align: center;
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 1rem;
    color: var(--ink-muted);
}

/* -------------------------------------------------------------------------- */
/* 2. "PRESS RUN" PAGE TRANSITION                                              */
/* -------------------------------------------------------------------------- */
.web-curtain {
    position: fixed;
    inset: 0;
    z-index: 99999;
    pointer-events: none;
    visibility: hidden;
    --cols-in: 0.5s;
    --cols-out: 0.62s;
}
.wc-cols { position: absolute; inset: 0; display: flex; }
.wc-col {
    flex: 1 1 0;
    height: 100%;
    background: var(--bg-newsprint);
    border-right: 1px solid var(--border-subtle);
    transform: translate3d(0, -101%, 0);
    will-change: transform;
}
.wc-col:nth-child(odd) { background: color-mix(in srgb, var(--bg-newsprint) 92%, #e9e4d6); }
.wc-col:last-child { border-right: 0; }
.wc-center {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    pointer-events: none;
}
.wc-web {
    position: absolute;
    left: 50%;
    top: 44%;
    width: min(62vmin, 460px);
    height: min(62vmin, 460px);
    transform: translate(-50%, -50%) scale(0.6) rotate(-12deg);
    opacity: 0;
    overflow: visible;
}
.wc-spokes { fill: none; stroke: var(--silk-strong); stroke-width: 0.5; }
.wc-rings { fill: none; stroke: var(--silk); stroke-width: 0.4; }
.wc-spider {
    position: absolute;
    left: 50%;
    top: 0;
    width: 120px;
    margin-left: -60px;
    height: 44vh;
    transform: translate3d(0, -110%, 0);
}
.wc-thread {
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 100px;
    width: 1px;
    background: var(--silk-strong);
}
.wc-spider .curtain-spider { position: absolute; left: 0; bottom: 0; }
.curtain-mark {
    position: absolute;
    left: 50%;
    top: 62%;
    width: min(90vw, 760px);
    transform: translate(-50%, 0);
    display: grid;
    gap: 10px;
    justify-items: center;
    text-align: center;
    color: var(--ink-primary);
    opacity: 0;
}
.wc-kicker, .wc-mast {
    font-family: var(--font-mono);
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.26em;
    color: var(--ink-muted);
}
.wc-kicker { color: var(--accent-spider); }
.wc-label {
    font-family: var(--font-serif);
    font-size: clamp(2rem, 6vw, 4.2rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1;
    text-wrap: balance;
    padding-bottom: 10px;
    border-bottom: 3px double var(--border-ink);
}
.wc-label::before { content: var(--nav-label, "The Front Page"); }

/* LEAVING: columns drop in left → right, then the spider abseils in */
html.is-leaving .web-curtain,
html.is-arriving .web-curtain { visibility: visible; pointer-events: auto; }
html.is-leaving .wc-col {
    transform: translate3d(0, 0, 0);
    transition: transform var(--cols-in) cubic-bezier(0.76, 0, 0.24, 1) calc(var(--i) * 0.045s);
}
html.is-leaving .wc-spider {
    transform: translate3d(0, 0, 0);
    transition: transform 0.55s cubic-bezier(0.34, 1.45, 0.64, 1) 0.18s;
}
html.is-leaving .wc-web {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
    transition: opacity 0.3s ease 0.28s, transform 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.22s;
}
html.is-leaving .curtain-mark {
    opacity: 1;
    transform: translate(-50%, -6px);
    transition: opacity 0.3s ease 0.32s, transform 0.5s cubic-bezier(0.16, 1, 0.3, 1) 0.32s;
}

/* ARRIVING: already covered at first paint … */
html.is-arriving .wc-col { transform: translate3d(0, 0, 0); }
html.is-arriving .wc-spider { transform: translate3d(0, 0, 0); }
html.is-arriving .wc-web { opacity: 1; transform: translate(-50%, -50%) scale(1); }
html.is-arriving .curtain-mark { opacity: 1; transform: translate(-50%, -6px); }
/* … then the spider climbs out and the columns lift from the centre outward */
html.is-arriving.is-arrived .wc-spider {
    transform: translate3d(0, -115%, 0);
    transition: transform 0.42s cubic-bezier(0.55, 0, 0.75, 0.2);
}
html.is-arriving.is-arrived .wc-web {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.25) rotate(8deg);
    transition: opacity 0.35s ease 0.1s, transform 0.6s ease 0.05s;
}
html.is-arriving.is-arrived .curtain-mark {
    opacity: 0;
    transform: translate(-50%, -24px);
    transition: opacity 0.3s ease 0.05s, transform 0.45s ease 0.05s;
}
html.is-arriving.is-arrived .wc-col {
    transform: translate3d(0, -101%, 0);
    transition: transform var(--cols-out) cubic-bezier(0.76, 0, 0.24, 1) calc(0.24s + var(--d, 0) * 0.06s);
}
.wc-col:nth-child(1), .wc-col:nth-child(5) { --d: 2; }
.wc-col:nth-child(2), .wc-col:nth-child(4) { --d: 1; }
.wc-col:nth-child(3) { --d: 0; }

@media (max-width: 768px) {
    .wc-col:nth-child(4), .wc-col:nth-child(5) { display: none; }
    .wc-col:nth-child(1), .wc-col:nth-child(3) { --d: 1; }
    .wc-col:nth-child(2) { --d: 0; }
    .wc-spider { width: 96px; margin-left: -48px; height: 40vh; }
    .wc-thread { bottom: 80px; }
    .curtain-mark { top: 58%; }
}

/* -------------------------------------------------------------------------- */
/* 3. HANGING SCROLL-PROGRESS SPIDER                                           */
/* -------------------------------------------------------------------------- */
.hang-spider {
    position: fixed;
    top: 0;
    right: 26px;
    width: 74px;
    height: 100vh;
    z-index: 900;
    border: 0;
    padding: 0;
    background: none;
    pointer-events: none;
}
.hang-thread {
    position: absolute;
    top: 0;
    left: 50%;
    width: 1px;
    height: 100vh;
    background: var(--silk-strong);
    transform-origin: 50% 0;
    will-change: transform;
}
.hang-canvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: auto;
    cursor: pointer !important;
    will-change: transform;
    transform-origin: 50% 0;
}
.hang-tip {
    position: absolute;
    right: 70px;
    top: 0;
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    color: var(--ink-secondary);
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}
.hang-spider:hover .hang-tip { opacity: 1; }
html.intro-playing .hang-spider { visibility: hidden; }
@media (max-width: 768px) {
    .hang-spider { right: 2px; width: 44px; opacity: 0.85; }
    .hang-tip { display: none; }
}

/* Live corner cobweb in the hero (remnant of the intro web) */
.hero-cobweb {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 30;
    pointer-events: none;
}
html.intro-playing .hero-cobweb { visibility: hidden; }

/* Web-shot drawing layer */
.web-shot-layer {
    position: fixed;
    inset: 0;
    z-index: 899;
    pointer-events: none;
}

/* -------------------------------------------------------------------------- */
/* 4. SILK RULES, COBWEBS & MINI SPIDERS                                       */
/* -------------------------------------------------------------------------- */
.mini-spider {
    display: block;
    width: 22px;
    height: 22px;
    background: var(--mini-spider) center / contain no-repeat;
}

.section-banner { position: relative; }
.web-rule {
    position: relative;
    height: 28px;
    margin: -6px 0 10px;
    pointer-events: none;
}
.web-rule svg { width: 100%; height: 28px; overflow: visible; display: block; }
.web-rule-strand { fill: none; stroke: var(--silk-strong); stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.web-rule-strand.thin { stroke: var(--silk); stroke-width: 0.8; }
.web-rule-drop {
    position: absolute;
    top: 8px;
    width: 22px;
    margin-left: -11px;
    animation: rule-sway 4.5s ease-in-out infinite;
    transform-origin: 50% 0;
}
.web-rule-thread { display: block; width: 1px; height: 26px; margin: 0 auto; background: var(--silk-strong); }
@keyframes rule-sway {
    0%, 100% { rotate: -4deg; }
    50% { rotate: 4deg; }
}

.cobweb {
    position: absolute;
    top: -1px;
    right: -1px;
    width: 110px;
    height: 110px;
    pointer-events: none;
    z-index: 2;
}
.cobweb.small { width: 74px; height: 74px; }
.cobweb svg { width: 100%; height: 100%; overflow: visible; }
.cobweb-spoke { fill: none; stroke: var(--silk-strong); stroke-width: 0.8; vector-effect: non-scaling-stroke; }
.cobweb-ring { fill: none; stroke: var(--silk); stroke-width: 0.7; vector-effect: non-scaling-stroke; }
.featured-exhibit-card,
.archive-banner-callout,
.telegram-form-card,
.spec-table-box,
.archive-project-card { position: relative; }

/* Buttons: a tiny spider abseils onto them on hover */
.btn-newspaper-primary,
.news-btn-hire { position: relative; overflow: visible; }
.btn-newspaper-primary::after,
.news-btn-hire::after {
    content: '';
    position: absolute;
    right: 14px;
    bottom: 100%;
    width: 16px;
    height: 34px;
    background:
        var(--mini-spider) 50% 100% / 16px 16px no-repeat,
        linear-gradient(var(--silk-strong), var(--silk-strong)) 50% 0 / 1px calc(100% - 12px) no-repeat;
    transform: translateY(-26px) scaleY(0.2);
    transform-origin: 50% 0;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.55s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
}
.btn-newspaper-primary:hover::after,
.news-btn-hire:hover::after {
    opacity: 1;
    transform: translateY(14px) scaleY(1);
}

/* Images that drift inside their frames */
.parallax-box { overflow: hidden; }
.parallax-box > img { will-change: transform; }

/* Pointer tilt */
.has-tilt { transform-style: preserve-3d; will-change: transform; }

/* Sticky nav compacts once it is stuck */
.newspaper-nav.is-stuck { padding-top: 7px; padding-bottom: 7px; box-shadow: 0 10px 30px -12px rgba(20, 21, 30, 0.22); }

/* -------------------------------------------------------------------------- */
/* 5. SYSTEMS — HORIZONTAL PINNED TRACK (desktop)                               */
/* -------------------------------------------------------------------------- */
#stack.is-horizontal {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-top: 64px;
    padding-bottom: 20px;
    overflow: hidden;
    width: 100vw;
    max-width: none;
    margin-left: calc(50% - 50vw);
    margin-right: 0;
    padding-left: max(28px, calc(50vw - 592px));
    padding-right: 0;
    background: var(--bg-newsprint);
}
#stack.is-horizontal .section-banner { padding-right: max(28px, calc(50vw - 592px)); }
#stack.is-horizontal .systems-broadsheet-grid {
    display: flex;
    flex-wrap: nowrap;
    gap: 28px;
    overflow: visible;
    padding-right: max(28px, calc(50vw - 592px));
}
#stack.is-horizontal .system-pillar-box {
    flex: 0 0 min(520px, 40vw);
    will-change: transform;
}
#stack.is-horizontal .section-banner { margin-bottom: 18px; }
#stack.is-horizontal .section-title { font-size: clamp(2rem, 3.6vw, 3.2rem); }
.h-progress {
    position: relative;
    height: 26px;
    margin: 18px max(28px, calc(50vw - 592px)) 0 0;
    --p: 0;
}
.h-progress-line {
    position: absolute;
    left: 0;
    right: 0;
    top: 12px;
    height: 1px;
    background: var(--silk);
}
.h-progress-line::after {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--ink-primary);
    transform-origin: 0 50%;
    transform: scaleX(var(--p));
}
.h-progress-spider {
    position: absolute;
    top: 2px;
    left: 0;
    transform: translateX(calc(var(--p) * (min(1184px, 100vw - 56px) - 22px))) rotate(90deg);
}

/* -------------------------------------------------------------------------- */
/* 6. "EXTRA! EXTRA!" VELOCITY TICKERS                                         */
/* -------------------------------------------------------------------------- */
.ticker-band {
    position: relative;
    margin: 30px calc(50% - 50vw) 10px;
    height: 150px;
    overflow: hidden;
    pointer-events: none;
}
.news-ticker {
    position: absolute;
    left: -5%;
    right: -5%;
    top: 50%;
    padding: 12px 0;
    background: var(--ink-primary);
    color: var(--bg-newsprint);
    border-top: 2px solid var(--ink-primary);
    border-bottom: 2px solid var(--ink-primary);
    transform: translateY(-50%) rotate(-2.2deg);
    overflow: hidden;
}
.news-ticker.alt {
    background: var(--bg-newsprint);
    color: var(--ink-primary);
    transform: translateY(-50%) rotate(1.8deg);
    box-shadow: 0 0 0 1px var(--ink-primary) inset;
}
.ticker-track {
    display: flex;
    width: max-content;
    will-change: transform;
}
.ticker-track span {
    flex: none;
    padding-right: 2.5rem;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.14em;
    white-space: nowrap;
    text-transform: uppercase;
}
.ticker-track b { color: var(--accent-spider); font-weight: 700; }

/* -------------------------------------------------------------------------- */
/* 7. STAMPED DISPATCH CARDS                                                   */
/* -------------------------------------------------------------------------- */
.hackathon-dispatch-card.is-stamped .dossier-badge {
    animation: ink-bleed 0.6s ease-out both;
}
@keyframes ink-bleed {
    0% { box-shadow: 0 0 0 0 rgba(217, 32, 76, 0.35); }
    100% { box-shadow: 0 0 0 10px rgba(217, 32, 76, 0); }
}

@media (max-width: 768px) {
    .intro-hud { padding: 16px; font-size: 0.62rem; }
    .intro-hud .hud-long { display: none; }
    .ticker-band { height: 110px; }
    .ticker-track span { font-size: 0.78rem; }
    .cobweb { width: 70px; height: 70px; }
    .btn-newspaper-primary::after, .news-btn-hire::after { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .spider-intro, .web-curtain, .web-shot-layer { display: none !important; }
    .web-rule-drop { animation: none; }
}
