:root {
  --canvas: #0f1012;
  --panel: #191a1e;
  --panel-hover: #282a2f;
  --white: #f7f8fa;
  --muted: #b8bbc2;
  --zoom-blue: #2d8cff;
  --speak-green: #23d160;
  --danger: #ef4b55;
  --control-height: 78px;
  --gallery-height: calc(100dvh - var(--control-height) - 63px);
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }

body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--white);
  background: var(--canvas);
}

button, input { font: inherit; }
button { color: inherit; }

.meeting {
  display: grid;
  grid-template-rows: 47px minmax(0, 1fr) var(--control-height);
  height: 100dvh;
  min-height: 520px;
  background: var(--canvas);
}

.meeting-bar {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid #222328;
  background: #111214;
  font-size: 12px;
}

.security-pill, .view-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: fit-content;
  height: 30px;
  padding: 0 9px;
  border: 0;
  border-radius: 7px;
  background: #222328;
  color: #d8dae0;
}

.view-pill { justify-self: end; }
.security-pill svg, .view-pill svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.security-pill svg { color: var(--speak-green); }

.meeting-meta { display: flex; gap: 8px; align-items: center; color: #e4e6eb; }
.meeting-id { color: #767a83; }

.gallery {
  display: grid;
  gap: 5px;
  max-width: calc(100% - 16px);
  max-height: var(--gallery-height);
  margin: auto;
}
.gallery[data-count="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: minmax(0, 1fr); width: min(calc(100% - 16px), calc(var(--gallery-height) * 2)); aspect-ratio: 2 / 1; }
.gallery[data-count="3"] { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: minmax(0, 1fr); width: min(calc(100% - 16px), calc(var(--gallery-height) * 3)); aspect-ratio: 3 / 1; }
.gallery[data-count="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); width: min(calc(100% - 16px), var(--gallery-height)); aspect-ratio: 1 / 1; }
.gallery[data-count="5"], .gallery[data-count="6"] { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); width: min(calc(100% - 16px), calc(var(--gallery-height) * 1.5)); aspect-ratio: 3 / 2; }

.participant {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #22242a;
  box-shadow: 0 0 0 1px rgba(255,255,255,.025);
  transition: border-color .14s ease, box-shadow .14s ease;
  touch-action: none;
}

.participant.dragging { opacity: .22; cursor: grabbing !important; }
.participant.drag-target { box-shadow: inset 0 0 0 3px var(--zoom-blue); }
.participant.waiting-participant { display: none; }

.participant-drag-ghost {
  position: fixed !important;
  z-index: 50;
  margin: 0 !important;
  opacity: .9;
  pointer-events: none;
  cursor: grabbing;
  box-shadow: 0 18px 45px rgba(0,0,0,.48), 0 0 0 1px rgba(255,255,255,.16);
  transform: scale(1.015);
}

.participant-drag-ghost canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.participant.speaking, .participant.speaker-demo {
  border-color: var(--speak-green);
  box-shadow: 0 0 12px rgba(35, 209, 96, .08);
}

.participant.fake[role="button"] { cursor: grab; }
.participant.fake[role="button"]:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--zoom-blue);
}

.participant video, .fake-person {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.participant video { transform: scaleX(-1); background: #202228; }

.fake-video {
  z-index: 1;
  display: none;
  transform: none !important;
  filter: saturate(.96) contrast(.94) brightness(.98) blur(.4px);
}

.fake.has-generated-video .fake-video { display: block; }
.fake.has-generated-video .fake-person { visibility: hidden; }

.video-transition-frame {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 1;
  pointer-events: none;
  filter: saturate(.96) contrast(.94) brightness(.98) blur(.4px);
  transition: opacity .18s ease;
}
.video-transition-frame.fade-out { opacity: 0; }

.fake-person {
  background-image: url("assets/participants-v2-low.jpg");
  background-size: 300% 200%;
  background-position: var(--x) var(--y);
  background-repeat: no-repeat;
  filter: saturate(.96) contrast(.94) brightness(.98) blur(.4px);
}

[data-speaker="marcus"] .fake-person { background-image: url("assets/participants-low.jpg"); }

.camera-fallback, .preview-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 40%, #414653 0, #282b33 50%, #202228 100%);
}

.camera-fallback[hidden], .preview-fallback[hidden] { display: none; }

.camera-fallback span, .preview-fallback span {
  display: grid;
  place-items: center;
  width: 30%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #536072;
  color: white;
  font-size: clamp(34px, 5vw, 68px);
  font-weight: 500;
}

.camera-fallback .emoji-avatar, .preview-fallback .emoji-avatar { background: #424955; font-size: clamp(38px, 5.5vw, 72px); }

.participant-label, .preview-name {
  position: absolute;
  bottom: 7px;
  left: 7px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 27px;
  max-width: calc(100% - 14px);
  padding: 4px 8px;
  overflow: hidden;
  border-radius: 4px;
  background: rgba(13, 14, 16, .77);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
  backdrop-filter: blur(7px);
}

.mini-mic { width: 12px; height: 12px; fill: none; stroke: #ef5058; stroke-width: 2.2; }
.mini-mic .mute-slash { display: none; }
.signal-strength { width: 12px; height: 12px; flex: 0 0 auto; fill: #66dc78; }
.you.muted .mini-mic { stroke: #ef5058; }
.you.muted .mini-mic .mute-slash { display: block; }
.you:not(.muted) .mini-mic { stroke: #fff; }
.fake .mini-mic { stroke: #ef5058; }
.fake:not(.speaking) .mini-mic .mute-slash { display: block; }
.fake.speaking .mini-mic { stroke: #fff; }
.you.speaking:not(.muted) .mini-mic { stroke: var(--speak-green); }
.user-speaking #micButton[aria-pressed="true"] .icon { color: var(--speak-green); }

.coworker-camera-off {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: stretch;
  padding: 20%;
  background: #1c1e23;
  opacity: 0;
  pointer-events: none;
  transition: opacity .28s ease;
}
.fake.camera-off .coworker-camera-off { opacity: 1; }
.coworker-avatar {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 3px;
  background-image: url("assets/coworker-avatars.png");
  background-size: 200% 200%;
  background-position: var(--avatar-x) var(--avatar-y);
  background-repeat: no-repeat;
  filter: saturate(.92) contrast(.96) brightness(.92);
}

.speaking-badge {
  position: absolute;
  top: 7px;
  left: 7px;
  z-index: 4;
  padding: 5px 7px;
  border-radius: 4px;
  background: var(--speak-green);
  color: #07150c;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .02em;
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity .14s ease, transform .14s ease;
}

.participant.speaking .speaking-badge { opacity: 1; transform: none; }

.controls {
  position: relative;
  z-index: 8;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 15px;
  border-top: 1px solid #27282d;
  background: #17181b;
}

.control-cluster, .primary-controls { display: flex; align-items: center; }
.primary-controls { gap: 5px; }

.control {
  display: grid;
  justify-items: center;
  gap: 3px;
  min-width: 64px;
  height: 62px;
  padding: 7px 10px 5px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #f0f1f4;
  cursor: pointer;
}

.control:hover, .control:focus-visible, .chevron:hover, .chevron:focus-visible { background: var(--panel-hover); outline: none; }
.control:focus-visible, .chevron:focus-visible, .leave:focus-visible, .join-button:focus-visible, input:focus-visible { box-shadow: 0 0 0 2px var(--zoom-blue); }

.icon-wrap { position: relative; display: grid; place-items: center; height: 27px; }
.icon { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
.control-label { font-size: 11px; line-height: 1; }
.off-icon { display: none; }
.control[aria-pressed="false"] .on-icon { display: none; }
.control[aria-pressed="false"] .off-icon { display: block; color: #ff565f; }
.chevron { width: 22px; height: 55px; margin-left: -9px; padding: 0; border: 0; border-radius: 5px; background: transparent; color: #a6a9b0; cursor: pointer; }
.participants-icon .count { position: absolute; top: -3px; right: -8px; min-width: 17px; padding: 2px; border-radius: 9px; background: #34363c; font-size: 9px; }
.share .icon { color: #65d86e; }
.voices[aria-pressed="true"] .icon { color: #8fbfff; }

.leave {
  justify-self: end;
  min-width: 84px;
  height: 37px;
  border: 0;
  border-radius: 6px;
  background: #d9363e;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.leave:hover { background: #ee444d; }

.join-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
  background: rgba(14, 16, 20, .96);
  transition: opacity .25s ease, visibility .25s ease;
}

.join-screen.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.join-card {
  display: grid;
  width: min(92vw, 460px);
  padding: 26px;
  border: 1px solid #34363d;
  border-radius: 15px;
  background: #1a1c20;
  box-shadow: 0 30px 80px rgba(0,0,0,.55);
}

.brand-mark { margin-bottom: 22px; color: #4a95ff; font-size: 24px; font-weight: 600; letter-spacing: -1.5px; }

.preview-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 10px;
  background: #262931;
}

.preview-shell video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview-fallback span { width: 22%; font-size: 36px; }
.preview-name { bottom: 9px; left: 9px; }
.enable-camera {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: 15px;
  display: flex;
  align-items: center;
  gap: 7px;
  height: 35px;
  padding: 0 12px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 7px;
  background: rgba(18, 20, 24, .88);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transform: translateX(-50%);
  backdrop-filter: blur(8px);
}
.enable-camera:hover { background: #30333a; }
.enable-camera:focus-visible { outline: 2px solid var(--zoom-blue); outline-offset: 2px; }
.enable-camera svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.enable-camera.hidden { display: none; }
.camera-status { margin: 8px 0 0; color: #8d9199; font-size: 11px; text-align: center; }
.camera-status.error { color: #ff858b; }
.camera-status.success { color: #63d77a; }
.join-copy { margin: 20px 0 18px; }
.eyebrow { margin: 0 0 7px; color: #8fbfff !important; font-size: 11px !important; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.join-copy h1 { margin: 0 0 8px; color: #fff; font-size: 28px; font-weight: 600; letter-spacing: -.035em; }
.join-copy p { margin: 0; color: #aeb1b9; font-size: 14px; line-height: 1.5; }
.join-card label { margin-bottom: 7px; color: #d5d7dc; font-size: 12px; font-weight: 500; }
.join-card input { height: 44px; padding: 0 12px; border: 1px solid #484b54; border-radius: 7px; outline: 0; background: #111215; color: #fff; }
.join-card input:focus { border-color: var(--zoom-blue); }
.join-button { height: 45px; margin-top: 12px; border: 0; border-radius: 7px; background: var(--zoom-blue); color: #fff; font-weight: 600; cursor: pointer; }
.join-button:hover { background: #1f7eed; }
.permission-note { margin: 12px 0 0; color: #747780; font-size: 11px; text-align: center; }

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: 94px;
  padding: 10px 14px;
  border: 1px solid #40434b;
  border-radius: 6px;
  background: #26282e;
  color: #f6f7f9;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.settings-dialog {
  width: min(92vw, 470px);
  padding: 0;
  border: 1px solid #3a3d44;
  border-radius: 12px;
  background: #1b1c20;
  color: #fff;
  box-shadow: 0 28px 80px rgba(0,0,0,.65);
}
.settings-dialog::backdrop { background: rgba(0,0,0,.68); backdrop-filter: blur(3px); }
.settings-dialog form { padding: 22px; }
.settings-heading { display: flex; align-items: start; justify-content: space-between; }
.settings-heading .eyebrow { margin-bottom: 5px; }
.settings-heading h2 { margin: 0; font-size: 21px; }
.settings-close { width: 32px; height: 32px; border: 0; border-radius: 6px; background: #2a2c31; color: #dfe1e5; font-size: 22px; cursor: pointer; }
.settings-copy { margin: 10px 0 18px; color: #aeb1b9; font-size: 13px; }
.avatar-options { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.avatar-option { display: grid; gap: 6px; justify-items: center; padding: 10px 5px 8px; border: 1px solid #3b3e45; border-radius: 9px; background: #24262b; color: #fff; cursor: pointer; }
.avatar-option:hover, .avatar-option.selected { border-color: var(--zoom-blue); background: #293b54; }
.avatar-option span { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: #3e4652; font-size: 26px; }
.avatar-option small { color: #c6c8cd; font-size: 10px; }
.voice-trigger-setting { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-top: 18px; padding-top: 16px; border-top: 1px solid #35373d; }
.voice-trigger-setting strong, .voice-trigger-setting small { display: block; }
.voice-trigger-setting strong { font-size: 13px; }
.voice-trigger-setting small { margin-top: 4px; color: #9da0a8; font-size: 11px; }
.toggle-switch { position: relative; flex: 0 0 auto; width: 42px; height: 24px; padding: 0; border: 0; border-radius: 14px; background: #555961; cursor: pointer; transition: background .15s ease; }
.toggle-switch span { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: white; transition: transform .15s ease; }
.toggle-switch[aria-pressed="true"] { background: var(--zoom-blue); }
.toggle-switch[aria-pressed="true"] span { transform: translateX(18px); }

.voice-debug {
  position: fixed;
  z-index: 19;
  right: 15px;
  bottom: 94px;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(420px, calc(100vw - 30px));
  padding: 9px 11px;
  border: 1px solid #41444c;
  border-radius: 7px;
  background: rgba(28,30,35,.92);
  color: #e7e9ed;
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity .16s ease, transform .16s ease;
  backdrop-filter: blur(8px);
}
.voice-debug.show { opacity: 1; transform: none; }
.voice-debug-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: var(--speak-green); box-shadow: 0 0 0 3px rgba(35,209,96,.12); }

@media (max-width: 820px) {
  :root { --control-height: 72px; }
  .meeting-id, .view-pill span { display: none; }
  .gallery {
    max-width: calc(100% - 8px);
    gap: 4px;
  }
  .gallery[data-count="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: minmax(0, 1fr); width: min(calc(100% - 8px), calc(var(--gallery-height) * 2)); aspect-ratio: 2 / 1; }
  .gallery[data-count="3"], .gallery[data-count="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); }
  .gallery[data-count="5"], .gallery[data-count="6"] { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr)); }
  .controls { grid-template-columns: 1fr auto; padding: 0 8px; }
  .controls { grid-template-columns: auto 1fr auto; }
  .primary-controls { display: flex; justify-self: center; gap: 0; }
  .primary-controls .control:not(#voicesButton):not(#settingsButton) { display: none; }
  .primary-controls #voicesButton, .primary-controls #settingsButton { min-width: 52px; padding-inline: 5px; }
  .control { min-width: 58px; padding-inline: 7px; }
  .chevron { display: none; }
}

@media (max-width: 480px) {
  .meeting { min-height: 480px; }
  .meeting-meta { font-size: 11px; }
  .security-pill { background: transparent; padding-left: 2px; }
  .view-pill { padding: 0 7px; }
  .gallery { max-width: calc(100% - 6px); }
  .participant-label { bottom: 4px; left: 4px; font-size: 10px; }
  .control-label { font-size: 9px; }
  .leave { min-width: 68px; }
  .join-screen { place-items: start center; padding: 14px; }
  .join-card { padding: 20px; }
  .settings-dialog form { padding: 18px; }
  .avatar-options { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
  .avatar-option span { width: 38px; height: 38px; font-size: 22px; }
  .voice-debug { right: 8px; bottom: 80px; max-width: calc(100vw - 16px); }
}

@media (max-width: 600px) {
  .meeting { min-height: 0; }
  .gallery {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 4px;
    overflow-x: hidden;
    overflow-y: auto;
    align-content: start;
    overscroll-behavior: contain;
    scrollbar-width: none;
  }
  .gallery::-webkit-scrollbar { display: none; }
  .gallery[data-count="2"],
  .gallery[data-count="3"],
  .gallery[data-count="4"],
  .gallery[data-count="5"],
  .gallery[data-count="6"] {
    width: 100%;
    aspect-ratio: auto;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: none;
  }
  .gallery[data-count="2"] { align-content: center; }
  .gallery .participant { aspect-ratio: 1 / 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
