/* cat-card.css
 *
 * The cat card (js/scenes/day-beach/cat-card.js): a polaroid that rises
 * gently from the sand, slightly tilted, with a handwritten note in dark
 * ink below the photo, and hand-drawn arrows just under the photo to the
 * previous and next photo. For visitors who want less motion, it only
 * fades in.
 */

.cat-card {
  /* Each photo is shown whole, in its own shape (from its width and
     height in index.html, so its space is kept while it loads).
     --tallest-photo-shape is the shape (width / height) of the tallest of
     them; cat-card.js sets it from the photos. */
  --tallest-photo-shape: 0.694;

  /* The card's size: at most --card-widest wide and --card-screen-share
     of the screen's width; and the whole card, the note included, at most
     --card-tallest of the screen's height. For that, the tallest photo is
     at most the height left after --card-note-room for the arrows, the
     note and the paper around them, and the card is as wide as that photo. (Wider photos
     make the card shorter.) (--card-screen-share leaves room for the
     tilt: a tall card's corners swing out further.) */
  --card-widest: 21rem;
  --card-screen-share: 78vw;
  --card-tallest: 92dvh;
  --card-note-room: 17.5rem;
  --card-paper-sides: 1.5rem;
  --card-width: min(
    var(--card-screen-share),
    var(--card-widest),
    calc((var(--card-tallest) - var(--card-note-room)) * var(--tallest-photo-shape) + var(--card-paper-sides))
  );

  /* On a short, wide screen (see the end of this file) the note goes beside
     the photo instead of below it, --card-note-beside wide; the photo is
     at most as wide as leaves --card-beside-rest for the paper, the gap
     and the screen's edges. */
  --card-note-beside: 13rem;
  --card-beside-rest: 5rem;

  /* The arrows under the photo: each one's size (its tap area, with the
     drawing inside it), how far an arrow moves on hover; and how a new
     photo fades in. */
  --card-turn-width: 2.75rem;
  --card-turn-row: 2.75rem;
  --card-turn-nudge: 3px;
  --card-photo-fades-in: 0.35s;

  /* Its tilt, its paper and its ink. */
  --card-tilt: -3deg;
  --card-paper: #f8f4ec;
  --card-ink: #262a3d;
  --card-link-underline: rgba(38, 42, 61, 0.45);
  --card-shadow: 0 2px 4px rgba(10, 20, 40, 0.25), 0 18px 40px rgba(10, 20, 40, 0.35);
  /* Rising: from this far below (it starts down on the sand), turned this
     much further, over --card-rises; closing: fading over --card-closes. */
  --card-rise-from: 38vh;
  --card-rise-turn: 4deg;
  --card-rises: 1.1s;
  --card-fades-in: 0.5s;
  --card-closes: 0.3s;
  --card-backdrop: rgba(8, 18, 40, 0.3);

  /* The dialog is exactly the card's size (see cat-card.js: a click on
     the dialog itself is outside the card). */
  width: var(--card-width);
  max-width: none;
  max-height: none;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
}

/* As the photos change the card's shape, its bottom-right corner stays
   still, and with it the arrows under the photo (the photo grows and
   shrinks above them), so they do not move away from the pointer. cat-card.js works out where the corner goes: where it is when
   the card is centred on the screen showing its largest photo. */
.cat-card.is-held {
  top: auto;
  left: auto;
  bottom: var(--card-bottom);
  right: var(--card-right);
  margin: 0;
}

.cat-card::backdrop {
  background: var(--card-backdrop);
  animation: cat-card-fade-in var(--card-fades-in) ease both;
}

.cat-card__polaroid {
  position: relative;
  padding: 0.75rem 0.75rem 1.1rem;
  background: var(--card-paper);
  border-radius: 2px;
  box-shadow: var(--card-shadow);
  color: var(--card-ink);
  rotate: var(--card-tilt);
  /* Turned about its bottom-right corner, which stays still (cat-card.js). */
  transform-origin: 100% 100%;
  animation: cat-card-rise var(--card-rises) cubic-bezier(0.2, 0.75, 0.25, 1) both;
}

/* Focus starts on the card itself (so it does not jump to the first
   link); no ring for that. */
.cat-card__polaroid:focus {
  outline: none;
}

