/* =========================================
   NARUTO GRID — CSS
   Sigue el sistema de diseño de Naru2day:
   pergamino (#CE9D66) + tablero oscuro
   ========================================= */

/* ── Tutorial overlay: visible cuando no tiene .hidden ──────── */
#tutorialModal {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
}

/* ── CONTENEDOR PRINCIPAL ──────────────────────────────────── */
.container-grid {
    max-width: 600px;
    margin: 0 auto;
    padding: 0 15px 30px;
}

/* ── FILA DE TITULO ─────────────────────────────────────────── */
.grid-title-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 28px 0 22px;
}

.grid-title-h1 {
    margin: 0;
    font-family: 'Reggae One', cursive;
    font-size: 1.6rem;
    font-weight: 400;
    color: var(--wn-text);
}

.grid-btn-info {
    background: rgba(255, 107, 0, 0.15);
    border: 1.5px solid rgba(255, 107, 0, 0.4);
    color: #FF6B00;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    padding: 0;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    flex-shrink: 0;
    line-height: 1;
    transition: background 0.2s;
}

.grid-btn-info:hover {
    background: rgba(255, 107, 0, 0.3);
}

/* ── TABLERO (pergamino integrado) ────────────────────────────── */
.grid-game-container {
    background: url('../img/Fondo_Pergamino.webp') center center / cover no-repeat,
        linear-gradient(160deg, #e8d5b0, #d4b882);
    border: 2px solid #8B5A2B;
    border-radius: 18px;
    padding: 18px;
    box-shadow:
        0 12px 40px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.45),
        inset 0 -2px 0 rgba(0, 0, 0, 0.15);
    margin-bottom: 14px;
}

.grid-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 6px;
    background: rgba(74, 46, 21, 0.18);
    padding: 6px;
    border-radius: 12px;
    border: 1.5px solid rgba(139, 90, 43, 0.35);
    box-shadow: inset 0 2px 8px rgba(90, 50, 0, 0.15);
}

/* ── Celdas cabecera (criterios de fila/columna) ── */
.grid-cell-header {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, #4A2E15 0%, #3B2410 60%, #2E1A0B 100%);
    border: 2px solid #8B5A2B;
    color: #E8D0A9;
    border-radius: 10px;
    text-align: center;
    padding: 0;
    overflow: hidden;
    aspect-ratio: 1 / 1;
    position: relative;
    box-shadow:
        0 3px 8px rgba(0, 0, 0, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.grid-cell-header img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.6));
    display: block;
}

.grid-cat-icon {
    width: 100%;
    height: 100%;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.6));
}

.grid-cell-header span {
    font-size: clamp(0.42rem, 1.8vw, 0.68rem);
    line-height: 1.2;
    word-break: break-word;
    hyphens: auto;
    padding: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: #E8D0A9;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* Celda esquina: logo + timer */
.grid-cell-header.timer-cell {
    background: linear-gradient(145deg, #3B2410 0%, #2E1A0B 100%);
    border-color: #8B5A2B;
    flex-direction: column;
    gap: 4px;
    padding: 6px 4px;
}

.grid-cell-header.timer-cell .grid-logo-img {
    max-width: 50%;
    max-height: 46%;
    object-fit: contain;
    border-radius: 6px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}

.grid-timer {
    font-family: 'Reggae One', cursive;
    font-size: 1.15rem;
    color: #FF6B00;
    letter-spacing: 1px;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 8px rgba(255, 107, 0, 0.4);
}

/* ── CELDAS JUGABLES ─────────────────────────────────────────── */
.grid-cell.playable-cell {
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(139, 90, 43, 0.35);
    border-radius: 10px;
    cursor: default;
    transition: all 0.25s ease;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    box-shadow:
        0 2px 6px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

/* Resaltado: el personaje encaja aquí */
.grid-cell.playable-cell.highlight {
    background: rgba(255, 107, 0, 0.12);
    border: 2px solid #FF6B00;
    cursor: pointer;
    box-shadow:
        0 0 14px rgba(255, 107, 0, 0.3),
        inset 0 0 8px rgba(255, 107, 0, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    transform: scale(1.03);
}

.grid-cell.playable-cell.highlight:hover {
    background: rgba(255, 107, 0, 0.2);
    transform: scale(1.05);
}

/* Animaciones de celda */
@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; }
}

/* Celda correcta */
.grid-cell.playable-cell.filled {
    background: url('../img/Fondo_Pergamino.webp') center / cover no-repeat;
    background-color: #a0d4b0;
    background-blend-mode: multiply;
    border: 2px solid #3c7355;
    cursor: default;
    box-shadow: 0 4px 10px rgba(56, 193, 114, 0.3);
    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;
}

.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.85) 0%, rgba(0,0,0,0.35) 70%, transparent 100%);
    color: #e8ffe8;
    font-weight: 700;
    font-size: 0.62rem;
    padding: 10px 2px 3px;
    text-align: center;
    pointer-events: none;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

