/* ============================================================
   TraceRecord motion system — Concept 15 in production
   Objects register · relationships trace · actions connect ·
   limitations qualify · information reveals · approval resolves ·
   the record hands over. When nothing changes, everything is still.
   ============================================================ */

:root {
  --tr-motion-instant: 120ms;
  --tr-motion-fast: 160ms;
  --tr-motion-standard: 220ms;
  --tr-motion-relation: 320ms;
  --tr-motion-narrative: 460ms;

  --tr-motion-distance-micro: 2px;
  --tr-motion-distance-object: 5px;
  --tr-motion-distance-section: 10px;

  --tr-ease-control: cubic-bezier(.2, .8, .2, 1);
  --tr-ease-object: cubic-bezier(.22, .61, .36, 1);
  --tr-ease-narrative: cubic-bezier(.16, 1, .3, 1);

  --tr-motion-amber: #b7791f;
  --tr-motion-trace: #b7a77e;
  --tr-motion-node: #0f1b2d;
}

/* ---------- REGISTER · an object enters the record ---------- */
@keyframes trRegister {
  from { opacity: 0; transform: translateY(var(--tr-motion-distance-object)); }
  to { opacity: 1; transform: none; }
}
.tr-register {
  animation: trRegister var(--tr-motion-standard) var(--tr-ease-object) both;
}
/* registration corner resolves with the object, then stays */
.tr-register::after {
  content: "";
  position: absolute;
  top: -1px;
  left: -1px;
  width: 9px;
  height: 9px;
  border-top: 1.6px solid var(--tr-motion-trace);
  border-left: 1.6px solid var(--tr-motion-trace);
  opacity: 0;
  animation: trCorner var(--tr-motion-fast) var(--tr-ease-control) var(--tr-motion-standard) forwards;
  pointer-events: none;
}
@keyframes trCorner { to { opacity: 1; } }

/* ---------- TRACE · an existing relationship becomes visible ----------
   stroke-dasharray/offset are inherited properties, so setting them on the
   svg or <use> reaches the referenced symbol's own paths. */
@keyframes trTraceDraw { from { stroke-dashoffset: var(--tr-dash, 160); } to { stroke-dashoffset: 0; } }
.tr-trace {
  stroke-dasharray: var(--tr-dash, 160);
  animation: trTraceDraw var(--tr-motion-relation) var(--tr-ease-object) both;
}

/* ---------- CONNECT · the user creates a new relationship ---------- */
.tr-connect {
  stroke-dasharray: var(--tr-dash, 160);
  animation: trTraceDraw var(--tr-motion-relation) var(--tr-ease-control) both;
}
@keyframes trNodeReceive {
  0% { transform: scale(1); }
  55% { transform: scale(1.22); }
  100% { transform: scale(1); }
}
.tr-connect-node {
  transform-box: fill-box;
  transform-origin: center;
  animation: trNodeReceive var(--tr-motion-standard) var(--tr-ease-control) var(--tr-motion-relation) both;
}
/* the source object holds brief focus while its connection draws */
.tr-connect-source {
  animation: trSourceFocus var(--tr-motion-relation) var(--tr-ease-control) both;
}
@keyframes trSourceFocus {
  0% { box-shadow: 0 0 0 0 rgba(60, 96, 129, 0); }
  45% { box-shadow: 0 0 0 3px rgba(60, 96, 129, .18); }
  100% { box-shadow: 0 0 0 0 rgba(60, 96, 129, 0); }
}

/* ---------- QUALIFY · a limitation modifies how a finding reads ---------- */
@keyframes trQualifyTether { from { opacity: 0; } to { opacity: 1; } }
.tr-qualify {
  animation: trRegister var(--tr-motion-relation) var(--tr-ease-object) 90ms both;
}
.tr-qualify-tether {
  border-left: 1.4px dashed var(--tr-motion-amber);
  animation: trQualifyTether var(--tr-motion-standard) var(--tr-ease-control) both;
}

