body {
    background: linear-gradient(120deg, #00b4d8 0%, #bdb2ff 100%);
    background-attachment: fixed;
    background-size: cover;
}

/* Container principal del juego: se ajusta al tamaño de pantalla, sin scroll lateral */
.container-game-flex {
    display: flex;
    align-items: center;
    justify-content: center;
    width: fit-content;         /* Solo lo necesario para el contenido */
    max-width: 100%;           /* Nunca más ancho que el viewport */
    min-width: 0;
    min-height: 80vh;          /* Más bajo */
    margin: 0 auto;
    padding: 3vw 2vw;
background: linear-gradient(120deg, #2196f3 0%, #00b4d8 25%, #48cae4 50%, #5ee7df 75%, #bdb2ff 100%);    border-radius: 16px;
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.13);
    box-sizing: border-box;
    position: relative;
    overflow: hidden;           /* Oculta cualquier desborde */
}
.container-game-flex::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0.35;
    background: url("data:image/svg+xml;utf8,<svg width='100%' height='100%' viewBox='0 0 1440 900' fill='none' xmlns='http://www.w3.org/2000/svg'><polygon points='0,900 0,0 720,0' fill='%23fff' fill-opacity='0.08'/><polygon points='0,900 720,0 1440,900' fill='%23fff' fill-opacity='0.12'/><polygon points='1440,900 720,0 1440,0' fill='%23fff' fill-opacity='0.08'/></svg>");
    background-size: cover;
    background-repeat: no-repeat;
    border-radius: 16px;
}

/* Memory game box se ajusta al ancho de las cartas y no se desborda */
.memory-game-box {
    flex: 0 1 auto;
    min-width: unset;
    max-width: unset;
    width: fit-content;
    min-height: 700px;
    background: 0 4px 16px rgba(44,34,123,0.13), 0 1.5px 8px rgba(0,0,0,0.10);
    border-radius: 28px;
    box-shadow: 0 4px 24px rgba(44,34,123,0.13), 0 2px 12px rgba(0,0,0,0.10);
    padding: 3vw 2vw 5vw 2vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    overflow: visible;
    margin-left: 115px; /* <-- Aumenta el margen para moverlo más a la derecha */
}
/* Imagen de contexto: mucho más grande y centrada verticalmente */
.context-image-box {
    flex: 0 0 600px;
    min-width: 400px;
    max-width: 700px;
    min-height: 600px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 0;
}
/* Centra verticalmente la imagen principal */
#mainImagePreview {
    display: block;
    width: 100%;
    max-width: 520px;
    max-height: 600px;
    min-height: 400px;
    border-radius: 36px;
    background: #f8fafc;
    box-shadow:
        0 16px 48px rgba(44,34,123,0.13),
        0 6px 24px rgba(0,0,0,0.10),
        0 0 0 18px #e0e7ff,
        0 2px 8px #4cc9f033;
    border: 10px solid #4cc9f0;
    padding: 20px;
    outline: 5px solid #fff;
    object-fit: contain;
}

.context-image-box img {
    max-width: 320px;
    border-radius: 18px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.10);
}

/* Tablero de cartas más grande */
.memory-board {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    width: fit-content;
    max-width: 100vw;
    margin: 60px auto 0 auto;
}

