:root {
    --bg-color: #050505;
    --tile-bg: #151515;
    --tile-text: #fff;
    --c1: #00f3ff; --c2: #2980b9; --c3: #9b59b6; --c4: #ff00ff;
    --c5: #2ecc71; --c6: #f1c40f; --c7: #e67e22; --c8: #e74c3c;
    --accent-dog: #ff9f43;
}

* { box-sizing: border-box; }

/* VER 1.3 RESTRUCTURÉ */

/* 1. RETOUR À LA STRUCTURE V1.0 (LE VERROUILLAGE) */
body {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--tile-text);
    margin: 0; padding: 0;

    /* LA CLEF DU SUCCÈS V1.0 : On fixe l'écran comme un poster */
    position: fixed; 
    top: 0; left: 0; 
    width: 100%; 
    height: 100%;

    /* Gestion des marges iPhone */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);

    /* Flexbox pour tout aligner */
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: space-between;

    overscroll-behavior: none;
    -webkit-user-select: none; user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* 2. ÉLÉMENTS FIXES (Header, HUD, Controls) */
.top-bar, #betting-board, .hud, .controls {
    flex-shrink: 0; /* Interdit de s'écraser */
    width: 96%; 
    max-width: 500px;
    z-index: 10;
}

/* --- HEADER --- */
.top-bar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 0 5px 0;
}
h1 { 
    margin: 0; font-style: italic; color: #fff; 
    font-size: clamp(18px, 5vw, 24px); 
    font-weight: 900; letter-spacing: 2px;
    text-shadow: 0 0 10px rgba(0, 243, 255, 0.4);
}
.header-buttons { display: flex; gap: 8px; }
.btn-circle {
    width: 30px; height: 30px; border-radius: 50%; border: 2px solid #333;
    background: #111; color: #888; font-weight: bold; cursor: pointer;
    display: flex; align-items: center; justify-content: center; font-size: 1em;
}