/* ---------- REVEAL · relevant information becomes visible ---------- */
@keyframes trReveal {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}
.tr-reveal { animation: trReveal var(--tr-motion-standard) var(--tr-ease-object) both; }
.tr-reveal-seq > * { animation: trReveal var(--tr-motion-standard) var(--tr-ease-object) both; }
.tr-reveal-seq > *:nth-child(2) { animation-delay: 60ms; }
.tr-reveal-seq > *:nth-child(3) { animation-delay: 120ms; }
.tr-reveal-seq > *:nth-child(4) { animation-delay: 180ms; }
/* bounded result: the two sides arrive 100ms apart so neither collapses
   into a single pass/fail reading */
.tr-reveal-bounded > *:nth-child(2) { animation-delay: 100ms; }

/* ---------- RESOLVE · a review state completes ---------- */
@keyframes trResolve {
  0% { opacity: 0; transform: scale(.985); }
  100% { opacity: 1; transform: none; }
}
.tr-resolve { animation: trResolve var(--tr-motion-narrative) var(--tr-ease-object) both; }
@keyframes trMarkDraw { from { stroke-dashoffset: 26; } to { stroke-dashoffset: 0; } }
.tr-resolve-mark {
  stroke-dasharray: 26;
  animation: trMarkDraw var(--tr-motion-relation) var(--tr-ease-control) 120ms both;
}

/* ---------- HAND OVER · the record carries into the report ---------- */
@keyframes trHandover {
  0% { opacity: 0; transform: translateX(-6px); }
  100% { opacity: 1; transform: none; }
}
.tr-handover { animation: trHandover var(--tr-motion-narrative) var(--tr-ease-narrative) both; }
/* what the record carried into: a temporary tint, never movement */
.tr-handover-target,
.tr-traced {
  animation: trTraced 1.5s var(--tr-ease-control) both;
}
@keyframes trTraced {
  0% { background-color: rgba(183, 121, 31, 0); box-shadow: inset 2px 0 0 rgba(183, 121, 31, 0); }
  14% { background-color: rgba(183, 121, 31, .12); box-shadow: inset 2px 0 0 var(--tr-motion-amber); }
  70% { background-color: rgba(183, 121, 31, .12); box-shadow: inset 2px 0 0 var(--tr-motion-amber); }
  100% { background-color: rgba(183, 121, 31, 0); box-shadow: inset 2px 0 0 rgba(183, 121, 31, 0); }
}

/* ---------- FOCUS / INSPECT · reduce competition, never move ----------
   the examined object gains contrast, unrelated siblings go quieter,
   nothing shifts position by more than a pixel. */
.tr-focus-scope [data-tr-quiet] {
  opacity: .82;
  transition: opacity var(--tr-motion-standard) var(--tr-ease-control);
}
.tr-focused {
  transform: translateY(-1px);
  transition: transform var(--tr-motion-fast) var(--tr-ease-control),
    border-color var(--tr-motion-fast) var(--tr-ease-control);
}

/* ---------- icon motion hierarchy ----------
   L1 brand · L2 pathway · L3 instrument · L4 record · L5 utility.
   Each level moves differently, so the class of object is legible
   from behaviour as well as form. The glyphs are <use> references —
   stroke-dash properties do not reach the referenced geometry — so the
   choreography is carried by transform, which does. */
@keyframes trIconPathway {
  0% { transform: translateX(-2px); }
  60% { transform: translateX(1px); }
  100% { transform: none; }
}
@keyframes trIconTool {
  0% { transform: translateY(2px) scale(.97); }
  100% { transform: none; }
}
@keyframes trIconBrand {
  0% { transform: scale(.97); }
  100% { transform: none; }
}
.tr-icon-pathway.is-playing {
  animation: trIconPathway var(--tr-motion-narrative) var(--tr-ease-object) both;
}
.tr-icon-tool.is-playing {
  animation: trIconTool var(--tr-motion-relation) var(--tr-ease-object) both;
}
@keyframes trIconObject {
  0% { transform: translateY(1.5px); opacity: .78; }
  100% { transform: none; opacity: 1; }
}
.tr-icon-brand.is-playing {
  animation: trIconBrand 620ms var(--tr-ease-narrative) both;
}
/* L4 record object: the object's own affordance answers, briefly */
.tr-icon-object.is-playing {
  animation: trIconObject var(--tr-motion-fast) var(--tr-ease-control) both;
}
/* L5 utility: one standard quiet response, no choreography */
.tr-icon-utility {
  transition: transform var(--tr-motion-instant) var(--tr-ease-control),
    color var(--tr-motion-fast) var(--tr-ease-control);
}
a:hover > .tr-icon-utility,
button:hover > .tr-icon-utility,
a:focus-visible > .tr-icon-utility,
button:focus-visible > .tr-icon-utility { transform: translateX(1px); }

