/* The visitor's little kimono person (js/avatar.js, drawings in js/avatar-art.js): idle life, walking on
   the path, the dress-up sheet, the prayer poses in the worship hall; the shrine's people (js/npc.js) and
   the speech bubbles (js/bubble.js). Transform origins are in the drawing's units (feet at 0 0). */

/* ---------- the drawing's moving parts ---------- */
.av-svg { display: block; width: 100%; height: 100%; overflow: visible; }
.av-svg * { transform-box: view-box; }
.av-up { transform-origin: 0 -8px; }
.av-top { transform-origin: 0 -46px; }
.av-head { transform-origin: 0 -72px; }
.av-eyes { transform-origin: 0 -94.5px; }
.av-sl.l { transform-origin: -19px -69px; }
.av-sl.r { transform-origin: 19px -69px; }
.av-bow { transform-origin: 0 -46px; }
.av-charm { transform-origin: 0 0; }
.av-ft { transition: transform .12s; }
.av-peek { opacity: 0; transition: opacity .3s; }

/* alive: breathing, blinking, the sleeves and the charms sway a little */
.av-live .av-up { animation: avBreathe 3.4s ease-in-out infinite; }
.av-live .av-eyes { animation: avBlink 4.8s ease-in-out infinite; }
.av-live .av-sl.l { animation: avSleeveL 3.6s ease-in-out infinite; }
.av-live .av-sl.r { animation: avSleeveR 3.6s ease-in-out infinite; animation-delay: -1.1s; }
.av-live .av-charm { animation: avCharm 2.6s ease-in-out infinite; }
@keyframes avBreathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.012, 1.022); } }
@keyframes avBlink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.08); } }
@keyframes avSleeveL { 0%, 100% { transform: rotate(-2.4deg); } 50% { transform: rotate(2.4deg); } }
@keyframes avSleeveR { 0%, 100% { transform: rotate(2.4deg); } 50% { transform: rotate(-2.4deg); } }
@keyframes avCharm { 0%, 100% { transform: rotate(-7deg); } 50% { transform: rotate(7deg); } }

/* walking: a clear bobbing two-step (one cycle = two steps), the sleeves swing, the feet lift in turn */
.walking .pa-bob { animation: avBob .8s ease-in-out infinite; }
.walking .av-ft.l { animation: avStepL .8s ease-in-out infinite; }
.walking .av-ft.r { animation: avStepR .8s ease-in-out infinite; }
.walking .av-sl.l { animation: avSwingL .8s ease-in-out infinite; }
.walking .av-sl.r { animation: avSwingR .8s ease-in-out infinite; }
.walking .av-up { animation: avLean .8s ease-in-out infinite; }
@keyframes avBob { 0%, 50%, 100% { transform: translateY(0); } 25%, 75% { transform: translateY(-9%); } }
@keyframes avStepL { 0%, 50%, 100% { transform: translateY(0); } 25% { transform: translateY(-5px); } }
@keyframes avStepR { 0%, 50%, 100% { transform: translateY(0); } 75% { transform: translateY(-5px); } }
@keyframes avSwingL { 0%, 100% { transform: rotate(-11deg); } 50% { transform: rotate(11deg); } }
@keyframes avSwingR { 0%, 100% { transform: rotate(-11deg); } 50% { transform: rotate(11deg); } }
@keyframes avLean { 0%, 50%, 100% { transform: rotate(0); } 25% { transform: rotate(-2.5deg); } 75% { transform: rotate(2.5deg); } }

/* ---------- on the path ---------- */
/* the people of the path live in this layer, under the spots (a spot always wins a tap). They belong to the
   path alone: hidden (and out of every hit test) unless the path is the view shown and has finished zooming
   in (main.js sets .actors-on); everything inside inherits, so no part of them can show through a spot view */
