:root {
    color-scheme: dark;
    --page: #0b0c0d;
    --surface: #141617;
    --surface-raised: #1d2022;
    --line: #34383b;
    --line-strong: #555b5f;
    --text: #f3f4ef;
    --muted: #949a9d;
    --quiet: #697075;
    --live: #ff4d3d;
    --command: #c9362d;
    --ready: #45d17a;
    --waiting: #f1b94a;
    --focus: #8ad8ff;
    --radius: 4px;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    min-width: 320px;
    min-height: 100%;
    background: var(--page);
}

body {
    min-height: 100dvh;
    margin: 0;
    overflow-x: hidden;
    background: var(--page);
    color: var(--text);
    font-family: "Aptos", "Microsoft YaHei UI", sans-serif;
    letter-spacing: 0;
}

button,
select {
    font: inherit;
    letter-spacing: 0;
}

.topbar {
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 0 24px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.brand {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    color: inherit;
    text-decoration: none;
}

.brand-mark {
    width: 8px;
    height: 22px;
    flex: 0 0 auto;
    background: var(--live);
}

.brand-name {
    font-family: "Bahnschrift", "Microsoft YaHei UI", sans-serif;
    font-size: 15px;
    font-weight: 700;
}

.brand-channel {
    min-width: 0;
    padding-left: 10px;
    overflow: hidden;
    border-left: 1px solid var(--line-strong);
    color: var(--muted);
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.signal {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.signal-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--quiet);
}

.signal[data-state="connecting"] .signal-dot {
    background: var(--waiting);
}

.signal[data-state="live"] {
    color: var(--text);
}

.signal[data-state="live"] .signal-dot {
    background: var(--live);
    box-shadow: 0 0 0 4px rgb(255 77 61 / 14%);
    animation: signal-pulse 1.8s ease-out infinite;
}

.multiview-link {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 12px;
    text-decoration: none;
}

.multiview-link:hover {
    color: var(--text);
}

.multiview-link:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 3px;
}

.multiview-top-status {
    margin-left: auto;
    color: var(--muted);
    font-size: 12px;
}

.multiview-top-status[data-state="connected"] {
    color: var(--ready);
}

.multiview-top-status[data-state="reconnecting"] {
    color: var(--waiting);
}

.viewer {
    min-height: calc(100dvh - 58px);
    display: grid;
    place-items: center;
    padding: 22px 24px 26px;
}

.viewer-layout {
    width: min(100%, 1840px, calc(160dvh + 88px));
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(288px, 332px);
    align-items: stretch;
    gap: 12px;
}

.viewer-layout.sidebar-disabled {
    grid-template-columns: minmax(0, 1fr);
    width: min(100%, 1480px, calc(160dvh - 256px));
}

.viewer-layout.sidebar-disabled .viewer-sidebar {
    display: none;
}

.broadcast {
    width: 100%;
    min-width: 0;
}

.video-frame {
    position: relative;
    width: 100%;
    overflow: hidden;
    aspect-ratio: 16 / 10;
    border: 1px solid var(--line);
    border-radius: var(--radius) var(--radius) 0 0;
    background: #000;
    box-shadow: 0 24px 60px rgb(0 0 0 / 28%);
}

video {
    width: 100%;
    height: 100%;
    display: block;
    background: #000;
    object-fit: contain;
}

.offline-layer {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: #0e1011;
    text-align: center;
    transition: opacity 180ms ease, visibility 180ms ease;
}

