/* ==========================================================================
   BLOQUE 1: VARIABLES Y CONFIGURACIÓN GLOBAL
   ========================================================================== */
:root {
    --font-title: 'Fredoka', sans-serif;
    --font-body: 'Nunito', sans-serif;

    --baby-blue: #8FBEEB;
    --blue-grey: #619CD4;
    --baltic-blue: #0956A2;
    --grey: #828282;
    --light-gold: #E9DA8D;
    --old-gold: #C7B34E;
    --bg-dark: #121212;
    --neon-blue: rgb(97, 156, 212);
    --neon-red: #e74c3c;
    --white: #fff;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-image: url('images/fondo_ju.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    height: 100vh;
    color: var(--white);
    font-family: var(--font-body);
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.hidden {
    display: none !important;
}

.screen {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
}


/* ==========================================================================
   BLOQUE 2: COMPONENTES COMUNES Y ESTILOS NEÓN GLOBALES
   ========================================================================== */
.btn-neon {
    font-family: var(--font-title);
    background: linear-gradient(135deg, var(--baltic-blue), var(--blue-grey));
    color: #ffffff;
    border: 2px solid var(--baby-blue);
    padding: 12px 24px;
    font-size: 1.1rem;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 0 20px rgba(97, 156, 212, 0.7), inset 0 0 8px rgba(143, 190, 235, 0.4);
    transition: all 0.2s ease-in-out;
}

.btn-neon:hover {
    background: linear-gradient(135deg, var(--blue-grey), var(--baby-blue));
    color: var(--bg-dark);
    box-shadow: 0 0 25px var(--baby-blue);
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.65);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(6px);
}

.modal-content {
    background: #1a2634;
    border: 2px solid var(--baby-blue);
    padding: 30px;
    border-radius: 20px;
    width: 90%;
    max-width: 450px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-shadow: 0 0 25px rgba(97, 156, 212, 0.6);
}

.modal-content h2 {
    font-family: var(--font-title);
    color: var(--light-gold);
}

#abandon-modal .modal-content {
    border-color: var(--neon-red);
    box-shadow: 0 0 30px rgba(231, 76, 60, 0.8);
}

.btn-danger {
    background: linear-gradient(135deg, #c0392b, #e74c3c) !important;
    border-color: #ff6b6b !important;
    box-shadow: 0 0 15px rgba(231, 76, 60, 0.8) !important;
}


/* ==========================================================================
   BLOQUE 3: PANTALLA DE INICIO (DESKTOP-FIRST)
   ========================================================================== */
.game-title {
    font-family: var(--font-title);
    font-size: 5rem;
    font-weight: bold;
    text-align: center;
    margin-bottom: 8px;
    display: block;
    background: linear-gradient(to bottom, var(--baltic-blue) 0%, #ffffff 45%, #ffffff 55%, var(--baby-blue) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(-2px -2px 0px #4a82be) drop-shadow(2px -2px 0px #4a82be) drop-shadow(-2px 2px 0px #4a82be) drop-shadow(2px 2px 0px #4a82be) drop-shadow(0px 4px 5px rgba(74, 130, 190, 0.5));
}

.game-subtitle {
    font-size: 1.3rem;
    color: var(--baltic-blue);
    font-weight: bold;
    margin-bottom: 35px;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.6);
}

.level-buttons {
    display: flex;
    gap: 25px;
    margin-bottom: 25px;
}

.level-card {
    font-family: var(--font-title);
    background: linear-gradient(135deg, rgba(26, 38, 52, 0.95), rgba(9, 86, 162, 0.9));
    color: #ffffff;
    border: 2px solid var(--baby-blue);
    padding: 18px 22px;
    font-size: 1.15rem;
    border-radius: 16px;
    cursor: pointer;
    box-shadow: 0 0 15px rgba(97, 156, 212, 0.4);
    transition: all 0.25s ease-in-out;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 190px;
}

.level-card:hover {
    background: linear-gradient(135deg, var(--blue-grey), var(--baltic-blue));
    color: var(--bg-dark);
    border-color: var(--neon-blue);
    box-shadow: 0 0 25px var(--baltic-blue);
    transform: translateY(-4px);
}

.level-preview {
    width: 90px;
    height: 65px;
    background: #2c5e3b;
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    padding: 4px;
}

.start-utility-bar {
    display: flex;
    gap: 15px;
    margin-top: 10px;
}


/* ==========================================================================
   BLOQUE 4: PANTALLA DE JUEGO Y TABLERO (PC / BASE)
   ========================================================================== */
#game-screen {
    justify-content: flex-start;
    padding-top: 10px;
}

#game-container {
    width: 100%;
    max-width: 950px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* ==========================================================================
   CABECERA UNIFICADA EN UNA SOLA LÍNEA (Escritorio y Base)
   ========================================================================== */
.game-header.single-line-header {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px;
    gap: 8px;
    width: 100%;
    background: var(--neon-blue);
    border-radius: 16px;
    border: 2px solid var(--baby-blue);
    box-shadow: 0 0 30px rgba(97, 156, 212, 0.5);
    position: relative;
    flex-wrap: nowrap;
}

