﻿/*-----------------------------------*\
  #404 — "OFF THE MAP"
  A lost-explorer scene for RoDonate.
  Dark carbon base + signal-blue terrain + a warm amber
  "lost beacon" accent. Buoyant motion, not glitchy.
\*-----------------------------------*/

:root {
    --ff-mono: 'Space Mono', monospace;
    /* page-local accents, derived from the global palette */
    --err-beacon: #ffb454;          /* warm lost-signal amber */
    --err-beacon-soft: rgba(255, 180, 84, 0.18);
    --err-sky-1: rgba(79, 124, 255, 0.16);
    --err-sky-2: rgba(70, 198, 255, 0.10);
    --err-ink: #0a0c16;
}

body {
    padding-top: 73px;
}

/*-----------------------------------*\
  #STAGE
\*-----------------------------------*/

.error-main {
    position: relative;
    min-height: calc(100vh - 73px);
    display: flex;
    align-items: center;
    /* Clip horizontal overflow from the floating scene, but never the page vertically */
    overflow-x: clip;
    background:
        radial-gradient(120% 90% at 78% 8%, var(--err-sky-1) 0%, transparent 55%),
        radial-gradient(90% 80% at 12% 95%, var(--err-sky-2) 0%, transparent 50%),
        linear-gradient(180deg, var(--carbon-black) 0%, var(--err-ink) 100%);
}

/* Slow-breathing aurora wash */
.error-aurora {
    position: absolute;
    inset: -20% -10% auto -10%;
    height: 70%;
    background:
        radial-gradient(40% 60% at 30% 40%, rgba(79, 124, 255, 0.22), transparent 70%),
        radial-gradient(45% 55% at 72% 30%, rgba(70, 198, 255, 0.16), transparent 70%),
        radial-gradient(35% 50% at 55% 70%, var(--err-beacon-soft), transparent 70%);
    filter: blur(40px);
    opacity: 0.85;
    pointer-events: none;
    animation: errAurora 16s var(--ease-smooth) infinite alternate;
    z-index: 0;
}

