:root {
    color-scheme: dark;
    --bg: #0d121c;
    --panel: #161d2b;
    --panel-soft: #1f2737;
    --text: #f1f4fa;
    --muted: #94a0b8;
    --border: rgba(255, 255, 255, 0.08);
    --primary: #7c8cff;
    --success: #22c55e;
    --warning: #f5b544;
    --danger: #ef4444;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        Segoe UI,
        Roboto,
        Helvetica,
        Arial,
        sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 max(20px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(20px, env(safe-area-inset-left));
}

.top-bar {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 4px;
}

.top-bar h1 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.15rem;
    font-weight: 500;
}

.app-title-icon {
    width: 30px;
    height: 30px;
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.video-layout,
.offline-layout {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

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

.video-layout.self-preview-hidden {
    grid-template-columns: 1fr;
}

.video-layout.self-preview-hidden .local {
    display: none;
}

.video-card {
    position: relative;
    min-height: 0;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--panel);
    overflow: hidden;
}

.video-card.remote {
    background: radial-gradient(90% 80% at 50% 45%, #1a2133, #111826 70%);
    container-type: size;
}

.offline-card {
    display: grid;
    place-items: center;
}

.offline-content {
    position: relative;
    z-index: 2;
    width: min(580px, calc(100% - 32px));
    margin: 0 auto;
    padding: 20px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 14px;
    background: rgba(5, 9, 16, 0.62);
    text-align: center;
}

.offline-content h2 {
    margin: 0 0 8px;
    font-size: 1.2rem;
    letter-spacing: 0.2px;
}

.offline-content p {
    margin: 0;
    color: var(--muted);
    line-height: 1.45;
}

.video-card video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background: var(--panel);
}

.video-header {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    background: rgba(31, 37, 52, 0.85);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.connection-badge {
    --dot: var(--muted);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--muted);
    white-space: nowrap;
}

.connection-badge::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--dot);
}

.connection-badge.searching,
.connection-badge.waiting {
    --dot: var(--warning);
}

.connection-badge.connected {
    --dot: var(--success);
}

.connection-badge.reconnecting,
.connection-badge.error {
    --dot: var(--danger);
}

.offline-card .connection-badge::before {
    animation: offline-pulse 1.4s ease-out infinite;
}

.video-placeholder {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: clamp(6px, 3cqmin, 12px);
    z-index: 2;
    text-align: center;
    padding: clamp(8px, 4cqmin, 18px);
    overflow: hidden;
    color: var(--muted);
    font-size: clamp(0.72rem, 3.2cqmin, 0.86rem);
}

.video-placeholder[data-mode='searching'] {
    background: radial-gradient(90% 80% at 50% 45%, #1a2133, #111826 70%);
}

.video-placeholder[data-mode='matched'] {
    background: rgba(8, 11, 18, 0.35);
    -webkit-backdrop-filter: blur(28px);
    backdrop-filter: blur(28px);
}

.placeholder-title {
    margin: 0;
    font-size: clamp(1rem, 6cqmin, 1.3rem);
    font-weight: 700;
    color: var(--text);
}

.placeholder-text {
    margin: 0;
    max-width: 420px;
    font-size: clamp(0.75rem, 3.4cqmin, 0.88rem);
    line-height: 1.4;
}

.video-placeholder[data-mode='searching'] .placeholder-title {
    margin-top: clamp(0px, 2cqmin, 14px);
}

.video-placeholder[data-mode='searching'] .placeholder-text {
    margin-bottom: clamp(0px, 2cqmin, 10px);
}

.video-placeholder[data-mode='matched'] .placeholder-text {
    color: var(--text);
}

.placeholder-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: clamp(5px, 2cqmin, 9px) clamp(12px, 4cqmin, 18px);
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text);
    font-size: clamp(0.7rem, 3cqmin, 0.8rem);
}

.pill-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
}

.video-spinner {
    display: none;
    width: clamp(36px, 20cqmin, 84px);
    height: clamp(36px, 20cqmin, 84px);
    flex-shrink: 0;
    border-radius: 999px;
    border: 3px solid rgba(156, 171, 199, 0.16);
    border-top-color: var(--primary);
    animation: video-spinner-rotate 1.1s linear infinite;
}

.video-placeholder.is-searching .video-spinner {
    display: inline-block;
}

.match-check {
    display: none;
    width: clamp(36px, 18cqmin, 76px);
    height: clamp(36px, 18cqmin, 76px);
    border: 3px solid var(--success);
    border-radius: 50%;
    background: rgba(34, 197, 94, 0.08);
    color: var(--success);
    place-items: center;
    animation: match-check-in 0.35s ease-out;
}

