/* Buttons: plain pills, and the hand-drawn ones the site uses. data-state holds a button in one of its
   states without the cursor on it, to show it. */

/* Registered so the gradient and label can transition between states */
@property --btn-spread {
  syntax: '<percentage>';
  inherits: true;
  initial-value: 60%;
}

@property --btn-label-top {
  syntax: '<color>';
  inherits: true;
  initial-value: transparent;
}

@property --btn-label-bottom {
  syntax: '<color>';
  inherits: true;
  initial-value: transparent;
}

.btn-primary,
.btn-secondary {
  --btn-light: 0.08s ease-out;
  --btn-move: 0.16s cubic-bezier(0.3, 1.6, 0.6, 1);
  width: auto;
  height: 40px;
  padding: 4px 16px;
  border-radius: 20px;
  font-size: var(--font-size-body);
  line-height: var(--line-height-body);
  letter-spacing: var(--letter-spacing-body);
  color: transparent;
  text-shadow: none;
  overflow: visible;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform var(--btn-move),
    box-shadow var(--btn-light),
    --btn-spread var(--btn-light),
    --btn-label-top var(--btn-light),
    --btn-label-bottom var(--btn-light);
}

.btn-primary:hover,
.btn-primary:active,
.btn-secondary:hover,
.btn-secondary:active {
  filter: none;
}

/* Press lands fast, then the button springs back */
.btn-primary:active,
.btn-primary[data-state='pressed'],
.btn-secondary:active,
.btn-secondary[data-state='pressed'] {
  --btn-light: 0.04s ease-out;
  --btn-move: 0.04s ease-out;
  transform: scale(0.98);
}

/* A gradient can't transition to another one, so the pressed gradient fades in on top.
   This also holds the 4px hit area: the transparent border reaches past the button and catches
   the cursor, while the gradient stays inside it. The radius is the button's 20px plus those 4px. */
.btn-primary::before,
.btn-secondary::before {
  content: '';
  position: absolute;
  inset: -4px;
  border: 4px solid transparent;
  border-radius: 24px;
  opacity: 0;
  transition: opacity var(--btn-light);
}

.btn-primary:active::before,
.btn-primary[data-state='pressed']::before,
.btn-secondary:active::before,
.btn-secondary[data-state='pressed']::before {
  opacity: 1;
}

.btn-primary::after,
.btn-secondary::after {
  transition: box-shadow var(--btn-light);
}

/* The shadow is a filter because text-shadow would paint over a clipped gradient.
   The secondary label fades across its capitals, which sit from 6px to 18px of the 24px line. */
.btn-label {
  background: linear-gradient(var(--btn-label-top) var(--btn-label-start), var(--btn-label-bottom) 17.6px);
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(var(--btn-label-shadow));
  transition: filter var(--btn-light);
}

/* Trims the label to its capitals. The fill stops at the box,
   so the padding gives descenders like the y in "my" somewhere to paint. */
@supports (text-box-trim: trim-both) {
  .btn-label {
    text-box-trim: trim-both;
    text-box-edge: cap alphabetic;
    padding-block: 6px;
  }
}

/* Primary */
.btn-primary {
  --btn-green: var(--color-accent);
  --btn-glow: #00B87A;
  --btn-spread: 60%;
  --btn-label-start: 6px;
  --btn-label-top: var(--color-white);
  --btn-label-bottom: var(--color-white);
  --btn-label-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.24);
  background: radial-gradient(100% 100% at 50% 0, var(--btn-glow) 0%, var(--btn-green) var(--btn-spread));
  box-shadow: 0px 2px 2px -1px rgba(0, 0, 0, 0.08);
}

.btn-primary::before {
  background: radial-gradient(100% 100% at 50% 0, var(--btn-green) 20%, var(--btn-glow) 100%) padding-box;
}

.btn-primary::after {
  box-shadow:
    inset 0px -1px 0px 0px rgba(0, 0, 0, 0.12),
    inset 0px 0px 0px 1px var(--btn-green),
    inset 0px 0px 1px 2px rgba(255, 255, 255, 0.06),
    inset 0px -8px 8px -6px rgba(255, 244, 83, 0.5);
}

