/* Riadom motion system.
   One vocabulary for the whole app: things open from where you touched them,
   leave faster than they arrive, and paper-like objects settle with a small
   spring. Only transform, opacity and filter animate. Canvas objects and the
   camera are moved by board.js; nothing here moves the board itself.

   Timings follow the measured editor norms (most UI motion 120–300 ms,
   expo-out for entrances, ease-in for exits) with longer curves reserved for
   large panels. */
:root {
  --ease-expo:cubic-bezier(.19,1,.22,1);
  --ease-standard:cubic-bezier(.4,0,.2,1);
  --ease-exit:cubic-bezier(.4,0,1,1);
  --ease-lift:cubic-bezier(.27,-.01,.45,1.32);
  --ease-pop:cubic-bezier(.34,1.45,.55,1);
  --ease-drawer:cubic-bezier(.32,.72,0,1);
  --d-press:80ms;
  --d-hover:140ms;
  --d-exit:160ms;
  --d-enter:280ms;
  --d-panel:420ms;
  --d-drawer:560ms;
  --d-scene:640ms;
}

@media screen and (prefers-reduced-motion: no-preference) {
  /* ---------- Board arrival: one orchestrated sequence ---------- */
  body[data-screen=board] .board-bar {animation: rz-arrive-top var(--d-scene) var(--ease-expo) both}
  body[data-screen=board] .people-bar {animation: rz-arrive-top var(--d-scene) 50ms var(--ease-expo) both}
  body[data-screen=board] .creation-dock {animation: rz-arrive-left var(--d-scene) 90ms var(--ease-expo) both}
  body[data-screen=board] .controls {animation: rz-arrive-bottom var(--d-scene) 140ms var(--ease-expo) both}
  body[data-screen=board] .assistant-dock {animation: rz-arrive-bottom var(--d-scene) 190ms var(--ease-expo) both}
  body[data-screen=board] #canvas {animation: rz-canvas-in 520ms var(--ease-expo) both}

  /* ---------- Popovers & menus: grow from the anchor, quick exit ---------- */
  .popover:not([data-closing]) {animation: rz-pop-in var(--d-enter) var(--ease-expo) both}
  .popover[data-closing] {animation: rz-pop-out var(--d-exit) var(--ease-exit) both}
  .popover .menu-row {animation: rz-row-in 360ms var(--ease-expo) both}
  .popover .menu-row:nth-child(2) {animation-delay: 12ms}
  .popover .menu-row:nth-child(3) {animation-delay: 24ms}
  .popover .menu-row:nth-child(4) {animation-delay: 36ms}
  .popover .menu-row:nth-child(5) {animation-delay: 48ms}
  .popover .menu-row:nth-child(6) {animation-delay: 60ms}
  .popover .menu-row:nth-child(n+7) {animation-delay: 72ms}
  .popover .note-swatch {animation: rz-swatch-in 420ms var(--ease-pop) both}
  .popover .note-swatch:nth-child(4n+2) {animation-delay: 20ms}
  .popover .note-swatch:nth-child(4n+3) {animation-delay: 40ms}
  .popover .note-swatch:nth-child(4n) {animation-delay: 60ms}
  .menu-row svg {transition: translate var(--d-hover) var(--ease-expo), color var(--d-hover) ease}
  .menu-row:hover svg {translate: 2px 0}

  /* ---------- Side tools, context bar, panels ---------- */
  body[data-screen=board] .draw-tools:not([hidden]) {animation: rz-side-in var(--d-enter) var(--ease-expo) both}
  body[data-screen=board] .object-context:not([hidden]) {animation: rz-context-in 240ms var(--ease-expo) both}
  body[data-screen=board] .drawer:not([hidden]) {animation: rz-drawer-in var(--d-drawer) var(--ease-drawer) both}
  body[data-screen=board] .call-panel:not([hidden]) {animation: rz-drawer-in var(--d-panel) var(--ease-drawer) both}
  body[data-screen=board] .presentation-controls:not([hidden]) {animation: rz-arrive-bottom var(--d-panel) var(--ease-expo) both}
  #minimap:not([hidden]) {animation: rz-pop-in var(--d-enter) var(--ease-expo) both; transform-origin: bottom right}
  .board-timer:not([hidden]),.vote-status:not([hidden]) {animation: rz-chip-in 420ms var(--ease-pop) both}

  /* ---------- Dialogs: backdrop fades, sheet rises; exit is quick ---------- */
  dialog[open] {animation: rz-sheet-in 380ms var(--ease-expo) both}
  dialog[open]::backdrop {animation: rz-backdrop-in 260ms var(--ease-standard) both}
  dialog[open] .dialog-content > * {animation: rz-row-in 420ms var(--ease-expo) both}
  dialog[open] .dialog-content > :nth-child(2) {animation-delay: 30ms}
  dialog[open] .dialog-content > :nth-child(3) {animation-delay: 60ms}
  dialog[open] .dialog-content > :nth-child(n+4) {animation-delay: 90ms}
  @supports (transition-behavior: allow-discrete) and (overlay: auto) {
    dialog {
      transition: opacity var(--d-exit) var(--ease-exit), scale var(--d-exit) var(--ease-exit),
        display var(--d-exit) allow-discrete, overlay var(--d-exit) allow-discrete;
    }
    dialog:not([open]) {opacity: 0; scale: .985}
    dialog::backdrop {transition: opacity var(--d-exit) var(--ease-exit), display var(--d-exit) allow-discrete, overlay var(--d-exit) allow-discrete}
    dialog:not([open])::backdrop {opacity: 0}
  }

  /* ---------- Toasts: drop in from the top, fade out ---------- */
  #notice:not([hidden]) .notice-card {animation: rz-toast-in 420ms var(--ease-expo) both}
  #notice[data-leaving] .notice-card {animation: rz-toast-out 200ms var(--ease-exit) both}
  #notice .notice-icon {animation: rz-icon-pop 520ms 90ms var(--ease-pop) both}

  /* ---------- Press, hover, tool pick ---------- */
  :is(.square, .primary, .soft, .dark, .menu-row, .nav-row, .note-swatch, .preset, .zoom-value, .assistant-card, .assistant-starter, .assistant-chip, .assistant-action, .template-tile, .share-tabs button, .tool-panel-tabs button) {
    transition-property: background-color, color, box-shadow, border-color, scale, translate, opacity;
    transition-duration: var(--d-hover);
    transition-timing-function: var(--ease-expo);
  }
  :is(.square, .primary, .soft, .dark, .menu-row, .nav-row, .note-swatch, .preset, .zoom-value, .assistant-card, .assistant-starter, .assistant-chip, .assistant-action, .template-tile):active:not(:disabled) {
    scale: .95;
    transition-duration: var(--d-press);
  }
  body[data-screen=board] :is(.creation, .draw-tools, .undo-bar) .square svg {transition: scale 260ms var(--ease-pop)}
  body[data-screen=board] :is(.creation, .draw-tools, .undo-bar) .square:hover:not(:disabled) svg {scale: 1.08}
  .creation .square.selected svg, .draw-tools .square.selected svg {animation: rz-tool-pick 420ms var(--ease-pop)}

  /* ---------- Tooltips: delayed first time, then instant neighbours ---------- */
  @media (hover:hover) and (pointer:fine) {
    :is(.creation,.undo-bar,.launcher,.draw-tools,.controls,.board-bar,.people-bar) button[data-tip]::after {
      transition: opacity 140ms ease, translate 260ms var(--ease-expo), scale 260ms var(--ease-expo);
      scale: .96;
    }
    :is(.creation,.undo-bar,.launcher,.draw-tools,.controls,.board-bar,.people-bar) button[data-tip]:hover::after {scale: 1}
    :is(.creation,.undo-bar,.launcher,.draw-tools,.controls,.board-bar,.people-bar):has(button[data-tip]:hover) button[data-tip]:hover::after {transition-delay: 420ms}
  }

  /* ---------- Canvas objects created by tools settle in ---------- */
  .object-enter {transform-box: fill-box; transform-origin: center; animation: rz-object-in 360ms var(--ease-pop) backwards}
  .object-enter:is([data-type=pen],[data-type=arrow],[data-type=line]) {animation: rz-fade-in 200ms var(--ease-standard) backwards}
  #editor {animation: rz-fade-in 140ms var(--ease-standard)}

  /* ---------- Reactions float up and pop ---------- */
  .reaction {animation: rz-reaction-float 2200ms var(--ease-standard) both}
  .reaction > span {display: inline-block; animation: rz-reaction-pop 700ms var(--ease-pop) both}

  /* ---------- Skeleton loading ---------- */
  .board-skeleton-progress {animation: rz-progress-run 1600ms var(--ease-expo) infinite}
  .board-skeleton-mark .bsm-note {animation: rz-bsm-drop 1800ms var(--ease-pop) infinite}
  .board-skeleton-mark .bsm-note:nth-child(2) {animation-delay: 140ms}
  .board-skeleton-mark .bsm-note:nth-child(3) {animation-delay: 280ms}
  .board-skeleton-part {animation: rz-fade-in 300ms var(--ease-standard) both}

  /* ---------- Page transitions (View Transitions API) ---------- */
  ::view-transition-old(root),::view-transition-new(root) {animation-duration: 460ms; animation-timing-function: var(--ease-expo)}
  :root[data-route=into-board]::view-transition-old(root) {animation-name: rz-vt-zoom-out-old}
  :root[data-route=into-board]::view-transition-new(root) {animation-name: rz-vt-zoom-in-new}
  :root[data-route=out-of-board]::view-transition-old(root) {animation-name: rz-vt-shrink-old}
  :root[data-route=out-of-board]::view-transition-new(root) {animation-name: rz-vt-rise-new}
}

