/* Enimates — reusable "24 friends, 8 families" gallery + floating popover.
   Consumed by both the Atlas and globe previews. Tokens match globe.css/concepts.css:
   cream #FFFCF6, plum #2E2440, Nunito. Per-family colour comes from inline
   --family-color/--family-ink/--family-rgb set on each .emotion-family by root's HTML. */

.family-gallery {
  --fg-maxw: 1280px;
  max-width: var(--fg-maxw);
  margin: 0 auto;
  overflow-x:auto;
  padding-bottom:12px;
}

.family-gallery-guide {
  margin: 0 0 1.1rem;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--plum-soft, #55496b);
}

.family-columns {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  min-width:1120px;
  gap: 0.9rem 0.7rem;
}

/* ---------- one emotion family (tinted column) ---------- */
.emotion-family {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
  padding: 0.7rem 0.6rem 0.8rem;
  border-radius: 1.1rem;
  border: 1px solid rgba(var(--family-rgb), 0.22);
  background: rgba(var(--family-rgb), 0.07);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.emotion-family.is-family-active {
  background: rgba(var(--family-rgb), 0.14);
  border-color: rgba(var(--family-rgb), 0.4);
}

.emotion-family-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 0.15rem;
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--family-ink);
  overflow-wrap: break-word;
}

.family-colour {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--family-color);
}

