/* ════════════════════════════════════════════════════════
   Catch — underwater number-tap arcade
   ════════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100vh;
  min-height: 100vh;
  width: 100vw;
  overflow: hidden;
  font-family: 'Fredoka', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  color: #fff;
}

body {
  position: relative;
  background: transparent;
}

/* ─── Ocean backdrop ───────────────────────────────────── */
.ocean {
  position: fixed;
  inset: 0;
  background: linear-gradient(
    180deg,
    #5cc1e8 0%,
    #2998c8 18%,
    #1875a8 38%,
    #0f5586 60%,
    #08385e 82%,
    #04253d 100%
  );
  overflow: hidden;
  z-index: -2;
}

/* Surface shimmer at top */
.surface {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 12%;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.55) 0%, rgba(255,255,255,0) 100%);
  pointer-events: none;
  animation: surfaceShimmer 8s ease-in-out infinite;
}
@keyframes surfaceShimmer {
  0%, 100% { opacity: 0.7; transform: translateY(0); }
  50%      { opacity: 1.0; transform: translateY(-2px); }
}

/* God rays from the surface */
.sun-rays {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.55;
  mix-blend-mode: screen;
}
.ray {
  position: absolute;
  top: -10%;
  width: 14%;
  height: 130%;
  background: linear-gradient(180deg, rgba(255, 240, 180, 0.45) 0%, rgba(255, 240, 180, 0) 75%);
  transform-origin: top center;
  transform: skewX(-8deg);
  filter: blur(8px);
  animation: raySway 10s ease-in-out infinite;
}
.ray-1 { left: 8%;  animation-delay: 0s;     transform: skewX(-12deg); }
.ray-2 { left: 32%; animation-delay: -2.5s;  width: 10%; transform: skewX(-4deg); }
.ray-3 { left: 56%; animation-delay: -5s;    width: 16%; transform: skewX(2deg); }
.ray-4 { left: 78%; animation-delay: -7.5s;  width: 12%; transform: skewX(10deg); }
@keyframes raySway {
  0%, 100% { opacity: 0.55; transform: skewX(-8deg) translateX(0); }
  50%      { opacity: 0.30; transform: skewX(-4deg) translateX(8px); }
}

/* Background bubbles drifting up */
.bg-bubbles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 10% 90%, rgba(255,255,255,0.18) 0 4px, transparent 5px),
    radial-gradient(circle at 22% 70%, rgba(255,255,255,0.14) 0 3px, transparent 4px),
    radial-gradient(circle at 40% 95%, rgba(255,255,255,0.20) 0 5px, transparent 6px),
    radial-gradient(circle at 60% 80%, rgba(255,255,255,0.14) 0 3px, transparent 4px),
    radial-gradient(circle at 78% 88%, rgba(255,255,255,0.18) 0 4px, transparent 5px),
    radial-gradient(circle at 88% 60%, rgba(255,255,255,0.12) 0 3px, transparent 4px);
  background-size: 100% 200%;
  animation: bgBubblesUp 18s linear infinite;
}
@keyframes bgBubblesUp {
  from { background-position: 0 0; }
  to   { background-position: 0 -200%; }
}

