/* Photos design system.

   This file is the single source of how the site looks, public and admin.
   It is ordered from general to specific:

     1. Tokens       colours, type, spacing, sizes, radii, shadows, motion
     2. Base         element defaults
     3. Layout       page frame, navigation bar, page and section headings
     4. Components   button, icon button, link, tag, notice, field, segmented
                     control, panel, menu, dialog, hint, disclosure, facts
     5. Gallery      album grid, album layouts, photo page, lightbox
     6. Admin        library, album editor, photo editor, System, Preferences

   Rules that keep it one system (tests/test_design.py checks the first three):
     - Colours, text sizes and radii are only written in section 1. Everywhere
       else uses a token.
     - A control is always one of the components in section 4. Pages don't
       style their own buttons, tags or fields.
     - Buttons: FILLED (.primary) completes a form or dialog; there is at most
       one per form. OUTLINED (default) opens, navigates or acts on the spot.
       QUIET (.quiet) cancels or dismisses. Add .danger when it deletes.
       Every button has an icon and a verb, except Cancel and quiet helpers.
     - Icon-only buttons are for bars, toolbars and controls laid over a photo,
       and only with a familiar icon. They always carry an aria-label and a
       hover hint (data-tip). Everywhere else a control has visible text.
     - The live reference is /studio/design.                                     */

