*, *::before, *::after{
    box-sizing: border-box;
}

:root{
    --color-bg: #19171c;
    --color-text: #f5f5f7;
    --color-muted: #b3b3b8;
    --color-panel-bg: #212126;
    --color-panel-border: #000000;
    --color-twitch: #6441a4;
    --color-shadow: rgba(0, 0, 0, 0.35);

    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    --shadow-sm: 0 1px 3px var(--color-shadow);
    --shadow-md: 0 4px 14px var(--color-shadow);
}

:root[data-theme="light"]{
    --color-bg: #f4f4f7;
    --color-text: #18181b;
    --color-muted: #55555f;
    --color-panel-bg: #ffffff;
    --color-panel-border: #d8d8e0;
    --color-twitch: #6441a4;
    --color-shadow: rgba(24, 24, 27, 0.12);
}

body{
    background-color: var(--color-bg);
    font-family: Helvetica Neue,Helvetica,Arial,sans-serif;
    color: var(--color-text);
    margin: 0;
    transition: background-color .2s ease, color .2s ease;
}

.all{
    max-width: min(1800px, 96vw);
    margin: 0 auto;
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

/* Meme grille que .stream (video 3fr / chat 1fr) pour que .stream-links et
.header-actions s'alignent pile sur les bords de la video et du chat. */
.info-top{
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(280px, 1fr);
    align-items: center;
    gap: var(--space-lg);
}

.info-top-main{
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-lg);
    min-width: 0;
}

/*Gestion du nom Streamer, avatar, badge et viewers */
.stream-heading{
    display: flex;
    align-items: center;
    gap: var(--space-md);
    min-width: 0;
}

.streamer-avatar{
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
    background-color: var(--color-panel-bg);
    border: 2px solid var(--color-panel-border);
    flex-shrink: 0;
}

.streamer-avatar[src=""], .streamer-avatar:not([src]){
    visibility: hidden;
}

.stream-heading-text{
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stream-heading-row{
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-sm) var(--space-md);
}

.live-badge{
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: white;
    background-color: #eb0400;
    padding: 4px 10px;
    border-radius: 999px;
    flex-shrink: 0;
}

.live-badge::before{
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: white;
    animation: blink 1.6s ease-in-out infinite;
}

@keyframes blink{
    0%, 100% { opacity: 1; }
    50% { opacity: .3; }
}

