/* ============================================================================
   PHC 2026 — shared in-text reference engine (styling).

   Companion to phc-refs.js. Works on every /phc2026/ page regardless of which
   page CSS is present: every visual token falls back to a sensible default and,
   where the page already defines its own palette (--phc-cyan, --phc-tip-bg, …),
   inherits it so the card matches the page chrome.

   Three pieces:
     • .phc-ref-cite        — an in-text citation (cyan underline, hover/clickable)
     • #phc-ref-card    — the floating "full reference" card shown on hover
     • .phc-ref-back    — the inline return arrow injected into each reference
                          entry, revealed after a citation is clicked
   ========================================================================== */

:root {
  /* Dark defaults — most /phc2026/ pages are dark. Light override below. */
  --phcref-accent: var(--phc-cyan, #57b6ec);
  --phcref-card-bg: var(--phc-tip-bg, rgba(16, 18, 24, 0.97));
  --phcref-card-bd: var(--phc-tip-border, rgba(255, 255, 255, 0.14));
  --phcref-text: var(--phc-text, #f0f1f3);
  --phcref-dim: var(--phc-text-dim, rgba(240, 241, 243, 0.66));
  --phcref-ease: var(--phc-ease, cubic-bezier(0.22, 1, 0.36, 1));
}
html[data-theme="light"],
html[data-reading-scheme="light"],
html[data-reading-scheme="sepia"] {
  --phcref-accent: var(--phc-cyan, #1f7fc0);
  --phcref-card-bg: var(--phc-tip-bg, rgba(255, 255, 255, 0.98));
  --phcref-card-bd: var(--phc-tip-border, rgba(10, 22, 38, 0.14));
  --phcref-text: var(--phc-text, #14181f);
  --phcref-dim: var(--phc-text-dim, rgba(20, 24, 31, 0.66));
}

/* ── In-text citation ─────────────────────────────────────────────────────
   Mirrors the existing .fj-cite look so already-styled pages stay identical. */
.phc-ref-cite {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--phcref-accent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 2px;
  text-decoration-skip-ink: none;
  cursor: pointer;
  transition: color 0.15s var(--phcref-ease);
}
.phc-ref-cite:hover,
.phc-ref-cite[aria-expanded="true"] { color: var(--phcref-accent); }
.phc-ref-cite:focus-visible {
  outline: 2px solid var(--phcref-accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Brief pulse when the reader is sent *back* to a citation via the arrow. */
.phc-ref-cite-flash {
  border-radius: 3px;
  animation: phcref-cite-flash 1.6s var(--phcref-ease);
}
@keyframes phcref-cite-flash {
  0%, 38% {
    background: color-mix(in srgb, var(--phcref-accent) 30%, transparent);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--phcref-accent) 26%, transparent);
  }
  100% { background: transparent; box-shadow: 0 0 0 4px transparent; }
}

/* ── Floating "full reference" card (hover) ──────────────────────────────── */
#phc-ref-card {
  position: fixed;
  z-index: 2147483000; /* above page chrome + reading panel */
  max-width: 380px;
  width: max-content;
  padding: 13px 15px 14px;
  border-radius: 12px;
  background: var(--phcref-card-bg);
  border: 1px solid var(--phcref-card-bd);
  color: var(--phcref-text);
  font-size: 0.84rem;
  line-height: 1.5;
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--phcref-accent) 10%, transparent),
    0 18px 50px -12px rgba(0, 0, 0, 0.6),
    0 0 34px -8px color-mix(in srgb, var(--phcref-accent) 22%, transparent);
  backdrop-filter: blur(14px) saturate(1.1);
  -webkit-backdrop-filter: blur(14px) saturate(1.1);
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity 0.16s var(--phcref-ease), transform 0.16s var(--phcref-ease);
}
#phc-ref-card.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
#phc-ref-card .phc-ref-card-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 7px;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--phcref-accent);
}
#phc-ref-card .phc-ref-card-label svg {
  width: 13px; height: 13px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
#phc-ref-card .phc-ref-card-body { color: var(--phcref-text); }
#phc-ref-card .phc-ref-card-body em { font-style: italic; }
#phc-ref-card .phc-ref-card-body a {
  color: var(--phcref-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
#phc-ref-card .phc-ref-card-hint {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px solid var(--phcref-card-bd);
  font-size: 0.7rem;
  color: var(--phcref-dim);
}
#phc-ref-card .phc-ref-card-hint svg {
  width: 12px; height: 12px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
/* Hide the injected return-arrow if a reference entry is cloned into the card. */
#phc-ref-card .phc-ref-back { display: none !important; }

/* ── Reference entry: jump target + flash ────────────────────────────────── */
.phc-ref-entry {
  scroll-margin-top: 96px;
  scroll-margin-bottom: 24px;
  border-radius: 7px;
  transition: background 0.6s var(--phcref-ease), box-shadow 0.6s var(--phcref-ease);
}
.phc-ref-entry.phc-ref-flash {
  background: color-mix(in srgb, var(--phcref-accent) 16%, transparent);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--phcref-accent) 16%, transparent);
}

/* ── Inline return arrow inside a reference entry ────────────────────────── */
.phc-ref-back {
  appearance: none;
  -webkit-appearance: none;
  display: none; /* revealed via .is-active once a citation has been clicked */
  align-items: center;
  gap: 5px;
  margin-left: 8px;
  padding: 2px 9px 2px 7px;
  vertical-align: middle;
  border: 1px solid color-mix(in srgb, var(--phcref-accent) 45%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--phcref-accent) 12%, transparent);
  color: var(--phcref-accent);
  font: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.01em;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.18s var(--phcref-ease), transform 0.18s var(--phcref-ease);
}
.phc-ref-back.is-active { display: inline-flex; }
.phc-ref-back:hover {
  background: color-mix(in srgb, var(--phcref-accent) 24%, transparent);
  transform: translateX(-1px);
}
.phc-ref-back:focus-visible {
  outline: 2px solid var(--phcref-accent);
  outline-offset: 2px;
}
.phc-ref-back svg {
  width: 13px; height: 13px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.phc-ref-back .phc-ref-back-label { display: inline; }

@media (max-width: 560px) {
  #phc-ref-card { max-width: min(86vw, 380px); font-size: 0.82rem; }
  .phc-ref-back .phc-ref-back-label { display: none; } /* arrow-only on phones */
  .phc-ref-back { padding: 3px 7px; }
}

@media (prefers-reduced-motion: reduce) {
  .phc-ref-cite, #phc-ref-card, .phc-ref-entry, .phc-ref-back { transition: none; }
  .phc-ref-cite-flash { animation: none; background: color-mix(in srgb, var(--phcref-accent) 22%, transparent); }
}
