/* ──────────────────────────────────────────────────────────────────────────
 *  tg-player.css — the Tunegether player bar.
 *
 *  One bar, every surface. The website, the desktop app and whatever a phone
 *  wraps all mount the same markup from tg-bar.js and style it from here, so a
 *  control that moves moves everywhere and there is no such thing as "the web
 *  version behaves differently".
 *
 *  It adapts by DEVICE, not by product:
 *
 *    phone    a compact bar above the thumb, which opens into a full-screen
 *             now-playing sheet — artwork, transport, scrubber, the lot.
 *    tablet   the bar keeps its scrubber inline; the sheet is a tall card.
 *    desktop  everything inline, sheet is a large centred panel.
 *
 *  THE STAGE
 *
 *  One element carries whatever is making sound, and it never moves in the DOM
 *  — moving an iframe reloads it, which would stop the music every time
 *  somebody opened the sheet. It is the artwork slot, and it grows.
 *
 *  Surfaces that can be rendered without anybody else's furniture are shown and
 *  become the artwork. Surfaces that cannot are one pixel across behind the
 *  artwork, still playing. `.tgp-veil` sits over the top of both so a hover
 *  never reaches a frame and every click lands on this player's own controls.
 *
 *  Theme comes from tokens.css. The dark surfaces set --tgp-* overrides on a
 *  [data-tg-theme="dark"] ancestor; nothing here hard-codes a colour that a
 *  theme should own.
 * ────────────────────────────────────────────────────────────────────────── */

