/* ==========================================================================
   SANRIOCHARACTERS.COM — REUSABLE JIGSAW PUZZLE ENGINE STYLES
   ========================================================================== */

:root {
  --puzzle-bg: #1c0a16;
  --puzzle-card: #ffffff;
  --puzzle-border: rgba(28, 10, 22, 0.12);
  --puzzle-accent: #c2185b;
  --puzzle-accent-light: #fce8f1;
  --puzzle-gold: #c9a84c;
  --puzzle-gold-dark: #8c6b1e;
  --puzzle-ink: #1c0a16;
  --puzzle-radius: 16px;
  --puzzle-shadow: 0 10px 30px rgba(28, 10, 22, 0.12);
}

/* PUZZLE APP WRAPPER */
.puzzle-app-container {
  background: var(--puzzle-card);
  border: 1px solid var(--puzzle-border);
  border-radius: var(--puzzle-radius);
  box-shadow: var(--puzzle-shadow);
  padding: clamp(16px, 3vw, 28px);
  margin: 1.5rem 0 3rem;
  box-sizing: border-box;
  width: 100%;
  position: relative;
  overflow: hidden;
}

/* STATUS & CONTROLS HEADER */
.puzzle-status-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  margin-bottom: 20px;
  border-bottom: 2px solid rgba(194, 24, 91, 0.12);
}

.puzzle-stats-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.puzzle-stat-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fdf5f8;
  border: 1px solid rgba(194, 24, 91, 0.2);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--puzzle-ink);
}

.puzzle-stat-item .stat-icon {
  font-size: 1rem;
}

.puzzle-stat-item .stat-val {
  color: var(--puzzle-accent);
  font-family: monospace;
  font-size: 0.98rem;
  font-weight: 800;
}

.puzzle-difficulty-group {
  display: inline-flex;
  background: #f4ecf0;
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
}

.puzzle-diff-btn {
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 700;
  color: #6b4d5e;
  cursor: pointer;
  transition: all 0.2s ease;
}

.puzzle-diff-btn:hover {
  color: var(--puzzle-ink);
}

.puzzle-diff-btn.active {
  background: var(--puzzle-accent);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(194, 24, 91, 0.35);
}

.puzzle-controls-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.puzzle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: white;
  border: 1px solid rgba(28, 10, 22, 0.2);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--puzzle-ink);
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 38px;
  user-select: none;
  -webkit-user-select: none;
}

.puzzle-btn:hover {
  background: #fdf5f8;
  border-color: var(--puzzle-accent);
  color: var(--puzzle-accent);
  transform: translateY(-1px);
}

.puzzle-btn:active {
  transform: translateY(0);
}

.puzzle-btn.btn-primary {
  background: var(--puzzle-accent);
  border-color: var(--puzzle-accent);
  color: #ffffff;
}

.puzzle-btn.btn-primary:hover {
  background: #a3154c;
  color: #ffffff;
}

/* GAMEPLAY WORKSPACE */
.puzzle-workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  align-items: start;
}

@media (min-width: 900px) {
  .puzzle-workspace.layout-side {
    grid-template-columns: minmax(0, 560px) minmax(260px, 1fr);
  }
}

/* PUZZLE BOARD */
.puzzle-board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.puzzle-board {
  position: relative;
  width: 100%;
  max-width: 600px;
  aspect-ratio: 4 / 3;
  background: #2b1320;
  border-radius: 12px;
  border: 2px solid rgba(28, 10, 22, 0.2);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* BOARD SLOTS GRID OVERLAY */
.puzzle-slot {
  position: absolute;
  box-sizing: border-box;
  border: 1px dashed rgba(255, 255, 255, 0.22);
  pointer-events: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.puzzle-slot.slot-highlight {
  background: rgba(194, 24, 91, 0.35);
  border: 2px solid var(--puzzle-accent);
}

/* PUZZLE PIECE */
.puzzle-piece {
  position: absolute;
  box-sizing: border-box;
  background-repeat: no-repeat;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  border: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.28);
  border-radius: 4px;
  transition: box-shadow 0.15s ease, transform 0.1s ease;
  z-index: 10;
}

.puzzle-piece:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.38);
  border-color: #ffffff;
  z-index: 20;
}

.puzzle-piece.is-dragging {
  cursor: grabbing !important;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.45);
  transform: scale(1.04);
  z-index: 9999 !important;
  opacity: 0.96;
}

.puzzle-piece.is-placed {
  cursor: default !important;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: none;
  border-radius: 0;
  z-index: 5;
  pointer-events: none;
}

/* SNAP SUCCESS ANIMATION */
@keyframes pieceSnapPop {
  0% { transform: scale(1.08); filter: brightness(1.3); }
  100% { transform: scale(1); filter: brightness(1); }
}

