/* ==========================================================================
 * HANHAI AI (瀚海AI) — Stage 3: 120fps Precision UI Motion
 * Scope: /canvas/ (2D Canvas), /3d-canvas/ (3D Canvas), /3d-box/ (3D-BOX)
 *
 * IRON RULES:
 *  - ZERO background particles, ZERO canvas-wide heavy shadows
 *  - ZERO catch-all transitions (explicit GPU-only transform / opacity / scale / clip-path)
 *  - Strict Night (Obsidian Gold) & Day (Warm Ivory) theme scoping
 *  - Automatic pause of decorative wire pulses during active pan/zoom/drag
 *  - Full @media (prefers-reduced-motion: reduce) compliance
 * ========================================================================== */

:root {
  --hh-cm-ease-spring: cubic-bezier(0.22, 1, 0.36, 1);
  --hh-cm-ease-snappy: cubic-bezier(0.2, 0.9, 0.3, 1);
  --hh-cm-ease-exit: cubic-bezier(0.4, 0, 1, 1);

  /* Night (Warm Obsidian & Luminous Gold) */
  --hh-cm-glass-bg: rgba(20, 17, 13, 0.82);
  --hh-cm-glass-border: rgba(224, 182, 94, 0.28);
  --hh-cm-glass-border-hover: rgba(243, 203, 122, 0.52);
  --hh-cm-glass-inset: inset 0 1px 0 rgba(255, 248, 232, 0.07);
  --hh-cm-gold: #f3cb7a;
  --hh-cm-gold-deep: #d89b3c;
  --hh-cm-wire-glow: rgba(243, 203, 122, 0.62);
}

html[data-hhv-appearance^="day"],
html.hhd4-day {
  /* Day (Warm Ivory & Burnished Gold) */
  --hh-cm-glass-bg: rgba(255, 252, 246, 0.88);
  --hh-cm-glass-border: rgba(184, 130, 36, 0.24);
  --hh-cm-glass-border-hover: rgba(184, 130, 36, 0.50);
  --hh-cm-glass-inset: inset 0 1px 0 rgba(255, 255, 255, 0.82);
  --hh-cm-gold: #b87c1a;
  --hh-cm-gold-deep: #9c650e;
  --hh-cm-wire-glow: rgba(184, 130, 36, 0.45);
}

/* ---------- 1. Node Spring Pop-In & Smooth Fade-Shrink Exit ----------
 * Uses standalone `scale` + `opacity` so inline `transform: translate(x,y)`
 * controlled by canvas pan/drag engines is NEVER overridden or disrupted. */
@keyframes hhCmNodePopIn {
  0% {
    opacity: 0;
    scale: 0.92;
  }
  100% {
    opacity: 1;
    scale: 1;
  }
}

.hhce-node.hh-cm-node-enter,
.node-element.hh-cm-node-enter {
  animation: hhCmNodePopIn 220ms var(--hh-cm-ease-spring) both;
  will-change: opacity, scale;
}

.hhce-node.hh-cm-node-exit,
.node-element.hh-cm-node-exit {
  pointer-events: none !important;
  opacity: 0 !important;
  scale: 0.92 !important;
  transition: opacity 170ms var(--hh-cm-ease-exit), scale 170ms var(--hh-cm-ease-exit) !important;
}

/* ---------- 2. Active / Running Bezier Wire Flowing Warm-Gold Light Pulse ---------- */
@keyframes hhCmWireFlow {
  0% {
    stroke-dashoffset: 48;
  }
  100% {
    stroke-dashoffset: 0;
  }
}

svg path.hh-cm-wire-active {
  stroke: var(--hh-cm-gold) !important;
  stroke-dasharray: 10 14 !important;
  stroke-linecap: round;
  animation: hhCmWireFlow 1.15s linear infinite;
  filter: drop-shadow(0 0 3px var(--hh-cm-wire-glow));
  pointer-events: none;
}

/* Freeze decorative wire pulses during active pan/zoom/drag for pure 120fps */
html.hh-cm-interacting svg path.hh-cm-wire-active {
  animation-play-state: paused !important;
}