.match-check svg {
    width: 38px;
    height: 38px;
    stroke: currentColor;
    fill: none;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.video-placeholder[data-mode='matched'] .match-check {
    display: grid;
}

@keyframes match-check-in {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
}

@keyframes video-spinner-rotate {
    to {
        transform: rotate(360deg);
    }
}

.media-status {
    display: inline-flex;
}

.media-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border-radius: 999px;
    border: 1px solid rgba(255, 99, 125, 0.55);
    background: rgba(255, 99, 125, 0.2);
    color: #ff9db0;
}

.media-pill[hidden] {
    display: none;
}

.media-pill svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.remote-avatar-overlay {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 6px;
    text-align: center;
    background: radial-gradient(90% 80% at 50% 45%, #1a2133, #0e1420 75%);
    color: var(--muted);
}

.local-avatar-overlay {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 6px;
    text-align: center;
    background: radial-gradient(90% 80% at 50% 45%, #1a2133, #0e1420 75%);
    color: var(--muted);
}

.video-avatar {
    position: relative;
    width: 76px;
    height: 76px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    background: rgba(255, 255, 255, 0.06);
    display: grid;
    place-items: center;
    color: rgba(156, 171, 199, 0.95);
}

.video-avatar svg {
    width: 34px;
    height: 34px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.video-avatar .video-avatar-badge {
    position: absolute;
    right: -2px;
    bottom: -2px;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 999px;
    border: 1px solid rgba(255, 99, 125, 0.55);
    background: #2d1721;
    box-shadow: 0 0 0 2px #050910;
    color: #ff8ba0;
}

.video-avatar .video-avatar-badge svg {
    width: 14px;
    height: 14px;
    stroke-width: 2.2;
}

.remote-avatar-overlay > span,
.local-avatar-overlay > span {
    font-size: 0.8rem;
    letter-spacing: 0.2px;
    color: rgba(156, 171, 199, 0.95);
}

.settings-panel {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 10;
    width: min(320px, calc(100vw - 32px));
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--panel);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}

.control-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
    padding: 22px 4px;
}

.status-area {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    color: var(--muted);
    font-size: 0.8rem;
    line-height: 1.45;
}

.status-area p {
    margin: 0;
    white-space: pre-line;
    max-width: 280px;
}

.status-area svg {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    color: #8b97ff;
}

.call-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
}

.control-divider {
    flex-shrink: 0;
    align-self: center;
    width: 1px;
    height: 24px;
    background: var(--border);
}

.match-controls {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.capacity-modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    background: rgba(3, 5, 10, 0.72);
    -webkit-backdrop-filter: blur(8px) saturate(120%);
    backdrop-filter: blur(8px) saturate(120%);
    padding: 16px;
    animation: modal-backdrop-in 0.2s ease-out;
}

.capacity-modal-card {
    --modal-accent: var(--primary);
    --modal-accent-rgb: 124, 140, 255;
    position: relative;
    overflow: hidden;
    width: min(440px, 100%);
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    padding: 32px 28px 26px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background:
        radial-gradient(120% 70% at 50% -10%, rgba(var(--modal-accent-rgb), 0.16), transparent 60%),
        linear-gradient(180deg, #131a28 0%, #0b101b 100%);
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.4),
        0 24px 60px rgba(0, 0, 0, 0.6),
        0 0 80px rgba(var(--modal-accent-rgb), 0.12);
    text-align: center;
    animation: modal-card-in 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.capacity-modal-card::before {
    content: '';
    position: absolute;
    inset: 0 0 auto;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--modal-accent), transparent);
}

.capacity-modal-card.modal-danger {
    --modal-accent: var(--danger);
    --modal-accent-rgb: 239, 68, 68;
}

.capacity-modal-card.modal-warning {
    --modal-accent: var(--warning);
    --modal-accent-rgb: 245, 181, 68;
}

.modal-icon {
    display: grid;
    place-items: center;
    width: 60px;
    height: 60px;
    margin: 0 auto 18px;
    border-radius: 50%;
    color: var(--modal-accent);
    background: rgba(var(--modal-accent-rgb), 0.14);
    border: 1px solid rgba(var(--modal-accent-rgb), 0.35);
    box-shadow: 0 0 0 6px rgba(var(--modal-accent-rgb), 0.06);
}

.modal-icon svg {
    width: 28px;
    height: 28px;
    stroke: currentColor;
    stroke-width: 2;
}

.capacity-modal-card h2 {
    margin: 0 0 10px;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.25;
}

