/* =========================================
   1. VARIABLES & RESET
   ========================================= */
:root {
    --brand-color: #8b5cf6;
    --brand-gradient: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
    --glass-bg: rgba(20, 20, 20, 0.6);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-blur: blur(12px);
    --text-main: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.6);
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4);
}

/* =========================================
   2. UTILITIES & ANIMATIONS
   ========================================= */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--brand-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { transform: translateX(-50%) translateY(20px); opacity: 0; } to { transform: translateX(-50%) translateY(0); opacity: 1; } }
@keyframes slideDown { from { transform: translateX(-50%) translateY(-20px); opacity: 0; } to { transform: translateX(-50%) translateY(0); opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes scaleIn { from { transform: translate(-50%, -50%) scale(0.8); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
@keyframes toastSlideIn { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastFadeOut { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-10px); visibility: hidden; } }
@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* =========================================
   3. BUTTONS & INPUTS
   ========================================= */
.btn-icon-glass, .btn-icon-small, .modal-close {
    appearance: none;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: #eee;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-icon-glass { width: 36px; height: 36px; backdrop-filter: blur(8px); }
.btn-icon-small { padding: 6px; }
.modal-close { width: 32px; height: 32px; position: absolute; top: 20px; right: 20px; background: rgba(255, 255, 255, 0.1); }

.btn-icon-glass:hover, .btn-icon-small:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
    color: white;
}
.modal-close:hover { background: rgba(255, 255, 255, 0.3); transform: rotate(90deg); }

.btn-glass-primary {
    display: flex; align-items: center; gap: 8px;
    background: rgba(139, 92, 246, 0.25);
    border: 1px solid rgba(139, 92, 246, 0.4);
    color: white;
    padding: 0 16px; height: 36px;
    border-radius: 10px; font-weight: 600; font-size: 0.9rem;
    cursor: pointer; backdrop-filter: blur(8px);
    transition: all 0.2s;
}
.btn-glass-primary:hover {
    background: rgba(139, 92, 246, 0.4);
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.2);
    transform: translateY(-1px);
}

.btn-confirm, .btn-primary {
    background: var(--brand-color);
    border: none; color: white;
    padding: 10px 24px; border-radius: 10px;
    font-weight: 700; cursor: pointer;
    transition: all 0.2s;
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-confirm:hover, .btn-primary:hover { background: #7c3aed; transform: translateY(-2px); }
.btn-confirm:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-confirm.full-width { width: 100%; }

.btn-cancel {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.8);
    padding: 10px 20px; border-radius: 8px;
    cursor: pointer; font-weight: 600;
    transition: all 0.2s;
}
.btn-cancel:hover { background: rgba(255, 255, 255, 0.1); color: white; }

.btn-quick-action {
    display: flex; align-items: center; gap: 6px;
    height: 34px; padding: 0 12px;
    background: rgba(139, 92, 246, 0.15);
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: 8px; color: #d8b4fe;
    font-size: 0.85rem; font-weight: 600;
    cursor: pointer; transition: all 0.2s;
}
.btn-quick-action:hover {
    background: var(--brand-color); border-color: var(--brand-color);
    color: white; transform: translateY(-1px);
}
#copy-invite-btn { transition: all 0.3s ease; }
#copy-invite-btn:hover { transform: scale(1.05); }
#copy-invite-btn:active { transform: scale(0.95); }

/* Inputs */
input[type="text"], input[type="password"], input[type="number"], .form-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white; padding: 12px 16px;
    border-radius: 10px; font-size: 1rem;
    outline: none; transition: border-color 0.2s;
}
input:focus, .form-input:focus { border-color: var(--brand-color); background: rgba(255, 255, 255, 0.08); }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

/* Custom Select Wrappers */
.quick-select-wrapper {
    position: relative; display: flex; align-items: center;
    height: 34px; background: rgba(255, 255, 255, 0.03);
    border-radius: 8px; transition: all 0.2s;
    padding: 0 8px; min-width: 110px;
}
.quick-select-wrapper:hover { background: rgba(255, 255, 255, 0.08); }
.quick-select-wrapper svg { pointer-events: none; color: var(--text-muted); margin-right: 6px; flex-shrink: 0; }
.select-arrow { font-size: 0.6rem; color: rgba(255, 255, 255, 0.4); pointer-events: none; margin-left: 4px; }

.quick-select, .glass-select-sm {
    appearance: none; -webkit-appearance: none;
    background: transparent; border: none;
    color: #fff; width: 100%; height: 100%;
    cursor: pointer; outline: none; position: relative; z-index: 2;
}
.glass-select-sm {
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0 32px 0 12px; height: 32px; line-height: 30px;
    border-radius: 8px; font-size: 0.85rem; font-weight: 600;
    max-width: 140px; white-space: nowrap; text-overflow: ellipsis;
    background-image: url("data:image/svg+xml,..."); /* SVG truncated for brevity */
    background-repeat: no-repeat; background-position: right 8px center; background-size: 14px;
}
.quick-select option, .glass-select-sm option { background: #1a1a1a; color: #eee; }

/* =========================================
   4. LAYOUT
   ========================================= */
.room-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    height: 100vh; overflow: hidden;
    transition: grid-template-columns 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.room-layout.chat-hidden { grid-template-columns: 1fr 0px !important; }

/* Video Area */
.video-area {
    display: flex; flex-direction: column;
    background: #000; flex: 1; min-height: 0;
    overflow: hidden; position: relative;
}

/* =========================================
   5. HEADER
   ========================================= */
.room-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0 24px; height: 64px;
    background: rgba(10, 10, 10, 0.85); backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border);
    z-index: 20; flex-shrink: 0;
}

.header-left, .header-right { display: flex; align-items: center; gap: 16px; flex: 1; }
.header-right { justify-content: flex-end; }
.header-center { flex: 2; display: flex; justify-content: center; z-index: 50; }

.room-info { display: flex; flex-direction: column; justify-content: center; line-height: 1.2; }
#room-name { margin: 0; font-size: 1rem; font-weight: 700; color: white; letter-spacing: -0.01em; }
.np-fade { display: flex; align-items: center; opacity: 0.7; font-size: 0.8rem; gap: 6px; margin-top: 2px; }
.np-title { color: #ccc; font-weight: 500; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.np-sep { color: #555; }
.np-badge { background: rgba(255, 255, 255, 0.1); color: #fff; padding: 1px 6px; border-radius: 4px; font-size: 0.7rem; font-weight: 700; }

/* Header Controls */
.quick-controls-group {
    display: flex; align-items: center; gap: 4px;
    background: rgba(15, 15, 15, 0.85);
    backdrop-filter: blur(16px);
    padding: 4px; height: 44px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}
.quick-controls-group:hover { border-color: rgba(255, 255, 255, 0.2); box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3); }

.control-divider { width: 1px; height: 20px; background: rgba(255, 255, 255, 0.1); margin: 0 4px; }

/* Sub/Dub Toggle */
.sd-toggle.small {
    height: 34px; min-width: 86px;
    background: transparent; border: none;
    display: flex; position: relative; cursor: pointer; box-sizing: border-box;
    padding: 2px;
}
.sd-toggle.small .sd-bg {
    position: absolute; top: 2px; left: 2px;
    width: calc(50% - 2px); height: calc(100% - 4px);
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    transition: transform 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
}
.sd-toggle[data-state="dub"] .sd-bg { transform: translateX(100%); }
.sd-toggle.small .sd-option {
    flex: 1; z-index: 2;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 700;
    color: rgba(255,255,255,0.4);
    transition: color 0.2s; user-select: none;
}
.sd-toggle.small .sd-option.active { color: #fff; }

.viewers-pill {
    display: flex; align-items: center; gap: 6px;
    background: rgba(0,0,0,0.3); padding: 0 10px;
    border-radius: 20px; border: 1px solid rgba(255,255,255,0.05);
    font-size: 0.8rem; color: #aaa; height: 32px;
}

#toggle-chat-btn { position: relative; }
#toggle-chat-btn.has-unread::after {
    content: ''; position: absolute; top: 2px; right: 2px;
    width: 10px; height: 10px; background-color: #ef4444;
    border: 2px solid #1a1a1a; border-radius: 50%;
    animation: pulse 2s infinite;
}

/* =========================================
   6. PLAYER
   ========================================= */
.player-wrapper {
    display: flex !important; flex-direction: column; flex: 1;
    width: 100%; height: auto !important; min-height: 0;
    position: relative !important; z-index: 1 !important;
    background: transparent !important; overflow: hidden;
}
.player-container { width: 100%; height: 100%; display: flex; flex-direction: column; position: relative; }
.video-frame {
    flex: 1; min-height: 0; position: relative;
    background: #000; display: flex; align-items: center; justify-content: center;
}
#player { width: 100%; height: 100%; max-height: 100%; }
#subtitles-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 10; }

.custom-controls {
    position: absolute; bottom: 0; left: 0; width: 100%; z-index: 60;
    background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0) 100%);
    padding: 20px 10px 10px;
}
.controls-left { display: flex; align-items: center; gap: 10px; }
.time-display { white-space: nowrap; font-variant-numeric: tabular-nums; font-size: 0.9rem; color: #ddd; min-width: fit-content; }

/* Hidden Legacy Buttons */
#download-btn, #manual-match-btn, #server-select, #extension-select, #sd-toggle, .side-nav-btn { display: none !important; }

/* Settings Panel */
.settings-panel {
    position: absolute; bottom: 70px; right: 20px; z-index: 1000;
    max-height: 60vh; overflow-y: auto;
    background: rgba(15, 15, 15, 0.95);
    border: 1px solid var(--glass-border); border-radius: 8px;
}

/* Video Toasts */
.video-toast-container {
    position: absolute; bottom: 100px; left: 20px; z-index: 80;
    display: flex; flex-direction: column; gap: 10px;
    pointer-events: none; max-width: 400px;
}
.video-toast {
    display: flex; align-items: center; gap: 10px;
    background: rgba(15, 15, 15, 0.85); backdrop-filter: blur(8px);
    padding: 8px 12px; border-radius: 8px;
    border-left: 3px solid var(--brand-color);
    color: white; font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    animation: toastSlideIn 0.3s ease forwards, toastFadeOut 0.5s ease 4.5s forwards;
    pointer-events: auto; opacity: 0;
}
.toast-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.toast-content { display: flex; flex-direction: column; line-height: 1.2; }
.toast-user { font-weight: 700; font-size: 0.8rem; color: #a78bfa; }
.toast-msg { color: #eee; margin-top: 2px; }
.video-toast.system-toast {
    border-left-color: #9ca3af; background: rgba(20, 20, 20, 0.7);
    justify-content: center; padding: 6px 12px; min-height: auto;
}
.video-toast.system-toast .toast-msg { font-size: 0.85rem; font-style: italic; color: rgba(255, 255, 255, 0.8); margin: 0; }

/* =========================================
   7. CHAT SIDEBAR
   ========================================= */
.chat-sidebar {
    display: flex; flex-direction: column; height: 100%;
    background: rgba(15, 15, 15, 0.95);
    border-left: 1px solid var(--glass-border); overflow: hidden;
}
.room-layout.chat-hidden .chat-sidebar { opacity: 0; pointer-events: none; border-left: none; }

.chat-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px; border-bottom: 1px solid var(--glass-border);
}
.chat-header h3 { margin: 0; font-size: 1.1rem; font-weight: 700; color: white; }

.sidebar-tabs {
    display: flex; width: 100%; flex: 0 0 auto; height: 50px;
    border-bottom: 1px solid var(--glass-border); background: rgba(0,0,0,0.2);
}
.tab-btn {
    flex: 1; height: 100%; padding: 0;
    display: flex; align-items: center; justify-content: center;
    background: transparent; border: none; border-bottom: 2px solid transparent;
    color: var(--text-muted); font-weight: 600; cursor: pointer;
    transition: all 0.2s;
}
.tab-btn:hover { background: rgba(255,255,255,0.05); color: white; }
.tab-btn.active { border-bottom-color: var(--brand-color); color: white; background: rgba(255,255,255,0.02); }

.tab-content { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }

/* Users List */
.users-list {
    padding: 12px; border-bottom: 1px solid var(--glass-border);
    max-height: 200px; overflow-y: auto; background: rgba(0,0,0,0.2);
}
.user-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px; margin-bottom: 4px; }
.user-item:hover { background: rgba(255, 255, 255, 0.05); }
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--brand-gradient);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; color: white; font-size: 0.8rem;
}
.user-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.user-name { flex: 1; font-size: 0.9rem; color: white; }
.user-badge { font-size: 0.7rem; background: var(--brand-color); color: white; padding: 2px 8px; border-radius: 4px; font-weight: 600; }

