:root {
  --bg: #FFF8E7;
  --ink: #2B2A4C;
  --ink-soft: #4A4870;
  --primary: #FF7A59;
  --primary-dark: #E85F3D;
  --secondary: #FFFFFF;
  --secondary-border: #E8DDB8;
  --shadow: 0 8px 0 rgba(43, 42, 76, 0.12), 0 12px 28px rgba(43, 42, 76, 0.10);
  --shadow-pressed: 0 2px 0 rgba(43, 42, 76, 0.12), 0 4px 12px rgba(43, 42, 76, 0.08);
  --card-shadow: 0 6px 0 rgba(43, 42, 76, 0.10), 0 10px 24px rgba(43, 42, 76, 0.08);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Fredoka", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-weight: 500;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  position: relative;
}

#app {
  display: block;
  min-height: 100dvh;
  width: 100%;
}

/* ───── Screen routing ───── */
.screen {
  display: none;
  width: 100%;
  min-height: 100dvh;
  position: relative;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* The home screen needs centered content + space for floating emojis */
#screen-home.active {
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 24px;
}

/* ───── Floating background emojis (home only) ───── */
/* Gentler than the encounter idle bob — these are decorative ambience,
   not the focal target. Smaller distance + slower duration. */
.bg-emoji {
  position: absolute;
  font-size: clamp(48px, 9vw, 96px);
  opacity: 0.85;
  user-select: none;
  pointer-events: none;
  animation: drift 7.4s ease-in-out infinite alternate;
  will-change: transform;
  filter: drop-shadow(0 6px 10px rgba(43, 42, 76, 0.10));
}

.bg-emoji.e1 { top: 8%;     left: 7%;   animation-duration: 6.8s; animation-delay: -0.2s; }
.bg-emoji.e2 { top: 14%;    right: 9%;  animation-duration: 8.2s; animation-delay: -1.4s; }
.bg-emoji.e3 { bottom: 12%; left: 10%;  animation-duration: 7.6s; animation-delay: -2.1s; }
.bg-emoji.e4 { bottom: 9%;  right: 8%;  animation-duration: 7.0s; animation-delay: -0.9s; }
.bg-emoji.e5 { top: 46%;    left: 3%;   animation-duration: 8.4s; animation-delay: -3.0s; font-size: clamp(40px, 7vw, 80px); }
.bg-emoji.e6 { top: 52%;    right: 4%;  animation-duration: 7.8s; animation-delay: -1.7s; font-size: clamp(40px, 7vw, 80px); }

@keyframes drift {
  0%   { transform: translateY(0)    rotate(-1.5deg); }
  100% { transform: translateY(-9px) rotate(1.5deg);  }
}

/* ───── Home stack ───── */
.home {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  max-width: 640px;
  width: 100%;
  text-align: center;
}

.title {
  font-weight: 700;
  font-size: clamp(36px, 7vw, 64px);
  letter-spacing: -0.5px;
  margin: 0 0 4px;
  color: var(--ink);
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.6);
}

.subtitle {
  margin: 0;
  font-size: clamp(16px, 2.4vw, 20px);
  color: var(--ink-soft);
  font-weight: 500;
}

/* ───── Buttons ───── */
.btn {
  font-family: inherit;
  font-weight: 600;
  border: none;
  cursor: pointer;
  border-radius: 28px;
  transition: transform 80ms ease-out, box-shadow 80ms ease-out;
  touch-action: manipulation;
  user-select: none;
}

.btn:active {
  transform: translateY(4px);
  box-shadow: var(--shadow-pressed);
}

.btn-primary {
  min-width: 240px;
  min-height: 96px;
  padding: 0 36px;
  font-size: clamp(24px, 3.4vw, 32px);
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow);
  letter-spacing: 0.2px;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  min-width: 200px;
  min-height: 64px;
  padding: 0 28px;
  font-size: clamp(18px, 2.4vw, 22px);
  background: var(--secondary);
  color: var(--ink);
  border: 3px solid var(--secondary-border);
  box-shadow: var(--shadow);
}

