/* ============================================
   CSS Custom Properties (Design Tokens)
   ============================================ */
:root {
  --color-bg: #FFF8E7;
  --color-primary: #FF6B6B;
  --color-success: #51CF66;
  --color-slot-border: #DDD;
  --piece-size: min(35vw, 200px);
  --snap-duration: 0.2s;
  --border-radius: 12px;
}

/* ============================================
   CSS Reset
   ============================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

img, svg {
  display: block;
  max-width: 100%;
}

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

ul, ol {
  list-style: none;
}

/* ============================================
   Base Styles
   ============================================ */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--color-bg);
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

/* ============================================
   Screen Management
   ============================================ */
.screen {
  display: none;
  width: 100%;
  height: 100%;
}

/* Screen transitions: fade in when shown */
.screen--entering {
  animation: screen-fade-in 0.35s ease-out both;
}

/* ============================================
   Landing Screen
   ============================================ */
#landing-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 24px 16px;
  overflow-y: auto;
}

.landing-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  width: 100%;
  max-width: 600px;
  padding: 8px;
}

.landing-card {
  aspect-ratio: 1;
  min-width: 120px;
  min-height: 120px;
  background: #fff;
  border-radius: var(--border-radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  padding: 12px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  /* Remove entrance animation - was causing cards to disappear */
  opacity: 1;
}

.landing-card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.landing-card:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.landing-card:active {
  transform: scale(0.95);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

/* Subtle continuous pulse on landing cards - pure CSS */
@keyframes card-pulse {
  0%, 100% {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
  50% {
    box-shadow: 0 4px 20px rgba(255, 107, 107, 0.2);
  }
}

#landing-screen .landing-card {
  animation: card-pulse 3s ease-in-out infinite;
  animation-delay: 2s; /* Start pulsing after initial load */
}

/* ============================================
   Puzzle Screen
   ============================================ */
#puzzle-screen {
  flex-direction: column;
  align-items: center;
  min-height: 100%;
  padding: 16px;
  overflow-y: auto;
  gap: 24px;
}

.puzzle-header {
  width: 100%;
  max-width: 600px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.back-button {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: var(--color-primary);
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.back-button:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}

.back-button:active {
  transform: scale(0.85);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(2, var(--piece-size));
  grid-template-rows: repeat(2, var(--piece-size));
  gap: 4px;
}

.piece-tray {
  display: grid;
  grid-template-columns: repeat(4, var(--piece-size));
  gap: 12px;
  justify-content: center;
  padding: 12px;
}

/* ============================================
   Celebration Overlay
   ============================================ */
#celebration-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.55);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  animation: overlay-fade-in 0.3s ease-out both;
  overflow: hidden;
}

.celebration-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  background: #fff;
  border-radius: 24px;
  padding: 32px 28px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  max-width: 360px;
  width: 90%;
  text-align: center;
  animation: celebration-pop-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s both;
  z-index: 2001;
}

.celebration-heading {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--color-primary);
  line-height: 1.2;
  animation: bounce-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s both,
             celebration-heading-wiggle 1.2s ease-in-out 1s infinite;
}

.celebration-stars {
  font-size: 2rem;
  letter-spacing: 8px;
  animation: star-burst 0.6s ease-out 0.4s both;
}