.btn-primary:hover,
.btn-primary[data-state='hover'] {
  --btn-spread: 90%;
  box-shadow:
    0px 2px 2px -1px rgba(0, 0, 0, 0.08),
    0px 8px 8px -4px rgba(0, 153, 102, 0.24);
}

.btn-primary:active,
.btn-primary[data-state='pressed'] {
  --btn-label-top: rgba(255, 255, 255, 0.9);
  --btn-label-bottom: rgba(255, 255, 255, 0.9);
  --btn-label-shadow: 0 0 transparent;
  box-shadow: 0px 1px 0px 0px var(--color-white);
}

.btn-primary:active::after,
.btn-primary[data-state='pressed']::after {
  box-shadow:
    inset 0px 1px 0px 0px rgba(0, 0, 0, 0.12),
    inset 0px 0px 0px 1px var(--btn-green),
    inset 0px -8px 8px -6px rgba(255, 244, 83, 0.5);
}

/* Secondary */
.btn-secondary {
  --btn-spread: 60%;
  --btn-label-start: 6px;
  --btn-label-top: color-mix(in srgb, var(--color-text-primary) 65%, transparent);
  --btn-label-bottom: color-mix(in srgb, var(--color-text-primary) 85%, transparent);
  --btn-label-shadow: 0 1px 0.5px var(--color-white);
  background: radial-gradient(100% 100% at 50% 0, var(--color-white) 0%, #EDEDED var(--btn-spread));
  box-shadow: 0px 2px 2px -1px rgba(0, 0, 0, 0.06);
}

.btn-secondary::before {
  background: radial-gradient(100% 100% at 50% 0, #EDEDED 20%, var(--color-white) 100%) padding-box;
}

.btn-secondary::after {
  box-shadow:
    inset 0px -1px 0px 0px rgba(0, 0, 0, 0.08),
    inset 0px 0px 0px 1px rgba(0, 0, 0, 0.12),
    inset 0px 0px 0px 1px var(--color-white),
    inset 0px -8px 8px -4px rgba(255, 255, 255, 0.5),
    inset 0px 0px 1px 2px rgba(0, 0, 0, 0.02);
}

.btn-secondary:hover,
.btn-secondary[data-state='hover'] {
  --btn-spread: 90%;
  --btn-label-top: color-mix(in srgb, var(--color-text-primary) 85%, transparent);
  box-shadow:
    0px 2px 2px -1px rgba(0, 0, 0, 0.06),
    0px 8px 8px -4px rgba(0, 0, 0, 0.06);
}

.btn-secondary:active,
.btn-secondary[data-state='pressed'] {
  --btn-label-top: color-mix(in srgb, var(--color-text-primary) 90%, transparent);
  --btn-label-bottom: color-mix(in srgb, var(--color-text-primary) 90%, transparent);
  --btn-label-shadow: 0 0 transparent;
  box-shadow: 0px 1px 0px 0px var(--color-white);
}

.btn-secondary:active::after,
.btn-secondary[data-state='pressed']::after {
  box-shadow:
    inset 0px 1px 0px 0px rgba(0, 0, 0, 0.08),
    inset 0px 0px 0px 1px rgba(0, 0, 0, 0.12),
    inset 0px -8px 8px -4px rgba(255, 255, 255, 0.5);
}

/* Hand-drawn. kit/sketch.js fills in the marks behind the label.
   The fills stay opaque, because the ink filter drops anything see-through. */
.btn-drawn {
  --btn-move: 0.16s cubic-bezier(0.3, 1.6, 0.6, 1);
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 20px;
  border: 0;
  background: none;
  font-family: var(--font-body);
  font-weight: var(--font-weight-body);
  font-size: var(--font-size-body);
  line-height: var(--line-height-body);
  letter-spacing: var(--letter-spacing-body);
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform var(--btn-move);
}

.btn-drawn:active,
.btn-drawn[data-state='pressed'] {
  --btn-move: 0.04s ease-out;
  transform: scale(0.98);
}

/* The same 4px hit area as the other buttons */
.btn-drawn::before {
  content: '';
  position: absolute;
  inset: -4px;
}

.btn-drawn > span {
  filter: var(--ink);
}

/* A hand-drawn icon beside the label, in its color. It sits inside the label, so it gets the same ink
   edge and moves with the face. The 16px frame is the icon's whole height. */
.btn-icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-left: 6px;
  vertical-align: -3px;
  /* 90% of the label's color, mixed toward the button's fill rather than see-through: the ink edge turns
     see-through ink back to solid and punches holes in it */
  background: color-mix(in srgb, currentColor 90%, var(--btn-drawn-fill, transparent));
  mask: var(--btn-icon) center / contain no-repeat;
}

/* The icon's side gets 2px less. Its drawing sits 1px inside the frame and ends in a thin pen line,
   so equal padding looks roomier there. Icons follow the label, so that's the right. */
.btn-drawn:has(.btn-icon) {
  padding-right: 18px;
}

.btn-icon-copy {
  --btn-icon: url('/kit/copy.svg');
}

/* What a copy button's icon changes to once it's copied (kit/buttons.js) */
.btn-icon-check {
  --btn-icon: url('/kit/check.svg');
}

.btn-drawn-marks {
  position: absolute;
  inset: -8px;
  z-index: -1;
  width: calc(100% + 16px);
  height: calc(100% + 16px);
  pointer-events: none;
  /* The marker thins out over the paper's raised grain. sketch.js lines this up with the sheet.
     A mask cuts off anything past its box, so this one is 8px bigger than the button on every side. */
  mask: url('/kit/marker-grain.png') 0 0 / 512px 512px;
}

.btn-drawn-marks path {
  fill: none;
  stroke: var(--btn-drawn-fill);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: var(--ink-marker);
}

/* Where strokes overlap, the ink builds up. See-through only after the filter has run, which would drop it. */
.btn-drawn-pass {
  opacity: var(--btn-drawn-build);
}

.btn-drawn-pass path {
  stroke: var(--btn-drawn-wet);
}

/* Ink can't get darker than text-primary here, so one pass is lighter and overlaps build up to it */
.btn-drawn-primary {
  --btn-drawn-fill: color-mix(in srgb, var(--color-text-primary) 80%, var(--color-background));
  --btn-drawn-wet: var(--color-text-primary);
  --btn-drawn-build: 0.3;
  color: var(--color-background);
}

/* The light green the green buttons mix in, kept apart from the link highlight's, so a change to the
   highlight leaves the buttons and their label contrast as they are */
.btn-drawn-accent,
.btn-shaded-primary {
  --btn-green-light: #3DF2B6;
}

/* One pass is brighter than accent and overlaps are darker, so the average lands on accent.
   Lightened with a light green, because paper white dulls the green. */
.btn-drawn-accent {
  --btn-drawn-fill: color-mix(in srgb, var(--color-accent) 84%, var(--btn-green-light));
  --btn-drawn-wet: color-mix(in oklab, var(--color-accent), black 20%);
  --btn-drawn-build: 0.26;
  color: var(--color-background);
}

/* One grey for both: the pill's #EDEDED taken a touch toward the ink, or the shaded one's white glow
   has nothing to stand out from */
.btn-drawn-secondary,
.btn-shaded-secondary {
  --btn-drawn-fill: color-mix(in srgb, #EDEDED, var(--color-text-primary) 7%);
  --btn-drawn-wet: color-mix(in oklab, #EDEDED, var(--color-text-primary) 20%);
  --btn-drawn-build: 0.13;
  color: var(--color-text-primary);
}

/* Without a glow, the texture is the overlaps, so they're stronger here */
.btn-drawn-secondary {
  --btn-drawn-wet: color-mix(in oklab, var(--btn-drawn-fill), var(--color-text-primary) 35%);
}

/* Shaded: the pill buttons, drawn by hand. kit/sketch.js adds the glow, the darker base, a pen rim
   and a gel pen shine on top of the usual marker fill. */
.btn-shade-glow {
  opacity: var(--btn-shade-glow-strength);
}

.btn-shade-glow path {
  stroke: var(--btn-shade-glow);
}

.btn-shade-base {
  opacity: 0.22;
}

.btn-shade-base path {
  stroke: var(--btn-shade-base);
}

.btn-drawn-marks .btn-shade-rim {
  stroke: var(--btn-shade-rim);
  stroke-width: 1.5;
  filter: var(--ink);
}

.btn-drawn-marks .btn-shade-shine {
  stroke: var(--btn-shade-shine);
  stroke-width: 2;
  filter: var(--ink);
  opacity: 0.85;
}

/* Everything is drawn from one green, a little lighter than accent, so its darker bottom sits at the
   pill's tone. Lighten or darken the whole button there, and the rim, glow and shading keep their places. */
.btn-shaded-primary {
  --btn-shade-green: color-mix(in srgb, var(--color-accent) 80%, var(--btn-green-light));
  --btn-drawn-fill: var(--btn-shade-green);
  --btn-drawn-wet: color-mix(in oklab, var(--btn-shade-green), black 20%);
  --btn-drawn-build: 0.2;
  --btn-shade-glow: color-mix(in srgb, var(--btn-shade-green) 55%, var(--btn-green-light));
  --btn-shade-glow-strength: 0.45;
  --btn-shade-base: color-mix(in oklab, var(--btn-shade-green), black 35%);
  --btn-shade-rim: color-mix(in oklab, var(--btn-shade-green), black 30%);
  --btn-shade-shine: var(--color-white);
  color: var(--color-white);
}

/* v2, the one the site uses: the glow stops partway down the letters and the green is a touch darker than
   v1's, so white on it measures about 3.2:1. The rim takes less black, so the darker green doesn't make it
   heavy. */
.btn-shaded-primary.btn-shaded-v2 {
  --btn-shade-green: color-mix(in srgb, var(--color-accent) 90%, var(--btn-green-light));
  --btn-shade-glow-reach: 0.7;
  --btn-shade-rim: color-mix(in oklab, var(--btn-shade-green), black 22%);
}

.btn-shaded-secondary {
  --btn-shade-glow: var(--color-white);
  --btn-shade-glow-strength: 0.4; /* Stronger, and white strokes sit on the light grey as blotches */
  --btn-shade-base: color-mix(in oklab, #EDEDED, var(--color-text-primary) 25%);
  --btn-shade-rim: color-mix(in srgb, var(--color-text-primary) 30%, var(--color-background));
  --btn-shade-shine: var(--color-white);
}

/* The logo, drawn over the original by kit/sketch.js in the primary hand-drawn button's marker. The
   original stays, unseen, for screen readers and in case the script doesn't run, and it's written on
   the paper like the text, so it gets the letters' ink edge. A block, so its box is its own 32px, not a
   line of text with room for descenders under it. */
.logo {
  display: block;
  width: 32px;
  height: 32px;
}

/* A finer marker than a button's, in scale with the logo, and gone over more, so it holds its own as a mark.
   At this size the marker's bleed blurs it, so it takes the letters' ink edge instead. */
.logo-drawn {
  position: relative;
  isolation: isolate;
  --btn-drawn-fill: color-mix(in srgb, var(--color-text-primary) 90%, var(--color-background));
  --btn-drawn-build: 0.45;
}

.logo-drawn > .logo {
  filter: var(--ink);
}

.logo-drawn:has(> .btn-drawn-marks) > .logo {
  opacity: 0;
}

.logo-drawn .btn-drawn-marks path {
  stroke-width: 2.4;
  filter: var(--ink);
}

.logo-drawn .btn-drawn-marks .logo-line {
  stroke-width: 2;
}

/* The same 4px hit area as the links */
.logo-drawn::before {
  content: '';
  position: absolute;
  inset: -4px;
}
