@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;500;700;900&display=swap');

:root {
    --bg-dark: #0a0e17;
    --acc-gold: #fbbf24;
    --acc-gold-glow: rgba(251, 191, 36, 0.5);
    --card-bg: rgba(255, 255, 255, 0.05);
    --border-light: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body.dark-mode {
    background: radial-gradient(circle at center, #1a2336 0%, var(--bg-dark) 100%);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden; /* No scroll en broadcast */
    display: flex;
    flex-direction: column;
}

.broadcast-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* HEADER */
.broadcast-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 40px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
    border-bottom: 1px solid var(--border-light);
}

.logo-zone {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo-zone i {
    font-size: 2.5rem;
    color: var(--acc-gold);
}

.glow-text {
    font-family: 'Outfit', sans-serif;
    font-size: 2rem;
    font-weight: 900;
    text-transform: none;
    letter-spacing: -0.5px;
    color: #fff;
    text-shadow: 0 0 15px var(--acc-gold-glow);
    display: flex;
    align-items: center;
    gap: 15px;
}

.live-badge {
    background: #ef4444;
    color: white;
    font-size: 0.9rem;
    padding: 4px 10px;
    border-radius: 4px;
    animation: blink-pulse 2s infinite;
}

.sorteo-info {
    text-align: right;
}

.sorteo-info h2 {
    font-size: 1.8rem;
    color: var(--acc-gold);
    text-shadow: 0 0 10px var(--acc-gold-glow);
}

.sorteo-info p {
    font-size: 1.2rem;
    color: var(--text-muted);
}

/* MAIN STAGE */
.main-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    perspective: 1200px; /* Habilitar 3D */
}

.status-message {
    font-size: 2rem;
    font-weight: 300;
    color: var(--text-muted);
}

.blink {
    animation: blink-slow 2s infinite;
}

/* SPOTLIGHT */
.spotlight {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* Quitamos el scale/opacity previo para manejarlo en la tarjeta */
}

.extraction-number {
    font-size: 1.8rem;
    font-weight: 900;
    color: #22c55e; /* Verde Lotto7 */
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 20px;
    text-shadow: 0 0 20px rgba(34, 197, 94, 0.4);
}

/* --- ESTRUCTURA TARJETA 3D --- */
.card-3d {
    width: 380px;
    height: 520px;
    perspective: 1000px;
    transform-style: preserve-3d;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 1s cubic-bezier(0.23, 1, 0.32, 1);
    transform-style: preserve-3d;
    transform: rotateY(90deg) scale(0.5); /* Inicialmente oculta de lado */
    opacity: 0;
}

.card-inner.reveal {
    transform: rotateY(0deg) scale(1);
    opacity: 1;
}

.spotlight-animal {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    background: rgba(255, 255, 255, 0.05);
    border: 3px solid var(--acc-gold);
    border-radius: 30px;
    padding: 40px;
    box-shadow: 0 0 50px var(--acc-gold-glow), inset 0 0 30px rgba(251, 191, 36, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    backdrop-filter: blur(15px);
}

.spotlight-img-wrapper {
    width: 200px;
    height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
    border-radius: 50%;
}

.spotlight-img-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 10px 15px rgba(0,0,0,0.5));
}

.emoji-large {
    font-size: 8rem;
    filter: drop-shadow(0 10px 15px rgba(0,0,0,0.5));
}

.spotlight-details {
    text-align: center;
}

.s-numero {
    font-size: 5rem;
    font-weight: 900;
    color: #fff;
    line-height: 1;
    text-shadow: 0 4px 10px rgba(0,0,0,0.5);
    margin-bottom: 5px;
}

.s-nombre {
    font-size: 2.5rem;
    font-weight: 500;
    color: var(--acc-gold);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.layout-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden; /* No scroll en el broadcast */
}

/* SIDEBAR IZQUIERDA (Grilla de Resultados) */
.results-sidebar {
    width: 520px;
    background: rgba(0,0,0,0.6);
    border-right: 1px solid var(--border-light);
    padding: 16px;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.grid-header {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-align: center;
}

.extracted-grid {
    display: grid;
    /* Caben 7 columnas por 5 filas (7x5=35) */
    grid-template-columns: repeat(7, minmax(0, 1fr));
    grid-template-rows: repeat(5, minmax(0, 1fr));
    gap: 8px;
    flex: 1;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

/* ==========================================================================
   ESTRUCTURA Y ANIMACIÓN 3D DE CARTA (CARD FLIP) PARA LOS 35 RECUADROS
   ========================================================================== */
.grid-item {
    background: transparent;
    border: none;
    padding: 0;
    position: relative;
    height: 100%;
    min-height: 0;
    perspective: 750px; /* Perspectiva 3D para el volteo de carta */
    cursor: default;
}

.card-flip-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.8s cubic-bezier(0.34, 1.25, 0.64, 1);
    border-radius: 8px;
}

/* Cuando el animalito ya fue extraído, la carta queda volteada 180 grados */
.grid-item.slot-revealed .card-flip-inner {
    transform: rotateY(180deg);
}

/* Animación cinematográfica de elevación y volteo como baraja de casino */
.grid-item.slot-flipping .card-flip-inner {
    animation: card-flip-lift 0.85s cubic-bezier(0.34, 1.25, 0.64, 1) forwards;
}

@keyframes card-flip-lift {
    0% {
        transform: rotateY(0deg) scale(1);
    }
    40% {
        transform: rotateY(90deg) scale(1.18);
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.9), 0 0 20px rgba(34, 197, 94, 0.8);
    }
    75% {
        transform: rotateY(180deg) scale(1.08);
        box-shadow: 0 6px 18px rgba(0, 0, 0, 0.8), 0 0 25px rgba(255, 215, 0, 0.85);
    }
    100% {
        transform: rotateY(180deg) scale(1);
        box-shadow: 0 4px 14px rgba(0, 0, 0, 0.7), 0 0 12px rgba(251, 191, 36, 0.25);
    }
}

