/* The alphabet index: a contacts list in a rounded frame on a white page (no phone around it), the letters of the
   alphabet down its right edge. The letters, the swollen track and the bubble are placed by the script. */
:root {
  --page: #ffffff;          /* the page */
  --card: #ffffff;          /* the frame of the list */
  --edge: #e9e9ee;          /* the frame's border, the lines between rows */
  --ink: #15161a;           /* names */
  --soft: #8a8c95;          /* secondary text */
  --accent: #2f5be8;        /* the letters of the index, the bubble */
  --empty: #c9cbd3;         /* the letters with no one under them */
  --head: #f6f7f9;          /* the letter headers in the list */
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

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

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.stage {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 24px 16px;
}

/* ---------------------------------------------------------------- the frame */
.book {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(384px, 100%);
  height: min(740px, calc(100svh - 48px));
  border-radius: 30px;
  background: var(--card);
  box-shadow: 0 0 0 1px var(--edge), 0 40px 70px -40px rgba(30, 40, 90, 0.35), 0 12px 24px -16px rgba(30, 40, 90, 0.18);
  overflow: hidden;
}

.book__head {
  padding: 26px 24px 12px;
  border-bottom: 1px solid var(--edge);
}

.book__title {
  margin: 0;
  font-size: 30px;
  font-weight: 760;
  letter-spacing: -0.025em;
  line-height: 1.1;
}

.book__sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--soft);
}

.book__body {
  position: relative;
  flex: 1;
  min-height: 0;
}

/* ---------------------------------------------------------------- the list */
.book__list {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  outline: none;
}

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

.book__list:focus-visible {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.book__shake {
  padding-bottom: 24px;
  will-change: transform;
}

.group__head {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0;
  padding: 5px 24px;
  background: var(--head);
  font-size: 12.5px;
  font-weight: 720;
  color: var(--accent);
  transition: background-color 0.5s ease, color 0.5s ease;
}

.group__head.is-hit {
  background: #dfe6fd;
  transition: none;
}

.group__rows {
  margin: 0;
  padding: 0;
  list-style: none;
}

.row {
  display: flex;
  align-items: center;
  gap: 13px;
  height: 58px;
  padding: 0 44px 0 20px;
  position: relative;
}

.row + .row::before {
  content: '';
  position: absolute;
  top: 0;
  left: 71px;
  right: 0;
  height: 1px;
  background: var(--edge);
}

/* initials in a rounded square, tinted from the name */
.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: hsl(var(--h) 70% 94%);
  color: hsl(var(--h) 45% 36%);
  box-shadow: inset 0 0 0 1px hsl(var(--h) 50% 86%);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.row__text {
  min-width: 0;
}

.row__name {
  display: block;
  font-size: 15.5px;
  font-weight: 430;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row__name b {
  font-weight: 700;
}

.row__note {
  display: block;
  margin-top: 1px;
  font-size: 12.5px;
  color: var(--soft);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- the index */
.index {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 40px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: ns-resize;
}

.index__track {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.index__track path {
  fill: rgba(255, 255, 255, 0.9);
  stroke: rgba(47, 91, 232, 0.16);
  stroke-width: 1;
}

.index__letters {
  position: absolute;
  inset: 0;
  outline: none;
}

.index__letters:focus-visible::before {
  content: '';
  position: absolute;
  left: 8px;
  right: 4px;
  top: var(--y0, 0);
  height: var(--span, 100%);
  border-radius: 10px;
  box-shadow: 0 0 0 2px var(--accent);
}

.letter {
  position: absolute;
  right: 6px;
  top: 0;
  width: 24px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  transform-origin: 100% 50%;
  will-change: transform;
}

.letter.is-empty {
  color: var(--empty);
}

.letter.is-now {
  color: #fff;
}

.letter__mark {
  position: absolute;
  inset: -3px 3px;
  border-radius: 5px;
  background: var(--accent);
  opacity: 0;
  z-index: -1;
}

.letter.is-now .letter__mark {
  opacity: 1;
}

@media (hover: hover) {
  .index:hover .letter:not(.is-empty) {
    color: #1e45c9;
  }
}

@media (hover: hover) {
  .index:hover .letter.is-now {
    color: #fff;
  }
}

/* ---------------------------------------------------------------- the bubble */
.bubble {
  position: absolute;
  top: 0;
  right: 0;
  width: 120px;
  height: 120px;
  margin: -60px 0 0;
  pointer-events: none;
  opacity: 0;
  will-change: transform, opacity;
}

.bubble__shape {
  position: absolute;
  inset: 0;
  overflow: visible;
}

.bubble__shape path {
  fill: var(--accent);
}

/* a soft shadow made of two blurred-looking copies, cheaper than a filter on a shape that scales every frame */
.bubble__shape .bubble__shadow {
  fill: rgba(30, 50, 140, 0.12);
  transform: translate(0, 6px) scale(1.06);
}

.bubble__shape .bubble__shadow + .bubble__shadow {
  fill: rgba(30, 50, 140, 0.08);
  transform: translate(0, 11px) scale(1.12);
}

.bubble__letter {
  position: absolute;
  left: 0;
  top: 0;
  width: 92px;
  height: 120px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 40px;
  font-weight: 760;
  line-height: 1;
}

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