/* Digital Edge cube hub - 3D cube navigation.
   Deliberately separate from edge3d.css and NOT gated on html.edge3d-on:
   the cube is plain CSS 3D and must work even when WebGL never boots.
   All classes are bespoke (ch-*) because the Tailwind Play CDN cannot be
   trusted to style runtime-injected DOM. */

/* ---------- floating chip ---------- */

.ch-chip {
    position: fixed;
    right: 1.25rem;
    bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
    z-index: 80;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--brand-primary);
    background: color-mix(in srgb, var(--brand-surface) 82%, transparent);
    border: 1px solid var(--brand-border);
    border-radius: 2px;
    padding: 0.6rem 0.9rem;
    cursor: pointer;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    transition: border-color 200ms ease, box-shadow 200ms ease, opacity 300ms ease;
}
.ch-chip:hover,
.ch-chip:focus-visible {
    border-color: color-mix(in srgb, var(--brand-primary) 60%, transparent);
    box-shadow: 0 0 24px color-mix(in srgb, var(--brand-primary) 25%, transparent);
    outline: none;
}
html.cube-hub-open .ch-chip {
    opacity: 0;
    pointer-events: none;
}

/* ---------- arrival flash (zoom-in landing cover) ---------- */

html.edge3d-arriving body::before {
    content: '> open ' var(--edge3d-arrive-path, '/') ' _';
    position: fixed;
    inset: 0;
    z-index: 200;
    display: grid;
    place-items: center;
    background: var(--brand-background);
    color: var(--brand-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    letter-spacing: 0.1em;
    pointer-events: none;
    animation: ch-arrive-fade 1.1s ease-out forwards;
}
@keyframes ch-arrive-fade {
    0%, 55% { opacity: 1; }
    100% { opacity: 0; }
}

/* ---------- hub overlay ---------- */

#cube-hub {
    position: fixed;
    inset: 0;
    z-index: 90; /* above header (50), below legal modals (100) */
    font-family: 'JetBrains Mono', monospace;
}
#cube-hub[hidden] { display: none; }

html.cube-hub-open body > header,
html.cube-hub-open main,
html.cube-hub-open footer {
    visibility: hidden;
}

.ch-scrim {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse at center,
            transparent 30%,
            color-mix(in srgb, var(--brand-background) 72%, transparent) 100%),
        color-mix(in srgb, var(--brand-background) 38%, transparent);
    opacity: 0;
    transition: opacity 500ms ease;
}
#cube-hub.is-open .ch-scrim { opacity: 1; }

/* When the WebGL scene never booted there is nothing behind the hub:
   opaque background with the site's grid motif. */
html:not(.edge3d-on) .ch-scrim {
    background:
        linear-gradient(var(--brand-border) 1px, transparent 1px) 0 0 / 40px 40px,
        linear-gradient(90deg, var(--brand-border) 1px, transparent 1px) 0 0 / 40px 40px,
        var(--brand-background);
}

/* ---------- zoom (camera dolly) / stage / cube ---------- */

.ch-zoom {
    position: absolute;
    inset: 0;
    transform: scale(1);
}
#cube-hub.is-zooming .ch-zoom { transition: transform 650ms cubic-bezier(0.55, 0, 0.15, 1); }
#cube-hub.is-opening .ch-zoom { transition: transform 600ms cubic-bezier(0.22, 0.9, 0.3, 1); }

.ch-stage {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    perspective: 1200px;
    touch-action: none;
    cursor: grab;
}
#cube-hub.is-dragging .ch-stage { cursor: grabbing; }

.ch-cube {
    --ch-size: 560px;
    --ch-half: calc(var(--ch-size) / 2);
    --ch-yaw: 0deg;
    --ch-pitch: 0deg;
    --ch-out: 0px;
    position: relative;
    width: var(--ch-size);
    height: var(--ch-size);
    transform-style: preserve-3d;
    transform: rotateX(var(--ch-pitch)) rotateY(var(--ch-yaw));
}

/* ---------- faces ---------- */

