/**
 * PATRIX - Styles de la Grille
 * Auteur: Emmanuel Payet
 */

/* Conteneur de la grille - Maximisé */
.game-board {
    background: linear-gradient(135deg, #f5f1e8 0%, #fffef9 50%, #f5f1e8 100%);
    backdrop-filter: blur(8px);
    border: 3px solid #d4af37;
    border-radius: 0;
    padding: 3px;
    box-shadow: 
        0 0 40px rgba(212, 175, 55, 0.4),
        inset 0 0 30px rgba(255, 255, 255, 0.3),
        0 0 80px rgba(192, 192, 192, 0.2);
    width: 100%;
    height: 100%;
    min-height: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    position: relative;
    overflow: hidden;
}

/* Canvas pour tracer les lignes - Positionné sur le board */
.connection-canvas {
    position: absolute;
    pointer-events: none;
    z-index: 10;
}

/* Grille - S'adapte aux cellules carrées avec largeur minimale */
.board {
    background: linear-gradient(135deg, #c0c0c0 0%, #d4af37 50%, #c0c0c0 100%);
    border: 4px solid #d4af37;
    border-top: 3px solid #c0c0c0;
    border-radius: 0;
    padding: 6px;
    width: min(100%, max(300px, 80vw));
    max-width: 100%;
    position: relative;
    margin: 0 auto;
    box-shadow: 
        0 0 40px rgba(212, 175, 55, 0.6),
        inset 0 0 25px rgba(255, 255, 255, 0.5),
        0 0 80px rgba(192, 192, 192, 0.4);
}

/* Grille interne - s'adapte aux cellules */
.board-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-auto-rows: min-content;
    gap: 2px;
    width: 100%;
    position: relative;
    cursor: grab;
    user-select: none;
}

.board-grid:active {
    cursor: grabbing;
}

/* Canvas pour tracer les lignes - Sur board-grid */
.connection-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    grid-column: 1 / -1;
    grid-row: 1 / -1;
}

/* Cellules - Carrés parfaits avec ajustement auto */
.cell {
    aspect-ratio: 1;
    width: 100%;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(192, 192, 192, 0.5);
    border-radius: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(10px, 1.8vmin, 16px);
    transition: all 0.15s ease;
    user-select: none;
}

/* Cellule remplie */
.cell.filled {
    border-width: 1px;
    background: rgba(212, 175, 55, 0.15);
    transform: scale(0.98);
    font-weight: bold;
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.5);
}

/* Cellule poppable */
.cell.poppable {
    cursor: pointer;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.9), 0 0 15px rgba(255, 255, 255, 0.6);
    animation: cellPulse 1s ease-in-out infinite;
}

.cell.poppable:hover {
    box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 1), 0 0 25px rgba(255, 255, 255, 0.9);
    transform: scale(1.05);
}

/* Cellule tracée */
.cell.traced {
    box-shadow: 
        inset 0 0 0 3px rgba(255, 255, 255, 1),
        0 0 30px rgba(255, 255, 255, 0.9);
    transform: scale(1.1);
    z-index: 5;
    background: rgba(255, 255, 255, 0.5);
}

/* Cellule en transformation (ligne complète) */
.cell.transforming {
    animation: lineTransform 0.6s ease-out forwards;
}

/* Pièce en cours de jeu */
.cell.current-piece {
    animation: glowSF 1s ease-in-out infinite alternate;
}

@keyframes glowSF {
    from {
        box-shadow: 0 0 15px rgba(255, 255, 255, 0.9), inset 0 0 12px rgba(255, 255, 255, 0.7);
    }
    to {
        box-shadow: 0 0 35px rgba(255, 255, 255, 1), inset 0 0 25px rgba(255, 255, 255, 0.9);
    }
}

