/* === Reset & base === */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background-color: #0e0e10;
    color: #efeff1;
    min-height: 100vh;
    padding: 2rem;
}
/* === Transitions === */
#selection-screen,
#viewer-screen {
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Animations de la liste des streamers */
#streamers-list li {
    animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}
/* === Header === */
header {
    text-align: center;
    margin-bottom: 3rem;
}

h1 {
    color: #9147ff;
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: #adadb8;
    font-size: 1rem;
}

/* === Selection screen layout === */
#selection-screen {
    max-width: 600px;
    margin: 0 auto;
}

/* === Add streamer === */
.add-streamer {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

#streamer-input {
    flex: 1;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    background-color: #1f1f23;
    border: 1px solid #3a3a3d;
    border-radius: 4px;
    color: #efeff1;
}

#streamer-input:focus {
    outline: none;
    border-color: #9147ff;
}

button {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    background-color: #9147ff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.15s;
}

button:hover:not(:disabled) {
    background-color: #772ce8;
}

button:disabled {
    background-color: #3a3a3d;
    color: #6e6e73;
    cursor: not-allowed;
}

/* === Error message === */
.error {
    color: #ff5252;
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.hidden {
    display: none !important;
}

/* === Selected list === */
.selected-list {
    background-color: #18181b;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.selected-list h2 {
    font-size: 1.125rem;
    margin-bottom: 1rem;
    color: #adadb8;
}

#streamers-list {
    list-style: none;
}

#streamers-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background-color: #1f1f23;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

#streamers-list li:last-child {
    margin-bottom: 0;
}

.remove-button {
    background-color: transparent;
    color: #ff5252;
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid #ff5252;
}

.remove-button:hover:not(:disabled) {
    background-color: #ff5252;
    color: white;
}

/* === Start button === */
#start-button {
    width: 100%;
    padding: 1rem;
    font-size: 1.125rem;
}
/* === Viewer screen === */
#viewer-screen {
    min-height: calc(100vh - 4rem);
    height: calc(100vh - 4rem);
    display: flex;
    flex-direction: column;
}

/* Conteneur des streams + chat */
#viewer-content {
    flex: 1;
    display: flex;
    gap: 0.5rem;
    min-height: 0;
}

/* Quand le tchat est affiché, la grille rétrécit pour lui laisser la place */
#viewer-content:has(#chat-panel:not(.hidden)) #streams-grid {
    flex: 1 1 auto;
}

/* Panneau de chat Twitch */
#chat-panel {
    width: 340px;
    min-width: 340px;
    background-color: #18181b;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    padding: 0.75rem 1rem;
    background-color: #1f1f23;
    border-bottom: 1px solid #3a3a3d;
    color: #efeff1;
    font-weight: 600;
    font-size: 0.875rem;
}

#chat-container {
    flex: 1;
    min-height: 0;
}

#chat-container iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.viewer-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.viewer-info {
    margin-left: auto;
    color: #adadb8;
    font-size: 0.875rem;
}

#play-all-button {
    background-color: #00b050;
    color: white;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

#play-all-button:hover:not(:disabled) {
    background-color: #008f3f;
}



.viewer-info {
    color: #adadb8;
    font-size: 0.875rem;
}

/* === Streams grid (responsive) === */
#streams-grid {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    gap: 0.5rem;
    min-width: 0;
}

/* 1 stream = pleine surface */
#streams-grid.count-1 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
}

/* 2 streams = côte à côte */
#streams-grid.count-2 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;
}

/* 3-4 streams = grille 2x2 */
#streams-grid.count-3,
#streams-grid.count-4 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

/* 5-6 streams = grille 3x2 */
#streams-grid.count-5,
#streams-grid.count-6 {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

/* 7-8 streams = grille 4x2 */
#streams-grid.count-7,
#streams-grid.count-8 {
    grid-template-columns: 1fr 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.stream-container {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 300px;
    background-color: #000;
    border-radius: 4px;
    overflow: hidden;
}

.stream-container iframe {
    width: 100% !important;
    height: 100% !important;
    border: none;
    display: block;
}
.stream-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 40px; /* Laisse la barre de contrôles Twitch accessible */
    z-index: 5;
    cursor: pointer;
    background-color: transparent;
}
/* Quand le mode interaction est activé, l'overlay laisse passer les clics */
body.interact-mode .stream-overlay {
    pointer-events: none;
}
.stream-label {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    background-color: rgba(0, 0, 0, 0.7);
    color: #efeff1;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.875rem;
    font-weight: 600;
    z-index: 10;
    pointer-events: auto;
    cursor: grab;
    user-select: none;
}

