/* =========================
   DEMO CLUSTER LAYOUT
========================= */

#demo-cluster{

    display:grid;

    grid-template-columns: 360px 1fr;

    grid-template-areas:
        "demo nodes"
        "log log";

    grid-template-rows: auto auto;

    gap:20px;

    padding:50px 50px;

    align-items:stretch;

    position:relative;
}

#demo-cluster .raft-log {
    
  padding-top: 18px;   /* antes era 40px */
}

#demo-cluster .log-title {
  margin-top: 0;
  margin-bottom: 12px; /* antes 20px */
}

#demo-cluster .resultado {

  width: 100%;
  max-width: 740px;

  min-height: 110px;
  max-height: 180px;   /* misma altura fija */

  overflow-y: auto;    /* scroll interno */

  white-space: pre;    /* respeta saltos */
}

#demo-cluster .terminal {

  overflow-x: hidden;
  white-space: pre-wrap; /* evita que el texto se salga */

}

#demo-cluster .resultado::-webkit-scrollbar {
  width: 6px;
}

#demo-cluster .resultado::-webkit-scrollbar-thumb {
  background: #00ff88;
  border-radius: 4px;
}

#demo-cluster .terminal::-webkit-scrollbar {
  width: 6px;
}

#demo-cluster .terminal::-webkit-scrollbar-track {
  background: transparent;
}

#demo-cluster .terminal::-webkit-scrollbar-thumb {
  background: linear-gradient(#00eaff, #7b2bff);
  border-radius: 6px;
  box-shadow: 0 0 6px #00eaff;
}

#demo-cluster .terminal::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(#00ffff, #8a4dff);
}

/* =========================
   PANEL IZQUIERDO
========================= */

.demo-panel{
    grid-area:demo;
    display:flex;
    flex-direction:column;
}

.demo-title{
    font-size:30px;
    background: linear-gradient(90deg, #00eaff, #7b2bff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom:16px;
    white-space: nowrap;
}


/* BOTONES */

.demo-buttons{
    display:flex;
    flex-wrap:wrap;
    gap:8px;
    margin-bottom:16px;
}

.demo-buttons button{

    padding:9px 14px;

    border-radius:10px;

    border:none;

    background:linear-gradient(90deg,#00eaff,#7b2bff);

    color:white;

    font-weight:600;
    font-size:13px;

    box-shadow:0 0 16px rgba(0,234,255,.5);

    cursor:pointer;
}




/* TERMINAL */

.terminal{

    flex:1;
    min-height:80px;

    border-radius:14px;

    border:1px solid rgba(0,234,255,.2);

    background:rgba(0,0,0,.4);

    margin-bottom:12px;

    padding:14px 16px;

    overflow:hidden;
}

.resultado{

    height:80px;
    flex-shrink:0;

    border-radius:14px;

    border:1px solid rgba(0,234,255,.15);

    background:rgba(0,0,0,.25);

    padding:14px 16px;
}


/* =========================
   NODOS
========================= */

.cluster-network{
    grid-area:nodes;
    display:flex;
    gap:12px;
    margin-left:0;
    margin-top:0;
    align-items:stretch;
}

.cluster-node{

    flex:1;
    min-width:0;

    padding:18px;

    border-radius:16px;

    display:flex;
    flex-direction:column;

    background:rgba(10,10,30,.8);

    border:1px solid rgba(0,234,255,.25);

    box-shadow:0 0 20px rgba(0,234,255,.1);

    backdrop-filter:blur(6px);
}

.cluster-node h3{

    color:#00eaff;

    margin-bottom:10px;
}

.node-region,
.node-latency{

    font-size:13px;

    opacity:.8;

    margin-bottom:8px;
}


/* NODE HEADER */

.node-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.node-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 20px;
    letter-spacing: 0.5px;
}
.node-badge.live {
    background: rgba(0,255,136,0.15);
    color: #00ff88;
    border: 1px solid rgba(0,255,136,0.4);
}
.node-badge.dead {
    background: rgba(255,59,59,0.15);
    color: #ff3b3b;
    border: 1px solid rgba(255,59,59,0.4);
}

/* DIVIDER */

.node-divider {
    height: 1px;
    background: rgba(0,234,255,0.12);
    margin: 12px 0;
}

/* STATS */

.node-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 12px;
}

