/*
==================================================================
Menus
==================================================================
The site's own menus, drawn as macOS 27 draws a context menu, so the one
the page draws can't be told from the one macOS draws. The page opens
macOS's own where the browser lets it (shared/js/menus.js); it draws this
one where it can't: in Safari, and for the galleries' background menu,
whose Group By and Sort By are submenus, which macOS's menu for a page
can't have.

The metrics are AppKit's, read off live NSMenu windows on macOS 27. The
rows sit 5pt in from the top and bottom: rows 24pt high, separators 11pt
with a 1pt line across the middle. The text is the menu font, 13pt SF, on
a 16pt line 4pt down, 16pt in from the menu's start (AppKit's field is 14pt
in, and draws its text 2pt further) and 16pt short of its end. Where a row
of the menu is ticked, every row's text starts 30pt in, and the tick is the
checkmark symbol at 13pt bold small, its 13×11pt image 12pt in and 7pt
down. A row with a submenu ends in chevron.right at the same size, its
9×12pt image 28pt from the menu's end and 6pt down, and where a row of the
menu has one, every row's text stops 47pt short of the end. So the menu is
its widest text and those margins, rounded up to a whole point. The
highlighted row is a pill 5pt in from the sides, radius 7 (AppKit's corner
is continuous), in the accent colour, its text white. A separator runs from
the text's start to 16pt short of the end. The text is labelColor
(tertiaryLabelColor when the row can't be chosen), and the separator black
at 10% (white at 14.3% in dark), as measured over the glass.

The glass is the menu window's, drawn by the window server, so it is fitted
to AppKit's menu on screen, captured over the galleries themselves and over
plain greys, stripes, checks and blobs. Its corner is round at 12pt. Its
blur isn't one Gaussian: over a wide one, σ 16pt, it keeps a faint sharp
one, σ 4pt, so what lies behind the menu shows through it faintly, as
stripes and edges do through macOS's. So the glass is two layers: the
sharp blur alone (.menu-detail), and over it the wide blur, toned and
filled, at 92% (91.2% in light), the rest of the sharp one showing through.
macOS maps the brightness behind the glass through a curve (in dark, rising
to a cap near 125 and falling past it) and keeps its colour; here a filter
(saturation, then brightness, then contrast, clipped) under a fill stands
in, its brightness past 1 clipping to make the cap. Inside, the page's
glass is within 2 to 4 levels (RMS) of AppKit's, over the galleries and
over stripes and checks alike (one blur left stripes and checks 5 to 8
off); over bright, vivid colours the two part further. The glass adds a
glow along its top and bottom edges (+35, +21, +7 levels down the first
three pixels at 2x in dark, +29, +18, +7 in light), drawn as a glass layer
of the menu's own with the glow added over it. Around it is a dark hairline, a device pixel at 2x, strong at the sides
(72% black in dark, 36% in light) and faint at the top and bottom (1%, 13%).
The shadow is a Gaussian 10pt down, σ 16.6pt, 20.5% black in light and
23.3% in dark.

Near its edge macOS's glass bends what it shows, its blur reading a little
past the menu (shared/js/menus.js, The Glass). In Chrome the whole glass is
the script's SVG filter, both blurs and the bend included (--menu-lens),
its layer reaching 8pt past the menu, cut back to the menu's shape. Safari
can't bend a backdrop, so there a copy of the page behind the menu is bent
instead (.menu-rim), and is the whole glass: bent only near its edge, it
had shown a frame where it met the CSS glass. The CSS glass stays under it
for the moment before the copy is drawn, its blur reading 6pt past the
menu in dark and stopping at its edge in light, the sharp glass 12pt.
The shadow is a layer of its own, so the glass doesn't take it in.

The highlight is the accent colour where the browser tells the page it
(Safari), else macOS's default, which Chrome's AccentColor isn't.

Sizes are CSS px, which are macOS's points.
*/

