/* =========================================================
   פאזל הרכבת המפה – תחנה 1
   ========================================================= */

#screen-puzzle[hidden] {
  display: none;
}

#screen-puzzle:not([hidden]) {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(6px, 1.2vh, 14px) 20px;
  gap: clamp(4px, 0.8vh, 10px);
  overflow: hidden;
}

.puzzle-header {
  text-align: center;
  max-width: 720px;
}

.puzzle-title {
  margin: 0 0 6px;
  font-size: clamp(1.3rem, 2.2vw, 2rem);
  color: var(--color-gold);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.85), 0 0 16px rgba(232, 194, 122, 0.25);
  letter-spacing: 0.02em;
}

.puzzle-instruction {
  margin: 0;
  font-size: clamp(0.9rem, 1.15vw, 1.05rem);
  color: var(--color-parchment);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9);
}

.puzzle-hint-message {
  margin: 0;
  background: rgba(8, 6, 4, 0.78);
  border: 1px solid rgba(216, 164, 91, 0.55);
  color: var(--color-gold);
  padding: 7px 20px;
  border-radius: 7px;
  font-size: 0.92rem;
  text-align: center;
  max-width: 640px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

/* ===================== מרחב עבודה ===================== */

.puzzle-workspace {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* flex-start ולא center: מצמיד את הלוח לראש אזור העבודה במקום
     למרכז אותו אנכית (מה שהשאיר רווח גדול מתחת להוראה) - זה מה
     שבפועל "מעלה" את אזור הפאזל. */
  justify-content: flex-start;
  gap: clamp(10px, 1.8vh, 20px);
}

/* ===================== לוח ההרכבה ===================== */

/* חשוב: יחס הממדים המדויק (1672:941) נקבע על .puzzle-board עצמו,
   לא על המסגרת - כך שהריפוד/הגבול של המסגרת לא "מעוותים" בטעות
   את יחס התאים (וכל חלק ימשיך להיכנס בדיוק לתא שלו, בלי מתיחה). */
.puzzle-board-frame {
  position: relative;
  display: inline-flex;
  max-width: 92%;
  padding: 10px;
  border-radius: 10px;
  background: linear-gradient(155deg, #3a2e1c 0%, #1c150c 100%);
  border: 2px solid rgba(216, 164, 91, 0.55);
  box-shadow:
    0 14px 34px rgba(0, 0, 0, 0.55),
    inset 0 0 0 1px rgba(0, 0, 0, 0.4);
}

.puzzle-board-frame.is-complete-flash {
  animation: goldFrameSweep 1.3s ease-out;
}

@keyframes goldFrameSweep {
  0% { box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(0, 0, 0, 0.4), 0 0 0 rgba(232, 194, 122, 0); }
  35% { box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(0, 0, 0, 0.4), 0 0 46px 8px rgba(232, 194, 122, 0.85); }
  100% { box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(0, 0, 0, 0.4), 0 0 16px 2px rgba(232, 194, 122, 0.4); }
}

.puzzle-board {
  position: relative;
  /* רוחב הוא הבסיס הרספונסיבי (48vw), עם רצפה 720px (נכון גם
     ל-1366px, שבו 48vw~=656px נמוך מהרצפה) ותקרה 920px ב-1920px
     ומעלה. הגובה נגזר אוטומטית מיחס התמונה המקורי 1672:941. */
  width: clamp(720px, 48vw, 920px);
  aspect-ratio: 1672 / 941;
  height: auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  /* חשוב: גיאומטריית התמונה קבועה משמאל-לימין ללא קשר לכיווניות
     העמוד. בלי זה, מיקום האוטומטי של ה-grid בדף RTL היה שם את
     tile-0 (הפינה השמאלית-עליונה של המפה) בעמודה הימנית ביותר
     של הלוח - הרכבה נכונה לפי מזהים אך הפוכה חזותית (מראה). */
  direction: ltr;
  border-radius: 3px;
  overflow: hidden;
  background: #0c0a07;
}

.puzzle-cell {
  position: relative;
  box-sizing: border-box;
  border: 1px dashed rgba(216, 164, 91, 0.32);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: border-color 0.4s ease;
}

.puzzle-board.is-complete .puzzle-cell {
  border-color: transparent;
}

.puzzle-cell.hint-target-glow {
  animation: hintPulse 1.1s ease-in-out infinite;
  z-index: 2;
}

@keyframes hintPulse {
  0%, 100% { box-shadow: inset 0 0 0 rgba(232, 194, 122, 0); }
  50% { box-shadow: inset 0 0 22px 4px rgba(232, 194, 122, 0.85); }
}

.puzzle-cell.lock-flash-anim {
  animation: lockFlash 550ms ease-out;
}

@keyframes lockFlash {
  0% { box-shadow: inset 0 0 0 rgba(232, 194, 122, 0); }
  30% { box-shadow: inset 0 0 26px 6px rgba(232, 194, 122, 0.9); }
  100% { box-shadow: inset 0 0 0 rgba(232, 194, 122, 0); }
}

/* מסגרת זהובה עדינה שמופיעה רק כשחלק שנגרר קרוב/מעל התא הנכון
   שלו - לא נחשף מראש, ולא על אף תא אחר. */
.puzzle-cell.drag-hover-correct {
  border-color: rgba(232, 194, 122, 0.9);
  box-shadow: inset 0 0 0 3px rgba(232, 194, 122, 0.85), inset 0 0 18px rgba(232, 194, 122, 0.3);
}

/* ===================== חלקי הפאזל ===================== */

.puzzle-tray {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  justify-content: center;
  gap: 10px;
  width: min(920px, 94%);
}

.puzzle-piece {
  width: clamp(95px, 9vw, 165px);
  aspect-ratio: 1672 / 941;
  background-image: url("../assets/images/station1-map.png");
  background-size: 300% 300%;
  border: 1px solid rgba(216, 164, 91, 0.22);
  border-radius: 3px;
  box-shadow: 0 3px 9px rgba(0, 0, 0, 0.55);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  transition: border-color 0.4s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.puzzle-piece:hover:not(.is-locked):not(.is-dragging-placeholder) {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.6);
}

.puzzle-piece.is-selected {
  outline: 3px solid var(--color-gold);
  outline-offset: 1px;
  box-shadow: 0 0 16px rgba(232, 194, 122, 0.6);
}

/* החלק המקורי נשאר בדיוק במקומו באזור החלקים בזמן גרירה (לא
   עובר בין containers) - רק מועם, בתור placeholder. כל הגרירה
   החזותית בפועל היא על ה-clone הנפרד (ראו למטה). */
.puzzle-piece.is-dragging-placeholder {
  opacity: 0.32;
  cursor: grabbing;
}

/* ===================== שכבת גרירה + clone ===================== */

.puzzle-drag-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5000;
}

.puzzle-drag-clone {
  position: fixed;
  margin: 0;
  pointer-events: none;
  cursor: grabbing;
  box-shadow: 0 16px 28px rgba(0, 0, 0, 0.65);
  transform: scale(1.05);
  border-color: rgba(232, 194, 122, 0.6);
}

.puzzle-piece.is-locked {
  width: 100%;
  aspect-ratio: auto;
  height: 100%;
  cursor: default;
  box-shadow: none;
  border: 1px solid rgba(216, 164, 91, 0.2);
}

.puzzle-board.is-complete .puzzle-piece.is-locked {
  border-color: transparent;
}

.puzzle-piece.hint-glow {
  animation: hintPulse 1.1s ease-in-out infinite;
  z-index: 3;
}

.puzzle-piece.piece-return-bounce {
  animation: pieceReturnBounce 320ms ease;
}

@keyframes pieceReturnBounce {
  0% { transform: scale(1.07) rotate(-1.2deg); }
  55% { transform: scale(0.96) rotate(1deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* ===================== פאנל השלמה ===================== */

.puzzle-completion-panel[hidden] {
  display: none;
}

.puzzle-completion-panel:not([hidden]) {
  position: absolute;
  left: 50%;
  bottom: clamp(10px, 3vh, 26px);
  transform: translateX(-50%);
  z-index: 3;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.puzzle-completion-text {
  margin: 0;
  font-family: var(--font-heading);
  color: var(--color-gold);
  font-size: clamp(1rem, 1.5vw, 1.25rem);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.9), 0 0 14px rgba(232, 194, 122, 0.3);
  background: rgba(6, 5, 3, 0.55);
  padding: 8px 22px;
  border-radius: 8px;
}

.decode-route-btn {
  padding: 9px 30px;
  font-family: var(--font-heading);
  font-size: clamp(0.9rem, 1.1vw, 1.05rem);
  font-weight: 700;
  color: var(--color-gold);
  background: rgba(8, 6, 4, 0.4);
  border: 1.5px solid rgba(216, 164, 91, 0.6);
  border-radius: 5px;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 5px rgba(0, 0, 0, 0.85);
}

.decode-route-btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}