/* ---------- 3. Context Menus, Popovers & Template Drawers Directional Spring ---------- */
@keyframes hhCmMenuSpring {
  0% {
    opacity: 0;
    transform: translate3d(0, -6px, 0) scale(0.96);
  }
  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

@keyframes hhCmDrawerSpring {
  0% {
    opacity: 0;
    transform: translate3d(0, 10px, 0) scale(0.97);
  }
  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

body.hanhai-canvas-standalone .export-popover:not([hidden]),
body.hanhai-canvas-standalone .export-menu:not([hidden]),
body.hanhai-3d-canvas-standalone .ant-dropdown:not(.ant-dropdown-hidden),
body.hanhai-3d-canvas-standalone .ant-popover:not(.ant-popover-hidden),
body.hanhai-3d-canvas-standalone .ant-select-dropdown:not(.ant-select-dropdown-hidden),
body.hanhai-3d-box-standalone .hh3db-tpl-menu:not([hidden]),
body.hanhai-3d-box-standalone .hh3db-import-menu:not([hidden]) {
  transform-origin: top left;
  animation: hhCmMenuSpring 180ms var(--hh-cm-ease-spring) both;
}

body.hanhai-canvas-standalone .hhm-dock-drawer.is-open,
body.hanhai-3d-box-standalone .hh3db-asset-drawer.is-open,
body.hanhai-3d-box-standalone .hh3db-modal-card {
  animation: hhCmDrawerSpring 210ms var(--hh-cm-ease-spring) both;
}

/* ---------- 4. Floating Toolbars: Refined Frosted-Glass Hairline Gold Border ---------- */
body.hanhai-canvas-standalone .c7-toolbar,
body.hanhai-canvas-standalone .canvas-generation-dock,
body.hanhai-3d-box-standalone .hh3db-float-pill-bar,
body.hanhai-3d-box-standalone .hh3db-bridge-bar,
body.hanhai-3d-box-standalone .hh3db-timeline-dock,
body.hanhai-3d-box-standalone .hh3db-quickstart-bar,
body.hanhai-3d-box-standalone .hh3db-motion-toolbar {
  border-color: var(--hh-cm-glass-border) !important;
  box-shadow: var(--hh-cm-glass-inset), 0 8px 24px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(14px) saturate(135%);
  -webkit-backdrop-filter: blur(14px) saturate(135%);
  transition: border-color 180ms var(--hh-cm-ease-snappy);
}

html[data-hhv-appearance^="day"] body.hanhai-canvas-standalone .c7-toolbar,
html.hhd4-day body.hanhai-canvas-standalone .c7-toolbar,
html[data-hhv-appearance^="day"] body.hanhai-canvas-standalone .canvas-generation-dock,
html.hhd4-day body.hanhai-canvas-standalone .canvas-generation-dock,
html[data-hhv-appearance^="day"] body.hanhai-3d-box-standalone .hh3db-float-pill-bar,
html.hhd4-day body.hanhai-3d-box-standalone .hh3db-float-pill-bar,
html[data-hhv-appearance^="day"] body.hanhai-3d-box-standalone .hh3db-bridge-bar,
html.hhd4-day body.hanhai-3d-box-standalone .hh3db-bridge-bar,
html[data-hhv-appearance^="day"] body.hanhai-3d-box-standalone .hh3db-timeline-dock,
html.hhd4-day body.hanhai-3d-box-standalone .hh3db-timeline-dock,
html[data-hhv-appearance^="day"] body.hanhai-3d-box-standalone .hh3db-quickstart-bar,
html.hhd4-day body.hanhai-3d-box-standalone .hh3db-quickstart-bar,
html[data-hhv-appearance^="day"] body.hanhai-3d-box-standalone .hh3db-motion-toolbar,
html.hhd4-day body.hanhai-3d-box-standalone .hh3db-motion-toolbar {
  background-color: var(--hh-cm-glass-bg);
  border-color: var(--hh-cm-glass-border) !important;
  box-shadow: var(--hh-cm-glass-inset), 0 8px 22px rgba(42, 30, 12, 0.10);
}

body.hanhai-canvas-standalone .c7-toolbar:hover,
body.hanhai-3d-box-standalone .hh3db-float-pill-bar:hover,
body.hanhai-3d-box-standalone .hh3db-bridge-bar:hover,
body.hanhai-3d-box-standalone .hh3db-timeline-dock:hover {
  border-color: var(--hh-cm-glass-border-hover) !important;
}

/* 3D Canvas floating pill toolbars (marked lightweight via JS without heavy shadows) */
body.hanhai-3d-canvas-standalone .hh-cm-float-bar {
  border-color: var(--hh-cm-glass-border) !important;
  box-shadow: var(--hh-cm-glass-inset), 0 8px 22px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(14px) saturate(135%);
  -webkit-backdrop-filter: blur(14px) saturate(135%);
  transition: border-color 180ms var(--hh-cm-ease-snappy);
}
html[data-hhv-appearance^="day"] body.hanhai-3d-canvas-standalone .hh-cm-float-bar,
html.hhd4-day body.hanhai-3d-canvas-standalone .hh-cm-float-bar {
  box-shadow: var(--hh-cm-glass-inset), 0 8px 20px rgba(42, 30, 12, 0.09);
}

/* Crisp tactile micro-feedback on floating toolbar buttons (GPU-only) */
body.hanhai-canvas-standalone .c7-toolbar button,
body.hanhai-canvas-standalone .c7-am-btn,
body.hanhai-canvas-standalone .hhm-dock-fab,
body.hanhai-3d-box-standalone .hh3db-tool-btn,
body.hanhai-3d-box-standalone .hh3db-tl-btn,
body.hanhai-3d-box-standalone .hh3db-mode-btn,
body.hanhai-3d-box-standalone .hh3db-top-btn,
body.hanhai-3d-box-standalone .hh3db-tab-btn,
body.hanhai-3d-box-standalone .hh3db-chip-btn,
body.hanhai-3d-canvas-standalone .hh-cm-float-bar button {
  transition: transform 140ms var(--hh-cm-ease-snappy),
              border-color 150ms ease,
              opacity 150ms ease;
}

body.hanhai-canvas-standalone .c7-toolbar button:active,
body.hanhai-canvas-standalone .c7-am-btn:active,
body.hanhai-canvas-standalone .hhm-dock-fab:active,
body.hanhai-3d-box-standalone .hh3db-tool-btn:active,
body.hanhai-3d-box-standalone .hh3db-tl-btn:active,
body.hanhai-3d-box-standalone .hh3db-mode-btn:active,
body.hanhai-3d-box-standalone .hh3db-top-btn:active,
body.hanhai-3d-box-standalone .hh3db-tab-btn:active,
body.hanhai-3d-box-standalone .hh3db-chip-btn:active,
body.hanhai-3d-canvas-standalone .hh-cm-float-bar button:active {
  transform: scale(0.96);
}

/* 3D-BOX pose/template cards subtle crisp hover lift */
body.hanhai-3d-box-standalone .hh3db-pose-card {
  transition: transform 160ms var(--hh-cm-ease-spring), border-color 160ms ease;
}
body.hanhai-3d-box-standalone .hh3db-pose-card:hover {
  transform: translate3d(0, -1.5px, 0);
  border-color: var(--hh-cm-glass-border-hover);
}
body.hanhai-3d-box-standalone .hh3db-pose-card:active {
  transform: scale(0.97);
}

/* ---------- 5. 2D Canvas (/canvas/) Precision Anchor & Zero-Drift Guards ----------
 * Fixes:
 *  (a) Stranded .c5-multi-handle '+' button during pan/zoom/drag (overrides
 *      legacy 3-ID specificity opacity:1!important rule on .c5-multi-handle).
 *  (b) Frame-0 hide of screen-space overlays while GPU .hhce-world pans/zooms
 *      (html.c730-drag / html.c731-wheel / html.hh-cm-panning / [data-hh-interacting="1"]).
 *  (c) Rock-solid .c5-verbadge ('2 ⌄') anchor: identical top-right position
 *      on unselected & single-select (zero jump), and exact 40px*--c4-inv
 *      offset on multi-select (html.c5-multi) for guaranteed 10px gap from blue 1/2 badge.
 */
html:is(.c730-drag, .c731-wheel, .hh-cm-panning) body:not(#hhcm1):not(#hhcm2):not(#hhcm3):not(#hhcm4) :is(
  .c5-multi-handle,
  .c5-multibox,
  .c5-bar,
  .c72-np,
  .hhce-quickadd,
  .c5-hist,
  .hhce-link-preview,
  .c4-bar
) {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  transition: none !important;
}

/* Lock screen-space selection overlays to exact computed coordinates (no laggy left/top/transform transition) */
body.hanhai-canvas-standalone :is(.c5-multibox, .c5-multi-handle, .c5-bar, .c72-np) {
  transition-property: opacity, background-color, border-color, color !important;
}

/* Stabilize .c5-verbadge ('2 ⌄'): zero inward jump on single-select */
html.c5-on:not(.c5-multi) body:not(#hhcm1):not(#hhcm2):not(#hhcm3):not(#hhcm4) .hhce-shape > .c5-verbadge,
html.c5-on:not(.c5-multi) body:not(#hhcm1):not(#hhcm2):not(#hhcm3):not(#hhcm4) .hhce-shape.is-selected > .c5-verbadge {
  top: calc(10px * clamp(.75, calc(var(--c4-inv, 1) * .88), 2.2)) !important;
  right: calc(10px * clamp(.75, calc(var(--c4-inv, 1) * .88), 2.2)) !important;
  transition: background-color 150ms ease, border-color 150ms ease !important;
}

/* Multi-select: place .c5-verbadge cleanly 10px left of blue order badge (.hhce-sel-check: right 6px + width 24px = 30px) at ALL zoom levels */
html.c5-on.c5-multi body:not(#hhcm1):not(#hhcm2):not(#hhcm3):not(#hhcm4) .hhce-shape.is-selected > .c5-verbadge {
  top: calc(8px * clamp(.75, calc(var(--c4-inv, 1) * .88), 2.2)) !important;
  right: calc(40px * var(--c4-inv, 1)) !important;
  transition: none !important;
}

/* ---------- 6. Reduced Motion Respect ---------- */
@media (prefers-reduced-motion: reduce) {
  .hhce-node.hh-cm-node-enter,
  .node-element.hh-cm-node-enter,
  svg path.hh-cm-wire-active,
  body.hanhai-canvas-standalone .export-popover:not([hidden]),
  body.hanhai-canvas-standalone .export-menu:not([hidden]),
  body.hanhai-3d-canvas-standalone .ant-dropdown:not(.ant-dropdown-hidden),
  body.hanhai-3d-canvas-standalone .ant-popover:not(.ant-popover-hidden),
  body.hanhai-3d-canvas-standalone .ant-select-dropdown:not(.ant-select-dropdown-hidden),
  body.hanhai-3d-box-standalone .hh3db-tpl-menu:not([hidden]),
  body.hanhai-3d-box-standalone .hh3db-import-menu:not([hidden]),
  body.hanhai-canvas-standalone .hhm-dock-drawer.is-open,
  body.hanhai-3d-box-standalone .hh3db-asset-drawer.is-open,
  body.hanhai-3d-box-standalone .hh3db-modal-card {
    animation: none !important;
  }
  .hhce-node.hh-cm-node-exit,
  .node-element.hh-cm-node-exit,
  body.hanhai-canvas-standalone .c7-toolbar,
  body.hanhai-canvas-standalone .canvas-generation-dock,
  body.hanhai-canvas-standalone .c7-toolbar button,
  body.hanhai-3d-box-standalone .hh3db-pose-card,
  body.hanhai-3d-box-standalone .hh3db-tool-btn,
  body.hanhai-3d-canvas-standalone .hh-cm-float-bar {
    transition: none !important;
  }
}
