@import url('https://fonts.googleapis.com/css2?family=Quicksand:wght@400;600;700&display=swap');

/* =========================================
   VARIABLES & RESET
========================================= */
:root {
  /* Enhanced Color Palette */
  --bg: #f0ebfa;
  --ink: #2d2640;
  --ink-soft: #6f6880;
  --surface: #e8e1f4;
  --green: #4db87a;
  --green-soft: #d2f0dd;
  --lila: #7c5cbf;
  --lila-soft: #e3d9f8;
  --teal: #3ba8b3;
  --teal-soft: #ceeef1;
  --gold: #f0b429;
  --gold-soft: #fce9b8;
  --berry: #e06098;
  --berry-soft: #fad6e8;

  /* Typography & Shadows */
  --font-family: 'Quicksand', sans-serif;
  --shadow-sm: 0 2px 8px rgba(45, 38, 64, 0.08);
  --shadow-md: 0 8px 24px rgba(45, 38, 64, 0.12);
  --shadow-lg: 0 16px 40px rgba(45, 38, 64, 0.16);
  --glass-bg: rgba(255, 255, 255, 0.4);
  --glass-border: rgba(255, 255, 255, 0.6);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg);
  color: var(--ink);
  overflow: hidden; /* Prevent body scrolling */
  width: 100vw;
  height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
}

button {
  font-family: inherit;
  border: none;
  background: none;
  cursor: pointer;
  outline: none;
}

.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* =========================================
   START SCREEN
========================================= */
#age-select {
  justify-content: center;
  align-items: center;
  z-index: 10;
}

.start-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 200%;
  height: 200%;
  background: linear-gradient(45deg, var(--lila-soft), var(--green-soft), var(--teal-soft), var(--bg));
  background-size: 400% 400%;
  animation: gradientShift 15s ease infinite;
  z-index: -1;
}

.intro {
  text-align: center;
  margin-bottom: 3rem;
  z-index: 1;
}

.hero-paws {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.paw {
  font-size: 2.5rem;
  display: inline-block;
  animation: float 3s ease-in-out infinite;
}
.paw.p1 { animation-delay: 0s; }
.paw.p2 { animation-delay: 0.2s; }
.paw.p3 { animation-delay: 0.4s; }

.intro h1 {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--lila);
  text-shadow: 2px 2px 0px rgba(255,255,255,0.8);
  margin-bottom: 0.5rem;
}

.intro .subtitle {
  font-size: 1.1rem;
  color: var(--ink-soft);
  font-weight: 600;
}

/* Pet Customizer Card */
.customizer-card {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 2px solid var(--glass-border);
  border-radius: 1.5rem;
  padding: 1.25rem 1.75rem;
  max-width: 480px;
  width: 90%;
  margin: 0 auto 1.75rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  z-index: 1;
}

.customizer-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  text-align: left;
}

.customizer-label {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
}

