/* ==========================================================================
   rubi sewako — immersive listening
   A dark room for long sessions and for falling asleep. Everything moves on a
   scale of tens of seconds; nothing here should catch the eye.
   ========================================================================== */

.immersive {
  position: fixed;
  inset: 0;
  z-index: 200;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(120% 90% at 50% 58%, color-mix(in srgb, var(--sky-3) 20%, transparent) 0%, transparent 62%),
    color-mix(in srgb, var(--bg-deep) 82%, #000);
  color: var(--ink);
  animation: immersive-in .9s var(--ease-out) both;
  cursor: default;
}
.immersive.is-leaving { animation: immersive-out .7s var(--ease) both; }

@keyframes immersive-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes immersive-out { to { opacity: 0; } }

.immersive::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: var(--grain);
  opacity: .16;
  mix-blend-mode: soft-light;
}

/* the whole surface is a dismiss/reveal target */
.immersive__surface {
  position: absolute;
  inset: 0;
  border: none;
  background: none;
  padding: 0;
  cursor: default;
}
.immersive__surface:focus-visible { outline: 2px solid var(--line-soft); outline-offset: -6px; }

/* --------------------------------------------------------------------------
   The opening line
   -------------------------------------------------------------------------- */
.immersive__intro {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12vw;
  padding-right: max(12vw, env(safe-area-inset-right, 0px));
  padding-left: max(12vw, env(safe-area-inset-left, 0px));
  text-align: center;
  pointer-events: none;
  opacity: 0;
}
/* One-shot reveals use filled animations rather than transitions, so the end
   state is guaranteed even if the animation never gets a chance to run. */
.immersive__intro.is-in  { animation: imm-fade-in 1.6s var(--ease) forwards; }
.immersive__intro.is-out { animation: imm-fade-out 1.6s var(--ease) forwards; }

.immersive__intro p {
  font-family: var(--font-serif);
  font-size: clamp(21px, 5.2vw, 30px);
  font-weight: 300;
  line-height: 1.5;
  letter-spacing: .2px;
  color: var(--ink);
  max-width: 22ch;
  text-wrap: balance;
  text-shadow: 0 2px 26px color-mix(in srgb, var(--glow) 30%, transparent);
}

/* --------------------------------------------------------------------------
   The jellyfish
   -------------------------------------------------------------------------- */
.immersive__stage {
  position: relative;
  z-index: 2;
  width: min(70vw, 46vh);
  max-width: 420px;
  opacity: 0;
}
.immersive__stage.is-in { animation: imm-fade-in 3.4s var(--ease) forwards; }
.immersive__stage svg {
  width: 100%;
  height: auto;
  overflow: visible;
  transition: opacity .8s var(--ease);
}
.immersive__stage.is-dim svg { opacity: .45; }

@keyframes imm-fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes imm-fade-out { from { opacity: 1; } to { opacity: 0; } }

/* the whole animal wanders, very slowly */
.jelly-drift  { animation: jelly-drift 54s ease-in-out infinite alternate; }
.jelly-bob    { animation: jelly-bob 23s ease-in-out infinite; }

@keyframes jelly-drift {
  0%   { transform: translate3d(-3.5%, 1.5%, 0) rotate(-1.4deg); }
  100% { transform: translate3d(3.5%, -1.5%, 0) rotate(1.4deg); }
}
@keyframes jelly-bob {
  0%, 100% { transform: translate3d(0, 2.2%, 0); }
  50%      { transform: translate3d(0, -2.2%, 0); }
}

/* the bell breathes */
.jelly-bell {
  transform-box: fill-box;
  transform-origin: 50% 22%;
  animation: jelly-pulse 11s ease-in-out infinite;
  filter: drop-shadow(0 0 14px color-mix(in srgb, var(--glow) 45%, transparent));
}
@keyframes jelly-pulse {
  0%, 100% { transform: scale(1, 1); }
  45%      { transform: scale(1.045, .93); }
  70%      { transform: scale(.985, 1.025); }
}

