/* LOOP DIAGRAM — signature animated SVG. */

[data-mr="1"] .mr-loop {
  position: relative;
  width: 100%;
  aspect-ratio: 900 / 470;
  filter: drop-shadow(0 30px 60px rgba(0, 0, 0, 0.4));
}

[data-mr="1"] .mr-loop__svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

[data-mr="1"] .mr-loop__edge {
  fill: none;
  stroke: url(#mrLoopEdge);
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-dasharray: 6 10;
  animation: mr-loop-flow 6s linear infinite;
}

[data-mr="1"] .mr-loop__edge--return {
  stroke: url(#mrLoopEdgeReturn);
  stroke-dasharray: 5 9;
  opacity: 0.6;
  animation-duration: 9s;
}

@keyframes mr-loop-flow {
  from { stroke-dashoffset: 32; }
  to   { stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: reduce) {
  [data-mr="1"] .mr-loop__edge {
    animation: none;
    stroke-dasharray: 6 10;
  }
}

[data-mr="1"] .mr-loop__node {
  cursor: default;
  color: var(--mr-white);
  transition: transform var(--mr-dur-medium) var(--mr-ease-soft);
}

[data-mr="1"] .mr-loop__halo {
  opacity: 0;
  transform-origin: center;
  animation: mr-loop-halo 4.5s var(--mr-ease-soft) infinite;
}

/* Phase mktloop.4 — three phases now; the stagger walks Quote to Earn. */
[data-mr="1"] .mr-loop__node[data-node="quote"] .mr-loop__halo { animation-delay: 0s; }
[data-mr="1"] .mr-loop__node[data-node="board"] .mr-loop__halo { animation-delay: 1.2s; }
[data-mr="1"] .mr-loop__node[data-node="earn"]  .mr-loop__halo { animation-delay: 2.4s; }

@keyframes mr-loop-halo {
  0%, 100% { opacity: 0; transform: scale(0.85); }
  18%      { opacity: 0.7; transform: scale(1.05); }
  36%      { opacity: 0; transform: scale(1.25); }
}

[data-mr="1"] .mr-loop__circle {
  fill: rgba(15, 28, 47, 0.94);
  stroke: rgba(20, 149, 139, 0.45);
  stroke-width: 1.75;
  filter: drop-shadow(0 12px 30px rgba(0, 0, 0, 0.5));
  transition:
    stroke var(--mr-dur-medium) var(--mr-ease-soft),
    stroke-width var(--mr-dur-medium) var(--mr-ease-soft);
}

[data-mr="1"] .mr-loop__node:hover .mr-loop__circle {
  stroke: var(--mr-teal-400);
  stroke-width: 2.5;
}

[data-mr="1"] .mr-loop__icon {
  color: var(--mr-teal-400);
}

/* Phase mktloop.3 — these are USER UNITS inside a 900-unit viewBox, not
   pixels. In a ~560px column that is a 0.62 scale, so the old 14 rendered at
   8.7px and the sublabel at 7.1px. 21 and 17 bring them to roughly 13px and
   10.5px rendered — readable at the size the diagram is actually displayed.
   Sublabel opacity lifted from 0.6 to 0.72 for the same reason. */
[data-mr="1"] .mr-loop__label {
  font-family: var(--mr-font-sans);
  font-size: 21px;
  font-weight: 700;
  letter-spacing: 0.18em;
  fill: var(--mr-white);
}

[data-mr="1"] .mr-loop__sublabel {
  font-family: var(--mr-font-sans);
  font-size: 17px;
  font-weight: 500;
  fill: rgba(255, 255, 255, 0.72);
  letter-spacing: 0.03em;
}

[data-mr="1"] .mr-loop__chip rect {
  fill: rgba(15, 28, 47, 0.88);
  stroke: rgba(20, 149, 139, 0.38);
  stroke-width: 1;
}

[data-mr="1"] .mr-loop__chip text {
  font-family: var(--mr-font-sans);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.08em;
  fill: var(--mr-teal-400);
  text-transform: uppercase;
}

[data-mr="1"] .mr-loop__chip--return text {
  fill: rgba(20, 149, 139, 0.7);
}

@media (max-width: 1024px) {
  [data-mr="1"] .mr-loop {
    aspect-ratio: 900 / 500;
  }
}

/* PINNED node styling. */
[data-mr="1"] .mr-loop__node--pinned .mr-loop__circle {
  stroke: var(--mr-teal-400);
  stroke-width: 2.5;
  fill: rgba(18, 58, 94, 0.92);
}

[data-mr="1"] .mr-loop__node--pinned .mr-loop__halo {
  opacity: 1;
  animation-play-state: paused;
  transform: scale(1.15);
}

/* OVERLAY panel — slides in from right on the loop hover/pin.
 * The host fills the loop container; the overlay also fills it
 * (pointer-events: none on the wrapper, auto on the panel) so
 * the panel's right/bottom positioning + width is well-defined. */
[data-mr="1"] .mr-loop__react-host {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

[data-mr="1"] .mr-loop__overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  /* Children control their own pointer-events. */
}

[data-mr="1"] .mr-loop__hint {
  position: absolute;
  bottom: 0;
  left: 2%;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.68);
  padding: 6px 12px;
  background: rgba(11, 31, 51, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--mr-radius-pill);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  pointer-events: none;
  /* Phase mktloop.3 — the infinite fade dropped the hint to 2.07:1 at its
     trough. Static now: it is instructions, not decoration. */
}

@keyframes mr-loop-hint-fade {
  0%, 100% { opacity: 0.6; }
  50%      { opacity: 1; }
}

/* Phase mktloop.1 — the legend is the keyboard route to the ten module links
   (see the note in loop-diagram.ejs). It is sr-only until something inside it
   takes focus, at which point it becomes a normal visible list: tabbing into a
   control you cannot see is its own accessibility failure, and this is the
   only way to reach these links without a mouse.

   The !important flags mirror .mr-sr-only's own, which it needs to beat. */
[data-mr="1"] .mr-loop__legend:focus-within {
  position: static !important;
  width: auto !important;
  height: auto !important;
  margin: var(--mr-space-4) 0 0 !important;
  padding: var(--mr-space-4) var(--mr-space-5) !important;
  overflow: visible !important;
  clip: auto !important;
  white-space: normal !important;
  background: rgba(15, 28, 47, 0.94);
  border: 1px solid rgba(20, 149, 139, 0.32) !important;
  border-radius: var(--mr-radius-md);
  color: var(--mr-text-on-dark);
  font-size: 14px;
  line-height: 1.7;
  list-style: decimal;
  padding-left: 34px !important;
}

[data-mr="1"] .mr-loop__legend:focus-within a {
  color: var(--mr-blue-300);
  text-decoration: underline;
}

[data-mr="1"] .mr-loop__legend a:focus-visible {
  outline: 2px solid var(--mr-blue-300);
  outline-offset: 2px;
  border-radius: 2px;
}

[data-mr="1"] .mr-loop__panel {
  position: absolute;
  bottom: 4%;
  right: 4%;
  width: 320px;
  max-width: calc(100% - 32px);
  padding: 20px 22px 16px;
  background: rgba(15, 28, 47, 0.94);
  border: 1px solid rgba(20, 149, 139, 0.32);
  border-radius: var(--mr-radius-lg);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  box-shadow:
    0 30px 70px rgba(5, 12, 22, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  pointer-events: auto;
  animation: mr-loop-panel-in 280ms cubic-bezier(0.16, 1, 0.3, 1);
}

[data-mr="1"] .mr-loop__panel::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 14%;
  right: 14%;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(20, 149, 139, 0.7) 50%,
    transparent 100%
  );
}

@keyframes mr-loop-panel-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

[data-mr="1"] .mr-loop__panel-eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--mr-teal-400);
  margin-bottom: 8px;
}

