/* Page grid: side panel left, waveform bar on top, stage (now playing,
   transport) over the full-screen visualizer. On phones and in portrait the
   panel becomes a full-screen overlay that slides away to reveal the player. */

.jukebox {
    --panel-width: minmax(18rem, 40%);
    --panel-rail: 1.75rem;

    position: relative;
    display: grid;
    grid-template-columns: var(--panel-width) 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "panel waveform"
        "panel stage";
    height: 100dvh;
    overflow: hidden;
    isolation: isolate;
    background: linear-gradient(0deg, #000 0%, #044e02 47%, #000 100%);
    transition: grid-template-columns 300ms ease;

    &.is-panel-collapsed {
        grid-template-columns: var(--panel-rail) 1fr;
    }
}

.visualizer {
    position: absolute;
    inset: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.side-panel {
    grid-area: panel;
    position: relative;
    display: flex;
    min-width: 0;
    min-height: 0;
    border-right: 2px solid #000;
    background-image: var(--kp-panel-bg);
    box-shadow: var(--kp-shadow);
}

.side-panel__content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    padding: var(--kp-gap) calc(var(--kp-gap) + var(--panel-rail)) var(--kp-gap) var(--kp-gap);

    .is-panel-collapsed & {
        visibility: hidden;
    }
}

/* The handle on the panel's right edge (wide screens). */
.panel-collapse {
    position: absolute;
    inset: 0 0 0 auto;
    width: var(--panel-rail);
    padding: 0;
    border: 0;
    border-left: 1px solid rgb(255 255 255 / 0.08);
    background: rgb(0 0 0 / 0.35);
    color: var(--kp-text-muted);

    &:hover {
        background: rgb(19 145 0 / 0.35);
        color: #fff;
    }

    &:focus-visible {
        outline-offset: -3px;
    }
}

.panel-collapse__icon::before {
    content: "‹";
    font-family: system-ui, sans-serif;
    font-size: 2.2rem;
    font-weight: 800;
    line-height: 1;
}

/* Not nested: `&` can't stand for a pseudo-element. */
.is-panel-collapsed .panel-collapse__icon::before {
    content: "›";
}

.tabs-row {
    display: flex;
    gap: 0.4rem;
    margin-bottom: var(--kp-gap);

    & .tabs {
        flex: 1;
        margin-bottom: 0;
    }
}

/* Phone-only buttons between the panel overlay and the player. */
.panel-to-player,
.panel-to-library {
    display: none;
    min-height: 2.75rem;
    padding: 0 0.9rem;
    border: 1px solid #0f2602;
    color: #fff;
    font-weight: 700;
    background: linear-gradient(var(--kp-green-300), var(--kp-green-700));
    box-shadow: inset 0 1px 0 0 #92d480;
}

.stage {
    grid-area: stage;
    /* The logo fills the space left of the 40rem now-playing card: its width is
       what's left after the card and some air (none when there's no room), and
       calc(50% - 20rem) centres it in that space (a percentage position aligns
       the image within the area minus its own width). */
    background: url("../../images/kentaiplogo.png") calc(50% - 20rem) center / clamp(0px, calc(100% - 42rem), 30rem) auto no-repeat;
    position: relative;
    display: grid;
    place-items: center;
    min-height: 0;
    padding: var(--kp-gap);
}

.stage .placeholder,
.placeholder {
    padding: 1rem;
    color: var(--kp-text-muted);
}

@media (orientation: portrait), (max-width: 56rem) {
    .jukebox {
        --panel-drag: 0px;

        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr;
        grid-template-areas:
            "library"
            "stage"
            "waveform";
        height: auto;
        min-height: 100dvh;
        overflow: visible;
        transition: none;

        &.is-panel-collapsed {
            grid-template-columns: 1fr;
        }
    }

    /* Full-screen overlay; slid out to the left when the player is shown. */
    .side-panel {
        position: fixed;
        inset: 0;
        z-index: 40;
        border-right: 0;
        translate: var(--panel-drag) 0;
        transition: translate 250ms ease;
        touch-action: pan-y;

        .is-panel-collapsed & {
            translate: calc(-100% + var(--panel-drag)) 0;
        }

        .is-dragging & {
            transition: none;
        }
    }

    .side-panel__content {
        overflow-y: auto;
        overscroll-behavior: contain;
        padding-right: var(--kp-gap);

        .is-panel-collapsed & {
            visibility: visible;
        }
    }

    .panel-collapse {
        display: none;
    }

    .panel-to-player {
        display: inline-flex;
        align-items: center;
        gap: 0.4rem;
    }

    .panel-to-library {
        grid-area: library;
        justify-self: start;
        align-self: center;
        display: inline-flex;
        align-items: center;
        gap: 0.4rem;
        margin: var(--kp-gap) var(--kp-gap) 0;
    }

    .tab-panel {
        overflow: visible;
    }
}

@media (prefers-reduced-motion: reduce) {
    .jukebox,
    .side-panel {
        transition: none !important;
    }
}
