/* おひるね猫スイーパー：クリーム背景＋ミント・コーラル */
:root {
  --cream: #FFF4E0;
  --cream-2: #FFFBF3;
  --mint: #6FD3B6;
  --mint-dark: #2F9C80;
  --mint-tile: #BFEBDD;
  --coral: #FF8A78;
  --coral-dark: #E0604E;
  --ink: #4A3B35;
  --ink-soft: #7A6A62;
  --line: #EADCC6;
  --gap: 2px;
  --app-max: 760px;
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  color: var(--ink);
  background: var(--cream);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { min-height: 100vh; min-height: 100dvh; overflow-x: hidden; }
button { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

#app { max-width: var(--app-max); margin: 0 auto; }
.screen { padding: 12px 8px 16px; }

/* ---------- ボタン ---------- */
.btn {
  min-height: 48px; padding: 10px 20px; border-radius: 999px; border: 2px solid transparent;
  font-weight: 700; font-size: 1rem; cursor: pointer; touch-action: manipulation;
}
.btn-primary { background: var(--coral); color: #fff; border-color: var(--coral-dark); box-shadow: 0 3px 0 var(--coral-dark); }
.btn-secondary { background: var(--mint); color: #11473A; border-color: var(--mint-dark); box-shadow: 0 3px 0 var(--mint-dark); }
.btn-ghost { background: var(--cream-2); border-color: var(--line); }
.btn-small { min-height: 44px; padding: 6px 14px; font-size: .9rem; background: #fff; border-color: var(--line); }
.btn:active { transform: translateY(2px); box-shadow: none; }
:focus-visible { outline: 3px solid #3B82F6; outline-offset: 2px; }

/* ---------- 開始画面 ---------- */
#screen-start { text-align: center; padding-top: 28px; }
.hero { display: flex; justify-content: center; gap: 4px; }
.hero { flex-wrap: wrap; }
.hero .cat { width: min(48px, 11vw); height: min(48px, 11vw); }
h1 { font-size: clamp(1.6rem, 7vw, 2.1rem); margin: 10px 0 6px; letter-spacing: .03em; color: var(--coral-dark); }
.lead { color: var(--ink-soft); line-height: 1.7; margin: 0 0 18px; font-size: .95rem; }
.difficulty { border: 0; padding: 0; margin: 0 auto 18px; display: grid; gap: 8px; max-width: 340px; }
.difficulty legend { font-weight: 700; margin: 0 auto 8px; }
.difficulty label { display: block; cursor: pointer; }
.difficulty input { position: absolute; opacity: 0; }
.difficulty label span {
  display: flex; align-items: center; justify-content: space-between; min-height: 52px; padding: 8px 18px;
  border-radius: 16px; border: 2px solid var(--line); background: var(--cream-2);
}
.difficulty small { color: var(--ink-soft); }
.difficulty input:checked + span { border-color: var(--mint-dark); background: #E3F7F0; box-shadow: inset 0 0 0 1px var(--mint-dark); }
.difficulty input:checked + span b::before { content: "✓ "; color: var(--mint-dark); }
.difficulty input:focus-visible + span { outline: 3px solid #3B82F6; outline-offset: 2px; }
.difficulty.compact label span { min-height: 46px; }
.start-actions { display: flex; flex-direction: column; gap: 12px; max-width: 340px; margin: 0 auto; }
.start-sub { display: flex; justify-content: center; gap: 10px; margin: 16px 0 8px; flex-wrap: wrap; }
.foot { font-size: .85rem; }
.foot a { color: var(--mint-dark); }
.notice { background: #FFF0C2; border: 1px solid #E8C96A; border-radius: 12px; padding: 8px 12px; font-size: .88rem; margin: 10px auto; max-width: 420px; }

/* ---------- プレイ画面 ---------- */
#screen-play { padding: 0 8px; }
.hud {
  position: sticky; top: 0; z-index: 5; background: var(--cream);
  padding: 8px 0 6px; border-bottom: 1px solid var(--line); margin-bottom: 8px;
}
.hud-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.lives { display: flex; gap: 2px; }
.heart { width: 22px; height: 22px; }
.heart.full path { fill: var(--coral); stroke: var(--coral-dark); stroke-width: 1.2; }
.heart.empty path { fill: none; stroke: #C9B8A8; stroke-width: 1.6; stroke-dasharray: 3 2; }
.time { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 56px; }
.hud-buttons { margin-left: auto; display: flex; gap: 4px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 2px solid var(--line); background: var(--cream-2);
  font-size: 1.15rem; display: grid; place-items: center; cursor: pointer; padding: 0; touch-action: manipulation;
}
.counts { font-size: .85rem; gap: 10px; margin-top: 4px; flex-wrap: wrap; color: var(--ink-soft); }
.counts b { color: var(--ink); font-size: 1rem; }
.diff-chip { background: #E3F7F0; color: #11473A; border-radius: 999px; padding: 2px 10px; font-weight: 700; }
.end-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  background: #fff; border: 2px solid var(--coral); border-radius: 14px; padding: 6px 10px; margin-bottom: 8px; font-weight: 700;
}

/* ---------- 盤面 ---------- */
/* マスの大きさ(--cell)は render.js が盤面の置ける幅を実測して設定する。
   極端に狭い画面（最小16pxでも入らない時）だけ盤面の枠内で横スクロール */
.board-wrap { overflow-x: auto; padding-bottom: 8px; -webkit-overflow-scrolling: touch; }
#board {
  --cell: 32px;
  width: max-content; margin: 0 auto;
  display: flex; flex-direction: column; gap: var(--gap);
  touch-action: manipulation; /* 縦横スクロールとズームは残し、ダブルタップ拡大だけ無効 */
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.row { display: flex; gap: var(--gap); }
.cell {
  width: var(--cell); height: var(--cell); border-radius: max(4px, calc(var(--cell) * .2)); position: relative;
  display: grid; place-items: center; font-weight: 800; font-size: max(12px, calc(var(--cell) * .55)); line-height: 1;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.cell:focus-visible { outline: 3px solid #3B82F6; outline-offset: 1px; z-index: 1; }
/* 未開封：ふっくら盛り上がったタイル */
.cell.hidden {
  background: var(--mint-tile);
  box-shadow: inset 0 -4px 0 rgba(47, 156, 128, .45), inset 0 2px 0 rgba(255, 255, 255, .7);
}
@media (hover: hover) { .cell.hidden:hover { background: #CFF2E6; } }
/* 開封：平らで薄い枠 */
.cell.open { background: var(--cream-2); border: 1px solid var(--line); cursor: default; }
.cell.n1 { color: #2F6FD0; } .cell.n2 { color: #23885A; } .cell.n3 { color: #D9483B; } .cell.n4 { color: #6E44C2; }
.cell.n5 { color: #A4511F; } .cell.n6 { color: #12858D; } .cell.n7 { color: #3D3D3D; } .cell.n8 { color: #7A7A7A; }
/* 起きた猫：ピンクの丸いマス＋点線枠 */
.cell.woke { background: #FFE1DA; border: 2px dashed var(--coral); }
.cell .cat { width: 86%; height: 86%; }
.cell .paw { width: 66%; height: 66%; fill: var(--coral); }
.cell.flagged .paw { filter: drop-shadow(0 1px 0 var(--coral-dark)); }
.cell .paw.badge { position: absolute; right: 1px; bottom: 1px; width: 38%; height: 38%; }
.cell.result-cat { background: #E9E1F5; box-shadow: none; }
.cell.result-cat .cat { opacity: .9; }
.cell.wrong .x { position: absolute; font-size: calc(var(--cell) * .6); color: #8A5A50; font-weight: 900; }
.cell.wrong .paw { opacity: .45; }
#board.over .cell { cursor: default; }

/* 猫の目 */
.cat.asleep .eyes-open { display: none; }
.cat.awake .eyes-closed { display: none; }
/* 起床：まぶたが開く→約4px跳ねる→戻る（約350ms） */
.cat.waking { animation: hop 350ms ease-out; }
.cat.waking .eyes-closed { display: inline; animation: lid-off 350ms forwards; }
.cat.waking .eyes-open { animation: lid-on 350ms forwards; }
@keyframes hop { 0%, 30% { transform: translateY(0); } 60% { transform: translateY(-4px); } 100% { transform: translateY(0); } }
@keyframes lid-off { 0%, 28% { opacity: 1; } 30%, 100% { opacity: 0; } }
@keyframes lid-on { 0%, 28% { opacity: 0; } 30%, 100% { opacity: 1; } }

/* ---------- 操作欄（常に見える） ---------- */
.controls {
  position: sticky; bottom: 0; z-index: 5; background: linear-gradient(to top, var(--cream) 85%, rgba(255, 244, 224, 0));
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
}
.controls-row { display: flex; gap: 8px; max-width: 440px; margin: 0 auto; }
.mode-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; flex: 1; min-width: 0; }
.hint-btn {
  min-height: 54px; min-width: 64px; padding: 0 8px; border-radius: 16px; border: 2px solid #E8B93A; background: #FFE89A;
  color: #6B4A00; box-shadow: 0 3px 0 #E8B93A; font-weight: 800; font-size: .85rem; cursor: pointer; touch-action: manipulation;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; line-height: 1.1;
}
.hint-btn span:first-child { font-size: 1.2rem; }
.hint-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #E8B93A; }
.hint-btn:disabled { opacity: .5; cursor: default; }
/* ヒントで光らせたマス（色＋太い枠＋点滅で分かる） */
.cell.hint { outline: 3px solid #F2B705; outline-offset: 1px; z-index: 2; animation: hint-glow 900ms ease-in-out infinite alternate; }
.cell.hint.hint-cat { outline-style: dashed; outline-color: var(--coral-dark); }
@keyframes hint-glow { from { box-shadow: 0 0 0 0 rgba(242, 183, 5, .0); } to { box-shadow: 0 0 0 5px rgba(242, 183, 5, .55); } }
.mode-btn {
  min-height: 54px; border-radius: 16px; border: 2px solid var(--line); background: var(--cream-2);
  display: flex; align-items: center; justify-content: center; gap: 6px; font-weight: 800; font-size: 1.05rem;
  cursor: pointer; touch-action: manipulation;
}
.mode-btn .check { visibility: hidden; }
.mode-btn.active .check { visibility: visible; }
.mode-btn[data-mode="open"].active { background: var(--mint); border-color: var(--mint-dark); color: #0E3E33; box-shadow: 0 3px 0 var(--mint-dark); }
.mode-btn[data-mode="flag"].active { background: var(--coral); border-color: var(--coral-dark); color: #fff; box-shadow: 0 3px 0 var(--coral-dark); }
.paw-icon { width: 22px; height: 22px; display: inline-block; }
.paw-icon .paw { width: 100%; height: 100%; fill: currentColor; }
.mode-icon { font-size: 1.1rem; }
.controls-hint { text-align: center; font-size: .78rem; color: var(--ink-soft); margin: 6px 0 0; }

/* ---------- トースト ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100vw - 24px); width: max-content; background: var(--ink); color: #fff; border-radius: 14px;
  padding: 10px 14px; font-size: .92rem; display: flex; align-items: center; gap: 10px; z-index: 20;
  opacity: 0; pointer-events: none; transition: opacity .15s;
}
.toast.show { opacity: 1; pointer-events: auto; }
.toast-action { min-height: 40px; border-radius: 999px; border: 0; background: var(--mint); color: #0E3E33; font-weight: 700; padding: 4px 12px; cursor: pointer; }

/* ---------- ダイアログ ---------- */
dialog {
  border: 0; border-radius: 22px; padding: 20px 18px; width: min(420px, calc(100vw - 24px));
  background: var(--cream-2); color: var(--ink); box-shadow: 0 12px 40px rgba(74, 59, 53, .25);
  max-height: calc(100dvh - 32px); overflow: auto;
}
dialog::backdrop { background: rgba(74, 59, 53, .45); }
dialog h2 { margin: 0 0 10px; color: var(--coral-dark); text-align: center; }
dialog p { line-height: 1.6; }
.dlg-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.dlg-actions.vertical { flex-direction: column; align-items: stretch; }
.help-list { padding-left: 1.2em; line-height: 1.65; margin: 0; }
.help-list li { margin-bottom: 6px; }
.result-cats { display: flex; justify-content: center; gap: 8px; }
.result-cats .cat { width: 56px; height: 56px; }
.result-cats .cat.cheer { animation: cheer 800ms ease-out 1; }
.result-cats .cat.cheer:nth-child(2) { animation-delay: 80ms; }
.result-cats .cat.cheer:nth-child(3) { animation-delay: 160ms; }
@keyframes cheer { 0% { transform: translateY(0); } 25% { transform: translateY(-8px); } 50% { transform: translateY(0); } 70% { transform: translateY(-4px); } 100% { transform: translateY(0); } }
.result-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin: 8px 0 0; text-align: center; }
.result-stats div { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 6px 4px; }
.result-stats dt { font-size: .75rem; color: var(--ink-soft); }
.result-stats dd { margin: 2px 0 0; font-weight: 800; font-size: .95rem; }
.result-stats .wide { grid-column: 1 / -1; }
.best-badge {
  margin: 6px auto 0; width: fit-content; padding: 4px 12px; border-radius: 999px;
  background: #FFE89A; color: #6B4A00; font-weight: 800; font-size: .92rem; border: 2px solid #E8B93A;
}
.difficulty small.best { color: #B07A00; font-weight: 700; }
.difficulty small.best:empty { display: none; }

/* ---------- 拡大・縮小 ---------- */
.zoom { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; }
.zoom-icon { font-size: .9rem; }
.zoom-btn {
  min-width: 36px; min-height: 32px; border-radius: 10px; border: 2px solid var(--line); background: var(--cream-2);
  color: var(--ink); font-weight: 900; font-size: 1.05rem; cursor: pointer; touch-action: manipulation; line-height: 1;
}
.zoom-btn:disabled { opacity: .35; cursor: default; }
#board.zoomed { margin: 0; } /* 拡大中は左端から。はみ出た分は枠の中で横スクロール */

/* ---------- クリア演出 ---------- */
.cell.celebrate .cat { animation: cat-pop 650ms cubic-bezier(.2, 1.4, .4, 1) var(--d, 0ms) both; }
.cell.celebrate .cat .zz { animation: zz-float 1200ms ease-out calc(var(--d, 0ms) + 300ms) both; }
#board.celebrating .cell.open { animation: glow 900ms ease-out both; }
@keyframes cat-pop {
  0% { transform: scale(.2) rotate(-20deg); opacity: 0; }
  60% { transform: scale(1.25) rotate(8deg); opacity: 1; }
  80% { transform: scale(.95) rotate(-4deg); }
  100% { transform: scale(1) rotate(0); }
}
@keyframes zz-float { 0% { transform: translate(0, 0); opacity: 0; } 30% { opacity: 1; } 100% { transform: translate(2px, -4px); opacity: 1; } }
@keyframes glow { 0% { background: var(--cream-2); } 40% { background: #FFF1B8; } 100% { background: var(--cream-2); } }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 30; overflow: hidden; }
.confetti span {
  position: absolute; bottom: -40px; width: var(--size); height: var(--size); opacity: 0;
  animation: confetti-up var(--dur) ease-out var(--delay) both;
}
.confetti svg { width: 100%; height: 100%; }
.confetti .heart path { fill: #FF8A9A; }
.confetti .paw { fill: var(--coral); }
@keyframes confetti-up {
  0% { transform: translate(0, 0) rotate(0); opacity: 0; }
  10% { opacity: 1; }
  55% { transform: translate(calc(var(--drift) * .6), -62vh) rotate(calc(var(--rot) * .6)); opacity: 1; }
  100% { transform: translate(var(--drift), -40vh) rotate(var(--rot)); opacity: 0; }
}

/* 広い画面では盤面にふちを付ける */
@media (min-width: 440px) {
  .board-wrap #board { padding: 8px; background: #fff; border-radius: 16px; border: 2px solid var(--line); }
}

/* 動きを減らす設定：跳ね・拡大をやめ、表情と輪郭で伝える */
@media (prefers-reduced-motion: reduce) {
  .cat.waking, .result-cats .cat.cheer { animation: none !important; }
  .cat.waking .eyes-closed { display: none; animation: none !important; }
  .cat.waking .eyes-open { animation: none !important; opacity: 1; }
  .toast { transition: none; }
  .cell.celebrate .cat, .cell.celebrate .cat .zz, #board.celebrating .cell.open { animation: none !important; }
  .confetti { display: none; }
  .cell.hint { animation: none !important; box-shadow: 0 0 0 4px rgba(242, 183, 5, .55); }
}

/* 怒って起きた猫：まゆと怒りマーク（形でも分かる） */
.cat .anger { display: none; }
.cat.awake.angry .anger { display: inline; }
.cat.waking.angry .anger { animation: lid-on 350ms forwards; }

/* 眠っている猫の「zz」はタイトル画面と結果画面だけ（盤面のマスでは出さない） */
.cat .zz { display: none; }
.hero .cat.asleep .zz, .result-cats .cat.asleep .zz, .cell.celebrate .cat.asleep .zz { display: inline; }
