/* The frame is the journal page: a sheet of blue sugar paper. Everything on it is a cut or torn piece with
   its own tilt and its own shadow. Frame coordinates (CSS px): heading 12..122, photos below, tag bottom right. */
.tj {
  --ink: #16130f;
  --white: #f6f5f1;
  --red: #e23a26;
  --yellow: #ffd21e;
  --lay: drop-shadow(0 1px 0.6px rgb(4 10 60 / 0.5)) drop-shadow(0 3px 5px rgb(4 10 60 / 0.34));
  position: relative;
  display: block;
  width: 540px;
  height: 540px;
  overflow: hidden;
  background: #1b3fd0 url("./page.jpg") center / cover;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

.tj *,
.tj *::before,
.tj *::after { box-sizing: border-box; }

.tj-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---- cut paper: the shadow sits on the piece, the scissor line on its face ---- */
.tj-cut {
  position: relative;
  display: inline-block;
  flex: none;
  filter: var(--lay);
}

.tj-cut > i {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  background-image: url("./grain.png");
  background-size: 128px 80px;
  background-blend-mode: multiply;
  font-style: normal;
  line-height: 1;
  white-space: nowrap;
}

.tj-cut[data-edge="0"] > i { clip-path: polygon(3% 5%, 97% 0%, 100% 94%, 5% 100%); }
.tj-cut[data-edge="1"] > i { clip-path: polygon(0% 4%, 52% 0%, 100% 6%, 96% 100%, 4% 95%); }
.tj-cut[data-edge="2"] > i { clip-path: polygon(5% 0%, 100% 4%, 95% 100%, 48% 97%, 0% 99%); }
.tj-cut[data-edge="3"] > i { clip-path: polygon(1% 7%, 98% 2%, 100% 58%, 97% 100%, 3% 94%); }

/* ---- the heading: DAY 3 / MATERA ---- */
.tj-day,
.tj-place {
  position: absolute;
  z-index: 8;
  display: flex;
  align-items: flex-end;
}

.tj-day {
  left: 17px;
  top: 12px;
  gap: 3px;
}

.tj-place {
  left: 13px;
  top: 55px;
  gap: 1px;
}

.tj-date {
  position: absolute;
  z-index: 8;
  right: 12px;
  top: 83px;
  padding: 9px 20px 6px 22px;
  background: url("./scrap-2.png") center / 100% 100% no-repeat;
  font: 700 15px/1 "Courier Prime", monospace;
  white-space: nowrap;
  rotate: 2.5deg;
  filter: var(--lay);
}

/* ---- the count: a numeral and a word, cut from different pages. A new numeral is pressed down in the old
   one's place, so there is only ever one. ---- */
.tj-count {
  position: absolute;
  z-index: 8;
  right: 15px;
  top: 14px;
  display: flex;
  align-items: center;
}

.tj-now {
  z-index: 1;
  width: 40px;
  height: 50px;
  rotate: -5deg;
  animation: tj-land 200ms cubic-bezier(0.2, 0.9, 0.3, 1.25) both;
}

.tj-now > i {
  background-color: #ff9ab5;
  font: 400 38px/1 "Anton", sans-serif;
}

@keyframes tj-land {
  from {
    rotate: -14deg;
    scale: 1.35;
  }
}

@keyframes tj-was {
  to { visibility: hidden; }
}

.tj-word {
  height: 26px;
  margin-left: -3px;
  rotate: 3deg;
}

.tj-word > i {
  padding: 1px 11px 0 12px;
  background-color: var(--ink);
  color: #fff;
  font: 400 13px/1 "Archivo Black", sans-serif;
  letter-spacing: 0.08em;
}

/* ---- photos ---- */
.tj-list {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  outline: none;
  pointer-events: none;
  transition: opacity 180ms;
}

.tj-item {
  position: absolute;
  inset: 0;
  display: block;
  outline: none;
  pointer-events: none;
}

.tj-item:hover { z-index: 6; }
.tj-item:focus-visible { z-index: 7; }

/* the slot: where the photo lives on the page; photos re-seat themselves when one is peeled off */
.tj-slot {
  position: absolute;
  translate: -50% -50%;
  pointer-events: auto;
  transition:
    left 560ms cubic-bezier(0.3, 0.7, 0.2, 1),
    top 560ms cubic-bezier(0.3, 0.7, 0.2, 1),
    rotate 560ms cubic-bezier(0.3, 0.7, 0.2, 1);
}

/* where a photo is about to land: the cut line of the slot it is taking, gone once the print covers it */
.tj-mark {
  position: absolute;
  inset: 0;
  border: 2px dashed #fff;
  animation: tj-was 700ms steps(1) both;
  pointer-events: none;
}

/* the slide: from where it was let go, lifted and turned, down flat onto the page */
.tj-fly {
  position: absolute;
  inset: 0;
  filter: drop-shadow(0 1px 1px rgb(4 10 60 / 0.5)) drop-shadow(0 5px 9px rgb(4 10 60 / 0.38));
  animation: tj-arrive 760ms cubic-bezier(0.3, 0.6, 0.3, 1) both;
}

@keyframes tj-arrive {
  from {
    translate: var(--dx) var(--dy);
    rotate: var(--spin);
    scale: 1.12;
    filter: drop-shadow(0 2px 2px rgb(4 10 60 / 0.3)) drop-shadow(0 22px 26px rgb(4 10 60 / 0.5));
  }
  70% {
    scale: 1.05;
    filter: drop-shadow(0 2px 2px rgb(4 10 60 / 0.34)) drop-shadow(0 14px 18px rgb(4 10 60 / 0.44));
  }
}

.tj-print {
  position: absolute;
  inset: 0;
  background: #d8d2c6;
}

.tj-print img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* scissor lines: nearly straight, never quite */
.tj-print[data-edge="0"] { clip-path: polygon(0.5% 1.4%, 31% 0%, 68% 1.1%, 99.5% 0.2%, 100% 47%, 99% 99.2%, 61% 100%, 27% 98.6%, 0.2% 99.7%, 0% 52%); }
.tj-print[data-edge="1"] { clip-path: polygon(1.2% 0.3%, 52% 0.9%, 98.6% 0%, 100% 38%, 99.2% 99.6%, 44% 100%, 0% 98.8%, 0.8% 55%); }
.tj-print[data-edge="2"] { clip-path: polygon(0% 0.9%, 43% 0%, 99.7% 1.6%, 99% 51%, 100% 98.8%, 57% 100%, 1% 99.1%, 0.4% 44%); }
.tj-print[data-edge="3"] { clip-path: polygon(1.6% 0%, 99.2% 0.7%, 100% 62%, 98.4% 100%, 50% 99.2%, 0.6% 100%, 0% 31%); }
.tj-print[data-edge="4"] { clip-path: polygon(0.3% 1.1%, 60% 0%, 100% 1.3%, 99.3% 100%, 36% 98.9%, 0% 99.8%); }
.tj-print[data-edge="5"] { clip-path: polygon(0.9% 0%, 99% 1%, 100% 49%, 99.4% 99%, 0% 100%, 0.7% 50%); }

/* masking tape: pressed on as the photo comes to rest */
.tj-tape {
  position: absolute;
  width: 96px;
  height: 23px;
  /* paper tape lets a little of what is under it through, and is warmer than the page */
  opacity: 0.86;
  filter: sepia(0.35) saturate(1.5) brightness(1.07) contrast(1.06) drop-shadow(0 1px 1px rgb(4 10 60 / 0.32));
  animation: tj-stick 200ms 600ms cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
  pointer-events: none;
}

.tj-tape[data-at="0"] { top: -11px; left: calc(50% - 60px); rotate: -4deg; }
.tj-tape[data-at="1"] { top: -11px; left: calc(50% - 40px); rotate: 6deg; }
.tj-tape[data-at="2"] { top: -10px; left: 26px; rotate: -7deg; }
.tj-tape[data-at="3"] { top: 7px; right: -33px; rotate: 41deg; }
.tj-tape[data-at="4"] { top: 8px; left: -33px; rotate: -43deg; }
.tj-tape[data-at="5"] { top: -11px; left: calc(50% - 48px); rotate: 2deg; }

@keyframes tj-stick {
  from {
    opacity: 0;
    scale: 1.35;
  }
}

/* the caption: the time on one scrap, the name on another, stuck over a bottom corner above every photo.
   It arrives on its print, making the same slide (see tj-arrive) about the print's centre. */
.tj-note {
  position: absolute;
  z-index: 5;
  width: 0;
  height: 0;
  animation: tj-ride 760ms cubic-bezier(0.3, 0.6, 0.3, 1) both;
}

@keyframes tj-ride {
  from {
    translate: var(--px) var(--py);
    rotate: var(--spin);
    scale: 1.12;
  }
  70% { scale: 1.05; }
}

.tj-note-in {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  translate: 0 -50%;
  transform-origin: 0 50%;
  filter: drop-shadow(0 1px 0.6px rgb(4 10 60 / 0.45)) drop-shadow(0 2px 3px rgb(4 10 60 / 0.3));
}

.tj-note[data-side="right"] .tj-note-in {
  left: auto;
  right: 0;
  transform-origin: 100% 50%;
}

.tj-note b {
  position: relative;
  z-index: 1;
  flex: none;
  margin-right: -5px;
  padding: 4px 6px 3px 7px;
  background: var(--ink);
  clip-path: polygon(4% 0%, 100% 6%, 96% 100%, 0% 94%);
  color: #fff;
  font: 400 15px/1 "Anton", sans-serif;
  letter-spacing: 0.03em;
  rotate: -5deg;
}

.tj-note-in > span {
  padding: 7px 14px 4px 15px;
  overflow: hidden;
  background: url("./scrap-1.png") center / 100% 100% no-repeat;
  font: 700 13px/1 "Courier Prime", monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* peel a photo off: a round red sticker at its corner, shown to the pointer and to the keyboard */
.tj-remove {
  position: absolute;
  top: -11px;
  left: -11px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--red) url("./grain.png") center / 128px 80px;
  background-blend-mode: multiply;
  color: #fff;
  opacity: 0;
  scale: 0.6;
  cursor: pointer;
  transition: opacity 120ms, scale 160ms cubic-bezier(0.2, 0.9, 0.3, 1.4);
}

.tj-remove svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
}