.btn-secondary:hover {
  background: #FFFDF6;
}

.stat {
  margin-top: 4px;
  font-size: clamp(14px, 2vw, 18px);
  color: var(--ink-soft);
  font-weight: 500;
}

.stat-count {
  font-weight: 700;
  color: var(--primary-dark);
}

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

/* ───── Top bar (map + encounter) ───── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(43, 42, 76, 0.08);
  flex-wrap: wrap;
}

.topbar-title {
  margin: 0;
  font-size: clamp(20px, 3vw, 28px);
  font-weight: 700;
  color: var(--ink);
  user-select: none;
  cursor: default;
  /* Long-press parent gate target — wired up in step 15. */
}

.topbar-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 22px;
  background: white;
  border: 2px solid var(--secondary-border);
  font-family: inherit;
  font-weight: 600;
  font-size: 16px;
  color: var(--ink);
  box-shadow: 0 3px 0 rgba(43, 42, 76, 0.08);
  cursor: pointer;
  transition: transform 80ms ease-out, box-shadow 80ms ease-out;
  touch-action: manipulation;
  user-select: none;
}

.stat-pill:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(43, 42, 76, 0.08);
}

.stat-pill-static {
  cursor: default;
}

.stat-pill-static:active {
  transform: none;
  box-shadow: 0 3px 0 rgba(43, 42, 76, 0.08);
}

.stat-pill-icon {
  font-size: 20px;
  line-height: 1;
}

.stat-pill-toggle.muted .stat-pill-icon {
  filter: grayscale(0.6);
  opacity: 0.6;
}

/* ───── World map grid ───── */
.map-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 18px;
  padding: 24px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  align-content: start;
}

.habitat-card {
  position: relative;
  aspect-ratio: 1 / 1;
  min-height: 180px;
  border-radius: 24px;
  border: 3px solid rgba(43, 42, 76, 0.06);
  background: white;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px;
  cursor: pointer;
  transition: transform 100ms ease-out, box-shadow 100ms ease-out;
  font-family: inherit;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
  user-select: none;
  touch-action: manipulation;
  overflow: hidden;
}

.habitat-card:hover {
  transform: translateY(-2px);
}

.habitat-card:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(43, 42, 76, 0.10), 0 4px 12px rgba(43, 42, 76, 0.06);
}

.habitat-card-emoji {
  font-size: clamp(56px, 9vw, 84px);
  line-height: 1;
  filter: drop-shadow(0 4px 6px rgba(43, 42, 76, 0.12));
}

.habitat-card-label {
  font-size: clamp(16px, 2vw, 20px);
  font-weight: 700;
  color: inherit;
}

.habitat-card-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  max-width: 140px;
}

.habitat-card-progress-text {
  font-size: 14px;
  font-weight: 600;
  opacity: 0.8;
}

.habitat-card-progress-bar {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: rgba(43, 42, 76, 0.10);
  overflow: hidden;
}

.habitat-card-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 240ms ease-out;
}

.habitat-card.dark-text {
  color: #FFFFFF;
}

.habitat-card.dark-text .habitat-card-progress-text {
  color: rgba(255, 255, 255, 0.85);
}

.habitat-card.dark-text .habitat-card-progress-bar {
  background: rgba(255, 255, 255, 0.18);
}

/* Locked habitat */
.habitat-card.locked {
  cursor: default;
}

.habitat-card.locked .habitat-card-emoji {
  filter: grayscale(0.85) opacity(0.55);
}

.habitat-card.locked .habitat-card-label,
.habitat-card.locked .habitat-card-progress-text {
  opacity: 0.55;
}

.habitat-card-lock {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 22px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(43, 42, 76, 0.15);
}

.habitat-card.locked.shake {
  animation: cardShake 320ms ease-in-out;
}

