/* --------------------------------------------------------------------------
   The turn, told simply — You → Nura → the specialists → Answer
   (views/story.js, 2026-10-15)

   For an operator who is not technical: four steps that never grow wider,
   each specialist a card in its module's colour saying what it does now.
   What is working glows; Nura's light breathes while Nura thinks, and a card's
   icon while it looks at what it found. Under the answer, the line that
   opens to the diagram above names who worked on it.
   -------------------------------------------------------------------------- */

.story {
  position: relative;
  margin-top: 12px;
  padding: 18px 16px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-raised);
}

.story[hidden] { display: none; }

.story-clock {
  position: absolute;
  top: 7px;
  right: 12px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
}

.story-row {
  display: flex;
  align-items: center;
  margin: 0;
  padding: 0;
  list-style: none;
}

.story-stage,
.story-card,
.story-waiting {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: border-color .25s, box-shadow .25s, opacity .25s;
}

/* The steps either side hug their words, up to a point; the specialists keep
   room enough to say what they are doing on a line or two. */
.story-stage { flex: 0 1 auto; max-width: 180px; }

/* The specialists take what width there is; the others hug their words. */
.story-stage.is-team {
  flex: 1 1 240px;
  max-width: none;
  min-width: 220px;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
}

.story-stage[hidden] { display: none; }

.story-pic {
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-sunken);
  color: var(--text-muted);
}

.is-nura .story-pic { background: none; }
.is-answer .story-pic { background: var(--accent-soft); color: var(--accent); }

.story-words {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.35;
}

.story-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-strong);
}

.story-status {
  font-size: 12.5px;
  color: var(--text-muted);
}

.story-count {
  font-size: 11.5px;
  color: var(--text-faint);
}

.story-count:empty { display: none; }

.is-you .story-status, .is-answer .story-status { white-space: nowrap; }
.is-answer.is-done .story-status { color: var(--pos); font-weight: 600; }
.is-answer.is-failed .story-status { color: var(--neg); font-weight: 600; }

/* The specialists, stacked: two cards is two specialists working. */
.story-team {
  display: flex;
  flex-direction: column;
  width: 100%;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.story-card {
  border-left: 3px solid color-mix(in srgb, var(--hue) 70%, transparent);
  animation: story-join .35s var(--ease-out) both;
}

.story-card .story-pic {
  background: color-mix(in srgb, var(--hue) 13%, var(--surface));
  color: var(--hue);
}

.story-waiting {
  border-style: dashed;
  box-shadow: none;
  font-size: 12.5px;
  color: var(--text-faint);
}

/* Working: a soft glow in the step's own colour. */
.story-stage.is-active,
.story-card.is-active {
  border-color: color-mix(in srgb, var(--hue, var(--accent)) 45%, var(--border));
  animation: story-join .35s var(--ease-out) both, story-glow 1.8s ease-in-out .35s infinite;
}

.story-card.is-thinking .story-pic { animation: story-breathe 1.6s ease-in-out infinite; }
.is-nura.is-active .nura-light { animation: nura-breathe 1.6s ease-in-out infinite; }
.is-nura.is-active .nura-glow { animation: nura-halo 1.6s ease-in-out infinite; }

/* The arrows between steps; the one into what is working moves. */
.story-link {
  position: relative;
  flex: 0 0 26px;
  height: 2px;
  margin: 0 2px;
  background: var(--border-strong);
}

.story-link::after {
  content: "";
  position: absolute;
  right: -1px;
  top: -3px;
  border: 4px solid transparent;
  border-left-color: var(--border-strong);
  border-right: 0;
}

.story:not(.is-still) .story-link:has(+ .is-active),
.story:not(.is-still) .story-link:has(+ .is-team .is-active) {
  background: repeating-linear-gradient(to right, var(--accent) 0 4px, transparent 4px 8px);
  background-size: 8px 2px;
  animation: flow-move .5s linear infinite;
}

.story.is-still .story-stage,
.story.is-still .story-card { animation: none; }

@keyframes story-join {
  from { opacity: 0; transform: translateY(4px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

@keyframes story-glow {
  0%, 100% { box-shadow: var(--shadow-sm), 0 0 0 0 color-mix(in srgb, var(--hue, var(--accent)) 0%, transparent); }
  50%      { box-shadow: var(--shadow-sm), 0 0 0 4px color-mix(in srgb, var(--hue, var(--accent)) 18%, transparent); }
}

@keyframes story-breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(.88); }
}

/* Folded under an answer: who worked on it, how much, how long. */
.story-icons { display: inline-flex; }

.story-icons i {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-right: -3px;
  border: 2px solid var(--page-bg);
  border-radius: 50%;
  background: color-mix(in srgb, var(--hue) 16%, var(--surface));
  color: var(--hue);
}

.story-icons:not(:empty) { margin-right: 6px; }

/* A phone: the same story, top to bottom. */
@media (max-width: 600px) {
  .story-row { flex-direction: column; align-items: stretch; }
  .story-stage, .story-stage.is-team { max-width: none; min-width: 0; flex: none; }
  .story-link { flex: 0 0 14px; width: 2px; height: auto; margin: 2px 0 2px 27px; }
  .story-link::after { top: auto; bottom: -1px; right: -3px; border: 4px solid transparent; border-top-color: var(--border-strong); border-bottom: 0; }
  .story:not(.is-still) .story-link:has(+ .is-active),
  .story:not(.is-still) .story-link:has(+ .is-team .is-active) {
    background: repeating-linear-gradient(to bottom, var(--accent) 0 4px, transparent 4px 8px);
    background-size: 2px 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .story-card, .story-stage.is-active, .story-card.is-active,
  .story-card.is-thinking .story-pic, .is-nura.is-active .nura-light, .is-nura.is-active .nura-glow,
  .story-link { animation: none !important; }
}
