@layer modifiers {

/**
 * Modifiers only add overlays and set their strengths. They never move or resize anything and never touch a box face
 * except through the shade alpha and, for a box in shadow, its veil. The strengths below are the defaults of an element that
 * carries none of the choices.
 */
:root {
  --depth-k: 1;
  --seam-k: 1;
  --lamp-fade: 2000ms;
  --lamp-front: 0;
  --veil-alpha: 0.6;
  --veil-peek-alpha: 0.2;
  --veil-fade: 160ms;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --lamp-fade: 0ms;
    --veil-fade: 0ms;
  }
}

/**
 * Shadow. A box that does not match what the visitor is looking for stands where it stands under a dark veil with a thin lit
 * rim, so it stays a solid box and never becomes see-through. The veil is the last child of the box, so it lies above the box's
 * own face and, because the box is above the light layer, above the light of its cubby too: the lamp never lifts a box out of
 * its shadow. It only fades in and out and never takes a pointer event, so a box in shadow is clicked, focused and read exactly
 * like a lit one.
 */
.placement-veil {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  background: rgb(var(--box-shade-rgb) / var(--veil-alpha));
  box-shadow: inset 1px 1px 0 rgb(255 255 255 / 0.2);
  transition: opacity var(--veil-fade) ease-out;
}

.placement[data-dim] > .placement-veil {
  opacity: 1;
}

.placement[data-found] > .placement-veil {
  opacity: 0;
}

/**
 * A pass that changes many veils at once shows them at once: the filter script marks the cabinet for that pass, so hundreds of
 * veils never fade together on a cheap phone.
 */
.cabinet[data-bulk] {
  --veil-fade: 0ms;
}

/**
 * Pointing at a box in shadow lifts its veil to a thin one, so its title can be read before it is opened.
 */
@media (hover: hover) {
  .placement[data-dim]:hover > .placement-veil {
    opacity: calc(var(--veil-peek-alpha) / var(--veil-alpha));
  }
}

/**
 * Forced colours drop every fill, so the veil would vanish; the system's own mode gets the one place where a box is made
 * half transparent instead.
 */
@media (forced-colors: active) {
  .placement[data-dim] {
    opacity: 0.5;
  }
}

/**
 * Depth. Shaded is the default: the shelf above casts its shade across the boxes and onto the back of every cubby.
 */
.cabinet {
  --shade-alpha: 0.20;
  --shade-depth: 20%;
}

/**
 * Flat draws no shading at all: no shade over the boxes, none under the shelf above and none down the sides of the back. The
 * back keeps its construction, and the grain and lit edges of the furniture are untouched, because they are the design's own.
 */
[data-depth="flat"] {
  --depth-k: 0;
}

[data-depth="flat"] .cabinet {
  --shade-alpha: 0;
}

/**
 * Deep keeps the shade of the shelf above but lighter over the boxes, because the walls now carry part of the depth. The
 * look of a deep cubby is the wood's own: a ceiling, two side walls and a floor drawn from the wall tokens, seen from a
 * little above, so the floor is the largest and lightest face, the ceiling the thinnest and darkest, and each side wall
 * darkens toward the back.
 */
[data-depth="deep"] .cabinet {
  --shade-alpha: 0.12;
}

/**
 * The four faces are the four gradient layers of the cubby's own back, through the slot its design leaves for them, so
 * they paint behind the boxes and add no element and no clip. Sizes are the design's millimetre values.
 */
[data-depth="deep"] .cubby {
  --dw: calc(var(--depth-inset) * var(--u));
  --dt: calc(var(--depth-ceil) * var(--u));
  --df: calc(var(--depth-floor) * var(--u));
  --deep-img:
    linear-gradient(180deg, var(--cubby-top), color-mix(in srgb, var(--cubby-top) 70%, rgb(0 0 0 / 1))),
    linear-gradient(90deg, var(--cubby-left), color-mix(in srgb, var(--cubby-left) 70%, rgb(0 0 0 / 1))),
    linear-gradient(270deg, var(--cubby-right), color-mix(in srgb, var(--cubby-right) 70%, rgb(0 0 0 / 1))),
    linear-gradient(180deg, var(--cubby-floor-back), var(--cubby-floor-front));
  --deep-size: 100% var(--dt), var(--dw) calc(100% - var(--df)), var(--dw) calc(100% - var(--df)), 100% var(--df);
  --deep-pos: 0 0, 0 0, 100% 0, 0 100%;
}

/**
 * Every shelf board shows a thin lit top face in Deep, lit from above like the front edge: a hairline highlight that
 * fades into the board.
 */
[data-depth="deep"] .cubby::before {
  --top-hair: max(1px, calc(1 * var(--u)));
  --top-face-img: linear-gradient(
    to bottom,
    rgb(var(--highlight-rgb) / 0.55) 0 var(--top-hair),
    rgb(var(--highlight-rgb) / 0.20) var(--top-hair),
    transparent 100%
  );
  --top-face-size: 100% calc(var(--top-face) * var(--u));
}

