/* ---- The work screen (screens/work.js). CSS owns the layout; the script fills the lists and hands the
   cards' rectangles to the grains (work/grain-field.js). ---- */
/* Layouts by window shape: the breakpoints live at the end of this file (media queries cannot read custom
   properties). Each sets --cols (grid units across) and --shelves (rows of cards on a page; 0: no pages, the
   projects scroll), which the script reads as a page's room (work/pager.js). */
.work{
  --cols:5;--shelves:1;
  position:fixed;inset:0;display:grid;grid-template-rows:auto auto minmax(0,1fr) auto;grid-template-areas:"head" "filter" "projects" "foot";row-gap:var(--space-4);
  padding:var(--page-pad) var(--page-pad) max(var(--page-pad),env(safe-area-inset-bottom));outline:none;touch-action:none
}
/* One page of projects: no foot, so its row and gap give their height to the projects. */
.work:has(> .work-foot[hidden]){grid-template-rows:auto auto minmax(0,1fr);grid-template-areas:"head" "filter" "projects"}
.work.entering{pointer-events:none}
.work>*{transition:opacity var(--dur-slow) ease}
.work.entering>*{opacity:0}
/* Leaving with "Back": the whole screen fades while the music screen returns. */
.work.leaving{opacity:0;pointer-events:none;transition:opacity var(--dur-slow) ease}

/* Head: "Back" on the left, room on the right for the language and sound tools. The h1 names the screen
   for assistive technology; sighted visitors see the screen itself. */
.work-head{grid-area:head;display:flex;align-items:center;min-height:var(--control-size);padding-right:calc(2 * var(--control-size))}

/* ---- filter: one sentence, "show [what] for [whom]". Each word is a <details> whose fieldset of checkboxes
   opens under it; the chosen tags become the word. ---- */
.work-filter{grid-area:filter;margin:0;min-width:0}
.work-sentence{display:flex;flex-wrap:wrap;align-items:baseline;gap:0 var(--space-2);min-height:var(--control-size);font:400 var(--type-label)/var(--leading-text) var(--font-ui);color:var(--ink-secondary)}
.work-word{position:relative;display:inline-block;max-width:100%}
/* The word: a 44px target with the text in its middle; the dashed line belongs to the text, not to the target. */
.work-word-sum{list-style:none;display:inline-flex;align-items:center;gap:var(--space-1);min-height:var(--control-size);max-width:100%;cursor:pointer;color:var(--ink)}
.work-word-sum::-webkit-details-marker{display:none}
.work-word-text{overflow:hidden;white-space:nowrap;text-overflow:ellipsis;text-decoration:underline dashed var(--line) var(--hairline);text-underline-offset:.25em;transition:text-decoration-color var(--dur-fast)}
/* The small corner after the word says it opens. */
.work-word-sum::after{content:"";flex:none;width:.4em;height:.4em;margin-left:var(--space-1);border:solid var(--ink-secondary);border-width:0 var(--hairline) var(--hairline) 0;transform:translateY(-.15em) rotate(45deg);transition:transform var(--dur-fast)}
.work-word[open] .work-word-sum::after{transform:translateY(.1em) rotate(225deg)}
.work-word:hover .work-word-text,.work-word[open] .work-word-text,.work-word.on .work-word-text{text-decoration-style:solid;text-decoration-color:var(--ink)}
.work-word-sum:focus-visible{outline:var(--focus-ring);outline-offset:var(--space-1)}
.work-axis{position:absolute;left:0;top:100%;z-index:var(--z-sheet);min-width:16rem;max-width:calc(100vw - 2 * var(--page-pad));max-height:min(60vh,24rem);overflow:auto;scrollbar-width:thin;margin:var(--space-1) 0 0;padding:var(--space-2);border:var(--hairline) solid var(--line);background:var(--paper);touch-action:pan-y}
.work-axis-name{padding:var(--space-1) var(--space-2) var(--space-2);font:400 var(--type-intro)/var(--leading-text) var(--font-mono);letter-spacing:var(--track-data);color:var(--ink-secondary);text-transform:lowercase}
.work-chips{display:grid}
/* A tag: one row of the list, its count on the right. The checkbox covers the whole 44px row. */
.work-chip{position:relative;display:grid;grid-template-columns:minmax(0,1fr) auto;gap:var(--space-3);align-items:center;min-height:var(--control-size);padding:0 var(--space-2);font:400 var(--type-control)/var(--leading-ui) var(--font-ui);color:var(--ink);cursor:pointer;transition:background var(--dur-fast)}
.work-chip input{position:absolute;inset:0;width:100%;height:100%;margin:0;opacity:0;cursor:pointer}
.work-chip:hover{background:var(--tint-hover)}
.work-chip:has(:checked) .work-chip-name{text-decoration:underline;text-underline-offset:.2em}
.work-chip:has(:focus-visible){outline:var(--focus-ring);outline-offset:calc(-1 * var(--space-1))}
.work-chip-count{font:400 var(--type-micro)/1 var(--font-mono);letter-spacing:var(--track-data);color:var(--ink-secondary)}
.work-reset{min-height:var(--control-size);margin-left:var(--space-2);padding:0;border:0;background:none;font:400 var(--type-control)/var(--leading-ui) var(--font-ui);color:var(--ink-secondary);text-decoration:underline;text-decoration-color:var(--line);text-underline-offset:.2em;cursor:pointer}
.work-reset:hover,.work-reset:focus-visible{color:var(--ink)}
.work-reset:focus-visible{outline:var(--focus-ring);outline-offset:var(--space-1)}

