/* ─── KodeshWay.org search ────────────────────────────────────
   Beautiful, animated, candle-light skeleton.
   Trigger sits in the primary nav; ⌘K / Ctrl+K / "/" opens the
   overlay; Esc closes; arrows navigate; Enter opens.
*/

/* ─── Trigger ─────────────────────────────────────────────── */

/* Nav anchors the search button absolutely on the right so the
   primary nav links stay perfectly centered. */
nav.nav { position: relative; }
.nav-search {
  position: absolute;
  right: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.35rem 0.7rem 0.35rem 0.55rem;
  color: var(--text-soft);
  font-family: var(--font-display);
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  cursor: pointer;
  transition:
    border-color 0.25s var(--ease),
    color 0.25s var(--ease),
    background 0.25s var(--ease),
    box-shadow 0.25s var(--ease);
}
@media (min-width: 720px) {
  .nav-search { right: var(--space-3); }
}
@media (max-width: 720px) {
  /* On narrow screens, nav wraps multiple lines; pin search to the
     top-right of the first row so it doesn't drift below. */
  .nav-search {
    top: 0.5rem;
    transform: none;
  }
}
.nav-search:hover, .nav-search:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(205, 70, 35, 0.06);
  box-shadow: 0 0 18px rgba(205, 70, 35, 0.22);
  outline: none;
}
.nav-search__icon {
  flex: 0 0 auto;
  opacity: 0.85;
}
.nav-search__label {
  font-weight: 500;
}
.nav-search__kbd {
  font-family: 'SF Mono', 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.58rem;
  letter-spacing: 0.04em;
  padding: 0.08rem 0.35rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.25);
}
@media (max-width: 640px) {
  .nav-search__label, .nav-search__kbd { display: none; }
  .nav-search { padding: 0.4rem; }
}

/* ─── Overlay shell ───────────────────────────────────────── */

body.search-open { overflow: hidden; }

.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 1.25rem 1.25rem;
}
.search-overlay[hidden] { display: none; }

.search-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 6, 3, 0.78);
  backdrop-filter: blur(14px) saturate(120%);
  -webkit-backdrop-filter: blur(14px) saturate(120%);
  opacity: 0;
  transition: opacity 0.22s var(--ease, cubic-bezier(0.2, 0.8, 0.2, 1));
}
.search-overlay[data-state="open"] .search-backdrop { opacity: 1; }
.search-overlay[data-state="closing"] .search-backdrop { opacity: 0; }

/* ─── Panel ───────────────────────────────────────────────── */

.search-panel {
  position: relative;
  width: 100%;
  max-width: 640px;
  background:
    radial-gradient(ellipse at 100% 0%, rgba(205, 70, 35, 0.16) 0%, transparent 55%),
    var(--bg-card, #17130b);
  border: 1px solid var(--rule);
  border-radius: 16px;
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 220, 180, 0.04);
  overflow: hidden;
  transform: scale(0.96) translateY(-12px);
  opacity: 0;
  transition:
    transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1),
    opacity 0.22s ease;
}
.search-overlay[data-state="open"] .search-panel {
  transform: scale(1) translateY(0);
  opacity: 1;
}
.search-overlay[data-state="closing"] .search-panel {
  transform: scale(0.97) translateY(-8px);
  opacity: 0;
}

/* ─── Input ───────────────────────────────────────────────── */

.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1.1rem 1.25rem 1.05rem;
  border-bottom: 1px solid var(--rule);
}
.search-input__icon {
  flex: 0 0 auto;
  color: var(--accent);
  opacity: 0.8;
}
.search-input {
  flex: 1 1 auto;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1.15rem;
  line-height: 1.4;
  letter-spacing: 0.005em;
  caret-color: var(--accent);
  padding: 0;
}
.search-input::placeholder {
  color: var(--text-dim);
  font-style: italic;
}
.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}
.search-input__close {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.25rem 0.55rem;
  cursor: pointer;
  transition: border-color 0.2s var(--ease), color 0.2s var(--ease);
}
.search-input__close:hover {
  border-color: var(--accent);
}
.search-input__close kbd {
  font-family: 'SF Mono', ui-monospace, monospace;
  font-size: 0.62rem;
  color: var(--text-soft);
  letter-spacing: 0.05em;
}

/* ─── Results scroll area ─────────────────────────────────── */

.search-results {
  max-height: 60vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.5rem 0.5rem 0.85rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(205, 70, 35, 0.3) transparent;
}
.search-results::-webkit-scrollbar { width: 6px; }
.search-results::-webkit-scrollbar-thumb {
  background: rgba(205, 70, 35, 0.3);
  border-radius: 999px;
}

/* ─── Idle / empty ────────────────────────────────────────── */

.search-empty {
  padding: 2rem 1rem 2.4rem;
  text-align: center;
}
.search-empty__title {
  font-family: var(--font-display);
  font-size: 0.7rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 0.6rem;
}
.search-empty__line {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 1rem;
  color: var(--text-soft);
  margin: 0;
  line-height: 1.55;
}

/* ─── Result card ─────────────────────────────────────────── */

