/* ======================================================================
   0. VARIABLES Y RESET
   ====================================================================== */

   :root {
    --bg: #0f1720; /* Fondo principal oscuro */
    --panel: #0b1220; /* Color de paneles y modales */
    --accent: #ff6b6b; /* Rojo/Rosa vibrante para Primary */
    --accent-2: #ffd166; /* Amarillo/Dorado para HUD y Títulos */
    --accent-blue: #60a5fa; /* Azul acentuado */
    --muted: #9aa4b2; /* Gris tenue */
    --glass: rgba(255, 255, 255, 0.08); /* Efecto vidrio/transparencia */
    --glass-border: rgba(255, 255, 255, 0.2); 

    --font-game: "Press Start 2P", system-ui, sans-serif;
    --font-text: "Arial", sans-serif; 
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
    background: linear-gradient(180deg, #06101a 0%, var(--bg) 100%);
    color: #edf2f7;
    font-family: var(--font-text); 
    overflow: hidden; 
}

/* Estilos de Utilidad */
.hidden {
    display: none !important;
}

/* --- CONTENEDOR PRINCIPAL DEL JUEGO (Marco) --- */
#game-container {
    width: 100vw; 
    height: 100vh;
    margin: 0 auto;
    
    max-width: 900px; 
    max-height: 600px;
    
    aspect-ratio: 900 / 600; 

    position: fixed; 
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    
    border: 5px solid var(--accent-2); 
    box-shadow: 0 0 20px rgba(255, 209, 102, 0.5);
    overflow: hidden;
    background-color: var(--bg);
    
    display: flex; 
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* ======================================================================
   1. PANTALLAS Y MENÚ (Diseño clásico: Título arriba, Portada debajo)
   ====================================================================== */

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%; 
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: rgba(13, 27, 42, 0.95); 
    z-index: 100;
    text-align: center;
    padding: 16px;
    overflow-y: auto;
}

.menu-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    max-height: 90%;
    width: 100%;
}

/* Imagen de logo del libro (Título secundario/marca) */
.book-title-img {
    max-height: 100px;
    width: auto;
    margin: 0 auto 4px;
    display: block;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5));
}

/* Título principal del juego destacado */
#menu h1 {
    font-family: var(--font-game); 
    color: var(--accent); 
    text-shadow: 0 4px 14px rgba(232, 48, 138, 0.4);
    margin: 2px 0 4px 0;
    font-size: 1.8rem;
    letter-spacing: 1px;
}

h1 {
    font-family: var(--font-game); 
    color: var(--accent-2); 
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
    margin: 0 0 10px 0;
    font-size: 2.2rem;
}

h2 {
    font-family: var(--font-game);
    color: var(--accent-blue);
}

.subtitle {
    margin: 0 0 10px 0;
    font-size: 0.85rem;
    color: var(--muted);
    font-weight: 500;
}

/* Imagen de portada protagonista (Tamaño ampliado) */
.cover-img {
    max-height: 240px; /* Aumentado para mayor presencia visual */
    width: auto;
    max-width: 90%; /* Asegura que no desborde horizontalmente */
    margin: 8px auto 14px;
    display: block;
    border-radius: 10px;
    border: 3px solid var(--accent-blue);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
    object-fit: contain;
    transition: transform 0.2s ease;
}

.cover-img:hover {
    transform: scale(1.02);
}

.menu-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 240px;
}

.corner-cross {
    position: absolute;
    bottom: 12px;
    right: 12px;
    width: 38px;
    height: auto;
    opacity: 0.85;
    pointer-events: none;
    z-index: 100;
}

.copyright-notice {
    font-size: 10px;
    color: #8fa1b5;
    text-align: center;
    margin-top: 8px;
    font-family: Arial, sans-serif;
    text-transform: none; 
}

/* ======================================================================
   2. BOTONES
   ====================================================================== */

button {
    cursor: pointer;
    border: 0;
    padding: 12px 18px;
    border-radius: 10px;
    font-weight: 600;
    transition: transform 0.1s, box-shadow 0.1s, opacity 0.2s;
    font-family: var(--font-game);
    font-size: 0.8rem;
    text-transform: uppercase;
}

