/* ぽちゃん!おさかなすくい(水のみ) */

/* --- 大きめのマウスカーソル(おさかなすくいのアミ) ---
   デフォルトの16pxカーソルは小さな子には見えづらいので、48x48のSVGでアミを描く。
   通常は黄色いアミ、クリック可能な場所ではピンク枠のアミ(ちょっと強調)。
   タッチ端末では無視されるので影響なし。ブラウザが非対応/拒否した場合は
   フォールバックとして default / pointer を使う。
   ホットスポットは網の中心 (18, 18)。 */
:root {
  --cursor-arrow: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 32 32'><line x1='15' y1='15' x2='30' y2='30' stroke='%235a3d1c' stroke-width='4.6' stroke-linecap='round'/><line x1='15' y1='15' x2='30' y2='30' stroke='%23c68a3e' stroke-width='3.2' stroke-linecap='round'/><line x1='16' y1='16.5' x2='28' y2='28.5' stroke='%23ffd89a' stroke-width='0.9' stroke-linecap='round'/><circle cx='12' cy='12' r='9.5' fill='%23ffea4d' stroke='%23222222' stroke-width='1.5'/><circle cx='12' cy='12' r='7.5' fill='%23ffffff' opacity='0.88'/><path d='M4.5 12 L19.5 12 M12 4.5 L12 19.5' stroke='%237aa8d0' stroke-width='0.6' opacity='0.75'/><path d='M6.5 6.5 L17.5 17.5 M17.5 6.5 L6.5 17.5' stroke='%237aa8d0' stroke-width='0.4' opacity='0.55'/></svg>") 18 18;
  --cursor-hand: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 32 32'><line x1='15' y1='15' x2='30' y2='30' stroke='%235a3d1c' stroke-width='4.6' stroke-linecap='round'/><line x1='15' y1='15' x2='30' y2='30' stroke='%23c68a3e' stroke-width='3.2' stroke-linecap='round'/><line x1='16' y1='16.5' x2='28' y2='28.5' stroke='%23ffd89a' stroke-width='0.9' stroke-linecap='round'/><circle cx='12' cy='12' r='10' fill='%23ff5b5b' stroke='%23222222' stroke-width='1.5'/><circle cx='12' cy='12' r='8' fill='%23ffffff' opacity='0.92'/><path d='M4 12 L20 12 M12 4 L12 20' stroke='%23ff9aa8' stroke-width='0.7' opacity='0.8'/><path d='M6 6 L18 18 M18 6 L6 18' stroke='%23ff9aa8' stroke-width='0.5' opacity='0.6'/></svg>") 18 18;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;
  font-family: "Hiragino Maru Gothic ProN", "ヒラギノ丸ゴ ProN W4",
    "Yu Gothic", "Meiryo", system-ui, sans-serif;
  font-weight: bold;
  background: linear-gradient(180deg, #b8ecff 0%, #4ea9ff 55%, #1e5d9e 100%);
  cursor: var(--cursor-arrow), default;
}

.screen {
  position: fixed;
  inset: 0;
  overflow: hidden;
}
.hidden {
  display: none !important;
}

/* ---- スタート画面 ---- */
#start-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: clamp(12px, 4vh, 40px);
  padding: clamp(12px, 3vw, 24px);
}
.title {
  text-align: center;
  color: #fff;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.2), 0 0 20px rgba(255, 255, 255, 0.3);
  max-width: 100%;
}
.title-emoji {
  font-size: clamp(44px, min(16vw, 22vh), 130px);
  line-height: 1;
  height: clamp(70px, min(18vw, 24vh), 160px);
  aspect-ratio: 1.5;
  margin: 0 auto;
  animation: float 2s ease-in-out infinite;
  display: flex;
  align-items: center;
  justify-content: center;
}
.title-fish {
  width: 100%;
  height: 100%;
  background-repeat: no-repeat;
  background-size: 400% 400%;
  background-position: 0% 0%;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.22));
  transition: opacity 280ms ease, transform 280ms ease;
}
.title-fish.swap {
  opacity: 0;
  transform: scale(0.88);
}

/* タイトル左上のおと on/off ボタン */
.title-sound-btn {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  width: clamp(48px, 12vw, 64px);
  height: clamp(48px, 12vw, 64px);
  border-radius: 50%;
  border: 3px solid #fff;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: var(--cursor-hand), pointer;
  touch-action: manipulation;
}
.title-sound-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}
.title-sound-icon {
  font-size: clamp(24px, 7vw, 34px);
  line-height: 1;
}