@keyframes cardShake {
  0%   { transform: translateX(0); }
  20%  { transform: translateX(-6px); }
  40%  { transform: translateX(6px); }
  60%  { transform: translateX(-4px); }
  80%  { transform: translateX(4px); }
  100% { transform: translateX(0); }
}

/* ───── Encounter screen placeholder ───── */
.topbar-encounter {
  background: rgba(255, 255, 255, 0.7);
}

.back-btn {
  font-family: inherit;
  font-weight: 600;
  font-size: 18px;
  background: white;
  color: var(--ink);
  border: 2px solid var(--secondary-border);
  border-radius: 22px;
  min-height: 44px;
  padding: 0 18px;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(43, 42, 76, 0.08);
  transition: transform 80ms ease-out, box-shadow 80ms ease-out;
  touch-action: manipulation;
  user-select: none;
}

.back-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(43, 42, 76, 0.08);
}

.encounter-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 24px;
  gap: 24px;
  position: relative;
}

.encounter-target {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 220px;
}

.encounter-emoji-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
}

.encounter-emoji {
  font-size: clamp(120px, 22vw, 220px);
  line-height: 1;
  user-select: none;
  filter: drop-shadow(0 10px 18px rgba(43, 42, 76, 0.18));
  /* Continuous gentle idle bob — overridden by entrance/taunt/hopping/celebrate */
  animation: idleBob 1.2s ease-in-out infinite alternate;
}

@keyframes idleBob {
  from { transform: translateY(0); }
  to   { transform: translateY(-10px); }
}

/* Hint button — sits to the side of the emoji, dimmed until step 7 wires it up. */
.hint-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 3px solid var(--secondary-border);
  background: white;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  box-shadow: var(--card-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.55;
  transition: transform 80ms ease-out, box-shadow 80ms ease-out, opacity 200ms ease-out;
  touch-action: manipulation;
  user-select: none;
}

.hint-btn:active {
  transform: translateY(-46%);
  box-shadow: 0 2px 0 rgba(43, 42, 76, 0.10), 0 4px 12px rgba(43, 42, 76, 0.06);
}

.hint-btn-icon {
  font-size: 36px;
  line-height: 1;
}

/* Slots — empty squares where letters drop in. */
.slots-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.slot {
  width: clamp(56px, 11vw, 76px);
  height: clamp(56px, 11vw, 76px);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.7);
  border: 3px dashed rgba(43, 42, 76, 0.20);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 700;
  color: var(--ink);
  user-select: none;
  text-transform: lowercase;
}

.slot.filled {
  background: white;
  border-style: solid;
  border-color: rgba(43, 42, 76, 0.20);
  box-shadow: 0 3px 0 rgba(43, 42, 76, 0.08);
  cursor: pointer; /* tap to send letter back — wired up in step 6 */
}

/* Tiles — scrambled letter buttons. */
.tiles-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  min-height: 80px;
}

.tile {
  width: clamp(56px, 11vw, 76px);
  height: clamp(56px, 11vw, 76px);
  min-width: 56px;
  min-height: 56px;
  border-radius: 16px;
  background: white;
  border: 3px solid var(--secondary-border);
  font-family: inherit;
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: lowercase;
  transition: transform 80ms ease-out, box-shadow 80ms ease-out, opacity 200ms ease-out;
  touch-action: manipulation;
  user-select: none;
}

.tile:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(43, 42, 76, 0.10), 0 4px 12px rgba(43, 42, 76, 0.06);
}

.tile.used {
  visibility: hidden;
}

.tile.shake {
  animation: tileShake 340ms ease-in-out;
}

@keyframes tileShake {
  0%   { transform: translateX(0); }
  20%  { transform: translateX(-6px); }
  40%  { transform: translateX(6px); }
  60%  { transform: translateX(-4px); }
  80%  { transform: translateX(4px); }
  100% { transform: translateX(0); }
}

.slot.just-filled {
  animation: slotPop 240ms ease-out;
}