.video-frame[data-state="live"] .offline-layer {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

.offline-signal {
    width: 72px;
    height: 42px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 6px;
    margin-bottom: 21px;
}

.offline-signal span {
    width: 8px;
    background: var(--line-strong);
}

.offline-signal span:nth-child(1) {
    height: 14px;
}

.offline-signal span:nth-child(2) {
    height: 27px;
}

.offline-signal span:nth-child(3) {
    height: 42px;
}

.video-frame[data-state="connecting"] .offline-signal span {
    background: var(--waiting);
    animation: meter 1.1s ease-in-out infinite alternate;
}

.video-frame[data-state="connecting"] .offline-signal span:nth-child(2) {
    animation-delay: 120ms;
}

.video-frame[data-state="connecting"] .offline-signal span:nth-child(3) {
    animation-delay: 240ms;
}

.offline-title {
    margin: 0;
    font-family: "Bahnschrift", "Microsoft YaHei UI", sans-serif;
    font-size: 28px;
    font-weight: 600;
}

.offline-detail {
    min-height: 20px;
    margin: 8px 0 22px;
    color: var(--muted);
    font-size: 13px;
}

.retry-button {
    min-height: 38px;
    padding: 0 16px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface-raised);
    color: var(--text);
    cursor: pointer;
}

.retry-button:hover {
    border-color: var(--text);
}

.retry-button:focus-visible,
select:focus-visible,
.brand:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 3px;
}

.control-strip {
    min-height: 54px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 8px 12px 8px 16px;
    border: 1px solid var(--line);
    border-top: 0;
    border-radius: 0 0 var(--radius) var(--radius);
    background: var(--surface);
}

.control-left {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 18px;
}

.stream-state {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--muted);
    font-size: 12px;
}

.state-label {
    color: var(--quiet);
}

.stream-state strong {
    color: var(--muted);
    font-family: "Bahnschrift", sans-serif;
    font-size: 12px;
}

.video-frame[data-state="live"] + .control-strip .stream-state strong {
    color: var(--live);
}

.state-separator {
    width: 1px;
    height: 14px;
    background: var(--line-strong);
}

