/* Four independent paths form a loop; normalized dashes share one cycle. */
.process-connectors { display: block; z-index: 0; }
.process-ring-path { stroke: #b9a98d; stroke-width: 1.25; }
.process-flow {
  fill: none; stroke: #85704b; stroke-width: 2.5; stroke-linecap: round;
  stroke-dasharray: .12 1; stroke-dashoffset: .12;
  animation: process-flow 3s linear infinite paused;
  pointer-events: none;
}
.is-flow-running .process-flow { animation-play-state: running; }
@keyframes process-flow { to { stroke-dashoffset: -1; } }

.process-ring .process-node {
  position: relative; z-index: 1; transform: scale(.8); opacity: .82;
  background: #f6f1e7; border-color: #d7cdbb; box-shadow: none;
  transition: transform .32s cubic-bezier(.2,.7,.2,1), background .32s, border-color .32s, opacity .25s;
}
.process-ring .process-node.is-active {
  z-index: 2; transform: scale(1.02); opacity: 1;
  background: #e7d8b6; border-color: #ad8d51;
  animation: process-arrival .65s ease-out;
}
.process-ring .process-detail { display: none; }
.process-ring .process-node.is-active .process-detail { display: block; }

/* Hidden panels reserve a shared grid cell so the stage stays still in transit. */
.story-copy-area, html[lang="en"] .story-copy-area { display: grid; }
.story-copy-area .story-copy { grid-area: 1 / 1; align-self: center; }
.story-copy-area .story-copy[hidden] {
  display: block; visibility: hidden; pointer-events: none; opacity: 0;
}
.story-copy-area .story-copy.is-active { animation: none; }
.story-copy .story-more {
  display: inline-block;
  white-space: nowrap;
  color: #685037;
  font-size: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: .2em;
}
.story-more:hover, .story-more:focus-visible { color: var(--ink); }
@media (max-width: 600px) {
  .story-copy .story-more { min-height: 24px; }
}

.story-navigation {
  grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0;
  padding-top: 0; margin-top: clamp(20px, 3vh, 32px);
}
.story-navigation .story-progress {
  top: 5px; left: 12.5%; right: 12.5%; height: 2px;
  background: #cbbfa9; pointer-events: none;
}
.story-navigation .story-progress span {
  position: relative; width: calc(var(--story-stage-progress, 0) * 100%);
  height: 100%; background: #856d48; transition: none;
}
.story-progress span::after {
  content: ""; position: absolute; z-index: 1; right: 0; top: 50%;
  width: 9px; height: 9px; transform: translate(50%, -50%);
  border-radius: 50%; background: #f6e5b7; border: 2px solid #856d48;
}
.story-navigation button, html[lang="en"] .story-navigation button {
  position: relative; justify-content: center; min-height: 44px;
  padding: 17px 4px 3px; gap: 7px; text-align: center;
  color: #6e6250; line-height: 1.35;
}
.story-navigation button .mono { font-size: 13px; }
.story-navigation button::before {
  content: ""; position: absolute; top: 6px; left: 50%;
  width: 6px; height: 6px; transform: translate(-50%, -50%);
  border-radius: 50%; background: #b5a78c;
}
.story-navigation button[aria-pressed="true"] {
  color: var(--ink); font-weight: 600;
}
.story-navigation button:focus-visible {
  outline: 2px solid #856d48; outline-offset: 2px; border-radius: 4px;
}

@keyframes process-arrival {
  from { box-shadow: 0 0 0 1px #e1bf74, 0 0 30px #d4b56b88; }
  to { box-shadow: 0 0 0 1px transparent, 0 0 0 transparent; }
}

@media (min-width: 901px) and (min-height: 520px) and (max-height: 700px) {
  .story-navigation { margin-top: 12px; }
}
.story-swipe-hint { display: none; }

/* Fit the original four-node loop above its active detail on a phone. */
@media (max-width: 600px), (max-width: 900px) and (pointer: coarse),
       (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  .story-stage, html.chapter-paging .story-stage {
    position: relative; height: auto; min-height: var(--paging-height, 100svh);
    justify-content: center; padding-block: calc(var(--header-height) + 12px) 20px;
  }
  .story-heading h2 { font-size: clamp(1.7rem, 7.6vw, 2.15rem); overflow-wrap: anywhere; }
  .story-heading:lang(en) br { display: none; }
  .story-heading > :is(.story-manual-hint, .story-swipe-hint) { margin: 6px 0 0; padding: 0; line-height: 1.45; color: #756a57; }
  .touch-page .story-manual-hint { display: none; }
  .touch-page .story-swipe-hint { display: block; }
  .story-workbench {
    display: grid; grid-template-columns: minmax(0, 1fr); gap: clamp(14px, 3svh, 30px);
    margin-top: clamp(14px, 2.6svh, 24px);
  }
  .story-visual.process-visual { width: 100%; height: auto; max-width: 28rem; }
  .story-navigation, .process-ring .process-number { display: none; }
  .process-diagram.process-ring {
    /* Reserve both rows with the longest expanded caption on a narrow phone. */
    height: auto; min-height: max(11.5rem, min(29svh, 16.5rem));
    grid-template-rows: repeat(2, minmax(min-content, 1fr));
    column-gap: clamp(18px, 8vw, 56px); row-gap: clamp(15px, 3svh, 28px);
  }
  .process-ring .process-node {
    min-height: 44px; padding: 6px 8px; gap: 3px; border-radius: 8px;
    transform: scale(.88);
  }
  .process-ring .process-node.is-active { transform: scale(1.02); }
  .process-ring .process-label, html[lang="en"] .process-ring .process-label {
    font-size: clamp(1rem, 4.2vw, 1.25rem); overflow-wrap: anywhere;
  }
  .process-ring .process-detail, html[lang="en"] .process-ring .process-detail {
    font-size: clamp(.78rem, 3.5vw, .91rem); line-height: 1.24;
  }
  .story-copy-area { grid-template-columns: minmax(0, 1fr); }
  .story-copy-area .story-copy { align-self: start; min-width: 0; overflow-wrap: anywhere; }
  /* Keep the tallest translation's space when the global [hidden] rule hides other panels. */
  .story-copy-area .story-copy[hidden] { display: block !important; }
  [data-stage-direction="backward"] .story-copy-area { --panel-enter-y: -4px; }
  .story-copy-area .story-copy.is-active { animation: story-panel-in .3s ease-out; }
  @keyframes story-panel-in {
    from { opacity: 0; transform: translateY(var(--panel-enter-y, 4px)); }
    to { opacity: 1; transform: translateY(0); }
  }
  .story-copy h3, html[lang="en"] .story-copy h3 {
    font-size: clamp(1.5rem, 6.4vw, 1.9rem); margin-bottom: 8px; overflow-wrap: anywhere;
  }
  .story-detail-link { margin-top: 8px; min-height: 44px; max-width: 100%; }
}
@media (max-width: 600px) and (max-height: 640px) {
  .story-stage, html.chapter-paging .story-stage { padding-block: calc(var(--header-height) + 8px) 14px; }
  .story-heading h2 { line-height: 1.14; }
  .story-workbench { margin-top: 12px; gap: 12px; }
  .story-copy h3, html[lang="en"] .story-copy h3 { margin-bottom: 4px; }
  .story-copy > p:not(.eyebrow) { line-height: 1.65; }
  .story-detail-link { margin-top: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  .process-flow { animation: none; display: none; }
  .story-copy-area .story-copy.is-active { animation: none; }
  .process-ring .process-node { transition: none; }
  .process-ring .process-node.is-active { animation: none; }
}

#data-story .story-stage {
  justify-content: flex-start;
  padding-block-start: var(--header-height);
}
/* Use spare stage height for the opening inset. The controls keep their room in short windows. */
#data-story .story-stage::before {
  content: "";
  flex: 1 0 8px;
  max-block-size: var(--content-start-offset);
}