@keyframes slotPop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.encounter-emoji.celebrate {
  animation: emojiCelebrate 900ms ease-out;
}

@keyframes emojiCelebrate {
  0%   { transform: scale(1)   rotate(0deg); }
  35%  { transform: scale(1.4) rotate(360deg); }
  100% { transform: scale(1.1) rotate(360deg); }
}

/* Entrance — scale in from 0 with a slight overshoot */
.encounter-emoji.entrance {
  animation: emojiEntrance 600ms cubic-bezier(0.34, 1.4, 0.5, 1) forwards;
}

@keyframes emojiEntrance {
  0%   { transform: scale(0)    translateX(40px) rotate(-14deg); opacity: 0; }
  60%  { transform: scale(1.18) translateX(0)    rotate(6deg);   opacity: 1; }
  100% { transform: scale(1)    translateX(0)    rotate(0);      opacity: 1; }
}

/* One-shot taunts — picked randomly per encounter */
.encounter-emoji.taunt-wiggle { animation: tauntWiggle 400ms ease-in-out; }
.encounter-emoji.taunt-shake  { animation: tauntShake  400ms ease-in-out; }
.encounter-emoji.taunt-spin   { animation: tauntSpin   460ms ease-in-out; }

@keyframes tauntWiggle {
  0%, 100% { transform: rotate(0); }
  25%      { transform: rotate(-14deg); }
  50%      { transform: rotate(14deg); }
  75%      { transform: rotate(-7deg); }
}

@keyframes tauntShake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-9px); }
  40%      { transform: translateX(9px); }
  60%      { transform: translateX(-6px); }
  80%      { transform: translateX(6px); }
}

@keyframes tauntSpin {
  0%   { transform: rotate(0)    scale(1); }
  50%  { transform: rotate(180deg) scale(0.95); }
  100% { transform: rotate(360deg) scale(1); }
}

/* Idle hop — added periodically by the JS scheduler */
.encounter-emoji.hopping {
  animation: emojiHop 540ms ease-out;
}

@keyframes emojiHop {
  0%   { transform: translateY(0)     scaleY(1); }
  35%  { transform: translateY(-26px) scaleY(1.05); }
  72%  { transform: translateY(0)     scaleY(0.92); }
  86%  { transform: translateY(-4px)  scaleY(1.02); }
  100% { transform: translateY(0)     scaleY(1); }
}

@media (prefers-reduced-motion: reduce) {
  /* Only disable the rotation-heavy animations that can cause vestibular issues.
     Keep the gentle bob, hop, and entrance — they're what makes the emoji feel alive. */
  .encounter-emoji.taunt-spin,
  .encounter-emoji.celebrate {
    animation: none;
  }
}

/* Encounter screen text contrast on the dark Space backdrop. */
#screen-encounter.dark-text .topbar-title { color: var(--ink); }
#screen-encounter.dark-text .slot { color: white; background: rgba(255, 255, 255, 0.10); border-color: rgba(255, 255, 255, 0.30); }
#screen-encounter.dark-text .slot.filled { background: rgba(255, 255, 255, 0.95); color: var(--ink); }

/* ───── Hint button used state ───── */
.hint-btn.used {
  opacity: 1;
  border-color: var(--primary);
}

/* ───── Star-pill bump (after a catch) ───── */
.stat-pill-bump {
  animation: pillBump 380ms ease-out;
}

@keyframes pillBump {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* ───── Sparkle particles (capture celebration) ───── */
.sparkle {
  position: fixed;
  font-size: 32px;
  pointer-events: none;
  user-select: none;
  z-index: 200;
  left: 0;
  top: 0;
  animation: sparkleFly 720ms ease-out forwards;
}

@keyframes sparkleFly {
  0%   { transform: translate(-50%, -50%) scale(0.4); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, 0px))) scale(1.5); opacity: 0; }
}

/* ───── Collection book ───── */
#screen-collection.active {
  background: var(--bg);
}

.collection-content {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
  overflow-y: auto;
}

