:root {
  --bg-app: #1b1730;
  --card-bg: #2a2450;
  --accent: #ffb347;
  --accent-2: #6fd3ff;
  --text-light: #ffffff;
  --tile-radius: 20px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-app);
  color: var(--text-light);
  height: 100vh;
  overflow: hidden;
}

#app { height: 100%; position: relative; }

.screen {
  display: none;
  height: 100%;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 20px;
}
.screen.active { display: flex; }

/* ---------- Incoming call screen ---------- */
.incoming-card {
  text-align: center;
  animation: fadeIn 0.4s ease;
}
.incoming-avatars {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 20px;
}
.incoming-avatar-circle {
  width: 60px; height: 60px;
  border-radius: 50%;
  background-color: var(--accent-2);
  background-size: cover;
  background-position: center;
  animation: bob 1.2s ease-in-out infinite;
}
.incoming-avatar-circle:nth-child(2) { animation-delay: 0.15s; }
.incoming-avatar-circle:nth-child(3) { animation-delay: 0.3s; }

.btn-primary {
  margin-top: 24px;
  padding: 14px 32px;
  font-size: 18px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #2a1a00;
  font-weight: 700;
  cursor: pointer;
}
.btn-pulse { animation: pulse 1.1s ease-in-out infinite; }

/* ---------- Call screen ---------- */
.call-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 640px;
  height: 70vh;
}

.tile {
  position: relative;
  border-radius: var(--tile-radius);
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: flex-end;
  border: 2px solid transparent;
  transition: border-color 0.3s ease;
}
.tile.active-speaker { border-color: var(--accent); }

#tile-self {
  grid-column: 2;
  grid-row: 2;
}

.tile-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  transition: filter 0.6s ease, background-color 0.6s ease;
}

.bg-kitchen { background: url('assets/bg-kitchen.jpg') center/cover no-repeat; }
.bg-park    { background: url('assets/bg-park.jpg') center/cover no-repeat; }
.bg-bedroom { background: url('assets/bg-bedroom.jpg') center/cover no-repeat; }
.bg-self    { background: linear-gradient(180deg, #3a3a5c 0%, #22203f 100%); }

.tile-label {
  position: relative;
  z-index: 2;
  padding: 8px 12px;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}

.friend-face {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  height: 82%;
  width: auto;
  max-width: 92%;
  object-fit: contain;
  z-index: 2;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.35));
}

.speech-bubble {
  position: absolute;
  top: 8%;
  left: 50%;
  transform: translateX(-50%);
  background: white;
  color: #222;
  padding: 6px 14px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.25s ease;
  z-index: 3;
  white-space: nowrap;
}
.speech-bubble.show { opacity: 1; }

/* ---------- Tile surprise animations (one plays at random after the child's turn) ---------- */
.tile-animation {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 5;
}
.tile-animation .anim-icon {
  position: absolute;
  font-size: 46px;
  opacity: 0;
  filter: drop-shadow(0 3px 6px rgba(0,0,0,0.45));
}

/* Bird (Lily): a flock flies across the tile at staggered heights/times */
.anim-bird.play .item-1 { top: 12%; animation: birdFly 1.8s ease-in-out forwards; animation-delay: 0s; }
.anim-bird.play .item-2 { top: 32%; animation: birdFly 1.8s ease-in-out forwards; animation-delay: 0.2s; }
.anim-bird.play .item-3 { top: 52%; animation: birdFly 1.8s ease-in-out forwards; animation-delay: 0.4s; }
.anim-bird.play .item-4 { top: 22%; animation: birdFly 1.8s ease-in-out forwards; animation-delay: 0.6s; }
@keyframes birdFly {
  0%   { left: -20%; opacity: 0; transform: translateY(0); }
  10%  { opacity: 1; }
  50%  { transform: translateY(-10px); }
  90%  { opacity: 1; }
  100% { left: 115%; opacity: 0; transform: translateY(0); }
}

/* Book (Tom): a stack pops up and wobbles at staggered positions/times */
.anim-book.play .item-1 { left: 18%; bottom: 12%; animation: bookPop 1.6s ease-in-out forwards; animation-delay: 0s; }
.anim-book.play .item-2 { left: 40%; bottom: 12%; animation: bookPop 1.6s ease-in-out forwards; animation-delay: 0.15s; }
.anim-book.play .item-3 { left: 62%; bottom: 12%; animation: bookPop 1.6s ease-in-out forwards; animation-delay: 0.3s; }
.anim-book.play .item-4 { left: 84%; bottom: 12%; animation: bookPop 1.6s ease-in-out forwards; animation-delay: 0.45s; }
@keyframes bookPop {
  0%   { transform: translateX(-50%) scale(0) rotate(-8deg); opacity: 0; }
  30%  { transform: translateX(-50%) scale(1.15) rotate(6deg); opacity: 1; }
  55%  { transform: translateX(-50%) scale(1) rotate(-4deg); opacity: 1; }
  80%  { transform: translateX(-50%) scale(1) rotate(0deg); opacity: 1; }
  100% { transform: translateX(-50%) scale(0.9) rotate(0deg); opacity: 0; }
}

