.main {
    width: 100%;
    height: 100vh;
    display: flex;
    overflow: hidden;
    justify-content: center;
}


.container {
    display: flex;
    max-width: 880px;
    width: 100%;
    flex-direction: row;
}

nav {
    width: 96px;
    background-color: var(--surface-container-lowest);
    align-self: center;
    margin: 0 var(--spacing-16);
    padding: var(--spacing-24) 0;
    border-radius: var(--radius-48);
}

.page {
    flex: 1;
    overflow-y: scroll;
    overflow-x: hidden;
    padding: var(--spacing-16);
    overscroll-behavior-y: contain;
}

button { touch-action: manipulation; }

nav ul { padding: 0; }
nav ul li { list-style: none; width: 100%; }

nav ul li a {
    --nav-item-padding-y: 12px;
    display: block;
    font-size: var(--label-medium);
    color: var(--on-surface);
    text-decoration: none;
    padding: var(--nav-item-padding-y) 0;
    opacity: 0.7;
}

a.nav-active { opacity: 1; position: relative; }

/* Pill sits behind the icon as its own layer so the icon's dark-mode recolor
   filter (brightness/invert) doesn't also invert this background to white.
   top matches the link's own padding-top so it lines up with the icon
   (which sits right after that padding), not the top edge of the link. */
a.nav-active::before {
    content: '';
    position: absolute;
    top: var(--nav-item-padding-y);
    left: 50%;
    transform: translateX(-50%);
    width: 56px;
    height: 28px;
    background-color: var(--secondary-container);
    border-radius: var(--radius-48);
    z-index: -1;
}


nav ul li a span {
    width: 100%;
    display: block;
    text-align: center;
    padding-top: var(--spacing-6);
}

nav ul li img {
    width: 56px;
    height: 28px;
    display: block;
    margin: 0 auto;
    padding: var(--spacing-4) var(--spacing-16);
    border-radius: var(--radius-48);
}

/* Inactive nav icons rendered as pure black in light mode; active icons keep their natural SVG colour */
nav ul li a:not(.nav-active) img { filter: brightness(0); }

/* In dark mode: inactive icons invert to white; active icons also invert so they're
   readable on the dark --secondary-container (#564040) pill background */
[data-theme="dark"] nav ul li img { filter: brightness(0) invert(1); }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) nav ul li img { filter: brightness(0) invert(1); }
}

/* All icon <img> elements use brightness(0) in light mode to render as pure black,
   then invert in dark mode to render as white. */
.custom-select-chevron,
.drag-handle,
.btn-back img,
.search-clear img,
.ingredient-exclude img { filter: brightness(0); }

[data-theme="dark"] .custom-select-chevron,
[data-theme="dark"] .drag-handle,
[data-theme="dark"] .btn-back img,
[data-theme="dark"] .search-clear img,
[data-theme="dark"] .ingredient-exclude img { filter: brightness(0) invert(1); }

/* Active filter chip chevron must also invert in dark mode */
[data-theme="dark"] .custom-select-wrap.filter-active .custom-select-chevron { filter: brightness(0) invert(1); }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .custom-select-chevron,
    :root:not([data-theme="light"]) .drag-handle,
    :root:not([data-theme="light"]) .btn-back img,
    :root:not([data-theme="light"]) .search-clear img,
    :root:not([data-theme="light"]) .ingredient-exclude img { filter: brightness(0) invert(1); }
    :root:not([data-theme="light"]) .custom-select-wrap.filter-active .custom-select-chevron { filter: brightness(0) invert(1); }
}

nav ul li a:hover .nav-img { background: var(--on-surface-variant-opacity-0-08); }

/* ── Custom select (filter chip) ── */
.custom-select-wrap {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-4);
    position: relative;
    cursor: pointer;
    padding: 10px 14px;
    border: 1px solid var(--outline-variant);
    border-radius: 20px;
    background: transparent;
    flex-shrink: 0;
    transition: var(--default-transition);
}
.custom-select-wrap:hover { background: var(--primary-opacity-0-08); }
.custom-select-wrap:active { background: var(--primary-opacity-0-12); }

/* Active filter — a non-default value is selected */
.custom-select-wrap.filter-active {
    background: var(--secondary-container);
    border-color: var(--primary);
}
.custom-select-wrap.filter-active:hover  { box-shadow: inset 0 0 0 9999px var(--on-surface-variant-opacity-0-08); }
.custom-select-wrap.filter-active:active { box-shadow: inset 0 0 0 9999px var(--on-surface-variant-opacity-0-12); }

.custom-select-label {
    font-family: "Manrope-SemiBold", Arial, Helvetica, sans-serif;
    font-size: var(--body-medium);
    color: var(--on-surface-variant);
    white-space: nowrap;
    pointer-events: none;
}
.custom-select-wrap.filter-active .custom-select-label { color: var(--on-surface-variant); }

.custom-select-chevron {
    width: 10px;
    height: 6px;
    flex-shrink: 0;
    pointer-events: none;
}
.custom-select-native {
    position: absolute;
    inset: 0;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

@media screen and (max-width: 800px) {
    nav {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        border-radius: 0;
        border-top: 1px solid var(--outline-variant);
        margin: 0;
        padding: 0 0 calc(var(--spacing-8) + env(safe-area-inset-bottom)) 0;
        display: flex;
        z-index: 20;
        background: var(--surface-container-lowest);
    }
    nav ul { width: 100%; align-self: center; display: flex; margin: 0; }
    nav ul li { float: left; flex: 1; }
    nav ul li a { --nav-item-padding-y: 10px; width: 100%; padding: var(--nav-item-padding-y) 0; }

    /* ::after instead of padding-bottom — iOS Safari ignores padding-bottom on overflow:scroll */
    .page::after {
        content: '';
        display: block;
        height: calc(180px + env(safe-area-inset-bottom));
        pointer-events: none;
    }
}

/* ── Desktop layout ──────────────────────────────────────────────────────────
   Nav: fixed pill, pinned vertically centred in the viewport.
   Page: document scrolls naturally so the wheel works anywhere on the screen.
   Content height hugs its content — no forced 100vh on the page column.
   ─────────────────────────────────────────────────────────────────────────── */
@media (min-width: 801px) {
    /* Let the document scroll; removes the need for a specific scroll container */
    .main { height: auto; min-height: 100vh; overflow: visible; }

    /* Nav pill: fixed to viewport, always centred vertically.
       left tracks the left edge of the centred 880px container. */
    nav {
        position: fixed;
        top: 50%;
        transform: translateY(-50%);
        left: max(var(--spacing-24), calc(50vw - 464px + var(--spacing-16)));
    }

    /* Compensate for the fixed nav being out of flow:
       push page content right by nav-width (96px) + both side margins (2×16px).
       overflow-x: clip (not hidden) avoids creating an implicit scroll container
       that would swallow wheel events when hovering over the page column. */
    .page {
        overflow-y: visible;
        overflow-x: clip;
        padding-left: calc(96px + var(--spacing-16) * 2);
    }
}