.node-stat {
    display: flex;
    flex-direction: column;
    background: rgba(0,0,0,0.3);
    border-radius: 8px;
    padding: 6px 8px;
    border: 1px solid rgba(0,234,255,0.08);
}

.stat-label {
    font-size: 10px;
    color: #6e7681;
    margin-bottom: 2px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.stat-val {
    font-size: 12px;
    font-weight: 700;
    color: #00eaff;
}

.stat-val a {
    color: #7b2bff;
    text-decoration: none;
}
.stat-val a:hover { text-decoration: underline; }

/* HEARTBEAT */

.node-heartbeat {
    margin-top: auto;
    padding-top: 8px;
}

.hb-label {
    font-size: 10px;
    color: #6e7681;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: block;
    margin-bottom: 5px;
}

.hb-bars {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 28px;
}

.hb-bar {
    flex: 1;
    background: #00ff88;
    border-radius: 2px;
    animation: hbPulse 1.2s ease-in-out infinite;
    box-shadow: 0 0 4px rgba(0,255,136,0.5);
}
.hb-bar:nth-child(1) { animation-delay: 0s;    height: 40%; }
.hb-bar:nth-child(2) { animation-delay: 0.1s;  height: 70%; }
.hb-bar:nth-child(3) { animation-delay: 0.2s;  height: 100%;}
.hb-bar:nth-child(4) { animation-delay: 0.3s;  height: 55%; }
.hb-bar:nth-child(5) { animation-delay: 0.4s;  height: 80%; }
.hb-bar:nth-child(6) { animation-delay: 0.5s;  height: 30%; }
.hb-bar:nth-child(7) { animation-delay: 0.6s;  height: 90%; }
.hb-bar:nth-child(8) { animation-delay: 0.7s;  height: 60%; }
.hb-bar:nth-child(9) { animation-delay: 0.8s;  height: 45%; }

@keyframes hbPulse {
    0%, 100% { opacity: 0.3; transform: scaleY(0.6); }
    50%       { opacity: 1;   transform: scaleY(1);   }
}

.node-dead .hb-bar {
    background: #ff3b3b;
    box-shadow: 0 0 4px rgba(255,59,59,0.4);
    animation: hbFlat 0.5s ease forwards;
}
@keyframes hbFlat {
    to { height: 2px !important; opacity: 0.3; }
}

/* RANGES */

.range{

    padding:6px 10px;

    border-radius:8px;

    background:rgba(0,0,0,.4);

    margin-bottom:6px;

    font-size:13px;

    border:1px solid rgba(0,234,255,.2);
}

.range.leader{

    border:1px solid #00ff88;

    box-shadow:0 0 10px rgba(0,255,136,.5);
}


/* =========================
   BOTON NUCLEAR
========================= */

.nuclear-container{

    position:relative;

    width:100%;
    flex-basis:100%;
    height:44px;

    border-radius:50%;

    background:radial-gradient(circle,#ff4040,#990000);

    color:white;

    font-weight:bold;

    display:flex;
    align-items:center;
    justify-content:center;

    box-shadow:
        0 0 35px red,
        inset 0 0 20px #ff0000;

    animation:nuclearPulse 2s infinite;

}

@keyframes nuclearPulse{

    0%{box-shadow:0 0 25px red;}

    50%{box-shadow:0 0 60px red;}

    100%{box-shadow:0 0 25px red;}

}
.nuclear-button{
    opacity:0;
    pointer-events:none;
    transition:all .4s ease;
}



.safety-cover{

    width:100%;
    height:100%;

    border-radius:10px;

    background:#000;

    box-shadow:0 0 18px rgba(255,0,0,0.7);

    cursor:pointer;

    transform-origin:top;

    transition:transform .5s;

    overflow:hidden;

    animation: nuclearPulse 2s infinite;

}

.safety-cover.open{

    transform:rotateX(120deg);

}

.warning-stripes{

    width:100%;
    height:100%;

    border-radius:10px;

    background: repeating-linear-gradient(
        45deg,
        #ffdd00,
        #ffdd00 14px,
        #111 14px,
        #111 28px
    );
}

.nuclear-container #nuclear-button,
.nuclear-button{

    position:absolute !important;

    top:0;
    left:0;

    width:100%;
    height:100%;

    border:none;

    border-radius:10px;

    background: linear-gradient(90deg, #cc0000, #ff2020, #cc0000) !important;

    color:white;

    font-weight:800;
    font-size:13px;
    letter-spacing:1px;

    opacity:0;

    pointer-events:none;

    box-shadow: 0 0 20px rgba(255,0,0,0.6) !important;

}

/* =========================
   LOG PANEL
========================= */

.log-row{
    grid-area:log;
    width:100%;
    margin-top:0;
    padding-left:0;
}

.raft-log{

    border-radius:18px;

    padding:24px 30px;

    border:1px solid rgba(0,234,255,.35);

    background:rgba(0,0,0,.55);

    min-height:160px;

    box-shadow:0 0 35px rgba(0,255,200,.25);

    position:relative;
}

.log-title{

    text-align:center;

    color:#00eaff;

    font-size:20px;

    margin-bottom:14px;
}

/* LOG CONTENT */

#raft-log-content{

    font-family: monospace;
    line-height:1.8;
    font-size:15px;
    color:#00ff9c;
    text-align:left;

    max-height:180px;   /* limite del log */
    overflow-y:auto;    /* activa scroll vertical */
    padding-right:10px; /* evita que el texto toque el scrollbar */

}

#raft-log-content div{

    animation:fadeLine .25s ease;

}
#raft-log-content::-webkit-scrollbar{
    width:6px;
}

