/**
 * PriceONN GlobalPlayer — Floating Pill Widget
 * Mobile-first. Draggable — position persisted in cookie (separate for mobile/desktop).
 * Orb sits on top (z-index:2), panel slides out from orb center (z-index:1).
 * Panel opens RIGHT when orb is on left half, LEFT when orb is on right half.
 */

/* ── Root ───────────────────────────────────────────────── */
#gpPill {
    position: fixed;
    bottom: 80px;          /* fallback — JS overrides with top+left once it runs */
    left: 16px;            /* fallback */
    z-index: 9500;
    width: 52px;           /* exactly orb size — panel overflows outside this box */
    height: 52px;
    pointer-events: none;
}

/* ── Off state ──────────────────────────────────────────── */
#gpPill.gp--off {
    display: none;
}

/* ── Orb (circle button) — sits on top, z-index:2 ──────── */
.gp__orb {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 2;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 2px solid rgba(0, 212, 170, 0.35);
    background: rgba(10, 14, 22, 0.95);
    color: rgba(255, 255, 255, 0.8);
    cursor: grab;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    transition: border-color 0.2s, box-shadow 0.2s;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    overflow: hidden;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;     /* let JS handle all touch events on the orb */
}

.gp__orb:hover {
    border-color: rgba(0, 212, 170, 0.65);
}

/* While dragging */
#gpPill.gp--dragging .gp__orb {
    cursor: grabbing;
    border-color: rgba(0, 212, 170, 0.8);
    box-shadow: 0 8px 32px rgba(0, 212, 170, 0.2), 0 4px 16px rgba(0,0,0,0.6);
}

/* ── Play / Pause icons ─────────────────────────────────── */
.gp__ico {
    width: 18px;
    height: 18px;
    position: absolute;
    transition: opacity 0.15s, transform 0.15s;
    pointer-events: none;
}
.gp__ico-play  { opacity: 1; transform: scale(1); }
.gp__ico-pause { opacity: 0; transform: scale(0.7); }

/* Playing → show pause, hide play */
#gpPill.gp--playing .gp__ico-play  { opacity: 0; transform: scale(0.7); }
#gpPill.gp--playing .gp__ico-pause { opacity: 1; transform: scale(1); }
#gpPill.gp--playing .gp__orb {
    border-color: rgba(0, 212, 170, 0.7);
    box-shadow: 0 4px 24px rgba(0, 212, 170, 0.25), 0 2px 12px rgba(0,0,0,0.5);
    animation: gp-orb-pulse 2.5s ease-in-out infinite;
}

@keyframes gp-orb-pulse {
    0%, 100% { box-shadow: 0 4px 24px rgba(0, 212, 170, 0.25), 0 2px 12px rgba(0,0,0,0.5); }
    50%       { box-shadow: 0 4px 32px rgba(0, 212, 170, 0.45), 0 2px 12px rgba(0,0,0,0.5); }
}

/* ── Wave animation (playing, collapsed) ───────────────── */
.gp__wave {
    display: flex;
    align-items: flex-end;
    gap: 2.5px;
    height: 16px;
    position: absolute;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}
.gp__wave span {
    width: 3px;
    background: rgba(0, 212, 170, 0.85);
    border-radius: 2px;
    height: 4px;
    transform-origin: bottom;
}
#gpPill.gp--playing .gp__wave                  { opacity: 1; }
#gpPill.gp--playing .gp__ico-play,
#gpPill.gp--playing .gp__ico-pause             { opacity: 0; }

/* When expanded + playing: show pause icon, hide wave */
#gpPill.gp--playing.gp--expanded .gp__ico-pause { opacity: 1; transform: scale(1); }
#gpPill.gp--playing.gp--expanded .gp__wave      { opacity: 0; }

