: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.4rem;
    font-weight: 600;
}

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

.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: 16px;
    background: var(--panel);
    overflow: hidden;
}

.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(22, 29, 43, 0.72);
    -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: 12px;
    z-index: 2;
    text-align: center;
    padding: 18px;
    color: var(--muted);
    font-size: 0.86rem;
    background: linear-gradient(180deg, rgba(4, 7, 12, 0.16), rgba(4, 7, 12, 0.72));
}

.video-spinner {
    display: none;
    width: 42px;
    height: 42px;
    border-radius: 999px;
    border: 3px solid rgba(156, 171, 199, 0.28);
    border-top-color: #66e7cd;
    animation: video-spinner-rotate 900ms linear infinite;
}

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

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

.remote-media-status {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 4;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 7px;
    max-width: 60%;
}

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

.remote-media-pill svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2.2;
    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: rgba(5, 9, 16, 0.72);
    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: rgba(5, 9, 16, 0.72);
    color: var(--muted);
}

.video-avatar {
    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;
    font-size: 1.8rem;
}

.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.85rem;
    line-height: 1.45;
}

.status-area p {
    margin: 0;
    max-width: 280px;
}

.status-area svg {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    color: #a5b4fc;
}

.call-controls {
    display: flex;
    justify-content: center;
    gap: 20px;
}

.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.78);
    backdrop-filter: blur(4px);
    padding: 16px;
}

.capacity-modal-card {
    width: min(460px, 100%);
    border-radius: 14px;
    border: 1px solid var(--border);
    background: #0b101b;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
    padding: 18px;
    text-align: center;
}

.capacity-modal-card h2 {
    margin: 0 0 8px;
    font-size: 1.1rem;
}

.capacity-modal-card p {
    margin: 0 0 14px;
    color: var(--muted);
    line-height: 1.4;
}

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

.background-image-picker-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.background-image-picker-row .btn {
    padding: 7px 10px;
    border-radius: 8px;
    font-size: 0.76rem;
    white-space: nowrap;
}

.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: var(--panel-soft);
    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: 56px;
    height: 56px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

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

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

.pill-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 44px;
    padding: 0 20px;
    font-weight: 600;
}

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

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

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

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

.icon-btn.off {
    background: rgba(239, 68, 68, 0.16);
    border-color: rgba(239, 68, 68, 0.45);
    color: #fca5a5;
}

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

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

    .remote-media-status {
        top: 10px;
        right: 10px;
    }

    .control-bar {
        grid-template-columns: 1fr auto;
        gap: 10px;
        padding: 12px 2px;
    }

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

    .status-area svg {
        display: none;
    }

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

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

    .pill-btn {
        height: 48px;
        padding: 0 16px;
    }

    .background-image-picker-row {
        flex-direction: column;
        align-items: stretch;
    }

    .app-footer {
        display: none;
    }
}

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

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

@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);
    }
}