.puzzle-piece.snap-anim {
  animation: pieceSnapPop 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* PIECE TRAY */
.puzzle-tray-wrap {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.puzzle-tray-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.puzzle-tray-title {
  font-size: 0.88rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b4d5e;
}

.puzzle-tray {
  position: relative;
  background: #fdf5f8;
  border: 2px dashed rgba(194, 24, 91, 0.25);
  border-radius: 12px;
  min-height: 180px;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
  box-sizing: border-box;
  overflow-y: auto;
  max-height: 480px;
}

.puzzle-tray-piece-holder {
  position: relative;
  display: inline-block;
  flex-shrink: 0;
}

.puzzle-tray-empty {
  width: 100%;
  text-align: center;
  padding: 40px 10px;
  color: #9c7b8c;
  font-size: 0.95rem;
  font-weight: 600;
}

/* REFERENCE MODAL */
.puzzle-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 10, 22, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.puzzle-modal-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

.puzzle-modal-box {
  background: white;
  border-radius: 20px;
  max-width: 580px;
  width: 100%;
  padding: 24px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.35);
  position: relative;
  transform: scale(0.95);
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-sizing: border-box;
  max-height: 90vh;
  overflow-y: auto;
}

.puzzle-modal-backdrop.is-open .puzzle-modal-box {
  transform: scale(1);
}

.puzzle-modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: #f4ecf0;
  border: none;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--puzzle-ink);
  transition: all 0.2s;
}

.puzzle-modal-close:hover {
  background: var(--puzzle-accent);
  color: #ffffff;
}

.puzzle-reference-img {
  width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--puzzle-border);
  display: block;
  margin-top: 12px;
}

/* COMPLETION CELEBRATION MODAL */
.puzzle-complete-header {
  text-align: center;
  margin-bottom: 20px;
}

.puzzle-complete-emoji {
  font-size: 3.5rem;
  margin-bottom: 8px;
  display: inline-block;
  animation: bounceCelebrate 1s infinite alternate ease-in-out;
}

@keyframes bounceCelebrate {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-8px) scale(1.1); }
}

.puzzle-complete-title {
  font-family: var(--font-display);
  font-size: 1.85rem;
  color: var(--puzzle-ink);
  margin: 0 0 6px;
}

.puzzle-complete-sub {
  font-size: 0.95rem;
  color: #6b4d5e;
  margin: 0;
}

.puzzle-stats-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  background: #fdf5f8;
  border: 1px solid rgba(194, 24, 91, 0.15);
  border-radius: 12px;
  padding: 16px;
  margin: 20px 0;
  text-align: center;
}

.puzzle-summary-card b {
  display: block;
  font-size: 1.35rem;
  font-family: monospace;
  color: var(--puzzle-accent);
}

.puzzle-summary-card span {
  font-size: 0.8rem;
  text-transform: uppercase;
  font-weight: 700;
  color: #7a5c6d;
}

.puzzle-complete-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

@media (min-width: 480px) {
  .puzzle-complete-actions {
    flex-direction: row;
    justify-content: center;
  }
}

/* PROGRESS BAR */
.puzzle-progress-bar-wrap {
  width: 100%;
  height: 6px;
  background: #eee;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 12px;
}

.puzzle-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--puzzle-accent), var(--puzzle-gold));
  border-radius: 999px;
  transition: width 0.25s ease;
}

/* LOADING & ERROR STATES */
.puzzle-loading-state,
.puzzle-error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  text-align: center;
  padding: 30px;
  background: #faf6f8;
  border-radius: 12px;
  border: 2px dashed rgba(194, 24, 91, 0.2);
}

.puzzle-spinner {
  width: 42px;
  height: 42px;
  border: 4px solid rgba(194, 24, 91, 0.2);
  border-top-color: var(--puzzle-accent);
  border-radius: 50%;
  animation: puzzleSpin 0.8s linear infinite;
  margin-bottom: 16px;
}

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

/* ACCESSIBILITY & REDUCED MOTION */
@media (prefers-reduced-motion: reduce) {
  .puzzle-piece,
  .puzzle-modal-backdrop,
  .puzzle-modal-box,
  .puzzle-progress-bar,
  .puzzle-piece.snap-anim,
  .puzzle-complete-emoji {
    animation: none !important;
    transition: none !important;
  }
}

/* RESPONSIVE ADJUSTMENTS */
@media (max-width: 600px) {
  .puzzle-status-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .puzzle-stats-group {
    justify-content: space-between;
  }
  .puzzle-difficulty-group {
    width: 100%;
    justify-content: space-between;
  }
  .puzzle-diff-btn {
    flex: 1;
    text-align: center;
    padding: 8px 4px;
    font-size: 0.78rem;
  }
  .puzzle-controls-group {
    justify-content: space-between;
  }
  .puzzle-controls-group .puzzle-btn {
    flex: 1;
    justify-content: center;
    padding: 8px 6px;
    font-size: 0.78rem;
  }
  .puzzle-tray {
    min-height: 140px;
    max-height: 280px;
  }
}
