/* sigal-fgallery viewer.
 *
 * Layout is almost entirely CSS. Every thumbnail carries its precomputed box and
 * crop offset for both rail orientations as custom properties, and a single
 * aspect-ratio media query picks between them -- so the rail reflows on resize
 * with no JavaScript involved, and is correct on first paint.
 */

:root {
  --bg: #111;
  --fg: #fff;
  --rail-bg: rgba(255, 255, 255, 0.08);
  --accent: #e33;
  --pad: 22px;
  --fade: 320ms;
  --chrome-fade: 200ms;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: inherit; text-decoration: none; }

/* A leaf album is nothing but the viewer, so it pins to the viewport. An index
   page embeds the same viewer as one full-height block in a scrolling document. */
#gallery {
  position: relative;
  height: 100dvh;
  display: grid;
  overflow: hidden;
}

body.viewer-only { overflow: hidden; }
body.viewer-only #gallery { position: fixed; inset: 0; height: auto; }

/* ------------------------------------------------------------------ backdrop */

#backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  opacity: 0.55;
  transition: opacity var(--fade) ease;
}

/* Grain, so the heavily-upscaled backdrop does not band. Generated, not an asset. */
#grain {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.22;
  background-image: var(--grain);
}

/* --------------------------------------------------------------------- stage */

#stage {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

#frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  padding: var(--pad);
}

#frame img {
  position: absolute;
  max-width: calc(100% - var(--pad) * 2);
  max-height: calc(100% - var(--pad) * 2);
  box-shadow: 0 0 2.5em rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity var(--fade) ease;
}

#frame img.current { opacity: 1; }
#frame img.zoomable { cursor: zoom-in; }

/* ------------------------------------------------------------------- caption */

#caption {
  position: absolute;
  right: 0;
  bottom: 5%;
  z-index: 4;
  max-width: 80%;
  padding: 0.6em 5% 0.6em 12%;
  text-align: right;
  background: linear-gradient(
    to left,
    rgba(0, 0, 0, 0.72) 60%,
    rgba(0, 0, 0, 0.5) 78%,
    rgba(0, 0, 0, 0)
  );
  opacity: 0;
  transition: opacity var(--fade) ease;
  pointer-events: none;
}

#caption.visible { opacity: 1; }
#caption:empty { display: none; }

#caption h2 {
  margin: 0;
  font-size: clamp(1.1rem, 4.4vh, 2.6rem);
  font-weight: 600;
  line-height: 1.15;
}

#caption p {
  margin: 0.25em 0 0;
  font-size: clamp(0.85rem, 2.2vh, 1.3rem);
  white-space: pre-wrap;
  opacity: 0.85;
}

/* Camera data: a glance, not prose. Smaller and dimmer than the description, and
 * tabular figures so shutter and ISO do not jitter as images change. */
#caption .meta {
  margin: 0.45em 0 0;
  font-size: clamp(0.7rem, 1.5vh, 0.95rem);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  opacity: 0.6;
}

/* ------------------------------------------------------------------- chrome */

#chrome {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 5;
  display: flex;
  gap: 0.75em;
  align-items: center;
  padding: 0.5em 0.75em;
  background: rgba(0, 0, 0, 0.62);
  border-bottom-right-radius: 4px;
  transition: opacity var(--chrome-fade) ease;
}

#chrome svg { width: 1.15em; height: 1.15em; display: block; fill: currentColor; }
#chrome a, #chrome button {
  display: flex;
  align-items: center;
  gap: 0.35em;
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  opacity: 0.8;
}
#chrome a:hover, #chrome button:hover, #chrome a:focus-visible { opacity: 1; }
#counter { opacity: 0.7; font-variant-numeric: tabular-nums; }

/* Each toggle ships one icon per state and the viewer unhides the active one.
 * This rule is not redundant: `hidden` is an HTMLElement attribute, so neither the
 * UA stylesheet nor the IDL property hides an <svg>, and `#chrome svg` above would
 * outrank the UA rule anyway. */
#chrome svg[hidden] { display: none; }
#chrome button[aria-pressed="true"] { opacity: 1; }

