/* Plane the board: the hero bench (v2, calm). Pairs with js/bench.js, which builds the layers into .bench__stage and
   writes the geometry below from bench-hero.json (4000 x 2500 frame) as percentages, so the composition scales with
   the stage. Without JS, with reduced motion, or if the layers fail, the finished still picture in the HTML shows. */

.bench {
  /* geometry defaults = bench-hero.json (js/bench.js rewrites them on load) */
  --board-l: 16.25%; --board-t: 40%; --board-w: 63%; --board-h: 19.2%;
  --bimg-l: -25.7937%; --bimg-t: -208.3333%; --bimg-w: 158.7302%; --bimg-h: 520.8333%;
  --st-l: -25.7937%; --st-t: -208.3333%; --st-w: 158.7302%; --st-h: 520.8333%;
  --tool-w: 33.8095%; --tool-ar: 852 / 330; --tool-t: 25%; --tool-heel: .0352;
  --sliver: max(10px, 1.5%);   /* pre-planed sliver behind the plane (of the board width) */
  position: relative;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}
.bench__stage { position: relative; width: 100%; aspect-ratio: 4000 / 2500; }
.bench__still { display: block; }
.bench__still img { display: block; width: 100%; height: auto; }

/* the interactive layers: built by js/bench.js, shown once the first look is decoded */
.bench__layers {
  position: absolute; inset: 0;
  opacity: 0; transition: opacity .7s ease;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.bench.is-loaded .bench__layers { opacity: 1; }
.bench__layers img { display: block; max-width: none; -webkit-user-drag: none; user-select: none; }
/* the board and stamp layers are drawn at the whole frame's size, wider than their box */
.bench__layers picture { max-width: none; }
.bench__base, .bench__base img { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.bench__rough {
  position: absolute; z-index: 1;
  left: var(--board-l); top: var(--board-t); width: var(--board-w); height: var(--board-h);
  pointer-events: none;
}
.bench__rough img, .bench__planed img {
  position: absolute; left: var(--bimg-l); top: var(--bimg-t); width: var(--bimg-w); height: var(--bimg-h);
  object-fit: fill;
}

/* the board: the whole board is the drag lane */
.bench__board {
  position: absolute; z-index: 3;
  left: var(--board-l); top: var(--board-t); width: var(--board-w); height: var(--board-h);
  touch-action: pan-y;
  cursor: grab;
}
/* a few px of extra grab above and below the board */
.bench__board::before { content: ''; position: absolute; left: 0; right: 0; top: -12px; bottom: -12px; }
.bench.is-dragging .bench__board,
.bench.is-dragging .bench__tool { cursor: grabbing; }
.bench.is-done .bench__board { cursor: default; }

.bench__wood { position: absolute; inset: 0; overflow: hidden; }

/* pencil marks on the rough board (a face mark and a cut line): planed away with it */
.bench__pencil { position: absolute; color: #2e2e36; opacity: .5; mix-blend-mode: multiply; pointer-events: none; }
.bench__pencil--face { left: 30%; top: 30%; height: 38%; width: auto; aspect-ratio: 2; transform: rotate(-4deg); }
.bench__pencil--line { left: 66%; top: 0; height: 100%; width: auto; aspect-ratio: .3; }

/* compositor-only reveal: wrapper and inner translate in opposite directions (js/bench.js sets both) */
.bench__reveal { position: absolute; inset: 0; overflow: hidden; will-change: transform; transform: translate3d(calc(var(--sliver) - 100%), 0, 0); transition: opacity .3s ease; }
.bench__reveal-inner { position: absolute; inset: 0; will-change: transform; transform: translate3d(calc(100% - var(--sliver)), 0, 0); }
.bench__planed { position: absolute; inset: 0; display: block; pointer-events: none; }
/* fresh-planed wood has a soft satin sheen */
.bench__reveal-inner::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(100deg, rgba(255, 250, 238, 0) 8%, rgba(255, 250, 238, .1) 22%, rgba(255, 250, 238, 0) 38%, rgba(255, 250, 238, 0) 58%, rgba(255, 250, 238, .07) 72%, rgba(255, 250, 238, 0) 86%);
}
.bench.is-resetting .bench__reveal { opacity: 0; }

/* the burned stamp: the reward. It glows in the van's orange for a moment, then cools to the dark burn */
.bench__stamp, .bench__ember {
  position: absolute; left: var(--st-l); top: var(--st-t); width: var(--st-w); height: var(--st-h);
  pointer-events: none;
}
.bench__stamp img { width: 100%; height: 100%; }
.bench__stamp { opacity: 0; transform: scale(1.015); transition: opacity .25s ease, transform .3s ease; }
.bench.is-done .bench__stamp {
  opacity: 1; transform: none;
  transition: opacity 1.3s cubic-bezier(.35, .1, .3, 1) .3s, transform 1.4s cubic-bezier(.2, .7, .2, 1) .3s;
}
.bench.is-resetting .bench__stamp { opacity: 0; transition: opacity .25s ease; }
.bench__ember { opacity: 0; filter: blur(.7px) drop-shadow(0 0 3px rgba(255, 106, 30, .85)) drop-shadow(0 0 9px rgba(229, 72, 12, .55)); }
.bench__ember i {
  position: absolute; inset: 0;
  background: linear-gradient(100deg, #FFB25E, #FF6A1E 45%, #E5480C);
  -webkit-mask: var(--ember-mask) 0 0 / 100% 100% no-repeat;
  mask: var(--ember-mask) 0 0 / 100% 100% no-repeat;
}
.bench.is-done .bench__ember { animation: bench-ember 2.1s cubic-bezier(.3, .2, .3, 1) .12s both; }
.bench.is-resetting .bench__ember { animation: none; opacity: 0; }
@keyframes bench-ember {
  0% { opacity: 0; }
  16% { opacity: .95; }
  42% { opacity: .7; }
  100% { opacity: 0; }
}

/* fresh-cut edge riding the reveal boundary */
.bench__edge {
  position: absolute; top: 0; bottom: 0; left: var(--sliver); width: 0;
  will-change: transform; pointer-events: none;
  transition: opacity .25s ease;
}
.bench__edge::before,
.bench__edge::after { content: ""; position: absolute; top: 0; bottom: 0; }
.bench__edge::before { right: 0; width: 2px; background: linear-gradient(180deg, rgba(255, 240, 212, .9), rgba(255, 232, 196, .62)); }
.bench__edge::after { left: 0; width: 1px; background: rgba(48, 28, 10, .55); }
.bench__sheen {
  position: absolute; top: 0; bottom: 0; right: 0; width: 40px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, .35));
  mix-blend-mode: soft-light;
  opacity: 0;
}
.bench.is-done .bench__edge { opacity: 0; }

/* the plane: positioned in the board box; js/bench.js moves it with a transform from its left edge */
.bench__tool {
  position: absolute; z-index: 3;
  left: 0; top: var(--tool-t);
  width: var(--tool-w);
  aspect-ratio: var(--tool-ar);
  touch-action: pan-y;
  cursor: grab;
  will-change: transform;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}
/* at least a 64 x 64 grab, however small the bench is drawn */
.bench__tool::before {
  content: ''; position: absolute; left: -8px; right: -8px; top: 50%;
  height: max(72px, 100%); transform: translateY(-50%);
}
.bench__tool-shadow, .bench__tool-pic, .bench__tool-img {
  position: absolute; inset: 0; display: block; width: 100%; height: 100%;
  pointer-events: none;
}
.bench__tool-pic { transform-origin: 88% 50%; }
.bench__tool:focus-visible .bench__tool-pic { outline: 2px solid var(--orange-hi, #F26A2E); outline-offset: 3px; }
.bench.is-done .bench__tool { cursor: default; }

/* settled shavings lie on the oak beside the board; flying ones go over everything */
.bench__bed, .bench__shavings {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
}
.bench__bed { z-index: 2; transition: opacity .3s ease; }
.bench.is-resetting .bench__bed { opacity: 0; }
.bench__shavings { z-index: 4; }

/* under the bench, lined up with the board's left end: the clue before, a quiet "Plane it again" after.
   Same grid cell, so nothing shifts. Pulled up into the render's empty bottom strip (its shadow has faded by then) */
.bench__after {
  position: relative; z-index: 5;
  display: grid; align-items: center;
  margin-top: -3.2%;
  padding-left: calc(var(--bd-l, .1625) * 100%);
  min-height: 26px;
  opacity: 0; transition: opacity .7s ease;
}
.bench.is-loaded .bench__after { opacity: 1; }
.bench__go, .bench__again { grid-area: 1 / 1; justify-self: start; }
.bench__go {
  margin: 0;
  font: 500 clamp(15px, .3vw + 12px, 17px)/1.3 var(--text); letter-spacing: .01em;
  color: var(--bone-2, rgba(233, 227, 213, .74));
  white-space: nowrap;
  pointer-events: none;
  transition: opacity .35s ease, visibility 0s linear 0s;
}
.bench__arrow { display: inline-block; will-change: transform; }
.bench.is-touched .bench__go,
.bench.is-done .bench__go { opacity: 0; visibility: hidden; transition: opacity .35s ease, visibility 0s linear .35s; }
.bench__again {
  font: 500 clamp(15px, .3vw + 12px, 17px)/1.3 var(--text); letter-spacing: .01em;
  color: var(--bone, #E9E3D5);
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .22em;
  text-decoration-color: rgba(233, 227, 213, .45);
  /* a 44px tap target without making the row taller */
  padding: 12px 0; margin: -12px 0;
  opacity: 0; visibility: hidden;
  transition: opacity .3s ease, visibility 0s linear .3s, text-decoration-color .2s;
}
.bench__again:hover { text-decoration-color: var(--orange, #E5480C); }
.bench.is-done .bench__again { opacity: 1; visibility: visible; transition: opacity .6s ease 1.6s, visibility 0s linear 1.6s, text-decoration-color .2s; }
.bench.is-resetting .bench__again { opacity: 0; transition: opacity .2s ease; }

/* still picture modes: no JS, reduced motion, or the layers failed. The still is the finished bench */
@media (prefers-reduced-motion: no-preference) {
  html.js:not(.bench-still) .bench__still { display: none; }
}
html:not(.js) .bench__after,
html.bench-still .bench__after,
html.bench-still .bench__layers { display: none; }
@media (prefers-reduced-motion: reduce) {
  .bench__after, .bench__layers { display: none; }
}
