/* The tag field: a white field on a white page with soft coloured tags in it, a list of suggestions under it
   while typing. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #1f1d1a;
  --muted: #85817a;
  --line: #e3dfd7;
  --hover: #f3f1ec;
  --bad: #c9442f;
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
}

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

/* held from the top: the suggestions open downwards and the field grows downwards */
.stage {
  min-height: 100svh;
  display: grid;
  justify-items: center;
  align-content: start;
  padding: clamp(40px, 24vh, 230px) 16px 40px;
}

.tags {
  width: min(480px, 100%);
}

.tags__label {
  display: block;
  margin: 0 0 10px 4px;
  font-size: 15px;
  font-weight: 650;
}

.tags__box {
  position: relative;
}

.tags__field {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-height: 58px;
  padding: 10px;
  border-radius: 18px;
  background: #ffffff;
  box-shadow: inset 0 0 0 1.5px var(--line);
  cursor: text;
  transition: box-shadow 0.25s;
}

.tags__field:focus-within,
.tags__field.is-pretend {
  box-shadow: inset 0 0 0 1.5px var(--ink), 0 0 0 5px rgba(31, 29, 26, 0.07);
}

/* the list of tags lays its tags out in the field, next to the input */
.tags__list {
  display: contents;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* ---------------------------------------------------------------- a tag */
.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 36px;
  padding: 0 5px 0 14px;
  border-radius: 18px;
  color: var(--chip-ink);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}

/* the colour is a layer of its own, so it can grow round the words */
.chip__bg {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--chip-bg);
}

.chip__text,
.chip__x {
  position: relative;
}

.chip__x {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  .chip__x:hover {
    background: rgba(31, 29, 26, 0.09);
  }
}

.chip__x:focus-visible {
  outline: 2px solid var(--chip-ink);
  outline-offset: 1px;
}

.chip__x svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}

/* the last tag, ready to go at the next backspace */
.chip.is-armed .chip__bg {
  box-shadow: inset 0 0 0 2px var(--chip-ink);
}

/* ---------------------------------------------------------------- the input */
.tags__input {
  flex: 1 0 120px;
  min-width: 120px;
  height: 36px;
  padding: 0 6px;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font: 500 16px 'Rethink Sans Variable', system-ui, sans-serif;
}

.tags__input::placeholder {
  color: var(--muted);
}

/* ---------------------------------------------------------------- the suggestions */
.tags__options {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 8px);
  z-index: 5;
  margin: 0;
  padding: 6px;
  list-style: none;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(31, 29, 26, 0.06), 0 18px 40px -14px rgba(31, 29, 26, 0.3);
  transform-origin: 50% 0;
}

.option {
  display: flex;
  align-items: center;
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 15px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.option[aria-selected='true'] {
  background: var(--hover);
}

.option b {
  font-weight: 750;
}

/* ---------------------------------------------------------------- the line under the field */
.tags__hint {
  margin: 12px 4px 0;
  font-size: 14px;
  color: var(--muted);
  transition: color 0.25s;
}

.tags__hint.is-bad {
  color: var(--bad);
}

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