:root {
  --pen-rule: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 400 8'%3E%3Cpath d='M1 4C53 1 82 6 133 4S216 2 265 4S345 6 399 3' fill='none' stroke='black' stroke-width='1.3' stroke-linecap='round'/%3E%3C/svg%3E");
  --pen-rule-vertical: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 8 400'%3E%3Cpath d='M4 1C1 53 6 82 4 133S2 216 4 265S6 345 3 399' fill='none' stroke='black' stroke-width='1.3' stroke-linecap='round'/%3E%3C/svg%3E");
  --pen-underline: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 160 7'%3E%3Cpath d='M2 4Q44 1.8 81 3.2T158 2.7' fill='none' stroke='black' stroke-width='2.1' stroke-linecap='round'/%3E%3C/svg%3E");
  --pen-link-underline: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 160 7'%3E%3Cpath d='M2 4Q44 1.8 81 3.2T158 2.7' fill='none' stroke='%23544b89' stroke-width='2.1' stroke-linecap='round'/%3E%3C/svg%3E");
  --pen-example-underline: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio='none' viewBox='0 0 160 7'%3E%3Cpath d='M2 4Q44 1.8 81 3.2T158 2.7' fill='none' stroke='%23007579' stroke-width='2.1' stroke-linecap='round'/%3E%3C/svg%3E");
}

/* Stroke overlays replace existing outlines without changing their layout or fills. */
.sketch-frame {
  position: absolute;
  display: block;
  margin: 0;
  padding: 0;
  overflow: visible;
  pointer-events: none;
  user-select: none;
  fill: none;
  transform-origin: center;
}

.sketch-frame > path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.25px;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.sketch-frames-ready .group-outline {
  border-color: transparent;
  background: transparent;
}

.sketch-frame--group {
  color: #b8acd7;
}

.sketch-frame--group > path {
  fill: var(--agent);
  stroke-width: 1.6px;
}

.human-group > .sketch-frame--group > path {
  fill: var(--human);
}

.human-group > .sketch-frame--group {
  color: #cbb194;
}

.sketch-frames-ready .task .art,
.sketch-frames-ready .pipeline-node .art {
  position: relative;
}

.sketch-frames-ready .task.is-primary .art::before {
  border-color: transparent;
}

.sketch-frame--coding {
  z-index: -1;
  color: var(--indigo);
  opacity: 0;
  transform: scale(calc(.90 + .10 * var(--coding-emphasis, 0)));
}

.task.is-primary .sketch-frame--coding {
  opacity: var(--coding-emphasis, 0);
}

.sketch-frames-ready .pipeline-node .art,
.sketch-frames-ready .person img,
.sketch-frames-ready .role-core img,
.sketch-frames-ready .agent-core img {
  outline-color: transparent !important;
}

.sketch-frame--actor,
.sketch-frame--pipeline {
  z-index: 1;
  color: var(--indigo);
  opacity: 0;
  transition: opacity 180ms ease, color 180ms ease;
}

.sketch-frame--actor > path,
.sketch-frame--pipeline > path {
  stroke-width: 2px;
}

.pipeline-node.is-active .sketch-frame--pipeline,
.person.is-speaking > .sketch-frame--actor,
.role-core:is(.is-listening, .is-directing, .is-reviewing) > .sketch-frame--actor,
.agent-core:is(.is-receiving, .is-returning) > .sketch-frame--actor {
  opacity: 1;
}

.person.is-speaking > .sketch-frame--actor,
.role-core.is-listening > .sketch-frame--actor {
  color: var(--evidence);
}

.role-core.is-reviewing > .sketch-frame--actor,
.agent-core.is-returning > .sketch-frame--actor {
  color: var(--coral);
}

.sketch-frames-ready .priority-grid {
  background: transparent;
}

.sketch-frame--matrix {
  z-index: 1;
  color: var(--line);
}

.decision-art::after {
  width: 14px;
  height: 9px;
  margin-top: -4px;
  border: 0;
  background: var(--muted);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 9'%3E%3Cpath d='M1 4.5Q6 3.7 12 4.6M8.7 1.3Q10 3 12 4.6Q10.5 6.2 8.5 7.4' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 9'%3E%3Cpath d='M1 4.5Q6 3.7 12 4.6M8.7 1.3Q10 3 12 4.6Q10.5 6.2 8.5 7.4' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}

.decisions-animated .decision-art::after {
  border: 0;
  background: var(--decision-accent);
}

.decisions-animated .decision-art::before {
  content: none;
}

