/* =====================================================
   PHOSPHOR_OS — FX Layer
   The site is a living CRT machine.
   The cursor is the electron beam: it excites phosphor.
   ===================================================== */

:root {
    --fx-ph: #39ff14;
    /* phosphor green   */
    --fx-mag: #ff00ff;
    /* magenta accent   */
    --fx-cyn: #00ffff;
    /* cyan accent      */
    --fx-amber: #ffb000;
}

/* ---------- Layer 0: signal field (background canvas) ---------- */
#signal-field {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

/* ---------- Layer top: cursor canvas ---------- */
#fx-cursor {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 10001;
    pointer-events: none;
}

/* Hide native cursor only when the beam is online (JS adds .fx-cursor-on) */
@media (pointer: fine) {

    html.fx-cursor-on,
    html.fx-cursor-on * {
        cursor: none !important;
    }
}

/* ---------- Boot overlay (ZX cassette loader) ---------- */
#boot-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-origin: 50% 50%;
    transition: transform 0.45s cubic-bezier(0.8, 0, 0.2, 1), opacity 0.3s ease 0.35s;
}

#boot-overlay.boot-reveal {
    transform: scaleY(0.004);
    opacity: 0;
    pointer-events: none;
}

.boot-frame {
    width: min(560px, 86vw);
    color: #c8c8c8;
    font-family: 'VT323', monospace;
    font-size: clamp(16px, 2.2vw, 22px);
    line-height: 1.35;
}

.boot-frame .boot-line {
    white-space: pre-wrap;
    min-height: 1.35em;
}

.boot-frame .boot-ok {
    color: var(--fx-ph);
}

.boot-frame .boot-bright {
    color: #fff;
}

/* Cassette stripe borders (the iconic loading border) */
.boot-stripes {
    position: absolute;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}

#boot-overlay.is-loading .boot-stripes {
    opacity: 1;
}

.boot-stripes-h {
    left: 0;
    right: 0;
    height: 22px;
    background: repeating-linear-gradient(90deg,
            #00d8d8 0 10px, #e8e800 10px 20px);
    animation: stripeSlide 0.28s linear infinite;
}

.boot-stripes-h.top {
    top: 0;
}

.boot-stripes-h.bottom {
    bottom: 0;
}

.boot-stripes-v {
    top: 0;
    bottom: 0;
    width: 22px;
    background: repeating-linear-gradient(0deg,
            #00d8d8 0 10px, #e8e800 10px 20px);
    animation: stripeSlideV 0.28s linear infinite;
}

.boot-stripes-v.left {
    left: 0;
}

.boot-stripes-v.right {
    right: 0;
}

/* Second pass: data block = faster, magenta/red shift */
#boot-overlay.is-data .boot-stripes-h {
    background: repeating-linear-gradient(90deg,
            #d800d8 0 7px, #d82020 7px 14px);
    animation-duration: 0.12s;
}

#boot-overlay.is-data .boot-stripes-v {
    background: repeating-linear-gradient(0deg,
            #d800d8 0 7px, #d82020 7px 14px);
    animation-duration: 0.12s;
}

@keyframes stripeSlide {
    from {
        background-position-x: 0;
    }

    to {
        background-position-x: 20px;
    }
}

@keyframes stripeSlideV {
    from {
        background-position-y: 0;
    }

    to {
        background-position-y: 20px;
    }
}

.boot-skip {
    position: absolute;
    bottom: 34px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'VT323', monospace;
    font-size: 16px;
    color: #666;
    letter-spacing: 0.15em;
    animation: bootBlink 1.1s steps(2) infinite;
}

@keyframes bootBlink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.15;
    }
}

/* CRT power ON flash line */
#boot-flash {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 3px;
    background: #fff;
    box-shadow: 0 0 24px 6px rgba(255, 255, 255, 0.8);
    transform: scaleY(0);
    opacity: 0;
    pointer-events: none;
}

#boot-overlay.boot-reveal #boot-flash {
    opacity: 1;
    transform: scaleY(1);
    transition: opacity 0.5s ease 0.25s, transform 0.12s ease-out;
    animation: flashFade 0.55s ease 0.25s forwards;
}

@keyframes flashFade {
    to {
        opacity: 0;
    }
}

/* ---------- CRT power OFF (page exit transition) ---------- */
#crt-power {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: #000;
    transform: scaleY(0.004);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.4s cubic-bezier(0.8, 0, 0.2, 1), opacity 0.15s ease;
}

