/* ---------------------------------------------------------------------------
   Course search — find a topic or keyword across all 69 lessons.

   Separate from the two searches that already exist: the perennial sources
   lookup in Module 4 and the Source Library catalogue. This one searches the
   course text itself.
   --------------------------------------------------------------------------- */

/* ----------------------------------------------------- trigger in nav --- */
.search-open {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--card-sunk); border: 1px solid var(--line);
  border-radius: var(--radius-sm); cursor: pointer;
  font: inherit; font-size: 12.5px; color: var(--ink-soft);
  padding: 0 10px; min-height: 34px; white-space: nowrap;
}
.search-open:hover { color: var(--ink); border-color: var(--line-strong); }
.search-open .so-icon { font-size: 13px; line-height: 1; }
.search-open .so-key {
  font-size: 10.5px; font-weight: 700; letter-spacing: .04em;
  border: 1px solid var(--line-strong); border-radius: 4px;
  padding: 1px 5px; color: var(--ink-soft);
}

/* --------------------------------------------------------- the overlay --- */
.search-overlay {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(16, 20, 26, .5);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 10vh 18px 24px;
}
.search-overlay[hidden] { display: none; }

.search-panel {
  width: 100%; max-width: 620px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .3);
  display: flex; flex-direction: column;
  max-height: 100%;
  overflow: hidden;
}

.search-field {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.search-field .sf-icon { color: var(--ink-soft); font-size: 15px; flex: 0 0 auto; }
.search-field input {
  flex: 1 1 auto; min-width: 0;
  background: transparent; border: none; outline: none;
  font: inherit; font-size: 16.5px; color: var(--ink);
}
.search-field input::placeholder { color: var(--ink-soft); }
.search-close {
  flex: 0 0 auto;
  background: transparent; border: 1px solid var(--line);
  border-radius: var(--radius-sm); cursor: pointer;
  font: inherit; font-size: 10.5px; font-weight: 700; letter-spacing: .06em;
  color: var(--ink-soft); padding: 0 9px; min-height: 28px;
}
.search-close:hover { color: var(--ink); border-color: var(--line-strong); }

.search-results {
  flex: 1 1 auto; overflow-y: auto;
  padding: 6px;
  overscroll-behavior: contain;
}
.search-hint, .search-empty {
  padding: 18px 16px; font-size: 14px; color: var(--ink-soft);
}
.search-empty b { color: var(--ink); }

.search-hit {
  display: block; width: 100%; text-align: left;
  background: transparent; border: none; cursor: pointer;
  font: inherit; color: var(--ink);
  padding: 11px 12px; border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
}
.search-hit:hover, .search-hit.active {
  background: var(--accent-wash);
  border-left-color: var(--accent);
}
.search-hit .sh-top {
  display: flex; align-items: baseline; gap: 8px;
  margin-bottom: 3px;
}
.search-hit .sh-title {
  font-family: var(--font-head); font-weight: 650; font-size: 15px;
  letter-spacing: -.01em; line-height: 1.3;
  flex: 1 1 auto; min-width: 0;
}
.search-hit .sh-where {
  flex: 0 0 auto; font-size: 10.5px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft);
}
.search-hit.is-done .sh-where::after { content: " ✓"; color: var(--good); }
.search-hit .sh-snip {
  font-size: 13.5px; color: var(--ink-soft); line-height: 1.55;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.search-hit mark, .lesson-body mark, .lesson-titles mark {
  background: #ffe9a8; color: inherit;
  border-radius: 3px; padding: 0 1px;
}
:root[data-theme="dark"] .search-hit mark,
:root[data-theme="dark"] .lesson-body mark,
:root[data-theme="dark"] .lesson-titles mark { background: #6b5415; color: #fff6dc; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .search-hit mark,
  :root:not([data-theme="light"]) .lesson-body mark,
  :root:not([data-theme="light"]) .lesson-titles mark { background: #6b5415; color: #fff6dc; }
}

.search-foot {
  flex: 0 0 auto;
  display: flex; flex-wrap: wrap; gap: 14px;
  padding: 9px 16px; border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--ink-soft);
  background: var(--card-sunk);
}
.search-foot kbd {
  font: inherit; font-size: 10.5px; font-weight: 700;
  border: 1px solid var(--line-strong); border-radius: 4px;
  padding: 1px 5px; margin-right: 4px;
}

/* the lesson you jumped to, flashed briefly so it is obvious where you landed */
.lesson.search-landed { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }

@media (max-width: 680px) {
  .search-overlay { padding: 0; }
  .search-panel { max-width: none; border: none; border-radius: 0; height: 100%; }
  .search-open .so-key, .search-open .so-text { display: none; }
  .search-open { padding: 0 9px; }
  .search-foot { display: none; }
}
@media (max-width: 400px) {
  .nav-count { display: none; }
}

@media print { .search-open, .search-overlay { display: none !important; } }
