/* Import de Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Fira+Code:wght@400;500&display=swap');

/* Variables CSS - Thème CTF moderne */
:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --secondary-color: #1f2937;
    --accent-color: #f59e0b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --background-color: #0f172a;
    --surface-color: #1e293b;
    --surface-hover: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --border-color: #374151;
    --border-hover: #4b5563;
    --shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 20px 45px -5px rgba(0, 0, 0, 0.4);
    --glow-primary: 0 0 20px rgba(99, 102, 241, 0.3);
    --glow-success: 0 0 20px rgba(16, 185, 129, 0.3);
}

/* Reset et styles de base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}


body {
    font-family: 'Inter', sans-serif;
    background: linear-gradient(135deg, var(--background-color) 0%, #1a202c 100%);
    color: var(--text-primary);

    /* >> Remplacement clé : utilise la vraie hauteur visible */
    height: var(--app-height, 100dvh);   /* fallback : 100dvh si JS off */
    min-height: var(--app-height, 100dvh);

    /* Évite le scroll pour ton app “plein écran” */
    overflow: clip; /* (ou hidden) */

    /* Protège le bas du contenu contre la barre système */
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + var(--bottom-inset, 0px));

    padding: 10px;
    line-height: 1.4;
    display: flex;
    flex-direction: column;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    touch-action: manipulation;
}

/* En-tête principal - compact */
h1 {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 5px;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    flex-shrink: 0;
}

/* Style pour la version dans le titre */
.version {
    font-size: 0.7em;
    font-weight: 400;
    margin-left: 0.3em;
}

/* Container principal - plein écran */
#questionContainer {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--surface-color);
    padding: 15px;
    border-radius: 15px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
    position: relative;
    margin: 5px;
    overflow: hidden;
    /* Amélioration pour mobile */
    min-height: 0;
    max-height: 100%;
}

/* Barre de progression - compacte */
#progressBar {
    width: 100%;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    margin-bottom: 10px;
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
}

#progressBar::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    animation: shimmer 3s infinite;
    z-index: 1;
}

#progressFill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    border-radius: 3px;
    width: 25%;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    box-shadow: var(--glow-primary);
    z-index: 2;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

#questionHeader {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.05), rgba(245, 158, 11, 0.05));
    border-radius: 8px;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
    margin-bottom: 10px;
    padding: 10px;

    display: flex;
    align-items: center;
    width: 100%;
    gap: 10px;
    margin-top: 8px;
}

/* 1er élément : aligné à droite */
#questionHeader > :nth-child(1) {
    text-align: right;
    flex: 0 0 auto;
}

/* 2ème élément : occupe l'espace restant et centré */
#questionHeader > :nth-child(2) {
    flex: 1 1 auto;
    text-align: center;
}

/* 3ème élément : aligné à gauche */
#questionHeader > :nth-child(3) {
    text-align: left;
    flex: 0 0 auto;
}

/* Optionnel si un bloc central spécifique */
#questionHeader .question-info { text-align: center; }

#questionNumber {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 5px;
    text-shadow: var(--glow-primary);
}

#questionText {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 400;
    margin: 0 0 10px 0;
}

/* Styles pour l'indice */
.hint-container {
    margin-top: 8px;
}

.hint-label {
    font-weight: 600;
    color: var(--accent-color);
    font-size: 0.9rem;
    margin-right: 8px;
}

#hintText {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-style: italic;
}

/* Styles pour les résultats de victoire */
#resultContainer h2 {
    transition: color 0.3s ease;
    text-align: center;
    margin-bottom: 20px;
}

#resultContainer p {
    text-align: center;
    line-height: 1.6;
    margin-bottom: 20px;
}

#resultContainer code {
    background: var(--surface-color);
    padding: 4px 8px;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
    font-size: 0.9rem;
    color: var(--accent-color);
    border: 1px solid var(--border-color);
}

/* Grille d'images - Plein écran */
#imagesGrid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 15px;
    flex: 1;
    width: 100%;
    min-height: 0;
}

