/* ============================================================================
   LISTEN ALONG — Lobby & Room Styles
   ============================================================================ */

/* ── Lobby Page ── */

.listen-along-page {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    max-width: 1400px;
    margin: 0 auto;
    height: calc(100vh - var(--global-player-height, 0));
}

.listen-along-header {
    flex-shrink: 0;
    text-align: center;
    margin-bottom: 2rem;
}

.listen-along-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.listen-along-subtitle {
    font-size: 1.125rem;
    color: var(--neuro-text-secondary);
}

body[data-theme="evil"] .listen-along-subtitle {
    color: var(--evil-text-secondary);
}

body[data-theme="twins"] .listen-along-subtitle {
    color: var(--twins-text-secondary);
}

/* Action Cards */

.listen-along-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: var(--spacing-md);
    flex-shrink: 0;
}

.action-card {
    display: flex;
    gap: 20px;
    padding: 24px;
    border-radius: 16px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid transparent;
}

.action-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.action-card-disabled {
    pointer-events: none;
    opacity: 0.7;
}

.action-card-icon {
    flex-shrink: 0;
    width: 64px;
    height: 64px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-card-icon.create-icon {
    background: linear-gradient(135deg, rgba(0, 217, 255, 0.15), rgba(0, 217, 255, 0.05));
    color: var(--neuro-primary);
}

.action-card-icon.join-icon {
    background: linear-gradient(135deg, rgba(0, 217, 255, 0.15), rgba(0, 217, 255, 0.05));
    color: var(--neuro-primary);
}

.action-card-content {
    flex: 1;
    min-width: 0;
}

/* Public Rooms */

.listen-along-public-rooms {
    flex: 1;
    min-height: 0;
}

.rooms-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: var(--spacing-md);
}

.empty-rooms-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    border-radius: 16px;
    text-align: center;
}

/* ── Room Card ── */

.listen-room-card {
    border-radius: 12px;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid transparent;
}

.listen-room-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.room-card-cover {
    position: relative;
    width: 100%;
    aspect-ratio: 16/9;
    overflow: hidden;
}

.room-card-cover-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.room-card-cover-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(0, 217, 255, 0.08), rgba(255, 107, 157, 0.08));
}

.room-card-listeners-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 4px;
    backdrop-filter: blur(4px);
}

.room-card-listeners-inline {
    display: flex;
    align-items: center;
    gap: 3px;
    margin-left: auto;
    flex-shrink: 0;
    opacity: 0.7;
}

.room-card-host {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: var(--text-xs);
}

.room-card-playing-indicator {
    position: absolute;
    bottom: 8px;
    left: 8px;
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 16px;
}

.playing-bar {
    width: 3px;
    background: var(--neuro-primary);
    border-radius: 2px;
    animation: playing-bar-animation 0.8s ease-in-out infinite alternate;
}

.playing-bar:nth-child(1) { height: 60%; animation-delay: 0s; }
.playing-bar:nth-child(2) { height: 100%; animation-delay: 0.2s; }
.playing-bar:nth-child(3) { height: 40%; animation-delay: 0.4s; }

@keyframes playing-bar-animation {
    0%   { height: 30%; }
    100% { height: 100%; }
}

.room-card-info {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.room-card-name {
    font-weight: 700;
    font-size: var(--text-base);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.room-card-now-playing {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: var(--text-xs);
}

.room-card-now-playing span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Room Page ── */

.listen-room-page {
    height: calc(100vh - var(--global-player-height, 0px));
    display: flex;
    flex-direction: column;
}

.listen-room-loading,
.listen-room-error {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.listen-room-layout {
    flex: 1;
    display: flex;
    gap: 0;
    min-height: 0;
    overflow: hidden;
}

.listen-room-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0;
    min-width: 0;
    overflow-y: auto;
}

/* Room Header */

.listen-room-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.room-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.room-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Now Playing */

.listen-now-playing {
    display: flex;
    gap: 24px;
    padding: 24px;
    align-items: center;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.now-playing-cover {
    width: 160px;
    height: 160px;
    border-radius: 12px;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.now-playing-cover-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.now-playing-cover-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(0, 217, 255, 0.08), rgba(255, 107, 157, 0.08));
}

.now-playing-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Progress */

.now-playing-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}

.progress-time {
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    min-width: 36px;
    text-align: center;
}

.progress-bar-container {
    flex: 1;
    cursor: pointer;
    padding: 6px 0;
}

.progress-bar-bg {
    width: 100%;
    height: 4px;
    border-radius: 2px;
    position: relative;
    overflow: hidden;
}

.progress-bar-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    border-radius: 2px;
    background: var(--neuro-primary);
    transition: width 0.3s linear;
}

/* Controls */

.now-playing-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.play-btn {
    background: rgba(0, 217, 255, 0.12) !important;
    border-radius: 50% !important;
}

.listener-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: var(--text-sm);
}

.start-listening-btn {
    border-radius: 24px !important;
    padding: 8px 28px !important;
    font-weight: 700 !important;
    letter-spacing: 0.5px;
    text-transform: none !important;
    animation: start-listening-pulse 2s ease-in-out infinite;
}

