:root {
    /* Valor per defecte, es canviarà per JS */
    --num-problemes: 6; 
}

body {
    background-color: #050505;
    color: #ff00ff;
    font-family: 'Press Start 2P', cursive;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    margin: 0;
    background: radial-gradient(circle at center, #1a0826 0%, #050505 100%);
    min-height: 100vh;
}

#timer-header {
    background: rgba(0, 255, 255, 0.05);
    border: 2px solid #00ffff;
    box-shadow: 0 0 15px #00ffff;
    padding: 15px 40px;
    border-radius: 50px;
    margin-bottom: 40px;
    text-align: center;
    position: sticky;
    top: 10px;
    z-index: 100;
    backdrop-filter: blur(5px);
}

#game-clock {
    font-family: 'Orbitron', sans-serif;
    font-size: 2.5rem;
    color: #00ffff;
    text-shadow: 0 0 10px #00ffff;
}

#alumnes-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    /* Càlcul: Espai nom (300) + Globus (N * 55) + Gaps (N * 10) + Marges (60) */
    width: calc(300px + (var(--num-problemes) * 65px) + 60px);
    min-height: 85px; /* Una mica més d'alçada per estar còmodes amb 2 línies */
    align-items: center;
    max-width: 1200px; /* Augmentem el límit per a 12 problemes */
}

.alumne-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(0, 255, 255, 0.2);
    min-height: 80px; /* Alçada mínima fixa per mantenir la simetria */
    padding: 15px 25px;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 30px; /* Espai entre el nom i els globus */
    /* CÀLCUL DINÀMIC: 
       300px (nom) + (N * 55px mida globus) + (N * 10px gap) + padding lateral */
    width: calc(220px + (var(--num-problemes) * 65px) + 110px);
    max-width: 95vw; /* Seguretat per a pantalles petites */
    
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease;
}

.alumne-card:hover {
    border-color: #00ffff;
    transform: scale(1.02);
}

.info-alumne {
    display: flex;
    align-items: center;
    gap: 20px;
    /* RESERVEM UN ESPAI FIX PER AL NOM I POSICIÓ */
    flex: 0 0 220px; 
    border-right: 2px solid rgba(0, 255, 255, 0.1);
    margin-right: 20px;
    height: 60px; /* Alçada fixa per alinear bé amb els globus */
}

.posicio {
    font-size: 1.5rem;
    color: #00ffff;
    width: 50px;
    font-family: 'Orbitron', sans-serif;
    border-right: 1px solid rgba(0, 255, 255, 0.2);
    flex-shrink: 0;
}

.alias {
    font-size: 1rem;
    color: #fff;
    text-transform: uppercase;
    font-weight: bold;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;  
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.1; /* Interlineat estret per no augmentar l'alçada de la card */
    max-height: 2.2em; /* Limitem l'alçada a exactament 2 línies */
    word-break: break-word; /* Trenca paraules llargues si cal */
    flex: 1; /* Ocupa l'espai disponible */
}

.problemes {
    display: flex;
    gap: 12px; /* Reduïm l'espai entre cercles */
    flex-wrap: wrap; /* Important per evitar desbordaments */
    align-items: center;
}

.problema {
    /* Un gris fosc però que destaca sobre el fons negre */
    background: rgba(255, 255, 255, 0.08) !important; 
    
    /* Una vora dashed una mica més brillant */
    border: 2px dashed rgba(0, 255, 255, 0.3) !important;
    width: 60px;
    height: 60px;
    flex: 0 0 55px; /* No permetem que s'encongeixin ni creixin */
    /*border: 2px dashed rgba(255, 0, 255, 0.2);*/
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

/* Número de guia tènue */
.num-guia {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.1rem;
    color: rgba(0, 255, 255, 0.2);
    z-index: 1;
    pointer-events: none;
}

/* Ocultar número quan hi ha globus */
.problema.te-globus .num-guia {
    display: none;
}

.problema.te-globus {
    border: none;
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.2));
}

