/* ==========================================================================
   Links and the order button. Loaded right after components.css. The heading above the list
   (.links-head, .links-title) is in components.css and carries the gap down to the list.
   Hover, press and the icon bounce are in css/motion.css.
   ========================================================================== */

/* ---------- links: lace pills with a rose edge and a mocha icon disc ----------
   The disc sits on the centre of the pill's round end, so its stitched ring and the pill's own stitch are
   concentric: pill stitch inner edge at 6.5px from the pill's edge (2px edge + 3px + 1.5px stitch), ring
   outer edge at disc/2 + 2.5px (1px offset + 1.5px ring). With --link-h 56 / 52 and --link-dot 32 / 28 that
   leaves 3px of air all round the end (more on a two-line pill). */
.link-list { display: flex; flex-direction: column; gap: 11px; margin-top: 0; }
.link-item { min-width: 0; }
.link-tag {
  --pill-h: var(--link-h);
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: var(--pill-h);
  padding: 3px 20px 3px calc(var(--pill-h) / 2 - var(--link-dot) / 2 - 2px);
  border: 2px solid var(--c-rose-200);
  border-radius: var(--r-pill);
  background-color: var(--c-lace);
  color: var(--c-body);
  text-decoration: none;
  text-align: left;
  box-shadow: var(--sh-pill);
}
/* a pill with a second line (state or copy value) is taller, so tails and tall letters of both lines keep
   3px from the stitch: label ink 15px over its baseline + 21.5px to the state's baseline + 5px of tail = 41.5px */
.link-tag:has(> .link-body > .link-state) { --pill-h: max(var(--link-h), 62px); }
.link-tag::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1.5px dashed var(--c-stitch);
  border-radius: var(--r-pill);
  pointer-events: none;
}
.link-dot {
  outline: 1.5px dashed var(--c-stitch); /* not focusable: the outline is free for the stitched ring */
  outline-offset: 1px;
  flex: none;
  display: grid;
  place-items: center;
  width: var(--link-dot);
  height: var(--link-dot);
  border-radius: 50%;
  background-color: var(--c-mocha-700);
  --sp-thread: var(--c-cream);
  --sp-fill: var(--c-cream);
  --sp-paper: var(--c-mocha-700);
}
.link-icon { width: var(--link-icon); height: var(--link-icon); }
/* the two lines are set on line-height 1 and lifted by the gap between their box and their ink
   (Patrick Hand's ink sits .15em under the middle of its line box), so the ink is centred in the pill */
.link-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-bottom: .3em;
}
/* both lines clip for the ellipsis; 4px of padding (taken back by the margins) keeps tails and tall letters
   inside the clip, which ends at the padding box */