/**
 * Painted backs. The back panel is one flat matte colour with no planks, no grain and no seams, the same on every wood. The
 * shade of the shelf above and down the sides stays, because it is depth and not construction, so it follows the depth
 * choice. The strengths the wood tunes for its own back return to the neutral ones, because the painted colour is not the
 * wood's back.
 */
[data-backs="painted"] {
  --seam-k: 0;
  --back: var(--back-painted);
  --pool-k: var(--pool-k-painted, 1);
  --back-shade-k: 1;
  --fill-k: 0;
  --keyline-lit: 0.4;
}

/**
 * Lights. One layer per section holds everything that is lit and fades by opacity alone. It sits under the boxes, so it
 * lights the back, the shelves and the uprights and never a box face, which is why the share of the lamp that reaches a box
 * face, --lamp-front, is nothing and nothing in this file reads it above a box. While the lights are off the layer is not
 * displayed at all.
 */
[data-lights="on"] .section > .section-light,
[data-lights="evenings"] .section > .section-light {
  display: block;
}

[data-lit] .section > .section-light {
  opacity: 1;
}

/**
 * The fade exists only once the page is settled, so the first frame is exactly the markup the server wrote. The compositor
 * hint is given only while the fade runs.
 */
[data-settled] .section > .section-light {
  transition: opacity var(--lamp-fade) ease-in-out;
}

[data-fading] .section > .section-light {
  will-change: opacity;
}

/**
 * The dark outer keyline of every box switches on only while the lights are lit, where a soft light can bring the back to
 * the lightness of a dark box. It is an outer ring of the box shadow, never on the face, and it has no transition.
 */
[data-lit] {
  --keyline: var(--keyline-lit, 0.4);
}

/**
 * The lamp is a hidden strip behind the shelf above each cubby. Its bright source line is the top two millimetres of the
 * cubby, a short warm fill runs below it on a wood that has a light back, and the wide pool on the back panel is an ellipse
 * wider than the cubby, so the corners keep most of the strength of the middle and the wash reads as a strip.
 */
.light-pool {
  background-image:
    linear-gradient(
      to bottom,
      rgb(var(--lamp-hot-rgb) / 0.8) 0 max(2px, calc(2.5 * var(--u))),
      rgb(var(--lamp-rgb) / calc(0.25 * var(--fill-k) * var(--depth-k))) max(2px, calc(2.5 * var(--u))),
      transparent 14%
    ),
    radial-gradient(
      ellipse 200% 50% at 50% 0%,
      rgb(var(--lamp-rgb) / calc(0.55 * var(--pool-k))) 0,
      rgb(var(--lamp-rgb) / calc(0.55 * var(--pool-k))) 18%,
      rgb(var(--lamp-rgb) / calc(0.30 * var(--pool-k))) 34%,
      rgb(var(--lamp-rgb) / calc(0.12 * var(--pool-k))) 50%,
      rgb(var(--lamp-rgb) / calc(0.05 * var(--pool-k))) 70%,
      transparent 100%
    );
}

/**
 * The faint spill of the lamp on the upright to the left of the cubby and on the shelf front below it.
 */
.light-pool::before {
  content: "";
  position: absolute;
  inset: 0 0 calc(-1 * var(--frame) * var(--u)) calc(-1 * var(--frame) * var(--u));
  box-sizing: border-box;
  border-style: solid;
  border-color: rgb(var(--lamp-rgb) / calc(0.08 * var(--lamp-k)));
  border-width: 0 0 calc(var(--frame) * var(--u)) calc(var(--frame) * var(--u));
}

/**
 * In Deep the top face of the shelf board under the cubby catches the lamp: a hairline highlight and a warm wash over the top
 * third of the board.
 */
[data-depth="deep"] .light-pool::after {
  content: "";
  position: absolute;
  left: 0;
  top: 100%;
  width: calc(100% + var(--frame) * var(--u));
  height: calc(var(--frame) * var(--u));
  background-image:
    linear-gradient(to bottom, rgb(var(--highlight-rgb) / 0.55) 0 max(1px, calc(1 * var(--u))), transparent max(1px, calc(1 * var(--u)))),
    linear-gradient(to bottom, rgb(var(--lamp-rgb) / calc(0.32 * var(--lamp-k))) 0 32%, transparent 32%);
}

/**
 * The faint warm glow on the floor in front of the base, inside the margin the section reserves under it. It is nothing on a
 * wood that has no floor, because the room strength of such a wood is nothing. The skirting is not washed. The glow has faded
 * out completely a little before the bottom of the margin, so the box edge never cuts a visible tail off, and its strength is
 * raised by the share the shorter fade takes away, so the glow keeps its overall brightness.
 */
.section-light::before {
  content: "";
  position: absolute;
  left: calc(-30 * var(--u));
  width: calc(100% + 60 * var(--u));
  top: calc(100% + var(--base-height) * var(--u));
  height: calc(var(--floor-margin) * var(--u));
  background-image: radial-gradient(
    ellipse 50% 100% at 50% 0%,
    rgb(var(--lamp-rgb) / calc(0.155 * var(--lamp-k) * var(--room-k))),
    transparent 90%
  );
}

}