.pet-name-input {
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 0.65rem 1rem;
  border-radius: 1rem;
  border: 2px solid var(--surface);
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.pet-name-input:focus {
  border-color: var(--lila);
  box-shadow: 0 0 0 3px var(--lila-soft);
}

.pet-type-buttons {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.pet-type-btn {
  flex: 1;
  min-width: 90px;
  padding: 0.6rem 0.8rem;
  border-radius: 1rem;
  border: 2px solid var(--surface);
  background: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  transition: all 0.2s ease;
}

.pet-type-btn:hover {
  border-color: var(--lila-soft);
  transform: translateY(-2px);
}

.pet-type-btn.active {
  border-color: var(--lila);
  background: var(--lila-soft);
  color: var(--lila);
  box-shadow: 0 4px 10px rgba(124, 92, 191, 0.2);
}

.pet-color-buttons {
  display: flex;
  gap: 0.5rem;
  justify-content: space-between;
}

.pet-color-btn {
  flex: 1;
  height: 44px;
  border-radius: 0.9rem;
  border: 2.5px solid var(--surface);
  background: var(--swatch, #fff);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.pet-color-btn:hover {
  transform: translateY(-3px) scale(1.08);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.12);
}

.pet-color-btn.active {
  border-color: var(--ink);
  transform: translateY(-2px) scale(1.1);
  box-shadow: 0 0 0 3px rgba(124, 92, 191, 0.4), 0 6px 14px rgba(0, 0, 0, 0.15);
}

.age-cards {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
  padding: 0 1rem;
  z-index: 1;
}

.age-card {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 2px solid var(--glass-border);
  border-radius: 1.5rem;
  padding: 2rem 1.5rem;
  width: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.age-card:hover {
  transform: translateY(-5px) scale(1.05);
  box-shadow: var(--shadow-md), 0 0 15px rgba(255,255,255,0.5);
  border-color: #fff;
}

.age-card-emoji {
  font-size: 3.5rem;
  display: inline-block;
  transition: transform 0.3s ease;
}

.age-card:hover .age-card-emoji {
  animation: celebrateBounce 1s ease infinite;
}

.age-card-badge {
  background: var(--lila);
  color: white;
  padding: 0.2rem 0.6rem;
  border-radius: 1rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.age-card-title {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--ink);
}

.age-card-hint {
  font-size: 0.8rem;
  color: var(--ink-soft);
}

/* =========================================
   GAME SCREEN - HUD
========================================= */
#game {
  background: var(--bg);
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--glass-border);
  z-index: 20;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.icon-btn svg { width: 1.3rem; height: 1.3rem; }

.icon-btn:hover {
  transform: scale(1.1);
  background: #fff;
}

.icon-btn.active {
  background: var(--teal-soft);
  border: 2px solid var(--teal);
}

.icon-btn#mic-btn.active {
  background: #ff4757 !important;
  border: 2px solid #ff6b81 !important;
  color: #fff !important;
  animation: micGlow 1s infinite alternate ease-in-out;
}

@keyframes micGlow {
  0% { transform: scale(1); box-shadow: 0 0 5px rgba(255, 71, 87, 0.5); }
  100% { transform: scale(1.18); box-shadow: 0 0 18px rgba(255, 71, 87, 0.9); }
}

.mode-btn {
  width: auto;
  border-radius: 2rem;
  padding: 0 0.75rem;
  font-size: 0.85rem;
  font-weight: 700;
  gap: 0.3rem;
}

.hud-right {
  display: flex;
  gap: 0.5rem;
}

/* Mood & XP */
.mood {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255,255,255,0.6);
  padding: 0.3rem 0.5rem;
  border-radius: 2rem;
  flex: 1;
  max-width: 150px;
  margin: 0 0.5rem;
}

.mood-face {
  font-size: 1.5rem;
}

.mood-bar {
  flex: 1;
  height: 10px;
  background: rgba(0,0,0,0.1);
  border-radius: 5px;
  overflow: hidden;
  position: relative;
}

.mood-fill {
  height: 100%;
  width: 50%; /* JS controlled */
  background: linear-gradient(90deg, var(--berry), var(--gold), var(--green));
  background-size: 200% 100%;
  border-radius: 5px;
  transition: width 0.3s ease;
  position: relative;
}

.mood-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
  animation: shine 2s infinite;
}

.xp-display {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--gold-soft);
  padding: 0.3rem 0.8rem;
  border-radius: 2rem;
  font-weight: 700;
  color: #a67c00;
  border: 1px solid var(--gold);
}

.xp-icon {
  font-size: 1.2rem;
  animation: pulse 2s infinite ease-in-out;
}

/* =========================================
   MISSION BAR
========================================= */
.mission-bar {
  background: #fff;
  padding: 0.6rem 1rem;
  box-shadow: var(--shadow-sm);
  margin: 0.5rem;
  border-radius: 0.75rem;
  animation: slideDown 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 15;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.mission-picker {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0.2rem 0;
}

.mission-picker::-webkit-scrollbar { display: none; }

.mission-level-btn {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: 2.5px solid var(--surface);
  background: #fff;
  font-weight: 700;
  font-size: 1rem;
  color: var(--ink);
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  position: relative;
}

.mission-level-btn:hover {
  transform: scale(1.1);
  border-color: var(--lila-soft);
}

.mission-level-btn.active {
  border-color: var(--lila);
  background: var(--lila-soft);
  color: var(--lila);
  transform: scale(1.1);
  box-shadow: 0 0 0 3px rgba(124, 92, 191, 0.2);
}

.mission-level-btn.completed {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green);
}

