body {
  background-image: url(../../img/expression-bg5.png);
  color: #fff;
  text-align: center;
  padding: 2rem;
  font-family: "Taipei Sans TC Beta", sans-serif;
  margin: 0;
}

h1 {
  margin-bottom: 1.5rem;
  text-shadow: 0px 2px 4px rgba(0, 0, 0, 0.3);
}

h3 {
  margin: 0.5rem 0;
  color: #fff;
  text-shadow: 0px 1px 2px rgba(0, 0, 0, 0.2);
}

/* 遊戲容器佈局 */
.game-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 1000px;
  margin: 0 auto;
  gap: 20px;
}

/* 參考圖片區域 */
.reference-area {
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.reference-image {
  width: 250px;
  height: 250px;
  border: 3px solid #fff;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  margin-bottom: 15px;
  background-color: rgba(255, 255, 255, 0.1);
}

/* 拼圖板區域 */
.puzzle-area {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.puzzle-board {
  width: 400px;
  height: 400px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 2px;
  padding: 5px;
  background-color: rgba(255, 255, 255, 0.1);
  border: 3px solid #fff;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  margin-bottom: 15px;
}

.puzzle-cell {
  width: 100px;
  height: 100px;
  background-color: rgba(255, 255, 255, 0.1);
  border: 1px dashed rgba(255, 255, 255, 0.5);
}

/* 拼圖片段容器 */
.pieces-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.pieces-container {
  width: 90%;
  max-width: 900px;
  min-height: 180px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 15px;
  background-color: rgba(255, 255, 255, 0.1);
  border: 3px solid #fff;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  justify-content: center;
}

/* 拼圖片段 */
.puzzle-piece {
  width: 100px;
  height: 100px;
  cursor: grab;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s, box-shadow 0.2s;
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.puzzle-piece:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
  z-index: 10;
}

.puzzle-piece:active {
  cursor: grabbing;
}

/* 手機拖拉相關樣式 */
.being-dragged {
  transform: scale(1.05);
  box-shadow: 0 8px 15px rgba(0, 0, 0, 0.7);
}

/* 防止手機點擊高亮和提高觸控反應 */
.puzzle-piece,
.puzzle-cell {
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  /* 防止觸控時縮放和滾動 */
  user-select: none;
  -webkit-user-select: none;
}

/* 確保手指下方內容可見 */
.puzzle-board {
  touch-action: none;
  z-index: 1;
}

.pieces-container {
  touch-action: none;
  z-index: 1;
}

/* 提升整個頁面捲動流暢度 */
html,
body {
  overscroll-behavior: none;
  /* 防止過度捲動 */
  touch-action: pan-y;
  /* 只允許垂直捲動 */
}

/* 改善拼圖片段觸摸區域 */
.puzzle-piece {
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -webkit-touch-callout: none;
  /* 禁用iOS長按選單 */
}

/* 改善拼圖片段外觀以更清晰識別 */
.puzzle-piece {
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5);
  border: 2px solid rgba(255, 255, 255, 0.7);
}

/* 改善拼圖格子外觀以便於辨識目標區域 */
.puzzle-cell {
  border: 2px dashed rgba(255, 255, 255, 0.7);
  background-color: rgba(255, 255, 255, 0.2);
  transition: background-color 0.2s;
}

.puzzle-cell:empty:hover,
.puzzle-cell:empty:active {
  background-color: rgba(255, 255, 255, 0.3);
}

/* 拖曳時的視覺效果 */
.puzzle-piece.being-dragged {
  opacity: 0.4 !important;
  transform: scale(0.95);
}

/* 高亮顯示可放置的格子 */
.puzzle-cell.highlight {
  background-color: rgba(255, 255, 255, 0.4) !important;
  border: 2px dashed rgba(255, 255, 255, 0.9) !important;
  box-shadow: inset 0 0 15px rgba(255, 255, 255, 0.6);
  transition: all 0.2s ease;
}

/* 按鈕樣式 */
button {
  padding: 10px 25px;
  font-size: 16px;
  background: linear-gradient(45deg, #ff00cc, #3333ff);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  transition: all 0.2s;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

button:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* 響應式設計 */
@media (max-width: 900px) {
  .game-container {
    flex-direction: column;
    align-items: center;
  }

  .puzzle-board {
    width: 320px;
    height: 320px;
  }

  .puzzle-cell {
    width: 80px;
    height: 80px;
  }

  .puzzle-piece {
    width: 80px;
    height: 80px;
    background-size: 320px 320px;
  }

  .reference-image {
    width: 200px;
    height: 200px;
  }
}