/* Floating auto-play player — the always-on video window and the control
   toolbar that swings out above the page's own played-videos tray (#vstrip)
   when it is hovered. The script loads on every page (the session survives
   navigation), so these rules live in their own sheet; pages without a tray
   get a small round pad in the tray's spot as the hover handle. */

/* --- the window --------------------------------------------------------
   A fixed-position stage the user can park anywhere: grab mode unlocks it
   for dragging, locking fixes it in place, and hovering it fades it to half
   opacity *and* makes it click-through, so the page behind can be read and
   used while the clip keeps rolling. */
.fplayer {
  position: fixed; z-index: 80;
  width: min(340px, 92vw);
  border-radius: var(--r-md); overflow: hidden;
  background: #000;
  border: 1px solid var(--glass-border);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  transition: opacity .25s ease, border-color var(--t-fast);
  /* resting see-through level — the toolbar's transparency slider feeds
     these two custom properties (peek is the hover level) */
  opacity: var(--fp-rest, 1);
}
.fplayer video {
  display: block; width: 100%; height: auto;
  /* until metadata says otherwise; JS replaces this with the clip's real
     aspect so the window hugs the video exactly, like the PiP window */
  aspect-ratio: 16 / 9;
  object-fit: contain; background: #000;
}
.fplayer.peek { opacity: var(--fp-peek, .5); pointer-events: none; }
.fplayer.grab { cursor: grab; border-style: dashed; border-color: rgba(130, 64, 255, .65); }
.fplayer.grabbing { cursor: grabbing; }

/* the lock button exists only while grab mode is on: drag the window
   wherever it should live, then click here (or the toolbar's lock) to fix it */
.flock {
  position: absolute; top: 8px; right: 8px; z-index: 1;
  width: 34px; height: 34px; padding: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; background: rgba(0, 0, 0, .55); border: 1px solid rgba(255, 255, 255, .35);
  box-shadow: none;
}
.flock:hover { background: rgba(0, 0, 0, .8); transform: none; }
.flock.on { background: var(--brand-grad); border-color: transparent; }
.flock svg { width: 17px; height: 17px; }
.fgrabhint {
  position: absolute; left: 50%; bottom: 30px; z-index: 1;
  transform: translateX(-50%);
  font-size: 11px; font-weight: 600; color: #fff; white-space: nowrap;
  background: rgba(0, 0, 0, .65); border: 1px solid rgba(255, 255, 255, .25);
  border-radius: var(--r-pill); padding: 4px 12px;
  pointer-events: none;
}
.fprog { height: 3px; background: rgba(255, 255, 255, .14); }
.fprog i { display: block; height: 100%; width: 0; background: var(--brand-grad); }

/* minimized while the browser's Picture-in-Picture window holds the video:
   the element must stay mounted (it *is* the PiP source), so the window
   collapses to a slim "playing over all windows" strip instead */
.fplayer.mini video, .fplayer.mini .fprog,
.fplayer.mini .flock, .fplayer.mini .fgrabhint { display: none; }
.fmini { display: none; align-items: center; gap: 10px; padding: 10px 12px; font-size: 12px; color: var(--muted); }
.fplayer.mini .fmini { display: flex; }
.fmini > span:not(.fpulse) {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fmini button { flex: none; padding: 5px 12px; font-size: 12px; box-shadow: none; }
.fpulse {
  flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--ok);
  animation: fpulse 1.6s ease-out infinite;
}
@keyframes fpulse {
  0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, .5); }
  100% { box-shadow: 0 0 0 9px rgba(52, 211, 153, 0); }
}

/* --- the control toolbar -------------------------------------------------
   It is never inside the tray: it floats just above it (the JS pins it to
   the tray's measured height) and swings out — slide and fade — while the
   tray or the pad is hovered. */
.fbar {
  position: fixed; z-index: 82;
  left: 50%; bottom: 126px; transform: translate(-50%, 12px) scale(.96);
  display: flex; align-items: center; gap: 5px;
  padding: 7px 9px; border-radius: var(--r-pill);
  background: var(--glass-strong); border: 1px solid var(--glass-border);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .22s var(--t), transform .22s var(--t), visibility .22s, bottom .22s var(--t);
}
.fbar.show {
  opacity: 1; visibility: visible; pointer-events: auto;
  transform: translate(-50%, 0) scale(1);
}
.fbar button {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0; border-radius: 50%;
  background: transparent; color: var(--fg); box-shadow: none;
}
.fbar button:hover:not(:disabled) { background: var(--glass-strong); transform: none; }
.fbar button.on { background: var(--brand-grad); color: #fff; box-shadow: var(--brand-glow); }
.fbar button svg { width: 17px; height: 17px; }
.fsep { flex: none; width: 1px; height: 20px; background: var(--border); }
.fseekgrp { display: flex; align-items: center; gap: 5px; }
.fseek { flex: none; width: 150px; accent-color: var(--accent); }
.ftime {
  flex: none; font-size: 11px; color: var(--muted); white-space: nowrap;
  font-variant-numeric: tabular-nums; min-width: 74px; text-align: center;
}
.ftitle {
  flex: none; max-width: 170px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-size: 12px; color: var(--muted);
}

/* the default-transparency slider: an icon and a short range input */
.fop { display: flex; align-items: center; gap: 5px; color: var(--muted); }
.fop svg { width: 15px; height: 15px; flex: none; }
.fopacity { flex: none; width: 72px; accent-color: var(--accent); }

/* fallback handle where there is no tray to hover (gallery, character
   editor): a small round pad in the tray's spot */
.fpad {
  position: fixed; z-index: 82;
  left: 50%; bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: 44px; height: 44px; padding: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--fg);
  background: var(--glass-strong); border: 1px solid var(--glass-border);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.fpad:hover { background: var(--brand-grad); color: #fff; border-color: transparent; transform: translateX(-50%) translateY(-2px); }
.fpad svg { width: 20px; height: 20px; }

/* --- page interplay ----------------------------------------------------- */
/* the to-top button keeps clear of the tray + toolbar, the way it already
   does for the tray alone */
body.fplayer-open .toTop { bottom: calc(96px + env(safe-area-inset-bottom)); }

@media (max-width: 720px) {
  .ftitle, .fsep { display: none; }
  /* keep the mini strip readable on narrow screens: shorter label, tighter gaps */
  .fmini { gap: 8px; padding: 9px 10px; }
  .fmini button { padding: 6px 10px; }
  /* two rows: transport + settings on top, the seek line centered below */
  .fbar {
    flex-wrap: wrap; justify-content: center; row-gap: 3px;
    max-width: 94vw; padding: 8px; border-radius: var(--r-lg);
  }
  .fbar button { width: 31px; height: 31px; }
  .fseekgrp { order: 10; flex: 1 1 100%; justify-content: center; }
  .fseek { flex: 0 1 150px; width: auto; }
  .fopacity { width: 56px; }
}
@media (max-width: 380px) {
  .fbar button { width: 28px; height: 28px; }
  .fbar button svg { width: 15px; height: 15px; }
  .fopacity { width: 44px; }
  .fseek { flex-basis: 130px; }
}
@media (prefers-reduced-motion: reduce) {
  .fbar, .fplayer { transition: none; }
  .fpulse { animation: none; }
}