.context-menu,
.history-menu {
    --menu-glass-fill: rgba(55.3, 55.3, 55.3, 0.684);
    --menu-glass-blur: blur(16px);
    --menu-glass-tone: saturate(1.726) brightness(1.901) contrast(0.946);
    --menu-glass-opacity: 0.92;
    --menu-glass-reach: 6px;
    --menu-detail-blur: blur(4px);
    --menu-detail-reach: 12px;
    --menu-edge: rgba(0, 0, 0, 0.01);
    --menu-edge-sides: rgba(0, 0, 0, 0.72);
    --menu-glow-1: rgba(255, 255, 255, 0.137);
    --menu-glow-2: rgba(255, 255, 255, 0.082);
    --menu-glow-3: rgba(255, 255, 255, 0.027);
    --menu-shadow: rgba(0, 0, 0, 0.233);
    --menu-label: rgba(255, 255, 255, 0.85);
    --menu-label-disabled: rgba(255, 255, 255, 0.25);
    --menu-separator: rgba(255, 255, 255, 0.143);
    --menu-highlight: #007aff;
    --menu-highlight-label: #fff;
    display: none;
    position: fixed;
    z-index: 2000;
    box-sizing: border-box;
    margin: 0;
    padding: 5px 0;
    border: 0;
    border-radius: 12px;
    color: var(--menu-label);
    font: 400 13px/16px system-ui, -apple-system, sans-serif;
    letter-spacing: normal;
    text-align: left;
    text-transform: none;
    white-space: nowrap;
    cursor: default;
    -webkit-user-select: none;
    user-select: none;
}

@media (prefers-color-scheme: light) {

    .context-menu,
    .history-menu {
        --menu-glass-fill: rgba(240.7, 240.7, 240.7, 0.501);
        --menu-glass-tone: saturate(2.358) brightness(1.892) contrast(0.47);
        --menu-glass-opacity: 0.912;
        --menu-glass-reach: 0px;
        --menu-edge: rgba(0, 0, 0, 0.13);
        --menu-edge-sides: rgba(0, 0, 0, 0.264);
        --menu-glow-1: rgba(255, 255, 255, 0.114);
        --menu-glow-2: rgba(255, 255, 255, 0.071);
        --menu-glow-3: rgba(255, 255, 255, 0.027);
        --menu-shadow: rgba(0, 0, 0, 0.205);
        --menu-label: rgba(0, 0, 0, 0.85);
        --menu-label-disabled: rgba(0, 0, 0, 0.26);
        --menu-separator: rgba(0, 0, 0, 0.1);
    }

}

@supports (color: -apple-system-control-accent) {

    .context-menu,
    .history-menu {
        --menu-highlight: -apple-system-control-accent;
    }

}

/* The glass, a layer of the menu's own, so the menu holds what it shows
   and the glow can add to it. It reaches past the menu, so the blur takes
   in what lies past the edge, and is cut back to the menu's shape. Over
   the sharp glass, once the script has drawn it, it lets some through. */
.context-menu::before,
.history-menu::before {
    content: '';
    position: absolute;
    inset: calc(-1 * var(--menu-glass-reach));
    background-color: var(--menu-glass-fill);
    -webkit-backdrop-filter: var(--menu-glass-blur) var(--menu-glass-tone);
    backdrop-filter: var(--menu-glass-blur) var(--menu-glass-tone);
    -webkit-clip-path: inset(var(--menu-glass-reach) round 12px);
    clip-path: inset(var(--menu-glass-reach) round 12px);
    pointer-events: none;
}

.context-menu:has(> .menu-detail)::before,
.history-menu:has(> .menu-detail)::before {
    opacity: var(--menu-glass-opacity);
}

/* The sharp glass, under the toned one: a layer of the menu's own (the
   script's), drawn first. */
.context-menu > .menu-detail,
.history-menu > .menu-detail {
    position: absolute;
    z-index: -1;
    inset: calc(-1 * var(--menu-detail-reach));
    -webkit-backdrop-filter: var(--menu-detail-blur);
    backdrop-filter: var(--menu-detail-blur);
    -webkit-clip-path: inset(var(--menu-detail-reach) round 12px);
    clip-path: inset(var(--menu-detail-reach) round 12px);
    pointer-events: none;
}

/* In Chrome the script's SVG filter (--menu-lens) is the whole glass: its
   blurs, tone, fill, bend and glow. The glow can't be the blended layer
   below there: Chrome makes a menu with a blended layer the root of its
   glass's backdrop, and blurs nothing. */
.context-menu.has-glass-filter,
.history-menu.has-glass-filter {
    --menu-glass-reach: 8px;
}

