/* css/palette.css: Ctrl/Cmd+K search palette. Native <dialog> (top layer), Dewy Lab look. */

dialog.pal {
  --pal-ease: cubic-bezier(.16, 1, .3, 1); /* ease-out-expo */
  --pal-sheen: rgba(255, 255, 255, .75);
  --pal-sheen: light-dark(rgba(255, 255, 255, .75), rgba(255, 255, 255, .07));
  position: fixed;
  inset: 0 0 auto 0;
  margin: 0 auto;
  width: 100%;
  max-width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font);
  overflow: visible;
}
dialog.pal:not([open]) { display: none; }

.pal-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  max-height: min(84dvh, 640px);
  padding-top: env(safe-area-inset-top);
  overflow: hidden;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 24px 24px;
  background:
    radial-gradient(26rem 9rem at 0% 0%, var(--halo-a, rgba(255, 62, 157, .3)), transparent 70%),
    radial-gradient(22rem 9rem at 100% 0%, var(--halo-b, rgba(214, 200, 255, .4)), transparent 70%),
    var(--card);
  box-shadow: 0 1px 0 var(--pal-sheen) inset, 0 28px 60px -24px rgba(42, 15, 44, .45), 0 10px 24px -14px rgba(194, 0, 106, .3);
}
/* glossy top highlight */
.pal-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 74px;
  background: linear-gradient(180deg, var(--pal-sheen), transparent);
  pointer-events: none;
  opacity: .55;
}

.pal-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 12px 18px;
  border-bottom: 1px solid var(--hair, var(--line));
}
.pal-glass { display: grid; place-items: center; color: var(--accent-ink); flex: none; }
.pal-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1.15rem; /* >= 16px keeps iOS from zooming */
  font-weight: 560;
  letter-spacing: -.01em;
  outline: none;
}
.pal-input::placeholder { color: var(--mute); font-weight: 450; opacity: 1; }
.pal-head:has(.pal-input:focus-visible) .pal-glass { filter: drop-shadow(0 0 8px color-mix(in srgb, var(--accent) 60%, transparent)); }
.pal-x {
  flex: none;
  min-width: 44px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--mute);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: pointer;
}
.pal-x:hover { color: var(--ink); border-color: var(--accent-ink); }

.pal-body { position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 8px 8px; scroll-padding-block: 40px 8px; }
.pal-list[hidden], .pal-empty[hidden] { display: none; }

.pal-gh {
  position: sticky;
  top: -4px;
  z-index: 1;
  padding: 10px 10px 4px;
  background: linear-gradient(var(--card) 70%, transparent);
  color: var(--mute);
  font-size: .72rem;
  font-weight: 750;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.pal-opt {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 8px 12px;
  border-radius: 14px;
  cursor: pointer;
  scroll-margin-top: 34px;
}
.pal-opt.is-active {
  background: color-mix(in srgb, var(--accent) 13%, var(--card));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 38%, transparent) inset, 0 6px 14px -10px rgba(194, 0, 106, .5);
}
.pal-opt.is-active::before {
  content: "";
  position: absolute;
  left: 0; top: 12px; bottom: 12px;
  width: 3px;
  border-radius: 3px;
  background: var(--accent);
}
.pal-ico {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: var(--soft);
  color: var(--accent-ink);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
}
.pal-opt.is-active .pal-ico { background: var(--card); }
.pal-txt { flex: 1; min-width: 0; display: grid; gap: 1px; }
.pal-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; letter-spacing: -.005em; }
.pal-sub {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--mute);
  font-size: .82rem;
  line-height: 1.4;
}
.pal-via {
  display: inline-block;
  margin-right: 6px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--lav);
  color: var(--lav-ink);
  font-size: .74rem;
  font-weight: 700;
}
.pal-hl { background: color-mix(in srgb, var(--accent) 30%, transparent); color: inherit; border-radius: 4px; padding: 0 1px; font-weight: 800; }
.pal-via .pal-hl { background: color-mix(in srgb, var(--lav-ink) 24%, transparent); }
.pal-go { flex: none; color: var(--accent-ink); font-weight: 800; opacity: 0; transition: opacity .12s; }
.pal-opt.is-active .pal-go { opacity: 1; }

.pal-empty { padding: 12px 10px 6px; }
.pal-empty-t { margin: 0 0 14px; font-weight: 650; }
.pal-sug-t { margin: 0 0 8px; padding: 0 2px; color: var(--mute); font-size: .78rem; font-weight: 700; letter-spacing: .04em; }
.pal-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.pal-chip {
  min-height: 40px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .2s var(--pal-ease), border-color .2s;
}
.pal-chip:hover { transform: translateY(-2px); border-color: var(--accent-ink); }

.pal-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 9px 18px 10px;
  border-top: 1px solid var(--hair, var(--line));
  background: color-mix(in srgb, var(--soft) 55%, var(--card));
  color: var(--mute);
  font-size: .76rem;
}
.pal-hint { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.pal-foot .kbd { min-width: 20px; text-align: center; background: var(--card); }
@media (pointer: coarse) { .pal-foot { display: none; } }

.pal-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- desktop: centred 640px card ---------- */
@media (min-width: 680px) {
  dialog.pal { top: min(13vh, 120px); inset-inline: 0; width: min(640px, calc(100vw - 32px)); max-width: 640px; }
  .pal-panel { padding-top: 0; border-top: 1px solid var(--line); border-radius: 24px; max-height: min(70dvh, 560px); }
}

/* ---------- 320px ---------- */
@media (max-width: 380px) {
  .pal-head { padding: 10px 10px 8px 14px; gap: 6px; }
  .pal-input { font-size: 1rem; }
  .pal-opt { gap: 10px; padding: 8px; }
  .pal-ico { width: 30px; height: 30px; }
  .pal-x { min-width: 40px; padding: 0 6px; }
}

/* ---------- motion ---------- */
dialog.pal::backdrop {
  background: rgba(31, 26, 23, .42);
  backdrop-filter: blur(6px) saturate(1.1);
}
:root:has(dialog.pal[open]) { overflow: hidden; scrollbar-gutter: stable; }

@keyframes pal-in { from { opacity: 0; transform: translateY(-14px) scale(.965); } }
@keyframes pal-out { to { opacity: 0; transform: translateY(-8px) scale(.985); } }
@keyframes pal-fade { from { opacity: 0; } }
@keyframes pal-row { from { opacity: 0; transform: translateY(6px); } }

dialog.pal[open] { animation: pal-in .3s var(--pal-ease); }
dialog.pal[open]::backdrop { animation: pal-fade .24s ease-out; }
dialog.pal.closing { animation: pal-out .15s ease-in forwards; }
dialog.pal.closing::backdrop { opacity: 0; transition: opacity .15s ease-in; }
.pal-list.stagger .pal-opt { animation: pal-row .26s var(--pal-ease) both; animation-delay: calc(var(--i, 0) * 12ms); } /* <= 120 ms spread */

@media (prefers-reduced-motion: reduce) {
  dialog.pal[open], dialog.pal[open]::backdrop, dialog.pal.closing, .pal-list.stagger .pal-opt { animation: none !important; }
  .pal-chip, .pal-go { transition: none; }
  .pal-chip:hover { transform: none; }
}

@media (forced-colors: active) {
  .pal-opt.is-active { outline: 2px solid Highlight; }
  .pal-hl { background: Highlight; color: HighlightText; }
}
