/* 毛孩子日托班 · 独立互动层
 * 仅使用 .fun-* 命名空间；不更改地图尺寸、家庭顺序或已锁定状态。
 * data-beat 的静态终态也能独立表达剧情，减少动态时不会丢失信息。
 */
body.fun-open { overflow: hidden; }

/* 屋顶按钮完全脱离文档流：44px 点击区不侵占下方名字与投放区。 */
.fam > .fun-family,
.fam .h-roof .fun-family,
.daycare-home .fun-bell {
  position: absolute;
  z-index: 5;
  top: 3px;
  right: 3px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 4px;
  background: var(--card);
  color: var(--ink);
  font-size: 21px;
  line-height: 1;
  box-shadow: 2px 2px 0 rgba(74, 59, 42, .18);
  touch-action: manipulation;
}
.daycare-home .fun-bell { top: 0; right: 0; background: var(--accent); }
.fam .fun-family:hover,
.fam .fun-family:active,
.daycare-home .fun-bell:hover,
.daycare-home .fun-bell:active { transform: none; background: var(--accent); }
.gw-header .fun-launch {
  min-height: 36px;
  padding: 5px 10px;
  background: var(--pink);
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  box-shadow: 2px 2px 0 rgba(74, 59, 42, .2);
}

/* 独立于 .modal-mask；滚动发生在对话框内而非背景地图。 */
.fun-mask {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 16px;
  overflow: auto;
  overscroll-behavior: contain;
  background: rgba(55, 44, 31, .58);
}
.fun-mask[hidden] { display: none; }
.fun-dialog {
  width: min(480px, 100%);
  min-width: 0;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  padding: 0 18px 18px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-block: 76px 16px;
  color: var(--ink);
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: 6px;
  box-shadow: 6px 6px 0 rgba(30, 22, 12, .3);
  scrollbar-gutter: stable;
  overflow-wrap: anywhere;
}
.fun-heading {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  column-gap: 10px;
  align-items: center;
  padding: 12px 0 10px;
  background: var(--card);
  border-bottom: 2px dashed rgba(74, 59, 42, .25);
}
.fun-title { grid-column: 1; margin: 2px 0 0; font-size: 20px; line-height: 1.4; }
button.fun-close {
  grid-column: 2;
  grid-row: 1;
  width: 44px;
  height: 44px;
  min-width: 44px;
  padding: 0;
  background: #f7efdb;
  font-size: 20px;
  line-height: 1;
}
.fun-dialog button { max-width: 100%; touch-action: manipulation; }
.fun-dialog button:focus-visible,
.fun-dialog:focus-visible,
.fun-family:focus-visible,
.fun-bell:focus-visible,
.fun-launch:focus-visible {
  outline: 3px solid #276b9a;
  outline-offset: 3px;
}
/* 屋顶父卡 overflow:hidden，焦点圈向内避免被裁掉。 */
.fam .fun-family:focus-visible { outline-offset: -5px; }
.fun-dialog button:disabled { cursor: default; opacity: .6; transform: none; box-shadow: none; }

