/* =============================================================================
   DIGITAL GARDEN SEARCH (assets/js/garden-search.js, _includes/garden-search.html)
   A search-box trigger (sidebar + /digital-garden/) and a centred dialog with
   ranked results. Black / white / Aptos like the rest of the garden skin;
   loaded by the same gate as css/digital-garden.css.
   ========================================================================== */

/* ---- trigger: looks like a search box ---- */

body.theme-typesafe.dg-garden .site-shell .dg-search-trigger {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  margin: 0 0 1.2rem;
  padding: 0.62rem 0.75rem;
  background: #0b0b0b;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.6);
  font-family: var(--dg-sans);
  font-size: 0.9rem;
  text-align: left;
  cursor: text;
  transition: border-color 0.2s ease, color 0.2s ease;
}

body.theme-typesafe.dg-garden .site-shell .dg-search-trigger[hidden] {
  display: none;
}

body.theme-typesafe.dg-garden .site-shell .dg-search-trigger:hover,
body.theme-typesafe.dg-garden .site-shell .dg-search-trigger:focus-visible {
  border-color: #ffffff;
  color: #ffffff;
  outline: none;
}

body.theme-typesafe.dg-garden .dg-search-icon {
  flex: none;
}

body.theme-typesafe.dg-garden .dg-search-placeholder {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

body.theme-typesafe.dg-garden .dg-search-kbd,
body.theme-typesafe.dg-garden .dg-search-help kbd,
body.theme-typesafe.dg-garden .dg-search-esc {
  font-family: var(--dg-sans);
  font-size: 0.72rem;
  line-height: 1;
  padding: 0.22rem 0.42rem;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 4px;
  background: #161616;
  color: rgba(255, 255, 255, 0.75);
}

/* On the /digital-garden/ landing page the box sits under the hero text. */
body.theme-typesafe.dg-garden .dg-hero .dg-search-trigger {
  max-width: 560px;
  margin: 1.8rem 0 0;
  padding: 0.85rem 1rem;
  font-size: 1rem;
}

/* ---- dialog ---- */

html.dg-search-open {
  overflow: hidden;
}

.dg-search-dialog {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: min(10vh, 6rem) 1rem 1rem;
  font-family: "Aptos", "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
}

.dg-search-dialog[hidden] {
  display: none;
}

.dg-search-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(3px);
}

.dg-search-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(720px, 100%);
  max-height: min(78vh, 760px);
  background: #0b0b0b;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 12px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
  overflow: hidden;
  color: #ffffff;
}

.dg-search-field {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.95rem 1.1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.7);
}

.dg-search-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: none;
  color: #ffffff;
  font: inherit;
  font-size: 1.08rem;
}

.dg-search-input::placeholder {
  color: rgba(255, 255, 255, 0.42);
}

.dg-search-input::-webkit-search-cancel-button {
  display: none;
}

.dg-search-esc {
  cursor: pointer;
}

.dg-search-status {
  margin: 0;
  padding: 0.7rem 1.1rem 0.2rem;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.55);
}

.dg-search-status:empty {
  display: none;
}

.dg-search-results {
  list-style: none;
  margin: 0;
  padding: 0.4rem 0.55rem 0.6rem;
  overflow-y: auto;
}

.dg-search-results li {
  margin: 0;
}

.dg-search-dialog a.dg-sr {
  display: grid;
  gap: 0.22rem;
  padding: 0.75rem 0.85rem;
  border-radius: 8px;
  border: 1px solid transparent;
  text-decoration: none;
  color: inherit;
}

.dg-search-results li[aria-selected="true"] a.dg-sr {
  background: #161616;
  border-color: rgba(255, 255, 255, 0.28);
}

.dg-sr-where {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5);
}

.dg-sr-best {
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  background: #f74c00;
  color: #000000;
  letter-spacing: 0.08em;
}

.dg-sr-title {
  font-size: 1.02rem;
  font-weight: 700;
  color: #ffffff;
}

.dg-sr-snip {
  font-size: 0.9rem;
  line-height: 1.55;
  color: rgba(255, 255, 255, 0.72);
}

.dg-search-dialog mark {
  background: rgba(247, 76, 0, 0.28);
  color: #ffffff;
  border-radius: 2px;
  padding: 0 1px;
}

.dg-search-help {
  margin: 0;
  padding: 0.6rem 1.1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.45);
}

.dg-search-help kbd {
  margin-right: 0.2rem;
}

@media (max-width: 560px) {
  .dg-search-dialog {
    padding: 0.6rem;
  }

  .dg-search-panel {
    max-height: calc(100vh - 1.2rem);
  }

  .dg-search-help {
    display: none;
  }
}

/* A section reached from search (or any #link) briefly lights up. */
@media (prefers-reduced-motion: no-preference) {
  body.theme-typesafe.dg-garden .post-content.dg-notes h2:target {
    animation: dg-target-flash 1.6s ease-out;
  }
}

@keyframes dg-target-flash {
  0%, 30% { background: rgba(247, 76, 0, 0.22); }
  100% { background: transparent; }
}
