/*
 * CX Spatial Architecture — shared 2030 interface layer
 * Loaded after cx-system.css so existing page mechanics stay intact.
 */

:root {
    --cx-bg: #030405;
    --cx-void: #010203;
    --cx-graphite: #080a0c;
    --cx-panel: rgba(8, 10, 12, 0.66);
    --cx-panel-deep: rgba(4, 6, 8, 0.88);
    --cx-text: rgba(247, 245, 239, 0.96);
    --cx-muted: rgba(210, 216, 220, 0.62);
    --cx-gold: #d7b56d;
    --cx-gold-bright: #f0d395;
    --cx-ice: #b9d8ed;
    --cx-line: rgba(240, 235, 222, 0.13);
    --cx-line-bright: rgba(240, 235, 222, 0.24);
    --cx-spatial-x: 68vw;
    --cx-spatial-y: 34vh;
    --cx-spatial-radius: clamp(18px, 2vw, 32px);
    --cx-spatial-ease: cubic-bezier(0.16, 1, 0.3, 1);
}

html {
    color-scheme: dark;
    background: var(--cx-void);
}

body.cx-page {
    background:
        radial-gradient(circle at var(--cx-spatial-x) var(--cx-spatial-y), rgba(215, 181, 109, 0.045), transparent 26rem),
        linear-gradient(145deg, #050608 0%, #020304 58%, #060707 100%);
    color: var(--cx-text);
}

body.cx-page::before {
    z-index: 400;
    opacity: 0.026;
    background-image:
        url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
    background-size: 180px 180px;
    mix-blend-mode: soft-light;
}

::selection {
    background: rgba(215, 181, 109, 0.3);
    color: #fff;
}

.cx-spatial-chrome {
    position: fixed;
    inset: 0;
    z-index: 8;
    overflow: hidden;
    pointer-events: none;
}

.cx-spatial-grid {
    position: absolute;
    inset: 0;
    opacity: 0.18;
    background-image:
        linear-gradient(rgba(226, 233, 238, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(226, 233, 238, 0.03) 1px, transparent 1px);
    background-size: clamp(64px, 7vw, 112px) clamp(64px, 7vw, 112px);
    mask-image: radial-gradient(circle at var(--cx-spatial-x) var(--cx-spatial-y), #000 0, transparent 67%);
}

.cx-spatial-pointer-light {
    position: absolute;
    left: var(--cx-spatial-x);
    top: var(--cx-spatial-y);
    width: clamp(300px, 34vw, 640px);
    aspect-ratio: 1;
    border-radius: 50%;
    opacity: 0.26;
    transform: translate(-50%, -50%);
    background: radial-gradient(circle, rgba(215, 181, 109, 0.14), rgba(185, 216, 237, 0.035) 32%, transparent 68%);
    filter: blur(12px);
    transition: opacity 600ms ease;
}

.cx-spatial-coordinates {
    position: absolute;
    top: 50%;
    right: 8px;
    display: flex;
    align-items: center;
    gap: 9px;
    transform: translateY(-50%) rotate(90deg);
    transform-origin: center;
    color: rgba(238, 238, 232, 0.26);
    font: 500 0.52rem/1 var(--cx-mono, monospace);
    letter-spacing: 0.22em;
    text-transform: uppercase;
}

.cx-spatial-coordinates::before {
    content: "";
    width: 38px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--cx-gold));
}

.cx-page .cx-topbar {
    top: clamp(22px, 3.5vh, 38px);
    left: var(--cx-page-pad);
    right: var(--cx-page-pad);
    z-index: 310;
}

.cx-page .cx-brand {
    position: relative;
    min-width: 44px;
    min-height: 44px;
}

.cx-page .cx-logo {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
    border-color: rgba(215, 181, 109, 0.76);
    background:
        linear-gradient(135deg, rgba(215, 181, 109, 0.1), transparent 58%),
        rgba(3, 5, 6, 0.78);
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.08),
        0 0 0 7px rgba(215, 181, 109, 0.025),
        0 0 34px rgba(215, 181, 109, 0.14);
}

.cx-page .cx-logo::before {
    content: "";
    position: absolute;
    inset: -8px;
    border: 1px solid rgba(215, 181, 109, 0.08);
    transform: scale(0.94);
    transition: transform 650ms var(--cx-spatial-ease), border-color 650ms ease;
}

.cx-page .cx-brand:hover .cx-logo::before {
    border-color: rgba(215, 181, 109, 0.24);
    transform: scale(1.06);
}

.cx-page .cx-brand-name strong {
    font-weight: 750;
    letter-spacing: 0.24em;
}

.cx-page .cx-brand-name small {
    color: rgba(210, 216, 220, 0.42);
    font-family: var(--cx-mono, monospace);
    font-size: 0.68rem;
    letter-spacing: 0.055em;
}

.cx-page .cx-actions {
    position: relative;
    height: 50px;
    padding: 0.35rem 0.45rem;
    border-color: rgba(240, 235, 222, 0.14);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent),
        rgba(3, 5, 7, 0.62);
    box-shadow:
        0 22px 70px rgba(0, 0, 0, 0.34),
        inset 0 1px 0 rgba(255, 255, 255, 0.055);
    backdrop-filter: blur(30px) saturate(1.15);
}