.capacity-modal-card p {
    margin: 0 0 24px;
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.55;
    text-wrap: pretty;
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.modal-actions .btn {
    flex: 1 1 0;
    justify-content: center;
}

.capacity-modal-card .btn {
    justify-content: center;
    text-decoration: none;
    min-width: 140px;
}

.capacity-modal-card .primary-btn {
    background: linear-gradient(180deg, #8d9bff, var(--primary));
    box-shadow: 0 6px 18px rgba(124, 140, 255, 0.35);
}

.capacity-modal-card .end-btn {
    box-shadow: 0 6px 18px rgba(239, 68, 68, 0.35);
}

@keyframes modal-backdrop-in {
    from {
        opacity: 0;
    }
}

@keyframes modal-card-in {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.96);
    }
}

@media (max-width: 480px) {
    .capacity-modal-card {
        padding: 26px 20px 20px;
    }

    .modal-actions {
        flex-direction: column-reverse;
    }

    .capacity-modal-card .btn {
        flex: none;
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .capacity-modal,
    .capacity-modal-card {
        animation: none;
    }
}

.device-controls {
    display: grid;
    gap: 10px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 0.76rem;
    color: var(--muted);
}

.input-group select {
    width: 100%;
    background: var(--panel-soft);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 9px;
    font-size: 0.83rem;
}

.input-group select:disabled {
    opacity: 0.6;
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.76rem;
    color: var(--muted);
    cursor: pointer;
}

.switch {
    position: relative;
    flex-shrink: 0;
    width: 38px;
    height: 22px;
}

.switch input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.switch-track {
    position: absolute;
    inset: 0;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--panel-soft);
    transition:
        background 0.2s ease,
        border-color 0.2s ease;
    pointer-events: none;
}

.switch-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--muted);
    transition:
        transform 0.2s ease,
        background 0.2s ease;
}

.switch input:checked + .switch-track {
    background: var(--primary);
    border-color: transparent;
}

.switch input:checked + .switch-track::after {
    transform: translateX(16px);
    background: #fff;
}

.switch input:focus-visible + .switch-track {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.background-image-picker-row {
    display: grid;
    gap: 6px;
}

.background-image-picker-row[hidden] {
    display: none;
}

.background-preset-list {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
}

.background-preset {
    display: grid;
    place-items: center;
    aspect-ratio: 16 / 9;
    padding: 0;
    overflow: hidden;
    color: var(--muted);
    background: var(--panel-soft);
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition:
        border-color 0.15s ease,
        transform 0.15s ease;
}

.background-preset img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.background-preset svg {
    width: 18px;
    height: 18px;
}

.background-preset:hover:not(:disabled) {
    border-color: var(--muted);
}

.background-preset:active:not(:disabled) {
    transform: scale(0.95);
}

.background-preset:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.background-preset[aria-pressed='true'] {
    border-color: var(--primary);
}

.background-preset:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.background-image-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.74rem;
    color: var(--muted);
}

.btn {
    font: inherit;
    color: var(--text);
    background: #1c2230;
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition:
        transform 0.15s ease,
        filter 0.2s ease,
        opacity 0.2s ease;
}

.btn:hover:not(:disabled) {
    filter: brightness(1.2);
}

.btn:active:not(:disabled) {
    transform: scale(0.95);
}

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

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.icon-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

.icon-btn.end-btn {
    width: 44px;
    height: 44px;
}

.icon-btn.end-btn svg {
    transform: rotate(135deg);
    fill: currentColor;
}

.ghost-btn {
    width: 40px;
    height: 40px;
    background: transparent;
    border-color: transparent;
}

.icon-btn svg,
.pill-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.pill-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 36px;
    padding: 0 16px;
    font-size: 0.82rem;
    font-weight: 600;
}

.pill-btn svg {
    width: 15px;
    height: 15px;
}

.primary-btn {
    background: var(--primary);
    border-color: transparent;
    color: #fff;
}

.match-controls .pill-btn {
    font-weight: 700;
}

.match-controls .pill-btn svg {
    width: 17px;
    height: 17px;
}

#startBtn svg {
    fill: currentColor;
}

#nextBtn svg {
    fill: currentColor;
}

#startBtn.primary-btn:not(:disabled) {
    box-shadow: 0 0 0 0 rgba(124, 140, 255, 0.5);
    animation: start-pulse 2.4s ease-out infinite;
}

@keyframes start-pulse {
    70% {
        box-shadow: 0 0 0 10px rgba(124, 140, 255, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(124, 140, 255, 0);
    }
}

@media (prefers-reduced-motion: reduce) {
    #startBtn.primary-btn:not(:disabled) {
        animation: none;
    }
}

