/* ─────────────────────────────────────────────────────────────
   Voice Constellation — abstract star chart, never a map.
   Pure CSS animation. Respects prefers-reduced-motion.
   ───────────────────────────────────────────────────────────── */

.constellation-frame {
  position: relative;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  background:
    radial-gradient(circle at 50% 40%, rgba(200, 169, 110, 0.06), transparent 60%),
    #07060a;
  border: 1px solid rgba(200, 169, 110, 0.18);
  border-radius: 4px;
  overflow: hidden;
  aspect-ratio: 12 / 7;
}

.constellation-frame--small { aspect-ratio: 12 / 6; max-width: 720px; }

.constellation-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.constellation-frame::before,
.constellation-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 20% 30%, rgba(200, 169, 110, 0.04), transparent 30%),
              radial-gradient(circle at 80% 70%, rgba(200, 169, 110, 0.03), transparent 35%);
}

/* ─── Stars ──────────────────────────────────────────────── */

.star-link { cursor: pointer; }
.star-link:focus-visible .star__halo {
  filter: drop-shadow(0 0 6px rgba(200, 169, 110, 0.8));
}

.star {
  cursor: pointer;
  transform-box: fill-box;
  transform-origin: center;
}

.star__halo {
  animation: star-breathe 3.6s ease-in-out infinite;
  animation-delay: var(--pulse-offset, 0s);
  transform-box: fill-box;
  transform-origin: center;
}

.star__core {
  animation: star-twinkle 4.2s ease-in-out infinite;
  animation-delay: var(--pulse-offset, 0s);
}

@keyframes star-breathe {
  0%, 100% { opacity: 0.55; transform: scale(0.9); }
  50%      { opacity: 1;    transform: scale(1.35); }
}

@keyframes star-twinkle {
  0%, 100% { opacity: 0.7;  }
  50%      { opacity: 1;    }
}

/* New stars fade in (when re-rendered with new arrival) */
.star[data-new="true"] .star__halo { animation: star-arrive 2s ease-out; }
@keyframes star-arrive {
  from { opacity: 0; transform: scale(0); }
  to   { opacity: 1; transform: scale(1); }
}

