/* ------------------------------------------------------------
   Hero video player (app/static/js/hero-video.js)
   ------------------------------------------------------------
   The player itself, once, for every hero that carries the video: the
   overlay button, its icons and the states the script sets on the
   container. The FRAME around the video (border, radius, shadow, lane)
   is the host page's business: campaign.css draws the Handmarked ink
   frame, the course pages draw their editorial one. The host tunes the
   button through the custom properties below; the defaults are the
   course pages' palette.

   States (data-hv-state on the container):
     idle      nothing decided yet: the poster, no button
     loading   play requested, frames not flowing yet: the spinner disc
     playing   sound on: nothing over the video
     muted     autoplay without sound: the panel asks for a tap
     paused    tapped to pause: the play disc
     ended     finished: the replay disc
     blocked   the browser refused autoplay: the panel offers to play
   ------------------------------------------------------------ */
.hv {
  --hv-disc: #ffffff;
  --hv-disc-border: 0 solid transparent;
  --hv-disc-shadow: 0 18px 40px -12px rgba(23, 37, 84, 0.55);
  --hv-icon: #1d4ed8;
  --hv-panel-bg: rgba(29, 78, 216, 0.82);
  --hv-panel-rule: rgba(255, 255, 255, 0.85);
  --hv-panel-fg: #ffffff;
  --hv-panel-icon: #ffffff;
  --hv-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --hv-font-display: 'Lora', Georgia, 'Times New Roman', serif;
  --hv-scrim: rgba(12, 18, 36, 0.32);

  position: relative;
  overflow: hidden;
  cursor: pointer;
  /* iOS otherwise flashes its grey tap highlight over the whole video. */
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.hv video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #0c1224;
}

/* A quiet scrim behind the disc while the video is stopped, so it reads
   over a busy frame. Nothing while it plays, muted or not: the presenter's
   face is the point. The panel carries its own ground. */
.hv::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--hv-scrim);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}
.hv[data-hv-state="paused"]::after,
.hv[data-hv-state="ended"]::after {
  opacity: 1;
}

/* ---- the button ---------------------------------------------------- */
/* One <button>, two faces: the disc (paused, ended, loading) and the panel
   (muted, blocked). Neither shows while the video plays with sound, and
   nothing shows before the script has decided (idle): the poster alone. */
.hv__btn {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  -webkit-tap-highlight-color: transparent;
}
.hv[data-hv-state="paused"] .hv__btn,
.hv[data-hv-state="ended"] .hv__btn,
.hv[data-hv-state="loading"] .hv__btn,
.hv[data-hv-state="muted"] .hv__btn,
.hv[data-hv-state="blocked"] .hv__btn,
.hv__btn:focus-visible {
  opacity: 1;
  pointer-events: auto;
}

.hv__disc {
  display: none;
  place-items: center;
  width: clamp(84px, 24vw, 116px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--hv-disc);
  border: var(--hv-disc-border);
  box-shadow: var(--hv-disc-shadow);
  color: var(--hv-icon);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.hv[data-hv-state="paused"] .hv__disc,
.hv[data-hv-state="ended"] .hv__disc,
.hv[data-hv-state="loading"] .hv__disc,
.hv[data-hv-state="playing"] .hv__btn:focus-visible .hv__disc {
  display: grid;
}
.hv__btn:active .hv__disc {
  transform: scale(0.94);
}
.hv__btn:focus-visible .hv__disc {
  outline: 3px solid var(--hv-icon);
  outline-offset: 4px;
}

.hv__icon {
  display: none;
  width: 44%;
  height: 44%;
}
.hv__icon svg {
  display: block;
  width: 100%;
  height: 100%;
}
/* The play triangle sits optically left of centre in a circle; nudge it. */
.hv__icon--play { transform: translateX(6%); }

.hv[data-hv-state="paused"] .hv__icon--play,
.hv[data-hv-state="playing"] .hv__icon--play,
.hv[data-hv-state="ended"] .hv__icon--replay,
.hv[data-hv-state="loading"] .hv__icon--spin {
  display: block;
}

.hv__icon--spin svg {
  animation: hv-spin 0.9s linear infinite;
}
@keyframes hv-spin {
  to { transform: rotate(360deg); }
}

/* ---- the panel ----------------------------------------------------- */
/* The video is moving but silent, or would not start: a translucent card
   over the middle of the frame, the icon, one quiet line and one big one.
   Width follows the video so it reads the same at 374px and 416px. */
.hv__panel {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  width: 88%;
  padding: clamp(1.6rem, 7%, 2.4rem) clamp(1rem, 5%, 1.6rem);
  border: 2px solid var(--hv-panel-rule);
  border-radius: 16px;
  background: var(--hv-panel-bg);
  color: var(--hv-panel-fg);
  text-align: center;
  box-shadow: 0 24px 60px -18px rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.hv[data-hv-state="muted"] .hv__panel--muted,
.hv[data-hv-state="blocked"] .hv__panel--blocked {
  display: flex;
}
.hv__btn:active .hv__panel {
  transform: scale(0.985);
}

.hv__panel-icon {
  display: block;
  width: clamp(60px, 20%, 84px);
  aspect-ratio: 1;
  margin-bottom: 0.5rem;
  color: var(--hv-panel-icon);
}
.hv__panel-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

.hv__panel-kicker {
  display: block;
  font-family: var(--hv-font);
  font-size: clamp(0.9rem, 3.6vw, 1.05rem);
  font-weight: 500;
  line-height: 1.3;
  opacity: 0.85;
}

.hv__panel-line {
  display: block;
  font-family: var(--hv-font-display);
  font-size: clamp(1.5rem, 6.4vw, 2.05rem);
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

@media (prefers-reduced-motion: reduce) {
  .hv::after,
  .hv__btn,
  .hv__disc {
    transition: none;
  }
}
