/* Creative Provenance Indicator (CPI) — v1.0
   Load once per page alongside cpi.js.
   Set --cpi-lyrics-human and --cpi-music-human to change the two base colors.
   Derived AI shades are intentionally darker, as in the approved design.
*/

:root {
  --cpi-lyrics-human: #f92f97;
  --cpi-music-human: #65AEF2;
}

.cpi, .cpi *, .cpi *::before, .cpi *::after,
.cpi-popover, .cpi-popover *, .cpi-popover *::before, .cpi-popover *::after {
  box-sizing: border-box;
}

.cpi {
  display: inline-flex;
  position: relative;
  vertical-align: -.30em;
  flex: 0 0 auto;
  --cpi-diameter: 37px;
  --cpi-thickness: 6.5px;
  --cpi-glyph-size: 11px;
  --cpi-lyrics-ai: color-mix(in srgb, var(--cpi-lyrics-human) 57%, #10171e);
  --cpi-music-ai: color-mix(in srgb, var(--cpi-music-human) 57%, #10171e);
}

.cpi[data-size="sm"], .cpi[data-size="small"] {
  --cpi-diameter: 23px;
  --cpi-thickness: 4.5px;
  --cpi-glyph-size: 8px;
}

.cpi[data-size="lg"], .cpi[data-size="large"] {
  --cpi-diameter: 64px;
  --cpi-thickness: 10.5px;
  --cpi-glyph-size: 18px;
}

.cpi .cpi-trigger {
  appearance: none;
  width: var(--cpi-diameter);
  height: var(--cpi-diameter);
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--cpi-icon-color, currentColor);
  display: grid;
  place-items: center;
  position: relative;
  cursor: pointer;
  font: inherit;
  line-height: 1;
  touch-action: manipulation;
}

.cpi .cpi-trigger:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 3px;
}

.cpi .cpi-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--cpi-ring);
  transform: rotate(var(--cpi-orientation, 0deg));
  transition: transform .75s cubic-bezier(.2,.85,.2,1), filter .25s ease;
  /* Truly hollow center: works over images or any page background. */
  -webkit-mask: radial-gradient(farthest-side,
    transparent calc(100% - var(--cpi-thickness) - .3px),
    #000 calc(100% - var(--cpi-thickness) + .3px));
  mask: radial-gradient(farthest-side,
    transparent calc(100% - var(--cpi-thickness) - .3px),
    #000 calc(100% - var(--cpi-thickness) + .3px));
}

.cpi .cpi-trigger:hover .cpi-ring,
.cpi .cpi-trigger[aria-expanded="true"] .cpi-ring {
  transform: rotate(var(--cpi-orientation, 0deg)) scale(1.045);
}

.cpi .cpi-glyph {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  color: inherit;
  pointer-events: none;
}

.cpi .cpi-glyph svg {
  display: block;
  width: calc(var(--cpi-glyph-size) * 1.18);
  height: calc(var(--cpi-glyph-size) * 1.18);
  fill: currentColor;
}

.cpi .cpi-glyph i {
  display: block;
  font-size: calc(var(--cpi-glyph-size) * 1.05);
  line-height: 1;
}

.cpi .cpi-glyph [hidden] { display: none !important; }

/* The popup is appended to <body> and kept separate from host page styles. */
.cpi-popover {
  --cpi-lyrics-ai: color-mix(in srgb, var(--cpi-lyrics-human) 57%, #10171e);
  --cpi-music-ai: color-mix(in srgb, var(--cpi-music-human) 57%, #10171e);
  --cpi-pop-bg: #ffffff;
  --cpi-pop-ink: #20201f;
  --cpi-pop-muted: #686864;
  --cpi-pop-line: #dfded8;
  --cpi-pop-soft: #eeede9;
  --cpi-pop-shadow: 0 16px 48px rgba(22,22,20,.17);

  position: fixed;
  z-index: 2147483000;
  width: min(376px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 20px 17px;
  border: 1px solid var(--cpi-pop-line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--cpi-pop-bg) 90%, transparent);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  color: var(--cpi-pop-ink);
  box-shadow: var(--cpi-pop-shadow);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.48;
  text-align: left;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity .18s, visibility .18s, transform .18s;
}

@media (prefers-color-scheme: dark) {
  .cpi-popover:not([data-theme="light"]) {
    --cpi-pop-bg: #1d1e1d;
    --cpi-pop-ink: #f4f2ee;
    --cpi-pop-muted: #aaa9a4;
    --cpi-pop-line: #41423f;
    --cpi-pop-soft: #282927;
    --cpi-pop-shadow: 0 20px 54px rgba(0,0,0,.45);
  }
}

.cpi-popover[data-theme="dark"] {
  --cpi-pop-bg: #1d1e1d;
  --cpi-pop-ink: #f4f2ee;
  --cpi-pop-muted: #aaa9a4;
  --cpi-pop-line: #41423f;
  --cpi-pop-soft: #282927;
  --cpi-pop-shadow: 0 20px 54px rgba(0,0,0,.45);
}

.cpi-popover[data-theme="light"] {
  --cpi-pop-bg: #ffffff;
  --cpi-pop-ink: #20201f;
  --cpi-pop-muted: #686864;
  --cpi-pop-line: #dfded8;
  --cpi-pop-soft: #eeede9;
  --cpi-pop-shadow: 0 16px 48px rgba(22,22,20,.17);
}

.cpi-popover.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

.cpi-popover .pop-kicker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.cpi-popover .pop-head {
  font-size: 9px;
  letter-spacing: .13em;
  font-weight: 790;
  text-transform: uppercase;
  color: var(--cpi-pop-muted);
}
.cpi-popover .pop-status {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .025em;
  color: var(--cpi-pop-ink);
}
.cpi-popover .pop-status::before {
  content: "✓";
  display: inline-block;
  margin-right: 5px;
  font-weight: 800;
}
.cpi-popover .pop-title {
  margin: 5px 0 12px;
  font-size: 19px;
  line-height: 1.25;
  font-weight: 780;
  letter-spacing: -.04em;
}
.cpi-popover .pop-title a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--cpi-pop-line);
}
.cpi-popover .pop-title a:hover,
.cpi-popover .pop-title a:focus-visible {
  border-bottom-color: currentColor;
}
.cpi-popover .pop-hero {
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  gap: 15px;
  align-items: center;
  padding: 3px 0 14px;
}
.cpi-popover .pop-pie {
  display: block;
  width: 110px;
  height: 110px;
  overflow: visible;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.06));
}
.cpi-popover .pop-numbers { min-width: 0; }
.cpi-popover .pop-est {
  font-size: 35px;
  line-height: 1.07;
  font-weight: 790;
  letter-spacing: -.065em;
  font-variant-numeric: tabular-nums;
}
.cpi-popover .pop-est small {
  display: block;
  margin: 5px 0 12px;
  font-size: 11px;
  font-weight: 550;
  color: var(--cpi-pop-muted);
  letter-spacing: 0;
}
.cpi-popover .pop-ai-est {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 19px;
  line-height: 1;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}
