/*
 * Atmosphere for "The Descent": light rays, bubbles, drawn creatures and the depth gauge.
 * Everything here is decorative (aria-hidden) and stops moving with reduced motion.
 */

:root {
  --creature-fill: #03182b;
  --creature-rim: rgb(126 249 238 / 0.45);
  --creature-spot: rgb(214 250 246 / 0.9);
}

/* ---------- Light rays just below the surface ---------- */

.rays {
  position: absolute;
  inset: 0 0 auto;
  z-index: 0;
  height: 120vh;
  pointer-events: none;
  background:
    linear-gradient(100deg, transparent 16%, rgb(239 252 251 / 0.1) 21%, transparent 27%),
    linear-gradient(96deg, transparent 38%, rgb(239 252 251 / 0.07) 42%, transparent 48%),
    linear-gradient(104deg, transparent 57%, rgb(239 252 251 / 0.09) 61%, transparent 66%),
    linear-gradient(98deg, transparent 76%, rgb(239 252 251 / 0.06) 80%, transparent 86%);
  -webkit-mask-image: linear-gradient(180deg, #000, rgb(0 0 0 / 0.5) 40%, transparent 100%);
  mask-image: linear-gradient(180deg, #000, rgb(0 0 0 / 0.5) 40%, transparent 100%);
  transform-origin: 50% 0;
  animation: rays-sway 16s ease-in-out infinite alternate;
}

@keyframes rays-sway {
  from { transform: skewX(-5deg); opacity: 0.8; }
  to { transform: skewX(5deg); opacity: 1; }
}

/* ---------- Bubbles (created by js/ocean.js) ---------- */

.bubbles {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
}

.bubble {
  position: absolute;
  bottom: -24px;
  left: var(--x);
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, rgb(255 255 255 / 0.7), rgb(126 249 238 / 0.12) 55%, transparent 72%);
  box-shadow: inset 0 0 0 1px rgb(239 252 251 / 0.3);
  animation: rise var(--dur) linear var(--delay) infinite;
  will-change: transform;
}

@keyframes rise {
  0% { transform: translate3d(0, 0, 0); opacity: 0; }
  8% { opacity: 1; }
  50% { transform: translate3d(var(--sway), -55vh, 0); }
  92% { opacity: 0.8; }
  100% { transform: translate3d(0, -112vh, 0); opacity: 0; }
}

/* ---------- Creatures ---------- */

.creature {
  position: absolute;
  left: 0;
  z-index: 0;
  width: var(--w);
  pointer-events: none;
}

.creature__svg {
  display: block;
  width: 100%;
  height: auto;
  max-width: none;
  overflow: visible;
  opacity: var(--creature-opacity, 0.55);
}

.creature--leftward .creature__svg { transform: scaleX(-1); }

.creature__shape {
  fill: var(--creature-fill);
  stroke: var(--creature-rim);
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
}

.creature__line {
  fill: none;
  stroke: var(--creature-rim);
  stroke-width: 1.4;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.whaleshark__spots { fill: var(--creature-spot); }

.creature--manta { --w: clamp(150px, 30vw, 300px); --rest-x: 56vw; top: 24px; }
.creature--fish { --w: clamp(130px, 20vw, 220px); --rest-x: 6vw; top: -40px; }
.creature--turtle { --w: clamp(90px, 13vw, 150px); --rest-x: 66vw; top: 62%; }
.creature--whaleshark { --w: clamp(280px, 62vw, 640px); --rest-x: 12vw; --creature-opacity: 0.78; top: 24px; }

.creature--manta .creature__drift { animation: drift-right 38s linear -9s infinite; }
.creature--fish .creature__drift { animation: drift-left 30s linear -16s infinite; }
.creature--turtle .creature__drift { animation: drift-right 48s linear -31s infinite; }
.creature--whaleshark .creature__drift { animation: drift-left 72s linear -26s infinite; }

@keyframes drift-right {
  from { transform: translateX(-110%); }
  to { transform: translateX(100vw); }
}

@keyframes drift-left {
  from { transform: translateX(100vw); }
  to { transform: translateX(-110%); }
}

/* Swim motions */

.manta__body {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  animation: flap 3.6s ease-in-out infinite;
}

@keyframes flap {
  0%, 100% { transform: scaleX(1); }
  50% { transform: scaleX(0.8); }
}

.turtle__flipper {
  transform-box: fill-box;
  transform-origin: 95% 40%;
  animation: stroke-left 3.2s ease-in-out infinite;
}

.turtle__flipper--right {
  transform-origin: 5% 40%;
  animation-name: stroke-right;
}

@keyframes stroke-left {
  0%, 100% { transform: rotate(8deg); }
  50% { transform: rotate(-16deg); }
}

@keyframes stroke-right {
  0%, 100% { transform: rotate(-8deg); }
  50% { transform: rotate(16deg); }
}

.whaleshark__tail {
  transform-box: fill-box;
  transform-origin: 100% 58%;
  animation: sway 3s ease-in-out infinite;
}

@keyframes sway {
  0%, 100% { transform: rotate(5deg); }
  50% { transform: rotate(-5deg); }
}

.fish { animation: fish-bob 2.6s ease-in-out var(--d, 0s) infinite; }

@keyframes fish-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

/* ---------- Depth gauge ---------- */

.gauge {
  position: fixed;
  top: 50%;
  right: max(6px, env(safe-area-inset-right));
  z-index: 20;
  width: 14px;
  height: min(52vh, 380px);
  pointer-events: none;
  transform: translateY(-50%);
}

.gauge__track {
  position: absolute;
  inset: 0 auto 0 50%;
  width: 1px;
  background: rgb(239 252 251 / 0.28);
}

.gauge__tick {
  position: absolute;
  top: calc(var(--at) * 100%);
  right: -3px;
  width: 7px;
  height: 1px;
  background: rgb(239 252 251 / 0.5);
}

.gauge__tick b { display: none; }

.gauge__marker {
  position: absolute;
  top: calc(var(--progress, 0) * 100%);
  left: -6px;
  width: 13px;
  height: 2px;
  background: var(--xdc-red);
  box-shadow: 0 0 10px rgb(236 30 36 / 0.7);
}

/* The diver rides the line as the depth marker. It and its counter are one grab handle:
   drag it up or down to scroll (js/ocean.js). */
.gauge__handle {
  --diver-w: 46px;
  position: absolute;
  top: calc(var(--progress, 0) * 100%);
  right: 9px;
  width: var(--diver-w);
  pointer-events: auto;
  touch-action: none;
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
  transform: translateY(-50%);
}

/* A bigger grab area than the drawing, for fingers; it also covers the counter above. */
.gauge__handle::before {
  content: "";
  position: absolute;
  inset: -28px -10px -14px -12px;
}

.gauge__handle.is-dragging,
.is-grabbing,
.is-grabbing * { cursor: grabbing !important; }

.gauge__value {
  position: absolute;
  right: 0;
  bottom: calc(100% + 4px);
  padding: 2px 7px;
  border: 1px solid var(--glass-edge);
  border-radius: 999px;
  background: rgb(2 20 38 / 0.6);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: var(--foam);
  font: 600 11px/1.3 var(--font-mono);
  white-space: nowrap;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.gauge__handle:hover .gauge__value,
.gauge__handle.is-dragging .gauge__value {
  border-color: rgb(126 249 238 / 0.55);
  background: rgb(6 51 90 / 0.9);
}

/* ---------- The diver ---------- */

.diver {
  display: block;
  width: 100%;
  height: auto;
  max-width: none;
  overflow: visible;
  filter: drop-shadow(0 2px 4px rgb(2 20 38 / 0.6));
  transition: transform 0.6s ease;
}

/* Head-down while descending, head-up while ascending (set by js/ocean.js). */
.gauge__handle[data-dir="down"] .diver { transform: rotate(-25deg); }
.gauge__handle[data-dir="up"] .diver { transform: rotate(25deg); }

.diver__skin { fill: #e8fbf9; }
.diver__tank { fill: var(--xdc-red); }
.diver__mask { fill: var(--deep); }
.diver__glint { fill: var(--glow); }
.diver__fin { fill: var(--glow); }

.diver__limb {
  fill: none;
  stroke: #e8fbf9;
  stroke-width: 4.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.diver__bob { animation: diver-bob 3s ease-in-out infinite; }

.diver__kick {
  transform-box: fill-box;
  transform-origin: 0% 50%;
  animation: kick 1.4s ease-in-out infinite;
}

.diver__kick--late { animation-delay: -0.7s; }

.diver__bubble {
  fill: none;
  stroke: rgb(239 252 251 / 0.85);
  stroke-width: 1;
  opacity: 0;
  animation: exhale 3.2s ease-out infinite;
}

.diver__bubble--2 { animation-delay: 0.25s; }
.diver__bubble--3 { animation-delay: 0.5s; }

@keyframes diver-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-1.5px); }
}

@keyframes kick {
  0%, 100% { transform: rotate(-7deg); }
  50% { transform: rotate(7deg); }
}

@keyframes exhale {
  0% { opacity: 0; transform: translate(0, 0); }
  10% { opacity: 0.9; }
  45%, 100% { opacity: 0; transform: translate(-3px, -16px); }
}

@media (min-width: 900px) {
  .gauge { right: 30px; width: 44px; }
  .gauge__track { left: auto; right: 6px; }
  .gauge__handle { --diver-w: 64px; right: 10px; }
  /* Tick labels sit right of the line, so the diver (left of it) never covers them. */
  .gauge__tick b {
    display: block;
    position: absolute;
    top: -5px;
    left: 12px;
    font: 500 10px/1 var(--font-mono);
    color: var(--foam-dim);
  }
}

/* ---------- Reduced motion: creatures rest in view, no bubbles, the diver stays level ---------- */

@media (prefers-reduced-motion: reduce) {
  .bubbles { display: none; }
  .creature__drift { transform: translateX(var(--rest-x)); }
  .diver { transform: none !important; }
}
