/* =====================================================================================
   1-to-1 calls (public/js/calls.js)
   - .call: the call screen. It is its own layer on top of everything (sheets, the story
     viewer, toasts), so moving to another page never closes it. Full screen on phones, a
     card in the middle of the screen on wider screens.
   - .call-bar: the call made small, a bar at the top so the app stays usable while you talk.
   Colours come from base.css, so both themes work. Accept is green, Decline and Hang up red.
   ===================================================================================== */

.call-root {
  /* Green and red that keep a white icon readable in both themes (the dark theme's green is
     bright, so it is deepened a little). */
  --call-green: color-mix(in srgb, var(--ok) 82%, #000);
  --call-red: var(--danger);
  --call-btn: 68px;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) .call-root {
    --call-green: var(--ok);
  }
}
:root[data-theme='light'] .call-root {
  --call-green: var(--ok);
}

/* While the call fills the screen, the page underneath doesn't scroll. */
html.has-call {
  overflow: hidden;
}
/* Toasts stay readable above the call screen (at the top, away from its buttons). */
html.has-call .toasts {
  z-index: 3600;
  top: calc(var(--safe-t) + 12px);
  bottom: auto;
}

/* ---------- The call screen ---------- */
.call {
  position: fixed;
  inset: 0;
  z-index: 3500;
  display: flex;
  background: var(--bg);
  color: var(--text);
  outline: none;
  overscroll-behavior: contain;
}
.call.is-entering {
  animation: call-in var(--dur-3) var(--ease) both;
}
.call:focus,
.call:focus-visible {
  outline: none;
}

.call__panel {
  position: relative;
  isolation: isolate;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden auto;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 20px) calc(var(--safe-b) + 28px) calc(var(--safe-l) + 20px);
  background:
    radial-gradient(120% 60% at 50% 0%, color-mix(in srgb, var(--brand-2) 24%, transparent), transparent 72%),
    radial-gradient(90% 50% at 50% 100%, color-mix(in srgb, var(--brand-4) 14%, transparent), transparent 70%),
    var(--bg);
}

/* Their picture, large and soft, behind everything. */
.call__aura {
  position: absolute;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.call__aura img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.35);
  filter: blur(48px) saturate(1.3);
  opacity: 0.42;
}
.call__aura::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, color-mix(in srgb, var(--bg) 35%, transparent), color-mix(in srgb, var(--bg) 82%, transparent) 70%, var(--bg));
}

.call__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  flex: none;
}
.call__kicker {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface-2) 72%, transparent);
  border: 1px solid var(--line);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
}
.call__kicker .icon {
  color: var(--accent);
}
.call__min {
  margin-left: auto;
  background: color-mix(in srgb, var(--surface-2) 72%, transparent);
  border: 1px solid var(--line);
}

.call__who {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 0;
  padding: 24px 0;
  text-align: center;
}

/* The picture, with rings that ripple out while it rings. */
.call__face {
  --ring: var(--accent);
  position: relative;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border-radius: 50%;
  transition: box-shadow var(--dur-2) var(--ease);
}
.call__face .avatar {
  --s: clamp(104px, 34vw, 136px);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--bg) 70%, transparent), var(--shadow-2);
  border-radius: 50%;
}
.call__face.is-ringing::before,
.call__face.is-ringing::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 2px solid var(--ring);
  opacity: 0;
  animation: call-ripple 2s var(--ease) infinite;
  pointer-events: none;
}
.call__face.is-ringing::after {
  animation-delay: 1s;
}
/* They're talking: a soft green glow. */
.call__face.is-talking {
  box-shadow:
    0 0 0 4px color-mix(in srgb, var(--ok) 70%, transparent),
    0 0 36px 6px color-mix(in srgb, var(--ok) 35%, transparent);
}

.call__name {
  max-width: 100%;
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(32px, 9.5vw, 44px);
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1.08;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}
.call__status {
  max-width: 32ch;
  min-height: 1.5em;
  margin: 0;
  color: var(--text-2);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.45;
  text-wrap: balance;
}
.call__time {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: var(--text);
}
.call--ended .call__status {
  color: var(--text);
}
.call--ended .call__face {
  opacity: 0.75;
  filter: saturate(0.6);
}

/* "Asha is muted" */
.call__chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 10px 0 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 650;
}
/* "Your microphone is blocked…" */
.call__note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 34ch;
  margin: 14px 0 0;
  padding: 12px 14px;
  border-radius: var(--radius-m);
  background: var(--warn-soft);
  border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  color: var(--text);
  font-size: 14px;
  font-weight: 550;
  line-height: 1.4;
  text-align: left;
}
.call__note .icon {
  flex: none;
  margin-top: 1px;
  color: var(--warn);
}
.call__hear {
  margin-top: 16px;
}

/* ---------- The big round buttons ---------- */
.call__actions {
  flex: none;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: clamp(28px, 16vw, 72px);
  padding-top: 8px;
}
.call-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  min-width: 84px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.call-btn:focus-visible {
  outline: none;
}
.call-btn__circle {
  display: grid;
  place-items: center;
  width: var(--call-btn);
  height: var(--call-btn);
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  color: var(--text);
  box-shadow: var(--shadow-1);
  transition:
    transform var(--dur-1) var(--ease),
    filter var(--dur-2) var(--ease),
    background-color var(--dur-2) var(--ease);
}
.call-btn:focus-visible .call-btn__circle {
  outline: 3px solid var(--accent);
  outline-offset: 4px;
}
.call-btn:hover:not(:disabled) .call-btn__circle {
  filter: brightness(1.08);
}
.call-btn:active:not(:disabled) .call-btn__circle {
  transform: scale(0.94);
}
.call-btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}
.call-btn__label {
  line-height: 1.2;
}