.celebration-preview {
  width: 160px;
  height: 160px;
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.celebration-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.celebration-buttons {
  display: flex;
  gap: 16px;
  width: 100%;
  justify-content: center;
  flex-wrap: wrap;
}

.celebration-btn {
  padding: 16px 28px;
  border-radius: 16px;
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  border: none;
  cursor: pointer;
  min-width: 130px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.celebration-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.celebration-btn:active {
  transform: scale(0.9);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.celebration-btn--again {
  background: var(--color-success);
}

.celebration-btn--new {
  background: var(--color-primary);
}

/* Confetti particles */
.confetti-particle {
  position: fixed;
  top: -20px;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  z-index: 2002;
  pointer-events: none;
  animation: confetti-fall linear both, confetti-sway ease-in-out infinite both;
}

/* Sparkle/star particles for celebration */
.sparkle-particle {
  position: fixed;
  z-index: 2002;
  pointer-events: none;
  font-size: 1.5rem;
  animation: sparkle-float ease-out both;
}

/* ============================================
   Piece States
   ============================================ */
.piece {
  width: var(--piece-size);
  height: var(--piece-size);
  border-radius: var(--border-radius);
  background-size: 200% 200%;
  background-repeat: no-repeat;
  cursor: grab;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15);
  transition: transform var(--snap-duration) ease;
  /* Prevent double-tap zoom on pieces while maintaining drag */
  touch-action: none;
}

.piece--dragging {
  cursor: grabbing;
  transform: scale(1.1);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  will-change: transform;
  transition: none;
}

.piece--placed {
  cursor: default;
  pointer-events: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  transition: transform var(--snap-duration) ease;
}

/* Bounce effect when piece snaps correctly */
.piece--snap-bounce {
  animation: piece-bounce 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* Green glow after correct placement */
.piece--glow {
  animation: piece-glow 0.6s ease-out both;
}

/* Shake effect when piece is dropped on wrong slot */
.piece--shake {
  animation: shake 0.4s ease both;
}

/* ============================================
   Slot States
   ============================================ */
.slot {
  width: var(--piece-size);
  height: var(--piece-size);
  border: 3px dashed var(--color-slot-border);
  border-radius: var(--border-radius);
  background: rgba(255, 255, 255, 0.4);
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  position: relative;
}

.slot--filled {
  border-color: var(--color-success);
  border-style: solid;
  background: rgba(81, 207, 102, 0.1);
}

.slot--highlight {
  border-color: var(--color-primary);
  border-style: solid;
  background: rgba(255, 107, 107, 0.15);
  box-shadow: 0 0 12px rgba(255, 107, 107, 0.35);
}

/* ============================================
   Animations (@keyframes)
   ============================================ */

/* Screen fade in */
@keyframes screen-fade-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Landing card staggered entrance */
@keyframes card-entrance {
  from {
    opacity: 0;
    transform: scale(0.85) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Wrong placement shake */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-8px) rotate(-2deg); }
  30% { transform: translateX(8px) rotate(2deg); }
  45% { transform: translateX(-6px) rotate(-1deg); }
  60% { transform: translateX(6px) rotate(1deg); }
  75% { transform: translateX(-3px); }
  90% { transform: translateX(3px); }
}

/* Correct placement bounce */
@keyframes bounce-in {
  from {
    opacity: 0;
    transform: scale(0.3);
  }
  50% {
    opacity: 1;
    transform: scale(1.08);
  }
  70% {
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Piece bounce after snap */
@keyframes piece-bounce {
  0% { transform: scale(1); }
  30% { transform: scale(1.12); }
  60% { transform: scale(0.95); }
  80% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

/* Confetti falling */
@keyframes confetti-fall {
  0% {
    transform: translateY(0) rotate(0deg) scale(1);
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  100% {
    transform: translateY(105vh) rotate(var(--confetti-rotate, 720deg)) scale(0.4);
    opacity: 0;
  }
}

/* Confetti horizontal sway */
@keyframes confetti-sway {
  0%, 100% { margin-left: 0; }
  50% { margin-left: 30px; }
}

/* Star burst on celebration */
@keyframes star-burst {
  from {
    opacity: 0;
    transform: scale(0) rotate(-30deg);
  }
  50% {
    opacity: 1;
    transform: scale(1.3) rotate(10deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

/* Gentle pulse for landing page cards (attract attention) */
@keyframes pulse {
  0%, 100% {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
  50% {
    box-shadow: 0 4px 20px rgba(255, 107, 107, 0.25);
  }
}

/* Celebration overlay fade in */
@keyframes overlay-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Celebration content pop-in */
@keyframes celebration-pop-in {
  from {
    opacity: 0;
    transform: scale(0.5) translateY(30px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Celebration heading continuous gentle wiggle */
@keyframes celebration-heading-wiggle {
  0%, 100% { transform: rotate(0deg) scale(1); }
  25% { transform: rotate(-3deg) scale(1.02); }
  75% { transform: rotate(3deg) scale(1.02); }
}

/* Sparkle float up and fade */
@keyframes sparkle-float {
  0% {
    transform: translateY(0) scale(0) rotate(0deg);
    opacity: 0;
  }
  15% {
    transform: translateY(-20px) scale(1.2) rotate(30deg);
    opacity: 1;
  }
  50% {
    opacity: 1;
  }
  100% {
    transform: translateY(var(--sparkle-travel, -180px)) scale(0.3) rotate(var(--sparkle-rotate, 180deg));
    opacity: 0;
  }
}

/* Piece glow pulse when correctly placed */
@keyframes piece-glow {
  0% { box-shadow: 0 0 0 0 rgba(81, 207, 102, 0.5); }
  50% { box-shadow: 0 0 15px 5px rgba(81, 207, 102, 0.4); }
  100% { box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1); }
}

/* ============================================
   Responsive Breakpoints
   ============================================ */

/* Mobile: piece tray as 2x2 mini-grid */
@media (max-width: 479px) {
  .piece-tray {
    grid-template-columns: repeat(2, var(--piece-size));
    gap: 8px;
  }

  /* Phone: puzzle grid 70% width */
  .puzzle-grid {
    width: 70%;
    min-width: 240px;
  }

  /* Smaller celebration on phone */
  .celebration-content {
    padding: 24px 20px;
  }

  .celebration-heading {
    font-size: 1.8rem;
  }

  .celebration-preview {
    width: 130px;
    height: 130px;
  }

  .celebration-btn {
    padding: 14px 20px;
    font-size: 1rem;
    min-width: 110px;
  }

  /* Smaller landing cards on phone */
  .landing-card {
    min-width: 100px;
    min-height: 100px;
    padding: 10px;
  }

  /* Adjust padding on puzzle screen for phones */
  #puzzle-screen {
    padding: 12px;
    gap: 16px;
  }
}

@media (min-width: 480px) {
  .landing-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
  }

  /* Small tablet: puzzle grid 60% width */
  .puzzle-grid {
    width: 60%;
    max-width: 360px;
  }

  .piece-tray {
    grid-template-columns: repeat(4, var(--piece-size));
    gap: 16px;
  }

  /* Larger landing cards on tablet */
  .landing-card {
    min-width: 140px;
    min-height: 140px;
    padding: 16px;
  }
}

@media (min-width: 768px) {
  .landing-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
    max-width: 720px;
  }

  /* Larger tablet / desktop: puzzle grid 50% width */
  .puzzle-grid {
    width: 50%;
    max-width: 400px;
  }

  .piece-tray {
    grid-template-columns: repeat(4, var(--piece-size));
  }

  /* Larger celebration content on desktop */
  .celebration-content {
    max-width: 420px;
    padding: 40px 36px;
  }

  .celebration-heading {
    font-size: 2.6rem;
  }

  .celebration-preview {
    width: 180px;
    height: 180px;
  }
}

/* Additional responsive styles added in T9 */
