*, *::before, *::after { box-sizing: border-box; }

        :root {
            --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
        }

        html {
            background: #0d0f14;
        }

        html, body {
            width: 100%;
            height: 100%;
            overflow: hidden;
            overscroll-behavior: none;
        }

        body {
            position: relative;
            font-family: var(--font-sans);
            margin: 0;
            padding: 0;
            min-height: 100dvh;
            background:
                linear-gradient(180deg, rgba(5, 7, 18, 0.18) 0%, rgba(4, 20, 34, 0.62) 52%, rgba(1, 9, 15, 0.98) 100%),
                radial-gradient(ellipse at 50% 120%, rgba(6, 95, 90, 0.36) 0%, rgba(8, 47, 73, 0.16) 32%, transparent 64%),
                radial-gradient(ellipse at 18% 18%, rgba(20, 184, 166, 0.18) 0%, transparent 38%),
                radial-gradient(ellipse at 84% 12%, rgba(168, 85, 247, 0.20) 0%, transparent 36%),
                #030712;
            color: #e2e8f0;
            display: flex;
            flex-direction: column;
            touch-action: manipulation;
            -webkit-font-smoothing: antialiased;
            text-rendering: optimizeLegibility;
        }

        body::before,
        body::after {
            content: "";
            position: fixed;
            inset: 0;
            pointer-events: none;
        }

        body::before {
            z-index: 0;
            background:
                linear-gradient(116deg, transparent 5%, rgba(45, 212, 191, 0.24) 21%, rgba(59, 130, 246, 0.05) 37%, transparent 52%),
                linear-gradient(72deg, transparent 17%, rgba(34, 197, 94, 0.14) 34%, rgba(217, 70, 239, 0.20) 50%, transparent 70%),
                linear-gradient(142deg, transparent 34%, rgba(14, 165, 233, 0.12) 48%, rgba(124, 58, 237, 0.16) 62%, transparent 78%);
            filter: blur(28px) saturate(1.24);
            opacity: 0.88;
            transform: scale(1.14) translateY(-3%);
        }

        body::after {
            z-index: 0;
            background:
                radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.72) 0 1px, transparent 1.6px),
                radial-gradient(circle at 28% 34%, rgba(188, 247, 255, 0.48) 0 1px, transparent 1.7px),
                radial-gradient(circle at 64% 14%, rgba(255, 255, 255, 0.62) 0 1px, transparent 1.5px),
                radial-gradient(circle at 84% 38%, rgba(192, 132, 252, 0.46) 0 1px, transparent 1.8px),
                radial-gradient(circle at 72% 70%, rgba(125, 211, 252, 0.34) 0 1px, transparent 1.7px),
                repeating-linear-gradient(105deg, rgba(125, 211, 252, 0.07) 0 1px, transparent 1px 42px),
                linear-gradient(180deg, rgba(3, 7, 18, 0.05), rgba(2, 6, 23, 0.64));
            background-size: 180px 180px, 230px 230px, 210px 210px, 260px 260px, 310px 310px, auto, auto;
            mix-blend-mode: screen;
            opacity: 0.58;
        }

        .stream-meta {
            gap: 12px;
            padding: 9px 12px;
            background: rgba(7, 10, 16, 0.18);
            border: 1px solid rgba(255,255,255,0.08);
            border-radius: 14px;
            box-shadow: 0 8px 22px rgba(0,0,0,0.16);
            backdrop-filter: blur(14px) saturate(1.15);
        }

        /* ── Page wrapper ──────────────────────────── */
        .page {
            position: relative;
            z-index: 1;
            margin: 0 auto;
            width: 100%;
            max-width: 820px;
            min-height: 100dvh;
            padding: calc(clamp(58px, 13dvh, 108px) + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: flex-start;
        }

        h2 {
            font-size: 1rem;
            font-weight: 600;
            color: #a0aec0;
            margin: 0 0 16px;
            text-transform: uppercase;
            letter-spacing: 0.8px;
        }

        p {
            margin: 0 0 14px;
            font-size: 0.875rem;
            color: #718096;
        }

        /* ── Glass card ──────────────────────────── */
        .card {
            background: rgba(255,255,255,0.04);
            border: 1px solid rgba(255,255,255,0.08);
            border-radius: 18px;
            padding: 28px;
            backdrop-filter: blur(12px);
            width: 100%;
        }

        /* ── Home screen ─────────────────────────── */
        #home {
            display: flex;
            flex-direction: column;
            gap: 20px;
            text-align: center;
            max-width: 520px;
            background: transparent;
            border: none;
            box-shadow: none;
            backdrop-filter: none;
            padding: 0;
        }

        .home-copy {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 9px;
        }

        .home-kicker {
            margin: 0;
            color: rgba(125, 211, 252, 0.92);
            font-size: 0.68rem;
            font-weight: 800;
            letter-spacing: 0.16em;
            line-height: 1.2;
            text-transform: uppercase;
        }

        .home-copy h1 {
            max-width: 440px;
            margin: 0;
            color: #f8fafc;
            font-size: clamp(2rem, 3.5vw, 2.75rem);
            font-weight: 800;
            line-height: 1.08;
            text-wrap: balance;
            text-shadow: 0 14px 38px rgba(0, 0, 0, 0.38);
        }

        .home-subtitle {
            max-width: 430px;
            margin: 0;
            color: rgba(226, 232, 240, 0.70);
            font-size: 0.98rem;
            line-height: 1.48;
            text-wrap: balance;
        }

        .home-actions {
            display: flex;
            flex-direction: column;
            gap: 10px;
            width: 100%;
            align-items: stretch;
            max-width: 460px;
            margin: 0 auto;
            padding: 22px 12px;
            background: rgba(21, 25, 34, 0.92);
            border: 1px solid rgba(125, 211, 252, 0.18);
            border-image: none;
            border-radius: 22px;
            box-shadow: none;
        }

        .home-utility-actions {
            display: flex;
            justify-content: center;
            gap: 10px;
            flex-wrap: wrap;
        }

        .home-utility-btn {
            padding: 4px 6px;
            background: transparent;
            border: 0;
            border-radius: 999px;
            color: rgba(226, 232, 240, 0.42);
            font-size: 0.76rem;
            font-weight: 600;
            line-height: 1;
            transform: none;
            transition: none;
        }

        .home-utility-btn:hover {
            background: transparent;
            color: rgba(226, 232, 240, 0.42);
        }

        .home-utility-btn:active {
            transform: none;
        }

        .report-problem-modal {
            position: fixed;
            inset: 0;
            z-index: 50;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px 20px 18vh;
            background: rgba(2, 6, 23, 0.58);
            -webkit-backdrop-filter: blur(8px);
            backdrop-filter: blur(8px);
        }

        .report-problem-modal[hidden] {
            display: none;
        }

        .report-problem-dialog {
            width: min(100%, 320px);
            padding: 20px 18px 18px;
            border-radius: 14px;
            background: rgba(15, 23, 42, 0.94);
            border: 1px solid rgba(125, 211, 252, 0.18);
            box-shadow:
                0 22px 62px rgba(0, 0, 0, 0.40),
                inset 0 1px 0 rgba(255, 255, 255, 0.05);
            text-align: center;
        }

        .report-problem-dialog h2 {
            margin: 0 0 10px;
            color: #f8fafc;
            font-size: 0.94rem;
            font-weight: 800;
            letter-spacing: 0;
            line-height: 1.25;
            text-transform: none;
        }

        .report-problem-dialog p {
            margin: 0;
            color: rgba(226, 232, 240, 0.78);
            font-size: 0.86rem;
            line-height: 1.45;
        }

        .report-problem-dialog a {
            color: #7dd3fc;
            font-weight: 700;
            text-decoration: none;
        }

        .report-problem-close {
            margin-top: 14px !important;
            color: rgba(226, 232, 240, 0.48) !important;
            font-size: 0.72rem !important;
        }

        .home-notice {
            display: none;
            padding: 11px 12px;
            border-radius: 10px;
            background: rgba(244, 63, 94, 0.12);
            border: 1px solid rgba(244, 63, 94, 0.26);
            color: #fecdd3;
            font-size: 0.85rem;
            line-height: 1.4;
        }

        .home-notice.is-visible {
            display: block;
        }

        .home-separator {
            display: flex;
            align-items: center;
            align-self: center;
            width: 90%;
            gap: 12px;
            font-size: 0.68rem;
            font-weight: 700;
            letter-spacing: 0.18em;
            text-transform: uppercase;
            color: #8b98aa;
            margin: 2px 0;
        }

        .home-separator::before,
        .home-separator::after {
            content: "";
            height: 1px;
            flex: 1;
            background: rgba(148,163,184,0.18);
        }

        .action-card {
            background: #1b202b;
            border: 1px solid rgba(255,255,255,0.08);
            border-radius: 17px;
            padding: 13px 18px;
            cursor: pointer;
            transition: none;
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: flex-start;
            gap: 14px;
            font-family: inherit;
            color: inherit;
            text-align: left;
        }

        .action-card-body {
            display: flex;
            flex-direction: column;
            gap: 4px;
        }

        .action-card.primary {
            position: relative;
            overflow: hidden;
            isolation: isolate;
            min-height: 52px;
            background: #2b6ff4;
            border: 0;
            box-shadow: none;
            margin: 0 12px 4px;
        }

        .action-card.primary::before {
            content: none;
        }

        .action-card.primary::after {
            content: none;
        }

        .action-card.primary .action-card-body {
            position: relative;
            z-index: 1;
        }

        .action-card.primary:hover {
            box-shadow: none;
        }

        .action-card.secondary {
            background: transparent;
            border-color: transparent;
        }

        .action-card.primary .action-desc {
            color: #eff6ff;
        }

        .action-label {
            font-size: 1.04rem;
            font-weight: 700;
            color: #f7fafc;
        }

        .action-desc {
            font-size: 0.82rem;
            font-weight: 400;
            color: rgba(255,255,255,0.64);
            margin: 0;
            line-height: 1.4;
        }

        .join-card {
            text-align: left;
            align-items: center;
            justify-content: space-between;
            gap: 20px;
            min-height: 58px;
            padding: 8px 12px;
            background: transparent;
            border-color: transparent;
            box-shadow: none;
            cursor: default;
        }

        .join-card-header {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            flex: 1 1 auto;
            gap: 4px;
            min-width: 0;
        }

        .join-card-copy {
            display: flex;
            flex-direction: column;
            gap: 4px;
            width: 100%;
        }

        .join-card .action-desc {
            margin: 0;
        }

        .join-card .action-label {
            color: #f8fafc;
        }

        .join-card .action-desc {
            color: #9aa6b8;
        }

        .join-card .action-label,
        .join-card .action-desc {
            white-space: nowrap;
        }

        .join-card-form {
            display: flex;
            align-items: center;
            width: clamp(224px, 54%, 270px);
            min-width: 200px;
            flex: 0 0 auto;
            margin-left: auto;
            position: relative;
            height: 42px;
            min-height: 42px;
            padding: 0;
            border-radius: 0;
            background: transparent;
            border: none;
            overflow: visible;
        }

        .join-card-form .btn-primary {
            position: absolute;
            top: 5px;
            right: 5px;
            width: 32px;
            height: 32px;
            min-width: 32px;
            justify-content: center;
            padding: 0;
            border-radius: 50%;
            background: #2563eb;
            border: none;
            color: #ffffff;
            box-shadow: none;
            transform: none;
            transition: none;
        }

        .join-card-form .btn-primary:active,
        .join-arrow-btn:active {
            transform: none;
        }

        .join-arrow-btn svg {
            width: 19px;
            height: 19px;
            stroke: currentColor;
            fill: none;
            stroke-width: 2.35;
            stroke-linecap: round;
            stroke-linejoin: round;
            pointer-events: none;
        }

        .join-card-form .btn-primary:hover {
            background: #2563eb;
            box-shadow: none;
            filter: none;
        }

        .join-card-form input[type="text"] {
            min-width: 0;
            width: 100%;
            height: 42px;
            min-height: 0;
            padding: 0 48px 0 15px;
            background: #101827;
            border: 1px solid rgba(255,255,255,0.10);
            border-radius: 999px;
            box-shadow: none;
            font-size: 0.945rem;
            font-weight: 400;
            letter-spacing: 0.2px;
            color: #f8fafc;
            cursor: text;
        }

        .join-card-form input[type="text"]::placeholder {
            color: #8d98aa;
            font-size: 0.945rem;
            font-weight: 400;
        }

        .join-card-form input[type="text"]:focus {
            background: #101827;
            border-color: rgba(255,255,255,0.10);
            box-shadow: none;
        }

        .join-card-form .btn {
            flex: 0 0 auto;
        }

        /* ── Buttons ──────────────────────────────── */
        button {
            font-family: var(--font-sans);
            border: none;
            cursor: pointer;
            font-weight: 600;
            transition: all 0.15s;
            border-radius: 10px;
        }

        button:active { transform: scale(0.96); }

        .action-card:active {
            transform: none;
        }

        .btn {
            display: inline-flex;
            align-items: center;
            gap: 7px;
            padding: 10px 20px;
            font-size: 0.9rem;
            border-radius: 10px;
        }

        .btn-danger {
            background: linear-gradient(135deg, #f43f5e, #e11d48);
            color: #fff;
            box-shadow: 0 2px 12px rgba(244,63,94,0.3);
        }

        .btn-danger:hover {
            box-shadow: 0 4px 20px rgba(244,63,94,0.5);
            filter: brightness(1.08);
        }

        .btn-primary {
            background: linear-gradient(135deg, #6366f1, #8b5cf6);
            color: #fff;
            box-shadow: 0 2px 12px rgba(99,102,241,0.3);
        }

        .btn-primary:hover {
            box-shadow: 0 4px 20px rgba(99,102,241,0.5);
            filter: brightness(1.08);
        }

        .btn-ghost {
            background: rgba(255,255,255,0.07);
            color: #a0aec0;
            border: 1px solid rgba(255,255,255,0.1);
        }

        .btn-ghost:hover {
            background: rgba(255,255,255,0.12);
            color: #e2e8f0;
        }

        .btn-subtle {
            background: rgba(8, 12, 18, 0.42);
            color: #f8fafc;
            border: 1px solid rgba(255,255,255,0.12);
            -webkit-backdrop-filter: blur(10px);
            backdrop-filter: blur(10px);
        }

        .btn-subtle:hover {
            background: rgba(15, 20, 28, 0.58);
        }

        .stream-control {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            min-height: 52px;
            padding: 0 16px;
            border-radius: 999px;
            background: rgba(255,255,255,0.08);
            color: #f8fafc;
            border: 1px solid rgba(255,255,255,0.1);
            -webkit-backdrop-filter: blur(12px);
            backdrop-filter: blur(12px);
            box-shadow: 0 10px 30px rgba(0,0,0,0.28);
        }

        .stream-control:hover {
            background: rgba(255,255,255,0.14);
        }

        #toggleMicBtn:hover,
        #toggleMicBtn:active,
        #toggleCameraBtn:hover,
        #toggleCameraBtn:active,
        #viewerToggleMicBtn:hover,
        #viewerToggleMicBtn:active,
        #viewerToggleCameraBtn:hover,
        #viewerToggleCameraBtn:active,
        #switchCameraBtn:hover,
        #switchCameraBtn:active,
        #viewerSwitchCameraBtn:hover,
        #viewerSwitchCameraBtn:active {
            background: rgba(255,255,255,0.08);
            filter: none;
        }

        #toggleMicBtn.is-off:hover,
        #toggleMicBtn.is-off:active,
        #toggleCameraBtn.is-off:hover,
        #toggleCameraBtn.is-off:active,
        #viewerToggleMicBtn.is-off:hover,
        #viewerToggleMicBtn.is-off:active,
        #viewerToggleCameraBtn.is-off:hover,
        #viewerToggleCameraBtn.is-off:active {
            background: rgba(244,63,94,0.16);
            border-color: rgba(244,63,94,0.34);
        }

        .stream-control svg {
            width: 20px;
            height: 20px;
            stroke: currentColor;
            fill: none;
            stroke-width: 1.9;
            stroke-linecap: round;
            stroke-linejoin: round;
            pointer-events: none;
            flex: 0 0 auto;
        }

        .stream-control svg.solid-control-icon {
            fill: currentColor;
            stroke: none;
        }

        .stream-control-label {
            font-size: 0.88rem;
            font-weight: 700;
            letter-spacing: 0.01em;
            white-space: nowrap;
            display: none;
        }

        .stream-control.is-off {
            background: rgba(244,63,94,0.16);
            color: #ffd6de;
            border-color: rgba(244,63,94,0.34);
        }

        .stream-control-stop {
            background: linear-gradient(135deg, #f43f5e, #e11d48);
            border-color: rgba(255,255,255,0.18);
            color: #fff;
        }

        .stream-control-stop:hover {
            background: linear-gradient(135deg, #fb5074, #ef1f52);
        }

        .control-panel {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            padding: 12px;
            border-radius: 999px;
            background: rgba(8, 12, 18, 0.52);
            border: 1px solid rgba(255,255,255,0.1);
            -webkit-backdrop-filter: blur(16px) saturate(1.15);
            backdrop-filter: blur(16px);
            box-shadow: 0 20px 60px rgba(0,0,0,0.38);
            pointer-events: auto;
        }

        .control-panel .stream-control {
            width: 52px;
            height: 52px;
            min-height: 52px;
            padding: 0;
            border-radius: 50%;
            flex: 0 0 52px;
        }

        .icon-btn {
            justify-content: center;
            width: 46px;
            height: 46px;
            padding: 0;
            border-radius: 14px;
            background: transparent;
            border: none;
            backdrop-filter: none;
            box-shadow: none;
            color: rgba(248,250,252,0.92);
            text-shadow: 0 2px 12px rgba(0,0,0,0.55);
        }

        .icon-btn:hover {
            background: transparent;
            color: #ffffff;
            opacity: 0.82;
        }

        .icon-btn svg {
            width: 20px;
            height: 20px;
            stroke: currentColor;
            fill: none;
            stroke-width: 1.9;
            stroke-linecap: round;
            stroke-linejoin: round;
            pointer-events: none;
        }

        #switchCameraBtn,
        #viewerSwitchCameraBtn {
            padding: 0;
            border-radius: 50%;
            background: rgba(255,255,255,0.08);
            border: 1px solid rgba(255,255,255,0.1);
            -webkit-backdrop-filter: blur(12px);
            backdrop-filter: blur(12px);
            box-shadow: 0 10px 30px rgba(0,0,0,0.28);
            text-shadow: none;
        }

        #switchCameraBtn:hover,
        #viewerSwitchCameraBtn:hover {
            opacity: 1;
        }

        #switchCameraBtn,
        #viewerSwitchCameraBtn {
            display: none;
        }

        #toggleMicBtn svg,
        #toggleCameraBtn svg,
        #switchCameraBtn svg {
            width: 18px;
            height: 18px;
        }

        #fullscreenBtn,
        #viewerFullscreenBtn {
            display: inline-flex;
        }

        .hud.stream-meta {
            gap: 0;
            padding: 4px;
            background: rgba(8, 10, 16, 0.78);
            border: 1px solid rgba(255,255,255,0.10);
            border-radius: 18px;
            box-shadow:
                0 12px 34px rgba(0,0,0,0.30),
                inset 0 1px 0 rgba(255,255,255,0.04);
            -webkit-backdrop-filter: blur(14px) saturate(1.12);
            backdrop-filter: blur(14px) saturate(1.12);
        }

        .live-badge {
            display: inline-flex;
            align-items: center;
            padding: 9px 13px 9px 15px;
            color: #ff5a5a;
            font-size: 0.68rem;
            font-weight: 800;
            letter-spacing: 0.26em;
            text-transform: uppercase;
            line-height: 1;
        }

        .live-badge::before {
            content: none;
        }

        #streamId {
            display: inline-flex;
            align-items: center;
            gap: 9px;
            font-weight: 700;
            font-size: 0.76rem;
            color: rgba(248,250,252,0.76);
            letter-spacing: 0.20em;
            font-variant-numeric: tabular-nums;
            padding: 9px 11px 9px 15px;
            border-left: 1px solid rgba(255,255,255,0.12);
            text-shadow: 0 1px 10px rgba(0,0,0,0.22);
            line-height: 1;
            cursor: pointer;
            user-select: none;
        }

        .stream-id-value {
            display: inline-flex;
            align-items: center;
        }

        .copy-code-icon {
            width: 14px;
            height: 14px;
            fill: currentColor;
            opacity: 0.58;
            flex: 0 0 auto;
        }

        #streamId[data-copy-state]::after {
            content: attr(data-copy-state);
            font-size: 0.56rem;
            font-weight: 800;
            letter-spacing: 0.16em;
            color: #8a8f98;
        }

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

        /* ── Input ───────────────────────────────── */
        .join-input-row {
            display: flex;
            gap: 10px;
            flex-wrap: wrap;
            align-items: center;
            margin-bottom: 16px;
        }

        input[type="text"] {
            flex: 1;
            min-width: 160px;
            padding: 11px 16px;
            background: rgba(255,255,255,0.06);
            border: 1px solid rgba(255,255,255,0.12);
            border-radius: 10px;
            font-family: var(--font-sans);
            font-size: 1rem;
            font-weight: 600;
            color: #e2e8f0;
            letter-spacing: 3px;
            outline: none;
            transition: border-color 0.15s, box-shadow 0.15s;
        }

        input[type="text"]::placeholder {
            letter-spacing: 0;
            font-weight: 400;
            color: #4a5568;
            font-size: 0.9rem;
        }

        input[type="text"]:focus {
            border-color: #6366f1;
            box-shadow: 0 0 0 3px rgba(99,102,241,0.2);
            background: rgba(99,102,241,0.08);
        }

        /* ── Loading Dots ────────────────────────── */
        .spinner {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            margin-bottom: 10px;
        }

        .spinner span {
            width: 9px;
            height: 9px;
            border-radius: 50%;
            background: #a78bfa;
            opacity: 0.28;
            animation: dotPulse 1s ease-in-out infinite;
        }

        .spinner span:nth-child(2) {
            animation-delay: 0.16s;
        }

        .spinner span:nth-child(3) {
            animation-delay: 0.32s;
        }

        @keyframes dotPulse {
            0%, 100% {
                transform: translateY(0);
                opacity: 0.28;
            }
            50% {
                transform: translateY(-4px);
                opacity: 1;
            }
        }

        /* ── Video container ─────────────────────── */
        .video-container {
            position: fixed;
            inset: 0;
            width: 100vw;
            height: 100vh;
            height: 100dvh;
            background: #0a0b0f;
            z-index: 1;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .video-container.portrait {
            max-width: unset;
            width: 100vw;
        }

        video {
            width: 100%;
            height: 100%;
            object-fit: contain;
            object-position: center;
            background: #0a0b0f;
            display: block;
        }

        .video-inset {
            position: fixed;
            right: 18px;
            bottom: calc(104px + env(safe-area-inset-bottom));
            width: var(--inset-width, min(28vw, 176px));
            height: auto;
            max-height: var(--inset-max-height, min(32vh, 200px));
            aspect-ratio: var(--inset-ratio, 3 / 4);
            object-fit: cover;
            border-radius: 16px;
            overflow: hidden;
            background: #050812;
            border: 1px solid rgba(255,255,255,0.18);
            outline: 1px solid rgba(0,0,0,0.34);
            box-shadow:
                0 22px 52px rgba(0,0,0,0.42),
                0 0 0 6px rgba(5, 8, 18, 0.24);
            z-index: 12;
            transition: opacity 0.2s ease, transform 0.2s ease;
            touch-action: none;
            cursor: grab;
        }

        .video-inset.top-right {
            top: calc(72px + env(safe-area-inset-top));
            bottom: auto;
            width: var(--inset-width, min(25vw, 190px));
            height: auto;
            aspect-ratio: var(--inset-ratio, 4 / 3);
        }

        .video-inset.hidden {
            opacity: 0;
            pointer-events: none;
            transform: translateY(8px);
        }

        @media (orientation: landscape) and (max-width: 932px) {
            .video-container {
                width: 100vw;
                height: 100dvh;
            }

            video {
                width: 100vw;
                height: 100dvh;
            }

            .video-inset {
                width: min(18vw, 128px);
            }
        }

        /* ── HUD (controls on top of video) ─────── */
        .hud {
            position: fixed;
            z-index: 10;
            display: flex;
            align-items: center;
            gap: 10px;
            flex-wrap: wrap;
        }

        .hud-top {
            top: calc(16px + env(safe-area-inset-top));
            left: 16px;
            text-shadow: 0 1px 6px rgba(0,0,0,0.8);
            background: rgba(0,0,0,0.35);
            -webkit-backdrop-filter: blur(6px);
            backdrop-filter: blur(6px);
            padding: 6px 12px;
            border-radius: 8px;
        }

        .hud-top-right {
            top: calc(16px + env(safe-area-inset-top));
            right: 16px;
            left: auto;
            background: transparent;
            padding: 0;
            border-radius: 0;
            text-shadow: none;
            -webkit-backdrop-filter: none;
            backdrop-filter: none;
        }

        .hud-bottom {
            bottom: calc(20px + env(safe-area-inset-bottom));
            left: 0;
            right: 0;
            justify-content: center;
            pointer-events: none;
        }

        .hud-controls {
            gap: 12px;
        }

        .hud-join {
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            flex-direction: column;
            background: rgba(10,11,15,0.85);
            -webkit-backdrop-filter: blur(12px);
            backdrop-filter: blur(12px);
            border: 1px solid rgba(255,255,255,0.08);
            border-radius: 14px;
            padding: 24px 28px;
            gap: 14px;
        }

        .hud-join-row {
            display: flex;
            gap: 10px;
            align-items: center;
        }

        .streamer-chrome,
        .joiner-chrome {
            transition: none;
        }

        .streamer-chrome.is-hidden,
        .joiner-chrome.is-hidden {
            opacity: 0;
            visibility: hidden;
            pointer-events: none;
        }

        .stream-meta.streamer-chrome.is-hidden {
            transform: translateY(-10px);
        }

        .hud-top-right.streamer-chrome.is-hidden {
            transform: translateY(-10px);
        }

        .hud-top-right.joiner-chrome.is-hidden {
            transform: translateY(-10px);
        }

        .hud-bottom.streamer-chrome.is-hidden {
            transform: translateY(10px);
        }

        .hud-bottom.joiner-chrome.is-hidden {
            transform: translateY(10px);
        }

        .overlay {
            position: fixed;
            inset: 0;
            display: none;
            align-items: center;
            justify-content: center;
            flex-direction: column;
            text-align: center;
            background: rgba(7,8,12,0.82);
            -webkit-backdrop-filter: blur(4px);
            backdrop-filter: blur(4px);
            z-index: 20;
            font-size: 0.9rem;
            color: #a0aec0;
            gap: 4px;
        }

        @media (max-width: 640px) {
                    #switchCameraBtn,
                    #viewerSwitchCameraBtn {
                display: inline-flex;
            }

            #fullscreenBtn,
            #viewerFullscreenBtn {
                display: none;
            }

            .page {
                padding: calc(48px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
            }

            .card {
                padding: 24px 20px;
            }

            .home-actions {
                max-width: none;
                padding: 18px 10px;
                border-radius: 20px;
            }

            .home-copy {
                gap: 10px;
            }

            .home-copy h1 {
                font-size: 1.85rem;
                line-height: 1.08;
            }

            .home-subtitle {
                font-size: 0.92rem;
                line-height: 1.48;
            }

            .action-card {
                width: 100%;
            }

            .action-card.primary {
                width: auto;
                margin: 0 10px 6px;
            }

            .join-card {
                gap: 12px;
                padding: 10px;
            }

            .join-card-header {
                flex: 0 0 max-content;
            }

            .join-card-form {
                flex-direction: row;
                align-items: center;
                width: clamp(160px, 50%, 190px);
                min-width: 0;
                flex: 0 1 190px;
                margin-left: auto;
            }

            .hud-controls {
                gap: 10px;
            }

            .control-panel {
                gap: 8px;
                padding: 10px;
                max-width: calc(100vw - 24px);
            }

            .stream-control {
                min-height: 48px;
                padding: 0 14px;
            }

            .control-panel .stream-control {
                width: 48px;
                height: 48px;
                min-height: 48px;
                padding: 0;
                border-radius: 50%;
                flex: 0 0 48px;
            }

            .stream-control-label {
                display: none;
            }

            .video-inset {
                right: 14px;
                bottom: calc(90px + env(safe-area-inset-bottom));
                width: var(--inset-width, 108px);
                height: auto;
                max-height: var(--inset-max-height, 144px);
                border-radius: 14px;
            }

            .video-inset.top-right {
                top: calc(64px + env(safe-area-inset-top));
                bottom: auto;
                width: var(--inset-width, 124px);
                height: auto;
            }

            .btn {
                padding: 10px 16px;
            }

            .hud-join {
                width: min(92vw, 420px);
                padding: 20px;
            }

            .hud-join-row {
                width: 100%;
                flex-direction: column;
            }

            input[type="text"] {
                width: 100%;
            }
        }

        @media (hover: none) and (pointer: coarse) {
                    #switchCameraBtn,
                    #viewerSwitchCameraBtn {
                display: inline-flex;
            }

            #fullscreenBtn,
            #viewerFullscreenBtn {
                display: none;
            }
        }
