/* Mandala Theatre — site search: the button in the header bar, the search dialog, and the
   results page (/search). Values come from tokens.css. */

/* ---------- the search button in the bar, just before Menu ---------- */
.search-btn {
  position: relative; z-index: 2; display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; margin-right: -14px; padding: 0; border: 0; border-radius: var(--btn-radius); cursor: pointer;
  background: transparent; color: var(--white); text-decoration: none;
}
.search-btn:hover { background: rgba(255,255,255,.14); }
@media (max-width: 900px) {
  .search-btn { width: 48px; height: 48px; margin: 0; background: rgba(255,255,255,.12); }
  .search-btn:hover { background: rgba(255,255,255,.22); }
}

/* ---------- matched words ---------- */
mark { background: #ffe1a1; color: inherit; padding: 0 .08em; border-radius: 2px; }

/* ---------- the dialog: a white panel from the top, the page dimmed behind ---------- */
body.search-open { overflow: hidden; }
.search-dialog {
  width: min(880px, calc(100% - 2 * var(--margin))); max-width: none; max-height: calc(100dvh - 48px);
  margin: 24px auto auto; padding: 0; border: 0; border-radius: 8px;
  background: var(--white); color: var(--ink); box-shadow: 0 24px 80px rgba(0,0,0,.35);
  overflow: auto; overscroll-behavior: contain;
}
.search-dialog::backdrop { background: rgba(23, 10, 13, .72); }
.search-dialog[open] { animation: sd-in .22s var(--ease); }
.search-dialog[open]::backdrop { animation: sd-fade .22s ease; }
@keyframes sd-in { from { opacity: 0; transform: translateY(-12px); } }
@keyframes sd-fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .search-dialog[open], .search-dialog[open]::backdrop { animation: none; }
}
/* the dialog is light, so the focus ring is dark (saffron can't be seen on white) */
.search-dialog :focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

.sd-inner { padding: clamp(20px, 3vw, 36px); }
.sd-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.sd-title { font-size: clamp(1.5rem, 1.2rem + 1vw, 2rem); font-weight: 750; letter-spacing: -0.02em; line-height: 1.1; }
.sd-close {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border: 0; border-radius: var(--btn-radius);
  background: var(--soft); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
}
.sd-close:hover { background: var(--mist); }

.sd-form { margin-top: 20px; }
.sd-label { display: block; font-weight: 600; margin-bottom: 8px; }
.sd-field { position: relative; display: flex; gap: 8px; }
.sd-icon { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--ink-soft); pointer-events: none; }
.sd-field input {
  flex: 1; min-width: 0; min-height: 56px; padding: 0 16px 0 50px; border: 0; border-radius: var(--btn-radius);
  font: inherit; font-size: var(--t-lead); color: var(--ink); background: var(--soft); box-shadow: inset 0 0 0 1.5px #c9c3c5;
}
.sd-field input:focus { outline: none; background: var(--white); box-shadow: inset 0 0 0 2px var(--ink); }
.sd-field input:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.sd-submit { min-height: 56px; }
.sd-hint { margin-top: 8px; font-size: var(--t-small); color: var(--ink-soft); }

.sd-results:not(:empty) { margin-top: 24px; padding-top: 20px; border-top: 2px solid var(--ink); }
.sd-results[aria-busy="true"] { opacity: .6; transition: opacity .2s .15s; }
.sd-summary { font-weight: 700; }
.sd-group { margin-top: 20px; }
.sd-group-title { font-size: var(--t-small); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--crimson); }
.sd-group-count { font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--ink-soft); }
.sd-group-count::before { content: "· "; }
.sd-all { margin-top: 24px; }
.sd-none { margin-top: 8px; color: var(--ink-soft); }
.sd-none a { color: var(--ink); }

@media (max-width: 620px) {
  /* phones: the dialog fills the screen */
  .search-dialog { width: 100%; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; }
  .sd-hint { display: none; }
  .sd-submit { padding: 0 16px; }
}

