.asset-picker {
  position: relative;
  display: block;
}

.ap-trigger {
  width: 100%;
  display: grid;
  grid-template-columns: 32px 1fr 16px;
  gap: 8px;
  align-items: center;
  padding: 5px 8px;
  background: #0c0d10;
  border: 1px solid #2f3236;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  border-radius: 2px;
  min-height: 34px;
}
.ap-trigger:hover { border-color: var(--accent); }
.ap-trigger:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(212,210,202,0.2); }

.ap-thumb {
  width: 32px; height: 32px;
  background: #1e2024;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  border: 1px solid var(--panel-border);
  image-rendering: crisp-edges;
}
.ap-thumb--empty::after {
  content: '?';
  display: flex;
  align-items: center; justify-content: center;
  height: 100%;
  color: var(--text-dim);
  font-size: 14px;
  font-style: italic;
}

.ap-trigger-label {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text);
}
.ap-caret { color: var(--text-dim); font-size: 10px; }

/* Backdrop — dims the page behind the drawer + catches outside clicks
   so they close it.  Lower z-index than the drawer itself. */
.ap-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: ap-backdrop-in 0.18s ease-out;
}
.ap-backdrop.is-open { display: block; }

.ap-popup {
  /* Bottom-docked drawer: full width, lower 70% of viewport. Tall
     enough that you actually see a useful number of tiles without
     scrolling. */
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 70vh;
  z-index: 1000;
  background: linear-gradient(180deg, #1a1d20 0%, #14171a 100%);
  border-top: 2px solid var(--accent);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.75);
  padding: 22px 32px 24px;
  flex-direction: column;
  gap: 12px;
}
.ap-popup.is-open {
  display: flex;
  animation: ap-slide-up 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes ap-slide-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
@keyframes ap-backdrop-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Drag-handle bar at the top — pure decoration, hints "this is a sheet". */
.ap-popup::before {
  content: '';
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 48px;
  height: 4px;
  border-radius: 2px;
  background: #3c3f43;
}

.ap-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 10px;
}
.ap-close:hover { color: var(--accent); }
.ap-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  color: var(--accent);
}

/* Focus rings for the rest of the picker controls — keyboard users had
   no visible indication of where they were before this. */
.ap-chip:focus-visible,
.ap-clear:focus-visible,
.ap-tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}
.ap-tile:focus-visible {
  /* Tiles are visual; an outline alone gets lost in a busy grid. Add
     a subtle inner glow so the focused thumbnail pops. */
  box-shadow: 0 0 0 1px var(--accent), 0 0 12px rgba(212, 210, 202, 0.35);
}

.ap-popup-head {
  display: grid; grid-template-columns: 1fr auto; gap: 10px;
  margin-bottom: 10px;
  max-width: 720px;
}
.ap-search {
  padding: 10px 14px;
  font-size: 14px;
  background: #0c0d10;
  border: 1px solid #2f3236;
  color: var(--text);
  border-radius: 4px;
}
.ap-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(212,210,202,0.18); }
.ap-clear {
  padding: 8px 14px;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid #2f3236;
  border-radius: 4px;
  cursor: pointer; font-size: 14px;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.ap-clear:hover { color: var(--danger); border-color: var(--danger); }

.ap-categories {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 10px;
  max-height: 110px; overflow-y: auto;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.ap-chip {
  padding: 6px 12px;
  font-size: 11px;
  letter-spacing: 0.8px;
  background: #0c0d10;
  color: var(--text-dim);
  border: 1px solid #2f3236;
  border-radius: 14px;
  cursor: pointer;
  text-transform: uppercase;
  font-weight: 600;
  transition: color 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}
.ap-chip:hover { border-color: var(--accent); color: var(--text); }
.ap-chip.is-active {
  background: var(--accent-dim);
  color: #16181b;
  border-color: var(--accent);
}

.ap-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  /* Roomier cells — 110px minimum gives the 80px thumbnail breathing
     room and lets multi-word labels fit on one line. */
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  padding: 4px 4px 8px;
}
.ap-grid::-webkit-scrollbar { width: 10px; }
.ap-grid::-webkit-scrollbar-thumb { background: #2f3236; border-radius: 5px; }

.ap-tile {
  display: flex; flex-direction: column;
  align-items: center;
  padding: 10px 6px 8px;
  gap: 6px;
  background: #0c0d10;
  border: 1px solid #2f3236;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  transition: border-color 0.12s ease, background 0.12s ease, transform 0.08s ease;
}
.ap-tile:hover {
  border-color: var(--accent);
  background: #1a1d20;
  transform: translateY(-1px);
}
.ap-tile:active { transform: translateY(0); }
.ap-tile-img {
  width: 80px; height: 80px;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  image-rendering: crisp-edges;
}
.ap-tile-label {
  font-size: 11px;
  color: var(--text);
  text-align: center;
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.15px;
}

.ap-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  font-style: italic;
}