/* Seabed */
.seabed {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 18%;
  pointer-events: none;
}
.sand {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 60%;
  background: linear-gradient(180deg, #c8a96a 0%, #a07f4a 60%, #6e5430 100%);
  border-top: 4px solid #d4b67a;
  box-shadow: inset 0 8px 16px rgba(255, 230, 180, 0.4);
  border-radius: 50% 50% 0 0 / 14px 14px 0 0;
}
.kelp {
  position: absolute;
  bottom: 8%;
  width: 16px;
  background: linear-gradient(180deg, #2a8c4a 0%, #1d5e30 100%);
  border-radius: 50% 50% 0 0;
  transform-origin: bottom center;
  animation: kelpSway 5s ease-in-out infinite;
}
.kelp-1 { left: 6%;  height: 78%; animation-delay: 0s; }
.kelp-2 { left: 18%; height: 60%; animation-delay: -1.5s; width: 12px; }
.kelp-3 { left: 72%; height: 92%; animation-delay: -2.8s; width: 20px; }
.kelp-4 { left: 84%; height: 70%; animation-delay: -4s; }
@keyframes kelpSway {
  0%, 100% { transform: skewX(-6deg) scaleY(1); }
  50%      { transform: skewX(6deg) scaleY(1.04); }
}
.coral {
  position: absolute;
  bottom: 14%;
  font-size: 38px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
  animation: coralBob 4s ease-in-out infinite;
}
.coral-1 { left: 28%; animation-delay: 0s; }
.coral-2 { left: 48%; font-size: 48px; animation-delay: -1.2s; }
.coral-3 { left: 62%; font-size: 32px; animation-delay: -2.4s; }
@keyframes coralBob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50%      { transform: translateY(-3px) rotate(2deg); }
}

/* ─── HUD ──────────────────────────────────────────────── */
.hud {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px env(safe-area-inset-top, 12px);
  z-index: 10;
}

.hud-side {
  flex: 0 0 auto;
  min-width: 110px;
}
.hud-side--right { display: flex; justify-content: flex-end; }

.hud-center {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
}

.lives {
  display: inline-flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.92);
  padding: 8px 14px;
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  font-size: 18px;
}
.heart {
  display: inline-block;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
  transition: opacity 0.4s ease, transform 0.4s ease, filter 0.4s ease;
}
.heart--lost {
  filter: grayscale(100%) brightness(0.45);
  opacity: 0.4;
  animation: heartBreak 0.5s ease-out;
}
@keyframes heartBreak {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.6) rotate(8deg); filter: brightness(1.5) drop-shadow(0 0 8px #ff5560); }
  60%  { transform: scale(0.7) rotate(-12deg); }
  100% { transform: scale(1) rotate(0); }
}

.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.92);
  padding: 8px 16px;
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  font-size: 22px;
  font-weight: 700;
  color: #1a3a52;
  font-variant-numeric: tabular-nums;
  min-width: 84px;
  justify-content: center;
}
.score-icon { font-size: 20px; }
.score-num--bump {
  animation: scoreBump 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes scoreBump {
  0%   { transform: scale(1); color: #1a3a52; }
  40%  { transform: scale(1.6); color: #f5a700; }
  100% { transform: scale(1); color: #1a3a52; }
}

.mode-tabs {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.85);
  border: 3px solid #fff;
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}
.mode-btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  color: #5a7a8a;
  background: transparent;
  border: none;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, transform 0.12s ease;
  white-space: nowrap;
}
.mode-btn:active { transform: scale(0.94); }
.mode-btn--active {
  background: linear-gradient(180deg, #ffb04a, #f59100);
  color: #fff;
  box-shadow: 0 2px 6px rgba(245, 145, 0, 0.55), inset 0 -2px 0 rgba(0,0,0,0.1);
  text-shadow: 0 1px 0 rgba(0,0,0,0.2);
}

/* ─── Problem banner ───────────────────────────────────── */
.problem-banner {
  position: relative;
  margin: 6px auto 8px;
  padding: 12px 28px 10px;
  background: rgba(255, 255, 255, 0.96);
  border: 4px solid #ffd96e;
  border-radius: 24px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35), inset 0 -4px 0 rgba(0,0,0,0.06);
  text-align: center;
  z-index: 5;
  width: fit-content;
  max-width: 90vw;
  animation: bannerPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.problem-banner::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border: 8px solid transparent;
  border-top-color: #ffd96e;
}
@keyframes bannerPop {
  from { transform: scale(0.6) translateY(-10px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}
.problem-label {
  font-size: 13px;
  font-weight: 600;
  color: #5a7a8a;
  letter-spacing: 0.02em;
  margin-bottom: 2px;
}
.problem-math {
  font-size: 36px;
  font-weight: 700;
  color: #1a3a52;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  line-height: 1.1;
}
.problem-math--changing {
  animation: problemFlip 0.32s ease;
}
@keyframes problemFlip {
  0%   { transform: rotateX(0); opacity: 1; }
  50%  { transform: rotateX(90deg); opacity: 0; }
  100% { transform: rotateX(0); opacity: 1; }
}

.streak-pill {
  position: absolute;
  top: -14px;
  right: -14px;
  background: linear-gradient(180deg, #ff7e5f, #d63031);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 3px solid #fff;
  box-shadow: 0 4px 10px rgba(214, 48, 49, 0.5);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  animation: streakPulse 0.8s ease-in-out infinite;
}
.streak-pill[hidden] { display: none; }
@keyframes streakPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.07); }
}
.flame { font-size: 14px; }

/* ─── Scene ────────────────────────────────────────────── */
.scene {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 2;
}
.fish-layer, .particle-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* ─── Fish ─────────────────────────────────────────────── */
.fish {
  position: absolute;
  top: 0;
  left: 0;
  width: 110px;
  height: 70px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  will-change: transform;
  /* Padding around the fish for easier tapping */
  filter: drop-shadow(0 4px 8px rgba(0, 30, 60, 0.4));
}
.fish-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}
.fish-body { transform-origin: 70% 50%; animation: fishSwim 0.6s ease-in-out infinite; }
.fish-tail { transform-origin: 90% 50%; animation: fishTail 0.35s ease-in-out infinite; }
.fish-fin  { transform-origin: 50% 50%; animation: fishFin 0.45s ease-in-out infinite; }
@keyframes fishSwim {
  0%, 100% { transform: rotate(-1.5deg); }
  50%      { transform: rotate(1.5deg); }
}
@keyframes fishTail {
  0%, 100% { transform: rotate(-22deg); }
  50%      { transform: rotate(22deg); }
}
@keyframes fishFin {
  0%, 100% { transform: rotate(-8deg) scaleY(0.95); }
  50%      { transform: rotate(8deg) scaleY(1.05); }
}

.fish-num {
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  fill: #fff;
  stroke: #1a3a52;
  stroke-width: 0.8px;
  paint-order: stroke fill;
  font-size: 26px;
}

/* Facing-left flips the whole SVG so the number stays readable */
.fish[data-facing="-1"] .fish-svg { transform: scaleX(-1); }
.fish[data-facing="-1"] .fish-num { transform: scaleX(-1); transform-origin: center; transform-box: fill-box; }

.fish--correct {
  animation: fishCorrect 0.45s ease-out forwards;
}
@keyframes fishCorrect {
  0%   { transform: scale(1); filter: brightness(1) drop-shadow(0 4px 8px rgba(0,30,60,0.4)); }
  40%  { transform: scale(1.4); filter: brightness(1.6) drop-shadow(0 0 16px gold); }
  100% { transform: scale(0); opacity: 0; }
}
.fish--wrong {
  animation: fishWrong 0.55s ease-out forwards;
}
@keyframes fishWrong {
  0%   { transform: scale(1) rotate(0); }
  20%  { transform: scale(1.05) rotate(-12deg); filter: brightness(0.6) saturate(0); }
  40%  { transform: scale(0.95) rotate(12deg); }
  60%  { transform: scale(1) rotate(-6deg); }
  100% { transform: scale(0.9) rotate(0); opacity: 0; }
}

/* ─── Particles ────────────────────────────────────────── */
.bubble {
  position: absolute;
  width: var(--size, 14px);
  height: var(--size, 14px);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.95) 0%, rgba(255,255,255,0.4) 35%, rgba(255,255,255,0.1) 70%);
  border: 1.5px solid rgba(255,255,255,0.6);
  pointer-events: none;
  animation: bubbleRise var(--dur, 1.1s) ease-out forwards;
}
@keyframes bubbleRise {
  0%   { transform: translate(0, 0) scale(0.4); opacity: 1; }
  20%  { opacity: 1; }
  100% { transform: translate(var(--dx, 0), var(--dy, -200px)) scale(1); opacity: 0; }
}

