/* Flow simulator widget — one .flow-widget per flow, embedded inline in the
   chapter. All rules are scoped under .flow-widget so they never leak into
   the surrounding MkDocs Material page. */

.flow-widget {
  --fs-ink: #000;
  --fs-paper: #fff;
  --fs-line: #000;
  --fs-muted: #888;
  --fs-dim: #cfcfcf;
  --fs-hair: #e6e6e6;
  --fs-font-hand: "Kalam", "Comic Sans MS", "Segoe Print", cursive;
  --fs-font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --fs-scale: 1;

  display: grid;
  grid-template-rows: auto auto 1fr auto;
  grid-template-columns: 1fr;
  position: relative;
  isolation: isolate;
  width: 100%;
  height: 560px;
  border: 1px solid var(--fs-hair);
  background: var(--fs-paper);
  color: var(--fs-ink);
  font-family: var(--fs-font-body);
  margin: 1.5em 0;
  outline: none;
}
.flow-widget:focus { border-color: var(--fs-ink); }

.flow-widget * { box-sizing: border-box; }

/* Modal overlay: fullscreen zoom of a flow */
.flow-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 20, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 3vh 3vw;
  animation: fs-fade-in 0.2s ease;
}
@keyframes fs-fade-in { from { opacity: 0; } to { opacity: 1; } }

