* {
    scrollbar-width: thin;
    scrollbar-color: #3a3a3d transparent;
}
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #3a3a3d; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #e89c22; }

html { height: 100%; }
body { 
    background-color: #0e0e10; 
    color: #efeff1; 
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; 
    margin: 0; 
    display: flex; 
    height: 100%; 
    height: 100dvh; 
    overflow: hidden; 
}

#video-container { 
    flex: 3; 
    background: #000; 
    position: relative; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    overflow: hidden; 
}

video { 
    width: 100%; 
    height: 100%;
    object-fit: contain; 
    max-height: 100%; 
    box-shadow: 0 0 20px rgba(0,0,0,0.5); 
}

#svg-overlay { position: absolute; bottom: 10%; left: 50%; transform: translateX(-50%); width: 80%; pointer-events: none; text-align: center; z-index: 10; }

.unmute-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 25;
}

.unmute-overlay.show {
    opacity: 1;
}

.unmute-overlay svg {
    width: 64px;
    height: 64px;
    filter: drop-shadow(0 2px 6px rgba(0,0,0,0.8));
}

.unmute-overlay span {
    color: #fff;
    font-size: 1.8em;
    font-weight: 600;
    text-shadow: 0 2px 8px rgba(0,0,0,0.9);
    white-space: nowrap;
}

/* Retrait de l'animation sur "bottom" pour ne pas faire buguer le tactile */
#video-controls { position: absolute; bottom: 20px; right: 20px; display: flex; gap: 12px; opacity: 0; pointer-events: none; transition: opacity 0.3s; z-index: 50; align-items: center; }

#video-container:hover #video-controls,
#video-container.show-controls #video-controls { opacity: 1; pointer-events: auto; }

.control-group { 
    display: flex; 
    align-items: center; 
    height: 40px; 
    box-sizing: border-box;
    background: rgba(24, 24, 27, 0.4); 
    backdrop-filter: blur(4px); 
    border: 1px solid rgba(58, 58, 61, 0.5); 
    border-radius: 8px; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.2); 
    flex-shrink: 0; 
}

.solo-btn { 
    height: 40px; 
    box-sizing: border-box;
    background: rgba(24, 24, 27, 0.4); 
    border: 1px solid rgba(58, 58, 61, 0.5); 
    border-radius: 8px; 
    backdrop-filter: blur(4px); 
    flex-shrink: 0; 
}

.control-btn { 
    background: transparent; 
    color: #efeff1; 
    border: none; 
    height: 100%;
    box-sizing: border-box;
    padding: 0 14px; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    transition: all 0.2s; 
    border-radius: 8px; 
    gap: 6px;
    white-space: nowrap;
    touch-action: manipulation; /* Empêche le délai de 300ms sur mobile */
}

.control-btn svg { 
    width: 22px; 
    height: 22px; 
    stroke-width: 1.75; 
}