/* ==== 1. Tokens ====================================================================== */
:root {
  /* Colour. Each is light-dark(light, dark). The device decides which applies,
     unless the visitor picked a theme in Preferences (data-theme on <html>). */
  color-scheme: light dark;
  --bg: light-dark(#fafaf9, #0f0f0f);
  --surface: light-dark(#ffffff, #1b1a19);
  --ink: light-dark(#1d1c1a, #ece9e3);
  --muted: light-dark(#6b6862, #a19d95);
  --line: light-dark(#e6e5e2, #2a2928);
  /* The edge of something you can type in or tick: at least 3:1 against the
     page and against a panel, so the control is visible without its label. */
  --field-line: light-dark(#8c877e, #7d7870);
  --accent: light-dark(#8a5a2b, #d6a36b);
  --ok: light-dark(#2f7a45, #6cc28a);
  --ok-soft: light-dark(#e3f2e7, #173322);
  --warn: light-dark(#9a6400, #e2b45c);
  --warn-soft: light-dark(#fbf0d9, #3a2c10);
  --bad: light-dark(#b33a2e, #ef8a7e);
  --bad-soft: light-dark(#f9e2df, #3d1b18);
  --tint: color-mix(in srgb, var(--ink) 6%, transparent);        /* quiet fill, hover */
  --tint-strong: color-mix(in srgb, var(--ink) 12%, transparent);

  /* Colour over a photo or the dark photo stage: the same in both themes. */
  --stage: light-dark(#11100f, #000000);
  --photo-ink: #ffffff;
  --photo-ink-soft: rgb(244 241 235 / 0.72);
  --photo-tint: rgb(255 255 255 / 0.14);
  --photo-scrim: rgb(12 12 11 / 0.58);
  --photo-halo: drop-shadow(0 0 1px rgb(0 0 0 / 0.8)) drop-shadow(0 1px 3px rgb(0 0 0 / 0.5));

  /* Type. Every heading and text size on the site is one of these.
       hero      the site's name over the opening photograph on the home page
       display   a gallery title on the public site (album name)
       page      the title of an admin or settings page
       section   a part of a page ("Health", "Processing")
       title     the name of one item (album card, photo, dialog)
       sub       a card or list inside a section ("Version", "Failed")
       body      running text, controls and form fields
       small     secondary text, hints, rows
       label     the caption above a value (small capitals)
       metric    a number that is the point of its card
       mono      code, file paths, the build tag                              */
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "New York", ui-serif, Georgia, serif;
  --font-body: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, monospace;
  --size-reading: 1rem;
  --size-body: 0.9375rem;
  --size-small: 0.8125rem;
  --size-label: 0.6875rem;
  --text-hero: 400 clamp(1.75rem, 1.2rem + 2.2vw, 3rem)/1.05 var(--font-display);
  --text-display: 400 clamp(1.75rem, 1.35rem + 1.6vw, 2.5rem)/1.1 var(--font-display);
  --text-page: 500 1.625rem/1.15 var(--font-display);
  --text-section: 500 1.25rem/1.25 var(--font-display);
  --text-title: 400 1.125rem/1.3 var(--font-display);
  --text-brand: 500 1.1875rem/1.2 var(--font-display);
  --text-sub: 600 var(--size-body)/1.3 var(--font-body);
  --text-control: 500 var(--size-body)/1 var(--font-body);
  --text-reading: 400 var(--size-reading)/1.55 var(--font-body);
  --text-body: 400 var(--size-body)/1.5 var(--font-body);
  --text-small: 400 var(--size-small)/1.45 var(--font-body);
  --text-label: 500 var(--size-label)/1.3 var(--font-body);
  --text-metric: 600 1.375rem/1.15 var(--font-body);
  --text-mono: 400 var(--size-small)/1.45 var(--font-mono);
  --tracking-label: 0.06em;

  /* Spacing: gaps and paddings are one of these steps. */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --gap: clamp(0.5rem, 1.5vw, 0.875rem);   /* between photos in the gallery */

  /* Sizes. Buttons, fields and segmented controls share one height. */
  --control-h: 2.25rem;
  --control-h-compact: 1.75rem;
  --bar-h: 2.75rem;
  --icon: 1.125rem;         /* inside buttons, fields, menus */
  --icon-small: 0.875rem;   /* inside tags and small text */
  --icon-large: 1.375rem;   /* icon buttons over photos, empty states */
  --wrap: 88rem;
  --measure: 62ch;
  --form: 40rem;            /* widest a one-column form gets */
  /* Field widths: a field is as wide as the value it expects. */
  --field-xs: 4.5rem;       /* a number of up to four digits */
  --field-s: 7rem;          /* a longer number */
  --field-m: 16rem;         /* a short list or a name */

  /* Corners. */
  --radius-image: 4px;      /* photos and covers */
  --radius-control: 8px;    /* buttons, fields, segmented controls, rows */
  --radius-card: 10px;      /* panels and cards */
  --radius-overlay: 14px;   /* menus and dialogs */
  --radius-pill: 999px;     /* tags, the avatar, round icon buttons */

  /* Depth. */
  /* A card raised off the page: a tight contact shadow and a soft wide one.
     "lift" is the same card held up toward you. Darker in the dark theme,
     where a light shadow would not show. */
  --shadow-card: 0 1px 2px light-dark(rgb(0 0 0 / 0.08), rgb(0 0 0 / 0.5)), 0 10px 22px -10px light-dark(rgb(0 0 0 / 0.28), rgb(0 0 0 / 0.8));
  --shadow-card-lift: 0 2px 4px light-dark(rgb(0 0 0 / 0.1), rgb(0 0 0 / 0.55)), 0 28px 44px -14px light-dark(rgb(0 0 0 / 0.42), rgb(0 0 0 / 0.9));
  --card-tilt: 7deg;        /* the most a card leans toward the pointer */
  --card-lift: 0.5rem;      /* how far it rises */
  --card-depth: 55rem;      /* viewing distance: smaller is a stronger 3-D effect */
  --card-glare: rgb(255 255 255 / 0.22);
  --shadow-menu: 0 18px 50px rgb(0 0 0 / 0.18);
  --shadow-dialog: 0 30px 80px rgb(0 0 0 / 0.25);
  --shadow-photo: 0 24px 60px rgb(0 0 0 / 0.45);
  --focus: 2px solid var(--accent);

  /* Motion. */
  --fast: 0.15s ease;
  --settle: 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
/* Fingers need a larger target than a mouse pointer. */
@media (pointer: coarse) { :root { --control-h: 2.75rem; --control-h-compact: 2.25rem; } }

/* ==== 2. Base ======================================================================== */
@view-transition { navigation: auto; }
*, *::before, *::after { box-sizing: border-box; }

/* Room for the scrollbar is kept on every page, whether or not the page is
   long enough to scroll. Without it, the bar and everything under it sat a
   few pixels further left on long pages than on short ones, and jumped when
   moving between them. */
html { overflow-x: clip; scrollbar-gutter: stable; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: var(--text-reading);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: minmax(0, 1fr);  /* content can never widen the page */
}
img { display: block; max-width: 100%; height: auto; }
/* <picture> only chooses the file; layout rules target the <img> inside it. */
picture { display: contents; }
a { color: inherit; text-underline-offset: 0.2em; }
:focus-visible { outline: var(--focus); outline-offset: 2px; }
h1 { font: var(--text-display); margin: 0; text-wrap: balance; }
h2 { font: var(--text-section); margin: 0; }
h3 { font: var(--text-sub); margin: 0; }
p { margin: 0; }
code { font: var(--text-mono); overflow-wrap: anywhere; }
small { display: block; font: var(--text-small); color: var(--muted); }
form { margin: 0; }
.icon { width: var(--icon); height: var(--icon); flex: none; }
.muted { color: var(--muted); }
.small { font: var(--text-small); }
.error-text { color: var(--bad); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.stack { display: grid; gap: var(--space-4); align-content: start; }

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ==== 3. Layout ====================================================================== */
.wrap {
  width: 100%; max-width: var(--wrap); margin-inline: auto;
  padding-inline: max(var(--space-4), env(safe-area-inset-left)) max(var(--space-4), env(safe-area-inset-right));
}
.skip { position: absolute; left: -999px; top: 0; padding: var(--space-2) var(--space-4); background: var(--ink); color: var(--bg); }
.skip:focus { left: var(--space-2); z-index: 40; }
#main { padding-top: var(--space-2); }

/* Navigation bar: one slim frosted bar everywhere. In the admin area it
   carries the admin pages; on the public site the title is the way home.
   The right end always says who is looking: "Sign in", or the owner's name. */
.site-header {
  position: sticky; top: 0; z-index: 20;
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(18px) saturate(1.4);
  border-bottom: 1px solid var(--line);
}
.bar { display: flex; align-items: center; gap: var(--space-3) var(--space-5); min-height: var(--bar-h); }
.brand { flex: 0 1 auto; min-width: 0; font: var(--text-brand); text-decoration: none; }
.brand-text { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-nav { display: flex; align-items: center; align-self: stretch; gap: var(--space-4); margin-right: auto; font: var(--text-body); }
.bar-nav a { position: relative; display: flex; align-items: center; align-self: stretch; color: var(--muted); text-decoration: none; }
.bar-nav a:hover, .bar-nav a[aria-current="page"] { color: var(--ink); }
.bar-nav a[aria-current="page"]::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 2px;
  border-radius: 2px 2px 0 0; background: var(--accent);
}
.bar-tools { display: flex; align-items: center; gap: var(--space-1); flex: none; }
.bar-tools { margin-left: auto; }
.bar-link, .account {
  display: inline-flex; align-items: center; gap: var(--space-2); flex: none;
  height: var(--control-h-compact); padding-inline: var(--space-2); border: 0; border-radius: var(--radius-control);
  background: none; color: var(--muted); font: var(--text-control); text-decoration: none; cursor: pointer;
}
.bar-link:hover, .account:hover { color: var(--ink); background: var(--tint); }
.account { color: var(--ink); background: var(--tint); }
.account:hover { background: var(--tint-strong); }
.account-name { max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 40rem) {
  .bar { gap: var(--space-2) var(--space-3); }
  .site-header[data-area="admin"] .brand { display: none; }      /* the admin pages need the room */
  .bar-link span { display: none; }                               /* icon only; "Sign in" keeps its word */
  .bar-link[href="/login"] span { display: inline; }
  /* Three admin tabs: let them scroll sideways instead of widening the page. */
  .bar-nav { gap: var(--space-3); min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .bar-nav a, .bar-nav .tag { flex: none; }
}

.site-footer { padding-block: var(--space-4) var(--space-3); color: var(--muted); font: var(--text-small); }
.footer-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-2) var(--space-5); }
.build-tag { font: var(--text-mono); color: var(--muted); text-decoration: none; }
.build-tag:hover { color: var(--ink); }

/* Page heading: title on the left, the page's tools or actions on the right.
   Admin and settings pages use the quieter "page" size. */
.page-head {
  display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between;
  gap: var(--space-2) var(--space-6); margin-block: var(--space-2) var(--space-4);
}
/* A gallery title: back arrow, name and a short description share one line. */
.page-head.is-gallery { flex-wrap: nowrap; align-items: center; gap: var(--space-3); margin-block: 0 var(--space-2); }
.page-head.is-gallery .page-tools { flex: none; flex-wrap: nowrap; }
.title-line { display: flex; align-items: baseline; gap: var(--space-1) var(--space-3); min-width: 0; }
.title-line .icon-button { align-self: center; margin-left: calc(var(--space-2) * -1); }
.title-line h1 { font: var(--text-page); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title-line .lede { margin-top: 0; font: var(--text-small); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 40rem) {
  .title-line .lede, .title-line .icon-button { display: none; }   /* the site title is the way back */
  .title-line h1 { white-space: normal; overflow-wrap: anywhere; }
}
.page-head.is-tool { margin-block: var(--space-2) var(--space-4); }
.page-head.is-tool h1 { font: var(--text-page); }
.page-head > :first-child { min-width: 0; }
.page-head h1 { overflow-wrap: anywhere; }
.page-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-3); margin-top: var(--space-1); color: var(--muted); font: var(--text-small); }
.page-tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.lede { color: var(--muted); margin-top: var(--space-2); max-width: var(--measure); text-wrap: pretty; }

/* Section and subsection headings */
.section-h {
  margin: var(--space-5) 0 var(--space-3); padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--line); scroll-margin-top: calc(var(--bar-h) + var(--space-4));
}
.sub-h { margin: var(--space-4) 0 var(--space-2); }
.section-note { margin-top: var(--space-2); font: var(--text-small); color: var(--muted); }
.section-h + .section-note { margin: calc(-1 * var(--space-1)) 0 var(--space-3); }

.empty, .message { color: var(--muted); padding-block: var(--space-7); }
.message h1 { color: var(--ink); margin-bottom: var(--space-3); }
.message p + p { margin-top: var(--space-2); }

/* ==== 4. Components ================================================================== */

/* ---- Button. See the rules at the top for when to use each kind. ---- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: var(--control-h); padding: 0 var(--space-4); white-space: nowrap;
  border: 1px solid var(--line); border-radius: var(--radius-control);
  font: var(--text-control); color: var(--ink); background: var(--surface);
  text-decoration: none; cursor: pointer;
  transition: background var(--fast), border-color var(--fast), color var(--fast);
}
.button:hover { border-color: color-mix(in srgb, var(--ink) 35%, var(--line)); }
.button.primary { color: var(--bg); background: var(--ink); border-color: var(--ink); }
.button.primary:hover { background: color-mix(in srgb, var(--ink) 85%, var(--bg)); }
.button.quiet { background: transparent; border-color: transparent; }
.button.quiet:hover { background: var(--tint); }
.button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.button.danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.button.primary.danger { color: var(--bg); background: var(--bad); border-color: var(--bad); }
.button.primary.danger:hover { background: color-mix(in srgb, var(--bad) 85%, var(--ink)); }
.button:disabled { opacity: 0.5; cursor: progress; }
/* A row of buttons: at the end of a form, a panel or a dialog. */
.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); }

/* ---- Icon button: only the glyph shows; the round area is the target. ---- */
.icon-button {
  display: inline-grid; place-items: center; flex: none;
  width: var(--control-h); height: var(--control-h); padding: 0;
  border: 0; border-radius: var(--radius-pill);
  color: inherit; background: transparent; cursor: pointer; text-decoration: none;
  transition: background var(--fast), opacity var(--fast);
}
.icon-button:hover { background: color-mix(in srgb, currentColor 12%, transparent); }
.icon-button.compact { width: var(--control-h-compact); height: var(--control-h-compact); }
.icon-button.compact .icon { width: var(--icon-small); height: var(--icon-small); }
/* Over a photo or the dark stage: white glyph with a halo, larger target. */
.icon-button.on-photo { width: 2.75rem; height: 2.75rem; color: var(--photo-ink); filter: var(--photo-halo); }
.icon-button.on-photo .icon { width: var(--icon-large); height: var(--icon-large); }
.icon-button.on-photo:hover { background: var(--photo-tint); }
/* On a small tile the target shrinks back to the standard size. */
.icon-button.on-photo.compact { width: var(--control-h); height: var(--control-h); }
.icon-button.on-photo.compact .icon { width: var(--icon); height: var(--icon); }
span.icon-button { visibility: hidden; }  /* keeps a place when there is no previous / next */

/* ---- Hint: the words for an icon-only control, on hover or keyboard focus. ---- */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; top: calc(100% + var(--space-1)); left: 50%; translate: -50% -0.2rem; z-index: 30;
  padding: var(--space-1) var(--space-2); border-radius: var(--radius-control); white-space: nowrap; pointer-events: none;
  font: var(--text-small); font-weight: 500; filter: none;
  color: var(--bg); background: var(--ink);
  opacity: 0; transition: opacity var(--fast), translate var(--fast);
}
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; translate: -50% 0; transition-delay: 0.35s; }
[data-tip].tip-end::after { left: auto; right: 0; translate: 0 -0.2rem; }
[data-tip].tip-end:hover::after, [data-tip].tip-end:focus-visible::after { translate: 0 0; }
[data-tip].tip-top::after { top: auto; bottom: calc(100% + var(--space-1)); }
@media (hover: none) { [data-tip]::after { display: none; } }

/* ---- Link kinds. Plain text links are underlined (the element default). ---- */
/* Back: one step up, above the page title. */
.back { display: inline-flex; align-items: center; gap: var(--space-1); margin-top: var(--space-2); color: var(--muted); font: var(--text-small); text-decoration: none; }
.back:hover { color: var(--ink); }
/* Item link: the name of a thing in a list; underlined only on hover. */
.item-link { font-weight: 500; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-link:hover { text-decoration: underline; }

/* ---- Tag: a short state or count. One shape, five tones. ---- */
.tag {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 0.15rem var(--space-2); border-radius: var(--radius-pill); white-space: nowrap;
  font: var(--text-small); font-weight: 500; text-decoration: none;
  color: var(--ink); background: var(--tint);
}
.tag .icon { width: var(--icon-small); height: var(--icon-small); }
.tag-ok { color: var(--ok); background: var(--ok-soft); }
.tag-warn { color: var(--warn); background: var(--warn-soft); }
.tag-bad { color: var(--bad); background: var(--bad-soft); }
.tag-accent { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.tag-area { font: var(--text-label); font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; }
a.tag:hover { text-decoration: underline; }
/* Laid over a photo: dark glass, white text, in both themes. */
.tag.on-photo { color: var(--photo-ink); background: var(--photo-scrim); backdrop-filter: blur(10px); }
.tag.on-photo.tag-warn { background: color-mix(in srgb, var(--warn) 80%, var(--photo-scrim)); }
.tag.on-photo.tag-bad { background: color-mix(in srgb, var(--bad) 85%, var(--photo-scrim)); }
.tag.on-photo.tag-warn, .tag.on-photo.tag-bad { color: var(--photo-ink); }
/* Status dot */
.dot { display: inline-block; flex: none; width: 0.5rem; height: 0.5rem; border-radius: var(--radius-pill); background: var(--muted); }
.dot-ok { background: var(--ok); }
.dot-warn { background: var(--warn); }
.dot-bad { background: var(--bad); }
.dot-info { background: var(--accent); }

/* ---- Notice: a message about what just happened or what needs attention. ---- */
.notice {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-control);
  font: var(--text-body); background: var(--tint);
}
.notice a { text-decoration: none; }
.notice a:hover { text-decoration: underline; }
.notice-ok { color: var(--ok); background: var(--ok-soft); }
.notice-warn { color: var(--warn); background: var(--warn-soft); }
.notice-bad { color: var(--bad); background: var(--bad-soft); }
.notices { list-style: none; margin: 0 0 var(--space-4); padding: 0; display: grid; gap: var(--space-1); }
#main > .notice { margin-bottom: var(--space-3); }

/* ---- Field: a labelled input. Forms are one column; the label sits above,
        a <small> hint and any error below. Only short values that belong
        together share a row (.field-row). ---- */
label { display: grid; gap: var(--space-1); font: var(--text-sub); font-weight: 500; }
/* :where() keeps this default easy to refine (a sized or affixed field). */
:where(input:not([type="checkbox"], [type="radio"], [type="file"], [type="hidden"])), textarea {
  width: 100%; min-height: var(--control-h); padding: var(--space-2) var(--space-3);
  border: 1px solid var(--field-line); border-radius: var(--radius-control);
  font: var(--text-body); color: var(--ink); background: var(--surface);
}
input:focus-visible, textarea:focus-visible { outline-offset: 0; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: var(--space-2); font: var(--text-sub); font-weight: 500; }
.field { display: grid; gap: var(--space-1); justify-items: start; min-width: 0; }
.field > label { display: block; }
.field-row { display: flex; flex-wrap: wrap; align-items: start; gap: var(--space-3) var(--space-5); }
.w-xs { width: var(--field-xs); }
.w-s { width: var(--field-s); }
.w-m { width: var(--field-m); }
.w-l { width: 100%; }
/* Inside an affix the width is the value's; the unit is added to it. */
.affix > input { flex: none; }
.affix > input.w-l { flex: 1; }
/* A value with its unit inside the field: "150 MB". The unit is also in the
   field's description for screen readers. */
.affix {
  display: flex; align-items: center; max-width: 100%;
  border: 1px solid var(--field-line); border-radius: var(--radius-control); background: var(--surface);
}
.affix:focus-within { outline: var(--focus); outline-offset: 0; }
.affix input { min-width: 0; border: 0; background: transparent; outline: none; padding-right: var(--space-1); }
.affix-unit { flex: none; padding-right: var(--space-3); font: var(--text-small); color: var(--muted); white-space: nowrap; }
/* A field the server refused, with what to fix. */
.has-error input, .has-error textarea, .has-error .affix { border-color: var(--bad); }
.has-error .affix input { border: 0; }
.field-error { font: var(--text-small); font-weight: 400; color: var(--bad); }
/* Checkbox: a yes/no that is stored when the form is saved. (A switch would
   promise an instant effect, so forms don't use one.) */
input[type="checkbox"] { flex: none; width: 1.125rem; height: 1.125rem; margin: 0; accent-color: var(--accent); cursor: pointer; }
label.check { display: flex; align-items: center; gap: var(--space-2); font: var(--text-body); cursor: pointer; }
/* Several ticks from a known list, in columns. */
.checks { display: grid; gap: var(--space-2) var(--space-4); grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr)); }
.checks code { font: var(--text-mono); }

/* ---- Segmented control: pick one of a few. Links (layout switcher) or radios
        (Preferences) look the same. ---- */
.segmented {
  display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 2px;
  border: 1px solid var(--field-line); border-radius: var(--radius-control); background: var(--surface);
}
.segmented > a, .segmented > label > span {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: calc(var(--control-h) - 6px); min-width: calc(var(--control-h) - 6px); padding: 0 var(--space-3);
  border-radius: calc(var(--radius-control) - 2px);
  font: var(--text-control); color: var(--muted); text-decoration: none; cursor: pointer;
  transition: color var(--fast), background var(--fast);
}
.segmented.icons > a { padding: 0; }
/* Many choices: equal cells, three to a row, so a wrap gives full rows. */
.segmented.even { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: min(100%, 27rem); }
.segmented.even > label > span { width: 100%; padding-inline: var(--space-2); }
/* In the bar the control is as low as the bar's other tools. */
.segmented.compact > a { height: calc(var(--control-h-compact) - 6px); min-width: calc(var(--control-h-compact) - 6px); }
.segmented > a:hover, .segmented > label:hover > span { color: var(--ink); }
.segmented > a[aria-current="true"], .segmented > label > input:checked + span { color: var(--bg); background: var(--ink); }
.segmented > label { position: relative; display: block; }
.segmented > label > input { position: absolute; inset: 0; width: 1px; height: 1px; margin: 0; opacity: 0; pointer-events: none; }
.segmented > label > input:focus-visible + span { outline: var(--focus); outline-offset: 2px; }

/* ---- Panel: a card that groups related content. ---- */
.panel { padding: var(--space-4); border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--surface); }
.panel > h3 { margin-bottom: var(--space-3); }
.panel.stack > h3 { margin-bottom: 0; }
.panel > p { margin-top: var(--space-2); }
.panel.narrow { max-width: 24rem; margin: var(--space-7) auto; }
.panel-grid { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr)); align-items: start; }

/* ---- Menu: a native popover (account menu, Sort menu). ---- */
.menu {
  position: fixed; inset: auto; margin: 0;
  top: calc(env(safe-area-inset-top) + var(--bar-h) - var(--space-1));
  /* Lined up with the right end of the bar, which stops at the page width on a wide window. */
  right: max(var(--space-4), env(safe-area-inset-right), calc((100vw - var(--wrap)) / 2 + var(--space-4)));
  min-width: 14rem; padding: var(--space-1); border: 1px solid var(--line); border-radius: var(--radius-overlay);
  color: var(--ink); background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(20px) saturate(1.4); box-shadow: var(--shadow-menu);
  opacity: 0; translate: 0 -0.4rem;
  transition: opacity var(--fast), translate var(--settle), display 0.25s allow-discrete, overlay 0.25s allow-discrete;
}
.menu:popover-open { opacity: 1; translate: 0; }
@starting-style { .menu:popover-open { opacity: 0; translate: 0 -0.4rem; } }
.menu-label { padding: var(--space-2) var(--space-3); margin-bottom: var(--space-1); border-bottom: 1px solid var(--line); font: var(--text-small); color: var(--muted); }
.menu-label strong { color: var(--ink); font-weight: 500; }
.menu-item {
  display: flex; align-items: center; gap: var(--space-2); width: 100%; height: var(--control-h); padding: 0 var(--space-3);
  border: 0; border-radius: var(--radius-control); background: none; color: inherit; text-decoration: none;
  font: var(--text-body); text-align: left; cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--tint); outline: none; }
.menu-item .icon { color: var(--muted); }
/* In a menu of choices, the tick marks the current one. */
.menu-item .icon-check { visibility: hidden; color: var(--accent); }
.menu-item[aria-current="true"] .icon-check { visibility: visible; }
/* Each menu opens right under its own button. */
@supports (position-area: block-end) {
  .account { anchor-name: --account; }
  .menu-account {
    position-anchor: --account; top: auto; right: auto; margin-top: var(--space-1);
    position-area: block-end span-inline-start;
    position-try-fallbacks: flip-block, flip-inline;
  }
  .sort-button { anchor-name: --sort-button; }
  .menu-anchored {
    position-anchor: --sort-button; top: auto; right: auto; margin-top: var(--space-1);
    position-area: block-end span-inline-start;
    position-try-fallbacks: flip-block, flip-inline;
  }
}

/* ---- Dialog: a native modal <dialog class="dialog">. Always a title with a
        close button, the content, then Cancel and one filled action. ---- */
dialog.dialog {
  width: min(32rem, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem);
  padding: var(--space-5); border: 1px solid var(--line); border-radius: var(--radius-overlay);
  color: var(--ink); background: var(--surface); box-shadow: var(--shadow-dialog);
  opacity: 0; translate: 0 0.75rem;
  transition: opacity var(--fast), translate var(--settle), display 0.25s allow-discrete, overlay 0.25s allow-discrete;
}
dialog.dialog[open] { opacity: 1; translate: 0; }
@starting-style { dialog.dialog[open] { opacity: 0; translate: 0 0.75rem; } }
dialog.dialog::backdrop { background: rgb(0 0 0 / 0.4); backdrop-filter: blur(3px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); margin: calc(-1 * var(--space-1)) calc(-1 * var(--space-2)) 0 0; }
.dialog-head h2 { font: var(--text-title); font-size: 1.25rem; }
dialog.dialog p { color: var(--muted); font: var(--text-body); }
dialog.dialog .actions { margin-top: var(--space-2); }

/* ---- Disclosure: a list that opens on demand. ---- */
.disclosure { margin-top: var(--space-4); }
.disclosure summary { display: flex; align-items: center; gap: var(--space-2); width: fit-content; cursor: pointer; list-style: none; }
.disclosure summary::-webkit-details-marker { display: none; }
.disclosure summary .icon { width: var(--icon-small); height: var(--icon-small); color: var(--muted); transition: rotate var(--fast); }
.disclosure[open] summary .icon { rotate: 90deg; }
.disclosure[open] summary { margin-bottom: var(--space-2); }
.disclosure summary h2 { font: var(--text-section); }
.settings .disclosure { margin-top: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--line); }
.settings .disclosure .section-note { margin: 0 0 var(--space-2); }

/* ---- Facts: label and value pairs; stats: the numbers that matter. ---- */
.facts { margin: var(--space-3) 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2) var(--space-4); }
.panel > h3 + .facts { margin-top: 0; }
.panel > .facts:first-child { margin-top: 0; }
.facts.one-col { grid-template-columns: 1fr; }
.facts > div:last-child:nth-child(odd) { grid-column: 1 / -1; }  /* a lone last fact gets the full row */
.facts dt, .stats dt { display: flex; align-items: center; gap: var(--space-1); font: var(--text-label); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--muted); }
.facts dt .icon { width: var(--icon-small); height: var(--icon-small); }
.facts dd { margin: 0; font: var(--text-small); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.facts .is-private { grid-column: 1 / -1; padding: var(--space-2) var(--space-3); border-radius: var(--radius-control); background: var(--warn-soft); }
.facts .is-private dt, .facts .is-private dd { color: var(--warn); }
.stats { margin: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-2); }
.stats > div { padding: var(--space-2) var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--surface); }
.panel .stats > div { border: 0; background: var(--tint); }
.stats dd { margin: var(--space-1) 0 0; font: var(--text-metric); font-variant-numeric: tabular-nums; }
.stats .is-bad { background: var(--bad-soft); color: var(--bad); }
.stats .is-bad dt { color: var(--bad); }
.metric { margin-bottom: var(--space-2); font: var(--text-metric); font-variant-numeric: tabular-nums; }
.metric .muted { font: var(--text-small); }
@media (max-width: 40rem) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---- Rows: a bordered list of items, each with a thumbnail, text and state. ---- */
.rows { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--surface); overflow: hidden; }
.row { display: grid; grid-template-columns: var(--control-h) minmax(0, 1fr) auto; gap: var(--space-3); align-items: center; padding: var(--space-2) var(--space-3); font: var(--text-body); }
.row + .row { border-top: 1px solid var(--line); }
.row.is-bad { background: color-mix(in srgb, var(--bad-soft) 45%, transparent); }
.row-thumb { display: grid; place-items: center; width: var(--control-h); height: var(--control-h); border-radius: var(--radius-image); overflow: hidden; background: var(--line); color: var(--muted); }
.row-thumb img { width: 100%; height: 100%; object-fit: cover; }
.row-main { display: grid; gap: 0.1rem; min-width: 0; }
.row-main code { display: block; margin-top: var(--space-1); white-space: normal; }
.row-meta { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--space-1) var(--space-3); }
@media (max-width: 40rem) {
  .row { grid-template-columns: var(--control-h) minmax(0, 1fr); }
  .row-meta { grid-column: 2; justify-content: flex-start; }
}

