/* base.css — シーン構造・レイヤー・ハムスター(契約: docs/design.md)
   コンテンツの装飾は site.css へ。このファイルは Fable 管理。 */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: auto;
}

body {
  margin: 0;
  font-family: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", system-ui, sans-serif;
  color: #5a4634;
  background: #eaf4f8;
  overflow-x: hidden;
}

/* ---------- シーン ---------- */

#scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.layer {
  position: absolute;
  left: 0;
  right: 0;
  overflow: visible;
}

#layer-sky {
  inset: 0;
  z-index: 1;
}
#layer-hills {
  bottom: 22vh;
  height: 48vh;
  z-index: 2;
}
#layer-mid {
  bottom: 8vh;
  height: 34vh;
  z-index: 3;
}
#layer-near {
  bottom: 0;
  height: 26vh;
  z-index: 5;
}
#layer-front {
  bottom: -2vh;
  height: 18vh;
  z-index: 7;
}

.actors {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
#actors-mid {
  z-index: 4;
}
#actors-near {
  z-index: 6;
}
#actors-front {
  z-index: 8;
}

#layer-sky {
  height: 100%;
}
#layer-sky .strip {
  height: 100%;
}

.strip {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 100%;
  display: flex;
  align-items: flex-end;
  will-change: transform;
}

.strip img {
  height: 100%;
  width: auto;
  display: block;
  flex: none;
  user-select: none;
  -webkit-user-drag: none;
}

#tint {
  position: absolute;
  inset: 0;
  z-index: 9;
  pointer-events: none;
}

/* 夜: ティントを turbulence フィルタ(index.tsx の #mofu-mist)で歪ませ、
   直線的なグラデーションを自然なモヤに見せる。
   inset を -40px に広げることで、feDisplacementMap(scale=28)が端で
   要素外(透明)を参照して途切れるのを防ぐ。#scene の overflow:hidden で余分は隠れる。 */
#scene[data-time="night"] #tint {
  filter: url(#mofu-mist);
  inset: -40px;
}

/* z10: ティント(z9)より上に星・月・ホタルを描画するコンテナ。 */
#night-fx {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

/* ---------- ハムスターアクター(スプライト版・正式) ---------- */

.actor {
  position: absolute;
  bottom: 0;
  will-change: transform;
  transition:
    transform 0.55s cubic-bezier(0.34, 1.4, 0.64, 1),
    opacity 0.4s ease;
}
.actor.hidden-below {
  transform: translateY(115%);
}
.actor.sink {
  transform: translateY(118%);
  opacity: 0.9;
}

/* コマ送りストリップ(走り・たね食べ)。シートは左向き → data-dir=1 で右向きに反転 */
.s-strip {
  width: 100%;
  aspect-ratio: 330 / 310;
  background-repeat: no-repeat;
  background-position: 0 0;
  filter: drop-shadow(0 4px 5px rgba(60, 80, 45, 0.26));
  pointer-events: auto;
  cursor: pointer;
}
.s-strip[data-dir="1"] {
  transform: scaleX(-1);
}

/* 単発ポーズ */
.s-pose {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 4px 5px rgba(60, 80, 45, 0.26));
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: auto;
  cursor: pointer;
}
.s-pose[data-dir="1"] {
  transform: scaleX(-1);
}

/* 手を振る・あいさつのゆらゆら */
.actor.rock .s-pose {
  animation: mofu-rock 1.6s ease-in-out infinite;
  transform-origin: 50% 90%;
}
@keyframes mofu-rock {
  0%,
  100% {
    rotate: -3deg;
  }
  50% {
    rotate: 3.5deg;
  }
}

