/*
 * Threebird Music Widget — player styles
 *
 * Everything themable is a custom property with a fallback, so it can be
 * set at three levels and the nearest one wins:
 *   :root                  the plugin's settings page (site-wide)
 *   {{WRAPPER}} .tbmw      an Elementor widget's Style tab
 *   your theme's CSS       anything else
 *
 *   --tbmw-bg / --tbmw-bg-hover   background
 *   --tbmw-fg                     icons and text
 *   --tbmw-accent                 progress bar, focus ring, play button tint
 *   --tbmw-border                 border colour (default: fg at 22%)
 *   --tbmw-size                   button size
 *   --tbmw-radius                 corner radius
 *   --tbmw-offset-x / -y          floating distance from the corner
 *   --tbmw-z                      floating stacking order
 *
 * Buttons are reset hard, at higher specificity than a theme's `button`
 * rules: themes like Neuros give every button padding, a background,
 * min-height and uppercase text, which would blow the controls apart.
 */

.tbmw-mount {
  /* Reserve the height so the page does not jump when the player renders. */
  min-height: calc(var(--tbmw-size, 32px) + 12px);
}

.tbmw {
  --_size: var(--tbmw-size, 32px);
  --_fg: var(--tbmw-fg, #fff);
  --_accent: var(--tbmw-accent, var(--_fg));

  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  max-width: 100%;
  margin: 0;
  padding: 4px;
  border: 1px solid var(--tbmw-border, color-mix(in srgb, var(--_fg) 22%, transparent));
  border-radius: var(--tbmw-radius, 999px);
  background: var(--tbmw-bg, rgba(0, 0, 0, .55));
  color: var(--_fg);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font: 500 12px/1.25 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  letter-spacing: normal;
  text-align: left;
  text-transform: none;
  vertical-align: middle;
  transition: opacity .2s ease, background-color .2s ease;
}

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

/* ---- floating ---------------------------------------------------- */

.tbmw--floating {
  position: fixed;
  z-index: var(--tbmw-z, 2147483001);
  max-width: calc(100vw - 2 * var(--tbmw-offset-x, 16px));
  opacity: .75;
  /* transform: player.js slides it clear of other pinned buttons. */
  transition: opacity .2s ease, background-color .2s ease, transform .25s ease;
}

@media (prefers-reduced-motion: reduce) {
  .tbmw--floating { transition: opacity .2s ease, background-color .2s ease; }
}

.tbmw--floating:hover,
.tbmw--floating.is-open,
.tbmw--floating:focus-within {
  opacity: 1;
  background: var(--tbmw-bg-hover, rgba(0, 0, 0, .72));
}

.tbmw--bottom-right { right: calc(var(--tbmw-offset-x, 16px) + env(safe-area-inset-right, 0px)); bottom: calc(var(--tbmw-offset-y, 16px) + env(safe-area-inset-bottom, 0px)); }
.tbmw--bottom-left  { left:  calc(var(--tbmw-offset-x, 16px) + env(safe-area-inset-left, 0px));  bottom: calc(var(--tbmw-offset-y, 16px) + env(safe-area-inset-bottom, 0px)); }
.tbmw--top-right    { right: calc(var(--tbmw-offset-x, 16px) + env(safe-area-inset-right, 0px)); top:    calc(var(--tbmw-offset-y, 16px) + env(safe-area-inset-top, 0px)); }
.tbmw--top-left     { left:  calc(var(--tbmw-offset-x, 16px) + env(safe-area-inset-left, 0px));  top:    calc(var(--tbmw-offset-y, 16px) + env(safe-area-inset-top, 0px)); }

/* Left-anchored: open toward the page, so the main button stays put. */
.tbmw--bottom-left.tbmw--compact,
.tbmw--top-left.tbmw--compact { flex-direction: row; }
.tbmw--bottom-right.tbmw--compact,
.tbmw--top-right.tbmw--compact { flex-direction: row-reverse; }
/* ...and on the right, the title moves to the far side so the controls
   still read prev, next, play. */
.tbmw--bottom-right .tbmw-panel .tbmw-meta,
.tbmw--top-right .tbmw-panel .tbmw-meta { order: -1; padding: 0 6px 0 12px; text-align: right; }

@media (max-width: 767px) {
  .tbmw--hide-mobile { display: none !important; }
}

/* ---- buttons ----------------------------------------------------- */

.tbmw .tbmw-btn {
  -webkit-appearance: none;
  appearance: none;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--_size);
  height: var(--_size);
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: min(50%, var(--tbmw-radius, 999px));
  background: transparent;
  box-shadow: none;
  color: inherit;
  font: inherit;
  line-height: 0;
  letter-spacing: 0;
  text-transform: none;
  text-shadow: none;
  cursor: pointer;
  transition: background-color .15s ease, transform .15s ease;
}

