/**
 * CAN Clicker Game - Styles v3
 * Design "Flag-Trail" : Drapeau en haut, trainee coloree en bas
 * Extraction automatique de la couleur via Canvas
 */

/* ============================================= */
/* VARIABLES CSS                                 */
/* ============================================= */
:root {
    /* Couleurs principales */
    --color-primary: #ffd700;
    --color-secondary: #ff6b35;
    --color-success: #00d26a;
    --color-danger: #ff4757;
    --color-dark: #1a1a2e;
    --color-darker: #0f0f1a;
    --color-light: #ffffff;

    /* Backgrounds dynamiques */
    --bg-stadium: linear-gradient(180deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    --bg-sky: linear-gradient(180deg, #0f3460 0%, #1e5f74 50%, #5aa9e6 100%);
    --bg-space: linear-gradient(180deg, #0d1b2a 0%, #1b263b 50%, #415a77 100%);
    --bg-moon: linear-gradient(180deg, #000000 0%, #1a1a2e 30%, #2d2d44 60%, #4a4a6a 100%);

    /* Effet neon match en direct */
    --neon-green: #00ff88;
    --neon-glow: 0 0 10px var(--neon-green), 0 0 20px var(--neon-green), 0 0 40px var(--neon-green);

    /* Typographie */
    --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-display: 'Impact', 'Arial Black', sans-serif;

    /* Dimensions */
    --header-height: 50px;
    --bar-width: 60px;
    --bar-gap: 8px;
    --bar-min-height: 80px;
    --flag-height: 40px;
    --drop-size: 44px;
    --ground-height: 20px;
    --bar-radius: 12px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-camera: 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ============================================= */
/* RESET & BASE                                  */
/* ============================================= */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
    touch-action: pan-x;
}

body {
    font-family: var(--font-main);
    background: var(--bg-stadium);
    color: var(--color-light);
    transition: background 1s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* Backgrounds dynamiques */
body[data-background="stadium"] { background: var(--bg-stadium); }
body[data-background="sky"] { background: var(--bg-sky); }
body[data-background="space"] { background: var(--bg-space); }
body[data-background="moon"] { background: var(--bg-moon); }

/* Etoiles pour space/moon */
body[data-background="space"]::before,
body[data-background="moon"]::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
        radial-gradient(2px 2px at 20px 30px, white, transparent),
        radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.8), transparent),
        radial-gradient(1px 1px at 90px 40px, white, transparent),
        radial-gradient(2px 2px at 160px 120px, rgba(255,255,255,0.9), transparent);
    background-size: 200px 150px;
    animation: twinkle 3s ease-in-out infinite alternate;
    pointer-events: none;
    z-index: 0;
}

@keyframes twinkle {
    0% { opacity: 0.4; }
    100% { opacity: 1; }
}

body[data-background="moon"]::after {
    content: '🌙';
    position: fixed;
    top: 80px;
    right: 20px;
    font-size: 60px;
    opacity: 0.7;
    animation: float 5s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

.hidden { display: none !important; }

/* ============================================= */
/* ECRAN DE CHARGEMENT                          */
/* ============================================= */
#loading-screen {
    position: fixed;
    inset: 0;
    background: var(--color-darker);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

#loading-screen.fade-out {
    opacity: 0;
    visibility: hidden;
}

.loading-content {
    text-align: center;
}

.loading-trophy {
    font-size: 70px;
    animation: bounce 0.8s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

.loading-content h1 {
    font-family: var(--font-display);
    font-size: 2rem;
    color: var(--color-primary);
    margin: 15px 0 8px;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
}

.loading-content p {
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.loading-bar {
    width: 180px;
    height: 5px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
    margin: 0 auto;
}

.loading-progress {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), var(--color-secondary));
    border-radius: 3px;
    animation: loading 1.5s ease-in-out forwards;
}

@keyframes loading {
    0% { width: 0%; }
    50% { width: 70%; }
    100% { width: 100%; }
}

/* ============================================= */
/* HEADER                                        */
/* ============================================= */
#header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    z-index: 100;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo { font-size: 24px; }

.title {
    font-family: var(--font-display);
    font-size: 1rem;
    color: var(--color-primary);
    letter-spacing: 1px;
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.live-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    font-size: 0.75rem;
}

.live-indicator.active {
    background: rgba(0, 255, 136, 0.2);
}

.live-dot {
    width: 6px;
    height: 6px;
    background: #666;
    border-radius: 50%;
}

.live-indicator.active .live-dot {
    background: var(--neon-green);
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.3); }
}

