/* ============================================
   RAPPO.DEV HOMEPAGE SCENE — the animated blood-moon wallpaper behind the homepage
   Loaded after styles.css and index.css and only overrides what differs.
   ============================================ */

:root {
    /* Red taken from the moon in the wallpaper, a bit brighter for text contrast */
    --primary-color: #ff3b30;
    --primary-rgb: 255, 59, 48;
    --primary-hover: #ff6a5f;
    --glass-color: rgba(12, 2, 2, 0.6);
    --glass-border: rgba(var(--primary-rgb), 0.18);
    /* Wallpaper size in px; every effect below is placed in % of it */
    --scene-ratio: calc(1672 / 940);
    /* 0 at the top, 1 after one screen; set by js/scene.js */
    --scroll-progress: 0;
    /* Same as .nav-container, so hero and cards line up with the logo */
    --content-width: 1400px;
}

/* ---------- Scene: the wallpaper and its effects ---------- */

.scene {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    /* Large viewport height: the image doesn't jump when the mobile address bar slides */
    height: 100vh;
    height: 100lvh;
    z-index: 0;
    overflow: hidden;
    container-type: size;
    --pointer-x: 0;
    --pointer-y: 0;
}

/* Behaves like background-size: cover, but keeps the hooded figure and the code above it
   (77.5 % across)
   in view on narrow screens instead of the empty centre */
.scene-stage {
    --stage-width: max(100cqw, 100cqh * var(--scene-ratio));
    position: absolute;
    width: var(--stage-width);
    aspect-ratio: 1672 / 940;
    /* cqw inside the stage (code blocks) is then a share of the image width */
    container-type: inline-size;
    left: clamp(100cqw - var(--stage-width), 50cqw - var(--stage-width) * 0.775, 0px);
    top: 50%;
    translate: 0 -50%;
    /* Scaled up a little so the parallax shift never shows an edge */
    transform: translate(calc(var(--pointer-x) * -10px), calc(var(--pointer-y) * -8px)) scale(1.04);
    transition: transform 0.6s ease-out;
}

.scene-image {
    display: block;
    width: 100%;
    height: 100%;
}

.scene-stage > canvas,
.scene-stage > div {
    position: absolute;
    pointer-events: none;
}

.scene-water {
    left: 0;
    top: 73%;
    width: 62%;
    height: 27%;
    /* Fade into the untouched image so the rippled strip has no visible edge */
    -webkit-mask-image: linear-gradient(to bottom, transparent, #000 25%), linear-gradient(to left, transparent, #000 15%);
    -webkit-mask-composite: source-in;
    mask-image: linear-gradient(to bottom, transparent, #000 25%), linear-gradient(to left, transparent, #000 15%);
    mask-composite: intersect;
}

.scene-moon {
    left: 43.75%;
    top: -8.2%;
    width: 20%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 60, 40, 0.45) 0%, rgba(255, 30, 20, 0.15) 35%, transparent 68%);
    mix-blend-mode: screen;
    animation: moon-pulse 7s ease-in-out infinite;
}

.scene-rays {
    left: 42.75%;
    top: 15%;
    width: 22%;
    height: 73%;
    /* Centred under the moon (53.75 % across), from its lower rim down to the water;
       the top edge is 8 % wide, a bit narrower than the moon */
    clip-path: polygon(31.8% 0, 68.2% 0, 100% 100%, 0 100%);
    /* Soft sides; the clip alone leaves a hard diagonal edge */
    -webkit-mask-image: linear-gradient(to right, transparent 5%, #000 35%, #000 65%, transparent 95%);
    mask-image: linear-gradient(to right, transparent 5%, #000 35%, #000 65%, transparent 95%);
    background:
        repeating-linear-gradient(95deg, transparent 0 7%, rgba(255, 50, 40, 0.18) 9%, transparent 12%),
        linear-gradient(to bottom, rgba(255, 45, 35, 0.26), rgba(255, 45, 35, 0.22) 60%, rgba(255, 45, 35, 0.2));
    background-size: 200% 100%, 100% 100%;
    mix-blend-mode: screen;
    filter: blur(6px);
    animation: rays-drift 18s linear infinite, rays-flicker 9s ease-in-out infinite;
}

/* Where the moonlight hits the water, flickering along with the beam */
.scene-pool {
    left: 39%;
    top: 82%;
    width: 28%;
    height: 12%;
    border-radius: 50%;
    background: radial-gradient(ellipse, rgba(255, 80, 60, 0.85) 0%, rgba(255, 40, 30, 0.35) 40%, transparent 70%);
    mix-blend-mode: screen;
    animation: rays-flicker 9s ease-in-out infinite;
}

/* Glow of the laptop screen on the hood */
.scene-screen {
    left: 68.4%;
    top: 35%;
    width: 9%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 50, 40, 0.5) 0%, rgba(255, 30, 20, 0.12) 40%, transparent 70%);
    mix-blend-mode: screen;
    animation: screen-flicker 5s steps(1) infinite;
}

