/* The interlocking line-up: a white field on a white page, with the players chosen as jigsaw pieces locked into
   each other, one colour for every section of the band; a list of instruments under it while choosing. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #1d1b24;           /* the words */
  --muted: #67636f;         /* the hint, the sections in the list, the placeholder */
  --line: #dad7e0;          /* the field's border */
  --bad: #b5390f;           /* the hint when something can't be done */
  --seam: #ffffff;          /* the cut between two pieces */
  --rhythm: #ff9e85;        /* drums and bass */
  --rhythm-ink: #4d1708;
  --strings: #ffcc5c;       /* guitars and strings */
  --strings-ink: #4a3200;
  --keys: #86d6c4;          /* keyboards */
  --keys-ink: #0c3b32;
  --voice: #c3b4ff;         /* singers */
  --voice-ink: #2c1c69;
  --winds: #aedb82;         /* horns and winds */
  --winds-ink: #213c0c;
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
}

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

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

.band {
  width: min(460px, 100%);
  /* room for the list when it is open, so that the field with its list sits in the middle of a frame round it */
  padding-bottom: 84px;
}

.band__label {
  display: block;
  margin: 0 0 10px 2px;
  font-size: 16px;
  font-weight: 650;
  line-height: 20px;
  letter-spacing: -0.01em;
}

.band__box {
  position: relative;
}

/* ---------------------------------------------------------------- the field */
.band__field {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  align-content: flex-start;
  row-gap: 8px;
  min-height: 60px;
  padding: 8px;
  border-radius: 16px;
  background: var(--page);
  box-shadow: inset 0 0 0 1.5px var(--line);
  cursor: text;
  transition: box-shadow 0.2s ease;
}

.band__field:focus-within,
.band__field.is-pretend {
  box-shadow: inset 0 0 0 1.5px var(--ink), 0 0 0 4px rgba(29, 27, 36, 0.08);
}

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

/* ---------------------------------------------------------------- a piece */
.piece {
  position: relative;
  flex: none;
  height: 44px;
}

/* in the air, a piece passes over everything, the list included */
.piece:focus-within {
  z-index: 2;
}

.piece.is-up {
  z-index: 6;
}

.piece.is-up .piece__x {
  transition: none;
}

/* the piece is the button that takes it away; the script moves the piece, the css moves the button */
.piece__btn {
  position: relative;
  display: flex;
  align-items: center;
  height: 100%;
  margin: 0;
  padding: 0 12px 0 calc(var(--knob, 16px) + 10px);
  border: 0;
  background: none;
  color: var(--p-ink);
  font: 600 15px/1 'Gabarito Variable', system-ui, sans-serif;
  letter-spacing: -0.005em;
  white-space: nowrap;
  cursor: pointer;
  outline: none;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  -webkit-tap-highlight-color: transparent;
}

/* a finger gets a little more than the piece */
.piece__btn::after {
  content: '';
  position: absolute;
  inset: -2px 0;
}

.piece__btn:disabled {
  cursor: default;
}

.piece__shape {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.piece__shadow {
  fill: rgba(42, 24, 52, 0.34);
  opacity: 0;
}

.piece__fill {
  fill: var(--fill);
  stroke: var(--seam);
  stroke-width: 1.5;
  stroke-linejoin: round;
}

.piece__ring {
  fill: none;
  stroke: var(--p-ink);
  stroke-width: 2;
  stroke-linejoin: round;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.piece__btn:focus-visible .piece__ring,
.piece.is-armed .piece__ring {
  opacity: 1;
}

.piece__name,
.piece__x {
  position: relative;
}

.piece__x {
  flex: none;
  width: 14px;
  height: 14px;
  margin-left: 8px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  opacity: 0.55;
  transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.piece.is-armed .piece__x,
.piece__btn:focus-visible .piece__x {
  opacity: 1;
}

/* under the pointer a piece comes loose from its neighbours */
@media (hover: hover) {
  .piece__btn:not(:disabled):hover {
    transform: translateY(-2px);
  }

  .piece__btn:not(:disabled):hover .piece__x {
    opacity: 1;
    transform: rotate(90deg);
  }
}

.piece__btn:not(:disabled):active {
  transform: translateY(0) scale(0.96);
  transition-duration: 0.12s;
}

/* ---------------------------------------------------------------- the input */
.band__input {
  flex: 1 0 140px;
  min-width: 0;
  height: 44px;
  margin: 0 0 0 calc(var(--knob, 16px) + 6px);
  padding: 0 8px;
  border: 0;
  border-radius: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font: 500 16px/1 'Gabarito Variable', system-ui, sans-serif;
  -webkit-appearance: none;
  appearance: none;
}

/* at the start of a line there is no tab to clear */
.band__input.is-alone {
  margin-left: 0;
}

.band__input::placeholder {
  color: var(--muted);
  opacity: 1;
}

/* ---------------------------------------------------------------- the list */
.pop {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 8px);
  z-index: 5;
  padding: 6px;
  border-radius: 16px;
  background: var(--page);
  box-shadow: 0 0 0 1px rgba(29, 27, 36, 0.07), 0 18px 40px -14px rgba(29, 27, 36, 0.32);
  transform-origin: 50% 0;
}

.pop__note {
  margin: 0;
  padding: 10px 12px 8px;
  font-size: 14px;
  line-height: 20px;
  color: var(--muted);
}

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

.pop__list {
  max-height: 242px;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  scrollbar-width: thin;
}

/* more rows further down: the last one seen fades out */
.pop__list.has-more {
  -webkit-mask-image: linear-gradient(180deg, #000 calc(100% - 36px), transparent);
  mask-image: linear-gradient(180deg, #000 calc(100% - 36px), transparent);
}

.opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 44px;
  padding: 0 14px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

.opt b {
  font-weight: 750;
}

.opt__sec {
  flex: none;
  font-size: 13px;
  color: var(--muted);
}

/* the line-up is full: the instruments are still there, quieter */
.opt[aria-disabled='true'] .opt__name {
  color: var(--muted);
}

/* ---------------------------------------------------------------- the line under the field */
.band__hint {
  margin: 12px 2px 0;
  font-size: 14px;
  line-height: 20px;
  color: var(--muted);
  transition: color 0.25s ease;
}

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

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

.defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}
