/* Voice and video: the bar above the timeline, the device pickers, the
   video tiles. */

.call-bar {
    display: flex;
    align-items: center;
    gap: var(--space-6);
    flex-wrap: wrap;
    padding: var(--space-4) var(--space-8);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    font-size: var(--text-s);
}

.call-bar.in {
    box-shadow: inset 3px 0 var(--color-success);
}

.call-title {
    font-weight: 600;
}

.call-members {
    display: flex;
    gap: var(--space-5);
    flex-wrap: wrap;
    align-items: center;
}

.call-member {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-1) var(--space-5);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
}

.call-member .ring {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-round);
    background: var(--color-fill);
}

.call-member.speaking {
    border-color: var(--color-success);
}

.call-member.speaking .ring {
    background: var(--color-success);
    box-shadow: 0 0 6px var(--color-success);
}

.call-member.muted {
    opacity: .7;
}

.call-controls {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    margin-left: auto;
}

/* Muted, or a camera or screen that is being sent: said by colour too. */
.call-controls .off {
    color: var(--color-danger);
}

.call-controls .call-camera.on, .call-controls .call-screen.on {
    color: var(--color-success);
}

.call-bar .call-leave {
    margin-left: var(--space-4);
    padding: var(--space-2) var(--space-6);
}

.call-bar .device-pickers {
    flex-basis: 100%;
}

.room-head .call-join span {
    font-size: var(--text-s);
}

.call-bar select {
    width: auto;
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-s);
}

.device-pickers {
    display: inline-flex;
    gap: var(--space-4);
    align-items: center;
    flex-wrap: wrap;
}

.device-pickers .pick {
    flex-direction: row;
    align-items: center;
    gap: var(--space-2);
    color: var(--color-text);
}

.device-pickers select {
    max-width: 180px;
}

.media-devices .device-pickers select {
    max-width: 320px;
}

/* ── the stage: the pictures of a call ─────────────────────────────────── */

/* A good part of the room by default; the handle at its foot changes that. */
.call-stage {
    position: relative;
    flex: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    height: var(--stage-height);
    min-height: 120px;
    max-height: calc(100% - var(--bar-height) * 3);
    padding: var(--space-5) var(--space-8) var(--space-6);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);
}

/* The pictures that have the stage, in as square a grid as their number allows. */
.stage-main {
    position: relative;
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(var(--columns, 1), minmax(0, 1fr));
    grid-auto-rows: minmax(0, 1fr);
    gap: var(--space-4);
}

/* Our own pictures, small, over the bottom right of the stage. */
.stage-corner {
    position: absolute;
    right: var(--space-4);
    bottom: var(--space-4);
    z-index: 1;
    display: flex;
    gap: var(--space-3);
    height: var(--stage-corner-height);
}

.stage-corner .video-tile {
    height: 100%;
    aspect-ratio: 16 / 9;
    box-shadow: 0 4px 16px var(--color-scrim);
}

/* Under a focused picture, the others in a row. */
.stage-row {
    flex: none;
    display: flex;
    justify-content: center;
    gap: var(--space-4);
    height: var(--stage-row-height);
    overflow-x: auto;
}

.stage-row .video-tile {
    height: 100%;
    aspect-ratio: 16 / 9;
    flex: none;
}

.stage-handle {
    position: absolute;
    left: 0;
    right: 0;
    bottom: -3px;
    z-index: 2;
    height: 7px;
    cursor: ns-resize;
    touch-action: none;
}

.stage-handle::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 3px;
    width: 3rem;
    height: 3px;
    margin-left: -1.5rem;
    border-radius: var(--radius-pill);
    background: var(--color-border);
}

.stage-handle:hover::after {
    background: var(--color-accent);
}

.video-tile {
    position: relative;
    min-width: 0;
    min-height: 0;
    background: var(--color-media-bg);
    border-radius: var(--radius-l);
    overflow: hidden;
    border: 2px solid transparent;
}

.video-tile.speaking {
    border-color: var(--color-success);
}

.video-tile .picture, .video-tile canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* The whole picture, whatever the shape of its tile. */
.video-tile canvas {
    object-fit: contain;
}

