/* ==========================================================================
   gateway.css - the Gateway (index.html) only: portal, sigils and emblems, atmosphere,
   echoes, Codex, glimpses, phone layout, reduced motion, quality tiers.
   Loaded after site.css (needs its variables and the #gateway-container base box).
   ========================================================================== */

/* Center Portal */
#portal-area {
    flex: 1;
    display: flex; align-items: center; justify-content: center;
    position: relative;
}

.portal-wrapper {
    text-align: center;
    width: 100%; max-width: 500px;
    z-index: 20;
    /* Apply the slow breathing to the container */
    animation: portal-breath 8s infinite ease-in-out;
}

/* Canvas (body) and SVG (edge, core) share one box and pulse together */
.portal-stage {
    position: relative;
    width: 100%;
    /* Fits the screen's height too, so the orbit has room above and below */
    max-width: min(450px, 40vh, 70vw);
    margin: 0 auto;
    aspect-ratio: 2 / 3;
    animation: heart-pulse 4s infinite cubic-bezier(0.4, 0, 0.2, 1);
}

.portal-svg {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    /* Let the glow draw outside the SVG box */
    overflow: visible !important;
}

/* Extends 75 viewBox units past the SVG box on every side (MARGIN in portal.js), so the
   shifting edge and its flames are never cut off */
#portal-canvas {
    position: absolute;
    left: -18.75%; top: -12.5%;
    width: 137.5%; height: 125%;
    pointer-events: none;
}

/* Breathing Animation: Deep, slow cycle */
@keyframes portal-breath {
    0%, 100% { 
        transform: scale(0.9); 
        filter: brightness(0.8);
    }
    50% { 
        transform: scale(1.1); 
        filter: brightness(1.2);
    }
}

/* Heartbeat Animation: Quick, rhythmic spikes */
@keyframes heart-pulse {
    0%, 100% { transform: scale(1); filter: drop-shadow(0 0 18px var(--fire)); }
    5% { transform: scale(1.07); filter: drop-shadow(0 0 30px var(--fire)); }
    10% { transform: scale(1); }
    15% { transform: scale(1.1); filter: drop-shadow(0 0 40px var(--fire)); }
    25% { transform: scale(1); }
}

/* Lightning is drawn on this canvas by script.js (above the portal, below the buttons) */
#lightning-canvas {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 60;
}

.portal-name {
    position: absolute;
    left: 50%; top: calc(100% - 70px);   /* script.js moves it just below the orbit */
    transform: translate(-50%, -50%);
    width: max-content; max-width: 92%;
    text-align: center;
    font-family: var(--font-fantasy);
    color: var(--gold);
    font-size: 2rem;
    text-shadow: var(--glow-gold);
    z-index: 20;
    pointer-events: none;
}

/* Buttons */
#orbital-nav {
    position: absolute; width: 100%; height: 100%;
    pointer-events: none; top: 0; left: 0;
    z-index: 100; /* Ensure buttons are above everything else */
}

/* Sigils: a medallion per destination, its emblem in the place's colour (--sigil, set on
   each link), its name on a plaque beneath. The link's box is the disc, so script.js
   centres it on the orbit and the lightning lands on its edge. */
.nav-button {
    --sigil: var(--gold);
    position: absolute; pointer-events: auto;
    width: 72px; height: 72px;
    transform: translate(-50%, -50%);
    transition: transform 0.25s ease;
    text-decoration: none;
    color: var(--sigil);
    border-radius: 50%;
    outline: none;
}

/* Larger hit area for easier clicking */
.nav-button::after {
    content: '';
    position: absolute;
    inset: -12px -12px -34px;
    border-radius: 40px;
}

.sigil-disc {
    position: absolute; inset: 0;
    display: grid; place-items: center;
    border-radius: 50%;
    background:
        radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--sigil) 22%, #0b0b1c) 0%, #07071a 62%, #04040c 100%);
    border: 2px solid var(--gold);
    box-shadow:
        inset 0 0 0 4px rgba(5, 5, 14, 0.9),
        inset 0 0 0 5px rgba(255, 215, 0, 0.45),
        inset 0 0 14px color-mix(in srgb, var(--sigil) 45%, transparent),
        0 0 14px rgba(255, 190, 60, 0.45);
    transition: box-shadow 0.35s, border-color 0.35s;
}
.emblem {
    width: 58px; height: 58px;
    overflow: visible;
    filter: drop-shadow(0 0 3px color-mix(in srgb, var(--sigil) 75%, transparent));
}

