:root {
    color-scheme: dark;
    --bg: #101214;
    --panel: #171b1f;
    --panel-2: #20262b;
    --line: #303840;
    --text: #f2f5f7;
    --muted: #a9b3bc;
    --accent: #2dd4bf;
    --accent-2: #8bd450;
    --danger: #ff6b6b;
    --warning: #f4c152;
    --shadow: rgba(0, 0, 0, 0.35);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

button,
input,
select {
    font: inherit;
}

button {
    border: 0;
    cursor: pointer;
    transition:
        background-color 0.12s ease,
        border-color 0.12s ease,
        color 0.12s ease,
        box-shadow 0.12s ease,
        filter 0.12s ease,
        translate 0.08s ease;
}

button:disabled {
    cursor: wait;
    opacity: 0.65;
}

button:not(:disabled):active {
    translate: 0 1px;
    filter: brightness(0.92);
}

input,
select {
    width: 100%;
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #0c0e10;
    color: var(--text);
    padding: 0.75rem 0.85rem;
    outline: none;
}

select {
    cursor: pointer;
}

input:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.16);
}

a {
    color: var(--accent);
}

.hidden {
    display: none !important;
}

.home-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.25rem;
}

.home-panel {
    width: min(560px, 100%);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: clamp(1.25rem, 4vw, 2rem);
    box-shadow: 0 18px 50px var(--shadow);
}

.home-account {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.1rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.home-account > div {
    display: flex;
    gap: 0.5rem;
}

.account-shell {
    width: min(960px, 100%);
    margin: 0 auto;
    padding: 1.25rem;
}

.account-header {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--line);
    padding-bottom: 1rem;
}

.account-header h1 {
    margin-bottom: 0;
    font-size: clamp(2rem, 6vw, 3.4rem);
}

.account-header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    align-items: center;
    justify-content: flex-end;
}

.account-page-grid {
    display: grid;
    grid-template-columns: minmax(260px, 0.85fr) minmax(320px, 1.15fr);
    gap: 1rem;
    align-items: start;
}

.account-page-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 1rem;
    box-shadow: 0 16px 42px var(--shadow);
}

.eyebrow {
    margin: 0 0 0.4rem;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0.4rem;
    font-size: clamp(2.3rem, 8vw, 4.8rem);
    line-height: 0.95;
    letter-spacing: 0;
}

h2 {
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
    letter-spacing: 0;
}

.home-copy {
    max-width: 36rem;
    color: var(--muted);
}

.create-form fieldset {
    margin: 1.25rem 0;
    padding: 0;
    border: 0;
}

.create-form legend {
    margin-bottom: 0.7rem;
    color: var(--muted);
    font-weight: 700;
}

.radio-row {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.8rem;
    align-items: start;
    margin-bottom: 0.75rem;
    padding: 0.9rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #12161a;
}

.radio-row input {
    width: auto;
    margin-top: 0.2rem;
    accent-color: var(--accent);
}

.radio-row small {
    display: block;
    color: var(--muted);
}

.primary-button,
.source-form button,
.chat-form button,
.stack-form button[type="submit"] {
    border-radius: 6px;
    background: var(--accent);
    color: #061110;
    font-weight: 800;
    padding: 0.78rem 1rem;
}

.primary-button:not(:disabled):active,
.source-form button:not(:disabled):active,
.chat-form button:not(:disabled):active,
.stack-form button[type="submit"]:not(:disabled):active,
.privacy-banner button:not(:disabled):active,
.play-unlock:not(:disabled):active,
.icon-button.copied:not(:disabled):active {
    box-shadow: inset 0 2px 10px rgba(6, 17, 16, 0.38);
}

.ghost-button,
.nickname-button,
.icon-button,
.danger-button,
.ghost-link {
    border-radius: 6px;
    color: var(--text);
    background: var(--panel-2);
    border: 1px solid var(--line);
    padding: 0.52rem 0.7rem;
}

.ghost-link {
    display: inline-grid;
    place-items: center;
    min-height: 2.25rem;
    text-decoration: none;
}

.ghost-button:not(:disabled):active,
.nickname-button:not(:disabled):active,
.icon-button:not(:disabled):active {
    background: #171d22;
    border-color: var(--accent);
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.32);
}

.icon-button.copied {
    color: #061110;
    background: var(--accent);
    border-color: transparent;
}

.icon-button.copied:not(:disabled):active {
    color: #061110;
    background: var(--accent);
    border-color: transparent;
}

