/* ==========================================================================
   darwnlinz OS — shared surface layer

   Loaded by /, /ClaudeRouter/ and /tradiem2026/ so the three surfaces read as
   one shell: same tokens, same dock, same entry/exit transition, same 3D
   substrate. Self-contained on purpose — the ClaudeRouter SPA ships its own
   variable set and a strict `style-src 'self'` CSP, so nothing here may rely
   on a page-level stylesheet or an injected <style> tag.

   Loaded before each surface's own CSS, so a surface can still override.
   ========================================================================== */

:root {
    /* One motion vocabulary for all three surfaces. */
    --nx-ease: cubic-bezier(0.2, 0, 0.2, 1);
    --nx-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --nx-ease-spring: cubic-bezier(0.34, 1.42, 0.5, 1);
    --nx-dur-fast: 140ms;
    --nx-dur: 260ms;
    --nx-dur-slow: 480ms;

    /* Fallback palette. Surfaces that define their own tokens win, because
       every consumer below reads `var(--token, var(--nx-token))`. */
    --nx-bg: #0a0d12;
    --nx-panel: rgba(16, 21, 27, 0.74);
    --nx-border: #2b343f;
    --nx-border-subtle: #212932;
    --nx-fg: #e8edf4;
    --nx-fg-subtle: #8b98a8;
    --nx-accent: #6ba5ff;
    --nx-accent-quiet: #1b2b42;
    --nx-accent-line: #35558a;
    --nx-font: Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --nx-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Ambient 3D backdrop ---------------------------------------------------- */

.nx-layer {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    contain: layout paint;
}

.nx-layer canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Fade the ambient graph out at the edges so copy keeps its contrast. */
body[data-nx-surface='scores'] .nx-layer {
    -webkit-mask-image: radial-gradient(ellipse 78% 62% at 50% 34%, #000 18%, transparent 80%);
    mask-image: radial-gradient(ellipse 78% 62% at 50% 34%, #000 18%, transparent 80%);
}

/* Shared 3D stage -------------------------------------------------------- */

.stage-canvas {
    position: relative;
    z-index: 1;
    min-height: 200px;
    cursor: grab;
    touch-action: pan-y;
    -webkit-tap-highlight-color: transparent;
}

.stage-canvas.is-grabbing {
    cursor: grabbing;
}

.stage-canvas:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 1px var(--accent, var(--nx-accent));
}

.stage-canvas canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Surface dock ----------------------------------------------------------- */

.nx-dock {
    position: fixed;
    left: 50%;
    bottom: 18px;
    z-index: 900;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px;
    border: 1px solid var(--border, var(--nx-border));
    border-radius: 999px;
    background: var(--nx-panel);
    box-shadow:
        0 18px 48px rgba(0, 0, 0, 0.55),
        0 2px 10px rgba(0, 0, 0, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(18px) saturate(1.35);
    -webkit-backdrop-filter: blur(18px) saturate(1.35);
    transform: translate(-50%, 0);
    transition:
        transform var(--nx-dur-slow) var(--nx-ease-out),
        opacity var(--nx-dur) var(--nx-ease);
    font-family: var(--font-sans, var(--nx-font));
    animation: nx-dock-in 620ms 120ms var(--nx-ease-out) backwards;
}

@keyframes nx-dock-in {
    from { opacity: 0; transform: translate(-50%, 26px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}

.nx-dock.is-tucked {
    transform: translate(-50%, calc(100% + 24px));
    opacity: 0;
}

.nx-dock-brand {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    margin-left: 3px;
    border-radius: 999px;
    color: var(--accent, var(--nx-accent));
    background: var(--accent-quiet, var(--nx-accent-quiet));
}

.nx-dock-brand svg {
    width: 15px;
    height: 15px;
}

.nx-dock-sep {
    width: 1px;
    height: 20px;
    margin: 0 4px;
    background: var(--border-subtle, var(--nx-border-subtle));
}

.nx-dock-track {
    position: relative;
    display: flex;
    align-items: center;
    gap: 2px;
}

/* One pill follows hover/focus across the whole strip, so the dock reads as
   a single object rather than three independent buttons. */
.nx-dock-pill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: var(--accent-quiet, var(--nx-accent-quiet));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
    opacity: 0;
    pointer-events: none;
    transition:
        transform 420ms var(--nx-ease-spring),
        width 420ms var(--nx-ease-spring),
        opacity var(--nx-dur) var(--nx-ease);
}

.nx-dock-pill.is-ready { opacity: 1; }
.nx-dock-pill.is-instant { transition: opacity var(--nx-dur) var(--nx-ease); }

.nx-dock-item {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 32px;
    padding: 0 13px 0 11px;
    border-radius: 999px;
    color: var(--fg-subtle, var(--nx-fg-subtle));
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: -0.01em;
    text-decoration: none;
    white-space: nowrap;
    transition:
        color var(--nx-dur-fast) var(--nx-ease),
        transform 320ms var(--nx-ease-out);
}

.nx-dock-item svg {
    width: 14px;
    height: 14px;
    opacity: 0.85;
    transition: opacity var(--nx-dur-fast) var(--nx-ease), transform 320ms var(--nx-ease-out);
}

.nx-dock-item:hover {
    color: var(--fg, var(--nx-fg));
    transform: translateY(-2px);
}

.nx-dock-item:hover svg {
    opacity: 1;
    transform: scale(1.08);
}

.nx-dock-item:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--nx-bg), 0 0 0 4px var(--accent-line, var(--nx-accent-line));
}

.nx-dock-item.is-active {
    color: var(--fg, var(--nx-fg));
}

/* The underline marks the surface you are actually on; the pill only tracks
   the pointer. Keeping them separate stops hover from lying about location. */
.nx-dock-item.is-active::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: -5px;
    width: 16px;
    height: 2px;
    border-radius: 2px;
    background: var(--accent, var(--nx-accent));
    transform: translateX(-50%);
    box-shadow: 0 0 10px var(--accent, var(--nx-accent));
}

.nx-dock-item small {
    display: none;
}

/* Page veil — identical entry and exit on every surface -------------------- */

.nx-veil {
    position: fixed;
    inset: 0;
    z-index: 9998;
    display: grid;
    place-items: center;
    background: var(--nx-bg);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--nx-dur) var(--nx-ease);
}