/* Chat Messages */
.chat-messages {
    flex: 1; overflow-y: auto; padding: 16px;
    display: flex; flex-direction: column; gap: 12px; min-height: 0;
}
.chat-message { display: flex; gap: 10px; }
.chat-message.system { justify-content: center; margin: 8px 0; }
.chat-message.system .message-content {
    background: rgba(255, 255, 255, 0.05); color: var(--text-muted);
    font-size: 0.8rem; text-align: center; padding: 4px 12px; border-radius: 12px;
}
.message-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--brand-gradient);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; color: white; font-size: 0.9rem; flex-shrink: 0;
}
.message-body { flex: 1; min-width: 0; }
.message-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.message-username { font-weight: 600; color: white; font-size: 0.9rem; }
.message-time { font-size: 0.75rem; color: rgba(255, 255, 255, 0.4); }
.message-content { color: rgba(255, 255, 255, 0.9); font-size: 0.95rem; line-height: 1.4; word-wrap: break-word; }

.chat-input { display: flex; gap: 8px; padding: 16px; border-top: 1px solid var(--glass-border); }
.chat-input input {
    flex: 1; background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border); color: white;
    padding: 12px 16px; border-radius: 10px; outline: none;
}
.chat-input button {
    background: var(--brand-color); border: none; color: white;
    padding: 0 16px; border-radius: 10px; cursor: pointer; transition: background 0.2s;
}
.chat-input button:hover { background: #7c3aed; }

/* =========================================
   8. QUEUE TAB
   ========================================= */
.queue-list {
    flex: 1; overflow-y: auto; padding: 10px;
    display: flex; flex-direction: column; gap: 10px;
}
.queue-item {
    display: flex; gap: 10px; padding: 10px;
    background: rgba(255,255,255,0.05);
    border-radius: 8px; border: 1px solid transparent;
    position: relative; align-items: center; transition: transform 0.2s;
}
.queue-item:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.1); }
.q-img { width: 50px; height: 70px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.q-info { flex: 1; display: flex; flex-direction: column; justify-content: center; overflow: hidden; }
.q-title { font-weight: 700; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-meta { font-size: 0.8rem; color: #aaa; }
.q-actions { display: flex; flex-direction: column; gap: 4px; opacity: 0.7; transition: opacity 0.2s; }
.queue-item:hover .q-actions { opacity: 1; }

.q-btn {
    background: rgba(255,255,255,0.1); border: none; color: white;
    width: 28px; height: 28px; border-radius: 6px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.q-btn:hover { background: rgba(255,255,255,0.2); transform: scale(1.1); }
.q-btn.play:hover { background: var(--brand-color); }
.q-btn.remove:hover { background: #ff6b6b; }
.badge { background: var(--brand-color); padding: 1px 6px; border-radius: 10px; font-size: 0.7rem; margin-left: 6px; }
.queue-empty { text-align: center; color: #666; margin-top: 40px; font-style: italic; }

/* =========================================
   9. MODALS
   ========================================= */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.8); backdrop-filter: blur(8px);
    display: none; align-items: center; justify-content: center;
    z-index: 10000; opacity: 0; transition: opacity 0.3s ease;
}
.modal-overlay.show { display: flex; opacity: 1; }

.modal-content {
    background: rgba(20, 20, 20, 0.95);
    border: 1px solid var(--glass-border); border-radius: 16px;
    padding: 32px; max-width: 500px; width: 90%;
    position: relative; transform: scale(0.9); transition: transform 0.3s ease;
}
.modal-overlay.show .modal-content { transform: scale(1); }
.modal-title { margin: 0 0 24px 0; font-size: 1.5rem; font-weight: 800; color: white; }
.modal-header-row { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.modal-header-row .modal-title { margin: 0; }

.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 600; color: white; }
.form-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }

/* Join Info */
.join-host-info { display: flex; flex-direction: column; align-items: center; margin-bottom: 24px; animation: fadeIn 0.5s ease; }
.join-avatar-container {
    width: 80px; height: 80px; border-radius: 50%; padding: 3px;
    background: var(--brand-gradient); margin-bottom: 12px;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}
.join-avatar-container img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; border: 3px solid #1a1a1a; background: #2a2a2a; }
.join-text { font-size: 1.1rem; color: white; font-weight: 500; text-align: center; margin: 0; }
.join-text span { font-weight: 700; color: #a78bfa; }

/* Search Content */
.anime-search-content { max-width: 800px; max-height: 85vh; display: flex; flex-direction: column; }
.search-bar { display: flex; gap: 12px; margin-bottom: 20px; }
.search-bar button {
    background: var(--brand-color); border: none; color: white;
    padding: 12px 24px; border-radius: 10px; font-weight: 700; cursor: pointer;
}
.anime-results {
    flex: 1; overflow-y: auto; display: flex; flex-direction: column;
    gap: 12px; min-height: 0; max-height: 60vh; padding-right: 8px;
}
.anime-result-item, .search-item {
    display: flex; gap: 16px; padding: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 12px;
    cursor: pointer; text-decoration: none; color: inherit; transition: all 0.2s;
}
.anime-result-item:hover {
    background: rgba(255, 255, 255, 0.08); border-color: var(--brand-color);
    transform: translateX(4px);
}
.search-poster { width: 60px; height: 85px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.search-info { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.search-title { font-weight: 700; color: white; margin-bottom: 4px; font-size: 1rem; }
.search-meta { font-size: 0.85rem; color: var(--text-muted); }

/* Config Layout */
.config-layout { display: flex; gap: 24px; margin-top: 20px; }
.config-sidebar { width: 140px; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.config-cover {
    width: 100%; aspect-ratio: 2/3; object-fit: cover;
    border-radius: 12px; box-shadow: 0 8px 20px rgba(0,0,0,0.4);
    border: 1px solid var(--glass-border);
}
.config-main { flex: 1; display: flex; flex-direction: column; gap: 20px; }
.cfg-section-title {
    font-size: 0.85rem; text-transform: uppercase;
    letter-spacing: 1px; color: rgba(255,255,255,0.5);
    margin-bottom: 8px; font-weight: 700;
}

/* Chips & Toggles in Modal */
.chips-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
    padding: 8px 16px; background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 8px;
    color: #ccc; font-size: 0.9rem; cursor: pointer;
    transition: all 0.2s; user-select: none;
}
.chip:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.3); transform: translateY(-2px); }
.chip.active {
    background: var(--brand-color); border-color: var(--brand-color);
    color: white; box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}
.cat-toggle { display: flex; background: rgba(0,0,0,0.3); padding: 4px; border-radius: 10px; width: fit-content; }
.cat-opt {
    padding: 6px 16px; border-radius: 8px; font-size: 0.85rem; color: #888;
    cursor: pointer; transition: all 0.2s; font-weight: 600;
}
.cat-opt.active { background: rgba(255,255,255,0.15); color: white; }
.cat-opt.disabled { opacity: 0.3; pointer-events: none; text-decoration: line-through; }

/* Episodes Grid */
.episodes-grid-container {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 8px; max-height: 280px; overflow-y: auto; padding: 10px;
    background: rgba(0, 0, 0, 0.2); border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}
.episodes-grid-container::-webkit-scrollbar { width: 4px; }
.episodes-grid-container::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); }

.ep-grid-btn {
    background: rgba(255,255,255,0.03); border: 1px solid rgba(255, 255, 255, 0.1);
    color: #ccc; padding: 8px 0; border-radius: 6px; text-align: center;
    font-size: 0.9rem; font-weight: 600; cursor: pointer;
    transition: all 0.2s; user-select: none;
}
.ep-grid-btn:hover { background: white; color: black; transform: translateY(-2px); }
.ep-grid-btn.selected, .ep-grid-btn.active {
    background: var(--brand-color); color: white;
    border-color: var(--brand-color); box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.btn-text-tiny {
    background: transparent; border: none; color: var(--brand-color);
    font-size: 0.75rem; font-weight: 700; cursor: pointer; padding: 2px 6px;
}
.btn-text-tiny:hover { text-decoration: underline; }

/* Manual Control */
.ep-control {
    display: flex; align-items: center; justify-content: space-between;
    background: rgba(0, 0, 0, 0.4); border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px; padding: 4px; width: 100%; height: 48px;
    margin-top: 8px; box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}
.ep-btn {
    width: 40px; height: 38px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255,255,255,0.05);
    color: white; border-radius: 8px; cursor: pointer; font-size: 1.2rem; transition: all 0.2s ease;
}
.ep-btn:hover { background: var(--brand-color); border-color: var(--brand-color); transform: translateY(-1px); }
.ep-btn:active { transform: translateY(1px); }
.ep-input {
    flex: 1; min-width: 0; background: transparent; border: none;
    color: white; text-align: center; font-size: 1.2rem; font-weight: 800;
    outline: none; font-family: monospace;
}
.grid-loader { width: 100%; padding: 20px; text-align: center; color: var(--text-muted); font-size: 0.9rem; }

/* Modal Pagination */
.modal-pagination {
    display: flex; justify-content: center; align-items: center; gap: 15px;
    margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(255, 255, 255, 0.05);
}
.modal-page-btn {
    background: transparent; border: 1px solid rgba(255, 255, 255, 0.2);
    color: white; width: 30px; height: 30px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.2s;
}
.modal-page-btn:hover:not(:disabled) { background: white; color: black; }
.modal-page-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.modal-page-info { font-size: 0.85rem; color: #888; font-weight: 700; }

/* =========================================
   10. MEDIA QUERIES (Combined)
   ========================================= */
@media (max-width: 1200px) {
    .room-layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
    .room-layout.chat-hidden { grid-template-rows: 1fr 0px; }
    .chat-sidebar {
        height: 350px; border-left: none; border-top: 1px solid var(--glass-border);
    }
}

@media (max-width: 600px) {
    .config-layout { flex-direction: column; }
    .config-sidebar { width: 100%; flex-direction: row; }
    .config-cover { width: 80px; }
    .ep-control { width: auto; flex: 1; }
}

/* =========================================
   PERMISSIONS & MODERATION
   ========================================= */

.permissions-content {
    max-width: 700px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
}

.permissions-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 30px;
}

.permission-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    transition: all 0.2s;
}

.permission-card:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
}

