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

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

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

/* 猫ベッド */
.beds { display: flex; gap: 10px; }
.bed-cell { flex: 1; position: relative; display: flex; }
.bed {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border-radius: 40px;
  background: #c98a6b;
  box-shadow: inset 0 -6px 0 #a96c50;
  min-height: 64px;
}
.bed.empty { justify-content: center; color: #fff; font-size: 13px; opacity: 0.6; }
.bed-want { width: 44px; height: 44px; flex: none; }
.bed-slots { display: flex; gap: 4px; flex: 1; justify-content: center; }
.slot {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: #f4dccb;
}
.slot.filled { background: transparent; }

/* 3匹そろって完成したベッド（T50）。次のベッドの上に重ねて、弾んでから上へ消える */
.bed-done {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: #e5a07f;
  box-shadow: inset 0 -6px 0 #c47f5f, 0 0 0 3px #f2b632;
  animation: bed-done calc(var(--done) + var(--fade)) ease-out forwards;
}
@keyframes bed-done {
  0%   { transform: scale(1); opacity: 1; }
  14%  { transform: scale(1.07) translateY(-6px); }
  28%  { transform: scale(0.97); }
  42%  { transform: scale(1.03); }
  56%  { transform: scale(1); opacity: 1; }
  75%  { transform: scale(1); opacity: 1; }
  100% { transform: translateY(-26px) scale(0.9); opacity: 0; }
}
.bed-done .slot .cat { animation: bed-done-cat 0.4s ease-in-out 2 alternate; }
@keyframes bed-done-cat { 0% { transform: translateY(0); } 100% { transform: translateY(-5px); } }

/* こたつからベッドへ飛んでいく猫（T51）。結果の画面（z-index: 10）より下 */
.fly-layer { position: fixed; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
.fly-cat { position: absolute; left: 0; top: 0; display: flex; filter: drop-shadow(0 3px 2px rgba(0,0,0,0.2)); }
.fly-cat .cat { width: 92%; height: 92%; margin: auto; }

/* 盤面 */
.board {
  position: relative;
  width: 100%;
  overflow: hidden;
  border-radius: 12px;
  background: #f1e2c8;
}
.box {
  position: absolute;
  left: 0; top: 0;
  padding: 0;
  border: none;
  background: #d9a86c;
  box-shadow: inset 0 0 0 2px #b9874e, inset 0 6px 0 rgba(255,255,255,0.18);
  border-radius: 6px;
  transition: transform 0.18s ease-in;
  cursor: pointer;
  display: flex;
}
.box .cat { width: 84%; height: 84%; margin: auto; }
.box:disabled { cursor: default; }
.box.shake { animation: shake 0.3s; }
@keyframes shake {
  0%, 100% { margin-left: 0; }
  25% { margin-left: -5px; }
  75% { margin-left: 5px; }
}

/* こたつ */
/* こたつ: 木の天板（みかん付き）と、格子柄の布団。猫は布団から顔だけ出す */
.kotatsu-wrap {
  --futon: repeating-linear-gradient(0deg, rgba(255,240,220,0.22) 0 3px, transparent 3px 16px),
           repeating-linear-gradient(90deg, rgba(255,240,220,0.22) 0 3px, transparent 3px 16px),
           repeating-linear-gradient(90deg, rgba(110,25,25,0.12) 0 2px, transparent 2px 8px),
           #d9534f;
  position: relative;
}
.kotatsu-top {
  position: relative;
  z-index: 2;
  height: 26px;
  margin: 0 -6px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 6px;
  background: linear-gradient(#cf935b, #a96c3b);
  box-shadow: 0 3px 0 #7d4f2a, inset 0 2px 0 rgba(255,255,255,0.25);
}
.kotatsu-label { color: #fff8ec; font-size: 13px; font-weight: bold; text-shadow: 0 1px 0 rgba(0,0,0,0.25); }
.mikan { width: 36px; height: 22px; margin-top: -10px; }
.kotatsu-futon {
  padding: 12px 10px 16px;
  background: var(--futon);
  border-radius: 0 0 26px 26px / 0 0 16px 16px;
  box-shadow: inset 0 -6px 0 rgba(150, 40, 40, 0.55), inset 0 6px 6px -4px rgba(0,0,0,0.25);
}
.kotatsu { display: flex; gap: 6px; }
.kslot {
  position: relative;
  flex: 1;
  aspect-ratio: 1;
  display: flex;
  border-radius: 45% 45% 10px 10px;
  background: rgba(70, 15, 15, 0.22);
  overflow: hidden;
}
.kslot .cat { width: 92%; height: 92%; margin: 8% auto 0; }
/* 布団のすそ。猫の首から下を隠す */
.kslot.filled::after {
  content: '';
  position: absolute;
  left: -3px; right: -3px; bottom: 0;
  height: 30%;
  background: var(--futon);
  border-radius: 40% 40% 0 0 / 70% 70% 0 0;
  box-shadow: 0 -2px 3px rgba(0,0,0,0.18);
}
.kotatsu.full .kslot { background: rgba(70, 15, 15, 0.32); }
/* 入ってきた猫は、布団の中から顔を出す */
.kslot.enter .cat { animation: kotatsu-in 0.35s ease-out; }
@keyframes kotatsu-in { 0% { transform: translateY(45%); } 100% { transform: translateY(0); } }
/* ベッドへ移る順番を待っている猫は、うれしそうに弾む（T51） */
.kslot.leaving .cat { animation: kotatsu-hop 0.3s ease-in-out infinite alternate; }
@keyframes kotatsu-hop { 0% { transform: translateY(0); } 100% { transform: translateY(-14%); } }

/* 結果 */
.overlay {
  position: fixed; inset: 0;
  z-index: 10; /* 盤やこたつの上に重ねる（こたつの天板は z-index: 2） */
  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-buttons { display: flex; gap: 10px; justify-content: center; }
.btn-sub { background: #b9a08a; }
.overlay-stamp { font-size: 15px; margin: -4px 0 18px; }
.overlay-stamp[hidden] { display: none; }
.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: 34px !important; font-weight: bold; margin-bottom: 8px !important; }
.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; }
.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; }
.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; }