/* Celda revelada (al rendirse) */
.grid-cell.playable-cell.revealed {
    background: url('../img/Fondo_Pergamino.webp') center / cover no-repeat;
    background-color: #eaa4a8;
    background-blend-mode: multiply;
    border: 2px solid #a83f47;
    cursor: default;
    box-shadow: 0 4px 10px rgba(168, 63, 71, 0.25);
    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.6;
}

.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.88) 0%, rgba(80,20,20,0.4) 70%, transparent 100%);
    color: #ffcdd2;
    font-weight: 700;
    font-size: 0.62rem;
    padding: 10px 2px 3px;
    text-align: center;
    pointer-events: none;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

/* Error shake */
.grid-cell.playable-cell.error-anim {
    animation: gridShake 0.4s ease-in-out;
    background: rgba(220, 53, 69, 0.15);
    border-color: #dc3545;
    box-shadow: 0 0 10px rgba(220, 53, 69, 0.25);
}

@keyframes gridShake {
    0%, 100% { transform: translateX(0); }
    25%       { transform: translateX(-5px); }
    50%       { transform: translateX(5px); }
    75%       { transform: translateX(-5px); }
}

/* ── BUSQUEDA (dentro del card pergamino) ────────────────────── */
.grid-search-wrap {
    margin-top: 14px;
    position: relative;
}

.grid-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.grid-search-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.6);
    border: 2px solid #C19A6B;
    border-radius: 50px;
    padding: 11px 18px;
    font-size: 0.95rem;
    color: #3E2723;
    outline: none;
    width: 100%;
    transition: border-color 0.25s, box-shadow 0.25s;
}

.grid-search-input:focus {
    border-color: #8B5A2B;
    box-shadow: 0 0 0 3px rgba(139, 90, 43, 0.15);
    background: #fff;
}

.grid-search-input::placeholder {
    color: #8B5A2B;
    opacity: 0.7;
}

.grid-btn-guess {
    background: linear-gradient(135deg, #FF6B00, #e05200);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 11px 18px;
    font-size: 0.9rem;
    font-family: 'Reggae One', cursive;
    cursor: pointer;
    white-space: nowrap;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 4px 12px rgba(255, 107, 0, 0.35);
    flex-shrink: 0;
}

.grid-btn-guess:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(255, 107, 0, 0.45);
}

.grid-btn-guess:disabled {
    opacity: 0.6;
    cursor: default;
    transform: none;
}

/* Mensajes (match multiple / no match) */
.grid-msg {
    margin-top: 10px;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    animation: pulse 2s infinite;
}

.grid-msg.hidden {
    display: none;
}

.grid-msg--info {
    background: rgba(90, 50, 0, 0.12);
    border: 1px solid rgba(139, 90, 43, 0.4);
    color: #4A2E15;
}

.grid-msg--error {
    background: rgba(139, 60, 60, 0.12);
    border: 1px solid rgba(180, 80, 80, 0.45);
    color: #5B1E23;
}