.title-text {
  font-size: clamp(18px, min(6vw, 7vh), 46px);
  line-height: 1.2;
  margin-top: clamp(4px, 1vh, 10px);
  word-break: keep-all;
}
/* 横持ちの極端に低い画面ではタイトルの改行をやめて1行表示 */
@media (max-height: 420px) and (orientation: landscape) {
  #start-screen { gap: clamp(8px, 2vh, 20px); }
  .title-emoji { font-size: clamp(36px, 8vh, 72px); height: clamp(48px, 12vh, 90px); }
  .title-text {
    font-size: clamp(16px, 5vh, 28px);
  }
  .title-text br { display: none; }
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-14px); }
}

.start-btn {
  font: inherit;
  font-weight: bold;
  font-size: clamp(20px, min(5.5vw, 6vh), 40px);
  color: #ff5b5b;
  background: #fff;
  border: clamp(3px, 0.8vw, 6px) solid #ffea4d;
  border-radius: 999px;
  padding: clamp(10px, 2.5vw, 22px) clamp(26px, 8vw, 70px);
  box-shadow: 0 8px 0 #d9a200, 0 12px 20px rgba(0, 0, 0, 0.2);
  cursor: var(--cursor-hand), pointer;
  animation: pulse 1.6s ease-in-out infinite;
}
.start-btn:active {
  transform: translateY(4px);
  box-shadow: 0 4px 0 #d9a200;
}

/* エリア(habitat)選択 */
.habitat-picker {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: clamp(8px, 2vw, 16px);
  width: min(92vw, 600px);
  padding: 0 clamp(6px, 2vw, 16px);
}
.habitat-btn {
  font: inherit;
  font-weight: bold;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 1vw, 8px);
  color: #1e5d9e;
  background: #fff;
  border: clamp(3px, 0.6vw, 5px) solid #ffea4d;
  border-radius: clamp(14px, 3vw, 22px);
  padding: clamp(10px, 2.5vw, 18px) clamp(8px, 2vw, 16px);
  box-shadow: 0 6px 0 #d9a200, 0 10px 18px rgba(0, 0, 0, 0.2);
  cursor: var(--cursor-hand), pointer;
}
.habitat-btn:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #d9a200;
}
.habitat-emoji {
  font-size: clamp(28px, min(8vw, 8vh), 56px);
  line-height: 1;
}
.habitat-label {
  font-size: clamp(14px, min(3.6vw, 3.6vh), 22px);
  line-height: 1.15;
  text-align: center;
}
@media (max-height: 420px) and (orientation: landscape) {
  .habitat-picker { grid-template-columns: repeat(4, 1fr); width: min(96vw, 880px); }
  .habitat-emoji { font-size: clamp(20px, 5vh, 36px); }
  .habitat-label { font-size: clamp(12px, 3vh, 16px); }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}

/* ---- ゲーム画面 ---- */
#game-screen {
  display: flex;
  flex-direction: column;
}

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 20;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  font: inherit;
  font-weight: bold;
  display: inline-flex;
  align-items: center;
  gap: clamp(4px, 1.2vw, 8px);
  background: rgba(255, 255, 255, 0.9);
  border: 3px solid #fff;
  border-radius: 999px;
  padding: clamp(6px, 1.6vw, 10px) clamp(10px, 3vw, 16px);
  color: #333;
  font-size: clamp(14px, 3.5vw, 18px);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15);
  cursor: var(--cursor-hand), pointer;
}
.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}
.sound-btn { padding: clamp(6px, 1.6vw, 10px) clamp(8px, 2.4vw, 12px); }

.hud-icon { font-size: clamp(18px, 4.2vw, 24px); }
.hud-text { font-size: clamp(16px, 4vw, 22px); }