/* Botón Principal */
.primary, #start-game, #submit-post, #submit-post-btn, #finish-game-btn {
    background: linear-gradient(90deg, var(--accent), #ff9a9a);
    color: #071018;
    box-shadow: 0 6px 18px rgba(255, 107, 107, 0.38);
    margin-top: 10px;
}

/* Botones Secundarios */
.secondary, #how-to, #close-howto, #close-match-modal, #replay, #skip-answer, #pause-btn {
    background: var(--glass);
    color: var(--muted);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

/* Botón de Enviar (dentro del modal) */
#submit-answer {
    background-color: #2ecc71; 
    color: var(--panel);
}

button:hover {
    opacity: 0.9;
}
button:active {
    transform: translateY(2px);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5);
}

/* ======================================================================
   3. CANVAS Y HUD
   ====================================================================== */

#game-canvas {
    display: block;
    background-color: black;
    width: 100%;
    height: 100%;
}

#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10;
    box-sizing: border-box;
    font-family: var(--font-game);
    font-size: 10px;
}

#score {
    font-size: 14px;
    font-weight: 700;
    color: white;
}
#level-label {
    color: var(--accent-2);
}

/* ======================================================================
   4. MODALES GENERALES (Trivia y Acción)
   ====================================================================== */

.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(6, 16, 26, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.modal-content {
    background: linear-gradient(180deg, #071018, #08212a);
    padding: 30px;
    border-radius: 12px;
    width: 80%;
    max-width: 600px;
    color: #e6f7ff;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.7);
    text-align: center;
    font-family: var(--font-text);
}

#modal-choices {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.choice, .action-message {
    background: var(--glass);
    padding: 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    cursor: pointer;
    transition: background-color 0.2s, border 0.2s;
    font-size: 0.9rem;
}

.choice.selected {
    background: linear-gradient(90deg, #6ee7b732, #60a5fa33);
    border-color: #6ee7b766;
}

#modal-timer {
    color: var(--accent); 
    font-weight: bold;
    margin-right: 15px;
    font-family: var(--font-game);
}

#modal-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    margin-top: 15px;
}

#final-post {
    width: 100%;
    height: 120px;
    border-radius: 8px;
    padding: 10px;
    background: #071318;
    border: 1px solid rgba(255, 255, 255, 0.04);
    color: #fff;
    resize: vertical;
    font-family: var(--font-text);
}

/* ======================================================================
   5. MODAL DE MATCHING (Nivel 2 - Dones)
   ====================================================================== */

.match-prompt-text {
    font-size: 1.1rem;
    margin-bottom: 20px;
    color: var(--accent-2); 
}

#dilemma-cards {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px; 
    perspective: 1000px;
}

.don-card {
    width: 120px; 
    height: 150px; 
    cursor: pointer;
    background: transparent;
    border-radius: 10px;
    border: 3px solid #005f73;
    position: relative;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.8s;
    transform-style: preserve-3d;
}

.don-card.flipped .card-inner {
    transform: rotateY(180deg);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 7px;
    padding: 2px; 
    box-sizing: border-box;
}

.card-front {
    background-color: var(--panel); 
    color: white;
}

.don-card img {
    width: 100%;
    height: 100%;
    object-fit: contain; 
}

.card-back {
    background-color: #6200EE;
    color: #ffffff; 
    transform: rotateY(180deg);
    font-size: 12px; 
    line-height: 1.3;
    padding: 8px;
    align-items: center; 
    text-align: center; 
    font-family: var(--font-text); 
    font-weight: 600; 
}

.don-card.wrong {
    border-color: var(--accent); 
    opacity: 0.7;
}
.don-card.wrong .card-front {
    background-color: #B00020; 
}

.match-results-box {
    margin-top: 20px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 8px;
}

#match-feedback-message {
    color: #6ee7b7;
    font-weight: bold;
    font-family: var(--font-game);
    font-size: 0.8rem;
}

#match-correct-phrase {
    color: white;
    font-size: 0.9rem;
    margin-top: 8px;
    line-height: 1.4;
}

