:root {
    --bg-main: #0e0e10;
    --bg-secondary: #18181b;
    --bg-glass: rgba(24, 24, 27, 0.95);
    --border-glass: #303032;
    --accent: #9146FF;
    --accent-hover: #a970ff;
    --text-main: #efeff1;
    --text-muted: #adadb8;
    --chat-bg: #18181b;
    --chat-width: 340px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body.spa-layout {
    background-color: var(--bg-main);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ================== Top Navigation ================== */
.top-nav {
    height: 50px;
    background: var(--bg-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
    border-bottom: 1px solid var(--border-glass);
    z-index: 100;
    box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.nav-left, .nav-center, .nav-right {
    display: flex;
    align-items: center;
    height: 100%;
}

.nav-left { gap: 1.5rem; flex: 1; }
.nav-center { flex: 2; justify-content: center; }
.nav-right { flex: 1; justify-content: flex-end; gap: 1rem; }

.nav-logo {
    display: flex;
    align-items: center;
    color: var(--accent);
    text-decoration: none;
    transition: transform 0.2s ease;
}
.nav-logo:hover { transform: scale(1.05); }

.nav-link {
    color: var(--text-main);
    text-decoration: none;
    font-weight: 600;
    font-size: 1.15rem;
    position: relative;
    padding: 0 0.5rem;
}
.nav-link.active {
    color: var(--accent);
}
.nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -13px;
    left: 0; right: 0;
    height: 2px;
    background: var(--accent);
}

.search-bar {
    position: relative;
    width: 100%;
    max-width: 400px;
    display: flex;
}
.search-bar input {
    width: 100%;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.1);
    color: white;
    padding: 0.4rem 0.8rem;
    border-radius: 6px 0 0 6px;
    outline: none;
    font-size: 0.9rem;
    transition: background 0.2s, border 0.2s;
}
.search-bar input:focus {
    background: black;
    border-color: var(--accent);
}
.search-bar button {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-left: none;
    color: var(--text-main);
    padding: 0 0.6rem;
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    transition: background 0.2s;
}
.search-bar button:hover { background: rgba(255,255,255,0.15); }

.nav-icon-btn {
    background: transparent;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
}
.nav-icon-btn:hover { background: rgba(255,255,255,0.1); }

.nav-btn-primary {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.nav-btn-primary:hover { background: var(--accent-hover); }

/* ================== Main Wrapper ================== */
.main-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ================== Left Sidebar ================== */
.left-sidebar {
    width: 240px;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: width 0.2s ease;
    flex-shrink: 0;
}
.left-sidebar.collapsed {
    width: 50px;
}

.left-sidebar::-webkit-scrollbar { width: 6px; }
.left-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 10px;
}
.sidebar-header h4 { font-size: 0.8rem; text-transform: uppercase; color: var(--text-muted); }
.left-sidebar.collapsed .sidebar-header h4 { display: none; }
.sidebar-header button {
    background: transparent; border: none; color: var(--text-main); cursor: pointer; padding: 4px; border-radius: 4px;
}
.sidebar-header button:hover { background: rgba(255,255,255,0.1); }

.sidebar-section {
    margin-bottom: 1rem;
}
.sidebar-title {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0 10px;
    margin-bottom: 5px;
}
.left-sidebar.collapsed .sidebar-title { display: none; }

.sidebar-list {
    display: flex;
    flex-direction: column;
}
.sidebar-item {
    display: flex;
    align-items: center;
    padding: 5px 10px;
    cursor: pointer;
    text-decoration: none;
    color: var(--text-main);
}
.sidebar-item:hover { background: rgba(255,255,255,0.05); }

.sidebar-avatar {
    width: 30px; height: 30px; border-radius: 50%; background: #333; margin-right: 10px; flex-shrink:0;
    object-fit: cover;
}
.left-sidebar.collapsed .sidebar-avatar { margin-right: 0; }

.sidebar-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}
.left-sidebar.collapsed .sidebar-info { display: none; }

.sidebar-name { font-size: 0.9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-category { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-right {
    display: flex; align-items: center; gap: 4px; font-size: 0.8rem;
}
.left-sidebar.collapsed .sidebar-right { display: none; }
.live-dot { width: 8px; height: 8px; background: red; border-radius: 50%; }

/* ================== Content Area ================== */
.content-area {
    flex: 1;
    position: relative;
    overflow-y: auto;
    background: var(--bg-main);
}
.content-area::-webkit-scrollbar { width: 8px; }
.content-area::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }

.view-container {
    width: 100%;
    min-height: 100%;
}
.view-container.hidden { display: none !important; }

/* Home View */
.hero-banner {
    background: linear-gradient(135deg, #18181b 0%, #0e0e10 100%);
    padding: 3rem 2rem;
    border-bottom: 1px solid var(--border-glass);
}
.hero-content h1 { font-size: 2.5rem; margin-bottom: 0.5rem; }
.hero-content p { color: var(--text-muted); font-size: 1.1rem; }

.home-sections { padding: 2rem; }
.section-title { margin-bottom: 1rem; font-size: 1.2rem; }

.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}
.video-card {
    cursor: pointer;
    transition: transform 0.2s;
}
.video-card:hover { transform: translateY(-4px); }
.video-card-thumb-wrap { position: relative; aspect-ratio: 16/9; background: #222; overflow: hidden; }
.video-card-thumb { width: 100%; height: 100%; object-fit: cover; }
.video-card-badge { position: absolute; top: 10px; left: 10px; background: red; color: white; padding: 2px 6px; font-size: 0.75rem; border-radius: 4px; font-weight: bold; }
.video-card-info { display: flex; margin-top: 10px; gap: 10px; }
.video-card-avatar { width: 40px; height: 40px; border-radius: 50%; }
.video-card-text { flex: 1; min-width: 0; }
.video-card-title { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 2px; }
.video-card-channel { font-size: 0.85rem; color: var(--text-muted); }
.video-card-category { font-size: 0.85rem; color: var(--text-muted); }

/* Player View */
.player-wrapper { display: flex; flex-direction: column; height: 100%; }
.player-container {
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    position: relative;
    max-height: calc(100vh - 50px - 80px); /* Leave room for info bar */
}

body.theater-mode .player-container { height: 100vh; max-height: 100vh; aspect-ratio: auto; }
body.theater-mode .channel-info-bar { display: none; }
body.theater-mode .top-nav { display: none; }
body.theater-mode .left-sidebar { display: none; }

video { width: 100%; height: 100%; object-fit: contain; }

.video-controls {
    position: absolute; bottom: 0; left: 0; right: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.9), transparent);
    padding: 2rem 1rem 1rem 1rem;
    display: flex; flex-direction: column; gap: 0.5rem;
    opacity: 0; transition: opacity 0.2s;
}
.player-container:hover .video-controls { opacity: 1; }

.progress-area { padding-bottom: 10px; }
.progress-container { position: relative; height: 5px; background: rgba(255,255,255,0.2); cursor: pointer; border-radius: 2px; }
.progress-bar { position: absolute; height: 100%; background: var(--accent); border-radius: 2px; width: 0%; pointer-events:none; }
.progress-buffer { position: absolute; height: 100%; background: rgba(255,255,255,0.4); border-radius: 2px; width: 0%; pointer-events:none; }
.progress-container:hover { height: 8px; }

.controls-bottom { display: flex; justify-content: space-between; align-items: center; }
.controls-left, .controls-right { display: flex; align-items: center; gap: 10px; }
.control-btn { background: transparent; border: none; color: white; cursor: pointer; padding: 5px; }
.control-btn:hover { color: var(--accent); }
.time-display { font-size: 0.85rem; font-family: monospace; }
.live-indicator { background: red; padding: 2px 6px; border-radius: 4px; font-weight: bold; font-family: sans-serif; font-size: 0.75rem; margin-right: 5px;}

.player-select { background: rgba(0,0,0,0.7); border: 1px solid rgba(255,255,255,0.2); color: white; border-radius: 4px; padding: 2px 5px; }

/* Info Bar */
.channel-info-bar {
    display: flex; align-items: center; padding: 1rem 2rem; background: var(--bg-main); border-bottom: 1px solid var(--border-glass);
    gap: 1rem;
    flex-wrap: wrap;
}
.channel-avatar { width: 64px; height: 64px; border-radius: 50%; margin-right: 5px; border: 2px solid var(--accent); cursor: pointer; transition: transform 0.2s; flex-shrink: 0; }
.channel-avatar:hover { transform: scale(1.05); }
.channel-meta { flex: 1; min-width: 0; }
.channel-meta h2 { font-size: 1.2rem; font-weight: 700; cursor: pointer; transition: color 0.2s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-meta h2:hover { color: var(--accent); }
.channel-meta p { color: var(--text-muted); font-size: 0.9rem; margin-top: 2px; }
.category-link { color: var(--accent) !important; font-weight: 600; cursor: pointer; }
.channel-actions { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }

/* ================== Follow Button ================== */
.btn-follow {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.5rem 1.2rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    border: 2px solid var(--accent);
    background: transparent;
    color: var(--accent);
    transition: all 0.18s ease;
    white-space: nowrap;
    letter-spacing: 0.01em;
}
.btn-follow:hover {
    background: var(--accent);
    color: #fff;
    transform: scale(1.04);
    box-shadow: 0 4px 18px rgba(145,70,255,0.35);
}
.btn-follow--following {
    background: rgba(145,70,255,0.15);
    color: var(--accent);
    border-color: var(--accent);
}
.btn-follow--following:hover {
    background: rgba(220,38,38,0.15);
    border-color: #ef4444;
    color: #ef4444;
    box-shadow: 0 4px 18px rgba(220,38,38,0.2);
}
.btn-follow--outline {
    background: transparent;
    color: var(--text-muted);
    border-color: rgba(255,255,255,0.2);
}
.btn-follow--outline:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 4px 18px rgba(145,70,255,0.35);
}

/* ================== Right Sidebar (Chat) ================== */
.right-sidebar {
    width: var(--chat-width);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-glass);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.2s ease, margin-right 0.2s ease;
}
.right-sidebar.collapsed {
    margin-right: calc(var(--chat-width) * -1);
}
#expand-chat-btn {
    position: absolute; right: 10px; top: 60px; z-index: 100;
    background: var(--bg-secondary); border: 1px solid var(--border-glass);
    color: var(--text-main); padding: 5px; border-radius: 4px; cursor: pointer;
}
#expand-chat-btn:hover { background: rgba(255,255,255,0.1); }
body.theater-mode #expand-chat-btn { top: 10px; }
.chat-header {
    display: flex; align-items: center; padding: 10px; border-bottom: 1px solid var(--border-glass);
}
.chat-header h4 { font-size: 0.8rem; flex: 1; text-align: center; }
.chat-header button { background: transparent; border: none; color: var(--text-main); cursor: pointer;}
.chat-messages {
    flex: 1; overflow-y: auto; padding: 10px; font-size: 0.85rem; line-height: 1.4; display: flex; flex-direction: column; gap: 5px;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }
