/* ===========================================================================
   engine.css — Structural styles for the drishti-corpus engine.

   THEME-AGNOSTIC. No colour is hard-coded; every colour reads a `--cx-*` CSS
   variable. A host defines its palette by mapping its own theme onto these
   variables (see index.html / koshas-corpus-host). Sensible light fallbacks are
   provided so the page is usable even with no host palette.

   Owns: layout of the search page (wrap, search box, filter pills, result
   "hit" cards, citation chips, audio link, copy button, empty/load-more/footer)
   and the inline-note citation popovers. Calm, progressive-disclosure UI: one
   obvious search box; optional filter pills; quotes that read plainly.

   --cx-* contract (host maps these; fallbacks below):
     --cx-bg          page background
     --cx-panel       card / popover background
     --cx-ink         primary text
     --cx-ink-soft    secondary text
     --cx-line        borders / hairlines
     --cx-accent      accent (kicker, focus, active pill, links)
     --cx-accent-soft accent wash (code chips, default chip bg)
     --cx-mark        search highlight background
     --cx-en          EN language chip text
     --cx-es          ES language chip text
     --cx-radius      corner radius
     --cx-shadow      card shadow
     --cx-font        serif/reading face (quotes, headings)
     --cx-sans        UI sans face
   =========================================================================== */
:root {
  /* Light fallbacks — a host normally overrides these. */
  --cx-bg: #faf7f2; --cx-panel: #fffdf9; --cx-ink: #2b2620; --cx-ink-soft: #6c6358;
  --cx-line: #e8e0d4; --cx-accent: #b07d3a; --cx-accent-soft: #f0e3cd;
  --cx-en: #3a6ea5; --cx-es: #b0573a; --cx-mark: #ffe7a8;
  --cx-radius: 14px;
  --cx-shadow: 0 1px 2px rgba(40,30,15,.05), 0 8px 24px rgba(40,30,15,.06);
  --cx-font: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --cx-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--cx-bg); color: var(--cx-ink); font-family: var(--cx-sans);
  line-height: 1.55; -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 820px; margin: 0 auto; padding: 28px 20px 80px; }

/* ---- header / intro (progressive disclosure) ---- */
header { margin-bottom: 18px; }
.kicker {
  font-size: .72rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--cx-accent); font-weight: 700; margin: 0 0 6px;
}
h1 { font-family: var(--cx-font); font-size: 1.9rem; margin: 0 0 6px; font-weight: 600; }
.lede { color: var(--cx-ink-soft); margin: 0 0 4px; max-width: 60ch; }
details.about { margin: 10px 0 0; }
details.about summary {
  cursor: pointer; color: var(--cx-accent); font-size: .9rem; font-weight: 600;
  list-style: none; display: inline-flex; align-items: center; gap: 6px;
}
details.about summary::before { content: "›"; transition: transform .15s; }
details.about[open] summary::before { transform: rotate(90deg); }
details.about p { color: var(--cx-ink-soft); font-size: .92rem; max-width: 64ch; }
details.about code {
  background: var(--cx-accent-soft); padding: 1px 6px; border-radius: 6px;
  font-size: .86em;
}

/* ---- search box ---- */
.searchbar { position: sticky; top: 0; z-index: 5; padding: 14px 0; background: var(--cx-bg); }
.searchbox {
  display: flex; align-items: center; gap: 10px; background: var(--cx-panel);
  border: 1.5px solid var(--cx-line); border-radius: var(--cx-radius); padding: 4px 8px 4px 16px;
  box-shadow: var(--cx-shadow);
}
.searchbox:focus-within { border-color: var(--cx-accent); }
.searchbox svg { flex: none; opacity: .5; }
#q {
  flex: 1; border: 0; background: transparent; font-size: 1.06rem; color: var(--cx-ink);
  padding: 12px 4px; outline: none; font-family: var(--cx-sans);
}

/* ---- filters ---- */
.filters {
  display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center;
  margin: 10px 0 4px;
}
.filter-group { display: flex; gap: 6px; align-items: center; }
.filter-group .lbl { font-size: .76rem; color: var(--cx-ink-soft); margin-right: 2px; }
.pill {
  border: 1px solid var(--cx-line); background: var(--cx-panel); color: var(--cx-ink-soft);
  border-radius: 999px; padding: 5px 12px; font-size: .82rem; cursor: pointer;
  font-family: var(--cx-sans); transition: all .12s;
}
.pill:hover { border-color: var(--cx-accent); color: var(--cx-ink); }
.pill[aria-pressed="true"] {
  background: var(--cx-accent); border-color: var(--cx-accent); color: #fff; font-weight: 600;
}

/* ---- status line ---- */
.statusrow {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 12px 2px 6px; font-size: .82rem; color: var(--cx-ink-soft);
}
#counts { font-variant-numeric: tabular-nums; }

