:root {
  --table: #f1f0ec;
  --ink: #111110;
  --muted: #85827a;
  --paper: #fcfbf8;
  --paper-shade: #f1eee7;
  --stamp: #a7a194;
  --gutter: 16px;
  --shadow:
    0 0 0 0.5px rgb(40 32 20 / 0.08),
    0 1px 2px rgb(40 32 20 / 0.1),
    0 4px 10px -2px rgb(40 32 20 / 0.1),
    0 16px 30px -12px rgb(40 32 20 / 0.22);
  --shadow-lift:
    0 0 0 0.5px rgb(40 32 20 / 0.08),
    0 2px 4px rgb(40 32 20 / 0.08),
    0 14px 26px -6px rgb(40 32 20 / 0.18),
    0 40px 70px -20px rgb(40 32 20 / 0.34);
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .3 0 0 0 0 .22 0 0 0 .55 -.18'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root {
    --table: #151514;
    --ink: #ebe9e4;
    --muted: #8a877f;
    --paper: #f3f0ea;
    --paper-shade: #e4e0d7;
    --stamp: #9c968a;
    --shadow:
      0 0 0 0.5px rgb(0 0 0 / 0.4),
      0 1px 2px rgb(0 0 0 / 0.4),
      0 6px 14px -2px rgb(0 0 0 / 0.35),
      0 18px 34px -10px rgb(0 0 0 / 0.6);
    --shadow-lift:
      0 0 0 0.5px rgb(0 0 0 / 0.4),
      0 2px 4px rgb(0 0 0 / 0.35),
      0 16px 30px -6px rgb(0 0 0 / 0.45),
      0 44px 80px -20px rgb(0 0 0 / 0.75);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  background: var(--table);
  color: var(--ink);
  font: 400 14px/1.45 Geist, ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", sans-serif;
  letter-spacing: -0.003em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a,
button {
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
}

a {
  text-decoration: underline;
  text-underline-offset: 0.14em;
  text-decoration-thickness: 1px;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button[aria-pressed="true"] {
  text-decoration: underline;
  text-underline-offset: 0.14em;
  text-decoration-thickness: 1px;
}

a:hover,
button:hover {
  opacity: 0.55;
}

:focus-visible {
  outline: 1.5px solid currentColor;
  outline-offset: 3px;
  border-radius: 2px;
}

/* intro */

.intro {
  position: relative;
  z-index: 2;
  padding: 12px var(--gutter) 0;
  pointer-events: none;
}

.intro p {
  margin: 0;
}

.intro a {
  pointer-events: auto;
}

/* bar — four columns, like the original nav */

.bar {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 10px var(--gutter) calc(12px + env(safe-area-inset-bottom));
  white-space: nowrap;
}

.bar .title {
  text-decoration: none;
}

.bar > :last-child {
  justify-self: end;
}

.index {
  font-variant-numeric: tabular-nums;
}

.zoom [data-zoom] {
  display: inline-block;
  min-width: 4ch;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* table + pile */

.table {
  position: relative;
  z-index: 1;
  min-height: 0;
}

.pile {
  position: absolute;
  inset: 0;
  isolation: isolate;
}

.empty[hidden] {
  display: none;
}

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--muted);
}

.print {
  position: absolute;
  left: 50%;
  top: 50%;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.print.top {
  pointer-events: auto;
  cursor: grab;
}

.print.lifted {
  cursor: grabbing;
}

/* the photo paper */

.paper {
  position: relative;
  width: 100%;
  height: 100%;
  padding: var(--b) var(--b) var(--bb);
  background: linear-gradient(160deg, var(--paper) 30%, var(--paper-shade));
  border-radius: 1.5px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.3s ease;
}

.lifted .paper {
  box-shadow: var(--shadow-lift);
}

/* grain + a soft sheen across paper and emulsion */
.paper::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background:
    linear-gradient(118deg, rgb(255 255 255 / 0) 34%, rgb(255 255 255 / 0.09) 46%, rgb(255 255 255 / 0) 60%),
    var(--grain);
  background-size:
    100% 100%,
    180px 180px;
}

.emulsion {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--c, #888);
}

/* the image sits *in* the paper: hairline edge + faint vignette */
.emulsion::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow:
    inset 0 0 0 0.5px rgb(0 0 0 / 0.12),
    inset 0 0 22px rgb(0 0 0 / 0.1);
}

