/*
 * plan9-intro.css
 *
 * The once-per-tab Plan9 boot/glitch overlay. Loaded only from within
 * base.html's {% block intro %} -- pages that override that block empty
 * (account/base_account.html, and anything standalone like the error pages
 * and the staff dashboard) never request this file at all.
 *
 * Structural guarantees:
 *   - display:none by default. It is only ever shown by adding
 *     `p9-intro-pending` to <html> (done synchronously by the inline script
 *     in base.html, before this overlay is parsed) or `p9-intro-playing`
 *     (added by plan9-intro.js once it starts the animation). No selector
 *     here shows the overlay unconditionally.
 *   - position:fixed; inset:0 -- always removed from normal flow, so it can
 *     never push content around or affect scroll position (CLS-safe).
 *   - Total runtime is ~3200ms, staged as a clear hold -> fade-in -> glitch
 *     -> scanline -> clean hold -> fade-out sequence; see the per-keyframe
 *     comments for the timing breakdown. The duration lives in the
 *     --p9-intro-duration custom property below and in plan9-intro.js's
 *     INTRO_DURATION constant -- JS owns the authoritative total scene
 *     length, CSS animation timings are kept in sync with it but never
 *     drive teardown themselves (see plan9-intro.js).
 */

:root {
    --p9-intro-duration: 6000ms;
}

.p9-intro {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: #000;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    pointer-events: none; /* decorative only -- never blocks interaction */
    opacity: 1;
}

html.p9-intro-pending .p9-intro,
html.p9-intro-playing .p9-intro {
    display: flex;
}

/*
 * Final dissolve: the overlay's own black background (not just the
 * wordmark/scan children) fades to transparent over the last ~700ms of
 * the scene, so the homepage underneath is progressively revealed instead
 * of the overlay being snapped out of the DOM against a still-solid black
 * background. plan9-intro.js's teardown timer fires exactly at 100% of
 * this animation, so by the time the element is removed it is already
 * fully transparent -- no flash, no jump, no second "splash screen" feel.
 */
html.p9-intro-playing .p9-intro {
    animation: p9-intro-fade var(--p9-intro-duration) ease-out forwards;
}

@keyframes p9-intro-fade {
    0%, 88.3% { opacity: 1; }
    100% { opacity: 0; }
}

.p9-intro-word {
    position: relative;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-weight: 800;
    font-size: clamp(2rem, 8vw, 4.5rem);
    letter-spacing: 0.2em;
    color: #e8e8e8;
    opacity: 0;
}

.p9-intro-word::before,
.p9-intro-word::after {
    content: attr(data-text);
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    opacity: 0;
}

.p9-intro-word::before {
    color: #ff3b56;
    mix-blend-mode: screen;
}

.p9-intro-word::after {
    color: #37e0ff;
    mix-blend-mode: screen;
}

.p9-intro-scan {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        to bottom,
        transparent 0%,
        rgba(232, 51, 74, 0.08) 50%,
        transparent 100%
    );
    transform: translateY(-100%);
    opacity: 0;
}

/*
 * Timeline (total ~3200ms), staged as six clearly distinct beats:
 *   0-350ms     (0-11%)   - hold black / signal noise
 *   350-1050ms  (11-33%)  - wordmark emerges, reaching full opacity by 33%
 *   1050-1800ms (33-56%)  - glitch beat: horizontal displacement / RGB
 *                           channel split (red/cyan)
 *   1800-2400ms (56-75%)  - scanline sweeps through as things settle
 *   2400-2816ms (75-88%)  - clean resolve/hold: PLAN9 STUDIOS held steady,
 *                           nothing moving -- the "stabilise" beat
 *   2816-3200ms (88-100%) - fade-out
 * plan9-intro.js adds .p9-intro-playing to kick this off. JS owns a single
 * authoritative timer (INTRO_DURATION, matching --p9-intro-duration) that
 * tears the overlay down -- no `animationend` listener decides this, so
 * these animations are free to describe the full scene without worrying
 * about which child happens to finish last.
 */
html.p9-intro-playing .p9-intro-word {
    animation: p9-word-in var(--p9-intro-duration) cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}

html.p9-intro-playing .p9-intro-word::before {
    animation: p9-split-red var(--p9-intro-duration) steps(1, end) forwards;
}

html.p9-intro-playing .p9-intro-word::after {
    animation: p9-split-cyan var(--p9-intro-duration) steps(1, end) forwards;
}

html.p9-intro-playing .p9-intro-scan {
    animation: p9-scan var(--p9-intro-duration) ease-out forwards;
}

@keyframes p9-word-in {
    0% { opacity: 0; transform: translateX(0); }
    10% { opacity: 0; }
    30% { opacity: 1; transform: translateX(0); }
    34% { transform: translateX(-5px); }
    40% { transform: translateX(7px); }
    46% { transform: translateX(-3px); }
    52% { transform: translateX(0); }
    88% { opacity: 1; transform: translateX(0); }
    100% { opacity: 0; transform: translateX(0); }
}

@keyframes p9-split-red {
    0%, 30% { opacity: 0; transform: translateX(0); }
    34% { opacity: 0.85; transform: translateX(-7px); }
    39% { opacity: 0.65; transform: translateX(5px); }
    44% { opacity: 0.8; transform: translateX(-3px); }
    50% { opacity: 0; transform: translateX(0); }
    100% { opacity: 0; }
}

@keyframes p9-split-cyan {
    0%, 30% { opacity: 0; transform: translateX(0); }
    34% { opacity: 0.85; transform: translateX(7px); }
    39% { opacity: 0.65; transform: translateX(-5px); }
    44% { opacity: 0.8; transform: translateX(3px); }
    50% { opacity: 0; transform: translateX(0); }
    100% { opacity: 0; }
}

@keyframes p9-scan {
    0%, 52% { opacity: 0; transform: translateY(-100%); }
    56% { opacity: 1; }
    72% { opacity: 0.8; transform: translateY(100%); }
    76%, 100% { opacity: 0; transform: translateY(100%); }
}

@media (prefers-reduced-motion: reduce) {
    /* Belt-and-braces: the inline script in base.html already prevents
       `p9-intro-pending`/`p9-intro-playing` from ever being added when
       prefers-reduced-motion is set, so this rule should never need to
       apply in practice -- but if the class were ever present anyway
       (e.g. a user's OS setting changes mid-session), fall back to an
       instant, non-animated state rather than motion. */
    html.p9-intro-playing .p9-intro,
    html.p9-intro-playing .p9-intro-word,
    html.p9-intro-playing .p9-intro-word::before,
    html.p9-intro-playing .p9-intro-word::after,
    html.p9-intro-playing .p9-intro-scan {
        animation: none;
    }
    html.p9-intro-playing .p9-intro { opacity: 1; }
    html.p9-intro-playing .p9-intro-word { opacity: 1; }
    html.p9-intro-playing .p9-intro-word::before,
    html.p9-intro-playing .p9-intro-word::after,
    html.p9-intro-playing .p9-intro-scan {
        opacity: 0;
    }
}
