/* SCRS volunteer mascot (illustrated character): site-wide bottom-left greeter. DRAFT.
   Geometry of the figure layers is in % of the 805 x 1440 art, so every layer stays registered at any size.
   --mascot-z defaults to 30 (Big boss, 2:30pm 28 Nov 2026, Australia/Brisbane). That sits above page
   content (the SCRS site uses 1, 10 and 20) and below the fixed header (50), Radix dialogs/modals (50),
   the z-60 layer and the toast viewport (100). Never uses the bottom-right corner. */
.scrs-terry {
  --scrs-terry-h: 140px;                         /* figure height, desktop */
  --scrs-terry-w: calc(var(--scrs-terry-h) * 805 / 1440);
  --scrs-terry-gap: 24px;                        /* corner margin, desktop */
  --scrs-terry-chip: 52px;                       /* collapsed chip (48-56 px) */
  --scrs-terry-tab: 12px;                        /* visible part of a tucked chip */
  --scrs-terry-safe-l: env(safe-area-inset-left, 0px);
  --scrs-terry-safe-r: env(safe-area-inset-right, 0px);
  --scrs-terry-safe-b: env(safe-area-inset-bottom, 0px);
  --scrs-terry-safe-t: env(safe-area-inset-top, 0px);
  --scrs-terry-green: #24452d;
  --scrs-terry-yellow: #f2d21b;
  --mascot-z: 30;
  position: fixed;
  left: calc(var(--scrs-terry-gap) + var(--scrs-terry-safe-l));
  bottom: calc(var(--scrs-terry-gap) + var(--scrs-terry-safe-b));
  width: var(--scrs-terry-w);
  height: var(--scrs-terry-h);
  z-index: var(--mascot-z);
  pointer-events: none;                          /* only the figure, chip, bubble and buttons take input */
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  contain: layout style;
}
@media (max-width: 720px) { .scrs-terry { --scrs-terry-h: 90px; --scrs-terry-gap: 16px; --scrs-terry-chip: 48px; } }
@media print { .scrs-terry { display: none; } }

.scrs-terry__probe { position: absolute; left: 0; bottom: 0; visibility: hidden; pointer-events: none; }
.scrs-terry__probe--full { width: 100%; height: 100%; }
.scrs-terry__probe--chip { width: var(--scrs-terry-chip); height: var(--scrs-terry-chip); }
.scrs-terry__probe--tab { left: calc(-1 * (var(--scrs-terry-gap) + var(--scrs-terry-safe-l))); width: calc(var(--scrs-terry-tab) + var(--scrs-terry-safe-l)); height: var(--scrs-terry-chip); }
.scrs-terry__sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* figure (expanded) */
.scrs-terry__figure {
  position: absolute; left: 0; bottom: 0; width: 100%; height: 100%;
  opacity: 0; visibility: hidden;
  transition: opacity .2s ease, transform .2s ease, visibility 0s linear .2s;
  transform: translateY(6px);
}
.scrs-terry--loaded .scrs-terry__figure { opacity: 1; visibility: visible; transform: none; transition: opacity .25s ease, transform .25s ease; }
.scrs-terry--collapsed .scrs-terry__figure { opacity: 0; visibility: hidden; transform: translateY(8px) scale(.9); transition: opacity .18s ease, transform .18s ease, visibility 0s linear .18s; }
.scrs-terry__stage {
  pointer-events: auto;
  position: absolute; left: 0; top: 0; width: 100%; height: 100%;
  display: block; padding: 0; border: 0; margin: 0; background: none;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.scrs-terry__rig, .scrs-terry__arm, .scrs-terry__head, .scrs-terry__layer {
  position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block;
}
.scrs-terry__layer { user-select: none; -webkit-user-drag: none; pointer-events: none; }
.scrs-terry__rig {
  transform-origin: 50% 98%;
  animation: scrs-terry-breathe 4.2s ease-in-out infinite;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .25));
}
/* crest: the real SCRS crest file, locked to the torso (child of the rig, not of the head or the arm) */
.scrs-terry__crest { position: absolute; left: 60.8696%; top: 38.4722%; width: 7.4534%; height: auto; pointer-events: none; user-select: none; }
.scrs-terry__head { transform-origin: 45.96% 27.22%; transition: transform .7s cubic-bezier(.4, 0, .2, 1); }
.scrs-terry--look-left .scrs-terry__head { transform: rotate(-1.6deg) translateX(-.35%); }
.scrs-terry--look-right .scrs-terry__head { transform: rotate(1.6deg) translateX(.35%); }
.scrs-terry__arm { transform-origin: 84.47% 44.17%; }
.scrs-terry--waving .scrs-terry__arm { animation: scrs-terry-wave 1.7s ease-in-out 1; }
.scrs-terry--waving .scrs-terry__head { transform: rotate(1.2deg); }
/* eyelids: painted from the existing lid skin. Frames switch instantly (a blink is ~170 ms). */
.scrs-terry__lids { opacity: 0; }
.scrs-terry--blink-half .scrs-terry__lids--half,
.scrs-terry--blink-closed .scrs-terry__lids--closed { opacity: 1; }
/* mouth overlays: one visible at a time, 60 ms cross-fade so swaps never pop; "rest" = the drawn smile */
.scrs-terry__mouth { opacity: 0; transition: opacity 60ms linear; }
.scrs-terry--mouth-closed .scrs-terry__mouth--closed,
.scrs-terry--mouth-small .scrs-terry__mouth--small,
.scrs-terry--mouth-open .scrs-terry__mouth--open { opacity: 1; }
.scrs-terry--paused .scrs-terry__rig, .scrs-terry--paused .scrs-terry__arm { animation-play-state: paused; }

