/* TWO · Full-screen FaceTime-inspired call overlay (GPU-lightweight & mobile keyboard safe) */
.call-window {
  --ink: #f5f7fa;
  --muted: rgba(235, 240, 248, 0.72);
  --surface: rgba(18, 22, 29, 0.78);
  --surface-strong: rgba(28, 34, 44, 0.92);
  --stroke: rgba(255, 255, 255, 0.14);
  --accent: #0a84ff;
  --danger: #e5484d;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  box-sizing: border-box;
  position: fixed;
  top: var(--vv-top, 0px);
  left: var(--vv-left, 0px);
  width: var(--vv-width, 100vw);
  height: var(--vv-height, 100dvh);
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  overscroll-behavior: none;
  color: var(--ink);
  background: radial-gradient(circle at 50% 24%, #1a2230 0%, #0b0e14 58%, #05070a 100%);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  touch-action: manipulation;
}

.call-window[open] {
  display: flex;
  flex-direction: column;
}

/* Solid dark backdrop instead of full-screen blur to eliminate mobile GPU overheating */
.call-window::backdrop {
  background: #05070a;
}

.call-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  background: transparent;
}

.call-video .call-stage {
  background: #05070a;
}

/* Atmospheric voice/ringing hero */
.call-voice-hero {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px 24px 120px;
  text-align: center;
  pointer-events: none;
}

.call-video .call-voice-hero {
  display: none;
}

.call-avatar-ring {
  width: 96px;
  height: 96px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 36px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #ffffff;
  background: linear-gradient(145deg, #2b3950 0%, #161d29 100%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.48), 0 0 0 10px rgba(255, 255, 255, 0.03);
}

.call-ringing .call-avatar-ring {
  animation: call-pulse 2.2s ease-in-out infinite;
}

@keyframes call-pulse {
  0%, 100% { box-shadow: 0 18px 48px rgba(0, 0, 0, 0.48), 0 0 0 8px rgba(10, 132, 255, 0.12); }
  50% { box-shadow: 0 18px 48px rgba(0, 0, 0, 0.48), 0 0 0 22px rgba(10, 132, 255, 0.03); }
}

/* Videos: full-bleed main + floating clickable PiP */
.call-peer,
.call-self {
  display: none;
  background: #070a0f;
  object-fit: cover;
}

.call-video .call-peer,
.call-video .call-self {
  display: block;
  position: absolute;
}

/* Default state: peer is full screen, self is PiP */
.call-video:not(.call-swapped) .call-peer,
.call-video.call-swapped .call-self {
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 0;
  z-index: 1;
  cursor: default;
  box-shadow: none;
  border: 0;
}

.call-video:not(.call-swapped) .call-self,
.call-video.call-swapped .call-peer {
  top: calc(var(--safe-top) + 14px);
  right: 14px;
  width: clamp(92px, 26vw, 138px);
  aspect-ratio: 3 / 4;
  border-radius: 18px;
  z-index: 4;
  cursor: pointer;
  border: 1.5px solid rgba(255, 255, 255, 0.24);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.52);
  transition: transform 180ms ease, border-color 180ms ease;
}

.call-video.call-kb-open:not(.call-swapped) .call-self,
.call-video.call-kb-open.call-swapped .call-peer {
  width: clamp(72px, 19vw, 96px);
  border-radius: 14px;
}

.call-video:not(.call-swapped) .call-self:active,
.call-video.call-swapped .call-peer:active {
  transform: scale(0.96);
}

/* Front camera mirror applies only to self feed when facing user */
.call-self.call-mirror {
  transform: scaleX(-1);
}

.call-video:not(.call-swapped) .call-self.call-mirror:active {
  transform: scaleX(-1) scale(0.96);
}

.call-camera-off .call-self {
  opacity: 0.25;
}

/* Subtle clickable swap badge pinned to the PiP corner */
.call-swap-btn {
  display: none;
  position: absolute;
  top: calc(var(--safe-top) + 20px);
  right: 20px;
  z-index: 5;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(12, 16, 22, 0.66);
  color: #ffffff;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
}

.call-video .call-swap-btn {
  display: inline-flex;
}

.call-swap-btn svg {
  width: 14px;
  height: 14px;
}

/* Top & bottom soft gradient scrims so text/buttons remain legible without heavy blur */
.call-scrim-top,
.call-scrim-bottom {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
  z-index: 2;
}

.call-video .call-scrim-top {
  display: block;
  top: 0;
  height: 120px;
  background: linear-gradient(180deg, rgba(5, 7, 10, 0.74) 0%, rgba(5, 7, 10, 0) 100%);
}