.subtle-btn {
    background: rgba(124, 140, 255, 0.16);
    border-color: rgba(124, 140, 255, 0.3);
}

.end-btn {
    width: 46px;
    height: 46px;
    background: #ef3f4a;
    border-color: transparent;
    color: #fff;
}

/* Muted/off state: tinted red so the solid-red End button stays the only destructive action */
.icon-btn.off {
    background: rgba(239, 68, 68, 0.3);
    border-color: rgba(239, 68, 68, 0.7);
    color: #ffe1e1;
}

/* Hiding the self preview is a preference, not a problem: keep it neutral instead of red */
#hideSelfBtn.off {
    background: rgba(124, 140, 255, 0.16);
    border-color: rgba(124, 140, 255, 0.45);
    color: #c7ceff;
}

.icon-btn.has-unread {
    position: relative;
}

.icon-btn.has-unread::after {
    content: '';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 0 2px var(--bg);
}

/* Chat docks next to the videos as a third column and shrinks them to make room */
.video-layout:has(.chat-panel:not([hidden])) {
    grid-template-columns: 1fr 1fr minmax(300px, 340px);
}

.video-layout.self-preview-hidden:has(.chat-panel:not([hidden])) {
    grid-template-columns: 1fr minmax(300px, 340px);
}

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

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

.chat-title h2 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 0.72rem;
}

.chat-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
}

.chat-header .ghost-btn {
    width: 36px;
    height: 36px;
    background: var(--panel-soft);
    border-color: var(--border);
    color: var(--muted);
}

.chat-scroll {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    padding: 14px;
    overflow-y: auto;
}

.chat-notice {
    align-self: center;
    margin: 0 0 4px;
    padding: 4px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--muted);
    font-size: 0.68rem;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.chat-message {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 82%;
    padding: 9px 14px 7px;
    border-radius: 14px;
    font-size: 0.88rem;
    line-height: 1.4;
    animation: chat-message-in 0.18s ease-out;
}

.chat-message-text {
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.chat-message-time {
    align-self: flex-end;
    font-size: 0.64rem;
    opacity: 0.6;
}

.chat-message.me {
    align-self: flex-end;
    background: #4a4ee0;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-message.partner {
    align-self: flex-start;
    background: var(--panel-soft);
    border-bottom-left-radius: 4px;
}

.chat-message.partner .chat-message-time {
    align-self: flex-start;
}

.chat-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    align-self: flex-start;
    padding: 9px 12px;
    border-radius: 999px;
    background: var(--panel-soft);
}

.chat-typing-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--muted);
    animation: chat-typing-bounce 1.2s infinite ease-in-out;
}

.chat-typing-dot:nth-child(3) {
    animation-delay: 0.15s;
}

.chat-typing-dot:nth-child(4) {
    animation-delay: 0.3s;
}

.chat-form {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 14px 14px;
    padding: 5px 5px 5px 16px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg);
}

.chat-form:focus-within {
    border-color: rgba(124, 140, 255, 0.6);
}

.chat-form input {
    flex: 1;
    min-width: 0;
    height: 36px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 0.85rem;
    outline: none;
}

.chat-form input::placeholder {
    color: var(--muted);
}

.chat-send-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    background: #4a4ee0;
    border-radius: 50%;
}

.chat-send-btn svg {
    width: 16px;
    height: 16px;
}

/* The open chat toggle is highlighted with a ring, like an active control */
#chatBtn[aria-expanded='true'] {
    background: #4a4ee0;
    border-color: transparent;
    color: #fff;
    box-shadow: 0 0 0 4px rgba(74, 78, 224, 0.35);
}

@keyframes chat-message-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
}

@keyframes chat-typing-bounce {
    0%,
    60%,
    100% {
        opacity: 0.4;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-3px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-message,
    .chat-typing-dot {
        animation: none;
    }
}

.app-footer {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 0 0 12px;
    color: var(--muted);
    font-size: 0.75rem;
}

.app-footer a {
    color: var(--muted);
    text-decoration: none;
}

.app-footer a:hover {
    color: var(--text);
}

.app-footer .footer-version {
    opacity: 0.7;
}

.app-footer .footer-version:empty {
    display: none;
}

.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;
}

.tippy-box[data-theme~='mirotalk'] {
    background: rgba(8, 12, 20, 0.98);
    color: #edf2ff;
    border: 1px solid rgba(111, 131, 255, 0.38);
    border-radius: 8px;
    font-size: 0.75rem;
    letter-spacing: 0.2px;
    line-height: 1.2;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
    z-index: 9999;
}