.scene-leds {
    inset: 0;
}

.scene-led {
    position: absolute;
    width: 0.35%;
    aspect-ratio: 1;
    translate: -50% -50%;
    border-radius: 50%;
    background: #ff4a3d;
    box-shadow: 0 0 6px 2px rgba(255, 50, 40, 0.8);
    opacity: 0;
    animation: led-blink var(--blink-duration, 3s) steps(1) var(--blink-delay, 0s) infinite;
}

/* Typed code around the figure (js/scene.js); sized with the image */
.scene-code {
    position: absolute;
    margin: 0;
    font-family: var(--font-mono);
    font-size: 0.68cqw;
    line-height: 1.4;
    color: #ff3b30;
    text-shadow: 0 0 6px rgba(255, 40, 30, 0.7), 0 0 14px rgba(255, 30, 20, 0.35);
    opacity: 0.85;
    pointer-events: none;
}

.scene-code::after {
    content: "";
    display: inline-block;
    width: 0.6em;
    height: 1.1em;
    margin-left: 0.15em;
    vertical-align: text-bottom;
    background: currentColor;
    animation: cursor-blink 1s steps(1) infinite;
}

/* Not yet decoded characters of the code block (createDecoder in js/scene.js) */
.scene-code-glyph {
    opacity: 0.45;
    text-shadow: none;
}

.scene-rain {
    inset: 0;
    width: 100%;
    height: 100%;
}

.scene-embers {
    position: absolute;
    inset: -30px;
    width: calc(100% + 60px);
    height: calc(100% + 60px);
    pointer-events: none;
    transform: translate(calc(var(--pointer-x) * -24px), calc(var(--pointer-y) * -18px));
    transition: transform 0.6s ease-out;
}

/* Darkens the left side for the text, adds a vignette and scanlines,
   and dims the whole scene further as the page scrolls */
.scene-shade {
    position: absolute;
    inset: 0;
    background:
        repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.18) 0 1px, transparent 1px 3px),
        linear-gradient(90deg, rgba(0, 0, 0, 0.78) 0%, rgba(0, 0, 0, 0.35) 38%, transparent 62%),
        radial-gradient(ellipse at 60% 45%, transparent 45%, rgba(0, 0, 0, 0.7) 100%),
        rgba(0, 0, 0, calc(var(--scroll-progress) * 0.55));
}

@keyframes moon-pulse {
    0%, 100% { opacity: 0.7; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.06); }
}

@keyframes rays-drift {
    to { background-position: -200% 0, 0 0; }
}

@keyframes rays-flicker {
    0%, 100% { opacity: 0.8; }
    40% { opacity: 0.5; }
    70% { opacity: 1; }
}

/* Irregular steps read as a screen, not a smooth pulse */
@keyframes screen-flicker {
    0% { opacity: 0.85; }
    12% { opacity: 1; }
    14% { opacity: 0.55; }
    16% { opacity: 1; }
    48% { opacity: 0.9; }
    62% { opacity: 0.7; }
    64% { opacity: 1; }
    90% { opacity: 0.8; }
}

@keyframes led-blink {
    0% { opacity: 0; }
    10% { opacity: 1; }
    35% { opacity: 0; }
    55% { opacity: 0.8; }
    60% { opacity: 0; }
}

/* ---------- Page on top of the scene ---------- */

.scene-page .page-container {
    z-index: 1;
}