/* ==== 5. Gallery ===================================================================== */

/* The opening of the home page: one photograph as wide as the album grid
   below it and about a third of the window tall, so the first albums are
   still in view. The site's name sits over its lower left. Without any photo
   yet it is just the name. */
.opening { position: relative; margin-bottom: var(--gap); overflow: hidden; border-radius: var(--radius-image); background: var(--stage); }
.opening-photo { display: block; height: clamp(11rem, 36svh, 24rem); }
.opening-photo img { width: 100%; height: 100%; object-fit: cover; object-position: var(--fx, 50%) var(--fy, 50%); }
/* The part of a photo to keep in view when it is cropped, in steps of 10
   (the owner sets it in the Studio; a class per step keeps it out of inline styles). */
.fx-0 { --fx: 0%; } .fx-10 { --fx: 10%; } .fx-20 { --fx: 20%; } .fx-30 { --fx: 30%; } .fx-40 { --fx: 40%; } .fx-50 { --fx: 50%; } .fx-60 { --fx: 60%; } .fx-70 { --fx: 70%; } .fx-80 { --fx: 80%; } .fx-90 { --fx: 90%; } .fx-100 { --fx: 100%; }
.fy-0 { --fy: 0%; } .fy-10 { --fy: 10%; } .fy-20 { --fy: 20%; } .fy-30 { --fy: 30%; } .fy-40 { --fy: 40%; } .fy-50 { --fy: 50%; } .fy-60 { --fy: 60%; } .fy-70 { --fy: 70%; } .fy-80 { --fy: 80%; } .fy-90 { --fy: 90%; } .fy-100 { --fy: 100%; }
.opening-text {
  position: absolute; inset: auto 0 0 0; padding: var(--space-7) var(--space-4) var(--space-4); pointer-events: none;
  color: var(--photo-ink); background: linear-gradient(transparent, var(--photo-scrim) 90%);
}
.opening-text h1, .opening-name { margin: 0; font: var(--text-hero); text-shadow: 0 1px 12px var(--photo-scrim); }
.opening-text p { margin-top: var(--space-1); color: var(--photo-ink-soft); font: var(--text-body); }
.opening.is-plain { background: none; }
.opening.is-plain .opening-text { position: static; padding: var(--space-5) 0 var(--space-3); color: var(--ink); background: none; }
.opening.is-plain .opening-text h1 { text-shadow: none; }
.opening.is-plain .opening-text p { color: var(--muted); }

