* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #fbf3e6;
  color: #4a3a30;
  font-family: -apple-system, "Hiragino Maru Gothic ProN", "Hiragino Sans", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* 上の帯（戻る・やり直す）の下の部分を、残りの場所の真ん中に置く。
   盤が画面の上に寄って、下半分が空かないようにするため（T04） */
.app { min-height: 100vh; min-height: 100dvh; }
.app > .top + * { margin-top: auto; }
.app > :last-child { margin-bottom: auto; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.info { font-size: 15px; text-align: center; }

.btn {
  font: inherit;
  font-size: 15px;
  padding: 8px 16px;
  border: none;
  border-radius: 999px;
  background: #e0884a;
  color: #fff;
}
.btn-sub { background: #b9a08a; }
.btn:disabled { opacity: 0.5; }

/* 盤面: 木の額縁に写真 */
.board {
  position: relative;
  padding: 8px;
  border-radius: 14px;
  background: #c98a52;
  box-shadow: inset 0 0 0 3px #a86d3c;
}
.tiles {
  position: relative;
  aspect-ratio: 1;
  border-radius: 6px;
  background: #6b4a33;
  overflow: hidden;
}
/* かけら。位置は main.js が transform で決める */
.tile {
  position: absolute;
  left: 0; top: 0;
  width: calc(100% / var(--n, 3));
  height: calc(100% / var(--n, 3));
  padding: 0;
  border: none;
  border-radius: 0;
  background-color: #fff6e4;
  background-repeat: no-repeat;
  background-size: calc(var(--n, 3) * 100%) calc(var(--n, 3) * 100%);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.85), inset 0 0 0 3px rgba(60, 40, 30, 0.25);
  cursor: pointer;
  transition: transform 0.16s ease-out, box-shadow 0.4s;
}
.tiles.no-anim .tile { transition: none; }
.tile:disabled { cursor: default; }
/* 空きマス（右下のかけら）。そろうまでは絵の代わりに、こげ茶のしま模様と点線の枠と肉球を見せる（T55）。
   写真のどこにもなさそうな見た目にして、一目で「空いている」とわかるようにする */
.tile.blank { pointer-events: none; box-shadow: none; }
.tile .hole {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: repeating-linear-gradient(135deg, #5a3c28 0 8px, #6e4a32 8px 16px);
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.45);
  transition: opacity 0.6s;
}
.tile .hole::after {
  content: '';
  position: absolute; inset: 6%;
  border: 3px dashed rgba(255, 236, 205, 0.85);
  border-radius: 8px;
}
.tile .hole .paw { width: 44%; height: 44%; fill: rgba(255, 236, 205, 0.75); transform: rotate(-12deg); }

/* 空きマスのとなり（タップで1マスすべるかけら）は、空きマスの色に合わせたオレンジの枠で少し目立たせる */
.tile.movable { box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.85), inset 0 0 0 4px rgba(240, 150, 70, 0.9); }