/* Drifting starfield (populated by JS) */
.error-stars {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

.error-star {
    position: absolute;
    border-radius: 50%;
    background: var(--bright-snow);
    opacity: 0;
    box-shadow: 0 0 6px rgba(242, 242, 247, 0.6);
    animation:
        errTwinkle var(--tw) ease-in-out var(--td) infinite,
        errStarDrift 22s linear var(--td) infinite;
}

/* Fine grain to kill banding and add tactility */
.error-grain {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/*-----------------------------------*\
  #LAYOUT
  Scene leads on the left, copy on the right.
  Diagonal-leaning, asymmetric grid.
\*-----------------------------------*/

.error-container {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: 0.95fr 1.05fr;
    align-items: center;
    gap: var(--space-xxl);
    width: 100%;
    padding-top: var(--space-xxl);
    padding-bottom: var(--space-xxl);
}

/* Copy leads on the left, scene sits on the right.
   Both pinned to row 1 so source order (scene-first) doesn't force a 2nd row. */
.error-copy  { grid-column: 1; grid-row: 1; }
.error-scene { grid-column: 2; grid-row: 1; }

/*-----------------------------------*\
  #THE SCENE — floating terrain
\*-----------------------------------*/

.error-scene {
    position: relative;
    min-height: 460px;
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 1000px;
    /* keep all floating pieces + their motion inside the scene */
    overflow: hidden;
}

/* The floating cluster is a fixed-ratio stage: decorative pieces position
   against THIS box (not the variable-width numerals), so they always frame
   the 404 the same way and never leak out. Parallax via --px/--py from JS. */
.error-scene-float {
    --px: 0px;
    --py: 0px;
    position: relative;
    width: min(100%, 480px);
    aspect-ratio: 5 / 4;
    display: grid;
    place-items: center;
    transform: translate3d(var(--px), var(--py), 0);
    animation: errBob 7s ease-in-out infinite;
    will-change: transform;
    /* Become the sizing reference: numerals + decorative pieces measure
       against THIS box (cqw), so the whole scene shrinks in lockstep and
       the corner pieces always keep the same gutter from the digits. */
    container-type: inline-size;
}

/* The giant 404 reads as terrain/sky type. Centred in the stage; decorative
   pieces are positioned around it relative to the stage box. */
.error-numerals {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(2px, 1vw, 14px);
    line-height: 1;
    user-select: none;
    position: relative;
    z-index: 2;
}

.error-num {
    font-family: var(--ff-display);
    /* Sized from the stage box so the digits + corner pieces shrink together. */
    font-size: clamp(5rem, 34cqw, 13rem);
    font-weight: var(--fw-bold);
    letter-spacing: -0.05em;
    background: linear-gradient(165deg,
        #ffffff 0%,
        rgba(120, 160, 255, 0.95) 42%,
        var(--primary) 78%,
        rgba(58, 94, 219, 0.7) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 22px 30px rgba(8, 10, 18, 0.6));
}

/* The middle "0" becomes a glowing planet/orb */
.error-num--orb {
    position: relative;
    width: clamp(3.6rem, 26cqw, 9.5rem);
    height: clamp(3.6rem, 26cqw, 9.5rem);
    background: none;
    filter: none;
}

.error-orb {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background:
        radial-gradient(circle at 34% 30%, #9db8ff 0%, var(--primary) 38%, #2a3f9e 78%, #131a3d 100%);
    box-shadow:
        inset -14px -14px 32px rgba(0, 0, 0, 0.55),
        inset 10px 10px 26px rgba(157, 184, 255, 0.45),
        0 0 50px rgba(79, 124, 255, 0.45);
    animation: errSpin 28s linear infinite;
}

/* Ring around the orb */
.error-num--orb::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 128%;
    height: 36%;
    transform: translate(-50%, -50%) rotate(-22deg);
    border: 2px solid rgba(70, 198, 255, 0.4);
    border-radius: 50%;
    box-shadow: 0 0 14px rgba(70, 198, 255, 0.25);
    animation: errRing 28s linear infinite;
}

/*-----------------------------------*\
  #FLOATING ISLAND + DROPPED PIN
\*-----------------------------------*/

/* The island sits low and just left of centre — terrain the explorer fell
   from — tucked under the digits rather than over them. */
.error-island {
    position: absolute;
    left: 3%;
    bottom: 6%;
    /* cqw so the island scales with the stage instead of holding a px floor
       that crowds the digits on narrow screens. */
    width: clamp(58px, 24cqw, 124px);
    height: auto;
    aspect-ratio: 7 / 5;
    animation: errIslandBob 5.5s ease-in-out infinite;
    z-index: 1;            /* behind the numerals so it never blocks them */
}

/* A distant island, top-left, purely for depth. */
.error-island--far {
    left: 3%;
    right: auto;
    top: 5%;
    bottom: auto;
    width: clamp(38px, 14cqw, 76px);
    aspect-ratio: 7 / 5;
    height: auto;
    opacity: 0.45;
    filter: blur(0.6px) saturate(0.85);
    animation-duration: 8s;
    animation-direction: alternate;
    z-index: 1;
}

/* Grassy top — scales with the island box */
.error-island-top {
    position: absolute;
    inset: 0 0 auto 0;
    height: 42%;
    border-radius: 50% 50% 42% 42% / 70% 70% 30% 30%;
    background: linear-gradient(180deg, #5b86ff 0%, var(--primary) 60%, #3a5edb 100%);
    box-shadow:
        inset 0 6px 12px rgba(157, 184, 255, 0.5),
        0 8px 22px rgba(79, 124, 255, 0.3);
}

/* Rocky underside, tapering to a point */
.error-island-rock {
    position: absolute;
    top: 32%;
    left: 50%;
    transform: translateX(-50%);
    width: 78%;
    height: 68%;
    background: linear-gradient(180deg, #26305c 0%, #161c3a 70%, #0d1126 100%);
    clip-path: polygon(0 0, 100% 0, 84% 34%, 64% 60%, 50% 100%, 38% 58%, 16% 30%);
    filter: drop-shadow(0 14px 18px rgba(8, 10, 18, 0.5));
}

/* The lost beacon / dropped pin sitting on the island */
.error-pin {
    position: absolute;
    left: 50%;
    bottom: 70%;            /* sits just above the grassy top, scales with island */
    transform: translateX(-50%);
    z-index: 4;
    animation: errPinBounce 2.6s var(--ease-smooth) infinite;
}

.error-pin-head {
    display: block;
    width: 26px;
    height: 26px;
    margin: 0 auto;
    border-radius: 50% 50% 50% 0;
    transform: rotate(45deg);
    background: radial-gradient(circle at 35% 30%, #ffd79a, var(--err-beacon) 55%, #e08a2a 100%);
    box-shadow:
        0 0 18px var(--err-beacon),
        inset -2px -2px 5px rgba(0, 0, 0, 0.25);
}

.error-pin-head::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 9px;
    width: 9px;
    height: 9px;
    transform: translateX(-50%) rotate(-45deg);
    border-radius: 50%;
    background: var(--err-ink);
}

.error-pin-stick {
    display: block;
    width: 2px;
    height: 14px;
    margin: -2px auto 0;
    background: linear-gradient(180deg, var(--err-beacon), transparent);
}

/* Pulsing landing ring under the pin */
.error-pin-shadow {
    position: absolute;
    left: 50%;
    top: 8px;
    width: 30px;
    height: 10px;
    transform: translateX(-50%);
    border-radius: 50%;
    background: var(--err-beacon);
    opacity: 0.35;
    filter: blur(2px);
    animation: errPinPulse 2.6s ease-out infinite;
}

/*-----------------------------------*\
  #LOST EXPLORER (avatar)
\*-----------------------------------*/

/* Explorer drifts in the top-right of the stage, clear of the digits. */
.error-explorer {
    position: absolute;
    /* inset from the clip edge so the ±18px roam never crosses it */
    top: 22px;
    right: 22px;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    animation: errExplorerRoam 14s ease-in-out infinite;
}

.error-explorer img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.15);
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    box-shadow:
        0 8px 24px rgba(8, 10, 18, 0.55),
        0 0 0 6px rgba(79, 124, 255, 0.08);
    filter: grayscale(0.2);
}

.error-explorer-tag {
    font-family: var(--ff-mono);
    font-size: 0.6rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--err-beacon);
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(255, 180, 84, 0.1);
    border: 1px solid rgba(255, 180, 84, 0.25);
}

/*-----------------------------------*\
  #COPY
\*-----------------------------------*/

.error-copy {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

/* Coordinate eyebrow */
.error-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    width: fit-content;
    font-family: var(--ff-mono);
    font-size: var(--fs-body-md);
    letter-spacing: 0.1em;
    color: #6f9bff;
}

.error-coord {
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    background: rgba(79, 124, 255, 0.08);
    border: 1px solid rgba(79, 124, 255, 0.18);
}

.error-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--err-beacon);
    box-shadow: 0 0 10px var(--err-beacon);
    animation: errBlink 1.6s ease-in-out infinite;
}

