/* grid.css */
.grid-game-container {
    max-width: 580px;
    margin: 0 auto;
    padding: 10px;
    text-align: center;
}

.message-banner {
    background-color: #0c5460;
    color: #d1ecf1;
    border: 1px solid #117a8b;
    padding: 8px;
    margin-bottom: 10px;
    border-radius: 5px;
    font-weight: bold;
    animation: pulse 2s infinite;
    font-size: 0.85rem;
}

.message-banner.hidden {
    display: none;
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.8;
    }

    100% {
        opacity: 1;
    }
}

.grid-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 6px;
    background-color: #3e2723;
    padding: 8px;
    border-radius: 10px;
    border: 2px solid #8d6e63;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.6), inset 0 0 12px rgba(0, 0, 0, 0.3);
    margin-bottom: 15px;
}

/* Header cells (row/col labels) */
.grid-cell-header {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #5d4037, #3e2723);
    border: 1px solid #8d6e63;
    color: #f5e6c8;
    border-radius: 5px;
    font-weight: bold;
    text-align: center;
    padding: 4px;
    overflow: hidden;
    aspect-ratio: 1 / 1;
}

.grid-cell-header img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
}

/* Cabeceras con texto (categorías sin imagen) */
.grid-cell-header span {
    font-size: clamp(0.45rem, 2vw, 0.7rem);
    line-height: 1.2;
    word-break: break-word;
    hyphens: auto;
    padding: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Top-Left Timer Cell */
.grid-cell-header.timer-cell {
    background: linear-gradient(135deg, #2d201c, #1a1008);
    border: 1px solid #5d4037;
    flex-direction: column;
    gap: 4px;
    padding: 6px;
}

.grid-cell-header.timer-cell .grid-logo-img {
    max-width: 55%;
    max-height: 50%;
    object-fit: contain;
    border-radius: 6px;
}

.grid-timer {
    font-family: 'Bangers', cursive;
    font-size: 1.3rem;
    color: #FFD700;
    letter-spacing: 1px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

/* Playable Cells */
.grid-cell.playable-cell {
    background-color: #2d201c;
    border: 1px solid #5d4037;
    border-radius: 5px;
    cursor: default;
    transition: all 0.3s ease;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

/* Highlight state when a character matches this cell */
.grid-cell.playable-cell.highlight {
    background-color: #2a2a2a;
    border: 3px solid #FFD700;
    cursor: pointer;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
    transform: scale(1.02);
}

.grid-cell.playable-cell.highlight:hover {
    background-color: #444;
}

/* Filled cell (correct guess) */
@keyframes cellFill {
    0% {
        transform: scale(0.8);
        opacity: 0.6;
    }

    60% {
        transform: scale(1.08);
    }

    80% {
        transform: scale(0.97);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes cellReveal {
    0% {
        transform: scale(0.85);
        opacity: 0;
    }

    70% {
        transform: scale(1.04);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.grid-cell.playable-cell.filled {
    background-color: #0a2410;
    border: 3px solid #4CAF50;
    cursor: default;
    box-shadow: 0 0 18px rgba(76, 175, 80, 0.45), 0 4px 10px rgba(0, 0, 0, 0.4);
    animation: cellFill 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.grid-cell.playable-cell.filled img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    opacity: 1;
}

.grid-cell.playable-cell.filled .character-name-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.88) 0%, rgba(0, 0, 0, 0.4) 70%, transparent 100%);
    color: #e8ffe8;
    font-weight: bold;
    font-size: 0.65rem;
    padding: 10px 2px 3px;
    text-align: center;
    pointer-events: none;
}

/* Revealed cell (after surrender) */
.grid-cell.playable-cell.revealed {
    background-color: #2a0e0e;
    border: 3px solid #e57373;
    cursor: default;
    box-shadow: 0 0 18px rgba(229, 115, 115, 0.35), 0 4px 10px rgba(0, 0, 0, 0.4);
    animation: cellReveal 0.4s ease-out forwards;
}

.grid-cell.playable-cell.revealed img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    opacity: 0.65;
}

.grid-cell.playable-cell.revealed .character-name-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(to top, rgba(100, 20, 20, 0.9) 0%, rgba(80, 20, 20, 0.45) 70%, transparent 100%);
    color: #ffcdd2;
    font-weight: bold;
    font-size: 0.65rem;
    padding: 10px 2px 3px;
    text-align: center;
    pointer-events: none;
}

/* Error animation */
.grid-cell.playable-cell.error-anim {
    animation: shake 0.4s ease-in-out;
    background-color: #4a1313;
    border-color: #dc3545;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    50% {
        transform: translateX(5px);
    }

    75% {
        transform: translateX(-5px);
    }
}


/* ============ MOBILE ============ */
@media (max-width: 600px) {
    .grid-game-container {
        padding: 5px;
    }

    .message-container {
        padding: 0 16px;
        box-sizing: border-box;
    }

    .grid-board {
        gap: 3px;
        padding: 4px;
    }

    .grid-cell-header img {
        max-width: 100%;
        max-height: 100%;
    }

    .grid-cell-header.timer-cell .grid-logo-img {
        max-width: 45%;
    }

    .grid-timer {
        font-size: 1rem;
    }

    .grid-cell.playable-cell.filled,
    .grid-cell.playable-cell.revealed {
        border-width: 2px;
    }

    /* Nombre más compacto en móvil */
    .grid-cell.playable-cell.filled .character-name-overlay,
    .grid-cell.playable-cell.revealed .character-name-overlay {
        font-size: 0.55rem;
        padding: 8px 2px 2px;
    }
}

/* ============ PANTALLAS MUY PEQUEÑAS (< 380px) ============ */
@media (max-width: 380px) {
    .grid-board {
        gap: 2px;
        padding: 3px;
    }

    .grid-timer {
        font-size: 0.85rem;
    }

    /* Ocultar nombre solo en pantallas muy pequeñas donde no cabe */
    .grid-cell.playable-cell.filled .character-name-overlay,
    .grid-cell.playable-cell.revealed .character-name-overlay {
        display: none;
    }
}

/* ============ TUTORIAL VISUAL STEPS ============ */
.tutorial-steps {
    display: flex;
    gap: 16px;
    margin: 16px 0;
    justify-content: center;
    flex-wrap: wrap;
    align-items: stretch;
    /* Ensure cards match height */
}

.step-card {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 14px 10px;
    text-align: center;
    flex: 1 1 calc(50% - 16px);
    max-width: 190px;
    min-width: 140px;
    display: flex;
    flex-direction: column;
}

.step-card h3 {
    margin: 8px 0 4px;
    font-size: 0.9rem;
    color: #FFD700;
    font-family: 'Pirata One', cursive;
}

.step-card p {
    font-size: 0.75rem;
    color: #ccc;
    margin: 0;
    line-height: 1.3;
    flex-grow: 1;
    /* Pushes content to fill the card height */
    display: flex;
    align-items: center;
    /* Centers text vertically in its flexible space */
    justify-content: center;
}

.tutorial-steps .anim-box {
    height: auto;
    padding: 6px 0;
    min-height: 120px;
    /* Gives a consistent minimum area for the diagrams */
}

/* Mini grid demo (Step 1) */
.grid-demo-mini {
    display: grid;
    grid-template-columns: repeat(4, 28px);
    gap: 2px;
}

.gd-cell {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: bold;
}

.gd-cell.gd-corner {
    background: transparent;
}

.gd-cell.gd-col-header,
.gd-cell.gd-row-header {
    background: rgba(0, 0, 0, 0.5);
    color: #FFD700;
    font-family: 'Pirata One', cursive;
    font-size: 0.9rem;
}

.gd-cell.gd-play {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.gd-cell.gd-filled {
    background: rgba(76, 175, 80, 0.25);
    border-color: #4CAF50;
    color: #4CAF50;
    font-size: 0.9rem;
}

.gd-cell.gd-highlight {
    background: rgba(255, 215, 0, 0.25);
    border: 2px solid #FFD700;
    color: #FFD700;
    font-size: 1rem;
    animation: pulse 1.5s infinite;
}

/* Match demo (Step 2) — grid 2×2: esquina vacía | col header / fila header | celda */
.grid-match-demo {
    display: grid;
    grid-template-columns: auto auto;
    gap: 6px;
    align-items: center;
    justify-items: center;
}

.gd-corner-empty {
    width: 20px;
}

.gd-cond-box {
    padding: 4px 10px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 0.8rem;
    font-family: 'Pirata One', cursive;
}

.gd-cond-row {
    background: rgba(255, 152, 0, 0.3);
    border: 1px solid #FF9800;
    color: #FFB74D;
}

.gd-cond-col {
    background: rgba(33, 150, 243, 0.3);
    border: 1px solid #2196F3;
    color: #64B5F6;
}

.gd-target-cell {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(76, 175, 80, 0.25);
    border: 2px solid #4caf50;
    border-radius: 4px;
    font-size: 1.1rem;
}

/* Tutorial options row */
.tutorial-options {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 16px 0 10px;
}

.toggle-label {
    color: #ccc;
    font-size: 0.9rem;
}

/* ============ TUTORIAL MODAL COMPACT (MOBILE) ============ */
@media (max-width: 600px) {
    #tutorialModal .tutorial-content {
        padding: 20px 16px;
    }

    #tutorialModal .tutorial-title {
        font-size: 1.6rem;
        margin-bottom: 12px;
    }

    #tutorialModal .tutorial-steps {
        flex-direction: column;
        align-items: center;
        gap: 10px;
        margin: 10px 0;
    }

    #tutorialModal .step-card {
        width: 100%;
        max-width: 320px;
    }

    #tutorialModal .tutorial-steps .anim-box {
        min-height: 85px;
    }

    #tutorialModal .step-card {
        padding: 8px 6px;
    }

    #tutorialModal .step-card h3 {
        margin: 6px 0 3px;
        font-size: 1.2rem;
    }

    #tutorialModal .step-card p {
        font-size: 0.9rem;
    }

    #tutorialModal .tutorial-options {
        margin: 10px 0 6px;
        gap: 10px;
    }

    #tutorialModal .btn-play {
        margin-top: 6px;
        padding: 8px 30px;
        font-size: 1.3rem;
    }
}

/* ============ HOW TO PLAY — info-game overrides ============ */
/* Las demos necesitan más espacio que el anim-box genérico de common.css */
.info-game .static-step .anim-box {
    width: 100% !important;
    /* anula el width:70px mobile de common.css */
    height: auto !important;
    min-height: 140px;
    padding: 10px;
    box-sizing: border-box;
}

/* Centrar las demos dentro del anim-box */
.info-game .grid-demo-mini,
.info-game .grid-match-demo,
#tutorialModal .grid-demo-mini,
#tutorialModal .grid-match-demo {
    margin: 0 auto;
}

/* UI Messages */
#noMatchMsg,
#multiMatchMsg {
    margin-top: 10px;
    margin-bottom: 0;
}

#noMatchMsg {
    background: rgba(80, 20, 20, 0.95);
    border: 1px solid #ff4444;
    color: #ffcccc;
}

#noMatchCharName {
    color: #ffffff;
}