/* ============================================================
   Aerbits — PAL guide widget
   Floating launcher + conversational video panel.
   Inherits the tokens declared in css/style.css.
   ============================================================ */

.pal-root {
    --pal-w: 380px;
    --pal-radius: 16px;
    position: fixed;
    right: var(--space-lg);
    bottom: var(--space-lg);
    z-index: 900;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--space-md);
    font-family: var(--font-body);
    pointer-events: none;
}

.pal-root > * { pointer-events: auto; }

/* ── Launcher ───────────────────────────────────────────────── */

.pal-launcher {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    height: 56px;
    padding: 0 var(--space-lg) 0 var(--space-sm);
    border-radius: 999px;
    background: var(--text-display);
    color: var(--black);
    border: 1px solid var(--text-display);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
    transition: transform 200ms var(--ease), box-shadow 200ms var(--ease);
}

.pal-launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.24);
}

.pal-launcher:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.pal-launcher[hidden] { display: none; }

.pal-launcher-glyph {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--black);
    color: var(--text-display);
    display: grid;
    place-items: center;
}

.pal-launcher-glyph svg { width: 20px; height: 20px; }

.pal-launcher-label {
    font-family: var(--font-mono);
    font-size: var(--label);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    white-space: nowrap;
}

/* Slow breathing ring so the launcher reads as "available", not urgent. */
.pal-launcher::after {
    content: "";
    position: absolute;
    inset: -1px;
    border-radius: inherit;
    border: 1px solid var(--accent);
    opacity: 0;
    animation: pal-breathe 3.2s var(--ease) infinite;
    pointer-events: none;
}

@keyframes pal-breathe {
    0%   { opacity: 0.5; transform: scale(1); }
    70%  { opacity: 0;   transform: scale(1.08); }
    100% { opacity: 0;   transform: scale(1.08); }
}

/* ── Panel ──────────────────────────────────────────────────── */

.pal-panel {
    width: var(--pal-w);
    max-width: calc(100vw - var(--space-xl));
    background: var(--surface);
    border: 1px solid var(--border-visible);
    border-radius: var(--pal-radius);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.22);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform-origin: bottom right;
    animation: pal-panel-in 260ms var(--ease);
    /* Fade-out is quick so the page shows about as fast as the pointer
       arrives; the fade-back below is slower so the panel does not snap
       and flash as the pointer crosses a control. */
    transition: opacity 120ms var(--ease), box-shadow 120ms var(--ease);
}

.pal-panel[hidden] { display: none; }

/* ── Peek ───────────────────────────────────────────────────────
   Hovering the video fades the panel so the visitor can see — and
   click — the page underneath it. Only the stage goes click-through;
   the header and footer keep their controls live, and moving onto
   them drops .pal-peek, bringing the panel straight back.
   ─────────────────────────────────────────────────────────────── */

/* Low enough that body copy underneath is comfortably readable, high
   enough that the panel's outline still shows where the guide is. */
.pal-root.pal-peek .pal-panel {
    opacity: 0.18;
    box-shadow: none;
}

/* The panel itself has to go transparent to hit-testing, not just the
   stage: a parent still hit-tests its own box even when a child is set
   to pointer-events:none, so fading only the stage would leave the panel
   swallowing the click. Header and footer opt back in so their controls
   keep working. */
.pal-root.pal-peek .pal-panel {
    pointer-events: none;
}

.pal-root.pal-peek .pal-panel-header,
.pal-root.pal-peek .pal-panel-footer {
    pointer-events: auto;
}

.pal-root:not(.pal-peek) .pal-panel {
    transition: opacity 260ms var(--ease), box-shadow 260ms var(--ease);
}