.jelly-halo { animation: jelly-halo 13s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes jelly-halo {
  0%, 100% { opacity: .5;  transform: scale(1); }
  50%      { opacity: .72; transform: scale(1.06); }
}

/* arms and tentacles sway out of phase with one another */
.jelly-strand {
  transform-box: fill-box;
  transform-origin: 50% 0%;
  filter: drop-shadow(0 0 7px color-mix(in srgb, var(--glow) 34%, transparent));
}
.jelly-strand--a { animation: jelly-sway-a 17s ease-in-out infinite; }
.jelly-strand--b { animation: jelly-sway-b 21s ease-in-out infinite; }
.jelly-strand--c { animation: jelly-sway-a 25s ease-in-out infinite reverse; }
.jelly-strand--d { animation: jelly-sway-b 19s ease-in-out infinite reverse; }

@keyframes jelly-sway-a {
  0%, 100% { transform: rotate(-1.8deg) translateX(-1px); }
  50%      { transform: rotate(1.8deg) translateX(1px); }
}
@keyframes jelly-sway-b {
  0%, 100% { transform: rotate(1.4deg) skewX(1.2deg); }
  50%      { transform: rotate(-1.4deg) skewX(-1.2deg); }
}

/* drifting motes, like plankton */
.immersive__motes { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.mote {
  position: absolute;
  border-radius: 50%;
  background: var(--glow);
  opacity: 0;
  animation: mote-drift linear infinite;
}
@keyframes mote-drift {
  0%   { opacity: 0;   transform: translate3d(0, 12vh, 0); }
  22%  { opacity: .34; }
  78%  { opacity: .26; }
  100% { opacity: 0;   transform: translate3d(2vw, -18vh, 0); }
}

/* --------------------------------------------------------------------------
   Controls — hidden until you ask for them
   -------------------------------------------------------------------------- */
.immersive__controls,
.immersive__exit {
  transition: opacity .7s var(--ease), transform .7s var(--ease);
}
.immersive.is-quiet .immersive__controls,
.immersive.is-quiet .immersive__exit {
  opacity: 0;
  pointer-events: none;
}
.immersive.is-quiet .immersive__controls { transform: translate(-50%, 14px); }

.immersive__exit {
  position: absolute;
  top: 20px;
  top: calc(20px + env(safe-area-inset-top, 0px));
  right: max(20px, env(safe-area-inset-right, 0px));
  z-index: 6;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line-soft);
  color: var(--ink-3);
  background: color-mix(in srgb, var(--bg-deep) 55%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.immersive__exit:hover { color: var(--ink); border-color: var(--line); }

.immersive__controls {
  position: absolute;
  left: 50%;
  bottom: 30px;
  bottom: calc(30px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(420px, calc(100vw - 40px));
  width: min(420px, calc(100vw - 40px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
}

.immersive__row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.immersive__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 46px;
  padding: 0 20px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line-soft);
  color: var(--ink-2);
  font-size: 13px;
  background: color-mix(in srgb, var(--bg-deep) 55%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: color .25s var(--ease), border-color .25s var(--ease), transform .2s var(--ease);
}
.immersive__btn:hover { color: var(--ink); border-color: var(--line); }
.immersive__btn:active { transform: scale(.96); }
.immersive__btn--round { width: 56px; height: 56px; padding: 0; border-radius: 50%; }
.immersive__btn.is-on { color: var(--warm); border-color: color-mix(in srgb, var(--warm) 42%, transparent); }

.immersive__mix {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.immersive__chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line-soft);
  color: var(--ink-5);
  font-size: 11.5px;
  background: color-mix(in srgb, var(--bg-deep) 45%, transparent);
  transition: all .25s var(--ease);
}
.immersive__chip svg { width: 13px; height: 13px; }
.immersive__chip.is-on {
  color: var(--ink-2);
  border-color: var(--line);
  background: color-mix(in srgb, var(--glow) 8%, transparent);
}

.immersive__hint {
  font-size: 11px;
  color: var(--ink-5);
  text-align: center;
  letter-spacing: .3px;
}

/* a very quiet clock, for when you have lost track on purpose */
.immersive__clock {
  position: absolute;
  top: 24px;
  top: calc(24px + env(safe-area-inset-top, 0px));
  left: max(24px, env(safe-area-inset-left, 0px));
  z-index: 5;
  font-family: var(--font-serif);
  font-size: 15px;
  letter-spacing: 1px;
  color: var(--ink-5);
  opacity: .55;
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Entry point on the sounds screen
   -------------------------------------------------------------------------- */
.listen-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  width: 100%;
  height: 58px;
  border-radius: var(--r-pill);
  border: none;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: var(--accent-ink);
  font-family: var(--font-script);
  font-size: 23px;
  box-shadow: 0 8px 26px color-mix(in srgb, var(--accent) 42%, transparent);
  transition: transform .2s var(--ease), filter .2s var(--ease);
}
.listen-btn:hover { transform: translateY(-1px); filter: brightness(1.08); }
.listen-btn:active { transform: scale(.98); }
.listen-btn svg { width: 20px; height: 20px; }

/* --------------------------------------------------------------------------
   Nothing should drift for someone who asked it not to
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .jelly-drift, .jelly-bob, .jelly-bell, .jelly-halo, .jelly-strand, .mote {
    animation: none !important;
  }
  .mote { opacity: .22; }
}