/* ---------- chapter / panel transition · content only ----------
   shell, rail, header and record identity never move. */
@keyframes trPanelIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}
.tr-panel-in { animation: trPanelIn var(--tr-motion-standard) var(--tr-ease-object) both; }

/* ---------- narrative scroll reveal (landing only) ---------- */
.tr-motion-js [data-tr-scene] > * {
  opacity: 0;
  transform: translateY(var(--tr-motion-distance-section));
  transition: opacity var(--tr-motion-narrative) var(--tr-ease-narrative) var(--tr-scene-delay, 0ms),
    transform var(--tr-motion-narrative) var(--tr-ease-narrative) var(--tr-scene-delay, 0ms);
}
.tr-motion-js [data-tr-scene].is-registered > * { opacity: 1; transform: none; }

/* ---------- buttons · M1, quiet and responsive ---------- */
.tr-motion-js .cl-btn,
.tr-motion-js .wsv4-btn,
.tr-motion-js .lp-btn {
  transition: transform var(--tr-motion-instant) var(--tr-ease-control),
    background-color var(--tr-motion-fast) var(--tr-ease-control),
    border-color var(--tr-motion-fast) var(--tr-ease-control),
    color var(--tr-motion-fast) var(--tr-ease-control);
}
.tr-motion-js .cl-btn:hover,
.tr-motion-js .wsv4-btn:hover,
.tr-motion-js .lp-btn:hover { transform: translateY(-1px); }
.tr-motion-js .cl-btn:active,
.tr-motion-js .wsv4-btn:active,
.tr-motion-js .lp-btn:active { transform: none; }

/* ---------- reduced motion ----------
   every final state above is already a valid static design, so nothing
   is lost: relationships, approval, limitation links and traceability
   all remain visible. */
@media (prefers-reduced-motion: reduce) {
  .tr-register, .tr-register::after, .tr-trace, .tr-connect, .tr-connect-node,
  .tr-connect-source, .tr-qualify, .tr-qualify-tether, .tr-reveal,
  .tr-reveal-seq > *, .tr-resolve, .tr-resolve-mark, .tr-handover,
  .tr-handover-target, .tr-traced, .tr-panel-in,
  .tr-icon-brand.is-playing, .tr-icon-pathway.is-playing, .tr-icon-tool.is-playing,
  .tr-icon-object.is-playing {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
    stroke-dasharray: none !important;
    stroke-dashoffset: 0 !important;
  }
  .tr-register::after { opacity: 1 !important; }
  .tr-traced, .tr-handover-target {
    background-color: rgba(183, 121, 31, .12) !important;
    box-shadow: inset 2px 0 0 var(--tr-motion-amber) !important;
  }
  .tr-motion-js [data-tr-scene] > * {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
  .tr-focused { transform: none !important; }
  .tr-motion-js .cl-btn, .tr-motion-js .wsv4-btn, .tr-motion-js .lp-btn { transition: none !important; }
  .tr-motion-js .cl-btn:hover, .tr-motion-js .wsv4-btn:hover, .tr-motion-js .lp-btn:hover { transform: none !important; }
}

/* mobile: shorter distances, no hover-only choreography */
@media (max-width: 640px) {
  :root {
    --tr-motion-distance-object: 3px;
    --tr-motion-distance-section: 7px;
  }
}
@media (hover: none) {
  .tr-focus-scope [data-tr-quiet] { opacity: 1; }
}
