/* Stadsscener (scene.js). Alla klasser har prefixet .sc-. */

.sc-scene {
  --sc-dim: 1;
  position: relative;
  aspect-ratio: 16 / 7;
  max-height: var(--sc-height, 420px);
  overflow: hidden;
  isolation: isolate;
  background: var(--sc-top, #9cc4dc);
  contain: paint;
}
.sc-scene > .sc-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  filter: brightness(var(--sc-dim));
}
/* Mjuk papperskant (vinjett) */
.sc-scene::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 38px rgba(58, 46, 34, .28), inset 0 -26px 28px -22px rgba(58, 46, 34, .3);
  z-index: 3;
}
@media (prefers-color-scheme: dark) {
  .sc-scene { --sc-dim: .86; }
  .sc-scene::after { box-shadow: inset 0 0 44px rgba(0, 0, 0, .42), inset 0 -26px 28px -22px rgba(0, 0, 0, .4); }
}
:root[data-theme="dark"] .sc-scene { --sc-dim: .86; }
:root[data-theme="light"] .sc-scene { --sc-dim: 1; }

/* ---------- Resenären ---------- */
.sc-trav {
  position: absolute;
  left: 9%;
  bottom: 1.2%;
  height: clamp(44px, 24%, 92px);
  aspect-ratio: 64 / 96;
  z-index: 2;
  pointer-events: none;
}
.sc-trav-svg { width: 100%; height: 100%; display: block; overflow: visible; }
.sc-s2 .sc-trav-svg { filter: brightness(.9) sepia(.22) saturate(1.1); }
.sc-s3 .sc-trav-svg { filter: brightness(.62) saturate(.85) drop-shadow(0 0 3px rgba(255, 214, 140, .35)); }
.sc-w-rain .sc-trav-svg { filter: brightness(.88); }
.sc-w-rain.sc-s3 .sc-trav-svg { filter: brightness(.56); }
.sc-w-fog .sc-trav-svg { filter: brightness(.95) contrast(.92); }

.sc-trav-svg [class^="sc-t-"], .sc-trav-svg [class*=" sc-t-"] { transform-box: fill-box; }
.sc-t-all { transform-origin: 50% 100%; animation: sc-t-shift 7s ease-in-out infinite; }
.sc-t-body { transform-origin: 50% 100%; animation: sc-t-breathe 3.4s ease-in-out infinite; }
.sc-t-head { transform-origin: 40% 95%; animation: sc-t-nod 5.5s ease-in-out infinite; }
.sc-t-arm { transform-origin: 50% 8%; animation: sc-t-armidle 3.4s ease-in-out infinite; }
.sc-t-pack { transform-origin: 80% 70%; animation: sc-t-packidle 3.4s ease-in-out infinite; }
.sc-t-eye { transform-origin: center; animation: sc-t-blink 5.6s infinite; }
.sc-t-umb { transform-origin: 50% 100%; animation: sc-t-umb 4s ease-in-out infinite; }
@keyframes sc-t-shift { 0%, 100% { transform: rotate(0); } 45%, 55% { transform: rotate(1.4deg); } }
@keyframes sc-t-breathe { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(1.02); } }
@keyframes sc-t-nod { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(2.4deg); } 70% { transform: rotate(-1.4deg); } }
@keyframes sc-t-armidle { 0%, 100% { transform: rotate(3deg); } 50% { transform: rotate(-1deg); } }
@keyframes sc-t-packidle { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(.8deg); } }
@keyframes sc-t-blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }
@keyframes sc-t-umb { 0%, 100% { transform: rotate(-1.5deg); } 50% { transform: rotate(1.5deg); } }

/* Går på stället */
.sc-walking .sc-t-all { animation: sc-t-bob .58s ease-in-out infinite; }
.sc-walking .sc-t-body { animation: sc-t-lean 1.16s ease-in-out infinite; }
.sc-walking .sc-t-head { animation: sc-t-headbob 1.16s ease-in-out infinite; }
.sc-walking .sc-t-pack { animation: sc-t-packwalk .58s ease-in-out infinite; }
.sc-walking .sc-t-arm { transform-origin: 50% 8%; animation: sc-t-armswing 1.16s ease-in-out infinite; }
.sc-walking .sc-t-leg { transform-origin: 50% 2%; animation: sc-t-legswing 1.16s ease-in-out infinite; }
.sc-walking .sc-t-legb { animation-delay: -.58s; }
.sc-walking > .sc-svg { animation: sc-cam 1.16s ease-in-out infinite; }
@keyframes sc-t-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-1.8px); } }
@keyframes sc-t-lean { 0%, 100% { transform: rotate(3deg); } 50% { transform: rotate(4.5deg); } }
@keyframes sc-t-headbob { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }
@keyframes sc-t-packwalk { 0%, 100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(1.2px) rotate(1.4deg); } }
@keyframes sc-t-armswing { 0%, 100% { transform: rotate(-26deg); } 50% { transform: rotate(26deg); } }
@keyframes sc-t-legswing { 0%, 100% { transform: rotate(-27deg); } 50% { transform: rotate(27deg); } }
@keyframes sc-cam { 0%, 100% { transform: translateY(0) scale(1.012); } 50% { transform: translateY(.6px) scale(1.012); } }

/* ---------- Liv i scenen ---------- */
.sc-cross { animation: sc-cross var(--t, 60s) linear infinite; animation-delay: calc(var(--t, 60s) * var(--ph, 0) * -1); }
@keyframes sc-cross { from { transform: translateX(0); } to { transform: translateX(var(--dx)); } }

