/* ============================================================================
   Fiaschi Studio — shared motion + touch standard (every app moves the same way)
   Built 20/10/2026 from Loopr (screen slide, FAB bounce, popups) and Jim (touch areas).
   Load after components.css; behaviour lives in shared/motion.js (window.FSMotion).

   1. Screen slide   .slide-in-right / .slide-in-left on the screen element (FSMotion.slide)
   2. FAB bounce     .fab / .fab-mid squash while held and spring back past 1; the open menu pills gently
   3. Touch areas    an invisible ::before around every round floating button (.fab, .fab-mid), bigger than
                     the button, so a near-miss still lands on it. The visible size never changes. Reach per
                     side comes from --tz-t/-r/-b/-l (max) and is trimmed by FSMotion toward neighbours
                     (--tzf-*), so zones never overlap and never cover another button's circle.
   4. Popups         .pop-in / .pop-out on the overlay, .fs-pop-card on the card (FSMotion.show / hide):
                     centred cards bounce in and bounce back + fade out; bottom sheets (.fs-as-sheet, decided
                     from the layout when the popup opens) slide up and slide back down + fade.
   (The popup rules start with "html" so they win over an app's own fade / slide-up on the same element.)
   Reduced motion: no slide, no bounce, popups appear/disappear (.01s).
   ============================================================================ */
:root{
  --motion-view-dur:.26s;  --motion-view-ease:cubic-bezier(.22,.8,.3,1);
  --motion-spring:cubic-bezier(.34,1.9,.5,1);
  --motion-pop-in:.2s;     --motion-pop-ease:cubic-bezier(.2,.9,.3,1);
  --motion-pop-out:.16s;   --motion-fade-in:.12s;
  --motion-sheet-in:.22s;
}

/* ---------- 1. Screen slide ---------- */
@keyframes viewInFromRight{ from{ opacity:0; transform:translateX(44px); } to{ opacity:1; transform:none; } }
@keyframes viewInFromLeft{ from{ opacity:0; transform:translateX(-44px); } to{ opacity:1; transform:none; } }
.slide-in-right{ animation:viewInFromRight var(--motion-view-dur) var(--motion-view-ease) both; }
.slide-in-left{ animation:viewInFromLeft var(--motion-view-dur) var(--motion-view-ease) both; }
html.view-sliding, html.view-sliding body{ overflow-x:hidden; }

/* ---------- 2. Floating-button bounce ---------- */
.fab, .fab-mid{ transition:transform .32s var(--motion-spring), filter .15s; -webkit-user-select:none; user-select:none; -webkit-tap-highlight-color:transparent; }
.fab:active, .fab-mid:active{ transform:scale(.84); transition-duration:.08s, .15s; }
.fab-menu-wrap.open .fab-mini{ transition:opacity .18s ease, transform .32s var(--motion-spring); -webkit-user-select:none; user-select:none; }
.fab-menu-wrap.open .fab-mini:active{ transform:translateY(0) scale(.92); transition-duration:.18s, .08s; }

/* ---------- 3. Bigger invisible touch area (round floating buttons only; the menu pills keep their own size) ----------
   16px on the free sides (screen edge, below), less toward the screen centre and toward a neighbour. The right FAB
   keeps 6px toward the centre; the left FAB 8px above (the open menu pills sit 10px over it) and 6px toward the
   centre. --tz-bw adds the button's own border (offsets are measured from inside it). */
.fab{ --tz-t:16px; --tz-r:16px; --tz-b:16px; --tz-l:6px; }
.fab.fab-left, .fab-menu-wrap .fab{ --tz-t:8px; --tz-r:6px; --tz-b:16px; --tz-l:16px; }
.fab-mid{ --tz-t:12px; --tz-r:16px; --tz-b:16px; --tz-l:16px; --tz-bw:1px; }
.fab::before, .fab-mid::before{
  content:''; position:absolute; border-radius:inherit;
  top:calc(-1 * (var(--tzf-t, var(--tz-t)) + var(--tz-bw, 0px)));
  right:calc(-1 * (var(--tzf-r, var(--tz-r)) + var(--tz-bw, 0px)));
  bottom:calc(-1 * (var(--tzf-b, var(--tz-b)) + var(--tz-bw, 0px)));
  left:calc(-1 * (var(--tzf-l, var(--tz-l)) + var(--tz-bw, 0px)));
}

