/* ─── Variables ────────────────────────────────────────────────────────────── */
:root {
    --primary: #6b86ff;
    --secondary: #ecce22;
    --tertiary: #176d7c;
    --danger: #ff6868;
    --purple: #A78BFA;
    --card-bg: #ffffff;
    --text: #2D3748;
    --shadow: rgba(107, 134, 255, 0.2);
}

/* ─── Reset ────────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ─── Base ─────────────────────────────────────────────────────────────────── */
body {
    font-family: 'Fredoka', sans-serif;
    background-color: var(--primary);
    min-height: 100vh;
    padding: 2rem;
    overflow-x: hidden;
}

/* ─── Mise en page ─────────────────────────────────────────────────────────── */
.container {
    max-width: 1000px;
    margin: 0 auto;
}

/* ─── Titre ────────────────────────────────────────────────────────────────── */
h1 {
    font-family: 'Lilita One', cursive;
    font-size: clamp(2.5rem, 8vw, 4.5rem);
    text-align: center;
    margin-bottom: 1rem;
    color: var(--secondary);
    letter-spacing: 2px;
    animation: titleBounce 0.8s ease-out;
    user-select: none;
    /* Evite les problèmes avec background-clip sur certains navigateurs */
    background: var(--secondary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

@keyframes titleBounce {
    0% {
        transform: translateY(-20px);
        opacity: 0;
    }

    60% {
        transform: translateY(6px);
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.subtitle {
    text-align: center;
    font-size: 1.2rem;
    color: var(--secondary);
    margin-bottom: 3rem;
    font-weight: 600;
    user-select: none;
}

/* ─── Section de saisie ────────────────────────────────────────────────────── */
.input-section {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 30px;
    box-shadow: 0 20px 60px var(--shadow);
    margin-bottom: 2rem;
    border: 4px solid var(--primary);
}

.input-group {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

textarea {
    flex: 1;
    padding: 1rem 1.5rem;
    border: 3px solid var(--tertiary);
    border-radius: 20px;
    font-family: 'Fredoka', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--tertiary);
    background: #f9fffe;
    transition: border-color 0.3s ease, transform 0.3s ease;
    resize: none;
    min-height: 100px;
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
    transform: scale(1.01);
}

/* Animation d'erreur quand le champ est vide */
textarea.input-error {
    animation: shake 0.4s ease;
    border-color: var(--danger);
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    20% {
        transform: translateX(-6px);
    }

    40% {
        transform: translateX(6px);
    }

    60% {
        transform: translateX(-4px);
    }

    80% {
        transform: translateX(4px);
    }
}

/* ─── Boutons (base) ───────────────────────────────────────────────────────── */
button {
    padding: 1rem 2rem;
    border: none;
    border-radius: 20px;
    font-family: 'Fredoka', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

button:focus-visible {
    outline: 3px solid var(--secondary);
    outline-offset: 3px;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ─── Bouton Ajouter ───────────────────────────────────────────────────────── */
.btn-add {
    background-color: var(--primary);
    color: white;
    align-self: flex-start;
}

.btn-add:hover:not(:disabled) {
    transform: scale(1.06);
    box-shadow: 0 6px 20px var(--shadow);
}

.btn-add:active:not(:disabled) {
    transform: scale(0.95);
}

/* ─── Bouton Pika Pika ─────────────────────────────────────────────────────── */
.btn-plouf {
    background-color: var(--secondary);
    color: white;
    width: 100%;
    padding: 1.5rem;
    font-size: 1.5rem;
    box-shadow: 0 10px 30px rgba(236, 206, 34, 0.35);
    margin-top: 1rem;
}

.btn-plouf:hover:not(:disabled) {
    transform: scale(1.04);
    box-shadow: 0 14px 40px rgba(236, 206, 34, 0.45);
}

.btn-plouf:active:not(:disabled) {
    transform: scale(0.97);
}

/* ─── Bouton Tout supprimer ────────────────────────────────────────────────── */
.btn-clear {
    background-color: var(--danger);
    color: white;
    width: 100%;
    padding: 1.2rem;
    font-size: 1.1rem;
    margin-top: 0.5rem;
}

.btn-clear:hover:not(:disabled) {
    transform: scale(1.03);
    box-shadow: 0 6px 20px rgba(255, 104, 104, 0.35);
}

/* ─── Liste des élèves ─────────────────────────────────────────────────────── */
.students-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.student-tag {
    background: var(--card-bg);
    padding: 0.9rem 1.2rem;
    border-radius: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 3px solid var(--tertiary);
    animation: slideIn 0.35s ease-out;
    transition: transform 0.2s ease, background 0.2s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-16px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.student-tag:hover {
    transform: scale(1.04);
}

.student-tag.highlight {
    background: var(--primary);
    border-color: var(--primary);
    transform: scale(1.08);
    box-shadow: 0 6px 20px var(--shadow);
}

.student-tag.highlight .student-name {
    color: white;
}

.student-name {
    font-weight: 600;
    font-size: 1.05rem;
    color: var(--text);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-remove {
    background: transparent;
    color: var(--primary);
    padding: 0.25rem 0.6rem;
    font-size: 1.1rem;
    border-radius: 10px;
    text-transform: none;
    letter-spacing: 0;
    flex-shrink: 0;
    border: none;
}

.btn-remove:hover {
    background: var(--danger);
    color: white;
    transform: scale(1.1);
    border: none;
}

/* ─── Section résultat ─────────────────────────────────────────────────────── */
.result-section {
    background: var(--card-bg);
    padding: 3rem;
    border-radius: 32px;
    box-shadow: 0 20px 60px var(--shadow);
    text-align: center;
    min-height: 220px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border: 4px solid var(--secondary);
    transition: all 0.4s ease;
}

.empty-state {
    color: #aaa;
    font-size: 1.2rem;
    font-style: italic;
}

.winner-text {
    font-family: 'Lilita One', cursive;
    font-size: 1.8rem;
    color: var(--primary);
    margin-bottom: 0.8rem;
}

.winner-text.loading {
    font-size: 3rem;
    animation: spin 0.8s linear infinite;
}

.winner-name {
    font-family: 'Lilita One', cursive;
    font-size: clamp(2rem, 6vw, 3.5rem);
    color: var(--tertiary);
    animation: winnerAppear 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes winnerAppear {
    0% {
        opacity: 0;
        transform: scale(0.3) rotate(-10deg);
    }

    100% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* ─── Confettis ────────────────────────────────────────────────────────────── */
.confetti-piece {
    position: fixed;
    top: -12px;
    pointer-events: none;
    animation: confetti-fall ease-in forwards;
    z-index: 9999;
}

@keyframes confetti-fall {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translateY(105vh) rotate(540deg);
        opacity: 0;
    }
}

/* ─── Notifications ────────────────────────────────────────────────────────── */
.notification {
    position: fixed;
    top: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(-120px);
    background: var(--secondary);
    color: #2D3748;
    padding: 0.9rem 1.8rem;
    border-radius: 20px;
    font-weight: 700;
    font-size: 1rem;
    box-shadow: 0 8px 24px rgba(236, 206, 34, 0.35);
    z-index: 1000;
    border: 2px solid var(--primary);
    animation: notifDown 0.4s ease-out forwards, notifUp 0.4s ease-in 2.7s forwards;
    white-space: nowrap;
}

@keyframes notifDown {
    to {
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes notifUp {
    to {
        transform: translateX(-50%) translateY(-120px);
        opacity: 0;
    }
}

/* ─── Footer ───────────────────────────────────────────────────────────────── */
footer {
    text-align: center;
    padding: 1.5rem 1rem;
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.95rem;
    margin-top: 1rem;
}

footer a {
    color: var(--secondary);
    text-decoration: none;
    font-weight: 700;
}

footer a:hover {
    text-decoration: underline;
}

.btn-update {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    padding: 0.65rem 1.4rem;
    border-radius: 20px;
    font-size: 0.95rem;
    font-weight: 600;
    margin-top: 0.8rem;
    border: 2px solid rgba(255, 255, 255, 0.4);
    text-transform: none;
    letter-spacing: 0;
    backdrop-filter: blur(6px);
}

.btn-update:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: white;
    transform: scale(1.05);
}

/* ─── Modale ───────────────────────────────────────────────────────────────── */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background-color: rgba(0, 0, 0, 0.55);
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

/* display:flex quand ouverte (défini via JS) */
.modal[style*="flex"],
.modal[style*="block"] {
    display: flex !important;
}

.modal-content {
    background: var(--card-bg);
    padding: 2rem 2rem 1.5rem;
    border: 3px solid var(--primary);
    border-radius: 24px;
    max-width: 560px;
    width: 100%;
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalIn {
    from {
        transform: scale(0.85);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-content h1 {
    font-size: 2rem;
    margin-bottom: 0.25rem;
}

.modal-content h2 {
    font-size: 1.3rem;
    color: var(--tertiary);
    margin-bottom: 0.5rem;
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    /* Empêche l'héritage de background-clip du h1 */
    background: none;
    -webkit-background-clip: unset;
    -webkit-text-fill-color: var(--tertiary);
    background-clip: unset;
}

.modal-date {
    font-size: 0.85rem;
    color: #999;
    margin-bottom: 1rem;
}

.modal-warning {
    background: #fff8e1;
    border: 2px solid var(--secondary);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    color: #6b5c00;
    font-weight: 600;
    margin: 0.75rem 0 1rem;
    font-size: 0.95rem;
}

.modal-list {
    padding-left: 1.5rem;
    margin: 0.75rem 0 1rem;
    line-height: 2;
    color: var(--text);
}

.modal-contact {
    background: #f0f4ff;
    border: 2px solid var(--primary);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    color: var(--tertiary);
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
}

.modal-contact a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 700;
}

.modal-contact a:hover {
    text-decoration: underline;
}

.modal-thanks {
    text-align: center;
    color: var(--tertiary);
    font-weight: 600;
    margin-top: 0.5rem;
}

.close-btn {
    position: absolute;
    top: 0.6rem;
    right: 1rem;
    font-size: 2rem;
    font-weight: bold;
    color: var(--tertiary);
    cursor: pointer;
    background: none;
    border: none;
    padding: 0 0.3rem;
    line-height: 1;
    text-transform: none;
    letter-spacing: 0;
}

.close-btn:hover {
    color: var(--danger);
    transform: scale(1.15);
}

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    body {
        padding: 1rem;
    }

    .input-group {
        flex-direction: column;
    }

    .btn-add {
        width: 100%;
    }

    .students-list {
        grid-template-columns: 1fr;
    }

    .result-section {
        padding: 2rem 1.5rem;
    }
}