.search-result {
  --i: 0;
  display: block;
  padding: 0.85rem 1rem 0.95rem;
  margin: 0.25rem 0.45rem;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  border-left: 2px solid transparent;
  transition:
    background 0.2s var(--ease),
    border-color 0.2s var(--ease),
    transform 0.2s var(--ease);
  opacity: 0;
  transform: translateY(6px);
  animation: search-result-in 0.32s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  animation-delay: calc(var(--i, 0) * 0.035s);
}
@keyframes search-result-in {
  to { opacity: 1; transform: translateY(0); }
}
.search-result:hover, .search-result.is-active {
  background: rgba(205, 70, 35, 0.08);
  border-left-color: var(--accent);
}
.search-result__eyebrow {
  display: block;
  font-family: var(--font-display);
  font-size: 0.58rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.3rem;
}
.search-result__title {
  display: block;
  font-family: var(--font-headline);
  font-weight: 500;
  font-size: 1.08rem;
  line-height: 1.3;
  color: var(--text);
  margin: 0 0 0.35rem;
  letter-spacing: 0.005em;
}
.search-result__snippet {
  display: block;
  font-family: var(--font-prose);
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--text-soft);
  margin: 0;
}
.search-result mark {
  background: rgba(205, 70, 35, 0.22);
  color: var(--accent-bright);
  padding: 0 0.12em;
  border-radius: 2px;
  font-weight: 500;
}

/* ─── Skeleton — iOS candle-light port ────────────────────── */
/*
   Each bar is a small placeholder with:
     • base = card-surface (warm dark parchment)
     • warm-fill overlay = kodeshWayGold @ 10% alpha
     • radial halo overlay = kodeshWayGold 22% → 0%
   Both overlays share a 1.3s half-cycle ease-in-out alternate
   pulse (2.6s total) — opacity 0 → 1 — staggered 0.18s per row
   so the column reads as a row of candles catching light.
   Matches KodeshWaySkeletonView.swift exactly.
*/

.search-skeleton {
  --i: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 1rem 1.1rem 1.05rem;
  margin: 0.4rem 0.45rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid var(--rule);
  opacity: 0;
  animation: search-result-in 0.3s ease forwards;
  animation-delay: calc(var(--i, 0) * 0.06s);
}
.search-skeleton__bar {
  position: relative;
  display: block;
  background: #17130b; /* kodeshWayCardSurface */
  border-radius: 4px;
  overflow: hidden;
  isolation: isolate;
}
.search-skeleton__bar::before,
.search-skeleton__bar::after {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  animation: candle-pulse 3.6s ease-in-out infinite alternate;
  animation-delay: calc(var(--i, 0) * 0.22s);
  will-change: opacity;
}
/* Warm fill — kodeshWayGold #A8742A @ 10% */
.search-skeleton__bar::before {
  background: rgba(168, 116, 42, 0.10);
  z-index: 0;
}
/* Radial glow halo — kodeshWayGold @ 22% → 0% */
.search-skeleton__bar::after {
  background: radial-gradient(
    ellipse at 50% 50%,
    rgba(168, 116, 42, 0.22) 0%,
    rgba(168, 116, 42, 0) 70%
  );
  z-index: 1;
}
.search-skeleton__bar--eye   { width: 30%; height: 0.55rem; }
.search-skeleton__bar--title { width: 65%; height: 0.95rem; }
.search-skeleton__bar--text  { width: 92%; height: 0.7rem; }

@keyframes candle-pulse {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ─── Section flash — when arriving from a search result, the
   target section briefly catches a crimson candle-light to confirm
   the destination. */
.section-flash {
  animation: section-flash 1.8s cubic-bezier(0.2, 0.7, 0.1, 1) 1;
  border-radius: 14px;
}
@keyframes section-flash {
  0%   { box-shadow: 0 0 0 0 rgba(205, 70, 35, 0); }
  18%  { box-shadow: 0 0 60px 4px rgba(205, 70, 35, 0.55); }
  100% { box-shadow: 0 0 0 0 rgba(205, 70, 35, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .section-flash { animation: none; }
}

/* Smooth-scroll only inside this site (don't fight the user's setting
   on long pages — scoped via :where for low specificity). */
:where(html) { scroll-behavior: smooth; }

/* ─── Footer meta ─────────────────────────────────────────── */

.search-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1.1rem;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 0.75rem 0.85rem;
  border-top: 1px solid var(--rule);
  font-family: var(--font-display);
  font-size: 0.55rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.search-meta kbd {
  display: inline-block;
  font-family: 'SF Mono', ui-monospace, monospace;
  font-size: 0.58rem;
  letter-spacing: 0.04em;
  padding: 0.08rem 0.32rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  margin: 0 0.18rem 0 0;
  text-transform: none;
  color: var(--text-soft);
  background: rgba(0, 0, 0, 0.3);
}

/* ─── Reduced motion — honor the system preference ───────── */

@media (prefers-reduced-motion: reduce) {
  .search-skeleton__bar::before,
  .search-skeleton__bar::after {
    animation: none;
    opacity: 0.5;
  }
  .search-result {
    animation: none;
    opacity: 1;
    transform: none;
  }
  .search-overlay[data-state="open"] .search-panel,
  .search-panel {
    transition: none;
  }
}