.path-actors { position: absolute; inset: 0; pointer-events: none; }
.view-path:not(.actors-on) .path-actors, .view-path:not(.actors-on) .path-actors * { visibility: hidden !important; }
.view-path.actors-on .path-actors { animation: actorsIn .28s ease-out; }
@keyframes actorsIn { from { opacity: 0; } to { opacity: 1; } }
.pa-avatar {
  position: absolute; left: 0; top: 0; z-index: 2; width: calc(51 / 390 * 100%); aspect-ratio: 100 / 158;
  padding: 0; margin: 0; border: 0; background: none; cursor: pointer; pointer-events: auto;
  -webkit-tap-highlight-color: transparent; will-change: transform;
}
.pa-avatar:focus-visible { outline-offset: 0; }
.pa-bob, .pa-hop, .pa-turn { position: absolute; inset: 0; }
.pa-avatar .av-svg { position: absolute; inset: 0; }
.pa-avatar .av-svg.back { visibility: hidden; }
.pa-avatar.from-back .av-svg.back { visibility: inherit; }
.pa-avatar.from-back .av-svg.front { visibility: hidden; }
/* a small dot until the visitor has opened the dress-up once */
.pa-dot {
  position: absolute; right: 8%; top: 4%; width: 11px; height: 11px; border-radius: 50%;
  background: #ffb3a1; box-shadow: 0 0 0 2.5px #fff, 0 2px 6px rgba(110, 95, 170, .25);
  animation: paDot 1.6s ease-in-out infinite;
}
@keyframes paDot { 0%, 100% { transform: scale(.85); } 50% { transform: scale(1.15); } }

