/* T7 — Player controls, src/studio/player/.

   Two views of the same controls:
   - the mixer transport (.pl-transport) at the foot of the mixer card:
     stop · previous · play · next · time | saved loops | master volume;
   - the compact player bar (.pl-mini) under the centre when the mixer is
     off: previous · play · next · time · progress · total · loop · volume.
   The progress bar is coloured by section (--st-sect-* through --sect);
   positions are fractions of the song in --from, --to, --at and --played.
   The loop is --st-loop everywhere. */

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

.pl-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--st-text-dim);
  cursor: pointer;
}
.pl-btn .st-icon { width: 16px; height: 16px; }
.pl-btn:hover { background: var(--st-surface-2); color: var(--st-text); }
.pl-btn:focus-visible { outline: 2px solid var(--st-accent); outline-offset: 2px; }

.pl-btn--stop {
  outline: 1px solid var(--st-line);
  outline-offset: -0.5px;
  background: var(--st-surface-2);
}
.pl-btn--stop .st-icon { width: 13px; height: 13px; }
.pl-btn--mini { width: 34px; height: 34px; }

.pl-play,
.pl-play:hover { background: var(--st-text-strong); color: var(--st-bg); }
.pl-play--lg { width: 46px; height: 46px; box-shadow: 0 6px 18px color-mix(in srgb, var(--st-text-strong) 15%, transparent); }
.pl-play--lg .st-icon { width: 18px; height: 18px; }
.pl-play--md { width: 44px; height: 44px; }
.pl-play--md .st-icon { width: 17px; height: 17px; }
.pl-play .st-icon path { fill: none; }
.pl-play[aria-label='Play'] .st-icon path { fill: currentColor; }

.pl-divider { flex: none; width: 1px; height: 24px; background: var(--st-line); }

/* ---- Master volume --------------------------------------------------------------- */

.pl-volume { flex: none; display: flex; align-items: center; gap: 10px; }
.pl-volume--mini { gap: 8px; }
.pl-volume__speaker {
  display: grid;
  place-items: center;
  /* A 24px target drawn in the design's 16px spot. */
  width: 24px;
  height: 24px;
  margin: -4px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--st-text-dim);
  cursor: pointer;
}
.pl-volume__speaker:hover { color: var(--st-text); }
.pl-volume__speaker:focus-visible { outline: 2px solid var(--st-accent); outline-offset: -2px; border-radius: 6px; }
.pl-volume__speaker .st-icon { width: 16px; height: 16px; }

.pl-volume__slider {
  --fill: 80%;
  width: 84px;
  /* A 24px target drawn in the design's 12px row. */
  height: 24px;
  margin: -6px 0;
  background: none;
  cursor: pointer;
  appearance: none;
}
.pl-volume__slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--st-text) var(--fill), var(--st-line-strong) var(--fill));
}
.pl-volume__slider::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--st-text) var(--fill), var(--st-line-strong) var(--fill));
}
.pl-volume__slider::-webkit-slider-thumb {
  width: 12px;
  height: 12px;
  margin-top: -4px;
  border: 0;
  border-radius: 6px;
  background: var(--st-text-strong);
  appearance: none;
}
.pl-volume__slider::-moz-range-thumb { width: 12px; height: 12px; border: 0; border-radius: 6px; background: var(--st-text-strong); }
.pl-volume__slider:focus-visible { outline: 2px solid var(--st-accent); outline-offset: 3px; border-radius: 4px; }

/* ---- Loop chips ------------------------------------------------------------------- */

.pl-chip {
  flex: none;
  display: flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  outline: 1px solid var(--st-line);
  outline-offset: -0.5px;
  background: var(--st-panel);
  color: var(--st-text);
  white-space: nowrap;
  cursor: pointer;
}
.pl-chip:hover { background: var(--st-surface-2); }
/* After the active and dashed styles below, so they never recolour the ring. */
.pl-chip__name { min-width: 0; max-width: 140px; overflow: hidden; font: 500 12px/normal var(--st-font); text-overflow: ellipsis; white-space: nowrap; }
.pl-chip__range { color: var(--st-text-faint); font: 400 10.5px/normal var(--st-font-mono); }
.pl-chip__dot { flex: none; width: 6px; height: 6px; border-radius: 3px; background: var(--dot, var(--st-text-faint)); }
.pl-chip__icon { width: 12px; height: 12px; color: var(--st-loop-ink); }