#crt-power::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 2px;
    background: #fff;
    box-shadow: 0 0 30px 8px rgba(255, 255, 255, 0.9);
}

#crt-power.on {
    transform: scaleY(1);
    opacity: 1;
    pointer-events: all;
}

#crt-power.collapse {
    transform: scaleY(0.004) scaleX(1);
    opacity: 1;
    transition: transform 0.35s cubic-bezier(0.8, 0, 0.2, 1) 0.25s;
}

/* ---------- Scroll signal progress ---------- */
#sig-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 2px;
    width: 0%;
    z-index: 101;
    background: linear-gradient(90deg, var(--fx-ph), var(--fx-cyn));
    box-shadow: 0 0 8px rgba(57, 255, 20, 0.7);
    pointer-events: none;
}

#sig-progress::after {
    content: "";
    position: absolute;
    right: -3px;
    top: -2px;
    width: 6px;
    height: 6px;
    background: #fff;
    box-shadow: 0 0 10px 2px rgba(57, 255, 20, 0.9);
}

/* ---------- Hero phosphor chars ---------- */
.pchar {
    display: inline-block;
    will-change: transform, filter;
    transition: none;
}

/* ---------- Decode (scramble) ---------- */
.decode-char {
    display: inline-block;
    min-width: 0.3em;
}

/* ---------- Power-on reveal ---------- */
html.fx-arm .fx-reveal {
    clip-path: inset(0 100% 0 0);
}

html.fx-arm .fx-reveal.fx-on {
    clip-path: inset(-2% -2% -2% -2%);
    transition: clip-path 0.65s cubic-bezier(0.75, 0, 0.2, 1);
}

.fx-reveal.fx-jolt {
    animation: fxJolt 0.22s steps(3) 1;
}

@keyframes fxJolt {
    0% {
        transform: translate(0, 0);
    }

    33% {
        transform: translate(-3px, 1px);
    }

    66% {
        transform: translate(2px, -2px);
    }

    100% {
        transform: translate(0, 0);
    }
}

/* ---------- Signal warp (fast scroll glitch) ---------- */
body.warp main {
    animation: warpShift 0.2s steps(2) both;
}

@keyframes warpShift {
    0% {
        transform: translateX(0);
        filter: none;
    }

    34% {
        transform: translateX(-3px) skewX(0.35deg);
        filter: drop-shadow(2px 0 rgba(255, 0, 255, 0.35)) drop-shadow(-2px 0 rgba(0, 255, 255, 0.35));
    }

    67% {
        transform: translateX(2px);
        filter: drop-shadow(-2px 0 rgba(255, 0, 255, 0.3)) drop-shadow(2px 0 rgba(0, 255, 255, 0.3));
    }

    100% {
        transform: translateX(0);
        filter: none;
    }
}

/* ---------- ASCII portrait ---------- */
#portrait-frame canvas.ascii-portrait {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
}

/* keep the frame badges (LIVE_FEED / ID) above the signal canvas */
#portrait-frame>div {
    z-index: 3;
}

/* ---------- Magnetic ---------- */
.magnetic {
    will-change: transform;
}

/* ---------- Toasts ---------- */
#fx-toasts {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 9700;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.fx-toast {
    font-family: 'VT323', monospace;
    font-size: 18px;
    color: var(--fx-ph);
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid rgba(57, 255, 20, 0.5);
    border-left: 4px solid var(--fx-ph);
    padding: 8px 14px;
    max-width: 320px;
    box-shadow: 0 0 18px rgba(57, 255, 20, 0.15);
    animation: toastIn 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.fx-toast.out {
    opacity: 0;
    transform: translateX(20px);
    transition: opacity 0.3s, transform 0.3s;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(30px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ---------- Guest terminal ---------- */
#term-overlay {
    position: fixed;
    inset: 0;
    z-index: 9500;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0 12px 40px;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.2s ease, visibility 0s;
}

#term-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0s linear 0.22s;
}

#term-panel {
    width: min(640px, 94vw);
    max-height: min(70vh, 520px);
    display: flex;
    flex-direction: column;
    background: rgba(2, 8, 2, 0.96);
    border: 1px solid rgba(57, 255, 20, 0.55);
    box-shadow: 0 0 40px rgba(57, 255, 20, 0.18), 4px 4px 0 rgba(255, 0, 255, 0.55);
    transform: translateY(0);
    transition: transform 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

