/* ═══════════════════════════════════════════════════════
   AI Friends — Style
   Ages 5–8 · Mobile-first · WCAG 2.1 AA
   Bright, bouncy and celebratory, while staying in the same
   Sparky / tone() / mute family as the rest of the Academy games.
════════════════════════════════════════════════════════ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Sky — bright and cheerful */
  --sky-a:        #79d7ff;
  --sky-b:        #a7f0e0;
  --sky-c:        #fff0b8;

  /* Bins */
  --animals:       #43a047;
  --animals-light: #66bb6a;
  --animals-dark:  #1b5e20;
  --animals-glow:  rgba(67,160,71,0.45);
  --vehicles:      #fb8c00;
  --vehicles-light:#ffb74d;
  --vehicles-dark: #bf360c;
  --vehicles-glow: rgba(251,140,0,0.45);
  --food:          #e91e63;
  --food-light:    #f06292;
  --food-dark:     #880e4f;
  --food-glow:     rgba(233,30,99,0.45);

  /* Sparky */
  --sparky-body:  #64b5f6;
  --sparky-deep:  #0d47a1;
  --sparky-gold:  #ffd54f;

  /* UI */
  --white:        #ffffff;
  --text:         #0d2440;
  --text-soft:    #37474f;
  --shadow-sm:    0 4px 16px rgba(0,0,0,0.14);
  --shadow-md:    0 10px 32px rgba(0,0,0,0.20);
  --shadow-lg:    0 18px 48px rgba(0,0,0,0.26);
  --radius-card:  30px;
  --radius-bin:   22px;
  --radius-pill:  50px;
}

/* ─── BASE ─────────────────────────────────────────── */

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: linear-gradient(165deg, var(--sky-a) 0%, var(--sky-b) 48%, var(--sky-c) 100%);
  background-attachment: fixed;
  overflow: hidden;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ─── Sky decor (clouds, sun, rainbow) ─────────────── */

.sky-decor {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.sky-decor span {
  position: absolute;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,0.08));
}

.sun {
  top: 4%;
  right: 6%;
  font-size: clamp(3rem, 10vw, 5.5rem);
  animation: sunSpin 24s linear infinite;
}

.cloud {
  font-size: clamp(2.4rem, 8vw, 4rem);
  opacity: 0.9;
}

.cloud-1 { top: 14%; left: -4%; animation: cloudDrift 26s ease-in-out infinite alternate; }
.cloud-2 { top: 38%; right: -6%; animation: cloudDrift 32s ease-in-out infinite alternate-reverse; }

.rainbow {
  bottom: -3%;
  left: 4%;
  font-size: clamp(3.4rem, 12vw, 6rem);
  opacity: 0.55;
  transform: rotate(-8deg);
  animation: rainbowBob 5s ease-in-out infinite;
}

/* ─── SCREENS ───────────────────────────────────────── */

.screen {
  display: none;
  position: fixed;
  inset: 0;
  flex-direction: column;
  z-index: 1;
}

.screen.active { display: flex; }

/* ═══════════════════════════════════════════════════════
   START SCREEN
════════════════════════════════════════════════════════ */

#start-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.start-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  max-width: 440px;
  width: 100%;
  background: rgba(255,255,255,0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 3px solid rgba(255,255,255,0.9);
  border-radius: 40px;
  padding: 30px 24px 26px;
  box-shadow: var(--shadow-md);
}

.start-inner h1 {
  font-size: clamp(2.5rem, 9vw, 3.8rem);
  font-weight: 900;
  color: var(--sparky-deep);
  letter-spacing: -0.02em;
  text-shadow: 0 3px 0 rgba(255, 213, 79, 0.8), 0 6px 18px rgba(21,101,192,0.25);
}

.start-tagline {
  font-size: clamp(1.15rem, 4.4vw, 1.45rem);
  color: var(--text);
  font-weight: 700;
}

.start-learn-line {
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-soft);
  background: #fff8e1;
  border: 2px dashed #f9a825;
  border-radius: 16px;
  padding: 10px 14px;
  max-width: 34ch;
}