/* Clear over the moon at the top, solid once the cards scroll underneath */
.scene-page .main-nav {
    background-color: rgba(0, 0, 0, calc(var(--scroll-progress) * 0.75));
    border-bottom-color: rgba(var(--primary-rgb), calc(var(--scroll-progress) * 0.18));
    backdrop-filter: blur(calc(var(--scroll-progress) * 10px));
    -webkit-backdrop-filter: blur(calc(var(--scroll-progress) * 10px));
}

/* Only the current page stands out; the other entries step back until hovered.
   .scene-page raises the specificity above the search button's injected styles. */
.scene-page .nav-links a:not(.active),
.scene-page .search-trigger {
    color: var(--text-subtle);
}

.scene-page .nav-links a:not(.active):hover,
.scene-page .nav-links a:not(.active):focus-visible,
.scene-page .search-trigger:hover,
.scene-page .search-trigger:focus-visible {
    color: var(--text-strong);
}

.scene-hero {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    /* Fill the first screen below the sticky nav */
    min-height: calc(100svh - 4.25rem);
    padding-top: 4rem;
    padding-bottom: 6rem;
}

.scene-hero .hero-content,
.scene-page .section-container {
    width: 100%;
    max-width: var(--content-width);
}

/* Smaller than on the plain homepage so it stays in the dark left part of the image */
.scene-hero .hero-title {
    position: relative;
    font-size: clamp(4rem, 6.5vw, 8.5rem);
    width: fit-content;
    text-shadow: 0 0 24px rgba(var(--primary-rgb), 0.45), 0 0 64px rgba(var(--primary-rgb), 0.25);
}

.scene-hero .hero-subtitle {
    color: var(--text-color);
}

/* Glitch: two offset copies of the title, cut into slices, shown briefly
   whenever js/scene.js sets .is-glitching, and nonstop during the breach */
.scene-hero .hero-title::before,
.scene-hero .hero-title::after {
    content: attr(data-text);
    position: absolute;
    inset: 0;
    opacity: 0;
    pointer-events: none;
}

.scene-hero .hero-title.is-glitching::before,
.is-breached .scene-hero .hero-title::before {
    opacity: 1;
    color: #ff0040;
    animation: glitch-slice-a 0.4s steps(2) both;
}

.scene-hero .hero-title.is-glitching::after,
.is-breached .scene-hero .hero-title::after {
    opacity: 1;
    color: #00e5ff;
    mix-blend-mode: screen;
    animation: glitch-slice-b 0.4s steps(2) both;
}

@keyframes glitch-slice-a {
    0% { clip-path: inset(10% 0 70% 0); transform: translate(-6px, 0); }
    25% { clip-path: inset(55% 0 20% 0); transform: translate(5px, 0); }
    50% { clip-path: inset(30% 0 45% 0); transform: translate(-4px, 0); }
    75% { clip-path: inset(80% 0 5% 0); transform: translate(6px, 0); }
    100% { clip-path: inset(40% 0 40% 0); transform: translate(0, 0); }
}

@keyframes glitch-slice-b {
    0% { clip-path: inset(65% 0 10% 0); transform: translate(5px, 0); }
    25% { clip-path: inset(15% 0 60% 0); transform: translate(-6px, 0); }
    50% { clip-path: inset(45% 0 30% 0); transform: translate(4px, 0); }
    75% { clip-path: inset(5% 0 85% 0); transform: translate(-5px, 0); }
    100% { clip-path: inset(40% 0 40% 0); transform: translate(0, 0); }
}

.hero-terminal {
    position: relative;
    margin-top: 1.25rem;
    font-family: var(--font-mono);
    font-size: 0.95rem;
    color: var(--primary-color);
    cursor: text;
}

.terminal-row {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    min-height: 1.6em;
    margin: 0;
}

/* Answers of the interactive terminal (js/terminal.js), above the prompt */
.terminal-output {
    max-width: 42rem;
    font-size: 0.85rem;
    line-height: 1.5;
}

.terminal-out {
    white-space: pre-wrap;
    color: var(--text-color);
    opacity: 0.85;
}

.terminal-out a {
    color: var(--primary-color);
}

/* Takes the keystrokes (and opens the phone keyboard); what is typed shows in .terminal-line */
.terminal-input {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    border: 0;
    padding: 0;
    /* 16 px keeps iOS from zooming in on focus */
    font-size: 16px;
}

