@layer components {
  /* ——— The dock ———
     The call, carried from page to page (layouts/_call): the stage, the
     window or, on a phone, the bar, as the accepted canvas draws them. One
     node for the whole visit history; data-mode says where it sits. */
  .call-dock {
    position: fixed;
    z-index: var(--z-overlay);
    display: flex;
    flex-direction: column;
    gap: var(--block-space-half);
    padding: var(--block-space-half) var(--inline-space-double) var(--block-space);
    background-color: var(--color-canvas);
    /* The stage asks its own width, not the screen's: a narrow one stacks a
       shared screen over the people. */
    container: call-dock / inline-size;

    /* Outside a call its keys are nobody's: a control that takes no pointer
       answers no key (hotkey_controller). */
    &[hidden] {
      pointer-events: none;
    }
  }

  .call-dock__title {
    font-weight: 600;
    text-decoration: none;
  }

  .call-dock__leave {
    margin-inline-start: auto;
  }

  /* One line, said or not: a line that came and went with each speaker
     resized the stage's pictures and moved the window (owner, 2026-11-12). */
  .call-dock__status {
    min-block-size: 1lh;
  }

  /* Its own display, not utilities': the phone bar takes it away below,
     and a utility's layer would win over that. */
  .call-dock__transcribing {
    display: flex;
    align-items: center;
    gap: var(--inline-space-half);
  }

  /* A slot for the newest screen: its tile stands in the stage or the window
     as one of theirs. */
  .call-dock__screens {
    display: contents;
  }

  /* The float's frame closes the last line, so it draws none of its own
     (owner, 2026-11-12). */
  .call-dock__devices .label:last-child .input {
    border-block-end: none;
  }

  /* Two classes: the circle that an icon and a label make of any .btn
     declares these same properties at that weight (buttons.css). */
  .btn.call-control {
    --btn-size: 2.5rem;
    --btn-color: var(--color-ink);
    --btn-background: var(--color-canvas);
    --btn-border-color: var(--color-line);

    &[aria-pressed="false"] {
      --btn-color: var(--color-ink-subtle);
      --btn-background: var(--color-surface);
      --btn-border-color: transparent;
    }
  }

  /* One icon each, its picture swapped by the state, as the lightbox's copy
     does. */
  .call-control[aria-pressed="false"] .icon--mic { --svg: url("/assets/mic-off-80f7469a.svg"); }
  .call-control[aria-pressed="false"] .icon--video { --svg: url("/assets/video-off-10717b92.svg"); }
  .call-dock[data-mode="stage"] .icon--maximize-2 { --svg: url("/assets/minimize-2-0271aaa8.svg"); }

  /* A person: their camera or screen when they show one, their initials
     when not, a ring while they talk. */
  .call-tile {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background-color: var(--color-surface);
    border-radius: var(--border-radius);

    video {
      position: absolute;
      inset: 0;
      inline-size: 100%;
      block-size: 100%;
      object-fit: cover;
    }
  }

  /* A screen shows whole: cropped to fill its tile, it lost its top and its
     foot (owner, 2026-11-12). */
  .call-tile--screen video {
    object-fit: contain;
  }

  /* Your own camera as a mirror, the way every call shows you to yourself. */
  .call-tile--me video {
    transform: scaleX(-1);
  }

  .call-tile--me .call-tile__initials {
    color: var(--color-selected-ink);
  }

  .call-tile--me:not(:has(video)) {
    background-color: var(--color-selected);
  }

  .call-tile--talking {
    outline: 2px solid var(--color-ink);
    outline-offset: 2px;
  }

  .call-tile__initials {
    font-size: var(--text-small);
    font-weight: 600;
    color: var(--color-ink-subtle);
  }

  .call-tile__name {
    position: absolute;
    inset-inline-start: var(--inline-space);
    inset-block-end: var(--block-space-half);
    padding-inline: var(--inline-space-half);
    font-size: var(--text-x-small);
    background-color: var(--color-canvas);
    border-radius: var(--border-radius);
  }

  /* The window: a float out of the page's way, the people as faces. */
  .call-dock[data-mode="window"] {
    inset-inline-end: var(--inline-space-double);
    inset-block-end: calc(var(--footer-bar) + var(--block-space));
    inline-size: 19rem;
    border: var(--border);
    border-radius: var(--border-radius-float);
    box-shadow: var(--shadow);

    .call-dock__view {
      display: contents;
    }

    /* A screen is a picture across the window, and a click on it opens the
       stage (owner, 2026-11-12). */
    .call-dock__screens {
      cursor: pointer;
    }

    .call-tile--screen {
      aspect-ratio: 16 / 10;
    }

    .call-dock__people {
      display: flex;
      flex-wrap: wrap;
      gap: var(--inline-space);
    }

    /* Larger than the canvas draws them: a ping's call is watched from here,
       beside the chat (owner, 2026-11-12). */
    .call-dock__people .call-tile {
      inline-size: 4rem;
      block-size: 4rem;
      border-radius: 50%;
    }

    /* An older screen waits for the stage. */
    .call-dock__people .call-tile--screen,
    .call-dock__people .call-tile__name,
    .call-dock__devices-toggle {
      display: none;
    }
  }

  /* The stage: the main column, with the panel left open beside it, and
     under the chrome, so the panel that floats over a narrow page floats
     over the stage too. */
  .call-dock[data-mode="stage"] {
    inset: var(--header-height) var(--panel-inset, 0px) var(--footer-height) 0;
    z-index: var(--z-panel);
    transition: inset-inline-end var(--speed) var(--ease-out);

    .call-dock__view {
      display: grid;
      flex: 1;
      gap: var(--inline-space);
      min-block-size: 0;

      /* The newest screen takes the stage, the people beside it in a column
         of pictures of the canvas's shape, which share its height when more
         come than it holds. A narrow stage, a phone's above all, stacks the
         screen over them. */
      &:has(.call-tile--screen) {
        grid-template-columns: minmax(0, 1fr) 14rem;

        .call-dock__people {
          grid-template-columns: minmax(0, 1fr);
          grid-auto-rows: minmax(0, 8.75rem);
          align-content: start;
        }

        @container call-dock (width < 40rem) {
          grid-template-columns: minmax(0, 1fr);
          grid-template-rows: auto minmax(0, 1fr);

          .call-tile--screen {
            aspect-ratio: 16 / 10;
          }

          .call-dock__people {
            grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
            grid-auto-rows: minmax(0, 6.75rem);
          }
        }
      }
    }

    .call-dock__people {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
      grid-auto-rows: minmax(8rem, 1fr);
      gap: var(--inline-space);
      min-block-size: 0;
    }

    .call-dock__people .call-tile--screen {
      cursor: pointer;
    }

    .call-dock__controls {
      justify-content: center;
    }

    .call-dock__leave {
      margin-inline-start: var(--inline-space-double);
    }
  }

  /* The call in a window of its own (call_dock_controller#popOut): the stage,
     filling it, without the buttons that move it. */
  @media (display-mode: picture-in-picture) {
    .call-dock[data-mode="stage"] {
      inset: 0;

      .call-dock__head .btn {
        display: none;
      }
    }
  }

  /* On a phone the window is the bar: the call's name, its time, the
     microphone and Leave in one row above the foot (the canvas's PhoneBar).
     The shell keeps that row clear of the page (layout.css), and while the
     keyboard is up the bar steps aside, as the footer does. */
  @media (width < 35rem) {
    html:has(#call[data-mode="window"]:not([hidden])):not(.keyboard-up) {
      --call-bar-clearance: calc(3.5rem + var(--block-space));
    }

    .call-dock[data-mode="window"] {
      flex-direction: row;
      align-items: center;
      inset-inline-start: var(--inline-space-double);
      inline-size: auto;
      block-size: 3.5rem;
      padding-block: var(--block-space-half);

      .call-dock__head {
        flex: 1;
        min-inline-size: 0;
      }

      .call-dock__view,
      .call-dock__status,
      .call-dock__transcribing,
      .call-dock__picture {
        display: none;
      }

      .keyboard-up & {
        display: none;
      }
    }
  }
}