.start-how {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.how-item {
  background: var(--white);
  border-radius: var(--radius-pill);
  padding: 9px 18px;
  font-size: 1rem;
  font-weight: 800;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 7px;
  border-bottom: 4px solid transparent;
}

.how-item:nth-child(1) { color: var(--animals-dark); border-color: var(--animals); background: #e8f5e9; }
.how-item:nth-child(2) { color: var(--vehicles-dark); border-color: var(--vehicles); background: #fff3e0; }
.how-item:nth-child(3) { color: var(--food-dark);    border-color: var(--food);    background: #fce4ec; }

.how-item span { font-size: 1.4rem; }

.start-hint {
  font-size: 0.9rem;
  color: var(--text-soft);
  opacity: 0.85;
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════════
   GAME HEADER
════════════════════════════════════════════════════════ */

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(255,255,255,0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 3px solid rgba(255,255,255,0.95);
  flex-shrink: 0;
  gap: 8px;
}

.round-pill {
  background: linear-gradient(180deg, #1e88e5, var(--sparky-deep));
  color: var(--white);
  border-radius: var(--radius-pill);
  padding: 6px 15px;
  font-size: 0.95rem;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(21,101,192,0.35);
}

.round-of { font-weight: 400; opacity: 0.85; }

.star-pill {
  background: linear-gradient(180deg, #fff9c4, #ffecb3);
  border: 2px solid #ffd54f;
  color: #e65100;
  border-radius: var(--radius-pill);
  padding: 6px 15px;
  font-size: 0.95rem;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(255,183,77,0.35);
}

/* Progress dots */
.progress-dots {
  display: flex;
  gap: 6px;
  flex: 1;
  justify-content: center;
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: rgba(13,71,161,0.18);
  border: 2px solid rgba(13,71,161,0.30);
  transition: background 0.3s ease, border-color 0.3s ease, transform 0.2s ease;
}

.dot.done      { background: var(--animals); border-color: var(--animals-dark); }
.dot.active    { background: var(--sparky-deep); border-color: var(--sparky-deep); transform: scale(1.35); }
.dot.correct   { background: var(--animals-light); border-color: var(--animals-dark); }
.dot.wrong-try { background: var(--vehicles); border-color: var(--vehicles-dark); }

/* ═══════════════════════════════════════════════════════
   SPARKY ROW + "Sparky noticed" chip
════════════════════════════════════════════════════════ */

.sparky-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px 6px;
  flex-shrink: 0;
}

#sparky-game svg  { width: 74px;  height: auto; filter: drop-shadow(0 5px 10px rgba(13,71,161,0.25)); }
#sparky-start svg { width: 132px; height: auto; }
#sparky-round svg { width: 92px;  height: auto; }
#sparky-complete svg { width: 122px; height: auto; }

.sparky-hero { animation: bounce 1.4s ease-in-out infinite; }

.speech-bubble {
  position: relative;
  background: var(--white);
  border: 3px solid #e3f2fd;
  border-radius: 20px;
  padding: 10px 18px;
  font-size: clamp(0.95rem, 3.5vw, 1.15rem);
  font-weight: 700;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  max-width: calc(100vw - 130px);
}

.speech-bubble::before {
  content: '';
  position: absolute;
  left: -11px;
  top: 50%;
  transform: translateY(-50%);
  border: 10px solid transparent;
  border-right-color: #e3f2fd;
  border-left: 0;
}

.feature-chip {
  margin: 6px auto 2px;
  max-width: min(92vw, 420px);
  background: #fff8e1;
  border: 2px dashed #f9a825;
  color: #7a4f01;
  border-radius: var(--radius-pill);
  padding: 7px 16px;
  font-size: clamp(0.88rem, 3.4vw, 1.05rem);
  font-weight: 800;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

/* ═══════════════════════════════════════════════════════
   ITEM AREA
════════════════════════════════════════════════════════ */

.item-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.item-card {
  position: relative;
  background: var(--white);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: grab;
  user-select: none;
  touch-action: none;
  border: 4px solid rgba(255,255,255,0.98);
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.2s ease;
  /* Responsive size */
  width:  min(190px, 48vw);
  height: min(190px, 48vw);
}

/* Rainbow strip along the top of the card */
.item-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 12px;
  background: linear-gradient(90deg, #ef5350, #ffb74d, #ffee58, #66bb6a, #42a5f5, #ab47bc);
}

.item-card:hover:not(.is-dragging) {
  transform: scale(1.05) rotate(-1.5deg);
  box-shadow: var(--shadow-lg);
}

.item-card:focus-visible {
  outline: 4px solid var(--sparky-deep);
  outline-offset: 5px;
}

.item-card.is-dragging {
  opacity: 0.25;
  cursor: grabbing;
}

.item-emoji {
  font-size: min(5.8rem, 24vw);
  line-height: 1;
  pointer-events: none;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.12));
}

.item-name {
  font-size: clamp(1.05rem, 4.2vw, 1.35rem);
  font-weight: 800;
  color: var(--text);
  pointer-events: none;
}

/* Drag ghost (clone following cursor/finger) */
#drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  transition: none;
  transform-origin: center center;
}

/* ═══════════════════════════════════════════════════════
   BINS
════════════════════════════════════════════════════════ */

.bins-area {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 12px 14px 18px;
  background: rgba(255,255,255,0.62);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 3px solid rgba(255,255,255,0.9);
  flex-shrink: 0;
}

.bin {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 92px;
  padding: 10px 6px;
  border: none;
  border-bottom: 6px solid rgba(0,0,0,0.18);
  border-radius: var(--radius-bin);
  cursor: pointer;
  font-family: inherit;
  color: var(--white);
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  position: relative;
  overflow: hidden;
}

.bin-animals  { background: linear-gradient(180deg, var(--animals-light), var(--animals)); }
.bin-vehicles { background: linear-gradient(180deg, var(--vehicles-light), var(--vehicles)); }
.bin-food     { background: linear-gradient(180deg, var(--food-light), var(--food)); }

.bin::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0);
  transition: background 0.15s ease;
  border-radius: inherit;
  pointer-events: none;
}

.bin:hover:not(:disabled),
.bin:focus-visible {
  transform: translateY(-5px) scale(1.05);
  box-shadow: 0 12px 30px rgba(0,0,0,0.24);
}

.bin:focus-visible { outline: 4px solid var(--white); outline-offset: 3px; }

.bin.drag-over {
  transform: translateY(-7px) scale(1.08);
  box-shadow: 0 16px 38px rgba(0,0,0,0.30);
  filter: brightness(1.12);
}

.bin-icon  { font-size: clamp(1.7rem, 6.5vw, 2.4rem); filter: drop-shadow(0 3px 4px rgba(0,0,0,0.18)); }
.bin-label { font-size: clamp(0.82rem, 3.4vw, 1.05rem); font-weight: 800; text-shadow: 0 2px 3px rgba(0,0,0,0.2); }

/* ═══════════════════════════════════════════════════════
   OVERLAYS
════════════════════════════════════════════════════════ */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 24, 51, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.overlay.hidden { display: none; }

.overlay-card {
  background:
    linear-gradient(#ffffff, #ffffff) padding-box,
    linear-gradient(135deg, #ffd54f, #64b5f6, #f06292) border-box;
  border: 5px solid transparent;
  border-radius: 36px;
  padding: 34px 28px 30px;
  text-align: center;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 26px 70px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 13px;
  position: relative;
  z-index: 1;
  animation: popIn 0.38s cubic-bezier(0.34,1.56,0.64,1) forwards;
}

.overlay-card h2 {
  font-size: clamp(1.7rem, 6.5vw, 2.2rem);
  font-weight: 900;
  color: var(--sparky-deep);
}

.overlay-card p {
  font-size: clamp(1rem, 3.6vw, 1.15rem);
  color: var(--text-soft);
  font-weight: 600;
}

.trophy {
  font-size: 3.2rem;
  line-height: 1;
  animation: trophyBounce 1.2s ease-in-out infinite;
  filter: drop-shadow(0 6px 12px rgba(255,193,7,0.55));
}

.trophy.large { font-size: 4rem; }

.round-praise {
  background: #e8f5e9;
  border-radius: 999px;
  padding: 7px 16px;
  color: #1b5e20 !important;
  font-size: 0.95rem !important;
}

.learn-box {
  background: linear-gradient(180deg, #e3f2fd, #e8eaf6);
  border-radius: 18px;
  padding: 14px 18px;
  border: 2px solid #bbdefb;
}

.learn-box p {
  font-size: clamp(0.92rem, 3.4vw, 1.02rem);
  color: #0d47a1;
  font-style: italic;
  line-height: 1.55;
  font-weight: 700;
}

/* ─── Stars ─────────────────────────────────────────── */

.stars-row {
  font-size: 2.2rem;
  letter-spacing: 6px;
  line-height: 1;
  text-shadow: 0 3px 6px rgba(255,193,7,0.5);
}

.stars-row.large { font-size: 3rem; }

/* ─── Confetti ───────────────────────────────────────── */

#confetti-stage {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.confetti-bit {
  position: absolute;
  top: -20px;
  border-radius: 3px;
  animation: confettiFall linear forwards;
}

/* In-game burst stage (sits above screens, below the mute button) */
#burst-stage {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 8500;
  overflow: hidden;
}

.burst-bit {
  position: absolute;
  border-radius: 3px;
  animation: burstFly ease-out forwards;
}

/* ═══════════════════════════════════════════════════════
   BUTTONS
════════════════════════════════════════════════════════ */

.btn-primary {
  background: linear-gradient(180deg, #42a5f5, var(--sparky-deep));
  color: var(--white);
  border: none;
  border-bottom: 5px solid #0a3d91;
  border-radius: var(--radius-pill);
  padding: 14px 40px;
  font-size: clamp(1.05rem, 4vw, 1.25rem);
  font-weight: 900;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(21,101,192,0.45);
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
  min-height: 54px;
}

.btn-primary:hover {
  background: linear-gradient(180deg, #64b5f6, #1565c0);
  transform: translateY(-3px);
  box-shadow: 0 12px 30px rgba(21,101,192,0.55);
}

.btn-primary:active { transform: translateY(0); border-bottom-width: 3px; }

.btn-primary:focus-visible {
  outline: 4px solid var(--sparky-gold);
  outline-offset: 4px;
}

/* ─── Mute button (text, like the other games) ──────── */

.mute-btn {
  position: fixed;
  top: 12px;
  right: 14px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  border: 2px solid rgba(13,71,161,0.18);
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--sparky-deep);
  cursor: pointer;
  z-index: 9000;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, background 0.12s ease;
  white-space: nowrap;
}

.mute-btn:hover { transform: scale(1.08); background: #fff; }
.mute-btn:focus-visible { outline: 3px solid var(--sparky-gold); outline-offset: 3px; }

/* ═══════════════════════════════════════════════════════
   ANIMATIONS
════════════════════════════════════════════════════════ */

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

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

@keyframes cloudDrift {
  from { transform: translateX(0); }
  to   { transform: translateX(46px); }
}

@keyframes rainbowBob {
  0%, 100% { transform: rotate(-8deg) translateY(0); }
  50%      { transform: rotate(-8deg) translateY(-10px); }
}

@keyframes popIn {
  0%   { transform: scale(0.6); opacity: 0; }
  70%  { transform: scale(1.06); }
  100% { transform: scale(1);   opacity: 1; }
}

@keyframes trophyBounce {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-8px) scale(1.08); }
}

@keyframes cardIn {
  0%   { transform: scale(0.5) rotate(-8deg); opacity: 0; }
  70%  { transform: scale(1.06) rotate(2deg); }
  100% { transform: scale(1) rotate(0deg);   opacity: 1; }
}

@keyframes cardCorrect {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.18) rotate(6deg); }
  60%  { transform: scale(0.9) rotate(-3deg); }
  100% { transform: scale(0) rotate(12deg); opacity: 0; }
}

@keyframes cardShake {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  15%       { transform: translateX(-14px) rotate(-5deg); }
  35%       { transform: translateX(14px)  rotate(5deg); }
  55%       { transform: translateX(-8px)  rotate(-3deg); }
  75%       { transform: translateX(6px)   rotate(2deg); }
}

@keyframes binPulse {
  0%   { transform: translateY(0) scale(1); }
  40%  { transform: translateY(-8px) scale(1.1); }
  70%  { transform: translateY(-4px) scale(1.04); }
  100% { transform: translateY(0) scale(1); }
}

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

@keyframes burstFly {
  0%   { transform: translate(0, 0) scale(1);   opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0.4); opacity: 0; }
}

