:root {
    --indigo: #5b5bf7;
    --indigo-hover: #4848e0;
    --indigo-soft: #eeeefe;
    --ink: #0d1321;
    --ink-2: #1f2937;
    --muted: #6b7280;
    --muted-2: #9ca3af;
    --line: #e5e7eb;
    --line-2: #eef0f3;
    --bg: #f4f4f6;
    --card: #ffffff;
    --red: #e03131;
    --red-hover: #c92727;
    --green: #16a34a;
    --dark: #0b0b0f;
    --dark-2: #14141b;
    --glass: rgba(22, 22, 30, 0.88);
    --glass-line: rgba(255, 255, 255, 0.08);
    --radius-card: 20px;
    --radius: 12px;
    --pill: 999px;
    --shadow-card: 0 1px 2px rgba(13, 19, 33, 0.04),
        0 8px 28px rgba(13, 19, 33, 0.08);
    --shadow-float: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI",
        system-ui, sans-serif;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.live {
    background-color: var(--dark);
}

#stream {
    width: 100%;
    height: 100%;
    background-color: #000;
}

.hidden {
    display: none !important;
}

.clickable {
    cursor: pointer;
}

/* ---------- Centered-view layout (landing / chooser / pin / errors) ---- */

.popup {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 4;
}

.popup.hidden {
    display: none !important;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-card);
    padding: 32px 28px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.card-wide {
    max-width: 560px;
}

.brand {
    color: var(--indigo);
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.01em;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.card-back {
    all: unset;
    cursor: pointer;
    color: var(--muted);
    padding: 6px;
    border-radius: 8px;
    line-height: 0;
}

.card-back:hover {
    background: var(--line-2);
    color: var(--ink);
}

.hero-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--indigo-soft);
    color: var(--indigo);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 4px 0 2px;
}

h1.hero-title {
    font-size: 22px;
    line-height: 1.2;
    margin: 0;
    letter-spacing: -0.01em;
    color: var(--ink);
    font-weight: 600;
}

h1.hero-title .accent {
    color: var(--indigo);
    display: block;
}

.hero-sub {
    color: var(--muted);
    margin: 0;
    font-size: 14px;
    line-height: 1.4;
}

.card-title {
    font-size: 18px;
    margin: 0;
    font-weight: 600;
    letter-spacing: -0.005em;
}

.card-title .room-name {
    color: var(--indigo);
    font-family: "SF Mono", ui-monospace, Menlo, monospace;
    font-size: 0.95em;
    font-weight: 500;
}

.card p {
    margin: 0;
    line-height: 1.5;
    color: var(--ink);
}

.footer-hint {
    color: var(--muted);
    font-size: 12.5px;
    line-height: 1.5;
    margin: 4px 0 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    justify-content: center;
    text-align: center;
}

.hint {
    color: var(--muted);
    font-size: 13px;
    margin: 0;
    line-height: 1.4;
}

.error {
    color: var(--red);
    margin: 0;
    font-size: 13px;
}

.room-name {
    color: var(--indigo);
    font-family: "SF Mono", ui-monospace, Menlo, monospace;
}

/* ---------- Buttons ---------- */

.btn {
    all: unset;
    box-sizing: border-box;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 18px;
    border-radius: var(--radius);
    font-size: 14.5px;
    font-weight: 500;
    background: var(--line-2);
    color: var(--ink);
    border: 1px solid transparent;
    transition: background 120ms ease, transform 120ms ease, opacity 120ms ease;
    user-select: none;
}

.btn:hover {
    background: var(--line);
}

.btn-block {
    width: 100%;
    padding: 13px 18px;
}

.btn-primary {
    background: var(--indigo);
    color: #fff;
    font-weight: 500;
}

.btn-primary:hover {
    background: var(--indigo-hover);
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--ink);
}

.btn-ghost:hover {
    background: var(--line-2);
}

.btn-danger {
    background: var(--red);
    color: #fff;
}

.btn-danger:hover {
    background: var(--red-hover);
}

.btn:disabled,
.btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-small {
    padding: 6px 10px;
    font-size: 13px;
    border-radius: 8px;
}