.error-headline {
    font-family: var(--ff-display);
    font-size: clamp(2.4rem, 4.4vw, 4rem);
    font-weight: var(--fw-bold);
    line-height: 1.04;
    letter-spacing: -0.02em;
    color: var(--bright-snow);
    margin: 0;
}

.error-headline::after { display: none; }

.error-headline em {
    font-style: normal;
    background: linear-gradient(100deg, var(--primary) 0%, #46c6ff 60%, var(--err-beacon) 130%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.error-desc {
    font-family: var(--ff-body);
    font-size: var(--fs-body-lg);
    font-weight: var(--fw-semibold);
    color: var(--text-light);
    line-height: var(--body-line-height);
    max-width: 46ch;
    margin: 0;
}

/*-----------------------------------*\
  #ACTIONS
\*-----------------------------------*/

.error-actions {
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
    margin-top: var(--space-xs);
}

.error-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    font-family: var(--ff-display);
    font-size: var(--fs-body-lg);
    font-weight: var(--fw-bold);
    letter-spacing: 0.01em;
    text-decoration: none;
    padding: 14px var(--space-xl);
    border-radius: var(--radius-md);
    transition:
        transform var(--motion-sm) var(--ease-standard),
        box-shadow var(--motion-sm) var(--ease-standard),
        background var(--motion-sm) var(--ease-standard),
        border-color var(--motion-sm) var(--ease-standard);
}

.error-btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.error-btn--primary {
    color: #fff;
    background: var(--primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.error-btn--primary:hover {
    opacity: 1;
    transform: translateY(-1px);
    background: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.error-btn--ghost {
    color: var(--bright-snow);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.16);
}

.error-btn--ghost:hover {
    opacity: 1;
    border-color: rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.07);
    transform: translateY(-2px);
}

/*-----------------------------------*\
  #QUICK ROUTES
\*-----------------------------------*/

.error-routes {
    list-style: none;
    display: flex;
    flex-direction: column;
    margin: var(--space-sm) 0 0;
    border-top: 1px solid var(--glass-border);
}

.error-routes li {
    border-bottom: 1px solid var(--glass-border);
}

.error-routes a {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-xs);
    font-family: var(--ff-body);
    font-size: var(--fs-body-md);
    font-weight: var(--fw-semibold);
    color: var(--text-light);
    transition:
        color var(--motion-sm) var(--ease-standard),
        padding var(--motion-sm) var(--ease-standard);
}

.error-routes a:hover {
    opacity: 1;
    color: var(--bright-snow);
    padding-left: var(--space-md);
}

.error-route-icon {
    color: var(--primary);
    font-size: 0.7rem;
    transition: color var(--motion-sm) var(--ease-standard);
}

.error-routes a:hover .error-route-icon {
    color: var(--err-beacon);
}

/*-----------------------------------*\
  #REVEAL (CSS-only stagger)
\*-----------------------------------*/

