.matching {
  background: radial-gradient(ellipse at 80% 0%, #c8f03114, transparent 45%), var(--bg-raised);
  color: var(--heading);
  position: relative;
}
.matching .section-marker {
  color: var(--muted);
  border-color: var(--line-strong);
}
.matching-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 60px;
  margin: 52px 0 46px;
}
.matching-header .eyebrow {
  color: var(--accent);
  margin-bottom: 24px;
}
.matching-header h2 {
  font-size: clamp(38px, 4.4vw, 64px);
  font-weight: 400;
}
.matching-header > p {
  max-width: 280px;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.9;
  margin: 0 0 4px;
}
.match-interface {
  background: var(--surface);
  color: var(--ink);
  border-radius: 16px;
  border: 1px solid var(--line-strong);
  box-shadow: 0 40px 90px -40px #000000e6;
  overflow: hidden;
}
.interface-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 21px 30px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.interface-bar > span:first-child {
  display: flex;
  align-items: center;
  gap: 11px;
}
.interface-bar .status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow:
    0 0 0 4px var(--accent-soft),
    0 0 10px var(--accent);
}
.demo-tag {
  font-size: 10px;
  color: var(--muted);
}
.match-workbench {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
}
.match-specification {
  padding: 32px;
  border-right: 1px solid var(--line);
}
.micro-label {
  font-size: 9px;
  letter-spacing: 0.14em;
  color: var(--muted);
}
.requirement-summary h3 {
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.025em;
  margin: 13px 0 17px;
}
.request-size {
  font-size: 27px;
  letter-spacing: -0.055em;
  margin: 0 0 9px;
  color: var(--heading);
  white-space: nowrap;
}
.request-size small {
  font-size: 12px;
  letter-spacing: 0;
}
.request-species {
  font-size: 11px;
  color: var(--muted);
}
.matching-steps {
  display: grid;
  margin-top: 31px;
}
.matching-step {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 77px;
  padding: 17px 0;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  text-align: left;
  color: var(--muted);
  transition: color 0.2s;
}
.matching-step > span:first-child {
  font-size: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  transition:
    background 0.2s,
    color 0.2s;
}
.matching-step strong {
  display: block;
  font-size: 12px;
  font-weight: 600;
}
.matching-step small {
  display: block;
  margin-top: 6px;
  font-size: 10px;
  font-weight: 400;
  line-height: 1.5;
}
.matching-step .step-tick {
  font-size: 15px;
  opacity: 0;
}
.matching-step[aria-pressed='true'],
.matching-step:hover {
  color: var(--heading);
}
.matching-step[aria-pressed='true'] > span:first-child {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.matching-step[aria-pressed='true'] .step-tick {
  opacity: 1;
}
.timber-view {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.timber-canvas {
  position: relative;
  min-height: 345px;
  flex: 1;
  perspective: 1200px;
  background:
    radial-gradient(ellipse at 53% 65%, #e4b47a24, transparent 60%),
    radial-gradient(#ffffff14 0.7px, transparent 0.7px);
  background-size:
    auto,
    24px 24px;
}
.canvas-label {
  position: absolute;
  top: 26px;
  left: 30px;
  font-size: 9px;
  letter-spacing: 0.13em;
  color: var(--muted);
}
.canvas-index {
  position: absolute;
  top: 24px;
  right: 28px;
  font-size: 10px;
  color: var(--muted);
}
.timber-assembly {
  --board-size: clamp(240px, 32vw, 460px);
  --depth: calc(var(--board-size) / 30);
  position: absolute;
  left: 50%;
  top: 56%;
  width: var(--board-size);
  height: calc(var(--board-size) / 2);
  transform-style: preserve-3d;
  transform: translate(-50%, -50%) rotateX(48deg) rotateZ(-26deg);
  transition: transform 1.2s var(--ease-out);
  /* Wave shelf outline, generated from waveShelf(400, 200) in wood-shapes.js. */
  --wave-shape: polygon(
    0% 0%,
    100% 0%,
    100% 61.7%,
    99.8% 61.2%,
    99.2% 59.9%,
    98.3% 57.8%,
    97% 54.9%,
    95.3% 51.5%,
    93.3% 47.8%,
    91% 44.2%,
    88.3% 40.9%,
    85.4% 38.6%,
    82.1% 37.6%,
    78.7% 38.4%,
    75% 41.3%,
    71.1% 46.3%,
    67.1% 53.2%,
    62.9% 61.6%,
    58.7% 70.8%,
    54.4% 79.9%,
    50% 88%,
    45.6% 94.3%,
    41.3% 98.4%,
    37.1% 100%,
    32.9% 99.1%,
    28.9% 96.1%,
    25% 91.6%,
    21.3% 86%,
    17.9% 80%,
    14.6% 74.2%,
    11.7% 68.8%,
    9% 64.2%,
    6.7% 60.4%,
    4.7% 57.4%,
    3% 55.1%,
    1.7% 53.5%,
    0.8% 52.5%,
    0.2% 51.9%,
    0% 51.7%
  );
}
.stock-board,
.reusable-piece {
  position: absolute;
  transform-style: preserve-3d;
  background:
    repeating-linear-gradient(1deg, transparent 0 3px, #8e602b18 4px, transparent 5px 9px),
    repeating-radial-gradient(
      ellipse at 12% -140%,
      transparent 0 17px,
      #67451e17 18px,
      transparent 19px 33px
    ),
    linear-gradient(95deg, #bf965e, #e4cda5 35%, #d4b07b 75%, #b58c55);
}
.stock-board {
  inset: 0;
  box-shadow: 10px 34px 40px -12px #000000cc;
}
.stock-board:before,
.reusable-piece:before {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  height: var(--depth);
  transform-origin: top;
  transform: rotateX(-90deg);
  background: repeating-linear-gradient(0deg, #855c31 0 1px, #b18a54 2px 4px);
}
.stock-board:after,
.reusable-piece:after {
  content: '';
  position: absolute;
  left: 100%;
  top: 0;
  bottom: 0;
  width: var(--depth);
  transform-origin: left;
  transform: rotateY(90deg);
  background: repeating-linear-gradient(90deg, #996f3b 0 1px, #c5a16c 2px 4px);
}
/* One component: 400/600 by 200/300. Cutting envelope: 407/600 by 207/300. */
.cut-envelope {
  position: absolute;
  top: 12%;
  left: 8%;
  width: var(--envelope-length, 67.8333%);
  height: var(--envelope-width, 69%);
  border: 1px dashed var(--accent);
  transform: translateZ(1px);
  transition: opacity 0.4s;
}
.cut-seat {
  position: absolute;
  top: 12.6667%;
  left: 8.3333%;
  width: var(--piece-length, 66.6667%);
  height: var(--piece-width, 66.6667%);
  background: linear-gradient(160deg, #1a130b, #3b2b17);
  clip-path: var(--wave-shape);
  transform: translateZ(0.5px);
}
/* A natural live edge beyond the declared usable rectangle; it is never counted. */
.stock-live-edge {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  height: 11%;
  background:
    linear-gradient(180deg, #4a2f17 0 34%, #8a6237 52%, #c9a16a 74%, transparent 100%),
    linear-gradient(95deg, #bf965e, #d4b07b 75%);
  clip-path: polygon(
    0% 58.8%,
    4.2% 49%,
    8.3% 42.7%,
    12.5% 36.8%,
    16.7% 37.4%,
    20.8% 42.5%,
    25% 39.8%,
    29.2% 51%,
    33.3% 43.2%,
    37.5% 37%,
    41.7% 30.2%,
    45.8% 20.4%,
    50% 24.7%,
    54.2% 30.9%,
    58.3% 33.3%,
    62.5% 41.3%,
    66.7% 39.4%,
    70.8% 38.9%,
    75% 39.7%,
    79.2% 41.9%,
    83.3% 45.8%,
    87.5% 46%,
    91.7% 50.8%,
    95.8% 59.2%,
    100% 51.1%,
    100% 100%,
    0% 100%
  );
}
.reusable-piece {
  top: 12.6667%;
  left: 8.3333%;
  width: var(--piece-length, 66.6667%);
  height: var(--piece-width, 66.6667%);
  background: none;
  transform: translate3d(0, 0, 1px);
  transition: transform 1.2s var(--ease-out);
}
.reusable-piece:before,
.reusable-piece:after {
  display: none;
}
/* clip-path flattens 3D, so the shelf's thickness is stacked flat slices. */
.piece-slice,
.piece-face {
  position: absolute;
  inset: 0;
  clip-path: var(--wave-shape);
}
.piece-slice {
  background: #7d5630;
  transform: translateZ(calc(var(--depth) * -1));
}
.piece-slice:nth-child(2) {
  background: #8d6339;
  transform: translateZ(calc(var(--depth) * -0.75));
}
.piece-slice:nth-child(3) {
  background: #9b6f41;
  transform: translateZ(calc(var(--depth) * -0.5));
}
.piece-slice:nth-child(4) {
  background: #a97b4a;
  transform: translateZ(calc(var(--depth) * -0.25));
}
.piece-face {
  display: grid;
  place-items: start center;
  padding-top: 18%;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: #2b1d0d;
  background:
    repeating-linear-gradient(1deg, transparent 0 3px, #8e602b1c 4px, transparent 5px 9px),
    repeating-radial-gradient(
      ellipse at 40% -120%,
      transparent 0 15px,
      #67451e1c 16px,
      transparent 17px 30px
    ),
    linear-gradient(95deg, #d2ab72, #f0dbb4 40%, #e0bd87 75%, #c79d63);
}
.piece-outline {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  transform: translateZ(0.5px);
}
.piece-outline polygon {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 4px #c8f03199);
}
.stock-length {
  position: absolute;
  top: calc(100% + 34px);
  width: 100%;
  left: 0;
  padding-top: 8px;
  border-top: 1px solid var(--line-strong);
  text-align: center;
  font-size: 11px;
  color: var(--muted);
}
.stock-width {
  position: absolute;
  left: calc(100% + 29px);
  height: 100%;
  top: 0;
  border-left: 1px solid var(--line-strong);
  padding-left: 8px;
  writing-mode: vertical-rl;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
}
.depth-callout {
  position: absolute;
  right: 30px;
  bottom: 22px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--heading);
  transition: opacity 0.4s;
}
.depth-callout:before {
  content: '';
  width: 24px;
  height: 7px;
  border-block: 1px solid currentColor;
}
[data-match-step='0'] .reusable-piece {
  transform: translate3d(-12px, -10px, 86px);
}
[data-match-step='1'] .reusable-piece {
  transform: translate3d(0, 0, 115px);
}
[data-match-step='0'] .cut-envelope,
[data-match-step='0'] .depth-callout {
  opacity: 0.2;
}
[data-match-step='1'] .timber-assembly {
  transform: translate(-50%, -50%) rotateX(39deg) rotateZ(-22deg);
}
.timber-legend {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 15px;
  padding: 24px 30px;
  border-top: 1px solid var(--line);
}
.timber-legend strong {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 7px;
}
.timber-legend span {
  font-size: 11px;
  color: var(--muted);
}
.timber-legend > span {
  text-align: right;
  font-size: 9px;
  line-height: 1.7;
}
.match-caption {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  border-top: 1px solid var(--line);
  padding: 19px 30px;
  background: var(--surface-2);
}
.match-caption p {
  margin: 0;
  font-size: 12px;
  line-height: 1.8;
  max-width: 650px;
  color: var(--muted);
}
.replay-matching {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  border: 0;
  background: transparent;
  color: var(--heading);
  font-size: 11px;
  padding: 7px 0;
}
.replay-matching svg {
  width: 16px;
  height: 16px;
}
.match-result {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 23px 30px;
  background: var(--accent-soft);
  border-top: 1px solid #c8f0313d;
}
.result-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 50%;
  box-shadow: 0 0 18px var(--accent-glow);
  font-size: 15px;
  flex-shrink: 0;
}
.match-result strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}
.match-result div > span {
  font-size: 11px;
  line-height: 1.8;
  color: var(--heading);
}
.result-label {
  margin-left: auto;
  font-size: 10px;
  color: var(--heading);
}
.match-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 32px;
  margin-top: 28px;
}
.match-bottom p {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.9;
}
.match-bottom .text-link {
  color: var(--heading);
}
.match-explanation {
  margin-top: 30px;
  padding-top: 25px;
  border-top: 1px solid var(--line-strong);
  max-width: 850px;
}
.match-explanation h3 {
  font-weight: 500;
  font-size: 23px;
}
.match-explanation p {
  font-size: 14px;
  line-height: 1.9;
  color: var(--ink);
}
.match-explanation a {
  color: var(--heading);
  margin-top: 8px;
}
.is-direct .timber-assembly,
.is-direct .reusable-piece {
  transition: none;
}
[data-match-driver='scroll'] .reusable-piece {
  transform: translate3d(var(--story-x), var(--story-y), var(--story-lift));
  transition: none;
}
[data-match-driver='scroll'] .timber-assembly {
  transform: translate(-50%, -50%) rotateX(var(--story-tilt)) rotateZ(var(--story-roll));
  transition: none;
}
@media (max-width: 1100px) {
  .match-workbench {
    grid-template-columns: 290px minmax(0, 1fr);
  }
  .match-specification {
    padding: 25px;
  }
  .request-size {
    font-size: 24px;
  }
  .timber-assembly {
    --board-size: 29vw;
  }
  .timber-canvas {
    min-height: 365px;
  }
  .timber-legend {
    padding-inline: 25px;
  }
  .result-label {
    display: none;
  }
}
@media (max-width: 900px) {
  .matching-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 24px;
  }
  .matching-header > p {
    max-width: 430px;
  }
  .match-workbench {
    grid-template-columns: 250px minmax(0, 1fr);
  }
  .match-specification {
    padding: 24px;
  }
  .request-size {
    font-size: 22px;
  }
  .matching-step {
    grid-template-columns: 25px 1fr;
    gap: 10px;
  }
  .matching-step .step-tick {
    display: none;
  }
  .matching-step strong {
    font-size: 11px;
  }
  .timber-assembly {
    --board-size: 27vw;
  }
  .timber-legend {
    flex-direction: column;
    align-items: flex-start;
  }
  .timber-legend > span {
    text-align: left;
  }
  .depth-callout {
    right: 18px;
  }
  .canvas-label {
    left: 24px;
    font-size: 8px;
  }
}
@media (max-width: 700px) {
  .matching-header {
    margin: 36px 0;
  }
  .matching-header h2 {
    font-size: clamp(34px, 8vw, 48px);
  }
  .matching-header .eyebrow {
    font-size: 9px;
    margin-bottom: 20px;
  }
  .matching-header > p {
    font-size: 14px;
  }
  .interface-bar {
    padding: 18px;
    font-size: 10px;
  }
  .interface-bar .demo-tag {
    font-size: 9px;
  }
  .match-workbench {
    grid-template-columns: 1fr;
  }
  .match-specification {
    display: contents;
  }
  .requirement-summary {
    order: 0;
    padding: 24px;
    border-bottom: 1px solid var(--line);
  }
  .requirement-summary h3 {
    margin: 10px 0 13px;
  }
  .request-size {
    font-size: 29px;
    margin-bottom: 8px;
  }
  .timber-view {
    order: 1;
  }
  .matching-steps {
    order: 2;
    grid-template-columns: repeat(3, 1fr);
    margin: 0;
    border-top: 1px solid var(--line);
    padding-inline: 15px;
  }
  .matching-step {
    display: block;
    padding: 18px 8px;
    border-top: 0;
  }
  .matching-step > span:first-child {
    margin-bottom: 12px;
    width: 25px;
    height: 25px;
  }
  .matching-step small {
    font-size: 9px;
  }
  .timber-canvas {
    min-height: 310px;
  }
  .timber-assembly {
    --board-size: min(63vw, 360px);
    top: 58%;
  }
  .canvas-label {
    top: 23px;
  }
  .timber-legend {
    padding: 20px 24px;
    flex-direction: row;
    align-items: flex-end;
  }
  .timber-legend strong {
    font-size: 12px;
  }
  .timber-legend span {
    font-size: 10px;
  }
  .timber-legend > span {
    max-width: 72px;
    text-align: right;
    font-size: 8px;
  }
  .match-caption {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 20px 24px;
  }
  .match-caption p {
    font-size: 11px;
    min-height: 58px;
  }
  .match-result {
    align-items: flex-start;
    padding: 22px 24px;
    gap: 12px;
  }
  .match-result strong {
    font-size: 13px;
  }
  .match-bottom {
    flex-direction: column;
    align-items: flex-start;
    gap: 22px;
  }
  .stock-length,
  .stock-width {
    font-size: 10px;
  }
  .stock-length {
    top: calc(100% + 22px);
  }
  .stock-width {
    left: calc(100% + 19px);
  }
  .piece-face {
    font-size: 8px;
  }
  .depth-callout {
    font-size: 10px;
    bottom: 14px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .timber-assembly,
  .reusable-piece {
    transition: none;
  }
}
@supports not (transform-style: preserve-3d) {
  .timber-assembly,
  [data-match-step='1'] .timber-assembly {
    transform: translate(-50%, -50%);
  }
  .reusable-piece,
  [data-match-step] .reusable-piece {
    transform: none;
  }
  .stock-board:before,
  .stock-board:after,
  .reusable-piece:before,
  .reusable-piece:after {
    display: none;
  }
}
