/* The project board as the work page shows it: the split-flap board in a Matte housing, with its column labels, a lamp
   beside each row and the lit row in view. Shared by work.html and the Split-Flap Lab's "Work page" finish, so the lab
   shows what the site shows. Load after styles.css and matte.css. The markup:

   <div class="board matte">
     <div class="board__head mono"><span>Project</span><span>Released</span></div>
     <div class="board__stage">
       <p class="board__flap"></p>      split-flap.js mounts the board here
       <div class="board__keys"></div>  one button per row, each holding a span.m-led
     </div>
   </div>

   The page's script measures the board and sets --project-x, --released-x, --lamp-x and --lamp-y. */
/* each heading starts at the left edge of the first module of its column; the script measures where */
.board__head { position: relative; padding-bottom: var(--space-2); }
.board__head span { display: block; margin-left: var(--project-x, 0px); }
.board__head span:last-child { position: absolute; top: 0; left: var(--released-x, 75%); margin: 0; }
.board__stage { position: relative; }
.board__flap { margin: 0; }
.board__flap .sf-board { --sf-width: 100%; max-width: none; width: 100%; }
.board__keys { position: absolute; inset: 0; display: grid; grid-auto-rows: 1fr; padding-block: var(--sf-frame-pad, 0px); }
.board__keys button { background: none; border: 0; padding: 0; cursor: pointer; border-radius: var(--radius-xs); }
.board__keys button:focus-visible { outline: 2px solid var(--fg); outline-offset: -2px; }
/* a lamp in the plate's margin beside each project; the one in view is lit (Matte lights a lamp inside a pressed button).
   The script measures where the margin and the rows are. */
