* { box-sizing: border-box; margin: 0; padding: 0; font-family: sans-serif; }

body {
    height: 100vh; 
    height: 100dvh; 
    box-sizing: border-box;
    overflow: hidden;
}

.logo-contenedor {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-bottom: 40px; /* Espacio antes de los botones */
    margin-top: 20px;
}

#canvas-logo {
    cursor: pointer; /* Indica que es interactivo */
    max-width: 100%; /* Adaptable a pantallas pequeñas */
}

#app-container {
    display: flex;
    width: 100%;
    height: 100%;
	overflow: hidden;
}

/* ==========================================
   --- 1. PANELES Y LAYOUT GENERAL (PC) ---
   ========================================== */

.panel {
    width: 250px;
    background-color: #ecf0f1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px; 
    border-right: 2px solid #bdc3c7;
    border-left: 2px solid #bdc3c7;
    z-index: 10;
    max-height: 100vh;
}

#panel-central {
    flex-grow: 1; 
    position: relative;
    /* Efecto Madera Realista con CSS Puro */
    background-color: #7d5c3d;
    background-image: 
        repeating-linear-gradient(90deg, rgba(0,0,0,0.03) 0px, rgba(0,0,0,0.03) 1px, transparent 1px, transparent 40px),
        repeating-linear-gradient(180deg, rgba(0,0,0,0.05) 0px, rgba(0,0,0,0.05) 1px, transparent 1px, transparent 2px),
        linear-gradient(90deg, rgba(0,0,0,0.1) 0%, transparent 0.5%, transparent 99.5%, rgba(0,0,0,0.1) 100%);
    background-size: 80px 100%, 100% 2px, 250px 100%;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* --- GRIDS DE RESERVA Y MERCADO (PC) --- */
.grid-ui {
    background-color: rgba(189, 195, 199, 0.3);
    border: 2px inset #bdc3c7;
    padding: 10px;
    border-radius: 8px;
    display: grid;
    gap: 10px;
}

/* RESERVA: 6 huecos fijos que se reparten el alto */
#reserva-grid {
    grid-template-rows: repeat(6, 1fr); 
    flex-grow: 1; 
    min-height: 0;
    overflow: hidden;
}

/* MERCADO: 2 huecos de tamaño fijo */
#mercado-grid {
    grid-template-rows: repeat(2, 100px); 
    flex-grow: 0; 
    place-items: center;    
    margin-bottom: 20px;
}

#reserva-grid .pieza-ui, #mercado-grid .pieza-ui {
    align-self: center;
    margin: 0 auto;
}

/* ==========================================
   --- 2. ELEMENTOS DE UI (Fichas, Botones, Estadísticas) ---
   ========================================== */

.pieza-ui {
    display: flex;
    justify-content: center;
    align-items: center;
    background: #ffffff;
    border-radius: 8px;
    padding: 5px;
    cursor: pointer;
    transition: transform 0.2s, border 0.2s;
    border: 3px solid transparent;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.pieza-ui:hover { transform: scale(1.05); border-color: #3498db; }
.pieza-ui.seleccionada { border-color: #f39c12; background: #fdf5e6; transform: scale(1.05); }

#info-bolsa {
    font-size: 0.9em;
    color: #7f8c8d; 
    margin-top: 5px;
    font-style: italic;
}

.botonera-acciones {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-accion {
    padding: 15px;
    background-color: #f39c12;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
}
.btn-accion:hover { background-color: #e67e22; }

.btn-control {
    transition: opacity 0.3s ease;
    cursor: pointer;
}
.btn-control:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    filter: grayscale(100%);
}

/* --- CONTROLES DE CÁMARA FLOTANTES --- */
#controles-camara {
    position: absolute;
    bottom: 80px; 
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 50; 
}

#controles-camara button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #bdc3c7;
    background: #ecf0f1;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
}
#controles-camara button:active { transform: scale(0.9); }

/* ==========================================
   --- 3. MENÚS Y PANTALLAS ---
   ========================================== */

.capa-menu {
    position: absolute; top: 0; left: 0; width: 100vw; height: 100vh;
    background-color: #2c3e50; color: white;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    z-index: 1000;
}
.capa-menu h1 { font-size: 4rem; margin-bottom: 2rem; }

.boton-grande {
    width: 280px;         /* Ancho fijo para homogeneidad */
    padding: 15px 25px;
    margin: 10px auto;    /* Centrados y con espacio entre ellos */
    font-size: 1.2rem;
    font-weight: bold;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    color: white;
    display: block;       /* Uno debajo de otro */
    transition: transform 0.1s, filter 0.2s;
}

.opcion-config {
    margin: 15px 0; display: flex; align-items: center; justify-content: space-between;
    width: 350px; min-height: 40px;
}
.opcion-config label { flex: 1; cursor: pointer; color: white; font-size: 1rem; }
.opcion-config input[type="checkbox"] { width: 25px; height: 25px; margin-right: 10px; cursor: pointer; accent-color: #2ecc71; }

#pantalla-fin {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85); display: none; justify-content: center; align-items: center; z-index: 9999;
}
.contenedor-final {
    background: #1a1a1a; color: white; padding: 2rem; border-radius: 15px; border: 2px solid #e67e22; text-align: center; min-width: 320px;
}

#btn-continuar { 
    background-color: #27ae60 !important; 
    box-shadow: 0 5px #1e8449; 
}
#btn-jugar { 
    background-color: #3498db !important; 
    box-shadow: 0 5px #2980b9; 
}
#btn-abrir-config { 
    background-color: #95a5a6 !important; 
    box-shadow: 0 5px #7f8c8d; 
}