.icon-button.active {
    color: var(--accent);
    background: rgba(45, 212, 191, 0.12);
    border-color: rgba(45, 212, 191, 0.42);
}

#copy-link {
    min-width: 4.75rem;
    text-align: center;
}

.room-invite {
    position: relative;
}

.invite-popover {
    position: absolute;
    left: 0;
    top: calc(100% + 0.5rem);
    z-index: 15;
    width: min(320px, calc(100vw - 2rem));
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #0d1012;
    padding: 0.85rem;
    box-shadow: 0 18px 50px var(--shadow);
}

.invite-popover .stack-form {
    margin-bottom: 0;
}

.danger-button {
    color: #240607;
    background: var(--danger);
    border-color: transparent;
    font-weight: 800;
}

.danger-button:not(:disabled):active {
    box-shadow: inset 0 2px 10px rgba(36, 6, 7, 0.38);
}

.form-error {
    min-height: 1.4rem;
    margin: 0.6rem 0 0;
    color: var(--danger);
}

.privacy-banner {
    position: fixed;
    inset: auto 1rem 1rem 1rem;
    z-index: 10;
    display: flex;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    max-width: 760px;
    margin: 0 auto;
    padding: 0.9rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #090b0c;
    box-shadow: 0 12px 35px var(--shadow);
}

.privacy-banner button {
    border-radius: 6px;
    background: var(--accent);
    color: #061110;
    padding: 0.45rem 0.8rem;
    font-weight: 800;
}

.room-error {
    max-width: 720px;
    margin: 3rem auto;
    padding: 1rem;
    border: 1px solid var(--danger);
    border-radius: 8px;
    color: var(--danger);
    background: rgba(255, 107, 107, 0.1);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(5, 6, 6, 0.72);
}

.nickname-modal,
.account-modal {
    width: min(420px, 100%);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: clamp(1rem, 4vw, 1.4rem);
    box-shadow: 0 18px 50px var(--shadow);
}

.nickname-modal h2,
.account-modal h2 {
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.nickname-modal label,
.account-modal label,
.stack-form label {
    display: block;
    margin-bottom: 0.45rem;
    color: var(--muted);
    font-weight: 700;
}

.account-modal label {
    margin-top: 0.75rem;
}

.optional-label {
    color: var(--muted);
    font-size: 0.78em;
    font-weight: 600;
}

.segmented-control {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.25rem;
    margin-bottom: 0.9rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #0c0e10;
    padding: 0.25rem;
}

.segmented-control button {
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    padding: 0.48rem 0.6rem;
    font-weight: 800;
}

.segmented-control button.active {
    background: var(--panel-2);
    color: var(--text);
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.9rem;
}

.modal-primary-actions {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    justify-content: flex-end;
}

.room-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr;
}

.topbar {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    min-height: 64px;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--line);
    background: #0d1012;
}

.room-id,
.topbar-status {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    align-items: center;
}

.room-id {
    position: relative;
}

.room-id .label {
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0;
}

#room-code {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 1.05rem;
}

.status-pill {
    min-height: 2.1rem;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.28rem 0.68rem;
    color: var(--muted);
    background: var(--panel);
    font-size: 0.86rem;
    white-space: nowrap;
}

#transport-pill[data-mode="p2p"] {
    color: #061110;
    background: var(--accent-2);
    border-color: transparent;
    font-weight: 800;
}

#transport-pill[data-mode="connecting"] {
    color: #211702;
    background: var(--warning);
    border-color: transparent;
    font-weight: 800;
}

.watch-layout {
    --side-panel-width: 380px;
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--side-panel-width);
    min-height: 0;
}

.watch-column {
    min-width: 0;
    padding: 1rem;
}

.host-controls {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(220px, 0.7fr) auto;
    gap: 0.8rem;
    align-items: end;
    margin-bottom: 1rem;
    padding: 0.9rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.source-form label {
    display: block;
    margin-bottom: 0.4rem;
    color: var(--muted);
    font-weight: 700;
}

.inline-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.5rem;
}

.drop-zone {
    position: relative;
    min-height: 86px;
    display: grid;
    place-items: center;
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 0.75rem;
    background: #12161a;
    text-align: center;
}

.drop-zone.dragging {
    border-color: var(--accent);
    background: rgba(45, 212, 191, 0.08);
}

.drop-zone input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.drop-zone span {
    display: block;
    color: var(--muted);
    font-size: 0.88rem;
}