[data-mr="1"] .mr-loop__panel-blurb {
  font-size: 13px;
  line-height: 1.55;
  color: rgba(255, 255, 255, 0.78);
  margin: 0 0 14px 0;
}

[data-mr="1"] .mr-loop__panel-modules {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

[data-mr="1"] .mr-loop__panel-module {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--mr-radius-sm);
  text-decoration: none;
  transition:
    background-color 180ms cubic-bezier(0.4, 0, 0.2, 1),
    border-color 180ms cubic-bezier(0.4, 0, 0.2, 1),
    transform 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

[data-mr="1"] .mr-loop__panel-module:hover {
  background: rgba(20, 149, 139, 0.12);
  border-color: rgba(20, 149, 139, 0.35);
  transform: translateX(2px);
}

[data-mr="1"] .mr-loop__panel-module-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--mr-white);
  letter-spacing: -0.005em;
}

[data-mr="1"] .mr-loop__panel-module-desc {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.6);
  line-height: 1.4;
}

[data-mr="1"] .mr-loop__panel-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: transparent;
  border: 0;
  font-size: 22px;
  line-height: 1;
  color: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--mr-radius-sm);
  transition: color 180ms cubic-bezier(0.4, 0, 0.2, 1), background-color 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

[data-mr="1"] .mr-loop__panel-close:hover {
  color: var(--mr-white);
  background-color: rgba(255, 255, 255, 0.06);
}