@keyframes start-listening-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(0, 217, 255, 0.3); }
    50%      { box-shadow: 0 0 0 10px rgba(0, 217, 255, 0); }
}

body[data-theme="evil"] .start-listening-btn {
    animation-name: start-listening-pulse-evil;
}

@keyframes start-listening-pulse-evil {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 0, 102, 0.3); }
    50%      { box-shadow: 0 0 0 10px rgba(255, 0, 102, 0); }
}

body[data-theme="twins"] .start-listening-btn {
    animation-name: start-listening-pulse-twins;
}

@keyframes start-listening-pulse-twins {
    0%, 100% { box-shadow: 0 0 0 0 rgba(157, 92, 255, 0.3); }
    50%      { box-shadow: 0 0 0 10px rgba(157, 92, 255, 0); }
}

/* Volume Control */

.volume-control {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}

.volume-slider-wrapper {
    width: 80px;
    display: flex;
    align-items: center;
}

.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.15);
    outline: none;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--neuro-primary, #00d9ff);
    cursor: pointer;
    border: none;
}

.volume-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--neuro-primary, #00d9ff);
    cursor: pointer;
    border: none;
}

/* Queue */

.listen-queue {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 16px 20px;
}

.queue-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.queue-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.queue-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    text-align: center;
}

.queue-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-radius: 8px;
    transition: background 0.15s;
}

.queue-item-active {
    background: rgba(0, 217, 255, 0.08) !important;
    border-left: 3px solid var(--neuro-primary);
}

.queue-item-order {
    width: 28px;
    text-align: center;
    font-size: var(--text-sm);
    flex-shrink: 0;
}

.queue-item-cover {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 4px;
    overflow: hidden;
}