.context-menu.has-glass-filter::before,
.history-menu.has-glass-filter::before {
    background-color: transparent;
    -webkit-backdrop-filter: var(--menu-lens);
    backdrop-filter: var(--menu-lens);
}

.context-menu.has-glass-filter::after,
.history-menu.has-glass-filter::after {
    display: none;
}

/* Safari's glass: a copy of the page behind the menu, as far past it as
   the blur reaches, which the script's filter turns into the glass (both
   blurs, tone, fill, bend) and cuts to the menu's shape. Nothing clips it,
   or WebKit would blur only the part left showing. A layer of its own, so
   a row lighting up doesn't run the filter again. The script places the
   canvas. */
.context-menu > .menu-rim,
.history-menu > .menu-rim {
    position: absolute;
    inset: 0;
    pointer-events: none;
    will-change: transform;
}

.menu-rim > canvas {
    position: absolute;
}

/* Until the script has drawn this open's copy, after the menu's first frame,
   the last open's isn't shown, nor put through the filter. */
.context-menu.is-awaiting-glass > .menu-rim,
.history-menu.is-awaiting-glass > .menu-rim {
    visibility: hidden;
}

/* The hairline round the menu and its shadow, painted after the glass so
   it doesn't take them in. */
.context-menu > .menu-shadow,
.history-menu > .menu-shadow {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow:
        0 0 0 0.5px var(--menu-edge),
        -0.5px 0 0 0 var(--menu-edge-sides),
        0.5px 0 0 0 var(--menu-edge-sides),
        0 10px 33.3px 0.75px var(--menu-shadow);
    pointer-events: none;
}

/* The glow along the top and bottom edges, which AppKit's glass adds to
   whatever it shows: three device pixels at 2x, fading. */
.context-menu::after,
.history-menu::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background:
        linear-gradient(var(--menu-glow-1) 0 0.5px, var(--menu-glow-2) 0.5px 1px, var(--menu-glow-3) 1px 1.5px, transparent 1.5px) top / 100% 1.5px no-repeat,
        linear-gradient(to top, var(--menu-glow-1) 0 0.5px, var(--menu-glow-2) 0.5px 1px, var(--menu-glow-3) 1px 1.5px, transparent 1.5px) bottom / 100% 1.5px no-repeat;
    mix-blend-mode: plus-lighter;
    pointer-events: none;
}

.context-menu ul,
.history-menu ul {
    position: relative;
    margin: 0;
    padding: 0;
    list-style: none;
}

/* The row's box is its highlight's pill: 5pt in from the sides, so its
   text is 11pt further in. */
.context-menu ul li,
.history-menu ul li {
    position: relative;
    box-sizing: border-box;
    height: 24px;
    margin: 0 5px;
    padding: 4px 11px;
    border-radius: 7px;
    white-space: nowrap;
}

.context-menu ul li:not(.separator):not(.is-disabled):hover,
.context-menu ul li.context-menu-parent.is-open,
.history-menu ul li:hover {
    background-color: var(--menu-highlight);
    color: var(--menu-highlight-label);
}

/* While the script draws a submenu's glass before it opens (gallery.js),
   the menu's rows are lit as they will be then: only the row it opens
   from, not the one under the pointer. */
.context-menu.is-readying-submenu ul li:not(.separator):not(.is-disabled):not(.is-open):hover {
    background-color: transparent;
    color: inherit;
}

.context-menu ul li.separator,
.history-menu ul li.separator {
    height: 11px;
    margin: 0 16px;
    padding: 0;
    border-radius: 0;
    background: linear-gradient(var(--menu-separator), var(--menu-separator)) 0 5px / 100% 1px no-repeat;
}

/* A row that can't be chosen, such as Reverse Order with no key. */
.context-menu ul li.is-disabled {
    color: var(--menu-label-disabled);
    pointer-events: none;
}

/* A menu with a ticked row keeps a column for the tick, as a Mac menu
   does: the submenus, whose current choice is ticked, and the gallery
   menu while Use Suggested Scenes is on (localhost). */
.context-submenu ul li,
.context-menu:has(li.is-checked:not([hidden])) ul li {
    padding-left: 25px;
}

.context-submenu ul li.separator,
.context-menu:has(li.is-checked:not([hidden])) ul li.separator {
    margin-left: 30px;
    padding-left: 0;
}