.memory-card-item {
    width: 100%;
    /* Rectangulares: más anchas que altas */
    aspect-ratio: 4/5;
    max-width: 240px;   /* Antes 160px, ahora más grandes */
    min-width: 100px;   /* Antes 60px, ahora más grandes */
    min-height: 160px;  /* Antes 90px, ahora más grandes */
    max-height: 340px;  /* Antes 200px, ahora más grandes */
    font-size: 1.6rem;  /* Texto más grande */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.card-inner {
    width: 100%;
    height: 100%;
    transition: transform 0.5s;
    transform-style: preserve-3d;
    position: relative;
}
.memory-card-item.flipped .card-inner,
.memory-card-item.matched .card-inner {
    transform: rotateY(180deg);
}
.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.card-front {
    background: #202020 url('/images/cards/cover.png') center center no-repeat;
    background-size: 100% auto;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
    border-radius: 12px;
}
.card-back {
    background: #fff;
    color: #3a0ca3;
    font-size: 1.05rem;
    padding: 10px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: rotateY(180deg);
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    border-radius: 12px;
    min-height: 100%;
    min-width: 100%;
    /* Elimina el overflow y scroll */
    overflow: hidden;
}
.card-back span {
    display: block;
    width: 100%;
    font-size: 1.05rem;
    line-height: 1.1;
    word-break: break-word;
    /* Ajuste automático de tamaño */
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: inherit;
}

/* Ajuste automático de tamaño de fuente para definiciones largas */
.memory-card-item .card-back span {
    font-weight: bold; /* <-- agrega esta línea */
    font-size: clamp(0.8rem, 1.2vw, 1.05rem);
}
.memory-card-item.matched {
    
    pointer-events: none;
}

/* Pantalla de presentación (intro) */
.intro-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(180deg, #1e2b17, #00b4d8);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 9999;
    color: white;
}
.intro-content {
    text-align: center;
}
.title {
    font-size: 28px;
    font-weight: bold;
}
.subtitle {
    font-size: 20px;
    color: #a8ff88;
    margin-bottom: 30px;
}
.player-box {
    background-color: #6c3;
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 18px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}
.start-button {
    padding: 12px 30px;
    background-color: #ffd700;
    border: none;
    border-radius: 30px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    color: #333;
}
.danger-button {
    background-color: #e74c3c;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    margin-top: 10px;
    transition: background-color 0.3s ease;
}
.danger-button:hover {
    background-color: #c0392b;
}

/* Cuenta regresiva animada */
.countdown-screen {
    position: fixed;
    top: 0;
    left: 0;
    background: #000c;
    width: 100vw;
    height: 100vh;
    z-index: 9998;
    display: flex;
    justify-content: center;
    align-items: center;
}
.countdown-number {
    font-size: 100px;
    font-weight: bold;
    color: white;
    animation: scaleUp 1s ease-in-out infinite;
}
@keyframes scaleUp {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(2); opacity: 0; }
}

.memory-controls-bottom {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 12px 0 18px 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.2em;
    z-index: 10000;
    background: linear-gradient(0deg, #fff8 60%, transparent 100%);
    backdrop-filter: blur(2px);
}

/* Asegura visibilidad en fullscreen */
:fullscreen .memory-controls-bottom,
:-webkit-full-screen .memory-controls-bottom {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 10000 !important;
    display: flex !important;
}

/* NUEVO: Contenedor para puntos y tiempo en la esquina superior derecha del área de juego */
.game-stats-topright {
    position: absolute;
    top: 24px;
    right: 36px;
    z-index: 20;
    display: flex;
    gap: 24px;
    align-items: center;
    font-size: 1.25rem;
    font-weight: 600;
    color: #22223b;
    background: rgba(255,255,255,0.85);
    border-radius: 16px;
    padding: 10px 22px;
    box-shadow: 0 2px 12px rgba(44,34,123,0.10);
}

/* Ajuste de memory-game-box cuando el container está en pantalla completa */
:fullscreen .memory-game-box,
:-webkit-full-screen .memory-game-box,
:-moz-full-screen .memory-game-box,
:-ms-fullscreen .memory-game-box {
    max-width: 100vw !important;
    min-width: 0 !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 2vw 2vw 2vw 2vw !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: #fff;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
}

/* Responsive */
@media (max-width: 1400px) {
    .container-game-flex {
        max-width: 98vw;
        padding: 20px 2vw;
        gap: 18px;
    }
    .memory-game-box {
        min-width: 80vw;
        max-width: 98vw;
        padding: 24px 2vw 60px 2vw;
    }
    .context-image-box {
        min-height: 320px;
        padding: 10px;
        flex: 0 0 340px;
    }
    #mainImagePreview {
        max-width: 98vw;
        max-height: 320px;
        padding: 10px;
    }
    .memory-board {
        grid-template-columns: repeat(3, 1fr);
        column-gap: 10px;
        row-gap: 10px;
        margin: 20px auto 0 auto;
    }
    .memory-card-item {
        width: 110px;
        height: 120px;
    }
}

@media (max-width: 900px) {
    .container-game-flex {
        flex-direction: column;
        gap: 10px;
        padding: 10px 2vw;
        max-width: 100vw;
    }
    .memory-game-box {
        max-width: 98vw;
        min-width: unset;
        padding: 16px 6px 60px 6px;
    }
    .context-image-box {
        min-height: 180px;
        padding: 10px;
        margin-left: 0;
        flex: 0 0 auto;
        width: 100%;
        justify-content: center;
    }
    #mainImagePreview {
        max-width: 90vw;
        max-height: 220px;
        padding: 6px;
    }
    .memory-board {
        margin: 20px auto 0 auto;
        grid-template-columns: repeat(2, 1fr);
        column-gap: 6px;
        row-gap: 6px;
    }
    .memory-card-item {
        width: 80px;
        height: 90px;
    }
}