/* Album grid (public home) */
.albums {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr));
}
/* The album's name is written on its cover, so the grid is all photograph. */
.album-card a { position: relative; display: block; text-decoration: none; }
.album-card .cover { margin-bottom: 0; }
.album-caption {
  position: absolute; inset: auto 0 0 0; display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-7) var(--space-3) var(--space-3); border-radius: 0 0 var(--radius-image) var(--radius-image);
  color: var(--photo-ink); background: linear-gradient(transparent, var(--photo-scrim) 80%);
}
.album-card .album-name { font: var(--text-section); text-shadow: 0 1px 3px var(--photo-scrim); }
.album-card .album-count { color: var(--photo-ink-soft); }
.cover {
  position: relative; display: grid; place-items: center; aspect-ratio: 4 / 3; overflow: hidden;
  margin-bottom: var(--space-2); border-radius: var(--radius-image); background: var(--line);
}
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: scale 0.5s ease; }
a:hover > .cover img { scale: 1.03; }
.cover-empty { display: grid; place-items: center; width: 100%; height: 100%; color: var(--muted); }
.cover-empty .icon { width: var(--space-6); height: var(--space-6); }
.album-name { font: var(--text-title); }
.album-count { color: var(--muted); font: var(--text-small); font-variant-numeric: tabular-nums; }