.sc-wing { transform-box: fill-box; transform-origin: 50% 100%; animation: sc-flap .46s ease-in-out infinite alternate; animation-delay: var(--d, 0s); }
@keyframes sc-flap { from { transform: scaleY(1); } to { transform: scaleY(.2); } }

.sc-bob { transform-box: fill-box; transform-origin: 50% 90%; animation: sc-bob 4.4s ease-in-out infinite alternate; animation-delay: var(--d, 0s); }
@keyframes sc-bob { from { transform: translateY(-1px) rotate(calc(-1.4deg * var(--k, 1))); } to { transform: translateY(1.2px) rotate(calc(1.4deg * var(--k, 1))); } }

.sc-frond { transform-box: fill-box; transform-origin: 50% 55%; animation: sc-sway var(--t, 4s) ease-in-out infinite alternate; animation-delay: var(--d, 0s); }
@keyframes sc-sway { from { transform: rotate(-3.2deg); } to { transform: rotate(3.2deg); } }

.sc-flag { transform-box: fill-box; transform-origin: 0 50%; animation: sc-flagwave 1.9s ease-in-out infinite alternate; animation-delay: var(--d, 0s); }
@keyframes sc-flagwave { from { transform: skewY(-5deg) scaleX(.95); } to { transform: skewY(5deg) scaleX(1); } }

.sc-wave { animation: sc-wave var(--t, 6s) linear infinite; animation-delay: var(--d, 0s); }
@keyframes sc-wave { to { transform: translateX(calc(var(--p) * -1)); } }

.sc-glint { transform-box: fill-box; transform-origin: center; animation: sc-glint 3.4s ease-in-out infinite; animation-delay: var(--d, 0s); }
@keyframes sc-glint { 0%, 100% { opacity: .15; transform: scaleX(.5); } 50% { opacity: .95; transform: scaleX(1.1); } }

.sc-flick { animation: sc-flick 3.6s ease-in-out infinite; animation-delay: var(--d, 0s); }
@keyframes sc-flick { 0%, 100% { opacity: 1; } 8% { opacity: .65; } 12% { opacity: 1; } 55% { opacity: .85; } 60% { opacity: 1; } 78% { opacity: .55; } 82% { opacity: 1; } }

.sc-dim { opacity: 0; animation: sc-dim 3.6s ease-in-out infinite; animation-delay: var(--d, 0s); }
@keyframes sc-dim { 0%, 100% { opacity: 0; } 8% { opacity: .4; } 12% { opacity: 0; } 55% { opacity: .25; } 60% { opacity: 0; } 78% { opacity: .45; } 82% { opacity: 0; } }

.sc-twinkle { animation: sc-twinkle 3.2s ease-in-out infinite; animation-delay: var(--d, 0s); }
@keyframes sc-twinkle { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

.sc-smoke { animation: sc-smoke 6s ease-out infinite; animation-delay: var(--d, 0s); }
@keyframes sc-smoke { 0% { transform: translate(0, 4px); opacity: 0; } 20% { opacity: 1; } 100% { transform: translate(6px, -18px); opacity: 0; } }

.sc-step { animation: sc-step .55s ease-in-out infinite alternate; animation-delay: var(--d, 0s); }
@keyframes sc-step { from { transform: translateY(0); } to { transform: translateY(-1.3px); } }
.sc-idle { transform-box: fill-box; transform-origin: 50% 100%; animation: sc-idle 3.4s ease-in-out infinite alternate; animation-delay: var(--d, 0s); }
@keyframes sc-idle { from { transform: scaleY(1); } to { transform: scaleY(1.03); } }

.sc-fall { animation: sc-fall var(--t, 1s) linear infinite; }
@keyframes sc-fall { to { transform: translateY(var(--p)); } }
.sc-swayx { animation: sc-swayx var(--t, 5s) ease-in-out infinite alternate; }
@keyframes sc-swayx { from { transform: translateX(-12px); } to { transform: translateX(12px); } }
.sc-fog { animation: sc-fog var(--t, 20s) ease-in-out infinite alternate; animation-delay: var(--d, 0s); }
@keyframes sc-fog { from { transform: translateX(-70px); } to { transform: translateX(70px); } }

.sc-aurora { transform-box: fill-box; transform-origin: 50% 100%; animation: sc-aurora var(--t, 14s) ease-in-out infinite alternate; animation-delay: var(--d, 0s); }
@keyframes sc-aurora { from { transform: translateX(-26px) scaleY(.82); opacity: .55; } to { transform: translateX(26px) scaleY(1.12); opacity: 1; } }

.sc-flutter { transform-box: fill-box; transform-origin: 50% 0; animation: sc-flutter 1.3s ease-in-out infinite alternate; animation-delay: var(--d, 0s); }
@keyframes sc-flutter { from { transform: rotate(-9deg); } to { transform: rotate(9deg); } }

.sc-spin { transform-box: fill-box; transform-origin: center; animation: sc-spin var(--t, 40s) linear infinite; }
@keyframes sc-spin { to { transform: rotate(360deg); } }
.sc-pulse { animation: sc-pulse 4s ease-in-out infinite; animation-delay: var(--d, 0s); }
@keyframes sc-pulse { 0%, 100% { opacity: .4; } 50% { opacity: 1; } }

/* Respektera reducerad rörelse: stilla bild, rörliga föremål står på sin fasposition */
@media (prefers-reduced-motion: reduce) {
  .sc-scene *, .sc-scene > .sc-svg { animation: none !important; }
  .sc-cross { transform: translateX(calc(var(--dx) * var(--ph, 0))); }
  .sc-fall { transform: none; }
}
/* Klass som kan sättas av spelet/testsidan för att pausa allt (t.ex. i galleri) */
.sc-paused, .sc-paused * { animation-play-state: paused !important; }