/* Ambas caras de la carta */
.card-face {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-sizing: border-box;
    padding: 3px;
}

/* CARA FRONTAL (Dorso de la baraja: Logo Lotto 7 antes de salir) */
.card-face.card-front {
    background: linear-gradient(145deg, rgba(30, 41, 59, 0.8) 0%, rgba(15, 23, 42, 0.95) 100%);
    border: 1px dashed rgba(251, 191, 36, 0.35);
    box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.7), 0 2px 6px rgba(0, 0, 0, 0.4);
    transform: rotateY(0deg);
}

.card-face.card-front:hover {
    border-color: rgba(251, 191, 36, 0.6);
    background: linear-gradient(145deg, rgba(30, 41, 59, 0.95) 0%, rgba(15, 23, 42, 1) 100%);
}

.card-face .pos-tag {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 0.68rem;
    font-weight: 900;
    letter-spacing: -0.3px;
    font-family: 'Outfit', sans-serif;
    color: var(--acc-gold);
}

.card-face.card-front .pos-tag {
    opacity: 0.45;
}

/* Branding de Lotto 7 en el dorso */
.slot-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Outfit', sans-serif;
    font-weight: 900;
    line-height: 1;
    user-select: none;
    letter-spacing: -0.5px;
    margin-top: 4px;
}

.slot-brand .brand-lotto {
    font-size: 0.76rem;
    color: var(--acc-gold);
    text-shadow: 0 0 8px var(--acc-gold-glow);
}

.slot-brand .brand-7 {
    font-size: 0.95rem;
    color: #22c55e;
    text-shadow: 0 0 10px rgba(34, 197, 94, 0.6);
    margin-left: 1px;
}

/* CARA TRASERA (Cara revelada: Animalito, figura y número) */
.card-face.card-back {
    background: linear-gradient(145deg, rgba(30, 41, 59, 0.92) 0%, rgba(15, 23, 42, 0.98) 100%);
    border: 1.5px solid rgba(251, 191, 36, 0.65);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.7), 0 0 14px rgba(251, 191, 36, 0.3);
    transform: rotateY(180deg);
}

.card-face.card-back .pos-tag {
    opacity: 1;
    color: var(--acc-gold);
    text-shadow: 0 0 6px var(--acc-gold-glow);
}

.card-face.card-back .card-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.card-face.card-back img {
    max-height: 44px;
    width: auto;
    max-width: 88%;
    object-fit: contain;
    margin-top: 2px;
}

.card-face.card-back .grid-emoji {
    font-size: 1.8rem;
    line-height: 1;
    margin-top: 2px;
}

.card-face.card-back .g-num {
    font-size: 1.2rem;
    font-weight: 900;
    color: #fff;
    line-height: 1;
    margin-top: 1px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

/* Scrollbar para la grid */
.extracted-grid::-webkit-scrollbar {
    width: 8px;
}
.extracted-grid::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.2);
    border-radius: 4px;
}
.extracted-grid::-webkit-scrollbar-thumb {
    background: var(--acc-gold);
    border-radius: 4px;
}

/* ANIMATIONS */
@keyframes blink-pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 10px #ef4444; }
    50% { opacity: 0.5; box-shadow: 0 0 0px #ef4444; }
}

@keyframes blink-slow {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

@keyframes pop-in {
    0% { transform: scale(0.5) translateY(50px); opacity: 0; }
    70% { transform: scale(1.05); }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes pop-in-small {
    0% { transform: scale(0) translateY(20px); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* FULLSCREEN GRID MODE (Repeticiones automáticas) */
.broadcast-container.fullscreen .results-sidebar {
    width: 100% !important;
    border-right: none;
    align-items: center; 
    padding: 15px 20px;
    background: transparent;
}
.broadcast-container.fullscreen .grid-header {
    font-size: 2.2rem;
    color: var(--acc-gold);
    text-shadow: 0 0 15px var(--acc-gold-glow);
    margin-bottom: 20px;
}
.broadcast-container.fullscreen .main-stage {
    display: none !important;
}
.broadcast-container.fullscreen .extracted-grid {
    /* minmax(0, 1fr) fuerza a que nunca desborde el ancho disponible */
    grid-template-columns: repeat(7, minmax(0, 1fr));
    grid-template-rows: repeat(5, minmax(0, 1fr));
    width: 100%;
    height: 100%;
    gap: 10px;
    padding: 0;
    overflow: visible; 
}
.broadcast-container.fullscreen .card-face.card-back {
    flex-direction: row; 
    padding: 5px 10px;
    border-width: 2px;
    border-radius: 12px;
    justify-content: center;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 5px 10px rgba(0,0,0,0.5);
    overflow: hidden; 
}
.broadcast-container.fullscreen .card-face.card-back .card-content {
    flex-direction: row;
    gap: 10px;
}
.broadcast-container.fullscreen .card-face.card-back img {
    width: auto;
    height: 55px; 
    margin-bottom: 0;
    max-height: 100%;
    object-fit: contain;
}
.broadcast-container.fullscreen .card-face.card-back .g-num {
    font-size: 2.8rem;
    line-height: 1;
    text-shadow: 0 3px 8px rgba(0,0,0,0.7);
    margin: 0;
}
.broadcast-container.fullscreen .card-face.card-back .pos-tag {
    font-size: 0.9rem;
    left: 8px;
    top: 3px;
}
.broadcast-container.fullscreen .card-face.card-back .grid-emoji {
    font-size: 4rem;
}
