* { 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; }
.info { font-size: 15px; }

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

.cat { width: 100%; height: 100%; display: block; }

/* 段ボール箱。マスの大きさ --cell は main.js が画面に合わせて決める */
.play { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.box {
  --cell: 48px;
  --n: 4;
  position: relative;
  padding: 10px;
  border-radius: 6px;
  background: #c98a52;
  box-shadow: inset 0 0 0 3px #3b2f2a, 0 3px 0 #a26a3a;
}
/* 箱のふた（左右に開いている） */
.box::before, .box::after {
  content: '';
  position: absolute; top: 6px; bottom: 6px; width: 10px;
  background: #dba06a;
  border: 3px solid #3b2f2a;
  border-radius: 4px;
}
.box::before { left: -9px; transform: skewY(-8deg); }
.box::after { right: -9px; transform: skewY(8deg); }
.grid {
  position: relative;
  width: calc(var(--cell) * var(--n));
  height: calc(var(--cell) * var(--n));
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  background: #8a5a32;
  border-radius: 3px;
}
.grid .hole {
  box-shadow: inset 0 0 0 1px rgba(255, 230, 190, 0.18);
  background: radial-gradient(circle, rgba(255, 230, 190, 0.18) 0 10%, transparent 12%);
}
.grid .hole.ghost { background: rgba(255, 245, 200, 0.55); }
.grid .hole.ghost.bad { background: rgba(230, 90, 90, 0.35); }

/* 猫（SVG 1枚で形・顔・しっぽを描く） */
.piece {
  position: absolute;
  touch-action: none;
  -webkit-touch-callout: none;
  cursor: grab;
}
.piece svg { display: block; width: 100%; height: 100%; overflow: visible; }
.grid .piece { z-index: 1; }
.grid .piece.dragging-src { opacity: 0.25; }
.grid.cleared .piece { animation: hop 0.7s ease-in-out 2; }
@keyframes hop {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-8%); }
}

/* 置き場 */
.tray {
  width: 100%;
  display: flex; flex-wrap: wrap; justify-content: center; align-content: flex-start; gap: 8px;
  padding: 10px;
  border-radius: 14px;
  background: #efe2cc;
}
.tray .slot {
  position: relative;
  padding: 6px;
  border-radius: 10px;
  background: #f8efe0;
  touch-action: none;
}
.tray .slot .piece { position: relative; }
.tray .slot.dragging-src { opacity: 0.3; }
.tray .slot.turned .piece { animation: spin 0.2s ease-out; }
@keyframes spin { from { transform: rotate(-90deg); } to { transform: rotate(0); } }
.tray-empty { margin: 0; font-size: 14px; opacity: 0.6; align-self: center; }

/* 引っぱっている猫（指の少し上に出す） */
.floating {
  position: fixed;
  z-index: 5;
  pointer-events: none;
  filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.3));
  cursor: grabbing;
}
.floating svg { display: block; width: 100%; height: 100%; overflow: visible; }

.hint { margin: 0; font-size: 13px; opacity: 0.65; text-align: center; }

/* ヒント（ボタンの色・光り方はレーザーポインター・ねこの寝かしつけとそろえる） */
.below-row { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.below-row .hint { flex: 1; text-align: left; }
.below-row .hint.hint-on { opacity: 1; font-weight: bold; color: #8a6a00; }
.btn-hint { background: #7d86b5; flex: none; }
.btn-hint:disabled { opacity: 0.5; }
/* 入れる場所: 箱のマスを薄い黄色の影にし、その上に猫を薄く重ねる（向きがわかるように） */
.grid .hole.hint-spot { background: rgba(255, 211, 77, 0.35); box-shadow: inset 0 0 0 2px rgba(199, 154, 0, 0.9); }
.grid .hint-ghost { opacity: 0.4; pointer-events: none; z-index: 0; }
/* 光らせる猫 */
.tray .slot.hinted { box-shadow: inset 0 0 0 4px #ffd34d, 0 0 12px 2px rgba(255, 211, 77, 0.8); animation: glow 1s ease-in-out infinite; }
.grid .piece.hinted { animation: glow-piece 1s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: inset 0 0 0 4px #ffe58a, 0 0 4px 1px rgba(255, 211, 77, 0.4); } }
@keyframes glow-piece {
  0%, 100% { filter: drop-shadow(0 0 3px #ffd34d) drop-shadow(0 0 6px rgba(255, 211, 77, 0.9)); }
  50% { filter: drop-shadow(0 0 1px #ffe58a) drop-shadow(0 0 2px rgba(255, 211, 77, 0.4)); }
}
/* 結果 */
.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-card .overlay-sub { font-size: 15px; margin: -8px 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: 32px !important; font-weight: bold; margin-bottom: 8px !important; white-space: nowrap; }
.title-name + .menu-buttons { margin-top: 28px; }
.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; }