/* Types de blocs - Couleurs sombres (avant transformation) */
.cell.cross { 
    border-color: #4a5568; 
    color: #4a5568;
    background: linear-gradient(135deg, #FFD1DC 0%, #FFC0CB 25%, #FFB6C1 50%, #FFC0CB 75%, #FFD1DC 100%);
    background-size: 200% 200%;
    animation: marbleShift 3s ease infinite;
}

.cell.heart { 
    border-color: #553c5e; 
    color: #553c5e;
    background: linear-gradient(135deg, #E0BBE4 0%, #D8BFD8 25%, #DDA0DD 50%, #D8BFD8 75%, #E0BBE4 100%);
    background-size: 200% 200%;
    animation: marbleShift 3s ease infinite;
}

.cell.star { 
    border-color: #5e4a3c; 
    color: #5e4a3c;
    background: linear-gradient(135deg, #FFFACD 0%, #FDFD96 25%, #FAFAD2 50%, #FDFD96 75%, #FFFACD 100%);
    background-size: 200% 200%;
    animation: marbleShift 3s ease infinite;
}

.cell.anchor { 
    border-color: #3c4e5e; 
    color: #3c4e5e;
    background: linear-gradient(135deg, #AEC6CF 0%, #B0E0E6 25%, #ADD8E6 50%, #B0E0E6 75%, #AEC6CF 100%);
    background-size: 200% 200%;
    animation: marbleShift 3s ease infinite;
}

.cell.llight { 
    border-color: #4e5e3c; 
    color: #4e5e3c;
    background: linear-gradient(135deg, #C1E1C1 0%, #B4E7CE 25%, #A8E4A0 50%, #B4E7CE 75%, #C1E1C1 100%);
    background-size: 200% 200%;
    animation: marbleShift 3s ease infinite;
}

.cell.tcross { 
    border-color: #5e3c4a; 
    color: #5e3c4a;
    background: linear-gradient(135deg, #FFE5B4 0%, #FFDAB9 25%, #FFCC99 50%, #FFDAB9 75%, #FFE5B4 100%);
    background-size: 200% 200%;
    animation: marbleShift 3s ease infinite;
}

.cell.pillar { 
    border-color: #5e5e4a; 
    color: #5e5e4a;
    background: linear-gradient(135deg, #E8E8E8 0%, #D3D3D3 25%, #C0C0C0 50%, #D3D3D3 75%, #E8E8E8 100%);
    background-size: 200% 200%;
    animation: marbleShift 3s ease infinite;
}

/* Transformation → Couleurs lumineuses */
.cell.transformed.cross { 
    border-color: #ffd700 !important; 
    color: #ffd700 !important;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.6);
}

.cell.transformed.heart { 
    border-color: #ff6b9d !important; 
    color: #ff6b9d !important;
    box-shadow: 0 0 15px rgba(255, 107, 157, 0.6);
}

.cell.transformed.star { 
    border-color: #ffeb3b !important; 
    color: #ffeb3b !important;
    box-shadow: 0 0 15px rgba(255, 235, 59, 0.6);
}

.cell.transformed.anchor { 
    border-color: #4fc3f7 !important; 
    color: #4fc3f7 !important;
    box-shadow: 0 0 15px rgba(79, 195, 247, 0.6);
}

.cell.transformed.llight { 
    border-color: #81c784 !important; 
    color: #81c784 !important;
    box-shadow: 0 0 15px rgba(129, 199, 132, 0.6);
}

.cell.transformed.tcross { 
    border-color: #ba68c8 !important; 
    color: #ba68c8 !important;
    box-shadow: 0 0 15px rgba(186, 104, 200, 0.6);
}

.cell.transformed.pillar { 
    border-color: #f4a460 !important; 
    color: #f4a460 !important;
    box-shadow: 0 0 15px rgba(244, 164, 96, 0.6);
}

/* Animation d'explosion */
.cell.exploding {
    animation: explode 0.6s ease-out forwards;
}

@keyframes explode {
    0% { 
        transform: scale(0.95); 
        opacity: 1; 
    }
    50% { 
        transform: scale(1.4); 
        opacity: 0.8;
        box-shadow: 0 0 30px currentColor;
    }
    100% { 
        transform: scale(0); 
        opacity: 0; 
    }
}

/* Animation du marbre cuivré */
@keyframes marbleShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Responsive - La grille s'adapte automatiquement via aspect-ratio et grid fr */
@media (max-width: 768px) {
    .board {
        max-width: 320px;
        padding: 5px;
    }
    
    .connection-canvas {
        max-width: 320px;
    }
    
    .treasure-content {
        padding: 30px 20px;
    }
    
    .treasure-icon {
        font-size: 60px;
    }
    
    .treasure-level {
        font-size: 20px;
    }
    
    .treasure-level span {
        font-size: 28px;
    }
    
    .treasure-message {
        font-size: 16px;
    }
}

@media (max-width: 430px) {
    .board {
        max-width: 280px;
        padding: 4px;
    }
    
    .connection-canvas {
        max-width: 280px;
    }
    
    .cell {
        border-radius: 1px;
    }
}

/* Modal Trésor - Style cristal blanc épuré */
.treasure-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(8px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    animation: fadeIn 0.3s ease;
}

.treasure-modal.show {
    display: flex;
}

.treasure-content {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(245, 241, 232, 0.95));
    border: 3px solid #d4af37;
    border-radius: 15px;
    padding: 40px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    box-shadow: 
        0 20px 60px rgba(212, 175, 55, 0.4),
        inset 0 0 40px rgba(255, 255, 255, 0.5);
    animation: treasureAppear 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    position: relative;
}

.treasure-content::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    background: linear-gradient(45deg, #d4af37, #c0c0c0, #d4af37);
    border-radius: 15px;
    z-index: -1;
    opacity: 0.3;
    animation: rotateBorder 4s linear infinite;
}

@keyframes rotateBorder {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.6; }
}

@keyframes treasureAppear {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.treasure-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: treasureBounce 2s ease-in-out infinite;
    filter: drop-shadow(0 4px 8px rgba(212, 175, 55, 0.3));
}

@keyframes treasureBounce {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-20px) scale(1.1); }
}

.treasure-level {
    font-size: 24px;
    font-weight: 600;
    color: #d4af37;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 20px;
    text-shadow: 0 2px 4px rgba(212, 175, 55, 0.3);
}

.treasure-level span {
    font-size: 36px;
    color: #d4af37;
}

.treasure-message {
    font-size: 20px;
    line-height: 1.6;
    color: #5a5a5a;
    margin: 30px 0;
    padding: 20px;
    background: rgba(212, 175, 55, 0.05);
    border-radius: 10px;
    border-left: 4px solid #d4af37;
    text-align: left;
    box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.3);
}

.treasure-button {
    background: linear-gradient(135deg, #d4af37 0%, #c0c0c0 100%);
    color: #ffffff;
    border: 2px solid #d4af37;
    padding: 15px 40px;
    font-size: 20px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 5px 20px rgba(212, 175, 55, 0.3);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.treasure-button:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 30px rgba(255, 215, 0, 0.6);
}

.treasure-button:active {
    transform: translateY(-1px) scale(1.02);
