/* Shape Sorter — Modernized Styles
   Tactile Wooden Toybox Aesthetic for Toddlers & Young Children (Ages 2-4)
*/

:root {
  --board-bg: #F8F3EA;
  --board-border: #E8DCCF;
  --board-shadow: rgba(80, 50, 30, 0.08);
  --tray-bg: #FFFFFF;
  --tray-border: #EFE8DE;
  --slot-bg: rgba(226, 216, 203, 0.65);
  --slot-border: rgba(160, 140, 120, 0.45);
  --wood-accent: #C49A6C;
  --snap-glow: #FF7B89;
  --card-radius: 20px;
}

/* Container */
.shape-sorter {
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: radial-gradient(circle at 50% 20%, #FFFDF9 0%, #F5EFEB 100%);
  overflow: hidden;
  padding-top: var(--header-h, 96px);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* Controls & Title Bar */
.ss-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 20px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  gap: 12px;
  flex-shrink: 0;
}

.ss-title-box {
  display: flex;
  flex-direction: column;
}

.ss-game-title {
  font-family: var(--font-display, 'Space Grotesk', sans-serif);
  font-size: clamp(1.4rem, 3.8vw, 2.1rem);
  font-weight: 800;
  color: var(--coral, #FF7B89);
  line-height: 1.1;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ss-game-title .ss-icon-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  animation: gentleBounce 2.5s ease-in-out infinite;
}

.ss-game-subtitle {
  font-size: clamp(0.78rem, 1.8vw, 0.95rem);
  color: var(--text-muted, #64748B);
  font-weight: 500;
  margin: 2px 0 0 0;
}

/* Action Controls (Sound, Voice, Reset) */
.ss-controls-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ss-pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1.5px solid #E2E8F0;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 2px 6px var(--shadow, rgba(15, 23, 42, 0.06));
  font-size: 0.82rem;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  touch-action: manipulation;
  min-height: 36px;
}

.ss-pill-btn:hover {
  background: #F8FAFC;
  border-color: #CBD5E1;
  transform: translateY(-1px);
}

.ss-pill-btn:active {
  transform: scale(0.94);
}

.ss-pill-btn.muted {
  opacity: 0.55;
  background: #F1F5F9;
  border-color: #E2E8F0;
}

/* Play Arena */
.ss-play-arena {
  flex: 1;
  display: flex;
  padding: 10px 20px;
  gap: 20px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  min-height: 0;
  position: relative;
  align-items: stretch;
}

/* Boards (Tray and Silhouette Board) */
.ss-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-radius: var(--card-radius);
  position: relative;
  padding: 14px 18px;
  box-shadow: 0 8px 24px var(--board-shadow);
  border: 2px solid var(--board-border);
  min-height: 0;
  overflow: hidden;
}

/* Tray on left / bottom */
.ss-panel-tray {
  background: var(--tray-bg);
  border-color: var(--tray-border);
}

/* Silhouette Puzzle Board on right / top */
.ss-panel-board {
  background: var(--board-bg);
  border-color: var(--board-border);
  box-shadow: 0 10px 28px rgba(90, 60, 40, 0.09), inset 0 2px 6px rgba(255, 255, 255, 0.7);
}

.ss-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.ss-panel-title {
  font-family: var(--font-display, 'Space Grotesk', sans-serif);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--wood-accent);
  display: flex;
  align-items: center;
  gap: 6px;
}

.ss-panel-hint {
  font-size: 0.75rem;
  color: #94A3B8;
  font-weight: 500;
}

/* Item Grids */
.ss-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  align-content: center;
  justify-content: center;
  justify-items: center;
  align-items: center;
  gap: 16px;
  position: relative;
  overflow: visible;
  padding: 6px;
}

/* Tray Bay (recessed socket where shape rests) */
.ss-bay {
  width: 92px;
  height: 92px;
  border-radius: 18px;
  background: rgba(246, 243, 238, 0.7);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.05);
  border: 2px dashed rgba(200, 190, 175, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.25s ease;
}