#gpPill.gp--playing .gp__wave span:nth-child(1) { animation: gp-bar 0.80s ease-in-out infinite; }
#gpPill.gp--playing .gp__wave span:nth-child(2) { animation: gp-bar 1.10s ease-in-out infinite 0.15s; }
#gpPill.gp--playing .gp__wave span:nth-child(3) { animation: gp-bar 0.65s ease-in-out infinite 0.05s; }
#gpPill.gp--playing .gp__wave span:nth-child(4) { animation: gp-bar 0.90s ease-in-out infinite 0.25s; }
#gpPill.gp--playing .gp__wave span:nth-child(5) { animation: gp-bar 0.75s ease-in-out infinite 0.10s; }

@keyframes gp-bar {
    0%, 100% { height: 3px; }
    50%       { height: 14px; }
}

/* ── Panel — opens RIGHT by default (orb on left side) ─── */
.gp__panel {
    position: absolute;
    left: 26px;      /* starts at orb center → left portion hidden behind orb */
    top: 0;
    z-index: 1;      /* behind orb */
    height: 52px;
    max-width: 0;
    overflow: hidden;
    opacity: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(10, 14, 22, 0.95);
    border-radius: 0 26px 26px 0;
    border: 2px solid rgba(0, 212, 170, 0.35);
    border-left: none;
    padding: 0;
    pointer-events: none;
    white-space: nowrap;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 4px 4px 20px rgba(0,0,0,0.4);
    transition: max-width 0.28s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.2s ease,
                padding 0.28s ease;
}

#gpPill.gp--expanded .gp__panel {
    max-width: 300px;
    opacity: 1;
    /* left padding 30px: 26px orb-overlap + 4px breathing room */
    padding: 0 12px 0 30px;
    pointer-events: auto;
}

/* ── Panel opens LEFT (orb on right half of screen) ─────── */
#gpPill.gp--panel-left .gp__panel {
    left: auto;
    right: 26px;     /* right edge at orb center → panel extends LEFT */
    border-radius: 26px 0 0 26px;
    border: 2px solid rgba(0, 212, 170, 0.35);
    border-right: none;
    box-shadow: -4px 4px 20px rgba(0,0,0,0.4);
}

#gpPill.gp--panel-left.gp--expanded .gp__panel {
    padding: 0 30px 0 12px;  /* right padding 30px: 26px orb-overlap + 4px breathing room */
}

/* ── Panel info block ───────────────────────────────────── */
.gp__info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.gp__title {
    font-size: 11px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 170px;
    line-height: 1.2;
}

.gp__seek-row {
    display: flex;
    align-items: center;
    gap: 5px;
}

.gp__time {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.45);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    min-width: 28px;
}

/* ── Seek slider ────────────────────────────────────────── */
.gp__seek {
    -webkit-appearance: none;
    appearance: none;
    width: 110px;
    height: 3px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
    flex-shrink: 0;
}
.gp__seek::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #00d4aa;
    cursor: pointer;
    transition: transform 0.1s;
}
.gp__seek::-webkit-slider-thumb:active { transform: scale(1.3); }
.gp__seek::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: none;
    background: #00d4aa;
    cursor: pointer;
}

/* ── Close button ───────────────────────────────────────── */
.gp__close {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}
.gp__close:hover {
    background: rgba(255, 80, 80, 0.25);
    color: #fff;
}

/* ── Pointer events ─────────────────────────────────────── */
#gpPill:not(.gp--off) .gp__orb          { pointer-events: auto; }
#gpPill.gp--expanded  .gp__panel        { pointer-events: auto; }

/* ── Narrow screen: smaller panel (position handled by JS) ── */
@media (max-width: 400px) {
    #gpPill.gp--expanded .gp__panel {
        max-width: 240px;
    }
    #gpPill.gp--expanded:not(.gp--panel-left) .gp__panel {
        padding: 0 10px 0 30px;
    }
    #gpPill.gp--panel-left.gp--expanded .gp__panel {
        padding: 0 30px 0 10px;
    }
    .gp__title { max-width: 120px; }
    .gp__seek  { width: 80px; }
}
