/* ==========================================================================
   loop.css — THE SIGNATURE.

   One unbroken stroke carrying four stations. It draws itself the first time
   it is seen, then a travelling arc runs the circuit forever while the centre
   reports whichever station is currently live. This is the "fully integrated
   ecosystem" claim rendered as a single continuous line.
   ========================================================================== */

.loop {
  position: relative;
  display: grid;
  gap: clamp(2.5rem, 6vw, 4rem);
  justify-items: center;
}

@media (min-width: 1060px) {
  .loop {
    grid-template-columns: minmax(0, 1fr) minmax(0, 0.82fr);
    align-items: center;
    gap: clamp(3rem, 6vw, 6rem);
  }
}

/* --- The ring ------------------------------------------------------------- */

.loop__stage {
  position: relative;
  width: min(100%, 560px);
  aspect-ratio: 1;
}

.loop__svg { width: 100%; height: 100%; overflow: visible; }

.loop__track {
  fill: none;
  stroke: var(--line);
  stroke-width: 1;
}

.loop__path {
  fill: none;
  stroke: url(#loopGradient);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: var(--len, 942px) var(--len, 942px);
  stroke-dashoffset: var(--len, 942px);
  transition: stroke-dashoffset 2200ms var(--e-out);
}
.loop.is-drawn .loop__path { stroke-dashoffset: 0; }

/* The travelling comet — a short dash chasing the circuit. */
.loop__comet {
  fill: none;
  stroke: var(--c-kunyit);
  stroke-width: 3;
  stroke-linecap: round;
  opacity: 0;
  /* A short dash chasing a gap the length of the whole ring. */
  stroke-dasharray: 34px calc(var(--len, 942px) - 34px);
  filter: drop-shadow(0 0 5px rgba(217, 149, 39, 0.55));
  transition: opacity 600ms var(--e-out) 1600ms;
}
.loop.is-drawn .loop__comet {
  opacity: 1;
  animation: comet-run 14s linear infinite;
}
@keyframes comet-run {
  from { stroke-dashoffset: 0; }
  to   { stroke-dashoffset: calc(var(--len, 942px) * -1); }
}

.loop__spoke {
  stroke: var(--line);
  stroke-width: 1;
  stroke-dasharray: 2 5;
  opacity: 0.7;
}

/* --- Stations ------------------------------------------------------------- */

.loop__node {
  position: absolute;
  /* --x / --y are percentages of the square stage, so the stations stay on
     the ring at every viewport width without any JS measurement. */
  left: calc(50% + var(--x, 0%));
  top: calc(50% + var(--y, 0%));
  width: clamp(74px, 14vw, 112px);
  height: clamp(74px, 14vw, 112px);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--c-night-2);
  border: 1px solid var(--line);
  color: var(--fg);
  transition: border-color var(--d-mid) var(--e-out), background var(--d-mid) var(--e-out), box-shadow var(--d-mid) var(--e-out);
}

.loop__node img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
  opacity: 0.5;
  transition: opacity var(--d-mid) var(--e-out), transform var(--d-slow) var(--e-out);
}

.loop__node-mark {
  width: 44%; height: 44%;
  object-fit: contain;
  opacity: 0.6;
  border-radius: 0;
}

.loop__node-label {
  position: absolute;
  top: calc(100% + 0.7rem);
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--f-mono);
  font-size: 0.58rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--fg-faint);
  /* A sliver of background so the label reads cleanly where it crosses
     the ring stroke. */
  background: var(--c-night);
  padding-inline: 0.4rem;
  transition: color var(--d-mid) var(--e-out);
}

.loop__node:hover img { opacity: 0.85; }

.loop__node.is-live {
  border-color: var(--node-accent);
  box-shadow:
    0 0 0 1px var(--node-accent),
    0 0 26px -10px color-mix(in srgb, var(--node-accent) 60%, transparent);
}
.loop__node.is-live img { opacity: 1; transform: scale(1.06); }
.loop__node.is-live .loop__node-label { color: var(--node-accent); }