/* ---- projects: cards on shelves ----
   A card is its picture and its caption under it. The picture is --tile-rows grid units tall and the card's
   tile.cols units wide, so a 2-wide picture is square and a 3-wide one about 3:2, at any window size; the
   caption is a band of fixed height below it, outside the units.
   The lattice of grains runs down the middle of every gap, so its outer line lies half a gap outside the
   cards: the stage keeps that half gap as padding and the canvas covers it, so the lattice is always whole.
   The unit --u is the largest at which --cols units fit across and --shelves shelves fit down. */
.work-projects{
  --tile-rows:2;
  --caption:calc(var(--card-gap) + var(--type-label) * var(--leading-tight) + var(--space-1) + var(--caption-lines) * var(--type-caption) * var(--leading-ui));
  --caption-lines:2;
  grid-area:projects;position:relative;display:flex;align-items:center;justify-content:center;min-height:0;container-type:size
}
.work-stage{position:relative;padding:calc(var(--work-gap) / 2)}
.work-field{z-index:0;pointer-events:none}
.work-grid{
  --u:min(
    calc((100cqw - var(--work-gap) - (var(--cols) - 1) * var(--work-gap)) / var(--cols)),
    calc(((100cqh - var(--work-gap) - (var(--shelves) - 1) * var(--work-gap)) / var(--shelves) - var(--caption) - (var(--tile-rows) - 1) * var(--work-gap)) / var(--tile-rows))
  );
  --picture:calc(var(--tile-rows) * var(--u) + (var(--tile-rows) - 1) * var(--work-gap));
  position:relative;z-index:1;display:grid;grid-template-columns:repeat(var(--cols),var(--u));gap:var(--work-gap);
  margin:0;padding:0;list-style:none
}
.work-card{--tw:2;grid-column:span 2;min-width:0}
.work-card[data-tw="1"]{--tw:1;grid-column:span 1}.work-card[data-tw="3"]{--tw:3;grid-column:span 3}.work-card[data-tw="4"]{--tw:4;grid-column:span 4}
/* The card's body: a link to the project page when the project is open, the same box without one while it is
   coming soon. Both look the same. */
.work-card-body{display:grid;gap:var(--card-gap);color:inherit;text-decoration:none;outline:none}
/* The tile: the frame of the picture. The lattice frames it, so it has no line of its own; a tile without a
   picture keeps a faint one, or it would not be there at all. A tile wider than the page keeps its shape:
   it is cut to the page's width and gets lower by the same share. */
