/* The final-week puzzle page. */
.puzzle-page { overflow-x: hidden; }

.puzzle-header {
  position: relative;
  z-index: 20;
  text-align: center;
  padding: 4.2rem 1rem 0.8rem;
}
.puzzle-header .button { position: absolute; top: 1rem; left: 1rem; font-size: 0.9rem; }
.puzzle-header h1 { font-size: clamp(1.7rem, 6vw, 2.6rem); color: var(--gold); text-shadow: 0 3px 12px rgba(0, 0, 0, 0.5); }
.puzzle-tabs { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; margin: 0.8rem 0 0.2rem; }
.puzzle-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.35em 0.9em;
  font-size: 0.9rem;
  color: var(--cream);
  text-decoration: none;
  background: rgba(7, 13, 36, 0.55);
  border: 1px solid rgba(244, 199, 82, 0.5);
  border-radius: 10px;
}
.puzzle-tab small { font-size: 0.72rem; opacity: 0.8; }
.puzzle-tab.is-current { color: #3a2606; background: var(--gold); border-color: var(--gold); font-weight: bold; }
.puzzle-tab.is-locked { opacity: 0.45; }
.puzzle-header__status { max-width: 30rem; margin: 0.4rem auto 0; font-style: italic; }

.puzzle-main {
  position: relative;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
  padding: 0 1rem 3rem;
}

/* The board: a wooden frame around a white card with one slot per piece. */
.board-frame {
  position: relative;
  width: min(94vw, 760px);
  min-width: 260px;
  padding: 14px;
  background: linear-gradient(145deg, #a8703f, #5e3920);
  border-radius: 14px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5), inset 0 0 0 3px rgba(244, 199, 82, 0.6);
}
.board {
  position: relative;
  background: #1b2b4a;
  border-radius: 3px;
}
.board[role="button"] { cursor: zoom-in; }
.slots { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.slot {
  fill: #24375c;
  stroke: rgba(244, 199, 82, 0.55);
  stroke-width: 1.5px;
  stroke-dasharray: 6 5;
  vector-effect: non-scaling-stroke;
  transition: fill 0.2s;
}
.slot.is-near { fill: #4a5f86; stroke: var(--gold); stroke-width: 3px; stroke-dasharray: none; }
.slot.is-filled { visibility: hidden; }

/* Pieces: tilted in the satchel, picked up while dragging, flush when placed. */
.piece {
  position: relative;
  display: block;
  flex: none;
  padding: 0;
  border: 0;
  background: none;
  transform: rotate(var(--tilt, 0deg));
  touch-action: none;
  cursor: grab;
  transition: transform 0.2s;
}
.piece svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  filter: drop-shadow(0 5px 6px rgba(0, 0, 0, 0.45));
}
.piece-edge { stroke: var(--gold); stroke-width: 2.5px; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.piece:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }
.piece:disabled { cursor: default; opacity: 0.9; }
.piece.is-dragging {
  position: fixed;
  z-index: 60;
  transform: scale(1.04);
  cursor: grabbing;
  transition: none;
}
.piece.is-dragging svg { filter: drop-shadow(0 14px 14px rgba(0, 0, 0, 0.55)); }
.piece.is-wrong { animation: nope 0.45s; }
.board .piece.is-placed {
  position: absolute;
  transform: none;
  cursor: default;
  animation: settle 0.35s ease-out;
}
.board .piece.is-placed svg { filter: none; }
.board .piece.is-placed .piece-edge { stroke: rgba(255, 255, 255, 0.18); stroke-width: 1px; }
.piece--missing {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #f4e3c3;
  font-size: 0.85rem;
  background: rgba(0, 0, 0, 0.25);
  outline: 2px dashed rgba(244, 199, 82, 0.7);
  border-radius: 6px;
}

/* Once complete, the code becomes one seamless image. */
.board__whole { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; transition: opacity 0.6s 0.3s; }
.board.is-complete .board__whole { opacity: 1; }
.board__qr { opacity: 0; transition: opacity 1.4s 1.2s; }
.board.is-complete .board__qr { opacity: 1; }

/* The code, big enough to scan from another phone. */
.zoom {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(5, 10, 30, 0.8);
}
.zoom[hidden] { display: none; }
.zoom__card {
  width: min(90vw, 70vh, 460px);
  padding: 1rem;
  text-align: center;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}
.zoom__card svg { display: block; width: 100%; height: auto; margin-bottom: 0.8rem; }
.board.is-complete ~ .board__burst { display: none; }
.board-frame:has(.is-complete) { animation: glow 2.4s ease-in-out infinite; }

.board__burst { position: absolute; z-index: 5; margin: 14px; pointer-events: none; }
.board__burst i {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px;
  background: #fff3b0;
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  animation: pop 0.8s ease-out forwards;
}

/* The satchel the pieces wait in. */
.satchel {
  width: min(100%, 560px);
  padding: 0.9rem 1rem 1.2rem;
  background: linear-gradient(#8a5a34, #6b4226);
  border-radius: 18px 18px 26px 26px;
  box-shadow: inset 0 0 0 4px #5e3920, 0 10px 24px rgba(0, 0, 0, 0.45);
  outline: 2px dashed rgba(244, 199, 82, 0.55);
  outline-offset: -11px;
}
.satchel[hidden] { display: none; }
.satchel__title { text-align: center; font-size: 1.1rem; color: #f4e3c3; margin-bottom: 0.7rem; }
.tray {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 14px;
  min-height: 60px;
}

.done {
  width: min(26rem, 100%);
  text-align: center;
  color: #35210f;
  background: var(--cream);
  border: 3px double var(--red);
  border-radius: 14px;
  padding: 1rem 1.2rem 1.1rem;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
  animation: rise 0.6s ease-out;
}
.done h2 { color: var(--red); }
.done p { margin: 0.3rem 0 0.8rem; }
.done .done__hint { margin: 0.8rem 0 0; font-size: 0.85rem; font-style: italic; color: #5a4630; }

.confetti { position: fixed; inset: 0; z-index: 40; pointer-events: none; overflow: hidden; }
.confetti i {
  position: absolute;
  top: -20px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  animation: fall linear forwards;
}

@keyframes settle { from { transform: scale(1.12); } }
@keyframes nope {
  20%, 60% { transform: translateX(-6px) rotate(var(--tilt, 0deg)); }
  40%, 80% { transform: translateX(6px) rotate(var(--tilt, 0deg)); }
}
@keyframes pop {
  from { opacity: 1; transform: translate(0, 0) scale(0.4); }
  to   { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1.1) rotate(160deg); }
}
@keyframes glow {
  50% { box-shadow: 0 0 40px 8px rgba(255, 214, 100, 0.8), inset 0 0 0 3px rgba(244, 199, 82, 0.6); }
}
@keyframes rise { from { opacity: 0; transform: translateY(20px); } }
@keyframes fall { to { transform: translateY(110vh) rotate(var(--spin)); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