.cx-page .cx-actions::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    opacity: 0.42;
    background: linear-gradient(105deg, transparent 12%, rgba(240, 211, 149, 0.22), transparent 38%);
    pointer-events: none;
    mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    mask-composite: exclude;
}

.cx-page .cx-link,
.cx-page .cx-sound {
    color: rgba(236, 236, 230, 0.56);
    font-weight: 750;
    transition:
        color 360ms var(--cx-spatial-ease),
        background 360ms var(--cx-spatial-ease),
        transform 360ms var(--cx-spatial-ease);
}

.cx-page .cx-link:hover,
.cx-page .cx-link[aria-current="page"],
.cx-page .cx-sound:hover {
    color: #fff;
    background: rgba(215, 181, 109, 0.075);
}

.cx-page .cx-link[aria-current="page"]::after {
    background: linear-gradient(90deg, transparent, var(--cx-gold) 22% 78%, transparent);
    box-shadow: 0 0 14px rgba(215, 181, 109, 0.45);
}

.cx-page .cx-sound {
    border-color: rgba(215, 181, 109, 0.18);
    color: var(--cx-gold-bright);
}

.cx-menu-toggle {
    display: none;
    position: relative;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    border: 1px solid rgba(240, 235, 222, 0.16);
    border-radius: 50%;
    padding: 0;
    background: rgba(4, 6, 8, 0.72);
    color: #fff;
    cursor: pointer;
    pointer-events: auto;
    backdrop-filter: blur(24px);
}

.cx-menu-toggle span,
.cx-menu-toggle::before,
.cx-menu-toggle::after {
    content: "";
    position: absolute;
    left: 13px;
    width: 16px;
    height: 1px;
    background: currentColor;
    transition: transform 420ms var(--cx-spatial-ease), opacity 250ms ease, top 420ms var(--cx-spatial-ease);
}

.cx-menu-toggle::before {
    top: 15px;
}

.cx-menu-toggle span {
    top: 21px;
}

.cx-menu-toggle::after {
    top: 27px;
}

.cx-menu-toggle[aria-expanded="true"]::before {
    top: 21px;
    transform: rotate(45deg);
}

.cx-menu-toggle[aria-expanded="true"] span {
    opacity: 0;
}

.cx-menu-toggle[aria-expanded="true"]::after {
    top: 21px;
    transform: rotate(-45deg);
}

.cx-page .cx-contact-fab {
    min-height: 44px;
    border-color: rgba(215, 181, 109, 0.26);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent),
        rgba(3, 5, 7, 0.7);
    color: rgba(248, 246, 239, 0.84);
    box-shadow: 0 18px 55px rgba(0, 0, 0, 0.42);
    backdrop-filter: blur(24px);
}

.cx-page .cx-contact-fab::before {
    background: var(--cx-gold-bright);
    box-shadow: 0 0 16px rgba(215, 181, 109, 0.82);
}

.cx-mobile-dock {
    display: none;
}

.cx-spatial-intro {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: #010203;
    color: #fff;
    transition: opacity 700ms ease, visibility 700ms ease;
}

.cx-spatial-intro::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: min(76vw, 920px);
    height: 1px;
    transform: translate(-50%, -50%) scaleX(0);
    transform-origin: left;
    background: linear-gradient(90deg, transparent, var(--cx-gold-bright) 18% 82%, transparent);
    box-shadow: 0 0 32px rgba(215, 181, 109, 0.42);
    animation: cx-intro-line 1150ms 140ms var(--cx-spatial-ease) both;
}

.cx-spatial-intro__mark {
    position: relative;
    display: grid;
    place-items: center;
    width: 76px;
    aspect-ratio: 1;
    border: 1px solid rgba(215, 181, 109, 0.72);
    transform: rotate(45deg) scale(0.72);
    background: #020304;
    box-shadow: 0 0 70px rgba(215, 181, 109, 0.12);
    opacity: 0;
    animation: cx-intro-mark 850ms 420ms var(--cx-spatial-ease) forwards;
}

.cx-spatial-intro__mark span {
    transform: rotate(-45deg);
    font: 650 1rem/1 var(--cx-display);
    letter-spacing: 0.12em;
}

.cx-spatial-intro__mark b {
    color: var(--cx-gold-bright);
}

.cx-spatial-intro__label {
    position: absolute;
    top: calc(50% + 72px);
    left: 50%;
    transform: translateX(-50%);
    color: rgba(235, 235, 230, 0.42);
    font: 500 0.55rem/1 var(--cx-mono);
    letter-spacing: 0.3em;
    text-transform: uppercase;
    white-space: nowrap;
    opacity: 0;
    animation: cx-intro-label 600ms 650ms ease forwards;
}

.cx-spatial-intro.is-complete {
    opacity: 0;
    visibility: hidden;
}

@keyframes cx-intro-line {
    0% { transform: translate(-50%, -50%) scaleX(0); opacity: 0; }
    20% { opacity: 1; }
    100% { transform: translate(-50%, -50%) scaleX(1); opacity: 0.35; }
}