/* Mantener compatibilidad por si se usa la clase antigua sola */
.game-header {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px;
    gap: 8px;
    width: 100%;
    background: var(--neon-blue);
    border-radius: 16px;
    border: 2px solid var(--baby-blue);
    box-shadow: 0 0 30px rgba(97, 156, 212, 0.5);
    position: relative;
}

.header-top-row {
    display: none; /* Ya no se usa con la estructura en línea */
}

.btn-abandon {
    font-size: 1rem;
    padding: 0;
    width: 38px;
    height: 38px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}

.stats-group {
    display: flex;
    gap: 15px;
    align-items: center;
}

.stat-badge {
    font-family: var(--font-title);
    background: var(--bg-dark);
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--blue-grey);
    font-size: 0.9rem;
    color: var(--light-gold);
    white-space: nowrap;
}

/* Botones de acción rápida (Deshacer y Pista) */
.btn-header-action {
    background: var(--bg-dark);
    border: 1px solid var(--baby-blue);
    color: var(--white);
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 0 8px rgba(97, 156, 212, 0.3);
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-header-action:hover:not(.disabled) {
    background: var(--baby-blue);
    color: var(--bg-dark);
    box-shadow: 0 0 15px var(--neon-blue);
}

.btn-header-action.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Contenedor del menú hamburguesa */
.hamburger-container {
    position: relative;
    display: inline-block;
    flex-shrink: 0;
}

.mobile-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    background: rgba(18, 18, 18, 0.95);
    border: 2px solid var(--baby-blue);
    border-radius: 14px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 0 20px rgba(97, 156, 212, 0.6);
    z-index: 1100;
    backdrop-filter: blur(6px);
}

.mobile-dropdown.hidden {
    display: none !important;
}

.btn-icon {
    background: var(--bg-dark);
    border: 1px solid var(--baby-blue);
    color: var(--baby-blue);
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 0 8px rgba(97, 156, 212, 0.3);
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-icon:hover {
    background: var(--baby-blue);
    color: var(--bg-dark);
    box-shadow: 0 0 15px var(--neon-blue);
}

/* Caja de Parking en Línea */
.parking-box,
.parking-box-inline {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: rgba(18, 18, 18, 0.3);
    padding: 6px 10px;
    border-radius: 12px;
    border: 2px dashed var(--baby-blue);
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.25);
}

.parking-action-btn {
    background: linear-gradient(135deg, var(--baltic-blue), var(--blue-grey));
    border: 1px solid var(--light-gold);
    color: #ffffff;
    width: 38px;
    height: 50px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 0 8px rgba(97, 156, 212, 0.4);
    transition: all 0.2s;
    flex-shrink: 0;
}

.parking-action-btn:hover:not(.disabled) {
    background: linear-gradient(135deg, var(--blue-grey), var(--baby-blue));
    color: var(--bg-dark);
    box-shadow: 0 0 15px var(--light-gold);
}

.parking-action-btn.disabled {
    background: #181c22;
    border-color: #333d4a;
    color: var(--grey);
    cursor: not-allowed;
    opacity: 0.5;
}

.parked-slot {
    width: 38px;
    height: 50px;
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid rgba(143, 190, 235, 0.7);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
    transition: transform 0.15s, border-color 0.15s;
    flex-shrink: 0;
}

.parked-slot:hover {
    transform: translateY(-2px);
    border-color: var(--light-gold);
}

.parked-slot img {
    width: 85%;
    height: 85%;
    object-fit: contain;
}

/* Tablero de PC */
#board-container {
    width: 100%;
    overflow: visible;
    max-height: 75vh;
    padding: 5px;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
}

#board {
    position: relative;
    background-color: #2c5e3b;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    border: 4px solid #1e3f28;
}

.tile {
    position: absolute;
    width: 82px;
    height: 106px;
    background: #fdfefe;
    border: 2px solid #bdc3c7;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 2px 4px 10px rgba(0, 0, 0, 0.35);
    user-select: none;
}

.tile:hover {
    transform: translateY(-3px);
    border-color: var(--blue-grey);
}

.tile.blocked {
    filter: brightness(0.7);
    cursor: not-allowed;
}

.tile.selected {
    border-color: var(--light-gold);
    background: #fffdf0;
    box-shadow: 0 0 12px var(--light-gold);
}

.tile.hint {
    border-color: #2ecc71;
    box-shadow: 0 0 15px #2ecc71;
    animation: pulse-hint 0.8s infinite alternate;
}

@keyframes pulse-hint {
    from { transform: scale(1); }
    to { transform: scale(1.05); }
}


/* ==========================================================================
   BLOQUE 5: CANVAS DE CONFETI Y ELEMENTOS FIJOS
   ========================================================================== */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 9999;
}

.modal-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.victory-stats {
    background: rgba(0, 0, 0, 0.35);
    padding: 15px;
    border-radius: 12px;
    display: flex;
    justify-content: space-around;
}


