/* ==========================================================================
   The pin placer.

   Full screen on purpose: placing a pin is aiming, and the thumbnail it is
   opened from is about ninety pixels across. Aiming at ninety pixels with a
   fingertip has a failure rate, and the failure is silent — the pin lands near
   where you meant and points at the wrong thing.
   ========================================================================== */

.pinner {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--ink);
  color: #fff;
  /* The iPad's home indicator and notch. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.pinner__bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .75rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, .16);
}
.pinner__lede { margin: 0; font-size: .9rem; color: rgba(255, 255, 255, .75); }
.pinner__acts { margin-left: auto; display: flex; gap: .5rem; }

/* ---- The photograph ------------------------------------------------------ */

.pinner__stage {
  display: grid;
  place-items: center;
  min-height: 0;      /* so the image shrinks instead of pushing the list off */
  padding: 1rem;
  overflow: hidden;
  /* So the frame inside can ask this box how tall it is. It cannot ask with a
     percentage: a percentage height means nothing unless the parent's own
     height is settled, and the frame is what settles it. */
  container-type: size;
}

/* Exactly the picture and nothing else, so the pins' percentages are measured
   against the photograph and not against a box with letterboxing in it.

   It has to fit BOTH ways round — a wide photo runs out of stage width first,
   a tall one runs out of height — and `max-height: 100%` cannot express the
   second, for the reason given on the stage above. Left as a plain
   inline-block, a tall photograph rendered at its natural size, overflowed the
   stage and had its lower half clipped away: the bottom of it could not be
   pinned at all. `--shot-ratio` is the photograph's own proportions, set once
   it has loaded; the fallback covers the moment before that. */
.pinner__frame {
  position: relative;
  width: min(100%, calc(100cqh * var(--shot-ratio, 1.4)));
  aspect-ratio: var(--shot-ratio, 1.4);
  line-height: 0;
  /* A finger dragging a pin must not also scroll the page under it. */
  touch-action: none;
}
.pinner__frame img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-sm);
  /* Placing a pin is a tap, not a text selection or a save-image long press. */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.pinner__pin {
  position: absolute;
  transform: translate(-50%, -50%);
  /* 44px is the smallest thing worth aiming at with a finger; the visible
     circle is smaller, and the rest of the target is padding. */
  min-width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: none;
  color: #fff;
  font: 700 .95rem/44px system-ui, sans-serif;
  text-align: center;
  cursor: grab;
  touch-action: none;
}
.pinner__pin::before {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .62);
  border: 2px solid #fff;
  z-index: -1;
}
.pinner__pin.is-on::before {
  background: var(--accent, #4E6B8A);
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .35);
}
.pinner__pin:active { cursor: grabbing; }

/* ---- The notes themselves ------------------------------------------------ */

.pinner__list {
  padding: .75rem 1rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, .16);
  display: grid;
  gap: .45rem;
  max-height: 38vh;
  overflow-y: auto;
}
.pinner__empty { color: rgba(255, 255, 255, .6); margin: 0; }

.pinner__row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: .5rem;
  align-items: center;
}
.pinner__num {
  width: 1.6rem; height: 1.6rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, .16);
  font: 700 .8rem/1.6rem system-ui, sans-serif;
  text-align: center;
}
.pinner__row.is-on .pinner__num { background: var(--accent, #4E6B8A); }
.pinner__row input {
  width: 100%;
  padding: .5rem .6rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, .25);
  background: rgba(255, 255, 255, .08);
  color: #fff;
  font: inherit;
}
.pinner__row input::placeholder { color: rgba(255, 255, 255, .45); }
.pinner__list .btn { color: #fff; border-color: rgba(255, 255, 255, .3); }

@media (max-width: 640px) {
  .pinner__bar { flex-wrap: wrap; }
  .pinner__lede { flex-basis: 100%; }
}