@keyframes pal-panel-in {
    from { opacity: 0; transform: translateY(12px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.pal-panel-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    border-bottom: 1px solid var(--border);
}

.pal-panel-title {
    flex: 1;
    min-width: 0;
}

.pal-panel-title strong {
    display: block;
    font-size: var(--body-sm);
    font-weight: 500;
    color: var(--text-display);
    letter-spacing: -0.01em;
}

.pal-panel-title span {
    display: block;
    font-family: var(--font-mono);
    font-size: var(--label);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

.pal-icon-btn {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: var(--text-secondary);
    border: 1px solid transparent;
    transition: background 160ms var(--ease), color 160ms var(--ease), border-color 160ms var(--ease);
}

.pal-icon-btn:hover {
    background: var(--surface-raised);
    color: var(--text-display);
}

.pal-icon-btn:focus-visible {
    outline: none;
    border-color: var(--accent);
}

.pal-icon-btn svg { width: 16px; height: 16px; }

.pal-icon-btn[aria-pressed="true"] {
    background: var(--accent-subtle);
    color: var(--accent);
}

/* ── Video stage ────────────────────────────────────────────── */

.pal-stage {
    position: relative;
    aspect-ratio: 4 / 3;
    background: #0d0d0d;
    overflow: hidden;
}

.pal-stage video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    opacity: 0;
    transition: opacity 400ms var(--ease);
}

.pal-root[data-state="live"] .pal-stage video { opacity: 1; }

/* Loading overlay — covers the stage until the face is actually on screen. */
.pal-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    padding: var(--space-lg);
    text-align: center;
    background: #0d0d0d;
    color: #f5f5f5;
    transition: opacity 300ms var(--ease), visibility 300ms var(--ease);
}

.pal-root[data-state="live"] .pal-loading {
    opacity: 0;
    visibility: hidden;
}

.pal-spinner {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid rgba(245, 245, 245, 0.18);
    border-top-color: #f5f5f5;
    animation: pal-spin 900ms linear infinite;
}

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

.pal-root[data-state="error"] .pal-spinner { display: none; }

.pal-loading-status {
    font-family: var(--font-mono);
    font-size: var(--caption);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(245, 245, 245, 0.86);
}

.pal-loading-hint {
    font-size: var(--body-sm);
    line-height: 1.5;
    color: rgba(245, 245, 245, 0.6);
    max-width: 28ch;
}

/* Stepper: shows which stage of the connection we're in. */
.pal-steps {
    display: flex;
    gap: 6px;
}

.pal-steps span {
    width: 22px;
    height: 2px;
    border-radius: 1px;
    background: rgba(245, 245, 245, 0.2);
    transition: background 300ms var(--ease);
}

.pal-steps span.done { background: rgba(245, 245, 245, 0.55); }
.pal-steps span.active { background: #f5f5f5; }

.pal-retry {
    font-family: var(--font-mono);
    font-size: var(--label);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 10px 20px;
    border-radius: 999px;
    border: 1px solid rgba(245, 245, 245, 0.4);
    color: #f5f5f5;
    transition: background 160ms var(--ease);
}

.pal-retry:hover { background: rgba(245, 245, 245, 0.12); }
.pal-retry[hidden] { display: none; }

/* Live badge over the video */
.pal-live-badge {
    position: absolute;
    top: var(--space-sm);
    left: var(--space-sm);
    display: none;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #f5f5f5;
}

.pal-root[data-state="live"] .pal-live-badge { display: inline-flex; }

.pal-live-badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #ff4d4d;
    animation: pal-pulse 1.6s var(--ease) infinite;
}

@keyframes pal-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.25; }
}

/* ── Footer / controls ──────────────────────────────────────── */

.pal-panel-footer {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    border-top: 1px solid var(--border);
}

.pal-context {
    flex: 1;
    min-width: 0;
    font-family: var(--font-mono);
    font-size: var(--label);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pal-end {
    flex-shrink: 0;
    font-family: var(--font-mono);
    font-size: var(--label);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 9px 16px;
    border-radius: 999px;
    border: 1px solid var(--border-visible);
    color: var(--text-primary);
    transition: border-color 160ms var(--ease), color 160ms var(--ease);
}

.pal-end:hover { border-color: var(--error); color: var(--error); }

/* ── Scroll target highlight ────────────────────────────────── */

.pal-highlight {
    animation: pal-flash 2.2s var(--ease);
}

@keyframes pal-flash {
    0%   { box-shadow: inset 0 0 0 0 var(--accent-subtle); }
    18%  { box-shadow: inset 0 0 0 3px var(--accent-subtle); }
    100% { box-shadow: inset 0 0 0 0 rgba(91, 69, 217, 0); }
}

/* ── Responsive ─────────────────────────────────────────────── */

@media (max-width: 520px) {
    .pal-root {
        right: var(--space-md);
        left: var(--space-md);
        bottom: var(--space-md);
        align-items: stretch;
    }

    .pal-panel { width: 100%; max-width: none; }

    .pal-launcher {
        align-self: flex-end;
        padding-right: var(--space-md);
    }

    .pal-launcher-label { display: none; }

    .pal-launcher {
        width: 56px;
        padding: 0;
        justify-content: center;
    }
}

@media (prefers-reduced-motion: reduce) {
    .pal-launcher::after,
    .pal-live-badge::before,
    .pal-highlight { animation: none; }
    /* The peek fade is functional, not decorative — keep the opacity
       change, just make it instant. */
    .pal-panel { animation: none; transition: none; }
    .pal-root:not(.pal-peek) .pal-panel { transition: none; }
    .pal-spinner { animation-duration: 2s; }
}