#term-overlay.hidden #term-panel {
    transform: translateY(24px);
}

#term-header {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(57, 255, 20, 0.12);
    border-bottom: 1px solid rgba(57, 255, 20, 0.35);
    padding: 6px 10px;
    font-family: 'VT323', monospace;
    font-size: 16px;
    color: var(--fx-ph);
    letter-spacing: 0.08em;
}

#term-header .term-hint {
    margin-left: auto;
    color: rgba(57, 255, 20, 0.45);
    font-size: 14px;
}

@media (max-width: 520px) {
    #term-header .term-hint {
        display: none;
    }
}

#term-close {
    background: none;
    border: none;
    color: var(--fx-mag);
    font-family: 'VT323', monospace;
    font-size: 16px;
    padding: 0 4px;
}

#term-output {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    font-family: 'VT323', monospace;
    font-size: 18px;
    line-height: 1.3;
    color: #b6ffb0;
    scrollbar-width: thin;
    scrollbar-color: rgba(57, 255, 20, 0.4) transparent;
}

#term-output .t-dim {
    color: rgba(182, 255, 176, 0.55);
}

#term-output .t-ph {
    color: var(--fx-ph);
}

#term-output .t-mag {
    color: var(--fx-mag);
}

#term-output .t-cyn {
    color: var(--fx-cyn);
}

#term-output .t-err {
    color: #ff5555;
}

#term-output a {
    color: var(--fx-cyn);
    text-decoration: underline;
}

#term-form {
    display: flex;
    align-items: center;
    gap: 8px;
    border-top: 1px solid rgba(57, 255, 20, 0.25);
    padding: 8px 12px;
}

.term-prompt {
    font-family: 'VT323', monospace;
    font-size: 18px;
    color: var(--fx-ph);
    white-space: nowrap;
}

#term-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #e6ffe0;
    font-family: 'VT323', monospace;
    font-size: 18px;
    caret-color: var(--fx-ph);
}

/* Header / footer FX buttons */
.fx-term-btn {
    font-family: 'Space Mono', monospace;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: rgba(57, 255, 20, 0.7);
    background: transparent;
    border: 1px solid rgba(57, 255, 20, 0.4);
    padding: 4px 10px;
    transition: all 0.2s;
}

.fx-term-btn:hover {
    color: #000;
    background: var(--fx-ph);
    box-shadow: 0 0 14px rgba(57, 255, 20, 0.6);
}

.fx-footer-btn {
    background: none;
    border: none;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    padding: 0;
}

.fx-footer-btn:hover {
    color: var(--fx-ph);
    text-shadow: 0 0 6px rgba(57, 255, 20, 0.7);
}

/* ---------- Mobile menu ---------- */
#mobile-menu {
    position: fixed;
    inset: 0;
    z-index: 9600;
    background: rgba(3, 6, 3, 0.97);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.2s ease, visibility 0s;
}

#mobile-menu.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0s linear 0.22s;
}

#mobile-menu nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 22px;
}

#mobile-menu a {
    font-family: 'Press Start 2P', monospace;
    font-size: 20px;
    color: rgba(57, 255, 20, 0.75);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

#mobile-menu a:hover {
    color: var(--fx-ph);
    text-shadow: 0 0 12px rgba(57, 255, 20, 0.8);
}

#menu-close {
    position: absolute;
    top: 18px;
    right: 22px;
    background: none;
    border: none;
    color: var(--fx-mag);
    font-family: 'VT323', monospace;
    font-size: 26px;
}

#mobile-menu .mm-hint {
    margin-top: 34px;
    font-family: 'VT323', monospace;
    font-size: 16px;
    color: rgba(57, 255, 20, 0.4);
}

/* ---------- Cheat mode ---------- */
body.cheats .scanline-overlay {
    animation: hueSpin 3s linear infinite;
}

@keyframes hueSpin {
    to {
        filter: hue-rotate(360deg);
    }
}

/* ---------- Reduced motion: beam goes quiet ---------- */
@media (prefers-reduced-motion: reduce) {

    #signal-field,
    #fx-cursor,
    .boot-stripes,
    .moving-scanline {
        display: none !important;
    }

    body.warp main {
        animation: none;
    }

    html.fx-arm .fx-reveal {
        clip-path: none;
    }
}
