/* Jigsaw Puzzle styles */

/* Base Placeholders */
.collected-piece.placeholder {
  visibility: visible;
  opacity: 0.3;
  background: rgba(255, 255, 255, 0.05);
  /* Explicit border props to override generic */
  border-width: 1px;
  border-style: dashed;
  border-color: var(--text-muted);
  pointer-events: auto;
  cursor: default; /* Arrow for empty placeholders */
  box-shadow: none; /* Ensure no shadow */
  transform: none; /* Ensure no scale */
}

/* Selected State - Must come AFTER placeholder or have higher specificity if we want selection to show on placeholders (usually we don't select placeholders but just in case) */
.collected-piece.selected,
.sudoku-chunk-slot.selected {
  border-color: var(--accent-color) !important;
  box-shadow: 0 0 15px var(--accent-color);
  transform: scale(1.1);
  z-index: 1510; /* Slightly higher than hover z-index */
  opacity: 1;
}

/* Base style for all jigsaw mode pieces to ensure they can glow outside */
.jigsaw-mode .collected-piece,
.jigsaw-mode .sudoku-chunk-slot {
  overflow: visible !important;
}

/* Jigsaw Mode Transitions */
/* Default Jigsaw Cursors */
.jigsaw-mode .collected-piece {
  cursor: pointer; /* Selectable pieces */
}
.jigsaw-mode .collected-piece.placeholder {
  cursor: default; /* Not selectable */
}

.jigsaw-mode .sudoku-chunk-slot {
  cursor: default; /* Not selectable if empty */
}
.jigsaw-mode .sudoku-chunk-slot.filled {
  cursor: pointer; /* Selectable piece on board */
}

/* Active Selection Cursors: Everything becomes a target */
.jigsaw-mode.selection-active .collected-piece.placeholder {
  cursor: pointer; /* Valid Drop Target */
}

.jigsaw-mode.selection-active .sudoku-chunk-slot {
  cursor: pointer; /* Valid Move/Swap Target */
}

/* Locked Center Place always locked during Jigsaw */
.jigsaw-mode .sudoku-chunk-slot[data-slot-index="4"] {
  cursor: not-allowed;
  position: relative; /* Ensure pseudo-element is positioned relative to this */
}

/* Overlay effect to ensure it is visible ON TOP of the piece */
.jigsaw-mode .sudoku-chunk-slot[data-slot-index="4"]::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.05); /* Much lighter for Light Mode */
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2); /* Softer shadow */
  pointer-events: none; /* Let clicks pass through (though slot is locked anyway) */
  z-index: 10;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px; /* Match the parent slot's curvature */
}

/* Dark Mode Override for Center Slot */
.dark-mode .jigsaw-mode .sudoku-chunk-slot[data-slot-index="4"]::after {
  background: rgba(0, 0, 0, 0.3); /* Darker for proper contrast in Dark Mode */
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.6);
}