/* Navigation arrows */
.nav {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 4;
  width: 8%;
  min-width: 3em;
  border: 0;
  background: none;
  color: var(--fg);
  cursor: pointer;
  opacity: 0.25;
  transition: opacity var(--chrome-fade) ease;
}
.nav:hover, .nav:focus-visible { opacity: 0.75; }
.nav svg { width: 2.2em; height: 2.2em; fill: currentColor; filter: drop-shadow(0 0 3px #000); }
#prev { left: 0; }
#next { right: 0; }

/* Idle: hide the chrome and the pointer, but never while a control has focus. */
#gallery.idle #chrome,
#gallery.idle .nav { opacity: 0; pointer-events: none; }
#gallery.idle { cursor: none; }

/* ---------------------------------------------------------------------- rail */

#rail {
  position: relative;
  z-index: 3;
  background: var(--rail-bg);
  backdrop-filter: blur(6px);
  box-shadow: 0 0 1em rgba(0, 0, 0, 0.5);
  scrollbar-width: thin;
  scroll-behavior: smooth;
}

.thumb {
  position: relative;
  display: block;
  flex: 0 0 auto;
  border: 2px solid transparent;
  outline-offset: -2px;
  overflow: hidden;
}

.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: none;
  background: #222;
}

.thumb:hover, .thumb:focus-visible { border-color: rgba(255, 255, 255, 0.85); }
.thumb[aria-current="true"] { border-color: var(--accent); }

/* Cut markers: a soft inner shade along an edge the crop ate into. */
.thumb::before,
.thumb::after {
  content: "";
  position: absolute;
  pointer-events: none;
  opacity: 0.85;
}

/* ------------------------------------------------------- orientation: default
 * Portrait and squarish viewports: rail along the bottom, scrolling sideways.
 * Each thumb uses its --h-* (horizontal-rail) precomputed values.
 */

#gallery {
  grid-template-rows: 1fr auto;
  grid-template-columns: 100%;
}

#rail {
  display: flex;
  flex-direction: row;
  gap: 8px;
  padding: 8px;
  overflow-x: auto;
  overflow-y: hidden;
}

.thumb {
  width: calc(var(--h-w) * 1px);
  height: calc(var(--h-h) * 1px);
}

.thumb img { object-position: calc(var(--h-x) * 1px) calc(var(--h-y) * 1px); }

.thumb[data-h-cuts~="left"]::before {
  left: 0; top: 0; bottom: 0; width: 6px;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.75), transparent);
}
.thumb[data-h-cuts~="right"]::after {
  right: 0; top: 0; bottom: 0; width: 6px;
  background: linear-gradient(to left, rgba(0, 0, 0, 0.75), transparent);
}
.thumb[data-h-cuts~="top"]::before {
  top: 0; left: 0; right: 0; height: 6px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.75), transparent);
}
.thumb[data-h-cuts~="bottom"]::after {
  bottom: 0; left: 0; right: 0; height: 6px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75), transparent);
}

/* --------------------------------------------------- orientation: wide screens
 *
 * The switch point is derived, not guessed: a right-hand rail costs the main
 * image `min_w` of width, a bottom rail costs it `min_h` of height, so the right
 * rail wins exactly when the viewport aspect exceeds min_w/min_h.
 *
 * Because that ratio is configurable, the `@media (min-aspect-ratio: ...)` block
 * carrying these overrides is emitted by album.html rather than living here --
 * custom properties are not permitted in media query conditions. See the
 * `rail_orientation_css` block in the template.
 */

/* ---------------------------------------------------------------- index pages
 * Album-list pages scroll normally and reuse the same palette. When such a page
 * also has photos of its own, the viewer above is embedded below the tiles.
 */

body.index { overflow-y: auto; }

.masthead {
  max-width: 72rem;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 1rem;
}

.masthead h1 {
  margin: 0 0 0.25em;
  font-size: clamp(1.6rem, 4vw, 2.6rem);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.masthead .intro { opacity: 0.75; max-width: 60ch; }
.masthead nav#menu { margin-top: 0.75em; opacity: 0.7; }
.masthead nav#menu a { text-decoration: underline; margin-right: 1em; }

.albums {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1.25rem;
  list-style: none;
  max-width: 72rem;
  margin: 0 auto;
  padding: 1.25rem;
}

.albums a {
  display: block;
  border-radius: 6px;
  overflow: hidden;
  background: var(--rail-bg);
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.albums a:hover, .albums a:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}

.albums img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #222;
}

.albums .label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5em;
  padding: 0.6em 0.75em;
}

.albums .label em { font-style: normal; opacity: 0.6; font-size: 0.85em; }

.loose { max-width: 72rem; margin: 0 auto; padding: 0 1.25rem; }
.loose h2 { font-size: 1.1rem; font-weight: 600; opacity: 0.75; margin: 1.5rem 0 0; }

footer {
  max-width: 72rem;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
  opacity: 0.55;
  font-size: 0.9em;
}
footer a { text-decoration: underline; }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 1ms !important; scroll-behavior: auto !important; }
}