/* Draggable / Tappable Shapes */
.ss-shape {
  width: 86px;
  height: 86px;
  border-radius: 18px;
  cursor: grab;
  touch-action: none;
  background: #FFFFFF;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  transition: transform 0.2s cubic-bezier(0.17, 0.67, 0.29, 1.2), box-shadow 0.2s ease, filter 0.2s ease;
  position: relative;
  z-index: 10;
  user-select: none;
  -webkit-user-select: none;
}

.ss-shape:hover {
  transform: scale(1.06) translateY(-3px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.14);
}

.ss-shape:active, .ss-shape.grabbing {
  cursor: grabbing;
}

/* Breathing idle animation */
.ss-shape.idle-breath {
  animation: gentleBreathe 3s ease-in-out infinite;
}

/* Active Dragging */
.ss-shape.dragging {
  position: fixed !important;
  z-index: 9999 !important;
  opacity: 0.95;
  transform: scale(1.22) rotate(-3deg);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.24), 0 8px 12px rgba(0, 0, 0, 0.15) !important;
  pointer-events: none !important;
  cursor: grabbing !important;
  animation: none !important;
  transition: none !important;
}

/* Tap-to-select mode */
.ss-shape.selected {
  transform: scale(1.18) translateY(-6px);
  box-shadow: 0 0 0 4px var(--coral, #FF7B89), 0 12px 24px rgba(255, 123, 137, 0.35);
  animation: selectWiggle 0.6s ease infinite alternate;
  z-index: 25;
}

/* Placeholder ghost left behind in bay */
.ss-placeholder {
  width: 86px;
  height: 86px;
  border-radius: 18px;
  background: rgba(230, 220, 205, 0.25);
  border: 2px dashed rgba(180, 160, 140, 0.35);
  pointer-events: none;
}

/* Slots (Silhouette Cutouts) */
.ss-slot {
  width: 96px;
  height: 96px;
  border-radius: 20px;
  background: var(--slot-bg);
  border: 3px dashed var(--slot-border);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.12), inset 0 1px 2px rgba(0, 0, 0, 0.18), 0 2px 4px rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  position: relative;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
  touch-action: manipulation;
}

/* Slot Hover & Magnetic Proximity */
.ss-slot.hover, .ss-slot.magnetic {
  background: rgba(255, 240, 243, 0.9);
  border-color: var(--coral, #FF7B89);
  border-style: solid;
  transform: scale(1.1);
  box-shadow: 0 0 0 4px rgba(255, 123, 137, 0.35), 0 10px 24px rgba(255, 123, 137, 0.28), inset 0 2px 4px rgba(0,0,0,0.06);
  animation: magneticPulse 0.8s ease-in-out infinite alternate;
}

/* Gentle hint pulse for tap-to-select */
.ss-slot.hint-target {
  border-color: var(--coral, #FF7B89);
  animation: hintPulse 1s ease-in-out infinite;
}

/* Filled Slot */
.ss-slot.filled {
  background: #FFFFFF;
  border-color: transparent;
  border-style: solid;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
  cursor: default;
  pointer-events: none;
  animation: snapSquash 0.45s cubic-bezier(0.17, 0.89, 0.32, 1.25) forwards;
}

/* SVG Inside Elements */
.ss-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  pointer-events: none;
}

/* Kawaii Face Details */
.ss-svg .ss-eye {
  transform-origin: center;
}

.ss-shape:hover .ss-eye,
.ss-shape.selected .ss-eye {
  animation: eyeBlink 3s infinite;
}

/* Bottom Progress & Star Bar */
.ss-bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 24px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  flex-shrink: 0;
  gap: 16px;
}

.ss-stars-track {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ss-star-badge {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.8);
  border: 2px solid #E2E8F0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  color: #CBD5E1;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
  transition: all 0.35s cubic-bezier(0.17, 0.89, 0.32, 1.25);
}

.ss-star-badge.completed {
  background: linear-gradient(135deg, #FFF9C4 0%, #FFD54F 100%);
  border-color: #FFA000;
  color: #B45309;
  transform: scale(1.12);
  box-shadow: 0 4px 10px rgba(245, 158, 11, 0.35);
  animation: starPop 0.5s cubic-bezier(0.17, 0.89, 0.32, 1.25);
}

.ss-status-msg {
  font-size: clamp(0.85rem, 2vw, 1.05rem);
  font-weight: 600;
  color: #475569;
  text-align: right;
  flex: 1;
}

.ss-status-msg span.highlight {
  color: var(--coral, #FF7B89);
  font-weight: 700;
}

/* Animations */
@keyframes gentleBreathe {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-4px) scale(1.02); }
}

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