/* ---------- one result (dialog and page) ---------- */
.hits { margin-top: 8px; }
.hits > li + li { border-top: 1px solid #e6e3e4; }
.hit { position: relative; display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 16px; align-items: start; padding: 14px 0; }
.hit-img { width: 56px; aspect-ratio: 4 / 5; object-fit: cover; background: var(--mist); }
.hit-none { display: block; background: var(--soft); }
.hit-title { font-weight: 700; line-height: 1.25; color: var(--ink); text-decoration: none; }
/* the title link covers the whole row */
.hit-title::after { content: ""; position: absolute; inset: 0; }
.hit:hover .hit-title, .hit-title:focus-visible {
  text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; text-decoration-color: var(--crimson);
}
.hit-title:focus-visible { outline: none; }
.hit:has(.hit-title:focus-visible) { outline: 3px solid var(--ink); outline-offset: 2px; }
.hit-deva { font-weight: 500; color: var(--ink-soft); }
.hit-meta { margin-top: 2px; font-size: var(--t-small); color: var(--ink-soft); }
.hit-snip { margin-top: 6px; font-size: var(--t-small); line-height: 1.5; max-width: 72ch; }

/* ---------- the results page ---------- */
.sf { display: grid; gap: 20px; }
.sf-label { display: block; font-weight: 600; margin-bottom: 8px; }
.sf-row { display: flex; gap: 8px; max-width: 880px; }
.sf-row input, .sf-field input, .sf-field select {
  min-height: 56px; width: 100%; padding: 0 16px; border: 0; border-radius: var(--btn-radius);
  font: inherit; color: var(--ink); background: var(--soft); box-shadow: inset 0 0 0 1.5px #c9c3c5;
}
.sf-row input { flex: 1; min-width: 0; font-size: var(--t-lead); }
.sf-row .btn { min-height: 56px; }
.sf-row input:focus, .sf-field input:focus, .sf-field select:focus { background: var(--white); box-shadow: inset 0 0 0 2px var(--ink); }
.sf [aria-invalid="true"] { box-shadow: inset 0 0 0 2px var(--crimson); }

.sf-more { max-width: 1100px; border-top: 1px solid #dcd8d9; border-bottom: 1px solid #dcd8d9; }
.sf-more summary { display: flex; align-items: center; gap: 10px; min-height: 52px; font-weight: 700; cursor: pointer; list-style: none; }
.sf-more summary::-webkit-details-marker { display: none; }
.sf-more summary::before { content: "+"; display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: var(--white); font-weight: 700; line-height: 1; }
.sf-more[open] summary::before { content: "–"; }
.sf-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px var(--gap); padding: 8px 0 20px; }
.sf-kinds { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px 10px; margin: 0; padding: 0; border: 0; }
.sf-kinds legend { width: 100%; margin-bottom: 8px; padding: 0; font-weight: 600; }
.sf-kinds label {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px 0 12px; border-radius: 22px; cursor: pointer;
  box-shadow: inset 0 0 0 1.5px #d4cfd1; font-weight: 600;
}
.sf-kinds label:has(input:checked) { background: var(--ink); color: var(--white); box-shadow: none; }
.sf-kinds input { width: 18px; height: 18px; margin: 0; accent-color: var(--crimson); }
.sf-kinds label:has(input:focus-visible) { outline: 3px solid var(--ink); outline-offset: 2px; }
.sf-field { display: grid; gap: 8px; align-content: start; }
.sf-field label { font-weight: 600; }
.sf-note { font-size: var(--t-small); color: var(--ink-soft); max-width: 72ch; }
.sf-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 28px; padding: 20px 0 24px; }
@media (max-width: 820px) { .sf-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) {
  .sf-grid { grid-template-columns: 1fr; }
  .sf-row { flex-direction: column; }
}

.sf-errors { margin-bottom: 28px; padding: 18px 20px; border-left: 4px solid var(--crimson); background: #fbeef0; }
.sf-errors h3 { font-size: var(--t-body); font-weight: 700; }
.sf-errors ul { margin-top: 6px; }
.sf-errors a { color: var(--crimson-deep); font-weight: 600; }

.rs-results { padding-top: 0; }
.rs-summary { font-size: clamp(1.5rem, 1.1rem + 1.4vw, 2.25rem); font-weight: 750; letter-spacing: -0.02em; line-height: 1.15; text-wrap: balance; }
.rs-empty { margin-top: 16px; max-width: 64ch; color: var(--ink-soft); }
.rs-empty ul { margin-top: 8px; padding-left: 1.2em; list-style: disc; }
.rs-empty a { color: var(--ink); }
.rs-group { margin-top: clamp(40px, 5vw, 64px); }
.rs-group-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 20px; padding-bottom: 10px; border-bottom: 2px solid var(--ink); }
.rs-group-title { font-size: var(--t-lead); font-weight: 750; }
.rs-group-count { font-size: var(--t-small); color: var(--ink-soft); }
.rs-group .hit { grid-template-columns: 88px minmax(0, 1fr); gap: 20px; padding: 18px 0; }
.rs-group .hit-img { width: 88px; }
.rs-group .hit-title { font-size: clamp(1.125rem, 1rem + .4vw, 1.375rem); }
.rs-more { margin-top: 16px; }
.rs-pages { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 28px; margin-top: 24px; font-size: var(--t-small); color: var(--ink-soft); }
@media (max-width: 520px) {
  .rs-group .hit { grid-template-columns: 64px minmax(0, 1fr); gap: 14px; }
  .rs-group .hit-img { width: 64px; }
}