.grid-msg--error strong {
    color: #3E1010;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.8;
    }
}

/* ── WIN / LOSE: mismo ancho que el game-container ──────────── */
.container-grid .game-result-wrapper {
    max-width: 100%;
    width: 100%;
}

.container-grid .game-result-wrapper .game-result-modal {
    width: 100%;
    max-width: 100%;
    margin: 0;
    box-sizing: border-box;
}

/* ── RANKING ─────────────────────────────────────────────────── */
#grid-ranking {
    margin: 14px 0 0;
    width: 100%;
    background: url('../img/Fondo_Pergamino.webp') center center / cover no-repeat;
    background-color: #CE9D66;
    border: 2px solid #C19A6B;
    border-radius: 14px;
    padding: 18px 18px 14px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

#grid-ranking.hidden {
    display: none;
}

/* ── TUTORIAL (pergamino style) ──────────────────────────────── */
.grid-tut-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin: 14px 0 18px;
}

.grid-tut-card {
    background: rgba(255, 255, 255, 0.3);
    border: 1.5px solid rgba(139, 90, 43, 0.3);
    border-radius: 12px;
    padding: 12px 8px;
    display: grid;
    grid-template-rows: 115px min-content 1fr;
    align-items: start;
    justify-items: center;
    gap: 8px;
    text-align: center;
}

.grid-tut-card> :first-child {
    align-self: center;
}

.grid-tut-card strong {
    color: #4A2E15;
    font-size: 0.84rem;
    font-weight: 800;
    line-height: 1.3;
}

.grid-tut-card small {
    color: #5c4033;
    font-size: 0.77rem;
    line-height: 1.4;
}

.tutorial-timer-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 20px 0;
}

.tutorial-overlay.tutorial-help-open .tutorial-timer-row {
    display: none;
}

/* Toggle switch (timer en tutorial) */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 54px;
    height: 30px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 30px;
    transition: .3s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    border-radius: 50%;
    transition: .3s;
}