.chat-input-container {
    padding: 15px 10px; border-top: 1px solid var(--border-glass);
}
#chat-form { display: flex; flex-direction: column; gap: 10px; }
#chat-input-field { background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); color: white; padding: 8px; border-radius: 4px; outline: none;}
#chat-input-field:focus { border-color: var(--accent); background: black; }
#chat-send-btn { background: var(--accent); color: white; border: none; padding: 8px; border-radius: 4px; font-weight: bold; cursor: pointer; }

.chat-msg { word-wrap: break-word; }
.chat-author { font-weight: 700; margin-right: 5px; }

/* Modals & Overlays */
.overlay { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.8); display: flex; align-items: center; justify-content: center; z-index: 10; }
.hidden { display: none !important; }
.spinner { width: 40px; height: 40px; border: 4px solid rgba(255,255,255,0.1); border-top: 4px solid var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
.loader-spinner { width: 36px; height: 36px; border: 3px solid rgba(255,255,255,0.1); border-top: 3px solid var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 3rem auto; }
@keyframes spin { 100% { transform: rotate(360deg); } }
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.8); z-index: 200; display: flex; align-items: center; justify-content: center;}
.modal-box { background: var(--bg-secondary); border: 1px solid var(--border-glass); border-radius: 8px; padding: 30px; width: 400px; max-width: 90%; position: relative; }
.modal-close { position: absolute; top: 15px; right: 20px; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); }