/* --- HUD --- */
#betting-board {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px;
    margin-bottom: 5px;
}
.bet-card {
    display: flex; justify-content: space-between; align-items: center;
    background: #0f0f0f; padding: 4px 8px; border-radius: 6px;
    border: 1px solid #333; border-left: 3px solid #444; font-size: 12px;
}
.bet-card.winner { border-color: #2ecc71; background: #0b2210; }
.bet-card.loser { opacity: 0.3; filter: grayscale(100%); }
.dog-badge { 
    background: #fff; color: #000; font-size: 0.8em; 
    width: 16px; height: 16px; border-radius: 50%; 
    display: flex; align-items: center; justify-content: center; font-weight: 900; margin-right: 5px;
}
.dog-name { display: flex; align-items: center; font-weight: 700; color:#ccc;}
.bet-amount { color: #2ecc71; font-family: monospace; font-weight: bold; }

.hud { 
    display: flex; justify-content: space-between;
    background: #111; padding: 5px 15px; border-radius: 50px; border: 1px solid #222;
    margin-bottom: 5px;
}
.hud-item { display: flex; flex-direction: column; align-items: center; }
.hud-label { font-size: 0.6em; color: #666; letter-spacing: 1px; }
.hud-value { font-size: 1.1em; font-weight: bold; color: #fff; font-family: monospace; }
.hud-value.highlight { color: #f1c40f; }

/* 3. LE RETOUR DE LA LOGIQUE V1.0 POUR LA GRILLE */
.game-container {
    flex-grow: 1; /* Occupe l'espace restant */
    display: flex; align-items: center; justify-content: center;
    width: 100%; position: relative; overflow: hidden; padding: 5px 0;
}

#game-grid {
    display: grid; 
    grid-template-columns: repeat(8, 1fr); 
    grid-template-rows: repeat(8, 1fr); 
    gap: 3px;
    
    background: #000; padding: 4px; border-radius: 12px; border: 2px solid #333;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);

    /* --- ICI : ON REPREND LA LOGIQUE EXACTE DE LA V1.0 --- */
    /* width: min(Largeur, 52% Hauteur) */
    /* Le !important bloque les skins capricieux */
    width: min(94vw, 52vh) !important;
    height: min(94vw, 52vh) !important;
    
    margin: auto !important;
}

/* --- TUILES (Style V1.3 conservé) --- */
.tile {
    width: 100%; height: 100%; background-color: var(--tile-bg);
    display: flex; align-items: center; justify-content: center;
    font-size: clamp(10px, 3.5vh, 26px);
    font-weight: 800; border-radius: 4px;
    position: relative; transition: transform 0.1s;
    border-bottom: 2px solid rgba(0,0,0,0.3); cursor: pointer;
}
.val-1 { color: var(--c1); border: 1px solid rgba(0, 243, 255, 0.3); background: rgba(0, 243, 255, 0.05); }
.val-2 { color: var(--c2); border: 1px solid rgba(41, 128, 185, 0.3); background: rgba(41, 128, 185, 0.05); }
.val-3 { color: var(--c3); border: 1px solid rgba(155, 89, 182, 0.3); background: rgba(155, 89, 182, 0.05); }
.val-4 { color: var(--c4); border: 1px solid rgba(255, 0, 255, 0.3); background: rgba(255, 0, 255, 0.05); }
.val-5 { color: var(--c5); border: 1px solid rgba(46, 204, 113, 0.3); background: rgba(46, 204, 113, 0.05); }
.val-6 { color: var(--c6); border: 1px solid rgba(241, 196, 15, 0.3); background: rgba(241, 196, 15, 0.05); }
.val-7 { color: var(--c7); border: 1px solid rgba(230, 126, 34, 0.3); background: rgba(230, 126, 34, 0.05); }
.val-8 { color: var(--c8); border: 1px solid rgba(231, 76, 60, 0.3); background: rgba(231, 76, 60, 0.05); }

.tile.nine { border: 2px solid var(--accent-dog); background-color: #000; padding: 0; overflow: hidden; }
.tile.selected { background-color: #333; transform: scale(0.9); box-shadow: 0 0 10px #fff; z-index: 10; border-color:#fff;}
.tile.empty { background: transparent; border: 1px dashed #222; box-shadow: none; }
.anim-match { animation: flash 0.2s forwards; background: #fff !important; }
@keyframes flash { 0% { opacity: 1; } 50% { opacity: 0.5; transform: scale(1.1); } 100% { opacity: 0; } }

/* 4. CONTRÔLES (BAS) */
.controls { 
    display: flex; gap: 8px; 
    width: 96%; max-width: 500px;
    
    /* V1.0 Logic : Marge du bas sécurisée */
    margin-bottom: max(10px, env(safe-area-inset-bottom));
    
    flex-shrink: 0;
}

button { 
    flex: 1; padding: 12px 0; border: none; border-radius: 8px;
    font-weight: bold; font-size: clamp(12px, 3.5vw, 16px);
    text-transform: uppercase; cursor: pointer; transition: 0.1s;
    box-shadow: 0 4px 0 rgba(0,0,0,0.5);
}
button:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,0.5); }
#btn-hint { color: var(--c1); background: #0a1f20; }
#btn-shuffle { color: var(--c6); background: #1f1d0a; }
#btn-reset { color: #fff; background: #222; }

/* ECRAN TITRE */
#start-screen {
    position: absolute; top: 0; left: 0; 
    width: 100%; height: 100%; 
    background: #050505; z-index: 9999;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.logo-title {
    font-size: 3em; font-weight: 900; font-style: italic;
    background: linear-gradient(45deg, #fff, #888);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    margin-bottom: 20px; letter-spacing: 4px; text-align: center;
}
.btn-start {
    background: #e67e22; color: #fff; border: none;
    padding: 15px 40px; font-size: 1.5em; font-weight: bold;
    border-radius: 50px; cursor: pointer;
    box-shadow: 0 0 20px rgba(230, 126, 34, 0.4);
    animation: pulse 1.5s infinite;
    flex: 0 0 auto;
    width: auto; max-width: 80%;
}
@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.05); } 100% { transform: scale(1); } }

/* OVERLAYS */
#message-overlay {
    position: absolute; top:0; left:0; width:100%; height:100%;
    background: rgba(0,0,0,0.92); backdrop-filter: blur(8px); z-index: 100;
    display: none; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: 20px;
}
.tile.hint-flash {
    background-color: #2ecc71 !important; color: #000 !important;
    box-shadow: 0 0 20px #2ecc71; transform: scale(1.1);
    z-index: 50; transition: all 0.2s;
}
