/* Avatar builder ------------------------------------------------------- */
/* The account's Avatar tab: the avatar large beside a tab per layer, and
   under the tabs a gallery in which every thumbnail is the whole avatar with
   that one part swapped. Every picture is a stack of the six 32x32 layer
   files drawn over each other at a whole multiple of 32, never smoothed —
   the same stack the shop composes into one file on save. On a phone the
   preview goes first and stays small enough to keep the gallery in view. */
.avatar-builder {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-6);
}

@media (min-width: 820px) {
  .avatar-builder {
    grid-template-columns: 18rem minmax(0, 1fr);
    align-items: start;
  }
}

.avatar-builder__preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-6);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

@media (min-width: 820px) {
  .avatar-builder__preview {
    position: sticky;
    top: calc(4rem + var(--space-6));
  }
}

/* On a phone the preview is a row — the avatar at 128, the buttons beside
   it — so the gallery starts on the first screen instead of under a 256 px
   picture. 128 is the next whole multiple of 32 down. */
@media (max-width: 819px) {
  .avatar-builder__preview {
    display: grid;
    grid-template-columns: 128px minmax(0, 1fr);
    align-items: center;
    padding: var(--space-4);
  }

  .avatar-builder__preview .avatar-stack--256 {
    width: 128px;
    height: 128px;
    border-radius: var(--radius-md);
  }

  .avatar-builder__actions {
    flex-direction: column;
  }

  .avatar-builder__status {
    grid-column: 1 / -1;
    min-height: 0;
  }

  .avatar-builder__status:empty {
    display: none;
  }
}

.avatar-builder__actions {
  display: flex;
  gap: var(--space-2);
  width: 100%;
}

.avatar-builder__actions > * {
  flex: 1;
}

.avatar-builder__status {
  min-height: 1.4em;
  margin: 0;
  color: var(--success);
  font-weight: 700;
  font-size: var(--text-sm);
}

.avatar-builder__picker {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}

.avatar-builder__tabs {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding: 2px 2px var(--space-2);
  scrollbar-width: none;
}

.avatar-builder__tabs::-webkit-scrollbar {
  display: none;
}

.avatar-builder__tab {
  flex: none;
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink-soft);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.avatar-builder__tab[aria-selected="true"] {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}

.avatar-builder__panel {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.avatar-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
  gap: var(--space-3);
}

.avatar-option {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.avatar-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.avatar-option:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
}

.avatar-option:has(input:checked) {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft), var(--glow-pink);
}

.avatar-option:has(input:focus-visible) {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.avatar-option__name {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--ink-soft);
  line-height: 1.25;
}

/* A stack: the six layer pictures over each other, bottom first. The
   modifier is its side, a whole multiple of 32. */
.avatar-stack {
  position: relative;
  display: block;
  flex: none;
  margin-inline: auto;
  overflow: hidden;
  border-radius: var(--radius-md);
}

.avatar-stack img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.avatar-stack--96 {
  width: 96px;
  height: 96px;
}

.avatar-stack--256 {
  width: 256px;
  height: 256px;
  max-width: 100%;
  border-radius: var(--radius-lg);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}

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

  .avatar-option:hover {
    transform: none;
  }
}