/* 吹き出しセリフ */
.bubble {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  translate: calc(-50% + var(--bubble-shift, 0px)) 0;
  background: rgba(255, 252, 244, 0.96);
  color: #5a4634;
  box-sizing: border-box;
  width: max-content;
  max-width: min(240px, calc(100vw - 16px));
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  padding: 0.32em 0.75em;
  border-radius: 14px;
  box-shadow: 0 3px 10px rgba(90, 70, 52, 0.18);
  pointer-events: none;
  animation: bubble-pop 0.28s cubic-bezier(0.34, 1.5, 0.64, 1);
}
.bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: clamp(12px, calc(50% + var(--bubble-tail-shift, 0px)), calc(100% - 12px));
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(255, 252, 244, 0.96);
}
@keyframes bubble-pop {
  from {
    transform: scale(0.5);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* 正面走り/後ろ姿のぽてぽて感 */
.actor.bobbing .s-pose {
  animation: mofu-hop-bob 0.38s ease-in-out infinite alternate;
}
@keyframes mofu-hop-bob {
  from {
    translate: 0 0;
  }
  to {
    translate: 0 -5px;
  }
}

/* なでなで中のうっとりゆらゆら */
.actor.petted .s-pose,
.actor.petted .s-strip {
  animation: mofu-pet 0.6s ease-in-out infinite;
}
@keyframes mofu-pet {
  0%,
  100% {
    rotate: -2.5deg;
    scale: 1 1;
  }
  50% {
    rotate: 2.5deg;
    scale: 1.02 1.03;
  }
}

/* そっと呼吸(待機アクター) */
.actor .s-pose {
  animation-name: mofu-breathe;
  animation-duration: 2.6s;
  animation-iteration-count: infinite;
  animation-timing-function: ease-in-out;
}
.actor.rock .s-pose {
  animation-name: mofu-rock;
}
@keyframes mofu-breathe {
  0%,
  100% {
    scale: 1 1;
  }
  50% {
    scale: 1.008 1.018;
  }
}

/* ---------- コンテンツ土台(装飾は site.css) ---------- */

main {
  position: relative;
  z-index: 10;
  /* たねやり: カード以外のクリックは草原(document)へ通す */
  pointer-events: none;
}

.panel {
  min-height: 110vh;
  display: flex;
  align-items: center;
}

.card,
.site-foot,
.friend {
  pointer-events: auto;
}

/* ---------- インタラクション(runtime/actors.ts が生成) ---------- */

.actor svg {
  pointer-events: auto;
  cursor: pointer;
}

.actor.startle {
  animation: mofu-hop 0.32s cubic-bezier(0.3, 1.6, 0.5, 1);
}
@keyframes mofu-hop {
  0%,
  100% {
    translate: 0 0;
  }
  40% {
    translate: 0 -13px;
  }
}

.seed {
  position: absolute;
  width: 15px;
  height: 21px;
  pointer-events: none;
  will-change: transform;
  filter: drop-shadow(0 2px 2px rgba(60, 80, 45, 0.35));
}

.fx {
  position: absolute;
  width: 26px;
  height: 26px;
  pointer-events: none;
  animation: fx-pop 0.8s ease-out forwards;
}
@keyframes fx-pop {
  0% {
    transform: translateY(0) scale(0.4);
    opacity: 0;
  }
  25% {
    transform: translateY(-8px) scale(1.1);
    opacity: 1;
  }
  100% {
    transform: translateY(-30px) scale(0.9);
    opacity: 0;
  }
}

.butterfly {
  position: absolute;
  width: 26px;
  pointer-events: none;
  will-change: transform;
}
.butterfly svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.butterfly .wing-l {
  transform-box: fill-box;
  transform-origin: right center;
  animation: bf-flap 0.52s ease-in-out infinite;
}
.butterfly .wing-r {
  transform-box: fill-box;
  transform-origin: left center;
  animation: bf-flap 0.52s ease-in-out infinite;
}
@keyframes bf-flap {
  0%,
  100% {
    transform: scaleX(1);
  }
  50% {
    transform: scaleX(0.32);
  }
}

.firefly {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: radial-gradient(
    circle at 50% 45%,
    #fffbe0 0%,
    #ffe98f 45%,
    rgba(255, 236, 150, 0) 72%
  );
  pointer-events: none;
  will-change: transform, opacity;
  animation: ff-glow 2.4s ease-in-out infinite;
}
@keyframes ff-glow {
  0%,
  100% {
    opacity: 0.15;
  }
  50% {
    opacity: 0.95;
  }
}

/* ---------- 今日の草原(v8): 時間帯・季節・天気の演出 ---------- */

/* 星 */
.mofu-star {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #fff7d9;
  box-shadow: 0 0 6px 1px rgba(255, 244, 200, 0.8);
  animation: mofu-twinkle 2.6s ease-in-out infinite;
  pointer-events: none;
}
.mofu-star.is-big {
  width: 5px;
  height: 5px;
}
@keyframes mofu-twinkle {
  0%,
  100% {
    opacity: 0.25;
  }
  50% {
    opacity: 1;
  }
}

/* 月 */
.mofu-moon {
  position: absolute;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 34%, #fffdf0 0%, #f6ecc4 55%, #e8d9a4 100%);
  box-shadow:
    0 0 34px 10px rgba(255, 246, 200, 0.35),
    0 0 90px 30px rgba(255, 246, 200, 0.14);
  pointer-events: none;
  animation: mofu-moon-breathe 5s ease-in-out infinite;
}
.mofu-moon::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 62% 40%, rgba(200, 180, 130, 0.28) 0 7%, transparent 8%),
    radial-gradient(circle at 40% 66%, rgba(200, 180, 130, 0.24) 0 5%, transparent 6%),
    radial-gradient(circle at 70% 70%, rgba(200, 180, 130, 0.2) 0 4%, transparent 5%);
}
@keyframes mofu-moon-breathe {
  0%,
  100% {
    box-shadow:
      0 0 34px 10px rgba(255, 246, 200, 0.35),
      0 0 90px 30px rgba(255, 246, 200, 0.14);
  }
  50% {
    box-shadow:
      0 0 44px 14px rgba(255, 246, 200, 0.42),
      0 0 110px 38px rgba(255, 246, 200, 0.18);
  }
}