.mission-level-btn.completed::after {
  content: '✓';
  position: absolute;
  top: -4px;
  right: -4px;
  width: 14px;
  height: 14px;
  background: var(--green);
  color: #fff;
  border-radius: 50%;
  font-size: 0.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.mission-detail {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-top: 1px solid var(--surface);
  background: #faf8fd;
  border-radius: 0.6rem;
}

.mission-icon {
  font-size: 1.3rem;
  animation: pulse 2s infinite ease-in-out;
}

.mission-text {
  flex: 1;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
  line-height: 1.4;
}

.speak-btn {
  background: var(--surface);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
  flex-shrink: 0;
}

.speak-btn:hover {
  transform: scale(1.15);
  background: var(--lila-soft);
}

.speak-btn:active {
  transform: scale(0.95);
}

/* =========================================
   CANVAS AREA
========================================= */
#canvas-wrap {
  flex: 1;
  position: relative;
  margin: 0.5rem;
  border-radius: 1.5rem;
  overflow: hidden;
  background: linear-gradient(to bottom, #d4f0ff 0%, #e8f5e9 100%);
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.05);
  transition: transform 0.1s ease;
}

#canvas-wrap.shake {
  animation: screenShake 0.3s ease-in-out;
}

#scene {
  width: 100%;
  height: 100%;
  display: block;
}

/* Speech / Text Box am unteren Rand */
.speech-bubble {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(20px) scale(0.95);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 0.8rem 1.4rem;
  border-radius: 1.25rem;
  box-shadow: 0 10px 28px rgba(45, 38, 64, 0.16);
  border: 2px solid rgba(255, 255, 255, 0.9);
  width: 90%;
  max-width: 520px;
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  opacity: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  pointer-events: auto;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.speech-bubble-text {
  flex: 1;
}

.bubble-speak-btn {
  background: var(--surface);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  cursor: pointer;
  border: none;
  flex-shrink: 0;
  transition: transform 0.2s, background-color 0.2s;
}

.bubble-speak-btn:hover {
  transform: scale(1.15);
  background: var(--gold-soft);
}

@keyframes screenShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px) rotate(-0.5deg); }
  40% { transform: translateX(6px) rotate(0.5deg); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.speech-bubble.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}

.speech-bubble.hiding {
  opacity: 0;
  transform: translateX(-50%) translateY(15px) scale(0.95);
}

/* Particles */
.particles-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 10;
}

.particle {
  position: absolute;
  pointer-events: none;
}