/* Clicked into but not focused right now: the cursor rests */
.hero-terminal.is-active:not(.is-focused) .terminal-cursor {
    animation: none;
    opacity: 0.35;
}

.terminal-prompt {
    color: var(--text-muted);
}

.terminal-line {
    font-family: inherit;
    white-space: pre;
}

.terminal-cursor {
    display: inline-block;
    width: 0.6em;
    height: 1.1em;
    align-self: center;
    background: var(--primary-color);
    animation: cursor-blink 1s steps(1) infinite;
}

@keyframes cursor-blink {
    50% { opacity: 0; }
}

.scroll-hint {
    position: absolute;
    left: 50%;
    bottom: 1.5rem;
    translate: -50% 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem;
    font-size: 0.7rem;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--text-muted);
    text-decoration: none;
}

.scroll-hint::after {
    content: "";
    width: 1px;
    height: 36px;
    background: linear-gradient(to bottom, var(--primary-color), transparent);
    transform-origin: top;
    animation: scroll-line 2s ease-in-out infinite;
}

@keyframes scroll-line {
    0% { transform: scaleY(0); }
    50% { transform: scaleY(1); }
    100% { transform: scaleY(1); opacity: 0; }
}

.scene-page .featured-section {
    padding-top: 2rem;
}

.scene-page .section-label {
    color: var(--text-color);
    border-bottom-color: var(--glass-border);
}

.scene-page .featured-card {
    background: var(--glass-color);
    border-color: var(--glass-border);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.scene-page .featured-card:hover,
.scene-page .featured-card:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 32px rgba(var(--primary-rgb), 0.18);
}

.scene-page .featured-card-meta {
    border-top-color: var(--glass-border);
}

.scene-page .enhanced-footer {
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* ---------- Breach: the secret door was opened (js/secret-door.js, js/scene.js) ----------
   Runs for the door's OPEN_DELAY_MS (1.8 s), ending in black before the page changes */

.is-breached .scene-hero .hero-title::before,
.is-breached .scene-hero .hero-title::after {
    animation-iteration-count: infinite;
}

.is-breached .scene-screen {
    animation: breach-flare 0.18s steps(2) infinite;
}

.is-breached .scene-moon {
    animation-duration: 0.5s;
}

.is-breached .scene-led {
    animation-duration: 0.3s;
}

.is-breached .scene-stage {
    animation: breach-jolt 0.24s steps(3) infinite;
}

/* Red interference bands jumping over the image */
.is-breached .scene::after {
    content: "";
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(to bottom, transparent 0 46px, rgba(255, 40, 30, 0.16) 46px 50px);
    mix-blend-mode: screen;
    pointer-events: none;
    animation: breach-bands 0.2s steps(4) infinite;
}

.is-breached .scene,
.is-breached .page-container {
    animation: breach-fade 0.5s ease-in 1.3s forwards;
}

@keyframes breach-flare {
    0% { opacity: 1; transform: scale(2.2); }
    50% { opacity: 0.6; transform: scale(1.6); }
}

/* Uses scale and filter, so the parallax transform of the stage keeps working */
@keyframes breach-jolt {
    0% { scale: 1; filter: none; }
    33% { scale: 1.02; filter: brightness(1.4) saturate(1.3); }
    66% { scale: 1.005; filter: hue-rotate(-12deg) contrast(1.2); }
}

@keyframes breach-bands {
    to { background-position: 0 200px; }
}

@keyframes breach-fade {
    to { opacity: 0; }
}

/* ---------- Search overlay (markup and base styles in js/global-enhancements.js) ---------- */

/* Lighter backdrop so the wallpaper shows through behind the glass */
.scene-page #global-search-overlay {
    background-color: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.scene-page .search-modal {
    background: var(--glass-color);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7), 0 0 40px rgba(var(--primary-rgb), 0.12);
}

/* The input reads as a terminal prompt; the line below turns red while typing */
.scene-page .search-header {
    gap: 0.75rem;
    border-bottom-color: var(--glass-border);
    transition: border-color 0.2s ease;
}

.scene-page .search-header:focus-within {
    border-bottom-color: var(--primary-color);
}