.collection-progress {
  background: white;
  border-radius: 18px;
  padding: 16px 20px;
  box-shadow: var(--card-shadow);
  margin-bottom: 24px;
}

.collection-progress-text {
  margin: 0 0 10px;
  font-size: clamp(16px, 2.4vw, 20px);
  color: var(--ink);
  font-weight: 500;
  text-align: center;
}

.collection-progress-text strong {
  color: var(--primary-dark);
  font-weight: 700;
}

.collection-progress-bar {
  height: 12px;
  border-radius: 6px;
  background: rgba(43, 42, 76, 0.08);
  overflow: hidden;
}

.collection-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  border-radius: 6px;
  transition: width 280ms ease-out;
  width: 0%;
}

.collection-habitat {
  margin-bottom: 28px;
}

.collection-habitat-header {
  margin: 0 0 12px;
  font-size: clamp(18px, 2.6vw, 22px);
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
}

.collection-habitat-header-emoji {
  font-size: 1.4em;
  line-height: 1;
}

.collection-habitat-header-count {
  margin-left: auto;
  font-size: 0.8em;
  font-weight: 600;
  color: var(--ink-soft);
}

.collection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 12px;
}

.collection-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 8px 10px;
  background: white;
  border-radius: 16px;
  border: 2px solid rgba(43, 42, 76, 0.06);
  min-height: 120px;
  cursor: default;
  user-select: none;
  transition: transform 100ms ease-out;
  font-family: inherit;
}

.collection-card.caught {
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(43, 42, 76, 0.08);
}

.collection-card.caught:active {
  transform: translateY(2px);
}

.collection-card-emoji {
  font-size: 44px;
  line-height: 1;
  filter: drop-shadow(0 3px 4px rgba(43, 42, 76, 0.12));
}

.collection-card.uncaught {
  background: rgba(43, 42, 76, 0.04);
}

.collection-card.uncaught .collection-card-emoji {
  filter: grayscale(1) opacity(0.32);
}

.collection-card-word {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  text-transform: lowercase;
}

.collection-card.uncaught .collection-card-word {
  color: rgba(43, 42, 76, 0.4);
}

.collection-card-count {
  position: absolute;
  top: 6px;
  right: 8px;
  background: var(--primary);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 24px;
  text-align: center;
  line-height: 1.4;
  box-shadow: 0 1px 3px rgba(43, 42, 76, 0.2);
}

/* Rarity styling — basic version, full polish in step 12 */
.collection-card.caught.rare {
  box-shadow:
    0 0 0 2px rgba(212, 112, 158, 0.45),
    0 4px 14px rgba(212, 112, 158, 0.18);
}

.collection-card.caught.legendary {
  border: 3px solid transparent;
  background:
    linear-gradient(white, white) padding-box,
    conic-gradient(from 0deg, #FF6B6B, #FFD93D, #6BCB77, #4D96FF, #B16BFF, #FF6B6B) border-box;
}

.collection-card-pop {
  animation: cardPop 280ms ease-out;
}

@keyframes cardPop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* ───── Habitat-complete celebration ───── */
#screen-complete.active {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.complete-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  max-width: 520px;
  width: 100%;
  text-align: center;
}

.complete-banner {
  font-size: clamp(22px, 4vw, 34px);
  font-weight: 700;
  margin: 0;
  color: var(--ink);
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.5);
}

.complete-sub {
  margin: 0;
  font-size: clamp(16px, 2.4vw, 20px);
  color: var(--ink-soft);
}

#screen-complete.dark-text .complete-banner,
#screen-complete.dark-text .complete-sub {
  color: white;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.complete-circle-wrap {
  position: relative;
  width: clamp(280px, 60vw, 360px);
  aspect-ratio: 1 / 1;
  margin: 12px auto;
}

.complete-circle {
  position: absolute;
  inset: 0;
  animation: circleSpin 6.5s linear infinite;
}

@keyframes circleSpin {
  from { transform: rotate(0); }
  to   { transform: rotate(360deg); }
}

