*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --font-head: 'Plus Jakarta Sans', system-ui, sans-serif;
    --font-body: 'Inter', system-ui, sans-serif;
    --bg: #0e0e13;
    --surface-low: #131319;
    --surface: #19191f;
    --surface-high: #1f1f26;
    --surface-highest: #25252d;
    --surface-bright: #2c2b33;
    --text: #f9f5fd;
    --text-dim: #acaab1;
    --text-muted: #76747b;
    --accent: #aca3ff;
    --accent-dim: #6f5fea;
    --accent-deep: #6c5ce7;
    --accent-secondary: #b190fe;
    --accent-chat: #ff9eca;
    --ghost: rgba(72, 71, 77, 0.15);
    --radius: 8px;
    --radius-lg: 12px;
    --tg-blue: #2AABEE;
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

.screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    z-index: 100;
}

.loader-wrap { text-align: center; }

.spinner {
    width: 32px;
    height: 32px;
    border: 2.5px solid var(--surface-bright);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 0 auto 12px;
}

.loader-text {
    font-size: 0.85rem;
    color: var(--text-dim);
    font-family: var(--font-body);
}

.error-wrap { text-align: center; padding: 24px; }
.error-icon { font-size: 2.5rem; margin-bottom: 12px; }
.error-msg { font-size: 0.95rem; color: var(--text-dim); }

.player-screen {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.room-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--surface-low);
    flex-shrink: 0;
    z-index: 10;
}

.room-title-wrap {
    flex: 1;
    min-width: 0;
}

.room-title {
    font-family: var(--font-head);
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    color: var(--text);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    margin-left: 12px;
}

.header-icon-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    padding: 6px;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, background 0.15s;
}

.header-icon-btn:hover {
    color: var(--text);
    background: var(--surface-high);
}

.header-icon-btn:active {
    color: var(--accent);
}

.video-wrap {
    flex-shrink: 0;
    background: #000;
    position: relative;
    max-height: 38vh;
}

.video-wrap .plyr { width: 100%; height: 100%; }
.video-wrap .plyr__video-wrapper { height: 100%; display: flex; align-items: center; }
.video-wrap video { width: 100%; max-height: 100%; object-fit: contain; }

.watching-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(14, 14, 19, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-family: var(--font-body);
    color: var(--text-dim);
    z-index: 5;
    pointer-events: none;
}

.watching-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.fs-chat-notifs {
    position: absolute;
    bottom: 60px;
    left: 12px;
    right: 80px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 10;
    pointer-events: none;
}

.fs-chat-pill {
    background: rgba(14, 14, 19, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 6px 12px;
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 0.78rem;
    color: var(--text);
    line-height: 1.35;
    animation: fs-slide-in 0.3s cubic-bezier(0.33, 1, 0.68, 1);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fs-chat-pill-user {
    font-weight: 600;
    color: var(--accent-chat);
    margin-right: 6px;
    font-family: var(--font-head);
    font-size: 0.72rem;
}

.fs-chat-pill.hiding {
    opacity: 0;
    transition: opacity 0.3s;
}

@keyframes fs-slide-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.tabs {
    display: flex;
    flex-shrink: 0;
    background: var(--surface-low);
    padding: 0 16px;
    gap: 24px;
}

.tab {
    padding: 10px 0;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-head);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    position: relative;
    transition: color 0.2s;
}

.tab.active { color: var(--accent); }

.tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 3px;
    background: var(--accent);
    border-radius: 3px;
}

.tab-count {
    display: inline-block;
    background: var(--surface-high);
    color: var(--text-dim);
    font-size: 0.68rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: 4px;
    font-family: var(--font-body);
}

.tab-panel {
    display: none;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: var(--bg);
}

.tab-panel.active {
    display: flex;
    flex-direction: column;
}

.queue-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.queue-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.2s cubic-bezier(0.33, 1, 0.68, 1), padding-left 0.2s;
}

.queue-item:hover {
    background: rgba(108, 92, 231, 0.05);
    padding-left: 20px;
}

.queue-item.active {
    background: rgba(108, 92, 231, 0.08);
}

