/**
 * Fichier: tetris.css
 * Description: Styles pour le jeu Tétris
 */

/* === GRILLE PRINCIPALE === */
.tetris-grid-container {
    /* Hauteur = 60% du viewport, largeur calculée via aspect-ratio */
    height: min(60vh, 500px);
    height: min(60dvh, 500px);
    aspect-ratio: 10 / 20;
    background: #0f0f1e;
    border: 3px solid #404060;
    border-radius: 8px;
    overflow: hidden;
    /* Swipe mobile: bloque gestes natifs sur la grille */
    touch-action: none;
    overscroll-behavior: contain;
}

.tetris-grid {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(20, 1fr);
    gap: 0;
    padding: 0;
}

.tetris-row {
    display: contents;
}

.tetris-cell {
    border: 1px solid #333344;
    background: #0f0f1e;
    transition: background 0.1s ease;
}

/* Couleurs des pièces */
.tetris-cell.filled-1 {
    background: #06b6d4;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

.tetris-cell.filled-2 {
    background: #eab308;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

.tetris-cell.filled-3 {
    background: #a855f7;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

.tetris-cell.filled-4 {
    background: #22c55e;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

.tetris-cell.filled-5 {
    background: #ef4444;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

.tetris-cell.filled-6 {
    background: #f97316;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

.tetris-cell.filled-7 {
    background: #3b82f6;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Ghost pieces (preview of landing position) */
.tetris-cell.ghost-1 {
    background: transparent;
    border: 2px solid #06b6d4;
    box-sizing: border-box;
}

.tetris-cell.ghost-2 {
    background: transparent;
    border: 2px solid #eab308;
    box-sizing: border-box;
}

.tetris-cell.ghost-3 {
    background: transparent;
    border: 2px solid #a855f7;
    box-sizing: border-box;
}

.tetris-cell.ghost-4 {
    background: transparent;
    border: 2px solid #22c55e;
    box-sizing: border-box;
}

.tetris-cell.ghost-5 {
    background: transparent;
    border: 2px solid #ef4444;
    box-sizing: border-box;
}

.tetris-cell.ghost-6 {
    background: transparent;
    border: 2px solid #f97316;
    box-sizing: border-box;
}

.tetris-cell.ghost-7 {
    background: transparent;
    border: 2px solid #3b82f6;
    box-sizing: border-box;
}

/* === ZONE PRINCIPALE === */
.tetris-main-area {
    display: flex;
    gap: 15px;
    align-items: flex-start;
    justify-content: center;
    margin-bottom: 20px;
}

/* === PROCHAINE PIÈCE === */
.tetris-next-piece {
    text-align: center;
    background: #1a1a2e;
    padding: 10px;
    border-radius: 8px;
    border: 2px solid #404060;
    width: 80px;
}

.tetris-next-piece h3 {
    margin: 0 0 8px 0;
    font-size: 11px;
    font-weight: 600;
    color: #b0b0d0;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.next-piece-preview {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 2px;
    width: 100%;
    aspect-ratio: 1;
    background: #0f0f1e;
    padding: 5px;
    border-radius: 6px;
}

.preview-row {
    display: contents;
}

.preview-cell {
    aspect-ratio: 1;
    background: #1a1a2e;
    border: 1px solid #333344;
    border-radius: 3px;
}

/* Couleurs preview */
.preview-cell.filled-1 { background: #06b6d4; }
.preview-cell.filled-2 { background: #eab308; }
.preview-cell.filled-3 { background: #a855f7; }
.preview-cell.filled-4 { background: #22c55e; }
.preview-cell.filled-5 { background: #ef4444; }
.preview-cell.filled-6 { background: #f97316; }
.preview-cell.filled-7 { background: #3b82f6; }

.key-btn:hover:not(:disabled) {
    background: #252540;
    border-color: #505080;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.key-btn:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.key-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.key-arrow {
    flex: 1;
}

.key-action {
    flex: 1;
}

/* === CONTRÔLES EN JEU === */
.action-game-panel {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.cheat-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* === AFFICHAGE DE FIN DE PARTIE === */
.game-end-overlay {
    position: absolute; 
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.game-end-result-card {
    background: linear-gradient(135deg, #1a1a2e 0%, #0f0f1e 100%);
    border: 2px solid #404060;
    border-radius: 16px;
    padding: 30px;
    text-align: center;
    max-width: 400px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.game-end-result-icon {
    font-size: 64px;
    display: block;
    margin-bottom: 20px;
}

.game-end-result-card h2 {
    margin: 0 0 15px 0;
    font-size: 28px;
    color: #e0e0ff;
    font-weight: 700;
}

.game-end-result-card p {
    margin: 8px 0;
    color: #a0a0c0;
    font-size: 16px;
    line-height: 1.5;
}

.game-end-result-card .credit {
    font-size: 18px;
    font-weight: 600;
    color: #eab308;
}

.reward-text-group {
    background: #0f0f1e;
    padding: 15px;
    border-radius: 8px;
    margin: 15px 0;
}

.reward-text-group p {
    margin: 8px 0;
}

.text-link {
    color: #3b82f6;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s ease;
    text-decoration: underline;
}

.text-link:hover {
    color: #2563eb;
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .tetris-grid-container {
        height: min(55vh, 450px);
        height: min(55dvh, 450px);
    }

    .tetris-main-area {
        gap: 10px;
    }

    .tetris-next-piece {
        width: 70px;
        padding: 8px;
    }

    .tetris-next-piece h3 {
        font-size: 10px;
        margin-bottom: 6px;
    }

    .game-end-result-card {
        max-width: 90%;
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .tetris-grid-container {
        height: min(50vh, 400px);
        height: min(50dvh, 400px);
    }

    .tetris-main-area {
        gap: 8px;
    }

    .tetris-next-piece {
        width: 60px;
        padding: 6px;
    }

    .tetris-next-piece h3 {
        font-size: 9px;
        margin-bottom: 4px;
    }

    .next-piece-preview {
        padding: 3px;
        gap: 1px;
    }

    .game-end-result-card {
        padding: 15px;
    }

    .game-end-result-icon {
        font-size: 40px;
    }

    .game-end-result-card h2 {
        font-size: 18px;
    }
}

/* Écrans très petits en hauteur (paysage mobile) */
@media (max-height: 500px) {
    .tetris-grid-container {
        height: min(70vh, 350px);
        height: min(70dvh, 350px);
    }

    .tetris-next-piece {
        width: 55px;
        padding: 5px;
    }

    .tetris-next-piece h3 {
        font-size: 8px;
    }
}