.stream-label:active {
    cursor: grabbing;
}
/* === Active stream highlight === */
.stream-container {
    cursor: pointer;
    transition: box-shadow 0.2s, transform 0.2s;
}

.stream-container.active {
    box-shadow: 0 0 0 3px #9147ff;
    z-index: 2;
}

.stream-container.active .stream-label {
    background-color: #9147ff;
}
/* === Empty state === */
#streamers-list .empty-state {
    background-color: transparent;
    color: #6e6e73;
    font-style: italic;
    text-align: center;
    padding: 1rem;
    justify-content: center;
}
/* === Performance warning === */
.perf-warning {
    margin-top: 1rem;
    padding: 0.75rem;
    background-color: rgba(255, 184, 0, 0.1);
    border-left: 3px solid #ffb800;
    border-radius: 4px;
    color: #ffb800;
    font-size: 0.875rem;
    line-height: 1.4;
}
/* === Boutons du header du viewer (taille unifiée) === */
#back-button,
#interact-toggle,
#chat-toggle {
    background-color: #1f1f23;
    color: #efeff1;
    border: 1px solid #3a3a3d;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.2;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#back-button:hover:not(:disabled),
#interact-toggle:hover:not(:disabled),
#chat-toggle:hover:not(:disabled) {
    background-color: #3a3a3d;
}

/* État actif : Mode interaction → vert */
#interact-toggle.active {
    background-color: #00b050;
    border-color: #00b050;
    color: white;
}

#interact-toggle.active:hover:not(:disabled) {
    background-color: #008f3f;
}

/* État actif : Tchat → violet Twitch */
#chat-toggle.active {
    background-color: #9147ff;
    border-color: #9147ff;
    color: white;
}

#chat-toggle.active:hover:not(:disabled) {
    background-color: #772ce8;
}
/* === Drag & Drop === */

/* Curseur "grab" sur les éléments draggables au repos */
#streamers-list li:not(.empty-state) {
    cursor: grab;
}

#streamers-list li:not(.empty-state):active {
    cursor: grabbing;
}

.stream-container {
    cursor: grab;
}

.stream-container:active {
    cursor: grabbing;
}

/* Élément laissé à la position d'origine pendant le drag */
.sortable-ghost {
    opacity: 0.3;
    background-color: #9147ff !important;
}

/* Élément qu'on est en train de faire glisser */
.sortable-drag {
    opacity: 0.9;
}

/* Élément temporairement déplacé pour montrer où le drag va atterrir */
.sortable-chosen {
    box-shadow: 0 0 0 2px #9147ff;
}

/*  Lorsqu'il y a un drag & drop sur la grille on va désactiver les iframes
   pour qu'elles n'interceptent pas la souris (sinon crash) */
body.is-dragging .stream-container iframe {
    pointer-events: none;
}
/* Icône drag dans le label */
.drag-icon {
    display: inline-block;
    margin-right: 0.25rem;
    opacity: 0.6;
    font-size: 1rem;
    line-height: 1;
    vertical-align: middle;
    transition: opacity 0.15s;
}

.stream-label:hover .drag-icon,
#streamers-list li:hover .drag-icon {
    opacity: 1;
}

/* === Suggestions section === */
.suggestions-section {
    background-color: #18181b;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.suggestions-section h2 {
    font-size: 1.125rem;
    margin-bottom: 0.25rem;
    color: #adadb8;
}

.suggestions-hint {
    color: #6e6e73;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

#suggestions-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.suggestion-card {
    background-color: #1f1f23;
    border: 1px solid #3a3a3d;
    border-radius: 6px;
    padding: 0.75rem;
    cursor: pointer;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    transition: background-color 0.15s, border-color 0.15s, transform 0.15s;
    text-align: left;
    color: #efeff1;
    font-family: inherit;
    position: relative;
}

.suggestion-card:hover:not(:disabled) {
    background-color: #2a2a2e;
    border-color: #9147ff;
    transform: translateY(-2px);
}

