:root {
  --safe-banner-height: 0px;
  /* Ad zone scales the browser, no need for reserved space */
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

:root {
  --blob-1: #4f46e5;
  /* Indigo */
  --blob-2: #7c3aed;
  /* Violet */
  --blob-3: #0ea5e9;
  /* Light Blue */
  --blob-4: #ec4899;
  /* Pink */
  --bg-dark: #0f172a;
}

.theme-pink {
  --blob-1: #f43f5e;
  --blob-2: #ec4899;
  --blob-3: #d946ef;
  --blob-4: #fbcfe8;
  --bg-dark: #831843;
}

.theme-gold {
  --blob-1: #fbbf24;
  --blob-2: #f59e0b;
  --blob-3: #d97706;
  --blob-4: #fef3c7;
  --bg-dark: #451a03;
}

.theme-green {
  --blob-1: #10b981;
  --blob-2: #059669;
  --blob-3: #065f46;
  --blob-4: #a7f3d0;
  --bg-dark: #064e3b;
}

.theme-cyber {
  --blob-1: #3b82f6;
  --blob-2: #a855f7;
  --blob-3: #ec4899;
  --blob-4: #06b6d4;
  --bg-dark: #000000;
}

.theme-aurora {
  --blob-1: #00ffcc;
  /* Mint/Cyan */
  --blob-2: #0099ff;
  /* Sky Blue */
  --blob-3: #33ff99;
  /* Bright Green */
  --blob-4: #0044ff;
  /* Deep Blue */
  --bg-dark: #001a1a;
}

html {
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  /* Deep Blue/Midnight Base */
  background-color: var(--bg-dark);
  font-family: 'Outfit', sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  /* Improved touch handling */
  color: white;
  transition: background-color 1s ease;
  min-height: 100vh;
  min-height: 100svh;
  /* Modern mobile height */
}

/* ---------------- MESH BACKGROUND ---------------- */
#mesh-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  background: var(--bg-dark);
  overflow: hidden;
  filter: blur(100px);
  transition: background 1s ease;
}

.blob {
  position: absolute;
  width: 50vw;
  height: 50vw;
  border-radius: 50%;
  opacity: 0.5;
  filter: blur(80px);
  animation: floatBlobs 20s infinite alternate ease-in-out;
  transition: background 1.5s ease;
}

.blob-1 {
  background: var(--blob-1);
  top: -10%;
  left: -10%;
  animation-duration: 25s;
}

.blob-2 {
  background: var(--blob-2);
  bottom: -10%;
  right: -10%;
  animation-duration: 30s;
  animation-delay: -5s;
}

.blob-3 {
  background: var(--blob-3);
  top: 40%;
  right: 10%;
  width: 40vw;
  height: 40vw;
  animation-duration: 22s;
  animation-delay: -10s;
}

.blob-4 {
  background: var(--blob-4);
  bottom: 20%;
  left: 20%;
  width: 35vw;
  height: 35vw;
  animation-duration: 28s;
  animation-delay: -15s;
}

/* Performance optimization for mobile bg */
@media (pointer: coarse),
(max-width: 768px) {
  #mesh-bg {
    filter: none !important;
    background: radial-gradient(circle at top left, var(--blob-1), var(--bg-dark), var(--blob-2));
    perspective: none;
    backface-visibility: hidden;
    transform: translate3d(0, 0, 0);
  }

  .blob {
    display: none !important;
    /* Hide expensive blobs on mobile */
  }

  /* Optimization: Removed will-change/backface-visibility to avoid blurriness on desktop */
}

@keyframes floatBlobs {
  0% {
    transform: translate(0, 0) scale(1) rotate(0deg);
  }

  33% {
    transform: translate(15%, 10%) scale(1.1) rotate(60deg);
  }

  66% {
    transform: translate(-10%, 20%) scale(0.9) rotate(120deg);
  }

  100% {
    transform: translate(5%, -15%) scale(1.05) rotate(180deg);
  }
}

#game-wrapper {
  height: 100vh;
  height: 100svh;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  /* Bottom spacing for sticky banner */
  padding-bottom: var(--safe-banner-height);
}