.score-wrap {
  display: inline-flex;
  align-items: center;
  gap: clamp(4px, 1.2vw, 8px);
  background: rgba(255, 255, 255, 0.9);
  border: 3px solid #fff;
  border-radius: 999px;
  padding: clamp(6px, 1.6vw, 10px) clamp(12px, 3.6vw, 20px);
  color: #333;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15);
}
#score.bump {
  animation: scoreBump 0.35s ease-out;
  display: inline-block;
}
@keyframes scoreBump {
  0%   { transform: scale(1);   color: #333; }
  40%  { transform: scale(1.5); color: #ff5b5b; }
  100% { transform: scale(1);   color: #333; }
}
#book-btn.flash { animation: bookFlash 0.6s ease-out; }
@keyframes bookFlash {
  0%   { background: rgba(255, 255, 255, 0.9); }
  40%  { background: #ffea4d; transform: scale(1.1); }
  100% { background: rgba(255, 255, 255, 0.9); }
}

.play-area {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 10;
}
.play-area.has-bg {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* ---- 背景装飾 ---- */
.decor-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.decor-sand {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: clamp(60px, 12vh, 110px);
}
.decor-sand-front {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: clamp(44px, 8vh, 72px);
  z-index: 9;
  pointer-events: none;
}
.decor-sand svg,
.decor-sand-front svg { width: 100%; height: 100%; display: block; }
.decor-rock {
  position: absolute;
  bottom: 0;
  z-index: 10;
  pointer-events: none;
}
.decor-rock svg { width: 100%; height: 100%; display: block; }

.decor-coral {
  position: absolute;
}
.decor-coral svg { width: 100%; height: 100%; display: block; }
.decor-seaweed {
  position: absolute;
  transform-origin: bottom center;
  animation: sway 4.5s ease-in-out infinite;
  animation-delay: var(--sway-delay, 0s);
}
.decor-seaweed svg { width: 100%; height: 100%; display: block; }
.decor-anemone {
  position: absolute;
  transform-origin: bottom center;
  animation: sway 3.6s ease-in-out infinite;
  animation-delay: var(--sway-delay, 0s);
}
.decor-anemone svg { width: 100%; height: 100%; display: block; }
@keyframes sway {
  0%, 100% { transform: rotate(-4deg); }
  50%      { transform: rotate(4deg); }
}

/* ---- 生き物 ---- */
.critter {
  position: absolute;
  will-change: transform, left, top;
  pointer-events: auto;
  z-index: 5;
  cursor: var(--cursor-hand), pointer;
}
.critter-inner {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  overflow: visible;
}
.critter svg,
.critter img {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.18));
}
/* 体全体に微細な揺らぎ(しっぽ振り+口/呼吸の拡縮)を載せるラッパー。
   SVGは自然な「左向き」なので、transform-origin を頭寄り(左側25%)にして
   後ろ半分がしっぽのように大きく振れるようにする。 */
.body-wiggle {
  width: 100%;
  height: 100%;
  display: block;
  transform-origin: 25% 50%;
  animation: aliveMotion 1.4s ease-in-out infinite;
}
/* 縦長SVGをrotateSvgで回転している個体は、内部コンテンツを絶対配置で
   追加変形しているので、ラッパー側のアニメは無効化(二重回転防止)。*/
.body-wiggle.rotated {
  animation: none;
}
/* スプライトシート(ChatGPT画像)モード: 4列×4行のシートを背景画像として使う。
   背景位置は critter.js が JS で更新する。*/
.body-wiggle.sprite {
  background-repeat: no-repeat;
  background-size: 400% 400%;
  animation: aliveMotion 1.4s ease-in-out infinite;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.18));
}
@keyframes aliveMotion {
  0%, 100% { transform: rotate(-1.6deg) scaleX(1);    }
  25%      { transform: rotate( 0deg)   scaleX(1.03); }
  50%      { transform: rotate( 1.6deg) scaleX(1);    }
  75%      { transform: rotate( 0deg)   scaleX(0.97); }
}
.critter.captured {
  animation: capturedVanish 1.4s ease-out forwards;
  pointer-events: none;
  z-index: 50;
}
@keyframes capturedVanish {
  0%   { transform: scale(1) translateY(0); opacity: 1; }
  60%  { transform: scale(1.15) translateY(-20px); opacity: 1; }
  85%  { transform: scale(1.6) translateY(-80px); opacity: 1; }
  100% { transform: scale(2.2) translateY(-160px); opacity: 0; }
}

/* レア魚: 光背がキラキラ回る */
.critter.rare::before {
  content: "";
  position: absolute;
  inset: -14%;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(255, 230, 100, 0.55) 0%,
    rgba(255, 210, 80, 0.28) 30%,
    rgba(255, 220, 120, 0) 70%);
  z-index: -1;
  animation: rareHalo 2.2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes rareHalo {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50%      { transform: scale(1.15); opacity: 1; }
}

/* ヌシ: 赤紫の威圧オーラ + ラベル */
.critter.nushi::before {
  content: "";
  position: absolute;
  inset: -10%;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(180, 60, 180, 0.45) 0%,
    rgba(140, 40, 160, 0.25) 35%,
    rgba(80, 20, 100, 0) 75%);
  z-index: -1;
  animation: nushiHalo 2.4s ease-in-out infinite;
  pointer-events: none;
}
@keyframes nushiHalo {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50%      { transform: scale(1.18); opacity: 1; }
}
.nushi-label {
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #b03cb0, #5d1075);
  color: #fff;
  font-size: clamp(14px, 3.2vw, 22px);
  font-weight: 900;
  padding: 4px 12px;
  border-radius: 14px;
  border: 2px solid #fff;
  letter-spacing: 0.1em;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
  box-shadow: 0 3px 8px rgba(80, 20, 100, 0.5);
  pointer-events: none;
  z-index: 6;
  animation: nushiLabelPulse 1.6s ease-in-out infinite;
}
@keyframes nushiLabelPulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50%      { transform: translateX(-50%) scale(1.08); }
}