.pl-chip[data-active='true'] {
  outline-color: color-mix(in srgb, var(--st-loop) 50%, transparent);
  background: color-mix(in srgb, var(--st-loop) 12%, transparent);
}
.pl-chip[data-active='true']:hover { background: color-mix(in srgb, var(--st-loop) 18%, transparent); }
.pl-chip[data-active='true'] .pl-chip__name { color: color-mix(in srgb, var(--st-loop) 25%, var(--st-text-strong)); }
.pl-chip[data-active='true'] .pl-chip__range { color: var(--st-loop-ink); }
/* Selected but not looping: still the active loop, drawn quieter. */
.pl-chip[data-active='true'][aria-pressed='false'] { outline-style: dashed; }
.pl-chip--mini { height: 32px; }
/* The chips row clips its overflow, so the ring is drawn inside the chip. */
.pl-chip { --st-focus-offset: -2px; }
.pl-chip:focus-visible,
.pl-chip[data-active='true']:focus-visible { outline: 2px solid var(--st-accent); outline-offset: var(--st-focus-offset); }
.pl-chip[hidden] { display: none; }

/* ---- Mixer transport ------------------------------------------------------------ */

.mixer > [data-slot='transport'] { flex: none; }

.pl-transport {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 55.5px;
  margin-top: -0.5px;
  padding: 0 4px;
  border-top: 1px solid var(--st-line);
}

.pl-time { flex: none; display: flex; align-items: flex-end; gap: 6px; padding: 0 2px; }
.pl-time__now { color: var(--st-text); font: 600 20px/normal var(--st-font-mono); }
.pl-time__total { color: var(--st-text-faint); font: 400 14px/normal var(--st-font-mono); padding-bottom: 1px; }

.pl-loops { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; padding: 0 4px; }
/* Whole chips only: loops.ts hides the ones that don't fit and counts them in "+N". */
.pl-loops__chips { flex: 0 1 auto; display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; }
.pl-loops:focus { outline: none; }
.pl-loops:focus-visible { outline: 2px solid var(--st-accent); outline-offset: 2px; border-radius: 8px; }
.pl-loops__more-wrap { position: relative; flex: none; }
.pl-loops__more {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  outline: 1px solid var(--st-line);
  outline-offset: -0.5px;
  background: none;
  color: var(--st-text-dim);
  cursor: pointer;
}
.pl-loops__more:hover { background: var(--st-surface-2); }
.pl-loops__more:focus-visible { outline: 2px solid var(--st-accent); outline-offset: 1px; }
.pl-loops__more .st-icon { width: 12px; height: 12px; }
.pl-loops__more[hidden] { display: none; }
.pl-loops__count { font: 400 11px/normal var(--st-font-mono); }

.pl-loops__menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  z-index: 40;
  width: max-content;
  min-width: 260px;
  padding: 8px;
  border-radius: 12px;
  outline: 1px solid var(--st-line-strong);
  outline-offset: -0.5px;
  background: var(--st-popover-bg);
  box-shadow: 0 16px 40px -12px color-mix(in srgb, var(--st-shadow) 70%, transparent);
}
.pl-loops__menu[hidden] { display: none; }
.pl-loops__title {
  margin: 2px 4px 8px;
  color: var(--st-text-faint);
  font: 400 10px/normal var(--st-font-mono);
  letter-spacing: 1px;
  text-transform: uppercase;
}
.pl-loops__list { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.pl-loops__item { display: flex; align-items: center; gap: 6px; }
.pl-loops__item .pl-chip { flex: 1; min-width: 0; }
.pl-loops__item .pl-chip__name { flex: 1; max-width: 160px; text-align: left; }
.pl-loops__rename,
.pl-loops__remove {
  display: grid;
  flex: none;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--st-text-faint);
  cursor: pointer;
}
.pl-loops__rename:hover,
.pl-loops__remove:hover { background: var(--st-line); color: var(--st-text); }
.pl-loops__rename:focus-visible,
.pl-loops__remove:focus-visible { outline: 2px solid var(--st-accent); outline-offset: -2px; }
.pl-loops__rename .st-icon,
.pl-loops__remove .st-icon { width: 13px; height: 13px; }
/* The pencil shows on the row's hover and on keyboard focus; it keeps its room, so nothing shifts. */
.pl-loops__rename { opacity: 0; }
.pl-loops__item:hover .pl-loops__rename,
.pl-loops__item:focus-within .pl-loops__rename { opacity: 1; }