/* The halo that fires when a station becomes live. */
.loop__node::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  border: 1px solid var(--node-accent);
  opacity: 0;
}
.loop__node.is-live::after { animation: pulse-ring 1.8s var(--e-out); }

/* --- Centre readout ------------------------------------------------------- */

.loop__hub {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 46%;
  text-align: center;
  display: grid;
  gap: var(--s-2);
  pointer-events: none;
}

.loop__hub-no {
  font-family: var(--f-mono);
  font-size: 0.62rem;
  letter-spacing: 0.24em;
  color: var(--fg-faint);
}

.loop__hub-title {
  font-family: var(--f-display);
  font-size: clamp(1.15rem, 3vw, 1.6rem);
  font-weight: 300;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.loop__hub-owner {
  font-family: var(--f-mono);
  font-size: 0.56rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--hub-accent, var(--c-kunyit));
}

.loop__hub.is-swapping { opacity: 0; transform: translate(-50%, -50%) scale(0.96); }
.loop__hub { transition: opacity 260ms var(--e-out), transform 260ms var(--e-out); }

/* --- Side panel ----------------------------------------------------------- */

.loop__panel { display: grid; gap: var(--s-5); max-width: 44ch; width: 100%; }

.loop__steps { display: grid; }

.loop__step {
  display: grid;
  grid-template-columns: 2.2rem minmax(0, 1fr);
  gap: var(--s-4);
  align-items: start;
  width: 100%;
  text-align: left;
  padding-block: var(--s-4);
  border-top: 1px solid var(--line);
  opacity: 0.55;
  transition: opacity var(--d-mid) var(--e-out), padding-left var(--d-mid) var(--e-out);
}
.loop__step:last-child { border-bottom: 1px solid var(--line); }
.loop__step:hover { opacity: 0.85; padding-left: var(--s-2); }

.loop__step.is-live { opacity: 1; padding-left: var(--s-3); }

.loop__step-no {
  font-family: var(--f-mono);
  font-size: 0.68rem;
  color: var(--fg-faint);
  padding-top: 0.3rem;
}
.loop__step.is-live .loop__step-no { color: var(--step-accent); }

.loop__step-title {
  font-size: var(--fs-lg);
  font-weight: 300;
  line-height: 1.2;
}
.loop__step.is-live .loop__step-title { color: var(--step-accent); }

.loop__step-owner {
  display: block;
  font-family: var(--f-mono);
  font-size: 0.58rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--fg-faint);
  margin-top: 0.35rem;
}

.loop__step-body {
  font-size: var(--fs-sm);
  color: var(--fg-dim);
  margin-top: 0.5rem;
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--d-slow) var(--e-out), margin var(--d-slow) var(--e-out);
}
.loop__step-body > span { overflow: hidden; }
.loop__step.is-live .loop__step-body { grid-template-rows: 1fr; }

.loop__hint {
  font-family: var(--f-mono);
  font-size: 0.6rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--fg-faint);
  display: flex;
  align-items: center;
  gap: var(--s-3);
}
.loop__hint i {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--c-kunyit);
  animation: blink-caret 2s steps(1) infinite;
}

/* --- Narrow screens ------------------------------------------------------
   On phones the ring is small enough that the per-node labels crowd the
   stroke and clip at the stage edges. The numbered panel steps below already
   name every station, so the labels are redundant here — drop them, pull the
   nodes in a touch, and give the stage a little breathing room. */
@media (max-width: 620px) {
  .loop__stage { width: min(88%, 400px); }

  .loop__node {
    width: clamp(66px, 21vw, 92px);
    height: clamp(66px, 21vw, 92px);
  }

  /* Inline style sets --x, so the pull-in needs !important to win here. */
  .loop__node[data-pos="right"] { --x: 36% !important; }
  .loop__node[data-pos="left"]  { --x: -36% !important; }

  .loop__node-label { display: none; }

  .loop__hub { width: 52%; }
}

@media (prefers-reduced-motion: reduce) {
  .loop__path { stroke-dashoffset: 0; }
  .loop__comet { display: none; }
  .loop__step-body { grid-template-rows: 1fr; }
  .loop__step { opacity: 1; }
}