/* 番号（絵の正しい順番） */
.tile .num {
  position: absolute; left: 4px; top: 4px;
  min-width: 20px; padding: 1px 5px;
  border-radius: 999px;
  font-size: 12px; font-weight: bold; line-height: 18px;
  background: rgba(255, 250, 242, 0.88); color: #4a3a30;
  display: none;
}
.tiles.show-numbers .tile .num { display: block; }
.tiles.show-numbers .tile.home .num { background: rgba(124, 185, 122, 0.92); color: #fff; }

/* そろったとき: 最後のマスが埋まり、かけらの線が消えて写真が1枚になる */
.board.done .tile { box-shadow: none; }
.board.done .tile .hole { opacity: 0; }
.board.done .tile .num { display: none !important; }

/* お手本: 盤の上に元の絵を重ねる（タップで閉じる） */
.sample {
  position: absolute; inset: 8px;
  border-radius: 6px;
  background-size: cover;
  background-position: center;
  cursor: pointer;
}
.sample[hidden] { display: none; }
.sample-label {
  position: absolute; left: 8px; top: 8px;
  padding: 2px 10px; border-radius: 999px;
  font-size: 13px; background: rgba(255, 250, 242, 0.9);
}

/* 盤の下: 動かした回数と、番号・お手本のボタン */
.below {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 12px; gap: 8px;
}
.moves { font-size: 15px; }
.below-buttons { display: flex; gap: 8px; }
.btn-tool { background: #8a9fb5; padding: 8px 14px; }
.btn-tool[aria-pressed="true"] { background: #5d7891; }

/* 結果 */
.overlay {
  position: fixed; inset: 0;
  z-index: 10; /* 盤の上の部品より上に重ねる */
  background: rgba(60, 40, 30, 0.45);
  display: flex; align-items: center; justify-content: center;
}
.overlay[hidden] { display: none; }
.overlay-card {
  background: #fffaf2;
  padding: 24px 32px;
  border-radius: 16px;
  text-align: center;
}
.overlay-card p { font-size: 22px; margin: 0 0 16px; }
.overlay-photo {
  width: 140px; height: 140px; margin: -4px auto 14px;
  border-radius: 10px;
  border: 4px solid #fff;
  box-shadow: 0 2px 8px rgba(60, 40, 30, 0.3);
  background-size: cover; background-position: center;
  transform: rotate(-3deg);
}
.overlay-card .overlay-moves { font-size: 15px; margin: 0 0 14px; opacity: 0.8; }
.overlay-buttons { display: flex; gap: 10px; justify-content: center; }
.overlay-stamp { font-size: 15px; margin: 0 0 18px; }
.overlay-paws { display: flex; justify-content: center; gap: 6px; margin-bottom: 6px; }
.overlay-paws .paw { width: 40px; height: 40px; fill: #e5728a; transform: rotate(-12deg); }
.back-link { display: block; margin-top: 8px; font-size: 15px; color: #8a6f5a; text-decoration: none; padding: 8px; }

/* ホーム・遊び方画面（難易度はホーム画面で選ぶ） */
.screen { background: #fbf3e6; }
.screen .overlay-card { background: transparent; width: min(320px, 100%); }
.title-name { font-size: 30px !important; font-weight: bold; margin-bottom: 8px !important; white-space: nowrap; }
.photo-note { font-size: 14px !important; margin: 0 0 4px !important; opacity: 0.8; line-height: 1.5; }
.title-name + .photo-note + .menu-buttons { margin-top: 24px; }
.home-modes { margin: 6px 0 0; }
.screen-title { font-size: 24px !important; font-weight: bold; }
.menu-buttons { display: flex; flex-direction: column; gap: 14px; }
.btn-big { font-size: 20px; padding: 14px 0; width: 100%; }
.option-group { margin-bottom: 28px; text-align: left; }
.option-label { font-size: 15px; margin-bottom: 8px; }
.modes { display: flex; gap: 8px; }
.mode-choice {
  flex: 1;
  font: inherit;
  font-size: 15px;
  padding: 12px 2px;
  white-space: nowrap;
  border-radius: 12px;
  border: 3px solid transparent;
  background: #eadfd2;
  color: #6b5a4c;
}
.mode-choice.selected { color: #fff; border-color: #4a3a30; }
.mode-easy.selected { background: #7cb97a; }
.mode-normal.selected { background: #e0884a; }
.mode-hard.selected { background: #c95a5a; }
.mode-choice small { display: block; font-size: 12px; opacity: 0.85; }
.howto-card { width: min(400px, 100%) !important; text-align: left; }
.howto-card .screen-title { text-align: center; }
.howto-list { margin: 0 0 16px; padding-left: 1.4em; font-size: 15px; line-height: 1.6; }
.howto-list li { margin-bottom: 8px; }
.howto-tip { font-size: 14px !important; margin: 0 0 10px !important; opacity: 0.85; }
.howto-card .btn-big { margin-top: 12px; }