/* ---- Loop name field (decision 36) ------------------------------------------------ */

/* The Sections name box's look (sections.css, decision 23) in the loop's pink:
   a thin border and a soft glow, no ring; the border is the focus indicator. */
.pl-name-field {
  min-width: 0;
  height: 30px;
  margin: 0;
  padding: 0 10px;
  box-sizing: border-box;
  border: 1px solid var(--st-loop);
  border-radius: 7px;
  background: var(--st-surface-2);
  color: var(--st-text);
  font: 500 12px/normal var(--st-font);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--st-loop) 30%, transparent);
}
.pl-name-field:focus,
.pl-name-field:focus-visible { --st-focus-ring-style: none; outline: none; }
.pl-name-field::selection { background: color-mix(in srgb, var(--st-loop) 40%, var(--st-surface-2)); color: var(--st-text); }
.pl-name-field--list { flex: 1; }
/* In the Loop A–B row, where the range was ("Saved as"): the row is 44px tall. */
.pl-name-field--row { width: 100%; height: 24px; padding: 0 7px; border-radius: 6px; }
.pl-loops__quota {
  margin: 8px 4px 2px;
  color: var(--st-text-faint);
  font: 400 11px/normal var(--st-font-mono);
}
.pl-loops__quota[data-full='true'] { color: var(--st-loop-ink); }

/* ---- Compact player bar ---------------------------------------------------------- */

.pl-mini {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 68px;
  padding: 0 18px;
  border-radius: var(--st-radius-card);
  outline: 1px solid var(--st-line);
  outline-offset: -0.5px;
  background: var(--st-surface);
}
.pl-mini__controls { flex: none; display: flex; align-items: center; gap: 6px; }
.pl-mini__now { flex: none; color: var(--st-text); font: 600 15px/normal var(--st-font-mono); }
.pl-mini__total { flex: none; color: var(--st-text-faint); font: 400 13px/normal var(--st-font-mono); }

.pl-progress {
  --at: 0;
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  height: 36px;
  cursor: pointer;
  touch-action: none;
}
.pl-progress:focus-visible { outline: 2px solid var(--st-accent); outline-offset: 4px; border-radius: 4px; }

.pl-progress__bar { position: relative; flex: none; width: 100%; height: 6px; }
.pl-progress[data-sections='off'] .pl-progress__bar { overflow: hidden; border-radius: 3px; background: var(--st-line-strong); }
.pl-progress__played { width: calc(var(--at) * 100%); height: 100%; background: color-mix(in srgb, var(--st-text-strong) 80%, transparent); }

.pl-seg {
  --sect: var(--st-menu-thumb);
  --played: 0;
  position: absolute;
  top: 0;
  left: calc(var(--from) * 100%);
  width: max(0px, calc((var(--to) - var(--from)) * 100% - 2px));
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: color-mix(in srgb, var(--sect) 25%, transparent);
}
.pl-seg__played { width: calc(var(--played) * 100%); height: 100%; background: var(--sect); }

.pl-progress__labels { position: relative; flex: none; width: 100%; height: 12px; }
.pl-progress__label {
  position: absolute;
  top: 0;
  left: calc(var(--from) * 100%);
  max-width: calc((var(--to) - var(--from)) * 100% - 2px);
  overflow: hidden;
  color: var(--st-text-faint);
  font: 400 9px/normal var(--st-font-mono);
  white-space: nowrap;
}
.pl-progress__label.is-current { color: color-mix(in srgb, var(--sect) 70%, var(--st-text-strong)); }