.work-tile{position:relative;height:calc(var(--picture) * min(1, var(--cols) / var(--tw)));overflow:hidden}
.work-tile:not(:has(.work-tile-image)){outline:var(--hairline) solid var(--line-faint);outline-offset:calc(-1 * var(--hairline))}
.work-card-body:focus-visible .work-tile{outline:var(--focus-ring);outline-offset:calc(-1 * var(--space-1))}
/* The picture fills the tile. It arrives as grains: while the card is "grain" the picture is hidden and the
   grains draw it; then it shows through as the grains dissolve. */
.work-tile-image,.work-tile-clip{position:absolute;inset:0;width:100%;height:100%;display:block;object-fit:cover}
.work-tile-image{transition:opacity var(--dur-slow) ease}
.work-card.grain .work-tile-image{opacity:0;transition:none}
/* The clip lies over its first frame and shows while it plays (pointer or focus on the card, or — on a touch
   screen — on its own while the card is in view). It stays hidden until the picture has formed from its
   grains, so a looping clip never flashes over the grains. */
.work-tile-clip{opacity:0;transition:opacity var(--dur-ui) ease}
.work-tile-clip.playing{opacity:1}
.work-card.grain .work-tile-clip{opacity:0}
.work-tile .soon{position:absolute;top:var(--space-2);left:var(--space-2);z-index:1}
/* The caption: the title on one line, the line under it on up to --caption-lines lines. */
.work-card-text{display:grid;align-content:start;gap:var(--space-1);height:calc(var(--caption) - var(--card-gap));min-width:0;text-align:center}
.work-card-title{margin:0;overflow:hidden;font:400 var(--type-label)/var(--leading-tight) var(--font-ui);white-space:nowrap;text-overflow:ellipsis}
.work-card-line{display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:var(--caption-lines);margin:0;overflow:hidden;font:400 var(--type-caption)/var(--leading-ui) var(--font-ui);color:var(--ink-secondary)}
.work-empty{position:absolute;inset:0;z-index:1;display:grid;place-items:center;margin:0;padding:0 var(--space-4);text-align:center;font:400 var(--type-control)/var(--leading-text) var(--font-ui);color:var(--ink-secondary)}

/* ---- foot: the pages, centred; there only when there is more than one page ---- */
.work-foot{grid-area:foot;display:flex;justify-content:center;align-items:center;min-height:var(--control-size)}
.work-pages{display:flex;align-items:center;gap:var(--space-2)}
.work-page-count{min-width:5ch;text-align:center;font:400 var(--type-intro)/var(--leading-text) var(--font-mono);letter-spacing:var(--track-data);color:var(--ink-secondary)}
.work-page-step:disabled{opacity:.3;cursor:default}
.work-page-step:disabled:hover{color:var(--ink-secondary)}

/* ---- layouts ---- */
/* shelf, the default: 5 units across, one shelf a page: a wide card (3) and a square one (2) side by side. */
/* stack, portrait windows (tablets): 3 units across, two shelves a page: the cards stand one under the other. */
@media (max-aspect-ratio:5/6){.work{--cols:3;--shelves:2}}
/* scroll, phones held upright: 2 units across and no pages: the unit follows the width and the projects
   scroll. A 3-wide card is cut to the 2 columns and keeps its shape. A word's list opens from the page frame. */
@media (max-width:599px){
  .work{--cols:2;--shelves:0;touch-action:pan-y}
  .work-projects{display:block;overflow-y:auto;overscroll-behavior:contain;scrollbar-width:none}
  .work-grid{--u:calc((100cqw - var(--work-gap) - (var(--cols) - 1) * var(--work-gap)) / var(--cols))}
  .work-card[data-tw="3"],.work-card[data-tw="4"]{grid-column:span 2}
  .work-word{position:static}
  .work-axis{left:var(--page-pad);right:var(--page-pad);top:auto;min-width:0;max-width:none}
}
/* strip, phones held sideways and other short windows: one shelf, small, and the caption is the title only. */
@media (max-height:499px){
  .work{--cols:5;--shelves:1;row-gap:var(--space-2)}
  .work-projects{--caption-lines:0}
  .work-card-line{display:none}
}
@media (prefers-reduced-motion:reduce){.work-tile-image{transition:none}}