@media (max-width: 600px) {
    .container-game-flex {
        padding: 4px;
        gap: 6px;
    }
    .memory-game-box {
        padding: 8px 2px 40px 2px;
        border-radius: 8px;
    }
    .memory-board {
        grid-template-columns: repeat(2, 1fr);
        column-gap: 2px;
        row-gap: 6px;
    }
    .memory-card-item {
        width: 60px;
        height: 70px;
    }
    #mainImagePreview {
        max-width: 98vw;
        max-height: 120px;
        padding: 2px;
    }
}

/* Ajuste para que los controles no se salgan en pantallas pequeñas */
@media (max-width: 400px) {
    .memory-controls-bottom {
        flex-direction: column;
        gap: 0.5em;
        bottom: 6px;
    }
}

.blurred {
    filter: blur(8px) grayscale(0.2) brightness(0.9);
    pointer-events: none !important;
    user-select: none !important;
}

#points-animation {
    position: fixed;
    left: 50%;
    top: 30%;
    z-index: 20000;
    pointer-events: none;
    display: none;
    font-size: 2.2rem;
    font-weight: bold;
    color: #06d6a0;
    text-shadow: 0 2px 8px #fff,0 1px 2px #222;
    transform: translate(-50%,0);
}

/* Para fullscreen sobre container-game-flex */
:fullscreen #points-animation,
:-webkit-full-screen #points-animation {
    position: fixed !important;
    left: 50% !important;
    top: 30% !important;
    z-index: 20000 !important;
    display: block !important;
}

:fullscreen .modal,
:-webkit-full-screen .modal {
    position: fixed !important;
    z-index: 30000 !important;
    left: 0 !important;
    top: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: rgba(0,0,0,0.35) !important;
}

:fullscreen .modal-dialog,
:-webkit-full-screen .modal-dialog {
    margin: auto !important;
    max-width: 90vw !important;
    max-height: 90vh !important;
}

:fullscreen .modal-backdrop,
:-webkit-full-screen .modal-backdrop {
    z-index: 29999 !important;
    position: fixed !important;
}

/* Números arriba: compactos y centrados */
/* Números arriba: compactos y centrados */
.coord-top-label {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(78, 185, 167, 0.92);
    border-radius: 7px;
    border: 1.5px solid #bdb2ff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    font-weight: bold;
    color: #1976d2;
    font-size: 1.1em;
    letter-spacing: 1px;
    min-width: 1.7em;
    min-height: 1.7em;
    padding: 2px 7px;
    width: 2.2em;
    height: 2.2em;
    margin: 0 auto;
}

/* Letras a la izquierda: mismo tamaño y centradas verticalmente respecto a cada card */
.coords-left-col {
    display: flex !important;
    flex-direction: column;
    justify-content: flex-start;
    gap: 0;                /* El espacio lo da el alto de cada label */
    margin-right: 18px;
    height: auto;
    padding-top: 30px;     /* Ajusta este valor para bajar más las letras */
}

.coord-left-label {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(78, 185, 167, 0.92);
    border-radius: 7px;
    border: 1.5px solid #bdb2ff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    font-weight: bold;
    color: #1976d2;
    font-size: 1.1em;
    opacity: 0.95;
    letter-spacing: 1px;
    min-width: 2.2em;
    height: 38px;          /* Más bajo */
    line-height: 38px;     /* Centrado vertical */
    width: 2.2em;
    margin: 0;
    padding: 2px 7px;
}

/* NUEVO: Estilos para pantalla completa */
/* Añade esto al final de tu CSS */
:fullscreen .memory-board,
:-webkit-full-screen .memory-board,
:-moz-full-screen .memory-board,
:-ms-fullscreen .memory-board {
    margin: 0 auto !important;  /* Centrado horizontal */
    width: fit-content !important;  /* Solo ocupa el espacio necesario */
    max-width: 100% !important;  /* Nunca más ancho que la pantalla */
    padding: 10px !important;
    justify-content: center !important;
    justify-items: center !important;
}