.complete-emoji {
  position: absolute;
  width: 56px;
  height: 56px;
  font-size: clamp(40px, 6vw, 56px);
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 4px 6px rgba(43, 42, 76, 0.18));
  animation: emojiBobble 0.7s ease-in-out infinite alternate;
  user-select: none;
  line-height: 1;
}

@keyframes emojiBobble {
  0%   { transform: translateY(0)    scale(1); }
  100% { transform: translateY(-8px) scale(1.10); }
}

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

/* ───── Grand Finale (all 56 caught) ───── */
#screen-finale.active {
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at center,
      #FFF8E7 0%,
      #FFE4EC 45%,
      #DAEFD6 100%);
}

.finale-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 720px;
  width: 100%;
  text-align: center;
}

.finale-banner {
  margin: 0;
  font-size: clamp(26px, 5vw, 44px);
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(45deg, #FF6B6B, #FFD93D, #6BCB77, #4D96FF, #B16BFF);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.15));
  animation: finaleBannerPop 600ms cubic-bezier(0.34, 1.4, 0.5, 1) backwards;
}

.finale-sub {
  margin: 0;
  font-size: clamp(15px, 2.4vw, 19px);
  color: var(--ink-soft);
  font-weight: 600;
  animation: finaleBannerPop 600ms cubic-bezier(0.34, 1.4, 0.5, 1) 120ms backwards;
}

@keyframes finaleBannerPop {
  0%   { transform: scale(0.6) translateY(-10px); opacity: 0; }
  100% { transform: scale(1)   translateY(0);     opacity: 1; }
}

.finale-rings {
  position: relative;
  width: clamp(320px, 88vw, 600px);
  aspect-ratio: 1 / 1;
  margin: 4px auto;
}

.finale-ring {
  position: absolute;
  inset: 0;
  animation-name: ringSpin;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
  will-change: transform;
}

/* Outer wrapper handles position-centering transform; inner span handles
   the bobble animation, so the two transforms don't fight for the same property. */
.finale-emoji {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: none;
  user-select: none;
}

.finale-emoji-inner {
  display: inline-block;
  font-size: clamp(26px, 5vw, 38px);
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(43, 42, 76, 0.18));
  animation: emojiBobble 0.7s ease-in-out infinite alternate;
}

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

/* ───── End-of-session screen ───── */
#screen-session-end.active {
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.session-end-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  max-width: 560px;
  width: 100%;
  text-align: center;
}

.session-end-title {
  font-size: clamp(28px, 5vw, 44px);
  font-weight: 700;
  margin: 0;
  color: var(--ink);
}

.session-end-sub {
  margin: 0;
  font-size: clamp(15px, 2.2vw, 18px);
  color: var(--ink-soft);
}

.session-end-catches {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin: 8px 0;
}

.session-end-emoji {
  font-size: clamp(50px, 10vw, 72px);
  line-height: 1;
  filter: drop-shadow(0 4px 8px rgba(43, 42, 76, 0.18));
  animation: sessionEmojiPop 500ms cubic-bezier(0.34, 1.4, 0.5, 1) backwards;
}

@keyframes sessionEmojiPop {
  0%   { transform: scale(0) rotate(-20deg); opacity: 0; }
  60%  { transform: scale(1.2) rotate(8deg);  opacity: 1; }
  100% { transform: scale(1)   rotate(0);     opacity: 1; }
}

.session-end-stars {
  display: flex;
  gap: 24px;
  font-size: clamp(20px, 3vw, 28px);
  font-weight: 700;
  color: var(--ink);
}

.session-end-star-icon {
  font-size: 1.2em;
  margin-right: 4px;
}

.session-end-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  margin-top: 8px;
}

/* ───── Legendary banner (full-screen on legendary capture) ───── */
.legendary-banner {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(135deg,
    rgba(255, 107, 107, 0.18),
    rgba(255, 217, 61, 0.18),
    rgba(107, 203, 119, 0.18),
    rgba(77, 150, 255, 0.18),
    rgba(177, 107, 255, 0.18));
}