#game-container {
  flex: 1;
  /* This is the main 3-section container */
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  height: 100%;
  /* Explicitly take full height of wrapper */
  position: relative;
  z-index: 1;
}

/* ---------------- UI HEADER ---------------- */
#ui-header {
  flex-shrink: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  margin-top: 20px;
  padding: 15px 15px 5px 15px;
  background: transparent;
  box-sizing: border-box;
  z-index: 100;
}

#ui-header .icon-btn {
  --base-scale: 0.8;
  transform: scale(var(--base-scale));
}

#ui-header .level-badge-container {
  transform: scale(0.85);
}

@media (max-width: 600px) {
  #ui-header {
    gap: 12px;
    padding: 0 5%;
    height: 44px;
  }

  #level-title {
    font-size: 18px;
    /* Compressed */
  }
}

.level-badge-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#level-title {
  font-size: 32px;
  font-weight: 800;
  text-shadow: 0 4px 6px rgba(0, 0, 0, 0.5);
  margin: 0 0 5px 0;
  color: #fff;
}

.level-subtitle {
  background: #f59e0b;
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  padding: 3px 15px;
  border-radius: 20px;
  text-transform: uppercase;
  box-shadow: 0 3px 0 #b45309;
}

/* Gorgeous 3D Round Buttons */
.icon-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  background: linear-gradient(to bottom, #818cf8, #4f46e5);
  box-shadow:
    0 6px 0 #3730a3,
    inset 0 3px 2px rgba(255, 255, 255, 0.6),
    0 10px 10px rgba(0, 0, 0, 0.3);
  transform: scale(1.15);
  /* Slightly bigger buttons */
  transition: transform 0.1s, box-shadow 0.1s;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:active {
  transform: scale(1.15) translateY(6px);
  box-shadow:
    0 0 0 #3730a3,
    inset 0 3px 2px rgba(255, 255, 255, 0.6),
    0 3px 5px rgba(0, 0, 0, 0.3);
}

.notif-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #ef4444;
  color: white;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  z-index: 10;
}

.badge-count {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #22c55e;
  /* Unified Green */
  color: white;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  z-index: 10;
}

.pupil {
  width: 3px !important;
  height: 3px !important;
  background: #000;
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.bounce-anim {
  animation: settingsBounce 1.5s infinite ease-in-out;
}

@keyframes settingsBounce {

  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(var(--base-scale, 1)) rotate(0deg);
  }

  25% {
    transform: translate3d(0, 0, 0) scale(calc(var(--base-scale, 1) * 1.15)) rotate(-15deg);
  }

  50% {
    transform: translate3d(0, 0, 0) scale(calc(var(--base-scale, 1) * 1.15)) rotate(15deg);
  }

  75% {
    transform: translate3d(0, 0, 0) scale(calc(var(--base-scale, 1) * 1.15)) rotate(-15deg);
  }
}

/* ---------------- GAME AREA (THE BODY) ---------------- */
#game-area {
  flex: 1;
  min-height: 0;
  /* CRITICAL: allows flex item to shrink below content size */
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
  /* Important: scale happens here */
  padding: 10px;
  box-sizing: border-box;
}

#game-area .flask-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: flex-end;
  flex-wrap: nowrap;
  transform-origin: center center;
  transition: transform 0.2s ease-out;
}

/* ---------------- FOOTER ---------------- */
#ui-footer {
  flex-shrink: 0;
  width: 100%;
  display: flex;
  justify-content: space-around;
  align-items: center;
  margin-bottom: 5px;
  padding: 10px 15px 25px 15px;
  /* Bottom padding for mobile home indicators */
  background: transparent;
  backdrop-filter: none;
  box-sizing: border-box;
}

#ui-footer .icon-btn {
  --base-scale: 0.9;
  transform: scale(var(--base-scale));
}

/* 3D Base Platform for elements to stack on (Replaces the "Box/Flask" visually) */
.box {
  position: relative;
  width: 66px;
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-start;
  align-items: center;
  padding-top: 10px;
  padding-bottom: 25px;
  background: rgba(255, 255, 255, 0.05);
  /* Sleek glass backing */
  border: 2px solid rgba(255, 255, 255, 0.05);
  border-bottom: none;
  border-radius: 20px;
}