/* ---- results ---- */
#results { display: flex; flex-direction: column; gap: 10px; }
.hit {
  background: var(--cx-panel); border: 1px solid var(--cx-line); border-radius: var(--cx-radius);
  padding: 14px 16px; box-shadow: var(--cx-shadow);
}
.hit-top { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-bottom: 8px; }
.hit-text { margin: 0; font-family: var(--cx-font); font-size: 1.04rem; line-height: 1.62; }
.hit-text mark { background: var(--cx-mark); border-radius: 3px; padding: 0 2px; }

.chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: .72rem;
  font-weight: 600; padding: 3px 9px; border-radius: 999px; letter-spacing: .02em;
  background: var(--cx-accent-soft); color: var(--cx-accent);
}
.chip.sess { background: color-mix(in srgb, var(--cx-accent-soft) 80%, var(--cx-ink) 6%); color: var(--cx-ink-soft); }
.chip.lang-en { background: #e3edf7; color: var(--cx-en); }
.chip.lang-es { background: #f7e6e0; color: var(--cx-es); }
.chip.spk { background: #eee9f6; color: #6a4fa0; }
.chip.time { background: color-mix(in srgb, var(--cx-line) 60%, var(--cx-panel)); color: var(--cx-ink-soft); }

/* audio deep-link */
a.audio {
  display: inline-flex; align-items: center; gap: 5px; font-size: .72rem; font-weight: 700;
  padding: 3px 9px; border-radius: 999px; text-decoration: none;
  background: var(--cx-ink); color: var(--cx-panel);
}
a.audio:hover { background: var(--cx-accent); color: #fff; }
.play {
  width: 0; height: 0; border-style: solid; border-width: 4px 0 4px 7px;
  border-color: transparent transparent transparent currentColor; display: inline-block;
}

/* copyable citation token */
.cite-copy {
  margin-left: auto; border: 1px dashed var(--cx-line); background: transparent;
  color: var(--cx-ink-soft); font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: .7rem; padding: 3px 8px; border-radius: 8px; cursor: pointer;
}
.cite-copy:hover { border-color: var(--cx-accent); color: var(--cx-accent); }
.cite-copy.copied { border-color: #3a8a4a; color: #3a8a4a; background: #eef7ef; }

/* ---- empty / load more / footer ---- */
.empty { text-align: center; color: var(--cx-ink-soft); padding: 48px 20px; }
.empty .big { display: block; font-family: var(--cx-font); font-size: 1.25rem; color: var(--cx-ink); margin-bottom: 6px; }
.empty code { background: var(--cx-accent-soft); padding: 1px 6px; border-radius: 6px; }
#loadMoreWrap { text-align: center; margin: 18px 0; }
#loadMore {
  border: 1px solid var(--cx-line); background: var(--cx-panel); color: var(--cx-ink);
  border-radius: 999px; padding: 9px 22px; cursor: pointer; font-size: .9rem;
}
#loadMore:hover { border-color: var(--cx-accent); color: var(--cx-accent); }
footer { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--cx-line);
  font-size: .78rem; color: var(--cx-ink-soft); text-align: center; }
footer a { color: var(--cx-accent); }

/* ---- inline-note citation popovers (note renderer) ---- */
.note {
  background: var(--cx-panel); border: 1px solid var(--cx-line); border-radius: var(--cx-radius);
  box-shadow: var(--cx-shadow); padding: 22px 26px; font-family: var(--cx-font);
  font-size: 1.08rem; line-height: 1.7;
}
.note p { margin: 0 0 1rem; }
.cite { position: relative; }
.cite-mark { color: var(--cx-accent); font-weight: 700; cursor: pointer; padding: 0 1px; }
.cite-mark:hover, .cite-mark:focus { outline: none; text-decoration: underline; }
.cite-bad { color: #b04a3a; }
.src-pop {
  display: none; position: absolute; left: 0; top: 1.4em; z-index: 20; width: min(360px, 80vw);
  background: var(--cx-panel); border: 1px solid var(--cx-line); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(40,30,15,.16);
  padding: 12px 14px; font-family: var(--cx-sans); font-size: .9rem; line-height: 1.5; text-align: left;
}
.cite:hover .src-pop, .cite-mark:focus + .src-pop, .src-pop:hover { display: block; }
.src-head { display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--cx-accent); font-weight: 700; margin-bottom: 5px; }
.src-quote { display: block; color: var(--cx-ink); font-style: italic; margin-bottom: 9px; }
.src-audio { display: inline-flex; align-items: center; gap: 5px; font-size: .76rem; font-weight: 700;
  text-decoration: none; background: var(--cx-ink); color: var(--cx-panel); padding: 4px 10px; border-radius: 999px; }
.src-audio:hover { background: var(--cx-accent); color: #fff; }
.src-audio.muted { background: color-mix(in srgb, var(--cx-line) 60%, var(--cx-panel)); color: var(--cx-ink-soft); }

@media (max-width: 560px) {
  .wrap { padding: 18px 14px 60px; }
  h1 { font-size: 1.55rem; }
}