.tbmw .tbmw-btn:hover,
.tbmw .tbmw-btn:focus {
  background: color-mix(in srgb, var(--_fg) 14%, transparent);
  color: inherit;
  border: 0;
  box-shadow: none;
  outline: none;
}

.tbmw .tbmw-btn:focus-visible {
  outline: 2px solid var(--_accent);
  outline-offset: -2px;
}

.tbmw .tbmw-btn svg {
  display: block;
  width: calc(var(--_size) * .56);
  height: calc(var(--_size) * .56);
  fill: currentColor;
  pointer-events: none;
}

/* Play/pause is the primary action: bigger, and tinted. */
.tbmw .tbmw-main {
  width: calc(var(--_size) + 4px);
  height: calc(var(--_size) + 4px);
  background: color-mix(in srgb, var(--_accent) 16%, transparent);
}

.tbmw .tbmw-main:hover,
.tbmw .tbmw-main:focus {
  background: color-mix(in srgb, var(--_accent) 26%, transparent);
}

.tbmw .tbmw-prev,
.tbmw .tbmw-next { opacity: .85; }
.tbmw .tbmw-prev:hover,
.tbmw .tbmw-next:hover { opacity: 1; }

/* ---- title and progress ------------------------------------------ */

.tbmw-meta {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  padding: 0 12px 0 6px;
}

.tbmw-title {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  opacity: .9;
}

.tbmw--full .tbmw-meta { min-width: 120px; }
.tbmw--compact .tbmw-title { max-width: 42vw; }

.tbmw-progress {
  position: relative;
  height: 3px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--_fg) 20%, transparent);
  cursor: pointer;
}

/* A 3px bar is too thin to hit; widen the target, not the bar. */
.tbmw-progress::before {
  content: "";
  position: absolute;
  inset: -7px 0;
}

.tbmw-progress-bar {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0;
  border-radius: inherit;
  background: var(--_accent);
  transition: width .25s linear;
}

/* ---- compact: a button that opens into a pill -------------------- */

/* Width animates rather than display, so it can transition and the
   controls stay in tab order; visibility takes the closed panel out of
   the accessibility tree without breaking the transition. */
.tbmw-panel {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  max-width: 0;
  overflow: hidden;
  visibility: hidden;
  transition: max-width .28s ease, visibility 0s linear .28s;
}

.tbmw.is-open .tbmw-panel {
  max-width: min(70vw, 440px);
  visibility: visible;
  transition: max-width .28s ease, visibility 0s;
}

/* Idle: nothing has played yet. The button is an invitation, so it
   breathes gently instead of sitting there looking like a mute button. */
.tbmw--floating.is-idle { opacity: .6; }
.tbmw--floating.is-idle:hover { opacity: 1; }
.tbmw--floating.is-idle .tbmw-main { animation: tbmw-breathe 2.6s ease-in-out infinite; }

@keyframes tbmw-breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.1); }
}

/* Equalizer bars on the collapsed button while music plays. */
.tbmw-eq rect {
  transform-box: fill-box;
  transform-origin: center bottom;
  animation: tbmw-eq 1.1s ease-in-out infinite;
}
.tbmw-eq rect:nth-child(2) { animation-delay: -.45s; }
.tbmw-eq rect:nth-child(3) { animation-delay: -.8s; }

@keyframes tbmw-eq {
  0%, 100% { transform: scaleY(.35); }
  50%      { transform: scaleY(1); }
}

@media (prefers-reduced-motion: reduce) {
  .tbmw,
  .tbmw-panel,
  .tbmw-progress-bar,
  .tbmw .tbmw-btn { transition: none; }
  .tbmw--floating.is-idle .tbmw-main,
  .tbmw-eq rect { animation: none; }
  .tbmw-eq rect { transform: scaleY(.7); }
}