/* Top rim of the base */
.box::before {
  content: '';
  position: absolute;
  bottom: 12px;
  width: 70px;
  height: 16px;
  background: #e2e8f0;
  border-radius: 50%;
  z-index: 10;
}

/* Body of the base */
.box::after {
  content: '';
  position: absolute;
  bottom: 0;
  width: 70px;
  height: 18px;
  background: #94a3b8;
  border-radius: 50%;
  z-index: 5;
  box-shadow: 0 10px 10px rgba(0, 0, 0, 0.5);
}

/* The Screw/Thread base for empty slots omitted */

/* ---------------- ITEMS (MONSTERS) ---------------- */
.monster {
  width: 62px;
  height: 40px;
  border-radius: 12px;
  background: #fff;
  /* set by JS via inline var */
  margin-top: -6px;
  margin-bottom: 0;
  /* seamless stacking overlap */
  position: relative;
  z-index: 20;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: grab;
  transition: filter 0.2s, transform 0.2s;
  will-change: transform;

  /* 3D Bevel, imitating the nuts from screenshot */
  box-shadow:
    inset 0 12px 10px -8px rgba(255, 255, 255, 0.7),
    inset 0 -10px 10px -5px rgba(0, 0, 0, 0.3),
    0 4px 6px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  /* For gloss clip */
}

/* Glossy highlight for extra "juiciness" */
.monster::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 4px;
  right: 4px;
  height: 14px;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0));
  border-radius: 8px 8px 2px 2px;
  pointer-events: none;
  z-index: 25;
}

/* Overriding gloss for darkened monsters to keep them flat/stone-like */
.monster.darkened::after {
  display: none;
}

/* Optimization: disable heavy filters during animation */
.monster.animating {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5) !important;
  filter: none !important;
}

.monster.animating {
  z-index: 200 !important;
  pointer-events: none;
}

.monster.selected {
  z-index: 200;
  filter: brightness(1.2) drop-shadow(0 10px 10px rgba(0, 0, 0, 0.5));
  transform: translateY(-22px);
}

/* Darkened Hidden Monsters - Stone Effect */
.monster.darkened {
  background: #334155 !important;
  /* Dark slate */
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    inset 0 10px 10px -5px rgba(255, 255, 255, 0.05),
    inset 0 -12px 10px -5px rgba(0, 0, 0, 0.8),
    0 4px 5px rgba(0, 0, 0, 0.6);
}

/* Magical glowing eyes for darkened monsters */
.monster.darkened .eyes {
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 1));
}

.monster.darkened .eye {
  background: #fff;
}

.monster.darkened .pupil {
  display: none;
}

/* Facial features */
.eyes {
  display: flex;
  gap: 8px;
  margin-bottom: 3px;
  pointer-events: none;
  /* Let drag pass through */
}

.eye {
  width: 10px;
  height: 10px;
  background: #fff;
  border-radius: 50%;
  position: relative;
  box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.1);
}

.pupil {
  width: 4px;
  height: 4px;
  background: #0f172a;
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: idle-eyes 16s infinite var(--idle-delay, 0s) ease-in-out;
}

@keyframes idle-eyes {

  0%,
  100%,
  80% {
    transform: translate(-50%, -50%);
  }

  20%,
  30% {
    transform: translate(calc(-50% + 2px), calc(-50% - 1px));
  }

  40%,
  50% {
    transform: translate(calc(-50% - 2px), calc(-50% + 1px));
  }

  60%,
  70% {
    transform: translate(calc(-50% + 1px), calc(-50% + 2px));
  }
}

@keyframes blink {

  0%,
  90%,
  100% {
    transform: scaleY(1);
  }

  95% {
    transform: scaleY(0.1);
  }
}

.eye {
  width: 10px;
  height: 10px;
  background: #fff;
  border-radius: 50%;
  position: relative;
  box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.1);
  animation: blink 10s infinite var(--blink-delay, 0s);
}

