/* ========================================
   명화 직소 퍼즐 - 스타일
   퍼즐 보드, 조각 트레이, 드래그 피드백
   ======================================== */

/* ---- 앱 컨테이너 ---- */
.jigsaw-app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
}

/* ========== 시작 화면 ========== */
#start-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--spacing-md);
}

.start-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-md);
  width: 100%;
  max-width: 340px;
}

.start-emoji {
  font-size: 72px;
  line-height: 1;
  animation: float 3s ease-in-out infinite;
}

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

.start-title {
  font-size: var(--font-xl);
  font-weight: 700;
  color: var(--color-text);
}

.start-subtitle {
  font-size: var(--font-md);
  color: var(--color-text-sub);
}

.start-day {
  display: inline-block;
  padding: 4px 16px;
  border-radius: var(--radius-full);
  background: var(--color-primary-light);
  color: #2D7A50;
  font-size: var(--font-sm);
  font-weight: 600;
}

/* 명화 선택 영역 */
.choices-area {
  width: 100%;
}

.choices-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-xl) var(--spacing-md);
  color: var(--color-text-hint);
  font-size: var(--font-sm);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.choices-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--spacing-xs);
}

.choices-label {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--color-text-sub);
}

.shuffle-btn {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px 10px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-sub);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  transition: all var(--transition-instant);
}

.shuffle-btn:active {
  transform: scale(0.94);
  background: var(--color-surface-alt);
}

.choices-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--spacing-sm);
  width: 100%;
}

/* 선택 가능한 명화 카드 */
.choice-card {
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  border: 3px solid transparent;
  transition: all var(--transition-instant);
  -webkit-user-select: none;
  user-select: none;
}

.choice-card:active {
  transform: scale(0.96);
}

.choice-card.selected {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--color-primary-light), var(--shadow-md);
}

.choice-card-img {
  width: 100%;
  height: 80px;
  object-fit: cover;
  display: block;
}

.choice-card-info {
  padding: 6px 8px;
}

.choice-card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.choice-card-artist {
  font-size: 11px;
  color: var(--color-text-hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

/* 난이도 선택 */
.selector-group {
  width: 100%;
  margin-top: var(--spacing-sm);
}

.selector-label {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--color-text-sub);
  margin-bottom: var(--spacing-xs);
  text-align: left;
}

.selector-buttons {
  display: flex;
  gap: var(--spacing-sm);
  width: 100%;
}

.difficulty-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: var(--touch-min);
  padding: var(--spacing-sm) var(--spacing-xs);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  transition: all var(--transition-instant);
  -webkit-user-select: none;
  user-select: none;
}

.difficulty-btn:active {
  transform: scale(0.96);
}

.difficulty-btn.selected {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  color: #2D7A50;
}

.start-btn {
  width: 100%;
  margin-top: var(--spacing-sm);
}

.best-record {
  font-size: var(--font-sm);
  color: var(--color-text-hint);
  margin-top: var(--spacing-xs);
}

/* ========== 게임 화면 ========== */
#game-screen {
  align-items: center;
  padding-top: var(--spacing-sm);
  gap: var(--spacing-sm);
}

/* 상단 통계 바 */
.game-stats-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 360px;
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-item-ref {
  flex-direction: row;
  gap: 6px;
}

.stat-label {
  font-size: 13px;
  color: var(--color-text-hint);
  font-weight: 500;
}

.stat-value {
  font-size: var(--font-md);
  font-weight: 700;
  color: var(--color-text);
}

/* 힌트 버튼 */
.hint-btn {
  height: 40px;
  padding: 0 10px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-size: 15px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  -webkit-user-select: none;
  user-select: none;
  transition: all var(--transition-instant);
}

.hint-btn:active {
  transform: scale(0.92);
}

.hint-btn.hint-used {
  opacity: 0.4;
  pointer-events: none;
}

.hint-btn #hintCount {
  font-size: 13px;
  color: var(--color-text-sub);
}

.ref-toggle-btn {
  width: 40px;
  height: 40px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-user-select: none;
  user-select: none;
}

.ref-toggle-btn:active {
  transform: scale(0.92);
}

/* 완성본 오버레이 */
.ref-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-md);
  cursor: pointer;
}