/* ANIMACIÓ GLOBUS VOLANT (Només nous) */
@keyframes balloonFly {
    0% { transform: translateY(100px) scale(0); opacity: 0; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

.nou-globus img {
    animation: balloonFly 0.8s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
}

.problema img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    z-index: 5;
}

.centered {
    position: absolute;
    top: 42%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 16px;
    color: #fff;
    font-family: 'Orbitron', sans-serif;
    font-weight: bold;
    text-shadow: 0px 0px 4px #000, 2px 2px 2px #000;
    z-index: 10;
    pointer-events: none;
}
/* Animació per fer marxar els globus al final */
.balloons-away img {
    transition: transform 2s cubic-bezier(0.4, 0, 1, 1), opacity 1s !important;
    transform: translateY(-1000px) scale(0.5) !important;
    opacity: 0 !important;
}

/* Pantalla de Pòdium (Finestra emergent) */
#podium-overlay {
    display: none; /* Amagat per defecte */
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95); /* Fons negre opac per tapar el rànquing */
    z-index: 9999; /* Per sobre de tot */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-family: 'Press Start 2P', cursive;
    backdrop-filter: blur(10px); /* Efecte de desenfocament del fons */
}

.podium-title {
    color: #ff00ff;
    font-size: 2.5rem;
    text-shadow: 0 0 20px #ff00ff, 0 0 40px #00ffff;
    margin-bottom: 35px;
    text-align: center;
    line-height: 1.5;
}

.podium-container {
    display: flex;
    align-items: flex-end;
    gap: 20px;
    padding-bottom: 50px;
}

.podium-spot {
    background: linear-gradient(to top, #1a0826, #000);
    border: 4px solid #00ffff;
    width: 180px;
    padding: 10px 20px 100px;
    text-align: center;
    border-radius: 15px 15px 0 0;
    position: relative;
}

/* Contenidor de globus dins del pòdium */
.podium-balloons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 5px;
    margin-top: 15px;
}

.podium-balloons img {
    width: 30px !important; /* Mida petita per al pòdium */
    height: 30px !important;
    transform: none !important; /* Evitem que heretin l'animació de fugida */
    opacity: 1 !important;
}
/* Estat inicial dels globus al pòdium (pre-animació) */
.podium-balloons .problema img {
    width: 35px !important;
    height: 35px !important;
    opacity: 0 !important;
    transform: scale(0) !important; /* Comencen a mida zero */
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s !important;
}

/* Quan afegim aquesta classe, faran el "pop" */
.podium-balloons .problema img.pop-in {
    opacity: 1 !important;
    transform: scale(1) !important;
}

/* Amaguem el número de minuts i el cercle dashed al pòdium per estètica */
.podium-balloons .centered { display: none !important; }
.podium-balloons .problema { 
    border: none !important; 
    background: rgba(255, 255, 255, 0.12) !important;
    }