.link-label {
  font-family: var(--font-label);
  font-size: var(--fs-link);
  font-weight: var(--label-bold);
  line-height: 1;
  color: var(--c-body);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-block: 4px;
  margin-block: -4px;
}
.link-state {
  font-family: var(--font-label);
  font-size: var(--fs-small);
  line-height: 1;
  color: var(--c-rose-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-block: 4px;
  margin-top: calc(.175em - 2.5px); /* baseline to baseline: 1em of label + .175em + 1.5px: the label's tails keep 3px from the state's tall letters */
  margin-bottom: -4px;
}
/* the "to fill" band covers the line, not the clip room above and below it */
.link-label.is-placeholder, .link-state.is-placeholder { background-clip: content-box; }
.link-tag.is-copied { border-color: var(--c-rose-300); }
.link-tag.is-copied .link-state { font-weight: var(--label-bold); text-decoration: none; background-color: transparent; }
.link-tag.is-unset { cursor: default; box-shadow: none; }
.copy-fallback,
.order .copy-fallback {
  display: block;
  width: 100%;
  min-height: var(--tap);
  margin-top: 8px;
  padding: 8px 14px;
  border: 2px solid var(--c-rose-300);
  border-radius: var(--r-chip);
  background-color: var(--c-lace);
  color: var(--c-body);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  font-size: 16px;
}
@media (min-width: 960px) {
  .link-list { gap: 7px; }
}

/* ---------- order: the main button. Petal cloth, cocoa outline, one cream seam stitched inside the edge (as on
   the active tab tile), big bold cocoa lettering, and a scalloped edge all the way round (two versions below).
   The button is a pill 2 x --order-r tall; a taller one (two lines, or a long label that wraps) keeps the same
   round corners and gets straight sides. The scallops need --rim-m of room outside the button: .order holds it,
   plus 2px on phones so the rim keeps 10px from the panel's stitch frame. ---------- */
.order {
  --order-r: 39px;        /* corner radius: R in scripts/make-scallop.cjs and RIM in js/links.mjs */
  --rim-m: 10px;          /* room for the scallops outside the button: M in the same two places */
  --rim-p: 9.741px;       /* one scallop on a straight run: P in the same two places */
  --order-sh: drop-shadow(0 1px 1px var(--c-cocoa-a12)) drop-shadow(0 5px 5px var(--c-cocoa-a22));
  --order-sh-hover: drop-shadow(0 3px 2px var(--c-cocoa-a12)) drop-shadow(0 10px 9px var(--c-cocoa-a22));
  --order-sh-pressed: drop-shadow(0 1px 1px var(--c-cocoa-a12)) drop-shadow(0 2px 2px var(--c-cocoa-a22));
  position: relative;
  margin-top: 15px;       /* 16px of air between the last pill and the scallop tips */
  padding: var(--rim-m) calc(var(--rim-m) + 2px);
}
.order-badge {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  /* js/links.mjs sets --order-h so the straight sides of a taller button hold a whole number of scallops */
  min-height: var(--order-h, calc(2 * var(--order-r)));
  padding: 6px 26px 8px;
  border: 2px solid var(--c-cocoa);
  border-radius: var(--order-r);
  background-color: var(--mat-petal-color);
  background-image: var(--mat-petal);
  background-size: var(--mat-petal-size);
  background-blend-mode: var(--mat-petal-blend);
  color: var(--c-cocoa-900);
  text-align: center;
  text-decoration: none;
  /* the shadow follows the scallops: a filter on the whole button (its lettering sits on opaque cloth, so the
     letters cast nothing that shows). The filter also makes the button the stacking context its rim paints in. */
  filter: var(--order-sh);
}
/* desktop: the label and its state line need more than a pill; one scallop more on each side */
@media (min-width: 960px) {
  .order-badge:has(> .order-state) { min-height: var(--order-h, calc(2 * var(--order-r) + var(--rim-p))); }
}
.order-badge::before {
  content: "";
  position: absolute;
  inset: 3px;
  z-index: 1;
  border: 2px dashed var(--c-lace);
  border-radius: calc(var(--order-r) - 5px); /* concentric with the outline: 2px outline + 3px */
  pointer-events: none;
}
.order-badge:focus-visible { outline-offset: calc(var(--rim-m) + 3px); } /* the ring goes round the scallops */
.order-label {
  display: block;
  position: relative;
  z-index: 2;
  max-width: 100%;
  font-family: var(--font-display);
  font-weight: 700;
  --letter-size: max(20px, var(--fs-badge));
  font-size: var(--letter-size);
  line-height: var(--display-lh);
  letter-spacing: calc(var(--display-track) * 1em);
  color: inherit;
  overflow-wrap: anywhere;
}
/* a long state (a copy value) wraps: line-height 1.4 keeps an accent of one line 3px from the tails of the line above */
.order-state {
  position: relative;
  z-index: 2;
  margin-top: 2px;
  font-family: var(--font-label);
  font-size: var(--fs-sub);
  font-weight: var(--label-bold);
  line-height: 1.4;
  overflow-wrap: anywhere;
  color: var(--c-cocoa-900);
}
.order-badge.is-copied .order-state { text-decoration: none; background-color: transparent; }
.order-badge.is-unset { cursor: default; }
.order-note {
  margin: 12px auto 0;    /* 12.75px of air under the scallop tips (10.75px while the button is pressed down) */
  font-family: var(--font-text);
  font-size: var(--fs-text-small);
  line-height: 1.4;       /* two lines: an accent keeps 3px from the tails above (1.2em of ink + 3px) */
  color: var(--c-body);
  text-align: center;
  text-wrap: balance;
}
@media (min-width: 960px) {
  .order { margin-top: 15px; padding-inline: var(--rim-m); }
}

/* ---------- the scalloped edge, in two versions (compared on the real page; the one not chosen gets deleted).
   Default: "scalloped cloth". <html data-order-rim="lace"> switches to "lace rim". ---------- */

/* ---------- version "scalloped cloth" (default): the petal cloth itself is cut in scallops and the cocoa outline
   follows them; no straight outline; the cream seam stays inside as a plain pill line. js/links.mjs computes the
   edge for the button's real size and sets it as --rim-clip (clip-path of the cloth layer) and as the outline path
   of svg.order-rim; until then (or without JavaScript) the button is the plain pill, on the same footprint. ---------- */
html:not([data-order-rim="lace"]) .order-badge.has-rim { border-color: transparent; background: none; }
html:not([data-order-rim="lace"]) .order-badge.has-rim::after {
  content: "";
  position: absolute;
  z-index: -2;
  inset: calc(-2px - var(--rim-m));
  background-color: var(--mat-petal-color);
  background-image: var(--mat-petal);
  background-size: var(--mat-petal-size);
  background-blend-mode: var(--mat-petal-blend);
  clip-path: var(--rim-clip);
  pointer-events: none;
}
.order-rim { display: none; }
html:not([data-order-rim="lace"]) .order-badge.has-rim > .order-rim {
  display: block;
  position: absolute;
  z-index: -1;
  top: calc(-2px - var(--rim-m));
  left: calc(-2px - var(--rim-m));
  max-width: none;        /* drawn 1:1 at the size js/links.mjs gives it, wider than the button */
  overflow: visible;
  fill: none;
  stroke: var(--c-cocoa);
  stroke-width: 1.5px;
  stroke-linejoin: round;
  pointer-events: none;
}

/* ---------- version "lace rim" (html[data-order-rim="lace"]): the button keeps its straight cocoa outline; a band
   of cream lace scallops with a fine cocoa outline runs round it. A nine-slice border-image from
   assets/trim/scallop.svg (drawn 1:1, corners R + M square, edges one scallop wide and repeated whole), pure CSS.
   The rim repeats the button's 2px outline under its inner edge, so the two meet without a hairline. ---------- */
html[data-order-rim="lace"] .order-badge::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: calc(-2px - var(--rim-m));
  border: calc(var(--order-r) + var(--rim-m)) solid transparent;
  /* slices drawn 1:1; the widths are .25px wider than the slices so that on a one-line pill the four corners fill the
     height exactly (scaled back by the browser) and pixel snapping never leaves a sliver of side edge to fill */
  border-image: url("../assets/trim/scallop.svg") 49 / calc(var(--order-r) + var(--rim-m) + .25px) round;
  pointer-events: none;
}