/* Options d'images - maximisées */
.image-option {
    background: var(--background-color);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    padding: 0;
    cursor: pointer;
    transition: all 0.3s ease, background 0.4s ease, border-color 0.3s ease;
    text-align: center;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Indicateur de chargement */
.loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 10;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

.image-container {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Icône de zoom */
.zoom-icon {
    position: absolute;
    bottom: 12px;
    right: 12px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 21px;
    cursor: pointer;
    z-index: 15;
    transition: all 0.3s ease;
    opacity: 0.9;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.zoom-icon:hover {
    background: rgba(0, 0, 0, 0.9);
    opacity: 1;
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.image-option::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.5s;
}

/* Effet de survol avec couleur subtile */
.image-option:hover {
    border-color: var(--primary-color);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(99, 102, 241, 0.04));
    transition: all 0.3s ease;
}

/* Animation ::before de survol supprimée */

.image-option.selected {
    border-color: var(--success-color);
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(16, 185, 129, 0.08));
    box-shadow: var(--glow-success), var(--shadow);
}

/* Label d'option (A, B, C, D) - agrandi */
.option-label {
    position: absolute;
    top: 10px;
    left: 10px;
    background: var(--secondary-color);
    color: var(--text-primary);
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
    border: 2px solid var(--border-color);
    z-index: 1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.image-option.selected .option-label {
    background: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: var(--glow-primary);
}

.image-option.selected::after {
    content: '✓';
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--success-color);
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    z-index: 2;
}

.image-option img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
    transition: transform 0.3s ease, opacity 0.3s ease;
    display: block;
}

.image-option img.loading {
    opacity: 0;
}

.image-option img.loaded {
    opacity: 1;
}

/* Animation de survol des images supprimée */

/* Styles pour les paragraphes supprimés car plus utilisés */


button {
    font-family: 'Inter', sans-serif;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    /* Centrage du texte par défaut */
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

/* Bouton précédent */
#prevButton {
    background: var(--secondary-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

#prevButton:not(:disabled):hover {
    background: #374151;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

#prevButton:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Bouton suivant */
#nextButton {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

#nextButton:not(:disabled):hover {
    background: linear-gradient(135deg, var(--primary-dark), #3730a3);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4);
}

#nextButton:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Container des résultats - adapté */
#resultContainer {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: var(--surface-color);
    padding: 20px;
    border-radius: 15px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    text-align: center;
    margin: 5px;
}

#resultContainer h2 {
    font-size: 1.6rem;
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--success-color);
}

#resultContainer p {
    font-size: 1rem;
    margin-bottom: 15px;
    color: var(--text-secondary);
}

/* Affichage du flag - compact */
#flagDisplay {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-direction: column;
    align-items: center;
    margin: 20px 0;
    padding: 15px;
    background: var(--background-color);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

#flagInput {
    font-family: 'Fira Code', monospace;
    font-size: 1.4rem;
    font-weight: 500;
    background: transparent;
    border: none;
    color: var(--accent-color);
    text-align: center;
    width: 100%;
    letter-spacing: 2px;
    outline: none;
}

/* Bouton copier - spécificité renforcée pour éviter l'écrasement */
#flagDisplay button {
    background: linear-gradient(135deg, var(--success-color), #059669) !important;
    color: white !important;
    padding: 10px 20px;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

#flagDisplay button:hover {
    background: linear-gradient(135deg, #059669, #047857) !important;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

/* Boutons de fin - côte à côte */
#resultContainer button {
    margin: 10px 5px;
    padding: 12px 30px;
    font-size: 1rem;
    /* Sur desktop : largeur naturelle */
    flex: none;
    min-width: 140px;
}

/* Container pour aligner les boutons de fin */
#resultContainer {
    display: flex;
    flex-direction: column;
}

/* Wrapper pour les boutons de fin */
.result-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

#resultContainer button:first-of-type {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
}

#resultContainer button:last-of-type {
    background: var(--danger-color);
    color: white;
}

#resultContainer button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Animation supprimée pour éviter le clignotement des images */

/* Animation des caractères du flag */
@keyframes flagCharAppear {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.8) rotateX(90deg);
    }
    50% {
        opacity: 0.8;
        transform: translateY(-5px) scale(1.1) rotateX(0deg);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1) rotateX(0deg);
    }
}

@keyframes flagCharFloat {
    0%, 100% {
        transform: translateY(0) rotate(0deg);
    }
    25% {
        transform: translateY(-3px) rotate(1deg);
    }
    75% {
        transform: translateY(2px) rotate(-1deg);
    }
}

@keyframes flagCharGlow {
    0%, 100% {
        text-shadow: 0 0 5px var(--accent-color);
    }
    50% {
        text-shadow: 0 0 15px var(--accent-color), 0 0 25px var(--primary-color);
    }
}