.cat-card__photo {
  display: block;
  width: 100%;
  height: auto;
  /* While the photo is on its way. */
  background: #d9d2c4;
  user-select: none;
  -webkit-user-select: none;
}

/* (display: block above would otherwise show the hidden photos.) */
.cat-card__photo[hidden] {
  display: none;
}

.cat-card__photo.is-arriving {
  animation: cat-card-fade-in var(--card-photo-fades-in) ease both;
}

.cat-card__note {
  margin-top: 0;
  font-family: "Nanum Pen Script", cursive;
  font-weight: 400;
  font-synthesis: none;
  font-size: 1.6rem;
  line-height: 1.05;
}

.cat-card__note p {
  margin: 0 0 0.35em;
}

.cat-card__note p:last-child {
  margin-bottom: 0;
}

/* The row under the photo: the previous arrow at its left end, the next
   at its right, each drawing lined up with the photo's edge. */
.cat-card__turn {
  display: flex;
  justify-content: space-between;
  height: var(--card-turn-row);
}

.cat-card__previous,
.cat-card__next {
  width: var(--card-turn-width);
  height: 100%;
  padding: 0.6rem 0.25rem;
  border: 0;
  background: none;
  color: var(--card-ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.cat-card__previous {
  margin-left: -0.25rem;
}

.cat-card__next {
  margin-right: -0.25rem;
}

.cat-card__previous svg,
.cat-card__next svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: translate 0.2s ease;
}

/* The previous arrow is the same drawing, turned round. */
.cat-card__previous svg {
  scale: -1 1;
}

@media (hover: hover) {
  .cat-card__next:hover svg {
    translate: var(--card-turn-nudge) 0;
  }

  .cat-card__previous:hover svg {
    translate: calc(-1 * var(--card-turn-nudge)) 0;
  }
}

.cat-card__previous:focus-visible,
.cat-card__next:focus-visible {
  outline: 2px solid var(--card-ink);
  outline-offset: -2px;
  border-radius: 4px;
}

.cat-card__note a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--card-link-underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.12em;
}

.cat-card__note a:hover {
  text-decoration-color: currentColor;
}

.cat-card__note a:focus-visible {
  outline: 2px solid var(--card-ink);
  outline-offset: 2px;
  border-radius: 2px;
}

/* A short, wide screen (a phone on its side, a small laptop): below the
   photo there is no room for the note, so it goes beside the photo, and
   the photo is as tall as the card can be. The card is as wide as the
   two together. */
@media (orientation: landscape) and (max-height: 660px) {
  .cat-card {
    width: fit-content;
    /* Shorter: the card is wide here, so tilted, its far corner drops. */
    --card-tallest: 82dvh;
  }

  .cat-card__polaroid {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
  }

  .cat-card__pictures {
    flex: none; /* never squeezed out of shape */
  }

  /* As tall as the card can be, with the arrows under it, unless that
     would make a wide photo too wide for the screen. (--photo-shape: this
     photo's width / height, set by cat-card.js.) */
  .cat-card__photo {
    width: auto;
    height: min(
      calc(var(--card-tallest) - 1.85rem - var(--card-turn-row)),
      calc((100vw - var(--card-note-beside) - var(--card-beside-rest)) / var(--photo-shape))
    );
  }

  .cat-card__note {
    width: var(--card-note-beside);
    margin-top: 0;
    /* Its last line level with the arrows. */
    margin-bottom: 0.45rem;
  }
}

/* Closing: the card and the backdrop fade out. */
.cat-card.is-closing .cat-card__polaroid {
  animation: cat-card-fade-out var(--card-closes) ease both;
}

.cat-card.is-closing::backdrop {
  animation: cat-card-fade-out var(--card-closes) ease both;
}

@media (prefers-reduced-motion: reduce) {
  .cat-card__polaroid {
    animation: cat-card-fade-in var(--card-fades-in) ease both;
  }
}

@keyframes cat-card-rise {
  from {
    opacity: 0;
    translate: 0 var(--card-rise-from);
    rotate: calc(var(--card-tilt) + var(--card-rise-turn));
  }
  45% {
    opacity: 1;
  }
  to {
    opacity: 1;
    translate: 0 0;
    rotate: var(--card-tilt);
  }
}

@keyframes cat-card-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes cat-card-fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}