@keyframes selectWiggle {
  0% { transform: scale(1.18) translateY(-6px) rotate(-4deg); }
  100% { transform: scale(1.18) translateY(-6px) rotate(4deg); }
}

@keyframes magneticPulse {
  0% { transform: scale(1.06); box-shadow: 0 0 0 3px rgba(255, 123, 137, 0.3); }
  100% { transform: scale(1.12); box-shadow: 0 0 0 8px rgba(255, 123, 137, 0.5), 0 12px 28px rgba(255, 123, 137, 0.35); }
}

@keyframes hintPulse {
  0%, 100% { transform: scale(1); box-shadow: inset 0 3px 8px rgba(0,0,0,0.12); }
  50% { transform: scale(1.05); box-shadow: 0 0 0 4px rgba(255, 123, 137, 0.4); }
}

@keyframes snapSquash {
  0% { transform: scale(0.75); }
  50% { transform: scale(1.16); }
  75% { transform: scale(0.95); }
  100% { transform: scale(1); }
}

@keyframes starPop {
  0% { transform: scale(0.5); }
  70% { transform: scale(1.35) rotate(15deg); }
  100% { transform: scale(1.12) rotate(0deg); }
}

@keyframes eyeBlink {
  0%, 45%, 55%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(0.1); }
}

@keyframes idleHintWiggle {
  0%, 100% { transform: rotate(0deg) scale(1); }
  25% { transform: rotate(-10deg) scale(1.1); }
  75% { transform: rotate(10deg) scale(1.1); }
}

/* Responsive Media Queries */
@media (max-width: 820px) {
  .ss-play-arena {
    flex-direction: column-reverse; /* Put Puzzle Board on top, Tray on bottom for toddlers! */
    gap: 12px;
    padding: 6px 14px;
  }
  
  .ss-panel {
    padding: 10px 14px;
  }
  
  .ss-grid {
    grid-template-columns: repeat(auto-fit, minmax(76px, 1fr));
    gap: 12px;
  }
  
  .ss-bay {
    width: 78px;
    height: 78px;
    border-radius: 16px;
  }
  
  .ss-shape {
    width: 74px;
    height: 74px;
    border-radius: 16px;
  }
  
  .ss-slot {
    width: 82px;
    height: 82px;
    border-radius: 18px;
  }
}

@media (max-width: 480px) {
  .ss-top-bar {
    padding: 4px 12px;
    gap: 8px;
  }
  
  .ss-pill-btn {
    padding: 5px 9px;
    font-size: 0.76rem;
    min-height: 32px;
  }

  .ss-play-arena {
    padding: 4px 8px;
    gap: 8px;
  }

  .ss-panel {
    padding: 8px 10px;
    border-radius: 16px;
  }

  .ss-panel-header {
    margin-bottom: 6px;
  }

  .ss-grid {
    grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
    gap: 8px;
    padding: 2px;
  }

  .ss-bay {
    width: 68px;
    height: 68px;
    border-radius: 14px;
  }

  .ss-shape {
    width: 64px;
    height: 64px;
    border-radius: 14px;
    padding: 4px;
  }

  .ss-slot {
    width: 72px;
    height: 72px;
    border-radius: 16px;
    padding: 6px;
  }

  .ss-bottom-bar {
    padding: 6px 14px;
  }

  .ss-star-badge {
    width: 30px;
    height: 30px;
    font-size: 0.95rem;
  }
}

@media (max-width: 360px) {
  .ss-grid {
    grid-template-columns: repeat(auto-fit, minmax(56px, 1fr));
    gap: 6px;
  }
  
  .ss-bay {
    width: 58px;
    height: 58px;
  }
  
  .ss-shape {
    width: 54px;
    height: 54px;
  }
  
  .ss-slot {
    width: 60px;
    height: 60px;
  }
}