/* minimise button (top-right of the figure, outside the art) */
.scrs-terry__min {
  pointer-events: auto;
  position: absolute; top: -4px; right: -18px;
  width: 22px; height: 22px; padding: 0;
  border: 0; border-radius: 50%;
  background: rgba(36, 69, 45, .88); color: #fff;
  font: 700 15px/22px system-ui, sans-serif; text-align: center;
  cursor: pointer; opacity: .6; transition: opacity .15s;
}
.scrs-terry__min:hover, .scrs-terry__min:focus-visible, .scrs-terry__figure:hover .scrs-terry__min { opacity: 1; }

/* collapsed chip */
.scrs-terry__chip {
  pointer-events: none;
  position: absolute; left: 0; bottom: 0;
  width: var(--scrs-terry-chip); height: var(--scrs-terry-chip);
  padding: 0; border: 2px solid #fff; border-radius: 50%;
  background: var(--scrs-terry-green); overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
  cursor: pointer;
  opacity: 0; visibility: hidden; transform: scale(.6);
  transition: opacity .18s ease, transform .18s ease, visibility 0s linear .18s;
}
.scrs-terry__chip-img { display: block; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.scrs-terry--collapsed .scrs-terry__chip { pointer-events: auto; opacity: 1; visibility: visible; transform: none; transition: opacity .18s ease, transform .18s ease; }
/* tucked: even the chip would cover a control, so only an edge tab stays on screen */
.scrs-terry--collapsed.scrs-terry--tucked .scrs-terry__chip {
  transform: translateX(calc(-1 * (var(--scrs-terry-gap) + var(--scrs-terry-chip) - var(--scrs-terry-tab))));  /* safe-l is in the left offset already */
  opacity: .92;
}
.scrs-terry__stage:focus-visible, .scrs-terry__min:focus-visible, .scrs-terry__chip:focus-visible {
  outline: 3px solid var(--scrs-terry-yellow); outline-offset: 2px;
}
.scrs-terry--collapsed.scrs-terry--tucked .scrs-terry__chip:focus-visible { transform: none; }
/* stowed: even the edge tab would touch a control, so nothing shows until the corner is clear again */
.scrs-terry--collapsed.scrs-terry--stowed .scrs-terry__chip { opacity: 0; visibility: hidden; pointer-events: none; }  /* keyboard users see the whole chip */

/* caption bubble: opens up from the figure and extends to the right; switches to the right side when there is no room above */
.scrs-terry__bubble {
  pointer-events: auto;
  position: absolute; left: 0; bottom: calc(100% + 10px);
  box-sizing: border-box;
  width: max-content;
  max-width: min(260px, calc(100vw - 2 * var(--scrs-terry-gap) - var(--scrs-terry-safe-l) - var(--scrs-terry-safe-r)));
  max-height: calc(100vh - var(--scrs-terry-h) - 2 * var(--scrs-terry-gap) - var(--scrs-terry-safe-b) - var(--scrs-terry-safe-t) - 20px);
  overflow: auto;
  margin: 0; padding: 8px 12px;
  border: 2px solid var(--scrs-terry-green); border-radius: 12px;
  background: #fff; color: #1c2a20;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
  opacity: 0; visibility: hidden; transform: translateY(6px);
  transition: opacity .18s ease, transform .18s ease, visibility 0s linear .18s;
}
.scrs-terry__bubble::after {
  content: ""; position: absolute; bottom: -8px; left: calc(var(--scrs-terry-w) * .45);
  width: 12px; height: 12px; background: #fff;
  border-right: 2px solid var(--scrs-terry-green); border-bottom: 2px solid var(--scrs-terry-green);
  transform: rotate(45deg);
}
.scrs-terry--bubble-right .scrs-terry__bubble {
  left: calc(100% + 14px); bottom: 0;
  max-width: min(260px, calc(100vw - var(--scrs-terry-w) - 14px - 2 * var(--scrs-terry-gap) - var(--scrs-terry-safe-l) - var(--scrs-terry-safe-r)));
  max-height: calc(100vh - 2 * var(--scrs-terry-gap) - var(--scrs-terry-safe-b) - var(--scrs-terry-safe-t));
  transform: translateX(-6px);
}
.scrs-terry--bubble-right .scrs-terry__bubble::after { bottom: 18px; left: -8px; transform: rotate(135deg); }
.scrs-terry__text { margin: 0; }
.scrs-terry--saying .scrs-terry__bubble { opacity: 1; visibility: visible; transform: none; transition: opacity .18s ease, transform .18s ease; }

@keyframes scrs-terry-breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.004, 1.008); } }
@keyframes scrs-terry-wave {
  0%, 100% { transform: rotate(0); } 15% { transform: rotate(-8deg); } 35% { transform: rotate(6deg); }
  55% { transform: rotate(-8deg); } 75% { transform: rotate(5deg); }
}

/* reduced motion: static pose; no breathing, waving, head turns, mouth animation or slide/fade transitions */
.scrs-terry--reduced .scrs-terry__rig, .scrs-terry--reduced .scrs-terry__arm { animation: none; }
.scrs-terry--reduced .scrs-terry__lids { opacity: 0 !important; }
.scrs-terry--reduced .scrs-terry__head { transform: none; transition: none; }
.scrs-terry--reduced .scrs-terry__mouth, .scrs-terry--reduced .scrs-terry__bubble,
.scrs-terry--reduced .scrs-terry__figure, .scrs-terry--reduced .scrs-terry__chip { transition: none; }
@media (prefers-reduced-motion: reduce) {
  .scrs-terry__rig, .scrs-terry__arm { animation: none !important; }
  .scrs-terry__head { transform: none !important; transition: none !important; }
  .scrs-terry__mouth, .scrs-terry__bubble, .scrs-terry__figure, .scrs-terry__chip { transition: none !important; }
}