.legendary-banner.show {
  animation: legendaryFlash 1400ms ease-out forwards;
}

@keyframes legendaryFlash {
  0%   { opacity: 0; }
  20%  { opacity: 1; }
  80%  { opacity: 1; }
  100% { opacity: 0; }
}

.legendary-banner-text {
  font-size: clamp(36px, 9vw, 96px);
  font-weight: 700;
  letter-spacing: 1px;
  background: linear-gradient(45deg, #FF6B6B, #FFD93D, #6BCB77, #4D96FF, #B16BFF);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.15);
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.25));
}

.legendary-banner.show .legendary-banner-text {
  animation: legendaryText 1400ms cubic-bezier(0.34, 1.4, 0.5, 1) forwards;
}

@keyframes legendaryText {
  0%   { transform: scale(0.4) rotate(-12deg); }
  30%  { transform: scale(1.25) rotate(6deg); }
  60%  { transform: scale(1)    rotate(0); }
  100% { transform: scale(1.15) rotate(0); }
}

/* ───── Star-fly animation (after capture) ───── */
.fly-star {
  position: fixed;
  font-size: 44px;
  pointer-events: none;
  z-index: 250;
  user-select: none;
  animation: starFly 720ms cubic-bezier(0.55, 0, 0.5, 1) forwards;
}

@keyframes starFly {
  0%   { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  18%  { transform: translate(-50%, -50%) scale(1.5); opacity: 1; }
  100% {
    transform:
      translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, 0px)))
      scale(0.5);
    opacity: 0.2;
  }
}

/* ───── Speech-bubble taunt (rare encounter flavor) ───── */
.taunt-bubble {
  position: absolute;
  background: white;
  color: var(--ink);
  border-radius: 18px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: clamp(14px, 2vw, 18px);
  box-shadow: 0 4px 12px rgba(43, 42, 76, 0.18);
  pointer-events: none;
  z-index: 5;
  white-space: nowrap;
  animation: tauntBubble 1700ms ease-out forwards;
  transform-origin: bottom left;
}

.taunt-bubble::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: 18px;
  width: 12px;
  height: 12px;
  background: white;
  transform: rotate(45deg);
  box-shadow: 2px 2px 4px rgba(43, 42, 76, 0.10);
}

@keyframes tauntBubble {
  0%   { transform: scale(0)   translateY(8px); opacity: 0; }
  18%  { transform: scale(1.1) translateY(0);   opacity: 1; }
  30%  { transform: scale(1)   translateY(0);   opacity: 1; }
  80%  { transform: scale(1)   translateY(0);   opacity: 1; }
  100% { transform: scale(0.9) translateY(-6px); opacity: 0; }
}

/* ───── Parent-gate modal ───── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 42, 76, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
  padding: 24px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-overlay[hidden] { display: none; }

.modal-card {
  background: white;
  border-radius: 24px;
  padding: 28px 24px 22px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  text-align: center;
}

.modal-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 16px;
  color: var(--ink);
  cursor: pointer;
  padding: 8px 4px;
}

.modal-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin-top: 2px;
  cursor: pointer;
}

.modal-row strong {
  display: block;
  font-weight: 700;
}

.modal-row-sub {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  margin-top: 2px;
}

.modal-btn {
  width: 100%;
  min-width: 0;
}

/* ───── Toast ───── */
.toast {
  position: fixed;
  top: 90px;
  left: 50%;
  transform: translate(-50%, -20px);
  background: var(--ink);
  color: white;
  padding: 12px 20px;
  border-radius: 18px;
  font-weight: 600;
  font-size: 16px;
  box-shadow: 0 8px 20px rgba(43, 42, 76, 0.3);
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms ease-out, transform 200ms ease-out;
  z-index: 100;
  max-width: calc(100vw - 32px);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