/* Album layouts. Every layout keeps DOM order = reading order = lightbox
   order. The visitor's choice is the ul's view-* class (see gallery.js). */
.photos { list-style: none; margin: 0; padding: 0; }
.photos a { display: block; border-radius: var(--radius-image); overflow: hidden; background: var(--line); }
.photos img { transition: opacity var(--fast); }
.photos a:hover img { opacity: 0.88; }
.story-caption, .photos .card-caption { display: none; }

/* Cards ("baseball cards"): every card is the same upright 4:5 shape. The
   picture fills the top edge to edge; under it sit two lines: the title with
   its year, then a tag and one fact. Used for photos in an album (.view-cards)
   and for albums on the home page (.albums.as-cards). */
.view-cards, .albums.as-cards { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(min(46%, 15rem), 1fr)); }
.view-cards li, .albums.as-cards .album-card a {
  display: grid; grid-template-rows: minmax(0, 1fr) auto; aspect-ratio: 4 / 5; overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--surface);
}
/* Depth. Every card rests on a shadow, raised off the page. Under a mouse
   pointer it lifts and leans toward the pointer, the picture shifts a little
   the other way (so it seems to sit behind the card's surface), and a soft
   light follows the pointer across it. gallery.js reports where the pointer
   is as --px and --py (-1 to 1 across and down the card) and --gx, --gy for
   the light. Touch screens and "reduce motion" get the shadow only. */
