/* The copy button: a dark snippet with an install command and its Copy button, on a white page. The characters that
   fly into the clipboard keep the colours of their tokens. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #17171a;           /* the words */
  --snippet: #121216;       /* the snippet */
  --prompt: #5d5d68;        /* the $ before the command */
  --bin: #f4f4f6;           /* the program: npm, pnpm, yarn */
  --verb: #b6a8ff;          /* install, add */
  --pkg: #7ff0c4;           /* the package */
  --liquid: #7ff0c4;        /* what fills the clipboard */
  --button: #e9e9ee;        /* the Copy button's words and icon */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Geist Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

p,
figure,
pre {
  margin: 0;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.stage {
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: 64px 16px;
}

/* ---------------------------------------------------------------- the snippet */
.snippet {
  width: min(560px, 100%);
  overflow: hidden;
  border-radius: 14px;
  background: var(--snippet);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.9),
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 2px 4px rgba(18, 18, 22, 0.12),
    0 22px 44px -22px rgba(18, 18, 22, 0.55);
}

/* the command and its Copy button, on one row */
.snippet__row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px 0 0;
}

/* the Copy button: a quiet button with a fine edge that lights up under the pointer */
.copy {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px 0 10px;
  border: 0;
  border-radius: 10px;
  background: #1d1d23;
  box-shadow: inset 0 0 0 1px #2c2c34, inset 0 1px 0 rgba(255, 255, 255, 0.05);
  color: var(--button);
  font-family: 'Geist Mono Variable', ui-monospace, monospace;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.2s, transform 0.35s cubic-bezier(0.3, 1.6, 0.5, 1);
}

.copy::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.09);
  opacity: 0;
  transition: opacity 0.2s;
}

@media (hover: hover) {
  .copy:hover {
    background: #25252c;
  }

  .copy:hover::before {
    opacity: 1;
  }

  /* the clip of the board lifts a little, as if about to open */
  .copy:hover .copy__clip {
    transform: translateY(-0.8px);
  }
}

.copy:active {
  transform: scale(0.95);
  transition-duration: 0.1s;
}

.copy.is-done {
  color: var(--liquid);
}

.copy__icon {
  width: 24px;
  height: 24px;
  overflow: visible;
}

.copy__line,
.copy__clip {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
}

.copy__clip {
  fill: #1d1d23;
  transition: transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1);
}

.copy__liquid {
  fill: var(--liquid);
}

.copy__tick {
  fill: none;
  stroke: var(--liquid);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

[data-board] {
  transform-box: view-box;
  transform-origin: 12px 13px;
}

/* the label: two words, Copy and Copied, written by the script one character at a time */
.copy__label {
  display: block;
  width: 4ch;
  overflow: hidden;
  white-space: pre;
  text-align: left;
  transition: width 0.4s cubic-bezier(0.3, 1.3, 0.5, 1);
}

.copy:focus-visible {
  outline: 2px solid var(--pkg);
  outline-offset: 2px;
}

html[data-using='pointer'] .copy:focus-visible {
  outline: none;
}

/* the command, one span per character so that each can fly; the dark room above it is where they arc on their way
   to the clipboard (above the snippet the white ones would vanish on the page) */
.snippet__code {
  flex: 1;
  min-width: 0;
  padding: 48px 0 48px 20px;
  overflow-x: auto;
  color: var(--bin);
  font-family: 'Geist Mono Variable', ui-monospace, monospace;
  font-size: 16px;
  line-height: 1.6;
  scrollbar-width: none;
}

.snippet__code::-webkit-scrollbar {
  display: none;
}

.snippet__code code {
  font: inherit;
  white-space: pre;
}

.tok--prompt {
  color: var(--prompt);
  user-select: none;
  -webkit-user-select: none;
}

.ch {
  display: inline-block;
  white-space: pre;
}

.ch--bin {
  color: var(--bin);
}

.ch--verb {
  color: var(--verb);
}

.ch--pkg {
  color: var(--pkg);
}

/* ---------------------------------------------------------------- the characters in flight */
.flight {
  position: fixed;
  inset: 0;
  z-index: 5;
  overflow: hidden;
  pointer-events: none;
}

.flight canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.flier {
  position: absolute;
  left: 0;
  top: 0;
  font-family: 'Geist Mono Variable', ui-monospace, monospace;
  font-size: 16px;
  line-height: 1;
  white-space: pre;
  will-change: transform, opacity;
}

/* ---------------------------------------------------------------- reduced motion */
@media (prefers-reduced-motion: reduce) {
  .copy__label {
    transition: none;
  }

  .copy:active {
    transform: none;
  }

  @media (hover: hover) {
    .copy:hover .copy__clip {
      transform: none;
    }
  }
}

/* ---------------------------------------------------------------- phone */
@media (max-width: 480px) {
  .snippet__row {
    padding-right: 10px;
    gap: 8px;
  }

  .snippet__code {
    padding: 44px 0 44px 14px;
    font-size: 13.5px;
  }

  .copy {
    height: 38px;
    padding: 0 11px 0 8px;
    gap: 6px;
    font-size: 12.5px;
  }

}