.call-video .call-scrim-bottom {
  display: block;
  bottom: 0;
  height: 196px;
  background: linear-gradient(0deg, rgba(5, 7, 10, 0.86) 0%, rgba(5, 7, 10, 0.42) 56%, rgba(5, 7, 10, 0) 100%);
}

/* Top floating status header */
.call-heading {
  position: absolute;
  top: calc(var(--safe-top) + 14px);
  left: 14px;
  z-index: 4;
  max-width: calc(100% - 148px);
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 14px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--stroke);
  pointer-events: none;
}

.call-heading-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.call-heading strong {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: #ffffff;
}

.call-timer {
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.72);
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.call-timer:empty {
  display: none;
}

.call-heading [role="status"] {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.3;
}

/* Bottom floating HUD (captions + silent-mode typing bar + action dock) */
.call-hud {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 8px 14px calc(var(--safe-bottom) + 14px);
  pointer-events: none;
}

.call-kb-open .call-hud {
  padding-bottom: 10px;
  gap: 8px;
}

.call-caption {
  max-width: min(92%, 520px);
  padding: 10px 16px;
  border-radius: 16px;
  background: rgba(10, 14, 21, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #ffffff;
  font-size: 15px;
  line-height: 1.45;
  text-align: center;
  overflow-wrap: anywhere;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.42);
  pointer-events: none;
}

.call-caption:empty {
  display: none;
}

/* Silent-mode keyboard composer */
.call-text {
  width: min(100%, 540px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 14px;
  border-radius: 999px;
  background: var(--surface-strong);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.46);
  pointer-events: auto;
}

.call-text[hidden] {
  display: none;
}

/* 16px prevents iOS Safari / WeChat WebView from auto-zooming & shifting the screen */
.call-text input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: #ffffff;
  font-size: 16px;
  line-height: 1.35;
  padding: 6px 2px;
  user-select: text;
}

.call-text input::placeholder {
  color: rgba(226, 232, 240, 0.56);
}

.call-text button[type="submit"] {
  flex: 0 0 auto;
  height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  font: 500 14px/1 inherit;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, opacity 140ms ease;
}

.call-text button[type="submit"]:active {
  transform: scale(0.96);
}

/* Bottom control dock */
.call-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  max-width: min(100%, 540px);
  padding: 10px 14px;
  border-radius: 28px;
  background: var(--surface);
  border: 1px solid var(--stroke);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.48);
  pointer-events: auto;
}

.call-kb-open .call-actions {
  padding: 6px 10px;
  gap: 8px;
  border-radius: 22px;
}

.call-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 58px;
  padding: 6px 8px;
  border: 0;
  border-radius: 18px;
  background: transparent;
  color: #ffffff;
  font: 500 11.5px/1.15 inherit;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease;
}

.call-kb-open .call-btn {
  flex-direction: row;
  min-width: auto;
  padding: 6px 12px;
  gap: 6px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  font-size: 12.5px;
}

.call-btn:active {
  transform: scale(0.94);
}

.call-btn-circle {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: background 150ms ease, border-color 150ms ease;
}

.call-kb-open .call-btn-circle {
  width: 22px;
  height: 22px;
  background: transparent;
  border: 0;
}

.call-btn-circle svg {
  width: 21px;
  height: 21px;
}

.call-kb-open .call-btn-circle svg {
  width: 16px;
  height: 16px;
}

.call-btn.is-active .call-btn-circle {
  background: #ffffff;
  color: #0b0f17;
  border-color: #ffffff;
}

.call-kb-open .call-btn.is-active {
  background: #ffffff;
  color: #0b0f17;
}

.call-kb-open .call-btn.is-active .call-btn-circle {
  background: transparent;
  color: #0b0f17;
}

.call-btn.is-off .call-btn-circle {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.65);
}

.call-btn.call-accept .call-btn-circle {
  background: #30d158;
  border-color: transparent;
  color: #ffffff;
}

.call-btn.call-danger .call-btn-circle {
  background: var(--danger);
  border-color: transparent;
  color: #ffffff;
}

.call-kb-open .call-btn.call-danger {
  background: var(--danger);
  color: #ffffff;
}

.call-kb-open .call-btn.call-danger .call-btn-circle {
  background: transparent;
  color: #ffffff;
}

.call-btn-label {
  white-space: nowrap;
  color: inherit;
  opacity: 0.92;
}

.call-text:focus-within {
  border-color: rgba(120, 183, 255, 0.72);
}

.call-window :focus-visible {
  outline: 2px solid #78b7ff;
  outline-offset: 2px;
}

.call-text input:focus-visible {
  outline: none;
}

@media (prefers-reduced-motion: reduce) {
  .call-ringing .call-avatar-ring,
  .call-btn,
  .call-btn-circle,
  .call-video .call-self,
  .call-video .call-peer {
    animation: none;
    transition: none;
  }
}
