/* =========================================================
   THE HOLLOW - INTERACTIVE PUZZLE MECHANIC STYLES
   ========================================================= */

:root {
  --puzzle-red: #e63946;
  --puzzle-red-glow: rgba(230, 57, 70, 0.6);
  --puzzle-blue: #29abf7;
  --puzzle-blue-glow: rgba(41, 171, 247, 0.6);
  --puzzle-dark: #0a0a12;
  --puzzle-card: #141420;
  --puzzle-gold: #f5bb27;
  --puzzle-gold-glow: rgba(245, 187, 39, 0.6);
}

/* Container */
.puzzle-section {
  position: relative;
  width: 100%;
  max-width: 900px;
  margin: 2rem auto;
  padding: 1.5rem;
  background: radial-gradient(circle at top, rgba(230, 57, 70, 0.15) 0%, rgba(10, 10, 18, 0.95) 70%);
  border: 2px solid rgba(230, 57, 70, 0.35);
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7), 0 0 30px rgba(230, 57, 70, 0.2);
  backdrop-filter: blur(10px);
  color: #fff;
  font-family: 'Rubik', sans-serif;
  box-sizing: border-box;
  overflow: hidden;
}

.puzzle-section::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 30% 20%, rgba(41, 171, 247, 0.08) 0%, transparent 40%),
              radial-gradient(circle at 70% 80%, rgba(230, 57, 70, 0.08) 0%, transparent 40%);
  pointer-events: none;
  z-index: 0;
}

/* Header */
.puzzle-header {
  position: relative;
  z-index: 1;
  text-align: center;
  margin-bottom: 1.5rem;
}

.puzzle-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  background: linear-gradient(135deg, rgba(230, 57, 70, 0.3), rgba(41, 171, 247, 0.3));
  border: 1px solid rgba(230, 57, 70, 0.5);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #ffb4ba;
  margin-bottom: 0.5rem;
  box-shadow: 0 0 15px rgba(230, 57, 70, 0.3);
  animation: pulse-badge 2.5s infinite;
}

@keyframes pulse-badge {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.03); opacity: 0.9; }
}