/* Reduced motion: keep state changes, drop travel and loops. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}

@keyframes rz-fade-in {from {opacity: 0}}
@keyframes rz-arrive-top {from {opacity: 0; translate: 0 -14px}}
@keyframes rz-arrive-left {from {opacity: 0; translate: -16px 0}}
@keyframes rz-arrive-bottom {from {opacity: 0; translate: 0 18px}}
@keyframes rz-canvas-in {from {opacity: 0; scale: 1.015}}
@keyframes rz-pop-in {from {opacity: 0; scale: .96}}
@keyframes rz-pop-out {to {opacity: 0; scale: .98}}
@keyframes rz-row-in {from {opacity: 0; translate: 0 4px}}
@keyframes rz-swatch-in {from {opacity: 0; scale: .6}}
@keyframes rz-side-in {from {opacity: 0; translate: -10px 0; scale: .97}}
@keyframes rz-context-in {from {opacity: 0; translate: 0 6px; scale: .97}}
@keyframes rz-drawer-in {from {opacity: 0; translate: 28px 0}}
@keyframes rz-chip-in {from {opacity: 0; scale: .7}}
@keyframes rz-sheet-in {from {opacity: 0; translate: 0 18px; scale: .975}}
@keyframes rz-backdrop-in {from {opacity: 0}}
@keyframes rz-toast-in {from {opacity: 0; translate: 0 -16px; scale: .96}}
@keyframes rz-toast-out {to {opacity: 0; translate: 0 -6px; scale: .98}}
@keyframes rz-icon-pop {from {scale: .3; rotate: -30deg}}
@keyframes rz-tool-pick {0% {scale: .78} 55% {scale: 1.12} 100% {scale: 1}}
@keyframes rz-object-in {from {opacity: 0; scale: .9}}
@keyframes rz-reaction-float {0% {opacity: 0; translate: 0 10px} 12% {opacity: 1; translate: 0 0} 80% {opacity: 1} 100% {opacity: 0; translate: 0 -34px}}
@keyframes rz-reaction-pop {from {scale: .5; rotate: -30deg}}
@keyframes rz-progress-run {0% {scale: 0 1; opacity: 1} 70% {scale: 1 1; opacity: 1} 100% {scale: 1 1; opacity: 0}}
@keyframes rz-bsm-drop {0% {opacity: 0; translate: 0 -10px; scale: .8} 18%, 70% {opacity: 1; translate: 0 0; scale: 1} 90%, 100% {opacity: 0; translate: 0 4px; scale: .96}}
@keyframes rz-vt-zoom-out-old {to {opacity: 0; scale: 1.035; filter: blur(2px)}}
@keyframes rz-vt-zoom-in-new {from {opacity: 0; scale: .975}}
@keyframes rz-vt-shrink-old {to {opacity: 0; scale: .975}}
@keyframes rz-vt-rise-new {from {opacity: 0; translate: 0 10px}}
