/* ==========================================================================
   POTIPLAYLISTS — the spinning button on Home and the radial picker it opens
   ========================================================================== */

/* The button lives in the pinned header, on the search box's row. */
.library-search-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}
.library-search-row .search-container {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
}

.potiplaylists-btn {
    position: relative;
    /* Everything inside is redrawn many times a second while music plays; this
       keeps that from re-laying-out the header and page around it. */
    contain: layout style;
    flex: 0 0 auto;
    width: 54px;
    height: 54px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--accent);
    cursor: pointer;
    display: grid;
    place-items: center;
    touch-action: none;                 /* the press carries on as a drag */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    transition: transform 0.15s ease;
    --pp-beat: 0;
}
.potiplaylists-btn:active {
    transform: scale(0.94);
}
.potiplaylists-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 50%;
}
.pp-blob {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.22));
}
/* The colours below are set from JS while music plays (shifting through the
   profile's highlight and background colours); the fallbacks are the plain,
   quiet look. */
.pp-stop-a { stop-color: var(--pp-c1, var(--surface-3)); }
.pp-stop-b { stop-color: var(--pp-c2, var(--surface-2)); }
.pp-blob-path {
    stroke: var(--pp-stroke, var(--border-strong));
    stroke-width: 1.4;
    stroke-linejoin: round;
}
/* Still until something plays; then the glow rides the beat. The glow is its
   own soft disc whose opacity and size follow the beat: a drop-shadow filter
   with a changing radius was being re-rendered every frame, which is hard on
   a phone's graphics memory and the likely reason the page was being thrown
   away a few minutes into a song. Only the hit of each beat glows, and
   softly: it sits next to the search box, not on a stage. */
.potiplaylists-btn::before {
    content: "";
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--pp-glow, rgb(var(--accent-rgb))) 0%, transparent 68%);
    opacity: 0;
    transform: scale(calc(0.9 + var(--pp-beat) * 0.2));
    pointer-events: none;
}
.potiplaylists-btn.is-playing::before {
    opacity: calc(var(--pp-beat) * 0.5);
}
.pp-spin {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    /* Always turning, music or no music. */
    animation: ppSpin 11s linear infinite;
    will-change: transform;
    pointer-events: none;
}
.pp-spin svg {
    display: block;
    width: 100%;
    height: 100%;
}
.pp-spin text {
    fill: var(--pp-text, var(--fg-2));
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.4px;
}
.pp-core {
    position: relative;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--on-accent);
    display: grid;
    place-items: center;
    pointer-events: none;
}
.pp-core svg {
    width: 14px;
    height: 14px;
}
@keyframes ppSpin { to { transform: rotate(360deg); } }

/* ---------- the overlay ---------- */
body.pp-open {
    overflow: hidden;
}
.pp-overlay {
    position: fixed;
    inset: 0;
    z-index: 4500;                       /* over the tab bar, mini player and drawers */
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.72);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}
.pp-overlay.open {
    display: flex;
    animation: ppFade 0.18s ease-out;
}
.pp-overlay.closing {
    animation: ppFadeOut 0.17s ease-in forwards;
}
.pp-overlay.closing .pp-wheel {
    transform: scale(1.08);
    opacity: 0;
    transition: transform 0.17s ease-in, opacity 0.17s ease-in;
}
@keyframes ppFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ppFadeOut { to { opacity: 0; } }

.pp-wheel {
    position: relative;
    flex: none;
}
.pp-wheel.pp-swap .pp-seg {
    animation: ppIn 0.26s cubic-bezier(0.2, 0.9, 0.3, 1.2) backwards;
}
.pp-wheel.pp-swap .pp-chip {
    animation: ppChipIn 0.26s cubic-bezier(0.2, 0.9, 0.3, 1.2) backwards;
}
/* A chip is centred on its slice with translate(-50%, -50%), so the animation has
   to carry that along. Animating only the scale replaces it, and the chip
   starts off to one side and slides across to where it belongs. */
@keyframes ppChipIn {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.82); }
    to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes ppIn {
    from { opacity: 0; transform: scale(0.82); }
    to   { opacity: 1; transform: scale(1); }
}

.pp-svg {
    position: absolute;
    inset: 0;
    overflow: visible;
}
.pp-seg {
    fill: rgba(34, 34, 34, 0.94);
    stroke: rgba(var(--tint-rgb), 0.1);
    stroke-width: 1;
    transform-origin: 50% 50%;
    transform-box: view-box;
    transition: transform 0.14s cubic-bezier(0.2, 0.9, 0.3, 1.3), fill 0.14s ease, stroke 0.14s ease;
}
.pp-seg.current {
    stroke: rgba(var(--accent-rgb), 0.7);
    stroke-width: 1.5;
}
.pp-seg.hot {
    transform: scale(1.06);
    fill: rgba(var(--accent-rgb), 0.3);
    stroke: var(--accent);
    stroke-width: 2;
    filter: drop-shadow(0 0 10px rgba(var(--accent-rgb), 0.55));
}
/* Resting on Shared / Public: it fills in to say it's about to open. */
.pp-seg.charging {
    animation: ppCharge 0.45s linear forwards;
}
@keyframes ppCharge {
    from { fill: rgba(var(--accent-rgb), 0.2); }
    to   { fill: rgba(var(--accent-rgb), 0.7); }
}