.ref-full-image {
  max-width: 90vw;
  max-height: 70vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 32px rgba(0, 0, 0, 0.5);
  touch-action: none;
  transform-origin: center center;
  user-select: none;
  -webkit-user-select: none;
}

.ref-info {
  color: rgba(255, 255, 255, 0.9);
  font-size: var(--font-sm);
  text-align: center;
  line-height: 1.4;
}

.ref-close-hint {
  color: rgba(255, 255, 255, 0.5);
  font-size: 13px;
}

/* 퍼즐 보드 */
.puzzle-board-area {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  flex: 1;
  min-height: 0;
}

.puzzle-board {
  position: relative;
  background: var(--color-surface-alt);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* 보드 가이드 셀 */
.board-cell {
  position: absolute;
  border: 1.5px dashed rgba(0, 0, 0, 0.08);
  border-radius: 4px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-cell.filled {
  border-color: transparent;
}

.board-cell.filled .cell-label {
  display: none;
}

/* 보드 셀 좌표 라벨 - 기본 숨김 (힌트 시 표시) */
.cell-label {
  font-size: 11px;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.12);
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  display: none;
}

/* 조각 위 좌표 라벨 - 기본 숨김 (힌트 시 표시) */
.piece-label {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  line-height: 1;
  display: none;
}

/* 힌트 활성화 시 좌표 표시 */
.hint-active .cell-label {
  display: block;
  animation: hintFade 3s ease-out forwards;
}

.hint-active .piece-label,
.hint-active .piece-in-tray .piece-label {
  display: block;
  animation: hintFade 3s ease-out forwards;
}

@keyframes hintFade {
  0% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

/* 퍼즐 조각 */
.puzzle-piece {
  position: absolute;
  background-size: cover;
  background-repeat: no-repeat;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  transition: box-shadow 0.15s ease;
  z-index: 1;
}

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

.puzzle-piece.dragging {
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  transform: scale(1.06);
  transition: box-shadow 0.1s ease, transform 0.1s ease;
}

.puzzle-piece.snapped {
  cursor: default;
  box-shadow: none;
  border-radius: 0;
  z-index: 0;
  transition: left 0.2s ease, top 0.2s ease, box-shadow 0.2s ease;
}

.puzzle-piece.snap-flash {
  animation: snapFlash 0.4s ease;
}

@keyframes snapFlash {
  0% { box-shadow: 0 0 0 4px rgba(76, 175, 130, 0.6); }
  100% { box-shadow: none; }
}

.puzzle-piece.wrong-snap {
  animation: wrongShake 0.3s ease;
}

@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* 조각 트레이 */
.tray-area {
  width: 100%;
  max-width: 360px;
}

.tray-label {
  font-size: 13px;
  color: var(--color-text-hint);
  text-align: center;
  margin-bottom: var(--spacing-xs);
}

.piece-tray {
  display: flex;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  min-height: 90px;
  align-items: center;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

.piece-tray::-webkit-scrollbar {
  height: 4px;
}

.piece-tray::-webkit-scrollbar-track {
  background: transparent;
}

.piece-tray::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 2px;
}

/* 트레이 안 조각 */
.tray-piece-wrapper {
  flex-shrink: 0;
  position: relative;
}

.piece-in-tray {
  position: relative;
  background-size: cover;
  background-repeat: no-repeat;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
  cursor: grab;
  touch-action: pan-x;
  -webkit-user-select: none;
  user-select: none;
}

/* 게임 하단 네비 */
.game-nav-links {
  display: flex;
  gap: var(--spacing-sm);
  justify-content: center;
  padding: var(--spacing-xs) 0;
}

.game-nav-btn {
  font-size: var(--font-sm);
  color: var(--color-text-hint);
  text-decoration: none;
  padding: 6px 12px;
  background: none;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: inherit;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.game-nav-btn:active {
  background: var(--color-surface-alt);
}

/* ========== 결과 화면 ========== */
#result-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--spacing-md);
  padding: var(--spacing-md);
}

.result-header {
  font-size: var(--font-xl);
  font-weight: 700;
  color: var(--color-text);
}

.result-message {
  font-size: var(--font-lg);
  font-weight: 600;
  color: var(--color-encourage);
  animation: fadeSlideUp var(--transition-page) ease-out;
}

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

/* 완성된 명화 카드 */
.result-painting {
  width: 100%;
  max-width: 320px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--color-surface);
  box-shadow: var(--shadow-md);
}

.result-painting-img-wrap {
  position: relative;
  cursor: pointer;
  overflow: hidden;
}

.result-painting-img {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  display: block;
}

.result-painting-tap-hint {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px;
  background: linear-gradient(transparent, rgba(0,0,0,0.5));
  color: rgba(255,255,255,0.8);
  font-size: 12px;
  text-align: center;
  pointer-events: none;
}

/* 전체 보기 오버레이 */
.fullview-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-md);
  cursor: pointer;
}