#activeProfile {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.viewer-count,
.chat-viewers {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.viewer-count strong,
.chat-viewers strong {
    min-width: 1.3em;
    color: var(--text);
    font-family: "Bahnschrift", sans-serif;
    font-size: 13px;
    text-align: right;
}

.viewer-count-icon {
    position: relative;
    width: 14px;
    height: 10px;
    display: inline-block;
    border: 1px solid var(--muted);
    border-radius: 8px 8px 5px 5px;
    opacity: .85;
}

.viewer-count-icon::before {
    content: "";
    position: absolute;
    top: -7px;
    left: 4px;
    width: 5px;
    height: 5px;
    border: 1px solid var(--muted);
    border-radius: 50%;
    background: var(--surface);
}

.viewer-sidebar {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 12px;
}

.viewer-layout.chat-disabled .viewer-sidebar {
    grid-template-rows: auto;
    align-self: start;
}

.viewer-layout.channels-disabled .viewer-sidebar {
    grid-template-rows: minmax(0, 1fr);
}

.channel-panel {
    min-width: 0;
    max-height: 230px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.channel-panel-header {
    min-height: 54px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 13px;
    border-bottom: 1px solid var(--line);
}

.channel-panel-header h2 {
    margin: 0;
    font-family: "Bahnschrift", "Microsoft YaHei UI", sans-serif;
    font-size: 15px;
    font-weight: 600;
}

.channel-panel-header p {
    margin: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 10px;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.channel-panel-header p[data-state="connected"] {
    color: var(--ready);
}

.channel-panel-header p[data-state="reconnecting"] {
    color: var(--waiting);
}

.channel-list {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-color: var(--line-strong) transparent;
}

.channel-option {
    width: 100%;
    min-height: 43px;
    display: grid;
    grid-template-columns: 8px minmax(0, 1fr) auto;
    align-items: center;
    gap: 9px;
    padding: 8px 12px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-left: 2px solid transparent;
    background: transparent;
    color: var(--muted);
    text-align: left;
    cursor: pointer;
}

.channel-option:last-child {
    border-bottom: 0;
}

.channel-option:hover {
    background: var(--surface-raised);
    color: var(--text);
}

.channel-option[aria-pressed="true"] {
    border-left-color: var(--live);
    background: var(--surface-raised);
    color: var(--text);
}

.channel-option:focus-visible {
    position: relative;
    z-index: 1;
    outline: 2px solid var(--focus);
    outline-offset: -2px;
}

.channel-live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--quiet);
}

.channel-live-dot[data-state="live"] {
    background: var(--ready);
    box-shadow: 0 0 0 3px rgb(69 209 122 / 12%);
}

.channel-option-title {
    min-width: 0;
    overflow: hidden;
    font-size: 12px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.channel-option-status {
    color: var(--muted);
    font-size: 10px;
    white-space: nowrap;
}

.channel-option[aria-pressed="true"] .channel-option-status {
    color: var(--muted);
}

.chat-panel {
    min-width: 0;
    min-height: 0;
    height: auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.chat-header {
    min-height: 64px;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
}

.chat-header h2 {
    margin: 0;
    font-family: "Bahnschrift", "Microsoft YaHei UI", sans-serif;
    font-size: 16px;
    font-weight: 600;
}

.chat-header p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 11px;
}

.chat-header p[data-state="connected"] {
    color: var(--ready);
}

.chat-header p[data-state="reconnecting"] {
    color: var(--waiting);
}

.chat-header p[data-state="offline"] {
    color: var(--muted);
}

.chat-messages {
    min-height: 160px;
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 12px 14px;
    overscroll-behavior: contain;
    scrollbar-color: var(--line-strong) transparent;
}

.chat-empty {
    margin: 28px 0;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

.chat-message {
    margin: 0 0 12px;
    overflow-wrap: anywhere;
}

.chat-message:last-child {
    margin-bottom: 0;
}

.chat-message-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 3px;
}

.chat-message-name {
    max-width: 16em;
    overflow: hidden;
    color: var(--focus);
    font-size: 12px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-message-time {
    color: var(--muted);
    font-size: 10px;
}

.chat-message-text {
    margin: 0;
    color: var(--text);
    font-size: 13px;
    line-height: 1.45;
    white-space: pre-wrap;
}

.chat-compose {
    display: grid;
    flex: 0 0 auto;
    gap: 8px;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
}

.chat-compose input {
    width: 100%;
    height: 36px;
    min-width: 0;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    outline: none;
    background: var(--surface-raised);
    color: var(--text);
}

.chat-compose input::placeholder {
    color: var(--quiet);
}

.chat-compose input:focus-visible,
.chat-compose button:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

.chat-compose input:disabled {
    color: var(--quiet);
    cursor: not-allowed;
}

.chat-input-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
}

.chat-compose button {
    min-width: 58px;
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--command);
    border-radius: var(--radius);
    background: var(--command);
    color: #fff;
    cursor: pointer;
}

.chat-compose button:disabled {
    border-color: var(--line);
    background: var(--line);
    color: var(--quiet);
    cursor: not-allowed;
}

.chat-hint {
    min-height: 15px;
    margin: 0;
    color: var(--muted);
    font-size: 10px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.multiview-page {
    width: min(100%, 1840px);
    min-height: calc(100dvh - 58px);
    margin: 0 auto;
    padding: 26px 24px 36px;
}

.multiview-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 16px;
}

.multiview-heading h1 {
    margin: 0;
    font-family: "Bahnschrift", "Microsoft YaHei UI", sans-serif;
    font-size: 24px;
    font-weight: 600;
}

.multiview-heading p {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.multiview-limit {
    color: var(--muted);
    font-size: 11px;
}

.stream-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.stream-empty {
    grid-column: 1 / -1;
    min-height: 220px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--muted);
    background: var(--surface);
    font-size: 13px;
}

.stream-tile {
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.stream-tile-header,
.stream-tile-footer {
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 11px;
}

.stream-tile-header {
    border-bottom: 1px solid var(--line);
}

.stream-tile-header h2 {
    min-width: 0;
    margin: 0;
    overflow: hidden;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stream-tile-status {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 10px;
}

.stream-tile-status[data-state="live"] {
    color: var(--ready);
}

.stream-tile-status[data-state="offline"] {
    color: var(--waiting);
}

.stream-tile-frame {
    position: relative;
    overflow: hidden;
    aspect-ratio: 16 / 10;
    background: #000;
}

.stream-tile-frame video {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    background: #000;
}

.stream-tile-overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgb(9 10 11 / 76%);
    color: var(--muted);
    font-size: 12px;
}

.stream-tile-overlay[hidden] {
    display: none;
}

.stream-tile-footer {
    min-height: 40px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 10px;
}

.stream-audio-button {
    min-height: 28px;
    padding: 0 9px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface-raised);
    color: var(--muted);
    cursor: pointer;
    font-size: 11px;
}

.stream-audio-button:hover {
    border-color: var(--text);
    color: var(--text);
}

.stream-audio-button:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

.quality-control {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 12px;
}

select {
    min-width: 106px;
    height: 36px;
    padding: 0 30px 0 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-raised);
    color: var(--text);
}