.tgp {
  --tgp-bg: #ffffff;
  --tgp-ink: var(--tg-ink, #0B0B12);
  --tgp-ink-soft: var(--tg-ink-soft, #3B3B4C);
  --tgp-ink-mute: var(--tg-ink-mute, #5A5A70);
  --tgp-rule: var(--tg-rule, #E8E6F3);
  --tgp-surface-2: var(--tg-surface-2, #F3F1FF);
  --tgp-accent: var(--tg-purple, #7A3CFF);
  --tgp-shadow: 0 -2px 12px rgba(11, 11, 18, .06), 0 -18px 60px rgba(122, 60, 255, .10);

  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  background: var(--tgp-bg);
  border-top: 1px solid var(--tgp-rule);
  box-shadow: var(--tgp-shadow);
  color: var(--tgp-ink);
  font-family: var(--tg-font-body, system-ui, sans-serif);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "art main right";
  align-items: center;
  gap: 12px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  transform: translateY(110%);
  transition: transform var(--tg-dur, 220ms) var(--tg-ease-out, ease),
              height var(--tg-dur, 220ms) var(--tg-ease-out, ease);
  will-change: transform;
}

[data-tg-theme="dark"] .tgp,
.tgp[data-theme="dark"] {
  --tgp-bg: var(--tg-dark-surface, #10101C);
  --tgp-ink: var(--tg-dark-ink, #F5F5FA);
  --tgp-ink-soft: var(--tg-dark-ink-soft, #B4B4C8);
  --tgp-ink-mute: var(--tg-dark-ink-mute, #7E7E96);
  --tgp-rule: var(--tg-dark-rule, #242438);
  --tgp-surface-2: var(--tg-dark-surface-2, #181828);
  --tgp-shadow: 0 -2px 12px rgba(0, 0, 0, .5);
}

.tgp[data-open="true"] { transform: translateY(0); }

/* ─────────────────────────────── the stage ──────────────────────────────── */

.tgp-art {
  grid-area: art;
  position: relative;
  width: 52px;
  height: 52px;
  flex: none;
  border: 0;
  padding: 0;
  border-radius: 10px;
  overflow: hidden;
  background: var(--tgp-surface-2);
  cursor: pointer;
  transition: width var(--tg-dur, 220ms) var(--tg-ease-out, ease),
              height var(--tg-dur, 220ms) var(--tg-ease-out, ease),
              border-radius var(--tg-dur, 220ms) var(--tg-ease-out, ease);
}

.tgp-art-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tgp-art-letter {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--tg-font-display, system-ui, sans-serif);
  font-weight: 700;
  font-size: 20px;
  color: #fff;
  background: var(--tg-grad-diagonal, linear-gradient(135deg, #FF2DD1, #00F5FF));
}

/* The surface that is actually making sound. A clean video fills it and
   becomes the artwork; a frame that carries somebody else's marks sits at one
   pixel and the artwork above covers for it. */
.tgp-stage-host {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.tgp-stage-host[data-visible="false"] {
  width: 1px;
  height: 1px;
  opacity: 0;
  inset: auto auto 0 0;
}

.tgp-stage-host[data-visible="true"] { opacity: 1; z-index: 1; }

/* A 16:9 frame inside a square crop: scaled to cover, centred, so a music
   video reads as artwork rather than as a letterboxed strip. */
.tgp-frame-video {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 178%;
  height: 178%;
  transform: translate(-50%, -50%);
  border: 0;
}

.tgp-frame-headless {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  pointer-events: none;
}

/* Over everything in the art slot: stops a pointer ever reaching a frame, so
   no hover furniture of anybody else's is ever summoned, and a click on the
   artwork is a click on this player. */
.tgp-veil {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: transparent;
}

/* ──────────────────────────────── the middle ────────────────────────────── */

.tgp-main {
  grid-area: main;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tgp-title {
  font-weight: 650;
  font-size: 14px;
  line-height: 1.25;
  color: var(--tgp-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tgp-sub {
  font-size: 12.5px;
  color: var(--tgp-ink-mute);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tgp-live {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--tgp-accent);
}

.tgp-live .pip {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: tgp-pulse 1.8s var(--tg-ease-out, ease) infinite;
}

@keyframes tgp-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .35; transform: scale(.7); }
}

/* ─────────────────────────────── the scrubber ───────────────────────────── */

.tgp-scrub {
  grid-area: scrub;
  display: none;
  align-items: center;
  gap: 8px;
}

.tgp-scrub[data-on="true"] { display: flex; }

.tgp-time {
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  color: var(--tgp-ink-mute);
  min-width: 34px;
}

.tgp-time.right { text-align: right; }

.tgp-range {
  -webkit-appearance: none;
  appearance: none;
  flex: 1 1 auto;
  min-width: 60px;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(to right,
      var(--tgp-accent) 0%, var(--tgp-accent) var(--tgp-pct, 0%),
      var(--tgp-rule) var(--tgp-pct, 0%), var(--tgp-rule) 100%);
  cursor: pointer;
  /* A drag on a slider in a fixed bar is otherwise read as a drag on the page
     behind it, and the seek is lost halfway through on every phone. */
  touch-action: none;
}

.tgp-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--tgp-accent);
  border: 2px solid var(--tgp-bg);
  box-shadow: 0 1px 4px rgba(11, 11, 18, .25);
}

.tgp-range::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 2px solid var(--tgp-bg);
  border-radius: 50%;
  background: var(--tgp-accent);
}

.tgp-range:disabled { opacity: .45; cursor: default; }

/* ──────────────────────────────── controls ──────────────────────────────── */

.tgp-right {
  grid-area: right;
  display: flex;
  align-items: center;
  gap: 4px;
}

.tgp-btn {
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--tgp-ink-soft);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  flex: none;
  transition: background var(--tg-dur-fast, 150ms), color var(--tg-dur-fast, 150ms);
}

.tgp-btn:hover { background: var(--tgp-surface-2); color: var(--tgp-ink); }
.tgp-btn:focus-visible { outline: 2px solid var(--tgp-accent); outline-offset: 2px; }
.tgp-btn[aria-pressed="true"] { color: var(--tgp-accent); }
.tgp-btn[disabled] { opacity: .3; cursor: default; }

/* `hidden` has to actually hide.
 *
 * Every control in this bar sets `display` in a class rule, and an author
 * `display` beats the user agent's own `[hidden] { display: none }` however
 * specific that looks — so a control the player had hidden stayed on screen.
 * That is how a station's "save to a list" plus ended up standing next to a
 * record's save plus, two identical + buttons on a phone with nothing to tell
 * them apart, and how a recorded track carried a "live" pip. One rule, scoped
 * to the player, closes the whole class of it. */
.tgp [hidden] { display: none !important; }
.tgp-btn svg { width: 20px; height: 20px; display: block; }

.tgp-play {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--tg-grad-diagonal, linear-gradient(135deg, #FF2DD1, #00F5FF));
  color: #fff;
}

.tgp-play:hover { background: var(--tg-grad-diagonal, linear-gradient(135deg, #FF2DD1, #00F5FF)); color: #fff; filter: brightness(1.06); }
.tgp-play svg { width: 22px; height: 22px; }

.tgp-vol {
  width: 78px;
  height: 4px;
  flex: none;
}

.tgp-data {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--tgp-ink-mute);
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--tgp-surface-2);
  white-space: nowrap;
}

/* ───────────────────────────── the note line ────────────────────────────── */

.tgp-note {
  grid-column: 1 / -1;
  font-size: 12.5px;
  color: var(--tgp-ink-soft);
  background: var(--tgp-surface-2);
  border-radius: 10px;
  padding: 7px 11px;
  margin-top: 2px;
}

.tgp-note[hidden] { display: none; }

/* ───────────────────────────── the device menu ──────────────────────────── */

.tgp-pop {
  position: absolute;
  bottom: calc(100% + 10px);
  right: 12px;
  min-width: 232px;
  max-width: min(320px, calc(100vw - 24px));
  background: var(--tgp-bg);
  border: 1px solid var(--tgp-rule);
  border-radius: var(--tg-r, 12px);
  box-shadow: var(--tg-shadow-2, 0 12px 40px rgba(0, 0, 0, .18));
  padding: 8px;
  z-index: 5;
}

.tgp-pop[hidden] { display: none; }

.tgp-pop h4 {
  margin: 4px 8px 8px;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--tgp-ink-mute);
  font-weight: 700;
}

.tgp-dev {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--tgp-ink);
  text-align: left;
  padding: 9px 8px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13.5px;
}

.tgp-dev:hover { background: var(--tgp-surface-2); }
.tgp-dev[aria-pressed="true"] { color: var(--tgp-accent); font-weight: 600; }
.tgp-dev .tgp-dev-sub { display: block; font-size: 11.5px; color: var(--tgp-ink-mute); font-weight: 400; }
.tgp-dev svg { width: 18px; height: 18px; flex: none; }
.tgp-pop-note { margin: 8px; font-size: 11.5px; color: var(--tgp-ink-mute); line-height: 1.45; }

/* ───────────────────────────── expanded sheet ───────────────────────────── */

.tgp[data-expanded="true"] {
  top: 0;
  height: 100dvh;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto auto auto auto 1fr;
  grid-template-areas: "head" "art" "main" "scrub" "controls" "rail" "rest";
  align-content: start;
  justify-items: center;
  gap: 16px;
  padding: max(18px, env(safe-area-inset-top, 0px)) 20px calc(24px + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
}

.tgp[data-expanded="true"] .tgp-art {
  width: min(70vw, 320px);
  height: min(70vw, 320px);
  border-radius: var(--tg-r-lg, 20px);
  box-shadow: var(--tg-shadow-3, 0 24px 70px rgba(0, 0, 0, .25));
}

.tgp[data-expanded="true"] .tgp-main { align-items: center; text-align: center; width: 100%; max-width: 520px; gap: 6px; }
.tgp[data-expanded="true"] .tgp-title { font-size: 21px; white-space: normal; }
.tgp[data-expanded="true"] .tgp-sub { font-size: 15px; white-space: normal; justify-content: center; }
.tgp[data-expanded="true"] .tgp-scrub { display: flex; width: 100%; max-width: 520px; }
.tgp[data-expanded="true"] .tgp-controls { justify-content: center; gap: 14px; }
.tgp[data-expanded="true"] .tgp-play { width: 62px; height: 62px; }
.tgp[data-expanded="true"] .tgp-play svg { width: 30px; height: 30px; }
.tgp[data-expanded="true"] .tgp-head { display: flex; }

/* The secondary rail rides under the transport rather than beside it — save,
   data, volume, devices — because in a full-screen sheet the transport is the
   thing the thumb is aiming at and everything else is one row further away. */
.tgp[data-expanded="true"] .tgp-right {
  grid-area: rail;
  width: 100%;
  max-width: 520px;
  justify-content: center;
  gap: 8px;
}

.tgp[data-expanded="true"] .tgp-note { max-width: 520px; }

.tgp-head {
  grid-area: head;
  display: none;
  width: 100%;
  align-items: center;
  justify-content: space-between;
}

.tgp-head-label {
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--tgp-ink-mute);
  font-weight: 700;
}

/* ─────────────────────────────── responsive ─────────────────────────────── */

.tgp-controls { display: flex; align-items: center; gap: 6px; }

/* Phone: the bar is thumb-sized and everything else lives in the sheet one tap
   away. Fewer, bigger targets beats more, smaller ones on a device held in one
   hand — and the whole bar is 60 pixels of a screen somebody is reading. */
@media (max-width: 700px) {
  .tgp:not([data-expanded="true"]) {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    /* Two rows, and the second one is the scrubber.
       It used to be a 2px line painted on the bar's ::after — a picture of
       progress that nothing could grab. "How far in am I" and "take me to
       2:14" are not the same question, and a music player has to answer both
       on the device most people are holding. The row costs 22px. */
    grid-template-areas:
      "art main controls right"
      "scrub scrub scrub scrub";
    gap: 8px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
  }
  .tgp:not([data-expanded="true"]) .tgp-art { width: 44px; height: 44px; }

  /* Full width, and a thumb-sized thing to drag. The visible track stays 4px:
     the element is 22px tall and paints its gradient as a 4px band down the
     middle, so the hit area is a thumb and the bar still looks like a hairline. */
  .tgp:not([data-expanded="true"]) .tgp-scrub[data-on="true"] {
    grid-area: scrub;
    display: flex;
    margin-top: 2px;
  }
  .tgp:not([data-expanded="true"]) .tgp-range {
    height: 22px;
    background-size: 100% 4px;
    background-position: center;
    background-repeat: no-repeat;
  }
  .tgp:not([data-expanded="true"]) .tgp-vol,
  .tgp:not([data-expanded="true"]) .tgp-data,
  .tgp:not([data-expanded="true"]) [data-tgp="prev"],
  .tgp:not([data-expanded="true"]) [data-tgp="mute"],
  /* Shuffle and repeat are real controls and they are not thumb-sized ones.
     On the compact bar they live one tap away in the sheet, where the artwork
     is and where somebody is actually choosing how the queue behaves. */
  .tgp:not([data-expanded="true"]) [data-tgp="shuffle"],
  .tgp:not([data-expanded="true"]) [data-tgp="repeat"],
  .tgp:not([data-expanded="true"]) [data-tgp="devices"] { display: none; }
  .tgp:not([data-expanded="true"]) .tgp-title { font-size: 13.5px; }
  .tgp:not([data-expanded="true"]) .tgp-play { width: 38px; height: 38px; }
  .tgp:not([data-expanded="true"]) .tgp-play svg { width: 19px; height: 19px; }

}

/* Tablet and up: the scrubber is inline, which is what a wider bar is for. */
@media (min-width: 701px) {
  .tgp:not([data-expanded="true"]) {
    grid-template-columns: auto minmax(160px, 1fr) auto minmax(180px, 2fr) auto;
    grid-template-areas: "art main controls scrub right";
    gap: 16px;
    padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .tgp:not([data-expanded="true"]) .tgp-controls { grid-area: controls; }
  .tgp:not([data-expanded="true"]) .tgp-scrub { grid-area: scrub; display: flex; }
}

/* The page needs to know the bar is there, or the last row of any list on any
   surface sits underneath it forever. */
body[data-tgp-open="true"] { padding-bottom: 88px; }

@media (max-width: 700px) {
  /* The compact bar now carries a scrub row, so the last item in any list on
     the page has to clear a taller bar than it used to. */
  body[data-tgp-open="true"] { padding-bottom: 98px; }
}

@media (prefers-reduced-motion: reduce) {
  .tgp, .tgp-art { transition: none; }
  .tgp-live .pip { animation: none; }
}

/* ─────────────────────────── the light on the beat ───────────────────────────
 *
 * Two surfaces, one control. The veil is the strobe on a phone whose browser
 * will not hand over the camera lamp — every iPhone, today — and it has to be
 * the topmost thing on the page and take no clicks, because it is a light and
 * not a layer of the interface.
 *
 * It is appended to <body> rather than to the player bar on purpose: the bar is
 * a frosted, backdrop-filtered element, and a backdrop filter makes an element
 * the containing block for its own fixed children. A veil parented there would
 * be a rectangle the size of the bar.
 */

.tgl-veil {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  background: #FFFFFF;
  opacity: 0;
  pointer-events: none;
  transition: opacity 90ms linear;
  will-change: opacity;
}

.tgp-light {
  padding: 8px;
  min-width: 250px;
}

.tgp-light-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
}

.tgp-light-row label {
  font-size: 12px;
  color: var(--tgp-ink-mute);
  flex: none;
  min-width: 68px;
}

.tgp-light-row input[type="range"] { flex: 1; }

.tgp-light-row select {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 12.5px;
  color: var(--tgp-ink);
  background: var(--tgp-surface-2);
  border: 1px solid var(--tgp-rule);
  border-radius: 8px;
  padding: 6px 8px;
}

.tgp-light-bpm {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 8px 2px;
}

.tgp-light-bpm b {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--tgp-ink);
  font-variant-numeric: tabular-nums;
}

.tgp-light-bpm span { font-size: 11.5px; color: var(--tgp-ink-mute); }

.tgp-light-acts {
  display: flex;
  gap: 8px;
  padding: 6px 8px 2px;
}

.tgp-light-acts button {
  flex: 1;
  border: 1px solid var(--tgp-rule);
  background: transparent;
  color: var(--tgp-ink);
  border-radius: 9px;
  padding: 8px 6px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.tgp-light-acts button:hover { background: var(--tgp-surface-2); }
.tgp-light-acts button[disabled] { opacity: .45; cursor: default; }

/* A record that stops when the screen goes dark says so here, once, in the
   place the listener is already looking. */
.tgp-lock {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--tgp-ink-mute);
}

.tgp-lock[hidden] { display: none; }

/* The lock line's action. A row of its own, because the sub line is one
   ellipsised line on a phone and a button inside it would be cut in half. */
.tgp-keep {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-start;
  margin-top: -2px;
}

.tgp-keep[hidden] { display: none; }

.tgp-keep-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 5px 12px;
  border: 1px solid var(--tgp-rule);
  border-radius: 999px;
  background: transparent;
  color: var(--tgp-ink-soft);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.tgp-keep-btn svg { width: 14px; height: 14px; flex: none; }
.tgp-keep-btn:hover { background: var(--tgp-surface-2); color: var(--tgp-ink); }
.tgp-keep-btn:focus-visible { outline: 2px solid var(--tgp-accent); outline-offset: 2px; }
.tgp[data-expanded="true"] .tgp-keep { justify-content: center; max-width: 520px; }

@media (prefers-reduced-motion: reduce) {
  /* A full-screen strobe is the single most likely thing on this platform to
     hurt somebody. If the operating system has been told to reduce motion, the
     screen never flashes — the lamp, which is not the screen and not in anyone's
     visual field, still can. */
  .tgl-veil { display: none; }
}

/* ── the blend ────────────────────────────────────────────────────────────
 * How long one song takes to become the next one. A slider and two lines:
 * what it is set to, and what it can and cannot reach. The second line is not
 * decoration — without it a blend that was a clean cut on a framed record
 * reads as the setting not working. */
.tgp-blend { min-width: 280px; }
.tgp-pop-title {
  margin: 4px 8px 8px;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--tgp-ink-mute);
  font-weight: 700;
}
.tgp-blend .tgp-range { width: calc(100% - 16px); margin: 0 8px; }
.tgp-blend .tgp-pop-note:first-of-type { color: var(--tgp-ink); }
