/* =========================================================================
   Picker — command-palette-style modal for concept / character selection.
   Themed with the four-element CSS variables already on :root /
   [data-theme="..."] (--bg, --bg-elevated, --bg-input, --border,
   --border-hover, --accent, --accent-soft, --grad, --text, --text-muted,
   --text-dim). Drop these rules at the bottom of style.css.
   ========================================================================= */

/* ---------- Overlay ----------
   Translucent, blurred backdrop sitting above everything else on the page.
   Pinned to the corners with `inset: 0`. Uses CSS Grid as the centering
   mechanism so the modal can grow tall without losing horizontal centering. */
.picker-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: start center;
  padding: 8vh 1rem 1rem;
  background: color-mix(in oklab, var(--bg) 70%, transparent);
  -webkit-backdrop-filter: blur(6px);
          backdrop-filter: blur(6px);
  animation: picker-fade 0.16s ease-out;
}
@keyframes picker-fade { from { opacity: 0; } to { opacity: 1; } }
.picker-overlay[hidden] { display: none; }

/* ---------- Modal shell ----------
   Reuses .output-card's silhouette: rounded box on --bg-elevated, with a
   thin 2px gradient seam at the top (the same gradient that fills H1 and
   the mode-toggle underline elsewhere). */
.picker-modal {
  width: 100%;
  max-width: 680px;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  position: relative;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.35),
    0 2px 10px rgba(0, 0, 0, 0.18);
  animation: picker-pop 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.picker-modal::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--grad);
  z-index: 1;
}
@keyframes picker-pop {
  from { transform: translateY(-6px) scale(0.985); opacity: 0; }
  to   { transform: none;                          opacity: 1; }
}