@keyframes speechPop {
  0%   { transform: scale(0.8); opacity: 0; }
  60%  { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes featurePop {
  0%   { transform: scale(0.7) rotate(-2deg); opacity: 0; }
  60%  { transform: scale(1.06) rotate(1deg); }
  100% { transform: scale(1) rotate(0deg);   opacity: 1; }
}

/* Utility classes applied via JS */
.animate-card-in      { animation: cardIn      0.38s cubic-bezier(0.34,1.56,0.64,1) forwards; }
.animate-card-correct { animation: cardCorrect 0.52s ease forwards; }
.animate-card-shake   { animation: cardShake   0.45s ease forwards; }
.animate-bin-pulse    { animation: binPulse    0.4s ease; }
.animate-speech       { animation: speechPop   0.25s ease forwards; }
.animate-feature      { animation: featurePop  0.3s cubic-bezier(0.34,1.56,0.64,1) forwards; }

.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════
   RESPONSIVE OVERRIDES
════════════════════════════════════════════════════════ */

@media (max-width: 380px) {
  .bin { min-height: 76px; }
  .bin-icon  { font-size: 1.5rem; }
  .bin-label { font-size: 0.76rem; }
  .bins-area { gap: 7px; padding: 10px 10px 16px; }
  .mute-btn  { top: 8px; right: 8px; padding: 6px 10px; font-size: 0.74rem; }
}

@media (min-width: 600px) {
  .item-card { width: 230px; height: 230px; }
  .bin { min-height: 108px; padding: 14px 10px; }
  .bin-icon  { font-size: 2.6rem; }
  .bin-label { font-size: 1.1rem; }
  .bins-area { gap: 18px; padding: 18px 28px 24px; }
  .game-header { padding: 12px 26px; }
}

@media (min-width: 900px) {
  /* On wide screens, keep the playful three-row layout stable */
  #game-screen.active { display: grid; grid-template-rows: auto 1fr auto; }
  .sparky-row { padding: 18px 36px 8px; }
  .item-area  { padding: 18px; }
  .bins-area  { padding: 22px 40px 30px; }
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
