/* ==========================================================================
   WANDERING PERCHED CHARACTER NARRATOR & BLACK HOLE VOID TELEPORTATION
   Stylized Cartoon Depiction of Kartikay Mathur // Interactive Dynamic Guide
   Color Palette: Deep Obsidian Void (#040108), Electric Violet (#9d4edd),
   Lilac (#c77dff), Ultraviolet (#7b2cbf), Photon White (#ffffff, #f3e8ff).
   Strict Zero-Emoji Policy Enforced
   ========================================================================== */

/* Fullscreen Void Teleportation Canvas */
.void-teleport-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 9998;
}

/* Dynamic Perched Narrator Host Mounted inside active section */
.perched-narrator-system {
    position: relative;
    width: 100%;
    height: 0;
    margin: 0;
    padding: 0;
    overflow: visible;
    z-index: 90;
    display: flex;
    justify-content: flex-end;
    pointer-events: none;
    transition: opacity 300ms ease;
}

.perched-narrator-system * {
    pointer-events: auto;
}

/* State 1: Hero Section (#top) - Perched above hero monolith card */
.perched-narrator-system.at-hero {
    position: relative;
    width: 100%;
    height: 0;
    margin: 0;
    padding: 0;
    overflow: visible;
    z-index: 90;
    display: flex;
    justify-content: flex-end;
    pointer-events: none;
}

.perched-narrator-system.at-hero .perched-character-container {
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: flex-end;
    gap: 1.15rem;
    max-width: 680px;
    width: 100%;
    margin-right: 1.5rem;
    transform: translateY(-8px);
    transform-origin: top right;
}

/* State 2: Sovereign Right-Flank Companion Rail across all other sections (#structure to #identity)
   ZERO COLLISION GUARANTEE: Fixed on the right rail, completely clear of all section titles & bottom controls */
.perched-narrator-system.at-flank {
    position: fixed;
    right: 24px;
    top: 50%;
    transform: translateY(-50%);
    width: auto;
    max-width: calc(100vw - 48px);
    height: auto;
    margin: 0;
    padding: 0;
    z-index: 992;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    pointer-events: none;
    transition: transform 350ms cubic-bezier(0.16, 1, 0.3, 1), opacity 350ms ease;
}

.perched-narrator-system.at-flank .perched-character-container {
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: flex-end;
    gap: 0.85rem;
    max-width: 480px;
    width: auto;
    margin-right: 0;
    transform: none;
}

.perched-narrator-system.at-flank .perched-figure-box {
    width: 105px;
    height: 170px;
    margin-bottom: 0;
    z-index: 3;
    flex-shrink: 0;
}

.perched-narrator-system.at-flank .perched-speech-bubble {
    width: 320px;
    max-width: 330px;
    margin-top: 8px;
    margin-bottom: 0;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.95), 0 0 30px rgba(157, 78, 221, 0.28);
}

.perched-narrator-system.at-flank .perched-bubble-tail {
    top: 24px;
    bottom: auto;
    right: -9px;
    left: auto;
    width: 16px;
    height: 16px;
    background: rgba(15, 10, 26, 0.96);
    border-right: 1px solid rgba(199, 125, 255, 0.38);
    border-top: 1px solid rgba(199, 125, 255, 0.38);
    border-left: none;
    border-bottom: none;
    transform: rotate(45deg);
}

/* Ambient Docked/Faded State during exploration */
.perched-narrator-system.at-flank.narrator-faded {
    opacity: 0.50;
    transform: translateY(-50%) translateX(calc(100% - 46px));
}

