:root {
  --bg: #fff;
  --fg: #000;
  --font: Arimo, "Helvetica Neue", Helvetica, Arial, sans-serif;
  /* set per breakpoint by app.js */
  --cols: 16;
  --rows: 10;
  --margin: 24px;
  --gap: 4px;
  --label: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font-family: var(--font); -webkit-font-smoothing: antialiased; }

/* ---------- grid ---------- */
#grid {
  height: 100vh;
  height: 100svh;
  padding: var(--margin);
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  gap: var(--gap);
}

.cell {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  container-type: inline-size;
}

.area {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  container-type: size;
}

.box {
  position: relative;
  width: min(100cqw, 100cqh);
  aspect-ratio: 1 / 1;
  transform-origin: 50% 100%;
  transition: transform var(--dur, 450ms) cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
  cursor: zoom-in;
}

.box img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: 50% 100%;
  transform-origin: 50% 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 240ms ease-out;
}
.box img.loaded { opacity: 1; }

/* all screens: each photo+number block drifts gently in every direction.
   x and y are animated separately (own speed/phase per cell, set in app.js),
   so together they trace a slow, irregular loop instead of a straight bob. */
@property --fx { syntax: "<length>"; inherits: false; initial-value: 0px; }
@property --fy { syntax: "<length>"; inherits: false; initial-value: 0px; }
@media (prefers-reduced-motion: no-preference) {
  .cell {
    transform: translate(var(--fx), var(--fy));
    animation:
      float-x var(--float-x-dur, 3600ms) ease-in-out var(--float-x-delay, 0ms) infinite alternate,
      float-y var(--float-y-dur, 3000ms) ease-in-out var(--float-y-delay, 0ms) infinite alternate;
  }
}
@keyframes float-x {
  from { --fx: calc(var(--float, 1.3px) * -1); }
  to   { --fx: var(--float, 1.3px); }
}
@keyframes float-y {
  from { --fy: var(--float, 1.3px); }
  to   { --fy: calc(var(--float, 1.3px) * -1); }
}

.label {
  font-size: min(var(--label), 50cqw);
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  user-select: none;
}

/* ---------- lightbox ---------- */
#lightbox {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  cursor: zoom-out;
}
#lightbox.open { display: flex; animation: fade 220ms ease-out; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.lb-frame {
  position: relative;
  flex-shrink: 0;
  /* width/height set from the photo's aspect ratio in app.js */
}
.lb-frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.lb-full { opacity: 0; transition: opacity 160ms ease-out; }
.lb-full.loaded { opacity: 1; }

.lb-caption {
  font-size: 16px;
  line-height: 1.4;
  letter-spacing: 0.02em;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lb-body {
  width: 100%;
  max-width: 640px;
  min-height: 0;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: keep-all;
  cursor: auto;
  scrollbar-width: thin;
}
.lb-body:empty { display: none; }
.lb-ref { color: #999; }
.lb-theme { text-transform: uppercase; }