.suggestion-card:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.suggestion-card.selected {
    border-color: #00b050;
    background-color: rgba(0, 176, 80, 0.1);
    opacity: 1; /* surcharge le :disabled */
}

.suggestion-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.suggestion-info {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.suggestion-pseudo {
    font-weight: 600;
    font-size: 0.95rem;
}

.suggestion-category {
    font-size: 0.75rem;
    color: #adadb8;
}

.suggestion-check {
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    color: #00b050;
    font-weight: 700;
    font-size: 1.1rem;
}

/* Responsive : 2 colonnes sur mobile */
@media (max-width: 600px) {
    #suggestions-list {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ========================================================
   LE RESPONSIVE MOBILE 
   ======================================================== */

/* === Tablette / petit écran (< 900px) === */
@media (max-width: 900px) {

    /* Grilles du viewer : max 2 colonnes */
    #streams-grid.count-3,
    #streams-grid.count-4 {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
    }

    #streams-grid.count-5,
    #streams-grid.count-6 {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto auto;
    }

    #streams-grid.count-7,
    #streams-grid.count-8 {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto auto auto;
    }

    /* Tchat sidebar plus étroite */
    #chat-panel {
        width: 280px;
        min-width: 280px;
    }
}

/* === Mobile (< 768px) === */
@media (max-width: 768px) {

    /* --- Global --- */
    body {
        padding: 1rem;
    }

    /* --- Header --- */
    h1 {
        font-size: 1.75rem;
    }

    .subtitle {
        font-size: 0.875rem;
    }

    /* --- Écran de sélection --- */
    #selection-screen {
        max-width: 100%;
    }

    /* Input + bouton empilés */
    .add-streamer {
        flex-direction: column;
    }

    #streamer-input {
        width: 100%;
    }

    /* Suggestions en 2 colonnes */
    #suggestions-list {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Bouton "Lancer" reste full width */
    .action-buttons {
        flex-direction: column;
    }

    /* --- Écran du viewer --- */

    /* Le viewer prend toute la hauteur dispo */
    #viewer-screen {
        height: auto;
        min-height: calc(100vh - 2rem);
    }

    /* Boutons header : wrap + compacts */
    .viewer-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    #back-button,
    #interact-toggle,
    #chat-toggle {
        font-size: 0.75rem;
        padding: 0.4rem 0.6rem;
        height: 32px;
    }

    /* Texte d'aide masqué sur mobile (trop long) */
    .viewer-info {
        display: none;
    }

    /* Layout streams + chat : passage en colonne */
    #viewer-content {
        flex-direction: column;
    }

    /* Grille : 1 colonne pour tout */
    #streams-grid.count-1,
    #streams-grid.count-2,
    #streams-grid.count-3,
    #streams-grid.count-4,
    #streams-grid.count-5,
    #streams-grid.count-6,
    #streams-grid.count-7,
    #streams-grid.count-8 {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
    }

    /* Chaque stream en ratio 16:9 fixe pour lisibilité */
    .stream-container {
        min-height: unset;
        aspect-ratio: 16 / 9;
    }

    /* Tchat : full width sous la grille au lieu de sidebar */
    #chat-panel {
        width: 100%;
        min-width: unset;
        height: 400px;
    }

    /* Labels plus petits */
    .stream-label {
        font-size: 0.75rem;
        padding: 0.2rem 0.4rem;
    }
}

/* === Petit mobile (< 480px) === */
@media (max-width: 480px) {

    /* Titre encore plus compact */
    h1 {
        font-size: 1.4rem;
    }

    /* Suggestions en 2 colonnes compactes */
    .suggestion-card {
        padding: 0.5rem;
        gap: 0.5rem;
    }

    .suggestion-avatar {
        width: 32px;
        height: 32px;
    }

    .suggestion-pseudo {
        font-size: 0.85rem;
    }

    .suggestion-category {
        font-size: 0.7rem;
    }

    /* Boutons header encore plus compacts */
    #back-button,
    #interact-toggle,
    #chat-toggle {
        font-size: 0.7rem;
        padding: 0.35rem 0.5rem;
        height: 28px;
    }

    /* Tchat légèrement moins haut */
    #chat-panel {
        height: 350px;
    }

    /* Liste de sélection : pseudo + bouton retirer plus compacts */
    #streamers-list li {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }

    .remove-button {
        padding: 0.2rem 0.5rem;
        font-size: 0.75rem;
    }
}