:root {
  color-scheme: dark;
  --ocean-deep: #021a33;
  --cyan: #5ef0ff;
  --gold: #ffe45b;
  --gold-deep: #f5c542;
  --ink: #063b63;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #021a33;
  background-image: url('assets/ocean-background.png');
  background-position: center center;
  background-size: cover;
  background-repeat: no-repeat;
  overscroll-behavior: none;
  touch-action: none;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

/* Animated bubbles over full-page ocean background (letterbox sides) */
#bg-bubbles {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.bg-bubble {
  position: absolute;
  bottom: -48px;
  border-radius: 50%;
  background: rgba(220, 245, 255, 0.18);
  border: 1.5px solid rgba(255, 255, 255, 0.55);
  box-shadow: inset -2px -3px 0 rgba(255, 255, 255, 0.35);
  animation-name: bg-bubble-rise;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  will-change: transform, opacity;
}

@keyframes bg-bubble-rise {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
    opacity: 0;
  }
  8% {
    opacity: 1;
  }
  85% {
    opacity: 0.85;
  }
  100% {
    transform: translate3d(18px, calc(-100vh - 80px), 0) scale(1.08);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bg-bubble {
    animation: none;
    opacity: 0.35;
  }
}

/* Portrait stage — 12:16 (3:4), centered with letterbox on wide screens */
#stage {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 480px;
  height: 640px;
  overflow: hidden;
  background: var(--ocean-deep);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 20px 60px rgba(0, 0, 0, 0.55);
  z-index: 1;
}

#game {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: none;
  z-index: 0;
}

#game.show-cursor {
  cursor: default;
}

/* ── Home: one action in 3s → TAP START ─────────────────────────── */
#home-screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding:
    max(10px, var(--safe-top))
    max(12px, var(--safe-right))
    max(16px, var(--safe-bottom))
    max(12px, var(--safe-left));
  overflow: hidden;
  background: transparent;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.4s ease, visibility 0.4s ease;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#home-screen.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.home-hud {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  pointer-events: none;
}

.hud-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(0, 20, 45, 0.45);
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 16px rgba(0, 10, 30, 0.25);
}

.hud-chip__label {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.7);
}

.hud-chip__value {
  font-size: 1.05rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.hud-chip--coins .hud-chip__value {
  color: var(--gold);
}

/* Logo — shrink to fit, never crop */
.home-brand {
  flex: 0 1 auto;
  width: min(90%, 380px);
  text-align: center;
  pointer-events: none;
  line-height: 0;
}

.home-title {
  margin: 0;
  line-height: 0;
}

.home-logo {
  display: block;
  width: 100%;
  height: auto;
  max-height: 110px;
  object-fit: contain;
  object-position: center;
  margin: 0 auto;
  filter: drop-shadow(0 8px 18px rgba(0, 10, 40, 0.4));
}

/* Fish — fills remaining space, scales down fully visible */
.home-hero {
  flex: 1 1 0;
  min-height: 0;
  width: min(70%, 240px);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.home-hero__fish {
  display: block;
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
  filter: drop-shadow(0 12px 24px rgba(0, 10, 40, 0.45));
  animation: hero-swim 3.2s ease-in-out infinite;
  transform-origin: center center;
}

@keyframes hero-swim {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-8px) rotate(2deg); }
}

/* START always fully visible at bottom */
.home-cta {
  flex: 0 0 auto;
  width: min(240px, 78%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 2;
}

/* Circular SHOP FAB — bottom-right, pure CSS glossy gold */
.shop-fab {
  appearance: none;
  border: none;
  cursor: pointer;
  position: absolute;
  right: max(14px, var(--safe-right));
  bottom: max(18px, var(--safe-bottom));
  z-index: 3;
  width: 58px;
  height: 58px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.75) 0%, transparent 42%),
    linear-gradient(180deg, #fff06a 0%, #f5c542 48%, #e0a800 100%);
  box-shadow:
    0 5px 0 #c9a000,
    0 12px 24px rgba(0, 0, 0, 0.35),
    inset 0 2px 0 rgba(255, 255, 255, 0.55),
    inset 0 -4px 10px rgba(180, 120, 0, 0.28);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transform: translate3d(0, 0, 0);
  will-change: transform;
  animation: shop-fab-breathe 2.4s ease-in-out infinite;
  transition: filter 0.12s ease;
}

.shop-fab__icon {
  display: block;
  width: 26px;
  height: 26px;
  filter: drop-shadow(0 1px 1px rgba(90, 60, 0, 0.35));
  pointer-events: none;
}

.shop-fab:hover,
.shop-fab:focus-visible {
  filter: brightness(1.08);
  outline: none;
}

.shop-fab:active {
  transform: translate3d(0, 0, 0) scale(0.9);
  animation: none;
  box-shadow:
    0 2px 0 #c9a000,
    0 6px 14px rgba(0, 0, 0, 0.3),
    inset 0 2px 0 rgba(255, 255, 255, 0.45);
}

@keyframes shop-fab-breathe {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(0, 0, 0) scale(1.08); }
}