.live-duration{
    font-size: 12px;
    color: var(--color-muted);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.live-duration:empty{
    display: none;
}

h1{
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.viewer-count{
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--color-muted);
    font-size: 15px;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.icon-eye{
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.viewer-sparkline{
    width: 46px;
    height: 16px;
    overflow: visible;
}

.viewer-sparkline:empty{
    display: none;
}

.viewer-sparkline polyline{
    fill: none;
    stroke: var(--color-twitch);
    stroke-width: 1.5;
    stroke-linejoin: round;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
}

.seen-badge{
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--color-muted);
    border: 1px solid var(--color-panel-border);
    border-radius: 999px;
    padding: 3px 9px;
    flex-shrink: 0;
}

.seen-badge:empty{
    display: none;
}

.seen-badge.is-new{
    color: white;
    background-color: var(--color-twitch);
    border-color: var(--color-twitch);
}

.connected-viewers{
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--color-muted);
    border: 1px solid var(--color-panel-border);
    border-radius: 999px;
    padding: 3px 9px;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.icon-people{
    width: 14px;
    height: 14px;
    fill: currentColor;
}

.title{
    margin: 0;
    font-size: 14px;
    color: var(--color-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.game-name{
    display: block;
    margin: 0;
    font-size: 13px;
    color: var(--color-muted);
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.game-name:hover{
    color: var(--color-text);
    text-decoration: underline;
}

.game-name:empty{
    display: none;
}

.clock-block{
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.clock-label{
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--color-muted);
}

#clockdiv{
	color: var(--color-text);
	display: inline-block;
	text-align: center;
	font-size: 40px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.header-actions{
    display: flex;
    align-items: center;
    justify-content: flex-end;
    justify-self: end;
    gap: var(--space-lg);
}

.button, .stream-links{
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-sm);
}

.twitch, .subscribe{
    height: 40px;
    padding: 0 var(--space-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: transform .15s ease;
    white-space: nowrap;
}

.twitch:hover, .subscribe:hover{
    transform: translateY(-1px);
}

.twitch{
    background-color: var(--color-twitch);
    border: 1px solid var(--color-twitch);
    color: white;
}

.subscribe{
    background-color: transparent;
    border: 1px solid var(--color-panel-border);
    color: var(--color-text);
}

.theme-toggle, .share-button, .twitch-open-button{
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-panel-border);
    background-color: var(--color-panel-bg);
    color: var(--color-text);
    font-size: 18px;
    cursor: pointer;
    transition: background-color .2s ease, border-color .2s ease;
}

.twitch-open-button{
    color: var(--color-twitch);
}

.twitch-open-button:hover{
    border-color: var(--color-twitch);
}

.icon-twitch{
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.stats-link{
    height: 40px;
    padding: 0 var(--space-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-panel-border);
    color: var(--color-text);
    white-space: nowrap;
    transition: transform .15s ease;
}

.stats-link:hover{
    transform: translateY(-1px);
}

.action-buttons{
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.skip-vote-button, .like-button{
    height: 36px;
    padding: 0 var(--space-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-twitch);
    background-color: transparent;
    color: var(--color-twitch);
    cursor: pointer;
    white-space: nowrap;
    transition: background-color .15s ease, color .15s ease, opacity .15s ease;
}

.skip-vote-button:hover:not(:disabled), .like-button:hover:not(:disabled){
    background-color: var(--color-twitch);
    color: white;
}

.skip-vote-button:disabled, .like-button:disabled{
    opacity: .5;
    cursor: not-allowed;
    border-color: var(--color-panel-border);
    color: var(--color-muted);
}

.like-button{
    border-color: #eb0400;
    color: #eb0400;
}

.like-button:hover:not(:disabled){
    background-color: #eb0400;
    color: white;
}

.like-button.liked{
    background-color: #eb0400;
    color: white;
    opacity: 1;
}

/*Gestion du Live et du Chat */
.stream{
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(280px, 1fr);
    gap: var(--space-lg);
    align-items: stretch;
}

.live{
    width: 100%;
    aspect-ratio: 16 / 9;
    height: auto;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: box-shadow .2s ease;
}

.live iframe{
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

.chat_info{
    display: flex;
    min-width: 0;
    height: 100%;
}

.chat_info iframe.chat{
    width: 100%;
    height: 100%;
    min-height: 300px;
    border: none;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

/* Panneaux encadres : historique + stats, cote a cote sous le stream */
/* Meme grille que .stream et .info-top pour que l'historique s'aligne sur la
video et les stats sur le chat. */
.panels-row{
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(280px, 1fr);
    gap: var(--space-lg);
    align-items: stretch;
}

.site-footer{
    width: 100%;
    text-align: center;
    padding: var(--space-md) 0;
}

.site-footer a{
    color: var(--color-muted);
    font-size: 0.85em;
    text-decoration: none;
}

.site-footer a:hover{
    text-decoration: underline;
}

.panel{
    width: 100%;
    background-color: var(--color-panel-bg);
    border: 1px solid var(--color-panel-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: var(--space-md);
    transition: background-color .2s ease, border-color .2s ease;
}

.panel h3{
    font-size: 13px;
    margin: 0 0 var(--space-md) 0;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--color-muted);
}

.panel-header{
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-sm);
}

.panel-header h3{
    margin: 0 0 var(--space-md) 0;
}

.panel-header-link{
    color: var(--color-muted);
    font-size: 12px;
    text-decoration: none;
    white-space: nowrap;
}

.panel-header-link:hover{
    color: var(--color-text);
}

.history-list{
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: var(--space-sm) var(--space-md);
}

.history-list li{
    min-width: 0;
}

.history-empty{
    color: var(--color-muted);
    font-size: 13px;
}

.history-item{
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    background-color: var(--color-bg);
    border: 1px solid var(--color-panel-border);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
    padding-right: 40px;
    min-width: 0;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: transform .15s ease, border-color .15s ease;
}

.history-item:hover{
    transform: translateY(-1px);
    border-color: var(--color-twitch);
}

.history-avatar{
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    background-color: var(--color-panel-bg);
    flex-shrink: 0;
}

.history-avatar[src=""], .history-avatar:not([src]){
    visibility: hidden;
}

.history-text{
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.history-name{
    color: var(--color-text);
    font-weight: 600;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-badges{
    position: absolute;
    top: 6px;
    right: 6px;
    display: flex;
    align-items: center;
    gap: 3px;
}

.history-badges:empty{
    display: none;
}

.history-badge{
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    padding: 3px 5px;
    border-radius: 999px;
    background-color: var(--color-panel-bg);
    border: 1px solid var(--color-panel-border);
    color: var(--color-muted);
}

.history-badge.skip{
    background-color: #eb0400;
    border-color: #eb0400;
    color: white;
}

.history-badge.like{
    background-color: transparent;
    border-color: #eb0400;
    color: #eb0400;
}

.history-meta{
    color: var(--color-muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-time{
    color: var(--color-muted);
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-search{
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
}

.history-search-input{
    flex: 1;
    height: 40px;
    padding: 0 var(--space-md);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-panel-border);
    background-color: var(--color-panel-bg);
    color: var(--color-text);
    font-size: 14px;
}

.history-search-input::placeholder{
    color: var(--color-muted);
}

.history-search-button{
    height: 40px;
    padding: 0 var(--space-lg);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-twitch);
    background-color: transparent;
    color: var(--color-twitch);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease;
}

.history-search-button:hover{
    background-color: var(--color-twitch);
    color: white;
}

.full-history-list{
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.history-pagination{
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    margin-top: var(--space-lg);
}

.history-pagination-link{
    color: var(--color-text);
    text-decoration: none;
    font-size: 14px;
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid var(--color-panel-border);
    border-radius: var(--radius-sm);
}

.history-pagination-link:hover{
    border-color: var(--color-twitch);
}

.history-pagination-link.disabled{
    color: var(--color-muted);
    opacity: .5;
}

.history-pagination-info{
    color: var(--color-muted);
    font-size: 13px;
}

/* Grille de tuiles de stats */
.stat-grid{
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-md);
}

.stat-tile{
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label{
    font-size: 12px;
    color: var(--color-muted);
}

.stat-value{
    font-size: 24px;
    font-weight: 600;
    color: var(--color-text);
}

/* La colonne stats du panneau principal est plus etroite (alignee sur le
chat) : 3 colonnes y font passer les libelles longs a la ligne et desalignent
les tuiles entre elles. 2 colonnes + police un peu plus petite = tout tient
sur une ligne. */
.stats-section .stat-grid{
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-sm) var(--space-md);
}

.stats-section .stat-label{
    font-size: 11px;
}

.stats-section .stat-value{
    font-size: 20px;
}

/* Boite a suggestions : bouton flottant + petit panneau, hors du flux pour
ne pas reperturber l'agencement du header. */
.suggestion-fab{
    position: fixed;
    right: var(--space-lg);
    bottom: var(--space-lg);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid var(--color-panel-border);
    background-color: var(--color-panel-bg);
    color: var(--color-text);
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: transform .15s ease;
    z-index: 50;
}

.suggestion-fab:hover{
    transform: translateY(-2px);
}

.suggestion-popover{
    position: fixed;
    right: var(--space-lg);
    bottom: calc(48px + var(--space-lg) + var(--space-sm));
    width: min(320px, calc(100vw - 2 * var(--space-lg)));
    background-color: var(--color-panel-bg);
    border: 1px solid var(--color-panel-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: var(--space-md);
    z-index: 50;
}

.suggestion-popover[hidden]{
    display: none;
}

.suggestion-popover h3{
    margin: 0 0 var(--space-sm) 0;
    font-size: 14px;
}

.suggestion-textarea{
    width: 100%;
    min-height: 90px;
    resize: vertical;
    background-color: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-panel-border);
    border-radius: var(--radius-sm);
    padding: var(--space-sm);
    font-family: inherit;
    font-size: 13px;
}

.suggestion-popover-actions{
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    margin-top: var(--space-sm);
}

.suggestion-feedback{
    font-size: 12px;
    color: var(--color-muted);
}

.suggestion-feedback.error{
    color: #eb0400;
}

.suggestion-submit{
    height: 32px;
    padding: 0 var(--space-md);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-twitch);
    background-color: var(--color-twitch);
    color: white;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.suggestion-submit:disabled{
    opacity: .5;
    cursor: not-allowed;
}

@media (max-width: 900px){
    .stream{
        grid-template-columns: 1fr;
    }
    .chat_info{
        height: auto;
        margin-top: 0;
    }
    .chat_info iframe.chat{
        height: 360px;
    }
    .panels-row{
        grid-template-columns: 1fr;
    }
    .history-list{
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .full-history-list{
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .stat-grid{
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .info-top{
        grid-template-columns: 1fr;
        justify-items: center;
        text-align: center;
    }
    .info-top-main{
        flex-direction: column;
        align-items: center;
    }
    .stream-heading{
        justify-content: center;
    }
    .header-actions{
        justify-content: center;
        flex-wrap: wrap;
    }
    .button, .stream-links{
        justify-content: center;
    }
}

/* Flash discret au changement reel de stream (voir web/app.js) */
@keyframes pulse-outline{
    0%   { box-shadow: 0 0 0 0 var(--color-twitch), var(--shadow-md); }
    70%  { box-shadow: 0 0 0 10px rgba(100, 65, 164, 0); }
    100% { box-shadow: 0 0 0 0 rgba(100, 65, 164, 0), var(--shadow-md); }
}

@keyframes pulse-text{
    0%   { color: var(--color-twitch); }
    100% { color: var(--color-text); }
}

.pulse-update{
    animation-duration: 900ms;
    animation-timing-function: ease-out;
}

.live.pulse-update{
    animation-name: pulse-outline;
}

.streamer.pulse-update{
    animation-name: pulse-text;
}

@media (prefers-reduced-motion: reduce){
    .pulse-update{
        animation: none;
    }
}
