:root {
  --pink: #fbcfe8;
  --rose: #be185d;
  --light-rose: #f8bbd9;
  --ink: #3d2b2b;
  --shadow: rgba(0,0,0,0.15);
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  width: 100%;
}

body {
  margin: 0;
  font-family: 'Georgia', serif;
  background: linear-gradient(135deg, #fdf2f8, #fce7f3, #fbcfe8);
  color: #3d2b2b;
  overflow-x: hidden;
  width: 100%;
}

.puzzle-header {
  padding: 16px 0;
  background: rgba(255,255,255,0.7);
  border-bottom: 1px solid #f8bbd9;
  backdrop-filter: blur(10px);
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-logo {
  font-size: 26px;
  font-weight: bold;
  color: #be185d;
  text-decoration: none;
}

.header-nav {
  display: flex;
  gap: 24px;
  align-items: center;
}

.header-nav a {
  color: #be185d;
  text-decoration: none;
  font-size: 16px;
  font-weight: 500;
  transition: color 0.2s, opacity 0.2s;
  padding: 4px 0;
}

.header-nav a:hover {
  color: #831843;
  opacity: 0.9;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px;
  overflow-x: hidden;
  width: 100%;
  text-align: center;
}

h1 {
  color: #be185d;
  margin-bottom: 20px;
  text-align: center;
  font-size: 32px;
}

.puzzle-preview-container {
  background: rgba(255, 255, 255, 0.6);
  border-radius: 16px;
  padding: 30px;
  margin: 30px 0;
  text-align: center;
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
}

.puzzle-preview-title {
  font-size: 24px;
  color: #be185d;
  margin-bottom: 20px;
}

.puzzle-board-container {
  position: relative;
  margin: 0 auto 30px;
  overflow: hidden;
  width: 100%;
  max-width: 500px;
  border-radius: 12px;
  background: #f0f0f0;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.1);
  padding: 20px;
  box-sizing: border-box;
  min-height: fit-content;
}

.puzzle-board {
  position: relative;
  margin: 0 auto;
  overflow: hidden;
  background: #e0e0e0;
  border-radius: 12px;
  width: 400px;
  height: 400px;
  max-width: 100%;
  box-sizing: border-box;
  border: 3px solid #be185d;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* Grid overlay for puzzle board */
.puzzle-board::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
    linear-gradient(to right, rgba(190, 24, 93, 0.15) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(190, 24, 93, 0.15) 1px, transparent 1px);
  background-size: var(--grid-size, 100px) var(--grid-size, 100px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.6;
}

/* Feedback animations */
@keyframes correctPlacement {
  0% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(34, 197, 94, 0);
    transform: scale(1.05);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
    transform: scale(1);
  }
}

@keyframes incorrectPlacement {
  0% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0);
    transform: translateX(5px);
  }
  75% {
    transform: translateX(-3px);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    transform: translateX(0);
  }
}

.puzzle-piece.correct-feedback {
  animation: correctPlacement 0.5s ease-out;
  border: 2px solid rgba(34, 197, 94, 0.8);
}

.puzzle-piece.incorrect-feedback {
  animation: incorrectPlacement 0.4s ease-out;
  border: 2px solid rgba(239, 68, 68, 0.6);
}

.puzzle-pieces-area {
  position: relative;
  margin: 30px auto 0;
  padding: 15px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  border: 2px dashed #f8bbd9;
  min-height: 200px;
  overflow-x: hidden;
  overflow-y: visible;
  width: 100%;
  max-width: 600px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
  justify-items: center;
  align-items: start;
  align-content: flex-start;
  grid-auto-rows: min-content;
  clear: both;
}

.puzzle-pieces-area .puzzle-piece {
  box-sizing: border-box;
  object-fit: contain;
}

.puzzle-piece {
  position: absolute;
  cursor: move;
  border: 3px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  user-select: none;
  background: rgba(255, 255, 255, 0.1);
}

.puzzle-piece:hover {
  transform: scale(1.08);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
  z-index: 10;
  border-color: #be185d;
}

.puzzle-piece.placed {
  border: none !important;
  box-shadow: none !important;
}

.puzzle-piece.edge-piece {
  border-color: #f472b6;
  box-shadow: 0 3px 12px rgba(244, 114, 182, 0.4);
}

.puzzle-piece.edge-piece:hover {
  border-color: #be185d;
  box-shadow: 0 5px 18px rgba(190, 24, 93, 0.5);
}

.puzzle-solved-message {
  display: none;
  background: linear-gradient(135deg, #be185d, #f472b6);
  color: white;
  padding: 30px;
  border-radius: 16px;
  margin-top: 20px;
  text-align: center;
}

.puzzle-solved-message.show {
  display: block;
  animation: fadeIn 0.5s;
}

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

@media (max-width: 600px) {
  .container {
    padding: 20px 10px !important;
  }
  
  h1 {
    font-size: 24px;
  }
  
  .puzzle-board-container {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 auto 20px !important;
    padding: 10px !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    display: block !important;
    clear: both !important;
  }
  
  .puzzle-board {
    width: 100% !important;
    max-width: 280px !important;
    height: auto !important;
    aspect-ratio: 1 !important;
    max-height: 280px !important;
    min-width: 220px !important;
    min-height: 220px !important;
    margin: 0 auto !important;
    overflow: hidden !important;
    position: relative !important;
    float: none !important;
    box-sizing: border-box !important;
  }
  
  .puzzle-pieces-area {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 200px !important;
    max-height: none !important;
    height: auto !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
    padding: 10px 5px !important;
    gap: 10px !important;
    grid-template-columns: repeat(2, 1fr) !important;
    box-sizing: border-box;
    margin-top: 20px !important;
    margin-bottom: 20px !important;
    margin-left: auto !important;
    margin-right: auto !important;
    display: grid !important;
    clear: both !important;
    float: none !important;
    position: relative !important;
    grid-auto-rows: min-content !important;
    contain: none !important;
    padding-bottom: 100px !important;
  }
  
  .puzzle-pieces-area .puzzle-piece {
    max-width: calc(50% - 8px) !important;
    max-height: none !important;
    object-fit: contain !important;
    min-width: 0;
    min-height: 0;
    visibility: visible !important;
    opacity: 1 !important;
    display: block !important;
  }
  
  .puzzle-piece {
    touch-action: none !important;
    -webkit-touch-callout: none !important;
    border-width: 2px !important;
  }
  
  .puzzle-preview-container {
    padding: 12px !important;
    margin: 15px 0 !important;
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }
  
  .puzzle-preview-title {
    font-size: 18px !important;
    margin-bottom: 12px !important;
  }
  
  .puzzle-solved-message {
    padding: 20px;
    font-size: 16px;
  }
}