/* =========================================
   1. DESKTOP BASE STYLES
   ========================================= */
.anim-stage {
    position: relative;
    width: 100%;
    max-width: 800px;
    height: 240px;
    margin: 0 auto;
    background: radial-gradient(ellipse at center, #1e293b 0%, #020617 70%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    overflow: hidden;
    font-family: monospace, sans-serif;
    z-index: 1;
}

.router-boundary {
    position: absolute;
    top: 20px;
    bottom: 40px;
    left: 170px;
    right: 170px;
    border: 1px dashed rgba(56, 189, 248, 0.3);
    border-radius: 12px;
    background: rgba(56, 189, 248, 0.03);
    z-index: 2;
}

.boundary-label {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: #020617;
    padding: 0 10px;
    color: #38bdf8;
    font-size: 0.7rem;
    font-weight: bold;
    border: 1px solid #1e293b;
    border-radius: 10px;
    white-space: nowrap;
}

.anim-lines-desktop {
    display: block;
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
}

.anim-lines-mobile {
    display: none;
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
}

.line-base {
    stroke: #334155;
    stroke-width: 4;
    fill: none;
    stroke-linecap: round;
}

.line-err {
    stroke: #ef4444;
    stroke-width: 2;
    fill: none;
    stroke-dasharray: 6 4;
    opacity: 0.3;
}

.line-succ {
    stroke: #22c55e;
    stroke-width: 2;
    fill: none;
    stroke-dasharray: 8 6;
    opacity: 0.2;
}

/* NODES (Desktop Positions) */
.anim-node {
    position: absolute;
    top: 120px;
    width: 0;
    height: 0;
    z-index: 10;
    display: flex;
    justify-content: center;
}

.node-1 {
    left: 80px;
}

.node-2 {
    left: 240px;
}

.node-3 {
    left: 400px;
}

.node-4 {
    left: 560px;
}

.node-5 {
    left: 720px;
}

.node-icon {
    position: absolute;
    top: -30px;
    left: -30px;
    width: 60px;
    height: 60px;
    background: #0f172a;
    border: 2px solid #334155;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    transition: 0.3s;
    z-index: 2;
    overflow: visible;
}

.icon-security, .icon-mask, .icon-router {
    overflow: hidden;
}

/* Clip effects inside */

.external-node {
    border-style: dotted;
}

.internal-node {
    border-style: solid;
}

/* LABELS & TEXT (Desktop) */
.node-label {
    position: absolute;
    top: 45px;
    width: 140px;
    left: -70px;
    text-align: center;
    color: #94a3b8;
    font-size: 0.75rem;
    font-weight: bold;
}

.node-status-text {
    position: absolute;
    top: 65px;
    width: 140px;
    left: -70px;
    text-align: center;
    font-size: 0.7rem;
    font-weight: bold;
    font-family: monospace;
}

/* POPOVERS (Desktop defaults: Top Center) */
.node-popover {
    position: absolute;
    top: -95px;
    left: -80px; /* Default offset */
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid #334155;
    border-radius: 6px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 20;
}

.popover-mask {
    left: -105px;
}

.popover-provider {
    left: -75px;
}

.p-txt {
    position: absolute;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 0.7rem;
    font-weight: bold;
    display: block;
    top: 8px;
}

/* PACKETS (Desktop Paths) */
.packet {
    position: absolute;
    top: 0;
    left: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    z-index: 5;
    opacity: 0;
}

.packet-blue {
    background: #38bdf8;
    box-shadow: 0 0 10px #38bdf8;
    animation: move-blue 12s linear infinite;
    offset-path: path("M 80 120 L 720 120");
}

.packet-red {
    background: #ef4444;
    box-shadow: 0 0 10px #ef4444;
    animation: move-red 12s linear infinite;
    offset-path: path("M 240 120 Q 160 60 80 120");
}

.packet-green {
    background: #22c55e;
    box-shadow: 0 0 10px #22c55e;
    animation: move-green 12s linear infinite;
    offset-path: path("M 720 120 Q 400 240 80 120");
}

/* --- EFFECTS --- */

/* Satellites */
.provider-satellites {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    z-index: 1;
}

.sat {
    position: absolute;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.55rem;
    font-weight: bold;
    color: #94a3b8;
    background: #0f172a;
    border: 1px solid #334155;
    white-space: nowrap;
    opacity: 0;
    transform: scale(0);
    animation: sat-anim 12s infinite;
}

.sat-1 {
    top: -60px;
    left: -50px;
}

.sat-2 {
    top: -60px;
    left: 10px;
}

.sat-3 {
    top: 40px;
    left: -50px;
}

.sat-4 {
    top: 40px;
    left: 10px;
}

.sat.selected {
    animation: sat-anim-sel 12s infinite;
}

.sat-line {
    position: absolute;
    width: 2px;
    height: 0;
    background: #22c55e;
    opacity: 0;
    transform-origin: bottom center;
    animation: line-anim 12s infinite;
}

.line-2 {
    top: -30px;
    left: 20px;
    height: 30px;
    transform: rotate(-20deg);
}

/* Scan Line */
.scan-line {
    position: absolute;
    width: 100%;
    height: 2px;
    top: 0;
    left: 0;
    background: #ef4444;
    box-shadow: 0 0 10px #ef4444;
    opacity: 0;
    animation: scan-anim 12s linear infinite;
}

/* Glitch */
.icon-mask {
    animation: glitch-anim 12s linear infinite;
}

/* Spinner */
.thinking-ring {
    position: absolute;
    inset: 2px;
    border-radius: 12px;
    border: 2px dashed transparent;
    opacity: 0;
    animation: spin-anim 12s linear infinite;
}

/* Ripple */
.signal-ripple {
    position: absolute;
    top: -30px;
    left: -30px;
    width: 60px;
    height: 60px;
    border: 2px solid #38bdf8;
    border-radius: 14px;
    opacity: 0;
    pointer-events: none;
    z-index: 1;
    animation: ripple-anim 12s infinite;
}

.signal-ripple.delay {
    animation-delay: 0.4s;
}

/* --- KEYFRAMES --- */
@keyframes move-blue {
    0% {
        offset-distance: 0%;
        opacity: 0;
    }
    5% {
        opacity: 1;
    }
    15%, 25% {
        offset-distance: 25%;
    }
    35%, 45% {
        offset-distance: 50%;
    }
    55%, 65% {
        offset-distance: 75%;
    }
    75% {
        offset-distance: 100%;
        opacity: 1;
    }
    80% {
        opacity: 0;
    }
    100% {
        offset-distance: 100%;
        opacity: 0;
    }
}

@keyframes move-red {
    0%, 15% {
        offset-distance: 0%;
        opacity: 0;
    }
    16% {
        opacity: 1;
    }
    30% {
        offset-distance: 100%;
        opacity: 1;
    }
    35% {
        opacity: 0;
    }
    100% {
        offset-distance: 100%;
        opacity: 0;
    }
}

@keyframes move-green {
    0%, 75% {
        offset-distance: 0%;
        opacity: 0;
    }
    76% {
        opacity: 1;
    }
    95% {
        offset-distance: 100%;
        opacity: 1;
    }
    100% {
        offset-distance: 100%;
        opacity: 0;
    }
}

@keyframes pulse-user {
    0%, 10% {
        border-color: #38bdf8;
        box-shadow: 0 0 15px rgba(56, 189, 248, 0.4);
    }
    30%, 35% {
        border-color: #ef4444;
        box-shadow: 0 0 15px rgba(239, 68, 68, 0.5);
    }
    40%, 93% {
        border-color: #334155;
        box-shadow: none;
    }
    95%, 100% {
        border-color: #22c55e;
        background: rgba(34, 197, 94, 0.1);
        box-shadow: 0 0 20px rgba(34, 197, 94, 0.5);
    }
}

@keyframes pulse-sec {
    15%, 23% {
        border-color: #ef4444;
        background: rgba(239, 68, 68, 0.1);
    }
    24%, 30% {
        border-color: #22c55e;
        background: #0f172a;
    }
}

@keyframes pulse-mask {
    35%, 45% {
        border-color: #c084fc;
        background: rgba(192, 132, 252, 0.1);
        box-shadow: 0 0 15px rgba(192, 132, 252, 0.4);
    }
}

@keyframes pulse-route {
    55%, 65% {
        border-color: #38bdf8;
        box-shadow: 0 0 15px rgba(56, 189, 248, 0.4);
    }
}

@keyframes pulse-prov {
    75%, 85% {
        border-color: #22c55e;
        background: rgba(34, 197, 94, 0.1);
        box-shadow: 0 0 15px rgba(34, 197, 94, 0.4);
    }
}

@keyframes scan-anim {
    15% {
        opacity: 1;
        top: 0;
        background: #ef4444;
    }
    19% {
        top: 100%;
    }
    20% {
        opacity: 0;
    }
    24% {
        opacity: 1;
        top: 0;
        background: #22c55e;
        box-shadow: 0 0 10px #22c55e;
    }
    28% {
        top: 100%;
        opacity: 1;
    }
    30% {
        opacity: 0;
    }
}

@keyframes glitch-anim {
    0%, 34% {
        transform: translate(0);
        border-color: #334155;
    }
    35% {
        border-color: #c084fc;
        background: rgba(192, 132, 252, 0.1);
    }
    36% {
        transform: translate(-2px, 1px);
    }
    38% {
        transform: translate(1px, 2px);
    }
    40% {
        transform: translate(0);
    }
    45% {
        border-color: #334155;
        background: #0f172a;
    }
}

@keyframes spin-anim {
    55% {
        opacity: 1;
        border-color: #38bdf8;
        transform: rotate(0deg);
    }
    65% {
        opacity: 1;
        border-color: #38bdf8;
        transform: rotate(180deg);
    }
    70% {
        opacity: 0;
    }
}

@keyframes ripple-anim {
    0% {
        transform: scale(1);
        opacity: 0.8;
        border-width: 2px;
    }
    8% {
        transform: scale(2.2);
        opacity: 0;
        border-width: 0px;
    }
    100% {
        transform: scale(2.2);
        opacity: 0;
    }
}

@keyframes sat-anim {
    70% {
        opacity: 0;
        transform: scale(0);
    }
    72% {
        opacity: 1;
        transform: scale(1);
    }
    75% {
        opacity: 1;
    }
    85% {
        opacity: 0;
        transform: scale(0.5);
    }
    100% {
        opacity: 0;
    }
}

@keyframes sat-anim-sel {
    70% {
        opacity: 0;
        transform: scale(0);
    }
    72% {
        opacity: 1;
        transform: scale(1);
    }
    75% {
        border-color: #22c55e;
        color: #22c55e;
        background: rgba(34, 197, 94, 0.1);
        transform: scale(1.2);
        z-index: 20;
    }
    85% {
        opacity: 0;
        transform: scale(0.5);
    }
    100% {
        opacity: 0;
    }
}

@keyframes line-anim {
    74% {
        opacity: 0;
        height: 0;
    }
    75% {
        opacity: 1;
        height: 30px;
    }
    82% {
        opacity: 1;
        height: 30px;
    }
    85% {
        opacity: 0;
        height: 0;
    }
}

/* Popover Vis */
.popover-security {
    animation: pop-sec 12s infinite;
}

.popover-mask {
    animation: pop-mask 12s infinite;
}

.popover-router {
    animation: pop-route 12s infinite;
}

.popover-provider {
    animation: pop-prov 12s infinite;
}

@keyframes pop-sec {
    15%, 30% {
        opacity: 1;
        transform: translateY(0);
    }
    0%, 10%, 35%, 100% {
        opacity: 0;
        transform: translateY(10px);
    }
}

@keyframes pop-mask {
    35%, 50% {
        opacity: 1;
        transform: translateY(0);
    }
    0%, 30%, 55%, 100% {
        opacity: 0;
        transform: translateY(10px);
    }
}

@keyframes pop-route {
    55%, 68% {
        opacity: 1;
        transform: translateY(0);
    }
    0%, 50%, 75%, 100% {
        opacity: 0;
        transform: translateY(10px);
    }
}

@keyframes pop-prov {
    70%, 88% {
        opacity: 1;
        transform: translateY(0);
    }
    0%, 65%, 93%, 100% {
        opacity: 0;
        transform: translateY(10px);
    }
}

/* Texts */
.t-check {
    color: #94a3b8;
    animation: txt-check 12s infinite;
}

.t-block {
    color: #ef4444;
    animation: txt-block 12s infinite;
    opacity: 0;
}

.t-pass {
    color: #22c55e;
    animation: txt-pass 12s infinite;
    opacity: 0;
}

@keyframes txt-check {
    0%, 19% {
        opacity: 1;
    }
    20%, 100% {
        opacity: 0;
    }
}

@keyframes txt-block {
    20%, 23% {
        opacity: 1;
        transform: translateY(0);
    }
    0%, 19% {
        opacity: 0;
        transform: translateY(5px);
    }
    24%, 100% {
        opacity: 0;
        transform: translateY(-5px);
    }
}

@keyframes txt-pass {
    24%, 30% {
        opacity: 1;
        transform: translateY(0);
    }
    0%, 23% {
        opacity: 0;
        transform: translateY(5px);
    }
    35%, 100% {
        opacity: 0;
        transform: translateY(-5px);
    }
}

.t-raw {
    color: #ef4444;
    animation: txt-raw 12s infinite;
}

.t-masked {
    color: #22c55e;
    animation: txt-masked 12s infinite;
    opacity: 0;
}

@keyframes txt-raw {
    0%, 41% {
        opacity: 1;
    }
    42%, 100% {
        opacity: 0;
    }
}

@keyframes txt-masked {
    0%, 41% {
        opacity: 0;
        transform: translateY(5px);
    }
    42%, 50% {
        opacity: 1;
        transform: translateY(0);
    }
    55%, 100% {
        opacity: 0;
        transform: translateY(-5px);
    }
}

.node-status-text::after {
    content: '';
    animation: txt-status 12s infinite;
}

@keyframes txt-status {
    0% {
        content: 'Sending...';
        color: #38bdf8;
    }
    15% {
        content: 'Safety Check...';
        color: #94a3b8;
    }
    30% {
        content: 'Blocked 🚫';
        color: #ef4444;
    }
    45% {
        content: 'Masking PII...';
        color: #c084fc;
    }
    55% {
        content: 'Routing...';
        color: #38bdf8;
    }
    95% {
        content: 'Success ✅';
        color: #22c55e;
    }
    100% {
        content: '';
    }
}


/* =========================================
   6. MOBILE OVERRIDES (FIXED)
   ========================================= */
@media (max-width: 768px) {
    /* 1. Blokujemy szerokość kontenera, żeby SVG się nie rozciągało */
    .anim-stage {
        width: 320px;
        max-width: 320px;
        margin: 0 auto;
        height: 660px;
    }

    .anim-lines-desktop {
        display: none;
    }

    .anim-lines-mobile {
        display: block;
    }

    /* Ramka pionowa */
    .router-boundary {
        top: 150px;
        bottom: 150px;
        left: 30px;
        right: 30px;
    }

    /* Reset węzłów do środka */
    .anim-node {
        left: 50% !important;
        transform: translateX(-50%);
    }

    /* Pozycje Y */
    .node-1 {
        top: 60px;
    }

    /* User */
    .node-2 {
        top: 180px;
    }

    /* Guard */
    .node-3 {
        top: 300px;
    }

    /* Mask */
    .node-4 {
        top: 420px;
    }

    /* Router */
    .node-5 {
        top: 540px;
    }

    /* Prov */
    /* Label (Prawo) */
    .node-label {
        top: 18px;
        left: 45px;
        text-align: left;
    }

    .node-status-text {
        top: 38px;
        left: 45px;
        text-align: left;
    }

    /* Popover (Lewo) - Rozdzielamy strony, żeby się nie nakładały */
    .node-popover {
        top: 5px;
        left: auto;
        right: 45px; /* Zakotwiczony z prawej krawędzi ikony = leci w lewo */
        align-items: flex-end;
    }

    .p-txt {
        text-align: right;
        right: 6px;
        left: auto;
    }

    /* Tekst do prawej w dymku */
    /* Ścieżki Mobile (Offset Path musi pasować do SVG Mobile) */
    /* M 160 90 L 160 570 */
    .packet-blue {
        offset-path: path("M 160 90 L 160 570") !important;
    }

    /* M 160 210 Q 60 150 160 90 */
    .packet-red {
        offset-path: path("M 160 210 Q 60 150 160 90") !important;
    }

    /* M 160 570 Q 280 330 160 90 */
    .packet-green {
        offset-path: path("M 160 570 Q 280 330 160 90") !important;
    }

    /* Satellites Mobile - Bliżej i mniejsze */
    .provider-satellites {
        transform: scale(0.7);
    }

    .sat-1 {
        top: -45px;
        left: -45px;
    }

    .sat-2 {
        top: -45px;
        left: 45px;
    }

    .sat-3 {
        top: 45px;
        left: -45px;
    }

    .sat-4 {
        top: 45px;
        left: 45px;
    }

    .line-2 {
        height: 20px;
        top: -20px;
        left: 20px;
    }
}