.user-info-section {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 180px;
}

.user-avatar-small {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--brand-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: white;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.user-avatar-small img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.user-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.user-name-text {
    font-weight: 600;
    color: white;
    font-size: 0.95rem;
}

.guest-badge {
    font-size: 0.7rem;
    background: rgba(255, 255, 255, 0.1);
    color: #aaa;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
    width: fit-content;
}

.permissions-toggles {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.perm-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.perm-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--brand-color);
}

.perm-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.8);
    transition: color 0.2s;
}

.perm-toggle:hover .perm-label {
    color: white;
}

.perm-label svg {
    opacity: 0.6;
}

.ban-btn {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
    white-space: nowrap;
}

.ban-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: #ef4444;
    transform: translateY(-1px);
}

.banned-ips-section {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.section-title {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 12px;
    font-weight: 700;
}

.banned-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.banned-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: rgba(239, 68, 68, 0.05);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 8px;
}

.banned-ip {
    font-family: monospace;
    color: #ef4444;
    font-size: 0.9rem;
}

.unban-btn {
    background: transparent;
    border: 1px solid rgba(74, 222, 128, 0.3);
    color: #4ade80;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.unban-btn:hover {
    background: rgba(74, 222, 128, 0.1);
    border-color: #4ade80;
}

.empty-state {
    text-align: center;
    color: #666;
    font-style: italic;
    padding: 20px;
}

/* Responsive */
@media (max-width: 768px) {
    .permission-card {
        flex-direction: column;
        align-items: stretch;
    }

    .user-info-section {
        min-width: auto;
    }

    .ban-btn {
        width: 100%;
        justify-content: center;
    }
}