/* Buttons */
.btn-primary { background: var(--accent); color: white; border: none; padding: 8px 18px; border-radius: 6px; cursor: pointer; font-weight: 700; font-size: 0.9rem; transition: background 0.18s, transform 0.15s; display: inline-flex; align-items: center; gap: 0.4rem; }
.btn-primary:hover { background: var(--accent-hover); transform: scale(1.03); }
.btn-primary-sm { background: var(--accent); color: white; border: none; padding: 5px 12px; border-radius: 4px; cursor: pointer; font-size: 0.8rem; font-weight: 600; }
.btn-secondary { background: transparent; border: 1px solid rgba(255,255,255,0.25); color: var(--text-main); padding: 8px 18px; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 0.9rem; transition: all 0.18s; display: inline-flex; align-items: center; gap: 0.4rem; }
.btn-secondary:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.4); }
.btn-ghost-sm { background: transparent; border: 1px solid var(--border-glass); color: white; padding: 5px 10px; border-radius: 4px; cursor: pointer; font-size: 0.8rem; transition: background 0.18s; }
.btn-ghost-sm:hover { background: rgba(255,255,255,0.08); }

/* Utility */
.search-dropdown { position: absolute; top: 100%; left: 0; right: 0; background: var(--bg-secondary); border: 1px solid var(--border-glass); border-radius: 0 0 6px 6px; max-height: 300px; overflow-y: auto; z-index: 50; margin-top: 5px;}
.search-item { padding: 10px; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.search-item:hover { background: rgba(255,255,255,0.05); }

/* ================== Channel View ================== */
.channel-banner-container {
    position: relative;
    width: 100%;
}
.channel-page-banner {
    width: 100%;
    height: 250px;
    background-color: var(--bg-secondary);
    background-size: cover;
    background-position: center;
}
.channel-page-header {
    display: flex;
    align-items: flex-end;
    padding: 0 2rem;
    margin-top: -40px;
    margin-bottom: 2rem;
    position: relative;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.channel-page-avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 4px solid var(--bg-main);
    background: var(--bg-secondary);
    margin-right: 20px;
    object-fit: cover;
}
.channel-page-meta {
    flex: 1;
    margin-bottom: 10px;
}
.channel-page-meta h1 {
    font-size: 2rem;
    font-weight: 700;
}
.channel-page-actions {
    margin-bottom: 10px;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.text-muted {
    color: var(--text-muted);
}
.video-card-thumb-wrap .continue-progress-bar { position: absolute; bottom: 0; left: 0; height: 4px; background: var(--accent); }

/* Chat Input Wrapper */
.chat-input-wrapper {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
}

#chat-input-field {
    flex: 1;
    padding-right: 40px !important;
}

#emote-picker-toggle {
    position: absolute;
    right: 10px;
    cursor: pointer;
    font-size: 1.2rem;
    user-select: none;
    transition: transform 0.2s;
    z-index: 10;
}

#emote-picker-toggle:hover {
    transform: scale(1.2);
}

/* Emote Picker Menu */
#emote-picker-menu {
    position: absolute;
    bottom: 100%;
    right: 0;
    width: 300px;
    max-height: 400px;
    background: #18181b;
    border: 1px solid #333;
    border-radius: 8px;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    z-index: 1000;
}

#emote-picker-menu.hidden {
    display: none;
}

.emote-picker-header {
    padding: 10px;
    font-weight: bold;
    font-size: 0.85rem;
    border-bottom: 1px solid #333;
    color: #efeff1;
    background: #1f1f23;
    border-radius: 8px 8px 0 0;
}

.emote-list-grid {
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 8px;
    overflow-y: auto;
    max-height: 350px;
}

.emote-item {
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.emote-item:hover {
    background: rgba(255,255,255,0.1);
}

.emote-item img {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

/* Scrollbar for Emote Menu */
.emote-list-grid::-webkit-scrollbar {
    width: 6px;
}
.emote-list-grid::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 3px;
}

.chat-badge {
    width: 18px;
    height: 18px;
    vertical-align: middle;
    margin-right: 4px;
    border-radius: 2px;
}