@keyframes cx-intro-mark {
    to { opacity: 1; transform: rotate(45deg) scale(1); }
}

@keyframes cx-intro-label {
    to { opacity: 1; }
}

:where(a, button, input, select, textarea):focus-visible {
    outline: 1px solid var(--cx-gold-bright) !important;
    outline-offset: 4px;
}

@media (max-width: 760px) {
    .cx-spatial-grid {
        opacity: 0.1;
        background-size: 72px 72px;
    }

    .cx-spatial-pointer-light,
    .cx-spatial-coordinates {
        display: none;
    }

    .cx-page .cx-topbar {
        top: max(12px, env(safe-area-inset-top));
        left: 16px;
        right: 14px;
        min-height: 52px;
    }

    .cx-page .cx-brand-name {
        display: grid;
    }

    .cx-page .cx-brand-name strong {
        font-size: 0.7rem;
        letter-spacing: 0.2em;
    }

    .cx-page .cx-brand-name small {
        display: none;
    }

    .cx-page .cx-logo {
        width: 34px;
        height: 34px;
        flex-basis: 34px;
    }

    .cx-menu-toggle {
        display: block;
        margin-left: auto;
    }

    .cx-page .cx-actions {
        position: fixed;
        z-index: 309;
        top: calc(max(12px, env(safe-area-inset-top)) + 56px);
        right: 12px;
        left: 12px;
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        width: auto;
        height: auto;
        max-width: none;
        padding: 12px;
        border-radius: 22px;
        opacity: 0;
        visibility: hidden;
        transform: translateY(-14px) scale(0.97);
        transform-origin: top;
        pointer-events: none;
        transition:
            opacity 280ms ease,
            visibility 280ms ease,
            transform 430ms var(--cx-spatial-ease);
    }

    body.cx-menu-open.cx-page .cx-actions {
        opacity: 1;
        visibility: visible;
        transform: translateY(0) scale(1);
        pointer-events: auto;
    }

    .cx-page .cx-actions .cx-link {
        width: 100%;
        height: 48px;
        min-height: 48px;
        justify-content: flex-start;
        padding: 0 16px;
        border: 1px solid rgba(240, 235, 222, 0.08);
        border-radius: 14px;
        font-size: 0.65rem;
        letter-spacing: 0.13em;
    }

    .cx-page .cx-actions .cx-link[aria-current="page"] {
        border-color: rgba(215, 181, 109, 0.28);
    }

    .cx-page .cx-actions .cx-link[aria-current="page"]::after {
        display: none;
    }

    .cx-page .cx-actions .cx-sound {
        width: 100%;
        min-height: 48px;
        border-radius: 14px;
    }

    .cx-mobile-dock {
        position: fixed;
        z-index: 305;
        right: 12px;
        bottom: max(10px, env(safe-area-inset-bottom));
        left: 12px;
        display: grid;
        grid-template-columns: 1fr 1.24fr 1fr;
        gap: 4px;
        min-height: 62px;
        padding: 5px;
        border: 1px solid rgba(240, 235, 222, 0.13);
        border-radius: 22px;
        background:
            linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent),
            rgba(3, 5, 7, 0.78);
        box-shadow: 0 18px 60px rgba(0, 0, 0, 0.52);
        backdrop-filter: blur(28px) saturate(1.15);
        transition: opacity 280ms ease, transform 420ms var(--cx-spatial-ease);
    }

    body:has(.cx-studio.is-open) .cx-mobile-dock,
    body:has(.cx-lightbox.is-open) .cx-mobile-dock,
    body:has(.cx-gallery-archive[aria-hidden="false"]) .cx-mobile-dock {
        opacity: 0;
        transform: translateY(calc(100% + 24px));
        pointer-events: none;
    }

    .cx-mobile-dock a {
        display: grid;
        place-items: center;
        gap: 4px;
        min-width: 0;
        border-radius: 16px;
        color: rgba(236, 236, 230, 0.56);
        font: 620 0.54rem/1 var(--cx-font);
        letter-spacing: 0.06em;
        text-align: center;
        text-transform: uppercase;
    }

    .cx-mobile-dock a.is-primary {
        background: linear-gradient(135deg, var(--cx-gold-bright), #c6a35e);
        color: #070706;
    }

    .cx-mobile-dock svg {
        width: 18px;
        height: 18px;
        fill: none;
        stroke: currentColor;
        stroke-linecap: round;
        stroke-linejoin: round;
        stroke-width: 1.6;
    }

    .cx-page .cx-contact-fab {
        display: none !important;
    }

    .cx-spatial-intro__mark {
        width: 62px;
    }
}

@media (max-width: 390px) {
    .cx-page .cx-brand-name {
        display: none;
    }

    .cx-page .cx-actions {
        grid-template-columns: 1fr;
    }

    .cx-page .cx-actions .cx-link,
    .cx-page .cx-actions .cx-sound {
        min-height: 44px;
        height: 44px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cx-spatial-intro {
        display: none;
    }

    .cx-spatial-pointer-light {
        display: none;
    }

    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
    }
}
