.model-stage { margin-top: 7px; }

.product-model {
  display: grid;
  grid-template-columns: minmax(0, 2.06fr) minmax(0, 1fr);
  grid-template-areas: "flow detail" "approaches approaches";
  border: 1px solid var(--ink);
  background: var(--forest);
}

.flow-board {
  --route: #dced76;
  --route-muted: #a5b29065;
  --engraving-height: clamp(74px, 13.9vw, 179px);
  grid-area: flow;
  isolation: isolate;
  min-width: 0;
  padding: clamp(17px, 2.3vw, 35px);
}

.flow-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  flex-wrap: wrap;
  gap: 12px 22px;
}

.flow-header h2, .resource-intro h2, .flow-detail h3 {
  font-family: "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  font-stretch: condensed;
  font-weight: 900;
  line-height: 0.99;
  letter-spacing: -0.062em;
}

.flow-header h2 { font-size: clamp(2rem, 4vw, 3.85rem); }
.flow-header p { margin-top: 8px; color: #d3dec3; font-size: clamp(0.92rem, 1.35vw, 1.1rem); }

.flow-modes { display: flex; align-items: stretch; gap: 6px; }
.flow-modes button {
  color: var(--paper);
  background: var(--forest-deep);
  border: 1px solid #a1b190;
  padding: 6px 12px;
  min-height: 40px;
  font-size: 0.88rem;
  font-weight: 690;
  cursor: pointer;
  transition: background-color 170ms ease, color 170ms ease;
}
.flow-modes button:hover { background: #344d38; }
.flow-modes button[aria-pressed="true"] { background: var(--lime); color: var(--ink); border-color: var(--lime); }

.flow-figure { position: relative; margin-top: 11px; }

.flow-engraving {
  height: var(--engraving-height);
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  mix-blend-mode: lighten;
  pointer-events: none;
}
.flow-engraving img {
  position: absolute;
  width: 100%;
  height: auto;
  top: 50%;
  transform: translateY(-50%);
}

.flow-rail {
  height: 2px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 9px 12.5% 0;
}
.flow-segment {
  position: relative;
  background: var(--route-muted);
  transition: background-color 240ms ease;
}
.flow-segment.flow-emphasis { background: var(--route); }
.flow-segment.flow-emphasis::after, .return-route::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #efffa8;
  box-shadow: 0 0 10px 2px #dbef717c;
  animation: material-right 1.7s ease-in-out 2 both;
}
.flow-segment:nth-child(2)::after { animation-delay: 120ms; }
.flow-segment:nth-child(3)::after { animation-delay: 240ms; }
@keyframes material-right {
  0% { left: 0; transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
  16%, 84% { opacity: 1; }
  100% { left: 100%; transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
}

.flow-stations {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  list-style: none;
  margin: 0;
  padding: 0;
}
.flow-station {
  position: relative;
  text-align: center;
  font-size: clamp(0.69rem, 1.12vw, 1rem);
  font-weight: 770;
  color: #d0ddc4;
  transition: color 200ms ease;
}
.station-button {
  position: relative;
  display: block;
  width: 100%;
  min-height: 30px;
  padding: 10px 1px 0;
  border: 0;
  background: none;
  font-weight: inherit;
  cursor: pointer;
}
.station-button::before {
  content: "";
  position: absolute;
  inset: calc(-1 * var(--engraving-height) - 10px) 2px 0;
  border: 1px dashed transparent;
  background: transparent;
  transition: border-color 170ms ease, background-color 170ms ease;
}
.station-button:hover::before, .station-button[aria-pressed="true"]::before, .station-button:focus-visible::before {
  border-color: #c6d88395;
  background: #a9d06518;
}
.station-button:hover, .station-button[aria-pressed="true"] { color: #f3ffb8; }
.station-button[aria-pressed="true"] { text-decoration: underline; text-underline-offset: 0.28em; }
.flow-station::before {
  content: "";
  width: 9px;
  height: 9px;
  position: absolute;
  left: 50%;
  top: -1px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #869c72;
  border: 1px solid #15261a;
  transition: background-color 200ms ease, box-shadow 200ms ease;
}
.flow-station.flow-emphasis, [data-mode="linear"] .flow-station { color: #f4ffcb; }
.flow-station.flow-emphasis::before, [data-mode="linear"] .flow-station::before {
  background: var(--route);
  box-shadow: 0 0 0 3px #dced7633;
}

.flow-branch { position: relative; height: 31px; margin-top: 8px; }
.return-route {
  position: absolute;
  inset: 0 12.5% auto 62.5%;
  height: 26px;
  border: 2px solid var(--route);
  border-top: 0;
  border-radius: 0 0 14px 14px;
  transform-origin: 50% 0;
  transition: scale 270ms ease, opacity 230ms ease;
}
.return-route::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 0;
  width: 8px;
  height: 8px;
  border-top: 2px solid var(--route);
  border-left: 2px solid var(--route);
  transform: rotate(45deg);
}
.return-route::after {
  top: 100%;
  animation-name: material-left;
  animation-delay: 360ms;
}
@keyframes material-left {
  0% { left: 100%; transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
  16%, 84% { opacity: 1; }
  100% { left: 0; transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
}

.exit-route {
  position: absolute;
  left: 62.5%;
  top: 0;
  width: 30%;
  height: 23px;
  border-left: 2px solid var(--route);
  border-bottom: 2px solid var(--route);
  border-radius: 0 0 0 12px;
  transform-origin: left top;
  opacity: 0;
  scale: 0.55 1;
  transition: opacity 230ms ease, scale 250ms ease;
}
.exit-route::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -5px;
  width: 8px;
  height: 8px;
  border-top: 2px solid var(--route);
  border-right: 2px solid var(--route);
  transform: rotate(45deg);
}
[data-mode="linear"] .return-route { opacity: 0; scale: 1 0.25; }
[data-mode="linear"] .return-route::after { animation-name: none; }
[data-mode="linear"] .exit-route { opacity: 1; scale: 1; }
[data-mode="linear"] .flow-engraving img { mask-image: linear-gradient(90deg, #000 73%, #0006 78%); }
[data-mode="linear"] .flow-station:last-child { color: #acb9a3; }
[data-mode="linear"] .flow-station:last-child::before { background: #75906d; box-shadow: none; }
[data-mode="loop"][data-lens="0"] .return-route,
[data-mode="loop"][data-lens="2"] .return-route { opacity: 0.5; }
[data-mode="loop"][data-lens="2"] .return-route::after { animation-name: none; }
[data-mode="loop"][data-lens="4"] .flow-figure {
  outline: 1px dashed #d6e69180;
  outline-offset: 5px;
}

.flow-figure figcaption {
  font: 650 clamp(0.73rem, 1.13vw, 0.94rem) var(--mono);
  color: #e1edb1;
  text-align: right;
}
#flow-state {
  margin-top: 10px;
  color: #d8e1cc;
  max-width: 68ch;
  font-size: clamp(0.85rem, 1.15vw, 1rem);
  line-height: 1.43;
}

.flow-detail {
  grid-area: detail;
  min-width: 0;
  padding: clamp(20px, 2.2vw, 32px);
  border-left: 1px solid var(--ink);
}
.model-label {
  margin: 0;
  font: 720 0.72rem/1.23 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.flow-detail h3 {
  margin: 12px 0 0;
  padding-top: 15px;
  border-top: 1px solid var(--line);
  font-size: clamp(2rem, 3vw, 3.2rem);
  overflow-wrap: break-word;
}
.flow-detail h3 + p { margin-top: 13px; font-size: clamp(0.94rem, 1.37vw, 1.13rem); line-height: 1.48; }

.flow-example {
  margin-top: 20px;
  border-left: 3px solid #788864;
  background: #eff0dd;
  padding: 11px 14px;
}
.flow-example p { margin-top: 6px; font-size: clamp(0.91rem, 1.2vw, 1.02rem); line-height: 1.42; }

.approach-list {
  grid-area: approaches;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  background: var(--ink);
  border-top: 1px solid var(--ink);
}
.approach-list button {
  min-width: 0;
  min-height: 59px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  overflow-wrap: anywhere;
  font-weight: 780;
  font-size: clamp(0.84rem, 1.26vw, 1.05rem);
  letter-spacing: -0.023em;
  background: var(--paper);
  border: 0;
  padding: 10px clamp(8px, 1.15vw, 19px);
  cursor: pointer;
  transition: background-color 180ms ease;
}
.approach-list button:hover { background: #e0e8ce; }
.approach-list button[aria-pressed="true"] { background: var(--lime); }
.approach-list button:focus-visible { outline-offset: -4px; }
.approach-list button span {
  padding-right: 9px;
  border-right: 1px solid #748464;
  font: 650 0.81rem/1.35 var(--mono);
  letter-spacing: 0;
}

.resource-lab {
  --indicator: #daee75;
  display: grid;
  grid-template-columns: minmax(0, 0.78fr) minmax(0, 1fr) minmax(0, 1fr);
  border: 1px solid var(--ink);
  margin-top: 12px;
  background: #edeee1;
}
.resource-lab[data-trend="down"] { --indicator: #b8d3a7; }
.resource-lab[data-trend="same"] { --indicator: #d4ddbb; }
.resource-intro, .resource-controls, .resource-comparison { padding: clamp(16px, 2.25vw, 32px); }
.resource-intro h2 { font-size: clamp(2rem, 3.4vw, 3.15rem); }
.resource-intro > p { margin-top: 9px; font-size: 0.94rem; line-height: 1.44; max-width: 33ch; }
.resource-controls, .resource-comparison { border-left: 1px solid #8b9680; }

.resource-control + .resource-control { margin-top: 11px; }
.resource-control > div { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.resource-control label { font-size: 0.95rem; font-weight: 750; }
.resource-control output { font: 700 0.9rem var(--mono); white-space: nowrap; }
.resource-control input {
  display: block;
  width: 100%;
  height: 30px;
  accent-color: #4d6540;
  cursor: ew-resize;
  margin: 1px 0 0;
}
.resource-presets { display: flex; flex-wrap: wrap; column-gap: 5px; row-gap: 4px; margin-top: 9px; }
.resource-presets button {
  border: 1px solid #8c9a81;
  background: transparent;
  color: var(--ink);
  font-size: 0.76rem;
  font-weight: 660;
  padding: 3px 6px;
  min-height: 30px;
  cursor: pointer;
}
.resource-presets button:hover { background: #dce4cc; }
.resource-presets button[aria-pressed="true"] { background: #d5e4a5; border-color: #526044; }

.resource-ledger { display: grid; gap: 3px; }
#resource-delta {
  display: inline-block;
  width: fit-content;
  padding: 2px 9px 4px;
  font-size: clamp(2rem, 3.9vw, 3.75rem);
  font-weight: 830;
  letter-spacing: -0.062em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  background: var(--indicator);
  transition: background-color 200ms ease;
}
.resource-bars { display: grid; gap: 7px; margin-top: 11px; }
.resource-row { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 3px; font-size: 0.82rem; }
.resource-row strong, .resource-row output { font: 710 0.83rem var(--mono); }
.resource-row i {
  --bar: 45.4545%;
  grid-column: 1 / -1;
  width: var(--bar);
  height: 8px;
  background: #415844;
  transition: width 230ms ease;
}
#variant-bar { --bar: 53.1818%; background: var(--indicator); border: 1px solid #718651; }

.resource-reading {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 5px 18px;
  border-top: 1px solid #8b9680;
  padding: 10px clamp(16px, 2.25vw, 32px);
  font-size: 0.91rem;
  line-height: 1.4;
}
#resource-formula { font: 680 0.78rem var(--mono); white-space: nowrap; }

@media (max-width: 1020px) {
  .product-model { grid-template-columns: minmax(0, 1.72fr) minmax(0, 1fr); }
  .approach-list button { gap: 6px; }
  .approach-list button span { padding-right: 6px; }
}

@media (max-width: 730px) {
  .product-model {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "flow" "approaches" "detail";
  }
  .flow-board { --engraving-height: clamp(71px, 20vw, 150px); }
  .flow-detail { border-left: 0; border-top: 1px solid var(--ink); }
  .flow-detail h3 { margin-top: 8px; padding-top: 11px; }
  .flow-example { margin-top: 14px; }
  .resource-lab { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .resource-intro { grid-column: 1 / -1; border-bottom: 1px solid #8b9680; }
  .resource-intro > p { max-width: 48ch; }
  .resource-controls { border-left: 0; }
}

@media (max-width: 485px) {
  .flow-board { padding-inline: 11px; }
  .flow-header { gap: 10px; }
  .flow-header h2 { font-size: clamp(1.72rem, 7.2vw, 2.2rem); }
  .flow-modes button { min-height: 37px; }
  .flow-station { font-size: clamp(0.61rem, 2.55vw, 0.74rem); }
  .station-button { min-height: 24px; padding-top: 8px; }
  .flow-branch { height: 24px; }
  .return-route { height: 19px; }
  .exit-route { height: 17px; }
  .approach-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .approach-list button { min-height: 45px; }
  .approach-list button:last-child { grid-column: 1 / -1; }
  .resource-lab { grid-template-columns: minmax(0, 1fr); }
  .resource-comparison { border-left: 0; border-top: 1px solid #8b9680; }
}

@media (prefers-reduced-motion: reduce) {
  .flow-segment::after, .return-route::after { display: none; }
}