#btn-start {
  appearance: none;
  border: none;
  cursor: pointer;
  width: 100%;
  max-width: 260px;
  padding: 0;
  margin: 0;
  background: transparent;
  border-radius: 0;
  line-height: 0;
  box-shadow: none;
  transition: transform 0.18s ease, filter 0.18s ease;
  touch-action: manipulation;
  animation: cta-pulse 2.4s ease-in-out infinite;
  -webkit-tap-highlight-color: transparent;
}

.btn-start__art {
  display: block;
  width: 100%;
  max-height: 64px;
  height: auto;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 8px 14px rgba(0, 10, 40, 0.4));
  user-select: none;
}

#btn-start:hover,
#btn-start:focus-visible {
  transform: scale(1.05);
  filter: brightness(1.08);
  outline: none;
}

#btn-start:active {
  transform: scale(0.96);
  filter: brightness(0.98);
  animation: none;
}

@keyframes cta-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

/* ── Result overlays (GAME OVER / VICTORY) — CSS only, no popup image ─ */
.result-screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, var(--safe-top)) 18px max(20px, var(--safe-bottom));
  background: rgba(2, 18, 40, 0.28);
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.28s ease, visibility 0.28s ease;
  will-change: opacity;
}

.result-screen.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.go-panel {
  width: min(320px, 92%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

.go-title {
  margin: 0;
  font-size: clamp(2.1rem, 11vw, 3rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1.05;
  transform: translate3d(0, -120%, 0);
  opacity: 0;
}

.go-title--lose {
  color: #ff3b4a;
  text-shadow:
    0 0 12px rgba(255, 80, 90, 0.85),
    0 0 28px rgba(255, 40, 60, 0.55),
    0 3px 0 #8b0010,
    0 6px 0 rgba(80, 0, 10, 0.45),
    0 12px 24px rgba(0, 0, 0, 0.45);
  -webkit-text-stroke: 1px rgba(255, 200, 200, 0.35);
}

.go-title--win {
  color: #ffe45b;
  background: linear-gradient(180deg, #fff6a0 0%, #5ef0ff 55%, #38bdf8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter:
    drop-shadow(0 0 10px rgba(94, 240, 255, 0.65))
    drop-shadow(0 3px 0 #0a4a6e)
    drop-shadow(0 8px 18px rgba(0, 0, 0, 0.4));
}

.result-screen.is-active .go-title {
  animation: go-title-bounce 0.85s cubic-bezier(0.22, 1.4, 0.36, 1) forwards;
}

@keyframes go-title-bounce {
  0% {
    transform: translate3d(0, -140%, 0) scale(0.92);
    opacity: 0;
  }
  55% {
    transform: translate3d(0, 8%, 0) scale(1.06);
    opacity: 1;
  }
  72% {
    transform: translate3d(0, -4%, 0) scale(0.98);
  }
  100% {
    transform: translate3d(0, 0, 0) scale(1);
    opacity: 1;
  }
}

.go-score-label {
  margin: 18px 0 0;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: rgba(220, 245, 255, 0.75);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  opacity: 0;
}

.result-screen.is-active .go-score-label {
  animation: go-fade-up 0.4s ease 0.35s forwards;
}

.go-score {
  margin: 0;
  min-height: 1.1em;
  font-size: clamp(2.4rem, 12vw, 3.4rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow:
    0 2px 0 #063b63,
    0 0 20px rgba(94, 240, 255, 0.45),
    0 8px 20px rgba(0, 0, 0, 0.4);
  opacity: 0;
}

.result-screen.is-active .go-score {
  animation: go-fade-up 0.4s ease 0.4s forwards;
}

@keyframes go-fade-up {
  from {
    opacity: 0;
    transform: translate3d(0, 12px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

.go-actions {
  margin-top: 22px;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 10px;
  opacity: 0;
}

.result-screen.is-active .go-actions {
  animation: go-fade-up 0.45s ease 0.55s forwards;
}

/* Result CTAs — same image-button pattern as Home START, equal width side-by-side */
.img-cta {
  appearance: none;
  border: none;
  cursor: pointer;
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  max-width: none;
  padding: 0;
  margin: 0;
  background: transparent;
  border-radius: 0;
  line-height: 0;
  box-shadow: none;
  transition: transform 0.18s ease, filter 0.18s ease;
  touch-action: manipulation;
  animation: cta-pulse 2.4s ease-in-out infinite;
  -webkit-tap-highlight-color: transparent;
}

.img-cta__art {
  display: block;
  width: 100%;
  max-height: 56px;
  height: auto;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 8px 14px rgba(0, 10, 40, 0.4));
  user-select: none;
}

.img-cta:hover,
.img-cta:focus-visible {
  transform: scale(1.05);
  filter: brightness(1.08);
  outline: none;
}

.img-cta:active {
  transform: scale(0.96);
  filter: brightness(0.98);
  animation: none;
}

.img-cta.is-hidden-btn {
  display: none;
}

/* When NEXT is hidden, HOME takes full row */
.go-actions .img-cta:only-child {
  flex: 0 1 160px;
}

@media (prefers-reduced-motion: reduce) {
  .img-cta {
    animation: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  #home-screen,
  #btn-start,
  .shop-fab,
  .home-hero__fish,
  .result-screen.is-active .go-title,
  .result-screen.is-active .go-score-label,
  .result-screen.is-active .go-score,
  .result-screen.is-active .go-actions,
  .img-cta,
  .shop-fab {
    transition: none;
    animation: none;
  }

  .result-screen.is-active .go-title,
  .result-screen.is-active .go-score-label,
  .result-screen.is-active .go-score,
  .result-screen.is-active .go-actions {
    opacity: 1;
    transform: none;
    -webkit-text-fill-color: unset;
    filter: none;
  }

  .go-title--win {
    color: #ffe45b;
    -webkit-text-fill-color: #ffe45b;
  }
}

/* ── FISH SHOP — HTML grid, GPU-friendly, large hitboxes ─────────── */
.shop-screen {
  position: absolute;
  inset: 0;
  z-index: 22;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding:
    max(10px, var(--safe-top))
    max(12px, var(--safe-right))
    max(14px, var(--safe-bottom))
    max(12px, var(--safe-left));
  background: rgba(2, 24, 48, 0.22);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate3d(0, 12px, 0);
  transition:
    opacity 0.28s ease,
    visibility 0.28s ease,
    transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform, opacity;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.shop-screen.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translate3d(0, 0, 0);
}

.shop-screen.is-hidden {
  /* kept for aria parity with other screens */
}

.shop-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 auto;
  margin-bottom: 4px;
}

.shop-close {
  appearance: none;
  border: none;
  background: transparent;
  padding: 8px;
  margin: -8px;
  width: 64px;
  height: 64px;
  cursor: pointer;
  touch-action: manipulation;
  transform: translateZ(0);
  will-change: transform;
  transition: transform 0.12s ease;
}

.shop-close img {
  display: block;
  width: 48px;
  height: 48px;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35));
}

.shop-close:active {
  transform: translate3d(0, 0, 0) scale(0.92);
}

.shop-coins {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(0, 20, 45, 0.5);
  border: 1.5px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(6px);
}

.shop-coins__label {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.7);
}

.shop-coins__value {
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.shop-title {
  margin: 2px 0 12px;
  flex: 0 0 auto;
  font-size: clamp(1.7rem, 8vw, 2.35rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #5ef0ff;
  text-shadow:
    0 2px 0 #0a4a6e,
    0 0 18px rgba(94, 240, 255, 0.4),
    0 8px 20px rgba(0, 0, 0, 0.35);
}

.shop-grid {
  flex: 1 1 auto;
  min-height: 0;
  width: min(100%, 360px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 12px 14px;
  align-content: stretch;
}

.shop-slot {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-height: 0;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(180, 240, 255, 0.45);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 8px 18px rgba(0, 20, 50, 0.25);
  overflow: hidden;
  transform: translateZ(0);
  will-change: transform, opacity;
  transition: opacity 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.shop-slot.is-locked {
  opacity: 0.4;
}

.shop-slot.is-selected {
  border-color: #ffe45b;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 0 0 2px rgba(255, 228, 91, 0.45),
    0 8px 18px rgba(0, 20, 50, 0.25);
}

.shop-slot__art {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 8px;
}

.shop-slot__art img {
  display: block;
  max-width: 88%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  pointer-events: none;
  transform: translate3d(0, 0, 0);
  filter: drop-shadow(0 6px 12px rgba(0, 10, 40, 0.35));
}

.shop-buy {
  appearance: none;
  border: none;
  cursor: pointer;
  flex: 0 0 auto;
  width: 100%;
  min-height: 52px;
  padding: 14px 12px;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-size: clamp(0.95rem, 3.8vw, 1.1rem);
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #3a2e00;
  background: linear-gradient(180deg, #fff06a 0%, #f5c542 55%, #e8a800 100%);
  box-shadow:
    0 3px 0 #c9a000,
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  touch-action: manipulation;
  transform: translate3d(0, 0, 0);
  will-change: transform;
  transition: transform 0.1s ease, filter 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

.shop-buy:disabled {
  cursor: default;
  filter: grayscale(0.35) brightness(0.85);
}

.shop-buy:not(:disabled):active {
  transform: translate3d(0, 0, 0) scale(0.95);
  filter: brightness(0.98);
}

.shop-buy__coin {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3a0, #f5c542 45%, #c9a000);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15);
  flex: 0 0 auto;
}

.shop-buy__price {
  font-variant-numeric: tabular-nums;
}

.shop-toast {
  margin: 10px 0 0;
  min-height: 1.2em;
  flex: 0 0 auto;
  font-size: 0.95rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: #ffe45b;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translate3d(0, 6px, 0);
  transition: opacity 0.2s ease, transform 0.2s ease;
  will-change: opacity, transform;
  pointer-events: none;
}

.shop-toast.is-on {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

@media (prefers-reduced-motion: reduce) {
  .shop-screen,
  .shop-slot,
  .shop-buy,
  .shop-close,
  .shop-toast {
    transition: none;
    animation: none;
  }
}