.puzzle-title {
  font-family: 'Fredoka', 'Rubik', sans-serif;
  font-size: 2.2rem;
  font-weight: 700;
  margin: 0.2rem 0;
  background: linear-gradient(90deg, #ff4d5a, #ffffff, #38b6ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 2px 20px rgba(230, 57, 70, 0.5);
}

.puzzle-subtitle {
  font-size: 0.95rem;
  color: #a4a4b8;
  max-width: 550px;
  margin: 0 auto;
}

/* Game Controls & Status Bar */
.puzzle-bar {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(18, 18, 28, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px 16px;
  margin-bottom: 1.5rem;
}

.puzzle-progress-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 220px;
}

.puzzle-progress-bar-bg {
  flex: 1;
  height: 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.puzzle-progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #e63946, #f5bb27, #2ecc71);
  border-radius: 999px;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 10px rgba(46, 204, 113, 0.5);
}

.puzzle-progress-text {
  font-size: 0.85rem;
  font-weight: 600;
  color: #f0f0f5;
  white-space: nowrap;
}

.puzzle-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.puzzle-btn-icon {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #f0f0f5;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.puzzle-btn-icon:hover {
  background: rgba(230, 57, 70, 0.25);
  border-color: var(--puzzle-red);
  transform: translateY(-1px);
  color: #fff;
}

/* Mode Selector */
.puzzle-mode-selector {
  display: flex;
  gap: 4px;
  background: rgba(0, 0, 0, 0.4);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.puzzle-mode-btn {
  background: transparent;
  border: none;
  color: #8e8e9e;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.puzzle-mode-btn.active {
  background: var(--puzzle-red);
  color: #fff;
  box-shadow: 0 0 10px var(--puzzle-red-glow);
}

/* Main Interactive Area */
.puzzle-main {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

/* Board Outer Wrapper */
.puzzle-board-wrap {
  position: relative;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
}

/* The 3x3 Puzzle Board */
.puzzle-board {
  position: relative;
  width: 100%;
  aspect-ratio: 479 / 640;
  background: #0d0d16;
  border-radius: 14px;
  padding: 6px;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 5px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.8),
              inset 0 0 20px rgba(0, 0, 0, 0.8),
              0 0 0 2px rgba(255, 255, 255, 0.08);
  transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.puzzle-board.completed {
  box-shadow: 0 0 40px var(--puzzle-gold-glow),
              0 0 80px rgba(230, 57, 70, 0.4),
              inset 0 0 30px rgba(245, 187, 39, 0.3),
              0 0 0 3px var(--puzzle-gold);
  border-color: var(--puzzle-gold);
  animation: victory-glow 2s infinite alternate;
}

@keyframes victory-glow {
  0% { box-shadow: 0 0 25px var(--puzzle-gold-glow), 0 0 50px rgba(230, 57, 70, 0.3); }
  100% { box-shadow: 0 0 45px rgba(245, 187, 39, 0.8), 0 0 85px rgba(230, 57, 70, 0.6); }
}

/* Individual Slot on the Board */
.puzzle-slot {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  overflow: hidden;
  box-sizing: border-box;
  background-color: #12121e;
  transition: all 0.25s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Slot when missing/empty */
.puzzle-slot.is-empty {
  border: 2px dashed rgba(230, 57, 70, 0.5);
  background: radial-gradient(circle, rgba(230, 57, 70, 0.12) 0%, rgba(18, 18, 30, 0.95) 80%);
  cursor: pointer;
  animation: pulse-slot 2.2s infinite ease-in-out;
}

@keyframes pulse-slot {
  0%, 100% {
    border-color: rgba(230, 57, 70, 0.45);
    background-color: rgba(230, 57, 70, 0.05);
  }
  50% {
    border-color: rgba(41, 171, 247, 0.8);
    background-color: rgba(41, 171, 247, 0.12);
  }
}

.puzzle-slot.is-empty::before {
  content: '?';
  font-family: 'Fredoka', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.25);
  transition: all 0.2s;
}

.puzzle-slot.is-empty:hover {
  border-color: var(--puzzle-blue);
  background-color: rgba(41, 171, 247, 0.2);
  transform: scale(0.98);
}

.puzzle-slot.is-empty:hover::before {
  color: var(--puzzle-blue);
  transform: scale(1.2);
}

/* Drag over active slot */
.puzzle-slot.drag-over {
  border-color: #2ecc71 !important;
  background: rgba(46, 204, 113, 0.25) !important;
  box-shadow: 0 0 15px rgba(46, 204, 113, 0.6) inset;
  transform: scale(1.02);
}

/* Slot shake on invalid drop */
.puzzle-slot.shake-error {
  animation: shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
  border-color: #e63946 !important;
  background: rgba(230, 57, 70, 0.3) !important;
}

@keyframes shake {
  10%, 90% { transform: translate3d(-2px, 0, 0); }
  20%, 80% { transform: translate3d(3px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
  40%, 60% { transform: translate3d(4px, 0, 0); }
}

/* Tile rendered inside slot (or tray) */
.puzzle-tile {
  width: 100%;
  height: 100%;
  background-image: url('../images/puzzle_ref.jpg');
  background-size: 300% 300%;
  background-repeat: no-repeat;
  border-radius: 8px;
  position: relative;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-sizing: border-box;
}

/* 3x3 Grid background positions */
.tile-pos-0 { background-position: 0% 0%; }
.tile-pos-1 { background-position: 50% 0%; }
.tile-pos-2 { background-position: 100% 0%; }
.tile-pos-3 { background-position: 0% 50%; }
.tile-pos-4 { background-position: 50% 50%; }
.tile-pos-5 { background-position: 100% 50%; }
.tile-pos-6 { background-position: 0% 100%; }
.tile-pos-7 { background-position: 50% 100%; }
.tile-pos-8 { background-position: 100% 100%; }

/* Tile snap animation */
.puzzle-tile.just-placed {
  animation: tile-snap 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes tile-snap {
  0% { transform: scale(1.25); filter: brightness(1.8); }
  50% { transform: scale(0.95); filter: brightness(1.3); }
  100% { transform: scale(1); filter: brightness(1); }
}

/* Missing Pieces Tray */
.puzzle-tray-container {
  width: 100%;
  max-width: 520px;
  background: rgba(14, 14, 22, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 1rem 1.2rem;
  box-sizing: border-box;
  text-align: center;
}

.puzzle-tray-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #ffb4ba;
  margin-bottom: 0.8rem;
}

.puzzle-tray-pieces {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  min-height: 105px;
  padding: 6px;
}

/* Individual piece in tray */
.tray-piece {
  position: relative;
  width: 90px;
  aspect-ratio: 479 / 640;
  border-radius: 10px;
  cursor: grab;
  touch-action: none;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6), 0 0 0 2px rgba(255, 255, 255, 0.2);
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
  background-color: #12121a;
}

.tray-piece:hover {
  transform: translateY(-6px) scale(1.05);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.8), 0 0 15px var(--puzzle-blue-glow), 0 0 0 2px var(--puzzle-blue);
}

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

.tray-piece.selected {
  transform: translateY(-8px) scale(1.08);
  box-shadow: 0 0 20px var(--puzzle-gold-glow), 0 0 0 3px var(--puzzle-gold) !important;
  animation: pulse-selected 1.5s infinite;
}

@keyframes pulse-selected {
  0%, 100% { box-shadow: 0 0 15px var(--puzzle-gold-glow), 0 0 0 3px var(--puzzle-gold); }
  50% { box-shadow: 0 0 25px rgba(245, 187, 39, 0.9), 0 0 0 3px #fff; }
}

.tray-piece-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 4px;
  color: #fff;
  pointer-events: none;
}

/* Floating clone during drag */
.puzzle-drag-clone {
  position: fixed;
  pointer-events: none;
  z-index: 99999;
  border-radius: 10px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8), 0 0 25px var(--puzzle-red-glow), 0 0 0 2px #fff;
  opacity: 0.92;
  transform: translate(-50%, -50%) rotate(2deg) scale(1.1);
  transition: opacity 0.15s ease;
  overflow: hidden;
}

/* Instruction notice */
.puzzle-hint-bar {
  font-size: 0.85rem;
  color: #9292a8;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 0.5rem;
}

/* =========================================================
   CLAIM BUTTON AREA (Locked until puzzle complete)
   ========================================================= */
.puzzle-claim-area {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 440px;
  margin: 1.5rem auto 0;
  text-align: center;
}

/* Locked state */
.puzzle-claim-locked {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 24px;
  background: rgba(25, 25, 35, 0.6);
  border: 1.5px dashed rgba(255, 255, 255, 0.2);
  border-radius: 14px;
  color: #7b7b90;
  font-size: 0.95rem;
  font-weight: 600;
  user-select: none;
  transition: all 0.4s ease;
}

.puzzle-claim-locked .lock-icon {
  font-size: 1.2rem;
  color: #9090a8;
}

/* Unlocked active Claim Button */
.puzzle-claim-btn {
  display: none;
  width: 100%;
  padding: 16px 28px;
  background: linear-gradient(135deg, #e63946 0%, #ff5964 50%, #f5bb27 100%);
  border: none;
  border-radius: 14px;
  font-family: 'Fredoka', 'Rubik', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(230, 57, 70, 0.6), 0 0 20px rgba(245, 187, 39, 0.4);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  position: relative;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.puzzle-claim-btn.unlocked {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  animation: claim-appear 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards,
             claim-pulse 2s infinite ease-in-out;
}

@keyframes claim-appear {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes claim-pulse {
  0%, 100% {
    box-shadow: 0 10px 30px rgba(230, 57, 70, 0.6), 0 0 20px rgba(245, 187, 39, 0.4);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 14px 40px rgba(230, 57, 70, 0.9), 0 0 35px rgba(245, 187, 39, 0.8);
    transform: scale(1.03);
  }
}

.puzzle-claim-btn::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -60%;
  width: 40%;
  height: 200%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  transform: rotate(25deg);
  animation: shine-sweep 3s infinite;
}

@keyframes shine-sweep {
  0% { left: -60%; }
  30%, 100% { left: 140%; }
}

.puzzle-claim-btn:hover {
  transform: translateY(-3px) scale(1.04);
  filter: brightness(1.1);
}

.puzzle-claim-btn:active {
  transform: translateY(1px) scale(0.98);
}

/* Confetti Canvas */
.puzzle-confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 99998;
}

/* =========================================================
   CLAIM REWARD MODAL (Standalone)
   ========================================================= */
.puzzle-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  box-sizing: border-box;
}

.puzzle-modal.open {
  display: flex;
}

.puzzle-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(5, 5, 10, 0.85);
  backdrop-filter: blur(8px);
}

.puzzle-modal-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 460px;
  background: #12121c;
  border: 2px solid var(--puzzle-red);
  border-radius: 20px;
  padding: 2rem;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9), 0 0 40px var(--puzzle-red-glow);
  animation: modal-pop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modal-pop {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.puzzle-modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.puzzle-modal-close:hover {
  background: var(--puzzle-red);
  transform: rotate(90deg);
}

.puzzle-reward-preview {
  width: 130px;
  aspect-ratio: 479 / 640;
  margin: 1rem auto;
  border-radius: 12px;
  background-image: url('../images/puzzle_ref.jpg');
  background-size: cover;
  background-position: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8), 0 0 20px var(--puzzle-gold-glow);
  border: 2px solid var(--puzzle-gold);
}

.puzzle-modal-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.8rem;
  color: #fff;
  margin-bottom: 0.3rem;
}

.puzzle-modal-desc {
  font-size: 0.9rem;
  color: #a0a0b5;
  margin-bottom: 1.2rem;
}

/* Responsive adjustments */
@media (max-width: 600px) {
  .puzzle-section {
    padding: 1rem;
    border-radius: 14px;
  }
  .puzzle-title {
    font-size: 1.6rem;
  }
  .puzzle-board-wrap {
    max-width: 280px;
  }
  .tray-piece {
    width: 72px;
  }
  .puzzle-tray-pieces {
    gap: 8px;
  }
  .puzzle-claim-btn {
    font-size: 1.1rem;
    padding: 14px 20px;
  }
}
