:root {
    --mobile-nav-height: 80px;
}

/* ─── Sidebar widths ──────────────────────────────────────────────
   Two states. Collapsed = icon-only (with native tooltips via title attr),
   expanded = icon + label. Toggling adds/removes the label column without
   reflowing the rest of the page since the sidebar is position:fixed and the
   layout grid below holds a column for it. */
.menu {
    --sidebar-w-collapsed: 80px;
    --sidebar-w-expanded: 165px;
    --sidebar-w: var(--sidebar-w-collapsed);

    height: 65px;
    overflow: hidden;
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr 60px;
    font: bold 17px/1 Helvetica, Arial, sans-serif;
    transition: grid-template-columns 0.18s ease;

    &.menu--expanded {
        --sidebar-w: var(--sidebar-w-expanded);
    }

    .sidebar {
        /* Icon state vars - each item flips --m-fill and --m-inner via the .selected
           override below, so SVGs reference the vars unconditionally and the template
           no longer needs an if/else twin block per icon.
             --m-stroke = outer outline colour (always white)
             --m-fill   = outer fill: transparent unselected, white selected
             --m-inner  = inner detail (smile, eyes, arrow, #): white unselected so it
                          matches the outline, dark when the outer goes white so the
                          inner reads as inverted-through-the-fill. */
        --m-stroke: #fff;

        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: var(--sidebar-w);
        z-index: 30;
        overflow: hidden;
        background: image-set(
            url('/artwork/v2/1_350.avif') type('image/avif'),
            url('/artwork/v2/1_350.jpg')  type('image/jpeg')
        ) right top / cover no-repeat;
        transition: width 0.18s ease;

        &::after {
            content: '';
            position: absolute;
            inset: 0;
            backdrop-filter: blur(30px);
            background-color: rgba(0,0,0,0.4);
        }

        .items {
            position: relative;
            z-index: 2;
            padding: 25px 10px 20px;
            cursor: pointer;
            display: flex;
            flex-direction: column;
            height: 100vh;
            box-sizing: border-box;
            justify-content: space-between;

            .top-items {
                display: flex;
                flex-direction: column;
                gap: 4px;
            }

            .bottom-items {
                display: flex;
                flex-direction: column;
            }

            .item {
                /* Per-item state for the icon fill/inner pair. .selected flips both. */
                --m-fill: transparent;
                --m-inner: #fff;

                border-radius: 13px;
                padding: 10px 10px;
                display: flex;
                align-items: center;
                gap: 12px;
                color: #fff;
                text-decoration: none;
                opacity: 0.5;
                transition: opacity 0.15s, background-color 0.15s;

                &.selected {
                    opacity: 1;
                    --m-fill: #fff;
                    --m-inner: rgba(0, 0, 0, 0.75);
                }

                &:not(.selected):hover {
                    opacity: 0.85;
                }

                &[style*="display: none"] {
                    display: none;
                }

                .item-icon {
                    flex: 0 0 auto;
                    width: 40px;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                }

                .item-label {
                    font-size: 0.9375rem;
                    font-weight: 400;
                    letter-spacing: 0.5px;
                    white-space: nowrap;
                    overflow: hidden;
                    line-height: 1.3em;
                }

                svg {
                    width: 38px;
                }

                .blockie-thumb {
                    width: 38px;
                    height: 38px;
                    border-radius: 6px;
                    overflow: hidden;
                    display: block;

                    svg {
                        width: 38px;
                        height: 38px;
                        display: block;
                    }
                }
            }
        }

        /* Collapse handle. Sits on the inside-right edge of the rail, vertically centered. */
        .sidebar-toggle {
            position: absolute;
            top: 50%;
            right: 4px;
            transform: translateY(-50%);
            z-index: 3;
            width: 22px;
            height: 44px;
            padding: 0;
            border: 0;
            background: rgba(255,255,255,0.08);
            color: #fff;
            border-radius: 6px;
            cursor: pointer;
            opacity: 0.55;
            transition: opacity 0.15s, background-color 0.15s;

            &:hover {
                opacity: 1;
                background: rgba(255,255,255,0.18);
            }

            svg {
                width: 16px;
                height: 16px;
                display: block;
                margin: 0 auto;
            }
        }
    }

    /* Collapsed: hide labels, return to centered icon layout. */
    &.menu--collapsed .sidebar .items .item {
        justify-content: center;
        padding: 10px 0;

        .item-label {
            display: none;
        }
    }

    /* ─── Mobile top nav ─────────────────────────────────────────
       Hidden by default (desktop uses the left sidebar). The @media
       block below flips the visibility below 900px. Placed at the top
       so iOS Safari's collapsing bottom chrome doesn't cause the bar
       to hover over disappearing viewport. */
    .mobile-nav {
        /* Same state-driven pattern as .sidebar above (see comments there). */
        --mn-stroke: #fff;

        display: none;
        position: fixed;
        left: 0;
        right: 0;
        top: -1px;
        height: var(--mobile-nav-height);
        z-index: 40;
        background: rgba(30, 33, 42, 0.88);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-bottom: 1px solid rgba(255,255,255,0.08);
        padding: 0 4px;
        padding-top: env(safe-area-inset-top, 0);
        box-sizing: content-box;
        justify-content: space-around;
        align-items: center;
        color: #fff;

        .mn-item {
            --mn-fill: transparent;
            --mn-inner: #fff;

            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100%;
            opacity: 0.6;
            cursor: pointer;
            transition: opacity 0.15s;
            -webkit-tap-highlight-color: transparent;

            &.selected,
            &.open,
            &:active {
                opacity: 1;
            }

            &.selected {
                --mn-fill: #fff;
                --mn-inner: rgba(0, 0, 0, 0.55);
            }

            &.hidden {
                visibility: hidden;
                pointer-events: none;
            }

            /* Per-icon sizing balances the visual height across the bar. The four
               SVGs have different content extents inside their viewBoxes (hamburger
               lines occupy ~10/24 units, pin path fills ~32/32, hex shapes ~23/25),
               so a single CSS width would render them at noticeably different sizes.
               These targets pull all four to roughly the same on-screen height. */
            svg {
                width: 40px;
                height: 40px;
            }

            &.hamburger svg {
                width: 44px;
                height: 44px;
            }

            &.detail svg {
                width: 36px;
                height: 40px;
            }
        }
    }

    /* ─── Hamburger sheet ────────────────────────────────────────
       Slides up from the bottom nav. Closed state is hidden but present
       in DOM so the transform transition can animate. */
    .menu-sheet-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 39;
        background: rgba(0,0,0,0.4);

        &.open {
            display: block;
        }

        .menu-sheet {
            position: absolute;
            left: 0;
            right: 0;
            top: calc(var(--mobile-nav-height) + env(safe-area-inset-top, 0px));
            background: #fff;
            border-radius: 0 0 18px 18px;
            padding: 18px 16px 10px;
            box-shadow: 0 8px 24px rgba(0,0,0,0.22);
            max-height: 80vh;
            overflow-y: auto;
            display: flex;
            flex-direction: column;
            gap: 8px;

            .sheet-handle {
                width: 40px;
                height: 4px;
                background: #d0d4dc;
                border-radius: 2px;
                margin: 12px auto 4px;
                flex-shrink: 0;
                order: 1;
            }

            .sheet-item {
                display: flex;
                align-items: center;
                justify-content: space-between;
                gap: 12px;
                min-height: 35px;
                padding: 14px 18px;
                background: #f4f6fa;
                border-radius: 12px;
                font: 600 17px/1.2 '-apple-system', BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
                color: #1f2a32;
                cursor: pointer;
                -webkit-tap-highlight-color: transparent;
                transition: background-color 0.12s, transform 0.08s;

                .sheet-item-label {
                    flex: 1;
                    min-width: 0;
                }

                .sheet-item-arrow {
                    width: 18px;
                    height: 18px;
                    flex-shrink: 0;
                    color: #8a94a6;
                }

                &:active {
                    background: #e6ebf3;
                    transform: scale(0.985);
                }

                &.selected {
                    background: #ede4f9;
                    color: #5b2a96;

                    .sheet-item-arrow {
                        color: #7b42b8;
                    }
                }
            }
        }
    }
}

@media (max-width: 900px) {
    .menu .sidebar {
        display: none;
    }

    .menu .mobile-nav {
        display: flex;
    }
}