/* ---------- the speech bubble (js/bubble.js) ---------- */
.bubble {
  position: absolute; z-index: 6; left: 0; top: 0; width: max-content; max-width: min(230px, 72vw);
  padding: 8px 13px 9px; border-radius: 16px; pointer-events: none;
  background: #fffdf8; border: 2.5px solid #e6dcf7; box-shadow: 0 3px 0 #e6dcf7, 0 8px 18px rgba(110, 95, 170, .14);
  color: var(--ink); font-size: 14.5px; font-weight: 600; line-height: 1.25; text-align: center;
  opacity: 0; transform: translate(-50%, calc(-100% - 12px)) scale(.8); transform-origin: var(--tail, 50%) 100%;
  transition: opacity .2s, transform .28s cubic-bezier(.3, 1.5, .5, 1);
}
.bubble.show { opacity: 1; transform: translate(-50%, calc(-100% - 12px)) scale(1); }
.bubble::after {
  content: ''; position: absolute; left: var(--tail, 50%); bottom: -9px; width: 14px; height: 14px; margin-left: -7px;
  background: #fffdf8; border-right: 2.5px solid #e6dcf7; border-bottom: 2.5px solid #e6dcf7; border-bottom-right-radius: 4px;
  transform: rotate(45deg) scale(.85, .85);
}
.bubble.sheep { border-color: #f6cdb9; box-shadow: 0 3px 0 #f6cdb9, 0 8px 18px rgba(110, 95, 170, .14); }
.bubble.sheep::after { border-color: #f6cdb9; }
.bubble.you { border-color: #ffc8ba; box-shadow: 0 3px 0 #ffc8ba, 0 8px 18px rgba(110, 95, 170, .14); color: var(--coral-ink); }
.bubble.you::after { border-color: #ffc8ba; }

/* a little heart, a poof, sparkles */
.npc-heart { position: absolute; z-index: 6; width: 22px; height: 22px; pointer-events: none; }
.npc-heart svg { width: 100%; height: 100%; overflow: visible; }

/* ---------- the dress-up sheet ---------- */
.dress {
  position: fixed; z-index: 23; left: 0; right: 0; bottom: 0; top: calc(env(safe-area-inset-top) + var(--head) + 8px);
  max-width: var(--col); margin: 0 auto;
  display: flex; flex-direction: column;
  background: rgba(255, 252, 247, .99); border: 2.5px solid #efe3f6; border-bottom: 0; border-radius: 28px 28px 0 0;
  box-shadow: 0 -8px 30px rgba(110, 95, 170, .16);
  transform: translateY(105%); visibility: hidden;
  transition: transform .38s cubic-bezier(.3, 1.1, .4, 1), visibility 0s .38s;
}
.dress.open { transform: none; visibility: visible; transition: transform .42s cubic-bezier(.3, 1.15, .4, 1), visibility 0s; }
.dress-scrim { position: fixed; inset: 0; z-index: 22; background: rgba(120, 104, 170, .14); opacity: 0; visibility: hidden; transition: opacity .3s, visibility 0s .3s; }
.dress-scrim.open { opacity: 1; visibility: visible; transition: opacity .3s; }
.dress-stage { position: relative; flex: none; height: min(36dvh, 300px); display: flex; justify-content: center; align-items: flex-end; padding-bottom: 6px; }
.dress-stage::before { /* a soft round spot of light under the figure */
  content: ''; position: absolute; left: 50%; bottom: 6px; width: min(66%, 250px); aspect-ratio: 1.6; translate: -50% 0; border-radius: 50%;
  background: radial-gradient(closest-side, #fff4dc, rgba(255, 236, 214, .55) 60%, rgba(255, 236, 214, 0));
}
.dress-fig { position: relative; height: calc(100% - 4px); aspect-ratio: 100 / 158; }
.dress-fig .av-svg { position: absolute; inset: 0; }
.dress-fig .av-svg.back { visibility: hidden; }
.dress-fig.turned .av-svg.back { visibility: inherit; }
.dress-fig.turned .av-svg.front { visibility: hidden; }
.dress-turn { position: absolute; right: 14px; top: 10px; }
.dress-rows { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 2px 0 8px; scrollbar-width: none; }
.dress-rows::-webkit-scrollbar { display: none; }
.dress-row { padding: 2px 0 4px; }
.dress-label { margin: 0 0 1px 18px; font-size: 13px; font-weight: 700; color: var(--ink-soft); letter-spacing: .02em; }
.dress-opts { display: flex; gap: 6px; padding: 3px 16px 4px; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; }
.dress-opts::-webkit-scrollbar { display: none; }
.dress-opt {
  flex: none; width: 46px; height: 46px; padding: 2px; border-radius: 50%; border: 0; cursor: pointer;
  background: #fff; box-shadow: 0 0 0 2px #ece5f7, 0 3px 0 #ece5f7;
  display: grid; place-items: center; -webkit-tap-highlight-color: transparent;
  transition: transform .15s, box-shadow .15s;
}
.dress-opt svg { width: 40px; height: 40px; }
.dress-opt[aria-pressed="true"] { box-shadow: 0 0 0 3px #b3a5f2, 0 3px 0 #b3a5f2; }
.dress-opt:active { transform: scale(.92); }
.dress-opt.wide { width: 58px; border-radius: 18px; }
.dress-opt.wide svg { width: 52px; height: 40px; }
.dress-actions {
  flex: none; display: flex; gap: 8px; justify-content: flex-end; align-items: center;
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom)); border-top: 2px solid #f3ecf8;
}
.dress-actions .btn { min-height: 46px; padding: 0 16px; white-space: nowrap; }
/* Cancel: quiet, at the far left (the season button is hidden while the sheet is open) */
.dress-actions .dress-cancel { margin-right: auto; background: transparent; border-color: transparent; box-shadow: none; color: var(--ink-soft); padding: 0 10px; }
.dress-actions .dress-cancel:active { transform: translateY(2px); box-shadow: none; }
@media (max-width: 350px) { .dress-actions { gap: 6px; padding-left: 8px; padding-right: 8px; } .dress-actions .btn { padding: 0 13px; font-size: 16px; } .dress-actions .dress-cancel { padding: 0 6px; } }
body[data-dress="open"] .season-btn { visibility: hidden; opacity: 0; pointer-events: none; }
body[data-dress="open"] .path-hint { visibility: hidden; }
/* the poof of "Surprise me" */
.dress-poof { position: absolute; left: 50%; top: 55%; width: 70%; aspect-ratio: 1; translate: -50% -50%; pointer-events: none; opacity: 0; }
.dress-poof svg { width: 100%; height: 100%; overflow: visible; }

/* ---------- in the spots (js/avatar.js createSpotAvatar): the visitor from behind ---------- */
/* the box is the drawing's (100 × 158, the feet 6/158 above its bottom); each spot places it below */
.sp-avatar { position: absolute; z-index: 3; aspect-ratio: 100 / 158; pointer-events: none; }
.sp-aside, .sp-avatar .pa-hop { position: absolute; inset: 0; }
.sp-avatar .av-svg { position: absolute; inset: 0; }
.sp-avatar[data-face="back"] .av-svg.front, .sp-avatar[data-face="front"] .av-svg.back { visibility: hidden; }
.sp-avatar .av-sl, .sp-avatar .av-head, .sp-avatar .av-up, .sp-avatar .av-top { transition: transform .35s ease; }
.sp-avatar .sp-aside { transition: opacity .35s ease; }

/* the worship hall: before the offering box, its head below the 奉納 plate, its feet on the ground just
   in front of the hall (the step dots sit lower, css/haiden.css gives them the room) */
.hd-avatar {
  /* as tall as the room between the plate's lower edge and the feet allows: the feet go (pad - 8px) below
     the hall, so it grows with that drop (≈ 79 px tall on a 390 phone, was 72) */
  left: 50%; bottom: calc(8px - var(--hd-pad, 30px)); width: calc(10% + (var(--hd-pad, 30px) - 8px) * .62);
  translate: -50% 3.8%;
}
.hd-av-glow {
  position: absolute; left: 50%; top: 52%; width: 260%; aspect-ratio: 1; translate: -50% -50%; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 246, 205, .95), rgba(255, 228, 160, .55) 45%, rgba(255, 220, 160, 0) 100%);
  opacity: 0; transform: scale(.4); transition: opacity .5s, transform 2.4s cubic-bezier(.3, .1, .4, 1);
}
.hd-avatar.glow .hd-av-glow { opacity: 1; transform: scale(1); }
.hd-avatar[data-pose="clap"] .av-sl.l { transform: rotate(-7deg); }
.hd-avatar[data-pose="clap"] .av-sl.r { transform: rotate(7deg); }
.hd-avatar[data-pose="wish"] .av-sl.l { transform: rotate(-15deg); }
.hd-avatar[data-pose="wish"] .av-sl.r { transform: rotate(15deg); }
.hd-avatar[data-pose="wish"] .av-head { transform: translateY(3px); }
.hd-avatar[data-pose="done"] .av-head { transform: rotate(7deg); }
.hd-avatar[data-pose="done"] .av-peek { opacity: 1; }
.hd-avatar[data-pose="clap"] .av-sl, .hd-avatar[data-pose="wish"] .av-sl { animation: none; }

/* the omikuji corner: on the ground between the omikuji box and the rack (a flex item of the row),
   three-quarter from behind, turned toward the box on its left */
.sp-omikuji {
  --lean: -1;
  position: relative; flex: none; z-index: 2; align-self: flex-end;
  width: calc(var(--u) * .33); margin-left: calc(var(--u) * .06); margin-right: calc(var(--u) * -.12); margin-bottom: calc(var(--u) * -.012);
}
.sp-omikuji[data-face="back"] .av-head { transform: rotate(-5deg) translateX(-1px); }
.sp-omikuji[data-pose="coin"] .av-head { transform: rotate(-8deg) translateY(2px); }
.sp-omikuji[data-pose="stick"] .av-up { transform: rotate(-6deg); }
.sp-omikuji[data-pose="stick"] .av-head { transform: rotate(-10deg) translate(-2px, 2px); }
.sp-omikuji[data-pose="shake"] .pa-hop { animation: spBob .3s ease-in-out infinite alternate; }
.sp-omikuji[data-face="front"] .av-head { transform: none; }
.sp-omikuji[data-pose="slip"][data-happy] .av-sl.l { transform: rotate(-24deg); }
.sp-omikuji[data-pose="slip"][data-happy] .av-sl.r { transform: rotate(24deg); }
.sp-omikuji[data-pose="slip"][data-happy] .pa-hop { animation: spHappy .9s ease-in-out infinite; }
/* while the box is large for shaking it steps aside (omikuji.js moves it) and fades behind the box */
.sp-omikuji.stepped .sp-aside { opacity: .45; }
.scene.focus .sp-omikuji { z-index: 0; }
@keyframes spBob { from { transform: translateY(0); } to { transform: translateY(-5%); } }
@keyframes spHappy { 0%, 100% { transform: translateY(0); } 30% { transform: translateY(-9%); } 50% { transform: translateY(0); } 65% { transform: translateY(-4%); } }

/* the ema rack: in front of the table, to its right, between the table's leg and the post */
.sp-ema {
  --lean: -1;
  left: 82.6%; bottom: 0.6%; width: 15%; translate: -50% 3.8%;
}
.sp-ema[data-pose="look"] .av-head { transform: rotate(-7deg) translateY(-2px); }
.sp-ema[data-pose="look"] .av-up { transform: rotate(-2deg); }
.sp-ema[data-pose="hang"] .av-head { transform: translateY(-3px); }
.sp-ema[data-pose="done"] .av-sl.l { transform: rotate(-20deg); }
.sp-ema[data-pose="done"] .av-sl.r { transform: rotate(20deg); }

/* the shrine office: before the counter of the window in use (phones: the one shown), under the book
   or under My charms; on a wide window at rest, in the middle, before the shared post */
.sp-goshuin {
  --lean: -1;
  /* in the scene, beside the building (the building's mask would cut its feet off): the building's left is
     --xg (goshuin shown) or --xo (omamori shown), its width W × 1.875; window units / 750 */
  left: calc(var(--xg) + var(--W) * 1.875 * .1867); bottom: 1px; width: calc(var(--W) * .098 + var(--of-lift, 0px) * .55);
  translate: -50% 3.8%;
  transition: left .55s cubic-bezier(.45, 0, .25, 1);
}
.view-office[data-tab="omamori"] .sp-goshuin { left: calc(var(--xo) + var(--W) * 1.875 * .6533); }
.view-office.of-wide .sp-goshuin { left: calc(var(--xg) + var(--W) * .9375); }
.view-office.of-wide[data-busy="goshuin"] .sp-goshuin { left: calc(var(--xg) + var(--W) * 1.875 * .1867); }
.view-office.of-wide[data-busy="omamori"] .sp-goshuin { left: calc(var(--xg) + var(--W) * 1.875 * .6533); }
.sp-goshuin[data-pose="watch"] .av-head { transform: rotate(-6deg) translateY(2px); }
.sp-goshuin[data-pose="watch"] .av-up { transform: rotate(-2deg); }
.hd-burst { position: fixed; z-index: 71; width: 26px; height: 26px; pointer-events: none; }
.hd-burst svg { width: 100%; height: 100%; overflow: visible; }

/* ---------- the shrine's people on the path (js/npc.js) ---------- */
.npc {
  position: absolute; left: 0; top: 0; z-index: 1; padding: 0; margin: 0; border: 0; background: none; cursor: pointer;
  pointer-events: auto; -webkit-tap-highlight-color: transparent; will-change: transform;
}
.npc svg { display: block; width: 100%; height: 100%; overflow: visible; }
.npc * { transform-box: view-box; }
.npc-sheep { width: calc(58 / 390 * 100%); aspect-ratio: 60 / 50; }
.npc-miko { width: calc(58 / 390 * 100%); aspect-ratio: 112 / 158; }
.npc-visitor { width: calc(46 / 390 * 100%); aspect-ratio: 100 / 158; }
.npc-in { position: absolute; inset: 0; }
.npc-visitor .av-svg { position: absolute; inset: 0; }
.npc-visitor .av-svg.back { visibility: hidden; }
.npc-visitor.from-back .av-svg.back { visibility: inherit; }
.npc-visitor.from-back .av-svg.front { visibility: hidden; }
.npc-flip { position: absolute; inset: 0; transition: transform .25s; }
.npc.face-r .npc-flip { transform: scaleX(-1); }
.npc-visitor.walking .npc-in { animation: avBob .9s ease-in-out infinite; }

/* the sheep: grazing (head down and up), its fleece breathing, legs while it trots */
.sh-head { transform-origin: 17px 26px; transition: transform .4s ease; }
.npc-sheep.grazing .sh-head { animation: shGraze 2.4s ease-in-out infinite; }
@keyframes shGraze { 0%, 100% { transform: rotate(0); } 35%, 70% { transform: rotate(-24deg) translate(-1px, 3px); } }
.sh-body { transform-origin: 32px 40px; animation: shFluff 3.2s ease-in-out infinite; }
@keyframes shFluff { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.025, 1.04); } }
.npc-sheep.trot .npc-in { animation: shTrot .34s ease-in-out infinite; }
@keyframes shTrot { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6%); } }
.npc-sheep.trot .sh-leg.a { animation: shLeg .34s ease-in-out infinite; }
.npc-sheep.trot .sh-leg.b { animation: shLeg .34s ease-in-out infinite reverse; }
@keyframes shLeg { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2px); } }
.sh-tail { transform-origin: 52px 30px; animation: shTail 1.6s ease-in-out infinite; }
@keyframes shTail { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(10deg); } }