.splash {
  position: absolute;
  width: 60px;
  height: 60px;
  border: 4px solid rgba(255,255,255,0.6);
  border-radius: 50%;
  pointer-events: none;
  animation: splashRing 0.5s ease-out forwards;
}
@keyframes splashRing {
  0%   { transform: scale(0.2); opacity: 1; border-width: 4px; }
  100% { transform: scale(2.4); opacity: 0; border-width: 1px; }
}

.x-mark {
  position: absolute;
  font-size: 48px;
  pointer-events: none;
  font-weight: 900;
  color: #ff4040;
  text-shadow: 0 2px 0 #fff, 0 4px 12px rgba(0,0,0,0.6);
  animation: xMark 0.7s ease-out forwards;
}
@keyframes xMark {
  0%   { transform: scale(0.2) rotate(-30deg); opacity: 1; }
  30%  { transform: scale(1.3) rotate(0); }
  100% { transform: scale(1) rotate(8deg); opacity: 0; }
}

.spark {
  position: absolute;
  font-size: 22px;
  pointer-events: none;
  animation: sparkRise var(--dur, 1.1s) ease-out forwards;
}
@keyframes sparkRise {
  0%   { transform: translate(0, 0) scale(0.3) rotate(0); opacity: 0; }
  20%  { opacity: 1; }
  100% { transform: translate(var(--dx, 0), var(--dy, -180px)) scale(1.2) rotate(var(--rot, 360deg)); opacity: 0; }
}