.tippy-box[data-theme~='mirotalk'] .tippy-content {
    padding: 7px 9px;
}

.tippy-box[data-theme~='mirotalk'][data-placement^='top'] > .tippy-arrow::before {
    border-top-color: rgba(8, 12, 20, 0.98);
}

.tippy-box[data-theme~='mirotalk'][data-placement^='left'] > .tippy-arrow::before {
    border-left-color: rgba(8, 12, 20, 0.98);
}

.tippy-box[data-theme~='mirotalk'][data-placement^='right'] > .tippy-arrow::before {
    border-right-color: rgba(8, 12, 20, 0.98);
}

.tippy-box[data-theme~='mirotalk'][data-placement^='bottom'] > .tippy-arrow::before {
    border-bottom-color: rgba(8, 12, 20, 0.98);
}

@media (max-width: 720px) {
    /* Full-screen sheet: stays inside the viewport and keeps the input usable with the on-screen keyboard */
    .chat-panel {
        position: fixed;
        inset: 0;
        z-index: 15;
        height: 100dvh;
        border: 0;
        border-radius: 0;
        padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
            env(safe-area-inset-left);
    }

    .video-layout:has(.chat-panel:not([hidden])) {
        grid-template-columns: 1fr;
    }

    /* 16px+ stops iOS Safari from zooming the page when the input is focused */
    .chat-form input {
        height: 40px;
        font-size: 16px;
    }

    .chat-message {
        max-width: 85%;
        font-size: 0.95rem;
    }

    .app-shell {
        padding: 0 10px env(safe-area-inset-bottom);
    }

    .top-bar {
        padding: 10px 2px;
    }

    .top-bar h1 {
        font-size: 1.1rem;
    }

    .app-title-icon {
        width: 26px;
        height: 26px;
    }

    .video-layout {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
        gap: 10px;
    }

    .video-layout.self-preview-hidden {
        grid-template-rows: 1fr;
    }

    .video-header {
        top: 10px;
        left: 10px;
        font-size: 0.78rem;
        padding: 5px 12px;
    }

    .control-bar {
        grid-template-columns: minmax(0, 1fr);
        gap: 10px;
        padding: 8px 2px 12px;
    }

    .status-area {
        justify-content: center;
        text-align: center;
        font-size: 0.8rem;
    }

    .status-area p {
        max-width: none;
    }

    .status-area svg {
        display: none;
    }

    /* Icon buttons share one centered row and shrink to fit narrow screens */
    .call-controls {
        min-width: 0;
        justify-content: center;
        gap: 8px;
    }

    .call-controls .icon-btn {
        flex: 1 1 0;
        width: auto;
        height: auto;
        min-width: 34px;
        max-width: 48px;
        aspect-ratio: 1;
    }

    .control-divider {
        display: none;
    }

    /* Start/Next take the full row so the primary action is an easy tap target */
    .match-controls {
        justify-content: stretch;
        gap: 8px;
    }

    .match-controls .pill-btn {
        flex: 1 1 0;
        justify-content: center;
        height: 44px;
        padding: 0 12px;
        gap: 6px;
    }

    .match-controls .pill-btn[hidden] {
        display: none;
    }

    /* Keep legal and safety links reachable on phones, in a compact single row */
    .app-footer {
        flex-wrap: wrap;
        gap: 6px;
        padding: 0 0 max(8px, env(safe-area-inset-bottom));
        font-size: 0.7rem;
    }
}

/* Tablet: status on its own row, call controls and match controls share the next one */
@media (min-width: 721px) and (max-width: 1024px) {
    .control-bar {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 12px 16px;
        padding: 14px 4px 18px;
    }

    .status-area {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }

    .status-area p {
        max-width: none;
    }

    .call-controls {
        justify-content: flex-start;
        gap: 12px;
    }

    .call-controls .icon-btn {
        width: 44px;
        height: 44px;
    }
}

@media (max-width: 380px) {
    .call-controls {
        gap: 5px;
    }

    .call-controls .icon-btn {
        min-width: 30px;
    }

    .call-controls .icon-btn svg {
        width: 16px;
        height: 16px;
    }
}

@media (max-height: 560px) and (min-width: 721px) {
    .top-bar,
    .control-bar {
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .icon-btn {
        width: 46px;
        height: 46px;
    }

    .app-footer {
        display: none;
    }
}

@keyframes offline-pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 139, 160, 0.55);
    }
    70% {
        transform: scale(1.12);
        box-shadow: 0 0 0 12px rgba(255, 139, 160, 0);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 139, 160, 0);
    }
}