.fullview-image {
  max-width: 92vw;
  max-height: 75vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  touch-action: none;
  transform-origin: center center;
  user-select: none;
  -webkit-user-select: none;
}

.fullview-info {
  color: rgba(255, 255, 255, 0.9);
  font-size: var(--font-sm);
  text-align: center;
  line-height: 1.5;
}

.result-painting-info {
  padding: var(--spacing-sm) var(--spacing-md) var(--spacing-md);
}

.result-painting-title {
  font-size: var(--font-md);
  font-weight: 700;
  color: var(--color-text);
}

.result-painting-artist {
  font-size: var(--font-sm);
  color: var(--color-text-sub);
  margin-top: 2px;
}

.result-painting-year {
  font-size: 14px;
  color: var(--color-text-hint);
  margin-top: 2px;
}

.result-painting-desc {
  padding: var(--spacing-sm) var(--spacing-md) var(--spacing-md);
  border-top: 1px solid var(--color-border);
  font-size: var(--font-sm);
  color: var(--color-text-sub);
  line-height: 1.6;
  text-align: left;
}

.result-painting-desc:empty {
  display: none;
}

.result-painting-desc .desc-loading {
  color: var(--color-text-hint);
  font-style: italic;
}

/* 결과 통계 카드 */
.result-stats-card {
  width: 100%;
  max-width: 320px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  box-shadow: var(--shadow-sm);
}

.result-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-sm) 0;
}

.result-stat-row + .result-stat-row {
  border-top: 1px solid var(--color-border);
}

.result-stat-label {
  font-size: var(--font-sm);
  color: var(--color-text-sub);
  display: flex;
  align-items: center;
  gap: 6px;
}

.result-stat-value {
  font-size: var(--font-md);
  font-weight: 700;
  color: var(--color-text);
}

/* 결과 버튼 */
.result-actions {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: var(--touch-gap);
}

.share-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--touch-min);
  padding: var(--spacing-md) var(--spacing-lg);
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-family: inherit;
  font-size: var(--font-btn);
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  transition: all var(--transition-instant);
  -webkit-user-select: none;
  user-select: none;
}

.share-btn:active {
  transform: scale(0.96);
}

.share-btn.copied {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
  color: #2D7A50;
}

/* ========== 에러 상태 ========== */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-md);
  padding: var(--spacing-xl);
  text-align: center;
}

.error-emoji {
  font-size: 56px;
}

.error-text {
  font-size: var(--font-md);
  color: var(--color-text-sub);
  line-height: 1.6;
}

/* ========== 반응형 ========== */
@media (max-width: 360px) {
  .difficulty-btn {
    font-size: 13px;
    padding: var(--spacing-sm) 4px;
    gap: 2px;
  }

  .game-stats-bar {
    padding: var(--spacing-xs) var(--spacing-sm);
  }

  .stat-value {
    font-size: 18px;
  }

  .choice-card-img {
    height: 60px;
  }
}

@media (max-height: 640px) {
  #start-screen {
    padding-top: var(--spacing-sm);
    gap: var(--spacing-sm);
  }

  .start-emoji {
    font-size: 48px;
  }

  .choice-card-img {
    height: 50px;
  }

  #game-screen {
    padding-top: var(--spacing-xs);
    gap: var(--spacing-xs);
  }

  #result-screen {
    gap: var(--spacing-sm);
  }

  .result-painting-img {
    max-height: 140px;
  }
}
