@layer views {
  /* ── background music: a small button, and the player it opens ── */
  .music { display: inline-flex; flex: none; }
  .music.labeled { display: flex; width: 100%; }

  .music-btn { position: relative; }
  /* icon-only: round like the session bar's sound toggle beside it */
  .icon-btn.music-btn { border-radius: 50%; color: var(--muted); }
  .icon-btn.music-btn svg { width: 16px; height: 16px; }
  /* with a label: a row like the sidebar's links */
  .music-btn.labeled {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; border-radius: 9px;
    background: none; color: var(--muted); font-weight: 600; font-size: 13.5px; text-align: left;
    & > svg { width: 16px; height: 16px; flex: none; }
  }
  .music-label { flex: 1; min-width: 0; }

  /* three little bars while it plays (still while it loads, or when motion is reduced) */
  .music-eq { display: none; align-items: flex-end; gap: 2px; width: 13px; height: 12px; flex: none; }
  .music-eq i { flex: 1; height: 100%; border-radius: 1px; background: currentColor; transform-origin: 50% 100%; scale: 1 .4; }
  .music:is([data-state="on"], [data-state="loading"]) {
    & .music-btn { color: var(--fg-2); }
    & .music-eq { display: inline-flex; }
    & .icon-btn.music-btn > svg { display: none; }
  }
  .music[data-state="on"] .music-eq i { animation: music-eq 900ms ease-in-out infinite alternate; }
  .music[data-state="on"] .music-eq i:nth-child(2) { animation-duration: 650ms; animation-delay: -300ms; }
  .music[data-state="on"] .music-eq i:nth-child(3) { animation-duration: 1100ms; animation-delay: -700ms; }
  .music[data-state="loading"] .music-eq i { opacity: .45; }
  @keyframes music-eq { from { scale: 1 .25; } to { scale: 1 1; } }
  @media (prefers-reduced-motion: reduce) {
    .music[data-state] .music-eq i { animation: none; }
    .music[data-state] .music-eq i:nth-child(1) { scale: 1 .55; }
    .music[data-state] .music-eq i:nth-child(2) { scale: 1 1; }
    .music[data-state] .music-eq i:nth-child(3) { scale: 1 .7; }
  }

  /* it was on last time: one click picks it up again */
  .music[data-state="resume"] .music-btn::after {
    content: ""; position: absolute; top: 5px; right: 5px;
    width: 6px; height: 6px; border-radius: 50%; background: var(--fg-2);
  }
  .music.labeled[data-state="resume"] .music-btn::after { top: 50%; right: 12px; translate: 0 -50%; }

  /* hovered or open: full ink (after the states above, so it wins over them) */
  .music .music-btn:hover, .music .music-btn[aria-expanded="true"] { color: var(--fg); }
  .music .music-btn.labeled:hover { background: var(--surface); }
  .music .music-btn[aria-expanded="true"] { background: var(--surface-2); }

  /* ── the player ── */
  .music-pop {
    position: fixed; inset: auto; margin: 0; z-index: 50;
    width: min(280px, calc(100vw - 16px)); padding: 14px 16px 12px;
    display: grid; gap: 12px; overflow: visible;
    border: 1px solid var(--line-2); border-radius: var(--r-card);
    background: var(--surface); color: var(--fg-2); box-shadow: var(--shadow-float);
    font-size: var(--fs-sm); font-weight: 400; line-height: 1.45; letter-spacing: normal;
    text-align: left; white-space: normal; cursor: auto;
    animation: music-in var(--t-fast) var(--ease-liquid);
    &[data-side="above"] { animation-name: music-in-above; }
    &:focus-visible { outline: none; }
  }
  .music-pop[popover]:not(:popover-open) { display: none; }
  @keyframes music-in { from { opacity: 0; translate: 0 -4px; } }
  @keyframes music-in-above { from { opacity: 0; translate: 0 4px; } }

  .music-eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: .04em; color: var(--faint); }
  .music-now { display: grid; gap: 1px; min-width: 0; margin-top: -6px; }
  .music-title, .music-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .music-title { color: var(--fg); font-weight: 700; font-size: 14.5px; letter-spacing: -0.015em; }
  .music-sub { color: var(--muted); font-size: 12.5px; }
  .music-sub:empty { display: none; }

  .music-controls { display: flex; align-items: center; gap: 6px; }
  .music-play {
    width: 36px; height: 36px; flex: none; display: grid; place-items: center; padding: 0;
    border: 0; border-radius: 50%; background: var(--btn-bg); color: var(--btn-fg);
    transition: background var(--t-fast), transform var(--t-fast) var(--ease-spring);
    & svg { width: 14px; height: 14px; }
    &:hover:not(:disabled) { background: color-mix(in oklch, var(--btn-bg) 88%, var(--grad-b)); }
    &:active:not(:disabled) { transform: scale(.94); }
  }
  .music-next { color: var(--muted); }
  .music-play svg path, .music-next svg path { fill: currentColor; }
  .music-play:disabled, .music-next:disabled { opacity: .45; cursor: not-allowed; }

  .music-vol { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding-left: 4px; color: var(--muted); }
  .music-vol-icon { display: grid; place-items: center; flex: none; }
  .music-vol-icon svg { width: 15px; height: 15px; }
  .music-range {
    --v: 35%;
    flex: 1; min-width: 0; height: 20px; margin: 0; background: transparent; cursor: pointer;
    -webkit-appearance: none; appearance: none;
    &::-webkit-slider-runnable-track {
      height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--fg-2) var(--v), var(--line-2) var(--v));
    }
    &::-webkit-slider-thumb {
      -webkit-appearance: none; appearance: none; width: 14px; height: 14px; margin-top: -5px;
      border: 0; border-radius: 50%; background: var(--fg); box-shadow: 0 0 0 3px var(--surface);
    }
    &::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line-2); }
    &::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--fg-2); }
    &::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--fg); box-shadow: 0 0 0 3px var(--surface); }
    &:disabled { opacity: .45; cursor: not-allowed; }
    &:focus-visible { outline: none; }
    &:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--focus); outline-offset: 2px; }
    &:focus-visible::-moz-range-thumb { outline: 2px solid var(--focus); outline-offset: 2px; }
  }
  .music-hint { flex: 1; min-width: 0; padding-left: 4px; font-size: 12px; color: var(--muted); }

  .music-loading, .music-error { margin-top: -4px; font-size: 12.5px; }
  .music-loading { color: var(--muted); }
  .music-error { color: var(--wrong); font-weight: 600; }
  .music-loading:empty, .music-error:empty { display: none; }

  .music-credit {
    padding-top: 10px; border-top: 1px solid var(--line);
    font-size: 11.5px; color: var(--faint); overflow-wrap: anywhere;
    & a { color: var(--muted); text-decoration-color: var(--line-2); }
    & a:hover { color: var(--fg); text-decoration-color: currentColor; }
  }
}
