/* Sound selector: two sections of chips on a 3D "depth lens" (built by js/selector.js).
   Classes: .sel, .sel-head(.is-active), .sel-title, .sel-count, .sel-grid, .chip(.gloss0/.gloss1),
   .chip-fx, .chip-gloss, .chip-badge(.is-long), .chip-name, .sel-snap. Body classes: .intro, .calm.
   .chip rules are scoped under .sel so a .chip elsewhere in the app is not affected. */

.sel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* Room inside the panel for the lifted chip (scale + translateZ under perspective grows it by
     ~7 px a side and ~3 px top / bottom) and part of its shadow, so a scrolling or clipping panel
     does not cut it off. No top padding: the first heading sits above the chips. */
  padding: var(--sel-pad, 0 8px 16px);
  --sel-accent: rgb(238, 243, 248);
}
.sel,
.sel * { box-sizing: border-box; }

/* ---- section headings ---- */
.sel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.sel-grid + .sel-head { margin-top: 10px; }
.sel-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: rgba(238, 243, 248, .55);
  transition: color .5s;
}
.sel-head.is-active .sel-title { color: var(--sel-accent); }
.sel-count {
  font-size: 12px;
  font-weight: 600;
  color: rgba(238, 243, 248, .5);
}

/* ---- grid: 2 columns in a ~300 px panel, more when wider ---- */
.sel-grid {
  position: relative; /* offsetParent of the chips (js measures rows / columns from it) */
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
  gap: 8px;
  perspective: 900px;
}

/* ---- chips ---- */
.sel .chip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  height: 64px;
  margin: 0;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 18px;
  background-color: rgba(255, 255, 255, .03);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  /* --td: ripple delay, set per chip by js (0 unless the selection changed with animate) */
  transition: transform .7s cubic-bezier(.2, .9, .25, 1) var(--td, 0s), opacity .5s ease var(--td, 0s),
    border-color .4s, background-color .4s, box-shadow .4s;
}
.sel .chip[aria-pressed="true"] {
  border-color: var(--c);
  background-color: rgba(var(--c-rgb), .12);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .55), 0 0 32px rgba(var(--c-rgb), .27);
}
.sel .chip:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}
.sel .chip:not([aria-pressed="true"]):active { background-color: rgba(255, 255, 255, .08); }
@media (hover: hover) {
  .sel .chip:not([aria-pressed="true"]):hover { border-color: rgba(255, 255, 255, .2); }
}

.chip-badge {
  position: relative;
  flex: 0 0 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  border: 1.5px solid var(--c);
  color: var(--c-ink, var(--c)); /* the chip colour, lightened where needed for contrast (js) */
  background-color: transparent;
  transition: background-color .4s, color .4s;
}
.chip-badge.is-long { font-size: 10px; }
.sel .chip[aria-pressed="true"] .chip-badge {
  background-color: var(--c);
  color: #05070b;
}

.chip-name {
  position: relative;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  overflow-wrap: break-word;
}

/* Light band swept across a newly selected chip; rests outside the clip box. The band animates
   on the compositor, and Chromium does not round-clip it with overflow + border-radius inside a
   3D-transformed chip (square corners poke out), so the box also gets a rounded clip-path. It sits
   on this inner box, not on the chip, so the chip's shadow and focus ring are not clipped. */
.chip-fx {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  border-radius: 17px;
  overflow: hidden;
  clip-path: inset(0 round 17px);
  pointer-events: none;
}
.chip-gloss {
  position: absolute;
  top: -20%;
  bottom: -20%;
  left: 0;
  width: 36%;
  pointer-events: none;
  background: rgba(255, 255, 255, .16);
  transform: translateX(420%) skewX(-20deg);
}

@keyframes selGloss0 { from { transform: translateX(-160%) skewX(-20deg); } to { transform: translateX(420%) skewX(-20deg); } }
@keyframes selGloss1 { from { transform: translateX(-160%) skewX(-20deg); } to { transform: translateX(420%) skewX(-20deg); } }
@keyframes selGlossIntro { from { transform: translateX(-160%) skewX(-20deg); } to { transform: translateX(420%) skewX(-20deg); } }
/* Chips flip in from depth to their resting (inline) transform and opacity. */
@keyframes selChipIn { from { opacity: 0; transform: translateZ(-240px) rotateX(70deg); } }

/* ---- intro (body.intro): flip-in staggered by distance from the selection (--id), then a
   gloss on the selected chip once it has landed ---- */
.intro .sel .chip { animation: selChipIn .6s cubic-bezier(.2, .8, .2, 1) var(--id, 1.3s) backwards; }
.intro .sel .chip[aria-pressed="true"] .chip-gloss { animation: selGlossIntro .9s 1.75s cubic-bezier(.4, 0, .2, 1) backwards; }

/* ---- sound switch: gloss on the newly selected chip (after the intro rule, and more specific) ---- */
.sel .sel-grid .chip.gloss0 .chip-gloss { animation: selGloss0 .9s .35s cubic-bezier(.4, 0, .2, 1) backwards; }
.sel .sel-grid .chip.gloss1 .chip-gloss { animation: selGloss1 .9s .35s cubic-bezier(.4, 0, .2, 1) backwards; }

/* ---- instant change (select without animate) ---- */
.sel-snap .chip,
.sel-snap .chip-badge,
.sel-snap .sel-title { transition: none !important; }

/* ---- driving (body.calm): short, no delays, no gloss ---- */
.calm .sel .chip { transition-duration: .25s !important; transition-delay: 0s !important; }
.calm .sel .chip-badge,
.calm .sel .sel-title { transition-duration: .25s !important; }
/* js starts no gloss while calm; one already sweeping is hidden, not cancelled (animation: none
   would cancel it, and it would replay when calm ends). */
.calm .sel .chip-gloss { visibility: hidden; }

/* ---- reduced motion: flat, instant ---- */
@media (prefers-reduced-motion: reduce) {
  .sel-grid { perspective: none; }
  .sel .chip {
    transform: none !important;
    opacity: 1 !important;
    animation: none !important;
    transition: none !important;
  }
  .sel .chip-badge,
  .sel .sel-title { transition: none !important; }
  .sel .chip-gloss { display: none; }
}