.perched-narrator-system.at-flank.narrator-faded:hover,
.perched-narrator-system.at-flank.narrator-focused {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

/* Minimized State */
.perched-narrator-system.at-flank.minimized-companion {
    transform: translateY(-50%) translateX(calc(100% - 62px));
}

.perched-narrator-system.at-flank.minimized-companion .perched-speech-bubble {
    display: none;
}

.perched-narrator-system.at-flank.minimized-companion .perched-figure-box {
    width: 58px;
    height: 92px;
    margin-bottom: 0;
}

/* Character Container (Speech Bubble + Sitting Mascot Figure) */
.perched-character-container {
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    gap: 1.25rem;
    max-width: 680px;
    width: 100%;
    margin-right: 1.5rem;
    transform: translateY(-8px);
    transform-origin: top right;
}

/* Perched Character Mascot Figure (Sitting Reference Pose) */
.perched-figure-box {
    position: relative;
    width: 135px;
    height: 215px;
    flex-shrink: 0;
    cursor: pointer;
    user-select: none;
    z-index: 2;
    transform-origin: bottom center;
    transition: transform 300ms cubic-bezier(0.16, 1, 0.3, 1), filter 300ms ease;
}

.perched-figure-box:hover {
    transform: scale(1.05) translateY(-3px);
}

.perched-figure-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    filter: drop-shadow(0 14px 28px rgba(0, 0, 0, 0.95)) 
           drop-shadow(0 0 18px rgba(157, 78, 221, 0.45));
    transition: filter 250ms ease;
}

.perched-figure-box:hover .perched-figure-img {
    filter: drop-shadow(0 18px 36px rgba(0, 0, 0, 0.98)) 
           drop-shadow(0 0 28px rgba(199, 125, 255, 0.75));
}

/* Singularity Aura Glow */
.perched-singularity-aura {
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 90px;
    height: 18px;
    background: radial-gradient(ellipse at center, rgba(157, 78, 221, 0.6) 0%, rgba(60, 9, 108, 0.25) 55%, transparent 75%);
    border-radius: 50%;
    pointer-events: none;
    animation: singularityAuraPulse 2.4s ease-in-out infinite alternate;
}

@keyframes singularityAuraPulse {
    0% { transform: translateX(-50%) scale(0.85); opacity: 0.55; }
    100% { transform: translateX(-50%) scale(1.15); opacity: 0.95; }
}

/* ==========================================================================
   Feature 5: Anisotropic Mascot Spaghettification & Reconstitution
   Feature 6: Circular Heat-Haze Distortion & Stacked Micro-Glitch Filters
   ========================================================================== */

/* Mascot Departure: Tidal Vertical Elongation, Horizontal Squashing & Rotational Disintegration (0.5x Calibrated) */
.perched-figure-box.teleporting-out,
.perched-character-container.teleporting-out {
    animation: mascotTidalSpaghettification 840ms cubic-bezier(0.55, 0, 1, 0.45) 160ms forwards;
    transform-origin: center center;
    pointer-events: none;
}