.memory-board,
.collected-piece,
.collected-wrapper,
.sudoku-chunk-slot {
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Hover Feedback */
@media (hover: hover) {
  /* Panel Pieces Hover */
  .jigsaw-mode .collected-piece:not(.placeholder):not(.selected):hover {
    transform: scale(1.05);
    z-index: 1500;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  }

  /* Board Pieces Hover */
  .jigsaw-mode
    .sudoku-chunk-slot.filled:not(.selected):not([data-slot-index="4"]):hover {
    transform: scale(1.05);
    z-index: 1500;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  }

  /* Selected Pieces Hover - Even higher to stay on top */
  .jigsaw-mode .collected-piece.selected:hover,
  .jigsaw-mode .sudoku-chunk-slot.selected:hover {
    transform: scale(1.15);
    z-index: 1600;
  }
}

/* Standard Desktop Jigsaw Expansion (769px - 1099px, Height > 850px) */
@media (min-width: 769px) and (max-width: 1099px) and (min-height: 1001px) {
  .jigsaw-mode .memory-board,
  .sudoku-mode .memory-board {
    width: 400px !important;
    height: 400px !important;
  }

  .jigsaw-mode .collected-piece {
    width: 91px !important;
    height: 91px !important;
    font-size: 1.6rem !important;
  }

  /* Adjust grid columns for larger Jigsaw board */
  .jigsaw-mode .memory-grid-layout,
  .sudoku-mode .memory-grid-layout {
    grid-template-columns: 120px 400px 120px !important;
    column-gap: 4rem !important;
    max-width: 1250px !important;
  }

  /* Expand Board vertical budget when in Jigsaw or Sudoku Mode to allow growth */
  .jigsaw-mode .memory-board,
  .sudoku-mode .memory-board {
    width: 400px !important;
    height: 400px !important;
  }

  .jigsaw-mode .collected-zone,
  .sudoku-mode .collected-zone {
    gap: 12px !important;
  }
}

/* Large Desktop Jigsaw Expansion (Scale Up only if there is enough height) */
@media (min-width: 1100px) and (min-height: 1001px) {
  .jigsaw-mode .memory-board,
  .sudoku-mode .memory-board {
    width: 420px !important; /* Force larger size */
    height: 420px !important;
  }

  .jigsaw-mode .collected-piece {
    width: 99px !important;
    height: 99px !important;
    /* Large Font for large pieces */
    font-size: 2rem;
  }

  .jigsaw-mode .collected-wrapper,
  .sudoku-mode .collected-wrapper {
    gap: 15px;
    padding: 10px;
  }

  /* Adjust layout to fit larger board */
  .jigsaw-mode .memory-grid-layout,
  .sudoku-mode .memory-grid-layout {
    gap: 2rem;
    /* Unlock the middle column to fit the 420px board */
    grid-template-columns: 110px 420px 110px;
  }
}

/* Drag & Drop Styles */
.dragging-clone {
  position: fixed;
  pointer-events: none; /* Let clicks pass through to detect drop target */
  z-index: 9999;
  opacity: 0.9;
  transform: scale(1.1);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
  /* Enable transition for size (shrink effect) but NOT for position (lag) */
  transition:
    width 0.4s ease,
    height 0.4s ease,
    transform 0.4s ease;
}

/* Override Selected State during Drag (No glow/scale on the empty hole) */
.collected-piece.selected.dragging-source,
.sudoku-chunk-slot.selected.dragging-source {
  border-color: transparent !important;
  box-shadow: none !important;
  transform: none !important;
  z-index: auto !important;
}

/* Force background to appear "empty" when lifting the piece */
/* Case A: Board Slot -> Opaque Grey */
.sudoku-chunk-slot.filled.dragging-source {
  background: var(--bg-tertiary) !important;
}

/* Case B: Panel Slot -> Transparent Dashed (Matches Placeholder) */
.collected-piece.dragging-source {
  background: rgba(255, 255, 255, 0.05) !important;
  border: 1px dashed var(--text-muted) !important;
  opacity: 0.5 !important; /* Slightly dimmed to match placeholder vibe */
}

.drop-hover {
  background-color: rgba(255, 255, 255, 0.2);
  border-color: var(--accent-color) !important;
}

/* Fix for Self-Hover: Allow drop-hover to win against dragging-source background */
/* Board: Highlight Background + Border */
.sudoku-chunk-slot.filled.dragging-source.drop-hover {
  background-color: rgba(255, 255, 255, 0.2) !important;
  border-color: var(--accent-color) !important;
  opacity: 1 !important;
}

/* Panel: Highlight Border ONLY (Keep background subtle) for ALL panel slots */
.collected-piece.drop-hover,
.collected-piece.dragging-source.drop-hover {
  background: rgba(
    255,
    255,
    255,
    0.05
  ) !important; /* Keep original placeholder look */
  border-color: var(--accent-color) !important;
}

/* Ensure self-hover matches opacity of placeholders */
.collected-piece.dragging-source.drop-hover {
  opacity: 0.3 !important;
}

/* Error Feedback Styles */
@keyframes shake-red {
  0% {
    transform: translate(1px, 1px) rotate(0deg);
    box-shadow: 0 0 10px red;
    border-color: red;
  }
  10% {
    transform: translate(-1px, -2px) rotate(-1deg);
  }
  20% {
    transform: translate(-3px, 0px) rotate(1deg);
  }
  30% {
    transform: translate(3px, 2px) rotate(0deg);
  }
  40% {
    transform: translate(1px, -1px) rotate(1deg);
  }
  50% {
    transform: translate(-1px, 2px) rotate(-1deg);
  }
  60% {
    transform: translate(-3px, 1px) rotate(0deg);
  }
  70% {
    transform: translate(3px, 1px) rotate(-1deg);
  }
  80% {
    transform: translate(-1px, -1px) rotate(1deg);
  }
  90% {
    transform: translate(1px, 2px) rotate(0deg);
  }
  100% {
    transform: translate(1px, -2px) rotate(-1deg);
    box-shadow: 0 0 10px red;
    border-color: red;
  }
}

.board-error {
  animation: shake-red 0.5s;
  border-color: red !important;
  box-shadow: 0 0 15px red !important;
}

/* Mark specific number as duplicate */
.mini-cell.error-number {
  color: red !important;
  font-weight: bold;
}