.nx-veil.is-on {
    opacity: 1;
    pointer-events: all;
}

.nx-veil-core {
    position: relative;
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    opacity: 0;
    transform: scale(0.86);
    transition:
        opacity var(--nx-dur) var(--nx-ease),
        transform var(--nx-dur-slow) var(--nx-ease-out);
}

.nx-veil.is-on .nx-veil-core {
    opacity: 1;
    transform: scale(1);
}

.nx-veil-glyph {
    display: grid;
    place-items: center;
    color: var(--accent, var(--nx-accent));
}

.nx-veil-glyph svg {
    width: 20px;
    height: 20px;
}

.nx-veil-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 1.5px solid var(--accent-line, var(--nx-accent-line));
    border-top-color: var(--accent, var(--nx-accent));
    animation: nx-spin 760ms linear infinite;
}

@keyframes nx-spin {
    to { transform: rotate(360deg); }
}

/* Entry: every surface fades its content up the same way. Driven purely by CSS
   on markup that exists at first paint — gating this on a JS-applied class (or
   on an injected overlay) would show the page, then cover it. */
.main-content,
.lookup-main,
.app-shell {
    animation: nx-page-in 520ms var(--nx-ease-out) backwards;
}

@keyframes nx-page-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Magnetic and tilt hooks are driven frame-by-frame from JS. A `transition:
   all` on the same element would re-target every frame and turn a crisp pull
   into rubber, so transform is explicitly excluded from their transitions. */
[data-magnetic],
[data-tilt] {
    transition-property: color, background-color, background, border-color, box-shadow, opacity, filter;
}

/* Scroll reveal — only armed when the shared observer took ownership, so a
   surface whose own animation library fails to load still shows its content. */
