/*
 * D2 — Cinematic Vault Gravity (reusable animated background system)
 * ---------------------------------------------------------------------------
 * Source of truth: design-variants/D2-accounting-variant-G-cinematic-vault.html
 * ("Variant G — Cinematic Vault Gravity"). This file extracts that prototype's
 * .vault-stage mechanic into a drop-in component that any section, on any of
 * the four site pages, can use behind its own real content — themed with the
 * accounting, marketing OR web icon set (not accounting-only).
 *
 * ============================================================================
 * MARKUP CONTRACT (read this before wiring the component into a page)
 * ============================================================================
 *
 * Minimal instance, used as a BACKDROP behind real section content:
 *
 *   <section style="position:relative;">
 *     <div class="vault-bg" data-vault-folder="uctovnictvo" data-vault-icons='[
 *       "01-calculator-centered.png","02-form-document-centered.png",
 *       "03-ledger-book-centered.png","04-bar-chart-centered.png",
 *       "05-pie-chart-centered.png","06-percentage-document-centered.png",
 *       "08-coins-centered.png","09-balance-scale-centered.png"
 *     ]' data-vault-core="07-safe-centered.png"></div>
 *
 *     <div style="position:relative;z-index:1;"> ... real heading/CTA/etc ... </div>
 *   </section>
 *
 * Used as a FULL, self-contained section (the way the prototype's own
 * .vault-stage <main> is composed, e.g. a page hero):
 *
 *   <div class="vault-bg vault-bg--section" data-vault-folder="marketing" data-vault-icons='[...]'>
 *     <div class="vault-sanctuary"> ... real heading/CTA/etc ... </div>
 *   </div>
 *
 * Data attributes (all read by js/d2-vault-background.js):
 *   data-vault-folder   "uctovnictvo" | "marketing" | "web"
 *                        -> maps to images/jsagency/items/<folder>/
 *   data-vault-base      optional override for the base path, default
 *                        "images/jsagency/items/" (root-relative; all four
 *                        pages — index.php, marketing.php, uctovnictvo.php,
 *                        webstranky.php — live at the site root).
 *   data-vault-icons     JSON array of filenames inside that folder, in
 *                        orbit order, e.g. '["01-crown.png","02-globe.png"]'.
 *                        Optional — omit it and hand-write .vault-object
 *                        children instead (see NO-JS FALLBACK below).
 *                        For a MIXED-THEME instance (icons from more than one
 *                        folder, e.g. the hero pulling from accounting +
 *                        marketing + web at once), an entry can instead be an
 *                        object naming its own folder: '[{"folder":"uctovnictvo",
 *                        "file":"01-calculator-centered.png"},{"folder":"marketing",
 *                        "file":"11-growth-chart.png"}, ...]'. Plain-string entries
 *                        keep resolving against data-vault-folder as before, so the
 *                        two forms can be freely mixed in the same array; when every
 *                        entry is an object, data-vault-folder can be omitted.
 *   data-vault-orbit     "rings" opts into a bigger orbit split across a few
 *                        concentric rings (RING_SCALES in the JS) instead of
 *                        the default single ellipse — for a section whose real
 *                        content is tall/busy (e.g. the hero: heading + CTA +
 *                        a card row), where one centered ellipse would look
 *                        cramped. Safe to let it sweep across that content
 *                        because the content is a later sibling in a higher
 *                        stacking context (see MARKUP CONTRACT) and always
 *                        paints over these icons — passing "behind" it just
 *                        means briefly hidden, never visually colliding with
 *                        it. The even per-ring phase spacing + one shared
 *                        speed per ring is what keeps objects from visually
 *                        overlapping EACH OTHER as they move.
 *   data-vault-core      optional filename (same folder) for the centered
 *                        "safe" image inside .vault-safe-core. Omit it and
 *                        only the abstract rotating dial ring shows — this
 *                        keeps the component from forcing an accounting-only
 *                        "safe" icon onto marketing/web sections.
 *
 * Modifier classes:
 *   .vault-bg--section   switches from "absolute backdrop, fills a relative
 *                        ancestor" (the default) to "own full viewport-ish
 *                        section" mode (min-height, its own stacking, like
 *                        the prototype's .vault-stage).
 *
 * Orbiting objects: the prototype's own thesis is "nine real gold objects"
 * (8 orbiters + 1 central safe). 8 is the tuned default (sizes, stagger
 * delays and the no-JS fallback ring below are tuned for up to 8 evenly
 * spaced positions, then CYCLE for any extra items via :nth-child(8n+N),
 * so more than 8 still renders, just re-using the same 8 layout slots).
 *
 * ============================================================================
 * NO-JS FALLBACK (requirement: orbiters must be visibly positioned by CSS
 * alone if JS never runs)
 * ============================================================================
 * IMPORTANT: the prototype itself has NO CSS fallback for orbit position —
 * without its <script>, all 8 .orbiter elements sit exactly on top of each
 * other at dead center (left:50%;top:50%, never offset). This file improves
 * on that: :nth-child(1..8) below gives every .vault-object a real static
 * ring position + plausible depth (scale/opacity) approximating one paused
 * animation frame, with zero JS required.
 *
 * That fallback only helps once .vault-object nodes actually exist in the
 * DOM. Two authoring paths:
 *   (a) Hand-write the .vault-object/<img> children directly in the page
 *       HTML (skip data-vault-icons). Guaranteed to render correctly with
 *       CSS alone, JS or no JS — this is the resilient path.
 *   (b) Use data-vault-icons and let JS build the children. Convenient, but
 *       if JS fails to load/execute entirely, no .vault-object nodes exist
 *       and the section shows only the ambient vault atmosphere/architecture/
 *       core (still a full, presentable gradient backdrop — just without the
 *       orbiting icons). This is the one part of the effect that cannot be
 *       fully "no-JS safe" when the JSON-driven convenience path is used;
 *       call it out to whoever wires a page section in and let them pick (a)
 *       if strict no-JS parity for that specific section matters more than
 *       markup convenience.
 */

