/* ═══════════════════════════════════════════
   Dreamspace — Collab Presence Layer
   Live cursors · drag ghosts · selection glow · roster · toasts

   Theming: cursors/ghosts/outlines float over the canvas, which stays dark
   in BOTH themes (see base.css: [data-theme="light"] .canvas-area), so those
   are styled light-on-dark regardless of theme. Roster + toasts live in the
   themed shell and lean on the app's CSS custom props (--panel, --text-*,
   --border) which switch via [data-theme]. A prefers-color-scheme block
   provides fallbacks for those neutrals per project convention.
   Per-user accent color arrives as the inline custom property --c.
   ═══════════════════════════════════════════ */

/* Presence-local fallbacks (used only if the app vars are absent). */
.collab-roster,
.collab-toasts {
  --cp-surface: var(--panel, #241535);
  --cp-text: var(--text-primary, rgba(255, 255, 255, 0.85));
  --cp-text-dim: var(--text-secondary, rgba(255, 255, 255, 0.45));
  --cp-border: var(--border-hover, rgba(255, 255, 255, 0.12));
  --cp-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: light) {
  /* Honor the system default when the app hasn't pinned [data-theme]. */
  :root:not([data-theme="dark"]) .collab-roster,
  :root:not([data-theme="dark"]) .collab-toasts {
    --cp-shadow: 0 8px 28px rgba(60, 40, 90, 0.18);
  }
}

/* ═══ Overlay (cursors + drag ghosts + selection outlines) ═══ */

#collab-presence-overlay.collab-presence {
  position: absolute;
  inset: 0;
  z-index: 40;
  pointer-events: none;     /* never intercept canvas interaction */
  overflow: hidden;         /* clip presence that drifts off-canvas */
  contain: layout style;
}

/* Visually-hidden live region — presence announcements for assistive tech.
   (presence.js #collab-presence-live; the visual cursors/roster carry no
   semantics on their own.) */
