/* Every surface is a squircle. Put .sq on it and set --sq-r for the corner size, --sq-fill and --sq-line for paint,
   and --sq-shadow for a shadow (a list of drop-shadow() functions). Never set background, border or box-shadow on a .sq element.
   No rule on this site sets a corner radius. The corner is the curve from docs/pstack-architecture.html, Lamé
   quadrants with exponent 4 and extent k = r * 1.72, carried here as mask tiles, so it is right on first paint and
   with script off. ::before paints the fill and ::after the one-pixel edge, so a .sq element keeps neither for itself.
   A popover, or a surface that wraps a select, keeps both, and squircle.js draws it instead. */

/* Registered so --sq-fill and --sq-line can transition and animate. */
@property --sq-fill { syntax: '<color>'; inherits: true; initial-value: transparent; }
@property --sq-line { syntax: '<color>'; inherits: true; initial-value: transparent; }

/* Written by tileCSS() in squircle.js. Regenerate, never edit. */
:root {
  --sq-tile-tl: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cg%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0V100Z'/%3E%3C/g%3E%3C/svg%3E");
  --sq-edge-tl: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3CclipPath id='c'%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0V100Z'/%3E%3C/clipPath%3E%3Cg%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0' fill='none' stroke='black' stroke-width='2' vector-effect='non-scaling-stroke' clip-path='url(%23c)'/%3E%3C/g%3E%3C/svg%3E");
  --sq-ring-tl: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3CclipPath id='c'%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0V100Z'/%3E%3C/clipPath%3E%3Cg%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0' fill='none' stroke='black' stroke-width='4' vector-effect='non-scaling-stroke' clip-path='url(%23c)'/%3E%3C/g%3E%3C/svg%3E");
  --sq-tile-tr: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cg transform='translate(100 0) scale(-1 1)'%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0V100Z'/%3E%3C/g%3E%3C/svg%3E");
  --sq-edge-tr: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3CclipPath id='c'%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0V100Z'/%3E%3C/clipPath%3E%3Cg transform='translate(100 0) scale(-1 1)'%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0' fill='none' stroke='black' stroke-width='2' vector-effect='non-scaling-stroke' clip-path='url(%23c)'/%3E%3C/g%3E%3C/svg%3E");
  --sq-ring-tr: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3CclipPath id='c'%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0V100Z'/%3E%3C/clipPath%3E%3Cg transform='translate(100 0) scale(-1 1)'%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0' fill='none' stroke='black' stroke-width='4' vector-effect='non-scaling-stroke' clip-path='url(%23c)'/%3E%3C/g%3E%3C/svg%3E");
  --sq-tile-br: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cg transform='translate(100 100) scale(-1 -1)'%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0V100Z'/%3E%3C/g%3E%3C/svg%3E");
  --sq-edge-br: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3CclipPath id='c'%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0V100Z'/%3E%3C/clipPath%3E%3Cg transform='translate(100 100) scale(-1 -1)'%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0' fill='none' stroke='black' stroke-width='2' vector-effect='non-scaling-stroke' clip-path='url(%23c)'/%3E%3C/g%3E%3C/svg%3E");
  --sq-ring-br: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3CclipPath id='c'%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0V100Z'/%3E%3C/clipPath%3E%3Cg transform='translate(100 100) scale(-1 -1)'%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0' fill='none' stroke='black' stroke-width='4' vector-effect='non-scaling-stroke' clip-path='url(%23c)'/%3E%3C/g%3E%3C/svg%3E");
  --sq-tile-bl: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cg transform='translate(0 100) scale(1 -1)'%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0V100Z'/%3E%3C/g%3E%3C/svg%3E");
  --sq-edge-bl: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3CclipPath id='c'%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0V100Z'/%3E%3C/clipPath%3E%3Cg transform='translate(0 100) scale(1 -1)'%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0' fill='none' stroke='black' stroke-width='2' vector-effect='non-scaling-stroke' clip-path='url(%23c)'/%3E%3C/g%3E%3C/svg%3E");
  --sq-ring-bl: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3CclipPath id='c'%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0V100Z'/%3E%3C/clipPath%3E%3Cg transform='translate(0 100) scale(1 -1)'%3E%3Cpath d='M0 100 0.19 70.48 0.76 58.33 1.72 49.13 3.06 41.52 4.8 34.99 6.94 29.29 9.49 24.27 12.48 19.83 15.91 15.91 19.83 12.48 24.27 9.49 29.29 6.94 34.99 4.8 41.52 3.06 49.13 1.72 58.33 0.76 70.48 0.19 100 0' fill='none' stroke='black' stroke-width='4' vector-effect='non-scaling-stroke' clip-path='url(%23c)'/%3E%3C/g%3E%3C/svg%3E");
  --sq-solid: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cpath d='M0 0H100V100H0Z'/%3E%3C/svg%3E");
}

