/* Réinitialisation et Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent; /* Enlève le flash bleu au toucher sur mobile */
}

html, body {
    height: 100%;
    overflow: hidden; /* Empêche le scroll global */
}

body {
    font-family: 'Arial', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #a5d6a7; /* Vert plus soutenu */
    color: #333;
    font-size: 16px; /* Base pour rem/em */
}

#game-wrapper {
    width: 100%;
    max-width: 450px; /* Légèrement plus large */
    height: 100%;
    max-height: 700px;
    background-color: #ffffff;
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
    display: flex;
    position: relative;
    overflow: hidden;
}

/* Gestion des Écrans */
.screen {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    display: flex; /* Utilise flex pour centrer */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 15px; /* Plus de padding horizontal */
    text-align: center;
    background-color: #fff;
    opacity: 0;
    visibility: hidden; /* Masque complètement quand inactif */
    transition: opacity 0.4s ease-in-out, visibility 0.4s;
    overflow-y: auto; /* Permet le scroll si contenu dépasse (écran fin) */
}

.screen.active {
    opacity: 1;
    visibility: visible; /* Rend visible */
    z-index: 1;
}

/* --- Écran de Démarrage --- */
#start-screen h1 {
    color: #388e3c; /* Vert plus foncé */
    margin-bottom: 1em;
    font-size: 2.2em;
    font-weight: bold;
}
#start-screen p#instructions {
    margin-bottom: 1.8em;
    line-height: 1.6;
    color: #444;
    max-width: 95%;
    font-size: 1em;
}
/* Cache/Affiche instructions spécifiques desktop/mobile */
.mobile-only { display: none; }
.desktop-only { display: block; }
@media (hover: none) and (pointer: coarse) { /* Détecte les écrans tactiles */
  .mobile-only { display: block; }
  .desktop-only { display: none; }
}

.links-start, .links-end {
    margin-top: 1.5em;
    display: flex;
    flex-direction: column; /* Empile les liens sur mobile */
    gap: 10px; /* Espace entre les boutons */
    align-items: center;
}
@media (min-width: 380px) { /* Côte à côte sur écrans un peu plus larges */
     .links-start, .links-end { flex-direction: row; justify-content: center;}
}


/* --- Zone de Jeu --- */
#game-container {
    background-color: #bbdefb; /* Bleu plus clair */
    justify-content: flex-start;
    position: relative;
    cursor: none;
    touch-action: none; /* Empêche scroll/zoom pendant jeu tactile */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    overflow: hidden; /* Empêche le contenu de déborder */
}

#hud {
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0.6em 1em;
    background-color: rgba(255, 255, 255, 0.6); /* Fond blanc semi-transparent */
    font-weight: bold;
    color: #1565c0; /* Bleu foncé */
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10;
    border-bottom: 1px solid rgba(0,0,0,0.1);
}
#score-board, #timer { font-size: 1.1em; }

#player {
    position: absolute;
    width: 55px; /* Taille panier */
    height: 45px;
    bottom: 10px; /* Un peu plus bas */
    left: 50%;
    transform: translateX(-50%);
    font-size: 40px; /* Taille emoji panier */
    text-align: center;
    line-height: 45px;
    z-index: 5;
    /* Transition enlevée pour réactivité max sur mobile */
}

.item {
    position: absolute;
    width: 40px; /* Taille items */
    height: 40px;
    font-size: 35px;
    text-align: center;
    line-height: 40px;
    z-index: 2;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), /* Effet rebond */
                opacity 0.2s ease-out;
}
.item.caught {
    transform: scale(0);
    opacity: 0;
}
.item.penalty {
    animation: shake 0.3s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px) rotate(-5deg); }
  75% { transform: translateX(6px) rotate(5deg); }
}

#feedback {
    position: absolute;
    bottom: 70px; /* Au-dessus panier */
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.8em; /* Plus gros */
    font-weight: bold;
    color: #4caf50; /* Vert */
    text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
    opacity: 0;
    transition: opacity 0.6s ease-out, bottom 0.6s ease-out;
    z-index: 6;
    pointer-events: none; /* N'interfère pas avec le toucher */
}
#feedback.bad { color: #e53935; /* Rouge plus vif */ }
#feedback.show { opacity: 1; bottom: 90px; }