.tj-item:hover .tj-remove,
.tj-item:focus-visible .tj-remove {
  opacity: 1;
  scale: 1;
}

.tj-remove:hover { background-color: #c22a18; }

/* keyboard focus: a solid white frame held off the print (dashes are kept for the open slot) */
.tj-item:focus-visible .tj-fly::after {
  content: "";
  position: absolute;
  inset: -8px;
  border: 3px solid #fff;
  pointer-events: none;
}

/* ---- the open slot: a cut line around the next free place ---- */
/* a point at the place's centre: the cut line and the words hang from it, so a change of place is a transform
   and a change of size moves nothing but the line */
.tj-anchor {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 4;
  pointer-events: none;
  transition: translate 260ms cubic-bezier(0.2, 0.9, 0.3, 1);
}

.tj-anchor:has(.tj-open[data-over]) { z-index: 6; }

.tj-open {
  position: absolute;
  left: 0;
  top: 0;
  translate: -50% -50%;
  border: 2px dashed #fff;
  background: rgb(6 16 96 / 0.34);
  transition: border-color 140ms, background-color 140ms, scale 180ms cubic-bezier(0.2, 0.9, 0.3, 1.3);
}

.tj-face {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 11px;
  translate: -50% -50%;
  color: #fff;
  pointer-events: auto;
}

.tj-snip {
  position: absolute;
  top: -10px;
  left: 14px;
  width: 18px;
  height: 18px;
  fill: #1b3fd0;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  rotate: -90deg;
}

.tj-say {
  display: grid;
  justify-items: center;
  gap: 7px;
  text-align: center;
}

.tj-say b {
  font: 400 15px/17px "Archivo Black", sans-serif;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  white-space: nowrap;
}

.tj-say small {
  font: 700 12px/1 "Courier Prime", monospace;
  white-space: nowrap;
}

.tj-say-ok,
.tj-say-no { display: none; }

/* the last place lies over the other photos, so there the slot is a solid piece above their captions */
.tj-open[data-over] {
  background: rgb(14 30 128 / 0.94);
  box-shadow: 0 0 0 5px rgb(14 30 128 / 0.94), 0 6px 14px 5px rgb(4 10 60 / 0.4);
}

/* a slot the size of a full print has room for larger words */
.tj-face[data-roomy] { gap: 14px; }
.tj-face[data-roomy] .tj-say b { font-size: 19px; line-height: 21px; }
.tj-face[data-roomy] .tj-say small { font-size: 13px; }
.tj-face[data-roomy] .tj-add i { padding: 12px 15px 11px 16px; font-size: 14px; }

/* files over the page: the slot lifts and says what letting go will do */
.tj[data-dragging] .tj-open {
  border-color: var(--yellow);
  border-width: 3px;
  background: rgb(6 16 96 / 0.6);
  scale: 1.06;
}

.tj[data-dragging] .tj-list { opacity: 0.5; }
.tj[data-dragging] .tj-say-idle { display: none; }
.tj[data-dragging] .tj-say-ok { display: block; color: var(--yellow); }

.tj[data-drag-reject] .tj-open { border-color: #ff7a66; }
.tj[data-drag-reject] .tj-say-ok { display: none; }
.tj[data-drag-reject] .tj-say-no { display: block; color: #ff8f7d; }

/* ---- add photos: a yellow tag, stuck inside the slot ---- */
.tj-add {
  position: relative;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  rotate: -3deg;
  cursor: pointer;
  outline: none;
  transition: translate 140ms, rotate 140ms;
}

.tj-add .tj-cut { display: block; }

.tj-add i {
  padding: 10px 10px 9px 11px;
  background-color: var(--yellow);
  font: 400 12px/1 "Archivo Black", sans-serif;
  letter-spacing: 0.05em;
}

.tj-add:hover { translate: 0 -2px; rotate: -1.5deg; }
.tj-add:active { translate: 0 1px; }

.tj-add:focus-visible::after {
  content: "";
  position: absolute;
  inset: -6px;
  border: 3px solid #fff;
}

/* a full page has no slot: the tag stays, greyed, over the last place */
.tj-add[data-full] {
  position: absolute;
  z-index: 9;
  left: 388px;
  top: 366px;
  cursor: default;
  translate: none;
  rotate: -3deg;
}

.tj-add[data-full] i {
  background-color: #c9cede;
  color: #4a5270;
}

.tj[data-drag-reject] .tj-add[data-full] i {
  background-color: var(--red);
  color: #fff;
}

/* ---- a file that did not stick: a red slip slides in and says why ---- */
.tj-slip {
  position: absolute;
  z-index: 11;
  left: 14px;
  bottom: 16px;
  display: flex;
  align-items: center;
  max-width: 340px;
  rotate: 2deg;
  filter: var(--lay);
  animation: tj-slip 4200ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.tj-slip b {
  position: relative;
  z-index: 1;
  flex: none;
  margin-right: -6px;
  padding: 9px 12px 8px 13px;
  background: var(--red) url("./grain.png") center / 128px 80px;
  background-blend-mode: multiply;
  clip-path: polygon(2% 6%, 98% 0%, 100% 92%, 0% 100%);
  color: #fff;
  font: 400 14px/1 "Archivo Black", sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  rotate: -3deg;
  white-space: nowrap;
}

.tj-slip span {
  min-width: 0;
  padding: 10px 18px 7px 18px;
  overflow: hidden;
  background: url("./scrap-1.png") center / 100% 100% no-repeat;
  font: 700 14px/1 "Courier Prime", monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@keyframes tj-slip {
  0% { translate: -380px 0; }
  9%, 91% { translate: 0 0; }
  100% { translate: -380px 0; }
}