/* Comportamiento al hacer clic para todos */
.boton-grande:active {
    transform: translateY(3px);
    box-shadow: 0 2px rgba(0,0,0,0.2) !important;
}

/* ==========================================
   --- 4. ADAPTACIÓN RESPONSIVE (MÓVILES) ---
   ========================================== */

@media (max-width: 800px) {
    #app-container {
        flex-direction: column !important; /* Apilamos en vertical (Reserva -> Tablero -> Mercado) */
    }

    /* Convertimos los paneles laterales en barras horizontales arriba y abajo */
    .panel {
        width: 100% !important;
        height: 75px !important;       /* Barra fina */
        min-height: 75px !important;
        flex-direction: row !important; /* Elementos de izquierda a derecha */
        padding: 5px 10px !important;
        gap: 10px !important;
        align-items: center;
        border: none !important;
        background-color: #ecf0f1;
    }

    #panel-izquierdo { order: 1; border-bottom: 2px solid #bdc3c7 !important; } /* Arriba */
    
    #panel-central { 
        order: 2; /* En medio */
        flex-grow: 1 !important; /* Ocupa todo el espacio jugable */
    }

  #panel-derecho {
        order: 3 !important;
        border-top: 2px solid #bdc3c7 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-evenly !important; /* Reparte el espacio sobrante uniformemente */
        padding: 4px !important;
        gap: 4px !important;
        min-height: 58px !important;
        height: auto !important;
        background-color: #ecf0f1 !important;
        overflow: hidden !important; /* 👈 Elimina cualquier scroll accidental */
    }

    /* Ocultamos títulos y estadísticas para ganar espacio */
    .panel h2, #estadisticas { display: none !important; }
	
	/* Hacemos visibles los puntos y la bolsa en formato mini */
    #estadisticas {
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: flex-start !important;
        min-width: 38px !important;
        gap: 1px;
        font-size: 0.7rem !important;
        line-height: 1.1;
        flex-shrink: 0 !important;
    }


    .stat-item {
        display: flex;
        align-items: center;
        gap: 5px;
        font-size: 0.85rem;
        font-weight: bold;
    }

	#mercado-grid {
        display: flex !important;
        flex-direction: row !important;
        justify-content: center !important;
        align-items: center !important;
        flex: 1 1 auto !important;
        height: 48px !important;
        padding: 2px !important;
        margin: 0 !important;
        overflow-x: hidden !important; /* 👈 Clave: oculta el scroll horizontal */
        gap: 6px !important;
        background: transparent !important;
        border: none !important;
    }
	
	#mercado-grid .pieza-ui {
        width: 40px !important;
        height: 40px !important;
        flex-shrink: 0 !important;
        padding: 3px !important;
    }

    /* 🎮 Botonera: Compacta a la derecha */
    .botonera-acciones {
        display: flex !important;
        flex-direction: row !important;
        gap: 3px !important;
        margin: 0 !important;
        flex-shrink: 0 !important;
    }

    .btn-control {
        width: 34px !important;
        height: 34px !important;
        font-size: 0.85rem !important;
        padding: 0 !important;
        flex-shrink: 0 !important;
    }

    /* Forzamos que las zonas de fichas fluyan en horizontal con scroll si hace falta */
    #reserva-grid, #mercado-grid {
        display: flex !important;
        flex-direction: row !important; /* Fichas apiladas horizontalmente */
        height: 60px !important;
        flex-grow: 1;
        padding: 5px !important;
        margin: 0 !important;
        overflow-x: auto !important; /* Scroll horizontal si hay muchas fichas */
        overflow-y: hidden !important;
        background: transparent !important;
        border: none !important;
        gap: 10px !important;
    }

    /* Fichas un poco más pequeñas */
    .pieza-ui {
        width: 45px !important;
        height: 45px !important;
        flex-shrink: 0; /* Impide que se aplasten */
    }

    /* Botonera en línea y compacta */
    .botonera-acciones {
        flex-direction: row !important;
        gap: 5px !important;
        margin: 0 !important;
    }

    .btn-control {
        height: 45px;
        width: 45px;
        font-size: 1.2rem;
        padding: 0;
    }
}
/* ==========================================
   --- ESTILOS DE LA VENTANA DE REGLAS ---
   ========================================== */