.sigil-name {
    position: absolute;
    left: 50%; top: calc(100% + 7px);
    transform: translateX(-50%);
    padding: 2px 10px 3px;
    white-space: nowrap;
    font-family: var(--font-fantasy);
    font-size: 0.72rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--gold);
    background: rgba(5, 5, 14, 0.72);
    border: 1px solid rgba(255, 215, 0, 0.35);
    border-radius: 3px;
    text-shadow: 0 0 6px rgba(255, 200, 80, 0.45);
    transition: color 0.3s, border-color 0.3s, box-shadow 0.3s;
}

.nav-button:hover, .nav-button:focus-visible {
    transform: translate(-50%, -50%) scale(1.15);
    z-index: 101;
}
.nav-button:hover .sigil-disc, .nav-button:focus-visible .sigil-disc {
    border-color: color-mix(in srgb, var(--sigil) 55%, var(--gold));
    box-shadow:
        inset 0 0 0 4px rgba(5, 5, 14, 0.9),
        inset 0 0 0 5px color-mix(in srgb, var(--sigil) 70%, transparent),
        inset 0 0 22px color-mix(in srgb, var(--sigil) 65%, transparent),
        0 0 26px color-mix(in srgb, var(--sigil) 70%, transparent);
}
.nav-button:hover .sigil-name, .nav-button:focus-visible .sigil-name {
    color: #fff6d8;
    border-color: color-mix(in srgb, var(--sigil) 70%, transparent);
    box-shadow: 0 0 12px color-mix(in srgb, var(--sigil) 45%, transparent);
}