.particle.heart { color: #ff4b72; font-size: 1.5rem; animation: floatUp 1.5s ease-out forwards; }
.particle.zzz { color: #4b8cff; font-size: 1.2rem; font-weight: bold; animation: floatUpSway 2s ease-in forwards; }
.particle.note { color: var(--lila); font-size: 1.5rem; animation: floatUpRotate 1.8s ease-out forwards; }
.particle.star { color: var(--gold); font-size: 1.5rem; animation: starPop 1s ease-out forwards; }
.particle.sparkle { color: #fff; text-shadow: 0 0 5px var(--gold); font-size: 1.2rem; animation: sparkleFlash 0.8s ease-out forwards; }

/* =========================================
   SEQUENCE BAR
========================================= */
.sequence-wrap {
  background: #251f33; /* Darker editor-like bg */
  padding: 0.45rem 0.75rem;
  border-top-left-radius: 1.25rem;
  border-top-right-radius: 1.25rem;
  box-shadow: 0 -4px 15px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  z-index: 15;
  flex-shrink: 0;
}

.sequence-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0.1rem;
}

.sequence-label {
  color: #a49bae;
  font-size: 0.78rem;
  font-weight: 700;
  font-family: monospace;
  letter-spacing: 0.5px;
}

.clear-seq-btn {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.18);
  color: #d1c8de;
  border-radius: 0.5rem;
  padding: 0.15rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.clear-seq-btn:hover, .clear-seq-btn:active {
  background: rgba(255, 71, 87, 0.3);
  color: #fff;
  border-color: #ff4757;
}

.sequence-bar {
  display: flex;
  align-items: center;
  min-height: 2.8rem;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  padding-bottom: 0.15rem;
  scrollbar-width: none; /* Firefox */
}

.sequence-bar::-webkit-scrollbar {
  display: none; /* Safari/Chrome */
}

.seq-chip {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.6rem;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
  flex-shrink: 0;
  position: relative;
  transition: all 0.2s;
}

.seq-chip svg { width: 1.25rem; height: 1.25rem; }

.seq-chip.running {
  animation: glowPulse 1s infinite alternate;
  transform: scale(1.1);
  z-index: 2;
}

.seq-connector {
  color: #6a5a87;
  font-size: 1.1rem;
  margin: 0 0.25rem;
  flex-shrink: 0;
}

.seq-empty-hint {
  color: #6a5a87;
  font-style: italic;
  font-size: 0.85rem;
  margin: auto;
}

/* =========================================
   CARD TRAY (RESPONSIVE NO-SCROLL GRID)
========================================= */
.tray-wrap {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 0.4rem 0.55rem max(0.45rem, env(safe-area-inset-bottom));
  display: flex;
  gap: 0.45rem;
  align-items: stretch;
  z-index: 15;
  flex-shrink: 0;
}

.card-tray {
  display: grid;
  flex: 1;
  gap: 0.35rem;
  padding: 0;
  overflow: visible;
}

/* Adult mode: 5 columns x 3 rows = 15 cards complete view */
.card-tray.mode-adult {
  grid-template-columns: repeat(5, 1fr);
}

/* Baby mode: 4 columns x 2 rows = 7 cards */
.card-tray.mode-baby {
  grid-template-columns: repeat(4, 1fr);
}

.card-btn {
  width: 100%;
  min-width: 0;
  height: auto;
  min-height: 2.6rem;
  padding: 0.32rem 0.1rem;
  border-radius: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  background: #fff;
  box-shadow: 0 2px 5px rgba(0,0,0,0.06);
  transition: transform 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
  opacity: 1 !important;
  visibility: visible !important;
  user-select: none;
  -webkit-user-select: none;
}

.card-btn:hover, .card-btn:active {
  transform: translateY(-2px) scale(1.03);
  box-shadow: var(--shadow-md);
}

.card-btn:disabled {
  opacity: 0.4 !important;
  cursor: not-allowed;
  transform: none;
}

.card-btn svg { width: 1.3rem; height: 1.3rem; }

.card-btn.move { background: var(--green-soft); border: 1.5px solid var(--green); }
.card-btn.care { background: var(--lila-soft); border: 1.5px solid var(--lila); }
.card-btn.bonus { background: var(--teal-soft); border: 1.5px solid var(--teal); }

.card-label {
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1.1;
}

.run-btn {
  background: linear-gradient(135deg, var(--lila), var(--berry));
  color: #fff;
  border-radius: 0.85rem;
  padding: 0.4rem 0.5rem;
  width: 3.8rem;
  min-width: 3.8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  font-weight: 800;
  box-shadow: 0 4px 14px rgba(124, 92, 191, 0.4);
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.run-btn-icon {
  font-size: 1.35rem;
  line-height: 1;
}

.run-btn-text {
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.run-btn::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 50%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  transform: skewX(-20deg);
}

.run-btn:not(:disabled)::after {
  animation: shine 3s infinite;
}

.run-btn:not(:disabled):hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(124, 92, 191, 0.6);
}

.run-btn:disabled {
  background: #ccc;
  color: #888;
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}


/* =========================================
   OVERLAYS & TOASTS
========================================= */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.overlay-card {
  background: #fff;
  border-radius: 1.5rem;
  padding: 2rem;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: bubblePop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.level-up-card {
  background: radial-gradient(circle at top, #fff, var(--gold-soft));
  border: 4px solid var(--gold);
}

.level-up-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  animation: celebrateBounce 1s infinite alternate;
}

.level-up-card h2 {
  color: var(--ink);
  margin-bottom: 0.5rem;
  font-size: 1.8rem;
}

.accessory-reveal {
  margin: 1.5rem 0;
  padding: 1rem;
  background: rgba(255,255,255,0.6);
  border-radius: 1rem;
}

.accessory-label {
  font-size: 0.9rem;
  color: var(--ink-soft);
  margin-bottom: 0.5rem;
}

.accessory-name {
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--ink);
  background: var(--gold);
  padding: 0.3rem 0.8rem;
  border-radius: 1rem;
  display: inline-block;
}

.primary-btn {
  background: var(--green);
  color: #fff;
  border-radius: 2rem;
  padding: 0.8rem 2rem;
  font-weight: 700;
  font-size: 1.1rem;
  box-shadow: 0 4px 10px rgba(77, 184, 122, 0.3);
  transition: all 0.2s;
  width: 100%;
  margin-top: 1rem;
}

.primary-btn:hover {
  transform: scale(1.05);
  background: #3da068;
}

.ghost-btn {
  background: transparent;
  color: var(--ink-soft);
  font-weight: 600;
  padding: 0.8rem 2rem;
  width: 100%;
  margin-top: 0.5rem;
}

.discovery-toast {
  position: fixed;
  bottom: calc(5rem + max(1rem, env(safe-area-inset-bottom))); /* above tray */
  left: 50%;
  transform: translateX(-50%);
  background: var(--gold-soft);
  border: 2px solid var(--gold);
  color: #a67c00;
  padding: 0.75rem 1.5rem;
  border-radius: 2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: var(--shadow-md);
  z-index: 50;
  transition: all 0.3s;
}

.discovery-toast:not([hidden]) {
  animation: toastSlideUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* Confetti */
.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 90;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 20px;
  background: #f00;
  animation: confettiFall linear forwards;
}

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

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

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

@keyframes shine {
  0% { left: -100%; }
  100% { left: 200%; }
}

@keyframes slideDown {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes bubblePop {
  0% { transform: translateX(-50%) scale(0); opacity: 0; }
  70% { transform: translateX(-50%) scale(1.1); opacity: 1; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

@keyframes bubbleHide {
  from { transform: translateX(-50%) scale(1); opacity: 1; }
  to { transform: translateX(-50%) scale(0); opacity: 0; }
}

@keyframes fadeInUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes glowPulse {
  0% { box-shadow: 0 0 5px var(--gold), 0 0 10px var(--gold); background: #fff; }
  100% { box-shadow: 0 0 15px var(--gold), 0 0 20px var(--gold); background: var(--gold-soft); }
}

@keyframes floatUp {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(-50px) scale(1.5); opacity: 0; }
}

@keyframes floatUpSway {
  0% { transform: translateY(0) translateX(0); opacity: 1; }
  50% { transform: translateY(-30px) translateX(15px); opacity: 0.8; }
  100% { transform: translateY(-60px) translateX(-10px); opacity: 0; }
}

@keyframes floatUpRotate {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(-40px) rotate(45deg); opacity: 0; }
}

@keyframes starPop {
  0% { transform: scale(0); opacity: 0; }
  50% { transform: scale(1.5); opacity: 1; }
  100% { transform: scale(1); opacity: 0; }
}

@keyframes sparkleFlash {
  0% { transform: scale(0) rotate(0); opacity: 0; }
  50% { transform: scale(1.2) rotate(180deg); opacity: 1; }
  100% { transform: scale(0) rotate(360deg); opacity: 0; }
}

@keyframes confettiFall {
  0% { transform: translateY(-10vh) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

@keyframes toastSlideUp {
  0% { transform: translate(-50%, 20px); opacity: 0; }
  100% { transform: translate(-50%, 0); opacity: 1; }
}

@keyframes celebrateBounce {
  0% { transform: scale(1) translateY(0); }
  50% { transform: scale(1.1) translateY(-10px); }
  100% { transform: scale(1) translateY(0); }
}

/* =========================================
   RESPONSIVE DESIGN
========================================= */
@media (min-width: 600px) {
  .card-tray.mode-adult {
    grid-template-columns: repeat(8, 1fr);
    gap: 0.45rem;
  }
  .card-tray.mode-baby {
    grid-template-columns: repeat(7, 1fr);
    gap: 0.45rem;
  }
  .card-btn {
    padding: 0.45rem 0.2rem;
    min-height: 3rem;
    border-radius: 0.85rem;
  }
  .card-btn svg { width: 1.5rem; height: 1.5rem; }
  .card-label { font-size: 0.7rem; }
  .run-btn {
    width: 4.8rem;
    min-width: 4.8rem;
    padding: 0.5rem 0.8rem;
    border-radius: 1rem;
  }
  .run-btn-icon { font-size: 1.6rem; }
  .run-btn-text { font-size: 0.95rem; }
}

@media (min-width: 900px) {
  #game {
    align-items: center;
  }
  
  .hud, .mission-bar, #canvas-wrap, .sequence-wrap, .tray-wrap {
    width: 100%;
    max-width: 820px;
  }
  
  #canvas-wrap {
    margin: 0.5rem auto;
    max-height: 55vh;
  }
  
  .sequence-wrap, .tray-wrap {
    border-radius: 1.5rem;
    margin-bottom: 0.5rem;
  }
}