/* --- Écran de Fin --- */
#game-over-screen h2 {
    color: #f57c00; /* Orange plus soutenu */
    margin-bottom: 0.5em;
    font-size: 2em;
}
#final-message { font-size: 1.2em; margin-bottom: 0.2em; color: #555;}
#final-score-display {
    font-size: 3.5em;
    font-weight: bold;
    color: #00796b; /* Vert foncé */
    margin-bottom: 0.5em;
}
.reward-message {
    font-style: italic;
    color: #444;
    margin-bottom: 1.5em;
    font-size: 1.1em;
}

#leaderboard-section {
    width: 95%;
    max-width: 380px;
    margin-bottom: 1.5em;
    padding-top: 1em;
    border-top: 1px solid #eee;
}
#leaderboard-section h3 {
    margin-bottom: 0.8em;
    color: #1e88e5; /* Bleu plus vif */
    font-size: 1.4em;
}
.input-group {
    display: flex;
    flex-wrap: wrap; /* Pour petits écrans */
    justify-content: center;
    align-items: center;
    margin-bottom: 1em;
    gap: 8px;
}
.input-group label { font-size: 0.95em; margin-right: 5px; }
#player-name {
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 0.95em;
    flex-grow: 1;
    max-width: 180px;
    text-align: center;
}
#leaderboard {
    width: 100%;
    border-collapse: collapse;
    font-size: 1em;
    margin: 0 auto; /* Centrer le tableau */
}
#leaderboard th, #leaderboard td {
    border: 1px solid #e0e0e0;
    padding: 8px 10px;
    text-align: left;
}
#leaderboard th { background-color: #f5f5f5; color: #555; font-weight: bold;}
#leaderboard tr:nth-child(even) { background-color: #fafafa; }
#leaderboard td:first-child, #leaderboard th:first-child { width: 15%; text-align: center;} /* Rang */
#leaderboard td:last-child, #leaderboard th:last-child { width: 30%; text-align: right; font-weight: bold; } /* Score */


/* --- Boutons Généraux --- */
.btn {
    padding: 0.8em 1.8em; /* Utilise em pour s'adapter à la font-size */
    font-size: 1em;
    border: none;
    border-radius: 50px; /* Très arrondi */
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
    font-weight: bold;
    text-decoration: none;
    display: inline-block;
    background-color: #ddd; /* Fallback */
    color: #333;
    box-shadow: 0 3px 6px rgba(0,0,0,0.1);
    -webkit-appearance: none; /* Style iOS */
    -moz-appearance: none;
    appearance: none;
}
.btn:hover { filter: brightness(95%); }
.btn:active {
     transform: translateY(1px);
     box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.btn-start { background-color: #66bb6a; color: white; font-size: 1.1em; } /* Vert clair */
.btn-restart { background-color: #ffa726; color: white; } /* Orange clair */
.btn-save {
    background-color: #42a5f5; /* Bleu clair */
    color: white;
    padding: 0.6em 1em; /* Plus petit */
    font-size: 0.9em;
    border-radius: 5px;
}
.btn-save:disabled { background-color: #bdbdbd; cursor: not-allowed; box-shadow: none;}

.btn-link {
    background-color: #f5f5f5;
    color: #555;
    font-size: 0.9em;
    padding: 0.6em 1.2em;
    box-shadow: none;
    border: 1px solid #ccc;
}
.btn-link:hover { background-color: #e0e0e0;}
.btn-shop { border-color: #388e3c; color: #388e3c; }

/* Responsive fin */
@media (max-height: 600px) { /* Pour écrans courts */
    #start-screen h1, #game-over-screen h2 { font-size: 1.8em; }
    #final-score-display { font-size: 3em; }
    .btn { padding: 0.7em 1.5em; }
    #player { width: 50px; height: 40px; font-size: 35px; }
    .item { width: 35px; height: 35px; font-size: 30px; }
}