/* ============ 共通 ============ */
*{
  margin:0; padding:0; box-sizing:border-box;
  -webkit-tap-highlight-color:transparent;
  /* 長押しの選択・コピーメニューを無効化（子どもの誤操作防止） */
  -webkit-user-select:none; user-select:none; -webkit-touch-callout:none;
}
html,body{
  touch-action:manipulation;
  -webkit-text-size-adjust:100%;
  overscroll-behavior:none;
  height:100%;
}
body{
  font-family:"Hiragino Maru Gothic ProN","Hiragino Sans",sans-serif;
  background:#f4ead6;
  color:#1c1c1c;
  overflow:hidden;
}
.screen{
  height:100svh;
  display:flex; flex-direction:column;
}
.screen[hidden]{ display:none !important; }

/* 角丸の押しボタン（ヘッダー用） */
.top-btn{
  flex:none;
  width:52px; height:52px;
  display:flex; align-items:center; justify-content:center;
  background:#fff; border:3px solid #1c1c1c; border-radius:16px;
  box-shadow:0 4px 0 #1c1c1c;
  text-decoration:none; cursor:pointer;
  transition:transform .08s, box-shadow .08s;
}
.top-btn:active{ transform:translateY(4px); box-shadow:0 0 0 #1c1c1c; }

/* ============ えらぶ画面 ============ */
.select-screen{
  overflow-y:auto;
  gap:18px;
  padding:calc(16px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
}
.select-top{
  display:flex; align-items:center; gap:16px;
}
.select-top h1{
  font-size:24px; font-weight:800; letter-spacing:.06em;
}
.pick-grid{
  display:grid; gap:16px;
  grid-template-columns:repeat(2, 1fr);
}
@media (min-width:620px){
  .pick-grid{ grid-template-columns:repeat(3, 1fr); }
}
@media (min-width:980px){
  .pick-grid{ grid-template-columns:repeat(4, 1fr); }
}
.pick{
  position:relative;
  aspect-ratio:1;
  padding:0; overflow:hidden;
  background:#fff;
  border:4px solid #1c1c1c; border-radius:20px;
  box-shadow:0 5px 0 #1c1c1c;
  cursor:pointer;
  transition:transform .08s, box-shadow .08s;
}
.pick:active{ transform:translateY(5px); box-shadow:0 0 0 #1c1c1c; }
.pick img{
  position:absolute; inset:0;
  width:100%; height:100%;
  object-fit:cover;
  pointer-events:none;
}

/* ============ あそぶ画面 ============ */
.game-screen{
  position:relative;                 /* 操作類を上に重ねる基準 */
  padding-top:env(safe-area-inset-top);
}
/* 操作類。ヘッダーを作らず絶対配置で重ねるので、遊ぶ面の高さが削られない */
.hud{
  position:absolute; top:0; left:0; right:0;
  /* おいわいの 夜空(55)と 降ってくる 絵(60)より 上。
     おいわいの あいだも もどるボタンを 押せるように する */
  z-index:65;
  display:flex; align-items:flex-start; justify-content:space-between;
  gap:12px;
  padding:10px 14px;
  pointer-events:none;               /* すき間は下のピースを掴める */
}
.hud-left{
  display:flex; align-items:flex-start; gap:10px;
}
.hud .top-btn{ pointer-events:auto; } /* ボタンだけ反応する */

/* 右上の操作。ひろい画面では 横ならびを 2段に積む
   （上段＝ピースのかず4つ / 下段＝ヒント3つ） */
.hud-right{ display:flex; flex-direction:column; align-items:flex-end; gap:10px; }
.hud-row{ display:flex; gap:10px; }
/* えらんでいるものを塗りつぶして示す */
.hint-btn, .count-btn{ color:#1c1c1c; }
.hint-btn.is-active, .count-btn.is-active{ background:#e8913a; color:#ffffff; }

/* 原画（見本）。見ながら組み立てるので大きめに出す。
   クリックは透過させ、下に来たピースを掴めなくしない */
.ref-img{
  display:block;
  height:auto; width:auto;
  object-fit:contain;
  pointer-events:none;
  background:#fff;
  border:3px solid #1c1c1c; border-radius:12px;
  box-shadow:0 4px 0 #1c1c1c;
}
@media (max-width:560px){
  .hud{ gap:8px; padding:8px 10px; }
  .hud-left{ gap:8px; }
  /* 原画の幅を 削らないよう、縦ならびを 2列にして 横幅を おさえる */
  .hud-right{ flex-direction:row; align-items:flex-start; gap:8px; }
  .hud-row{ flex-direction:column; gap:8px; }
  .hud .top-btn{ width:44px; height:44px; border-radius:13px; }
  .ref-img{ border-radius:12px; }
}
#playArea{
  flex:1;
  position:relative;
  overflow:hidden;
  touch-action:none;   /* ドラッグ中のスクロールを止める */
}

/* 盤面 */
#boardBox{
  position:absolute;
  background:rgba(255,255,255,.55);
  outline:3px dashed rgba(28,28,28,.3);
  outline-offset:5px;
  border-radius:4px;
}
#ghostCanvas{
  display:block; width:100%; height:100%;
}

/* 完成画像（フェードイン用） */
#fullCanvas{
  position:absolute;
  opacity:0;
  pointer-events:none;
  z-index:3;
  transition:opacity 1.2s ease;
}
#fullCanvas.show{ opacity:1; }

#piecesLayer{
  position:absolute; inset:0;
}

/* ピース */
.piece{
  position:absolute; left:0; top:0;
  z-index:2;
  will-change:transform;
}
.piece.anim{ transition:transform .18s ease; }
.piece.locked{ z-index:1; }
.piece canvas{
  display:block; width:100%; height:100%;
  filter:drop-shadow(0 3px 4px rgba(0,0,0,.3));
  transition:transform .15s, filter .15s;
}
.piece.drag canvas{
  transform:scale(1.05);
  filter:drop-shadow(0 9px 12px rgba(0,0,0,.35));
}
.piece.locked canvas{
  filter:none;
  transform:none;
}

/* おいわい（夜空・はなび・降ってくる 絵）は /common/celebrate.js が うけもつ。
   重なり順も あちらに 書いてある。
   おいわいの あいだは 上の HUD も 夜空の 下に かくれる */

/* かんせいの あと 出る「つぎの え」。おいわいの ふぶき(101)より 上に のせて、
   夜空の 上でも 押せるように する。下地は 置かない（夜空が そのまま 見える）。
   さわれるのは ボタンだけで、すき間は ふぶきを たたける */
.cover{
  position:fixed; inset:0; z-index:103;
  display:flex; align-items:center; justify-content:center;
  pointer-events:none;
}
.cover[hidden]{ display:none }
.go{
  pointer-events:auto;
  padding:14px 30px;
  background:#e8913a; color:#fff;
  border:4px solid #1c1c1c; border-radius:18px;
  box-shadow:0 6px 0 #1c1c1c;
  font-family:inherit; font-size:22px; font-weight:800; letter-spacing:.06em;
  cursor:pointer;
}
.go:active{ transform:translateY(6px); box-shadow:0 0 0 #1c1c1c }
