* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    background: radial-gradient(circle at 0% 0%, #1a1a1a 0%, #121212 45%, #0a0a0a 100%);
    color: var(--text-primary, #ffffff);
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

.hidden { display: none !important; }

.page-shell {
    max-width: 1500px;
    margin: 0 auto;
    padding: 18px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 16px;
}

.topbar h1 {
    margin: 0;
    font-size: clamp(1.2rem, 2vw, 1.8rem);
    line-height: 1.15;
}

.beta-tag {
    display: inline-block;
    vertical-align: middle;
    margin-left: 8px;
    padding: 2px 8px;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: #fff;
    background: var(--accent-primary, #ff3366);
    border-radius: 999px;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25) inset;
}

.subtitle {
    margin: 7px 0 0;
    color: var(--text-secondary, #b3b3b3);
    font-size: 0.93rem;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.help-link {
    color: var(--text-secondary, #b3b3b3);
    text-decoration: none;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 9px;
    padding: 6px 10px;
    white-space: nowrap;
}

.help-link:hover {
    border-color: rgba(255, 255, 255, 0.5);
    color: #fff;
}

.exit-link {
    color: var(--text-secondary, #b3b3b3);
    text-decoration: none;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 9px;
    padding: 6px 10px;
}

.exit-link:hover {
    border-color: rgba(255, 255, 255, 0.5);
    color: #fff;
}

.layout {
    display: grid;
    grid-template-columns: 300px 1fr 360px;
    gap: 14px;
}

.rooms-panel,
.stage-panel,
.chat-panel {
    background: rgba(26, 26, 26, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 14px;
    backdrop-filter: blur(8px);
}

.rooms-panel,
.chat-panel {
    padding: 12px;
}

.panel-head h2 {
    margin: 0 0 10px;
    font-size: 0.95rem;
    color: var(--text-primary, #f0f0f0);
}

.host-btn,
.primary-btn,
.danger-btn,
.ghost-btn {
    border: 0;
    border-radius: 10px;
    padding: 9px 11px;
    font-size: 0.86rem;
    cursor: pointer;
}

.host-btn,
.primary-btn {
    background: linear-gradient(135deg, #ff3366, #ff1a4d);
    color: #fff;
}

.host-btn {
    width: 100%;
    margin-bottom: 12px;
    font-weight: 700;
}

.danger-btn {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
}

.ghost-btn {
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: transparent;
    color: var(--text-secondary, #b3b3b3);
}

.primary-btn:disabled,
.danger-btn:disabled,
.ghost-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.room-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 65vh;
    overflow: auto;
    padding-right: 2px;
}

.empty-rooms {
    color: var(--text-secondary, #b3b3b3);
    font-size: 0.84rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px dashed rgba(255, 255, 255, 0.13);
    border-radius: 10px;
    padding: 11px;
}

.room-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 11px;
    padding: 9px;
}

.room-card.active-room {
    border-color: rgba(255, 51, 102, 0.8);
    box-shadow: 0 0 0 1px rgba(255, 51, 102, 0.5) inset;
}

.room-card-private {
    opacity: 0.7;
    margin-top: 8px;
}

.room-card-private .primary-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.my-room-card {
    margin-bottom: 10px;
    background: rgba(255, 51, 102, 0.12);
    border-color: rgba(255, 51, 102, 0.45);
}

.room-title-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
}

.room-meta {
    margin: 6px 0 0;
    color: var(--text-secondary, #b3b3b3);
    font-size: 0.78rem;
}

.room-actions {
    margin-top: 8px;
    display: flex;
    gap: 7px;
}

.room-badge,
.live-pill {
    font-size: 0.68rem;
    font-weight: 700;
    border-radius: 999px;
    padding: 4px 7px;
}

.room-badge {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.live-pill.is-live {
    background: rgba(16, 185, 129, 0.18);
    color: #6ee7b7;
}

.live-pill.is-offline {
    background: rgba(255, 255, 255, 0.12);
    color: #d1d5db;
}

.stage-panel {
    display: flex;
    flex-direction: column;
    min-height: 70vh;
    padding: 12px;
}

.stage-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.stage-head-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.stage-head h2 {
    margin: 0;
    font-size: 1.03rem;
}

.icon-btn {
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary, #b3b3b3);
    border-radius: 8px;
    padding: 4px 8px;
    font-size: 0.85rem;
    line-height: 1;
    cursor: pointer;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-primary, #fff);
}

.icon-btn.is-active {
    background: rgba(255, 51, 102, 0.25);
    border-color: var(--accent-primary, #ff3366);
    color: var(--text-primary, #fff);
}

.room-badge-lock {
    background: rgba(255, 51, 102, 0.2);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-box {
    background: var(--bg-secondary, #1a1a1a);
    border: 1px solid var(--border-color, #333);
    border-radius: 12px;
    padding: 22px;
    width: 90%;
    max-width: 360px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.modal-box h3 {
    margin: 0 0 14px;
    font-size: 1.05rem;
    color: var(--text-primary, #fff);
}

.modal-input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color, #333);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary, #fff);
    font-size: 0.95rem;
    margin-bottom: 16px;
}

.modal-input:focus {
    outline: none;
    border-color: var(--accent-primary, #ff3366);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.stage-body {
    margin-top: 12px;
    flex: 1;
    min-height: 440px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: linear-gradient(145deg, rgba(10, 10, 10, 0.92), rgba(37, 37, 37, 0.75));
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.stage-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.video-controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    background: linear-gradient(0deg, rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0));
    z-index: 2;
}

.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #fff;
    background: rgba(239, 68, 68, 0.85);
    border-radius: 999px;
    padding: 3px 9px;
}

.video-controls-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.volume-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.video-ctrl-btn {
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    border-radius: 8px;
    padding: 5px 8px;
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
}

.video-ctrl-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.volume-slider {
    width: 80px;
    accent-color: var(--accent-primary, #ff3366);
}

.empty-stage {
    text-align: center;
    color: var(--text-secondary, #b3b3b3);
    padding: 20px;
}

.empty-stage h3 {
    margin: 0;
    font-size: 1.1rem;
}

.empty-stage p {
    margin: 8px 0 0;
    font-size: 0.9rem;
}

.stage-status {
    margin: 10px 0 0;
    color: var(--text-secondary, #b3b3b3);
    font-size: 0.85rem;
}

.viewer-counter {
    margin: 6px 0 0;
    color: var(--text-secondary, #b3b3b3);
    font-size: 0.85rem;
    font-weight: 600;
}

.chat-panel {
    display: flex;
    flex-direction: column;
    min-height: 70vh;
}

.chat-messages {
    flex: 1;
    min-height: 320px;
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 10px;
    background: rgba(3, 5, 12, 0.35);
    overflow: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-msg {
    font-size: 0.84rem;
    line-height: 1.35;
    color: var(--text-primary, #f0f0f0);
}

.chat-msg .msg-name {
    color: var(--accent-primary, #ff3366);
    font-weight: 700;
}

.chat-msg.system-msg {
    color: var(--text-secondary, #b3b3b3);
    font-style: italic;
}

.chat-msg.self-msg .msg-name {
    color: var(--success, #10b981);
}

.chat-input-row {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

#chat-input {
    flex: 1;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
    padding: 9px 10px;
    font-size: 0.88rem;
}

#chat-input:focus {
    outline: none;
    border-color: rgba(255, 51, 102, 0.9);
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    background: rgba(20, 20, 20, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: var(--text-primary, #f0f0f0);
    border-radius: 11px;
    padding: 9px 12px;
    font-size: 0.82rem;
}

.mobile-only {
    display: none;
}

#switch-camera-btn {
    flex: 0 0 auto;
    font-size: 1rem;
    padding: 9px 12px;
}

.rooms-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(3, 5, 15, 0.6);
    z-index: 45;
}

@media (max-width: 1200px) {
    .layout {
        grid-template-columns: 280px 1fr;
    }

    .chat-panel {
        grid-column: 1 / -1;
        min-height: 300px;
    }

    .chat-messages {
        min-height: 210px;
    }
}

@media (max-width: 900px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .rooms-panel,
    .stage-panel,
    .chat-panel {
        min-height: auto;
    }

    .stage-body {
        min-height: 46vh;
    }

    .topbar {
        flex-direction: column;
    }

    .mobile-only {
        display: inline-flex;
        align-items: center;
    }

    /* Rooms panel becomes a slide-in drawer on small screens so the camera
       view + chat stay the primary focus (portrait: stacked, chat under stage). */
    .rooms-panel {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: 84%;
        max-width: 320px;
        z-index: 50;
        border-radius: 0 16px 16px 0;
        transform: translateX(-105%);
        transition: transform 0.25s ease;
        overflow-y: auto;
    }

    .rooms-panel.mobile-open {
        transform: translateX(0);
    }

    .stage-panel {
        order: 1;
    }

    .chat-panel {
        order: 2;
        min-height: 320px;
    }

    .chat-messages {
        min-height: 220px;
    }
}

/* Phones/tablets in landscape: keep camera + chat side-by-side (like popular
   live-streaming apps) since portrait's stacked layout wastes width here. */
@media (max-width: 900px) and (orientation: landscape) {
    .page-shell {
        padding: 10px 14px;
    }

    .topbar {
        flex-direction: row;
        margin-bottom: 10px;
    }

    .layout {
        display: grid;
        grid-template-columns: 1fr minmax(230px, 300px);
        grid-template-rows: auto;
        align-items: start;
    }

    .stage-panel {
        order: 1;
    }

    .chat-panel {
        order: 2;
        max-height: 82vh;
        min-height: 0;
    }

    .stage-body {
        min-height: 0;
        height: 60vh;
    }

    .chat-messages {
        min-height: 0;
        flex: 1;
    }
}

@media (max-width: 480px) {
    .stage-body {
        min-height: 40vh;
    }

    .room-actions {
        flex-wrap: wrap;
    }
}
