.room-mobile-close, .room-mobile-rotate, .room-mobile-rotate-hint, .room-mobile-tools, .room-plaza-link { display: none; }

#chatSection .room-chat-history {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    min-width: 0;
}
#chatSection #chatMessages { flex: 1; min-height: 0; }
#chatSection :is(#chatMessages, .chat-input-area) {
    font-family: var(--reading-font);
    font-weight: 400;
}
#chatSection #chatMessages :is(.chat-username, .chat-msg-name) {
    font-weight: 600;
}

@media (max-width: 700px), (max-width: 1000px) and (max-height: 550px) and (orientation: landscape) and (pointer: coarse) {
    #chatSection .chat-input-area .chat-input { font-size: 16px; }
}

@media (max-width: 700px) and (orientation: portrait) {
    :root { --live-video-lift: 17dvh; }
    .room-wide-video #mainContainer, #channelDiscovery.room-wide-video {
        --live-video-top: max(0px, calc((100dvh - 100vw / var(--room-video-ratio)) / 2 - var(--live-video-lift)));
    }

    body.room-mobile-live {
        --bg: var(--brand-ink);
        --card: var(--brand-surface);
        --card-hover: var(--brand-surface);
        --text: #fff9ed;
        --text2: var(--brand-muted);
        --border: #ffffff26;
        background: var(--brand-ink);
        color: var(--text);
    }

    .room-mobile-live .header-mobile { display: none !important; }

    .room-mobile-live :is(#mainContainer, #inlineLiveRoom) {
        position: relative;
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr) auto minmax(0, 1fr);
        align-items: stretch;
        width: 100%;
        height: 100dvh;
        gap: 0;
        padding: 0;
        background: linear-gradient(160deg, #221c13, var(--brand-ink) 32%, var(--brand-ink) 72%, #1a1712);
    }

    .room-wide-video :is(#mainContainer, #inlineLiveRoom) {
        grid-template-rows: var(--live-video-top) auto minmax(0, 1fr);
    }

    .room-mobile-live .stream-title-section {
        align-self: start;
        position: relative;
        z-index: 3;
        background: transparent;
        border: 0;
        padding: calc(10px + env(safe-area-inset-top)) 12px 8px;
    }

    .room-mobile-live .stream-title-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto 36px;
        align-items: start;
        gap: 7px;
    }
    .room-mobile-live .stream-title-right { display: contents; }
    .room-mobile-live .stream-title-left { grid-area: 1 / 1; }
    .room-mobile-live .room-follow { flex-shrink: 0; }
    .room-mobile-live .room-audience { display: contents; }
    .room-mobile-live .stream-stats {
        grid-area: 1 / 2;
        justify-self: end;
        min-height: 34px;
        padding-inline: 7px;
        border-radius: 999px;
        background: color-mix(in srgb, var(--brand-surface) 72%, transparent);
        color: #fff9ed;
        font-variant-numeric: tabular-nums;
    }
    .room-mobile-live .room-plaza-link {
        grid-area: 2 / 2 / 3 / 4;
        justify-self: end;
        display: inline-flex;
        align-items: center;
        gap: 4px;
        min-height: 28px;
        padding: 0 7px;
        border-radius: 999px;
        background: color-mix(in srgb, var(--brand-surface) 72%, transparent);
        color: var(--brand-gold);
        text-decoration: none;
        font-size: .75rem;
        font-weight: 650;
        white-space: nowrap;
    }
    .room-mobile-live .room-mobile-close { grid-area: 1 / 3; }
    .room-mobile-live .stream-title-info { display: flex; flex: 0 1 auto; flex-direction: column; }
    .room-mobile-live .streamer-name-sm { display: block; order: -1; color: var(--text); font-weight: 700; }
    .room-mobile-live .stream-description { display: none; }
    .room-mobile-live .stream-title { color: var(--text2); font-weight: 500; }
    .room-mobile-live .streamer-avatar-sm { border: 1px solid var(--brand-gold); background: #292318; }

    .room-mobile-live .room-mobile-close,
    .room-wide-video .room-mobile-rotate {
        display: grid;
        place-items: center;
        width: 36px;
        height: 36px;
        padding: 0;
        border: 1px solid #ffffff45;
        border-radius: 50%;
        background: color-mix(in srgb, var(--brand-surface) 72%, transparent);
        color: #fff;
        text-decoration: none;
        cursor: pointer;
    }

    .room-mobile-close { font-size: 1.35rem; }
    .room-wide-video .player-container { aspect-ratio: var(--room-video-ratio); }
    .room-wide-video .player-container video { object-fit: contain; }
    .room-portrait-video .player-section { position: absolute; inset: 0; }
    .room-portrait-video .player-container { height: 100%; aspect-ratio: auto; }
    .room-mobile-live .player-section { touch-action: pinch-zoom; }
    .room-mobile-live .player-container :is(video, iframe) { display: block; }
    .room-mobile-live .player-container video { object-fit: cover; }
    .room-mobile-live .room-mobile-rotate { position: absolute; right: 10px; top: 10px; z-index: 2; }
    .room-wide-video .room-mobile-rotate-hint:not([hidden]) {
        display: block;
        position: absolute;
        z-index: 2;
        top: 51px;
        right: 10px;
        padding: 6px 10px;
        border-radius: 8px;
        background: color-mix(in srgb, var(--brand-surface) 91%, transparent);
        color: #fff;
        font-size: .75rem;
    }

    .room-mobile-live #chatSection {
        grid-row: 3;
        min-height: 0;
        height: auto !important;
        display: flex;
        flex-direction: row;
        align-items: end;
        justify-content: end;
        gap: 6px;
        padding: 0 8px calc(8px + env(safe-area-inset-bottom));
        background: transparent;
        overflow: visible;
    }

    .room-wide-video #chatSection {
        display: grid;
        grid-template: minmax(0, 1fr) auto / minmax(0, 1fr) auto;
        padding-block-start: clamp(12px, 2.2dvh, 22px);
    }

    .room-wide-video #chatSection .chat-input-area { grid-area: 2 / 1; }
    .room-wide-video #chatSection .room-mobile-tools { grid-area: 2 / 2; }
    .room-portrait-video #chatSection { position: absolute; inset: auto 0 0; z-index: 2; }
    .room-mobile-live #chatSection .chat-header,
    .room-mobile-live #chatSection .chat-disabled { display: none; }

    .room-portrait-video #chatSection .room-chat-history {
        position: absolute;
        z-index: 2;
        inset-inline-start: 0;
        bottom: 100%;
        width: min(80%, 25rem);
        max-height: min(30dvh, 16rem);
    }

    .room-portrait-video #chatSection #chatMessages { min-height: 36px; max-height: min(24dvh, 12rem); }

    .room-mobile-live #chatMessages {
        box-sizing: border-box;
        display: block;
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-width: none;
        background: transparent;
        padding: 8px 12px;
        color: #fff;
        text-shadow: 0 1px 3px #000, 0 0 7px #000;
    }

    .room-wide-video #chatSection .room-chat-history { grid-area: 1 / 1 / 2 / -1; align-self: stretch; }
    .room-wide-video #chatMessages {
        align-self: stretch;
        display: flex;
        flex-direction: column;
        width: auto;
        min-height: 0;
        max-height: none;
        padding: 4px 4px 8px;
        scroll-behavior: auto;
        touch-action: pan-y;
    }
    .room-mobile-live #chatMessages :is(.chat-message, .chat-msg) {
        display: grid;
        grid-template-columns: 24px minmax(0, 1fr);
        align-items: start;
        gap: 7px;
        width: fit-content;
        max-width: 100%;
        background: transparent;
        border: 0;
        border-radius: 12px;
        padding: 3px 4px;
        margin: 0 0 4px;
        font-size: .8125rem;
        line-height: 1.45;
    }
    .room-portrait-video #chatMessages .chat-caption {
        display: inline;
        padding: 2px 4px;
        background: #120f0c91;
        -webkit-box-decoration-break: clone;
        box-decoration-break: clone;
    }
    .room-wide-video #chatMessages > * { flex: 0 0 auto; }
    .room-wide-video #chatMessages > :first-child { margin-block-start: auto; }
    .room-mobile-live #chatMessages :is(.chat-avatar, .chat-msg-avatar) {
        width: 24px;
        height: 24px;
        font-size: .6875rem;
        box-shadow: none;
    }
    .room-mobile-live #chatMessages :is(.chat-time, .chat-msg-time) { display: none; }
    .room-mobile-live #chatMessages :is(.chat-content, .chat-msg-content) {
        min-width: 0;
        padding-block-start: 2px;
        overflow-wrap: anywhere;
    }
    .room-mobile-live #chatMessages :is(.chat-username, .chat-msg-name, .chat-text, .chat-msg-text) {
        display: inline;
        font-size: inherit;
        line-height: inherit;
    }
    .room-mobile-live #chatMessages :is(.chat-username, .chat-msg-name) {
        color: var(--brand-gold) !important;
    }
    .room-mobile-live #chatMessages :is(.chat-username, .chat-msg-name)::after { content: ": "; }
    .room-mobile-live #chatMessages :is(.chat-text, .chat-msg-text) { color: #fff; }
    .room-mobile-live #glbar,
    .room-mobile-live .stream-title-right :is(.like-btn, .share-btn) { display: none !important; }

    .room-mobile-live #chatSection .chat-input-area {
        position: relative;
        flex: 1;
        min-width: 0;
        padding: 0;
        background: transparent;
        border: 0;
    }

    .room-mobile-live #chatSection .chat-input-wrapper {
        min-height: 42px;
        gap: 2px;
        padding-right: 4px;
        border: 1px solid #fff2;
        border-radius: 999px;
        background: #231d17b8;
    }

    .room-mobile-live #chatSection .chat-input {
        padding-inline: 12px 0;
        border: 0;
        background: transparent;
    }

    .room-mobile-live #chatSection .chat-input:focus { box-shadow: none; }
    .room-mobile-live #chatSection .chat-input-wrapper:focus-within { border-color: color-mix(in srgb, var(--brand-gold) 60%, transparent); }
    .room-mobile-live #chatSection .emoji-picker-wrap { order: 1; position: static; }
    .room-mobile-live #chatSection .emoji-picker-btn {
        padding: 4px;
        border: 0;
        background: transparent;
        filter: grayscale(1);
    }

    .room-mobile-live #chatSection .emoji-picker-panel {
        left: 0;
        width: min(280px, calc(100vw - 16px));
    }

    .room-mobile-live #chatSection .chat-send {
        order: 2;
        width: 27px;
        height: 30px;
        color: var(--brand-gold);
        background: transparent;
        box-shadow: none;
    }

    .room-mobile-live #chatSection .chat-input:placeholder-shown ~ .chat-send { display: none; }

    .room-mobile-live .room-mobile-tools { display: flex; gap: 4px; }
    .room-mobile-action {
        display: grid;
        place-items: center;
        flex: 0 0 auto;
        width: clamp(38px, 10vw, 44px);
        height: 42px;
        border: 1px solid #fff2;
        border-radius: 50%;
        background: #231d17b8;
        color: #fff9ed;
        cursor: pointer;
        font: inherit;
        font-size: 1.2rem;
    }

    .room-mobile-action svg { width: 20px; height: 20px; }
    .room-mobile-like { color: var(--brand-gold); }
    .room-mobile-like[aria-pressed="true"] { color: #ff738a; }
}

