:root {
  --bg: #0a0a0a;
  --gap: 10px;
  --unit: 4px;          /* grid row unit — must match UNIT in build.mjs */
  --cols: 5;
  --radius: 3px;
  --ui: rgba(255,255,255,.72);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: #fff;
  font: 500 13px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body.lb-open { overflow: hidden; }

/* ---------- collection switcher ---------- */

.cols {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  gap: 2px;
  padding: 10px var(--gap) 8px;
  overflow-x: auto;
  scrollbar-width: none;
  background: linear-gradient(var(--bg) 65%, rgba(10,10,10,0));
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.cols::-webkit-scrollbar { display: none; }
.cols[hidden] { display: none; }

.cols button {
  flex: 0 0 auto;
  font: inherit;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: rgba(255,255,255,.4);
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 7px 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: color .18s, background .18s;
  -webkit-tap-highlight-color: transparent;
}
.cols button:hover { color: rgba(255,255,255,.75); }
.cols button.on { color: #fff; background: rgba(255,255,255,.1); }

/* order control sits apart from the collection tabs */
.cols .order-btn {
  margin-left: auto;
  color: rgba(255,255,255,.3);
  border: 1px solid rgba(255,255,255,.09);
}
.cols .order-btn[hidden] { display: none; }
.cols .order-btn:hover { color: #fff; border-color: rgba(255,255,255,.25); }

/* ---------- grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-auto-rows: var(--unit);
  gap: var(--gap);
  padding: var(--gap);
  padding-bottom: max(var(--gap), env(safe-area-inset-bottom));
  align-content: start;
}

@media (max-width: 1500px) { :root { --cols: 4; } }
@media (max-width: 1100px) { :root { --cols: 3; } }
@media (max-width: 720px)  { :root { --cols: 2; --gap: 6px; } }

.tile {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: #141414 center/cover no-repeat;
  cursor: zoom-in;
  contain: paint;
  /* off-screen tiles skip rendering; the grid row span already fixes their
     geometry, so this costs nothing in layout stability */
  content-visibility: auto;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* the low-quality placeholder sits behind, blurred, so tiles never flash empty */
.tile::before {
  content: "";
  position: absolute;
  inset: -6%;
  background: var(--lqip) center/cover no-repeat;
  filter: blur(14px) saturate(1.1);
  transform: scale(1.05);
  opacity: 1;
  transition: opacity .35s ease .05s;
}
.tile.ready::before { opacity: 0; }

/* a captioned tile (the Films collection): the picture above, its title and year below */
.tile.cap { background: none; }
.tile.cap::before,
.tile.cap img,
.tile.cap video { inset: 0 0 64px 0; height: auto; border-radius: var(--radius); }
.tile.cap img, .tile.cap video { height: calc(100% - 64px); }
.tile-cap {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 64px;
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
  overflow: hidden;
  white-space: nowrap;
  font-size: 12px;
  color: rgba(255,255,255,.5);
}
.tile-cap b { max-width: 100%; font-weight: 500; color: rgba(255,255,255,.9); overflow: hidden; text-overflow: ellipsis; }
.tile-cap span { flex: none; }   /* what kind of film · year, on the line under the title */

picture { display: contents; }

.tile img,
.tile video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity .35s ease, transform .5s cubic-bezier(.2,.7,.3,1);
  will-change: opacity;
}
.tile img.loaded { opacity: 1; }
.tile .pv-prev.playing { opacity: 1; }
.tile .pv-prev { z-index: 1; }

@media (hover: hover) and (pointer: fine) {
  .tile:hover img,
  .tile:hover .pv-prev { transform: scale(1.035); }
}

/* video badge — only marker of type, no text labels anywhere */
.tile[data-type="video"]::after,
.tile[data-type="mux"]::after {
  content: "";
  position: absolute;
  right: 8px; bottom: 8px;
  width: 0; height: 0;
  border-left: 9px solid rgba(255,255,255,.92);
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,.6));
  z-index: 2;
  opacity: .85;
  transition: opacity .2s;
}
.tile[data-type="video"].playing-preview::after,
.tile[data-type="mux"].playing-preview::after { opacity: 0; }
.tile.cap::after { bottom: 72px; }   /* on the picture, above the caption */

/* ---------- lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;   /* solid, so nothing shows through from the page */
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .18s ease;
  touch-action: none;
}
.lightbox[hidden] { display: none; }
.lightbox.show { opacity: 1; }

.lb-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lb-stage img,
.lb-stage video {
  max-width: 100vw;
  max-height: 100dvh;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  opacity: 0;
  transition: opacity .2s ease;
  background: #000;
}
.lb-stage img.loaded,
.lb-stage video.loaded { opacity: 1; }

/* Mux streams: sized to fit the screen at the film's own ratio */
.lb-stage mux-player {
  width: min(100vw, calc(100dvh * var(--ar, 1.7778)));
  aspect-ratio: var(--ar, 1.7778);
  --media-object-fit: contain;
  --controls-backdrop-color: transparent;
}

/* caption, only for items that have one (sidecar .json or .mux metadata) */
.lb-cap {
  position: absolute;
  left: 18px; bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 2;
  display: flex; gap: 12px; align-items: baseline;
  font-size: 12px;
  color: rgba(255,255,255,.55);
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}
.lb-cap[hidden] { display: none; }
.lb-cap b { font-weight: 500; color: rgba(255,255,255,.9); }
.lightbox.ui .lb-cap { opacity: 1; }
/* Mux's controls own the bottom edge — lift the caption to the top there */
.lightbox:has(mux-player) .lb-cap { bottom: auto; top: 18px; }

