#playlist {
    position: absolute;
    /*height: 116px;*/
    height: calc(var(--tg-viewport-stable-height, 100vh)/var(--scale-factor) - 116px - (var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px) + var(--tg-safe-area-inset-bottom, 0px) + var(--tg-content-safe-area-inset-bottom, 0px))/var(--scale-factor));
    width: 275px;
    top: calc((116px * var(--scale-factor)) + var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
    transform: scale(var(--scale-factor));
    transform-origin: top left;
    /*margin-top: -58px;
    margin-left: -137px;
    margin-left: -137px;
    top: 40%;
    left: 20%;*/
    flex-grow: 1; /* Take up the remaining space vertically */
/*    background-color: #444;*/
/*    overflow-y: auto; /* Scroll if content overflows */
}
#playlist.closed { display: none; }

#playlist #tracks {
    position: absolute;
    padding: 0;
    margin: 0;
    list-style: none;
    top: 20px;
    left: 11px;

    width: -moz-calc(100% - 31px);
    width: -webkit-calc(100% - 31px);
    width: calc(100% - 31px);

    height: -moz-calc(100% - 58px);
    height: -webkit-calc(100% - 58px);
    height: calc(100% - 58px);

    overflow-y: scroll;
    overflow-x: hidden;
}
#playlist #tracks li {
    white-space: nowrap;
    font-size: 8px;
}
#playlist #tracks li.selected {
}

#playlist .top {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 20px;
    overflow: hidden;
}

#playlist .top .top-left {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 25px;
}
#playlist .top .title {
    position: relative;
    height: 100%;
    width: 100px;
    margin: 0 auto;
}

#playlist .top .top-right {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    width: 25px;
}

#playlist .top #playlist-shade {
    position: absolute;
    top: 3px;
    right: 13px;
    height: 9px;
    width: 9px;
}

#playlist .top #playlist-close {
    position: absolute;
    top: 3px;
    right: 3px;
    height: 9px;
    width: 9px;
}

#playlist .left {
    height: 100%;
    width: 24px;
    overflow: hidden;
}

#playlist .right {
    height: 100%;
    position: absolute;
    right: 0px;
    top: 0px;
    width: 24px;
    overflow: hidden;
}
#playlist .bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 38px;
    overflow: hidden;
}

#playlist .bottom-left {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 125px;
}

/* ADD / REM / SEL / MISC buttons, positioned to match PLEDIT.BMP's button row */
#playlist-add, #playlist-rem, #playlist-sel, #playlist-misc {
    position: absolute;
    top: 8px;
    height: 18px;
    cursor: pointer;
}
#playlist-add  { left: 0px;  width: 37px; }
#playlist-rem  { left: 37px; width: 29px; }
#playlist-sel  { left: 66px; width: 29px; }
#playlist-misc { left: 95px; width: 29px; }

/* No dedicated "pressed" sprite exists for these 4 in PLEDIT.BMP (unlike
   play/stop/etc), so fake the press feedback with a brightness dip. */
#playlist-add:active, #playlist-rem:active, #playlist-sel:active, #playlist-misc:active {
    filter: brightness(0.8);
}

/* Positioned relative to #playlist itself (not .bottom-left) because .bottom
   has overflow:hidden and would clip a menu that pops up above it. */
#playlist-rem-menu {
    position: absolute;
    left: 37px;
    bottom: 38px;
    width: 24px;
    z-index: 50;
}
#playlist-rem-menu.hidden {
    display: none;
}
#playlist-rem-menu > div {
    width: 24px;
    height: 18px;
    cursor: pointer;
}
#playlist .bottom-right {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    width: 150px;
}

#playlist-previous {
    position: absolute;
    height: 9px;
    width: 9px;
    top: 22px;
    left: 5px;
}

#playlist-play {
    position: absolute;
    height: 9px;
    width: 9px;
    top: 22px;
    left: 14px;
}

#playlist-pause {
    position: absolute;
    height: 9px;
    width: 9px;
    top: 22px;
    left: 23px;
}

#playlist-stop {
    position: absolute;
    height: 9px;
    width: 9px;
    top: 22px;
    left: 32px;
}

#playlist-next {
    position: absolute;
    height: 9px;
    width: 9px;
    top: 22px;
    left: 41px;
}

#playlist-eject {
    position: absolute;
    height: 9px;
    width: 9px;
    top: 22px;
    left: 50px;
}
#playlist #playlist-resize-handle {
    position: absolute;
    width: 20px;
    height: 20px;
    bottom: 0px;
    right: 0px;
}

/* Shade View */
#playlist.shade {
    height: 14px;
}

#playlist.shade .bottom,
#playlist.shade .left,
#playlist.shade .right,
#playlist.shade .title
{
    display: none;
}
#playlist.shade .playlist-top-tile {
    background: none;
}

#playlist.shade .top .top-left {
    width: 25px;
    height: 14px;
}
#playlist.shade .top .top-right {
    width: 50px;
    height: 14px;
}
#playlist.shade #tracks {
    top: 0;
    height: 14px;
    background: none;
}
#playlist.shade #tracks li {
    display: none;
    height: 10px;
    margin: 2px 0;
    background: none;
}

#playlist.shade #tracks li.current {
    display: block;
}
