:root {
    --bg-deep: #121212;
    --bg-main: #181818;
    --bg-surface: #282828;
    --bg-surface-hover: #3a3a3a;
    --text-primary: #ffffff;
    --text-secondary: #b3b3b3;
    --primary-color: #00aeff;
    --primary-color-dark: #008fcc;
    --accent-yellow: #ffeb3b;
    --divider-color: #3f3f3f;
    --scrollbar-thumb: #4f4f4f;
    --scrollbar-track: var(--bg-main);
    --modal-bg: rgba(0, 0, 0, 0.7);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    --transition-speed: 0.3s;
}

html[data-theme='light'] {
    --bg-deep: #f0f2f5;
    --bg-main: #ffffff;
    --bg-surface: #e4e6eb;
    --bg-surface-hover: #d8dadf;
    --text-primary: #050505;
    --text-secondary: #65676b;
    --primary-color: #1877f2;
    --primary-color-dark: #166fe5;
    --accent-yellow: #f5c33b;
    --divider-color: #ced0d4;
    --scrollbar-thumb: #bcc0c4;
    --scrollbar-track: var(--bg-surface);
    --modal-bg: rgba(0, 0, 0, 0.5);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

html, body {
    width: 100vw;
    height: 100vh;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    overflow: hidden;
    background: var(--bg-deep);
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

*, *::before, *::after {
    box-sizing: inherit;
}

body {
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    direction: rtl;
}

.container {
    background: var(--bg-deep);
    width: 100vw;
    height: 100vh;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    transition: background-color var(--transition-speed);
}

.video-header {
    display: flex;
    flex-direction: row-reverse;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-main);
    padding: 10px 14px;
    gap: 12px;
    z-index: 101;
    box-shadow: var(--shadow);
    transition: background-color var(--transition-speed);
}

#video-title {
    color: var(--text-primary);
    font-size: 1.12rem;
    font-weight: bold;
    flex: 1;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color var(--transition-speed);
}

#menu-btn {
    background: none;
    border: none;
    outline: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    color: var(--text-primary);
    align-items: center;
    justify-content: center;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

#menu-btn:hover {
    background-color: var(--bg-surface-hover);
}

.sidebar {
    position: fixed;
    top: 0;
    right: -280px;
    width: 280px;
    height: 100%;
    background-color: var(--bg-main);
    box-shadow: var(--shadow);
    z-index: 200;
    transition: right var(--transition-speed) ease-in-out;
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.sidebar.open {
    right: 0;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 15px;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--divider-color);
    color: var(--text-primary);
}

.sidebar-header h3 {
    margin: 0;
    font-size: 1.2rem;
}

#close-sidebar-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
}

.sidebar-content .menu-item {
    display: flex;
    align-items: center;
    padding: 12px 10px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

.sidebar-content .menu-item:hover {
    background-color: var(--bg-surface-hover);
    color: var(--text-primary);
}

.sidebar-content .menu-item i {
    margin-left: 15px;
    width: 20px;
    text-align: center;
}

.theme-switch-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.theme-switch {
    display: inline-block;
    height: 24px;
    position: relative;
    width: 44px;
}

.theme-switch input {
    display: none;
}

.slider {
    background-color: var(--bg-surface);
    bottom: 0;
    cursor: pointer;
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    background-color: #fff;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
    position: absolute;
    transition: .4s;
    border-radius: 50%;
    box-shadow: 0 0 2px rgba(0,0,0,0.4);
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 199;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-speed), visibility var(--transition-speed);
}

.overlay.show {
    opacity: 1;
    visibility: visible;
}

.user-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-surface);
    padding: 7px 14px;
    color: var(--text-secondary);
    font-size: 1rem;
    margin: 0 0 2px 0;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

.users-icon::before {
    content: "👥";
    margin-left: 4px;
}

.video-box {
    background: #000;
    flex: 1 1 50%;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    position: relative;
}

#youtube-player-container {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

#youtube-player-container iframe {
    width: 100%;
    height: 100%;
}

#yt-play-overlay-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #ff0000;
    color: white;
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
}

#yt-play-overlay-btn:hover {
    transform: translate(-50%, -50%) scale(1.1);
}

.chat-section {
    background: var(--bg-main);
    padding: 10px 8px 8px 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 40vh;
    overflow: hidden;
    transition: background-color var(--transition-speed);
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 7px;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

.message {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    max-width: 85%;
    direction: rtl;
}

.message .avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid #00aeff;
    flex-shrink: 0;
}

.message .message-content {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-radius: 10px;
    padding: 5px 11px 7px 9px;
    box-shadow: var(--shadow);
    word-break: break-word;
    max-width: 100%;
}

.message .message-content .meta {
    font-size: 0.85em;
    color: var(--text-secondary);
    margin-bottom: 2px;
    font-weight: bold;
}