/* Reveal is opt-in only when motion is allowed, so copy is never stuck
   invisible if the animation can't run. */
@media (prefers-reduced-motion: no-preference) {
    .error-copy .reveal {
        opacity: 0;
        transform: translateY(20px);
        animation: errRevealUp var(--motion-lg) var(--ease-smooth) forwards;
    }

    .error-copy .reveal:nth-child(1) { animation-delay: 80ms; }
    .error-copy .reveal:nth-child(2) { animation-delay: 180ms; }
    .error-copy .reveal:nth-child(3) { animation-delay: 300ms; }
    .error-copy .reveal:nth-child(4) { animation-delay: 420ms; }
    .error-copy .reveal:nth-child(5) { animation-delay: 540ms; }
}

/*-----------------------------------*\
  #ANIMATIONS
\*-----------------------------------*/

@keyframes errAurora {
    0%   { transform: translate(0, 0) scale(1); }
    100% { transform: translate(3%, 4%) scale(1.08); }
}

@keyframes errTwinkle {
    0%, 100% { opacity: 0.15; }
    50%       { opacity: 0.9; }
}

@keyframes errStarDrift {
    from { transform: translateX(0); }
    to   { transform: translateX(var(--drift)); }
}

@keyframes errBob {
    0%, 100% { transform: translate3d(var(--px), calc(var(--py) - 8px), 0); }
    50%       { transform: translate3d(var(--px), calc(var(--py) + 8px), 0); }
}

@keyframes errIslandBob {
    0%, 100% { transform: translateY(0) rotate(-1deg); }
    50%       { transform: translateY(-12px) rotate(1deg); }
}

@keyframes errSpin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

@keyframes errRing {
    from { transform: translate(-50%, -50%) rotate(-22deg); }
    to   { transform: translate(-50%, -50%) rotate(338deg); }
}

@keyframes errPinBounce {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50%       { transform: translateX(-50%) translateY(-7px); }
}

@keyframes errPinPulse {
    0%   { transform: translateX(-50%) scale(0.6); opacity: 0.45; }
    100% { transform: translateX(-50%) scale(1.6); opacity: 0; }
}

/* Roam drifts down-and-inward from the top-right corner — kept off the
   right/top clip edge so it never pokes out on a narrow stage. */
@keyframes errExplorerRoam {
    0%   { transform: translate(0, 0) rotate(-4deg); }
    25%  { transform: translate(-14px, 10px) rotate(3deg); }
    50%  { transform: translate(-4px, 16px) rotate(-2deg); }
    75%  { transform: translate(-10px, 6px) rotate(4deg); }
    100% { transform: translate(0, 0) rotate(-4deg); }
}

@keyframes errBlink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.2; }
}

@keyframes errRevealUp {
    to { opacity: 1; transform: none; }
}

/*-----------------------------------*\
  #RESPONSIVE
\*-----------------------------------*/

@media (max-width: 1024px) {
    .error-container {
        grid-template-columns: 1fr;
        gap: var(--space-xl);
        padding-top: var(--space-xl);
        padding-bottom: var(--space-xl);
        text-align: center;
    }

    /* Single column: reset the explicit row pin so the two blocks auto-flow
       into separate stacked rows instead of colliding in one cell. */
    .error-copy,
    .error-scene {
        grid-column: 1;
        grid-row: auto;
    }

    /* Stacked: scene gets its own band above the copy. */
    .error-scene {
        order: -1;
        min-height: 340px;
        padding-block: var(--space-lg);
    }

    .error-eyebrow,
    .error-copy .error-desc {
        margin-left: auto;
        margin-right: auto;
    }

    .error-actions,
    .error-routes {
        justify-content: center;
    }

    .error-routes a { justify-content: center; }
    .error-routes a:hover { padding-left: var(--space-xs); }
}

@media (max-width: 768px) {
    .error-scene { min-height: 280px; }

    /* The stage + clamp()-sized pieces scale on their own; just trim the
       avatar a touch so it stays clear of the digits on narrow screens. */
    .error-explorer img { width: 48px; height: 48px; }
}

@media (max-width: 576px) {
    .error-actions { flex-direction: column; }

    .error-btn {
        justify-content: center;
        width: 100%;
    }

    .error-explorer { right: 0; }
    .error-island--far { display: none; }
}

/*-----------------------------------*\
  #ACCESSIBILITY — honour reduced motion
\*-----------------------------------*/

@media (prefers-reduced-motion: reduce) {
    .error-aurora,
    .error-star,
    .error-scene-float,
    .error-island,
    .error-orb,
    .error-num--orb::after,
    .error-pin,
    .error-pin-shadow,
    .error-explorer,
    .error-dot {
        animation: none !important;
    }
}
