/**
 * Coastal Key — floating Avatar PIP (Manus master deployment MP4)
 * Collapsed ≈ 1/8 viewport · Expanded ≈ 1/2 viewport · position:fixed floats on scroll
 */

#ck-avatar-float {
  --ck-av-navy: #0b1629;
  --ck-av-gold: #c5a46e;
  --ck-av-gold-hi: #d4af37;
  --ck-av-sand: #e8e4d9;
  /*
   * Manus deployment MP4 is 512×512 square.
   * Collapsed ≈ 1/8 of screen area → side ≈ √(1/8) of min viewport ≈ 35.35vmin
   * Expanded ≈ 1/2 of screen → 50vw × 50vh box
   */
  --ck-av-collapsed-w: 35.35vmin;
  --ck-av-collapsed-h: 35.35vmin;
  --ck-av-expanded-w: 50vw;
  --ck-av-expanded-h: 50vh;
  --ck-av-min-w: 140px;
  --ck-av-min-h: 140px;

  position: fixed;
  right: max(12px, 1.25vw);
  bottom: max(12px, 1.25vw);
  z-index: 9990;
  width: max(var(--ck-av-min-w), var(--ck-av-collapsed-w));
  height: max(var(--ck-av-min-h), var(--ck-av-collapsed-h));
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  margin: 0;
  padding: 0;
  border: 1px solid rgba(197, 164, 110, 0.55);
  border-radius: 14px;
  background: var(--ck-av-navy);
  box-shadow:
    0 0 0 1px rgba(11, 22, 41, 0.4),
    0 12px 40px rgba(0, 0, 0, 0.45),
    0 0 28px rgba(197, 164, 110, 0.12);
  overflow: hidden;
  cursor: pointer;
  transition:
    width 0.35s cubic-bezier(0.22, 1, 0.36, 1),
    height 0.35s cubic-bezier(0.22, 1, 0.36, 1),
    border-radius 0.3s ease,
    box-shadow 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  font-family: "Space Grotesk", system-ui, sans-serif;
}

#ck-avatar-float.is-expanded {
  width: min(var(--ck-av-expanded-w), calc(100vw - 24px));
  height: min(var(--ck-av-expanded-h), calc(100vh - 24px));
  border-radius: 16px;
  box-shadow:
    0 0 0 1px rgba(197, 164, 110, 0.35),
    0 24px 64px rgba(0, 0, 0, 0.55),
    0 0 48px rgba(197, 164, 110, 0.18);
  cursor: default;
}

#ck-avatar-float .ck-av-media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover; /* full MP4 frame as-is, no crop bias */
  object-position: center center;
  display: block;
  background: #000;
  pointer-events: none; /* clicks hit the shell so expand/collapse stays reliable */
}

#ck-avatar-float.is-expanded .ck-av-media {
  pointer-events: auto; /* allow native controls when expanded */
  object-fit: contain; /* full frame visible at 1/2 screen */
  background: #000;
}

#ck-avatar-float .ck-av-chrome {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(6, 16, 31, 0.55) 35%,
    rgba(6, 16, 31, 0.92) 100%
  );
  pointer-events: none;
}

#ck-avatar-float .ck-av-label {
  color: var(--ck-av-sand);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#ck-avatar-float .ck-av-label span {
  color: var(--ck-av-gold);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: none;
  display: block;
  font-size: 0.62rem;
  opacity: 0.9;
}

#ck-avatar-float .ck-av-hint {
  flex-shrink: 0;
  color: var(--ck-av-navy);
  background: linear-gradient(145deg, #b8860b 0%, var(--ck-av-gold-hi) 50%, #b8860b 100%);
  border: 1px solid var(--ck-av-gold);
  border-radius: 999px;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 8px;
  white-space: nowrap;
}

#ck-avatar-float.is-expanded .ck-av-hint {
  display: none;
}

#ck-avatar-float .ck-av-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(197, 164, 110, 0.55);
  border-radius: 999px;
  background: rgba(11, 22, 41, 0.85);
  color: var(--ck-av-sand);
  font-size: 1.1rem;
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
  transition: background 0.15s ease, border-color 0.15s ease;
}

#ck-avatar-float .ck-av-close:hover,
#ck-avatar-float .ck-av-close:focus-visible {
  background: rgba(197, 164, 110, 0.2);
  border-color: var(--ck-av-gold);
  outline: none;
}

#ck-avatar-float.is-expanded .ck-av-close {
  display: inline-flex;
}

#ck-avatar-float .ck-av-ring {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(197, 164, 110, 0.25);
  pointer-events: none;
}

/* Backdrop when expanded for focus */
#ck-avatar-float-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9985;
  background: rgba(6, 16, 31, 0.55);
  backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

#ck-avatar-float-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  #ck-avatar-float {
    transition: none;
  }
}

/* Narrow screens: keep readable min size; expanded still half viewport */
@media (max-width: 640px) {
  #ck-avatar-float {
    --ck-av-collapsed-w: min(42vmin, 180px);
    --ck-av-collapsed-h: min(42vmin, 180px);
    --ck-av-expanded-w: 92vw;
    --ck-av-expanded-h: 50vh;
    right: 10px;
    bottom: 10px;
  }
}