.ch-face {
    position: absolute;
    inset: 0;
    display: block;
    text-decoration: none;
    transform-style: preserve-3d;
    -webkit-user-drag: none;
    user-select: none;
    -webkit-user-select: none;
    /* Only the front face is clickable. 3D hit-testing of the away-facing
       anchors is unreliable (their backsides can steal clicks meant for the
       front card), and pointer events pass through to the drag stage. */
    pointer-events: none;
    transition: transform 900ms cubic-bezier(0.34, 1.3, 0.4, 1), opacity 500ms ease;
}
.ch-face.is-front { pointer-events: auto; }
.ch-face-back { pointer-events: none; }
.ch-face[data-face="home"]      { transform: translateZ(calc(var(--ch-half) + var(--ch-out))); }
.ch-face[data-face="starter"]   { transform: rotateY(90deg)  translateZ(calc(var(--ch-half) + var(--ch-out))); }
.ch-face[data-face="wagtail"]   { transform: rotateY(180deg) translateZ(calc(var(--ch-half) + var(--ch-out))); }
.ch-face[data-face="mentoring"] { transform: rotateY(-90deg) translateZ(calc(var(--ch-half) + var(--ch-out))); }
.ch-face[data-face="about"]     { transform: rotateX(90deg)  translateZ(calc(var(--ch-half) + var(--ch-out))); }
.ch-face[data-face="blog"]      { transform: rotateX(-90deg) translateZ(calc(var(--ch-half) + var(--ch-out))); }
.ch-face:focus { outline: none; }

/* intro assembly: faces start pushed out along their normals, then fly into
   place (staggered) once .is-open lands */
#cube-hub.is-intro .ch-face {
    --ch-out: calc(var(--ch-size) * 0.4);
    opacity: 0;
}
#cube-hub.is-intro.is-open .ch-face { --ch-out: 0px; opacity: 1; }
#cube-hub.is-intro.is-open .ch-face:nth-child(2) { transition-delay: 60ms; }
#cube-hub.is-intro.is-open .ch-face:nth-child(3) { transition-delay: 120ms; }
#cube-hub.is-intro.is-open .ch-face:nth-child(4) { transition-delay: 180ms; }
#cube-hub.is-intro.is-open .ch-face:nth-child(5) { transition-delay: 240ms; }
#cube-hub.is-intro.is-open .ch-face:nth-child(6) { transition-delay: 300ms; }

/* zoom-in: everything but the chosen face fades away */
#cube-hub.is-zooming .ch-face:not(.is-target) { opacity: 0; transition: opacity 250ms ease; }
#cube-hub.is-zooming .ch-hud { opacity: 0; }

/* ---------- face card ---------- */

.ch-card {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    padding: calc(var(--ch-size) * 0.055);
    background: color-mix(in srgb, var(--brand-surface) 90%, transparent);
    border: 1px solid var(--brand-border);
    border-radius: 2px;
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    backface-visibility: hidden;
    transition: border-color 250ms ease, box-shadow 250ms ease, background-color 300ms ease;
}
html.light .ch-card { background: color-mix(in srgb, var(--brand-surface) 95%, transparent); }
html.edge3d-lowtier .ch-card {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: color-mix(in srgb, var(--brand-surface) 96%, transparent);
}

/* corner brackets, echoing .callout */
.ch-card::before,
.ch-card::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border: 0 solid var(--brand-primary);
}
.ch-card::before { top: -1px; left: -1px; border-top-width: 2px; border-left-width: 2px; }
.ch-card::after { bottom: -1px; right: -1px; border-bottom-width: 2px; border-right-width: 2px; }

.ch-face:hover .ch-card,
.ch-face:focus-visible .ch-card,
.ch-face.is-front .ch-card {
    border-color: color-mix(in srgb, var(--brand-primary) 45%, var(--brand-border));
}
.ch-face:hover .ch-card,
.ch-face:focus-visible .ch-card {
    box-shadow: 0 0 44px color-mix(in srgb, var(--brand-primary) 18%, transparent);
}
.ch-face:focus-visible .ch-card {
    outline: 2px solid var(--brand-primary);
    outline-offset: 3px;
}
#cube-hub.is-zooming .ch-face.is-target .ch-card {
    background: var(--brand-background);
    border-color: var(--brand-border);
    box-shadow: none;
}