/* ---------- 4. Popups ---------- */
@keyframes popOverlayIn{ from{ opacity:0; } to{ opacity:1; } }
@keyframes popOverlayOut{ from{ opacity:1; } to{ opacity:0; } }
@keyframes popCardIn{ 0%{ transform:scale(.82); opacity:0; } 55%{ transform:scale(1.05); opacity:1; } 80%{ transform:scale(.985); } 100%{ transform:scale(1); opacity:1; } }
@keyframes popCardOut{ 0%{ transform:scale(1); opacity:1; } 30%{ transform:scale(1.04); opacity:1; } 100%{ transform:scale(.78); opacity:0; } }
@keyframes sheetIn{ from{ transform:translateY(32px); opacity:0; } to{ transform:none; opacity:1; } }
@keyframes sheetOut{ from{ transform:none; opacity:1; } to{ transform:translateY(40px); opacity:0; } }
html .pop-in{ animation:popOverlayIn var(--motion-fade-in) ease-out both; }
html .pop-out{ animation:popOverlayOut var(--motion-pop-out) ease-in both; pointer-events:none; }
html .pop-in .fs-pop-card{ animation:popCardIn var(--motion-pop-in) var(--motion-pop-ease) both; }
html .pop-out .fs-pop-card{ animation:popCardOut var(--motion-pop-out) ease-in both; }
html .pop-in.fs-as-sheet .fs-pop-card{ animation:sheetIn var(--motion-sheet-in) var(--motion-pop-ease) both; }
html .pop-out.fs-as-sheet .fs-pop-card{ animation:sheetOut var(--motion-pop-out) ease-in both; }

/* Popup frame (FSMotion.frame): the title stays at the top, the buttons at the bottom, only the middle scrolls.
   The card is limited to its overlay (FSMotion.show keeps the overlay the size of what the phone keyboard leaves free).
   Doubled class: wins over each card's own max-height / overflow without !important. */
.fs-framed.fs-framed{ display:flex; flex-direction:column; overflow:hidden; max-height:min(92vh, 100%); }
.fs-framed > *{ flex:0 0 auto; }
.fs-framed > .fs-frame-body{
  flex:1 1 auto; min-height:0; overflow-y:auto; overscroll-behavior:contain;
  color-scheme:dark; scrollbar-width:thin; scrollbar-color:var(--border, #404859) transparent;
}
.fs-frame-body::-webkit-scrollbar{ width:8px; }
.fs-frame-body::-webkit-scrollbar-thumb{ background:var(--border, #404859); border-radius:8px; }
.fs-frame-body::-webkit-scrollbar-track{ background:transparent; }
.fs-frame-body.fs-frame-flex{ display:flex; flex-direction:column; gap:inherit; }
/* thin dividers only while the middle really scrolls */
.fs-framed.fs-scrolls > .fs-frame-body{ border-top:1px solid var(--border, #404859); border-bottom:1px solid var(--border, #404859); padding-top:12px; padding-bottom:12px; }

@media (prefers-reduced-motion: reduce){
  .slide-in-right, .slide-in-left{ animation:none; }
  .fab, .fab:active, .fab-mid, .fab-mid:active, .fab-menu-wrap.open .fab-mini, .fab-menu-wrap.open .fab-mini:active{ transition:none; }
  .fab:active, .fab-mid:active{ transform:none; }
  .fab-menu-wrap.open .fab-mini:active{ transform:translateY(0) scale(1); }
  html .pop-in, html .pop-out, html .pop-in .fs-pop-card, html .pop-out .fs-pop-card{ animation-duration:.01s !important; }
}
