/* まるっとスライドパズル — board.css（盤）担当 B
 * 木の枠／くぼんだ盤面／ピース（絵の切り出し・すきま・丸い角・うすい影）／番号札／
 * ヒントの光／みほん／完成の演出。大きさは board.js が CSS 変数で入れる：
 *   --sp-frame 枠の太さ  --sp-gap すきま  --sp-rad 角の丸み  --sp-num 番号の文字  --sp-pic 絵
 * 盤の外の大きさは親（containerEl）が決める。盤はその中で正方形にいっぱい広がる。
 */

.sp-board-host {
  position: relative; width: 100%; height: 100%; min-width: 0; min-height: 0;
  display: flex; align-items: center; justify-content: center;
}

/* ---- 木の枠 ---- */
.sp-board {
  --sp-frame: 14px; --sp-gap: 2.5px; --sp-rad: 8px; --sp-num: 18px; --sp-outer-rad: 18px;
  touch-action: none;           /* 木の枠から始めたスワイプも盤の操作に（ページが動かないように・盤だけ） */
  --sp-land: 150ms; --sp-fade: 320ms;
  position: relative; flex: 0 0 auto;
  width: min(100%, 100vh); aspect-ratio: 1 / 1;   /* JS が動く前の仮の大きさ */
  padding: var(--sp-frame);
  border-radius: var(--sp-outer-rad);
  background:
    /* 木目（ゆるい縞） */
    repeating-linear-gradient(97deg, rgba(255, 236, 200, .06) 0 2px, rgba(0, 0, 0, 0) 2px 9px, rgba(90, 50, 20, .07) 9px 11px, rgba(0, 0, 0, 0) 11px 19px),
    radial-gradient(120% 70% at 30% 0%, rgba(255, 228, 180, .35), rgba(255, 228, 180, 0) 60%),
    linear-gradient(165deg, #D19B62 0%, #B9834F 38%, #9E6A3C 75%, #8A5A33 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 238, 205, .55),
    inset 0 -3px 0 rgba(70, 38, 14, .35),
    inset 0 0 0 1px rgba(70, 38, 14, .25),
    0 4px 0 #6E4526,
    0 14px 28px rgba(74, 52, 38, .28);
}
/* 枠の内がわの細い溝 */
.sp-board::before {
  content: ""; position: absolute; pointer-events: none;
  inset: calc(var(--sp-frame) * .45);
  border-radius: calc(var(--sp-outer-rad) * .7);
  box-shadow: inset 0 1px 0 rgba(70, 38, 14, .28), 0 1px 0 rgba(255, 236, 200, .35);
}

/* ---- くぼんだ盤面（あいたマスはここが見える） ---- */
.sp-field {
  position: relative; width: 100%; height: 100%; overflow: hidden;
  border-radius: calc(var(--sp-rad) + 2px);
  background:
    repeating-linear-gradient(90deg, rgba(255, 220, 170, .03) 0 3px, rgba(0, 0, 0, 0) 3px 8px),
    linear-gradient(180deg, #5A3A22, #6B4529);
  box-shadow: inset 0 3px 8px rgba(30, 14, 4, .55), inset 0 0 0 1px rgba(30, 14, 4, .4);
  touch-action: none;           /* スワイプでページが動かないように（盤だけ） */
  cursor: pointer;
  outline: none;
}
.sp-board.is-locked .sp-field { cursor: default; }
.sp-tiles { position: absolute; inset: 0; }

/* ---- ピース ---- */
.sp-tile {
  position: absolute; left: 0; top: 0;
  width: calc(100% / var(--sp-cols, 3)); height: calc(100% / var(--sp-rows, 3));
  transform: translate3d(0, 0, 0);
  transition-property: transform;
  transition-duration: 125ms;
  transition-timing-function: cubic-bezier(.2, .85, .25, 1);  /* すっと出て、やわらかく止まる */
  will-change: transform;
  z-index: 1;
}
.sp-tile.is-moving { z-index: 2; }
.sp-tile.is-shuffle { transition-timing-function: cubic-bezier(.35, .2, .3, 1); }

/* うすい影の台（すきまの内がわ） */
.sp-tile::before {
  content: ""; position: absolute; pointer-events: none;
  inset: var(--sp-gap); border-radius: var(--sp-rad);
  box-shadow: 0 2px 2px rgba(25, 10, 2, .38), 0 3px 8px rgba(25, 10, 2, .22);
  transition: opacity var(--sp-fade) ease, inset var(--sp-fade) ease;
}

/* 絵の面：1枚の絵を、そのピースの所だけ見せる。すきまと角は clip-path で */
.sp-face {
  position: absolute; inset: 0;
  background-color: #EEDDC4;
  background-image: var(--sp-pic, none);
  background-size: calc(var(--sp-cols, 3) * 100%) calc(var(--sp-rows, 3) * 100%);
  background-repeat: no-repeat;
  clip-path: inset(var(--sp-gap) round var(--sp-rad));
  -webkit-clip-path: inset(var(--sp-gap) round var(--sp-rad));
  transition: clip-path var(--sp-fade) ease, -webkit-clip-path var(--sp-fade) ease, filter .2s ease;
}
/* ふちの光と陰（ほんのり立体） */
.sp-face::after {
  content: ""; position: absolute; pointer-events: none;
  inset: var(--sp-gap); border-radius: var(--sp-rad);
  box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, .42), inset 0 -2px 0 rgba(40, 20, 5, .16), inset 0 0 0 1px rgba(255, 255, 255, .12);
  transition: opacity var(--sp-fade) ease;
}

/* あきのピース（右下の1枚）。ふだんは見せない */
.sp-tile.is-blank { opacity: 0; z-index: 0; transition: opacity var(--sp-fade) ease; }

/* ---- 番号札（左上の小さな丸） ---- */
.sp-num {
  position: absolute; z-index: 1;
  left: calc(var(--sp-gap) + var(--sp-num) * .22); top: calc(var(--sp-gap) + var(--sp-num) * .22);
  min-width: calc(var(--sp-num) * 1.45); height: calc(var(--sp-num) * 1.45); padding: 0 .18em; box-sizing: border-box;
  border-radius: 999px; display: none; align-items: center; justify-content: center;
  font-size: var(--sp-num); line-height: 1; font-weight: 900; letter-spacing: 0;
  color: var(--ink, #4A3426); background: rgba(255, 253, 248, .92);
  box-shadow: 0 1px 2px rgba(40, 20, 5, .35), inset 0 0 0 1.5px rgba(74, 52, 38, .18);
  font-variant-numeric: tabular-nums;
}
.sp-board.is-numbers .sp-num,
.sp-board.is-noimg .sp-num { display: flex; }
.sp-board.is-complete:not(.is-noimg) .sp-num { display: none; }
.sp-tile.is-blank .sp-num { display: none; }

/* ---- 絵が読めないとき：やさしい色のグラデーション（つながって見える）＋大きな番号 ---- */
.sp-board.is-noimg .sp-face {
  background-image:
    radial-gradient(60% 60% at 25% 20%, rgba(255, 255, 255, .55), rgba(255, 255, 255, 0) 70%),
    linear-gradient(135deg, #F8C98F 0%, #F3A6A0 35%, #C8B2E0 65%, #93C3E6 100%);
}
.sp-board.is-noimg .sp-num {
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  font-size: calc(var(--sp-num) * 1.4); min-width: calc(var(--sp-num) * 2.1); height: calc(var(--sp-num) * 2.1);
  background: rgba(255, 253, 248, .85);
}

/* ---- 置いたときの「コトッ」／動かせないときの首ふり ---- */
.sp-face.is-land-x { animation: sp-land-x 150ms ease-out both; }
.sp-face.is-land-y { animation: sp-land-y 150ms ease-out both; }
@keyframes sp-land-x { 0% { transform: scale(.975, 1); } 45% { transform: scale(1.006, .996); } 100% { transform: none; } }
@keyframes sp-land-y { 0% { transform: scale(1, .975); } 45% { transform: scale(.996, 1.006); } 100% { transform: none; } }

.sp-face.is-bump { animation: sp-bump 280ms ease-in-out both; }
@keyframes sp-bump {
  0% { transform: none; }
  20% { transform: rotate(-2.4deg) translateX(-1.5%); }
  45% { transform: rotate(2deg) translateX(1.2%); }
  70% { transform: rotate(-1deg) translateX(-.5%); }
  100% { transform: none; }
}
.sp-field.is-bump-x { animation: sp-bump-x 260ms ease-in-out both; }
.sp-field.is-bump-y { animation: sp-bump-y 260ms ease-in-out both; }
@keyframes sp-bump-x { 0%, 100% { transform: none; } 25% { transform: translateX(-3px); } 55% { transform: translateX(2.5px); } 80% { transform: translateX(-1px); } }
@keyframes sp-bump-y { 0%, 100% { transform: none; } 25% { transform: translateY(-3px); } 55% { transform: translateY(2.5px); } 80% { transform: translateY(-1px); } }

/* ---- ヒントの光（あたたかい黄色・ゆっくり息をする） ---- */
.sp-tile::after {
  content: ""; position: absolute; pointer-events: none; z-index: 3;
  inset: var(--sp-gap); border-radius: var(--sp-rad);
  opacity: 0; transition: opacity .2s ease;
  box-shadow: inset 0 0 0 3px #FFD56A, inset 0 0 18px rgba(255, 213, 106, .75), 0 0 0 2px rgba(255, 236, 170, .9), 0 0 16px 4px rgba(255, 200, 80, .65);
}
.sp-tile.is-hint { z-index: 3; }
.sp-tile.is-hint::after { opacity: 1; animation: sp-hint 1.1s ease-in-out infinite; }
.sp-tile.is-hint .sp-face { filter: brightness(1.1) saturate(1.05); }
@keyframes sp-hint { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

/* ---- 混ぜている間は、すこしだけ落ちついた色（「まださわらないで」の合図） ---- */
.sp-board.is-shuffling .sp-field { cursor: default; }

/* ---- みほん（完成の絵を上にかさねる） ---- */
.sp-peek {
  position: absolute; inset: 0; z-index: 6; pointer-events: none;
  opacity: 0; transition: opacity .18s ease;
}
.sp-peek-pic {
  position: absolute; inset: 0; border-radius: inherit;
  background-color: #EEDDC4; background-image: var(--sp-pic, none);
  background-size: 100% 100%; background-repeat: no-repeat;
  display: flex; flex-wrap: wrap;
}
.sp-board.is-noimg .sp-peek-pic {
  background-image: linear-gradient(135deg, #F8C98F 0%, #F3A6A0 35%, #C8B2E0 65%, #93C3E6 100%);
}
.sp-peek-cell {
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--sp-num) * 1.5); font-weight: 900; color: var(--ink, #4A3426);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .5);
}
.sp-peek-tag {
  position: absolute; left: 10px; top: 10px; padding: 4px 12px; border-radius: 999px;
  background: rgba(74, 52, 38, .82); color: #fff; font-size: 15px; font-weight: 800; letter-spacing: .1em;
}
.sp-board.is-peek .sp-peek { opacity: 1; }
.sp-board.is-peek .sp-field { cursor: default; }

/* ---- 完成の1枚絵：すきまが閉じる ---- */
.sp-board.is-complete .sp-face { clip-path: inset(0 round 0); -webkit-clip-path: inset(0 round 0); }
.sp-board.is-complete .sp-face::after { opacity: 0; }
.sp-board.is-complete .sp-tile::before { opacity: 0; }
.sp-board.is-complete .sp-tile.is-blank,
.sp-board.is-celebrate .sp-tile.is-blank { opacity: 1; z-index: 1; }

/* もどってくる1枚 */
.sp-face.is-arrive { animation: sp-arrive 460ms cubic-bezier(.2, .9, .3, 1.15) both; }
@keyframes sp-arrive {
  0% { opacity: 0; transform: scale(1.18) translateY(-6%); filter: brightness(1.25); }
  60% { opacity: 1; }
  100% { opacity: 1; transform: none; filter: none; }
}

/* 光がよぎる */
.sp-shine {
  position: absolute; inset: -20%; z-index: 7; pointer-events: none; opacity: 0;
  background: linear-gradient(115deg, rgba(255, 255, 255, 0) 38%, rgba(255, 252, 235, .55) 48%, rgba(255, 255, 255, .8) 50%, rgba(255, 252, 235, .55) 52%, rgba(255, 255, 255, 0) 62%);
  transform: translateX(-70%);
}
.sp-shine.is-run { animation: sp-shine 820ms cubic-bezier(.45, .05, .35, 1) both; }
@keyframes sp-shine {
  0% { opacity: 0; transform: translateX(-70%); }
  15% { opacity: 1; }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translateX(70%); }
}
.sp-board.is-glow { animation: sp-glow 820ms ease-out both; }
@keyframes sp-glow {
  0% { transform: scale(1); }
  30% { transform: scale(1.012); }
  100% { transform: scale(1); }
}

/* ---- 動きをひかえる設定 ---- */
@media (prefers-reduced-motion: reduce) {
  .sp-tile { transition-timing-function: ease-out; }
  .sp-face.is-land-x, .sp-face.is-land-y, .sp-face.is-bump,
  .sp-field.is-bump-x, .sp-field.is-bump-y, .sp-board.is-glow { animation: none; }
  .sp-tile.is-hint::after { animation: none; }
  .sp-shine.is-run { animation-name: sp-fade; }
}