/* Animation continue pour les caractères après l'apparition */
.flag-char {
    animation: flagCharAppear 0.4s ease-out both, 
               flagCharFloat 2s ease-in-out 0.5s infinite,
               flagCharGlow 1.5s ease-in-out 0.8s infinite;
    font-family: 'Fira Code', monospace;
    font-size: inherit;
    font-weight: inherit;
    color: inherit;
    line-height: 1;
    vertical-align: middle;
    white-space: nowrap;
    overflow: visible;
}

/* Conteneur du flag animé */
.flag-animated-container {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 0;
    font-family: 'Fira Code', monospace;
    font-size: 1.4rem;
    font-weight: 500;
    color: var(--accent-color);
    letter-spacing: 0;
    min-height: 2rem;
    padding: 10px;
    background: transparent;
    border: none;
    width: 100%;
    text-align: center;
    line-height: 1.2;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    transition: all 0.3s ease;
    border-radius: 8px;
}

.flag-animated-container:hover {
    background: rgba(99, 102, 241, 0.1);
    transform: scale(1.02);
}

.flag-animated-container:active {
    transform: scale(0.98);
    background: rgba(99, 102, 241, 0.2);
}

/* Animation de pulsation pour le flag (fallback) */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.8;
    }
}

#flagInput {
    animation: pulse 2s infinite;
}

/* Scrollbar personnalisée */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background-color);
}

::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* Toast notification */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: linear-gradient(135deg, var(--success-color), #059669);
    color: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4), 0 8px 32px rgba(0, 0, 0, 0.2);
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    font-size: 14px;
    z-index: 2000;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 300px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast.hide {
    opacity: 0;
    transform: translateX(100%);
}

.toast-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
}

/* Animation d'apparition du toast */
@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toastSlideOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* Responsive toast */
@media (max-width: 768px) {
    .toast {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
        font-size: 13px;
        padding: 12px 16px;
    }
}

/* Modal pour affichage d'image en plein écran */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    animation: fadeIn 0.3s ease-out;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    position: relative;
    max-width: 98vw;
    max-height: 98vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content img {
    max-width: 98vw;
    max-height: 98vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    transition: transform 0.3s ease;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.modal-content img:active {
    cursor: grabbing;
}

/* Styles pour le zoom */
.modal-content img.zoomed {
    cursor: grab;
    transform-origin: center;
}

.modal-content img.zoomed:active {
    cursor: grabbing;
}

/* Conteneur pour les contrôles de zoom */
.zoom-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
    z-index: 1002;
}

.zoom-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.zoom-btn:hover {
    background: rgba(0, 0, 0, 0.9);
    border-color: rgba(255, 255, 255, 0.6);
    transform: scale(1.1);
}

.zoom-btn:active {
    transform: scale(0.95);
}

.zoom-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Indicateur de zoom */
.zoom-indicator {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    z-index: 1002;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.zoom-indicator.show {
    opacity: 1;
}

.close-button {
    position: absolute;
    right: 10px;
    top: 10px;
    color: white;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.7);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 1003;
}

.close-button:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.modal-character-label {
    position: absolute;
    top: 10px;
    left: 10px;
    background: var(--primary-color);
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    box-shadow: var(--glow-primary);
    z-index: 1003;
}

/* ===============================================
   RESPONSIVE DESIGN - VERSION MOBILE
   =============================================== */

/* Tablettes et petits ordinateurs portables */
@media (max-width: 1024px) {
    body {
        padding: 8px;
    }
    
    h1 {
        font-size: 1.4rem;
        margin-bottom: 8px;
    }
    
    #questionContainer {
        padding: 12px;
        margin: 3px;
    }
    
    #imagesGrid {
        gap: 12px;
    }
    
    .option-label {
        width: 42px;
        height: 42px;
        font-size: 22px;
    }
    
    .zoom-icon {
        width: 38px;
        height: 38px;
        font-size: 19px;
    }
}

