/* Photos are judged on neutral grey, the way prints are checked against a
   grey card: no warm or cool cast, no glare from white, no crushed blacks. */
:root {
  --surface: #c8c8c6;
  --tile: #b9b9b7;
  --ink: #161616;
  --muted: #555553;
  --line: #9e9e9c;
  --field: #d9d9d7;
  --accent: #b35900; /* darkroom safelight: focus and state only */
  --viewer: #1d1d1d;
  --viewer-ink: #dcdcda;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "URW Palladio L", P052, ui-serif, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --row: 250px;
  --gap: 4px;
  --gutter: clamp(12px, 3vw, 40px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface: #303030;
    --tile: #3b3b3b;
    --ink: #e6e6e4;
    --muted: #a2a2a0;
    --line: #555;
    --field: #262626;
    --accent: #f0a04b;
    color-scheme: dark;
  }
}

@media (max-width: 700px) {
  :root { --row: 130px; --gap: 3px; }
}

* { box-sizing: border-box; }

html { background: var(--surface); }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--surface);
  color: var(--ink);
  font: 1rem/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Headings --------------------------------------------------------- */

.masthead { padding: clamp(28px, 6vw, 64px) var(--gutter) clamp(16px, 3vw, 28px); }

.site,
.album-title {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1.05;
}

.site { font-size: clamp(1.75rem, 4vw, 2.6rem); }
.album-title { font-size: clamp(2.2rem, 7vw, 4.5rem); overflow-wrap: anywhere; }

.meta,
.back,
.counter,
.badge,
.viewer-nav a,
.viewer-nav button,
button {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.meta { margin: 0.6rem 0 0; color: var(--muted); }

.back {
  display: inline-block;
  margin-bottom: 1.25rem;
  color: var(--muted);
  text-decoration: none;
}
a.back::before { content: "← "; }
a.back:hover { color: var(--ink); }

.page { padding: 0 var(--gutter) 64px; }
.narrow { max-width: 24rem; margin: 14vh auto 0; }
.empty { color: var(--muted); }

/* ---- Justified grid ----------------------------------------------------
   Each tile grows in proportion to its aspect ratio (--r, set by the script
   from data-w/data-h), so rows fill the width without cropping much.
   Without the script every tile is a square crop. */

.grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  margin: 0;
  padding: 0;
  list-style: none;
}
.grid::after { content: ""; flex-grow: 1000000; } /* keep the last row from stretching */

.tile {
  position: relative;
  flex: calc(var(--r, 1) * 100) 1 calc(var(--r, 1) * var(--row));
  height: var(--row);
  min-width: 0;
  background: var(--tile);
  overflow: hidden;
}
.tile > a { display: block; height: 100%; }
.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.tile .live-clip {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  padding: 2px 6px;
  border-radius: 2px;
  background: rgb(0 0 0 / 0.55);
  color: #fff;
  font-size: 0.62rem;
  pointer-events: none;
}

/* Album covers carry their label underneath, like the mount of a slide. */
.covers { --gap: clamp(12px, 2vw, 24px); }
.covers .tile { height: auto; background: none; overflow: visible; }
.covers .tile img,
.covers .locked svg { height: var(--row); background: var(--tile); }
.covers .label { display: block; padding-top: 0.55rem; }
.covers .title {
  display: block;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.2rem;
  line-height: 1.2;
}
.covers .meta { display: block; margin-top: 0.2rem; }
.covers a { text-decoration: none; }
.covers a:hover .title { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }

.lock {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linejoin: round;
}
.covers .locked svg { display: block; width: 100%; padding: calc(var(--row) * 0.36) 0; color: var(--muted); }

/* ---- Password form ---------------------------------------------------- */

.unlock { display: grid; gap: 0.75rem; }
.unlock .lock { width: 28px; height: 28px; color: var(--muted); }
.unlock .album-title { font-size: clamp(2rem, 6vw, 3rem); margin-bottom: 1rem; }
.unlock label { color: var(--muted); }
.unlock input {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--field);
  color: var(--ink);
  font: inherit;
}
.unlock input[aria-invalid="true"] { border-color: var(--accent); }
.error { margin: 0; color: var(--ink); border-left: 2px solid var(--accent); padding-left: 0.6rem; }

button {
  justify-self: start;
  padding: 0.75rem 1.2rem;
  border: 0;
  border-radius: 3px;
  background: var(--ink);
  color: var(--surface);
  cursor: pointer;
}

/* ---- Viewer: item page and lightbox ----------------------------------- */

.viewer-page { background: var(--viewer); }

.viewer {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;
  background: var(--viewer);
  color: var(--viewer-ink);
}

.viewer-bar,
.viewer-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 12px var(--gutter);
}

.viewer-bar .close {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.1rem;
  text-decoration: none;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.viewer-bar .close::before { content: "← "; font-style: normal; font-family: var(--mono); font-size: 0.8rem; }
.counter { color: #8a8a88; font-variant-numeric: tabular-nums; }

.stage { position: relative; margin: 0; min-height: 0; }
.stage > img,
.stage > video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.viewer-nav a,
.viewer-nav button {
  padding: 0.6rem 0.2rem;
  background: none;
  color: var(--viewer-ink);
  text-decoration: none;
}
.viewer-nav a:hover,
.viewer-nav button:hover { color: #fff; }
.viewer-nav .prev::before { content: "← "; }
.viewer-nav .next::after { content: " →"; }
.viewer-nav [hidden] { visibility: hidden; display: block; }

dialog.lightbox {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
}
dialog.lightbox::backdrop { background: var(--viewer); }
dialog.lightbox .close {
  padding: 0;
  background: none;
  color: var(--viewer-ink);
  text-transform: none;
  letter-spacing: 0;
}

@media (prefers-reduced-motion: no-preference) {
  dialog.lightbox[open] .stage > * { animation: appear 160ms ease-out; }
  @keyframes appear { from { opacity: 0; } }
}