.board__keys button { position: relative; }
.board__keys .m-led { position: absolute; left: var(--lamp-x, 11px); top: var(--lamp-y, 50%); translate: -50% -50%; pointer-events: none; }
/* the lit lamp throws more light here than Matte's stock lamp: a hot core, then two wider, fainter rings onto the plate */
.board__keys [aria-pressed="true"] > .m-led { background: color-mix(in srgb, var(--m-signal) 82%, #fff);
  box-shadow: 0 0 0 1px var(--m-edge), 0 0 4px 1px var(--m-signal), 0 0 12px 3px color-mix(in srgb, var(--m-signal) 55%, transparent), 0 0 26px 7px color-mix(in srgb, var(--m-signal) 22%, transparent); }
:root:root .board__flap.is-aside + .board__keys .m-led { background: var(--m-cap-hi); box-shadow: 0 1px 1px rgb(0 0 0 / calc(0.8 * var(--m-shade))) inset, 0 0 0 1px var(--m-edge); }
/* The row in view has lighter flaps; a row under the pointer lightens part of the way.
   On the light board, where the flaps are already near white, the row takes a shade instead. */
.board__flap .sf canvas { transition: filter .2s ease; }
.board__flap .sf-row.is-hover .sf canvas { filter: brightness(1.3); }
.board__flap .sf-row.is-chosen .sf canvas { filter: brightness(1.75); }
:root[data-theme="light"] .board__flap .sf-row.is-hover .sf canvas { filter: brightness(.97); }
:root[data-theme="light"] .board__flap .sf-row.is-chosen .sf canvas { filter: brightness(.92); }
/* while the board shows something other than the projects, no row is lit */
:root:root .board__flap.is-aside .sf-row .sf canvas { filter: none; }
@media (prefers-reduced-motion: reduce) { .board__flap .sf canvas { transition: none; } }

/* the board: its plate is a Matte body, speckle and all, and the flaps lose their blue so they sit in it */
.board.matte .board__head { color: var(--m-print-dim); font: 400 var(--m-text-legend)/1.5 var(--m-font); letter-spacing: 0.1em; text-transform: uppercase; padding-bottom: var(--space-3); }
.board.matte .sf-board.is-framed { position: relative; isolation: isolate; border-radius: var(--m-radius);
  /* side light across the plate, as on the plain board: at its brightest, on the left, it is the tone of a Matte key's
     face (--m-cap-hi), and it is gone 60% of the way across, leaving the body's own top-to-bottom shade */
  background: linear-gradient(100deg, var(--m-cap-hi), transparent 60%), linear-gradient(180deg, var(--m-body-hi), var(--m-body-lo));
  box-shadow: 0 1px 0 var(--m-shine) inset, 0 -1px 0 rgb(0 0 0 / calc(0.6 * var(--m-shade))) inset, 0 0 0 1px var(--m-edge), var(--m-drop); }
.board.matte .sf-board.is-framed::before { content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit; pointer-events: none;
  opacity: calc(var(--m-speckle) * var(--m-speckle-gain)); filter: var(--m-speckle-ink);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .9 -.42'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E"); }
.board.matte .is-framed .sf { background: var(--m-well); box-shadow: 0 1px 0 rgb(255 255 255 / calc(0.08 * var(--m-gloss))), 0 0 0 1px var(--m-edge); }
.board.matte .board__flap .sf canvas { filter: grayscale(1); }
.board.matte .board__flap .sf-row.is-hover .sf canvas { filter: grayscale(1) brightness(1.3); }
.board.matte .board__flap .sf-row.is-chosen .sf canvas { filter: grayscale(1) brightness(1.75); }
:root[data-theme="light"] .board.matte .board__flap .sf-row.is-hover .sf canvas { filter: grayscale(1) brightness(.97); }
:root[data-theme="light"] .board.matte .board__flap .sf-row.is-chosen .sf canvas { filter: grayscale(1) brightness(.92); }
:root:root .board.matte .board__flap.is-aside .sf-row .sf canvas { filter: grayscale(1); }
.board.matte .board__keys button:focus-visible { outline: 2px solid var(--m-signal); outline-offset: -2px; }

/* ---- Folding. Once the board has finished flipping in, it folds down to the one row in view, and opens again under
   the pointer or the keyboard's focus. The page's script adds .can-fold when it has measured the board (--plate-h the
   open plate's height, --pitch a row and its gap, --rows how many) and toggles .is-folded.

   One number drives all of it: --fold, 0 open and 1 folded. It is registered so that it can be animated, and the
   plate's height, every row's place, the lamps and the leaves under the plate are all worked out from it, so the
   parts cannot drift apart mid-move. Each row slides up by its own place in the stack (--k), which lands them all on
   the top slot together and keeps the last row exactly on the plate's rising lower edge; the row in view rides on top
   and the others slide in under it like cards into a stack, fading only as they come to rest. A browser that can't register the number folds without the movement. */
@property --fold { syntax: "<number>"; inherits: true; initial-value: 0; }
/* Both curves leave at full speed, so the board is seen to move on the frame the pointer arrives or goes. */
.board.can-fold { transition: --fold 260ms cubic-bezier(0.16, 1, 0.3, 1); }                      /* opening: quick, and most of the way there at once */
.board.can-fold.is-folded { --fold: 1; transition: --fold 520ms cubic-bezier(0.2, 0.7, 0.2, 1); }   /* folding, slower */
.board.can-fold .sf-board { height: calc(var(--plate-h) - var(--fold) * (var(--rows) - 1) * var(--pitch)); }
.board.can-fold .sf-row { flex: none; position: relative; }
.board.can-fold .sf-row, .board.can-fold .board__keys > * { translate: 0 calc(var(--fold) * var(--k, 0) * -1 * var(--pitch)); }
.board :is(.sf-row, .board__keys > *):nth-child(2) { --k: 1; }
.board :is(.sf-row, .board__keys > *):nth-child(3) { --k: 2; }
.board :is(.sf-row, .board__keys > *):nth-child(4) { --k: 3; }
.board :is(.sf-row, .board__keys > *):nth-child(5) { --k: 4; }
.board :is(.sf-row, .board__keys > *):nth-child(6) { --k: 5; }
.board :is(.sf-row, .board__keys > *):nth-child(7) { --k: 6; }
.board :is(.sf-row, .board__keys > *):nth-child(8) { --k: 7; }
.board.can-fold .sf-row.is-chosen { z-index: 1; }
.board.can-fold .sf-row:not(.is-chosen), .board.can-fold .board__keys > :not([aria-pressed="true"]) { opacity: calc((1 - var(--fold)) * 5); }   /* whole while they slide under the row in view, gone over the last fifth */
/* the row buttons keep the open board's layout whatever the plate's height, and move with their rows */
.board.can-fold .board__keys { inset: 0 0 auto; height: var(--plate-h); pointer-events: none; }
.board.can-fold .board__keys > * { pointer-events: auto; }
.board.can-fold.is-folded .board__keys > :not([aria-pressed="true"]) { pointer-events: none; }
/* Folded, the edges of two more leaves show under the plate's lower edge, each set in from the one above like the
   rest of a stack: there is more under here. They slide out from under the plate as it closes. */
.board.can-fold .board__stage { isolation: isolate; }
.board.can-fold .board__stage::before, .board.can-fold .board__stage::after { content: ""; position: absolute; top: 100%; z-index: -1;   /* they take the pointer: a leaf is part of the board, and coming onto one opens it */
  border-radius: 0 0 var(--m-radius) var(--m-radius); opacity: var(--fold);
  background: linear-gradient(180deg, color-mix(in srgb, var(--m-body-lo) 60%, #000), var(--m-body-hi) 70%);   /* in the plate's shadow at the top, catching light at its lip */
  box-shadow: 0 -1px 0 var(--m-shine) inset, 0 0 0 1px var(--m-edge), 0 3px 5px rgb(0 0 0 / calc(0.5 * var(--m-shade))); }
.board.can-fold .board__stage::before { inset-inline: 12px; height: 7px; translate: 0 calc((var(--fold) - 1) * 7px); }
.board.can-fold .board__stage::after { inset-inline: 28px; height: 13px; z-index: -2; filter: brightness(0.8); translate: 0 calc((var(--fold) - 1) * 13px); }
@media (prefers-reduced-motion: reduce) { .board.can-fold, .board.can-fold.is-folded { transition: none; } }