select:disabled {
    color: var(--quiet);
    cursor: not-allowed;
}

@keyframes signal-pulse {
    from {
        box-shadow: 0 0 0 0 rgb(255 77 61 / 30%);
    }
    to {
        box-shadow: 0 0 0 7px rgb(255 77 61 / 0%);
    }
}

@keyframes meter {
    from {
        transform: scaleY(.45);
        transform-origin: bottom;
    }
    to {
        transform: scaleY(1);
        transform-origin: bottom;
    }
}

@media (max-width: 1100px) {
    .viewer {
        place-items: start center;
        overflow-y: auto;
    }

    .viewer-layout {
        width: min(100%, 1480px);
        grid-template-columns: minmax(0, 1fr);
    }

    .viewer-sidebar {
        display: flex;
        flex-direction: column;
    }

    .channel-panel {
        max-height: none;
    }

    .channel-panel-header {
        min-height: 50px;
    }

    .channel-list {
        display: flex;
        gap: 8px;
        padding: 8px;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x proximity;
    }

    .channel-option {
        width: auto;
        min-height: 44px;
        flex: 0 0 min(190px, 48vw);
        border: 1px solid var(--line);
        border-left: 2px solid transparent;
        border-radius: var(--radius);
        scroll-snap-align: start;
    }

    .channel-option:last-child {
        border-bottom: 1px solid var(--line);
    }

    .channel-option[aria-pressed="true"] {
        border-left-color: var(--live);
    }

    .chat-panel {
        height: 380px;
        max-height: none;
    }

    .stream-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 680px) {
    .topbar {
        min-height: 52px;
        padding: 0 14px;
    }

    .brand-channel {
        display: none;
    }

    .multiview-top-status {
        display: none;
    }

    .viewer {
        min-height: calc(100dvh - 52px);
        place-items: start center;
        padding: 12px 10px 18px;
    }

    .broadcast {
        width: 100%;
    }

    .viewer-layout {
        gap: 10px;
    }

    .viewer-sidebar {
        gap: 10px;
    }

    .channel-panel-header {
        min-height: 48px;
        padding: 9px 11px;
    }

    .channel-list {
        gap: 7px;
        padding: 7px;
    }

    .channel-option {
        flex-basis: min(180px, 68vw);
        padding: 8px 10px;
    }

    .control-strip {
        min-height: 62px;
        gap: 10px;
        padding: 9px 10px;
    }

    .control-left {
        gap: 10px;
    }

    .viewer-count {
        gap: 5px;
    }

    .chat-panel {
        height: auto;
        max-height: none;
    }

    .chat-messages {
        min-height: 190px;
        max-height: 340px;
    }

    .chat-header {
        min-height: 58px;
        padding: 10px 12px;
    }

    .chat-messages,
    .chat-compose {
        padding-left: 12px;
        padding-right: 12px;
    }

    .state-label,
    .state-separator,
    #activeProfile {
        display: none;
    }

    .quality-control > span {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }

    select {
        min-width: 96px;
    }

    .offline-title {
        font-size: 20px;
    }

    .multiview-page {
        min-height: calc(100dvh - 52px);
        padding: 16px 10px 24px;
    }

    .multiview-heading {
        align-items: start;
        flex-direction: column;
        gap: 7px;
        margin-bottom: 12px;
    }

    .multiview-heading h1 {
        font-size: 20px;
    }

    .stream-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