.control-btn.off { color: #da3633 !important; }
.control-btn.off svg { stroke: #da3633 !important; }

/* Protection pour que les effets de survol ne buggent pas sur mobile */
@media (hover: hover) {
    .control-btn:hover { background: rgba(255, 255, 255, 0.1); color: #e89c22; }
    .control-btn.off:hover { color: #ff4a4a !important; background: rgba(218, 54, 51, 0.1) !important; }
    .control-btn.off:hover svg { stroke: #ff4a4a !important; }
}

.control-separator { width: 1px; height: 20px; background: #3a3a3d; flex-shrink: 0; }
.custom-dropdown { position: relative; display: flex; align-items: center; height: 100%; }
.dropdown-toggle { font-size: 0.9em; font-weight: 600; }
.dropdown-toggle span { min-width: 24px; text-align: left; }

.dropdown-menu { 
    display: none; 
    position: absolute; 
    bottom: calc(100% + 10px); 
    left: 50%; 
    transform: translateX(-50%); 
    background: rgba(18, 18, 20, 0.6); 
    backdrop-filter: blur(12px); 
    border: 1px solid rgba(58, 58, 61, 0.5); 
    border-radius: 8px; 
    min-width: 110px; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.4); 
    z-index: 100; 
    padding: 5px 0;
    height: max-content; 
    flex-direction: column;
}
.custom-dropdown:hover .dropdown-menu, 
.custom-dropdown.open .dropdown-menu { display: flex !important; }

.custom-dropdown::before {
    content: ''; position: absolute; bottom: 100%; left: 0; width: 100%; height: 15px;
}

.dropdown-item { 
    padding: 10px 20px; color: #efeff1; cursor: pointer; font-size: 0.85em; 
    font-weight: 500; text-align: center; transition: background 0.2s, color 0.2s; 
    white-space: nowrap; line-height: 1.2;
}
.dropdown-item:hover { background: rgba(255, 255, 255, 0.1); color: #e89c22; }
.dropdown-item.active { color: #e89c22; font-weight: bold; background: rgba(232, 156, 34, 0.1); }
.volume-container { padding: 0; position: relative; } 
.volume-slider-wrapper {
    width: 0;
    opacity: 0;
    pointer-events: none; 
    overflow: hidden;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    display: flex;
    align-items: center;
}
.volume-container:hover .volume-slider-wrapper,
.volume-container.open .volume-slider-wrapper,
.volume-slider-wrapper:focus-within {
    width: 70px;
    opacity: 1;
    pointer-events: auto; 
    margin-right: 14px;
}

#volume-slider {
    -webkit-appearance: none !important; 
    -moz-appearance: none !important; 
    appearance: none !important;
    width: 100%;
    height: 4px; 
    background: linear-gradient(to right, var(--vol-color, #e89c22) var(--vol, 100%), rgba(255, 255, 255, 0.2) var(--vol, 100%));
    border-radius: 2px;
    outline: none;
    margin: 0;
}

#volume-slider::-moz-range-progress { background: transparent; border: none; }
#volume-slider::-moz-range-track { background: transparent; border: none; height: 4px; }
#volume-slider::-webkit-slider-runnable-track { background: transparent !important; border: none !important; height: 4px !important; }

#volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none !important;
    appearance: none !important;
    width: 14px !important;
    height: 14px !important;
    border-radius: 50% !important;
    background: #e89c22 !important;
    cursor: pointer !important;
    box-shadow: 0 1px 4px rgba(0,0,0,0.6) !important;
    display: block !important;
    margin-top: -5px !important; 
}
#volume-slider::-moz-range-thumb {
    -moz-appearance: none !important;
    appearance: none !important;
    width: 14px !important;
    height: 14px !important;
    border-radius: 50% !important;
    background: #e89c22 !important;
    border: none !important;
    cursor: pointer !important;
    box-shadow: 0 1px 4px rgba(0,0,0,0.6) !important;
}

#volume-slider.muted::-webkit-slider-thumb { background: #adadb8 !important; }
#volume-slider.muted::-moz-range-thumb { background: #adadb8 !important; }
#volume-slider:hover::-webkit-slider-thumb { transform: scale(1.2); }
#volume-slider:hover::-moz-range-thumb { transform: scale(1.2); }

.icon-with-badge { 
    position: relative; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    width: 22px;
    height: 22px;
    margin-right: 6px;
}
.hd-badge {
    position: absolute;
    top: -4px; 
    right: -10px; 
    background-color: #e89c22;
    color: #0e0e10;
    font-size: 7.5px; 
    font-family: 'Roboto', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-weight: 800; 
    letter-spacing: 0.3px;
    padding: 1px 3px;
    border-radius: 2px; 
    pointer-events: none;
    opacity: 0; 
    transform: scale(0.8);
    transition: opacity 0.2s, transform 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap; 
    width: max-content;
    height: 12px;
    line-height: 1;
    box-sizing: border-box;
}
.hd-badge.show { opacity: 1; transform: scale(1); }
#quality-label { min-width: 38px; display: inline-block; text-align: left; }
#danmaku-container { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; overflow: hidden; z-index: 15; }
.danmaku-msg { position: absolute; white-space: nowrap; color: white; font-weight: 500; opacity: 0.85; text-shadow: 1px 1px 0px rgba(0,0,0,0.8), -1px -1px 0px rgba(0,0,0,0.8), 1px -1px 0px rgba(0,0,0,0.8), -1px 1px 0px rgba(0,0,0,0.8); font-size: 1.6em; will-change: transform, left; display: flex; align-items: center; gap: 6px; left: 100%; }
.danmaku-msg img { height: 1.2em; vertical-align: middle; }
@keyframes scrollDanmaku { 0% { left: 100%; transform: translateX(0); } 100% { left: 0%; transform: translateX(-100%); } }

#fullscreen-chat-wrap { 
    display: none; position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); 
    width: 350px; max-width: 90%; background: rgba(24, 24, 27, 0.15); backdrop-filter: blur(3px); 
    border: 1px solid rgba(255,255,255,0.05); border-radius: 20px; 
    z-index: 150; 
    padding: 4px 15px; align-items: center; gap: 8px; transition: all 0.3s; 
    box-shadow: 0 2px 10px rgba(0,0,0,0.2); box-sizing: border-box; 
}
#video-container.is-fullscreen #fullscreen-chat-wrap { display: flex; }
#fullscreen-chat-wrap:hover, #fullscreen-chat-wrap:focus-within { background: rgba(24, 24, 27, 0.7); border-color: rgba(232, 156, 34, 0.6); backdrop-filter: blur(8px); }
#fs-input { flex-grow: 1; background: transparent; border: none; color: #efeff1; outline: none; font-size: 0.95em; padding: 8px 0; min-width: 0; }
#fs-input::placeholder { color: rgba(255,255,255,0.5); }
#fs-input:disabled { cursor: not-allowed; opacity: 0.6; }

#fs-emote-picker { 
    position: absolute; bottom: calc(100% + 15px); right: 0; 
    background: rgba(24, 24, 27, 0.95); backdrop-filter: blur(8px); 
    border: 1px solid #3a3a3d; border-radius: 8px; padding: 10px; display: none; 
    grid-template-columns: repeat(4, 1fr); gap: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.6); 
    max-height: 200px; overflow-y: auto; box-sizing: border-box;
    z-index: 2147483647 !important; 
}

#chat-container { flex: 1; display: flex; flex-direction: column; border-left: 1px solid #222224; background-color: #18181b; min-width: 0; min-height: 0; }
#chat-header { padding: 15px; background-color: #18181b; border-bottom: 1px solid #222224; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 1px 2px rgba(0,0,0,0.5); z-index: 5; }

#pseudo-wrapper { display: flex; align-items: center; background: #1f1f23; border-radius: 4px; border: 1px solid #3a3a3d; padding: 4px 8px; transition: border-color 0.2s; cursor: pointer; }
#pseudo-wrapper:focus-within { border-color: #e89c22; }
#pseudo { border: none; background: transparent; color: #efeff1; width: 100px; font-weight: bold; outline: none; font-size: 0.9em; cursor: text; }
#pseudo::placeholder { color: #adadb8; font-weight: normal; }
#pseudo.locked { color: #adadb8; cursor: pointer; }

#edit-pseudo-btn { background: none; border: none; cursor: pointer; display: none; align-items: center; padding: 2px 4px; border-radius: 4px; margin-left: 5px; transition: background 0.2s; }
#edit-pseudo-btn:hover { background: #3a3a3d; }
#edit-pseudo-btn svg { fill: #adadb8; transition: fill 0.2s; width: 16px; height: 16px; }
#edit-pseudo-btn:hover svg { fill: #efeff1; }

#messages { flex-grow: 1; list-style-type: none; margin: 0; padding: 10px 15px; overflow-y: auto; font-size: 0.95em; line-height: 1.4; scroll-behavior: smooth; }
#messages li { margin-bottom: 6px; word-wrap: break-word; transition: background 0.3s, border-color 0.3s; border-left: 3px solid transparent; padding-left: 5px; }
.username { font-weight: bold; color: #ffb74d; margin-right: 5px; transition: color 0.3s; }
.emote { height: 28px; vertical-align: middle; margin: -4px 1px 0 1px; }

.mention-highlight { background-color: rgba(232, 156, 34, 0.1); border-left-color: #e89c22 !important; border-radius: 0 4px 4px 0; }
.mention-tag { color: #e89c22; font-weight: bold; background: rgba(232, 156, 34, 0.2); padding: 0 4px; border-radius: 4px; }

.history-loader { text-align: center; color: #adadb8; font-size: 0.85em; font-style: italic; padding: 10px 0; }
.history-end { text-align: center; color: #adadb8; font-size: 0.8em; font-style: italic; opacity: 0.5; padding: 10px 0; }

#chat-form { padding: 15px; background: #18181b; position: relative; }
.chat-input-wrapper { display: flex; align-items: center; background: #3a3a3d; border-radius: 6px; padding: 5px 10px; border: 2px solid transparent; transition: border-color 0.2s, background 0.2s; gap: 5px;}
.chat-input-wrapper:focus-within { border-color: #e89c22; background: #000; }
.chat-input-wrapper input { flex-grow: 1; border: none; background: transparent; color: #efeff1; padding: 8px 0; outline: none; font-size: 0.95em; min-width: 0; }
.chat-input-wrapper input::placeholder { color: #adadb8; }
.chat-input-wrapper input:disabled { cursor: not-allowed; opacity: 0.6; }

.emote-btn { background: none; border: none; color: #efeff1; cursor: pointer; padding: 5px; border-radius: 4px; display: flex; align-items: center; justify-content: center; transition: background 0.2s; flex-shrink: 0;}
.emote-btn:hover { background: #464649; }
.emote-btn svg { fill: #adadb8; width: 20px; height: 20px; transition: fill 0.2s; }
.emote-btn:hover svg { fill: #efeff1; }

#emote-picker { position: absolute; bottom: 70px; right: 15px; background: #18181b; border: 1px solid #3a3a3d; border-radius: 6px; padding: 10px; display: none; grid-template-columns: repeat(4, 1fr); gap: 10px; box-shadow: 0 4px 10px rgba(0,0,0,0.5); z-index: 100; max-height: 200px; overflow-y: auto; }
.emote-picker-item { cursor: pointer; display: flex; justify-content: center; align-items: center; padding: 5px; border-radius: 4px; transition: background 0.2s, transform 0.1s; }
.emote-picker-item:hover { background: #3a3a3d; transform: scale(1.1); }
.emote-picker-item img { max-width: 28px; max-height: 28px; }

@media (hover: none) {
    #video-container:hover #video-controls { opacity: 0; pointer-events: none; }
    #video-container.show-controls #video-controls { opacity: 1; pointer-events: auto; }
}

@media screen and (max-width: 850px) {
    body { flex-direction: column; }
    #video-container { flex: none; width: 100%; height: auto; aspect-ratio: 16 / 9; max-height: 40vh; }
    #chat-container { flex: 1; width: 100%; min-width: 0; min-height: 0; border-left: none; border-top: 1px solid #222224; }
    #chat-header { padding: 10px; }
    .unmute-overlay svg { width: 48px; height: 48px; }
    .unmute-overlay span { font-size: 1.4em; }

    #video-controls { bottom: 5px; right: 5px; left: auto; transform: scale(0.85); transform-origin: bottom right; gap: 8px; flex-wrap: nowrap; }
    
    #video-container.is-fullscreen #video-controls { bottom: 85px; }
    #video-container.is-fullscreen.danmaku-off #video-controls { bottom: calc(20px + env(safe-area-inset-bottom)); } 
    
    #quality-dropdown .dropdown-menu { left: auto; right: 0; transform: none; }
    
    .volume-slider-wrapper {
        position: absolute !important;
        bottom: 50px !important; 
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: 44px !important;
        height: 140px !important;
        background: rgba(18, 18, 20, 0.6) !important;
        backdrop-filter: blur(12px) !important;
        border: 1px solid rgba(58, 58, 61, 0.5) !important;
        border-radius: 8px !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        box-shadow: 0 4px 15px rgba(0,0,0,0.5) !important;
        margin: 0 !important;
    }
    
    #volume-slider {
        transform: rotate(-90deg) !important;
        width: 100px !important;
        height: 4px !important;
        margin: 0 !important;
        position: absolute !important; 
        transform-origin: center center !important;
    }

    .danmaku-msg { font-size: 0.75em; }
    
    #fullscreen-chat-wrap { width: 90%; bottom: 30px; }
    #emote-picker { right: 10px; left: 10px; bottom: 70px; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); }
    #fs-emote-picker { right: 50%; transform: translateX(50%); width: 280px; }
}

@media screen and (max-width: 850px) and (orientation: portrait) {
    #video-container.is-fullscreen.danmaku-off #video-controls { bottom: calc(65px + env(safe-area-inset-bottom)); }
}

@media screen and (max-width: 950px) and (orientation: landscape) {
    body { flex-direction: row; }
    #video-container { flex: 1; height: 100dvh; max-height: none; }
    #chat-container { flex: none; width: 35vw; min-width: 250px; border-top: none; border-left: 1px solid #222224; }
}