/* ---------- lettering set 2 (Borel): the label's box holds its ink (the Borel rule at the end of components.css:
   top edge 2px above the tallest ink, bottom edge 2px under the tails or the baseline). The seam's inner edge is
   7px inside the button (2px outline + 3px + 2px seam), so 11px of padding puts the ink 8px from the seam.
   The state line sits 3px or more under the label's ink and 3px or more over the seam. ---------- */
html[data-lettering="2"] .order-badge { padding: 11px 26px; }
/* the state's line box is .125em taller above and below than at line-height 1.15: margin and padding give it back, so
   a one-line state sits where it did */
html[data-lettering="2"] .order-badge:has(> .order-state) { padding-bottom: calc(10px - .125 * var(--fs-sub)); }
html[data-lettering="2"] .order-state { margin-top: calc(-1px - .125em); }
/* one line without tails: the box is centred on the ink, which puts the small letters low (the loops of d, h and !
   rise far above them); lifted .22em the small letters sit on the button's middle line and the loops keep 8px */
html[data-lettering="2"] .order-badge:not(:has(> .order-state)) > .order-label[data-tails="no"] { translate: 0 -.22em; }
/* desktop (32px): .2em, so the loops keep 8px from the seam by the font's own metrics too (canvas: 7.5px at .22em,
   8.2px at .2em; painted pixels 8.3 to 8.7px before), and the small letters stay within 1px of the middle line */
@media (min-width: 960px) {
  html[data-lettering="2"] .order-badge:not(:has(> .order-state)) > .order-label[data-tails="no"] { translate: 0 -.2em; }
}