/* Smartphones et petites tablettes */
@media (max-width: 768px) {
    body {
        padding: 5px;
        font-size: 14px;
        line-height: 1.5;
        /* Utilisation de dvh pour exclure automatiquement les barres UI */
        height: 100dvh;
        /* Fallback pour navigateurs qui ne supportent pas dvh */
        height: calc(100vh - 60px);
    }
    
    h1 {
        font-size: 1.2rem;
        margin-bottom: 5px;
        line-height: 1.3;
    }
    
    #questionContainer {
        padding: 10px;
        border-radius: 12px;
        margin: 2px;
    }
    
    #progressBar {
        height: 6px;
        margin-bottom: 12px;
    }
    
    #questionHeader {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
        gap: 12px;
        padding: 12px;
        text-align: center;
        grid-template-areas:
            "question question"
            "prev next";
    }
    
    /* Question en haut sur mobile */
    .question-info {
        grid-area: question;
        margin-bottom: 8px;
    }
    
    /* Boutons côte à côte sur mobile */
    #prevButton {
        grid-area: prev;
    }
    
    #nextButton {
        grid-area: next;
    }
    
    #questionNumber {
        font-size: 1.1rem;
        margin-bottom: 3px;
    }
    
    #questionText {
        font-size: 0.9rem;
    }
    
    /* Boutons de navigation mobile - côte à côte */
    #prevButton, #nextButton {
        padding: 10px 8px;
        font-size: 0.8rem;
        min-height: 48px; /* Zone tactile recommandée */
        border-radius: 8px;
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        /* Centrage du texte */
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }
    
    /* Grille d'images adaptée pour mobile */
    #imagesGrid {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr 1fr;
        gap: 10px;
        padding: 5px;
    }
    
    .image-option {
        min-height: 120px; /* Hauteur minimum pour les petits écrans */
        border-radius: 8px;
        border-width: 2px;
    }
    
    .option-label {
        width: 36px;
        height: 36px;
        font-size: 18px;
        top: 8px;
        left: 8px;
        border-width: 2px;
    }
    
    .zoom-icon {
        width: 36px;
        height: 36px;
        font-size: 16px;
        bottom: 8px;
        right: 8px;
    }
    
    /* Container des résultats adapté */
    #resultContainer {
        padding: 15px;
        margin: 2px;
    }
    
    #resultContainer h2 {
        font-size: 1.4rem;
        margin-bottom: 12px;
    }
    
    #resultContainer p {
        font-size: 0.9rem;
        margin-bottom: 12px;
    }
    
    #flagDisplay {
        padding: 12px;
        margin: 15px 0;
    }
    
    #flagInput {
        font-size: 1.1rem;
        letter-spacing: 1px;
    }
    
    .flag-animated-container {
        font-size: 1.1rem;
        letter-spacing: 1px;
    }
    
    #flagDisplay button {
        padding: 12px 24px !important;
        font-size: 0.9rem !important;
        min-height: 48px;
    }
    
    #resultContainer button {
        margin: 0;
        padding: 12px 20px;
        font-size: 0.9rem;
        min-height: 48px;
        /* Sur mobile : prendre toute la largeur */
        flex: 1;
        min-width: auto;
    }
    
    .result-buttons {
        gap: 8px;
        margin-top: 15px;
    }
    
    /* Toast responsive pour mobile */
    .toast {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
        font-size: 13px;
        padding: 12px 16px;
        border-radius: 6px;
    }
    
    /* Modal responsive pour mobile */
    .modal {
        padding: 10px;
    }
    
    .close-button {
        top: 15px;
        right: 15px;
        width: 44px;
        height: 44px;
        font-size: 22px;
        z-index: 1003;
    }
    
    .modal-character-label {
        top: 15px;
        left: 15px;
        width: 44px;
        height: 44px;
        font-size: 20px;
        z-index: 1003;
    }
}

