.workspace {
  height: 60vh;
  min-height: 400px;
  max-height: 800px;
  background: var(--workspace);
  border-radius: 15px;
  position: relative;
  /* Allow some overflow for jigsaw tabs near edges */
  overflow: hidden;
  margin: 20px 0;
  border: 2px solid var(--border);
  /* Add padding to accommodate jigsaw tabs at edges */
  padding: 10px;
  box-sizing: border-box;
}

.reset-button {
  background: var(--accent-yellow);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(255, 230, 109, 0.4);
}

.reset-button:hover {
  background: var(--accent-peach);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(255, 230, 109, 0.5);
}

.reset-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(255, 230, 109, 0.3);
}

.live-timer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--primary);
  color: white;
  padding: 12px 24px;
  border-radius: 50px;
  font-size: 1.25rem;
  font-weight: 700;
  margin: 20px auto;
  max-width: 200px;
  box-shadow: 0 4px 16px rgba(255, 107, 157, 0.4);
  animation: timerPulse 2s ease-in-out infinite;
  position: relative;
  overflow: hidden;
}

.live-timer::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.15);
  animation: shimmer 3s infinite;
}

@keyframes timerPulse {
  0%, 100% {
    box-shadow: 0 4px 16px rgba(255, 107, 157, 0.4);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 6px 20px rgba(255, 107, 157, 0.6);
    transform: scale(1.02);
  }
}

@keyframes shimmer {
  0% {
    left: -100%;
  }
  100% {
    left: 100%;
  }
}

.timer-icon {
  font-size: 1.5rem;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.timer-text {
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* ==================== COUNTDOWN TIMER ==================== */

.countdown-timer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--success);
  color: white;
  padding: 12px 24px;
  border-radius: 50px;
  font-size: 1.25rem;
  font-weight: 700;
  margin: 20px auto;
  max-width: 280px;
  box-shadow: 0 4px 16px rgba(127, 205, 187, 0.4);
  animation: countdownPulse 2s ease-in-out infinite;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
}

.countdown-timer::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.15);
  animation: shimmer 3s infinite;
}

@keyframes countdownPulse {
  0%, 100% {
    box-shadow: 0 4px 16px rgba(127, 205, 187, 0.4);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 6px 20px rgba(127, 205, 187, 0.6);
    transform: scale(1.02);
  }
}

/* Warning state - under 5 seconds */
.countdown-timer.warning {
  background: var(--accent-yellow);
  box-shadow: 0 4px 16px rgba(255, 230, 109, 0.5);
  animation: warningPulse 0.5s ease-in-out infinite;
}

@keyframes warningPulse {
  0%, 100% {
    box-shadow: 0 4px 16px rgba(255, 230, 109, 0.5);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 6px 24px rgba(255, 230, 109, 0.8);
    transform: scale(1.05);
  }
}

/* Overtime state */
.countdown-timer.overtime {
  background: #FF6B6B;
  box-shadow: 0 4px 16px rgba(255, 107, 107, 0.5);
  animation: overtimePulse 1s ease-in-out infinite;
  max-width: 320px;
}

@keyframes overtimePulse {
  0%, 100% {
    box-shadow: 0 4px 16px rgba(255, 107, 107, 0.5);
  }
  50% {
    box-shadow: 0 6px 24px rgba(255, 107, 107, 0.7);
  }
}