.view-cards li, .albums.as-cards .album-card a {
  --px: 0; --py: 0;
  position: relative; box-shadow: var(--shadow-card);
  transition: transform var(--settle), box-shadow var(--settle);
}
.view-cards li::after, .albums.as-cards .album-card a::after {
  content: ""; position: absolute; inset: 0; z-index: 2; border-radius: inherit; pointer-events: none;
  background: radial-gradient(circle at var(--gx, 50%) var(--gy, 0%), var(--card-glare), transparent 55%);
  opacity: 0; transition: opacity var(--settle);
}
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .view-cards li.is-tilting, .albums.as-cards .album-card a.is-tilting {
    z-index: 1; box-shadow: var(--shadow-card-lift);
    transform: perspective(var(--card-depth)) translateY(calc(var(--card-lift) * -1))
      rotateX(calc(var(--py) * var(--card-tilt) * -1)) rotateY(calc(var(--px) * var(--card-tilt)));
    transition: box-shadow var(--settle);   /* follows the pointer at once; settles back smoothly */
  }
  .is-tilting::after { opacity: 1; }
  .view-cards li img, .albums.as-cards .cover img { transition: transform var(--settle), scale 0.5s ease, opacity var(--fast); }
  .view-cards li.is-tilting img, .albums.as-cards a.is-tilting .cover img {
    scale: 1.06; transform: translate(calc(var(--px) * -1.5%), calc(var(--py) * -1.5%));
  }
}
/* Phone-width cards have no room for the camera name beside the exposure. */
@media (max-width: 40rem) { .view-cards .card-facts .tag:not(:only-child) { display: none; } }
.view-cards a { border-radius: 0; }
.view-cards a, .view-cards img { height: 100%; }
.view-cards img { width: 100%; object-fit: cover; }
.albums.as-cards .cover { aspect-ratio: auto; height: 100%; border-radius: 0; }
.view-cards .card-caption, .albums.as-cards .card-caption { display: grid; gap: var(--space-1); padding: var(--space-2) var(--space-3) var(--space-3); min-width: 0; }
/* In an album every caption is the same height, so every picture is too. */
.view-cards .card-line:first-child { align-items: start; min-height: calc(2 * 1.3 * var(--size-body)); }
.view-cards .card-year { margin-left: auto; }
.card-facts { min-height: 1.5rem; }
.card-title.is-placeholder { color: var(--muted); font-weight: 400; }
.card-line { display: flex; align-items: baseline; gap: var(--space-2); min-width: 0; margin: 0; }
/* When a line is too long, the camera name gives way before the exposure. */
.card-line .tag { align-self: center; display: block; flex: 0 1000 auto; min-width: 2.5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-title { min-width: 0; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; font: var(--text-sub); color: var(--ink); text-wrap: balance; }
.card-year, .card-fact { flex: none; color: var(--muted); font: var(--text-small); font-variant-numeric: tabular-nums; }
.card-fact { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Rows: justified rows; each photo keeps its shape, rows stretch slightly. */
.view-rows { display: flex; flex-wrap: wrap; gap: var(--gap); --row: clamp(9rem, 22vw, 15rem); }
.view-rows::after { content: ""; flex-grow: 999; }  /* keeps the last row from stretching */
.view-rows li { flex: 1 1 auto; height: var(--row); min-width: 6rem; }
.view-rows a { height: 100%; }
.view-rows img { height: 100%; width: auto; min-width: 100%; max-width: none; object-fit: cover; }

/* Grid: even square tiles, cropped to fill. */
.view-grid { display: grid; gap: calc(var(--gap) / 2); grid-template-columns: repeat(auto-fill, minmax(min(30%, 11rem), 1fr)); }
.view-grid a { aspect-ratio: 1; border-radius: 0; }
.view-grid img { width: 100%; height: 100%; object-fit: cover; }

/* Masonry: a few wide columns, every photo in its own shape, nothing cropped.
   Wide columns make the differences in height read as intended, not as a
   grid that slipped. gallery.js places each photo in the shortest column, to
   the pixel (the grid's rows are 1px tall), so columns stay balanced and the
   order still reads left to right. Until the script has run, or without it,
   tiles sit in order at a typical 3:2 shape. */
.view-masonry { --cols: 2; display: grid; column-gap: var(--gap); grid-auto-rows: 1px; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); }
@media (min-width: 56rem) { .view-masonry { --cols: 3; } }
.view-masonry li { position: relative; grid-row-end: span 300; padding-bottom: var(--gap); }
.view-masonry a, .view-masonry img { height: 100%; }
.view-masonry img { width: 100%; object-fit: cover; transition: scale var(--settle), opacity var(--fast); }
.view-masonry a:hover img { opacity: 1; scale: 1.025; }
/* The photo's title rises over it on hover or keyboard focus. */
.view-masonry .story-caption {
  display: block; position: absolute; inset: auto 0 var(--gap) 0; padding: var(--space-6) var(--space-3) var(--space-3);
  border-radius: 0 0 var(--radius-image) var(--radius-image); pointer-events: none;
  color: var(--photo-ink); background: linear-gradient(transparent, var(--photo-scrim) 85%);
  opacity: 0; translate: 0 0.35rem; transition: opacity var(--fast), translate var(--settle);
}
.view-masonry .story-caption:not(:has(.story-title)) { display: none; }
.view-masonry .story-caption > :not(.story-title) { display: none; }
.view-masonry .story-title { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.view-masonry li:hover .story-caption, .view-masonry li:focus-within .story-caption { opacity: 1; translate: 0; }
/* Touch screens have no hover: the title is in the viewer's details instead. */
@media (hover: none) { .view-masonry .story-caption { display: none; } }

/* Story: one photo at a time, large, with its caption. */
.view-story { display: grid; gap: clamp(2.5rem, 6vw, 4.5rem); margin-inline: calc(50% - 50vw); }
.view-story a { background: transparent; }
.view-story a { border-radius: 0; }
.view-story img { width: 100%; height: auto; max-height: calc(100dvh - var(--bar-h)); object-fit: contain; }
.view-story .story-caption { display: block; margin: var(--space-3) auto 0; max-width: var(--measure); padding-inline: var(--space-4); }
.story-title { font: var(--text-title); }
.story-meta { color: var(--muted); font: var(--text-small); margin-top: 0.15rem; }
.story-desc { margin-top: var(--space-2); text-wrap: pretty; }

/* Single photo page: the page is the viewer. The photo gets the whole window,
   nothing scrolls, and there is no site bar or footer. It uses the viewer's
   own pieces (lb-stage, lb-tools, lb-nav, lb-close), so the two cannot drift
   apart. */
html:has(.photo-view) { overflow: hidden; scrollbar-gutter: auto; }   /* the viewer takes the whole window */
.photo-view {
  position: fixed; inset: 0; z-index: 30;
  display: grid; grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr);
  color: var(--photo-ink); background: var(--stage);
}
.photo-page .site-footer { display: none; }

/* Details panel: frosted glass over the photo (native popover, top layer) */
.info-panel {
  position: fixed; inset: auto max(var(--space-4), env(safe-area-inset-right)) 5.5rem auto; margin: 0;
  width: min(22rem, calc(100vw - 2rem)); max-height: calc(100dvh - 8rem); overflow: auto; overscroll-behavior: contain;
  padding: var(--space-5) var(--space-5) var(--space-4);
  border: 1px solid var(--photo-tint); border-radius: var(--radius-overlay);
  color: var(--photo-ink); background: var(--photo-scrim);
  backdrop-filter: blur(24px) saturate(1.5); box-shadow: var(--shadow-photo);
  opacity: 0; translate: 0 0.75rem;
  transition: opacity var(--fast), translate var(--settle), display 0.25s allow-discrete, overlay 0.25s allow-discrete;
}
.info-panel:popover-open { opacity: 1; translate: 0; }
@starting-style { .info-panel:popover-open { opacity: 0; translate: 0 0.75rem; } }
.info-panel::backdrop { background: transparent; }
.info-title { margin-bottom: var(--space-1); font: var(--text-title); text-wrap: balance; }
.info-desc { color: var(--photo-ink-soft); font: var(--text-body); text-wrap: pretty; }
.info-list { margin: var(--space-4) 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3) var(--space-4); }
.info-list:empty { display: none; }
.info-list dt { color: var(--photo-ink-soft); font: var(--text-label); letter-spacing: var(--tracking-label); text-transform: uppercase; }
.info-list dd { margin: 0.15rem 0 0; font: var(--text-body); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.info-tags { list-style: none; padding: 0; margin: var(--space-4) 0 0; display: flex; flex-wrap: wrap; gap: var(--space-1); }
.info-link { display: inline-flex; align-items: center; gap: var(--space-2); margin-top: var(--space-4); color: var(--photo-ink-soft); font: var(--text-small); text-decoration: none; }
.info-link:hover { color: var(--photo-ink); }
@media (max-width: 40rem) {
  /* Bottom sheet on phones */
  .info-panel { inset: auto var(--space-3) max(var(--space-3), env(safe-area-inset-bottom)) var(--space-3); width: auto; max-height: 70dvh; }
}

/* Lightbox: fills the window exactly; nothing scrolls, the page behind is locked */
html:has(dialog.lightbox[open]) { overflow: hidden; scrollbar-gutter: auto; }
.lightbox {
  position: fixed; inset: 0;
  width: 100%; height: 100%; max-width: 100%; max-height: 100%;
  margin: 0; padding: 0; border: 0; overflow: hidden;
  color: var(--photo-ink); background: var(--stage);
}
.lightbox[open] { display: grid; grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); }
.lightbox::backdrop { background: var(--stage); }
.lb-stage {
  min-width: 0; min-height: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  /* No margins on any device: the photo gets every pixel of the window. The
     arrows, the count, the "i" and Close sit over it. */
  padding: 0;
}
/* The photo always fills the stage and is fitted inside it. Its size never
   depends on which file the browser picked, so every photo is shown as large
   as the window allows on every device. */