.btn .ico {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.btn .ico-trail {
    margin-left: auto;
}

/* ---------- Inputs ---------- */

input[type="text"] {
    all: unset;
    box-sizing: border-box;
    display: block;
    width: 100%;
    padding: 12px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--ink);
    font-size: 14.5px;
    font-family: "SF Mono", ui-monospace, Menlo, monospace;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

input[type="text"]::placeholder {
    color: var(--muted-2);
}

input[type="text"]:focus {
    border-color: var(--indigo);
    box-shadow: 0 0 0 3px rgba(91, 91, 247, 0.12);
}

.input-group {
    display: flex;
    align-items: stretch;
    gap: 8px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 4px 4px 4px 12px;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.input-group:focus-within {
    border-color: var(--indigo);
    box-shadow: 0 0 0 3px rgba(91, 91, 247, 0.12);
}

.input-group input[type="text"] {
    border: none;
    padding: 10px 0;
    background: transparent;
    box-shadow: none;
}

.input-group input[type="text"]:focus {
    box-shadow: none;
}

.input-group .input-icon {
    display: inline-flex;
    align-items: center;
    color: var(--muted-2);
    flex: 0 0 auto;
}

.input-arrow {
    all: unset;
    box-sizing: border-box;
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--indigo);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    align-self: center;
    transition: background 120ms ease;
}

.input-arrow:hover {
    background: var(--indigo-hover);
}

/* ---------- Dividers ---------- */

.or-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted-2);
    font-size: 12.5px;
    text-transform: lowercase;
    letter-spacing: 0.02em;
    margin: -2px 0;
}

.or-divider::before,
.or-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--line);
}

/* Centered pill divider: "Or join an existing room" */
.label-divider {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 4px 0 -4px;
}

.label-divider::before,
.label-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--line);
}

.label-divider span {
    padding: 6px 14px;
    border-radius: var(--pill);
    background: var(--indigo-soft);
    color: var(--indigo);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.005em;
}

/* Plain horizontal rule inside cards */
.hr {
    height: 1px;
    background: var(--line);
    margin: 4px 0;
}

/* Inner bordered card (Room ID input group) */
.card-inset {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--card);
}

.card-inset-label {
    color: var(--ink);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.005em;
}

.card-inset-hint {
    color: var(--muted);
    font-size: 12.5px;
    margin: 0;
}

.card-inset-row {
    display: flex;
    align-items: stretch;
    gap: 10px;
}

.card-inset-row .input-group {
    flex: 1 1 auto;
    padding: 2px 2px 2px 12px;
}

.card-inset-row .input-group input[type="text"] {
    font-family: inherit;
}

.card-inset-row .btn {
    flex: 0 0 auto;
    white-space: nowrap;
}

.hero-lead {
    font-size: 28px;
    line-height: 1.15;
    margin: 0;
    letter-spacing: -0.015em;
    color: var(--ink);
    font-weight: 700;
}

.hero-lead .accent {
    color: var(--indigo);
    display: block;
}

.footer-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
    padding: 4px 2px 0;
}

.footer-row svg {
    color: var(--ink-2);
    flex: 0 0 auto;
    margin-top: 2px;
}

/* ---------- Toggles & preference rows ---------- */

.section-label {
    color: var(--muted);
    font-size: 15px;
    font-weight: 500;
    letter-spacing: -0.005em;
    margin: 0 2px;
}

#role-share-options {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 4px;
}

#role-share-options .hr {
    margin: 4px 0 6px;
}

.pref-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
    background: var(--card);
}

.pref {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    cursor: pointer;
    user-select: none;
}

.pref + .pref {
    border-top: 1px solid var(--line);
}

.pref-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ink);
    flex: 0 0 auto;
}

.pref-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1 1 auto;
}

.pref-title {
    color: var(--ink);
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.005em;
}

.pref-sub {
    color: var(--muted);
    font-size: 13px;
}

.pref-extra {
    flex: 0 0 auto;
}

.switch {
    position: relative;
    width: 42px;
    height: 24px;
    background: #d6d8de;
    border-radius: 999px;
    transition: background 140ms ease;
    flex: 0 0 auto;
}

.switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    transition: transform 160ms ease;
}

.pref-check {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
}

.pref-check:checked ~ .switch,
.pref-check:checked + .switch {
    background: var(--indigo);
}

.pref-check:checked ~ .switch::after,
.pref-check:checked + .switch::after {
    transform: translateX(18px);
}

.pref-check:focus-visible ~ .switch {
    box-shadow: 0 0 0 3px rgba(91, 91, 247, 0.25);
}

/* PIN chip inside the Room PIN row */
.pin-chip {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    border-radius: 10px;
    background: var(--indigo-soft);
    color: var(--indigo);
    font-family: "SF Mono", ui-monospace, Menlo, monospace;
    font-size: 15px;
    letter-spacing: 0.08em;
    font-weight: 600;
}

.pin-chip .icon-btn {
    color: var(--indigo);
    padding: 3px;
}

.pin-chip .icon-btn:hover {
    background: rgba(91, 91, 247, 0.12);
    color: var(--indigo-hover);
}

/* Legacy .checkbox kept for anything outside the chooser (none today, but
   preserved in case a translation file hasn't been migrated yet). */
.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ink-2);
    font-size: 13.5px;
    cursor: pointer;
    user-select: none;
}

.checkbox input {
    accent-color: var(--indigo);
    width: 16px;
    height: 16px;
    margin: 0;
}

/* ---------- Occupied banner (role chooser) ---------- */

.info-pill {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--pill);
    background: #f0fdf4;
    color: #14532d;
    font-size: 13.5px;
    font-weight: 500;
    align-self: center;
}

.pulse-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--green);
    position: relative;
    flex: 0 0 auto;
}

.pulse-dot::after {
    content: "";
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    background: var(--green);
    opacity: 0.4;
    animation: pulse 1.6s ease-out infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    100% {
        transform: scale(1.4);
        opacity: 0;
    }
}

/* ---------- Role chooser section layout ---------- */

.role-option {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.role-divider {
    height: 1px;
    background: var(--line);
    margin: 4px 0;
}

/* ---------- PIN entry ---------- */

#pin-input {
    font-family: "SF Mono", ui-monospace, Menlo, monospace;
    font-size: 26px;
    letter-spacing: 0.35em;
    text-align: center;
    padding: 14px;
}

/* ---------- Live / broadcaster chrome ---------- */

body.live .popup:not(.hidden) {
    color: #fff;
}

body.live .card {
    background: var(--dark-2);
    border-color: var(--glass-line);
    color: #fff;
}

body.live .hint,
body.live .card p {
    color: #d1d5db;
}

/* Floating broadcaster info panel (top-right) */
.info-panel {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 5;
    width: min(320px, calc(100vw - 32px));
    background: var(--glass);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border: 1px solid var(--glass-line);
    border-radius: 16px;
    color: #fff;
    box-shadow: var(--shadow-float);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.info-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 2px 4px;
}

.info-count {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #d1d5db;
    font-size: 13px;
}

.info-count-value {
    color: #fff;
    font-weight: 600;
}

.info-toggle {
    all: unset;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    color: #d1d5db;
    font-size: 13px;
}

.info-toggle:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.info-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.info-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-line);
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 13px;
    color: #e5e7eb;
}

.info-row .info-label {
    color: #9ca3af;
    font-size: 11.5px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    flex: 0 0 auto;
}

.info-row .info-value {
    flex: 1 1 auto;
    font-family: "SF Mono", ui-monospace, Menlo, monospace;
    font-size: 13px;
    color: #fff;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.info-row .info-value-pin {
    letter-spacing: 0.2em;
    font-size: 14px;
}

.icon-btn {
    all: unset;
    cursor: pointer;
    color: #d1d5db;
    padding: 6px;
    border-radius: 8px;
    line-height: 0;
    flex: 0 0 auto;
    transition: background 120ms ease, color 120ms ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.audio-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid var(--glass-line);
    border-radius: 10px;
    font-size: 13px;
    color: #d1d5db;
}

.audio-status[data-state="shared"] {
    color: #86efac;
}

