/* ===== GAME ENGINE — Motor compartido (play, demo-bingu, knives) ===== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    overflow: hidden;
}

/* ========== INTRO OVERLAY ========== */
.intro-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    justify-content: center;
    align-items: center;
    z-index: 500;
}

.intro-overlay.active {
    display: flex;
}

.intro-container {
    width: 100vw;
    height: calc(100vw * 9 / 16);
    max-height: 100vh;
    max-width: calc(100vh * 16 / 9);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.intro-loader {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 15%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(8px, 1.5vw, 20px);
}

.intro-loader-bar-container {
    width: clamp(375px, 62.5vw, 750px);
    height: clamp(20px, 3vw, 40px);
    position: relative;
    overflow: hidden;
}

.intro-loader-bar {
    height: 100%;
    width: 100%;
    transform-origin: left center;
}

/* ========== VISTA DEL JUEGO ========== */
.game-view {
    display: none;
    width: 100vw;
    height: calc(100vw * 9 / 16);
    max-height: 100vh;
    max-width: calc(100vh * 16 / 9);
    overflow: hidden;
    position: relative;
}

.bingo-container {
    width: 100%;
    height: 100%;
    display: flex;
    gap: 1%;
    padding: 1%;
    box-sizing: border-box;
    overflow: hidden;
}

.number-cell {
    display: flex;
    justify-content: center;
    align-items: center;
}

.side-panel {
    width: 22%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 1% 0;
}

.logo {
    width: 90%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.logo img {
    width: 100%;
    height: auto;
    object-fit: contain;
}

.current-number {
    width: 90%;
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.last-numbers {
    text-align: center;
    width: 90%;
}

.last-balls {
    display: flex;
    gap: 5%;
    justify-content: center;
    width: 100%;
}

.last-ball {
    flex: 1;
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ========== GAME NUMBER OVERLAY ========== */
.game-number-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    justify-content: center;
    align-items: center;
    z-index: 650;
}

.game-number-overlay.active {
    display: flex;
}

/* ========== BOTONES ========== */
.demo-buttons {
    display: flex;
    gap: clamp(6px, 1vw, 12px);
    width: 100%;
}

.demo-btn {
    flex: 1;
    padding: clamp(8px, 1.2vw, 14px) clamp(10px, 1.5vw, 18px);
    border: none;
    border-radius: clamp(6px, 1vw, 10px);
    font-family: 'Nunito', sans-serif !important;
    font-size: clamp(0.65rem, 1.2vw, 0.9rem);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(4px, 0.5vw, 8px);
}

.demo-btn,
.demo-btn span {
    font-family: 'Nunito', sans-serif !important;
}

.demo-btn svg {
    width: clamp(14px, 2vw, 20px);
    height: clamp(14px, 2vw, 20px);
    flex-shrink: 0;
}

.demo-btn-pause {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #1f2937;
    box-shadow: 0 4px 15px rgba(251, 191, 36, 0.3);
}

.demo-btn-pause:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(251, 191, 36, 0.4);
}

.demo-btn-pause.paused {
    background: linear-gradient(135deg, #34d399, #10b981);
    color: white;
    box-shadow: 0 4px 15px rgba(52, 211, 153, 0.3);
}

.demo-btn-pause.paused:hover {
    box-shadow: 0 6px 20px rgba(52, 211, 153, 0.4);
}

.demo-btn-exit {
    background: linear-gradient(135deg, #f87171, #ef4444);
    color: white;
    box-shadow: 0 4px 15px rgba(248, 113, 113, 0.3);
}

.demo-btn-exit:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(248, 113, 113, 0.4);
}

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

/* ========== PANTALLA TOCA PARA INICIAR ========== */
.tap-to-start {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(ellipse at center, #1a1a2e 0%, #0a0a14 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    gap: clamp(20px, 4vh, 40px);
    transition: opacity 0.5s ease;
}

.tap-to-start.hiding {
    opacity: 0;
    pointer-events: none;
}

.tap-logo {
    width: clamp(200px, 40vw, 400px);
    filter: drop-shadow(0 0 20px rgba(26, 188, 245, 0.3));
    animation: tap-logo-float 3s ease-in-out infinite;
}

@keyframes tap-logo-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.tap-text {
    font-family: var(--font-family);
    font-size: clamp(1.4rem, 3.5vw, 2.4rem);
    font-weight: 700;
    color: #ffffff;
    text-align: center;
    background: linear-gradient(135deg, #ff6b9d, #c850c0, #6c63ff);
    border: none;
    border-radius: clamp(12px, 2vw, 24px);
    padding: clamp(14px, 2.5vh, 28px) clamp(40px, 8vw, 80px);
    cursor: pointer;
    letter-spacing: 1px;
    box-shadow: 0 8px 30px rgba(200, 80, 192, 0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    animation: tap-btn-glow 2s ease-in-out infinite;
}

.tap-text:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 40px rgba(200, 80, 192, 0.6);
}

@keyframes tap-btn-glow {
    0%, 100% { box-shadow: 0 8px 30px rgba(200, 80, 192, 0.4); }
    50% { box-shadow: 0 8px 40px rgba(200, 80, 192, 0.7); }
}

.tap-hint {
    font-family: var(--font-family);
    font-size: clamp(0.75rem, 1.5vw, 0.95rem);
    color: rgba(255, 255, 255, 0.4);
    text-align: center;
}

/* ========== PORTRAIT / PANTALLA VERTICAL ========== */
/* En móvil/tablet vertical, quitar la restricción 16:9 y reorganizar:
   - Side panel pasa de columna lateral a barra horizontal superior
   - Tablero ocupa todo el espacio restante a ancho completo
   - Patrón idéntico al ya usado en mode-75 (board-modes.css) */

@media (orientation: portrait) and (max-aspect-ratio: 3/4) {

    /* Quitar restricción 16:9 — usar toda la pantalla */
    .game-view {
        width: 100vw;
        height: 100vh;
        max-width: none;
        max-height: none;
    }

    .intro-container {
        width: 100vw;
        height: 100vh;
        max-width: none;
        max-height: none;
    }

    /* Intro: texto centrado con margen y barra ajustada */
    .intro-loader {
        padding: 0 8%;
    }

    .intro-loader-text {
        text-align: center;
        max-width: 80vw;
        line-height: 1.4;
        font-size: clamp(14px, 4.5vw, 24px) !important;
    }

    .intro-loader-bar-container {
        width: clamp(200px, 80vw, 750px);
    }

    /* ==========================================================
       LAYOUT 4 FILAS:
       Fila 1 — Número actual + Logo (header)
       Fila 2 — Tablero de números
       Fila 3 — Últimas bolas
       Fila 4 — Botones Pausar/Salir (sticky abajo)
       ========================================================== */

    .bingo-container {
        display: grid !important;
        grid-template-columns: minmax(0, auto) minmax(0, 1fr);
        grid-template-rows: 20vh 45vh 15vh;
        width: 100%;
        height: 100%;
        padding: 0 1%;
        gap: 12px 0;
        align-content: start;
    }

    /* Side panel → display: contents para liberar hijos al grid padre */
    .side-panel {
        display: contents !important;
        width: auto;
        height: auto;
    }

    /* ===== FILA 1 (20vh): Header — Número actual + Logo derecha ===== */
    .current-number {
        grid-column: 1;
        grid-row: 1;
        width: auto;
        height: 80%;
        aspect-ratio: 1;
        margin: 0;
        margin-left: clamp(8px, 2.5vw, 16px);
        align-self: center;
        font-size: 11vh !important;
    }

    /* ===== FILA 3 (15vh): Últimas bolas centradas ===== */
    .last-numbers {
        grid-column: 1 / -1;
        grid-row: 3;
        width: auto;
        text-align: center;
        align-self: center;
        justify-self: center;
        padding: 0 2%;
        margin-top: 4px;
    }

    .last-numbers h3 {
        font-size: clamp(0.75rem, 2.5vw, 1.2rem);
        margin-bottom: clamp(4px, 0.8vh, 10px);
    }

    .last-ball {
        flex: 0 0 auto;
        width: clamp(40px, 10vh, 80px);
        height: clamp(40px, 10vh, 80px);
        font-size: clamp(20px, 7vh, 50px) !important;
    }

    /* Stats oculto en portrait */
    .stats {
        display: none;
    }

    .game-info {
        display: contents;
    }

    .side-panel.mounting .game-info,
    .side-panel.mounting .game-info.mounted,
    .image-theme-active .side-panel .game-info.image-theme-mount-item {
        display: contents !important;
        opacity: 1 !important;
        transform: none !important;
        filter: none !important;
        animation: none !important;
        transition: none !important;
    }

    /* ===== FILA 2 (45vh): Tablero de números ===== */
    .board {
        grid-column: 1 / -1;
        grid-row: 2;
        grid-template-columns: repeat(10, minmax(0, 1fr)) !important;
        grid-template-rows: repeat(9, 1fr) !important;
        align-content: stretch;
        min-width: 0 !important;
        min-height: 0;
        width: 100% !important;
        max-width: 100% !important;
        height: 100%;
        padding-left: 2% !important;
        padding-right: 2% !important;
    }

    .board-wrapper {
        grid-column: 1 / -1;
        grid-row: 2;
        min-height: 0;
    }

    /* Celdas: se adaptan al espacio de la fila 2 */
    .number-cell {
        aspect-ratio: auto;
        min-width: 0 !important;
    }

    /* ===== FILA 1: Logo en el lado derecho del header ===== */
    .logo {
        grid-column: 2;
        grid-row: 1;
        position: static !important;
        min-width: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: 54% !important;
        display: flex !important;
        justify-content: flex-end;
        align-items: center;
        justify-self: end;
        overflow: hidden !important;
        padding: 0 3% !important;
        margin: 0 !important;
        align-self: center;
        animation: none !important;
    }

    .logo::before,
    .logo::after {
        content: none !important;
        display: none !important;
    }

    .logo img {
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        max-height: 100%;
        object-fit: contain;
    }

    /* ===== FILA 4 (10vh): Botones sticky abajo con texto ===== */
    .demo-buttons {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 10vh;
        z-index: 11;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        padding: 0 5%;
        gap: clamp(20px, 6vw, 40px);
        background: rgba(0, 0, 0, 0.8);
        transform: translate3d(0, 100%, 0);
        opacity: 0;
        will-change: transform, opacity;
        backface-visibility: hidden;
        animation: portrait-slide-up 0.52s cubic-bezier(0.22, 1, 0.36, 1) 0.12s both;
    }

    .demo-btn {
        padding: clamp(12px, 2vh, 18px) clamp(24px, 6vw, 40px);
        flex: none;
        font-size: clamp(0.85rem, 2.2vw, 1.15rem) !important;
        font-family: 'Nunito', sans-serif !important;
    }

    .demo-btn span {
        display: inline;
        font-family: 'Nunito', sans-serif !important;
    }

    .demo-btn svg {
        width: clamp(20px, 3.5vh, 28px);
        height: clamp(20px, 3.5vh, 28px);
    }

    /* Animación slide-up para botones */
    @keyframes portrait-slide-up {
        from {
            transform: translateY(100%);
            opacity: 0;
        }
        to {
            transform: translate3d(0, 0, 0);
            opacity: 1;
        }
    }

    /* ==========================================================
       MODE 75 — Misma estructura de 4 filas en portrait
       Sobreescribe board-modes.css (mayor especificidad)
       ========================================================== */

    .bingo-container.mode-75 {
        display: grid !important;
        grid-template-columns: minmax(0, auto) minmax(0, 1fr);
        grid-template-rows: 15dvh 59dvh 11dvh;
        gap: 12px 0;
        align-content: start;
        flex-direction: unset !important;
    }

    .bingo-container.mode-75 .side-panel {
        display: contents !important;
        width: auto !important;
        height: auto !important;
    }

    /* Fila 1: Número actual (izq) + Logo (der) */
    .bingo-container.mode-75 .current-number {
        grid-column: 1 !important;
        grid-row: 1 !important;
        width: auto !important;
        height: 80% !important;
        aspect-ratio: 1;
        margin: 0;
        margin-left: clamp(8px, 2.5vw, 16px);
        align-self: center;
        font-size: 11vh !important;
    }

    .bingo-container.mode-75 .logo {
        grid-column: 2 !important;
        grid-row: 1 !important;
        position: static !important;
        min-width: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: 54% !important;
        display: flex !important;
        justify-content: flex-end;
        align-items: center;
        justify-self: end;
        overflow: hidden !important;
        padding: 0 3% !important;
        margin: 0 !important;
        align-self: center;
        animation: none !important;
    }

    .bingo-container.mode-75 .logo::before,
    .bingo-container.mode-75 .logo::after {
        content: none !important;
        display: none !important;
    }

    .bingo-container.mode-75 .logo img {
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        object-fit: contain;
    }

    /* Fila 2: Tablero 75 bolas - vista compacta tipo 90 en movil */
    .board.mode-75 {
        --mobile-75-cell-size: min(calc((100vw - 46px) / 8), calc((59dvh - 28px) / 10));
        grid-column: 1 / -1 !important;
        grid-row: 2 !important;
        grid-template-columns: repeat(8, var(--mobile-75-cell-size)) !important;
        grid-template-rows: repeat(10, var(--mobile-75-cell-size)) !important;
        grid-auto-flow: row !important;
        align-content: center;
        justify-content: center;
        min-width: 0 !important;
        min-height: 0;
        width: 100% !important;
        max-width: 100% !important;
        height: 100%;
        padding-left: 2% !important;
        padding-right: 2% !important;
        gap: clamp(2px, 0.45vw, 4px) !important;
    }

    .board.mode-75 .number-cell {
        width: var(--mobile-75-cell-size) !important;
        height: var(--mobile-75-cell-size) !important;
        aspect-ratio: 1 / 1 !important;
        justify-self: center;
        align-self: center;
        font-size: clamp(1.15rem, 6.4vw, 2.4rem) !important;
    }

    .board.mode-75 .row-letter {
        display: none !important;
    }

    .board.mode-75 .number-cell:nth-last-child(3) {
        grid-column: 4 !important;
    }

    /* Fila 3: Últimas bolas */
    .bingo-container.mode-75 .last-numbers {
        grid-column: 1 / -1 !important;
        grid-row: 3 !important;
        width: auto !important;
        text-align: center;
        align-self: center;
        justify-self: center;
        padding: 0 2%;
        margin-top: 4px;
    }

    .bingo-container.mode-75 .last-numbers h3 {
        font-size: clamp(0.75rem, 2.5vw, 1.2rem);
        margin-bottom: clamp(4px, 0.8vh, 10px);
    }

    .bingo-container.mode-75 .last-ball {
        width: clamp(40px, 10vh, 80px) !important;
        height: clamp(40px, 10vh, 80px) !important;
        font-size: clamp(20px, 7vh, 50px) !important;
    }

    .bingo-container.mode-75 .stats {
        display: none !important;
    }

    .bingo-container.mode-75 .game-info {
        display: contents !important;
    }

    /* Fila 4: Botones sticky */
    .bingo-container.mode-75 .demo-buttons {
        position: fixed !important;
        bottom: 0;
        left: 0;
        width: 100% !important;
        height: 10vh;
        z-index: 11;
        flex-direction: row !important;
        align-items: center;
        justify-content: center;
        padding: 0 5%;
        gap: clamp(20px, 6vw, 40px);
        background: rgba(0, 0, 0, 0.8);
        grid-column: unset !important;
        grid-row: unset !important;
        transform: translate3d(0, 100%, 0);
        opacity: 0;
        will-change: transform, opacity;
        backface-visibility: hidden;
        animation: portrait-slide-up 0.52s cubic-bezier(0.22, 1, 0.36, 1) 0.12s both;
    }

    .bingo-container.mode-75 .demo-btn {
        padding: clamp(12px, 2vh, 18px) clamp(24px, 6vw, 40px) !important;
        width: auto !important;
        font-size: clamp(0.85rem, 2.2vw, 1.15rem) !important;
        font-family: 'Nunito', sans-serif !important;
    }

    .bingo-container.mode-75 .demo-btn span {
        display: inline !important;
        font-family: 'Nunito', sans-serif !important;
    }

    .bingo-container.mode-75 .demo-btn svg {
        width: clamp(20px, 3.5vh, 28px);
        height: clamp(20px, 3.5vh, 28px);
    }
}