.mouth {
  position: absolute;
  bottom: 8px;
  width: 12px;
  height: 2px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 2px;
}

/* Smiling and Bouncing for Completed */
.box.completed .monster .mouth {
  height: 6px;
  border-radius: 50%;
  border: none;
  border-bottom: 2px solid rgba(0, 0, 0, 0.6);
  background: transparent;
  transform: translateY(-2px);
}

.box.completed .monster {
  animation: bounceJoy 0.8s infinite alternate ease-in-out;
}

.box.completed .monster:nth-child(even) {
  animation-delay: 0.2s;
}

@keyframes bounceJoy {
  0% {
    transform: translate3d(0, 0, 0);
  }

  100% {
    transform: translate3d(0, -8px, 0);
  }
}

/* ---------------- VICTORY MODAL ---------------- */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding-bottom: var(--safe-banner-height);
}

#modal-content {
  background: #1e293b;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 95%;
  max-width: 500px;
  /* Increased from 400px for wider store/bestiary */
  max-height: 85vh;
  padding: 20px;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.824);
  box-sizing: border-box;
}

@media (max-width: 480px) {
  #modal-content {
    padding: 10px;
    width: 98%;
  }

  .victory-ribbon {
    font-size: 20px;
    /* Smaller ribbon */
    padding: 8px 25px;
    margin-bottom: 20px;
  }

  .crown-icon {
    font-size: 60px;
    /* Smaller crown */
    margin-bottom: -30px;
  }

  .btn-green {
    font-size: 20px;
    padding: 10px 30px;
  }
}

@media (max-height: 500px) {
  #modal-content {
    flex-direction: row;
    /* Layout change for landscape */
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
  }

  .crown-icon,
  .victory-ribbon {
    display: none;
  }

  /* Hide decorative bits in low landscape */
}

#modal-overlay.hidden #modal-content {
  transform: scale(0.6);
}

/* CSS Crown Emoji Animation */
.crown-icon {
  font-size: 70px;
  /* Reduced from 100px (~30%) */
  margin-bottom: -25px;
  z-index: 3;
  filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.5));
  animation: floatCrown 2.5s infinite ease-in-out;
}

@keyframes floatCrown {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-15px);
  }
}

/* Beautiful Red Ribbon with 3D ends */
.victory-ribbon {
  position: relative;
  background: linear-gradient(to bottom, #ef4444, #dc2626);
  color: white;
  font-size: 22px;
  /* Reduced from 32px (~30%) */
  font-weight: 800;
  padding: 10px 35px;
  /* Tighter padding */
  box-shadow: 0 8px 12px rgba(0, 0, 0, 0.4), inset 0 2px 0 rgba(255, 255, 255, 0.3);
  text-transform: uppercase;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  z-index: 2;
  margin-bottom: 35px;
  /* Reduced from 50px */
}

.victory-ribbon::before,
.victory-ribbon::after {
  content: '';
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 36px solid transparent;
  border-bottom: 36px solid transparent;
  z-index: -1;
  filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.4));
}

.victory-ribbon::before {
  left: -35px;
  border-right: 45px solid #b91c1c;
  /* Darker red corner */
}

/* Victory Modal Components */
.win-research-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  background: rgba(0, 0, 0, 0.2);
  padding: 20px;
  border-radius: 15px;
  text-align: center;
  margin-bottom: 15px;
}

.win-label {
  color: rgba(255, 255, 255, 0.5);
  font-weight: 800;
  font-size: 14px;
  margin-bottom: 5px;
  text-transform: uppercase;
}

.win-status-text {
  color: #fde047;
  font-weight: 800;
  font-size: 20px;
  margin-bottom: 15px;
  text-transform: uppercase;
  width: 100%;
  text-align: center;
}

.win-monster-box {
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 5px 0;
}

.win-monster-scale {
  transform: scale(1.5);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  height: 32px;
}

.win-monster-desc {
  color: white;
  font-size: 16px;
  /* Slightly smaller for fit */
  font-weight: 600;
  font-family: 'Outfit', sans-serif;
  margin: 10px 0;
  max-width: 320px;
  line-height: 1.4;
  opacity: 0;
  transition: opacity 0.5s;
  text-align: center;
}

