:root {
  color-scheme: dark;
  --cs: 60px;
  --ink: #1b2440;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #031427;
  font-family: 'Fredoka', 'Comic Sans MS', 'Chalkboard SE', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#sea {
  position: fixed;
  inset: 0;
  display: block;
  cursor: pointer;
}

#critters {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.critter {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform;
}

.critter .anim {
  position: absolute;
  left: 0;
  top: 0;
}

.critter .body {
  position: absolute;
  left: 0;
  top: 0;
  translate: -50% -50%;
  font-size: var(--cs);
  line-height: 1;
  white-space: nowrap;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
}

.critter .flip {
  display: inline-block;
}

.critter .flip svg {
  display: block;
  width: 1.7em;
  height: auto;
}

.critter.far .body {
  filter: brightness(0.55) saturate(0.6) blur(1px);
}

/* ---------- speech bubbles ---------- */
.bubble {
  position: absolute;
  left: 0;
  bottom: calc(var(--cs) * 0.62);
  translate: calc(-50% + var(--shift, 0px)) 0;
  width: max-content;
  max-width: min(240px, 62vw);
  padding: 8px 13px;
  border-radius: 18px;
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  font-size: clamp(14px, 3.7vmin, 19px);
  line-height: 1.2;
  text-align: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: scale(0.4);
  transform-origin: 50% 100%;
  transition: opacity 0.2s, transform 0.35s cubic-bezier(0.3, 1.6, 0.5, 1);
  pointer-events: none;
}

.bubble::after {
  content: '';
  position: absolute;
  left: calc(50% - var(--shift, 0px));
  bottom: -9px;
  translate: -50% 0;
  border: 10px solid transparent;
  border-top-color: inherit;
  border-top-color: #fff;
  border-bottom: 0;
}

.bubble.show {
  opacity: 1;
  transform: scale(1);
}

.bubble.jelly {
  position: fixed;
  left: 0;
  top: 0;
  bottom: auto;
  translate: calc(-50% + var(--shift, 0px)) calc(-100% - 12px);
  background: #ffe1f5;
  color: #5a1748;
  z-index: 5;
}

.bubble.jelly::after {
  border-top-color: #ffe1f5;
  left: calc(50% - var(--shift, 0px));
}

/* ---------- creature moves ---------- */
.fx-bob { animation: bob 2.2s ease-in-out infinite; }
@keyframes bob {
  50% { transform: translateY(-10px) rotate(-5deg); }
}

.fx-swim { animation: swimwig 0.45s ease-in-out infinite alternate; }
@keyframes swimwig {
  from { transform: rotate(-6deg) translateY(-3px); }
  to { transform: rotate(6deg) translateY(3px); }
}

.fx-puff { animation: puff 3.4s ease-in-out 0.9s both; }
@keyframes puff {
  0% { transform: scale(1); }
  12% { transform: scale(2.1) rotate(10deg); }
  18% { transform: scale(1.8) rotate(-8deg); }
  24% { transform: scale(2.05) rotate(6deg); }
  80% { transform: scale(2) rotate(0); }
  100% { transform: scale(1); }
}

.fx-wave { animation: wave 0.28s ease-in-out infinite alternate; }
@keyframes wave {
  from { transform: rotate(-14deg) scale(1, 0.95); }
  to { transform: rotate(14deg) scale(0.95, 1.05); }
}

.fx-shuffle { animation: shuffle 0.36s steps(2, jump-none) infinite; }
@keyframes shuffle {
  from { transform: translateX(-7px) rotate(-6deg); }
  to { transform: translateX(7px) rotate(6deg); }
}

.fx-tumble { animation: tumble 2.6s ease-in-out infinite; }
@keyframes tumble {
  0%, 100% { transform: rotate(-22deg); }
  50% { transform: rotate(22deg) translateX(8px); }
}

.fx-buzz { animation: buzz 1.2s linear infinite; }
@keyframes buzz {
  0%, 40%, 100% { transform: translate(0, 0) rotate(0); }
  44% { transform: translate(-3px, 1px) rotate(-6deg); }
  48% { transform: translate(3px, -1px) rotate(6deg); }
  52% { transform: translate(-3px, 0) rotate(-6deg); }
  56% { transform: translate(3px, 1px) rotate(6deg); }
  60% { transform: translate(0, 0) rotate(0); }
}

.fx-hover { animation: hover 1.6s ease-in-out infinite; }
@keyframes hover {
  0%, 100% { transform: translateY(0) rotate(-8deg); }
  50% { transform: translateY(-14px) rotate(8deg); }
}

.fx-hover::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 70%;
  width: 1.3em;
  height: 1.6em;
  translate: -50% 0;
  background: linear-gradient(rgba(170, 255, 170, 0.55), rgba(170, 255, 170, 0));
  clip-path: polygon(35% 0, 65% 0, 100% 100%, 0 100%);
  animation: beam 0.5s ease-in-out infinite alternate;
  z-index: -1;
}
@keyframes beam {
  to { opacity: 0.4; }
}

.fx-belly { animation: belly 0.7s ease-in-out infinite; }
@keyframes belly {
  0%, 100% { transform: scale(1, 1); }
  50% { transform: scale(1.06, 0.94) translateY(2px); }
}

.conga {
  display: inline-block;
  animation: conga 0.5s ease-in-out infinite alternate;
}
@keyframes conga {
  from { transform: translateY(-8px) rotate(-10deg); }
  to { transform: translateY(8px) rotate(10deg); }
}

.lure-glow { animation: lure 1.1s ease-in-out infinite alternate; transform-origin: 22px 14px; }
@keyframes lure {
  from { opacity: 0.45; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1.25); }
}

.ink {
  position: absolute;
  left: 0;
  top: 0;
  width: 160px;
  height: 160px;
  margin: -80px 0 0 -80px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(8, 4, 20, 0.95) 0 35%, rgba(8, 4, 20, 0.6) 55%, rgba(8, 4, 20, 0) 72%);
  animation: ink 2.4s ease-out forwards;
}
@keyframes ink {
  from { transform: scale(0.2); opacity: 1; }
  40% { opacity: 1; }
  to { transform: scale(2.4); opacity: 0; }
}

/* ---------- HUD ---------- */
#hint {
  position: fixed;
  left: 50%;
  top: max(16px, env(safe-area-inset-top));
  translate: -50% 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(220, 240, 255, 0.85);
  font-size: 14px;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 1.2s;
}

#hint.gone { opacity: 0; }

#flipdir {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  padding: 9px 15px;
  border-radius: 999px;
  background: rgba(255, 143, 220, 0.16);
  border: 1.5px solid rgba(255, 170, 230, 0.45);
  color: #ffd6f2;
  font-weight: 600;
  font-size: 15px;
  text-decoration: none;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.2s, transform 0.2s;
}

#flipdir:hover,
#flipdir:focus-visible {
  background: rgba(255, 143, 220, 0.3);
  transform: scale(1.05);
  outline: none;
}