.audio-status[data-state="denied"] {
    color: #fca5a5;
}

.audio-bars {
    display: inline-flex;
    align-items: flex-end;
    gap: 3px;
    height: 14px;
}

.audio-bars span {
    width: 3px;
    background: currentColor;
    border-radius: 1px;
    opacity: 0.4;
    height: 4px;
}

.audio-status[data-state="shared"] .audio-bars span {
    animation: bars 1.1s ease-in-out infinite;
    opacity: 0.9;
}

.audio-status[data-state="shared"] .audio-bars span:nth-child(1) {
    animation-delay: 0s;
}
.audio-status[data-state="shared"] .audio-bars span:nth-child(2) {
    animation-delay: 0.15s;
}
.audio-status[data-state="shared"] .audio-bars span:nth-child(3) {
    animation-delay: 0.3s;
}
.audio-status[data-state="shared"] .audio-bars span:nth-child(4) {
    animation-delay: 0.45s;
}

@keyframes bars {
    0%, 100% { height: 4px; }
    50% { height: 14px; }
}

/* Stop-sharing button (bottom-right) */
.stop-fab {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 5;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 11px 16px;
    border-radius: 12px;
    background: var(--red);
    color: #fff;
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    border: none;
    box-shadow: var(--shadow-float);
    transition: background 120ms ease;
}

.stop-fab:hover {
    background: var(--red-hover);
}

.stop-fab .stop-dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    background: #fff;
}

/* E2E chip (bottom-left on live) */
.e2e-chip {
    position: fixed;
    left: 16px;
    bottom: 16px;
    z-index: 5;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 11px;
    border-radius: var(--pill);
    background: rgba(22, 22, 30, 0.88);
    border: 1px solid var(--glass-line);
    color: #d1d5db;
    font-size: 12.5px;
    user-select: none;
    pointer-events: none;
}

/* Room name pill (viewer top-left) */
.room-pill {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 5;
    padding: 7px 12px;
    border-radius: var(--pill);
    background: var(--glass);
    border: 1px solid var(--glass-line);
    color: #fff;
    font-family: "SF Mono", ui-monospace, Menlo, monospace;
    font-size: 12.5px;
    user-select: none;
    pointer-events: none;
}

/* Viewer count pill (top-right on viewer side) */
.count-pill {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 5;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border-radius: var(--pill);
    background: var(--glass);
    border: 1px solid var(--glass-line);
    color: #fff;
    font-size: 12.5px;
    user-select: none;
    pointer-events: none;
}

/* Viewer HUD: big circular unmute button */
.hud-stack {
    position: fixed;
    left: 50%;
    bottom: 36px;
    transform: translateX(-50%);
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

#unmute-audio {
    all: unset;
    cursor: pointer;
    pointer-events: auto;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--indigo);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 30px rgba(91, 91, 247, 0.4),
        0 4px 12px rgba(0, 0, 0, 0.35);
    transition: background 120ms ease, transform 120ms ease;
}

#unmute-audio:hover {
    background: var(--indigo-hover);
    transform: scale(1.03);
}

.hud-caption {
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    letter-spacing: 0.005em;
}

/* Send-link button inside the broadcaster info panel */
.info-body .send-link {
    padding: 9px 14px;
    font-size: 14px;
}

/* Viewer fullscreen toggle (bottom-right) */
.fs-btn {
    all: unset;
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 5;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--glass);
    border: 1px solid var(--glass-line);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-float);
    transition: background 120ms ease;
}

.fs-btn:hover {
    background: rgba(40, 40, 52, 0.92);
}

.fs-btn:focus-visible {
    outline: 2px solid var(--indigo);
    outline-offset: 2px;
}

.fs-btn.hidden {
    display: none;
}

.fs-btn .fs-exit,
.fs-btn.is-active .fs-enter {
    display: none;
}

.fs-btn.is-active .fs-exit {
    display: block;
}

/* ---------- Responsive ---------- */

@media (max-width: 460px) {
    .card {
        padding: 24px 20px;
    }
    h1.hero-title {
        font-size: 20px;
    }
}