.header-right { display: flex; align-items: center; }

.users-count {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    font-size: 0.8rem;
}

/* ============================================= */
/* MONDE DU JEU                                  */
/* ============================================= */
#world-viewport {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    overflow-x: auto;
    overflow-y: hidden;
    z-index: 1;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.3) transparent;
}

#world-viewport::-webkit-scrollbar {
    height: 6px;
}

#world-viewport::-webkit-scrollbar-track {
    background: transparent;
}

#world-viewport::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

#world-container {
    position: relative;
    min-width: max-content;
    height: 100%;
    transform: translateY(0);
    transition: transform var(--transition-camera);
    will-change: transform;
}

#ground {
    position: absolute;
    bottom: var(--ground-height);
    left: 0;
    display: flex;
    align-items: flex-end;
    gap: var(--bar-gap);
    padding: 0 20px;
    min-height: 100px;
}

/* Ligne de sol visuelle */
#ground::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg,
        transparent,
        rgba(255,255,255,0.2) 10%,
        rgba(255,255,255,0.2) 90%,
        transparent
    );
}

/* ============================================= */
/* BARRES DES EQUIPES - DESIGN FLAG-TRAIL       */
/* ============================================= */
.team-bar {
    width: var(--bar-width);
    min-height: var(--bar-min-height);
    position: relative;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    transition: height 0.25s ease-out;
    transform-origin: bottom center;
    -webkit-touch-callout: none;
    /* Couleur de trainee par defaut (sera surchargee par JS) */
    --trail-color: #333333;
    /* Pas de padding/margin pour alignement parfait */
    padding: 0;
    margin: 0;
}

/* Conteneur principal avec bords arrondis - PILULE */
.bar-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    /* Bords arrondis uniquement sur le conteneur parent */
    border-radius: var(--bar-radius) var(--bar-radius) 0 0;
    /* CRITIQUE: overflow hidden pour que les enfants ne debordent pas */
    overflow: hidden;
    /* Pas de padding interne */
    padding: 0;
    margin: 0;
    /* Ombre portee subtile */
    box-shadow:
        0 4px 15px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* Partie superieure : Le Drapeau (flag-top) */
.bar-flag-section {
    /* Largeur 100% identique a la trainee */
    width: 100%;
    height: var(--flag-height);
    flex-shrink: 0;
    position: relative;
    /* Pas de padding/margin pour alignement parfait avec la trainee */
    padding: 0;
    margin: 0;
    /* Pas de bordure qui pourrait creer un decalage */
    border: none;
    /* Le drapeau remplit tout l'espace */
    overflow: hidden;
}

/* Image du drapeau - display block pour eviter marges fantomes */
.bar-flag-img {
    /* Occupe exactement 100% du conteneur parent */
    width: 100%;
    height: 100%;
    /* Cover pour remplir sans deformation */
    object-fit: cover;
    object-position: center;
    /* CRITIQUE: display block pour eviter l'espace sous l'image */
    display: block;
    /* Pas de bordures/marges */
    border: none;
    padding: 0;
    margin: 0;
    /* Pas de border-radius ici, gere par le parent */
    border-radius: 0;
}

/* Partie inferieure : La Trainee (flag-bottom) - gradient = derniere ligne du drapeau */
.bar-trail-section {
    /* Largeur 100% identique au drapeau */
    width: 100%;
    flex: 1;
    /* Gradient horizontal genere par JS */
    background: var(--trail-color);
    /* S'assurer que le gradient s'etire sur toute la largeur */
    background-size: 100% 100%;
    background-repeat: no-repeat;
    position: relative;
    min-height: 20px;
    /* Pas de padding/margin pour alignement parfait */
    padding: 0;
    margin: 0;
    border: none;
    /* Pas de border-radius ici, gere par le parent */
    border-radius: 0;
}