/* the shrine maiden sweeping */
.mko-broom { transform-origin: -30px -50px; animation: mkoSweep 2.6s ease-in-out infinite; }
@keyframes mkoSweep { 0%, 100% { transform: rotate(-7deg); } 50% { transform: rotate(9deg); } }
.mko-body { transform-origin: 0 -8px; animation: mkoSway 2.6s ease-in-out infinite; }
@keyframes mkoSway { 0%, 100% { transform: rotate(-1.5deg); } 50% { transform: rotate(1.5deg); } }
.npc-miko.greet .mko-broom, .npc-miko.greet .mko-body { animation-play-state: paused; }
.npc-miko.greet .av-head { transform: translateY(-2px) rotate(-4deg); transition: transform .25s; }
/* what she sweeps: blossom petals, green leaves, maple leaves, snow */
.mko-pile > g { display: none; }
[data-season="spring"] .mko-pile .spring, [data-season="summer"] .mko-pile .summer,
[data-season="autumn"] .mko-pile .autumn, [data-season="winter"] .mko-pile .winter { display: inline; }
.mko-pile { animation: mkoPile 2.6s ease-in-out infinite; transform-origin: -46px -2px; }
@keyframes mkoPile { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(2px); } }

/* the cats: css/cats.css */

@media (prefers-reduced-motion: reduce) {
  .view-path.actors-on .path-actors { animation: none; }
  .av-live .av-up, .av-live .av-sl.l, .av-live .av-sl.r, .av-live .av-charm, .walking .pa-bob, .walking .av-ft.l, .walking .av-ft.r,
  .walking .av-sl.l, .walking .av-sl.r, .walking .av-up, .pa-dot, .npc *, .npc .npc-in { animation: none !important; }
  .av-live .av-eyes { animation: none; }
  .bubble { transition: opacity .2s; transform: translate(-50%, calc(-100% - 12px)); }
  .dress, .dress.open { transition: visibility 0s; }
  .hd-av-glow { transition: opacity .3s; }
  .sp-avatar .av-sl, .sp-avatar .av-head, .sp-avatar .av-up, .sp-avatar .av-top, .sp-avatar .sp-aside, .sp-goshuin { transition: none !important; }
  .sp-avatar .pa-hop { animation: none !important; }
}
