/* ===== RESET & SAFETY ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0a1a;
  color: #fff;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  position: fixed;
  top: 0;
  left: 0;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Prevent pull-to-refresh */
html {
  overscroll-behavior-y: contain;
}

/* ===== SCREENS ===== */
.screen {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: none;
  z-index: 1;
}
.screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== SPLASH SCREEN ===== */
#splash-screen {
  background: radial-gradient(ellipse at center, #1a1040 0%, #0a0a1a 70%);
  flex-direction: column;
  z-index: 100;
  cursor: pointer;
}

.splash-content {
  text-align: center;
  position: relative;
}

.splash-title {
  font-size: clamp(2rem, 8vw, 4rem);
  font-weight: 900;
  background: linear-gradient(135deg, #ff6ff0, #7df9ff, #ffe66d, #ff6ff0);
  background-size: 300% 300%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientShift 3s ease infinite, floatUp 2s ease-in-out infinite;
  filter: drop-shadow(0 0 20px rgba(125, 249, 255, 0.5));
  padding: 0.5em;
}

.splash-title-glow {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 300px; height: 300px;
  background: radial-gradient(circle, rgba(125, 249, 255, 0.15) 0%, transparent 70%);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

.splash-sub {
  font-size: clamp(1rem, 4vw, 1.5rem);
  color: rgba(255,255,255,0.6);
  margin-top: 1rem;
  animation: blink 2s ease-in-out infinite;
}

.splash-dinos {
  margin-top: 2rem;
  font-size: clamp(3rem, 12vw, 6rem);
  display: flex;
  justify-content: center;
  gap: 1rem;
}

.splash-dino {
  display: inline-block;
  animation: floatUp 2s ease-in-out infinite;
  filter: drop-shadow(0 0 15px rgba(255, 111, 240, 0.6));
}
.splash-dino.d1 { animation-delay: 0s; }
.splash-dino.d2 { animation-delay: 0.4s; }
.splash-dino.d3 { animation-delay: 0.8s; }

/* ===== GAME SCREEN ===== */
#game-screen {
  background: #0a0a1a;
}
#game-screen.active {
  display: block;
}

#game-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: block;
}

/* ===== LEVEL NAME ===== */
.level-name {
  position: absolute;
  top: 12%;
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(1.2rem, 5vw, 2rem);
  font-weight: 700;
  color: rgba(255,255,255,0.8);
  text-shadow: 0 0 20px rgba(125, 249, 255, 0.6), 0 0 40px rgba(125, 249, 255, 0.3);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.8s ease;
  z-index: 5;
  text-align: center;
  white-space: nowrap;
}
.level-name.show {
  opacity: 1;
}
.level-name.fade-out {
  opacity: 0;
}

/* ===== PROGRESS BAR ===== */
.progress-bar-container {
  position: absolute;
  bottom: 3%;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  max-width: 300px;
  height: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  overflow: hidden;
  z-index: 5;
  pointer-events: none;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #7df9ff, #ff6ff0);
  border-radius: 4px;
  transition: width 0.3s ease;
  box-shadow: 0 0 10px rgba(125, 249, 255, 0.5);
}

/* ===== CELEBRATION ===== */
.celebration {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  background: rgba(0, 0, 0, 0.4);
  pointer-events: none;
}
.celebration.hidden { display: none; }