/* Subtle per-language tinting (kept extremely faint) */
.star--nl .star__core { fill: #F0EAD6; }
.star--af .star__core { fill: #F4DCB6; }
.star--de .star__core { fill: #EFE4C0; }
.star--fy .star__core { fill: #F2DCBE; }
.star--en .star__core { fill: #F0EAD6; }

/* ─── Threads ────────────────────────────────────────────── */

.thread {
  stroke-dasharray: 6 4;
  stroke-dashoffset: 0;
  animation: thread-shimmer 6s linear infinite;
  animation-delay: var(--shimmer-offset, 0s);
  transition: opacity 220ms ease, stroke-width 220ms ease;
  opacity: 0.65;
}

@keyframes thread-shimmer {
  from { stroke-dashoffset: 0;   }
  to   { stroke-dashoffset: -40; }
}

.thread-link:hover .thread,
.thread-link:focus .thread {
  opacity: 1;
  stroke-width: 1.6;
  outline: none;
}

.thread-link { cursor: pointer; }

/* When you hover a star, fade out unrelated threads */
.constellation-svg[data-focused] .thread { opacity: 0.18; }
.constellation-svg[data-focused] .thread[data-related="true"] {
  opacity: 1;
  stroke-width: 1.6;
}
.constellation-svg[data-focused] .star { opacity: 0.35; }
.constellation-svg[data-focused] .star[data-related="true"] { opacity: 1; }

/* ─── Filter fading (CSS-side, toggled by JS data attrs) ────── */

.star,
.thread-link {
  transition: opacity 220ms ease;
}

/* When filtering is active, fade non-matching elements to near-invisible */
.constellation-svg[data-filtering] .star[data-filtered="hide"] {
  opacity: 0.08;
  pointer-events: none;
}
.constellation-svg[data-filtering] .thread-link[data-filtered="hide"] {
  opacity: 0.08;
  pointer-events: none;
}
/* Ensure matching items stay fully visible even if data-focused is also set */
.constellation-svg[data-filtering] .star[data-filtered="show"] {
  opacity: 1;
}
.constellation-svg[data-filtering] .thread-link[data-filtered="show"] .thread {
  opacity: 0.65;
}

/* ─── Empty state ────────────────────────────────────────── */

.constellation-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
}

.constellation-empty p {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 1.4rem;
  color: var(--muted, #A89578);
  max-width: 28ch;
  line-height: 1.5;
  margin: 0;
}

.constellation-empty .lone-star {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle, #F0EAD6 0%, #C8A96E 60%, transparent 100%);
  margin-right: 0.5rem;
  vertical-align: middle;
  animation: star-breathe 3.6s ease-in-out infinite;
}

/* ─── Reduced motion ─────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .star__halo,
  .star__core,
  .thread,
  .constellation-empty .lone-star {
    animation: none !important;
  }
  .star__halo { opacity: 0.85; }
  .thread     { opacity: 0.5;  }

  /* Instant filter transitions for reduced-motion users */
  .star,
  .thread-link,
  .star-preview {
    transition: none !important;
  }
}

/* ─── Dedicated /constellation page ──────────────────────── */

.constellation-page {
  max-width: 1200px;
  margin: 3rem auto 5rem;
  padding: 0 1.5rem;
}

.constellation-page__header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.constellation-page__kicker {
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.78rem;
  color: var(--accent, #C8A96E);
  margin: 0 0 0.75rem;
}

.constellation-page__title {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: clamp(2.5rem, 5vw, 4.25rem);
  line-height: 1.1;
  margin: 0 0 1rem;
}

.constellation-page__lead {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.2rem;
  color: var(--muted, #A89578);
  line-height: 1.55;
  max-width: 50ch;
  margin: 0 auto;
}

.constellation-page__stats {
  display: flex;
  gap: 2rem;
  justify-content: center;
  margin: 2rem 0 3rem;
  flex-wrap: wrap;
}

.constellation-page__stat {
  text-align: center;
}

.constellation-page__stat strong {
  display: block;
  font-family: 'Cormorant Garamond', serif;
  font-size: 2.5rem;
  font-style: italic;
  color: var(--accent, #C8A96E);
  line-height: 1;
  transition: color 220ms ease;
}

.constellation-page__stat span {
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  color: var(--muted, #A89578);
}

/* ─── Filter chips ───────────────────────────────────────── */

.con-filters {
  max-width: 1200px;
  margin: 0 auto 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.con-filters__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.con-filters__label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted, #A89578);
  min-width: 72px;
  margin-right: 0.25rem;
}

/* Chips — match /lexicon visual language */
.con-chip {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border-mid, rgba(200, 169, 110, 0.28));
  border-radius: 2px;
  background: transparent;
  color: var(--muted, #A89578);
  cursor: pointer;
  transition: border-color 150ms ease, color 150ms ease, background 150ms ease;
  line-height: 1;
}

.con-chip:hover {
  border-color: rgba(200, 169, 110, 0.6);
  color: var(--fg, #F0EAD6);
}

.con-chip--active,
.con-chip[aria-pressed="true"] {
  border-color: var(--accent, #C8A96E);
  color: var(--accent, #C8A96E);
}

/* ─── Live caption ───────────────────────────────────────── */

.con-caption {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 0.9rem;
  color: var(--muted, #A89578);
  text-align: center;
  margin: 0 auto 1rem;
  max-width: 1200px;
  min-height: 1.4em;
  transition: opacity 200ms ease;
}

/* ─── Inline preview card ────────────────────────────────── */

.star-preview {
  /* Folded-letter aesthetic: parchment, gold accent line, no shadow */
  position: fixed;
  z-index: 9000;
  width: 280px;
  background: #0e0c10;
  border: 1px solid rgba(200, 169, 110, 0.32);
  border-radius: 3px;
  padding: 1.1rem 1.2rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  /* Smooth appear */
  transition: opacity 180ms ease, transform 180ms ease;
}

/* Shown: remove [hidden] via JS, card animates in */
.star-preview:not([hidden]) {
  opacity: 1;
  transform: translateY(0);
}

/* Initial state for animation (set before JS removes hidden) */
.star-preview[hidden] {
  display: flex !important; /* override UA hidden; JS controls visibility via opacity */
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
}

/* Gold accent line at top — the "letter fold" detail */
.star-preview__accent-line {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(to right, transparent, #C8A96E 30%, #C8A96E 70%, transparent);
  border-radius: 3px 3px 0 0;
}

.star-preview__close {
  position: absolute;
  top: 0.45rem;
  right: 0.55rem;
  background: none;
  border: none;
  color: var(--muted, #A89578);
  font-size: 0.8rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.2rem 0.3rem;
  border-radius: 2px;
  transition: color 150ms ease;
}
.star-preview__close:hover { color: var(--fg, #F0EAD6); }

.star-preview__name {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 1.2rem;
  color: var(--fg, #F0EAD6);
  margin: 0;
  line-height: 1.2;
  padding-right: 1.4rem; /* avoid overlap with close btn */
}

.star-preview__meta {
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.66rem;
  color: var(--muted, #A89578);
  margin: 0;
}

.star-preview__question {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 0.88rem;
  color: var(--muted, #A89578);
  margin: 0;
  line-height: 1.4;
}

.star-preview__audio {
  width: 100%;
  height: 28px;
  filter: invert(0.85) hue-rotate(180deg) brightness(0.9);
  border-radius: 2px;
}

.star-preview__link {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent, #C8A96E);
  text-decoration: none;
  border-bottom: 1px solid rgba(200, 169, 110, 0.3);
  padding-bottom: 0.05rem;
  align-self: flex-start;
  transition: border-color 150ms ease;
}
.star-preview__link:hover {
  border-bottom-color: var(--accent, #C8A96E);
}

/* Mobile: card sits centred below the chart, full-width-ish */
.star-preview--mobile {
  position: fixed;
  left: 50% !important;
  bottom: 1.5rem !important;
  top: auto !important;
  transform: translateX(-50%) !important;
  width: min(92vw, 360px);
  max-height: 50vh;
  overflow-y: auto;
}

.star-preview--floating {
  /* position set by JS */
}

/* Legend — clearly a static key, not interactive */
.constellation-page__legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem 2rem;
  max-width: 720px;
  margin: 2.5rem auto 0;
  padding: 1.25rem 1.5rem;
  border: 1px dashed rgba(200, 169, 110, 0.18);
  border-radius: 4px;
  background: transparent;
  color: var(--muted, #A89578);
  user-select: none;
}

.constellation-page__legend dl {
  display: contents;
  margin: 0;
}

.constellation-page__legend-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.constellation-page__legend-glyph {
  flex: 0 0 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 14px;
}

.constellation-page__legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: radial-gradient(circle, #F0EAD6 0%, #C8A96E 70%, transparent 100%);
  box-shadow: 0 0 8px rgba(200, 169, 110, 0.7);
}

.constellation-page__legend-line {
  display: inline-block;
  width: 28px;
  height: 1px;
  background: linear-gradient(to right, transparent, #C8A96E, transparent);
}

.constellation-page__legend-cluster {
  width: 18px; height: 12px; border-radius: 50%;
  border: 1px solid rgba(200, 169, 110, 0.4);
}

.constellation-page__legend-text {
  flex: 1;
  color: var(--muted, #A89578);
  font-weight: 400;
}

/* ─── Mobile adjustments (≤800px) ───────────────────────── */

@media (max-width: 800px) {
  .con-filters__label {
    min-width: 60px;
    font-size: 0.62rem;
  }
  .con-chip {
    font-size: 0.64rem;
    padding: 0.28rem 0.55rem;
  }
  .con-caption {
    font-size: 0.82rem;
    padding: 0 0.5rem;
  }
  /* Preview card stacks below chart on mobile — handled by .star-preview--mobile */
}

/* ─── Reduced motion (extend for new transitions) ────────── */

@media (prefers-reduced-motion: reduce) {
  .star__halo,
  .star__core,
  .thread,
  .constellation-empty .lone-star {
    animation: none !important;
  }
  .star__halo  { opacity: 0.85; }
  .thread      { opacity: 0.5;  }
  .star,
  .thread-link,
  .star-preview,
  .constellation-page__stat strong,
  .con-chip {
    transition: none !important;
  }
}
