/* swim-back.css
 *
 * "Swim back up to the beach": the way back from the underwater scene,
 * handwritten (lettered and painted by hand: underwater-words.js), with a
 * little arrow doodled pointing up to the surface. At the very top left of
 * the scene, in the surface's bright ripples, above the title; it scrolls
 * away with the painting. Like "Walk back to the beach" on the night beach
 * (night-words.css), but lit by the water's pale blue light rather than
 * the fire.
 */

/* The glow's two colours, as properties the browser knows are colours, so
   they fade in and out smoothly. */
@property --swim-glow-near {
  syntax: "<color>";
  inherits: true;
  initial-value: rgba(170, 215, 255, 0);
}

@property --swim-glow-far {
  syntax: "<color>";
  inherits: true;
  initial-value: rgba(170, 215, 255, 0);
}

#scene-underwater .swim-back {
  /* Its size; how far down from the top of the scene it sits (a little
     way down, so it does not hug the edge); and, on a narrow screen,
     where it would meet the sound button and the "Résumé" link at the top
     right, below them. */
  --swim-back-size: clamp(1.7rem, 1.4rem + 0.8vw, 2.25rem);
  --swim-back-top: max(clamp(2.5rem, 6vh, 4rem), env(safe-area-inset-top));
  --swim-back-top-narrow: calc(max(1rem, env(safe-area-inset-top)) + 2.25rem + 1rem);
  /* The arrow's height (its width is half that) and line. */
  --swim-back-arrow: 1.1em;
  --swim-back-arrow-stroke: 2.4;
  /* Hovered or focused: a paler colour, glowing with the water's light
     (near and far), lifted --swim-back-lift, over --swim-back-lights-up. */
  --swim-back-lit: #f2fbff;
  --swim-back-glow-near: rgba(170, 215, 255, 0.85);
  --swim-back-glow-near-blur: 4px;
  --swim-back-glow-far: rgba(130, 195, 255, 0.55);
  --swim-back-glow-far-blur: 12px;
  --swim-back-lift: 3px;
  --swim-back-lights-up: 0.4s;

  position: absolute;
  top: var(--swim-back-top);
  left: var(--words-side);
  /* Above the creatures and the light, with the words. */
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 0.3em;
  min-height: 44px;
  padding: 0.15em 0.3em;
  border-radius: 10px;
  font-size: var(--swim-back-size);
  color: var(--warm-white);
  text-decoration: none;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Where the screen is too narrow for it beside the sound button and the
   "Résumé" link at the top right: just below them. */
@media (max-width: 620px) {
  #scene-underwater .swim-back {
    top: var(--swim-back-top-narrow);
  }
}

/* The arrow and the words, painted, with the soft shadow, and (on hover)
   the glow. */
.swim-back__arrow,
.swim-back__words {
  filter: var(--hand-paint,) var(--hand-shadow)
    drop-shadow(0 0 var(--swim-back-glow-near-blur) var(--swim-glow-near))
    drop-shadow(0 0 var(--swim-back-glow-far-blur) var(--swim-glow-far));
  transition: --swim-glow-near var(--swim-back-lights-up) ease, --swim-glow-far var(--swim-back-lights-up) ease, color var(--swim-back-lights-up) ease, transform var(--swim-back-lights-up) ease;
}

.swim-back__words {
  white-space: nowrap;
}

/* The cat card's hand-drawn arrow, turned to point up, a little askew. */
.swim-back__arrow {
  flex: none;
  width: calc(var(--swim-back-arrow) / 2);
  height: var(--swim-back-arrow);
  fill: none;
  stroke: currentColor;
  stroke-width: var(--swim-back-arrow-stroke);
  stroke-linecap: round;
  stroke-linejoin: round;
  rotate: 6deg;
}

@media (hover: hover) {
  .swim-back:hover :is(.swim-back__arrow, .swim-back__words) {
    --swim-glow-near: var(--swim-back-glow-near);
    --swim-glow-far: var(--swim-back-glow-far);
    color: var(--swim-back-lit);
    transform: translateY(calc(-1 * var(--swim-back-lift)));
  }
}

/* A clear ring for keyboard focus (--focus-ring, underwater-words.css). */
.swim-back:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* On a touch screen: a little more room to tap, and it lights up while
   pressed. */
@media (pointer: coarse) {
  #scene-underwater .swim-back {
    padding: 0.2em 0.45em;
  }

  .swim-back:active :is(.swim-back__arrow, .swim-back__words) {
    --swim-glow-near: var(--swim-back-glow-near);
    --swim-glow-far: var(--swim-back-glow-far);
    color: var(--swim-back-lit);
  }
}

.swim-back:focus-visible :is(.swim-back__arrow, .swim-back__words) {
  --swim-glow-near: var(--swim-back-glow-near);
  --swim-glow-far: var(--swim-back-glow-far);
  color: var(--swim-back-lit);
}

/* For less motion: it lights up, but does not lift. */
@media (prefers-reduced-motion: reduce) {
  .swim-back:hover :is(.swim-back__arrow, .swim-back__words) {
    transform: none;
  }
}