.lb-nav, .lb-close {
  position: absolute;
  border: 0;
  background: none;
  cursor: pointer;
  z-index: 2;
  opacity: 0;
  transition: opacity .2s;
}
.lightbox.ui .lb-nav, .lightbox.ui .lb-close { opacity: .55; }
.lb-nav:hover, .lb-close:hover { opacity: 1 !important; }

.lb-nav { top: 0; bottom: 0; width: 22vw; max-width: 160px; }
.lb-prev { left: 0; }
.lb-next { right: 0; }

.lb-nav::before {
  content: "";
  position: absolute;
  top: 50%; margin-top: -7px;
  width: 14px; height: 14px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
}
.lb-prev::before { left: 22px; transform: rotate(45deg); }
.lb-next::before { right: 22px; transform: rotate(-135deg); }

.lb-close { top: 0; right: 0; width: 56px; height: 56px; }
.lb-close::before, .lb-close::after {
  content: "";
  position: absolute;
  left: 18px; top: 27px;
  width: 20px; height: 2px;
  background: #fff;
}
.lb-close::before { transform: rotate(45deg); }
.lb-close::after { transform: rotate(-45deg); }

@media (max-width: 720px) {
  .lb-nav { display: none; }   /* swipe instead */
}

/* ---------- edit mode ---------- */

.edit-hint {
  position: fixed;
  right: 10px; bottom: 10px;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(20,20,20,.6);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  cursor: pointer;
  opacity: 0;
  transition: opacity .2s;
  z-index: 60;
}
.edit-hint::before {
  content: "";
  position: absolute;
  left: 11px; top: 11px;
  width: 12px; height: 12px;
  background:
    linear-gradient(var(--ui) 0 0) 0 0 / 5px 5px no-repeat,
    linear-gradient(var(--ui) 0 0) 7px 0 / 5px 5px no-repeat,
    linear-gradient(var(--ui) 0 0) 0 7px / 5px 5px no-repeat,
    linear-gradient(var(--ui) 0 0) 7px 7px / 5px 5px no-repeat;
}
body:hover .edit-hint { opacity: .35; }
.edit-hint:hover { opacity: 1 !important; }
body.edit .edit-hint { display: none; }

.toolbar {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 6px;
  border-radius: 10px;
  background: rgba(18,18,18,.86);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,.1);
  box-shadow: 0 8px 30px rgba(0,0,0,.6);
  z-index: 80;
}
.toolbar[hidden] { display: none; }
.tb-tag {
  font-size: 10px;
  letter-spacing: .12em;
  padding: 0 8px;
  color: #ff5f56;
}
.toolbar button {
  font: inherit;
  font-size: 12px;
  color: var(--ui);
  background: rgba(255,255,255,.06);
  border: 0;
  border-radius: 6px;
  padding: 7px 10px;
  cursor: pointer;
}
.toolbar button:hover { background: rgba(255,255,255,.14); color: #fff; }
.toolbar button:disabled { opacity: .35; cursor: default; }

/* pan-y keeps the grid scrollable in edit mode; the long-press drag blocks
   scrolling itself once a tile is lifted. content-visibility is off here so a
   tile being dragged past the viewport edge can't blank mid-drag. */
body.edit .tile { cursor: grab; touch-action: pan-y; content-visibility: visible; }
body.edit .tile.selected { outline: 2px solid #fff; outline-offset: -2px; }
body.edit .tile.hidden-item { opacity: .28; }
body.edit .tile.dragging {
  z-index: 50;
  cursor: grabbing;
  opacity: .9;
  box-shadow: 0 18px 50px rgba(0,0,0,.7);
  transition: none !important;
}
body.edit .tile { transition: transform .22s cubic-bezier(.2,.7,.3,1); }
body:not(.edit) .tile.hidden-item { display: none; }

/* size stepper shown per tile in edit mode */
body.edit .tile .badge {
  position: absolute;
  left: 6px; top: 6px;
  z-index: 3;
  display: flex;
  gap: 2px;
}
.tile .badge { display: none; }
.badge button {
  width: 22px; height: 22px;
  border: 0;
  border-radius: 4px;
  background: rgba(0,0,0,.6);
  color: #fff;
  font: 600 11px/1 sans-serif;
  cursor: pointer;
}
.badge button.on { background: #fff; color: #000; }

@media print { .toolbar, .edit-hint { display: none; } }

/* a title's subtitle: lighter, thinner, dimmer */
.sub { margin-left: .5em; font-weight: 400; font-size: .82em; color: rgba(255,255,255,.5); }

/* the Films page packs its double-size films in tight, so every row stays full */
.grid.fill { grid-auto-flow: dense; }

/* phones: Previous and Next along the bottom of the viewer, the title and year just above them */
.vbar { display: none; }
@media (max-width: 720px) {
  .vbar {
    position: absolute;
    left: 0; right: 0;
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 4;
    display: flex;
    justify-content: space-between;
    padding: 0 12px;
  }
  .vbar[hidden] { display: none; }
  .vbar button {
    padding: 10px 6px;
    background: none;
    border: 0;
    color: rgba(244, 244, 242, .7);
    font: 500 11px/1 ui-monospace, Menlo, monospace;
    letter-spacing: .12em;
    text-transform: uppercase;
    -webkit-tap-highlight-color: transparent;
  }
  .vbar button:active { color: #fff; }
}
@media (max-height: 520px) and (orientation: landscape) { .vbar { display: none !important; } }
.cap-line { display: none; }
/* phones: room under the last tile, so its caption clears the browser's bottom bar */
@media (max-width: 720px) { .grid { padding-bottom: calc(96px + env(safe-area-inset-bottom)); } }