@media (prefers-reduced-motion: reduce) {
  .sketch-frame {
    transition: none;
  }
}

/* Underlines use the headline stroke while retaining the controls' existing size. */
.observation-controls button,
.flow-replay,
.begin,
.text-link,
.transcript-credit a,
.priority-source a {
  position: relative;
  text-decoration: none;
}

.observation-controls button,
.observation-controls button[aria-pressed="true"],
.observation-controls button:hover,
.begin {
  border-bottom-color: transparent;
}

.observation-controls button::after,
.flow-replay::after,
.begin::after,
.text-link::after,
.transcript-credit a::after,
.priority-source a::after {
  content: '';
  position: absolute;
  inset: auto 0 -4px;
  height: 7px;
  background: currentColor;
  -webkit-mask: var(--pen-underline) center / 100% 100% no-repeat;
  mask: var(--pen-underline) center / 100% 100% no-repeat;
  pointer-events: none;
}

.observation-controls button::after {
  inset: auto 5px -2px;
  opacity: 0;
  transform: scaleX(.75);
  transform-origin: left;
  transition: opacity 180ms ease, transform 180ms ease;
}

.observation-controls button[aria-pressed="true"]::after {
  opacity: 1;
  transform: scaleX(1);
}

.flow-replay::after,
.priority-source a::after {
  bottom: 4px;
}

.begin::after { bottom: -2px; }

/* Cloned inline backgrounds follow wrapped text without changing line breaks. */
.narration-link,
.source-notes a,
.footer > p > a {
  padding-bottom: 5px;
  background-image: var(--pen-link-underline);
  background-position: left bottom;
  background-size: 100% 7px;
  background-repeat: no-repeat;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  text-decoration: none;
}

.example-stream .narration-link { background-image: var(--pen-example-underline); }

@media (hover: hover) {
  .observation-controls button:hover::after {
    opacity: .55;
    transform: scaleX(1);
  }
  .observation-controls button[aria-pressed="true"]:hover::after { opacity: 1; }
  .flow-replay:hover { text-decoration: none; }
  .begin:hover,
  .text-link:hover,
  .transcript-credit a:hover,
  .priority-source a:hover,
  .narration-link:hover,
  .source-notes a:hover,
  .footer > p > a:hover { color: var(--indigo); }
}

@media (prefers-reduced-motion: reduce) {
  .observation-controls button::after { transition: none; }
}

/* Structural rules stay light; only their contour changes. */
.scroll-story,
.example-scene,
.running-example,
.story-navigation,
.footer > p,
.transcript section {
  position: relative;
  border-color: transparent;
}

.scroll-story::before,
.story-navigation::before,
.footer > p::before,
.transcript section::before,
.running-example::after {
  content: '';
  position: absolute;
  inset: -3px 0 auto;
  height: 7px;
  background: var(--line);
  -webkit-mask: var(--pen-rule) center / 100% 100% no-repeat;
  mask: var(--pen-rule) center / 100% 100% no-repeat;
  pointer-events: none;
}

.running-example::after { top: auto; bottom: -3px; }

.example-scene::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 -3px;
  width: 7px;
  background: var(--line);
  -webkit-mask: var(--pen-rule-vertical) center / 100% 100% no-repeat;
  mask: var(--pen-rule-vertical) center / 100% 100% no-repeat;
  pointer-events: none;
}

.brief-rewrite::after {
  height: 7px;
  bottom: -2px;
  -webkit-mask: var(--pen-underline) center / 100% 100% no-repeat;
  mask: var(--pen-underline) center / 100% 100% no-repeat;
}

.progress-track {
  height: 7px;
  -webkit-mask: var(--pen-rule) center / 100% 100% no-repeat;
  mask: var(--pen-rule) center / 100% 100% no-repeat;
}

.story-navigation button { position: relative; }
.story-navigation button::after {
  content: '';
  position: absolute;
  inset: auto 0 4px;
  height: 7px;
  background: currentColor;
  -webkit-mask: var(--pen-underline) center / 100% 100% no-repeat;
  mask: var(--pen-underline) center / 100% 100% no-repeat;
  opacity: 0;
  pointer-events: none;
}

@media (hover: hover) {
  .story-navigation button:not(:disabled):hover { text-decoration: none; }
  .story-navigation button:not(:disabled):hover::after { opacity: 1; }
}

@media (max-width: 900px) {
  .example-scene::before {
    inset: -3px 0 auto;
    width: auto;
    height: 7px;
    -webkit-mask-image: var(--pen-rule);
    mask-image: var(--pen-rule);
  }
  .running-example::after { display: none; }
}