/* ヌシ出現の暗いビネット(画面端から黒くなる) */
.nushi-vignette {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center,
    rgba(0, 0, 0, 0) 35%,
    rgba(20, 0, 30, 0.75) 100%);
  pointer-events: none;
  z-index: 70;
  animation: nushiVignette 1.6s ease-out forwards;
}
@keyframes nushiVignette {
  0%   { opacity: 0; }
  25%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ヌシ出現/捕獲の中央バナー */
.nushi-banner {
  position: fixed;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 18px 32px;
  border-radius: 22px;
  border: 4px solid #fff;
  text-align: center;
  pointer-events: none;
  z-index: 80;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}
.nushi-banner-sub {
  font-size: clamp(16px, 4vw, 28px);
  color: #fff;
  font-weight: 700;
}
.nushi-banner-main {
  font-size: clamp(24px, 7vw, 48px);
  color: #fff;
  font-weight: 900;
  letter-spacing: 0.05em;
}
.nushi-banner.appear {
  background: linear-gradient(180deg, #5d1075, #2a0040);
  box-shadow: 0 8px 24px rgba(80, 20, 100, 0.6);
  animation: nushiBannerIn 2.2s ease-out forwards;
}
.nushi-banner.caught {
  background: linear-gradient(180deg, #f7a91a, #c46a00);
  box-shadow: 0 8px 24px rgba(180, 100, 0, 0.5);
  animation: nushiBannerIn 2.6s ease-out forwards;
}
@keyframes nushiBannerIn {
  0%   { transform: translate(-50%, -50%) scale(0.4); opacity: 0; }
  15%  { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
  25%  { transform: translate(-50%, -50%) scale(1); }
  80%  { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -55%) scale(1); opacity: 0; }
}

/* ダメージ揺れ(大物をタップして捕まえ損ねたとき) */
.critter.hit { animation: critterHit 0.38s ease-out; }
@keyframes critterHit {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px) rotate(-3deg); }
  40%      { transform: translateX(6px) rotate(3deg); }
  60%      { transform: translateX(-4px) rotate(-2deg); }
  80%      { transform: translateX(4px) rotate(2deg); }
}

.sparkle.small { width: 10px; height: 10px; animation-duration: 0.5s; }

.damage-hint {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 24px;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 2px 0 #ff9a00, -1px 0 0 #ff9a00, 1px 0 0 #ff9a00,
    0 -1px 0 #ff9a00, 2px 3px 6px rgba(0, 0, 0, 0.4);
  animation: damageHint 0.6s ease-out forwards;
  white-space: nowrap;
  pointer-events: none;
}
@keyframes damageHint {
  0%   { transform: translate(-50%, -50%) scale(0.6); opacity: 0; }
  30%  { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
  100% { transform: translate(-50%, -90%) scale(1); opacity: 0; }
}

/* 空タップの波紋 */
.ripple {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
  animation: rippleGrow 0.7s ease-out forwards;
  pointer-events: none;
}
@keyframes rippleGrow {
  0%   { transform: translate(-50%, -50%) scale(0.3); opacity: 0.9; border-width: 4px; }
  100% { transform: translate(-50%, -50%) scale(3.2); opacity: 0;   border-width: 1px; }
}

/* レア魚スポーン予兆の中央光 */
.rare-omen-glow {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 240, 160, 0.95) 0%,
    rgba(255, 220, 120, 0.6) 40%, rgba(255, 220, 120, 0) 75%);
  animation: rareOmenGlow 0.8s ease-out forwards;
  pointer-events: none;
  filter: blur(1px);
}
@keyframes rareOmenGlow {
  0%   { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
  30%  { transform: translate(-50%, -50%) scale(1.4); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(2.0); opacity: 0; }
}

/* 底から昇る泡 */
.bubble {
  position: absolute;
  bottom: -30px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%,
    rgba(255, 255, 255, 0.8) 0%,
    rgba(200, 235, 255, 0.35) 40%,
    rgba(180, 220, 255, 0.15) 70%,
    rgba(180, 220, 255, 0) 100%);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: inset 0 0 6px rgba(255, 255, 255, 0.4);
  pointer-events: none;
  z-index: 2;
  animation: bubbleRise var(--dur, 6s) linear forwards;
  --drift: 0px;
}
@keyframes bubbleRise {
  0%   { transform: translate(0, 0)              scale(0.6); opacity: 0; }
  10%  { opacity: 0.9; }
  100% { transform: translate(var(--drift), -110vh) scale(1); opacity: 0; }
}

