/* The ribbon (design/ribbon-and-media.md): pinned to the top of the page, a frosted glass bar with the
   badge and name on the left and the buttons on the right. Below 48em the buttons don't fit on one
   row, so they move into a drawer that the menu button slides in from the right. */

.ribbon {
    --menu-ms: 300ms;  /* ribbon.js reads this to time hiding the drawer */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 8;  /* under the About Us sheet (10) and the photo viewer (30) */
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: calc(var(--ribbon-h) + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) max(var(--gutter), env(safe-area-inset-right, 0px)) 0 max(var(--gutter), env(safe-area-inset-left, 0px));
}

/* The glass is a layer behind the ribbon, not the ribbon itself: a backdrop-filter on the ribbon
   would make the fixed drawer inside it fill the ribbon instead of the screen. */
.ribbon::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: rgba(18, 18, 22, 0.55);
    border-bottom: 1px solid rgba(255, 255, 255, 0.14);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    backdrop-filter: blur(14px) saturate(140%);
}

.ribbon-home {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: #fff;
    text-decoration: none;
    border-radius: var(--radius);
    -webkit-tap-highlight-color: transparent;
}

.ribbon-badge {
    flex: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

.ribbon-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ribbon-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Text links on the glass; the button and the links look identical. */
.ribbon-btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    margin: 0;
    padding: 0.6em 0.9em;
    font: 600 1rem/1 var(--font);
    letter-spacing: 0.02em;
    white-space: nowrap;
    color: rgba(255, 255, 255, 0.88);
    text-decoration: none;
    background: transparent;
    border: 0;
    border-radius: var(--radius);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.2s, color 0.2s;
}

.ribbon-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
}

/* Photos / Videos under Media (B-14): a drop-down that shows while Media is hovered or the keyboard
   is on it or its items. */
.ribbon-menu {
    position: relative;
    display: flex;
}

.ribbon-submenu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 150px;
    padding: 6px;
    background: rgba(22, 22, 26, 0.94);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: var(--radius);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    visibility: hidden;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.15s, transform 0.15s, visibility 0s linear 0.15s;
}

/* Bridges the gap above, so the pointer can move down from Media without the menu closing. */
.ribbon-submenu::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: -10px;
    height: 10px;
}

.ribbon-menu:hover .ribbon-submenu,
.ribbon-menu:focus-within .ribbon-submenu {
    visibility: visible;
    opacity: 1;
    transform: none;
    transition: opacity 0.15s, transform 0.15s, visibility 0s;
}

.ribbon-home:focus-visible,
.ribbon-btn:focus-visible,
.menu-btn:focus-visible,
.menu-close:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 2px;
}

/* Only in the drawer layout below. */
.menu-btn,
.menu-close,
.menu-backdrop { display: none; }

/* While the drawer is open the page behind doesn't scroll. */
body.menu-open { overflow: hidden; }

@media (max-width: 48em) {
    .menu-btn {
        appearance: none;
        flex: none;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        margin: 0;
        padding: 0;
        font: 400 1.4rem/1 var(--font);
        color: #fff;
        background: rgba(255, 255, 255, 0.10);
        border: 1px solid rgba(255, 255, 255, 0.25);
        border-radius: var(--radius);
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .menu-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1;
        background: rgba(0, 0, 0, 0);
        transition: background-color var(--menu-ms) ease;
    }

    .menu-backdrop[hidden] { display: none; }

    .menu-backdrop.is-open { background: rgba(0, 0, 0, 0.5); }

    /* The drawer: hidden off the right edge (and from the keyboard) until it's opened. */
    .ribbon-nav {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        z-index: 2;
        width: min(300px, 82vw);
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        padding: calc(env(safe-area-inset-top, 0px) + 68px) max(16px, env(safe-area-inset-right, 0px)) 24px 16px;
        background: rgba(22, 22, 26, 0.94);
        border-left: 1px solid rgba(255, 255, 255, 0.14);
        box-shadow: -8px 0 32px rgba(0, 0, 0, 0.45);
        -webkit-backdrop-filter: blur(14px) saturate(140%);
        backdrop-filter: blur(14px) saturate(140%);
        visibility: hidden;
        transform: translateX(100%);
        transition: transform var(--menu-ms) cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear var(--menu-ms);
    }

    .ribbon-nav.is-open {
        visibility: visible;
        transform: translateX(0);
        transition: transform var(--menu-ms) cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s;
    }

    .ribbon-nav .ribbon-btn {
        padding: 14px 16px;
        font-size: 1.15rem;
    }

    /* In the drawer, Photos and Videos are always there, indented under Media. visibility inherits
       so they stay hidden with the closed drawer. */
    .ribbon-menu { flex-direction: column; }

    .ribbon-submenu {
        position: static;
        min-width: 0;
        margin-left: 16px;
        padding: 0 0 0 8px;
        background: none;
        border: 0;
        border-left: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: 0;
        box-shadow: none;
        visibility: inherit;
        opacity: 1;
        transform: none;
        transition: none;
    }

    .ribbon-submenu::before { display: none; }

    .ribbon-nav .ribbon-subbtn {
        padding: 10px 16px;
        font-size: 1.05rem;
    }

    .menu-close {
        appearance: none;
        display: block;
        position: absolute;
        top: calc(env(safe-area-inset-top, 0px) + 8px);
        right: 12px;
        width: 44px;
        height: 44px;
        margin: 0;
        padding: 0;
        font: 400 1.9rem/1 var(--font);
        color: #fff;
        background: transparent;
        border: 0;
        border-radius: 50%;
        cursor: pointer;
    }

    .menu-close:hover { background: rgba(255, 255, 255, 0.1); }
}

/* The drawer slides for everyone, like the About Us sheet; only the hover fade is dropped. */
@media (prefers-reduced-motion: reduce) {
    .ribbon-btn,
    .ribbon-menu .ribbon-submenu { transition: none; }
}