.celebration-text {
  text-align: center;
  animation: celebrationPop 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.good-job {
  font-size: clamp(2.5rem, 10vw, 5rem);
  font-weight: 900;
  background: linear-gradient(135deg, #ffe66d, #ff6ff0, #7df9ff);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientShift 2s ease infinite;
  filter: drop-shadow(0 0 30px rgba(255, 230, 109, 0.6));
}

.kato-name {
  font-size: clamp(2rem, 8vw, 4rem);
  font-weight: 900;
  color: #7df9ff;
  text-shadow: 0 0 30px rgba(125, 249, 255, 0.8), 0 0 60px rgba(125, 249, 255, 0.4);
  margin-top: 0.2em;
}

/* ===== REWARD CARD ===== */
.reward-card {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 25;
}
.reward-card.hidden { display: none; }

.card-backdrop {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.7);
}

.card-container {
  position: relative;
  z-index: 2;
  animation: cardReveal 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.card-glow {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 350px; height: 450px;
  border-radius: 20px;
  filter: blur(30px);
  opacity: 0.6;
  animation: cardGlowPulse 2s ease-in-out infinite;
}

.card-frame {
  position: relative;
  width: clamp(200px, 60vw, 280px);
  height: clamp(280px, 80vw, 380px);
  border-radius: 16px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  background: linear-gradient(160deg, rgba(30, 20, 60, 0.95), rgba(10, 10, 30, 0.95));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(125, 249, 255, 0.3), inset 0 0 30px rgba(125, 249, 255, 0.1);
}

.card-creature {
  font-size: clamp(5rem, 25vw, 8rem);
  filter: drop-shadow(0 0 20px rgba(255, 111, 240, 0.6));
  animation: floatUp 2s ease-in-out infinite;
}

.card-rarity {
  font-size: clamp(1rem, 4vw, 1.5rem);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-top: 0.5rem;
  padding: 0.3em 1em;
  border-radius: 20px;
  background: rgba(255,255,255,0.1);
}

/* Rarity Colors */
.card-rarity.common { color: #aab4be; text-shadow: 0 0 10px rgba(170,180,190,0.5); }
.card-rarity.rare { color: #7df9ff; text-shadow: 0 0 15px rgba(125,249,255,0.6); }
.card-rarity.epic { color: #c77dff; text-shadow: 0 0 15px rgba(199,125,255,0.6); }
.card-rarity.ultra-rare { color: #ffe66d; text-shadow: 0 0 20px rgba(255,230,109,0.7); }
.card-rarity.mythic { 
  background: linear-gradient(135deg, #ff6ff0, #7df9ff, #ffe66d);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 15px rgba(255,111,240,0.6));
}

.card-sparkles {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}

/* ===== PARENT ZONE ===== */
.parent-zone {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 80px;
  height: 80px;
  z-index: 30;
  /* Invisible but touchable */
}

/* ===== PARENT PANEL ===== */
.parent-panel {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.9);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.parent-panel.hidden { display: none; }

.parent-panel-inner {
  background: #1a1a2e;
  padding: 2rem;
  border-radius: 16px;
  width: 90%;
  max-width: 360px;
  border: 1px solid rgba(125, 249, 255, 0.2);
  box-shadow: 0 0 40px rgba(125, 249, 255, 0.1);
}

.parent-panel-inner h2 {
  font-size: 1.3rem;
  color: #7df9ff;
  margin-bottom: 1.5rem;
  text-align: center;
}

.parent-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.parent-option:last-child { border-bottom: none; }

.parent-option label {
  font-size: 0.95rem;
  color: rgba(255,255,255,0.7);
}

.toggle-btn {
  background: rgba(125, 249, 255, 0.15);
  color: #7df9ff;
  border: 1px solid rgba(125, 249, 255, 0.3);
  padding: 0.4rem 1.2rem;
  border-radius: 20px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}
.toggle-btn:active {
  background: rgba(125, 249, 255, 0.3);
}

.action-btn {
  width: 100%;
  background: rgba(255, 111, 240, 0.15);
  color: #ff6ff0;
  border: 1px solid rgba(255, 111, 240, 0.3);
  padding: 0.6rem 1rem;
  border-radius: 12px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}
.action-btn:active {
  background: rgba(255, 111, 240, 0.3);
}
.close-btn {
  background: rgba(125, 249, 255, 0.15);
  color: #7df9ff;
  border-color: rgba(125, 249, 255, 0.3);
  margin-top: 0.5rem;
}

.parent-input {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  font-size: 0.9rem;
  width: 120px;
  text-align: center;
  outline: none;
}
.parent-input:focus {
  border-color: #7df9ff;
}

/* ===== ANIMATIONS ===== */
@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

@keyframes floatUp {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 0.6; transform: translate(-50%, -50%) scale(1.1); }
}

@keyframes blink {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

@keyframes celebrationPop {
  0% { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes cardReveal {
  0% { transform: scale(0) rotateY(180deg); opacity: 0; }
  60% { transform: scale(1.1) rotateY(0deg); opacity: 1; }
  100% { transform: scale(1) rotateY(0deg); opacity: 1; }
}

@keyframes cardGlowPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

/* ===== RESPONSIVE ===== */
@media (max-height: 500px) {
  .splash-title { font-size: 1.8rem; }
  .splash-dinos { font-size: 3rem; margin-top: 1rem; }
}

/* Safe area padding for notched devices */
@supports (padding: env(safe-area-inset-top)) {
  .progress-bar-container {
    bottom: calc(3% + env(safe-area-inset-bottom));
  }
}