.emulsion img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  /* develops like a print in the tray */
  filter: sepia(0.5) contrast(0.55) brightness(1.35);
  transition:
    opacity 0.5s ease,
    filter 1.4s ease 0.1s;
}

.emulsion img.in {
  opacity: 1;
  filter: none;
}

.stamp {
  position: absolute;
  right: var(--b);
  bottom: 0;
  height: var(--bb);
  display: flex;
  align-items: center;
  font-size: clamp(8px, calc(var(--b) * 0.82), 11px);
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  color: var(--stamp);
}

/* viewer */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: minmax(0, 1fr) auto;
  background: var(--table);
  opacity: 0;
  transition: opacity 0.22s ease;
}

.viewer[hidden] {
  display: none;
}

.viewer.open {
  opacity: 1;
}

.viewer .bar {
  grid-column: 1 / -1;
}

.stage {
  position: relative;
  margin: 0;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: calc(var(--gutter) + 8px) var(--gutter) 4px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.info {
  width: 280px;
  padding: calc(var(--gutter) + 8px) var(--gutter) 0 4px;
  overflow-y: auto;
}

.info[hidden] {
  display: none;
}

.info dl {
  margin: 0;
}

.info dt {
  color: var(--muted);
}

.info dd {
  margin: 0 0 0.85em;
  overflow-wrap: anywhere;
}

.frame {
  position: relative;
  padding: var(--b, 12px);
  background: linear-gradient(160deg, var(--paper) 30%, var(--paper-shade));
  border-radius: 1.5px;
  box-shadow: var(--shadow);
  transform: scale(0.97);
  transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.25, 1);
}

.viewer.open .frame {
  transform: none;
}

.frame.easing {
  transition:
    transform 0.32s cubic-bezier(0.2, 0.8, 0.25, 1),
    translate 0.28s cubic-bezier(0.2, 0.8, 0.25, 1),
    scale 0.28s cubic-bezier(0.2, 0.8, 0.25, 1);
}

.frame img {
  display: block;
  width: 100%;
  height: 100%;
}

.frame .hi {
  position: absolute;
  inset: var(--b, 12px);
  width: calc(100% - 2 * var(--b, 12px));
  height: calc(100% - 2 * var(--b, 12px));
  opacity: 0;
  transition: opacity 0.35s ease;
}

.frame .hi.in {
  opacity: 1;
}

.viewer.can-hover .stage {
  cursor: none;
}

.viewer.can-hover.zoomed .stage {
  cursor: grab;
}

.viewer.can-hover.panning .stage {
  cursor: grabbing;
}

.cursor {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 11;
  pointer-events: none;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--table);
  color: var(--ink);
  opacity: 0;
  transition: opacity 0.15s;
}

.cursor.on {
  opacity: 1;
}

@media (max-width: 640px) {
  :root {
    --gutter: 14px;
  }

  body {
    font-size: 13px;
  }

  .bar {
    display: flex;
    justify-content: space-between;
    gap: 10px;
  }

  .viewer {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto auto;
  }

  .viewer .zoom {
    display: none;
  }

  .info {
    width: auto;
    max-height: 40vh;
    padding: 4px var(--gutter) 0;
  }

  .info dl {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 2px 14px;
  }

  .info dd {
    margin: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .emulsion img,
  .frame,
  .frame .hi,
  .viewer {
    transition-duration: 0.01s;
  }

  .emulsion img {
    filter: none;
  }
}