/* Balloon (You): a bunch floats up and sways at staggered positions/times */
.anim-balloon.play .item-1 { left: 22%; animation: balloonFloat 1.9s ease-in forwards; animation-delay: 0s; }
.anim-balloon.play .item-2 { left: 42%; animation: balloonFloat 1.9s ease-in forwards; animation-delay: 0.15s; }
.anim-balloon.play .item-3 { left: 58%; animation: balloonFloat 1.9s ease-in forwards; animation-delay: 0.3s; }
.anim-balloon.play .item-4 { left: 78%; animation: balloonFloat 1.9s ease-in forwards; animation-delay: 0.45s; }
@keyframes balloonFloat {
  0%   { bottom: -10%; opacity: 0; transform: translateX(-50%) rotate(0deg); }
  15%  { opacity: 1; }
  50%  { transform: translateX(-65%) rotate(-6deg); }
  75%  { transform: translateX(-35%) rotate(6deg); }
  100% { bottom: 105%; opacity: 0; transform: translateX(-50%) rotate(0deg); }
}

/* Food (Max): a few items fall with a tumble, staggered */
.anim-food.play .item-1 { left: 18%; animation: foodFall 1.6s ease-in forwards; animation-delay: 0s; }
.anim-food.play .item-2 { left: 40%; animation: foodFall 1.6s ease-in forwards; animation-delay: 0.15s; }
.anim-food.play .item-3 { left: 62%; animation: foodFall 1.6s ease-in forwards; animation-delay: 0.3s; }
.anim-food.play .item-4 { left: 84%; animation: foodFall 1.6s ease-in forwards; animation-delay: 0.45s; }
@keyframes foodFall {
  0%   { top: -15%; opacity: 0; transform: rotate(0deg); }
  15%  { opacity: 1; }
  85%  { opacity: 1; }
  100% { top: 95%; opacity: 0; transform: rotate(180deg); }
}

/* Mic indicator: centered below the call grid, not inside a tile */
.mic-indicator {
  position: relative;
  margin-top: 20px;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.mic-indicator.hidden { display: none; }
.mic-icon {
  font-size: 34px;
  z-index: 2;
}
.mic-ring {
  position: absolute;
  top: 0;
  left: 0;
  width: 60px; height: 60px;
  border-radius: 50%;
  border: 3px solid var(--accent-2);
  animation: micPulse 1s ease-in-out infinite;
}

/* ---------- Effects ---------- */
.effect-confetti-pop {
  animation: confettiFlash 0.8s ease;
}
.effect-warm-fade-wave {
  animation: warmFade 1.2s ease;
}

@keyframes confettiFlash {
  0%   { filter: brightness(1); }
  30%  { filter: brightness(1.6) saturate(1.5); }
  100% { filter: brightness(1); }
}
@keyframes warmFade {
  0%   { filter: brightness(1); }
  50%  { filter: brightness(0.7) saturate(0.8); }
  100% { filter: brightness(0.85); }
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
@keyframes micPulse {
  0% { transform: scale(0.9); opacity: 0.9; }
  70% { transform: scale(1.4); opacity: 0; }
  100% { transform: scale(0.9); opacity: 0; }
}
@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}

/* ---------- Giggle Messages screen ---------- */
.messages-chat {
  width: 100%;
  max-width: 480px;
  height: 85vh;
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border-radius: var(--tile-radius);
  overflow: hidden;
}
.messages-header {
  padding: 16px;
  text-align: center;
  font-weight: 700;
  background: rgba(255,255,255,0.06);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.messages-thread {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Shared focus overlay used by every opened photo card */
.card-focus-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 20;
  cursor: pointer;
}
.card-focus-overlay.show {
  opacity: 1;
  pointer-events: auto;
}
.card-focus {
  position: relative;
  width: 260px;
  height: 260px;
  border-radius: 20px;
  overflow: hidden;
  transform: scale(0.85);
  transition: transform 0.25s ease;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.card-focus-overlay.show .card-focus {
  transform: scale(1);
}
.card-focus-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
}
.card-focus-avatar {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  height: 82%;
  width: auto;
  max-width: 92%;
  object-fit: contain;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.35));
}
.card-focus-word {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.92);
  color: #222;
  font-weight: 700;
  font-size: 20px;
  padding: 6px 18px;
  border-radius: 999px;
}

/* ---------- Chat messages, typing indicator, photo cards ---------- */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 80%;
}
.msg-row-sent {
  width: 100%;
  max-width: 100%;
  justify-content: flex-end;
}
.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-size: cover;
  background-position: center top;
  flex-shrink: 0;
}
.msg-bubble {
  background: rgba(255,255,255,0.12);
  color: var(--text-light);
  padding: 8px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.3;
}
.messages-call-btn {
  margin-top: 20px;
}
.messages-call-btn.hidden {
  display: none;
}

.msg-typing-bubble {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 10px 14px;
}
.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.6);
  animation: typingBounce 0.9s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.msg-card {
  width: 120px;
  height: 80px;
  border-radius: 12px;
  background-size: cover;
  background-position: center;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.msg-card-pending {
  animation: cardInvite 1.4s ease-in-out infinite;
}
@keyframes cardInvite {
  0%, 100% { box-shadow: 0 2px 8px rgba(0,0,0,0.3), 0 0 0 0 rgba(255,179,71,0.6); transform: scale(1); }
  50%      { box-shadow: 0 2px 8px rgba(0,0,0,0.3), 0 0 0 8px rgba(255,179,71,0); transform: scale(1.04); }
}
