/* ── Presence bar ── */

.presence-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-top: 1px solid var(--line);
  z-index: 900;
  padding: 0 52px 0 12px;  /* right padding reserves space for dismiss button */
  contain: style;
}

.presence-circles {
  display: flex;
  gap: 4px;
  align-items: center;
  overflow: visible;           /* tooltips must escape; "+N" caps circle count */
  padding: 4px;               /* room for 2px box-shadow rings + badges */
  margin: -4px;               /* offset padding so layout stays centered */
}

.presence-circle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  font-family: system-ui, sans-serif;
  background: var(--accent);
  color: white;
  position: relative;
  flex-shrink: 0;
  user-select: none;
}

/* Hover tooltip */
.presence-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink, #1e293b);
  color: #fff;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.3;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.presence-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: var(--ink, #1e293b);
}

.presence-circle:hover .presence-tooltip {
  opacity: 1;
}

/* Edge-aware: pin tooltip near left edge */
.presence-circle:first-child .presence-tooltip {
  left: 0;
  transform: none;
}
.presence-circle:first-child .presence-tooltip::after {
  left: 14px;
  transform: none;
}

/* Edge-aware: pin tooltip near right edge */
.presence-circle:last-child .presence-tooltip {
  left: auto;
  right: 0;
  transform: none;
}
.presence-circle:last-child .presence-tooltip::after {
  left: auto;
  right: 10px;
  transform: none;
}

/* Single circle: revert to centered */
.presence-circle:only-child .presence-tooltip {
  left: 50%;
  right: auto;
  transform: translateX(-50%);
}
.presence-circle:only-child .presence-tooltip::after {
  left: 50%;
  right: auto;
  transform: translateX(-50%);
}

.presence-tooltip-page {
  font-weight: 400;
  opacity: 0.7;
  font-size: 10px;
}

@media (min-width: 640px) {
  .presence-circle {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }
}

/* Anonymous */
.presence-circle.is-anon {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--line);
}

/* Teacher ring */
.presence-circle.is-teacher {
  box-shadow: 0 0 0 2px #2563eb;
}

/* Admin ring */
.presence-circle.is-admin {
  box-shadow: 0 0 0 2px #d97706;
}

/* Current user pulse — layered on role ring */
.presence-circle.is-you {
  animation: presence-pulse 2.5s ease-in-out infinite;
}
.presence-circle.is-you:not(.is-teacher):not(.is-admin) {
  box-shadow: 0 0 0 2px var(--accent);
}

@keyframes presence-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

@media (prefers-reduced-motion: reduce) {
  .presence-circle.is-you {
    animation: none;
    outline: 2px dashed var(--accent);
    outline-offset: 1px;
  }
  .presence-circle.is-you.is-teacher {
    outline-color: #2563eb;
  }
  .presence-circle.is-you.is-admin {
    outline-color: #d97706;
  }
}

/* Badge (positioned bottom-right of circle) */
.presence-badge {
  position: absolute;
  bottom: -3px;
  right: -3px;
  width: 12px;
  height: 12px;
  background: var(--panel);
  border-radius: 50%;
  padding: 1px;
}

/* Overflow "+N" — lives outside .presence-circles to avoid being clipped */
.presence-circle.is-overflow {
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  flex-shrink: 0;
}

/* Dismiss button — 44px min touch target per Apple HIG */
.presence-dismiss {
  position: absolute;
  right: 4px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 14px;   /* (44 - 16) / 2 = 14px padding around 16px icon */
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.presence-dismiss:hover {
  color: var(--ink);
}

/* Restore button (floating, visible when bar is dismissed) — 44px touch target */
.presence-restore {
  position: fixed;
  bottom: 8px;
  right: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  cursor: pointer;
  z-index: 900;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  -webkit-tap-highlight-color: transparent;
}
.presence-restore:hover {
  color: var(--ink);
  border-color: var(--accent);
}

/* ── Mobile: stacking with word detail bottom bar ── */

/* Body padding to prevent content from being hidden behind the presence bar */
body[data-presence] {
  padding-bottom: 48px;
}

/*
 * Word detail page has a fixed .bottom-bar on mobile (Previous/Reveal/Next).
 * Lift it above the presence bar so both are usable.
 */
@media (max-width: 640px) {
  body[data-presence] .bottom-bar {
    bottom: 40px;
  }
  /* When both bars are visible, content needs extra padding for both */
  body[data-presence]:has(.bottom-bar) {
    padding-bottom: 96px;  /* 40px presence + ~56px bottom-bar */
  }
}

/* Print: hide everything */
@media print {
  .presence-bar,
  .presence-restore {
    display: none !important;
  }
  body[data-presence] {
    padding-bottom: 0;
  }
}