/* ---------- the three cards in a family ---------- */
.family-trio {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.family-card {
  user-select:none;
  display: grid;
  grid-template-columns:44px minmax(0,1fr);
  grid-template-rows:auto auto;
  align-items: center;
  gap: 0.6rem;
  min-height: 44px;
  padding: 0.4rem;
  background: #FFFCF6;
  border: 1px solid rgba(var(--family-rgb), 0.18);
  border-radius: 0.85rem;
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  text-align: left;
  cursor: pointer;
  box-shadow: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.family-card img {
  grid-column:1;grid-row:1 / 3;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(var(--family-rgb), 0.35);
}

.family-card-name {
  grid-column:2;grid-row:1;align-self:end;min-width:0;
  display: block;
  font-size: 0.8rem;
  font-weight: 800;
  color: #2E2440;
  line-height: 1.18;
  overflow-wrap: break-word;
}

.family-card-level {
  grid-column:2;grid-row:2;align-self:start;
  display: block;
  margin-top: 0.1rem;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--plum-soft, #55496b);
}

/* sibling lift + glow when the family is hovered/focused/tapped */
.emotion-family.is-family-active .family-card {
  transform: translateY(-3px);
  border-color: rgba(var(--family-rgb), 0.45);
  box-shadow: 0 10px 20px -12px rgba(var(--family-rgb), 0.55);
}

/* the actual chosen character gets a stronger lift + rim */
.emotion-family.is-family-active .family-card.is-character-active {
  transform: translateY(-5px);
  border-color: var(--family-color);
  box-shadow: inset 0 0 0 1px var(--family-color),0 8px 22px -6px rgba(var(--family-rgb), 0.55);
}

.family-card:hover,
.family-card:focus-visible {
  outline: none;
  border-color: var(--family-color);
}
.family-card:focus-visible {
  outline: 2px solid var(--family-ink);
  outline-offset: 2px;
}

/* ---------- responsive column counts ---------- */
/* mobile-first default above is 2 columns (<=649px) */

@media (hover: none) and (pointer: coarse) and (min-width: 650px) and (max-width: 1099px) {
  .family-columns {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (hover: hover), (pointer: fine), (min-width:1100px) {
  .family-columns {
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 0.85rem;
  }
  .emotion-family {
    padding: 0.75rem 0.6rem 0.85rem;
  }
  .family-card {
    display:flex;
    flex-direction: column;
    text-align: center;
    gap: 0.3rem;
    height: 142px;
    min-height:142px;
    justify-content: center;
    padding: 0.55rem 0.4rem;
  }
  .family-card img {
    width: 64px;
    height: 64px;
  }
  .family-card-name {
    font-size: 0.78rem;align-self:stretch;min-height:29px;
  }
  .family-card-level {align-self:center;margin:0}
  .emotion-family-title {min-height:34px;font-size:.82rem}
}

/* ---------- reduced motion: keep colour/glow, drop movement ---------- */
html[data-motion='reduced'] {
  .family-card,
  .emotion-family {
    transition: none !important;
  }
  .emotion-family.is-family-active .family-card,
  .emotion-family.is-family-active .family-card.is-character-active {
    transform: none;
  }
}

/* ================= floating popover ================= */

.family-popover {
  position:fixed;
  z-index:120;
  width:min(310px,calc(100vw - 24px));
  max-height:calc(100svh - 96px);
  overflow:auto;
  overscroll-behavior:contain;
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #FFFCF6;
  color: #2E2440;
  border: 1px solid rgba(var(--family-rgb, 46, 36, 64), 0.28);
  border-radius: 1rem;
  box-shadow: 0 18px 40px -20px rgba(46, 36, 64, 0.4);
  padding: 1rem 1.1rem 1.1rem;
}

.family-popover[hidden] {
  display: none;
}

.family-popover-close {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(var(--family-rgb, 46, 36, 64), 0.08);
  border: 1px solid rgba(var(--family-rgb, 46, 36, 64), 0.2);
  border-radius: 50%;
  color: #2E2440;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.family-popover-close:hover,
.family-popover-close:focus-visible {
  color: var(--family-ink, #773C0A);
  border-color: var(--family-color, #EF7D22);
  outline: none;
}
.family-popover-close:focus-visible {
  outline: 2px solid var(--family-ink, #773C0A);
  outline-offset: 2px;
}

.family-popover-emotion {
  margin: 0 2.2rem 0.3rem 0;
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--family-ink, #773C0A);
}

.family-popover h3#familyPopoverName {
  margin: 0 2.2rem 0.25rem 0;
  font-size: 1.15rem;
  color: #2E2440;
  overflow-wrap: break-word;
}

.family-popover-meta {
  margin: 0 0 0.6rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: #55496b;
}

.family-popover-trait,
.family-popover-bio {
  margin: 0 0 0.6rem;
  font-size: 0.88rem;
  line-height: 1.45;
  color: #2E2440;
}

.family-popover-profile {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0 1.05rem;
  border-radius: 999px;
  border: 1px solid var(--family-color, #EF7D22);
  background: #2E2440;
  color: #FFFCF6;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.85rem;
  cursor: pointer;
  transition: filter 0.15s ease;
}
.family-popover-profile:hover,
.family-popover-profile:focus-visible {
  filter: brightness(0.92);
  outline: none;
}
.family-popover-profile:focus-visible {
  outline: 2px solid var(--family-ink, #773C0A);
  outline-offset: 2px;
}

html[data-motion='reduced'] {
  .family-popover-close,
  .family-popover-profile {
    transition: none !important;
  }
}

/* ================= feelings route integration ================= */

body[data-route='feelings'] .page-content {
  padding-top: 100px;
}
@media (max-width: 640px) {
  body[data-route='feelings'] .page-content {
    padding-top: 88px;
  }
}

body[data-route='feelings'] .content-view {
  max-width: 1280px;
}

body[data-route='feelings'] .page-heading {
  margin-bottom: 1.25rem;
}
body[data-route='feelings'] .page-heading h1 {
  font-size: clamp(1.9rem, 3.4vw, 2.125rem);
}

#feelings.chapter {
  padding-top: 90px;
  padding-bottom: 70px;
}

#feelings .chapter-inner {
  max-width: 1280px;
}

#feelings .chapter-lede {
  margin-bottom: 1.25rem;
}

@media(hover:none) and (pointer:coarse) and (max-width:1099px){
 .family-columns {min-width:0}
 .emotion-family {padding:.6rem .45rem}
 .family-card {grid-template-columns:38px minmax(0,1fr);gap:2px 6px;padding:5px;min-height:66px}
 .family-card img {width:38px;height:38px}
 .family-card-name {font-size:.76rem}
 .family-card-level {font-size:.6rem;letter-spacing:.02em}
}
@media(hover:none) and (pointer:coarse) and (max-width:649px){
 .family-columns {grid-template-columns:repeat(2,minmax(0,1fr))}
 body[data-route='feelings'] .page-content,#feelings.chapter {padding-left:12px;padding-right:12px}
}
@media(hover:none) and (pointer:coarse) and (max-width:359px){
 .family-card {display:flex;flex-direction:column;gap:3px;text-align:center;min-height:108px}
 .family-card-name {align-self:stretch;min-height:28px}
 .family-card-level {align-self:center}
 .emotion-family-title {font-size:.76rem}
 body[data-route='feelings'] .header-right {display:none}
 body[data-route='feelings'] .header-center {left:auto;right:16px;transform:translateY(-50%)}
}

/* Cards remain hoverable while providing native profile links. */
a.family-card {color:inherit;text-decoration:none}
a.family-popover-profile {text-decoration:none}
