* { 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; }
.top .btn { flex: none; white-space: nowrap; }
/* 帯の真ん中の文は2行（1行目: ゲーム名・難易度、2行目: 光が届いた猫の数）。
   1行だと、むずかしいで「戻る」「やり直す」が2行に折れたため（T72）。帯が高くならないよう行間を詰める */
.info { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; text-align: center; line-height: 1.2; }
.info-mode { font-size: 12px; opacity: 0.75; }
.info-count { 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; }
/* 盤面。マスは CSS grid で並べる（--size × --size）。光の線は上に重ねた SVG で描くので、
   マスの間にすき間（gap）は作らない（すき間があると、マスの位置と線の位置がずれる） */
.board {
  padding: 10px;
  border-radius: 14px;
  background: #8a6f5a;
}
.field {
  --size: 5;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--size), 1fr);
  -webkit-touch-callout: none;
}
.cell {
  aspect-ratio: 1;
  padding: 0;
  border: none;
  font: inherit;
  background: #f3e3c6;
  /* 床の板の継ぎ目 */
  box-shadow: inset 0 0 0 1px rgba(120, 85, 40, 0.18);
  display: flex; align-items: center; justify-content: center;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
.cell.alt { background: #f7ebd3; }
/* 鏡: 銀色の板。向きは JS で回す（回すたびに 90 度ずつ足して、いつも同じ向きにくるっと回る） */
button.cell { cursor: pointer; }
.mirror {
  width: 96%;
  height: 16%;
  border-radius: 6px;
  background: linear-gradient(#ffffff, #b9d4e6 45%, #8fb3cc 55%, #e6f2fa);
  box-shadow: 0 0 0 2px #4a5a6a, 0 2px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s ease-out;
}
button.cell:active .mirror { filter: brightness(1.15); }
/* 鏡の台（タップできるマスの目印） */
button.cell { background: radial-gradient(circle, #e9eef3 0 34%, transparent 36%), #f3e3c6; }
button.cell.alt { background: radial-gradient(circle, #e9eef3 0 34%, transparent 36%), #f7ebd3; }
.cat-wrap { width: 88%; height: 88%; transition: transform 0.9s cubic-bezier(.3,.1,.3,1); }
.cell.cat-cell { background: #e6dccd; }
.cell.cat-cell.lit { background: #ffd6d2; }
.cell.cat-cell.lit .cat-wrap { animation: hop 0.9s ease-in-out infinite; }
@keyframes hop {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-10%) rotate(-4deg); }
}
.cell.cat-cell:not(.lit) .cat-wrap { filter: saturate(0.6); opacity: 0.85; }
.cell.cat-cell.lit.chase .cat-wrap { animation: none; }
.pointer, .box { width: 92%; height: 92%; display: block; }

/* ヒントで光る鏡（ねこの寝かしつけのヒントと同じ黄色）。正しい向きを薄い影で出す */
.mirror-cell { position: relative; }
.cell.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; }
@keyframes glow { 50% { box-shadow: inset 0 0 0 4px #ffe58a, 0 0 4px 1px rgba(255, 211, 77, 0.4); } }
.mirror-ghost {
  position: absolute; left: 2%; top: 42%;
  width: 96%; height: 16%;
  border-radius: 6px;
  border: 2px dashed #c79a00;
  background: rgba(255, 211, 77, 0.35);
  pointer-events: none;
}
.mirror-ghost[hidden] { display: none; }

/* 光の線（盤の上に重ねる。タップは下のマスに通す） */
.beam {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  overflow: visible;
  pointer-events: none;
}
.beam-glow { fill: none; stroke: #ff5a5a; stroke-opacity: 0.28; stroke-width: 0.3; stroke-linejoin: round; stroke-linecap: round; }
.beam-line { fill: none; stroke: #e8202a; stroke-width: 0.09; stroke-linejoin: round; stroke-linecap: round; }
.beam-dot { fill: #ff2020; }
.beam-dot-glow { fill: #ff4040; opacity: 0.35; animation: dot 0.8s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes dot { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.5); } }
.field.cleared .beam-line, .field.cleared .beam-glow { transition: opacity 0.6s; opacity: 0.25; }

/* 盤の下: 回した数とヒント */
.below { margin-top: 12px; text-align: center; }
.below-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.taps { margin: 0; font-size: 15px; min-height: 1.4em; text-align: left; }
.btn-hint { background: #7d86b5; flex: none; }
.btn-hint:disabled { opacity: 0.5; }
.hint { margin: 2px 0 0; font-size: 13px; opacity: 0.65; }

/* 結果 */
.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; }