body.nx-reveal .reveal-target {
    opacity: 0;
    transform: translateY(18px);
    transition:
        opacity 620ms var(--nx-ease-out),
        transform 620ms var(--nx-ease-out);
}

body.nx-reveal .reveal-target.is-revealed {
    opacity: 1;
    transform: none;
}

/* Leaving: hold the outgoing surface still while the veil closes over it. */
body.nx-leaving {
    pointer-events: none;
}

/* Boot splash (ClaudeRouter SPA) ------------------------------------------ */

.nx-boot {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: grid;
    place-items: center;
    background: var(--nx-bg);
    transition:
        opacity var(--nx-dur-slow) var(--nx-ease),
        transform var(--nx-dur-slow) var(--nx-ease-out);
    font-family: var(--font-sans, var(--nx-font));
}

.nx-boot.is-out {
    opacity: 0;
    transform: scale(1.03);
    pointer-events: none;
}

.nx-boot canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.nx-boot-copy {
    position: relative;
    display: grid;
    justify-items: center;
    gap: 6px;
    text-align: center;
    animation: nx-boot-copy-in 620ms var(--nx-ease-out) backwards;
}

@keyframes nx-boot-copy-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}

.nx-boot-mark {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    margin-bottom: 4px;
    border: 1px solid var(--nx-accent-line);
    border-radius: 12px;
    background: var(--nx-accent-quiet);
    color: var(--nx-accent);
}

.nx-boot-mark svg {
    width: 18px;
    height: 18px;
}

.nx-boot-copy strong {
    font-size: 19px;
    font-weight: 650;
    letter-spacing: -0.03em;
    color: var(--nx-fg);
}

.nx-boot-copy small {
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--nx-fg-subtle);
}

.nx-boot-bar {
    width: 132px;
    height: 2px;
    margin-top: 6px;
    border-radius: 2px;
    overflow: hidden;
    background: var(--nx-border-subtle);
}

.nx-boot-bar span {
    display: block;
    width: 40%;
    height: 100%;
    border-radius: inherit;
    background: var(--nx-accent);
    animation: nx-sweep 1.1s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}

@keyframes nx-sweep {
    0%   { transform: translateX(-105%); }
    100% { transform: translateX(255%); }
}

/* The SPA owns the whole viewport, so lift its chrome above the dock. */
body[data-nx-surface='app'] .nx-dock {
    bottom: 12px;
}

@media (max-width: 620px) {
    .nx-dock {
        left: 10px;
        right: 10px;
        bottom: max(10px, env(safe-area-inset-bottom));
        width: auto;
        max-width: none;
        transform: none;
        justify-content: space-evenly;
        padding: 4px;
        animation-name: nx-dock-in-mobile;
    }
    @keyframes nx-dock-in-mobile {
        from { opacity: 0; transform: translateY(26px); }
        to   { opacity: 1; transform: none; }
    }
    .nx-dock.is-tucked {
        transform: translateY(calc(100% + 28px));
    }
    .nx-dock-track {
        flex: 1;
        min-width: 0;
    }
    .nx-dock-item {
        flex: 1;
        justify-content: center;
        padding: 0 8px;
        font-size: 11.5px;
        min-width: 0;
    }
    .nx-dock-item span {
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .nx-dock-brand {
        display: none;
    }
    .nx-dock-sep {
        display: none;
    }
}

@media (max-width: 400px) {
    .nx-dock-item {
        padding: 0 6px;
        gap: 5px;
        font-size: 11px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .nx-dock,
    .nx-dock-item,
    .nx-dock-item svg,
    .nx-dock-pill,
    .nx-veil,
    .nx-veil-core,
    .nx-boot {
        transition: none;
        animation: none;
    }
    .main-content,
    .lookup-main,
    .app-shell,
    .nx-boot-copy {
        animation: none;
    }
    body.nx-reveal .reveal-target {
        opacity: 1;
        transform: none;
        transition: none;
    }
    .nx-veil:not(.is-on) {
        opacity: 0;
    }
    .nx-veil-ring,
    .nx-boot-bar span {
        animation: none;
    }
}