/* 落ち葉(秋) */
.mofu-leaf {
  position: absolute;
  width: 16px;
  height: 16px;
  pointer-events: none;
  will-change: transform;
  filter: drop-shadow(0 2px 2px rgba(120, 80, 40, 0.25));
}
.mofu-leaf svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* 雪(冬・雪の日) */
.mofu-snowflake {
  position: absolute;
  width: 12px;
  height: 12px;
  pointer-events: none;
  will-change: transform;
}
.mofu-snowflake svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* 雨上がりの水滴(草の葉先で光る) */
.mofu-droplet {
  position: absolute;
  width: 6px;
  height: 8px;
  border-radius: 50% 50% 55% 55% / 40% 40% 60% 60%;
  background: radial-gradient(
    circle at 34% 30%,
    rgba(255, 255, 255, 0.95) 0%,
    rgba(190, 225, 245, 0.75) 45%,
    rgba(140, 190, 220, 0.35) 100%
  );
  pointer-events: none;
  animation: mofu-drip 4.2s ease-in-out infinite;
}
@keyframes mofu-drip {
  0%,
  100% {
    opacity: 0.35;
    transform: translateY(0) scale(1);
  }
  45% {
    opacity: 0.9;
    transform: translateY(1px) scale(1.06);
  }
  60% {
    opacity: 0.6;
    transform: translateY(3px) scale(0.94);
  }
}

/* 虹(雨上がりの昼)。#layer-sky(z1) に描画 → 丘(z2)が脚を隠し、奥に薄くかかる */
.mofu-rainbow {
  position: absolute;
  left: 42%;
  bottom: 38vh;
  width: min(52vw, 520px);
  aspect-ratio: 2.4 / 1;
  transform: translateX(-50%) translateY(20px);
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  background: radial-gradient(
    farthest-side at 50% 100%,
    transparent 0 60%,
    rgba(235, 130, 130, 0.28) 60% 66%,
    rgba(240, 185, 120, 0.28) 66% 72%,
    rgba(245, 228, 145, 0.28) 72% 78%,
    rgba(160, 212, 150, 0.28) 78% 84%,
    rgba(140, 182, 224, 0.28) 84% 90%,
    rgba(175, 158, 214, 0.28) 90% 96%,
    transparent 96%
  );
  opacity: 0;
  pointer-events: none;
  filter: blur(3.5px);
  will-change: transform, opacity;
}

/* なかまたちのポートレート(runtime/actors.ts がスプライト画像を注入) */
.portrait img {
  display: block;
  width: 148%;
  height: auto;
  margin-left: -24%;
  margin-top: -8%;
  user-select: none;
  -webkit-user-drag: none;
}

@media (max-width: 640px) {
  body {
    font-family: "Hiragino Maru Gothic ProN", system-ui, sans-serif;
  }

  #scene[data-time="night"] #tint {
    filter: none;
    inset: 0;
  }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .actor .s-pose,
  .actor.rock .s-pose {
    animation: none;
  }
  .actor {
    transition: none;
  }
  .actor.hidden-below {
    transform: none;
  }
  .actor.startle,
  .firefly,
  .fx,
  .actor.bobbing .s-pose,
  .actor.petted .s-pose,
  .actor.petted .s-strip,
  .bubble,
  .butterfly .wing-l,
  .butterfly .wing-r,
  .mofu-star,
  .mofu-moon,
  .mofu-droplet {
    animation: none;
  }
  .butterfly,
  .mofu-leaf,
  .mofu-snowflake {
    display: none;
  }
}
