:root {
    color-scheme: dark;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #090a0c;
    color: #fff;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
button, input, textarea { font: inherit; }
button { color: inherit; }

.conference {
    width: 100vw;
    height: 100dvh;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    background: #090a0c;
    transition: filter 180ms ease, transform 180ms ease;
}

.remote-participants { display: contents; }

.participant {
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: #173f52;
    isolation: isolate;
}

.local-participant { background: #173f52; }
.remote-participants .participant:nth-child(5n + 1) { background: #503044; }
.remote-participants .participant:nth-child(5n + 2) { background: #3f4930; }
.remote-participants .participant:nth-child(5n + 3) { background: #392f57; }
.remote-participants .participant:nth-child(5n + 4) { background: #56442c; }

.conference[data-count="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.conference[data-count="3"] { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); }
.conference[data-count="3"] .local-participant { grid-column: 1 / -1; }
.conference[data-count="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); }

.participant-video,
.video-placeholder {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.participant-video { display: none; object-fit: cover; background: transparent; }
.participant.has-video .participant-video { display: block; }
.participant.has-video .video-placeholder { display: none; }

.participant-avatar { display: none; width: 100%; height: 100%; object-fit: contain; }
.video-placeholder.has-avatar .participant-avatar { display: block; }
.video-placeholder.has-avatar .avatar-fallback,
.video-placeholder.has-avatar .video-placeholder-text { display: none; }

.avatar-fallback {
    width: min(28vw, 220px);
    aspect-ratio: 1;
    border: 3px solid rgba(255,255,255,.42);
    border-radius: 50%;
    opacity: .55;
}

.avatar-fallback::before {
    content: "";
    display: block;
    width: 34%;
    aspect-ratio: 1;
    margin: 18% auto 8%;
    border: 3px solid currentColor;
    border-radius: 50%;
}

.avatar-fallback::after {
    content: "";
    display: block;
    width: 58%;
    height: 26%;
    margin: auto;
    border: 3px solid currentColor;
    border-bottom: 0;
    border-radius: 50% 50% 0 0;
}

.participant-name,
.room-title,
.connection-status,
.participant-description,
.tile-controls,
.join-button { z-index: 3; }

.participant-name {
    position: absolute;
    top: 20px;
    left: 22px;
    max-width: calc(100% - 44px);
    font-size: clamp(16px, 2vw, 24px);
    font-weight: 650;
    overflow-wrap: anywhere;
    filter: drop-shadow(0 2px 5px #000) drop-shadow(0 0 10px #000);
}

.participant-description {
    position: absolute;
    left: 22px;
    top: 50px;
    max-width: min(70%, 520px);
    margin: 0;
    color: rgba(255,255,255,.78);
    font-size: 13px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    filter: drop-shadow(0 1px 4px #000);
}
.participant-description:empty { display: none; }

.room-title {
    position: absolute;
    top: 26px;
    left: 50%;
    margin: 0;
    max-width: 60%;
    transform: translateX(-50%);
    font-size: clamp(26px, 4vw, 54px);
    line-height: 1;
    font-weight: 700;
    text-align: center;
    overflow-wrap: anywhere;
    filter: drop-shadow(0 3px 8px #000);
}

.conference.is-connected .room-title { display: none; }

.tile-controls {
    position: absolute;
    left: 50%;
    bottom: 28px;
    display: flex;
    align-items: center;
    gap: clamp(18px, 3vw, 36px);
    transform: translateX(-50%);
}

.icon-button {
    appearance: none;
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #fff;
    cursor: pointer;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,.9)) drop-shadow(0 0 7px rgba(0,0,0,.65));
}

.icon-button svg { width: 27px; height: 27px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-button:hover { color: #d9f7ff; transform: scale(1.08); }
.icon-button:focus-visible { outline: 2px solid #fff; outline-offset: 5px; }
.icon-button:disabled { cursor: wait; opacity: .45; }
.icon-button .off-mark { display: none; stroke-width: 2.4; }
.icon-button.is-off { color: rgba(255,255,255,.72); }
.icon-button.is-off .off-mark { display: initial; }
.leave-button[hidden] { display: none; }

.join-button {
    appearance: none;
    position: absolute;
    left: 50%;
    top: 50%;
    width: 96px;
    height: 96px;
    padding: 0;
    transform: translate(-50%, -50%);
    border: 0;
    background: transparent;
    color: #fff;
    cursor: pointer;
    filter: drop-shadow(0 4px 5px rgba(0,0,0,.85)) drop-shadow(0 0 12px rgba(0,0,0,.65));
}

.join-button svg { width: 48px; height: 48px; fill: currentColor; }
.join-button:hover { transform: translate(-50%, -50%) scale(1.08); }
.join-button:focus-visible { outline: 2px solid #fff; outline-offset: 6px; }
.conference.is-connected .join-button { display: none; }

.connection-status {
    position: absolute;
    right: 14px;
    bottom: 12px;
    max-width: 45%;
    color: rgba(255,255,255,.65);
    font-size: 12px;
    text-align: right;
    filter: drop-shadow(0 1px 3px #000);
}

.participant.speaking::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    box-shadow: inset 0 0 0 4px rgba(171,255,226,.9), inset 0 0 28px rgba(68,255,199,.2);
}

.profile-dialog {
    width: min(920px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
    padding: 0;
    border: 1px solid rgba(255,255,255,.35);
    border-radius: 0;
    overflow: visible;
    background: rgba(18,20,24,.78);
    color: #fff;
    box-shadow: 0 28px 80px rgba(0,0,0,.55);
    backdrop-filter: blur(22px);
}

.profile-dialog::backdrop { background: rgba(0,0,0,.28); backdrop-filter: blur(9px); }
.profile-shell { position: relative; display: grid; grid-template-columns: 1fr 1fr; min-height: 430px; }
.dialog-close { position: absolute; z-index: 5; top: 13px; right: 13px; }

.profile-visual { position: relative; min-height: 430px; background: #173f52; overflow: hidden; }
.avatar-picker { display: grid; place-items: center; width: 100%; height: 100%; cursor: pointer; }
.avatar-picker img { display: none; width: 100%; height: 100%; object-fit: contain; }
.avatar-picker.has-avatar img { display: block; }
.avatar-picker.has-avatar .avatar-fallback { display: none; }
.profile-media-action { position: absolute; right: 16px; bottom: 16px; z-index: 2; }

.profile-fields { display: flex; flex-direction: column; gap: 24px; min-width: 0; padding: 50px 46px 34px; background: rgba(255,255,255,.045); }
.profile-fields h2 { margin: 0 0 4px; font-size: 27px; font-weight: 600; }
.line-field { display: grid; gap: 7px; color: rgba(255,255,255,.65); font-size: 13px; }
.line-field input, .line-field textarea { width: 100%; min-width: 0; padding: 5px 0 9px; border: 0; border-bottom: 1px solid rgba(255,255,255,.5); border-radius: 0; outline: 0; resize: vertical; background: transparent; color: #fff; }
.line-field input:focus, .line-field textarea:focus { border-bottom-color: #fff; }
.sound-field { display: grid; gap: 10px; color: rgba(255,255,255,.65); font-size: 13px; }
.sound-actions { display: flex; gap: 20px; }
.entry-sound-settings { display: grid; gap: 12px; color: rgba(255,255,255,.75); font-size: 13px; }
.entry-sound-settings label { display: flex; align-items: center; gap: 10px; }
.entry-sound-settings input[type="range"] { min-width: 0; flex: 1; }
#profileStatus { min-height: 32px; margin: 0; color: rgba(255,255,255,.6); font-size: 12px; }
.save-profile { align-self: flex-start; padding: 8px 0; border: 0; border-bottom: 1px solid currentColor; border-radius: 0; background: transparent; color: #fff; cursor: pointer; }

body:has(.profile-dialog[open]) .conference { filter: blur(8px) brightness(.65); transform: scale(1.015); }

@media (max-width: 700px) {
    .conference[data-count="2"] {
        grid-template-columns: 1fr;
        grid-template-rows: repeat(2, minmax(0, 1fr));
    }

    .conference[data-count="3"] {
        grid-template-columns: 1fr;
        grid-template-rows: repeat(3, minmax(0, 1fr));
    }

    .conference[data-count="3"] .local-participant {
        grid-column: auto;
    }

    .conference[data-count="4"] {
        grid-template-columns: 1fr;
        grid-template-rows: repeat(4, minmax(0, 1fr));
    }

    .participant-name { top: 12px; left: 13px; max-width: calc(100% - 26px); font-size: 15px; }
    .participant-description { display: none; }
    .room-title { top: 20px; max-width: 72%; font-size: 28px; }
    .tile-controls { bottom: 22px; gap: 18px; }
    .connection-status { bottom: 5px; right: 7px; max-width: 60%; font-size: 10px; }
    .profile-dialog { width: calc(100vw - 20px); max-height: calc(100dvh - 20px); overflow-y: auto; }
    .profile-shell { grid-template-columns: 1fr; }
    .profile-visual { min-height: auto; aspect-ratio: 16 / 9; }
    .profile-fields { padding: 34px 25px 28px; }
}