/* ==========================================================================
   BLOQUE 6: MEDIA QUERIES RESPONSIVOS (TABLETS Y MÓVILES)
   ========================================================================== */
@media (min-width: 768px) and (max-width: 1024px) {
    #game-container {
        max-width: 95vw;
        gap: 10px;
    }
    #board-container {
        max-height: 60vh;
        overflow: auto;
    }
}

@media (max-width: 767px) {
    body {
        overflow-y: auto;
        height: 100vh;
        padding: 2px 0;
    }

    .screen {
        height: 100vh;
        padding: 4px;
        justify-content: flex-start;
    }

    #game-container {
        width: 100vw;
        height: 100%;
        max-width: 100vw;
        gap: 6px;
        padding: 0 4px;
        display: flex;
        flex-direction: column;
    }

    /* Cabecera adaptada para móvil (vuelve a envolver los elementos en filas) */
    .game-header,
    .game-header.single-line-header {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
        padding: 6px 8px;
        gap: 6px;
        width: 100%;
        flex-shrink: 0;
    }

    .header-top-row {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        gap: 6px;
    }

    .btn-abandon {
        width: 36px;
        height: 36px;
        padding: 0;
        font-size: 0.9rem;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-shrink: 0;
    }

    .btn-header-action {
        background: var(--bg-dark);
        border: 1px solid var(--baby-blue);
        color: var(--white);
        width: 36px;
        height: 36px;
        border-radius: 8px;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 1rem;
        cursor: pointer;
        box-shadow: 0 0 6px rgba(97, 156, 212, 0.3);
        flex-shrink: 0;
    }

    .stat-badge {
        padding: 4px 8px;
        font-size: 0.9rem;
        white-space: nowrap;
    }

    .hamburger-container {
        flex-shrink: 0;
    }

    .mobile-dropdown {
        position: absolute;
        top: 45px;
        right: 0;
        background: rgba(18, 18, 18, 0.95);
        border: 2px solid var(--baby-blue);
        border-radius: 12px;
        padding: 8px;
        display: flex;
        flex-direction: column;
        gap: 6px;
        box-shadow: 0 0 15px rgba(97, 156, 212, 0.6);
        z-index: 1100;
    }

    .mobile-dropdown.hidden {
        display: none !important;
    }

    /* Caja de parking abajo ocupando todo el ancho en móvil */
    .parking-box,
    .parking-box-inline {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        background: rgba(18, 18, 18, 0.3);
        padding: 6px 10px;
        border-radius: 12px;
        border: 2px dashed var(--baby-blue);
        width: 100%;
        order: 10;
    }

    .parking-action-btn {
        background: linear-gradient(135deg, var(--baltic-blue), var(--blue-grey));
        border: 1px solid var(--light-gold);
        color: #ffffff;
        width: 36px;
        height: 48px;
        border-radius: 6px;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 1rem;
        cursor: pointer;
        flex-shrink: 0;
    }

    .parking-action-btn.disabled {
        background: #181c22;
        border-color: #333d4a;
        color: var(--grey);
        cursor: not-allowed;
        opacity: 0.5;
    }

    .parked-slot {
        width: 36px;
        height: 48px;
        border-radius: 6px;
        flex-shrink: 0;
    }

    .parked-slot img {
        width: 85%;
        height: 85%;
        object-fit: contain;
    }

    #board-container {
        width: 100%;
        flex: 1;
        max-height: none;
        overflow: auto;
        display: block;
        position: relative;
        padding: 25px;
        box-sizing: border-box;
        background: #1e4620;
        border-radius: 16px;
        border: 4px solid #143216;
        box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
    }

    #board {
        transform: none;
        margin: 0;
        position: relative;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
    }

    .tile {
        width: 82px;
        height: 106px;
    }

    .tile img {
        width: 80% !important;
        height: 80% !important;
    }

    #start-screen {
        display: flex;
        flex-direction: column;
        justify-content: space-evenly;
        align-items: center;
        min-height: 100vh;
        padding: 20px 10px;
        box-sizing: border-box;
        text-align: center;
        overflow-y: auto;
    }

    #start-screen .start-utility-bar {
        display: flex !important;
        flex-direction: row !important;
        justify-content: center;
        align-items: center;
        gap: 15px;
        order: 1;
        margin-bottom: 5px;
        width: 100%;
    }

    #start-screen .game-title {
        font-size: clamp(3rem, 8vw, 3rem) !important;
        line-height: 1.15;
        max-width: 220px;
        margin: 0 auto;
        order: 2;
        box-sizing: border-box;
    }

    #start-screen .game-subtitle {
        font-size: 1.5rem !important;
        margin: 0;
        order: 3;
        padding: 0 10px;
    }

    #start-screen .level-buttons {
        display: flex !important;
        flex-direction: column !important;
        align-items: center;
        gap: 12px;
        width: 100%;
        order: 4;
        margin: 5px 0;
    }

    #start-screen .level-card {
        width: 85% !important;
        max-width: 260px;
    }
}