/* ---- 演出 ---- */
.fx-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
}

.sparkle {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: sparkleFly 0.6s ease-out forwards;
  box-shadow: 0 0 12px currentColor;
}
@keyframes sparkleFly {
  0%   { transform: translate(-50%, -50%) scale(0.5); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.2); opacity: 0; }
}

.praise-pop {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 44px;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 4px 0 #ff5b5b, -2px 0 0 #ff5b5b, 2px 0 0 #ff5b5b,
    0 -2px 0 #ff5b5b, 3px 4px 10px rgba(0, 0, 0, 0.4);
  animation: praisePop 0.9s ease-out forwards;
  white-space: nowrap;
}
@keyframes praisePop {
  0%   { transform: translate(-50%, -50%) scale(0.2) rotate(-10deg); opacity: 0; }
  30%  { transform: translate(-50%, -50%) scale(1.4) rotate(6deg); opacity: 1; }
  60%  { transform: translate(-50%, -80%) scale(1.2) rotate(-3deg); opacity: 1; }
  100% { transform: translate(-50%, -140%) scale(0.9) rotate(0); opacity: 0; }
}

.first-pop {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 32px;
  color: #ffea4d;
  font-weight: bold;
  text-shadow: 0 3px 0 #d9a200, -1px 0 0 #d9a200, 1px 0 0 #d9a200,
    0 -1px 0 #d9a200, 2px 4px 8px rgba(0, 0, 0, 0.4);
  animation: firstPop 1.2s ease-out forwards;
  white-space: nowrap;
}
@keyframes firstPop {
  0%   { transform: translate(-50%, -50%) scale(0.2); opacity: 0; }
  30%  { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
  100% { transform: translate(-50%, -180%) scale(1);   opacity: 0; }
}

/* サイズ記録更新ポップ */
.size-record-pop {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 26px;
  font-weight: bold;
  color: #fff;
  padding: 8px 18px;
  border-radius: 999px;
  white-space: nowrap;
  animation: sizeRecordPop 1.6s ease-out forwards;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.size-record-pop.max {
  background: linear-gradient(180deg, #ffb84d 0%, #ff7a1a 100%);
  text-shadow: 0 2px 0 #a04200;
}
.size-record-pop.min {
  background: linear-gradient(180deg, #7adfff 0%, #2a8acd 100%);
  text-shadow: 0 2px 0 #144a78;
}
@keyframes sizeRecordPop {
  0%   { transform: translate(-50%, -50%) scale(0.4); opacity: 0; }
  20%  { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  70%  { transform: translate(-50%, -160%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -220%) scale(0.9); opacity: 0; }
}

.name-pop {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 30px;
  color: #fff;
  background: rgba(0, 0, 0, 0.65);
  padding: 8px 22px;
  border-radius: 999px;
  animation: namePop 1.2s ease-out forwards;
  white-space: nowrap;
}
@keyframes namePop {
  0%   { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  20%  { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
  80%  { transform: translate(-50%, -100%) scale(1);   opacity: 1; }
  100% { transform: translate(-50%, -140%) scale(0.9); opacity: 0; }
}

/* ---- 図鑑 ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
}
.modal.open { display: block; }
.backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 2.5vw, 20px);
  animation: fadeIn 0.2s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.book-panel {
  background: #fff9e6;
  border-radius: clamp(14px, 3vw, 24px);
  border: clamp(3px, 0.8vw, 6px) solid #ffea4d;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  width: 100%;
  max-width: 540px;
  max-height: 92vh;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes popIn {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.book-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(6px, 2vw, 12px);
  padding: clamp(8px, 2.4vw, 14px) clamp(10px, 3vw, 18px);
  border-bottom: 3px dashed #e0c355;
}
.book-title {
  display: flex;
  gap: clamp(6px, 2vw, 12px);
  align-items: center;
  font-size: clamp(15px, 4.5vw, 22px);
  color: #8b5a2b;
  flex-wrap: wrap;
  min-width: 0;
}
.book-progress {
  font-size: clamp(12px, 3.5vw, 18px);
  background: #ffea4d;
  padding: clamp(2px, 0.8vw, 4px) clamp(8px, 2.4vw, 12px);
  border-radius: 999px;
  white-space: nowrap;
}
.book-close {
  background: #ff5b5b;
  color: #fff;
  border: none;
  width: clamp(32px, 8vw, 40px);
  height: clamp(32px, 8vw, 40px);
  border-radius: 50%;
  font-size: clamp(16px, 4.5vw, 20px);
  font-weight: bold;
  box-shadow: 0 3px 0 #c43838;
  cursor: var(--cursor-hand), pointer;
  flex-shrink: 0;
}
.book-close:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #c43838;
}

.book-grid {
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 2vw, 12px);
  padding: clamp(10px, 3vw, 16px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.book-cell {
  background: #fff;
  border-radius: clamp(10px, 2.5vw, 16px);
  padding: clamp(8px, 2vw, 12px) clamp(4px, 1.2vw, 6px);
  text-align: center;
  border: clamp(2px, 0.6vw, 3px) solid #e0c355;
  position: relative;
  min-height: clamp(120px, 30vw, 170px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  gap: clamp(4px, 1.2vw, 8px);
  cursor: var(--cursor-hand), pointer;
  min-width: 0;
  overflow: hidden;
  transition: transform 0.12s ease-out;
}
.book-cell.captured:active { transform: scale(0.94); }
.book-cell.locked {
  background: #e8e3c9;
  cursor: default;
}
/* 影シルエット */
.book-cell.locked .book-thumb img,
.book-cell.locked .book-thumb svg {
  filter: brightness(0) opacity(0.45);
}
/* 旧 .book-svg を残しつつ新 .book-thumb 系を追加 */
.book-thumb,
.book-svg {
  width: 88%;
  margin: 0 auto;
  display: block;
  flex-shrink: 0;
}
.book-svg {
  height: clamp(72px, 22vw, 120px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.book-svg svg,
.book-svg img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}
/* スプライトサムネ: 4x4 スプライトシートの Row1 (左→右) を steps アニメ */
.sprite-thumb {
  position: relative;
  width: 88%;
  aspect-ratio: 1.5; /* セル 384x256 比 */
  overflow: hidden;
}
.sprite-thumb img {
  position: absolute;
  left: 0;
  top: 0;
  width: 400%;
  height: 400%;
  user-select: none;
  -webkit-user-drag: none;
  --row-y: 0%;
  animation: book-walk 1.0s steps(1, end) infinite;
}
.sprite-thumb[data-row="0"] img { --row-y: 0%; }
.sprite-thumb[data-row="1"] img { --row-y: -25%; }
.sprite-thumb[data-row="2"] img { --row-y: -50%; }
.sprite-thumb[data-row="3"] img { --row-y: -75%; }
@keyframes book-walk {
  0%   { transform: translate(0%,   var(--row-y, 0%)); }
  25%  { transform: translate(-25%, var(--row-y, 0%)); }
  50%  { transform: translate(-50%, var(--row-y, 0%)); }
  75%  { transform: translate(-75%, var(--row-y, 0%)); }
  100% { transform: translate(-75%, var(--row-y, 0%)); }
}
/* SVG fallback サムネ */
.svg-thumb {
  width: 88%;
  height: clamp(72px, 22vw, 120px);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.svg-thumb svg,
.svg-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

/* 図鑑エリア別セクション */
.book-section {
  margin-bottom: clamp(10px, 2.5vw, 16px);
}
.book-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(6px, 1.6vw, 10px) clamp(8px, 2vw, 14px);
  margin-bottom: clamp(6px, 1.6vw, 10px);
  background: rgba(255, 234, 77, 0.85);
  border-radius: clamp(8px, 2vw, 12px);
  color: #6b4920;
  font-size: clamp(13px, 3.4vw, 16px);
}
.book-section-progress {
  background: #fff;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: clamp(11px, 2.8vw, 13px);
  color: #c43838;
}
/* ヌシ専用セクション: 紫金で目立たせる */
.book-section-nushi .book-section-header {
  background: linear-gradient(180deg, #b03cb0, #5d1075);
  color: #fff;
  font-weight: 900;
  letter-spacing: 0.15em;
}
.book-section-nushi .book-section-progress {
  background: #ffe26b;
  color: #5d1075;
  font-weight: 700;
}
.book-nushi-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 640px) {
  .book-nushi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.book-nushi-cell.captured {
  background: linear-gradient(180deg, #fff6d0, #ffd24a);
  border: 2px solid #b03cb0;
}
.book-nushi-cell .book-habitat-tag {
  font-size: clamp(10px, 2.6vw, 12px);
  color: #5d1075;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  padding: 1px 8px;
  margin-top: 2px;
}
.book-nushi-cell.locked .book-habitat-tag {
  color: #8a815e;
  background: rgba(255, 255, 255, 0.4);
}
.book-section-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(8px, 2vw, 12px);
}
@media (max-width: 460px) {
  .book-section-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-height: 480px) and (orientation: landscape) {
  .book-section-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
}
.book-name {
  font-size: clamp(11px, 3vw, 14px);
  color: #6b4920;
  line-height: 1.2;
}
.book-cell.locked .book-name { color: #8a815e; }
.book-count {
  position: absolute;
  top: clamp(2px, 0.8vw, 4px);
  right: clamp(4px, 1.6vw, 8px);
  background: #ff5b5b;
  color: #fff;
  font-size: clamp(11px, 3vw, 13px);
  padding: clamp(1px, 0.4vw, 2px) clamp(5px, 1.8vw, 8px);
  border-radius: 999px;
}

/* --- 図鑑 詳細モーダル --- */
.detail-panel {
  position: relative;
  background: #fff9e6;
  border-radius: clamp(16px, 3.5vw, 28px);
  border: clamp(3px, 0.8vw, 6px) solid #ffea4d;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  width: 100%;
  max-width: 440px;
  max-height: 92vh;
  max-height: 92dvh;
  padding: clamp(18px, 4.5vw, 28px) clamp(18px, 4vw, 24px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 2.2vw, 14px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.detail-close {
  position: absolute;
  top: clamp(6px, 1.8vw, 10px);
  right: clamp(6px, 1.8vw, 10px);
  background: #ff5b5b;
  color: #fff;
  border: none;
  width: clamp(34px, 9vw, 42px);
  height: clamp(34px, 9vw, 42px);
  border-radius: 50%;
  font-size: clamp(16px, 4.5vw, 20px);
  font-weight: bold;
  box-shadow: 0 3px 0 #c43838;
  cursor: var(--cursor-hand), pointer;
}
.detail-close:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #c43838;
}
.detail-svg {
  width: clamp(180px, 60vw, 300px);
  aspect-ratio: 1;
  max-height: 50vh;
  max-height: 50dvh;
  flex-shrink: 0;
}
@media (max-height: 480px) and (orientation: landscape) {
  .detail-svg {
    width: clamp(120px, 36vw, 200px);
    max-height: 36dvh;
  }
  .detail-name { font-size: clamp(16px, 5vh, 22px); }
  .detail-trivia { font-size: clamp(11px, 3.4vh, 14px); }
}
.detail-svg {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: clamp(12px, 3vw, 20px);
  border: clamp(2px, 0.6vw, 3px) solid #e0c355;
  padding: clamp(8px, 2vw, 14px);
}
.detail-svg svg,
.detail-svg > img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  animation: detailBob 2.4s ease-in-out infinite;
}
/* 詳細モーダル内のスプライトサムネは大きく */
.detail-sprite-thumb {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
}
.detail-sprite-thumb img {
  /* book-walk アニメを継続 */
}
@keyframes detailBob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}
.detail-name {
  font-size: clamp(22px, 6vw, 30px);
  color: #6b4920;
  font-weight: bold;
  text-align: center;
  line-height: 1.1;
}
.detail-trivia {
  font-size: clamp(14px, 4vw, 18px);
  color: #6b4920;
  line-height: 1.6;
  text-align: center;
  padding: 0 clamp(2px, 1vw, 6px);
}

/* 図鑑詳細: 「いちばん おおきい / ちいさい」の記録ペア */
.detail-sizes:empty { display: none; }
.detail-sizes .size-row {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(12px, 3vw, 24px);
  margin-top: clamp(8px, 2vw, 14px);
}
.detail-sizes .size-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1 1 0;
  max-width: 50%;
}
.detail-sizes .size-label {
  font-size: clamp(12px, 3.4vw, 16px);
  color: #6b4920;
  margin-bottom: 4px;
}
.detail-sizes .size-length {
  font-size: clamp(13px, 3.6vw, 17px);
  color: #2a5a8a;
  font-weight: bold;
  margin-top: 6px;
}
.detail-sizes .size-thumb {
  aspect-ratio: 1.5;
  overflow: hidden;
  position: relative;
}
.detail-sizes .size-thumb.sprite-thumb img {
  position: absolute;
  width: 400%;
  height: 400%;
  --row-y: 0%;
  animation: book-walk 1.0s steps(1, end) infinite;
}
.detail-sizes .size-thumb.svg-thumb img,
.detail-sizes .size-thumb.svg-thumb svg {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* --- 図鑑クリアモーダル --- */
.clear-panel {
  position: relative;
  background: linear-gradient(180deg, #fff9e6 0%, #ffeaa0 100%);
  border-radius: clamp(18px, 4vw, 32px);
  border: clamp(4px, 1vw, 8px) solid #ffc83d;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  width: 100%;
  max-width: 420px;
  padding: clamp(24px, 5vw, 36px) clamp(20px, 4.5vw, 32px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(12px, 3vw, 18px);
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-align: center;
}
.clear-emoji {
  font-size: clamp(60px, 16vw, 92px);
  line-height: 1;
  animation: clearEmojiBounce 1.4s ease-in-out infinite;
}
@keyframes clearEmojiBounce {
  0%, 100% { transform: translateY(0) rotate(-8deg); }
  50%      { transform: translateY(-10px) rotate(8deg); }
}
.clear-title {
  font-size: clamp(26px, 7vw, 36px);
  font-weight: bold;
  color: #fff;
  line-height: 1.2;
  text-shadow: 0 3px 0 #ff9a00, -2px 0 0 #ff9a00, 2px 0 0 #ff9a00,
    0 -2px 0 #ff9a00, 3px 4px 10px rgba(0, 0, 0, 0.35);
}
.clear-sub {
  font-size: clamp(18px, 5vw, 24px);
  color: #6b4920;
  font-weight: bold;
}
.clear-close {
  margin-top: clamp(4px, 1.5vw, 10px);
  background: #ff5b5b;
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: clamp(12px, 3vw, 16px) clamp(24px, 6vw, 36px);
  font-size: clamp(20px, 5.5vw, 26px);
  font-weight: bold;
  box-shadow: 0 5px 0 #c43838, 0 8px 14px rgba(0, 0, 0, 0.25);
  cursor: var(--cursor-hand), pointer;
}
.clear-close:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #c43838, 0 4px 8px rgba(0, 0, 0, 0.25);
}

/* --- 紙吹雪 --- */
.confetti {
  position: absolute;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  animation: confettiFall var(--dur, 3s) linear forwards;
  pointer-events: none;
}
@keyframes confettiFall {
  0%   { transform: translate(0, 0) rotate(0); opacity: 1; }
  100% { transform: translate(var(--drift, 0), 110vh) rotate(var(--spin, 360deg)); opacity: 0.9; }
}

/* 図鑑コンプ後はボタンを金色に */
.icon-btn.cleared {
  background: linear-gradient(180deg, #fff3a0 0%, #ffcf3d 100%);
  box-shadow: 0 3px 0 #c49400, 0 0 12px rgba(255, 210, 50, 0.8);
}