.vault-bg {
    /* Palette: kept close to the prototype's own near-black/gold system,
       already in the site's gold hue family (compare css/premium.css
       :root --accent: #c9a255). Scoped under .vault-bg, not :root, so it
       cannot collide with premium.css tokens (whose --ink is a different
       shade, #0d0d0d, on purpose — this stays local). */
    --vault-ink: #050504;
    --vault-ink-soft: #0b0a08;
    --vault-gold: #c9a255;
    --vault-gold-bright: #f0cf83;
    --vault-gold-pale: #fff0c5;
    --vault-warm-white: #f5f1e8;
    --vault-warm-muted: #c1b7a4;
    --vault-ease: cubic-bezier(.16, 1, .3, 1);
    --tilt-x: 0deg;
    --tilt-y: 0deg;

    /* Default mode: absolutely-positioned backdrop. Wrap in a
       position:relative section/container and give real content
       position:relative;z-index:1 (see MARKUP CONTRACT above). */
    position: absolute;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    isolation: isolate;
    pointer-events: none;
    background:
        radial-gradient(ellipse 72% 86% at 50% 52%, #16120b 0%, #080706 45%, #020202 79%),
        #020202;
    color: var(--vault-warm-white);
}

.vault-bg * { box-sizing: border-box; }

/* Standalone full-section mode, mirroring the prototype's own .vault-stage */
.vault-bg.vault-bg--section {
    position: relative;
    min-height: max(760px, 100svh);
    display: grid;
    place-items: center;
    pointer-events: auto;
}

/* Keep cinematic fade edges opt-in for standalone full-screen vaults.
   Normal section backdrops must meet their neighbors cleanly and keep
   orbiting icons visible at the section edges. */
.vault-bg::before,
.vault-bg::after {
    content: "";
    position: absolute;
    z-index: 20;
    left: 0;
    width: 100%;
    height: clamp(28px, 5vw, 70px);
    pointer-events: none;
    background: linear-gradient(#000 25%, rgba(0, 0, 0, .88));
    display: none;
}

.vault-bg::before { top: 0; }
.vault-bg::after { bottom: 0; transform: rotate(180deg); }

.vault-bg.vault-bg--section::before,
.vault-bg.vault-bg--section::after {
    display: block;
}

.vault-atmosphere,
.vault-architecture,
.vault-orbital-world,
.vault-safe-core {
    position: absolute;
    inset: 0;
}

/* ---------------------------------------------------------------------- */
/* Atmosphere: soft light beam + vignette                                  */
/* ---------------------------------------------------------------------- */

.vault-atmosphere {
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.vault-atmosphere::before {
    content: "";
    position: absolute;
    left: 50%;
    top: -12%;
    width: min(58vw, 900px);
    height: 90%;
    opacity: .82;
    transform: translateX(-50%);
    clip-path: polygon(42% 0, 58% 0, 93% 100%, 7% 100%);
    background: linear-gradient(180deg, rgba(255, 229, 160, .23), rgba(201, 162, 85, .065) 50%, transparent 88%);
    filter: blur(10px);
}

.vault-atmosphere::after {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 50% 49%, transparent 0 29%, rgba(0, 0, 0, .24) 46%, rgba(0, 0, 0, .72) 82%),
        linear-gradient(90deg, rgba(0, 0, 0, .9), transparent 17% 83%, rgba(0, 0, 0, .9));
}

/* ---------------------------------------------------------------------- */
/* Architecture: abstract vault-door leaves + tilted aperture ring.        */
/* Pure geometry/gradients, no imagery — theme-neutral, reused as-is.      */
/* ---------------------------------------------------------------------- */

.vault-architecture {
    z-index: 1;
    pointer-events: none;
    perspective: 1100px;
}

.vault-door {
    position: absolute;
    top: -5%;
    bottom: -5%;
    width: 34%;
    opacity: .92;
    background:
        linear-gradient(90deg, rgba(201, 162, 85, .12), transparent 7% 92%, rgba(201, 162, 85, .12)),
        linear-gradient(145deg, #12100c 0%, #050504 46%, #0d0b08 100%);
    box-shadow: 0 30px 90px rgba(0, 0, 0, .8);
}

.vault-door::before,
.vault-door::after {
    content: "";
    position: absolute;
    inset-block: 7%;
    width: 7px;
    background: linear-gradient(90deg, #17130c, #b78f43 45%, #2f2514 68%, #070604);
    box-shadow: 0 18px 32px rgba(201, 162, 85, .13);
}

.vault-door--left {
    left: -8%;
    transform: rotateY(13deg) translateX(-4%);
    clip-path: polygon(0 0, 100% 7%, 89% 50%, 100% 93%, 0 100%);
}

.vault-door--left::before { right: 18%; }
.vault-door--left::after { right: 28%; opacity: .35; }

.vault-door--right {
    right: -8%;
    transform: rotateY(-13deg) translateX(4%);
    clip-path: polygon(0 7%, 100% 0, 100% 100%, 0 93%, 11% 50%);
}

.vault-door--right::before { left: 18%; }
.vault-door--right::after { left: 28%; opacity: .35; }

.vault-aperture {
    position: absolute;
    left: 50%;
    top: 50%;
    width: min(74vw, 1020px);
    aspect-ratio: 1.65;
    transform: translate(-50%, -50%) rotateX(63deg) rotateZ(-4deg);
    border-radius: 50%;
    border: 1px solid rgba(201, 162, 85, .22);
    box-shadow:
        inset 0 0 0 18px rgba(0, 0, 0, .18),
        inset 0 0 0 19px rgba(201, 162, 85, .055),
        0 32px 70px rgba(0, 0, 0, .7);
}

.vault-aperture::before,
.vault-aperture::after {
    content: "";
    position: absolute;
    border-radius: inherit;
    inset: 8%;
    border: 1px solid rgba(240, 207, 131, .12);
}

.vault-aperture::after {
    inset: 20%;
    border-color: rgba(240, 207, 131, .07);
}

/* ---------------------------------------------------------------------- */
/* Safe core: rotating dial ring + optional centered image                 */
/* ---------------------------------------------------------------------- */

.vault-safe-core {
    z-index: 2;
    display: grid;
    place-items: center;
    pointer-events: none;
    transform: translateZ(-40px);
}

.vault-safe-core::before {
    content: "";
    position: absolute;
    width: min(60vw, 760px);
    aspect-ratio: 1;
    border-radius: 50%;
    background:
        radial-gradient(circle, rgba(201, 162, 85, .12), transparent 42%),
        conic-gradient(from 18deg, transparent, rgba(201, 162, 85, .11), transparent 17%, transparent 51%, rgba(201, 162, 85, .08), transparent 69%);
    -webkit-mask: radial-gradient(circle, transparent 0 47%, #000 48% 49%, transparent 50% 57%, #000 58% 58.5%, transparent 59%);
    mask: radial-gradient(circle, transparent 0 47%, #000 48% 49%, transparent 50% 57%, #000 58% 58.5%, transparent 59%);
    animation: vault-dial 34s linear infinite;
}

.vault-safe-core img {
    width: clamp(290px, 38vw, 560px);
    height: auto;
    opacity: .46;
    filter: contrast(1.16) brightness(.9) drop-shadow(0 38px 35px rgba(0, 0, 0, .9));
    mix-blend-mode: screen;
    display: block;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
}

@keyframes vault-dial { to { transform: rotate(360deg); } }

.vault-bg.is-paused .vault-safe-core::before { animation-play-state: paused; }

/* ---------------------------------------------------------------------- */
/* Orbital world: the orbiting gold icon objects                          */
/* ---------------------------------------------------------------------- */

.vault-orbital-world {
    z-index: 3;
    transform-style: preserve-3d;
    transform: perspective(1200px) rotateX(var(--tilt-x)) rotateY(var(--tilt-y));
    transition: transform .75s var(--vault-ease);
    pointer-events: none;
}

.vault-object {
    --base-opacity: .8;
    --order: 0;
    position: absolute;
    left: 50%;
    top: 50%;
    width: clamp(108px, 12.5vw, 205px);
    aspect-ratio: 1;
    margin: calc(clamp(108px, 12.5vw, 205px) / -2) 0 0 calc(clamp(108px, 12.5vw, 205px) / -2);
    opacity: var(--base-opacity);
    transform-style: preserve-3d;
    will-change: transform, opacity;
}

.vault-object:nth-child(2n) { width: clamp(94px, 10.5vw, 172px); }
.vault-object:nth-child(3n) { width: clamp(86px, 9.3vw, 152px); }

/* "rings" orbit instances (data-vault-orbit="rings", see
   js/d2-vault-background.js) — larger icons than the default orbit, tuned
   for a section big/busy enough to need the multi-ring treatment. */
.vault-bg[data-vault-orbit="rings"] .vault-object {
    width: clamp(96px, 10.5vw, 198px);
    margin: calc(clamp(96px, 10.5vw, 198px) / -2) 0 0 calc(clamp(96px, 10.5vw, 198px) / -2);
}

.vault-bg[data-vault-orbit="rings"] .vault-object:nth-child(2n) {
    width: clamp(84px, 9.1vw, 171px);
    margin: calc(clamp(84px, 9.1vw, 171px) / -2) 0 0 calc(clamp(84px, 9.1vw, 171px) / -2);
}
.vault-bg[data-vault-orbit="rings"] .vault-object:nth-child(3n) {
    width: clamp(75px, 8.1vw, 150px);
    margin: calc(clamp(75px, 8.1vw, 150px) / -2) 0 0 calc(clamp(75px, 8.1vw, 150px) / -2);
}

.vault-asset-shell {
    position: absolute;
    inset: 0;
    transform: scale(1);
    filter: brightness(1.12) contrast(1.08) drop-shadow(0 22px 28px rgba(0, 0, 0, .72));
    transition: transform 1.1s var(--vault-ease), filter 1.15s ease, opacity .9s ease;
    transition-delay: calc(var(--order, 0) * 65ms + 180ms);
}

.vault-asset-shell::after {
    content: "";
    position: absolute;
    z-index: -1;
    left: 15%;
    right: 15%;
    bottom: 3%;
    height: 18%;
    border-radius: 50%;
    background: rgba(201, 162, 85, .2);
    filter: blur(16px);
    transform: translateY(12px) rotateX(68deg);
}

.vault-object img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
    mix-blend-mode: screen;
    -webkit-mask-image: radial-gradient(circle at 50% 50%, #000 0 54%, rgba(0, 0, 0, .94) 65%, transparent 82%);
    mask-image: radial-gradient(circle at 50% 50%, #000 0 54%, rgba(0, 0, 0, .94) 65%, transparent 82%);
}

/* --- No-JS / pre-animation static ring fallback ------------------------
   8 evenly spaced positions (45deg apart) approximating one paused orbit
   frame, incl. plausible depth (scale/opacity), computed from the same
   ellipse (radiusX 42%, radiusY 36%) and depth formula the prototype's own
   JS uses. Cycles via :nth-child(8n+N) so >8 objects still all get placed.
   JS overwrites `transform`/`--base-opacity` inline once it runs, which
   always wins over these class rules regardless of specificity. */
.vault-object:nth-child(8n+1) { left: 92%; top: 50%; --order: 0; transform: translate(-50%, -50%) scale(.93); --base-opacity: .63; }
.vault-object:nth-child(8n+2) { left: 79.7%; top: 75.5%; --order: 1; transform: translate(-50%, -50%) scale(1.1); --base-opacity: .86; }
.vault-object:nth-child(8n+3) { left: 50%; top: 86%; --order: 2; transform: translate(-50%, -50%) scale(1.17); --base-opacity: .96; }
.vault-object:nth-child(8n+4) { left: 20.3%; top: 75.5%; --order: 3; transform: translate(-50%, -50%) scale(1.1); --base-opacity: .86; }
.vault-object:nth-child(8n+5) { left: 8%; top: 50%; --order: 4; transform: translate(-50%, -50%) scale(.93); --base-opacity: .63; }
.vault-object:nth-child(8n+6) { left: 20.3%; top: 24.5%; --order: 5; transform: translate(-50%, -50%) scale(.76); --base-opacity: .4; }
.vault-object:nth-child(8n+7) { left: 50%; top: 14%; --order: 6; transform: translate(-50%, -50%) scale(.69); --base-opacity: .3; }
.vault-object:nth-child(8n) { left: 79.7%; top: 24.5%; --order: 7; transform: translate(-50%, -50%) scale(.76); --base-opacity: .4; }

/* ---------------------------------------------------------------------- */
/* Optional readability vignette for a centered content/CTA zone.          */
/* Mirrors the prototype's .content-sanctuary::before. Purely decorative,  */
/* sits above the orbital world but still inside .vault-bg's own stacking  */
/* (z-index 0 relative to the page) — real content stays a separate        */
/* sibling with its own z-index:1+, per the MARKUP CONTRACT above.         */
/* ---------------------------------------------------------------------- */

.vault-vignette {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 4;
    width: min(76vw, 820px);
    height: min(62vh, 560px);
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: radial-gradient(ellipse, rgba(4, 4, 3, .94) 0 39%, rgba(4, 4, 3, .88) 53%, rgba(4, 4, 3, .48) 69%, transparent 79%);
    pointer-events: none;
}

/* Convenience wrapper for real foreground content placed inside a
   .vault-bg--section instance (see MARKUP CONTRACT). Optional — a
   .vault-bg used purely as a backdrop doesn't need this. */
.vault-sanctuary {
    position: relative;
    z-index: 8;
    display: grid;
    place-items: center;
    width: 100%;
    padding: 120px 24px 105px;
}

@media (max-width: 760px) {
    .vault-bg.vault-bg--section { min-height: max(720px, 100svh); }
    .vault-door { width: 43%; opacity: .75; }
    .vault-door--left { left: -22%; }
    .vault-door--right { right: -22%; }
    .vault-aperture { width: 122vw; }
    .vault-atmosphere::before { width: 110vw; }
    .vault-safe-core img { width: min(84vw, 350px); opacity: .38; }
    .vault-safe-core::before { width: 128vw; }
    .vault-sanctuary { padding: 112px 20px 105px; }
    .vault-vignette { width: 128vw; height: 59vh; }
    .vault-object { width: clamp(76px, 25vw, 104px); margin: calc(clamp(76px, 25vw, 104px) / -2) 0 0 calc(clamp(76px, 25vw, 104px) / -2); }
    .vault-object:nth-child(2n) { width: clamp(68px, 22vw, 92px); }
    .vault-object:nth-child(3n) { width: clamp(62px, 20vw, 84px); }
}

@media (max-height: 720px) and (min-width: 761px) {
    .vault-bg.vault-bg--section { min-height: 680px; }
    .vault-sanctuary { padding-block: 92px; }
}

@media (prefers-reduced-motion: reduce) {
    .vault-bg,
    .vault-bg *,
    .vault-bg *::before,
    .vault-bg *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
}