.win-progress-container {
  margin-top: 15px;
  height: 12px;
  width: 100%;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  overflow: hidden;
}

/* Mobile Compression for Victory Modal */
@media (max-width: 480px) {
  .win-research-block {
    padding: 12px;
    margin-bottom: 10px;
  }

  .win-status-text {
    font-size: 16px;
    margin-bottom: 8px;
  }

  .win-monster-box {
    height: 70px;
  }

  .win-monster-scale {
    transform: scale(1.2);
  }

  .win-monster-desc {
    font-size: 14px;
    margin: 5px 0;
  }

  .win-progress-container {
    margin-top: 10px;
    height: 10px;
  }

  .btn-green {
    margin-top: 5px;
    padding: 10px 30px;
    font-size: 18px;
  }
}

@media (max-height: 650px) {
  #modal-content {
    max-height: calc(90vh - 120px);
    padding: 8px;
  }

  .crown-icon {
    font-size: 50px;
    margin-bottom: -15px;
  }

  .victory-ribbon {
    font-size: 18px;
    padding: 6px 20px;
    margin-bottom: 20px;
  }

  .win-research-block {
    padding: 8px;
    margin-bottom: 8px;
  }

  .win-monster-box {
    height: 60px;
  }

  .win-monster-desc {
    display: none;
    /* Hide description on very short screens to save space */
  }
}

.victory-ribbon::after {
  right: -35px;
  border-left: 45px solid #b91c1c;
}

/* 3D Green 'Next' Button */
.btn-green {
  background: linear-gradient(to bottom, #22c55e, #16a34a);
  color: white;
  font-size: 20px;
  /* Reduced from 26px */
  font-weight: 800;
  padding: 12px 40px;
  border: 3px solid #86efac;
  border-radius: 20px;
  cursor: pointer;
  box-shadow:
    0 8px 0 #14532d,
    inset 0 3px 2px rgba(255, 255, 255, 0.3),
    0 15px 15px rgba(0, 0, 0, 0.4);
  transition: transform 0.1s, box-shadow 0.1s;
  outline: none;
  text-transform: uppercase;
}

.btn-green:active {
  transform: translateY(8px);
  box-shadow:
    0 0 0 #14532d,
    inset 0 3px 2px rgba(255, 255, 255, 0.3),
    0 5px 5px rgba(0, 0, 0, 0.4);
}

/* Tooltip */
#tutorial-tooltip {
  position: absolute;
  top: 140px;
  /* Moved lower to avoid overlapping title */
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, rgba(31, 41, 55, 0.9), rgba(15, 23, 42, 0.9));
  color: #f8fafc;
  margin-top: 35px;
  padding: 12px 24px;
  border-radius: 30px;
  font-weight: 600;
  z-index: 100;
  border: 2px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
  text-align: center;
  max-width: 90%;
  animation: pulse-tooltip 2s infinite ease-in-out;
}

@keyframes pulse-tooltip {

  0%,
  100% {
    transform: translateX(-50%) scale(1);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 0 0 rgba(59, 130, 246, 0);
  }

  50% {
    transform: translateX(-50%) scale(1.05);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 0 15px rgba(59, 130, 246, 0.5);
  }
}

.hidden {
  display: none !important;
}

/* ---------------- UI FOOTER ---------------- */
#ui-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 75px;
  padding: 10px;
  margin-top: 20px;
}

#undo-btn {
  font-size: 36px;
  padding-bottom: 5px;
  /* Alignment tweak for the arrow icon */
}

.icon-btn:disabled {
  background: #64748b;
  box-shadow: 0 6px 0 #475569, inset 0 3px 2px rgba(255, 255, 255, 0.2);
  cursor: not-allowed;
  opacity: 0.6;
}

.icon-btn:disabled:active {
  transform: scale(1.15);
  box-shadow: 0 6px 0 #475569, inset 0 3px 2px rgba(255, 255, 255, 0.2);
}