.call-btn--accept .call-btn__circle {
  background: var(--call-green);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 12px 28px -10px color-mix(in srgb, var(--ok) 75%, transparent);
}
.call-btn--decline .call-btn__circle,
.call-btn--end .call-btn__circle {
  background: var(--call-red);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 12px 28px -10px color-mix(in srgb, var(--danger) 75%, transparent);
}
/* Accept wiggles a little while it rings. */
.call--incoming .call-btn--accept .call-btn__circle {
  animation: call-nudge 2s var(--ease) infinite;
}
/* Muted: the button turns solid so it's clear at a glance. */
.call-btn--mute[data-muted] .call-btn__circle {
  background: var(--text);
  border-color: transparent;
  color: var(--bg);
}

/* ---------- The small bar (call minimised) ---------- */
.call-bar {
  position: fixed;
  z-index: 2600; /* above sheets, so you can always get back to the call */
  top: calc(var(--safe-t) + var(--topbar-h) + 8px);
  left: calc(var(--safe-l) + 12px);
  right: calc(var(--safe-r) + 12px);
  max-width: 460px;
  margin-inline: auto;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  /* Solid: the page scrolling underneath shouldn't show through the text. */
  background: var(--surface);
  border: 1px solid var(--line-2);
  box-shadow: var(--shadow-2);
  color: var(--text);
}
.call-bar.is-entering {
  animation: call-bar-in var(--dur-3) var(--ease-spring) both;
}
html.chrome-bare .call-bar,
html.chrome-immersive .call-bar {
  top: calc(var(--safe-t) + 8px);
}
.call-bar__open {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px 0 12px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
}
.call-bar__open:hover {
  background: var(--surface-2);
}
.call-bar__open:focus-visible,
.call-bar__btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: 999px;
}
.call-bar__dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent);
  animation: call-blink 1.6s ease-in-out infinite;
}
.call-bar--outgoing .call-bar__dot,
.call-bar--connecting .call-bar__dot {
  background: var(--warn);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 25%, transparent);
}
.call-bar--ended .call-bar__dot {
  background: var(--text-3);
  box-shadow: none;
  animation: none;
}
.call-bar__text {
  display: grid;
  min-width: 0;
  line-height: 1.25;
}
.call-bar__text strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 750;
}
.call-bar__state {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.call-bar__btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  transition:
    transform var(--dur-1) var(--ease),
    filter var(--dur-2) var(--ease);
  touch-action: manipulation;
}
.call-bar__btn:active:not(:disabled) {
  transform: scale(0.94);
}
.call-bar__btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.call-bar__btn[data-muted] {
  background: var(--text);
  border-color: transparent;
  color: var(--bg);
}
.call-bar__btn--end {
  background: var(--call-red);
  border-color: transparent;
  color: #fff;
}
.call-bar__btn--end:hover {
  filter: brightness(1.08);
}

/* The profile's Call button: the phone icon in green. */
.pr-btn--call .icon {
  color: var(--ok);
}

/* ---------- Motion ---------- */
@keyframes call-in {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
}
@keyframes call-bar-in {
  from {
    opacity: 0;
    transform: translateY(-10px) scale(0.97);
  }
}
@keyframes call-ripple {
  0% {
    opacity: 0.7;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.55);
  }
}
@keyframes call-nudge {
  0%,
  60%,
  100% {
    transform: none;
  }
  66% {
    transform: rotate(-12deg) scale(1.04);
  }
  72% {
    transform: rotate(12deg) scale(1.04);
  }
  78% {
    transform: rotate(-8deg) scale(1.02);
  }
  84% {
    transform: none;
  }
}
@keyframes call-blink {
  50% {
    opacity: 0.45;
  }
}

/* ---------- Wider screens: a card in the middle ---------- */
@media (min-width: 768px) {
  .call {
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--scrim);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }
  .call__panel {
    flex: none;
    width: min(420px, 100%);
    height: min(720px, 100%);
    padding: 20px 24px 32px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-2);
  }
  .call-root {
    --call-btn: 72px;
  }
}
@media (min-width: 1024px) {
  .call-bar {
    top: 16px;
    left: calc(var(--sidebar-w) + 24px);
    right: 24px;
  }
  html.chrome-bare .call-bar,
  html.chrome-immersive .call-bar {
    left: 24px;
    top: 16px;
  }
}

/* ---------- Short screens (a phone on its side) ---------- */
@media (max-height: 560px) {
  .call__who {
    padding: 8px 0;
    gap: 2px;
  }
  .call__face {
    margin-bottom: 10px;
  }
  .call__face .avatar {
    --s: 76px;
  }
  .call__name {
    font-size: 30px;
    -webkit-line-clamp: 1;
    line-clamp: 1;
  }
  .call-root {
    --call-btn: 60px;
  }
}

/* ---------- Less motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .call.is-entering,
  .call-bar.is-entering,
  .call-bar__dot,
  .call--incoming .call-btn--accept .call-btn__circle {
    animation: none;
  }
  /* A still ring instead of ripples. */
  .call__face.is-ringing::before {
    animation: none;
    opacity: 0.6;
    transform: scale(1.12);
  }
  .call__face.is-ringing::after {
    display: none;
  }
}