/* Zero specificity, so any component rule that sets these wins whatever the load order. */
:where(.sq) {
  --sq-r: 14px;
  --sq-fill: var(--surface);
  --sq-line: var(--line);
  --sq-shadow: none;
  position: relative;
}

/* The transparent border keeps the box the size it had when the edge was a real border. A button's own grey
   background would show in the corners, so it goes. */
.sq {
  border: 1px solid transparent;
  background: none;
  isolation: isolate;
  filter: var(--sq-shadow);
}

/* A box-shadow would be a rectangle behind a shape that is not one. squircle.js reads the value a component set,
   through the probe attribute, and writes it to --sq-shadow. New code sets --sq-shadow and waits for no script. */
.sq:not([data-sq-probe]) { box-shadow: none !important; }

.sq:not([popover], :has(> select))::before,
.sq:not([popover], :has(> select))::after {
  /* A box smaller than two corners gets corners of half its size. Whole pixels, so a tile never lands on a fraction. */
  --k: min(round(var(--sq-r) * 1.72, 1px), round(down, 50%, 1px));
  --band: calc(100% - 2 * var(--k) + 2px);
  content: '';
  position: absolute;
  inset: -1px;
  z-index: -1;
  pointer-events: none;
  mask-repeat: no-repeat;
}

.sq:not([popover], :has(> select))::before {
  background: var(--sq-fill);
  mask-image: var(--sq-tile-tl), var(--sq-tile-tr), var(--sq-tile-br), var(--sq-tile-bl), var(--sq-solid), var(--sq-solid);
  mask-position: left top, right top, right bottom, left bottom, center, center;
  mask-size: var(--k) var(--k), var(--k) var(--k), var(--k) var(--k), var(--k) var(--k), var(--band) 100%, 100% var(--band);
}

.sq:not([popover], :has(> select))::after {
  --edge: 1px;
  background: var(--sq-line);
  mask-image: var(--sq-edge-tl), var(--sq-edge-tr), var(--sq-edge-br), var(--sq-edge-bl), var(--sq-solid), var(--sq-solid), var(--sq-solid), var(--sq-solid);
  mask-position: left top, right top, right bottom, left bottom, center top, center bottom, left center, right center;
  mask-size: var(--k) var(--k), var(--k) var(--k), var(--k) var(--k), var(--k) var(--k), var(--band) var(--edge), var(--band) var(--edge), var(--edge) var(--band), var(--edge) var(--band);
}

/* Focus is a two-pixel ring three pixels out, on the same curve. --sq-focus sets its color on a dark ground. */
.sq:not([popover], :has(> select)):focus-visible,
.sq.sq:not([popover], :has(> select)):has(> :is(input, textarea):focus-visible) { outline-color: transparent; }
.sq:not([popover], :has(> select)):focus-visible::after,
.sq:not([popover], :has(> select)):has(> :is(input, textarea):focus-visible)::after {
  --k: min(round(var(--sq-r) * 1.72, 1px) + 5px, round(down, 50%, 1px));
  --edge: 2px;
  inset: -6px;
  background: var(--sq-focus, var(--ink, #1D1D1F));
  mask-image: var(--sq-ring-tl), var(--sq-ring-tr), var(--sq-ring-br), var(--sq-ring-bl), var(--sq-solid), var(--sq-solid), var(--sq-solid), var(--sq-solid);
}

/* Surfaces squircle.js draws. */
.sq > .sq-bg {
  position: absolute;
  inset: -1px;
  width: calc(100% + 2px);
  height: calc(100% + 2px);
  z-index: -1;
  pointer-events: none;
  overflow: visible;
}

.sq > .sq-bg path {
  fill: var(--sq-fill);
  stroke: var(--sq-line);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

/* A picture, or anything that paints its own background, cut to the same corner. The fill tiles above are used as
   a mask on the element itself, so .sqi needs no pseudo-element and no script. Set --sq-r for the corner size. */
.sqi {
  --k: min(round(var(--sq-r, 12px) * 1.72, 1px), round(down, 50%, 1px));
  --band: calc(100% - 2 * var(--k) + 2px);
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-image: var(--sq-tile-tl), var(--sq-tile-tr), var(--sq-tile-br), var(--sq-tile-bl), var(--sq-solid), var(--sq-solid);
  mask-image: var(--sq-tile-tl), var(--sq-tile-tr), var(--sq-tile-br), var(--sq-tile-bl), var(--sq-solid), var(--sq-solid);
  -webkit-mask-position: left top, right top, right bottom, left bottom, center, center;
  mask-position: left top, right top, right bottom, left bottom, center, center;
  -webkit-mask-size: var(--k) var(--k), var(--k) var(--k), var(--k) var(--k), var(--k) var(--k), var(--band) 100%, 100% var(--band);
  mask-size: var(--k) var(--k), var(--k) var(--k), var(--k) var(--k), var(--k) var(--k), var(--band) 100%, 100% var(--band);
}