/* ---------- Header row (search + actions) ---------- */
.picker-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 12px 16px;
  border-bottom: 1px solid var(--border);
}
.picker-search-icon {
  width: 16px;
  height: 16px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.picker-search {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  padding: 6px 4px;
  min-width: 0;
}
.picker-search::placeholder { color: var(--text-dim); }

/* Small always-on hint that sits under the search row. It calls out the
   gating rule for custom (user-typed) entries — dropdown picks are
   pre-vetted and don't go through any check. */
.picker-hint-text {
  padding: 6px 16px 8px;
  font-size: 11px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.02em;
}

/* "Surprise me" lives inside the search row, styled like an inline chip */
.picker-action.picker-surprise {
  padding: 6px 11px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.picker-action.picker-surprise:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.picker-action.picker-surprise kbd,
.picker-hint kbd,
.picker-empty kbd {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-elevated);
  color: var(--text-dim);
  border: 1px solid var(--border);
  line-height: 1.4;
}

/* Close button mirrors the search-action chip but squarer */
.picker-close {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  font-size: 18px;
  line-height: 1;
  transition: color 0.12s, border-color 0.12s;
}
.picker-close:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ---------- Scrollable list ---------- */
.picker-list {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.picker-list::-webkit-scrollbar { width: 10px; }
.picker-list::-webkit-scrollbar-track { background: transparent; }
.picker-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
  border: 2px solid var(--bg-elevated);
}

/* ---------- Group blocks ----------
   Each unit/category gets a small uppercase header and a count, with a
   thin hairline trailing into the empty space (`::after`). The "Recent"
   group gets the accent color on its label + a soft gradient hairline so
   it visually pops at the top. */
.picker-group + .picker-group { margin-top: 18px; }

.picker-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}
.picker-group-header::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.picker-group-count {
  color: var(--text-dim);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

.picker-group.is-recent .picker-group-header { color: var(--accent); }
.picker-group.is-recent .picker-group-header::after {
  background: linear-gradient(90deg,
              color-mix(in oklab, var(--accent) 40%, transparent),
              transparent);
  height: 2px;
}

/* ---------- Grid of item cards ---------- */
.picker-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.picker-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  min-height: 42px;
  transition: border-color 0.12s, background 0.12s, color 0.12s,
              transform 0.05s;
}
.picker-item:hover {
  border-color: var(--border-hover);
  background: var(--bg-elevated);
}
.picker-item.is-highlighted {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.picker-item:active { transform: translateY(1px); }

.picker-item-name {
  font-weight: 500;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Per-card tag in the top-right (the small "Hot/recent/Unit 1" labels
   from the sketch). It shows the group/category for normal results and
   "recent" for items pulled from localStorage. */
.picker-item-tag {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-dim);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.picker-item.is-highlighted .picker-item-tag {
  border-color: var(--accent);
  color: var(--accent);
  background: transparent;
}
.picker-item.is-recent .picker-item-tag {
  color: var(--accent);
  border-color: color-mix(in oklab, var(--accent) 35%, transparent);
  background: var(--accent-soft);
}

/* Match-highlight inside the name during live search */
.picker-item mark {
  background: var(--accent-soft);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}
.picker-item.is-highlighted mark {
  background: transparent;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Utility items (Custom…, "Use exactly …") get a dashed border + italic
   so they read as "actions" rather than concrete picks. */
.picker-item.is-utility {
  border-style: dashed;
  font-style: italic;
  color: var(--text-muted);
}
.picker-item.is-utility .picker-item-name { font-weight: 500; }
.picker-item.is-utility.is-highlighted {
  border-style: solid;
  color: var(--accent);
  font-style: normal;
}

/* Subtle ⏎ glyph on the highlighted card so users know Enter activates */
.picker-item.is-highlighted::after {
  content: '⏎';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--accent);
  opacity: 0.55;
}
.picker-item.is-highlighted .picker-item-tag {
  /* hide the tag when ⏎ is showing so they don't collide */
  visibility: hidden;
}

.picker-empty {
  padding: 28px 12px 32px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.6;
}
.picker-empty strong {
  display: block;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 600;
}

/* ---------- Footer (keyboard hints + type label) ---------- */
.picker-footer {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  font-size: 11px;
  color: var(--text-dim);
  flex-wrap: wrap;
}
.picker-type-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.picker-spacer { flex: 1; }
.picker-hint {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* ---------- Optional: picker-trigger button ----------
   A drop-in replacement for the old <select> chips that pops the picker
   open. Style mirrors the existing `select` rule so the sentence-builder
   row keeps its rhythm. Use it on <button class="picker-trigger"> — the
   inline ▾ caret is supplied by ::after. */
.picker-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  font-size: 15px;
  font-family: inherit;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  border-radius: 7px;
  cursor: pointer;
  min-width: 180px;
  /* Cap the width so a long custom pick truncates (label has ellipsis)
     instead of stretching the button and wrapping the sentence builder. */
  max-width: 260px;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.picker-trigger:hover  { border-color: var(--border-hover); }
.picker-trigger:focus,
.picker-trigger.is-open { border-color: var(--accent); outline: none; }
.picker-trigger .picker-trigger-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Placeholder state — fades the label when no pick has been made yet */
.picker-trigger[data-empty="true"] .picker-trigger-label { color: var(--text-dim); }
.picker-trigger::after {
  content: '▾';
  color: var(--text-muted);
  font-size: 10px;
  flex-shrink: 0;
}

/* ---------- Narrow screens ----------
   Collapse the grid to a single column; trim less-essential header chrome
   so the search input stays usable on phones. */
@media (max-width: 560px) {
  .picker-overlay { padding-top: 4vh; }
  .picker-modal { max-height: 92vh; border-radius: 12px; }
  .picker-grid { grid-template-columns: 1fr; }
  .picker-action.picker-surprise kbd { display: none; }
  .picker-action.picker-surprise { padding: 6px 9px; }
  .picker-footer .picker-hint { display: none; }
  .picker-footer .picker-hint:first-of-type { display: inline-flex; }
  /* Let the trigger fill the stacked sentence-builder row on phones. */
  .picker-trigger { max-width: none; width: 100%; min-width: 0; }
}