.contenedor-modal {
    background: #ecf0f1;
    padding: 30px;
    border-radius: 12px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh; /* Para que no ocupe más del 80% de la altura de la pantalla */
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    border: 3px solid #bdc3c7;
}

.contenido-reglas {
    overflow-y: auto; /* Activa la barra de desplazamiento si el texto es muy largo */
    text-align: left;
    line-height: 1.6;
    padding-right: 15px; /* Espacio para que el texto no se pegue a la barra de scroll */
}

.contenido-reglas h3 {
    margin-top: 20px;
    margin-bottom: 10px;
    color: #2980b9;
    border-bottom: 2px solid #bdc3c7;
    padding-bottom: 5px;
}

.contenido-reglas p, .contenido-reglas ul {
    margin-bottom: 10px;
    font-size: 16px;
    color: #333;
}

.contenido-reglas ul {
    padding-left: 25px;
}

/* Color específico para el botón de reglas */
#btn-abrir-reglas {
    background-color: #2980b9 !important; /* Un azul bonito */
    color: #ffffff !important; /* Texto blanco puro */
    border: 2px solid #1c5980;
}

/* ==========================================
--- TEMAS DE FONDO (CORREGIDO) ---
========================================== */
#panel-central {
    flex-grow: 1;
    position: relative;
    transition: background 0.5s ease;
}

/* 1. MADERA */
#panel-central.tema-madera {
    background-color: #7d5c3d !important;
    background-image: repeating-linear-gradient(90deg, rgba(0,0,0,0.03) 0px, rgba(0,0,0,0.03) 1px, transparent 1px, transparent 40px), repeating-linear-gradient(180deg, rgba(0,0,0,0.05) 0px, rgba(0,0,0,0.05) 1px, transparent 1px, transparent 2px), linear-gradient(90deg, rgba(0,0,0,0.1) 0%, transparent 0.5%, transparent 99.5%, rgba(0,0,0,0.1) 100%) !important;
    background-size: 80px 100%, 100% 2px, 250px 100% !important;
}

/* 2. BLANCO */
#panel-central.tema-blanco {
    background-color: #f8f9fa !important;
    background-image: radial-gradient(#e9ecef 1px, transparent 1px) !important;
    background-size: 20px 20px !important;
}

/* 3. ESPACIO */
/* 3. ESPACIO PROFUNDO (Cobertura total + sin interferir con el canvas) */
#panel-central.tema-espacio {
    background: #0b1120;
    position: relative;
    overflow: hidden;
}
#panel-central.tema-espacio::before {
    content: ""; position: absolute; inset: 0;
    background: radial-gradient(ellipse at center, #1e293b 0%, #0b1120 80%);
    z-index: 0; pointer-events: none;
}
#panel-central.tema-espacio::after {
    content: ""; position: absolute; inset: 0;
    /* Estrellas distribuidas por porcentajes para cubrir el 100% del panel */
    background-image: 
        radial-gradient(1.5px 1.5px at 10% 15%, #fff 50%, transparent 50%),
        radial-gradient(1px 1px at 25% 45%, rgba(255,255,255,0.7) 50%, transparent 50%),
        radial-gradient(2px 2px at 40% 80%, rgba(255,255,255,0.5) 50%, transparent 50%),
        radial-gradient(1px 1px at 55% 20%, #fff 50%, transparent 50%),
        radial-gradient(1.5px 1.5px at 70% 65%, rgba(255,255,255,0.8) 50%, transparent 50%),
        radial-gradient(1px 1px at 85% 30%, #fff 50%, transparent 50%),
        radial-gradient(2px 2px at 15% 90%, rgba(255,255,255,0.6) 50%, transparent 50%),
        radial-gradient(1px 1px at 35% 50%, #fff 50%, transparent 50%),
        radial-gradient(1.5px 1.5px at 90% 85%, rgba(255,255,255,0.9) 50%, transparent 50%),
        radial-gradient(1px 1px at 65% 10%, #fff 50%, transparent 50%);
    z-index: 1; pointer-events: none;
    animation: parpadeoEstrellas 4s infinite alternate ease-in-out;
}
@keyframes parpadeoEstrellas { 0% { opacity: 0.7; } 100% { opacity: 1; } }

/* 👈 CLAVE: Canvas siempre por encima y listo para pintar */
canvas {
    position: relative;
    z-index: 10;
    display: block;
    width: 100%;
    height: 100%;
    background: transparent !important; /* Evita que el navegador asigne fondo opaco */
}