/* ═══════════════════════════════════════════════════════════════════════════
   The meeting room.
   ═══════════════════════════════════════════════════════════════════════════ */

/* Dynamic viewport height. On phones 100vh includes the browser chrome that collapses
   as you scroll, so the control bar sits below the fold and the on-screen keyboard
   pushes it further out of reach. dvh tracks what is actually visible. */
#app {
    display: flex; flex-direction: column;
    height: 100vh; height: 100dvh;
    /* Nothing in the meeting view scrolls; a stray overflow here would surface as a
       scrollbar over the video and let the whole UI drag out of place on touch. */
    overflow: hidden;
}

.panel-close { display: none; }

/* ── Title bar ──────────────────────────────────────────────────────────────
   Doubles as the desktop app's draggable chrome: the shell runs frameless, so
   -webkit-app-region here is what lets someone move the window. Interactive
   children opt back out, or they become dead zones that drag instead of click. */
.titlebar {
    display: flex; align-items: center; gap: 12px;
    height: 46px; padding: 0 12px; flex: none;
    background: rgba(8, 11, 18, 0.72);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(20px);
    -webkit-app-region: drag;
}
.titlebar button, .titlebar .no-drag { -webkit-app-region: no-drag; }

.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -0.02em; }
.brand-mark {
    width: 24px; height: 24px; border-radius: 7px; flex: none;
    background: linear-gradient(140deg, var(--accent), #8b6bff);
    box-shadow: 0 2px 10px rgba(77, 141, 255, 0.4);
    display: grid; place-items: center;
    font-size: 0.72rem; font-weight: 800; color: #04070f;
}

.meeting-code {
    font-family: var(--mono); font-size: 0.86rem; font-weight: 600; letter-spacing: 0.09em;
}

/* Windows caption buttons, drawn by us because the shell has no native frame. */
.caption-btns { display: flex; gap: 0; margin-left: 6px; margin-right: -12px; }
.caption-btn {
    width: 44px; height: 46px; border: 0; background: transparent;
    color: var(--text-dim); cursor: pointer; display: grid; place-items: center;
    transition: background 0.12s var(--ease);
}
.caption-btn:hover { background: rgba(255,255,255,0.07); color: var(--text); }
.caption-btn.close:hover { background: var(--danger); color: #fff; }

/* ── Stage ──────────────────────────────────────────────────────────────── */
.stage { flex: 1; display: flex; min-height: 0; }

.grid-wrap { flex: 1; min-width: 0; padding: 14px; display: flex; }

/* The video grid.
   Column count is set from JS (--cols) rather than by media query, because what
   matters is the number of participants, not the width of the window. */
.grid {
    flex: 1; display: grid; gap: 12px; align-content: center;
    grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
}

/* Presenting splits the stage: the shared screen takes the room, everyone else
   becomes a filmstrip. Slides are the reason the meeting is happening. */
.stage.presenting .grid-wrap { flex-direction: column; gap: 12px; }
.stage.presenting .grid {
    flex: none; grid-auto-flow: column; grid-template-columns: none;
    height: 128px; align-content: stretch; overflow-x: auto; overflow-y: hidden;
}
.stage.presenting .grid .tile { width: 200px; }

.presentation {
    flex: 1; min-height: 0; position: relative;
    background: #000; border: 1px solid var(--border-strong);
    border-radius: var(--radius); overflow: hidden;
}
.presentation video { width: 100%; height: 100%; object-fit: contain; }
.presentation-label {
    position: absolute; top: 12px; left: 12px;
    background: rgba(4,6,10,0.78); backdrop-filter: blur(10px);
}

/* ── Tile ───────────────────────────────────────────────────────────────── */
.tile {
    position: relative; min-width: 0; aspect-ratio: 16 / 9;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
    display: grid; place-items: center;
    transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

/* Active speaker. A ring rather than a size change, because reflowing the grid
   every time somebody says "mhm" is nauseating to watch. */
.tile.speaking { border-color: var(--ok); box-shadow: 0 0 0 2px var(--ok-soft), 0 0 26px rgba(53,214,138,0.14); }

.tile video {
    position: absolute; inset: 0; width: 100%; height: 100%;
    object-fit: cover; background: #000;
}
/* Your own camera is mirrored: everyone expects their reflection, not a rear view.
   Outgoing video is never flipped — only this local preview. */
.tile.self video { transform: scaleX(-1); }
.tile.cam-off video { display: none; }

.tile-avatar {
    width: 78px; height: 78px; border-radius: 50%;
    display: grid; place-items: center;
    font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; color: #04070f;
    background: linear-gradient(140deg, var(--accent), #8b6bff);
}
.tile.speaking .tile-avatar { box-shadow: 0 0 0 4px var(--ok-soft); }

.tile-bar {
    position: absolute; left: 0; right: 0; bottom: 0;
    display: flex; align-items: center; gap: 7px;
    padding: 18px 10px 8px;
    background: linear-gradient(transparent, rgba(4, 6, 10, 0.85));
    font-size: 0.8rem; font-weight: 600;
}
.tile-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-icons { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.tile-icon { width: 15px; height: 15px; opacity: 0.9; flex: none; }
.tile-icon.danger { color: var(--danger); }

/* Connection quality. Deliberately quiet until it is bad — a warning that is
   always on is a warning nobody reads. */
.tile-net { display: none; }
.tile-net.poor { display: inline-flex; color: var(--warn); }
.tile-net.bad  { display: inline-flex; color: var(--danger); }

.tile-badge {
    position: absolute; top: 10px; left: 10px;
    background: rgba(4,6,10,0.75); backdrop-filter: blur(8px);
}

/* Connecting shimmer, so a tile that has not negotiated yet reads as "working on
   it" rather than "broken". */
.tile.connecting::after {
    content: ''; position: absolute; inset: 0;
    background: linear-gradient(100deg, transparent 30%, rgba(77,141,255,0.09) 50%, transparent 70%);
    background-size: 220% 100%;
    animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -60% 0; } }

/* ── Side panel ─────────────────────────────────────────────────────────── */
.panel {
    width: 336px; flex: none; display: flex; flex-direction: column;
    background: rgba(11, 14, 22, 0.86);
    border-left: 1px solid var(--border);
    backdrop-filter: blur(24px);
}
.panel.hidden { display: none !important; }

.panel-tabs { display: flex; gap: 2px; padding: 10px 10px 0; flex: none; }
.panel-tab {
    flex: 1; height: 36px; border: 0; border-radius: var(--radius-sm);
    background: transparent; color: var(--text-dim);
    font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer;
    transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.panel-tab:hover  { background: rgba(255,255,255,0.04); color: var(--text); }
.panel-tab.active { background: var(--accent-soft); color: var(--accent); }

.panel-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }

/* ── Roster ─────────────────────────────────────────────────────────────── */
.person { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius-sm); }
.person:hover { background: rgba(255,255,255,0.035); }
.person-avatar {
    width: 34px; height: 34px; border-radius: 50%; flex: none;
    display: grid; place-items: center;
    font-size: 0.82rem; font-weight: 700; color: #04070f;
    background: linear-gradient(140deg, var(--accent), #8b6bff);
}
.person-name { font-size: 0.9rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-sub  { font-size: 0.72rem; color: var(--text-faint); }
.person-icons { margin-left: auto; display: flex; gap: 7px; color: var(--text-faint); }

/* ── Host controls ──────────────────────────────────────────────────────── */
.host-tools { display: flex; gap: 6px; padding-bottom: 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }

.host-toggle {
    flex: 1; height: 32px; padding: 0 10px;
    font: inherit; font-size: 0.74rem; font-weight: 600;
    color: var(--text-dim);
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 999px; cursor: pointer;
    transition: background 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.host-toggle:hover { border-color: var(--border-strong); }
.host-toggle.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }

/* The queue outside the door. Amber-tinted, because it is the one thing in the panel
   that is waiting on the host to act. */
.pending-section {
    padding: 8px; margin-bottom: 6px;
    background: var(--warn-soft); border-radius: var(--radius-sm);
}
.pending-section .section-label { margin: 0 0 6px 2px; color: var(--warn); }
.person.pending:hover { background: transparent; }
.pending-btn { height: 30px; padding: 0 12px; font-size: 0.76rem; }

/* Per-person host actions: revealed on hover where hover exists, always present on
   touch — an invisible control on a phone is no control at all. */
.person-actions { margin-left: auto; display: flex; gap: 5px; flex: none; }
.person .person-actions { opacity: 0; transition: opacity 0.12s var(--ease); }
.person:hover .person-actions, .person.pending .person-actions { opacity: 1; }
@media (pointer: coarse) { .person .person-actions { opacity: 1; } }

.person-btn {
    width: 30px; height: 30px;
    display: grid; place-items: center;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-dim); cursor: pointer;
    transition: background 0.12s var(--ease), color 0.12s var(--ease);
}
.person-btn:hover { background: var(--surface-3); color: var(--text); }
.person-btn.danger:hover { background: var(--danger); border-color: transparent; color: #fff; }
.person-btn svg { width: 14px; height: 14px; }

/* ── Lobby ──────────────────────────────────────────────────────────────── */
.lobby-spinner {
    width: 36px; height: 36px; border-radius: 50%;
    border: 3px solid var(--border-strong); border-top-color: var(--accent);
    animation: spin 0.9s linear infinite;
}

/* ── Chat ───────────────────────────────────────────────────────────────── */
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 12px; }
.chat-msg { display: flex; flex-direction: column; gap: 3px; user-select: text; }
.chat-meta { display: flex; align-items: baseline; gap: 7px; font-size: 0.72rem; color: var(--text-faint); }
.chat-who  { font-weight: 700; color: var(--text-dim); }
.chat-body {
    font-size: 0.88rem; line-height: 1.45;
    padding: 8px 11px; border-radius: 4px 12px 12px 12px;
    background: var(--surface-2); word-break: break-word; white-space: pre-wrap;
}
.chat-msg.self .chat-body { background: var(--accent-soft); border-radius: 12px 4px 12px 12px; }
.chat-msg.locked .chat-body { color: var(--text-faint); font-style: italic; }

.chat-compose { flex: none; padding: 10px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.chat-compose textarea {
    flex: 1; resize: none; height: 42px; max-height: 120px; padding: 11px 13px;
    font: inherit; font-size: 0.9rem; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
    user-select: text;
}
.chat-compose textarea:focus { border-color: var(--accent-line); }

.panel-note {
    display: flex; gap: 8px; align-items: flex-start;
    padding: 10px; margin: 0 10px 10px;
    font-size: 0.74rem; line-height: 1.5; color: var(--text-faint);
    background: var(--ok-soft); border-radius: var(--radius-sm);
}

/* ── Control bar ────────────────────────────────────────────────────────── */
.controls {
    flex: none; height: var(--ctrl-height);
    display: flex; align-items: center; justify-content: center; gap: 10px;
    padding: 0 16px;
    background: rgba(8, 11, 18, 0.78);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(24px);
}

.ctrl {
    position: relative;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    width: 68px; height: 54px;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface-2); color: var(--text);
    font: inherit; font-size: 0.62rem; font-weight: 600; cursor: pointer;
    transition: background 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.ctrl:hover { background: var(--surface-3); }
.ctrl svg { width: 19px; height: 19px; }

/* "Off" is the state that needs to shout: someone who cannot be heard should be
   able to tell at a glance, from across the room, without reading a label. */
.ctrl.off { background: var(--danger); border-color: transparent; color: #fff; }
.ctrl.off:hover { background: var(--danger-hot); }
.ctrl.active { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }

.ctrl-badge {
    position: absolute; top: -5px; right: -5px;
    min-width: 18px; height: 18px; padding: 0 5px;
    display: grid; place-items: center;
    font-size: 0.65rem; font-weight: 700; color: #04070f;
    background: var(--accent); border-radius: 999px;
}

.ctrl-leave { width: auto; padding: 0 22px; background: var(--danger); border-color: transparent; color: #fff; }
.ctrl-leave:hover { background: var(--danger-hot); }

/* Mic level, drawn into the mic button itself — the meter is where the mic is. */
.ctrl-level {
    position: absolute; left: 6px; right: 6px; bottom: 5px; height: 2px;
    background: rgba(255,255,255,0.16); border-radius: 2px; overflow: hidden;
}
.ctrl-level i { display: block; height: 100%; width: 0%; background: var(--ok); transition: width 0.08s linear; }

/* ── Pre-join ("green room") ────────────────────────────────────────────── */
.prejoin {
    position: fixed; inset: 0; z-index: 40;
    display: grid; place-items: center; padding: 24px;
    background: var(--bg-deep);
    overflow-y: auto;
}
.prejoin-card {
    display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
    gap: 28px; padding: 28px;
    width: min(940px, 100%);
}
@media (max-width: 780px) { .prejoin-card { grid-template-columns: 1fr; } }

.preview {
    position: relative; aspect-ratio: 16 / 9;
    background: #000; border-radius: var(--radius); overflow: hidden;
    border: 1px solid var(--border);
}
.preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview-off {
    position: absolute; inset: 0; display: grid; place-items: center; gap: 10px;
    color: var(--text-faint); font-size: 0.86rem; text-align: center;
}
.preview-controls {
    position: absolute; left: 0; right: 0; bottom: 0;
    display: flex; justify-content: center; gap: 10px; padding: 14px;
    background: linear-gradient(transparent, rgba(4,6,10,0.8));
}

.prejoin-side { display: flex; flex-direction: column; gap: 14px; }
.prejoin-title { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }

.error-note {
    display: flex; gap: 9px; padding: 11px 13px;
    font-size: 0.82rem; line-height: 1.5;
    background: var(--warn-soft); color: var(--warn);
    border-radius: var(--radius-sm);
}

/* ── Background picker ──────────────────────────────────────────────────── */
.bg-menu {
    position: fixed; bottom: calc(var(--ctrl-height) + 12px); left: 50%; transform: translateX(-50%);
    z-index: 58; width: 268px; padding: 12px;
    background: var(--surface-2); border: 1px solid var(--border-strong);
    border-radius: var(--radius); box-shadow: var(--shadow-lg);
    backdrop-filter: blur(24px);
    animation: toast-in 0.16s var(--ease);
}
/* On the pre-join screen the control bar does not exist, so anchor to the viewport. */
.prejoin ~ .bg-menu, body:has(.prejoin:not(.hidden)) .bg-menu { bottom: 50%; transform: translate(-50%, 50%); }

.bg-menu-title {
    font-size: 0.68rem; font-weight: 700; letter-spacing: 0.09em;
    text-transform: uppercase; color: var(--text-faint); margin-bottom: 9px;
}

.bg-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }

.bg-item {
    display: flex; align-items: center; gap: 8px; padding: 7px 8px;
    background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
    color: var(--text); font: inherit; font-size: 0.8rem; font-weight: 600;
    cursor: pointer; text-align: left;
    transition: background 0.13s var(--ease), border-color 0.13s var(--ease);
}
.bg-item:hover { background: rgba(255,255,255,0.05); }
.bg-item.selected { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent); }

.bg-swatch {
    width: 26px; height: 20px; border-radius: 4px; flex: none;
    border: 1px solid var(--border);
    background: var(--surface-3);
}
/* The swatches mirror what each option produces, so the list reads at a glance. */
.bg-swatch.bg-none  { background: linear-gradient(135deg, #39414f, #262c38); }
.bg-swatch.bg-blur  { background: linear-gradient(135deg, #4b5468, #2b3242); filter: blur(1.1px); }
.bg-swatch.bg-blur2 { background: linear-gradient(135deg, #5a637a, #2b3242); filter: blur(2.2px); }
.bg-swatch.bg-slate { background: linear-gradient(135deg, #1c2434 0%, #141a27 55%, #0d111a 100%); }
.bg-swatch.bg-warm  { background: linear-gradient(135deg, #efe7dc 0%, #e2d8ca 55%, #d3c7b6 100%); }

.bg-upload {
    display: flex; align-items: center; gap: 8px; margin-top: 8px; padding: 9px 8px;
    border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
    font-size: 0.8rem; font-weight: 600; color: var(--text-dim); cursor: pointer;
    transition: border-color 0.13s var(--ease), color 0.13s var(--ease);
}
.bg-upload:hover { border-color: var(--accent-line); color: var(--text); }

.bg-note { margin-top: 9px; font-size: 0.7rem; line-height: 1.45; color: var(--text-faint); }

/* The segmenter is a one-time ~9.6 MB fetch; the button says so rather than
   appearing to have ignored the click. */
.ctrl.busy { opacity: 0.65; pointer-events: none; }
.ctrl.busy::after {
    content: ''; position: absolute; inset: -1px; border-radius: inherit;
    border: 1.5px solid transparent; border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toasts ─────────────────────────────────────────────────────────────── */
.toasts {
    position: fixed; bottom: calc(var(--ctrl-height) + 16px); left: 50%; transform: translateX(-50%);
    z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px;
    pointer-events: none;
}
.toast {
    padding: 10px 16px; font-size: 0.86rem; font-weight: 500;
    background: var(--surface-3); border: 1px solid var(--border-strong);
    border-radius: 999px; box-shadow: var(--shadow-lg);
    animation: toast-in 0.24s var(--ease);
}
.toast.err { background: var(--danger); border-color: transparent; color: #fff; }
.toast.ok  { background: var(--ok); border-color: transparent; color: #04070f; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ── Connection banner ──────────────────────────────────────────────────── */
.banner {
    position: fixed; top: 56px; left: 50%; transform: translateX(-50%); z-index: 55;
    display: flex; align-items: center; gap: 9px;
    padding: 9px 16px; font-size: 0.84rem; font-weight: 600;
    background: var(--warn); color: #100c02;
    border-radius: 999px; box-shadow: var(--shadow-lg);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Phones and foldables

   The desktop layout assumes width it does not have on a phone: a 336px side panel
   beside the video, seven 68px control buttons in a row, and a title bar carrying four
   labelled elements. On a 1080px-wide device at 420dpi — about 411 CSS px — that
   overflows in every direction at once.

   Everything below is additive, so the desktop layout is untouched above 780px.
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 780px) {

    /* Text that only earns its space on a wide screen: "Copy invite",
       "End-to-end encrypted". The icons carry the meaning; the tooltips carry
       the detail. */
    .wide-only { display: none; }

    /*
      Immersive call chrome. On a phone the video IS the app, so the bars float over
      it as gradients instead of reserving opaque bands — the same layout every phone
      call app converges on. Fixed positioning takes them out of flow, which is what
      lets the stage claim the whole display.
    */
    .titlebar {
        position: fixed; top: 0; left: 0; right: 0; z-index: 30;
        height: auto;
        min-height: 48px;
        padding: 0 8px;
        padding-top: env(safe-area-inset-top);   /* clear the punch-hole camera */
        gap: 8px;
        background: linear-gradient(rgba(4, 6, 10, 0.72), rgba(4, 6, 10, 0));
        border-bottom: none;
        backdrop-filter: none;                   /* a blur over live video costs real GPU */
    }
    .brand > span:last-child { display: none; }  /* keep the mark, drop the wordmark */
    .meeting-code { font-size: 0.78rem; letter-spacing: 0.06em; }
    .badge { height: 24px; padding: 0 8px; }
    #btn-copy { padding: 0 8px !important; }

    /* ── Stage: edge to edge ── */
    /* In the multi-person grid the tiles sit between the bars; solo and two-person
       calls go truly full-bleed underneath them. */
    .grid-wrap {
        padding: calc(50px + env(safe-area-inset-top)) 0 calc(66px + env(safe-area-inset-bottom));
    }
    .grid-wrap:has(.grid.pip), .grid-wrap:has(.grid.solo) { padding: 0; }
    .grid { gap: 2px; }

    /* A border and rounded corners are card styling; a call on a phone is not a card. */
    .tile { aspect-ratio: auto; min-height: 0; border: none; border-radius: 0; background: #000; }
    .grid { align-content: stretch; grid-auto-rows: 1fr; }
    .tile-bar { padding: 14px 10px 8px; font-size: 0.8rem; }
    .tile-avatar { width: 60px; height: 60px; font-size: 1.3rem; }

    /* One person (you, waiting): your preview fills the screen. */
    .grid.solo { display: block; position: relative; }
    .grid.solo > .tile { position: absolute; inset: 0; }
    .grid.solo .tile-bar,
    .grid.pip > .tile:not(.self) .tile-bar {
        /* Names must clear the floating control bar, not hide under it. */
        padding-bottom: calc(74px + env(safe-area-inset-bottom));
        background: none;
        text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
    }

    /*
      Two people: the other person gets the screen and you become a thumbnail. This is
      the arrangement every phone call app converges on, because splitting a phone
      screen in half gives two views too small to read a face in.
    */
    .grid.pip { display: block; position: relative; }
    .grid.pip > .tile { position: absolute; inset: 0; width: 100%; height: 100%; }
    .grid.pip > .tile.self {
        inset: auto 10px 10px auto;
        width: 30vw; max-width: 132px; height: auto;
        aspect-ratio: 3 / 4;
        z-index: 3;
        border-radius: 10px;
        border-color: var(--border-strong);
        box-shadow: 0 6px 20px rgba(0,0,0,0.55);
    }
    .grid.pip > .tile.self .tile-bar { display: none; }
    .grid.pip > .tile.self .tile-avatar { width: 40px; height: 40px; font-size: 0.95rem; }

    .stage.presenting .grid { height: 92px; }
    .stage.presenting .grid .tile { width: 132px; }

    /* ── Panel becomes a full-screen sheet ── */
    .panel {
        position: fixed;
        inset: 0;
        width: 100%;
        z-index: 50;
        border-left: none;
        background: rgba(8, 11, 18, 0.98);
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .panel-close {
        display: grid; place-items: center;
        width: 36px; height: 36px; flex: none;
        border: 0; border-radius: var(--radius-sm);
        background: transparent; color: var(--text-dim); cursor: pointer;
    }
    .panel-close:hover { background: rgba(255,255,255,0.06); color: var(--text); }
    .chat-log { padding: 12px 10px; }
    .chat-body { font-size: 0.92rem; }        /* comfortable to read at arm's length */

    /* ── Controls: floating over the video, like the title bar ── */
    .controls {
        position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
        height: auto;
        min-height: 60px;
        padding: 6px 4px;
        padding-bottom: calc(6px + env(safe-area-inset-bottom));  /* clear the gesture bar */
        gap: 3px;
        background: linear-gradient(rgba(4, 6, 10, 0), rgba(4, 6, 10, 0.78));
        border-top: none;
        backdrop-filter: none;
    }

    /* The self-view thumbnail and the presenter filmstrip must ride above the
       floating bar, not slide underneath it. */
    .grid.pip > .tile.self {
        bottom: calc(72px + env(safe-area-inset-bottom));
    }
    .stage.presenting {
        padding: calc(48px + env(safe-area-inset-top)) 0 calc(66px + env(safe-area-inset-bottom));
    }
    .stage.presenting .grid-wrap { padding: 0; }
    /*
      Buttons share the width evenly instead of each demanding 68px. Labels go; the
      height stays at 46px, which is above the 44px minimum a fingertip needs.
    */
    .ctrl {
        flex: 1 1 0;
        width: auto;
        min-width: 0;
        max-width: 78px;
        height: 46px;
        gap: 0;
    }
    .ctrl > span:not(.ctrl-level):not(.ctrl-badge) { display: none; }
    .ctrl svg { width: 21px; height: 21px; }
    .ctrl-leave { padding: 0; max-width: 78px; }
    .ctrl-level { bottom: 3px; left: 5px; right: 5px; }

    /* ── Background picker ── */
    .bg-menu {
        left: 8px; right: 8px;
        width: auto;
        transform: none;
        bottom: calc(72px + env(safe-area-inset-bottom));
    }
    body:has(.prejoin:not(.hidden)) .bg-menu { bottom: 50%; transform: translateY(50%); }

    /* ── Pre-join ── */
    .prejoin { padding: 0; align-items: stretch; }
    .prejoin-card {
        border-radius: 0;
        border: none;
        padding: 14px;
        padding-top: calc(14px + env(safe-area-inset-top));
        padding-bottom: calc(14px + env(safe-area-inset-bottom));
        gap: 14px;
        align-content: start;
    }
    .prejoin-title { font-size: 1.1rem; }
    .input, .select { height: 46px; }          /* thumb-sized, not mouse-sized */
    .field { gap: 4px; }

    .toasts { bottom: calc(72px + env(safe-area-inset-bottom)); left: 8px; right: 8px; transform: none; }
    .toast { width: fit-content; margin: 0 auto; max-width: 100%; }
    .banner { top: calc(54px + env(safe-area-inset-top)); }
}

/* Short and wide — a phone held sideways. Vertical space is the scarce resource, so
   the title bar goes and the controls shrink to what a thumb needs. */
@media (max-height: 480px) and (orientation: landscape) {
    .titlebar { display: none; }
    .controls { min-height: 52px; padding: 4px; }
    .ctrl { height: 42px; }
    .grid-wrap { padding: 6px; }
}

/*
  The Fold unfolded: ~1768x2208 physical, near-square and genuinely large. It is a small
  tablet, so it gets the side panel back rather than a sheet covering the video.
*/
@media (min-width: 781px) and (max-width: 1100px) {
    .panel { width: 300px; }
    .ctrl { width: 62px; font-size: 0.58rem; }
}

/* Touch devices: kill the 300ms tap delay and stop double-tap zoom from firing on
   controls people press repeatedly. */
@media (pointer: coarse) {
    .btn, .ctrl, .panel-tab, .bg-item, .caption-btn, .panel-close { touch-action: manipulation; }
    body { overscroll-behavior: none; }        /* no rubber-banding over a live call */
}

/* ── Landing page ───────────────────────────────────────────────────────── */
.landing { display: grid; place-items: center; height: 100vh; padding: 24px; overflow-y: auto; }
.landing-card { width: min(460px, 100%); padding: 32px; display: flex; flex-direction: column; gap: 18px; }
.landing-hero { text-align: center; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.landing-hero h1 { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.035em; }
.landing-hero p { font-size: 0.92rem; color: var(--text-dim); line-height: 1.55; }

.divider { display: flex; align-items: center; gap: 12px; color: var(--text-faint); font-size: 0.72rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.feature-list { display: flex; flex-direction: column; gap: 9px; font-size: 0.83rem; color: var(--text-dim); }
.feature-list li { display: flex; gap: 9px; align-items: flex-start; list-style: none; line-height: 1.45; }
.feature-list svg { width: 15px; height: 15px; flex: none; margin-top: 2px; color: var(--ok); }