.overtime-label {
  font-size: 0.7rem;
  background: rgba(255, 255, 255, 0.25);
  padding: 4px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

/* ==================== SOLVE STATS & POINTS ==================== */

.solve-stats {
  margin-bottom: 15px;
}

.solve-time.within-time {
  background: rgba(127, 205, 187, 0.15);
  border: 2px solid var(--success);
  color: var(--text) !important;
}

.solve-time.overtime {
  background: rgba(255, 107, 107, 0.15);
  border: 2px solid #FF6B6B;
  color: var(--text) !important;
}

.time-bonus {
  display: inline-block;
  background: var(--success);
  color: white;
  padding: 4px 10px;
  border-radius: 15px;
  font-size: 0.85rem;
  margin-left: 8px;
  font-weight: 600;
  animation: bonusGlow 1s ease-in-out infinite;
}

@keyframes bonusGlow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.points-earned {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--accent-orange);
  padding: 12px 18px;
  border-radius: 20px;
  margin-top: 10px;
  box-shadow: 0 6px 20px rgba(255, 165, 0, 0.4);
  animation: pointsPopIn 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

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

.points-earned .points-icon {
  font-size: 2rem;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
  animation: pointsStarSpin 1s ease-in-out;
}

@keyframes pointsStarSpin {
  0% { transform: rotate(-180deg) scale(0); }
  50% { transform: rotate(10deg) scale(1.2); }
  100% { transform: rotate(0deg) scale(1); }
}

.points-earned .points-value {
  font-size: 2rem;
  font-weight: 800;
  color: white;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.points-earned .points-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.bonus-badge {
  background: rgba(255, 255, 255, 0.3);
  padding: 6px 12px;
  border-radius: 15px;
  font-size: 0.75rem;
  font-weight: 700;
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  animation: bonusBadgePop 0.5s ease-out 0.3s backwards;
}

@keyframes bonusBadgePop {
  0% { transform: scale(0); }
  70% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.reference-image {
  max-width: 200px;
  max-height: 200px;
  border-radius: 12px;
  margin: 20px auto;
  display: block;
  box-shadow: 0 4px 16px var(--shadow);
  border: 3px solid white;
}

.piece {
  position: absolute;
  cursor: grab;
  touch-action: none;
  user-select: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
  /* Improve image quality when scaling up - smooth interpolation for photos */
  image-rendering: auto;
}

/* Jigsaw piece specific styles */
.piece.jigsaw-piece {
  /* No border since jigsaw pieces have their own shape */
  border: none;
  /* Allow overlapping tabs */
  overflow: visible;
  /* Subtle drop shadow for depth effect */
  /* filter: drop-shadow(2px 3px 4px rgba(0, 0, 0, 0.25)); */
}

/* .piece.jigsaw-piece:hover { */
  /* filter: drop-shadow(3px 4px 6px rgba(0, 0, 0, 0.35)); */
  /* z-index: 100; */
/* } */

.piece:active {
  cursor: grabbing;
  z-index: 1000;
}

/* Non-jigsaw pieces - keep legacy styles */
.piece:not(.jigsaw-piece):active {
  box-shadow: 0 8px 24px var(--shadow-lg);
}

.piece:not(.jigsaw-piece).placed {
  border-color: var(--success);
  box-shadow: 0 4px 12px rgba(127, 205, 187, 0.4);
}

/* Jigsaw piece states using drop-shadow for proper shape */
.piece.jigsaw-piece:active {
  filter: drop-shadow(4px 6px 10px rgba(0, 0, 0, 0.4));
  z-index: 1000;
}

.piece.jigsaw-piece.placed {
  filter: drop-shadow(2px 3px 6px rgba(127, 205, 187, 0.5));
}

.piece.snap-preview {
  z-index: 1001;
}

/* Non-jigsaw snap preview */
.piece:not(.jigsaw-piece).snap-preview {
  border-color: var(--primary);
  border-width: 4px;
  box-shadow: 0 0 30px rgba(255, 107, 157, 0.8), 0 4px 12px var(--shadow);
  outline: 3px solid rgba(255, 107, 157, 0.5);
  outline-offset: 2px;
  animation: snapPulse 0.4s ease-in-out infinite;
}

/* Jigsaw snap preview - use filter for shape-aware glow */
.piece.jigsaw-piece.snap-preview {
  filter: drop-shadow(0 0 15px rgba(255, 107, 157, 0.9)) 
          drop-shadow(0 0 8px rgba(255, 107, 157, 0.7))
          drop-shadow(3px 4px 6px rgba(0, 0, 0, 0.3));
  animation: jigsawSnapPulse 0.4s ease-in-out infinite;
}

@keyframes jigsawSnapPulse {
  0%, 100% {
    filter: drop-shadow(0 0 15px rgba(255, 107, 157, 0.9)) 
            drop-shadow(0 0 8px rgba(255, 107, 157, 0.7))
            drop-shadow(3px 4px 6px rgba(0, 0, 0, 0.3));
  }
  50% {
    filter: drop-shadow(0 0 20px rgba(255, 107, 157, 1)) 
            drop-shadow(0 0 12px rgba(255, 107, 157, 0.9))
            drop-shadow(4px 5px 8px rgba(0, 0, 0, 0.4));
  }
}

.piece.snap-target {
  z-index: 1000;
}

/* Non-jigsaw snap target */
.piece:not(.jigsaw-piece).snap-target {
  border-color: var(--success);
  border-width: 3px;
  box-shadow: 0 0 25px rgba(127, 205, 187, 0.6), 0 4px 12px var(--shadow);
  animation: targetPulse 0.5s ease-in-out infinite;
}

/* Jigsaw snap target */
.piece.jigsaw-piece.snap-target {
  filter: drop-shadow(0 0 12px rgba(127, 205, 187, 0.8))
          drop-shadow(0 0 6px rgba(127, 205, 187, 0.6))
          drop-shadow(2px 3px 4px rgba(0, 0, 0, 0.25));
  animation: jigsawTargetPulse 0.5s ease-in-out infinite;
}

@keyframes jigsawTargetPulse {
  0%, 100% {
    filter: drop-shadow(0 0 12px rgba(127, 205, 187, 0.8))
            drop-shadow(0 0 6px rgba(127, 205, 187, 0.6))
            drop-shadow(2px 3px 4px rgba(0, 0, 0, 0.25));
  }
  50% {
    filter: drop-shadow(0 0 18px rgba(127, 205, 187, 1))
            drop-shadow(0 0 10px rgba(127, 205, 187, 0.8))
            drop-shadow(3px 4px 6px rgba(0, 0, 0, 0.35));
  }
}

@keyframes snapPulse {
  0%, 100% {
    box-shadow: 0 0 30px rgba(255, 107, 157, 0.8), 0 4px 12px var(--shadow);
    outline-color: rgba(255, 107, 157, 0.5);
  }
  50% {
    box-shadow: 0 0 40px rgba(255, 107, 157, 1), 0 6px 16px var(--shadow-lg);
    outline-color: rgba(255, 107, 157, 0.8);
  }
}

@keyframes targetPulse {
  0%, 100% {
    box-shadow: 0 0 25px rgba(127, 205, 187, 0.6), 0 4px 12px var(--shadow);
  }
  50% {
    box-shadow: 0 0 35px rgba(127, 205, 187, 0.8), 0 6px 16px var(--shadow-lg);
  }
}

.piece.snapping {
  transition: left 0.2s ease, top 0.2s ease;
}

.completion-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--modal-overlay, rgba(45, 27, 30, 0.7));
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.3s ease;
  backdrop-filter: blur(8px);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.completion-content {
  background: var(--card-bg);
  padding: 30px;
  border-radius: 24px 0 0 24px;
  text-align: center;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  margin: 20px;
  animation: slideUp 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  box-shadow: 0 20px 60px var(--shadow-lg);
  position: relative;
  overflow-y: auto;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

/* Custom Scrollbar for Completion Modal */
.completion-content::-webkit-scrollbar {
  width: 8px;
}

.completion-content::-webkit-scrollbar-track {
  background: rgba(255, 107, 157, 0.08);
  border-radius: 24px;
  margin: 10px 0;
}

.completion-content::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb, var(--primary));
  border-radius: 24px;
  transition: background 0.2s ease;
}

.completion-content::-webkit-scrollbar-thumb:hover {
  background: var(--primary-dark);
}

/* Firefox Scrollbar */
.completion-content {
  scrollbar-width: thin;
  scrollbar-color: #ff6b9d rgba(255, 107, 157, 0.08);
}

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

.celebration-icon {
  font-size: 2.5rem;
  margin-bottom: 10px;
  animation: bounce 1s infinite;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2));
}

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