/* The inline room layers the same room UI over the existing feed player. */
body:has(.channels-room-active) .explore-nav,
.channels-room-active :is(.channels-mobile-overlay, .channels-mobile-details, .channels-showcase, .channels-list) {
    display: none;
}

#channelDiscovery.channels-room-active {
    position: relative;
    height: 100dvh;
    padding: 0;
    isolation: isolate;
    background: linear-gradient(160deg, #221c13, var(--brand-ink) 32%, var(--brand-ink) 72%, #1a1712);
    color: #fff9ed;
}

.channels-room-active .channels-mobile-feed {
    display: block;
    position: absolute;
    inset: 0;
    background: transparent;
}
.channels-room-active :is(.channels-mobile-slide, .channels-mobile-media) {
    position: absolute;
    inset: 0;
    background: transparent;
}
.channels-room-active .channels-mobile-media { z-index: 0; pointer-events: none; }
.channels-room-active .channels-mobile-media::after { display: none; }
.channels-room-active .channels-mobile-media video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    pointer-events: auto;
}

#inlineLiveRoom {
    position: absolute;
    z-index: 1;
    inset: 0;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    background: transparent;
    pointer-events: none;
    --text: #fff9ed;
    --text2: var(--brand-muted);
    --card: var(--brand-surface);
    --card-hover: var(--brand-surface);
    --border: #ffffff26;
}
#inlineLiveRoom :is(.stream-title-section, .room-chat-history, .chat-input-area, .room-mobile-tools, .room-mobile-rotate, .room-mobile-rotate-hint, .room-live-sound, .player-container iframe, dialog) {
    pointer-events: auto;
}
#inlineLiveRoom .player-container { position: relative; height: 100%; }
#inlineLiveRoom .stream-title-section { padding: calc(10px + env(safe-area-inset-top)) 12px 8px; }
#inlineLiveRoom .stream-title-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
#inlineLiveRoom .stream-title-info { min-width: 0; }
#inlineLiveRoom :is(.stream-title, .streamer-name-sm) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; }
#inlineLiveRoom .streamer-avatar-sm { display: grid; place-items: center; flex: 0 0 28px; height: 28px; border-radius: 50%; overflow: hidden; }
#inlineLiveRoom .streamer-avatar-sm img { width: 100%; height: 100%; object-fit: cover; }
#inlineLiveRoom .stream-stats { display: flex; align-items: center; gap: 4px; color: var(--text2); font-size: .8rem; }
#inlineLiveRoom .stream-stats svg { width: 14px; height: 14px; fill: currentColor; }
#inlineLiveRoom .room-follow { padding: 5px 11px; min-height: 34px; background: var(--brand-gold); color: #14100a; border: 1px solid var(--brand-gold); border-radius: 999px; font: inherit; font-size: .75rem; font-weight: 700; }
#inlineLiveRoom .room-follow[aria-pressed="true"] { background: transparent; color: var(--text); }
#inlineLiveRoom .room-follow-error, #inlineRoomStatus { color: var(--text2); font-size: .75rem; }
#inlineRoomStatus a { color: var(--brand-gold); }
#inlineLiveRoom dialog { margin: auto; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--card); color: var(--text); }
#inlineLiveRoom dialog input { max-width: 65vw; }