.lb-stage img {
  width: 100%; height: 100%; min-width: 0; min-height: 0;
  object-fit: contain; user-select: none; touch-action: pan-y;
  view-transition-name: lightbox-photo;
}
/* The only things over the photo: the count and the "i" that opens its details. */
.lb-tools {
  position: absolute; display: flex; align-items: center; gap: var(--space-2);
  bottom: max(var(--space-3), env(safe-area-inset-bottom)); right: max(var(--space-3), env(safe-area-inset-right));
}
.lb-count { font-variant-numeric: tabular-nums; }
.lb-nav, .lb-close { position: absolute; }
.lb-close { top: max(var(--space-3), env(safe-area-inset-top)); right: max(var(--space-3), env(safe-area-inset-right)); }
.lb-nav { top: 50%; translate: 0 -50%; }
.lb-prev { left: max(var(--space-3), env(safe-area-inset-left)); }
.lb-next { right: max(var(--space-3), env(safe-area-inset-right)); }
.lb-nav[disabled] { visibility: hidden; }
@media (hover: none) { .lb-nav { display: none; } }
/* The details panel opens just above the count and the "i". */
.lightbox .info-panel, .photo-view .info-panel { bottom: calc(max(var(--space-3), env(safe-area-inset-bottom)) + 3.25rem); }
/* Keep the details panel clear of the › arrow where the arrows are shown. */
@media (hover: hover) and (min-width: 40.01rem) {
  .lightbox .info-panel, .photo-view .info-panel { right: calc(max(var(--space-4), env(safe-area-inset-right)) + 3.75rem); }
}

/* ==== 6. Admin ======================================================================= */

/* Library: album cards */
.album-cards {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: var(--space-5) var(--space-4);
  grid-template-columns: repeat(auto-fill, minmax(min(46%, 15rem), 1fr));   /* two across on a phone */
}
.album-card-admin, .album-card-new { display: grid; gap: 0.15rem; width: 100%; text-decoration: none; color: inherit; }
.album-card-admin:focus-visible { outline: none; }
.album-card-admin:focus-visible .cover { outline: var(--focus); outline-offset: 3px; }
/* Choosing the home page's opening photograph: the crop as it will look, and
   the whole photo to click on. The mark shows the part that stays in view. */
.opening-editor { display: grid; gap: var(--space-5); margin-bottom: var(--space-4); }
/* Wide screens: the photo to click on the left, the result beside it, so a
   click and its effect are seen together. */
@media (min-width: 60rem) {
  .opening-editor { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); align-items: start; }
  .opening-editor > section { order: 2; position: sticky; top: calc(var(--bar-h) + var(--space-4)); }
}
.opening-editor .section-h { margin-top: 0; }
.opening-text .opening-name { margin: 0; color: var(--photo-ink); font: var(--text-hero); }
.opening-preview { margin-bottom: 0; }
.focus-stage {
  position: relative; display: block; width: fit-content; max-width: 100%; padding: 0; border: 0;
  border-radius: var(--radius-image); overflow: hidden; background: var(--stage); cursor: crosshair;
}
.focus-stage img { display: block; max-width: 100%; max-height: 60svh; width: auto; height: auto; }
.focus-stage:focus-visible { outline: var(--focus); outline-offset: 3px; }
.focus-mark {
  position: absolute; left: 50%; top: 50%; width: var(--space-6); height: var(--space-6); translate: -50% -50%;
  border: 2px solid var(--photo-ink); border-radius: var(--radius-pill); pointer-events: none;
  background: var(--photo-tint); filter: var(--photo-halo);
}

.pick-albums { display: flex; flex-wrap: wrap; gap: var(--space-1); margin-bottom: var(--space-3); }
.pick-albums a { text-decoration: none; }
.tile-pick { position: absolute; inset: 0; padding: 0; border: 0; background: none; cursor: pointer; }
.tile-pick img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: scale 0.4s ease; }
.tile-pick:hover img { scale: 1.03; }
.tile-pick:focus-visible { outline: var(--focus); outline-offset: -3px; }

/* Reordering: a handle on each card; the card being moved is lifted. */
.album-cards li { position: relative; }
.reorder-handle {
  position: absolute; z-index: 2; top: var(--space-2); right: var(--space-2);
  background: var(--photo-scrim); backdrop-filter: blur(8px); cursor: grab; touch-action: none;
}
.reorder-handle:active { cursor: grabbing; }
.album-cards li.is-moving { opacity: 0.55; outline: var(--focus); outline-offset: 3px; border-radius: var(--radius-image); }
.album-cards:has(.is-moving) { cursor: grabbing; user-select: none; }
.album-cards .cover-tags { right: calc(var(--control-h) + var(--space-3)); }
.cover-tags { position: absolute; inset: var(--space-2) var(--space-2) auto; display: flex; flex-wrap: wrap; gap: var(--space-1); }
.album-card-new { padding: 0; border: 0; background: none; font: inherit; text-align: left; color: var(--muted); cursor: pointer; }
.album-card-new .cover { background: transparent; border: 1.5px dashed var(--line); transition: border-color var(--fast), color var(--fast); }
.album-card-new:hover .cover { border-color: var(--accent); }
.album-card-new:hover { color: var(--accent); }

/* Upload drop zone */
.dropzone-form { margin-bottom: var(--space-5); }
.dropzone {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--space-1) var(--space-3);
  padding: var(--space-4); border: 1.5px dashed var(--line); border-radius: var(--radius-card);
  color: var(--muted); font: var(--text-body); text-align: center; cursor: pointer;
  transition: border-color var(--fast), background var(--fast), color var(--fast);
}
.dropzone strong { color: var(--ink); font-weight: 500; }
.dropzone small { flex-basis: 100%; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); color: var(--ink); background: color-mix(in srgb, var(--accent) 5%, transparent); }
.dropzone:focus-within { outline: var(--focus); outline-offset: 2px; }
.dropzone.busy { pointer-events: none; opacity: 0.6; }
.upload-list { list-style: none; margin: var(--space-3) 0 0; padding: 0; display: grid; gap: var(--space-2); font: var(--text-small); }
.upload-list li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(5rem, 10rem) minmax(0, 14rem); gap: var(--space-3); align-items: center; }
.upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-list progress { width: 100%; height: 0.35rem; accent-color: var(--accent); }
.upload-state { color: var(--muted); }
.upload-list .done .upload-state { color: var(--ok); }
.upload-list .failed .upload-state { color: var(--bad); }
@media (max-width: 40rem) { .upload-list li { grid-template-columns: 1fr; gap: var(--space-1); } }