/* ─── Floating text (combo / messages) ─────────────────── */
.float-text-layer {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 8;
}
.float-text {
  position: absolute;
  font-weight: 700;
  font-size: 28px;
  text-shadow: 0 2px 0 rgba(0,0,0,0.4), 0 4px 12px rgba(0,0,0,0.6);
  pointer-events: none;
  white-space: nowrap;
  animation: floatRise 1.1s ease-out forwards;
}
.float-text--good { color: #ffe066; }
.float-text--combo { color: #ff7eb3; font-size: 32px; }
.float-text--big { color: #6dffe0; font-size: 40px; }
@keyframes floatRise {
  0%   { transform: translate(-50%, 0) scale(0.6); opacity: 0; }
  15%  { transform: translate(-50%, -20px) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -120px) scale(1); opacity: 0; }
}

/* ─── Overlays (game over / paused) ────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 30, 50, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: overlayFade 0.3s ease;
}
@keyframes overlayFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.overlay[hidden] { display: none; }

.overlay-card {
  background: linear-gradient(180deg, #fff 0%, #fff8e0 100%);
  color: #1a3a52;
  border: 4px solid #ffd96e;
  border-radius: 28px;
  padding: 28px 32px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  max-width: 90vw;
  min-width: 280px;
  animation: cardPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes cardPop {
  from { transform: scale(0.5) translateY(40px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}
.overlay-emoji {
  font-size: 64px;
  line-height: 1;
  margin-bottom: 8px;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
}
.overlay-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 18px;
  color: #1a3a52;
}
.overlay-stats {
  display: flex;
  gap: 24px;
  justify-content: center;
  margin-bottom: 16px;
}
.stat {
  background: #f0f7fa;
  border: 3px solid #c8e1ec;
  border-radius: 16px;
  padding: 10px 18px;
  min-width: 96px;
}
.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: #5a7a8a;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stat-num {
  font-size: 36px;
  font-weight: 700;
  color: #1a3a52;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.overlay-msg {
  font-size: 16px;
  color: #5a7a8a;
  margin-bottom: 18px;
  min-height: 1.5em;
}
.overlay-msg--new-best {
  color: #f59100;
  font-weight: 700;
  font-size: 18px;
  animation: msgPulse 1s ease-in-out infinite;
}
@keyframes msgPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}

.big-btn {
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 22px;
  color: #fff;
  background: linear-gradient(180deg, #4cd964, #2ecc71);
  border: none;
  padding: 14px 36px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(0,0,0,0.18), 0 8px 16px rgba(46, 204, 113, 0.5);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  text-shadow: 0 1px 0 rgba(0,0,0,0.2);
}
.big-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(0,0,0,0.18), 0 4px 8px rgba(46, 204, 113, 0.5);
}

/* ─── Screen shake on lost life ────────────────────────── */
.scene--shake {
  animation: shake 0.4s ease-in-out;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-8px); }
  40%      { transform: translateX(8px); }
  60%      { transform: translateX(-5px); }
  80%      { transform: translateX(5px); }
}

/* ─── Responsive ───────────────────────────────────────── */
@media (max-width: 480px) {
  .hud { padding: 10px 10px env(safe-area-inset-top, 8px); gap: 8px; }
  .hud-side { min-width: 0; }
  .lives { padding: 6px 10px; font-size: 16px; gap: 2px; }
  .score-pill { padding: 6px 12px; font-size: 18px; min-width: 64px; }
  .score-icon { font-size: 16px; }
  .mode-btn { font-size: 12px; padding: 5px 9px; }
  .problem-math { font-size: 30px; }
  .problem-banner { padding: 8px 18px; }
  .problem-label { font-size: 11px; }
  .fish { width: 90px; height: 56px; }
  .fish-num { font-size: 22px; }
  .float-text { font-size: 24px; }
  .float-text--combo { font-size: 26px; }
  .float-text--big { font-size: 32px; }
  .overlay-card { padding: 22px 24px; min-width: 240px; }
  .overlay-emoji { font-size: 52px; }
  .overlay-title { font-size: 22px; }
  .stat-num { font-size: 28px; }
  .stat { padding: 8px 14px; min-width: 80px; }
  .big-btn { font-size: 18px; padding: 12px 28px; }
}

@media (max-width: 360px) {
  .fish { width: 78px; height: 50px; }
  .fish-num { font-size: 20px; }
  .mode-btn { font-size: 11px; padding: 4px 7px; }
}