/* We see ourselves as in a mirror; the others see us as we are. */
.video-tile.me:not(.screen) canvas {
    transform: scaleX(-1);
}

.video-tile .name {
    position: absolute;
    left: var(--space-4);
    bottom: var(--space-3);
    max-width: calc(100% - var(--control-size) - 3 * var(--space-4));
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--text-xs);
    background: var(--color-scrim);
    padding: var(--space-1) var(--space-4);
    border-radius: var(--radius-s);
}

.video-tile.me .name::after {
    content: " (you)";
    color: var(--color-text-muted);
}

/* What can be done with a picture: three dots in its corner when it is
   pointed at, always there where nothing can point. */
.tile-menu {
    position: absolute;
    right: var(--space-3);
    bottom: var(--space-3);
    background: var(--color-scrim);
    color: var(--color-text);
    visibility: hidden;
}

/* Our own pictures cover the corner of the last one on the stage; its dots
   sit just above them. */
.stage-main.has-corner > .video-tile:nth-last-child(2) .tile-menu {
    bottom: calc(var(--stage-corner-height) + var(--space-5));
}

.video-tile:hover .tile-menu, .tile-menu:focus-visible {
    visibility: visible;
}

@media (hover: none) {
    .tile-menu {
        visibility: visible;
    }
}

/* A name in the bar with a picture behind it opens the same menu. */
.call-member.has-video {
    cursor: pointer;
}

.call-member.has-video:hover {
    background: var(--color-fill);
}

/* ── the menu ──────────────────────────────────────────────────────────── */

.menu-shade {
    position: fixed;
    inset: 0;
    z-index: 8;
}

.menu {
    position: fixed;
    z-index: 9;
    min-width: 11rem;
    display: flex;
    flex-direction: column;
    padding: var(--space-2);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-m);
    box-shadow: 0 8px 24px var(--color-scrim);
    /* Opened at the pointer; kept on the page when that is near an edge. */
    transform: translate(min(0px, calc(100vw - 100% - var(--space-5) - var(--menu-x, 0px))),
                         min(0px, calc(100vh - 100% - var(--space-5) - var(--menu-y, 0px))));
}

.menu button {
    display: flex;
    align-items: center;
    gap: var(--space-5);
    padding: var(--space-4) var(--space-5);
    background: none;
    text-align: left;
    font-size: var(--text-s);
    border-radius: var(--radius-s);
}

.menu button:not(:disabled):hover {
    background: var(--color-fill);
    filter: none;
}

/* ── on a phone ────────────────────────────────────────────────────────── */

@media (max-width: 720px) {
    :root {
        --stage-height: 46vh;
        --stage-corner-height: 3.6rem;
        --stage-row-height: 4rem;
    }

    .call-bar {
        padding-left: var(--space-5);
        padding-right: var(--space-5);
        gap: var(--space-4);
    }

    /* The names in one line that is swiped, not a pile of lines. */
    .call-members {
        flex-wrap: nowrap;
        overflow-x: auto;
        max-width: 100%;
        scrollbar-width: none;
    }

    .call-member {
        flex: none;
    }

    .call-controls {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .call-stage {
        padding: var(--space-4) var(--space-4) var(--space-6);
    }

    /* One above the other: side by side, each would be a sliver. */
    .stage-main {
        grid-template-columns: minmax(0, 1fr);
    }

    .stage-row {
        justify-content: flex-start;
    }

    .stage-handle {
        height: 14px;
    }

    /* The menu comes up from the bottom, wide enough for a thumb. */
    .menu {
        left: 0 !important;
        right: 0;
        top: auto !important;
        bottom: 0;
        transform: none;
        min-width: 0;
        padding: var(--space-5) var(--space-7) var(--space-9);
        border-width: 1px 0 0;
        border-radius: var(--radius-l) var(--radius-l) 0 0;
    }

    .menu button {
        padding: var(--space-7) var(--space-4);
        font-size: var(--text-base);
    }

    .menu-shade {
        background: var(--color-scrim);
    }
}
