/* Pull-cord Bulb — Tactile UI.
   The lamp fills its host: give the host a width and a height. A tall narrow
   host (56 × 150 px under a nav) is a header toggle; a wide one is a hero. */

.pc {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 96px;
  /* A vertical swipe over the empty wall still scrolls the page; only the grip takes the drag. */
  touch-action: pan-y;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.pc canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  /* Host resets (img, svg, canvas { max-width: 100% }, as in Tailwind's) would squeeze
     the canvas's width and not its height. It sizes itself: leave it alone. */
  max-width: none;
  max-height: none;
}

/* The bulb's light on the wall adds to the page behind it, as light does. */
.pc-light, .pc-glow { mix-blend-mode: screen; }

/* Grain over that light, the kit's fractal noise as an overlay: a smooth light on a pale wall would
   band into rings in 8 bits. Overlay on mid grey changes nothing on average, and does most on a pale
   wall, where the banding is. It is as strong as the light (opacity is set as it draws) and fades
   with it toward the box's edge. */
.pc-grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  mix-blend-mode: overlay;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0.3 0 0 0 0.35 0.3 0 0 0 0.35 0.3 0 0 0 0.35 0 0 0 0 1'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  -webkit-mask-image: radial-gradient(closest-side, #000 70%, transparent);
  mask-image: radial-gradient(closest-side, #000 70%, transparent);
}

/* The acorn's hit target: 44 px, following it, taking the pull on touch. */
.pc-grip {
  position: absolute;
  left: 0;
  top: 0;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  touch-action: none;
  cursor: grab;
}
.pc.pc-held, .pc.pc-held .pc-grip { cursor: grabbing; }
/* The focus ring hugs the acorn (its size is set as it draws); the grip stays 44 px. */
.pc-grip::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--pc-ring, 36px);
  height: var(--pc-ring, 36px);
  transform: translate(-50%, -50%);
  border-radius: 50%;
}
.pc:focus-visible .pc-grip::after { outline: 2px solid var(--tui-focus, currentColor); outline-offset: 1px; }

/* `reveal`: lights on, the light page opens out of the bulb; lights off, it shrinks back into
   the bulb over the dark one. --pc-r is the light's radius (animated by the script), --pc-x/y the
   bulb; the edge is feathered over the outer tenth (REVEAL.feather). Nothing else animates under
   it (a page's own colour transition would smear inside the light). */
@property --pc-r { syntax: '<length>'; inherits: false; initial-value: 0px; }
html.pc-reveal::view-transition-old(root), html.pc-reveal::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
html.pc-reveal:not(.pc-closing)::view-transition-new(root),
html.pc-reveal.pc-closing::view-transition-old(root) {
  -webkit-mask-image: radial-gradient(circle at var(--pc-x) var(--pc-y), #000 calc(var(--pc-r) * 0.9), transparent var(--pc-r));
  mask-image: radial-gradient(circle at var(--pc-x) var(--pc-y), #000 calc(var(--pc-r) * 0.9), transparent var(--pc-r));
}
/* Going dark, the light page stays on top, whole until the script starts shrinking it. */
html.pc-reveal.pc-closing::view-transition-old(root) { z-index: 1; --pc-r: 300vmax; }
html.pc-reveal, html.pc-reveal *, html.pc-reveal *::before, html.pc-reveal *::after { transition: none !important; }

@media (forced-colors: active) {
  .pc:focus-visible .pc-grip::after { outline-color: Highlight; }
}