.cpi-popover .pop-ai-est span {
  font-size: 11px;
  font-weight: 500;
  color: var(--cpi-pop-muted);
}
.cpi-popover .pop-overall {
  border-top: 1px solid var(--cpi-pop-line);
  padding-top: 12px;
}
.cpi-popover .pop-line-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 10px;
  font-weight: 760;
}
.cpi-popover .pop-line-head span:last-child {
  font-weight: 550;
  color: var(--cpi-pop-muted);
}
.cpi-popover .pop-stack {
  display: flex;
  position: relative;
  width: 100%;
  height: 11px;
  overflow: hidden;
  border-radius: 6px;
  background: var(--cpi-pop-soft);
}
.cpi-popover .pop-stack::after {
  content: "";
  position: absolute;
  z-index: 1;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1.5px;
  transform: translateX(-50%);
  background: var(--cpi-pop-bg);
  pointer-events: none;
}
.cpi-popover .pop-stack .piece {
  flex: 0 0 auto;
  min-width: 0;
  width: 0;
  height: 100%;
}
.cpi-popover .pop-stack .piece + .piece {
  box-shadow: inset 1px 0 0 var(--cpi-pop-bg);
}
.cpi-popover .lyrics-human { background: var(--cpi-lyrics-human); }
.cpi-popover .lyrics-ai { background: var(--cpi-lyrics-ai); }
.cpi-popover .music-human { background: var(--cpi-music-human); }
.cpi-popover .music-ai { background: var(--cpi-music-ai); }
.cpi-popover .pop-total-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 7px;
  color: var(--cpi-pop-muted);
  font-size: 10px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
.cpi-popover .pop-total-row span:last-child { text-align: right; }
.cpi-popover .pop-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 9px;
  margin: 12px 0 15px;
  font-size: 10px;
  color: var(--cpi-pop-muted);
}
.cpi-popover .pop-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.cpi-popover .pop-legend-dot {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.cpi-popover .pop-details {
  border-top: 1px solid var(--cpi-pop-line);
  padding-top: 4px;
}
.cpi-popover .pop-section { margin-top: 11px; }
.cpi-popover .pop-section-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 750;
}
.cpi-popover .pop-section-title small {
  font-size: 10px;
  font-weight: 450;
  color: var(--cpi-pop-muted);
}
.cpi-popover .pop-bar {
  display: flex;
  width: 100%;
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--cpi-pop-soft);
}
.cpi-popover .pop-bar .human,
.cpi-popover .pop-bar .ai {
  flex: 0 0 auto;
  width: 0;
  height: 100%;
}
.cpi-popover .pop-section[data-source="lyrics"] .pop-bar .human { background: var(--cpi-lyrics-human); }
.cpi-popover .pop-section[data-source="lyrics"] .pop-bar .ai { background: var(--cpi-lyrics-ai); }
.cpi-popover .pop-section[data-source="music"] .pop-bar .human { background: var(--cpi-music-human); }
.cpi-popover .pop-section[data-source="music"] .pop-bar .ai { background: var(--cpi-music-ai); }
.cpi-popover .pop-row {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  color: var(--cpi-pop-muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 420px) {
  .cpi-popover { padding: 16px 16px 15px; }
  .cpi-popover .pop-hero { grid-template-columns: 100px minmax(0,1fr); gap: 10px; }
  .cpi-popover .pop-pie { width: 96px; height: 96px; }
  .cpi-popover .pop-est { font-size: 31px; }
  .cpi-popover .pop-line-head { font-size: 9px; }
}
@media (prefers-reduced-motion: reduce) {
  .cpi .cpi-ring,
  .cpi-popover { transition-duration: .01ms; }
}
