/* ==========================================================
   puzzle.css
   パズルのモーダル（パズル① first。retry でも使う予定）
   見た目は Elementor版（Galaxy S26で確認した状態）に合わせています。

   パネル全体を「基準px」で組み、JSが画面に合わせて
   --pz-scale 倍に拡大縮小します（ガイドとピースの比率を守るため）。
========================================================== */

/* モーダルを開いている間だけ、後ろのページをスクロールさせない */
html.is-modal-open,
html.is-modal-open body {
  overflow: hidden;
}


/* ---------- 画面全体を覆う暗幕 ---------- */

.pz-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  touch-action: none;             /* モーダル上ではスクロール・ズームしない */
  overscroll-behavior: contain;
  user-select: none;
  -webkit-user-select: none;
}

.pz-modal.is-open {
  display: flex;
}


/* ---------- 拡大縮小の枠（中身は基準pxのまま） ---------- */

.pz-frame {
  --pz-scale: 1;
  flex: none;
  padding-top: 34px;              /* 閉じるボタンの分 */
  transform: scale(var(--pz-scale));
  transform-origin: center center;
}


/* ---------- パネル ---------- */

.pz-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 25px 15px 20px;
  background: #f3d69a;
  border: 1px solid #333;
}

.pz-modal.is-open .pz-panel {
  animation: pzAppear 0.35s ease-out;
}

@keyframes pzAppear {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

.pz-title {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Noto Sans CJK JP", Meiryo, sans-serif;
  font-size: 24.5px;
  font-weight: 600;
  line-height: 1;
  text-align: center;
  color: #000;
}


/* ---------- 閉じるボタン（パネル右上の外側） ---------- */

.pz-close {
  position: absolute;
  top: -34px;
  right: 10.5px;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.pz-close svg {
  display: block;
  width: 100%;
  height: 100%;
}


/* ---------- 盤面（265×429 基準px） ---------- */

.pz-board {
  position: relative;
  box-sizing: content-box;
  width: 265px;
  height: 429px;
  background: #f8ebcf;
  border: 1px solid #000;
}

/* ピースの座標空間（盤面の内側の左上が 0,0） */
.pz-space {
  position: absolute;
  inset: 0;
  overflow: visible;
  touch-action: none;
}

.pz-guide {
  position: absolute;
  z-index: 2;
  display: block;
  max-width: none;
  pointer-events: none;
}


/* ---------- ピース ---------- */

.pz-piece {
  position: absolute;
  z-index: 10;
  display: block;
  max-width: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  pointer-events: none;           /* 判定は盤面側で透明部分を見て行う */
}

.pz-piece.is-dragging {
  cursor: grabbing;
}

/* ---------- retry（解き直し）の見た目：Elementor版の retry に合わせる ----------
   角丸のパネル・枠線なし、盤面は透明（大きさ・座標は first と同じ基準px） */

.pz-modal--retry .pz-panel {
  border-color: transparent;      /* 枠線は見せないが、幅は first と同じにする */
  border-radius: 12px;
}

.pz-modal--retry .pz-board {
  background: transparent;
  border-color: transparent;
}

/* 吸着して固定されたピース：背面へ回り、軽くポンと弾む */
.pz-piece.is-solved {
  z-index: 4;
  animation: pzSnapPop 0.25s ease;
}

@keyframes pzSnapPop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}


/* ---------- 完成したときの「完成！」（STEP T） ----------
   最後のピースがはまった瞬間に、盤面の上（ガイドより上の空いている所）に
   ふわっと出て、少し大きくなってから止まる。キラッと光る小さな星つき。
   一度出たら、パズルを閉じるまで表示したまま */
.pz-done {
  position: absolute;
  z-index: 20;
  top: 10px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  visibility: hidden;
}

.pz-done__text {
  position: relative;
  padding: 4px 22px 6px;
  border: 2px solid #9b3a24;
  border-radius: 6px;
  background: #fff8e8;
  box-shadow: 0 3px 0 rgba(155, 58, 36, 0.25), 0 6px 14px rgba(0, 0, 0, 0.18);
  color: #9b3a24;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Noto Sans CJK JP", Meiryo, sans-serif;
  font-size: 30px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

/* 左上と右下の小さな星 */
.pz-done__text::before,
.pz-done__text::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  background: #e8b53a;
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  opacity: 0;
}
.pz-done__text::before { top: -9px; left: -9px; }
.pz-done__text::after  { right: -8px; bottom: -8px; width: 12px; height: 12px; }

.pz-done.is-shown {
  visibility: visible;
}
.pz-done.is-shown .pz-done__text {
  animation: pzDoneIn 0.55s cubic-bezier(0.2, 1.3, 0.4, 1) both;
}
.pz-done.is-shown .pz-done__text::before,
.pz-done.is-shown .pz-done__text::after {
  animation: pzDoneSparkle 0.7s ease-out 0.3s both;
}

/* 完成済みのパズルをもう一度開いたときは、動きなしで表示 */
.pz-done.is-static .pz-done__text,
.pz-done.is-static .pz-done__text::before,
.pz-done.is-static .pz-done__text::after {
  animation: none;
}
.pz-done.is-static .pz-done__text::before,
.pz-done.is-static .pz-done__text::after {
  opacity: 1;
}

@keyframes pzDoneIn {
  0%   { opacity: 0; transform: scale(0.5); }
  60%  { opacity: 1; transform: scale(1.12); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes pzDoneSparkle {
  0%   { opacity: 0; transform: scale(0.2) rotate(0deg); }
  50%  { opacity: 1; transform: scale(1.3) rotate(45deg); }
  100% { opacity: 1; transform: scale(1) rotate(90deg); }
}

/* 完成済みのパズルを表示しているとき：ピースは固定（吸着の動きもなし） */
.pz-piece.is-static {
  animation: none;
  cursor: default;
}

@media (prefers-reduced-motion: reduce) {
  .pz-done.is-shown .pz-done__text,
  .pz-done.is-shown .pz-done__text::before,
  .pz-done.is-shown .pz-done__text::after {
    animation: none;
    opacity: 1;
  }
}