/* Added by script.js a moment after a bolt hits the sigil: white-hot, then its own colour */
.nav-button.charged .sigil-disc { animation: charge 1.6s ease-out; }
.nav-button.charged .emblem { animation: charge-emblem 1.6s ease-out; }
@keyframes charge {
    0% {
        background: radial-gradient(circle, #ffffff 0%, color-mix(in srgb, var(--sigil) 70%, #fff) 45%, #07071a 100%);
        box-shadow: 0 0 40px 10px rgba(190, 225, 255, 0.95), 0 0 90px 20px rgba(255, 255, 255, 0.5);
    }
    25% {
        box-shadow: inset 0 0 26px color-mix(in srgb, var(--sigil) 90%, transparent), 0 0 34px 8px color-mix(in srgb, var(--sigil) 85%, transparent);
    }
}
@keyframes charge-emblem {
    0% { filter: drop-shadow(0 0 10px #fff) brightness(2); }
    30% { filter: drop-shadow(0 0 8px var(--sigil)) brightness(1.5); }
}

/* --- The emblems --- */
.emblem .faint { fill: none; stroke: currentColor; stroke-width: 1; opacity: 0.35; }
.emblem .dashed { stroke-dasharray: 3 4; }
.emblem .thread { fill: none; stroke: currentColor; stroke-width: 1.1; opacity: 0.55; }
.emblem .core { fill: #fff; }
.emblem .spin-back { stroke: currentColor; stroke-width: 2; stroke-linecap: round; opacity: 0.85; }
.emblem .bubble { fill: color-mix(in srgb, currentColor 30%, transparent); stroke: currentColor; stroke-width: 1.6; }
.emblem .bubble.small { stroke-width: 1.2; }
.emblem .core-bubble { fill: color-mix(in srgb, #ffd24a 45%, transparent); stroke: #ffd24a; stroke-width: 2; }
.emblem .star { fill: #fff6d0; stroke: currentColor; stroke-width: 1; }
.emblem .twinkle { fill: #fff6d0; }
.emblem .crystal { fill: color-mix(in srgb, currentColor 22%, transparent); stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.emblem .facet { fill: none; stroke: currentColor; stroke-width: 1; opacity: 0.6; }
.emblem .glint { stroke: #fff; stroke-width: 3; stroke-linecap: round; opacity: 0; }
.emblem .chain { fill: none; stroke: #d8c08a; stroke-width: 1.6; stroke-dasharray: 2 2.5; }
.emblem .pendant { fill: color-mix(in srgb, currentColor 18%, #120c06); stroke: currentColor; stroke-width: 2; }
.emblem .gem { fill: #ff5a4a; stroke: #ffd0b0; stroke-width: 1; }
/* History: an hourglass, gold sand above and violet below (before and after Event 0), its
   waist bound by a cracked ring that flares now and then (Event 0) */
.emblem .glass { fill: color-mix(in srgb, currentColor 10%, transparent); stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }
.emblem .frame { fill: none; stroke: #ffd24a; stroke-width: 2.6; stroke-linecap: round; }
.emblem .sand-top { fill: #ffd24a; opacity: 0.85; }
.emblem .sand-bottom { fill: #b48cff; opacity: 0.9; }
.emblem .grain { fill: #fff3c4; opacity: 0; }
.emblem .rift { fill: none; stroke: #e9dcff; stroke-width: 1.5; stroke-linecap: round; }
.emblem .crack { fill: none; stroke: #ffffff; stroke-width: 1.2; stroke-linejoin: round; }

/* (with view-box, 0 0 is the centre of the emblem's own coordinates: its viewBox runs -50..50) */
.emblem g, .emblem path, .emblem circle { transform-box: view-box; transform-origin: 0 0; }
.emblem .spin { animation: emblem-spin 16s linear infinite; }
.emblem .spin-slow { animation: emblem-spin 24s linear infinite; }
.emblem .spin-slower { animation: emblem-spin 60s linear infinite; }
.emblem .spin-back { animation: emblem-spin 6s linear infinite reverse; }
.emblem .star { animation: star-pulse 3.2s ease-in-out infinite; }
.emblem .twinkle { animation: twinkle 2.6s ease-in-out infinite; }
.emblem .t2 { animation-delay: -0.5s; } .emblem .t3 { animation-delay: -1.1s; }
.emblem .t4 { animation-delay: -1.7s; } .emblem .t5 { animation-delay: -2.2s; }
.emblem .turn { animation: crystal-turn 5s ease-in-out infinite; }
.emblem .glint { animation: glint 5s ease-in-out infinite; }
.emblem .swing { transform-origin: 0 -36px; animation: swing 4.5s ease-in-out infinite; }
.emblem .gem { animation: gem-pulse 2.4s ease-in-out infinite; }
.emblem .tilt { animation: hourglass-tilt 7s ease-in-out infinite; }
.emblem .grain { animation: grain-fall 1.5s linear infinite; }
.emblem .grain.g2 { animation-delay: -0.5s; } .emblem .grain.g3 { animation-delay: -1s; }
.emblem .rift, .emblem .crack { animation: rift-flare 4.5s ease-in-out infinite; }
.nav-button:hover .emblem .grain { animation-duration: 0.6s; }
.nav-button:hover .emblem .spin, .nav-button:hover .emblem .spin-slow, .nav-button:hover .emblem .spin-back { animation-duration: 5s; }

@keyframes emblem-spin { to { transform: rotate(360deg); } }
@keyframes star-pulse { 50% { transform: scale(1.18) rotate(45deg); } }
@keyframes twinkle { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
@keyframes crystal-turn { 0%, 100% { transform: scaleX(1); } 50% { transform: scaleX(-1); } }
@keyframes glint { 0%, 60%, 100% { opacity: 0; transform: translateX(-30px); } 75% { opacity: 0.8; transform: translateX(0); } 90% { opacity: 0; transform: translateX(30px); } }
@keyframes swing { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } }
@keyframes gem-pulse { 50% { filter: brightness(1.6) drop-shadow(0 0 4px #ff5a4a); } }
@keyframes hourglass-tilt { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }
@keyframes grain-fall { 0% { transform: translateY(-2px); opacity: 0; } 15%, 80% { opacity: 1; } 100% { transform: translateY(20px); opacity: 0; } }
@keyframes rift-flare { 0%, 70%, 100% { opacity: 0.55; } 80% { opacity: 1; filter: drop-shadow(0 0 4px #c79bff) brightness(1.8); } }

@media (prefers-reduced-motion: reduce) {
    .emblem * { animation: none !important; }
    .nav-button.charged .sigil-disc, .nav-button.charged .emblem { animation: none; }
}


/* ==========================================================================
   Atmosphere (astral.js)
   ========================================================================== */
/* Cosmic winds, blue lights and the dark mist at the edge: behind the portal */
#astral-canvas {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 0;
}

/* Void tendrils: over the sea, under the portal (z-index 20) */
#void-canvas {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 15;
}


/* ==========================================================================
   Echoes (echoes.js): lore told by a voice outside time, condensed out of the
   sea's light. Above the sea, under the tendrils' canvas (z-index 15) so the
   void can reach over them, and under the portal (20); opened, above it.
   ========================================================================== */
.echoes {
    position: absolute; inset: 0;
    pointer-events: none;
}

.echo {
    --echo-ink: #dcebff;
    --echo-glow: 0 0 10px rgba(110, 180, 255, 0.55), 0 0 2px rgba(190, 225, 255, 0.6);
    position: absolute;
    z-index: 12;
    width: min(320px, 78vw);
    box-sizing: border-box;
    padding: 12px 16px;
    border-radius: 12px;
    pointer-events: auto;
    color: var(--echo-ink);
    text-shadow: var(--echo-glow);
    cursor: default;
    transform: translate(var(--shift-x, 0px), var(--shift-y, 0px));
    transition: background 0.45s, box-shadow 0.45s, width 0.45s, transform 0.45s;
}
.echo-title {
    font-family: var(--font-fantasy);
    font-size: 0.78rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: #9fd0ff;
    margin-bottom: 6px;
}
.echo-text {
    margin: 0;
    font-family: var(--font-body);
    font-style: italic;
    font-size: 1.08rem;
    line-height: 1.45;
}
.echo .w { display: inline-block; }
.echo.narrow { padding: 10px 12px; }
.echo.narrow .echo-text { font-size: 0.98rem; }
.echo.narrow .echo-title { font-size: 0.72rem; letter-spacing: 0.14em; }

/* Opened: held still, and the rest of it shown */
.echo-more {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.5;
    color: #c8daf2;
    transition: max-height 0.6s ease, opacity 0.5s ease 0.1s;
}
.echo-more p { margin: 10px 0 0; }
.echo.held {
    z-index: 30;
    width: min(400px, 88vw) !important;
    background: rgba(5, 9, 26, 0.86);
    box-shadow: 0 0 0 1px rgba(130, 190, 255, 0.35), 0 0 34px rgba(70, 140, 255, 0.28);
}
.echo.held .echo-more { max-height: 22em; opacity: 1; }

/* The sea's light condensing into the words */
@keyframes echo-condense {
    0%   { opacity: 0; filter: blur(8px); transform: translate(var(--fx), var(--fy)) scale(1.35);
           text-shadow: 0 0 22px rgba(160, 215, 255, 1); }
    55%  { opacity: 1; filter: blur(1.5px); text-shadow: 0 0 16px rgba(160, 215, 255, 0.95); }
    100% { opacity: 1; filter: none; transform: none; text-shadow: var(--echo-glow); }
}
.echo.forming .w { animation: echo-condense 1.15s cubic-bezier(0.2, 0.7, 0.2, 1) var(--d) both; }

/* Coming apart again, carried off by the wind */
.echo .w { transition: opacity 1.1s ease var(--sd), transform 1.3s ease-out var(--sd), filter 1.1s ease var(--sd); }
.echo.fading .w { opacity: 0; transform: translate(var(--sx), var(--sy)); filter: blur(5px); }
.echo.fading.eaten .w { transition-duration: 0.45s; transition-delay: 0s; }

/* Eaten by the void: dark holes open and spread, edged in violet */
.echo.voiding {
    /* the holes start small and spread faster towards the end of the bite */
    --k: calc(var(--void) * var(--void));
    --r1: calc(var(--void) * 25% + var(--k) * 110% - 8%);
    --r2: calc(var(--void) * 20% + var(--k) * 95% - 8%);
    --r3: calc(var(--void) * 25% + var(--k) * 120% - 8%);
    --r4: calc(var(--void) * 20% + var(--k) * 105% - 8%);
    -webkit-mask-image:
        radial-gradient(circle at var(--x1) var(--y1), transparent var(--r1), #000 calc(var(--r1) + 7%)),
        radial-gradient(circle at var(--x2) var(--y2), transparent var(--r2), #000 calc(var(--r2) + 7%)),
        radial-gradient(circle at var(--x3) var(--y3), transparent var(--r3), #000 calc(var(--r3) + 7%)),
        radial-gradient(circle at var(--x4) var(--y4), transparent var(--r4), #000 calc(var(--r4) + 7%));
            mask-image:
        radial-gradient(circle at var(--x1) var(--y1), transparent var(--r1), #000 calc(var(--r1) + 7%)),
        radial-gradient(circle at var(--x2) var(--y2), transparent var(--r2), #000 calc(var(--r2) + 7%)),
        radial-gradient(circle at var(--x3) var(--y3), transparent var(--r3), #000 calc(var(--r3) + 7%)),
        radial-gradient(circle at var(--x4) var(--y4), transparent var(--r4), #000 calc(var(--r4) + 7%));
    -webkit-mask-composite: source-in;
            mask-composite: intersect;
    filter: saturate(calc(1 - var(--void) * 0.7));
}
.echo.voiding::after {
    content: '';
    position: absolute; inset: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at var(--x1) var(--y1), transparent calc(var(--r1) + 1%), rgba(160, 110, 255, 0.85) calc(var(--r1) + 4%), transparent calc(var(--r1) + 11%)),
        radial-gradient(circle at var(--x2) var(--y2), transparent calc(var(--r2) + 1%), rgba(160, 110, 255, 0.85) calc(var(--r2) + 4%), transparent calc(var(--r2) + 11%)),
        radial-gradient(circle at var(--x3) var(--y3), transparent calc(var(--r3) + 1%), rgba(160, 110, 255, 0.85) calc(var(--r3) + 4%), transparent calc(var(--r3) + 11%)),
        radial-gradient(circle at var(--x4) var(--y4), transparent calc(var(--r4) + 1%), rgba(160, 110, 255, 0.85) calc(var(--r4) + 4%), transparent calc(var(--r4) + 11%));
}

@media (prefers-reduced-motion: reduce) {
    .echo .w, .echo.forming .w { animation: none; transition: none; }
    .echo { transition: opacity 0.8s; }
    .echo.forming { opacity: 0; animation: echo-appear 0.8s ease forwards; }
    .echo.fading { opacity: 0; }
    .echo.fading .w { opacity: 1; transform: none; filter: none; }
}
@keyframes echo-appear { to { opacity: 1; } }

/* ---------- Codex ---------- */
.codex-toggle {
    position: absolute;
    left: 22px; bottom: 20px;
    z-index: 110;
    display: flex; align-items: center; gap: 10px;
    padding: 8px 16px 8px 12px;
    background: rgba(5, 9, 26, 0.55);
    border: 1px solid rgba(255, 215, 0, 0.35);
    border-radius: 999px;
    color: var(--gold);
    font-family: var(--font-fantasy);
    font-size: 0.8rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.3s, border-color 0.3s, box-shadow 0.3s;
}
.codex-toggle:hover, .codex-toggle:focus-visible {
    background: rgba(255, 215, 0, 0.12);
    border-color: var(--gold);
    box-shadow: 0 0 18px rgba(255, 190, 60, 0.35);
    outline: none;
}
.codex-glyph {
    width: 14px; height: 14px;
    border-radius: 50%;
    border: 1.5px solid currentColor;
    box-shadow: inset 0 0 0 3px rgba(5, 9, 26, 0.9), inset 0 0 0 5px rgba(255, 215, 0, 0.6);
}

.codex {
    position: absolute; inset: 0;
    z-index: 120;
    display: flex; align-items: center; justify-content: center;
    background: rgba(2, 2, 6, 0.6);
    backdrop-filter: blur(3px);
}
.codex[hidden] { display: none; }
.codex-sheet {
    position: relative;
    width: min(680px, 92vw);
    max-height: 84vh;
    overflow-y: auto;
    box-sizing: border-box;
    padding: 34px 38px 30px;
    background: rgba(6, 10, 28, 0.94);
    border: 1px solid rgba(255, 215, 0, 0.3);
    border-radius: 14px;
    box-shadow: 0 0 60px rgba(60, 120, 255, 0.18);
    color: var(--text-color);
}
.codex-sheet h2 {
    margin: 0 0 6px;
    font-family: var(--font-fantasy);
    color: var(--gold);
    letter-spacing: 0.12em;
    font-weight: 400;
}
.codex-lead { margin: 0 0 22px; color: #9fb6d8; font-style: italic; }
.codex-entry { margin-bottom: 18px; }
.codex-entry h3 {
    margin: 0 0 4px;
    font-family: var(--font-fantasy);
    font-size: 0.85rem;
    font-weight: 400;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: #9fd0ff;
}
.codex-entry p { margin: 0; line-height: 1.55; color: #d6e2f3; }
.codex-close {
    position: absolute; top: 12px; right: 14px;
    width: 34px; height: 34px;
    background: none; border: 1px solid rgba(255, 215, 0, 0.3); border-radius: 50%;
    color: var(--gold); font-size: 1.3rem; line-height: 1;
    cursor: pointer;
}
.codex-close:hover, .codex-close:focus-visible { background: rgba(255, 215, 0, 0.12); outline: none; }


/* ==========================================================================
   Glimpses (glimpses.js): small rifts showing other places. Over the echoes,
   under the void tendrils (15), so a tendril can reach one.
   ========================================================================== */
.glimpse-canvas {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 13;
}
.glimpse-captions {
    position: absolute; inset: 0;
    pointer-events: none;
    z-index: 13;
}
.glimpse-caption {
    position: absolute;
    transform: translate(-50%, 0);
    font-family: var(--font-fantasy);
    font-size: 0.72rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    white-space: nowrap;
    opacity: 0;
    text-shadow: 0 0 10px currentColor;
    transition: opacity 0.8s ease;
}
.glimpse-caption.shown { opacity: 0.85; }


/* ==========================================================================
   Phones and narrow screens: the title at the top, a band under it for one echo
   at a time, a smaller portal lower down, smaller sigils, the Codex as a glyph
   ========================================================================== */
@media (max-width: 600px) {
    #portal-area { padding-top: 20vh; box-sizing: border-box; }
    .portal-stage { max-width: min(52vw, 32vh); }
    .portal-name { font-size: 1.15rem; max-width: 86vw; white-space: normal; line-height: 1.2; }

    .nav-button { width: 56px; height: 56px; }
    .emblem { width: 44px; height: 44px; }
    .sigil-name { font-size: 0.6rem; letter-spacing: 0.12em; padding: 1px 7px 2px; top: calc(100% + 5px); }
    .nav-button::after { inset: -10px -10px -28px; }

    .codex-toggle { left: 14px; bottom: 14px; padding: 9px; gap: 0; }
    .codex-toggle span:last-child { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
    .codex-sheet { padding: 28px 22px 22px; }

    .echo { padding: 10px 12px; }
    .echo-text { font-size: 1rem; }
}

/* ==========================================================================
   Reduced motion: no breathing or heartbeat on the portal
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    .portal-wrapper, .portal-stage { animation: none; }
    .portal-stage { filter: drop-shadow(0 0 18px var(--fire)); }
}


/* ==========================================================================
   Gateway by visual quality tier (html[data-quality], fx-quality.js)
   ========================================================================== */
/* Balanced and Light: the portal's drop-shadow is re-blurred every frame (its canvas
   changes every frame), so it becomes a soft glow behind the portal that pulses with
   the same heartbeat. The breathing and the heartbeat's movement stay. */
html[data-quality="balanced"] .portal-stage,
html[data-quality="light"] .portal-stage { animation-name: heart-pulse-lite; }
@keyframes heart-pulse-lite {
    0%, 100% { transform: scale(1); }
    5% { transform: scale(1.07); }
    10% { transform: scale(1); }
    15% { transform: scale(1.1); }
    25% { transform: scale(1); }
}
html[data-quality="balanced"] .portal-stage::before,
html[data-quality="light"] .portal-stage::before {
    content: '';
    position: absolute;
    left: -12%; right: -12%; top: 50%;
    aspect-ratio: 1;
    transform: translateY(-50%);
    border-radius: 50%;
    background: radial-gradient(closest-side, var(--fire) 72%, rgba(255, 150, 40, 0) 100%);
    opacity: 0.45;
    pointer-events: none;
    animation: fire-glow 4s infinite cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes fire-glow {
    0%, 100% { opacity: 0.45; }
    5% { opacity: 0.7; }
    10% { opacity: 0.5; }
    15% { opacity: 0.85; }
    25% { opacity: 0.45; }
}
/* Light: no blur behind the Codex */
html[data-quality="light"] .codex { backdrop-filter: none; background: rgba(2, 2, 6, 0.8); }

/* Still: the same as the reduced-motion rules above */
html[data-quality="still"] .emblem * { animation: none !important; }
html[data-quality="still"] .nav-button.charged .sigil-disc,
html[data-quality="still"] .nav-button.charged .emblem { animation: none; }
html[data-quality="still"] .echo .w,
html[data-quality="still"] .echo.forming .w { animation: none; transition: none; }
html[data-quality="still"] .echo { transition: opacity 0.8s; }
html[data-quality="still"] .echo.forming { opacity: 0; animation: echo-appear 0.8s ease forwards; }
html[data-quality="still"] .echo.fading { opacity: 0; }
html[data-quality="still"] .echo.fading .w { opacity: 1; transform: none; filter: none; }
html[data-quality="still"] .portal-wrapper,
html[data-quality="still"] .portal-stage { animation: none; }
html[data-quality="still"] .portal-stage { filter: drop-shadow(0 0 18px var(--fire)); }