/* Très petits smartphones */
@media (max-width: 480px) {
    body {
        padding: 3px;
        font-size: 13px;
        /* dvh s'adapte automatiquement aux barres UI */
        height: 100dvh;
        /* Fallback pour navigateurs qui ne supportent pas dvh */
        height: calc(100vh - 80px);
    }
    
    h1 {
        font-size: 1.1rem;
        margin-bottom: 3px;
        padding: 0 5px;
    }
    
    #questionContainer {
        padding: 8px;
        border-radius: 10px;
    }
    
    #questionHeader {
        padding: 10px;
        gap: 6px;
    }
    
    #questionNumber {
        font-size: 1rem;
    }
    
    #questionText {
        font-size: 0.85rem;
    }
    
    #prevButton, #nextButton {
        padding: 8px 12px;
        font-size: 0.75rem;
        min-height: 44px;
        /* Centrage du texte */
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }
    
    /* Modal sur très petits écrans */
    .close-button {
        top: 10px;
        right: 10px;
        width: 36px;
        height: 36px;
        font-size: 18px;
        z-index: 1003;
    }
    
    .modal-character-label {
        top: 10px;
        left: 10px;
        width: 36px;
        height: 36px;
        font-size: 16px;
    }
    
    /* Grille simplifiée pour très petits écrans */
    #imagesGrid {
        gap: 8px;
        padding: 3px;
    }
    
    .image-option {
        min-height: 100px;
        border-radius: 6px;
    }
    
    .option-label {
        width: 32px;
        height: 32px;
        font-size: 16px;
        top: 6px;
        left: 6px;
    }
    
    .zoom-icon {
        width: 32px;
        height: 32px;
        font-size: 14px;
        bottom: 6px;
        right: 6px;
    }
    
    #resultContainer {
        padding: 12px;
    }
    
    #resultContainer h2 {
        font-size: 1.2rem;
        margin-bottom: 10px;
    }
    
    #flagInput {
        font-size: 1rem;
        letter-spacing: 0.5px;
    }
    
    .flag-animated-container {
        font-size: 1rem;
        letter-spacing: 0.5px;
    }
    
    #flagDisplay button {
        padding: 10px 20px !important;
        font-size: 0.8rem !important;
        min-height: 44px;
    }
    
    #resultContainer button {
        margin: 0;
        padding: 10px 16px;
        font-size: 0.8rem;
        min-height: 44px;
        /* Sur très petits écrans : prendre toute la largeur */
        flex: 1;
        min-width: auto;
    }
    
    .result-buttons {
        gap: 6px;
        margin-top: 12px;
    }
}


/* Mode paysage pour smartphones */
@media (max-width: 768px) and (orientation: landscape) {
    body {
        padding: 3px;
        /* En mode paysage, dvh s'adapte aux barres UI */
        height: 100dvh;
        height: calc(100vh - 40px); /* Fallback */
    }
    
    h1 {
        font-size: 1rem;
        margin-bottom: 2px;
    }
    
    #questionContainer {
        padding: 8px;
    }
    
    #questionHeader {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
        gap: 8px;
        padding: 8px 12px;
        grid-template-areas:
            "question question"
            "prev next";
    }
    
    .question-info {
        grid-area: question;
        margin-bottom: 4px;
    }
    
    #prevButton {
        grid-area: prev;
    }
    
    #nextButton {
        grid-area: next;
    }
    
    #questionNumber {
        font-size: 0.9rem;
        margin-bottom: 2px;
    }
    
    #questionText {
        font-size: 0.8rem;
    }
    
    #prevButton, #nextButton {
        padding: 6px 10px;
        font-size: 0.75rem;
        min-height: 40px;
        /* Centrage du texte */
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }
    
    #imagesGrid {
        gap: 6px;
    }
    
    .image-option {
        min-height: 80px;
    }
    
    .option-label {
        width: 28px;
        height: 28px;
        font-size: 14px;
        top: 5px;
        left: 5px;
    }
    
    .zoom-icon {
        width: 28px;
        height: 28px;
        font-size: 12px;
        bottom: 5px;
        right: 5px;
    }
}

/* Amélioration des zones tactiles pour tous les appareils tactiles */
@media (pointer: coarse) {
    button {
        min-height: 44px;
        min-width: 44px;
    }
    
    .image-option {
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(99, 102, 241, 0.2);
    }
    
    .zoom-icon {
        min-width: 36px;
        min-height: 36px;
    }
    
    .option-label {
        min-width: 36px;
        min-height: 36px;
    }
}

/* Mode sombre automatique si supporté */
@media (prefers-color-scheme: dark) {
    /* Les styles sont déjà sombres par défaut, donc rien à changer */
}

/* Réduction du mouvement pour les utilisateurs sensibles */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    #progressBar::after {
        animation: none;
    }
    
    #flagInput {
        animation: none;
    }
    
    .flag-char {
        animation: none !important;
    }
    
    .flag-animated-container {
        animation: none !important;
    }
}

/* S'assure que la modale ne déborde pas sous les barres système */
.modal-content {
    max-height: calc(var(--app-height, 100dvh) - 40px);
}

.fixed-bottom,
.swipe-hint,
.footer {
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + var(--bottom-inset, 0px));
}