.collab-presence-live {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ── Live cursors ───────────────────────────── */

.collab-cursor {
  position: absolute;
  top: 0;
  left: 0;
  /* transform set inline (translate to screen px) — origin at the arrow tip */
  will-change: transform;
  pointer-events: none;
  z-index: 3;
}

.collab-cursor-arrow {
  display: block;
  fill: var(--c, #c4b5fd);
  stroke: rgba(255, 255, 255, 0.92);
  stroke-width: 1.1;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45))
          drop-shadow(0 0 6px color-mix(in srgb, var(--c, #c4b5fd) 70%, transparent));
}

.collab-cursor-label {
  position: absolute;
  left: 16px;
  top: 16px;
  max-width: 160px;
  padding: 2px 9px;
  border-radius: 11px 11px 11px 3px;
  font-family: 'Quicksand', sans-serif;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #fff;
  background: linear-gradient(135deg,
      color-mix(in srgb, var(--c, #c4b5fd) 92%, black 6%),
      color-mix(in srgb, var(--c, #c4b5fd) 70%, black 18%));
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35),
              0 0 10px color-mix(in srgb, var(--c, #c4b5fd) 45%, transparent);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

/* ── Selection awareness outline ────────────── */

.collab-selection {
  position: absolute;
  top: 0;
  left: 0;
  border: 2px solid var(--c, #c4b5fd);
  border-radius: 8px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18),
              0 0 14px color-mix(in srgb, var(--c, #c4b5fd) 55%, transparent),
              inset 0 0 22px color-mix(in srgb, var(--c, #c4b5fd) 14%, transparent);
  background: color-mix(in srgb, var(--c, #c4b5fd) 7%, transparent);
  pointer-events: none;
  z-index: 2;
  animation: collab-sel-breathe 2.8s var(--ease, ease-in-out) infinite;
}

@keyframes collab-sel-breathe {
  0%, 100% { box-shadow: 0 0 0 1px rgba(0,0,0,0.18),
                         0 0 12px color-mix(in srgb, var(--c, #c4b5fd) 45%, transparent),
                         inset 0 0 18px color-mix(in srgb, var(--c, #c4b5fd) 12%, transparent); }
  50%      { box-shadow: 0 0 0 1px rgba(0,0,0,0.18),
                         0 0 20px color-mix(in srgb, var(--c, #c4b5fd) 70%, transparent),
                         inset 0 0 26px color-mix(in srgb, var(--c, #c4b5fd) 18%, transparent); }
}

.collab-selection-tag {
  position: absolute;
  left: -2px;
  top: -22px;
  max-width: 180px;
  padding: 1px 8px;
  border-radius: 7px 7px 7px 0;
  font-family: 'Quicksand', sans-serif;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #fff;
  background: var(--c, #c4b5fd);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.4);
}

/* ── Live-drag ghost preview ────────────────── */

.collab-drag-ghost {
  position: absolute;
  top: 0;
  left: 0;
  /* transform (translate -50%,-50% + rotate) set inline */
  border: 2px dashed var(--c, #c4b5fd);
  border-radius: 10px;
  background: color-mix(in srgb, var(--c, #c4b5fd) 12%, transparent);
  box-shadow: 0 0 18px color-mix(in srgb, var(--c, #c4b5fd) 50%, transparent),
              inset 0 0 30px color-mix(in srgb, var(--c, #c4b5fd) 10%, transparent);
  pointer-events: none;
  z-index: 2;
  animation: collab-ghost-pulse 1.4s ease-in-out infinite;
}

@keyframes collab-ghost-pulse {
  0%, 100% { opacity: 0.78; }
  50%      { opacity: 1; }
}

.collab-drag-tag {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translate(-50%, -6px);
  padding: 2px 8px;
  border-radius: 9px;
  font-family: 'Quicksand', sans-serif;
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
  color: #fff;
  background: var(--c, #c4b5fd);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.4);
}

/* ═══ Presence roster (avatar stack) ═══ */

.collab-roster {
  display: flex;
  align-items: center;
  gap: 0;
  font-family: 'Quicksand', sans-serif;
}

.collab-roster.is-solo {
  opacity: 0.55;          /* gently de-emphasize when you're alone */
}

/* Fallback positioning — only when self-mounted on <body>. */
.collab-roster-floating {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 1200;
  padding: 5px 8px;
  border-radius: 30px;
  background: var(--cp-surface, #241535);
  border: 1px solid var(--cp-border, rgba(255, 255, 255, 0.12));
  box-shadow: var(--cp-shadow, 0 8px 32px rgba(0, 0, 0, 0.35));
  backdrop-filter: blur(8px);
}

.collab-avatar {
  position: relative;
  width: 30px;
  height: 30px;
  margin-left: -8px;        /* overlap into a stack */
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--c, #c4b5fd);
  box-shadow: 0 0 0 2px var(--cp-surface, #241535),       /* gap ring vs neighbor */
              0 0 0 3.5px var(--c, #c4b5fd),               /* color ring */
              0 0 10px color-mix(in srgb, var(--c, #c4b5fd) 45%, transparent);
  transition: transform 0.18s var(--ease, ease), z-index 0s;
  cursor: default;
}

.collab-avatar:first-child {
  margin-left: 0;
}

.collab-avatar:hover {
  transform: translateY(-3px) scale(1.08);
  z-index: 10;
}

.collab-avatar-self {
  box-shadow: 0 0 0 2px var(--cp-surface, #241535),
              0 0 0 3.5px #fff,
              0 0 0 5px var(--c, #c4b5fd),
              0 0 12px color-mix(in srgb, var(--c, #c4b5fd) 55%, transparent);
}

.collab-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.collab-avatar-initial {
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.3px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  user-select: none;
}

.collab-avatar-more {
  background: var(--cp-surface, #241535);
  color: var(--cp-text, rgba(255, 255, 255, 0.85));
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 0 0 2px var(--cp-surface, #241535),
              0 0 0 3.5px var(--cp-border, rgba(255, 255, 255, 0.2));
}

/* ═══ Join / leave toasts ═══ */

.collab-toasts {
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  font-family: 'Quicksand', sans-serif;
}

.collab-toasts-floating {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1300;
  align-items: center;
}

.collab-toast {
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: 320px;
  padding: 8px 14px 8px 11px;
  border-radius: 22px;
  color: var(--cp-text, rgba(255, 255, 255, 0.85));
  background: var(--cp-surface, #241535);
  border: 1px solid var(--cp-border, rgba(255, 255, 255, 0.12));
  box-shadow: var(--cp-shadow, 0 8px 32px rgba(0, 0, 0, 0.35));
  backdrop-filter: blur(10px);
  font-size: 12.5px;
  white-space: nowrap;
  animation: collab-toast-in 0.42s var(--ease, cubic-bezier(0.34, 1.56, 0.64, 1)) both;
}

.collab-toast.out {
  animation: collab-toast-out 0.6s var(--ease, ease) forwards;
}

.collab-toast-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--c, #c4b5fd);
  box-shadow: 0 0 8px color-mix(in srgb, var(--c, #c4b5fd) 75%, transparent);
}

.collab-toast-text strong {
  font-weight: 700;
  color: color-mix(in srgb, var(--c, #c4b5fd) 75%, var(--cp-text, #fff));
}

@keyframes collab-toast-in {
  from { opacity: 0; transform: translateY(-14px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes collab-toast-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-10px); }
}

/* ═══ Mobile / responsive ═══
   collab.css repositions the roster panel itself at this breakpoint; here we
   keep the presence overlays + toasts legible on small / touch screens. */

@media (max-width: 720px) {
  .collab-cursor-label { font-size: 10px; max-width: 120px; padding: 1px 7px; }
  .collab-cursor-arrow { width: 18px; height: 18px; }
  .collab-toast { max-width: min(86vw, 320px); white-space: normal; }
  .collab-toasts-floating { left: 50%; right: auto; width: max-content; max-width: 90vw; }
}

/* ═══ Reduced motion ═══ */

@media (prefers-reduced-motion: reduce) {
  .collab-selection,
  .collab-drag-ghost {
    animation: none;
  }
}

/* color-mix fallback: very old engines ignore unknown values and fall back to
   the solid --c declared just before each mix, so glows degrade gracefully. */