input:checked+.slider {
    background-color: var(--wn-orange, #FF6B00);
}

input:checked+.slider:before {
    transform: translateX(24px);
}

.toggle-label {
    font-size: 0.95rem;
    font-weight: 700;
    color: #4A2E15;
}

.btn-play {
    background: linear-gradient(135deg, var(--wn-orange, #FF6B00) 0%, #e05200 100%);
    color: #fff;
    border: none;
    border-radius: 50px;
    padding: 12px 36px;
    font-family: 'Reggae One', cursive;
    font-size: 1.15rem;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(255, 107, 0, 0.35);
    transition: transform 0.15s, filter 0.15s;
    width: 100%;
    margin-top: 4px;
}

.btn-play:hover {
    transform: translateY(-2px);
    filter: brightness(1.08);
}

/* ── DEMO MINI GRID (tutorial + how to play) ─────────────────── */
.grid-demo-mini {
    display: grid;
    grid-template-columns: repeat(4, 26px);
    gap: 2px;
}

.gd-cell {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 700;
}

.gd-cell.gd-corner {
    background: transparent;
}

.gd-cell.gd-col-header,
.gd-cell.gd-row-header {
    background: rgba(0, 0, 0, 0.12);
    color: #4A2E15;
    font-size: 0.85rem;
    font-weight: 800;
}

.gd-cell.gd-play {
    background: rgba(255, 255, 255, 0.25);
    border: 1px solid rgba(139, 90, 43, 0.25);
}

.gd-cell.gd-filled {
    background: rgba(56, 193, 114, 0.25);
    border: 1px solid #3c7355;
    color: #1A4027;
    font-size: 0.85rem;
}

.gd-cell.gd-highlight {
    background: rgba(255, 107, 0, 0.2);
    border: 1.5px solid #FF6B00;
    color: #4A2E15;
    font-size: 0.9rem;
}

/* Match demo 2x2 */
.grid-match-demo {
    display: grid;
    grid-template-columns: auto auto;
    gap: 5px;
    align-items: center;
    justify-items: center;
}

.gd-corner-empty {
    width: 18px;
}

.gd-cond-box {
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 0.75rem;
}

.gd-cond-row {
    background: rgba(255, 107, 0, 0.2);
    border: 1px solid #FF6B00;
    color: #4A2E15;
}

.gd-cond-col {
    background: rgba(56, 112, 193, 0.2);
    border: 1px solid #4A7CC7;
    color: #1a3a6e;
}

.gd-target-cell {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(56, 193, 114, 0.2);
    border: 1.5px solid #3c7355;
    border-radius: 4px;
    font-size: 1rem;
}

/* ── COMO JUGAR ───────────────────────────────────────────────── */


.grid-howto-steps {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: stretch;
}

.grid-howto-card {
    background: rgba(255, 255, 255, 0.3);
    border: 1.5px solid rgba(139, 90, 43, 0.3);
    border-radius: 12px;
    padding: 14px 10px;
    display: grid;
    grid-template-rows: 115px min-content 1fr;
    align-items: start;
    justify-items: center;
    gap: 8px;
    text-align: center;
    flex: 1 1 140px;
    max-width: 180px;
}

.grid-howto-card> :first-child {
    align-self: center;
}

.grid-howto-card strong {
    color: #FF6B00;
    font-family: 'Reggae One', cursive;
    font-size: 1rem;
    line-height: 1.2;
}

.grid-howto-card small {
    color: #4A2E15;
    font-size: 0.8rem;
    line-height: 1.4;
}

.grid-howto-icon {
    font-size: 2rem;
    line-height: 1;
}

/* ── RESPONSIVE ──────────────────────────────────────────────── */
@media (max-width: 600px) {
    .container-grid {
        padding: 0 8px 20px;
    }

    .grid-title-h1 {
        font-size: 1.2rem;
    }

    .grid-game-container {
        padding: 12px 10px;
    }

    .grid-board {
        gap: 4px;
        padding: 4px;
    }

    .grid-cell-header {
        border-radius: 8px;
    }

    .grid-cell.playable-cell {
        border-radius: 8px;
    }

    .grid-cell-header.timer-cell .grid-logo-img {
        max-width: 45%;
    }

    .grid-timer {
        font-size: 1rem;
    }

    .grid-search-wrap {
        padding: 10px;
    }

    .grid-btn-guess {
        padding: 10px 12px;
        font-size: 0.82rem;
    }

    .grid-cell.playable-cell.filled,
    .grid-cell.playable-cell.revealed {
        border-width: 2px;
    }

    .grid-cell.playable-cell.filled .character-name-overlay,
    .grid-cell.playable-cell.revealed .character-name-overlay {
        font-size: 0.52rem;
        padding: 8px 2px 2px;
    }

    .grid-howto-steps {
        flex-direction: column;
        align-items: center;
    }

    .grid-howto-card,
    .grid-tut-card {
        display: grid;
        grid-template-columns: auto 1fr;
        grid-template-rows: auto auto;
        column-gap: 16px;
        max-width: 100%;
        width: 100%;
        align-items: center;
        text-align: left;
    }

    .grid-howto-card> :first-child,
    .grid-tut-card> :first-child {
        grid-row: 1 / -1;
        grid-column: 1;
        align-self: center;
    }

    .grid-howto-card strong,
    .grid-tut-card strong {
        grid-row: 1;
        grid-column: 2;
        align-self: end;
        font-size: 0.9rem;
        margin-bottom: 2px;
    }

    .grid-howto-card small,
    .grid-tut-card small {
        grid-row: 2;
        grid-column: 2;
        align-self: start;
    }

    .grid-tut-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 380px) {
    .grid-board {
        gap: 2px;
        padding: 3px;
    }

    .grid-timer {
        font-size: 0.85rem;
    }

    .grid-cell.playable-cell.filled .character-name-overlay,
    .grid-cell.playable-cell.revealed .character-name-overlay {
        display: none;
    }
}