.pp-chips {
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.pp-chip {
    position: absolute;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    text-align: center;
    color: var(--fg);
    transition: transform 0.14s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
.pp-chip.hot {
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.22);
    color: var(--fg);
}
.pp-art {
    display: grid;
    place-items: center;
    border-radius: 50%;
    overflow: hidden;
    background: linear-gradient(145deg, var(--surface-3), var(--surface-2));
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.pp-art img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    -webkit-user-drag: none;
}
.pp-glyph {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--fg-2);
}
.pp-glyph svg {
    width: 46%;
    height: 46%;
}
.tone-liked .pp-art  { background: linear-gradient(145deg, #7c3aed, #ec4899); }
.tone-liked .pp-glyph,
.tone-folder .pp-glyph,
.tone-all .pp-glyph  { color: var(--fg); }
.tone-potantials .pp-art { background: linear-gradient(145deg, #10b981, #06b6d4); }
.tone-potantials .pp-glyph { color: var(--fg); }
.tone-weekly .pp-art { background: linear-gradient(145deg, #f59e0b, #ec4899); }
.tone-niche .pp-art { background: linear-gradient(145deg, #8b5cf6, #3b82f6); }
.tone-weekly .pp-glyph, .tone-niche .pp-glyph { color: var(--fg); }
.tone-mail .pp-art { background: linear-gradient(145deg, #f43f5e, #f59e0b); }
.tone-mail .pp-glyph { color: var(--fg); }
.tone-downloaded .pp-art { background: linear-gradient(145deg, #0ea5e9, #6366f1); }
.tone-downloaded .pp-glyph { color: var(--fg); }
.tone-folder .pp-art { background: linear-gradient(145deg, #3b82f6, #14b8a6); }
.tone-recent .pp-art { background: linear-gradient(145deg, #f97316, #facc15); }
.tone-recent .pp-glyph { color: var(--fg); }
.tone-all .pp-art    { background: linear-gradient(145deg, var(--accent), #0e6b30); }
.pp-name {
    font-weight: 700;
    line-height: 1.15;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

/* The hollow middle. */
.pp-hub {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--fg-2);
    border: 2px dashed rgba(var(--tint-rgb), 0.16);
    background: rgba(0, 0, 0, 0.25);
    transition: transform 0.14s ease, border-color 0.14s ease, color 0.14s ease, background 0.14s ease;
    pointer-events: none;
}
/* Nothing to do in the middle (e.g. no shared playlists to go to). */
.pp-hub.is-inert {
    opacity: 0.35;
    border-style: dotted;
}
.pp-hub.hot {
    transform: translate(-50%, -50%) scale(1.07);
    border-color: var(--accent);
    color: var(--fg);
    background: rgba(var(--accent-rgb), 0.18);
}
.pp-hub-icon {
    display: grid;
    place-items: center;
}
.pp-hub-icon svg {
    width: 24px;
    height: 24px;
}
.pp-hub.is-back .pp-hub-icon svg {
    transform: rotate(90deg);
}
.pp-hub-label {
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.6px;
    text-transform: uppercase;
}
.pp-hub-ring {
    position: absolute;
    inset: -2px;
    width: calc(100% + 4px);
    height: calc(100% + 4px);
    transform: rotate(-90deg);
    pointer-events: none;
}
.pp-hub-ring circle {
    fill: none;
    stroke: var(--accent);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
}
.pp-hub.charging .pp-hub-ring circle {
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.32s linear;
}

.pp-title,
.pp-caption {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: min(86vw, 340px);
    text-align: center;
    pointer-events: none;
}
.pp-title {
    top: -46px;
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: rgba(var(--tint-rgb), 0.5);
}
.pp-caption {
    bottom: -62px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.12s ease;
}
.pp-caption.show {
    opacity: 1;
}
.pp-caption strong {
    font-size: 1.15rem;
    color: var(--fg);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pp-caption span {
    font-size: 0.8rem;
    color: var(--fg-2);
}
.pp-wheel.is-empty .pp-caption {
    opacity: 1;
    bottom: auto;
    top: 50%;
    transform: translate(-50%, -50%);
    margin-top: calc(var(--pp-R) * 0.62);
}

@media (prefers-reduced-motion: reduce) {
    .pp-spin { animation: none; }
    .pp-wheel.pp-swap .pp-seg, .pp-wheel.pp-swap .pp-chip { animation: none; }
}

/* "Add to Playlist" in the song menu opens the wheel on press and carries on
   as a drag, so the browser must not claim that drag as a scroll (which would
   cancel the press halfway). */
#menu-add-to-playlist {
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* ---------- extra wheels, stacked along the bottom ---------- */
.pp-pages {
    position: absolute;
    left: 0;
    right: 0;
    bottom: max(14px, env(safe-area-inset-bottom));
    display: none;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 12px;
    pointer-events: none;
}
.pp-pages.show { display: flex; }
.pp-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 58px;
    padding: 6px 8px 5px;
    border-radius: 14px;
    background: rgba(var(--tint-rgb), 0.08);
    border: 1px solid rgba(var(--tint-rgb), 0.12);
    color: rgba(var(--tint-rgb), 0.75);
    transition: transform 0.14s ease, background 0.14s ease;
}
.pp-page svg { width: 34px; height: 34px; fill: currentColor; opacity: 0.8; }
.pp-page span { font-size: 0.7rem; font-weight: 800; letter-spacing: 0.4px; white-space: nowrap; }
.pp-page.current { background: var(--accent, #1db954); border-color: transparent; color: var(--on-accent, var(--fg-inverse)); }
.pp-page.hot { transform: scale(1.12); background: rgba(var(--tint-rgb), 0.22); }
.pp-page.current.hot { background: var(--accent, #1db954); }

/* The colours wheel.js picks while music plays are mixed toward white, which
   vanishes on Daylight; there the ring text stays the page's own text colour. */
html[data-theme="light"] .pp-spin text {
    fill: var(--fg-2);
}

/* Add-to-playlist: the playlists that already hold the song are lit. */
.pp-seg.has {
    fill: rgba(var(--accent-rgb), 0.22);
    stroke: rgba(var(--accent-rgb), 0.85);
    stroke-width: 1.5;
}
.pp-seg.has.hot {
    fill: rgba(var(--accent-rgb), 0.4);
}
.pp-chip.has .pp-art {
    box-shadow: 0 0 0 2px var(--accent), 0 2px 8px rgba(0, 0, 0, 0.5);
}
.pp-check {
    position: absolute;
    top: -6px;
    left: 50%;
    width: 18px;
    height: 18px;
    padding: 0;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--accent);
    color: var(--on-accent, #000);
    border: 2px solid var(--sheet);
    box-sizing: content-box;
}
.pp-check svg { width: 14px; height: 14px; }

/* ---------- Your own order: hold a playlist, drag it, group it ---------- */
/* One quiet line under the title: that they can be moved, and where to. */
.pp-hint {
    position: absolute;
    left: 50%;
    top: -27px;
    transform: translateX(-50%);
    width: max-content;
    max-width: min(86vw, 340px);
    text-align: center;
    pointer-events: none;
    font-size: 0.72rem;
    font-weight: 600;
    color: rgba(var(--tint-rgb), 0.42);
}
.pp-hint:empty { display: none; }
.pp-dragging .pp-hint { color: var(--accent); }

/* The playlist in the hand: it rides on the finger, a little above it so it
   can be seen, and the place it would land is left as an outline. */
.pp-ghost {
    position: fixed;
    z-index: 2;
    width: 64px;
    height: 64px;
    margin: -78px 0 0 -32px;
    pointer-events: none;
    animation: ppLift 0.16s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
.pp-ghost .pp-art {
    width: 100%;
    height: 100%;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.6), 0 0 0 3px var(--accent);
}
@keyframes ppLift {
    from { transform: scale(0.6); opacity: 0.4; }
    to   { transform: none; opacity: 1; }
}
.pp-chip.pp-lifted .pp-art { opacity: 0.28; outline: 2px dashed var(--accent); outline-offset: 2px; }
.pp-chip.pp-lifted .pp-name { opacity: 0.5; }
.pp-seg.pp-lifted {
    fill: rgba(var(--accent-rgb), 0.16);
    stroke: var(--accent);
    stroke-width: 1.5;
    stroke-dasharray: 5 4;
}
/* Nothing swells or jumps while something is being carried over it. */
.pp-dragging .pp-chip { transition: none; }

/* "+" (only while dragging) and "A-Z" (only on a wheel somebody arranged). */
.pp-page-new,
.pp-page-reset {
    justify-content: center;
    border-style: dashed;
}
.pp-page-new { border-color: var(--accent); color: var(--accent); }
.pp-page-plus,
.pp-page-az {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    font-size: 0.72rem;
    font-weight: 800;
}
.pp-page-plus svg { width: 22px; height: 22px; opacity: 1; }
.pp-page-new.hot { background: var(--accent); color: var(--on-accent, var(--fg-inverse)); transform: scale(1.18); }
.pp-dragging .pp-page.hot:not(.pp-page-new) { background: rgba(var(--accent-rgb), 0.35); }
@media (prefers-reduced-motion: reduce) { .pp-ghost { animation: none; } }