.queue-item-index {
    font-family: var(--font-head);
    font-size: 0.78rem;
    color: var(--text-muted);
    min-width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.queue-item.active .queue-item-index { display: none; }

.queue-eq {
    display: none;
    align-items: flex-end;
    gap: 2px;
    width: 20px;
    height: 16px;
    flex-shrink: 0;
    justify-content: center;
}

.queue-item.active .queue-eq { display: flex; }

.queue-eq-bar {
    width: 3px;
    background: var(--accent);
    border-radius: 1px;
    animation: eq-bounce 0.8s ease-in-out infinite;
}

.queue-eq-bar:nth-child(1) { height: 60%; animation-delay: 0s; }
.queue-eq-bar:nth-child(2) { height: 100%; animation-delay: 0.15s; }
.queue-eq-bar:nth-child(3) { height: 40%; animation-delay: 0.3s; }

@keyframes eq-bounce {
    0%, 100% { transform: scaleY(0.3); }
    50% { transform: scaleY(1); }
}

.queue-item-info { flex: 1; min-width: 0; }

.queue-item-name {
    font-size: 0.82rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
}

.queue-item.active .queue-item-name {
    font-weight: 600;
    color: #fff;
}

.queue-item-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
    font-family: var(--font-head);
}

.queue-item-badge {
    display: none;
    padding: 2px 8px;
    background: var(--accent-deep);
    color: #fff;
    font-family: var(--font-head);
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    border-radius: 4px;
    flex-shrink: 0;
}

.queue-item.active .queue-item-badge { display: block; }

.queue-item-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius);
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
    flex-shrink: 0;
}

.queue-item:hover .queue-item-remove { opacity: 1; }
.queue-item-remove:hover { color: #ff6e84; }
.queue-item.active .queue-item-remove { display: none; }

.queue-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px 8px;
    flex-shrink: 0;
}

.queue-heading {
    font-family: var(--font-head);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--text-dim);
}

.queue-hint {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    flex-shrink: 0;
}

.queue-hint-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--surface-high);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--text-muted);
    transition: background 0.2s, color 0.2s;
}

.queue-hint-icon:hover {
    background: var(--accent-deep);
    color: #fff;
}

.queue-hint span {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.queue-hint-bot {
    color: var(--accent);
    font-weight: 600;
}

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

.autoplay-toggle input { display: none; }

.autoplay-slider {
    width: 32px;
    height: 18px;
    background: var(--surface-bright);
    border-radius: 10px;
    position: relative;
    transition: background 0.2s;
}

.autoplay-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: var(--text-dim);
    border-radius: 50%;
    transition: transform 0.2s, background 0.2s;
}

.autoplay-toggle input:checked + .autoplay-slider {
    background: var(--accent-deep);
}

.autoplay-toggle input:checked + .autoplay-slider::after {
    transform: translateX(14px);
    background: #fff;
}

.autoplay-label {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-dim);
}

.viewers-strip {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--surface-low);
    overflow-x: auto;
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
}

.viewers-strip::-webkit-scrollbar { display: none; }

.viewer-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
}

.viewer-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-head);
    font-size: 0.72rem;
    font-weight: 700;
    color: #fff;
    text-transform: uppercase;
}

.viewer-name {
    font-size: 0.62rem;
    color: var(--text-dim);
    max-width: 48px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-msg {
    font-size: 0.82rem;
    line-height: 1.45;
    word-break: break-word;
}

.chat-msg-user {
    font-weight: 600;
    color: var(--accent-chat);
    margin-right: 6px;
    font-family: var(--font-head);
    font-size: 0.75rem;
}

.chat-msg-system {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-align: center;
    padding: 4px 0;
}

.chat-input-bar {
    display: flex;
    gap: 8px;
    padding: 8px 16px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    background: var(--surface-low);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    padding: 9px 14px;
    background: var(--surface-high);
    border: 1px solid var(--ghost);
    border-radius: var(--radius-lg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.82rem;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: rgba(108, 92, 231, 0.4);
}

.chat-input::placeholder {
    color: var(--text-muted);
}

.chat-send {
    padding: 9px 14px;
    background: linear-gradient(135deg, var(--accent), var(--accent-dim));
    color: #fff;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: opacity 0.15s;
}

.chat-send:active { opacity: 0.8; }

.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(14, 14, 19, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text);
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-family: var(--font-body);
    z-index: 200;
    pointer-events: none;
    transition: opacity 0.2s;
}

.toast.hiding { opacity: 0; }

@keyframes spin {
    to { transform: rotate(360deg); }
}

.plyr {
    --plyr-color-main: var(--accent-deep);
    --plyr-video-background: #000;
    --plyr-range-fill-background: var(--accent-deep);
    width: 100%;
}

.plyr__controls {
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8)) !important;
}

.plyr__control:hover {
    background: var(--accent-deep) !important;
}

@media (max-width: 380px) {
    .room-header { padding: 8px 12px; }
    .queue-item { padding: 8px 12px; }
    .chat-messages { padding: 8px 12px; }
    .chat-input-bar { padding: 8px 12px; }
    .tabs { padding: 0 12px; }
}