.pl-progress__loop {
  position: absolute;
  top: 2px;
  left: calc(var(--from) * 100%);
  width: calc((var(--to) - var(--from)) * 100%);
  height: 3px;
  border-radius: 2px;
  background: var(--st-loop);
  pointer-events: none;
}
.pl-progress__loop[data-looping='false'] { opacity: 0.45; }
.pl-progress__loop[hidden] { display: none; }

.pl-progress__head {
  position: absolute;
  top: 6px;
  left: calc(var(--at) * 100% - 6px);
  width: 12px;
  height: 12px;
  border-radius: 6px;
  outline: 2px solid var(--st-accent);
  outline-offset: -1px;
  background: var(--st-on-accent);
  box-shadow: 0 0 8px color-mix(in srgb, var(--st-accent) 60%, transparent);
  pointer-events: none;
}

/* ---- Fitting the transport (transport.ts sets data-fit; 0 is the design) ------------ */

/* 1: the total time goes (the compact bar and the ruler show the length). */
.pl-transport:is([data-fit='1'], [data-fit='2'], [data-fit='3']) .pl-time__total { display: none; }
/* 2: the dividers go and the spacing closes up. */
.pl-transport:is([data-fit='2'], [data-fit='3']) { gap: 8px; }
.pl-transport:is([data-fit='2'], [data-fit='3']) .pl-divider { display: none; }
/* 3: a shorter volume slider (still a 24px-tall target). */
.pl-transport[data-fit='3'] .pl-volume__slider { width: 56px; }

/* ---- Loading audio (decision 66) --------------------------------------------------
   Play waits for the audio: its button spins, and a slim line sits over the top
   edge of the bar that shows (the transport or the compact player bar), with the
   download's size, Cancel, or Retry after a failure. A wait with no download
   shows only after 400 ms, so a quick start doesn't flash it. */

.pl-transport,
.pl-mini { position: relative; }
.pl-play__spin { animation: pl-spin 1s linear infinite; }
.pl-play[aria-busy='true'] { cursor: progress; }

.pl-load {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 16px);
  height: 30px;
  padding: 0 5px 0 11px;
  overflow: hidden;
  transform: translateX(-50%);
  border: 1px solid var(--st-line-strong);
  border-radius: 15px;
  background: var(--st-panel);
  box-shadow: 0 10px 24px -12px var(--st-shadow);
  color: var(--st-text-dim);
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pl-load[hidden] { display: none; }
.pl-load[data-source='wait'] { animation: pl-load-in 0s 400ms both; }
.pl-load__spin { flex: none; width: 14px; height: 14px; color: var(--st-accent); animation: pl-spin 1s linear infinite; }
.pl-load__text { overflow: hidden; text-overflow: ellipsis; }
.pl-load__btn {
  flex: none;
  height: 22px;
  padding: 0 9px;
  border: 0;
  border-radius: 11px;
  background: none;
  color: var(--st-accent-ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.pl-load__btn:hover { background: var(--st-surface-2); }
.pl-load__btn[hidden] { display: none; }
.pl-load__bar { position: absolute; right: 0; bottom: 0; left: 0; height: 2px; overflow: hidden; background: color-mix(in srgb, var(--st-accent) 18%, transparent); }
.pl-load__fill { display: block; width: 0; height: 100%; background: var(--st-accent); transition: width 150ms linear; }
.pl-load[data-known='false'] .pl-load__fill { width: 30%; animation: pl-load-slide 1.2s ease-in-out infinite; }
.pl-load[data-state='failed'] { color: var(--st-text); }
.pl-load[data-state='failed'] .pl-load__spin,
.pl-load[data-state='failed'] .pl-load__bar { display: none; }
.pl-load[data-state='failed']::before { content: ''; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--st-error); }

@keyframes pl-spin { to { transform: rotate(360deg); } }
@keyframes pl-load-slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
@keyframes pl-load-in { from { visibility: hidden; } to { visibility: visible; } }
@media (prefers-reduced-motion: reduce) {
  .pl-play__spin, .pl-load__spin, .pl-load[data-known='false'] .pl-load__fill { animation: none; }
}