.fun-stage {
  display: block;
  width: 100%;
  padding: 0;
  font-weight: normal;
  box-shadow: none;
  touch-action: manipulation;
  position: relative;
  isolation: isolate;
  min-width: 0;
  min-height: 212px;
  margin-top: 12px;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 4px;
  background-color: #f5f1dc;
  background-image: linear-gradient(to bottom, transparent 76%, var(--grass1) 76%), radial-gradient(circle, rgba(74, 59, 42, .08) 1px, transparent 1.5px);
  background-size: 100% 100%, 12px 12px;
}
.fun-dialog .fun-stage:hover, .fun-dialog .fun-stage:active {
  transform: none;
  box-shadow: none;
  border-color: var(--accent-d);
}
.fun-dialog .fun-stage:focus-visible { outline: 3px solid #276b9a; outline-offset: 3px; }
.fun-cast {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 24%;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  padding: 0 8px;
}
.fun-pet {
  --pet-x: 0px;
  --pet-y: 0px;
  --pet-turn: 0deg;
  flex: 0 1 104px;
  min-width: 0;
  margin: 0;
  text-align: center;
}
.fun-pet-image {
  display: block;
  width: 96px;
  height: 96px;
  max-width: 100%;
  margin: 0 auto;
  object-fit: contain;
  image-rendering: pixelated;
  transform: translate(var(--pet-x), var(--pet-y)) rotate(var(--pet-turn));
  transform-origin: 50% 85%;
}
.fun-props { position: absolute; z-index: 1; inset: 0; pointer-events: none; }
.fun-prop {
  position: absolute;
  font-size: 28px;
  line-height: 1;
  transform-origin: 50% 80%;
}
.fun-paws { left: calc(50% - 14px); bottom: 12px; opacity: .6; font-size: 23px; }
.fun-door { right: 10px; top: 43px; font-size: 43px; }
.fun-toys {
  position: absolute;
  bottom: 12px;
  left: 50%;
  display: flex;
  gap: 10px;
  transform: translateX(-50%);
}
.fun-toy { display: block; width: 16px; height: 16px; border: 2px solid var(--line); background: var(--pink); }
.fun-toy:nth-child(2) { background: var(--accent); transform: translateY(-5px) rotate(12deg); }
.fun-toy:nth-child(3) { background: var(--blue, #7cc4e8); transform: translateY(3px); }
.fun-grass { left: calc(50% - 78px); bottom: 38px; }
.fun-box { right: 20px; bottom: 30px; font-size: 38px; }
.fun-sock { left: 36%; bottom: 38px; font-size: 25px; }
.fun-thought { left: calc(50% - 20px); top: 17px; padding: 0 9px 3px; background: var(--card); border: 2px solid var(--line); font-size: 25px; }
.fun-heart-one { left: calc(50% - 48px); top: 24px; color: #b83b57; opacity: 0; }
.fun-heart-two { left: calc(50% + 22px); top: 31px; color: #b83b57; font-size: 22px; opacity: 0; }

/* A：三只原图集合、靠近、各自探头；不改变 DOM 顺序。 */
.fun-stage[data-scene="A"][data-beat="1"] .fun-pet:nth-child(1) { --pet-x: 7px; }
.fun-stage[data-scene="A"][data-beat="1"] .fun-pet:nth-child(3) { --pet-x: -7px; }
.fun-stage[data-scene="A"][data-beat="1"] .fun-pet-image { animation: fun-hop 550ms ease-out both; }
.fun-stage[data-scene="A"][data-beat="1"] .fun-pet:nth-child(2) .fun-pet-image { animation-delay: 60ms; }
.fun-stage[data-scene="A"][data-beat="1"] .fun-pet:nth-child(3) .fun-pet-image { animation-delay: 110ms; }
.fun-stage[data-scene="A"][data-beat="2"] .fun-pet:first-child { --pet-x: 14px; }
.fun-stage[data-scene="A"][data-beat="2"] .fun-pet:nth-child(3) { --pet-x: -14px; }
.fun-stage[data-scene="A"][data-beat="2"] .fun-pet-image { animation: fun-arrive 500ms ease-out both; }
.fun-stage[data-scene="A"][data-beat="3"] .fun-pet:first-child { --pet-x: -5px; --pet-turn: -4deg; }
.fun-stage[data-scene="A"][data-beat="3"] .fun-pet:nth-child(2) { --pet-y: -3px; }
.fun-stage[data-scene="A"][data-beat="3"] .fun-pet:nth-child(3) { --pet-x: 5px; --pet-turn: 4deg; }
.fun-stage[data-scene="A"][data-beat="3"] .fun-pet-image { animation: fun-peek 550ms ease-out both; }

/* B：靠门、稍退、错身让路。 */
.fun-stage[data-scene="B"] .fun-cast { padding-right: 34px; }
.fun-stage[data-scene="B"][data-beat="1"] .fun-pet { --pet-x: 10px; }
.fun-stage[data-scene="B"][data-beat="1"] .fun-pet-image { animation: fun-arrive 500ms ease-out both; }
.fun-stage[data-scene="B"][data-beat="2"] .fun-pet:first-child { --pet-x: 10px; }
.fun-stage[data-scene="B"][data-beat="2"] .fun-pet:nth-child(2) { --pet-x: -6px; --pet-y: 3px; }
.fun-stage[data-scene="B"][data-beat="2"] .fun-pet-image { animation: fun-peek 500ms ease-out both; }
.fun-stage[data-scene="B"][data-beat="3"] .fun-pet:first-child { --pet-x: 13px; --pet-y: -4px; }
.fun-stage[data-scene="B"][data-beat="3"] .fun-pet:nth-child(2) { --pet-x: 2px; --pet-y: 3px; }
.fun-stage[data-scene="B"][data-beat="3"] .fun-pet-image { animation: fun-arrive 550ms ease-out both; }

/* C：方块自己说故事，不需要狗狗伸爪。 */
.fun-stage[data-scene="C"][data-beat="1"] .fun-toy { transform: none; animation: fun-toy-settle 500ms ease-out both; }
.fun-stage[data-scene="C"][data-beat="2"] .fun-toy:nth-child(2),
.fun-stage[data-scene="C"][data-beat="3"] .fun-toy:nth-child(2) { transform: translate(4px, -2px) rotate(18deg); }
.fun-stage[data-scene="C"][data-beat="2"] .fun-toy:nth-child(2) { animation: fun-toy-tip 500ms ease-out both; }
.fun-stage[data-scene="C"][data-beat="2"] .fun-pet:nth-child(2) .fun-pet-image { animation: fun-hop 600ms ease-out both; }
/* 第三拍故意不动画：大家停住看歪掉的方块。 */

/* D：脚边的草、绕开、恢复干净。 */
.fun-stage[data-scene="D"][data-beat="0"] .fun-grass { opacity: .45; }
.fun-stage[data-scene="D"][data-beat="1"] .fun-grass { animation: fun-grass-show 450ms ease-out both; }
.fun-stage[data-scene="D"][data-beat="2"] .fun-pet:nth-child(2) { --pet-x: 10px; --pet-turn: 3deg; }
.fun-stage[data-scene="D"][data-beat="2"] .fun-pet:nth-child(2) .fun-pet-image { animation: fun-hop 600ms ease-out both; }
.fun-stage[data-scene="D"][data-beat="3"] .fun-grass { visibility: hidden; opacity: 0; }
.fun-stage[data-scene="D"][data-beat="3"] .fun-pet-image { animation: fun-arrive 450ms ease-out both; }

/* E：袜子在盒边和狗旁移动；第三拍从盒沿露出来。 */
.fun-stage[data-scene="E"][data-beat="1"] .fun-sock { left: auto; right: 48px; bottom: 37px; animation: fun-sock-slide 550ms ease-out both; }
.fun-stage[data-scene="E"][data-beat="2"] .fun-sock { animation: fun-sock-return 550ms ease-out both; }
.fun-stage[data-scene="E"][data-beat="3"] .fun-sock { left: auto; right: 23px; bottom: 57px; transform: rotate(14deg); animation: fun-sock-reveal 500ms ease-out both; }

/* F：不拉伸脸或身体，只改变整张原图的极少透明度与位置。 */
.fun-stage[data-scene="F"][data-beat="2"] .fun-pet-image { opacity: .94; animation: fun-slow-blink 650ms ease-in-out both; }
.fun-stage[data-scene="F"][data-beat="3"] .fun-pet { --pet-y: -3px; --pet-turn: -2deg; }
.fun-stage[data-scene="F"][data-beat="3"] .fun-pet-image { animation: fun-arrive 650ms ease-out both; }

/* G：只按当前 cast 顺序轻靠近；不写入任何姓名、品种或配对。 */
.fun-stage[data-scene="G"][data-beat="1"] .fun-pet:first-child { --pet-x: 5px; }
.fun-stage[data-scene="G"][data-beat="1"] .fun-pet:first-child .fun-pet-image { animation: fun-arrive 550ms ease-out both; }
.fun-stage[data-scene="G"][data-beat="1"] .fun-heart-one,
.fun-stage[data-scene="G"][data-beat="2"] .fun-heart-one,
.fun-stage[data-scene="G"][data-beat="3"] .fun-heart-one { opacity: 1; }
.fun-stage[data-scene="G"][data-beat="1"] .fun-heart-one { animation: fun-heart-rise 550ms ease-out both; }
.fun-stage[data-scene="G"][data-beat="2"] .fun-pet:first-child { --pet-x: 5px; }
.fun-stage[data-scene="G"][data-beat="2"] .fun-heart-two,
.fun-stage[data-scene="G"][data-beat="3"] .fun-heart-two { opacity: 1; }
.fun-stage[data-scene="G"][data-beat="2"] .fun-heart-two { animation: fun-heart-rise 550ms ease-out both; }
.fun-stage[data-scene="G"][data-beat="3"] .fun-pet:first-child { --pet-x: 9px; }
.fun-stage[data-scene="G"][data-beat="3"] .fun-pet:nth-child(2) { --pet-x: -9px; }
.fun-stage[data-scene="G"][data-beat="3"] .fun-pet-image { animation: fun-arrive 550ms ease-out both; }

/* 门铃场景只呈现门铃与门牌，决不以狗或脚印表示隐藏数量。 */
.fun-stage[data-scene="bell"] { min-height: 188px; background-color: #f7efdb; }
.fun-stage[data-scene="bell"] .fun-cast,
.fun-stage[data-scene="bell"] .fun-paws { display: none; }
.fun-chime { top: 28px; left: calc(50% - 22px); font-size: 44px; transform-origin: 50% 10%; }
.fun-door-sign {
  position: absolute;
  top: 97px;
  left: 50%;
  width: max-content;
  max-width: calc(100% - 28px);
  padding: 7px 12px;
  border: 2px solid var(--line);
  border-radius: 3px;
  background: var(--accent);
  color: var(--ink);
  box-shadow: 3px 3px 0 rgba(74, 59, 42, .18);
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  transform: translateX(-50%);
  transform-origin: 50% 0;
}
.fun-stage[data-scene="bell"][data-beat="0"] .fun-chime,
.fun-stage[data-scene="bell"][data-beat="2"] .fun-chime { animation: fun-bell-left 600ms ease-out both; }
.fun-stage[data-scene="bell"][data-beat="1"] .fun-chime,
.fun-stage[data-scene="bell"][data-beat="3"] .fun-chime { animation: fun-bell-right 600ms ease-out both; }
.fun-stage[data-scene="bell"][data-beat="0"] .fun-door-sign,
.fun-stage[data-scene="bell"][data-beat="2"] .fun-door-sign { animation: fun-sign-left 650ms ease-out both; }
.fun-stage[data-scene="bell"][data-beat="1"] .fun-door-sign,
.fun-stage[data-scene="bell"][data-beat="3"] .fun-door-sign { animation: fun-sign-right 650ms ease-out both; }

.fun-line { margin: 12px 0 0; font-size: 14px; line-height: 1.6; text-align: center; }
.fun-line[hidden] { display: none; }
.fun-dialogue { display: block; }
.fun-speaker { color: #85601c; }
.fun-controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 14px; padding: 3px; }
.fun-controls button { min-height: 44px; padding: 8px 13px; font-size: 13px; line-height: 1.5; }
button.fun-back { background: #f7efdb; }
button.fun-sound { background: var(--card); font-size: 12px; }
button.fun-sound[aria-pressed="true"] { background: var(--grass1); border-style: double; }
.fun-menu { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 16px 3px 3px; }
button.fun-menu-item { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0; min-height: 64px; padding: 10px; background: #f7efdb; text-align: left; }
.fun-menu-owner { font-size: 14px; line-height: 1.4; }
.fun-menu-title { font-size: 11px; font-weight: normal; line-height: 1.5; color: var(--ink2, #8a7a60); }

@keyframes fun-hop {
  0%, 100% { transform: translate(var(--pet-x), var(--pet-y)) rotate(var(--pet-turn)); }
  42% { transform: translate(var(--pet-x), calc(var(--pet-y) - 9px)) rotate(var(--pet-turn)); }
}
@keyframes fun-arrive {
  from { transform: translate(0, 0); }
  to { transform: translate(var(--pet-x), var(--pet-y)) rotate(var(--pet-turn)); }
}
@keyframes fun-peek {
  from { transform: translate(0, 0) rotate(0deg); }
  to { transform: translate(var(--pet-x), var(--pet-y)) rotate(var(--pet-turn)); }
}
@keyframes fun-toy-settle { from { translate: 0 -4px; } to { translate: 0 0; } }
@keyframes fun-toy-tip { from { transform: none; } to { transform: translate(4px, -2px) rotate(18deg); } }
@keyframes fun-grass-show { from { transform: translateY(4px) rotate(-5deg); } to { transform: none; } }
@keyframes fun-sock-slide { from { transform: translateX(-24px) rotate(-8deg); } to { transform: none; } }
@keyframes fun-sock-return { from { transform: translateX(24px) rotate(8deg); } to { transform: none; } }
@keyframes fun-sock-reveal { from { transform: translateY(7px) rotate(0deg); } to { transform: rotate(14deg); } }
@keyframes fun-slow-blink { 0%, 100% { opacity: 1; } 50% { opacity: .94; } }
@keyframes fun-heart-rise { from { transform: translateY(5px); } to { transform: none; } }
@keyframes fun-bell-left { 0%, 100% { transform: rotate(0deg); } 30% { transform: rotate(-9deg); } 65% { transform: rotate(5deg); } }
@keyframes fun-bell-right { 0%, 100% { transform: rotate(0deg); } 30% { transform: rotate(9deg); } 65% { transform: rotate(-5deg); } }
@keyframes fun-sign-left { 0%, 100% { transform: translateX(-50%) rotate(0deg); } 35% { transform: translateX(-50%) rotate(-2deg); } 70% { transform: translateX(-50%) rotate(1deg); } }
@keyframes fun-sign-right { 0%, 100% { transform: translateX(-50%) rotate(0deg); } 35% { transform: translateX(-50%) rotate(2deg); } 70% { transform: translateX(-50%) rotate(-1deg); } }

/* 320px 窄屏使用原生 48px 犬图，三个名字和道具均不撑宽。 */
@media (max-width: 420px) {
  .fun-mask { padding: 8px; }
  .fun-dialog { max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); padding: 0 12px 14px; }
  .fun-title { font-size: 18px; }
  .fun-stage { min-height: 164px; }
  .fun-cast { gap: 4px; padding: 56px 8px 25px; }
  .fun-pet { flex-basis: 64px; }
  .fun-pet-image { width: 48px; height: 48px; }
  .fun-pet-name { font-size: 11px; }
  .fun-door { right: 5px; top: 38px; font-size: 32px; }
  .fun-grass { left: calc(50% - 59px); bottom: 35px; }
  .fun-box { right: 8px; font-size: 30px; }
  .fun-stage[data-scene="E"][data-beat="1"] .fun-sock { right: 31px; }
  .fun-stage[data-scene="E"][data-beat="3"] .fun-sock { right: 12px; bottom: 50px; }
  .fun-line { font-size: 13px; }
  .fun-controls { gap: 8px; }
  .fun-controls button { padding-inline: 10px; }
  .fun-menu { gap: 10px; }
}
/* 矮屏保留 44px 控件和粘性关闭键，内容可自然向下滚动。 */
@media (max-height: 420px) {
  .fun-mask { padding: 6px; }
  .fun-dialog { max-height: calc(100vh - 12px); max-height: calc(100dvh - 12px); padding-bottom: 12px; scroll-padding-top: 64px; }
  .fun-heading { padding-block: 6px; }
  .fun-title { font-size: 17px; }
  .fun-stage { min-height: 140px; margin-top: 8px; }
  .fun-cast { gap: 6px; }
  .fun-pet { flex-basis: 64px; }
  .fun-pet-image { width: 48px; height: 48px; }
  .fun-stage[data-scene="bell"] { min-height: 140px; }
  .fun-chime { top: 13px; font-size: 36px; }
  .fun-door-sign { top: 67px; }
  .fun-heart-one, .fun-heart-two, .fun-thought { top: 8px; }
  .fun-line { margin-top: 8px; }
  .fun-controls { margin-top: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .fun-mask, .fun-mask *, .fun-mask *::before, .fun-mask *::after,
  .fun-family, .fun-bell, .fun-launch {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
  .fun-stage[data-scene="F"][data-beat="2"] .fun-pet-image { opacity: .94; }
}
