/* The trace modules' own styles (agent V). Structure only: the stills that show before or without script, and the
   few controls the modules add. No fonts, no page layout. Colours and radii come from the custom properties in
   README.md. Curves are the app's (plan/12-motion.md): settle cubic-bezier(.19, 1, .22, 1), leave
   cubic-bezier(.3, 0, .5, 1). */

/* ------------------------------------------------------------------ shared */

.trace-viewfinder,
.trace-styles__frame,
.trace-wipe {
  position: relative;
  overflow: hidden;
  background: var(--trace-bg, #050506);
  border-radius: var(--trace-radius, 0px);
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.trace-viewfinder img,
.trace-styles__frame img,
.trace-wipe img {
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

.trace-viewfinder :focus-visible,
.trace-styles :focus-visible,
.trace-wipe :focus-visible {
  outline: 2px solid var(--trace-ice, #a9d2ff);
  outline-offset: 3px;
}

/* A control that would do nothing stays out of the way, whatever display the page gives it. */
.trace-styles [data-trace-controls][hidden],
.trace-wipe__range[hidden] {
  display: none !important;
}

/* ------------------------------------------------------------- viewfinder */

.trace-viewfinder {
  container-type: size;
  aspect-ratio: var(--trace-viewfinder-ratio, 3 / 4);
  color: var(--trace-fg, #f3f3f1);
  font-family: var(--trace-label-font, inherit);
}

/* The still: the pair, side by side, using the box. Each tile is half the box's width and as tall as the box
   allows with the labels and the control under them, from 3:4 up to 9:16 and no narrower; the pictures are
   cropped to the tile about their middle, as the camera's were. Tiles, labels and the control are one group,
   centred in the box (the padding at the foot is the control's share of that group). */
.trace-viewfinder .trace-pair {
  --_pad: var(--trace-pair-pad, 16px);
  --_gap: var(--trace-pair-gap, 12px);
  --_foot: 56px; /* the control and its gap */
  --_room: calc(100cqh - 2 * var(--_pad) - 30px - var(--_foot)); /* 30 is the labels */
  --_w: min((100cqw - 2 * var(--_pad) - var(--_gap)) / 2, var(--_room) * 0.75);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--_gap);
  padding: var(--_pad);
  padding-bottom: calc(var(--_pad) + var(--_foot));
  box-sizing: border-box;
}

@container (min-width: 700px) {
  .trace-viewfinder .trace-pair {
    --_foot: 60px;
  }
}

.trace-viewfinder .trace-tile {
  flex: none;
  margin: 0;
  width: var(--_w);
}

.trace-viewfinder .trace-tile img {
  display: block;
  width: 100%;
  height: min(var(--_room), var(--_w) * 16 / 9);
  object-fit: cover;
  border-radius: var(--trace-tile-radius, 12px);
  background: #0d0d0e;
}

.trace-viewfinder .trace-tile figcaption {
  margin-top: 10px;
  font-size: 13px;
  line-height: 20px;
  font-weight: 500;
  color: color-mix(in srgb, var(--trace-fg, #f3f3f1) 56%, transparent);
}

/* Before the module takes over, on a page that says script is running (`trace-js` on <html>): the shot alone,
   filling the box exactly where the camera picture will first be drawn, so nothing jumps. The numbers are
   viewfinder.js's FIRST (offset 8.5% and 4% of the short side, scale 1.2096, turn 0.6 degrees). */
@media (prefers-reduced-motion: no-preference) {
  .trace-js .trace-viewfinder:not([data-state]) .trace-pair,
  .trace-viewfinder[data-state='loading'] .trace-pair {
    padding: 0;
  }
  .trace-js .trace-viewfinder:not([data-state]) .trace-tile[data-trace-tile='trace'],
  .trace-viewfinder[data-state='loading'] .trace-tile[data-trace-tile='trace'],
  .trace-js .trace-viewfinder:not([data-state]) figcaption,
  .trace-viewfinder[data-state='loading'] figcaption {
    opacity: 0;
  }
  .trace-js .trace-viewfinder:not([data-state]) .trace-tile[data-trace-tile='shot'],
  .trace-viewfinder[data-state='loading'] .trace-tile[data-trace-tile='shot'] {
    position: absolute;
    inset: 0;
    width: auto;
  }
  .trace-js .trace-viewfinder:not([data-state]) .trace-tile[data-trace-tile='shot'] img,
  .trace-viewfinder[data-state='loading'] .trace-tile[data-trace-tile='shot'] img {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    border-radius: 0;
    transform: translate(8.5cqmin, 4cqmin) rotate(0.6deg) scale(1.2096);
  }
}

/* While the camera is live the pair is under the canvas, still there for a screen reader. */
.trace-viewfinder[data-state='idle'] .trace-pair,
.trace-viewfinder[data-state='following'] .trace-pair,
.trace-viewfinder[data-state='linedup'] .trace-pair {
  opacity: 0;
}

/* After the shot the canvas draws the two pictures (the shot as it was really framed); the captions are these. */
.trace-viewfinder[data-state='shot'] .trace-tile img {
  opacity: 0;
}

.trace-viewfinder[data-state='shot'] .trace-tile figcaption {
  opacity: 0;
  transition: opacity 0.2s cubic-bezier(0.3, 0, 0.5, 1);
}

.trace-viewfinder[data-state='shot'][data-trace-settled] .trace-tile figcaption {
  opacity: 1;
  transition: opacity 0.5s cubic-bezier(0.19, 1, 0.22, 1);
}

.trace-viewfinder__view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
  transition: opacity 0.2s cubic-bezier(0.3, 0, 0.5, 1);
  pointer-events: none;
}

.trace-viewfinder[data-trace-live] .trace-viewfinder__view {
  opacity: 1;
  transition: opacity 0.32s cubic-bezier(0.19, 1, 0.22, 1);
}

/* The frame traces itself in ice, clockwise from the top-left; it leaves fast. */
.trace-viewfinder__ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.trace-viewfinder__ring rect {
  fill: none;
  stroke: var(--trace-ice, #a9d2ff);
  stroke-width: 2px;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0;
  transition: opacity 0.22s cubic-bezier(0.3, 0, 0.5, 1), stroke-dashoffset 0s linear 0.22s;
}

.trace-viewfinder[data-state='linedup'] .trace-viewfinder__ring rect {
  stroke-dashoffset: 0;
  opacity: 1;
  transition: opacity 0.12s linear, stroke-dashoffset 0.5s cubic-bezier(0.19, 1, 0.22, 1);
}

.trace-viewfinder__chip,
.trace-viewfinder__hint {
  position: absolute;
  left: 50%;
  margin: 0;
  white-space: nowrap;
  pointer-events: none;
  font-size: 13px;
  line-height: 18px;
}

/* "Lined up" comes into focus 120 ms after the ring starts; it leaves in 0.2 s. */
.trace-viewfinder__chip {
  top: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 500;
  color: var(--trace-fg, #f3f3f1);
  background: rgba(10, 10, 12, 0.55);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  opacity: 0;
  transform: translate(-50%, 8px) scale(0.92);
  filter: blur(8px);
  transition: opacity 0.2s cubic-bezier(0.3, 0, 0.5, 1), transform 0s linear 0.2s, filter 0s linear 0.2s;
}

.trace-viewfinder[data-state='linedup'] .trace-viewfinder__chip {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
  filter: blur(0);
  transition: opacity 0.5s cubic-bezier(0.19, 1, 0.22, 1) 0.12s, transform 0.5s cubic-bezier(0.19, 1, 0.22, 1) 0.12s,
    filter 0.5s cubic-bezier(0.19, 1, 0.22, 1) 0.12s;
}

/* The hint line: there while there is something to do, empty once it is lined up (as in the app). */
.trace-viewfinder__hint {
  bottom: 104px;
  transform: translateX(-50%);
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--trace-fg, #f3f3f1);
  background: rgba(10, 10, 12, 0.4);
  opacity: 0;
  transition: opacity 0.5s cubic-bezier(0.3, 0, 0.5, 1);
}

.trace-viewfinder[data-state='idle'][data-trace-live] .trace-viewfinder__hint,
.trace-viewfinder[data-state='following'][data-trace-live] .trace-viewfinder__hint {
  opacity: 1;
  transition: opacity 0.36s cubic-bezier(0.19, 1, 0.22, 1) 0.3s;
}

/* The shutter: a real button. Down in 90 ms, back on a soft settle. */
.trace-viewfinder__shutter,
.trace-viewfinder__again {
  position: absolute;
  left: 50%;
  bottom: 20px;
  margin: 0;
  border: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s cubic-bezier(0.3, 0, 0.5, 1), visibility 0s linear 0.2s;
}

.trace-viewfinder__shutter {
  width: 68px;
  height: 68px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: inset 0 0 0 4px var(--trace-fg, #f3f3f1);
  transform: translateX(-50%);
}

.trace-viewfinder__shutter::before {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--trace-fg, #f3f3f1);
  transition: transform 0.4s cubic-bezier(0.19, 1, 0.22, 1);
}

.trace-viewfinder__shutter:active::before,
.trace-viewfinder__shutter[data-pressed]::before {
  transform: scale(0.86);
  transition: transform 0.09s ease-out;
}

.trace-viewfinder[data-trace-live]:is([data-state='idle'], [data-state='following'], [data-state='linedup'])
  .trace-viewfinder__shutter {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.36s cubic-bezier(0.19, 1, 0.22, 1), visibility 0s;
}

/* The quiet control under the pair. */
.trace-viewfinder__again {
  bottom: 16px;
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 14.5px;
  line-height: 22px;
  font-weight: 500;
  color: var(--trace-fg, #f3f3f1);
  background: rgba(255, 255, 255, 0.1);
  transform: translateX(-50%);
  transition: opacity 0.2s cubic-bezier(0.3, 0, 0.5, 1), visibility 0s linear 0.2s, transform 0.32s cubic-bezier(0.19, 1, 0.22, 1),
    background-color 0.2s ease;
}

.trace-viewfinder__again:active {
  transform: translateX(-50%) scale(0.97);
  transition: transform 0.12s ease-out;
}

@media (hover: hover) and (pointer: fine) {
  .trace-viewfinder__again:hover {
    background: rgba(255, 255, 255, 0.16);
  }
}

.trace-viewfinder[data-state='shot'][data-trace-settled] .trace-viewfinder__again {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.5s cubic-bezier(0.19, 1, 0.22, 1), visibility 0s, transform 0.32s cubic-bezier(0.19, 1, 0.22, 1),
    background-color 0.2s ease;
}

/* ----------------------------------------------------------------- styles */

.trace-styles__frame {
  aspect-ratio: 3 / 4;
}

.trace-styles__frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* The still: the trace as a photo over the scene at 45%, the app's Photo style at its starting opacity. */
.trace-styles__frame img[data-trace-tile='trace'] {
  opacity: 0.45;
}

.trace-styles__view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
  transition: opacity 0.3s cubic-bezier(0.19, 1, 0.22, 1);
}

.trace-styles[data-state='ready'] .trace-styles__view {
  opacity: 1;
}

.trace-styles[data-state='ready'] .trace-styles__frame {
  cursor: grab;
}

.trace-styles[data-dragging] .trace-styles__frame {
  cursor: grabbing;
}

/* ------------------------------------------------------------------- wipe */

.trace-wipe {
  --trace-wipe: 0.5;
  container-type: inline-size;
  aspect-ratio: 3 / 4;
  font-family: var(--trace-label-font, inherit);
}

.trace-wipe img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* As the app's Compare: the shot left of the handle, the trace right of it. */
.trace-wipe img[data-trace-tile='shot'] {
  z-index: 1;
  clip-path: inset(0 calc(100% - var(--trace-wipe) * 100%) 0 0);
}

/* The handle's line. With no script it is the still's hairline at the middle. */
.trace-wipe::after {
  content: '';
  position: absolute;
  z-index: 2;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  margin-left: -1px;
  background: #fff;
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.2);
  transform: translateX(calc(var(--trace-wipe) * 100cqw));
  pointer-events: none;
}

.trace-wipe__label {
  position: absolute;
  z-index: 3;
  top: 12px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  color: var(--trace-fg, #f3f3f1);
  background: rgba(10, 10, 12, 0.55);
  pointer-events: none;
}

.trace-wipe__label[data-trace-label='shot'] {
  left: 12px;
}

.trace-wipe__label[data-trace-label='trace'] {
  right: 12px;
}

/* The range input is the handle: the whole box is its track, its thumb is the white disc. */
.trace-wipe__range {
  position: absolute;
  z-index: 4;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: ew-resize;
  touch-action: pan-y;
  /* The module moves it; the native drag is off so that a vertical swipe still scrolls. */
  pointer-events: none;
}

.trace-wipe__range::-webkit-slider-runnable-track {
  height: 100%;
  background: transparent;
}

.trace-wipe__range::-moz-range-track {
  height: 100%;
  background: transparent;
}

.trace-wipe__range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 0;
  height: 0;
  border: 0;
  background: transparent;
}

.trace-wipe__range::-moz-range-thumb {
  width: 0;
  height: 0;
  border: 0;
  background: transparent;
}

.trace-wipe__range:focus-visible {
  outline: none;
}

.trace-wipe__knob {
  position: absolute;
  z-index: 3;
  top: 50%;
  left: 0;
  width: 36px;
  height: 36px;
  margin: -18px 0 0 -18px;
  border-radius: 50%;
  background: #fff;
  transform: translateX(calc(var(--trace-wipe) * 100cqw));
  pointer-events: none;
  transition: scale 0.32s cubic-bezier(0.19, 1, 0.22, 1);
}

.trace-wipe__knob::before,
.trace-wipe__knob::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-top: 1.5px solid #0b0b0c;
  border-left: 1.5px solid #0b0b0c;
  box-sizing: border-box;
}

.trace-wipe__knob::before {
  left: 9px;
  transform: rotate(-45deg);
}

.trace-wipe__knob::after {
  right: 9px;
  transform: rotate(135deg);
}

.trace-wipe[data-state='dragging'] .trace-wipe__knob {
  scale: 0.92;
  transition: scale 0.12s ease-out;
}

.trace-wipe:has(.trace-wipe__range:focus-visible) .trace-wipe__knob {
  outline: 2px solid var(--trace-ice, #a9d2ff);
  outline-offset: 3px;
}

.trace-wipe[data-state='ready'],
.trace-wipe[data-state='dragging'] {
  cursor: ew-resize;
}

/* ---------------------------------------------------------------- arrive */

.trace-arrive__lines {
  position: absolute;
  display: block;
  pointer-events: none;
  object-fit: cover;
  opacity: 0;
}