.celebration-title {
  color: var(--primary);
  font-size: 1.75rem;
  margin-bottom: 8px;
  font-weight: 800;
  letter-spacing: 0.5px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

.celebration-subtitle {
  color: var(--text-light);
  font-size: 0.95rem;
  margin-bottom: 15px;
  font-weight: 500;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.completion-image {
  max-width: 100%;
  max-height: 150px;
  border-radius: 12px;
  margin: 15px auto 10px;
  display: block;
  box-shadow: 0 4px 16px var(--shadow);
  border: 3px solid var(--border);
}

.completion-image-container {
  margin: 15px 0;
}

.download-button {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.3s ease;
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.download-button:hover {
  background: var(--primary-dark);
  transform: scale(1.05);
}

.celebration-button {
  background: var(--primary);
  color: white;
  padding: 12px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(255, 107, 157, 0.3);
  border: none;
  cursor: pointer;
  transition: all 0.3s ease;
  width: 100%;
  margin-top: 15px;
}

.celebration-button:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(255, 107, 157, 0.4);
}

.celebration-button.secondary {
  background: var(--secondary);
  box-shadow: 0 4px 12px rgba(168, 230, 207, 0.3);
  color: var(--text);
}

.celebration-button.secondary:hover {
  background: var(--secondary);
  filter: brightness(0.9);
  box-shadow: 0 6px 16px rgba(168, 230, 207, 0.4);
}

/* Dark theme celebration button adjustments */
body.theme-neonNights .celebration-button.secondary,
body.theme-midnight .celebration-button.secondary {
  background: var(--bg);
  color: var(--text);
  border: 2px solid var(--border);
}

body.theme-neonNights .celebration-button.secondary:hover,
body.theme-midnight .celebration-button.secondary:hover {
  background: var(--border);
  filter: none;
}

.solve-time {
  color: var(--text) !important;
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 10px;
  padding: 10px 16px;
  background: var(--bg);
  border-radius: 12px;
  display: inline-block;
  border: 2px solid var(--border);
}

/* Audio element for future music feature */
#completion-music {
  display: none;
}

@media (max-width: 768px) {
  .workspace {
    height: 65vh;
    min-height: 400px;
    max-height: none;
  }
  
  .completion-content {
    padding: 25px 20px;
    margin: 15px;
    width: calc(100% - 30px);
    max-width: 450px;
    max-height: 90vh;
  }
  
  .celebration-title {
    font-size: 1.75rem;
  }
  
  .celebration-subtitle {
    font-size: 1rem;
  }
  
  .celebration-icon {
    font-size: 3rem;
  }
  
  .completion-image {
    max-height: 150px;
  }
  
  .celebration-button {
    padding: 12px;
    font-size: 0.9rem;
  }

  .live-timer {
    font-size: 1.1rem;
    padding: 10px 20px;
    max-width: 180px;
  }

  .timer-icon {
    font-size: 1.3rem;
  }
  
  .countdown-timer {
    font-size: 1.1rem;
    padding: 10px 20px;
    max-width: 240px;
  }
  
  .countdown-timer.overtime {
    max-width: 280px;
  }
  
  .overtime-label {
    font-size: 0.65rem;
    padding: 3px 8px;
  }
  
  .points-earned {
    padding: 14px 20px;
  }
  
  .points-earned .points-icon {
    font-size: 1.75rem;
  }
  
  .points-earned .points-value {
    font-size: 1.75rem;
  }
  
  .points-earned .points-label {
    font-size: 0.8rem;
  }
  
  .bonus-badge {
    font-size: 0.7rem;
    padding: 5px 10px;
  }
}

/* Special handling for landscape mode on mobile */
@media (max-width: 768px) and (max-height: 500px) {
  .workspace {
    height: 75vh;
    min-height: 300px;
  }
}

/* Extra small phones */
@media (max-width: 400px) {
  .workspace {
    height: 60vh;
    min-height: 350px;
  }
  
  .completion-content {
    padding: 25px 15px;
    margin: 10px;
    width: calc(100% - 20px);
    border-radius: 20px 0 0 20px;
    max-height: 90vh;
  }
  
  .celebration-title {
    font-size: 1.5rem;
  }
  
  .celebration-subtitle {
    font-size: 0.9rem;
  }
  
  .celebration-icon {
    font-size: 2.5rem;
    margin-bottom: 15px;
  }
  
  .completion-image {
    max-height: 120px;
  }
  
  .celebration-button {
    padding: 12px;
    font-size: 0.875rem;
    width: 100%;
  }

  .live-timer {
    font-size: 1rem;
    padding: 8px 16px;
    max-width: 160px;
  }

  .timer-icon {
    font-size: 1.2rem;
  }

  .solve-time {
    font-size: 1.1rem;
    padding: 10px 16px;
  }
  
  .countdown-timer {
    font-size: 1rem;
    padding: 8px 16px;
    max-width: 200px;
    gap: 8px;
  }
  
  .countdown-timer.overtime {
    max-width: 240px;
  }
  
  .overtime-label {
    font-size: 0.6rem;
    padding: 2px 6px;
  }
  
  .points-earned {
    padding: 12px 16px;
    gap: 8px;
  }
  
  .points-earned .points-icon {
    font-size: 1.5rem;
  }
  
  .points-earned .points-value {
    font-size: 1.5rem;
  }
  
  .points-earned .points-label {
    font-size: 0.75rem;
  }
  
  .bonus-badge {
    font-size: 0.65rem;
    padding: 4px 8px;
    width: 100%;
    text-align: center;
  }
  
  .time-bonus {
    font-size: 0.75rem;
    padding: 3px 8px;
    margin-left: 5px;
  }
}