.progress-wrap {
    grid-column: 1 / -1;
}

.progress-meter {
    height: 10px;
    overflow: hidden;
    border-radius: 999px;
    background: #0c0e10;
}

.progress-meter span {
    display: block;
    width: 0;
    height: 100%;
    background: var(--accent);
    transition: width 0.15s linear;
}

#upload-status {
    margin: 0.4rem 0 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.video-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    min-height: 220px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #050606;
}

.video-stage video {
    width: 100%;
    height: 100%;
    display: block;
    background: #050606;
}

.video-empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--muted);
    pointer-events: none;
}

.video-loading {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: grid;
    place-items: center;
    background:
        linear-gradient(180deg, rgba(5, 6, 6, 0.34), rgba(5, 6, 6, 0.74)),
        rgba(5, 6, 6, 0.58);
    pointer-events: none;
}

.video-loading-panel {
    position: relative;
    width: min(22rem, calc(100% - 2rem));
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(18, 21, 24, 0.94);
    padding: 1.05rem 1.1rem;
    box-shadow: 0 16px 40px var(--shadow);
}

.video-loading.is-remote .video-loading-panel {
    border-color: rgba(45, 212, 191, 0.42);
    background: rgba(13, 16, 18, 0.96);
    box-shadow:
        0 18px 52px rgba(0, 0, 0, 0.48),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.video-loading.is-remote .video-loading-panel::before {
    content: "Syncing with host";
    display: block;
    margin-bottom: 0.4rem;
    color: var(--accent);
    font-size: 0.68rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    line-height: 1;
    text-transform: uppercase;
}

.video-loading.is-remote .video-loading-panel::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 2px;
    background: var(--accent);
    box-shadow: 0 0 18px rgba(45, 212, 191, 0.62);
}

.video-loading-panel span {
    display: block;
    margin-bottom: 0.35rem;
    color: var(--text);
    font-size: 0.98rem;
    font-weight: 800;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.video-loading-panel .video-loading-file {
    margin-bottom: 0.75rem;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1.25;
}

.video-loading-panel .video-loading-file::before {
    content: "Video";
    display: inline-block;
    margin-right: 0.45rem;
    color: var(--accent);
    font-size: 0.68rem;
    font-weight: 900;
    text-transform: uppercase;
}

.video-loading-meter {
    height: 7px;
    overflow: hidden;
    border-radius: 999px;
    background: #0c0e10;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.video-loading-meter span {
    display: block;
    width: 0;
    height: 100%;
    margin: 0;
    border-radius: inherit;
    background: var(--accent);
    box-shadow: 0 0 14px rgba(45, 212, 191, 0.46);
    transition: width 0.18s linear;
}

.video-loading.is-indeterminate .video-loading-meter span {
    width: 35%;
    animation: loading-sweep 1s ease-in-out infinite;
}

.video-loading.has-error .video-loading-meter {
    display: none;
}

@keyframes loading-sweep {
    0% {
        transform: translateX(-120%);
    }

    100% {
        transform: translateX(320%);
    }
}

.play-unlock {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    max-width: calc(100% - 2rem);
    border-radius: 6px;
    background: var(--accent);
    color: #061110;
    padding: 0.78rem 1rem;
    font-weight: 800;
    box-shadow: 0 12px 28px var(--shadow);
}

.drift-overlay {
    position: absolute;
    left: 50%;
    bottom: 1rem;
    transform: translateX(-50%);
    max-width: calc(100% - 2rem);
    border-radius: 999px;
    background: rgba(5, 6, 6, 0.82);
    color: var(--text);
    padding: 0.45rem 0.8rem;
    font-size: 0.9rem;
    pointer-events: none;
}

.side-panel {
    min-height: 0;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    gap: 1rem;
    padding: 1rem;
    border-left: 1px solid var(--line);
    background: #121518;
}

.side-panel-bar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    min-height: 2.4rem;
}

