/* sea-life.css
 *
 * The sea creatures (js/scenes/underwater/sea-life.js), and the dive-log
 * note that opens beside one when it is clicked (dive-log.js).
 */

#scene-underwater {
  /* A distant fish: softer and fainter, so the water's blue shows through
     it (it is also coloured a little bluer, in swimmer.js). */
  --far-opacity: 0.55;
  --far-blur: 1.1px;
  --far-saturation: 0.8;

  /* A creature with keyboard focus: a soft ring. */
  --creature-focus: rgba(244, 237, 224, 0.85);

  /* The dive-log note: a small handwritten note on light paper, tilted a
     little, fading in over --note-fades-in (rising --note-rise). */
  --note-width: min(15rem, 78vw);
  --note-paper: #f8f4ec;
  --note-ink: #262a3d;
  --note-tilt: -2deg;
  --note-shadow: 0 2px 4px rgba(10, 20, 40, 0.22), 0 12px 28px rgba(10, 20, 40, 0.3);
  --note-name-size: 1.9rem;
  --note-size: 1.45rem;
  --note-fades-in: 0.35s;
  --note-rise: 8px;
}

/* ---- The creatures ----------------------------------------------------- */

/* The whole scene, under the light rays (the scene's later layer): the
   creatures are in the water. Only the creatures themselves
   take clicks. */
.sea-life {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

/* Each creature: placed (by transform) in the scene, so it scrolls with
   the painting. A near one is a button, larger than its picture so it is
   easy to catch while it moves; nothing about it looks like a button. */
.creature {
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 40%;
  background: none;
  pointer-events: auto;
  cursor: pointer;
  will-change: transform;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.creature:focus-visible {
  outline: 2px solid var(--creature-focus);
  outline-offset: -4px;
}

.creature__picture {
  display: block;
  /* Turned and mirrored by swimmer.js. */
  transform-origin: 50% 50%;
}

.creature--far {
  pointer-events: none;
  opacity: var(--far-opacity);
  filter: blur(var(--far-blur)) saturate(var(--far-saturation));
}

/* The extra sea urchins about the reef: scenery, not buttons (only the
   first one opens the urchin's dive log). */
.creature--scenery {
  pointer-events: none;
  cursor: default;
}

/* (The words lie above the creatures and let clicks through to them,
   except on their links: see underwater-words.css.) */

/* ---- The dive-log note -------------------------------------------------- */

/* Above everything in the scene (the words, the light). Placed by
   dive-log.js, beside its creature. */
.dive-log {
  position: absolute;
  z-index: 3;
  width: var(--note-width);
  padding: 0.85rem 1.1rem 1rem;
  border-radius: 3px;
  background: var(--note-paper);
  box-shadow: var(--note-shadow);
  color: var(--note-ink);
  font-family: "Nanum Pen Script", cursive;
  font-weight: 400;
  font-synthesis: none;
  font-size: var(--note-size);
  line-height: 1.1;
  rotate: var(--note-tilt);
}

/* Keyboard focus moves into the note when it opens (so a screen reader
   reads it); no ring for that. */
.dive-log:focus {
  outline: none;
}

.dive-log p {
  margin: 0;
}

.dive-log .dive-log__name {
  margin-bottom: 0.2em;
  font-size: var(--note-name-size);
  line-height: 1;
}

.dive-log .dive-log__note {
  margin-top: 0.35em;
}

.dive-log.is-open {
  animation: dive-log-in var(--note-fades-in) ease-out both;
}

@keyframes dive-log-in {
  from {
    opacity: 0;
    translate: 0 var(--note-rise);
  }
  to {
    opacity: 1;
    translate: 0 0;
  }
}

/* For less motion: it only fades in. */
@media (prefers-reduced-motion: reduce) {
  .dive-log.is-open {
    animation-name: dive-log-fade-in;
  }
}

@keyframes dive-log-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