@keyframes mascotTidalSpaghettification {
    0% {
        transform: scale(1, 1) rotate(0deg) translateY(0);
        opacity: 1;
        filter: brightness(1) drop-shadow(0 0 0 rgba(157, 78, 221, 0));
    }
    35% {
        /* Gravitational tidal gradient begins pulling vertically */
        transform: scale(0.65, 1.45) rotate(90deg) translateY(18px);
        opacity: 0.95;
        filter: brightness(2.0) contrast(1.4) drop-shadow(0 0 25px #9d4edd) hue-rotate(240deg) url(#teleportHeatDistortionFilter);
    }
    70% {
        /* Peak anisotropic spaghettification: scaleY 1.8, scaleX 0.15, rotational swirl into singularity */
        transform: scale(0.15, 1.8) rotate(360deg) translateY(45px);
        opacity: 0.65;
        filter: brightness(3.2) contrast(1.8) drop-shadow(0 0 45px #c77dff) blur(3px) hue-rotate(280deg) url(#teleportHeatDistortionFilter);
    }
    100% {
        /* Total collapse into the event horizon */
        transform: scale(0.01, 0.01) rotate(540deg) translateY(65px);
        opacity: 0;
        filter: brightness(4.5) blur(9px) hue-rotate(310deg);
    }
}

/* Mascot Arrival: Reconstitution from Photon Point with Outward Flare & Damped Spring Recoil (0.5x Calibrated) */
.perched-figure-box.teleporting-in,
.perched-character-container.teleporting-in {
    animation: mascotReconstitutionSpring 1040ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
    transform-origin: center center;
}

@keyframes mascotReconstitutionSpring {
    0% {
        /* Reconstitution from ultra-dense photon point with outward chromatic flare */
        transform: scale(0.02, 2.2) rotate(-270deg) translateY(-40px);
        opacity: 0;
        filter: brightness(4.8) contrast(2.4) drop-shadow(0 0 50px #ffffff) drop-shadow(0 0 85px #9d4edd) blur(6px) url(#teleportHeatDistortionFilter);
    }
    35% {
        transform: scale(0.48, 1.62) rotate(-70deg) translateY(-15px);
        opacity: 0.88;
        filter: brightness(3.0) contrast(1.7) drop-shadow(0 0 40px #c77dff) blur(2px) url(#teleportHeatDistortionFilter);
    }
    68% {
        /* Critically damped spring overshoot */
        transform: scale(1.18, 0.86) rotate(4deg) translateY(6px);
        opacity: 1;
        filter: brightness(1.35) contrast(1.2) drop-shadow(0 0 22px #9d4edd) blur(0px);
    }
    85% {
        /* Damped micro-recoil */
        transform: scale(0.96, 1.04) rotate(-1.5deg) translateY(-2px);
        opacity: 1;
        filter: brightness(1.1) drop-shadow(0 0 12px rgba(157, 78, 221, 0.45));
    }
    100% {
        /* Sovereign rest equilibrium */
        transform: scale(1, 1) rotate(0deg) translateY(0);
        opacity: 1;
        filter: brightness(1) drop-shadow(0 0 0 rgba(0, 0, 0, 0));
    }
}

/* Legacy alias keyframe for external hooks */
@keyframes voidSingularityEmerge {
    0% {
        transform: scale(0.02, 2.2) rotate(-270deg) translateY(-40px);
        opacity: 0;
        filter: brightness(4.8) blur(6px);
    }
    68% {
        transform: scale(1.18, 0.86) rotate(4deg) translateY(6px);
        opacity: 1;
        filter: brightness(1.35) blur(0px);
    }
    100% {
        transform: scale(1, 1) rotate(0deg) translateY(0);
        opacity: 1;
        filter: brightness(1);
    }
}

/* Feature 6: Circular Heat-Haze Distortion Overlay & Lens */
.teleport-heat-distortion {
    position: fixed;
    top: 0;
    left: 0;
    width: 220px;
    height: 220px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 9997;
    opacity: 0;
    transform: translate3d(-50%, -50%, 0) scale(0.2);
    will-change: transform, opacity;
    backdrop-filter: url(#teleportHeatDistortionFilter) blur(1.5px);
    -webkit-backdrop-filter: url(#teleportHeatDistortionFilter) blur(1.5px);
    background: radial-gradient(circle, rgba(243, 232, 255, 0.14) 0%, rgba(157, 78, 221, 0.24) 35%, rgba(60, 9, 108, 0.12) 65%, transparent 75%);
    box-shadow: 0 0 55px rgba(157, 78, 221, 0.5), inset 0 0 35px rgba(255, 255, 255, 0.35);
    transition: opacity 220ms ease, transform 260ms cubic-bezier(0.16, 1, 0.3, 1);
}

.teleport-heat-distortion.active {
    opacity: 1;
    transform: translate3d(-50%, -50%, 0) scale(1);
}

/* Stacked Micro-Glitch CSS Trigger */
.teleporting-glitch {
    animation: teleportGlitchJitter 140ms steps(2, start) infinite;
}

@keyframes teleportGlitchJitter {
    0% { transform: translate(0, 0); }
    25% { transform: translate(-3px, 1px) skewX(1.5deg); }
    50% { transform: translate(3px, -1px) skewX(-1.5deg); }
    75% { transform: translate(-2px, -1px); }
    100% { transform: translate(0, 0); }
}

/* ==========================================================================
   DECONSTRUCTED BLACK HOLE UI BREAKING & SUCKING ANIMATION ENGINE
   Shatters dialogue station bubble into distinct individual fragments
   sucked separately into the singularity vortex ahead of the character
   ========================================================================== */

/* Bubble Glass Shell Implosion into Singularity */
#narratorCard.ui-sucking-out {
    animation: deconstructSuckBubbleShell 760ms cubic-bezier(0.55, 0, 1, 0.45) 240ms forwards;
    pointer-events: none;
    transform-origin: bottom right;
}

@keyframes deconstructSuckBubbleShell {
    0% {
        transform: scale(1) rotate(0deg) translate(0, 0);
        opacity: 1;
        border-color: rgba(199, 125, 255, 0.38);
    }
    40% {
        transform: scale(0.72, 1.35) rotate(12deg) translate(35px, -15px);
        opacity: 0.9;
        border-color: #c77dff;
        box-shadow: 0 0 45px rgba(157, 78, 221, 0.8), inset 0 0 25px rgba(255, 255, 255, 0.4);
    }
    75% {
        transform: scale(0.25, 1.6) rotate(35deg) translate(80px, -35px);
        opacity: 0.6;
        filter: brightness(2.8) contrast(1.6) drop-shadow(0 0 35px #9d4edd) blur(3px);
    }
    100% {
        transform: scale(0.01, 0.01) rotate(75deg) translate(130px, -55px);
        opacity: 0;
        filter: brightness(4.5) blur(9px);
    }
}

/* Fragment 1: Bubble Pointer Tail Snaps & Spirals First */
#narratorCard.ui-sucking-out .perched-bubble-tail {
    animation: deconstructSuckTail 480ms cubic-bezier(0.55, 0, 1, 0.45) 0ms forwards;
    transform-origin: center center;
}

@keyframes deconstructSuckTail {
    0% {
        transform: rotate(45deg) translate(0, 0) scale(1);
        opacity: 1;
    }
    40% {
        transform: rotate(180deg) translate(25px, -15px) scale(0.7, 1.4);
        opacity: 0.9;
        filter: drop-shadow(0 0 10px #c77dff) hue-rotate(90deg);
    }
    100% {
        transform: rotate(420deg) translate(80px, -35px) scale(0.05, 0.05);
        opacity: 0;
        filter: blur(4px) drop-shadow(0 0 15px #9d4edd);
    }
}

/* Fragment 2: Header Mini Controls & Speed Badge Shatter */
#narratorCard.ui-sucking-out .narrator-mini-btn,
#narratorCard.ui-sucking-out .perched-speed-badge {
    animation: deconstructSuckMiniControls 540ms cubic-bezier(0.55, 0, 1, 0.45) 50ms forwards;
    transform-origin: center center;
}

@keyframes deconstructSuckMiniControls {
    0% {
        transform: translate(0, 0) scale(1) rotate(0deg);
        opacity: 1;
    }
    40% {
        transform: translate(35px, -20px) scale(0.8, 1.3) rotate(-35deg);
        opacity: 0.9;
        filter: brightness(2) drop-shadow(0 0 12px #9d4edd);
    }
    100% {
        transform: translate(110px, -50px) scale(0.02, 0.02) rotate(-180deg);
        opacity: 0;
        filter: blur(6px) brightness(3);
    }
}

/* Fragment 3A: Primary Action Button NEXT -> Rips Off & Spins into Vortex */
#narratorCard.ui-sucking-out #narratorNextBtn {
    animation: deconstructSuckNextBtn 600ms cubic-bezier(0.55, 0, 1, 0.45) 100ms forwards;
    transform-origin: center center;
}

@keyframes deconstructSuckNextBtn {
    0% {
        transform: translate(0, 0) scale(1) rotate(0deg);
        opacity: 1;
    }
    45% {
        transform: translate(45px, -25px) scale(0.65, 1.5) rotate(45deg);
        opacity: 0.95;
        filter: brightness(2.2) drop-shadow(0 0 16px #c77dff);
    }
    100% {
        transform: translate(130px, -60px) scale(0.02, 0.02) rotate(270deg);
        opacity: 0;
        filter: blur(8px) brightness(4);
    }
}

/* Fragment 3B: Secondary Action Button <- PREV Breaks Away with Opposing Spin */
#narratorCard.ui-sucking-out #narratorPrevBtn {
    animation: deconstructSuckPrevBtn 630ms cubic-bezier(0.55, 0, 1, 0.45) 150ms forwards;
    transform-origin: center center;
}

@keyframes deconstructSuckPrevBtn {
    0% {
        transform: translate(0, 0) scale(1) rotate(0deg);
        opacity: 1;
    }
    45% {
        transform: translate(35px, -35px) scale(0.7, 1.35) rotate(-30deg);
        opacity: 0.9;
        filter: brightness(2) drop-shadow(0 0 14px #9d4edd);
    }
    100% {
        transform: translate(120px, -70px) scale(0.02, 0.02) rotate(-220deg);
        opacity: 0;
        filter: blur(8px) brightness(4);
    }
}

/* Fragment 4: Header Section Tag & Singularity Dot Stretch along Tidal Gradient */
#narratorCard.ui-sucking-out .perched-bubble-tag {
    animation: deconstructSuckTag 640ms cubic-bezier(0.55, 0, 1, 0.45) 180ms forwards;
    transform-origin: left center;
}

@keyframes deconstructSuckTag {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    50% {
        transform: translate(40px, -15px) scale(0.75, 1.25) skewX(-20deg);
        opacity: 0.85;
        filter: brightness(2) drop-shadow(0 0 14px #c77dff);
    }
    100% {
        transform: translate(115px, -40px) scale(0.02, 0.02) skewX(-60deg);
        opacity: 0;
        filter: blur(6px) brightness(3.5);
    }
}

/* Fragment 5: Footer Telemetry Tag Flings Upward into Singularity */
#narratorCard.ui-sucking-out #narratorStepTag {
    animation: deconstructSuckMeta 650ms cubic-bezier(0.55, 0, 1, 0.45) 200ms forwards;
    transform-origin: left center;
}

@keyframes deconstructSuckMeta {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    50% {
        transform: translate(30px, -20px) scale(0.7, 1.2) rotate(15deg);
        opacity: 0.85;
        filter: brightness(1.8) drop-shadow(0 0 12px #9d4edd);
    }
    100% {
        transform: translate(105px, -55px) scale(0.02, 0.02) rotate(90deg);
        opacity: 0;
        filter: blur(6px) brightness(3);
    }
}

/* Fragment 6: Speech Text Body Tidal Elongation & Suction */
#narratorCard.ui-sucking-out .narrator-speech-body {
    animation: deconstructSuckSpeech 680ms cubic-bezier(0.55, 0, 1, 0.45) 220ms forwards;
    transform-origin: center center;
}

@keyframes deconstructSuckSpeech {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    45% {
        transform: translate(30px, -10px) scale(0.65, 1.3) skewX(-15deg);
        opacity: 0.8;
        filter: brightness(2.2) blur(1px) drop-shadow(0 0 16px #c77dff);
    }
    100% {
        transform: translate(95px, -30px) scale(0.02, 0.02) skewX(-45deg);
        opacity: 0;
        filter: blur(8px) brightness(3.8);
    }
}

/* ==========================================================================
   RECONSTITUTION ON WHITE HOLE / DESTINATION ARRIVAL
   Critically damped spring re-assembly of UI elements out of singularity
   ========================================================================== */

#narratorCard.ui-reconstituting-in {
    animation: bubbleShellReconstitute 880ms cubic-bezier(0.16, 1, 0.3, 1) 120ms forwards;
    transform-origin: bottom right;
}

@keyframes bubbleShellReconstitute {
    0% {
        transform: scale(0.05, 1.8) rotate(-25deg) translate(50px, -20px);
        opacity: 0;
        filter: brightness(4.0) drop-shadow(0 0 45px #ffffff) blur(6px);
    }
    45% {
        transform: scale(1.08, 0.94) rotate(3deg) translate(-4px, 2px);
        opacity: 0.92;
        filter: brightness(1.6) drop-shadow(0 0 25px #c77dff) blur(1px);
    }
    75% {
        transform: scale(0.98, 1.02) rotate(-1deg) translate(1px, -1px);
        opacity: 1;
        filter: brightness(1.1) drop-shadow(0 0 15px rgba(157, 78, 221, 0.4));
    }
    100% {
        transform: scale(1) rotate(0deg) translate(0, 0);
        opacity: 1;
        filter: brightness(1) drop-shadow(0 0 0 rgba(0, 0, 0, 0));
    }
}

#narratorCard.ui-reconstituting-in .perched-nav-btns button,
#narratorCard.ui-reconstituting-in .narrator-mini-btn,
#narratorCard.ui-reconstituting-in .perched-bubble-tag,
#narratorCard.ui-reconstituting-in .perched-bubble-tail,
#narratorCard.ui-reconstituting-in .narrator-speech-body,
#narratorCard.ui-reconstituting-in #narratorStepTag {
    animation: elementReconstitute 760ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes elementReconstitute {
    0% {
        transform: scale(0.4) translateY(12px);
        opacity: 0;
    }
    60% {
        transform: scale(1.06) translateY(-2px);
        opacity: 1;
    }
    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

/* Speech Dialogue Bubble - Authentic Comic/Game Dialogue Callout Aesthetic */
.perched-speech-bubble {
    position: relative;
    flex: 1;
    width: 320px;
    max-width: 340px;
    background: linear-gradient(145deg, rgba(14, 8, 25, 0.94) 0%, rgba(7, 3, 14, 0.97) 100%);
    backdrop-filter: blur(24px) saturate(160%);
    -webkit-backdrop-filter: blur(24px) saturate(160%);
    border: 1px solid rgba(199, 125, 255, 0.28);
    border-radius: 16px;
    padding: 0.95rem 1.15rem 0.85rem 1.15rem;
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.88), 
                0 0 25px rgba(157, 78, 221, 0.2),
                inset 0 1px 0 rgba(255, 255, 255, 0.12),
                inset 0 0 20px rgba(157, 78, 221, 0.05);
    font-family: var(--font-syne), -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    transform-origin: top right;
    transition: opacity 250ms ease, transform 250ms cubic-bezier(0.16, 1, 0.3, 1), border-color 200ms ease, box-shadow 200ms ease;
    margin-bottom: 0;
    user-select: text;
}

.perched-speech-bubble::before {
    content: '';
    position: absolute;
    top: 0;
    left: 14px;
    right: 14px;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, rgba(199, 125, 255, 0.75) 25%, rgba(0, 255, 136, 0.5) 50%, rgba(157, 78, 221, 0.75) 75%, transparent 100%);
    pointer-events: none;
    border-radius: 16px 16px 0 0;
}

.perched-speech-bubble:hover {
    border-color: rgba(199, 125, 255, 0.55);
    box-shadow: 0 24px 56px rgba(0, 0, 0, 0.94), 
                0 0 35px rgba(157, 78, 221, 0.3),
                inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.perched-speech-bubble.bubble-hidden {
    opacity: 0;
    transform: scale(0.92) translateY(12px);
    pointer-events: none;
}

.perched-speech-bubble.minimized {
    opacity: 0;
    transform: scale(0.85) translateY(15px);
    pointer-events: none;
    display: none;
}

/* Bubble Pointer Tail pointing rightwards toward the character's mouth */
.perched-bubble-tail {
    position: absolute;
    top: 24px;
    right: -9px;
    bottom: auto;
    left: auto;
    width: 16px;
    height: 16px;
    background: rgba(14, 8, 25, 0.96);
    border-right: 1px solid rgba(199, 125, 255, 0.38);
    border-top: 1px solid rgba(199, 125, 255, 0.38);
    border-left: none;
    border-bottom: none;
    transform: rotate(45deg);
}

/* Header & Speaker Tag */
.perched-bubble-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 0.45rem;
    margin-bottom: 0.7rem;
}

.perched-bubble-tag {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    min-width: 0;
}

.narrator-speaker-name {
    font-family: var(--font-syne);
    font-size: 0.74rem;
    font-weight: 800;
    color: #ffffff;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
}

.perched-section-pill {
    font-family: var(--font-mono);
    font-size: 0.58rem;
    font-weight: 600;
    color: #c77dff;
    letter-spacing: 0.08em;
    background: rgba(157, 78, 221, 0.14);
    border: 1px solid rgba(199, 125, 255, 0.25);
    border-radius: 999px;
    padding: 0.1rem 0.45rem;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

.perched-singularity-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #00ff88;
    box-shadow: 0 0 8px #00ff88, 0 0 16px rgba(0, 255, 136, 0.6);
    display: inline-block;
    flex-shrink: 0;
}

.perched-bubble-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* Speed Indicator Badge (Kept in DOM for test suite, visually suppressed) */
.perched-speed-badge {
    display: none;
}

.perched-speed-badge.hidden {
    display: none;
}

/* Dialogue Speech Body - Highly legible, comfortable line-height */
.perched-bubble-body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 0.85rem;
    line-height: 1.5;
    color: #f1edfa;
    font-weight: 400;
    letter-spacing: 0.005em;
    min-height: 44px;
    margin-bottom: 0.7rem;
}

.narrator-typing-cursor {
    display: inline-block;
    width: 4px;
    height: 13px;
    background: #00ff88;
    margin-left: 2px;
    vertical-align: -1px;
    animation: typingCursorBlink 750ms infinite ease-in-out;
}

@keyframes typingCursorBlink {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}

/* Footer & Navigation Controls */
.perched-bubble-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.6rem;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    padding-top: 0.5rem;
}

.perched-travel-meta {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 600;
    color: rgba(199, 125, 255, 0.7);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* Narrator Header Controls */
.narrator-mini-btn {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #c77dff;
    font-size: 0.85rem;
    line-height: 1;
    cursor: pointer;
    transition: all 180ms ease;
    flex-shrink: 0;
    padding: 0;
}

.narrator-mini-btn:hover {
    background: rgba(199, 125, 255, 0.2);
    border-color: #c77dff;
    color: #ffffff;
    transform: scale(1.1);
}

.narrator-mini-btn:active {
    transform: scale(0.95);
}

.perched-nav-btns {
    display: flex;
    gap: 0.4rem;
}

.perched-nav-btns .narrator-primary-btn {
    background: linear-gradient(135deg, #7b2cbf 0%, #9d4edd 55%, #c77dff 100%);
    color: #ffffff;
    border: 1px solid rgba(243, 232, 255, 0.45);
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    padding: 0.26rem 0.75rem;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(123, 44, 191, 0.35);
    transition: all 180ms ease;
}

.perched-nav-btns .narrator-primary-btn:hover {
    background: linear-gradient(135deg, #9d4edd 0%, #c77dff 55%, #ffffff 100%);
    box-shadow: 0 6px 18px rgba(157, 78, 221, 0.55);
    transform: translateY(-1px);
}

.perched-nav-btns .narrator-primary-btn:active {
    transform: translateY(1px) scale(0.97);
}

.perched-nav-btns .narrator-secondary-btn {
    background: #0f071a;
    border: 1px solid rgba(199, 125, 255, 0.45);
    color: #d8b4fe;
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    padding: 0.26rem 0.65rem;
    border-radius: 999px;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: all 180ms ease;
}

.perched-nav-btns .narrator-secondary-btn:hover {
    border-color: rgba(199, 125, 255, 0.4);
    background: rgba(199, 125, 255, 0.12);
    color: #ffffff;
    transform: translateY(-1px);
}

.perched-nav-btns .narrator-secondary-btn:active {
    transform: translateY(1px) scale(0.97);
}

/* Responsive Scaling for Mobile (< 768px) */
@media (max-width: 768px) {
    .perched-narrator-system {
        margin: 0;
        height: 0;
        padding: 0;
        overflow: visible;
    }
    .perched-narrator-system.at-hero.minimized-companion .perched-speech-bubble {
        display: none !important;
    }
    .perched-narrator-system.at-hero.minimized-companion .perched-figure-box {
        width: 72px;
        height: 114px;
    }
    .perched-narrator-system.at-hero .perched-character-container {
        transform: translateY(210px);
        margin-right: 0.25rem;
        gap: 0.4rem;
        flex-direction: column !important;
        align-items: flex-end;
    }
    .perched-narrator-system.at-flank .perched-character-container,
    .perched-character-container {
        flex-direction: column !important; /* Speech bubble strictly ABOVE avatar on mobile */
        align-items: flex-end;
        gap: 0.4rem;
        margin-right: 0.25rem;
        max-width: 100%;
        transform: translateY(0);
    }
    .perched-figure-box {
        width: 82px;
        height: 130px;
    }
    .perched-speech-bubble {
        width: calc(100vw - 28px);
        max-width: 330px;
        margin-bottom: 0;
        padding: 0.85rem 0.95rem;
        transform-origin: bottom right;
    }
    .perched-bubble-tail {
        display: block !important;
        top: auto !important;
        bottom: -8px !important;
        right: 36px !important; /* Points directly down into avatar's head/mouth */
        border-right: 1px solid rgba(199, 125, 255, 0.38) !important;
        border-bottom: 1px solid rgba(199, 125, 255, 0.38) !important;
        border-top: none !important;
        border-left: none !important;
        transform: rotate(45deg) !important;
    }
    .perched-bubble-body {
        font-size: 0.82rem;
        min-height: 40px;
        margin-bottom: 0.6rem;
    }
}