/* Effet glossy global sur toute la barre */
.bar-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    border-radius: var(--bar-radius) var(--bar-radius) 0 0;
    background: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.35) 0%,
        rgba(255, 255, 255, 0.15) 30%,
        rgba(255, 255, 255, 0.05) 50%,
        transparent 100%
    );
    pointer-events: none;
    z-index: 5;
}

/* Reflet lateral pour effet 3D */
.bar-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 30%;
    border-radius: var(--bar-radius) 0 0 0;
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.1) 0%,
        transparent 100%
    );
    pointer-events: none;
    z-index: 4;
}

/* Hover effect */
.team-bar:hover .bar-container {
    filter: brightness(1.15);
    box-shadow:
        0 6px 20px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* Click effect */
.team-bar:active .bar-container {
    transform: scaleY(0.97);
}

.team-bar.clicking .bar-container {
    animation: barClick 0.15s ease-out;
}

@keyframes barClick {
    0% { transform: scaleY(1); }
    50% { transform: scaleY(0.95); }
    100% { transform: scaleY(1); }
}

/* Match en direct */
.team-bar.live-match .bar-container {
    box-shadow:
        0 0 20px var(--neon-green),
        0 0 40px rgba(0, 255, 136, 0.3),
        inset 0 0 15px rgba(0, 255, 136, 0.1);
    border: 2px solid var(--neon-green);
}

.team-bar.live-match {
    animation: neonPulse 1.5s ease-in-out infinite;
}

@keyframes neonPulse {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.2); }
}

/* ============================================= */
/* LABEL AU-DESSUS DE LA BARRE                  */
/* ============================================= */
.bar-label {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 8px;
    pointer-events: none;
    z-index: 10;
}

.bar-flag {
    font-size: 22px;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5));
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bar-flag .flag-img {
    width: 28px;
    height: 20px;
    object-fit: cover;
    border-radius: 2px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.bar-score {
    font-weight: bold;
    font-size: 1rem;
    color: var(--color-light);
    text-shadow:
        0 2px 4px rgba(0, 0, 0, 0.9),
        0 0 10px rgba(0, 0, 0, 0.5);
    background: rgba(0, 0, 0, 0.7);
    padding: 4px 10px;
    border-radius: 10px;
    white-space: nowrap;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.bar-name {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.8);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

/* ============================================= */
/* UI FIXE (OVERLAY)                            */
/* ============================================= */
#game-ui {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 50;
}

/* ============================================= */
/* CONTENEUR DES GOUTTES                        */
/* ============================================= */
#drops-container {
    position: fixed;
    bottom: 15px;
    left: 0;
    right: 0;
    height: calc(var(--drop-size) + 20px);
    display: flex;
    align-items: flex-end;
    padding: 0 20px;
    gap: var(--bar-gap);
    pointer-events: none;
    z-index: 60;
    overflow: visible;
}

/* ============================================= */
/* GOUTTE (pays hors ecran)                     */
/* ============================================= */
.team-drop {
    width: var(--drop-size);
    height: var(--drop-size);
    flex-shrink: 0;
    position: relative;
    pointer-events: auto;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
}

.team-drop.visible {
    opacity: 1;
    visibility: visible;
}

/* Forme de goutte inversee */
.team-drop::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.team-drop:hover::before {
    border-color: var(--color-primary);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.4);
}

.team-drop:active {
    transform: scale(0.9);
}

/* Drapeau dans la goutte */
.drop-flag {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(0deg);
    font-size: 18px;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drop-flag .flag-img {
    width: 22px;
    height: 16px;
    object-fit: cover;
    border-radius: 2px;
}

/* Score sous la goutte */
.drop-score {
    position: absolute;
    bottom: -16px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.6rem;
    color: rgba(255,255,255,0.6);
    background: rgba(0,0,0,0.5);
    padding: 1px 4px;
    border-radius: 6px;
    white-space: nowrap;
}

/* Gouttes visibles - pas d'animation pour éviter les vibrations */

/* Goutte match en direct */
.team-drop.live-match::before {
    border-color: var(--neon-green);
    box-shadow: 0 0 10px var(--neon-green);
}

/* ============================================= */
/* INDICATEUR DU LEADER                         */
/* ============================================= */
#leader-indicator {
    position: fixed;
    top: calc(var(--header-height) + 10px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    padding: 10px 20px;
    border-radius: 20px;
    border: 1px solid rgba(255, 215, 0, 0.3);
    pointer-events: auto;
    z-index: 70;
}

.leader-main {
    display: flex;
    align-items: center;
    gap: 8px;
}

.leader-crown {
    font-size: 20px;
    /* Pas d'animation pour éviter les vibrations */
}

#leader-name {
    font-weight: bold;
    font-size: 0.9rem;
    color: var(--color-primary);
}