/* Photo tiles (album editor) */
.tiles {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: var(--space-2);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 10.5rem), 1fr));
}
.tile { position: relative; aspect-ratio: 1; border-radius: var(--radius-image); overflow: hidden; background: var(--line); }
.tile-img { position: absolute; inset: 0; display: grid; place-items: center; text-decoration: none; }
.tile-img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: scale 0.4s ease; }
.tile:hover .tile-img img { scale: 1.03; }
.tile-state { padding: var(--space-3); font: var(--text-small); color: var(--muted); text-align: center; }
.tile-state.is-failed { color: var(--bad); }
.tile-select {
  position: absolute; top: var(--space-2); left: var(--space-2); z-index: 2;
  display: grid; place-items: center; width: calc(var(--icon) + var(--space-3)); height: calc(var(--icon) + var(--space-3));
  border-radius: var(--radius-pill); background: var(--photo-scrim); backdrop-filter: blur(8px); cursor: pointer;
  opacity: 0; transition: opacity var(--fast);
}
.tile:hover .tile-select, .tile-select:focus-within, .tiles:has(input:checked) .tile-select { opacity: 1; }
/* Selection ring drawn in a layer above the photo */
.tile::after {
  content: ""; position: absolute; inset: 0; z-index: 3; border-radius: inherit; pointer-events: none;
  box-shadow: inset 0 0 0 3px transparent; transition: box-shadow var(--fast);
}
.tile:has(input:checked)::after { box-shadow: inset 0 0 0 3px var(--accent); }
.tile > .tag { position: absolute; top: var(--space-2); right: var(--space-2); z-index: 2; }
.tile-bar {
  position: absolute; inset: auto 0 0 0; z-index: 1;
  display: flex; align-items: center; gap: var(--space-1); padding: var(--space-5) var(--space-1) var(--space-1) var(--space-2);
  color: var(--photo-ink); background: linear-gradient(transparent, var(--photo-scrim));
  opacity: 0; translate: 0 0.35rem; transition: opacity var(--fast), translate var(--fast);
}
.tile:hover .tile-bar, .tile:focus-within .tile-bar { opacity: 1; translate: 0; }
@media (hover: none) { .tile-bar { opacity: 1; translate: 0; } .tile-select { opacity: 1; } }
.tile-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: var(--text-small); }
.tile-name .icon { width: var(--icon-small); height: var(--icon-small); vertical-align: -0.1em; }
.tile-actions { display: flex; }

/* Floating bar: sticks to the bottom of the window while there is something
   to act on (selected photos, unsaved changes). */
.floating-bar {
  position: sticky; bottom: max(var(--space-4), env(safe-area-inset-bottom)); z-index: 5;
  width: fit-content; max-width: 100%; margin: var(--space-4) auto 0;
  display: flex; align-items: center; gap: var(--space-2); white-space: nowrap;
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  border: 1px solid var(--line); border-radius: var(--radius-overlay);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(20px) saturate(1.4);
  box-shadow: var(--shadow-menu);
}
.floating-bar[hidden] { display: none; }
.floating-bar > span { margin-right: var(--space-2); font: var(--text-body); font-variant-numeric: tabular-nums; }
/* The selection bar appears only while photos are selected (no JS needed). */
#bulk .floating-bar { display: none; }
#bulk:has(input[name="photo_ids"]:checked) .floating-bar { display: flex; }

@media (max-width: 40rem) {
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-1); }
  /* Phones: keep the star and edit icons, drop the filename */
  .tile-bar { justify-content: flex-end; }
  .tile-name { display: none; }
  .tile > .tag { top: auto; bottom: var(--space-1); right: var(--space-1); }
}

/* Photo editor */
.photo-editor { display: grid; gap: var(--space-4); align-items: start; grid-template-columns: minmax(0, 1fr) minmax(18rem, 24rem); }
@media (max-width: 60rem) { .photo-editor { grid-template-columns: minmax(0, 1fr); } }
.editor-stage {
  position: relative; margin: 0; display: grid; place-items: center;
  min-height: 18rem; padding: clamp(0.5rem, 2vw, 1rem); border-radius: var(--radius-card);
  background: var(--stage);
}
.editor-stage img { max-width: 100%; max-height: calc(100dvh - 14rem); width: auto; height: auto; border-radius: var(--radius-image); }
.editor-nav { position: absolute; top: 50%; translate: 0 -50%; }
.editor-prev { left: var(--space-2); }
.editor-next { right: var(--space-2); }
.editor-stage > .tag { position: absolute; bottom: var(--space-2); left: 50%; translate: -50% 0; font-variant-numeric: tabular-nums; }
.editor-side { display: grid; gap: var(--space-3); }
.job-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-3); }
.job-list li { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }
.job-list form { margin-left: auto; }
.job-list code { flex-basis: 100%; }

/* System: health, one compact line per service; details only for a problem */
.health { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); }
.health-item {
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 0 var(--space-2);
  padding: var(--space-2) var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--surface);
}
.health-item.is-warn { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.health-item.is-bad { border-color: color-mix(in srgb, var(--bad) 55%, var(--line)); background: color-mix(in srgb, var(--bad-soft) 50%, var(--surface)); }
.health-name { font: var(--text-sub); }
.health-summary { grid-column: 2; font: var(--text-small); color: var(--muted); }
.health-item .facts { grid-column: 1 / -1; }

/* Settings and Preferences are the same page design: section headings, each
   with a panel whose fields sit side by side, as many as fit. Settings adds
   a list of its sections on the left. */
.settings { display: grid; gap: var(--space-6); grid-template-columns: 11rem minmax(0, 1fr); align-items: start; }
.settings > form, .settings-main { min-width: 0; }
.settings .section-h:first-child { margin-top: 0; }
/* Fields sit side by side, as many as fit; a long list of ticks takes a whole line. */
.settings .panel.stack { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr)); gap: var(--space-5) var(--space-6); align-items: start; }
.settings .panel.stack > fieldset.w-l, .settings .panel.stack > .actions { grid-column: 1 / -1; }
.settings.is-single { grid-template-columns: minmax(0, 1fr); }   /* no section list beside it */
/* The home page's opening, shown at the top of Settings. */
.opening-summary { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-4) var(--space-5); }
.opening-summary .opening { flex: 1 1 18rem; max-width: 30rem; margin: 0; }
.opening-summary .opening-photo { height: 7rem; }
.opening-summary > div:not(.opening) { flex: 1 1 14rem; display: grid; gap: var(--space-2); justify-items: start; }
/* Section list: jumps within a long page and shows where you are. */
.section-nav { position: sticky; top: calc(var(--bar-h) + var(--space-4)); display: grid; gap: 2px; font: var(--text-body); }
.section-nav a { padding: var(--space-1) var(--space-3); border-radius: var(--radius-control); color: var(--muted); text-decoration: none; }
.section-nav a:hover { color: var(--ink); background: var(--tint); }
.section-nav a[aria-current="true"] { color: var(--ink); background: var(--tint); font-weight: 500; }
.section-nav hr { width: 100%; margin: var(--space-2) 0; border: 0; border-top: 1px solid var(--line); }
@media (max-width: 52rem) {
  .settings { grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
  .section-nav { position: static; display: flex; flex-wrap: wrap; gap: var(--space-1); }
  .section-nav hr { display: none; }
}

/* Design reference (/studio/design) */
.specimen { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.specimen-stage { padding: var(--space-4); border-radius: var(--radius-card); background: var(--stage); }
.swatches { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr)); }
.swatch { display: grid; gap: var(--space-1); font: var(--text-small); }
.swatch > span { height: var(--control-h); border: 1px solid var(--line); border-radius: var(--radius-control); }
.type-sample { display: grid; grid-template-columns: 6rem minmax(0, 1fr); align-items: baseline; gap: var(--space-2) var(--space-4); }
.type-sample dt { font: var(--text-mono); color: var(--muted); }
.type-sample dd { margin: 0; }
.sw-bg > span { background: var(--bg); } .sw-surface > span { background: var(--surface); }
.sw-ink > span { background: var(--ink); } .sw-muted > span { background: var(--muted); }
.sw-line > span { background: var(--line); } .sw-accent > span { background: var(--accent); }
.sw-ok > span { background: var(--ok); } .sw-ok-soft > span { background: var(--ok-soft); }
.sw-warn > span { background: var(--warn); } .sw-warn-soft > span { background: var(--warn-soft); }
.sw-bad > span { background: var(--bad); } .sw-bad-soft > span { background: var(--bad-soft); }
.sw-stage > span { background: var(--stage); }
.t-display { font: var(--text-display); } .t-page { font: var(--text-page); } .t-section { font: var(--text-section); }
.t-title { font: var(--text-title); } .t-sub { font: var(--text-sub); } .t-body { font: var(--text-body); }
.t-small { font: var(--text-small); } .t-metric { font: var(--text-metric); } .t-mono { font: var(--text-mono); }
.t-label { font: var(--text-label); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--muted); }