/* ======================================================================
   6. CONTROLES MÓVILES
   ====================================================================== */

#mobile-controls {
    position: absolute;
    bottom: 20px; 
    left: 0;
    width: 100%;
    height: 0; 
    display: flex;
    justify-content: space-between; 
    padding: 0 24px; 
    z-index: 20;
    pointer-events: none; 
    align-items: flex-end; 
}

.controls-group {
    display: flex;
    gap: 12px; 
    pointer-events: auto; 
    align-items: flex-end;
}

.ctl {
    width: 64px;
    height: 64px;
    border-radius: 50%; 
    background: rgba(255, 255, 255, 0.15); 
    backdrop-filter: blur(4px); 
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.8);
    font-size: 24px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto; 
    touch-action: manipulation; 
    transition: transform 0.1s, background 0.1s;
}

.ctl:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0.95);
}

/* ======================================================================
   7. RESPONSIVE (Optimizaciones para Móvil)
   ====================================================================== */

@media (max-width: 900px) { 
    #game-container {
        width: 100vw; 
        height: 100vh;
        margin: 0;
        border: none;
        box-shadow: none;
        position: static; 
        transform: none; 
        max-width: 100%;
        max-height: 100%;
    }

    h1 {
        font-size: 1.5rem;
    }
    
    button {
        padding: 10px 15px;
        font-size: 0.7rem;
    }

    #mobile-controls {
        bottom: 12px;
        padding: 0 12px;
    }
    
    .ctl {
        width: 58px;
        height: 58px;
        font-size: 20px;
    }
    
    .modal-content {
        width: 95%;
        padding: 20px;
    }
    
    #dilemma-cards {
        gap: 8px;
    }
    .don-card {
        width: 100px; 
        height: 130px; 
    }
}

/* ======================================================================
   8. MODAL FINAL (POST)
   ====================================================================== */

.final-challenge-content {
    max-width: 400px; 
    display: flex;
    flex-direction: column;
    align-items: center;
}

#final-post-input {
    width: 100%;
    min-height: 70px;
    margin: 10px 0 15px 0;
    padding: 10px;
    border: 2px solid var(--accent-2);
    background: #1a202c; 
    color: #edf2f7;
    resize: vertical;
    font-size: 0.9rem;
    border-radius: 8px;
    font-family: var(--font-text);
}

#post-preview, #tweet-preview {
    width: 100%;
    max-width: 380px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: #1a202c; 
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
    overflow: hidden; 
    text-align: left;
    padding: 12px;
}

.tweet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.username-tweet {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--accent-blue);
    font-family: var(--font-game);
}

.tweet-time-muted {
    color: var(--muted);
    font-size: 0.75rem;
}

.tweet-text-content {
    font-size: 0.9rem;
    line-height: 1.4;
    color: #edf2f7;
    margin: 0;
}

.post-header {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.profile-pic {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    margin-right: 8px;
    object-fit: cover;
    border: 2px solid var(--accent-2);
}

.username {
    font-weight: 700;
    font-size: 0.85rem;
    color: #fff;
    font-family: var(--font-game);
}

.post-media {
    width: 100%;
    height: auto;
    display: block;
    max-height: 200px;
    object-fit: cover;
    background-color: #000;
}

.post-caption {
    display: block;
    padding: 8px 12px;
    font-size: 0.85rem;
    line-height: 1.4;
    overflow: hidden;
}

#caption-username {
    display: inline;
    float: left; 
    margin-right: 5px;
}

.post-text {
    display: inline; 
    float: left;
    font-weight: 400;
    width: auto; 
}

.post-time {
    clear: both;
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 0.7rem;
}

.post-actions {
    padding: 8px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--muted);
    font-size: 0.75rem;
    display: flex;
    gap: 12px;
}

.post-actions span {
    cursor: default;
}

@media (max-width: 900px) {
    #post-preview, #tweet-preview {
        border-radius: 8px; 
        max-width: 100%;
    }
    .post-header, .post-caption, .post-actions {
        padding-left: 10px;
        padding-right: 10px;
    }
}