.queue-item-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.queue-item-title {
    font-size: var(--text-sm);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.queue-item-artist {
    font-size: var(--text-xs);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.queue-item-duration {
    font-size: var(--text-xs);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.queue-item-remove {
    opacity: 0;
    transition: opacity 0.15s;
}

.queue-item:hover .queue-item-remove {
    opacity: 1;
}

.queue-item-clickable {
    cursor: pointer;
}

.queue-item-clickable:hover {
    background: rgba(255, 255, 255, 0.06);
}

.queue-item-actions {
    display: flex;
    align-items: center;
    gap: 0;
    opacity: 0;
    transition: opacity 0.15s;
    flex-shrink: 0;
}

.queue-item:hover .queue-item-actions {
    opacity: 1;
}

.queue-item-action-btn {
    padding: 2px !important;
    min-width: unset !important;
}

/* Touch devices: always show queue item actions */
@media (hover: none) {
    .queue-item-actions {
        opacity: 1;
    }
}

/* ── Sidebar ── */

.listen-room-sidebar {
    width: 340px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-left: 1px solid rgba(255, 255, 255, 0.06);
    overflow: hidden;
    min-width: 20rem;
}

.listen-listeners {
    padding: 16px;
    flex-shrink: 0;
    max-height: 220px;
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.listeners-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.listener-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: 8px;
}

.listener-name {
    font-size: var(--text-sm);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.listen-chat-wrapper {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.listen-chat-wrapper .chat-container {
    border-radius: 0;
    height: 100%;
}

/* Collapsible sidebar sections */

.listen-section-header {
    user-select: none;
}

.listen-section-header:hover {
    opacity: 0.85;
}

.listen-listeners.collapsed {
    max-height: none;
    flex-shrink: 0;
}

.listen-chat-section {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.listen-chat-section.collapsed {
    flex: 0 0 auto;
}

/* ── Theme Overrides — Evil ── */

body[data-theme="evil"] .action-card-icon.create-icon {
    background: linear-gradient(135deg, rgba(255, 0, 102, 0.15), rgba(255, 0, 102, 0.05));
    color: var(--evil-primary);
}

body[data-theme="evil"] .action-card-icon.join-icon {
    background: linear-gradient(135deg, rgba(255, 0, 102, 0.15), rgba(255, 0, 102, 0.05));
    color: var(--evil-primary);
}

body[data-theme="evil"] .room-card-cover-placeholder,
body[data-theme="evil"] .now-playing-cover-placeholder {
    background: linear-gradient(135deg, rgba(255, 0, 102, 0.08), rgba(157, 0, 255, 0.08));
}

body[data-theme="evil"] .playing-bar {
    background: var(--evil-primary);
}

body[data-theme="evil"] .progress-bar-fill {
    background: var(--evil-primary);
}

body[data-theme="evil"] .play-btn {
    background: rgba(255, 0, 102, 0.12) !important;
}

body[data-theme="evil"] .volume-slider::-webkit-slider-thumb {
    background: var(--evil-primary);
}

body[data-theme="evil"] .volume-slider::-moz-range-thumb {
    background: var(--evil-primary);
}

body[data-theme="evil"] .queue-item-active {
    background: rgba(255, 0, 102, 0.08) !important;
    border-left-color: var(--evil-primary);
}

body[data-theme="evil"] .listen-room-card:hover {
    box-shadow: 0 8px 24px rgba(255, 0, 102, 0.15);
}

body[data-theme="evil"] .action-card:hover {
    box-shadow: 0 8px 24px rgba(255, 0, 102, 0.15);
}

/* ── Theme Overrides — Twins ── */

body[data-theme="twins"] .action-card-icon.create-icon {
    background: linear-gradient(135deg, rgba(157, 92, 255, 0.15), rgba(157, 92, 255, 0.05));
    color: var(--twins-primary);
}

body[data-theme="twins"] .action-card-icon.join-icon {
    background: linear-gradient(135deg, rgba(157, 92, 255, 0.15), rgba(157, 92, 255, 0.05));
    color: var(--twins-primary);
}

body[data-theme="twins"] .room-card-cover-placeholder,
body[data-theme="twins"] .now-playing-cover-placeholder {
    background: linear-gradient(135deg, rgba(157, 92, 255, 0.08), rgba(255, 107, 157, 0.08));
}

body[data-theme="twins"] .playing-bar {
    background: var(--twins-primary);
}

body[data-theme="twins"] .progress-bar-fill {
    background: var(--twins-primary);
}

body[data-theme="twins"] .play-btn {
    background: rgba(157, 92, 255, 0.12) !important;
}

body[data-theme="twins"] .volume-slider::-webkit-slider-thumb {
    background: var(--twins-primary);
}

body[data-theme="twins"] .volume-slider::-moz-range-thumb {
    background: var(--twins-primary);
}

body[data-theme="twins"] .queue-item-active {
    background: rgba(157, 92, 255, 0.08) !important;
    border-left-color: var(--twins-primary);
}

body[data-theme="twins"] .listen-room-card:hover {
    box-shadow: 0 8px 24px rgba(157, 92, 255, 0.15);
}

body[data-theme="twins"] .action-card:hover {
    box-shadow: 0 8px 24px rgba(157, 92, 255, 0.15);
}

/* ── Responsive ── */

@media (max-width: 900px) {
    .listen-along-actions {
        grid-template-columns: 1fr;
    }

    .rooms-grid {
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    }

    .listen-room-layout {
        flex-direction: column;
        overflow-y: auto;
    }

    .listen-room-main {
        flex: 0 0 auto;
        overflow-y: visible;
    }

    .listen-room-sidebar {
        width: 100%;
        border-left: none;
        border-top: 1px solid rgba(255, 255, 255, 0.06);
        min-height: 300px;
        flex: 0 0 auto;
    }

    .listen-now-playing {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
        padding: 16px;
    }

    .now-playing-cover {
        width: 100%;
        height: auto;
        aspect-ratio: 1;
        max-width: 200px;
        margin: 0 auto;
    }

    .listen-queue {
        flex: 0 0 auto;
        min-height: 0;
    }

    .queue-list {
        max-height: 40vh;
        overflow-y: auto;
    }

    .listen-chat-section {
        flex: 0 0 auto;
        min-height: 280px;
    }

    .listen-chat-wrapper {
        min-height: 220px;
    }
}

@media (max-width: 500px) {
    .action-card {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 12px;
        padding: 16px;
    }

    .now-playing-cover {
        max-width: 140px;
    }
}

/* ── Listener Sync Controls ── */

.listener-sync-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.latency-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    white-space: nowrap;
    user-select: none;
}

.latency-indicator.latency-good {
    color: #4caf50;
}

.latency-indicator.latency-fair {
    color: #ff9800;
}

.latency-indicator.latency-poor {
    color: #f44336;
}

.latency-indicator.latency-unknown {
    color: rgba(255, 255, 255, 0.4);
}

/* ── Drift Threshold Control ── */

.drift-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.drift-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    user-select: none;
}

.drift-slider-wrapper {
    width: 80px;
    display: flex;
    align-items: center;
}

.drift-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.15);
    outline: none;
    cursor: pointer;
}

.drift-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--neuro-primary, #00d9ff);
    cursor: pointer;
    border: none;
}

.drift-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--neuro-primary, #00d9ff);
    cursor: pointer;
    border: none;
}

body[data-theme="evil"] .drift-slider::-webkit-slider-thumb {
    background: var(--evil-primary, #ff0066);
}

body[data-theme="evil"] .drift-slider::-moz-range-thumb {
    background: var(--evil-primary, #ff0066);
}

body[data-theme="twins"] .drift-slider::-webkit-slider-thumb {
    background: var(--twins-primary, #9d5cff);
}

body[data-theme="twins"] .drift-slider::-moz-range-thumb {
    background: var(--twins-primary, #9d5cff);
}

@media (max-width: 768px) {
    .listener-sync-controls {
        flex-wrap: wrap;
    }
    .listen-chat-wrapper .chat-container {
        max-height: 500px;
    }
    .drift-control {
        flex-wrap: wrap;
    }

    .drift-slider-wrapper {
        width: 60px;
    }

    .queue-header {
        flex-wrap: wrap;
        gap: 8px;
    }

    .queue-header > div {
        flex-wrap: wrap;
        gap: 4px;
    }

    .queue-header .mud-button-root {
        min-width: 0;
        padding-left: 6px;
        padding-right: 6px;
    }
}