.scene-page .search-header::before {
    content: ">";
    font-family: var(--font-mono);
    font-size: 1.1rem;
    color: var(--primary-color);
}

.scene-page #global-search-input {
    padding: 0.5rem 0;
    background: none;
    border: none;
    font-family: var(--font-mono);
    font-size: 1.05rem;
    color: var(--text-strong);
    caret-color: var(--primary-color);
}

.scene-page #global-search-input::placeholder {
    color: var(--text-subtle);
}

.scene-page .search-close {
    color: var(--text-subtle);
}

.scene-page .search-close:hover,
.scene-page .search-close:focus-visible {
    background: rgba(var(--primary-rgb), 0.12);
    color: var(--text-strong);
}

.scene-page .search-hint,
.scene-page .no-results {
    font-family: var(--font-mono);
    font-style: normal;
    font-size: 0.85rem;
}

/* Results look like the project cards */
.scene-page .search-result-item {
    padding: 1rem 1.25rem;
    margin-bottom: 0.75rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.scene-page .search-result-item:hover,
.scene-page .search-result-item:focus-visible {
    background: rgba(var(--primary-rgb), 0.06);
    border-color: var(--primary-color);
    box-shadow: 0 0 24px rgba(var(--primary-rgb), 0.15);
    transform: translateY(-2px);
}

.scene-page .result-title {
    font-family: var(--font-display);
    font-weight: 400;
    text-transform: uppercase;
    font-size: 1.6rem;
    letter-spacing: 1px;
    line-height: 1.1;
    color: var(--text-strong);
}

.scene-page .search-result-item:hover .result-title,
.scene-page .search-result-item:focus-visible .result-title {
    color: var(--primary-color);
}

.scene-page .result-category {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 1.5px;
}

/* Matched text; its colour is set inline by the search script */
.scene-page .search-results strong {
    border-radius: 3px;
    background: rgba(var(--primary-rgb), 0.18);
}

/* Phones: the figure fills the middle of the screen, so the text moves to the bottom */
@media (max-width: 576px) {
    .scene-hero {
        justify-content: flex-end;
        padding-bottom: 7rem;
    }

    /* Top band keeps the logo readable over the moon */
    .scene-shade {
        background:
            repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.18) 0 1px, transparent 1px 3px),
            linear-gradient(to bottom, rgba(0, 0, 0, 0.7) 0%, transparent 14%),
            linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.4) 40%, transparent 65%),
            rgba(0, 0, 0, calc(var(--scroll-progress) * 0.55));
    }

    /* The flooded floor is outside the phone crop; hiding it also stops its drawing */
    .scene-water {
        display: none;
    }

    /* Long code lines wrap instead of widening the page; room for two lines
       so the text below doesn't jump while typing */
    .hero-terminal {
        font-size: 0.8rem;
    }

    .terminal-row {
        display: block;
        min-height: 3.2em;
    }

    .terminal-line {
        white-space: pre-wrap;
    }

    /* Inline text flow, so the cursor follows the last character of a wrapped line */
    .terminal-cursor {
        margin-left: 0.2em;
        vertical-align: text-bottom;
    }
}

/* Emote bubble over the figure (js/scene.js, Kenney Emotes Pack, CC0); 16 px pixel art, sized with the image */
.scene-emote {
    position: absolute;
    width: 3.2cqw;
    image-rendering: pixelated;
    pointer-events: none;
    opacity: 0;
    transform-origin: 20% 100%;
    transition: opacity 0.25s ease-out;
    filter: drop-shadow(0 0 0.4cqw rgba(255, 40, 30, 0.45));
}

.scene-emote.is-visible {
    opacity: 1;
    animation: emote-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), emote-bob 2.4s ease-in-out 0.45s infinite;
}

@keyframes emote-pop {
    from { transform: scale(0.3) translateY(30%); }
    to { transform: none; }
}

@keyframes emote-bob {
    50% { transform: translateY(-6%); }
}

/* The scene lies behind the page; this is set while the pointer is over the figure */
body.is-over-figure {
    cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
    .scene *,
    .scroll-hint::after,
    .terminal-cursor {
        animation: none !important;
    }

    .scene-stage,
    .scene-embers {
        transform: none;
    }
}