.side-panel-bar span {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.room-shell.chat-collapsed .watch-layout {
    grid-template-columns: minmax(0, 1fr);
}

.room-shell.chat-collapsed .side-panel {
    display: none;
}

.chat-toggle-button {
    position: absolute;
    top: 50%;
    right: var(--side-panel-width);
    z-index: 9;
    width: 2rem;
    height: 3.75rem;
    display: grid;
    place-items: center;
    transform: translateY(-50%);
    border: 1px solid var(--line);
    border-right: 0;
    border-radius: 8px 0 0 8px;
    background: #121518;
    color: var(--muted);
    box-shadow: -8px 10px 24px var(--shadow);
}

.chat-toggle-button::before {
    content: "";
    width: 0;
    height: 0;
    border-top: 0.42rem solid transparent;
    border-bottom: 0.42rem solid transparent;
    border-left: 0.55rem solid currentColor;
}

.chat-toggle-button:hover,
.chat-toggle-button:focus-visible {
    color: var(--text);
}

.chat-toggle-button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.chat-toggle-button:not(:disabled):active {
    background: #0c0e10;
    color: var(--text);
    box-shadow: inset 2px 0 10px rgba(0, 0, 0, 0.34);
}

.room-shell.chat-collapsed .chat-toggle-button {
    right: 0;
}

.room-shell.chat-collapsed .chat-toggle-button::before {
    border-left: 0;
    border-right: 0.55rem solid currentColor;
}

.members-section,
.chat-section {
    min-height: 0;
}

.section-title-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: space-between;
}

.panel-note {
    margin-bottom: 0.75rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.stack-form {
    display: grid;
    gap: 0.5rem;
    margin-bottom: 0.85rem;
}

.stack-form .inline-form {
    margin-bottom: 0;
}

.inline-status {
    min-height: 1.2rem;
    margin: 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.members-list {
    display: grid;
    gap: 0.45rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.members-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 0.45rem 0.6rem;
}

.members-list strong {
    border-radius: 999px;
    background: rgba(45, 212, 191, 0.16);
    color: var(--accent);
    padding: 0.15rem 0.45rem;
    font-size: 0.72rem;
}

.friends-list {
    display: grid;
    gap: 0.45rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.friends-list li {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    justify-content: space-between;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 0.5rem 0.6rem;
}

.friends-list li > span {
    min-width: 0;
    display: grid;
    gap: 0.1rem;
}

.friends-list strong,
.friends-list small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.friends-list strong {
    color: var(--text);
    font-size: 0.88rem;
}

.friends-list small,
.friends-empty {
    color: var(--muted);
    font-size: 0.8rem;
}

.friends-list button {
    flex: 0 0 auto;
    padding: 0.36rem 0.5rem;
    font-size: 0.76rem;
}

.chat-section {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
}

.chat-log {
    min-height: 280px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #0c0f11;
    padding: 0.75rem;
}

.chat-message,
.chat-system {
    overflow-wrap: anywhere;
    margin-bottom: 0.75rem;
}

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

.chat-meta {
    margin-bottom: 0.12rem;
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 800;
}

.chat-text {
    color: var(--text);
}

.chat-system {
    color: var(--muted);
    font-size: 0.9rem;
    font-style: italic;
}

.chat-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

@media (max-width: 900px) {
    .account-page-grid {
        grid-template-columns: 1fr;
    }

    .watch-layout {
        grid-template-columns: 1fr;
    }

    .side-panel {
        border-left: 0;
        border-top: 1px solid var(--line);
    }

    .chat-toggle-button {
        position: fixed;
        top: auto;
        right: 0.75rem;
        bottom: 0.75rem;
        width: 2.25rem;
        height: 2.75rem;
        transform: none;
        border: 1px solid var(--line);
        border-radius: 8px;
    }

    .room-shell.chat-collapsed .chat-toggle-button {
        right: 0.75rem;
    }

    .host-controls {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .account-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .account-header-actions,
    .home-account {
        align-items: stretch;
        flex-direction: column;
    }

    .home-account > div {
        flex-direction: column;
    }

    .topbar {
        align-items: flex-start;
    }

    .topbar,
    .topbar-status {
        flex-direction: column;
    }

    .room-id,
    .topbar-status {
        width: 100%;
    }

    .topbar-status > * {
        max-width: 100%;
    }

    .room-invite,
    .room-invite > button {
        width: 100%;
    }

    .invite-popover {
        left: 0;
        width: calc(100vw - 1.5rem);
    }

    .watch-column,
    .side-panel {
        padding: 0.75rem;
    }

    .inline-form,
    .chat-form {
        grid-template-columns: 1fr;
    }

    .video-stage {
        min-height: 180px;
    }

    .privacy-banner {
        align-items: stretch;
        flex-direction: column;
    }

    .modal-actions,
    .modal-primary-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .modal-actions button,
    .modal-primary-actions button {
        width: 100%;
    }

}