[data-mr="1"] .mr-loop__panel-hint {
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.4);
  margin: 12px 0 0 0;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 500;
}

@media (max-width: 1024px) {
  [data-mr="1"] .mr-loop__panel {
    bottom: 4%;
    right: 4%;
    width: min(320px, calc(100% - 32px));
  }
}

@media (max-width: 600px) {
  [data-mr="1"] .mr-loop__panel {
    bottom: 8px;
    right: 8px;
    left: 8px;
    width: auto;
    max-width: none;
    padding: 14px 14px 12px;
  }
  [data-mr="1"] .mr-loop__panel-modules {
    max-height: 140px;
    overflow-y: auto;
  }
  [data-mr="1"] .mr-loop__hint {
    bottom: 8px;
    right: 8px;
    font-size: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  [data-mr="1"] .mr-loop__panel { animation: none; }
  [data-mr="1"] .mr-loop__hint { animation: none; opacity: 0.8; }
}

/* ===========================================================================
   Phase mktloop.3 — the stacked view, and readable labels.

   Two separate problems on the same component:

   1. SIZE. The diagram is drawn in a 900-unit viewBox and its labels are set
      in USER UNITS, so they shrink with the container: 14 units renders at
      ~8.7px in a 560px column on desktop and under 5px on a phone. Raising
      the user-unit sizes below brings desktop to roughly 13px.

   2. TOUCH. The module links lived behind hover, which does not exist on a
      phone. Below 900px the SVG is replaced by the stacked list, where every
      link is simply a link.
   =========================================================================== */

/* --- Stacked list: hidden on desktop, where it is the keyboard/SR route --- */
[data-mr="1"] .mr-loop__steps {
  display: none;
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: mr-loop-step;
}

[data-mr="1"] .mr-loop__step {
  counter-increment: mr-loop-step;
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--mr-space-4);
  padding: var(--mr-space-4) var(--mr-space-4) var(--mr-space-4) var(--mr-space-3);
}

/* The connecting spine — carries the "loop" idea without needing the SVG. */
[data-mr="1"] .mr-loop__step:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 31px;
  top: 52px;
  bottom: -4px;
  width: 1px;
  background: linear-gradient(180deg, rgba(20, 149, 139, 0.45), rgba(20, 149, 139, 0.10));
}

[data-mr="1"] .mr-loop__step-icon {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--mr-radius-md);
  background: rgba(20, 149, 139, 0.12);
  border: 1px solid rgba(20, 149, 139, 0.28);
  color: var(--mr-blue-300);
}

[data-mr="1"] .mr-loop__step-body {
  min-width: 0;
  padding-top: 2px;
}

[data-mr="1"] .mr-loop__step-name {
  margin: 0 0 2px;
  font-size: 11px;
  font-weight: var(--mr-fw-semi);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.62);   /* 7.09:1 on the navy */
}

[data-mr="1"] .mr-loop__step-links {
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.35);   /* only the separators */
}

[data-mr="1"] .mr-loop__step-links a {
  color: rgba(255, 255, 255, 0.92);   /* ~14:1 */
  font-weight: var(--mr-fw-medium);
  text-decoration: none;
  /* WCAG 2.5.8: 15px text at 1.5 line-height gives a 22px line box, so pad to
     clear the 24px minimum target on touch. */
  display: inline-block;
  padding: 2px 0;
}

[data-mr="1"] .mr-loop__step-links a:hover,
[data-mr="1"] .mr-loop__step-links a:focus-visible {
  color: var(--mr-blue-300);
  text-decoration: underline;
}

/* --- Below 900px: stack replaces the diagram outright --- */
@media (max-width: 900px) {
  [data-mr="1"] .mr-loop__svg,
  [data-mr="1"] .mr-loop__react-host {
    display: none;
  }

  [data-mr="1"] .mr-loop__steps {
    display: block;
  }

  /* The legend is the desktop keyboard route; the stack supersedes it here. */
  [data-mr="1"] .mr-loop__legend {
    display: none;
  }
}

/* The container is aspect-ratio locked to the SVG's 900:620. With the SVG
   hidden below 900px that would reserve a tall empty box above the stack, so
   release it — and drop the drop-shadow, which exists to lift the diagram off
   the navy and does nothing for a list. */
@media (max-width: 900px) {
  [data-mr="1"] .mr-loop {
    aspect-ratio: auto;
    filter: none;
  }
}