/* The tick, and the chevron below, are their glyphs' paths cut out of the
   label colour. As SVG images (mask: url(data:...svg)), each new one Safari
   loaded made its next restyle of the page root redo every element: ~190 ms
   on Game of Thrones, at a menu's first open and its first close. */
.context-menu ul li.is-checked::before {
    content: '';
    position: absolute;
    top: 7px;
    left: 7px;
    width: 13px;
    height: 11px;
    background-color: currentColor;
    -webkit-clip-path: path("M5.240 10.000C5.613 10.000 5.905 9.859 6.106 9.562L10.796 2.479C10.942 2.264 11.000 2.059 11.000 1.871C11.000 1.368 10.618 1.000 10.092 1.000C9.733 1.000 9.509 1.125 9.289 1.467L5.218 7.827L3.140 5.260C2.939 5.020 2.719 4.911 2.411 4.911C1.886 4.911 1.500 5.286 1.500 5.794C1.500 6.022 1.571 6.220 1.766 6.444L4.394 9.600C4.628 9.875 4.894 10.000 5.240 10.000Z");
    clip-path: path("M5.240 10.000C5.613 10.000 5.905 9.859 6.106 9.562L10.796 2.479C10.942 2.264 11.000 2.059 11.000 1.871C11.000 1.368 10.618 1.000 10.092 1.000C9.733 1.000 9.509 1.125 9.289 1.467L5.218 7.827L3.140 5.260C2.939 5.020 2.719 4.911 2.411 4.911C1.886 4.911 1.500 5.286 1.500 5.794C1.500 6.022 1.571 6.220 1.766 6.444L4.394 9.600C4.628 9.875 4.894 10.000 5.240 10.000Z");
}

/* A row that opens a submenu: the chevron at its end, and lit while the
   submenu is open. Every row of its menu keeps the chevron's column. */
.context-menu:has(li.context-menu-parent:not([hidden])) ul li:not(.separator) {
    padding-right: 42px;
}

.context-menu ul li.context-menu-parent::after {
    content: '';
    position: absolute;
    top: 6px;
    right: 14px;
    width: 9px;
    height: 12px;
    background-color: currentColor;
    -webkit-clip-path: path("M7.438 6.405C7.434 6.140 7.343 5.925 7.127 5.711L3.436 2.052C3.276 1.888 3.085 1.812 2.853 1.812C2.383 1.812 2.000 2.191 2.000 2.658C2.000 2.888 2.097 3.106 2.273 3.282L5.449 6.402L2.273 9.527C2.100 9.704 2.000 9.918 2.000 10.155C2.000 10.622 2.383 11.000 2.853 11.000C3.082 11.000 3.276 10.924 3.436 10.760L7.127 7.099C7.347 6.884 7.438 6.666 7.438 6.405Z");
    clip-path: path("M7.438 6.405C7.434 6.140 7.343 5.925 7.127 5.711L3.436 2.052C3.276 1.888 3.085 1.812 2.853 1.812C2.383 1.812 2.000 2.191 2.000 2.658C2.000 2.888 2.097 3.106 2.273 3.282L5.449 6.402L2.273 9.527C2.100 9.704 2.000 9.918 2.000 10.155C2.000 10.622 2.383 11.000 2.853 11.000C3.082 11.000 3.276 10.924 3.436 10.760L7.127 7.099C7.347 6.884 7.438 6.666 7.438 6.405Z");
}

.context-submenu {
    z-index: 2001;
}

/* The Back and Forward list: a long one scrolls inside the glass, and a
   long name is cut short, as AppKit cuts it. */
.history-menu {
    max-width: min(448pt, calc(100vw - 16px));
}

.history-menu ul {
    max-height: calc(var(--history-menu-max-height, 100vh) - 10px);
    overflow-y: auto;
}

.history-menu ul li {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Where the browser lets a page open one, the menu is macOS's own: a
   <select> no one sees, placed so its menu opens where the page's would
   (shared/js/menus.js). macOS draws the menu in the select's font size, so
   it is the menu font's, 13pt ("font: menu" is 16px in Chrome). The ID
   outweighs the galleries' template rules for every select. */
#native-menu {
    position: fixed;
    display: block;
    width: 36px;
    height: 20px;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    opacity: 0;
    pointer-events: none;
    font: 13px system-ui, -apple-system, sans-serif;
    -webkit-appearance: none;
    appearance: none;
    transition: none;
}
