/* ======================================================================
   0. CARGA DE FUENTES Y VARIABLES
   ====================================================================== */
   @font-face {
    font-family: 'KG-Happy';
    src: url('src/fonts/KGHAPPY.ttf') format('truetype');
    font-weight: normal;
}

@font-face {
    font-family: 'Avenir-Next';
    src: url('src/fonts/Avenir Next.ttc') format('truetype');
    font-weight: normal;
}

:root {
    --primary-purple: #7b4397;   /* Morado de la portada */
    --book-green: #58b347;       /* Verde del título de la portada */
    --accent-orange: #e84e0f;    
    --success-green: #2ecc71;    
    --wrong-red: #e74c3c;        
    --bg: #0f1720;               
    --accent-gold: #ffd166;      
    --font-titles: 'KG-Happy', sans-serif;
    --font-body: 'Avenir-Next', sans-serif;
    --game-scale: 1;
}

/* ======================================================================
   1. CONFIGURACIÓN BASE Y CONTENEDOR (RESOLUCIÓN FIJA)
   ====================================================================== */
* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0;
}

html, body {
    height: 100%;
    width: 100%;
    background: radial-gradient(circle at center, #3d1b4d 0%, #0b0b1a 100%);
    color: #edf2f7;
    font-family: var(--font-body); 
    overflow: hidden; 
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
}

#game-container {
    width: 900px; 
    height: 600px;
    aspect-ratio: 900 / 600; 
    position: relative; 
    transform: scale(var(--game-scale));
    transform-origin: center;
    border: 5px solid white; 
    border-radius: 20px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.9);
    background-color: var(--bg);
    overflow: hidden;
    flex-shrink: 0;
    user-select: none;
    -webkit-user-select: none;
}

.hidden { display: none !important; }

canvas {
    width: 100%;
    height: 100%;
    display: block;
    position: absolute;
    top: 0; left: 0;
    z-index: 1;
    /* CAMBIOS REALIZADOS PARA NITIDEZ: */
    object-fit: fill; /* Cambiado de contain a fill para evitar bordes fantasma */
    image-rendering: -webkit-optimize-contrast; /* Optimiza nitidez en Chrome/Safari */
    image-rendering: crisp-edges;
    image-rendering: pixelated; /* Evita que el fondo se vea borroso al escalar */
}

/* ======================================================================
   2. PANTALLAS (ESTILO PORTADA DE LIBRO)
   ====================================================================== */
.screen {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    z-index: 100;
    text-align: center;
    padding: 40px;
}

#menu.screen {
    background: var(--primary-purple);
    background: radial-gradient(circle, #b985d1 0%, #7b4397 100%);
}

#map-screen { 
    background: transparent; 
    z-index: 10; 
}

h1.main-title {
    font-family: var(--font-titles);
    color: var(--book-green);
    font-size: 4.5rem;
    line-height: 0.85;
    margin-bottom: 5px;
    text-transform: uppercase;
    filter: drop-shadow(4px 4px 0px white) 
            drop-shadow(-4px -4px 0px white)
            drop-shadow(4px -4px 0px white)
            drop-shadow(-4px 4px 0px white);
}

.sub-title {
    font-family: var(--font-titles);
    color: white;
    font-size: 2rem;
    margin-bottom: 25px;
    text-shadow: 2px 2px 5px rgba(0,0,0,0.3);
}

.intro-text {
    font-family: var(--font-body);
    color: white;
    font-weight: bold;
    font-size: 1.1rem;
    margin-bottom: 30px;
}

/* ======================================================================
   3. BOTONES MODERNOS
   ====================================================================== */
button {
    cursor: pointer;
    border: 3px solid white;
    padding: 15px 40px;
    font-family: var(--font-titles);
    font-size: 1.1rem;
    text-transform: uppercase;
    color: white;
    margin: 10px 0;
    border-radius: 50px;
    transition: all 0.2s ease;
    pointer-events: auto;
}

.btn-primary { 
    background: var(--book-green); 
    box-shadow: 0 6px 0 #3d7d31; 
}

.btn-secondary, .choice { 
    background: #f39200; 
    box-shadow: 0 6px 0 #b36b00; 
}

button:hover { 
    transform: translateY(-2px);
    filter: brightness(1.1);
}

/* ======================================================================
   4. CONTROLES TÁCTILES UNIVERSALES
   ====================================================================== */
#mobile-controls {
    position: absolute;
    bottom: 30px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 40px;
    z-index: 99999;
    pointer-events: none; 
}

#mobile-controls:not(.hidden) {
    display: flex !important;
}

.controls-left, .controls-right {
    pointer-events: auto !important; 
}

.d-pad {
    display: flex;
    gap: 15px;
    align-items: center;
}

.touch-btn {
    width: 65px;
    height: 65px;
    background: rgba(255, 255, 255, 0.4);
    border: 3px solid white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: white;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    pointer-events: auto !important; 
}

.touch-btn:active {
    background: var(--accent-gold);
    transform: scale(0.9);
}

/* ======================================================================
   5. MODALES Y HUD
   ====================================================================== */
.modal-content {
    background: #ffffff;
    padding: 30px;
    border-radius: 30px;
    border: 6px solid var(--book-green);
    width: 90%;
    max-width: 550px;
    color: #333;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    animation: openModal 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: auto;
}

.modal-header {
    font-family: var(--font-titles);
    color: var(--primary-purple);
    margin-bottom: 15px;
}

#hud {
    position: absolute;
    top: 15px; left: 15px; right: 15px;
    display: flex; justify-content: space-between;
    z-index: 1500;
    pointer-events: none;
}

#gem-count-display {
    background: rgba(0,0,0,0.7);
    padding: 10px 20px;
    border-radius: 30px;
    border: 2px solid white;
    font-family: var(--font-titles);
    font-size: 1.2rem; color: white;
    pointer-events: auto; 
}

.copyright-notice {
    position: absolute;
    bottom: 15px;
    width: 100%;
    text-align: center;
    font-family: var(--font-body);
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
}

/* ======================================================================
   6. ESTILOS ESPECÍFICOS PARA LA PANTALLA FINAL
   ====================================================================== */
#final-treasure-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; 
    padding: 15px; 
    background: radial-gradient(circle, #3d1b4d 0%, #0b0b1a 100%);
    box-sizing: border-box;
    height: 100%;
}

#treasure-chest-anim {
    width: 100%;
    height: 280px; 
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 10px;
    margin-bottom: 5px;
}

#treasure-chest-anim img {
    max-width: 90%;
    max-height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 0 15px rgba(255, 255, 255, 0.4));
}

#stats-summary {
    margin: 5px 0;
    width: 100%;
    text-align: center;
    flex-shrink: 0;
}

#btn-restart {
    margin-top: 5px;
    margin-bottom: 10px;
    padding: 10px 30px; 
    width: auto;
    min-width: 220px;
    flex-shrink: 0;
}