@media (max-width: 700px) and (orientation: portrait) {
    .room-mobile-live #inlineLiveRoom { background: transparent; }
    .room-wide-video.channels-room-active .channels-mobile-media video {
        inset: var(--live-video-top) 0 auto;
        height: calc(100vw / var(--room-video-ratio));
    }
    .room-portrait-video.channels-room-active .channels-mobile-media video { object-fit: cover; }
    .room-wide-video #inlineLiveRoom .player-container { height: auto; }
}

@media (orientation: landscape), (min-width: 701px) {
    #inlineLiveRoom .stream-title-row, #inlineLiveRoom .stream-title-right { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
    #inlineLiveRoom .stream-title-section { background: #161411cf; }
    #inlineLiveRoom :is(.like-btn, .share-btn, .chat-header, .chat-disabled) { display: none; }
    #inlineLiveRoom .room-mobile-close { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--brand-surface); color: #fff; text-decoration: none; }
    #inlineLiveRoom #chatSection { grid-row: 3; display: flex; gap: 6px; padding: 0 10px 8px; align-items: end; justify-content: end; }
    #inlineLiveRoom .room-chat-history { position: absolute; bottom: 50px; left: 0; max-height: 32dvh; max-width: 45%; background: #18151295; border-radius: 8px; }
    #inlineLiveRoom #chatMessages { overflow: auto; }
    #inlineLiveRoom .chat-input-area { padding: 0; background: transparent; border: 0; }
    #inlineLiveRoom .room-mobile-tools { display: flex; gap: 4px; }
}
body:has(#inlineLiveRoom) #glbar { display: none; }

.room-live-sound {
    position: absolute;
    z-index: 3;
    top: 10px;
    left: 10px;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid #ffffff45;
    background: color-mix(in srgb, var(--brand-surface) 72%, transparent);
    color: #fff;
    cursor: pointer;
}

@media (max-width: 700px) and (orientation: portrait) {
    .room-portrait-video .room-live-sound {
        inset: auto 10px calc(58px + env(safe-area-inset-bottom)) auto;
    }
    .room-portrait-video #inlineLiveRoom .player-section { pointer-events: none; }
}

:is(.channels-mobile-rotate, .room-mobile-rotate)::before,
:is(.channels-mobile-rotate, .room-mobile-rotate)::after {
    content: "";
    position: absolute;
    box-sizing: border-box;
    border: 1.5px solid currentColor;
    pointer-events: none;
}

:is(.channels-mobile-rotate, .room-mobile-rotate)::before {
    top: calc(50% - 6px);
    left: calc(50% - 10px);
    width: 12px;
    height: 16px;
    border-radius: 3px;
    background: linear-gradient(currentColor, currentColor) center top / 4px 1.5px no-repeat;
}

:is(.channels-mobile-rotate, .room-mobile-rotate)::after {
    top: calc(50% + 1px);
    left: calc(50% + 4px);
    width: 7px;
    height: 9px;
    border-color: #ffffff66;
    border-inline-start: 0;
    border-radius: 0 3px 3px 0;
}

.rotate-glyph-arrow {
    position: absolute;
    top: calc(50% - 10px);
    left: 50%;
    width: 7px;
    height: 6px;
    border-top: 1.5px solid currentColor;
    border-right: 1.5px solid currentColor;
    border-top-right-radius: 6px;
    pointer-events: none;
}

.rotate-glyph-arrow::after {
    content: "";
    position: absolute;
    right: -3px;
    bottom: 0;
    width: 4px;
    height: 4px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg);
}