#leader-score {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.8);
}

/* Sous-titre "Qui va gagner la CAN !" */
.leader-subtitle {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.6);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 2px;
}

/* ============================================= */
/* EFFETS DE CLIC (+1)                          */
/* ============================================= */
#click-effects {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 200;
    overflow: hidden;
}

.click-effect {
    position: absolute;
    font-weight: bold;
    font-size: 1.4rem;
    color: var(--color-success);
    text-shadow: 0 0 8px var(--color-success), 0 2px 4px rgba(0,0,0,0.5);
    animation: floatUp 0.7s ease-out forwards;
    pointer-events: none;
    white-space: nowrap;
}

.click-effect.combo {
    font-size: 1.8rem;
    color: var(--color-secondary);
    text-shadow: 0 0 12px var(--color-secondary), 0 0 25px var(--color-primary);
}

@keyframes floatUp {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-60px) scale(0.6);
    }
}

/* ============================================= */
/* TOAST NOTIFICATIONS                          */
/* ============================================= */
#toast-container {
    position: fixed;
    top: calc(var(--header-height) + 100px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 0.85rem;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
    white-space: nowrap;
}

.toast.error { background: rgba(255, 71, 87, 0.9); }
.toast.success { background: rgba(0, 210, 106, 0.9); }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-15px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ============================================= */
/* COMBO OVERLAY                                 */
/* ============================================= */
#combo-overlay {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 250;
    pointer-events: none;
}

#combo-overlay:not(.hidden) {
    animation: comboPopIn 0.2s ease;
}

.combo-text {
    font-family: var(--font-display);
    font-size: 2.5rem;
    color: var(--color-secondary);
    text-shadow:
        0 0 15px var(--color-secondary),
        0 0 30px var(--color-primary);
    animation: comboPulse 0.4s ease-in-out infinite;
}

@keyframes comboPopIn {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes comboPulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.08); }
}

/* ============================================= */
/* RESPONSIVE - TABLETTES                        */
/* ============================================= */
@media (min-width: 768px) {
    :root {
        --bar-width: 70px;
        --bar-gap: 12px;
        --drop-size: 50px;
        --header-height: 55px;
        --flag-height: 46px;
        --bar-radius: 14px;
    }

    .title { font-size: 1.2rem; }
    .bar-score { font-size: 1rem; padding: 5px 12px; }

    #leader-indicator {
        padding: 12px 24px;
    }

    .combo-text { font-size: 3rem; }
}

/* ============================================= */
/* RESPONSIVE - DESKTOP                          */
/* ============================================= */
@media (min-width: 1024px) {
    :root {
        --bar-width: 80px;
        --bar-gap: 15px;
        --drop-size: 55px;
        --flag-height: 53px;
        --bar-radius: 16px;
    }

    .loading-trophy { font-size: 100px; }
    .loading-content h1 { font-size: 3rem; }

    .bar-score { font-size: 1.1rem; padding: 6px 14px; }
    .bar-name { font-size: 0.75rem; }

    .drop-flag { font-size: 22px; }
}

/* ============================================= */
/* TRES PETITS ECRANS                           */
/* ============================================= */
@media (max-width: 380px) {
    :root {
        --bar-width: 50px;
        --bar-gap: 6px;
        --drop-size: 38px;
        --header-height: 45px;
        --flag-height: 33px;
        --bar-radius: 10px;
    }

    .title { font-size: 0.85rem; }
    .live-indicator { display: none; }

    .bar-score { font-size: 0.75rem; padding: 3px 6px; }
    .bar-name { display: none; }

    #leader-indicator {
        padding: 8px 14px;
        font-size: 0.8rem;
    }

    .leader-subtitle { display: none; }

    .combo-text { font-size: 2rem; }
}

/* ============================================= */
/* PREFERENCE REDUCTION DES MOUVEMENTS          */
/* ============================================= */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