.ad-icon-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #22c55e;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  border: 2px solid #fff;
  color: #fff;
}

/* ---------------- STORE MODAL UI ---------------- */
.store-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 15px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  color: white;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.store-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 0 15px rgba(129, 140, 248, 0.3);
  border-color: rgba(129, 140, 248, 0.5);
}

.store-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.store-btn:disabled {
  opacity: 0.6;
  cursor: default;
  background: rgba(0, 0, 0, 0.3);
}

.store-category-title {
  color: #fde047;
  font-size: 14px;
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  margin: 15px 0 8px 0;
  text-transform: uppercase;
  text-align: center;
  width: 100%;
}

.store-block {
  width: 100%;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 18px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.store-icon {
  font-size: 28px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.store-info {
  flex: 1;
}

.store-info div:first-child {
  font-size: 14px;
  font-weight: 800;
  margin-bottom: 2px;
}

.store-price {
  font-size: 13px;
  font-weight: 800;
  color: #fde047;
  background: rgba(0, 0, 0, 0.3);
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  margin-top: 2px;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
}

@media (max-width: 350px) {
  .theme-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.theme-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 5px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 14px;
  border: 2px solid transparent;
  transition: all 0.2s ease;
  cursor: pointer;
}

.theme-item.active {
  border-color: #fde047;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 0 15px rgba(253, 224, 71, 0.2);
}

.theme-preview {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.theme-item:hover:not(.active) {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
}

/* ---------------- BESTIARY UI ---------------- */
.bestiary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  /* Reduced from 15px */
  width: 100%;
  max-width: 480px;
  padding: 10px;
  /* Reduced from 15px */
  max-height: 50vh;
  /* Better height control */
  overflow-y: auto;
  overflow-x: hidden;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 15px;
  margin-bottom: 15px;
  box-sizing: border-box;
}

.bestiary-card {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 6px;
  /* Reduced from 8px to fit more */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
}

.bestiary-card.unlocked:hover {
  transform: translateY(-5px);
  background: rgba(255, 255, 255, 0.15);
  box-shadow: 0 5px 15px rgba(168, 85, 247, 0.4);
}

.bestiary-card.locked {
  cursor: not-allowed;
  opacity: 0.6;
}

.monster-preview {
  width: 50px;
  height: 32px;
  border-radius: 8px;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: inset 0 6px 6px -4px rgba(255, 255, 255, 0.5), inset 0 -6px 6px -4px rgba(0, 0, 0, 0.3);
}

.monster-preview.silhouette {
  background: #334155 !important;
  /* Always grey stone color */
}

.monster-preview.silhouette::after {
  content: '?';
  font-size: 14px;
  /* Scaled down for 1.5x container */
  font-weight: 900;
  color: rgba(255, 255, 255, 0.4);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.bestiary-name {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  text-align: center;
  color: #94a3b8;
}

.unlocked .bestiary-name {
  color: #fff;
}

/* Happy Monster UI inside Bestiary */
.unlocked .monster-preview .eyes {
  display: flex;
  gap: 4px;
}

.unlocked .monster-preview .eye {
  width: 8px;
  height: 8px;
  background: #fff;
  border-radius: 50%;
  position: relative;
  animation: blinkEye 3s infinite;
}

.unlocked .monster-preview .pupil {
  width: 3px;
  height: 3px;
  background: #000;
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.unlocked .monster-preview .mouth {
  position: absolute;
  bottom: 4px;
  width: 10px;
  height: 6px;
  border-bottom: 2px solid rgba(0, 0, 0, 0.6);
  border-radius: 50%;
  background: transparent;
}

.unlocked .monster-preview {
  animation: bounceJoy 0.8s infinite alternate ease-in-out;
}

@keyframes blinkEye {

  0%,
  90%,
  100% {
    transform: scaleY(1);
  }

  95% {
    transform: scaleY(0.1);
  }
}

/* Info Panel */
.bestiary-info-panel {
  background: rgba(168, 85, 247, 0.2);
  border: 2px solid rgba(168, 85, 247, 0.4);
  border-radius: 15px;
  padding: 15px;
  width: 100%;
  max-width: 380px;
  margin-top: 5px;
  text-align: center;
  animation: slideUp 0.3s ease-out;
}

.info-title {
  color: #fde047;
  font-weight: 800;
  font-size: 18px;
  margin-bottom: 5px;
}

.info-desc {
  color: #fff;
  font-size: 14px;
  line-height: 1.4;
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Win Progress Bar */
.win-progress-container {
  width: 100%;
  max-width: 300px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 10px;
  height: 12px;
  overflow: hidden;
  margin: 10px 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.win-progress-fill {
  height: 100%;
  background: linear-gradient(to right, #f59e0b, #ed8936);
  /* Golden progress */
  width: 0%;
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.5);
}

/* Confetti effect */
.confetti {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #fde047;
  border-radius: 2px;
  z-index: 1001;
  will-change: transform;
  pointer-events: none;
}

@media (max-width: 400px) {
  .bestiary-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 10px;
  }
}

@media (max-width: 480px) {
  .bestiary-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .bestiary-name {
    font-size: 9px;
  }
}

@media (max-width: 350px) {
  .bestiary-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Hide question marks in Bestiary */
.bestiary-grid .monster-preview.silhouette::after {
  display: none;
}

/* ---------------- TUTORIAL TOOLTIP ---------------- */
#tutorial-tooltip {
  position: absolute;
  top: 100px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: linear-gradient(135deg, #a855f7, #6366f1);
  color: white;
  padding: 12px 40px 12px 20px;
  border-radius: 16px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3), inset 0 2px 2px rgba(255, 255, 255, 0.4);
  max-width: 90%;
  width: max-content;
  text-align: center;
  animation: tooltipPulse 2s infinite ease-in-out;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.tooltip-close {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: #ef4444;
  /* High-visibility red */
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.tooltip-close:hover {
  background: #dc2626;
  transform: translateY(-50%) scale(1.1);
}

@keyframes tooltipPulse {
  0% {
    transform: translateX(-50%) translateY(0);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  }

  50% {
    transform: translateX(-50%) translateY(-5px);
    box-shadow: 0 15px 35px rgba(168, 85, 247, 0.4);
  }

  100% {
    transform: translateX(-50%) translateY(0);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  }
}

#tutorial-tooltip.hidden {
  display: none;
}

/* Wider Layout for PC / Tablets */
@media (min-width: 1024px) {
  #game-container {
    max-width: 1000px;
  }
}

/* ---------------- LOADING SCREEN ---------------- */
#loading-screen {
  position: fixed;
  inset: 0;
  background: #0f172a;
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 0.5s ease-in-out, visibility 0.5s ease-in-out;
}

#loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
}

.loader-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.loader-monster {
  width: 100px;
  height: 65px;
  background: #a855f7; /* Purple base */
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  box-shadow: 
    inset 0 15px 15px -10px rgba(255, 255, 255, 0.4),
    0 20px 30px rgba(0, 0, 0, 0.5);
  animation: loaderBounce 1.5s infinite ease-in-out;
}

.loader-monster .eyes {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.loader-monster .eye {
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  position: relative;
  animation: none;
}

.loader-monster .pupil {
  width: 6px;
  height: 6px;
  background: #000;
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.loader-monster .mouth {
  width: 20px;
  height: 8px;
  background: transparent;
  border-radius: 50%;
  border-bottom: 3px solid rgba(0, 0, 0, 0.5);
  margin-top: -2px;
}

#loading-text {
  color: #fff;
  font-size: 24px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 2px;
  text-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
  min-height: 1em;
}

#loading-text::after {
  font-size: 24px;
}

.loader-bar {
  width: 200px;
  height: 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  overflow: hidden;
  position: relative;
}

.loader-progress {
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, #a855f7, transparent);
  animation: loaderProgress 1.5s infinite linear;
}

@keyframes loaderBounce {
  0%, 100% { transform: translateY(0) scale(1.05); }
  50% { transform: translateY(-30px) scale(0.95); }
}

@keyframes loaderProgress {
  0% { left: -100%; }
  100% { left: 100%; }
}