/* chrome bar */
.ch-chrome {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-bottom: calc(var(--ch-size) * 0.035);
    margin-bottom: calc(var(--ch-size) * 0.045);
    border-bottom: 1px solid var(--brand-border);
}
.ch-chrome i {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    opacity: 0.6;
}
.ch-chrome i:nth-child(1) { background: #ff5f56; }
.ch-chrome i:nth-child(2) { background: #ffbd2e; }
.ch-chrome i:nth-child(3) { background: #27c93f; }
.ch-path {
    margin-left: 10px;
    font-size: calc(var(--ch-size) * 0.021);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--brand-primary);
}

/* The home face carries the logo instead of a text title. The source
   images declare no intrinsic size, so height stays auto (guessing an
   aspect-ratio would reserve a mis-sized box); min-height keeps the card
   layout stable while the image loads. */
.ch-logo {
    display: block;
    width: 72%;
    max-width: 100%;
    height: auto;
    min-height: calc(var(--ch-size) * 0.1);
    object-fit: contain;
    object-position: left center;
    margin-bottom: calc(var(--ch-size) * 0.035);
}

.ch-title {
    font-family: 'Inter', ui-sans-serif, system-ui, sans-serif;
    font-weight: 700;
    font-size: calc(var(--ch-size) * 0.062);
    line-height: 1.15;
    letter-spacing: -0.01em;
    color: var(--brand-heading);
    margin-bottom: calc(var(--ch-size) * 0.03);
}
.ch-desc {
    font-family: 'Inter', ui-sans-serif, system-ui, sans-serif;
    font-size: calc(var(--ch-size) * 0.031);
    line-height: 1.5;
    color: var(--brand-body);
    margin-bottom: auto;
}
.ch-stat {
    font-size: calc(var(--ch-size) * 0.026);
    line-height: 1.6;
    color: var(--brand-heading);
    margin-bottom: calc(var(--ch-size) * 0.02);
}
.ch-stat b { color: var(--brand-primary); font-weight: 700; }
.ch-stat s { color: var(--brand-body); opacity: 0.7; }
.ch-crumbs {
    font-size: calc(var(--ch-size) * 0.021);
    letter-spacing: 0.12em;
    text-transform: lowercase;
    color: var(--brand-body);
    opacity: 0.75;
}
.ch-enter {
    position: absolute;
    right: calc(var(--ch-size) * 0.055);
    bottom: calc(var(--ch-size) * 0.055);
    font-size: calc(var(--ch-size) * 0.023);
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--brand-primary);
    opacity: 0;
    transition: opacity 200ms ease;
}
.ch-face:hover .ch-enter,
.ch-face:focus-visible .ch-enter,
.ch-face.is-front .ch-enter { opacity: 1; }

/* ghosted blueprint backside */
.ch-face-back {
    position: absolute;
    inset: 0;
    transform: rotateY(180deg);
    backface-visibility: hidden;
    border: 1px solid color-mix(in srgb, var(--brand-border) 70%, transparent);
    background:
        linear-gradient(to top right, transparent calc(50% - 0.5px), color-mix(in srgb, var(--brand-border) 45%, transparent) 50%, transparent calc(50% + 0.5px)),
        linear-gradient(to top left, transparent calc(50% - 0.5px), color-mix(in srgb, var(--brand-border) 45%, transparent) 50%, transparent calc(50% + 0.5px)),
        color-mix(in srgb, var(--brand-background) 30%, transparent);
    display: grid;
    place-items: center;
    color: color-mix(in srgb, var(--brand-body) 25%, transparent);
    font-size: calc(var(--ch-size) * 0.024);
    letter-spacing: 0.2em;
}

/* loading flash shown on the chosen face at the end of zoom-in */
.ch-flash {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: var(--brand-background);
    color: var(--brand-primary);
    font-size: calc(var(--ch-size) * 0.026);
    letter-spacing: 0.1em;
    opacity: 0;
    pointer-events: none;
    backface-visibility: hidden;
    transition: opacity 180ms ease-out;
}
.ch-face.is-target .ch-flash { opacity: 1; transition-delay: 480ms; }
.ch-flash b {
    display: inline-block;
    width: 0.6em;
    height: 1.1em;
    margin-left: 0.35em;
    vertical-align: text-bottom;
    background: var(--brand-primary);
    animation: ch-caret 0.8s steps(1) infinite;
}
@keyframes ch-caret { 50% { opacity: 0; } }

/* ---------- HUD ---------- */

.ch-hud {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    pointer-events: none;
    transition: opacity 250ms ease;
}
.ch-live {
    font-size: 12px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--brand-heading);
}
.ch-live b { color: var(--brand-primary); font-weight: 400; }
.ch-hint {
    font-size: 10px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--brand-body);
    opacity: 0.8;
}
.ch-skip {
    pointer-events: auto;
    font-family: inherit;
    font-size: 11px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--brand-primary);
    background: color-mix(in srgb, var(--brand-surface) 82%, transparent);
    border: 1px solid var(--brand-border);
    border-radius: 2px;
    padding: 0.55rem 0.9rem;
    cursor: pointer;
    transition: border-color 200ms ease, box-shadow 200ms ease;
}
.ch-skip:hover,
.ch-skip:focus-visible {
    border-color: color-mix(in srgb, var(--brand-primary) 60%, transparent);
    box-shadow: 0 0 24px color-mix(in srgb, var(--brand-primary) 25%, transparent);
    outline: none;
}

/* ---------- responsive ---------- */

@media (max-width: 640px) {
    .ch-stage { perspective: 1100px; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
    #cube-hub.is-zooming .ch-zoom,
    #cube-hub.is-opening .ch-zoom,
    .ch-face,
    .ch-scrim { transition-duration: 1ms !important; transition-delay: 0ms !important; }
    html.edge3d-arriving body::before { animation-duration: 350ms; }
}