.message.system {
    justify-content: center;
    background: var(--bg-surface);
    color: var(--accent-yellow);
    text-align: center;
    font-size: 0.95em;
    font-weight: bold;
    align-self: center;
    max-width: 90%;
    padding: 5px 10px;
    border-radius: 10px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: none; /* خط سفید دور پیام حذف شد */
    box-shadow: var(--shadow);
}

/* تمام پیام‌ها با عکس در سمت چپ */
.message {
    flex-direction: row;
}

#chat-form {
    display: flex;
    gap: 6px;
    flex-direction: row-reverse;
}

#chat-input {
    flex: 1;
    border: none;
    border-radius: 7px;
    padding: 8px 12px;
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 1em;
    outline: none;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

#send-btn {
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 7px;
    padding: 8px 18px;
    font-size: 1em;
    cursor: pointer;
    font-family: inherit;
    transition: background-color var(--transition-speed);
    order: -1;
}

#send-btn:hover {
    background-color: var(--primary-color-dark);
}

.modal {
    position: fixed;
    inset: 0;
    background: var(--modal-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 201;
}

.modal-content {
    background: var(--bg-main);
    padding: 32px 24px 20px 24px;
    border-radius: 14px;
    box-shadow: var(--shadow);
    text-align: center;
    min-width: 260px;
    color: var(--text-primary);
}

.modal-content h3 {
    margin-bottom: 18px;
    font-size: 1.1em;
}

.modal-content input {
    padding: 9px 12px;
    border-radius: 7px;
    border: 1px solid var(--divider-color);
    font-size: 1em;
    background: var(--bg-surface);
    color: var(--text-primary);
    margin-bottom: 15px;
    width: 90%;
}

.modal-content button {
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 7px;
    padding: 8px 22px;
    font-size: 1em;
    cursor: pointer;
    font-family: inherit;
    transition: background-color var(--transition-speed);
}

.modal-content .cancel-btn {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

.player-container {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    background: #000;
    font-family: 'Vazirmatn', sans-serif;
}

.player-container video {
    width: 100%;
    height: 100%;
    display: block;
}

.player-controls {
    position: absolute;
    bottom: 15px;
    left: 15px;
    right: 15px;
    padding: 10px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(25, 25, 25, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.player-container:hover .player-controls,
.player-container.paused .player-controls {
    opacity: 1;
    transform: translateY(0);
}

.timeline-container {
    width: 100%;
    cursor: pointer;
    padding: 5px 0;
}

.timeline {
    width: 100%;
    height: 5px;
    background: rgba(255, 255, 255, 0.25);
    position: relative;
    border-radius: 3px;
}

.timeline .progress {
    height: 100%;
    width: 0;
    background: #00aeff;
    border-radius: 3px;
    position: absolute;
    transition: width 0.1s linear;
}

.timeline .thumb-indicator {
    height: 15px;
    width: 15px;
    border-radius: 50%;
    background: #fff;
    border: 3px solid #00aeff;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%) scale(0);
    left: 0;
    transition: transform 0.2s ease;
}

.timeline-container:hover .thumb-indicator {
    transform: translate(-50%, -50%) scale(1);
}

.controls-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
}

.controls-left,
.controls-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.player-controls button {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 5px;
    transition: transform 0.2s, color 0.2s;
}

.player-controls button:hover {
    color: #00aeff;
    transform: scale(1.15);
}

.volume-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.volume-slider {
    width: 0;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    cursor: pointer;
    position: relative;
    border-radius: 3px;
    transition: width 0.3s ease-in-out;
}

.volume-container:hover .volume-slider {
    width: 80px;
}

.volume-progress {
    background: #fff;
    width: 100%;
    height: 100%;
    position: absolute;
    border-radius: 3px;
}

.time-display {
    font-size: 0.9em;
    user-select: none;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 1.2rem;
}

@media (max-width: 899px) {
    .container {
        height: 100vh !important;
        min-height: 100vh !important;
        flex-direction: column;
    }
    .video-box {
        aspect-ratio: 16/9;
        flex: 0 0 auto !important;
        margin-bottom: 0 !important;
        min-height: 0 !important;
        max-height: none !important;
        height: auto !important;
    }
    .video-box video {
        width: 100vw !important;
        height: 100% !important;
        min-height: 0 !important;
        max-height: 100% !important;
        aspect-ratio: 16/9 !important;
        object-fit: contain;
        display: block;
        border-radius: 0 !important;
        background: #000;
    }
    .chat-section {
        flex: 1 1 0 !important;
        min-height: 0 !important;
        max-height: none !important;
        height: auto !important;
        margin: 0 !important;
        padding: 10px 8px 8px 8px;
        border-radius: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        min-width: 100vw !important;
        display: flex;
        flex-direction: column;
        gap: 8px;
        overflow: hidden;
    }
    #chat-messages {
        flex: 1 1 0 !important;
        min-height: 0 !important;
    }
}