/* Alçades dels graons */
.spot-1 { height: 400px; border-color: #ffd700; box-shadow: 0 0 30px rgba(255, 215, 0, 0.4); }
.spot-2 { height: 320px; border-color: #c0c0c0; }
.spot-3 { height: 260px; border-color: #cd7f32; }

.winner-name {
    font-family: 'Orbitron', sans-serif;
    color: #fff;
    margin-top: 20px;
    word-wrap: break-word;
}

.winner-time {
    font-family: 'Orbitron', sans-serif;
    color: #00ffff;
    font-size: 0.6rem;
    margin-top: 5px;
    text-shadow: 0 0 5px #00ffff;
}
body.light-mode {
    background: radial-gradient(circle at center, #f0f0f0 0%, #dcdcdc 100%);
    color: #333;
}
body.light-mode .alumne-card {
    background: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.2);
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
body.light-mode .alias { color: #222; }
body.light-mode #timer-header { background: white; border-color: #333; box-shadow: 0 4px 10px rgba(0,0,0,0.1); }
body.light-mode #game-clock { color: #333; text-shadow: none; }
/* Fons de l'overlay del pòdium */
body.light-mode #podium-overlay {
    background: rgba(240, 240, 240, 0.95); /* Blanc semi-transparent */
    backdrop-filter: blur(10px);
}

/* Les targetes (graons) dels guanyadors */
body.light-mode .podium-spot {
    background: white;
    border: 2px solid #ddd;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

/* Textos dins del pòdium */
body.light-mode .winner-name {
    color: #222;
}

body.light-mode .podium-spot h2 { /* Si tens títols com "1r Lloc" */
    color: #444;
}

/* Ajust dels cercles on van els globus al pòdium */
body.light-mode .podium-balloons .problema {
    background: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.1);
}
body.light-mode #theme-toggle {
    background: #eee;
    color: #333;
    border: 1px solid #ccc;
}
body.light-mode #podium-overlay {
    background: rgba(235, 235, 235, 0.98) !important;
}
body.light-mode .podium-spot {
    background: #ffffff !important;
    border: 2px solid #cccccc !important;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1) !important;
}

body.light-mode .winner-name {
    color: #111111 !important; /* Nom ben fosc */
}

body.light-mode .podium-spot div {
    color: #444444 !important; /* Per als textos de #1, #2, #3 */
}
/* Cercles buits al pòdium en mode clar */
body.light-mode .podium-balloons .problema {
    background: rgba(0, 0, 0, 0.07) !important; /* Gris suau de fons */
    border-color: rgba(0, 0, 0, 0.2) !important; /* Vora dashed visible */
}

/* El número interior (els minuts) */
body.light-mode .podium-balloons .centered {
    color: #222222 !important; /* Negre/Gris molt fosc */
    text-shadow: none !important; /* Eliminem la brillantor neó que no deixa llegir */
    font-weight: bold !important;
}
body.light-mode .problema {
    background: rgba(0, 0, 0, 0.08) !important; /* Gris suau de fons */
    border-color: rgba(0, 0, 0, 0.25) !important; /* Vora dashed més marcada */
}

/* El text del número (els minuts) */
body.light-mode .centered {
    color: #1a1a1a !important;      /* Negre quasi pur per a màxim contrast */
    text-shadow: none !important;    /* Fora ombres de neó */
    font-weight: 700 !important;     /* Una mica més de gruix per llegibilitat */
}

/* Números de guia (identificadors a la cantonada si en fas servir) */
body.light-mode .num-guia {
    color: rgba(0, 0, 0, 0.5) !important;
}
/* Número de posició (#1, #2, etc.) al rànquing en mode clar */
body.light-mode .posicio {
    color: #1a1a1a !important;      /* Negre intens o gris molt fosc */
    text-shadow: none !important;    /* Eliminem la brillantor que el difumina */
    font-weight: 800 !important;     /* Una mica més de gruix perquè destaqui */
    opacity: 1 !important;           /* Assegurem que no tingui transparències */
}

/* Si el número està dins d'un cercle o una etiqueta específica */
body.light-mode .posicio-container {
    background: rgba(0, 0, 0, 0.05); /* Un fons suau si vols emmarcar-lo */
    border-radius: 50%;
}
/* Títol principal del pòdium en mode clar */
body.light-mode #podium-overlay h1, 
body.light-mode .podium-title {
    color: #1a1a1a !important;        /* Negre quasi pur */
    text-shadow: 2px 2px 0px rgba(0,0,0,0.05) !important; /* Ombra molt subtil, no neó */
    letter-spacing: 2px;              /* Manté l'estètica de títol */
    text-transform: uppercase;
}

/* Si tens un subtítol o text addicional al pòdium */
body.light-mode #podium-overlay p {
    color: #444444 !important;
}