/* Street scene (test page). Everything is sized in P, one person's height.
   JS sets --P on :root; change it and the whole scene rescales. */
:root {
  --maroon: #6E2A25;
  --green: #007A3F;
  --yellow: #FFDE59;
  --cream: #F4E8CF;
  --ink: #2E2118;
  --font-headline: "Bevan", serif;
  --font-body: "Jost", system-ui, sans-serif;
  --P: 100px;               /* fallback until JS measures the viewport */
  --ground: calc(var(--P) * 0.62);
  --sx: 0px;                /* scroll position, used for parallax */
}
* { box-sizing: border-box; }
html, body { margin: 0; background: #EFE3C8; color: var(--ink); font-family: var(--font-body); }
body { min-height: 100vh; }

.bar { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; padding: 10px 14px; }
.bar h1 { margin: 0; font: 400 20px/1.1 var(--font-headline); color: var(--maroon); }
.bar p { margin: 0; font-size: 14px; opacity: .75; }

.scene { position: relative; }
.scroller {
  height: calc(var(--P) * 7);
  overflow-x: auto; overflow-y: hidden;
  overscroll-behavior-x: contain;          /* don't trigger browser back/forward */
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  scrollbar-width: none;
  cursor: grab;
}
.scroller::-webkit-scrollbar { display: none; }
.scroller:focus-visible { outline: 3px solid var(--green); outline-offset: -3px; }
.scroller.snap { scroll-snap-type: x mandatory; }
.scroller.snap .item[data-snap] { scroll-snap-align: center; }
.scroller.dragging { cursor: grabbing; scroll-snap-type: none; user-select: none; }
html:not([data-rm]) .scroller { scroll-behavior: smooth; }
.scroller.dragging, .scroller.jump { scroll-behavior: auto !important; }
.scroller.jump { scroll-snap-type: none; }  /* off while we glide so snapping can't fight the animation */

.track { position: relative; height: 100%; width: calc(var(--P) * 24); overflow: hidden; } /* clips the parallax layers so they can't widen the scroll range */
.layer { position: absolute; inset: 0; will-change: transform; }
.sky { background: linear-gradient(#F4D9B4 0%, #FAEBD0 45%, #FBF3E2 100%); transform: translate3d(calc(var(--sx) * 0.9), 0, 0); }
.far { transform: translate3d(calc(var(--sx) * 0.55), 0, 0); }
.far svg { width: 100%; height: 100%; display: block; }
.mid, .front { will-change: auto; }

.street {
  position: absolute; left: 0; right: 0; bottom: 0; height: var(--ground);
  background: linear-gradient(#CDBDA2 0 48%, #A79683 48% 54%, #6F655E 54%);
}
.street::after { /* dashed centre line */
  content: ""; position: absolute; left: 0; right: 0; bottom: 14%; height: 3px;
  background: repeating-linear-gradient(90deg, #E8D9A8 0 calc(var(--P) * .5), transparent calc(var(--P) * .5) calc(var(--P) * 1));
  opacity: .8;
}
.groundline { display: none; position: absolute; left: 0; right: 0; bottom: var(--ground); height: 2px; background: #E0245E; z-index: 9; }

.item { position: absolute; bottom: var(--ground); }
.item img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.item .ph {
  width: 100%; height: 100%; display: grid; place-items: center; text-align: center;
  background: var(--c); color: rgba(255, 255, 255, .78);
  font: 600 max(10px, calc(var(--P) * .12))/1.1 var(--font-body); letter-spacing: .04em; text-transform: uppercase;
  border-radius: calc(var(--P) * .05);
}
/* Stacking, back to front: street, buildings, walkers (z 2), signs (z 4). Items must NOT create their own stacking context (no z-index, no transform), so the hover lift below moves only the art, never the sign. */
/* The front layer spans the whole street, so it must never catch taps meant for buildings behind it. */
.front { pointer-events: none; z-index: 3; } /* above the walkers (z 2): the trolley rides the road in front of the sidewalk */
.front .bld { pointer-events: auto; }

.sign {
  position: absolute; left: 50%; bottom: calc(var(--P) * -0.34); transform: translateX(-50%);
  background: var(--cream); color: var(--maroon);
  border: max(2px, calc(var(--P) * .03)) solid var(--maroon); border-radius: calc(var(--P) * .05);
  font: 400 max(12px, calc(var(--P) * .16))/1 var(--font-headline);
  padding: calc(var(--P) * .06) calc(var(--P) * .14); white-space: nowrap; z-index: 4;
}

.nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 20;
  width: 48px; height: 48px; border-radius: 50%; border: 2px solid var(--maroon);
  background: var(--cream); color: var(--maroon); font: 400 24px/1 var(--font-headline);
  display: grid; place-items: center; padding: 0 0 3px; cursor: pointer;
}
.nav.prev { left: 8px; } .nav.next { right: 8px; }
.nav:disabled { opacity: .3; cursor: default; }
.nav:focus-visible { outline: 3px solid var(--green); outline-offset: 2px; }

/* Debug outlines */
.dbg .groundline { display: block; }
.dbg .item { outline: 1px dashed #E0245E; }
.dbg .item::after {
  content: attr(data-dbg); position: absolute; left: 0; top: 0; background: #E0245E; color: #fff;
  font: 600 11px/1 var(--font-body); padding: 2px 4px; z-index: 9; white-space: nowrap;
}

.debug { margin: 14px; padding: 10px 14px; background: #FBF3E2; border: 2px solid var(--maroon); border-radius: 8px; max-width: 640px; }
.debug summary { font: 400 16px/1.2 var(--font-headline); color: var(--maroon); cursor: pointer; }
.debug label { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 15px; }
.debug input[type=range] { flex: 1; min-width: 120px; }
.debug .sizes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 12px; margin: 8px 0; }
.debug .sizes label { margin: 0; justify-content: space-between; }
.debug .sizes input { width: 64px; font: inherit; }
.debug button { font: 600 14px var(--font-body); padding: 8px 12px; border: 2px solid var(--maroon); background: var(--cream); color: var(--maroon); border-radius: 6px; cursor: pointer; }
.debug textarea { width: 100%; min-height: 90px; font: 12px/1.3 monospace; margin-top: 8px; }
.note { margin: 14px; font-size: 14px; max-width: 640px; }

/* ---------- Stage 2: links, link hub, locked buildings ---------- */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Buildings as links */
.bld { -webkit-tap-highlight-color: rgba(255, 222, 89, .35); color: inherit; text-decoration: none; }
.bld > img, .bld > .ph, .bld > .mbx-letters { transition: transform .15s ease; }
button.bld { background: none; border: 0; padding: 0; margin: 0; font: inherit; color: inherit; cursor: pointer; text-align: inherit; }
.bld:hover > img, .bld:focus-visible > img, .bld:hover > .ph, .bld:focus-visible > .ph, .bld:hover > .mbx-letters, .bld:focus-visible > .mbx-letters { transform: translateY(calc(var(--P) * -0.05)); }
.bld:hover .sign, .bld:focus-visible .sign { background: var(--yellow); }
.bld:focus-visible { outline: 3px solid var(--green); outline-offset: 4px; border-radius: 4px; }
html[data-rm] .bld > img, html[data-rm] .bld > .ph, html[data-rm] .bld > .mbx-letters { transition: none; transform: none !important; }
.bld.locked .ph, .bld.locked img { filter: saturate(.55) brightness(.92); }
.sign svg { vertical-align: -0.12em; }

/* Quick links above the scene */
.fast { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; padding: 0 14px 10px; max-width: 980px; }
.fbtn, .lbtn {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 48px; padding: 8px 14px; text-decoration: none; color: var(--maroon);
  background: var(--cream); border: 2px solid var(--maroon); border-radius: 10px;
}
.fbtn.hot, .lbtn.hot { background: var(--yellow); }
.fbtn:hover, .lbtn:hover { background: #fff6dc; }
.fbtn.hot:hover, .lbtn.hot:hover { background: #ffe97f; }
.fbtn:focus-visible, .lbtn:focus-visible, .today:focus-visible, .lock-note a:focus-visible, .lock-note button:focus-visible { outline: 3px solid var(--green); outline-offset: 2px; }
.ltext { display: flex; flex-direction: column; min-width: 0; }
.lt { font: 400 16px/1.15 var(--font-headline); }
.ld { font: 500 13px/1.3 var(--font-body); color: var(--ink); opacity: .8; margin-top: 2px; }
.larrow { font-size: 18px; flex: none; }
.fbtn .ld { display: none; }

/* Plain list of every link, below the scene */
.all { padding: 6px 14px 18px; max-width: 760px; }
.all h2 { margin: 6px 0 4px; font: 400 20px/1.1 var(--font-headline); color: var(--maroon); }
.lgroup { margin: 14px 0 6px; font: 800 12px/1 var(--font-body); letter-spacing: .08em; text-transform: uppercase; color: var(--maroon); opacity: .8; }
.llist { display: grid; gap: 8px; }

/* Persistent "Today's events" button */
.today {
  position: fixed; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 30;
  display: inline-flex; align-items: center; min-height: 48px; padding: 0 18px;
  background: var(--green); color: #fff; text-decoration: none; border: 2px solid var(--maroon); border-radius: 999px;
  font: 400 15px/1 var(--font-headline); box-shadow: 0 2px 0 var(--maroon);
}
.today:hover { background: #006b37; }

/* "Subscribers only" note for locked buildings */
.lock-note {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 25;
  width: min(320px, calc(100% - 24px)); padding: 12px 14px; background: var(--cream); color: var(--ink);
  border: 2px solid var(--maroon); border-radius: 10px; font: 500 15px/1.35 var(--font-body);
}
.lock-note[hidden] { display: none; }
.lock-note p { margin: 0 0 10px; }
.lock-note a, .lock-note button {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; margin-right: 8px;
  font: 600 14px var(--font-body); border: 2px solid var(--maroon); border-radius: 8px; cursor: pointer; text-decoration: none;
}
.lock-note a { background: var(--yellow); color: var(--maroon); }
.lock-note button { background: var(--cream); color: var(--maroon); }

.bar p.sub { flex-basis: 100%; }
.debug #diag { font: 600 12px/1.4 monospace; opacity: .8; margin: 8px 0 0; word-break: break-word; }


/* ---------- Stage 3: mailbox, contact card, walkers, clouds ---------- */
/* Mailbox mail: layers share the box's canvas, so they line up with no positioning. They start just below the slot, are clipped at the
   slot's lower edge (slot bottom is 543 of 1265 art px down (legs cropped off), so 57.08% is cut off the bottom) and rise out of it on hover, focus or open.
   Stacking, bottom to top: mail-3, mail-2, mail-1 (DOM order). --rise is each layer's travel as a share of the box height. */
.mbx-letters { position: absolute; inset: 0; pointer-events: none; clip-path: inset(0 0 57.08% 0); }
.mbx-letters img { position: absolute; inset: 0; width: 100%; height: 100%; transform: translateY(0); transition: transform .22s ease-in; }
.mbx-letters .ml1 { --rise: 13.4%; --d: .12s; }
.mbx-letters .ml2 { --rise: 15.05%; --d: .06s; }
.mbx-letters .ml3 { --rise: 11.87%; --d: 0s; }
.bld.mailbox:hover .mbx-letters img, .bld.mailbox:focus-visible .mbx-letters img, .bld.mailbox.open .mbx-letters img {
  transform: translateY(calc(-1 * var(--rise))); transition: transform .42s cubic-bezier(.2, .85, .25, 1.05) var(--d);
}
html[data-rm] .mbx-letters img { transition: none; }
/* invisible hit area: at least 44 x 44 CSS px even when the mailbox itself is smaller */
.bld.mailbox::before { content: ""; position: absolute; left: 50%; top: 50%; width: max(100%, 44px); height: max(100%, 44px); transform: translate(-50%, -50%); }

.contact-card a.plain { background: var(--cream); color: var(--maroon); }
.contact-card a, .contact-card button { margin-top: 4px; }

/* Walkers: a gentle slide across the sidewalk with a bob and a small rock, turning round at each end. */
.walkers { pointer-events: none; z-index: 2; }
.walker {
  position: absolute; left: 0; width: calc(var(--P) * var(--wP)); height: calc(var(--P) * var(--hP));
  bottom: calc(var(--ground) * var(--lane));
  animation: walk-x var(--cross) linear var(--start) infinite alternate;
  will-change: transform; pointer-events: none;
}
.walker .face { position: absolute; inset: 0; animation: walk-face calc(var(--cross) * 2) steps(1, end) var(--start) infinite; }
.walker .bob  { position: absolute; inset: 0; transform-origin: 50% 100%; animation: walk-bob var(--step) ease-in-out infinite; }
.walker img   { position: absolute; inset: 0; width: 100%; height: 100%; display: block; object-fit: contain; opacity: 0; }
.walker.sprite .bob { animation: none; }   /* the drawn frames already include the body dip and arm swing */
@keyframes walk-x    { from { transform: translateX(calc(var(--P) * -1.4)); } to { transform: translateX(calc(var(--P) * 25.05)); } }
@keyframes walk-face { 0% { transform: scaleX(1); } 50% { transform: scaleX(-1); } }
@keyframes walk-bob  { 0%, 100% { transform: translateY(0) rotate(-1.6deg); } 50% { transform: translateY(calc(var(--P) * -0.035)) rotate(1.6deg); } }

/* Clouds drift slowly in the sky layer */
.cloud {
  position: absolute; left: 0; display: block; height: calc(var(--P) * .22); width: calc(var(--P) * 1.2);
  background: #FFF8EA; border-radius: 999px; opacity: .55;
  animation: cloud-drift var(--dur, 220s) linear var(--delay, 0s) infinite;
}
.cloud::before, .cloud::after { content: ""; position: absolute; background: #FFF8EA; border-radius: 50%; }
.cloud::before { width: 42%; height: 150%; left: 14%; bottom: 25%; }
.cloud::after  { width: 32%; height: 120%; left: 50%; bottom: 20%; }
.cloud.c1 { top: 8%;  --dur: 240s; --delay: -60s; }
.cloud.c2 { top: 19%; --dur: 300s; --delay: -190s; transform-origin: left; width: calc(var(--P) * 1.7); }
.cloud.c3 { top: 13%; --dur: 270s; --delay: -120s; width: calc(var(--P) * .9); opacity: .4; }
@keyframes cloud-drift { from { transform: translateX(calc(var(--P) * -2)); } to { transform: translateX(calc(var(--P) * 25.65)); } }

/* Pause everything ambient when the scene is off screen; reduced motion stops it for good. */
html.offscreen .walker, html.offscreen .walker *, html.offscreen .cloud { animation-play-state: paused; }
html[data-rm] .cloud, html[data-rm] .walker, html[data-rm] .walker * { animation: none; }
html[data-rm] .walker { transform: translateX(calc(var(--P) * var(--rest))); }
html[data-rm] .walker img { opacity: 0; }
html[data-rm] .walker img:first-child { opacity: 1; }

/* Trolley: a faint idle bob (individual transform properties, so the hover lift still works). A plain click adds .leaving; it
   backs up a hair, then pulls away to the right past the end of the street, and street.js follows the link when it is gone. */
.item[data-id="trolley"] > img { animation: trolley-idle 3.4s ease-in-out infinite; }
@keyframes trolley-idle { 0%, 100% { translate: 0 0; rotate: 0deg; } 50% { translate: 0 calc(var(--P) * -0.012); rotate: .12deg; } }
.item[data-id="trolley"].leaving { pointer-events: none; animation: trolley-leave .85s cubic-bezier(.4, 0, .8, .6) forwards; }
.item[data-id="trolley"].leaving .sign { opacity: 0; transition: opacity .2s ease; }
@keyframes trolley-leave {
  0%   { transform: translateX(0); }
  14%  { transform: translateX(calc(var(--P) * -0.07)); }
  100% { transform: translateX(calc(var(--P) * 3.7)); }
}
html.offscreen .item[data-id="trolley"] > img { animation-play-state: paused; }
html[data-rm] .item[data-id="trolley"] > img { animation: none; }

/* Evening rooftop sitters: fade in as night falls (--lit2 is the night amount), while their walkers fade out. */
.sitter { position: absolute; left: calc(var(--P) * var(--sx)); width: calc(var(--P) * var(--sw)); height: calc(var(--P) * var(--sh));
  bottom: calc(var(--ground) + var(--P) * var(--sfy)); transform: translateX(-50%) scaleX(var(--flip, 1)); display: none; pointer-events: none; }
.sitter.ready { display: block; opacity: 0; transition: opacity 2.5s ease 1.5s; animation: sitter-in 1.1s ease-out both; }
html.folk-night .sitter.ready { opacity: 1; }
@keyframes sitter-in { from { filter: opacity(0); } to { filter: opacity(1); } }
html[data-rm] .sitter.ready { animation: none; }
.sitter img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; }
.sitter img.pose, .sitter .pose.seq { opacity: 0; }
.sitter .pose.seq { position: absolute; inset: 0; background-repeat: no-repeat; background-position: 0 0; }
.sitter .steam.blowst .sw { transform: rotate(var(--bdeg, 58deg)); }
.sitter .steam { position: absolute; left: calc(var(--stx) * 100%); top: calc(var(--sty) * 100%); width: 0; height: 0; pointer-events: none; }
.sitter .steam .sw { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-origin: 0 0; }
.sitter .steam i { position: absolute; left: 0; bottom: 0; width: calc(var(--P) * .02); height: calc(var(--P) * .08); margin-left: calc(var(--P) * -.01); border-radius: 50%;
  background: rgba(255, 252, 245, .85); filter: blur(calc(var(--P) * .005)); opacity: 0; animation: steam-rise 3.2s ease-out infinite; }
.sitter .steam i:nth-child(2) { animation-delay: 1.05s; margin-left: calc(var(--P) * .014); }
.sitter .steam i:nth-child(3) { animation-delay: 2.1s; margin-left: calc(var(--P) * -.026); }
@keyframes steam-rise { 0% { transform: translate(0, 0) scaleY(.45); opacity: 0; } 22% { opacity: .62; } 100% { transform: translate(calc(var(--P) * .016), calc(var(--P) * -.14)) scaleY(1.3); opacity: 0; } }
html[data-rm] .sitter .steam i, html[data-rm] .sitter img { animation: none !important; }
.walker.retire { opacity: 1; transition: opacity 3s ease; }
html.folk-night .walker.retire { opacity: 0; }
html.folk-init .walker.retire, html.folk-init .pet-win, html.folk-init .pet-sleep, html.folk-init .sitter.ready { transition: none !important; }
html[data-rm] .walker.retire { opacity: 1; }

/* ---------- Pets (Junie) ----------
   Pets sit inside their host building's node (so walkers pass in front of them). Position uses the individual `translate` property so the
   building's hover lift (which uses `transform`) still applies to them. By day she is in the window; at night she is on the sofa. */
.pet { position: absolute; pointer-events: none; left: calc(var(--x) * 100%); bottom: calc(var(--y) * 100%);
  height: calc(var(--h) * 100%); aspect-ratio: var(--aspect); translate: -50% 0; }
.pet i { position: absolute; inset: 0; display: block; background-repeat: no-repeat; background-size: 100% 100%; }
.bld:hover > .pet, .bld:focus-visible > .pet { transform: translateY(calc(var(--P) * -0.05)); }
.pet-win { opacity: 1; transition: opacity 2.5s ease; }
html.folk-night .pet-win { opacity: 0; }
.pet-win .look { opacity: 0; }
.pet-win .lid { position: absolute; display: block; border-radius: 50%; transform: scaleY(0); }
.pet-win.blink .lid { animation: pet-blink .2s ease-in-out; }
@keyframes pet-blink { 0%, 100% { transform: scaleY(0); } 45% { transform: scaleY(1); } }
.pet-sleep { opacity: 0; transition: opacity 2.5s ease 1.5s; }
html.folk-night .pet-sleep { opacity: 1; }
.pet-sleep .breathe { transform-origin: 62% 100%; animation: pet-breathe var(--breathe, 4.6s) ease-in-out infinite; }
@keyframes pet-breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.006, 1.04); } }
html.offscreen .pet-sleep .breathe { animation-play-state: paused; }
html[data-rm] .pet-sleep .breathe, html[data-rm] .pet-win .lid { animation: none; }

/* ---------- Storefront window dressing (see buildDecor in street.js) ---------- */
.decor { position: absolute; inset: 0; pointer-events: none; }
.decor svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.decor .dglow { opacity: var(--lit2, 0); }
.decor .dglow circle { animation: decor-twinkle 3.2s ease-in-out infinite; }
@keyframes decor-twinkle { 0%, 100% { opacity: .6; } 50% { opacity: 1; } }
html[data-rm] .decor .dglow circle, html.offscreen .decor .dglow circle { animation: none; }
@media (prefers-reduced-motion: reduce) { .decor .dglow circle { animation: none; } }

/* HQ window decal: day and night versions crossfade with the sky. */
.decor .decal-day { opacity: calc(1 - var(--lit2, 0)); }
.decor .decal-night { opacity: var(--lit2, 0); }


/* Trolley on the road: it sits lower than the buildings, so its label rides up to stay on the sidewalk row's level. */
.item[data-id="trolley"] .sign { bottom: calc(var(--P) * -0.27); }
.wire { position: absolute; pointer-events: none; filter: var(--scene-fx, none); }
.wire svg { display: block; width: 100%; height: 100%; overflow: visible; }