#raft-log-content::-webkit-scrollbar-thumb{
    background:#00eaff;
    border-radius:10px;
}

#raft-log-content div::after{

    content:"_";

    margin-left:4px;

    animation:cursorBlink 1s infinite;

}

@keyframes fadeLine{

    from{
        opacity:0;
        transform:translateY(6px);
    }

    to{
        opacity:1;
        transform:translateY(0);
    }

}

@keyframes cursorBlink{

    0%{opacity:1;}
    50%{opacity:0;}
    100%{opacity:1;}

}

@keyframes screenShake{

    0%{transform:translate(0,0);}
    20%{transform:translate(-4px,3px);}
    40%{transform:translate(4px,-3px);}
    60%{transform:translate(-3px,2px);}
    80%{transform:translate(3px,-2px);}
    100%{transform:translate(0,0);}

}

.screen-shake{

    animation:screenShake .45s ease;

}

.node-leader{

    border:2px solid #00ff88;

    box-shadow:
        0 0 20px #00ff88,
        0 0 40px #00ff88;

}

.range.leader{

    color:#00ff88;

    font-weight:bold;

}

@keyframes raftPulse{

    0%{box-shadow:0 0 10px #00ff88;}

    50%{
        box-shadow:
            0 0 30px #00ff88,
            0 0 60px #00ff88;
    }

    100%{box-shadow:0 0 10px #00ff88;}

}

.node-commit{

    animation:raftPulse .7s ease;

}

.log-raft{ color:#00eaff; }

.log-consensus{ color:#00ff88; }

.log-election{ color:#ffcc00; }

.log-fail{ color:#ff3b3b; }

.node-burning{

    position:relative;

    background:linear-gradient(180deg,#200000,#0a0000);

    border:1px solid #ff3b3b;

    animation:burningNode 1.5s infinite alternate;

}

@keyframes burningNode{

    0%{
        box-shadow:
        0 0 40px #ff3b3b,
        0 0 80px #ff0000,
        inset 0 0 40px rgba(255,0,0,.4);
    }

    100%{
        box-shadow:
        0 0 60px #ff3b3b,
        0 0 120px #ff0000,
        inset 0 0 70px rgba(255,0,0,.6);
    }

}

.node-burning::after {
    content: "";
    position: absolute;

    inset: -38px;
    /* EXPANDE el fuego alrededor */

    background-image: url("../img/fuego.webp");
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-position: center;

    pointer-events: none;
    z-index: 20;

    border-radius: 22px;

    animation: burnPulse 0.8s infinite alternate;
}

@keyframes burnPulse {
    0% {
        filter: brightness(1);
    }

    100% {
        filter: brightness(1.2);
    }
}

@keyframes fireFlicker {
    0% {
        transform: scale(1) rotate(-0.5deg);
    }

    100% {
        transform: scale(1.03) rotate(0.5deg);
    }
}

.explosion{

    position:absolute;

    left:50%;
    top:50%;

    width:12px;
    height:12px;

    background:radial-gradient(circle,#ffae00,#ff3b3b,#ff0000);

    border-radius:50%;

    transform:translate(-50%,-50%);

    pointer-events:none;

    box-shadow:
        0 0 12px #ff3b3b,
        0 0 25px #ff7b00,
        0 0 40px #ff0000;

    animation:explodeParticle 1.1s ease-out forwards;
}

@keyframes explodeParticle{

    0%{
        transform:translate(-50%,-50%) scale(1);
        opacity:1;
    }

    60%{
        opacity:1;
    }

    100%{
        transform:translate(calc(-50% + var(--x)), calc(-50% + var(--y))) scale(0.2);
        opacity:0;
    }

}

.shockwave{

    position:absolute;

    left:50%;
    top:50%;

    width:20px;
    height:20px;

    border-radius:50%;

    border:3px solid #ff3b3b;

    transform:translate(-50%,-50%);

    animation:shockExpand .9s ease-out forwards;

    pointer-events:none;

}

@keyframes shockExpand{

    0%{
        width:20px;
        height:20px;
        opacity:1;
    }

    100%{
        width:420px;
        height:420px;
        opacity:0;
    }

}
.fire-particle{

    position:absolute;

    width:6px;
    height:6px;

    background:#ff5e00;

    border-radius:50%;

    box-shadow:0 0 10px #ff3b3b;

    animation:fireRise 1.6s linear forwards;

}

@keyframes fireRise{

    0%{
        transform:translateY(0) scale(1);
        opacity:1;
    }

    100%{
        transform:translateY(-120px) scale(.3);
        opacity:0;
    }

}
.node-meltdown{

    position:relative;

    background:
    radial-gradient(circle at 50% 120%, #ff0000, #3a0000 70%);

    overflow:hidden;

}

.node-meltdown::before{

    content:"";

    position:absolute;

    inset:-50%;

    background:
    repeating-linear-gradient(
        45deg,
        rgba(255,0,0,.2),
        rgba(255,80,0,.2) 40px,
        rgba(0,0,0,.2) 80px
    );

    animation:lavaFlow 6s linear infinite;

    filter:blur(25px);

}

@keyframes lavaFlow{

    0%{transform:translateY(0);}
    100%{transform:translateY(200px);}

}
.electric{

    position:absolute;

    width:3px;
    height:60px;

    background:#ff2600;

    box-shadow:
        0 0 12px #ff0000,
        0 0 30px #ffa600;

    animation:electricFlash .3s linear forwards;

}

@keyframes electricFlash{

    0%{
        transform:scaleY(.2);
        opacity:1;
    }

    100%{
        transform:scaleY(1.6);
        opacity:0;
    }

}

/* ====================================
   EPIC NODE FAILURE — EXTRA EFFECTS
==================================== */

/* Flash rojo que cubre toda la pantalla */
.screen-flash{
    position:fixed;
    inset:0;
    background:radial-gradient(circle at center,
        rgba(255,100,0,.9),
        rgba(255,0,0,.6) 40%,
        transparent 75%);
    z-index:9999;
    pointer-events:none;
    animation:screenFlashFade .55s ease-out forwards;
}
@keyframes screenFlashFade{
    0%  { opacity:1; }
    100%{ opacity:0; }
}

/* Vignette roja pulsante en los bordes */
.red-alert{
    position:fixed;
    inset:0;
    z-index:9998;
    pointer-events:none;
    box-shadow:inset 0 0 200px rgba(255,0,0,.75);
    animation:redAlertPulse .35s ease-in-out 5 alternate;
}
@keyframes redAlertPulse{
    from{ opacity:0; }
    to  { opacity:1; }
}

/* Texto dramático centrado en pantalla */
.critical-text{
    position:fixed;
    top:50%;
    left:50%;
    transform:translate(-50%,-50%);
    font-family:'Orbitron',sans-serif;
    font-size:clamp(28px,4.5vw,64px);
    color:#ff3b3b;
    text-shadow:
        0 0 20px #ff0000,
        0 0 55px #ff0000,
        0 0 110px rgba(255,0,0,.5);
    letter-spacing:6px;
    text-align:center;
    white-space:nowrap;
    z-index:9997;
    pointer-events:none;
    animation:criticalTextAnim 2.2s ease-out forwards;
}
@keyframes criticalTextAnim{
    0%  { opacity:0; transform:translate(-50%,-50%) scale(.4) skewX(-4deg); }
    12% { opacity:1; transform:translate(-50%,-50%) scale(1.1) skewX(0deg); }
    25% { opacity:1; transform:translate(-50%,-50%) scale(1);   }
    70% { opacity:1; transform:translate(-50%,-50%) scale(1);   }
    100%{ opacity:0; transform:translate(-50%,-50%) scale(1.05); }
}

/* Shockwave extra — usamos misma clase pero con delay vía JS */
.shockwave-cyan{
    position:absolute;
    left:50%;
    top:50%;
    width:10px;
    height:10px;
    border-radius:50%;
    border:3px solid #00eaff;
    box-shadow:0 0 20px #00eaff, inset 0 0 10px rgba(0,234,255,.4);
    transform:translate(-50%,-50%);
    animation:empExpand .9s ease-out forwards;
    pointer-events:none;
}
@keyframes empExpand{
    0%  { width:10px;  height:10px;  opacity:1; border-width:4px; }
    100%{ width:700px; height:700px; opacity:0; border-width:1px; }
}

/* Debris — fragmentos grandes que salen girando */
.debris{
    position:absolute;
    left:50%;
    top:50%;
    width:var(--size,14px);
    height:calc(var(--size,14px) * .45);
    background:linear-gradient(90deg,#ff6600,#ffcc00);
    border-radius:3px;
    pointer-events:none;
    box-shadow:0 0 12px #ff3b3b, 0 0 28px #ff7b00;
    animation:debrisFly 1.9s ease-out forwards;
    animation-delay:var(--delay,0s);
}
@keyframes debrisFly{
    0%{
        transform:translate(-50%,-50%) rotate(var(--rot,0deg)) scale(1);
        opacity:1;
    }
    100%{
        transform:translate(calc(-50% + var(--x)),calc(-50% + var(--y)))
                  rotate(calc(var(--rot,0deg) + 720deg)) scale(.08);
        opacity:0;
    }
}

/* Screen shake más violento */
.screen-shake-epic{
    animation:screenShakeEpic .65s ease;
}
@keyframes screenShakeEpic{
    0%  { transform:translate(0,0)     rotate(0deg);   }
    8%  { transform:translate(-12px,9px) rotate(-.4deg); }
    16% { transform:translate(14px,-7px) rotate(.3deg);  }
    24% { transform:translate(-10px,-11px)rotate(-.5deg);}
    32% { transform:translate(13px,7px)  rotate(.4deg);  }
    40% { transform:translate(-14px,5px) rotate(-.3deg); }
    50% { transform:translate(10px,-9px) rotate(.35deg); }
    60% { transform:translate(-9px,11px) rotate(-.3deg); }
    70% { transform:translate(12px,-5px) rotate(.25deg); }
    82% { transform:translate(-8px,7px)  rotate(-.2deg); }
    92% { transform:translate(5px,-4px)  rotate(.1deg);  }
    100%{ transform:translate(0,0)     rotate(0deg);   }
}

/* ==========================================
   NODE FLICKER — "se va la luz" pre-fallo
   ========================================== */

@keyframes nodeFlicker {
    0%   { opacity: 1;    filter: brightness(1);    }
    8%   { opacity: 0.3;  filter: brightness(0.2);  }
    16%  { opacity: 0.9;  filter: brightness(0.8);  }
    27%  { opacity: 0.4;  filter: brightness(0.3);  }
    35%  { opacity: 0.85; filter: brightness(0.7);  }
    48%  { opacity: 0.1;  filter: brightness(0.05); }
    52%  { opacity: 0.75; filter: brightness(0.6);  }
    65%  { opacity: 0.2;  filter: brightness(0.1);  }
    75%  { opacity: 0.6;  filter: brightness(0.4);  }
    86%  { opacity: 0.05; filter: brightness(0);    }
    93%  { opacity: 0.3;  filter: brightness(0.2);  }
    100% { opacity: 0;    filter: brightness(0);    }
}

.node-flickering {
    animation: nodeFlicker 3s ease-in-out forwards !important;
    border-color: rgba(255, 120, 0, 0.55) !important;
    transition: none !important;
}