.flow-modal {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 1400px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: fs-modal-in 0.22s ease;
}
@keyframes fs-modal-in {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

.flow-modal-close {
  position: absolute;
  top: 16px;
  right: 18px;
  z-index: 10;
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--fs-hair, #e6e6e6);
  background: #fff;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  font-family: inherit;
  color: #000;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.06s ease;
}
.flow-modal-close:hover { background: #000; color: #fff; border-color: #000; }
.flow-modal-close:active { transform: scale(0.94); }

.flow-widget.flow-modal-stage {
  height: 100%;
  width: 100%;
  margin: 0;
  border: none;
  border-radius: 0;
}

/* Loader shown while YAML is being fetched */
.flow-widget .flow-loader {
  grid-row: 1 / -1;
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  height: 100%;
  width: 100%;
  color: var(--fs-muted);
  font-family: var(--fs-font-body);
  font-size: 13px;
}
.flow-widget .flow-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--fs-hair);
  border-top-color: var(--fs-ink);
  border-radius: 50%;
  animation: fs-spin 0.8s linear infinite;
}
@keyframes fs-spin { to { transform: rotate(360deg); } }
.flow-widget .flow-loader-text {
  letter-spacing: 0.02em;
}
.flow-widget .flow-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 10px 18px;
  min-height: 48px;
  border-bottom: 1px solid var(--fs-hair);
  background: var(--fs-paper);
}
.flow-widget .flow-nav .nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border: 1.5px solid var(--fs-ink);
  border-radius: 999px;
  background: var(--fs-paper);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  font-family: var(--fs-font-body);
  color: var(--fs-ink);
  transition: background 0.12s ease, color 0.12s ease, transform 0.06s ease;
}
.flow-widget .flow-nav .nav-btn:hover { background: var(--fs-ink); color: var(--fs-paper); }
.flow-widget .flow-nav .nav-btn:active { transform: translateY(1px); }
.flow-widget .flow-nav .nav-btn[disabled],
.flow-widget .flow-nav .nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.flow-widget .flow-nav .nav-btn[disabled]:hover,
.flow-widget .flow-nav .nav-btn:disabled:hover {
  background: var(--fs-paper);
  color: var(--fs-ink);
}
.flow-widget .flow-nav .steps { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.flow-widget .flow-nav .prev-btn,
.flow-widget .flow-nav .next-btn { margin: 0; }
.flow-widget .flow-nav .step {
  min-width: 30px; height: 30px; padding: 0 9px; border-radius: 999px;
  border: 1.5px solid var(--fs-dim);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; cursor: pointer; background: var(--fs-paper);
  font-family: var(--fs-font-body);
  font-weight: 500;
  color: var(--fs-muted);
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.flow-widget .flow-nav .step:hover { border-color: var(--fs-ink); color: var(--fs-ink); }
.flow-widget .flow-nav .step.done {
  border-color: var(--fs-ink);
  color: var(--fs-ink);
  background: var(--fs-paper);
}
.flow-widget .flow-nav .step.goal {
  padding: 0 12px;
  border-width: 2px;
  border-color: var(--fs-ink);
  color: var(--fs-ink);
  font-weight: 600;
}
.flow-widget .flow-nav .step.current {
  background: var(--fs-ink);
  color: var(--fs-paper);
  border-color: var(--fs-ink);
  box-shadow: none;
}
.flow-widget .flow-nav .step.current.goal {
  border-width: 2px;
}
.flow-widget .flow-nav .step-ellipsis {
  min-width: 16px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--fs-font-body);
  font-size: 14px;
  color: var(--fs-ink);
  opacity: 0.4;
  user-select: none;
  letter-spacing: 1px;
}

.flow-widget .caption-line {
  padding: calc(8px * var(--fs-scale)) calc(16px * var(--fs-scale));
  font-family: var(--fs-font-body);
  font-size: calc(14px * var(--fs-scale));
  border-bottom: 1px solid var(--fs-hair);
  color: var(--fs-ink);
  line-height: 1.4;
  letter-spacing: 0.01em;
}
.flow-modal-header {
  padding: 20px 72px 14px 28px;
  border-bottom: 1px solid var(--fs-hair);
  background: var(--fs-paper, #fff);
}
.flow-modal-title {
  font-family: var(--fs-font-body);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--fs-ink);
  letter-spacing: -0.01em;
}
.flow-widget.flow-modal-stage .caption-line {
  padding: 10px 28px;
  font-size: 13.5px;
  color: var(--fs-ink);
  opacity: 0.7;
  letter-spacing: 0.01em;
}
.flow-widget .canvas {
  position: relative;
  overflow: hidden;
  background: var(--fs-paper);
}
.flow-widget .banner-line {
  position: absolute;
  top: 14px;
  left: 24px;
  right: 24px;
  width: auto;
  text-align: left;
  padding: 8px 12px;
  background: var(--fs-paper);
  border: 1.5px solid var(--fs-ink);
  font-family: var(--fs-font-body);
  font-size: 12px;
  line-height: 1.45;
  letter-spacing: 0.005em;
  white-space: pre-line;
  box-shadow: 3px 3px 0 var(--fs-ink);
  z-index: 3;
  color: var(--fs-ink);
}
.flow-widget .canvas.narrative-step .banner-line {
  padding: 10px 14px;
  font-size: 12.5px;
  line-height: 1.5;
  box-shadow: 4px 4px 0 var(--fs-ink);
}
.flow-widget.flow-modal-stage .canvas.narrative-step .banner-line {
  font-size: 13px;
  padding: 12px 18px;
  line-height: 1.5;
}
.flow-widget .step-details {
  position: absolute;
  top: calc(10px * var(--fs-scale));
  left: 50%;
  transform: translateX(-50%);
  width: fit-content;
  max-width: calc(100% - 64px);
  text-align: left;
  padding: calc(7px * var(--fs-scale)) calc(14px * var(--fs-scale));
  background: #fafafa;
  border: 1px dashed var(--fs-ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: calc(8px * var(--fs-scale));
  line-height: 1.35;
  color: #333;
  white-space: pre;
  overflow-x: auto;
  z-index: 2;
}

/* Actors */
.flow-widget .actor {
  position: absolute;
  width: calc(110px * var(--fs-scale));
  display: flex; flex-direction: column; align-items: center; gap: calc(4px * var(--fs-scale));
  transition: opacity 0.3s ease;
  cursor: help;
}
.flow-widget .actor .glyph {
  width: calc(56px * var(--fs-scale)); height: calc(56px * var(--fs-scale));
  display: flex; align-items: center; justify-content: center;
  color: var(--fs-ink);
}
.flow-widget .actor .glyph svg { width: calc(48px * var(--fs-scale)); height: calc(48px * var(--fs-scale)); }
.flow-widget .actor .glyph.avatar {
  width: calc(80px * var(--fs-scale)); height: calc(80px * var(--fs-scale));
}
.flow-widget .actor .glyph.avatar img {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
}
.flow-widget .actor .label {
  font-family: var(--fs-font-body);
  font-size: calc(14px * var(--fs-scale));
  text-align: center;
  line-height: 1.1;
  color: var(--fs-ink);
}
.flow-widget .actor .label .sub { font-size: calc(11px * var(--fs-scale)); color: var(--fs-muted); }
.flow-widget .actor.dim { opacity: 0.22; }

/* Arrows */
.flow-widget svg.arrows {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
}
.flow-widget svg.arrows .arrow-path { fill: none; stroke: var(--fs-ink); stroke-width: 1.6; }
.flow-widget svg.arrows .arrow-past { stroke: var(--fs-ink); opacity: 0.35; stroke-dasharray: 4 3; }
.flow-widget svg.arrows .arrow-active { stroke: var(--fs-ink); stroke-width: 2; stroke-dasharray: 6 3; animation: fs-dash 0.9s linear infinite; }
.flow-widget svg.arrows .arrow-head { fill: var(--fs-ink); stroke: none; }
.flow-widget svg.arrows .arrow-head-past { opacity: 0.35; }
@keyframes fs-dash { to { stroke-dashoffset: -18; } }

.flow-widget .arrow-label {
  position: absolute;
  background: var(--fs-paper);
  border: 1px solid var(--fs-ink);
  padding: calc(2px * var(--fs-scale)) calc(8px * var(--fs-scale)) calc(3px * var(--fs-scale)) calc(8px * var(--fs-scale));
  font-family: var(--fs-font-body);
  font-size: calc(13px * var(--fs-scale));
  line-height: 1.25;
  border-radius: 2px;
  max-width: calc(460px * var(--fs-scale));
  text-align: center;
  overflow-wrap: anywhere;
  box-shadow: 1.5px 1.5px 0 var(--fs-ink);
  pointer-events: none;
  color: var(--fs-ink);
  z-index: 4;
}
.flow-widget .arrow-label.past { opacity: 0.45; box-shadow: 1px 1px 0 var(--fs-ink); }
.flow-widget .arrow-label .num {
  display: inline-block; margin-right: calc(6px * var(--fs-scale));
  width: calc(18px * var(--fs-scale)); height: calc(18px * var(--fs-scale));
  line-height: calc(17px * var(--fs-scale)); text-align: center;
  background: var(--fs-ink); color: var(--fs-paper);
  border-radius: 50%; font-size: calc(11px * var(--fs-scale)); font-weight: 700;
  font-family: var(--fs-font-body);
  vertical-align: middle;
}

/* Issues banner: black strip at the bottom, listing step-specific problems.
   Black-and-white on purpose — matches the rest of the widget. */
.flow-widget .issues-banner {
  background: var(--fs-ink);
  color: var(--fs-paper);
  padding: calc(5px * var(--fs-scale)) calc(14px * var(--fs-scale)) calc(6px * var(--fs-scale)) calc(14px * var(--fs-scale));
  border-top: 1.5px solid var(--fs-ink);
  font-family: var(--fs-font-body);
  font-size: calc(11px * var(--fs-scale));
  line-height: 1.35;
  display: flex;
  flex-direction: column;
  gap: calc(2px * var(--fs-scale));
}
.flow-widget .issues-banner .issues-title {
  font-family: var(--fs-font-body);
  font-size: calc(12px * var(--fs-scale));
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: calc(6px * var(--fs-scale));
  opacity: 0.85;
}
.flow-widget .issues-banner .issues-title::before {
  content: "⚠";
  font-family: var(--fs-font-body);
  font-size: calc(12px * var(--fs-scale));
}
.flow-widget .issues-banner ul {
  margin: 0;
  padding-left: calc(16px * var(--fs-scale));
  list-style: none;
  font-size: calc(11px * var(--fs-scale));
  line-height: 1.35;
  color: var(--fs-paper);
}
.flow-widget .issues-banner li {
  position: relative;
  padding-left: calc(2px * var(--fs-scale));
  font-size: calc(11px * var(--fs-scale));
  line-height: 1.35;
  margin: 0;
  color: var(--fs-paper);
}
.flow-widget .issues-banner li + li {
  margin-top: calc(2px * var(--fs-scale));
}
.flow-widget .issues-banner li::before {
  content: "•";
  position: absolute;
  left: calc(-10px * var(--fs-scale));
  color: var(--fs-paper);
}

.flow-widget .note-bubble {
  position: absolute;
  width: calc(160px * var(--fs-scale));
  background: var(--fs-paper);
  border: 1.5px solid var(--fs-ink);
  padding: calc(8px * var(--fs-scale)) calc(10px * var(--fs-scale));
  font-family: var(--fs-font-body);
  font-size: calc(12px * var(--fs-scale));
  line-height: 1.3;
  box-shadow: 2px 2px 0 var(--fs-ink);
  border-radius: 3px;
  z-index: 5;
  text-align: center;
  color: var(--fs-ink);
}
.flow-widget .note-bubble .tail {
  position: absolute;
  top: -8px; left: 50%; transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 8px solid var(--fs-ink);
}
.flow-widget .note-bubble .tail::after {
  content: "";
  position: absolute;
  top: 2px; left: -6px;
  width: 0; height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 7px solid var(--fs-paper);
}
.flow-widget .note-bubble.note-above .tail {
  top: auto; bottom: -8px;
  border-bottom: none;
  border-top: 8px solid var(--fs-ink);
}
.flow-widget .note-bubble.note-above .tail::after {
  top: auto; bottom: 2px;
  border-bottom: none;
  border-top: 7px solid var(--fs-paper);
}
.flow-widget.flow-modal-stage .note-bubble {
  font-size: calc(10.5px * var(--fs-scale));
}

.flow-widget .weakness-btn {
  position: absolute;
  bottom: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1.5px solid var(--fs-ink);
  border-radius: 999px;
  background: var(--fs-paper);
  color: var(--fs-ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 6;
  transition: background 0.12s ease, color 0.12s ease;
}
.flow-widget .weakness-btn:hover {
  background: var(--fs-ink);
  color: var(--fs-paper);
}
.flow-widget .weakness-btn svg {
  width: 62%;
  height: 62%;
}
.flow-widget .weakness-panel {
  display: none;
  position: absolute;
  bottom: 48px;
  right: 10px;
  width: min(340px, calc(100% - 40px));
  background: var(--fs-paper);
  border: 1.5px solid var(--fs-ink);
  border-radius: 3px;
  box-shadow: 3px 3px 0 var(--fs-ink);
  padding: 12px 14px 14px;
  z-index: 7;
  font-family: var(--fs-font-body);
  color: var(--fs-ink);
  text-align: left;
}
.flow-widget .weakness-panel.open { display: block; }
.flow-widget .weakness-panel .weakness-title {
  font-weight: 600;
  font-size: 12.5px !important;
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}
.flow-widget .weakness-panel ul {
  margin: 0 !important;
  padding-left: 18px !important;
  font-size: 11.5px !important;
  line-height: 1.45 !important;
  list-style: disc !important;
}
.flow-widget .weakness-panel li {
  font-size: 11.5px !important;
  line-height: 1.45 !important;
  margin: 0 0 5px !important;
}
.flow-widget .weakness-panel li:last-child { margin-bottom: 0 !important; }
