/* The code that changes: a dark code block on a black page, the words coloured by what they are. */
:root {
  --page: #000000;          /* the page */
  --card: #111318;          /* the block */
  --edge: #23262f;
  --bar: #181b22;
  --ink: #e8ebf2;
  --muted: #7d8496;
  --accent: #ff8a3d;        /* the box, and a line that changes */
  --kw: #ff7ab6;            /* the colours of the code: words of the language, functions, names, text, figures, signs */
  --fn: #7cc4ff;
  --prop: #c9a2ff;
  --str: #a6e3a1;
  --num: #ffb86b;
  --pun: #8b93a7;
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Red Hat Mono Variable', ui-monospace, monospace;
  -webkit-font-smoothing: antialiased;
}

/* the block hangs from the top: the code grows and shrinks downwards and its tabs never move */
.stage {
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  align-content: start;
  padding: max(28px, 12vh) 16px 28px;
}

.snippet {
  width: min(580px, 100%);
  border: 1px solid var(--edge);
  border-radius: 20px;
  background: var(--card);
  overflow: hidden;
}

/* ---------------------------------------------------------------- the bar: the steps and Copy */
.snippet__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 10px 10px 12px;
  border-bottom: 1px solid var(--edge);
  background: var(--bar);
}

.steps {
  position: relative;
  display: flex;
  gap: 2px;
}

.steps__pill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  border-radius: 10px;
  background: #2a2e39;
  pointer-events: none;
}

.step {
  position: relative;
  padding: 7px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: 600 13.5px 'Red Hat Mono Variable', ui-monospace, monospace;
  cursor: pointer;
  transition: color 0.3s;
  -webkit-tap-highlight-color: transparent;
}

.step[aria-selected='true'] {
  color: var(--ink);
}

@media (hover: hover) {
  .step:hover {
    color: var(--ink);
  }
}

.copy {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px 7px 9px;
  border: 1px solid var(--edge);
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: 600 13px 'Red Hat Mono Variable', ui-monospace, monospace;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.3s, background-color 0.3s;
}

@media (hover: hover) {
  .copy:hover {
    background: #1f232c;
  }
}

.copy.is-done {
  border-color: rgba(166, 227, 161, 0.5);
}

.copy__icon {
  width: 17px;
  height: 17px;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.copy__tick {
  stroke: var(--str);
  stroke-width: 2.4;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

/* the word that rolls from Copy to Copied */
.copy__label {
  display: inline-block;
  overflow: hidden;
  min-width: 6.2ch;
  text-align: left;
}

.copy__label > span {
  display: inline-block;
}

/* ---------------------------------------------------------------- the code */
.code {
  position: relative;
  margin: 0;
  padding: 18px 20px 20px;
  overflow-x: auto;
  overflow-y: hidden;
  font-size: 14px;
  line-height: 1.75;
  white-space: pre;
  tab-size: 2;
  scrollbar-width: none;
}

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

.code code {
  font: inherit;
}

/* a line: a block of its own, so a line that changes can light up from edge to edge */
.ln {
  display: block;
  min-height: 1.75em;
  margin: 0 -20px;
  padding: 0 20px;
}

/* a word of the code: inline-block, because a transform does not move an inline element */
.tk {
  display: inline-block;
  transition: color 0.4s;
}

.tk--kw { color: var(--kw); }
.tk--fn { color: var(--fn); }
.tk--prop { color: var(--prop); }
.tk--str { color: var(--str); }
.tk--num { color: var(--num); }
.tk--pun { color: var(--pun); }
.tk--id { color: var(--ink); }

/* the words that leave fade where they were, in a layer of their own */
.code__gone {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.code__gone .tk {
  position: absolute;
}

/* ---------------------------------------------------------------- the result */
.result {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 14px 16px;
  border-top: 1px solid var(--edge);
  background: #0c0d11;
}

.result__label {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.result__track {
  position: relative;
  height: 56px;
  border-radius: 12px;
  background: repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.045) 0 1px, transparent 1px 40px);
}

.box {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
}

.run {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--edge);
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  .run:hover {
    background: #1a1d24;
  }
}

.run svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.result__error {
  position: absolute;
  left: 16px;
  bottom: 18px;
  margin: 0;
  color: #ff8b8b;
  font-size: 12.5px;
  font-weight: 600;
}

.step:focus-visible,
.copy:focus-visible,
.run:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

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

@media (max-width: 480px) {
  .code {
    padding: 16px 16px 18px;
    font-size: 13px;
  }

  .ln {
    margin: 0 -16px;
    padding: 0 16px;
  }
}

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