/*
  Path: web/search.css

  Purpose:
  - The look of the search page: a quiet home with one box, and results that show why each page is
    where it is.
  - Light and dark follow the reader's system setting.
*/

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --raised: #f6f5f1;
  --ink: #17191c;
  --text: #3d4249;
  --muted: #6b717b;
  --line: #e6e3dc;
  --accent: #155e4b;
  --accent-soft: #9cc2b3;
  --tint: #edf5f1;
  --link: #11533f;
  --visited: #6a4a8c;
  --ring: rgb(21 94 75 / 0.16);
  --shadow: 0 1px 3px rgb(23 25 28 / 0.08), 0 4px 14px rgb(23 25 28 / 0.06);
  --rail: 160px;
  --col: 640px;
  --side: 340px;
  --gap: 32px;
  --gutter: 24px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111315;
    --surface: #181b1e;
    --raised: #1e2225;
    --ink: #eceef0;
    --text: #c4c9cf;
    --muted: #8f969e;
    --line: #2a2e33;
    --accent: #5cc2a0;
    --accent-soft: #2f5d50;
    --tint: #16302a;
    --link: #82d6b9;
    --visited: #c3abe8;
    --ring: rgb(92 194 160 / 0.2);
    --shadow: 0 1px 3px rgb(0 0 0 / 0.4), 0 6px 20px rgb(0 0 0 / 0.3);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link); }
button { font: inherit; }
code, kbd { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
[hidden] { display: none !important; }

/* Brand */

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; border-radius: 10px; }
.brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.mark { width: 30px; height: 30px; flex: none; }
.mark .near { fill: var(--accent); }
.mark .far { fill: var(--accent-soft); }
.mark .snow { fill: var(--bg); }
.word { font-size: 1.125rem; letter-spacing: -0.02em; color: var(--muted); white-space: nowrap; }
.word b { color: var(--ink); font-weight: 650; }

/* Search box */

.search {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search:hover, .search:focus-within { box-shadow: var(--shadow); border-color: transparent; }
.search:focus-within { box-shadow: var(--shadow), 0 0 0 3px var(--ring); }

.glass { position: absolute; left: 18px; width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; pointer-events: none; }

.search input {
  flex: 1;
  min-width: 0;
  height: 46px;
  padding: 0 84px 0 48px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1.0625rem;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; display: none; }

.clear {
  position: absolute;
  right: 46px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
}
.clear svg { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.clear:hover svg { stroke: var(--ink); }
.clear:focus-visible { outline: 2px solid var(--accent); }

.hint { position: absolute; right: 16px; padding: 4px 7px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); font-size: 12px; line-height: 1; pointer-events: none; }
.search:focus-within .hint { visibility: hidden; }

@media (hover: none) {
  .hint { display: none; }
  .search input { padding-right: 48px; }
  .clear { right: 8px; }
}

/* Home */

body[data-view="home"] .top {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px var(--gutter) 14vh;
  text-align: center;
}
body[data-view="home"] .brand { flex-direction: column; gap: 18px; margin-bottom: 30px; }
body[data-view="home"] .mark { width: 72px; height: 72px; }
body[data-view="home"] .word { font-size: clamp(2.1rem, 8vw, 3rem); }
body[data-view="home"] .search { max-width: 584px; }
body[data-view="home"] .search input { height: 52px; }
body[data-view="home"] main { display: none; }

.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 26px; }
.btn {
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--raised);
  color: var(--ink);
  font-size: 0.875rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--line); box-shadow: 0 1px 2px rgb(0 0 0 / 0.08); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tagline { max-width: 32rem; margin: 30px 0 0; color: var(--muted); font-size: 0.9375rem; }

.syntax { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 16px 0 0; padding: 0; list-style: none; }
.syntax code { display: inline-block; padding: 6px 11px; border: 1px solid var(--line); border-radius: 999px; color: var(--text); font-size: 13px; line-height: 1; }

body[data-view="results"] .actions,
body[data-view="results"] .tagline,
body[data-view="results"] .syntax { display: none; }

/* Results header */

body[data-view="results"] .top {
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: var(--rail) minmax(0, var(--col));
  column-gap: var(--gap);
  align-items: center;
  padding: 16px var(--gutter);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
}
body[data-view="results"] .search { box-shadow: var(--shadow); border-color: transparent; }

/* Results body */

main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, var(--col)) var(--side);
  column-gap: 64px;
  align-items: start;
  width: 100%;
  padding: 4px var(--gutter) 56px calc(var(--gutter) + var(--rail) + var(--gap));
}
.col { min-width: 0; }

.meta { margin: 14px 0 0; color: var(--muted); font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.meta:empty, .fix:empty { display: none; }
.fix { margin: 12px 0 0; font-size: 0.9375rem; }
.fix strong { color: var(--ink); font-weight: 600; font-style: italic; }

/* Answer card for questions */

.answer { margin-top: 20px; padding: 20px 22px 18px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.answer .lead { margin: 0; color: var(--ink); font-size: 1.0625rem; line-height: 1.6; overflow-wrap: anywhere; }
.answer .lead mark { background: var(--tint); color: var(--ink); font-weight: 600; border-radius: 3px; padding: 0 2px; }
.answer .from { display: flex; align-items: center; gap: 12px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.answer .from .title { margin: 0; font-size: 1rem; }

/* One result */

.list { margin: 0; padding: 0; list-style: none; }
.hit { padding-top: 28px; }

.src { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mono {
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: hsl(var(--h, 160) 38% 92%);
  color: hsl(var(--h, 160) 45% 28%);
  font-size: 12px;
  font-weight: 650;
}
.mono.big { width: 48px; height: 48px; font-size: 20px; border-radius: 14px; }
@media (prefers-color-scheme: dark) {
  .mono { background: hsl(var(--h, 160) 22% 20%); color: hsl(var(--h, 160) 45% 80%); }
}
.where { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.site { overflow: hidden; color: var(--ink); font-size: 0.875rem; white-space: nowrap; text-overflow: ellipsis; }
.path { overflow: hidden; color: var(--muted); font-size: 0.75rem; white-space: nowrap; text-overflow: ellipsis; }

.title { margin: 8px 0 0; font-size: 1.25rem; font-weight: 400; line-height: 1.3; overflow-wrap: anywhere; }
.title a { color: var(--link); text-decoration: none; border-radius: 4px; }
.title a:visited { color: var(--visited); }
.title a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.title a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.snip { margin: 4px 0 0; font-size: 0.9375rem; line-height: 1.58; overflow-wrap: anywhere; }
.snip mark { background: none; color: var(--ink); font-weight: 600; }
.when { color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--tint);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 550;
  line-height: 1.5;
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.pick { background: var(--accent); color: var(--bg); }

.why {
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.5;
  cursor: pointer;
}
.why:hover, .why[aria-expanded="true"] { color: var(--ink); border-color: var(--muted); }
.why:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hit .bars { margin-top: 12px; padding: 14px 16px; border-radius: 12px; background: var(--raised); }

/* Signal bars */

.bars { display: grid; gap: 9px; margin: 0; }
.bar { display: grid; grid-template-columns: 9.5em minmax(0, 1fr) 2.6em; align-items: center; gap: 10px; font-size: 0.8125rem; }
.bar dt { color: var(--text); }
.bar dd { margin: 0; }
.bar .track { display: block; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar .fill { display: block; height: 100%; width: calc(var(--v, 0) * 100%); border-radius: 3px; background: var(--accent); }
.bar .num { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }

/* Side panel */

.panel { position: sticky; top: 104px; margin-top: 20px; padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
.panel .head { display: flex; align-items: center; gap: 14px; }
.panel .kicker { margin: 0; color: var(--muted); font-size: 0.75rem; letter-spacing: 0.04em; text-transform: uppercase; }
.panel .name { margin: 2px 0 0; color: var(--ink); font-size: 1.125rem; font-weight: 600; overflow-wrap: anywhere; }
.panel .title { margin-top: 16px; font-size: 1rem; }
.panel .date { margin: 4px 0 0; color: var(--muted); font-size: 0.8125rem; }
.panel h3 { margin: 22px 0 12px; color: var(--ink); font-size: 0.8125rem; font-weight: 600; }
.panel .read { margin: 22px 0 0; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.8125rem; }
.panel .read b { color: var(--ink); font-weight: 600; }

/* Placeholders while a slow search runs */

.ghost .g { display: block; height: 12px; margin-top: 10px; border-radius: 6px; background: var(--raised); animation: pulse 1.2s ease-in-out infinite; }
.ghost .g.short { width: 28%; height: 10px; margin-top: 0; }
.ghost .g.head { width: 62%; height: 18px; }
.ghost .g.mid { width: 82%; }
@keyframes pulse { 50% { opacity: 0.45; } }

/* Empty, busy and failed */

.notice { margin-top: 28px; padding: 22px 24px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.notice p { margin: 0; color: var(--ink); }
.notice p + p { margin-top: 10px; }
.notice strong { font-weight: 600; }
.notice ul { margin: 12px 0 0; padding-left: 18px; color: var(--muted); font-size: 0.9375rem; }
.notice li + li { margin-top: 4px; }
.retry { margin-top: 16px; }

/* Pages */

.pager { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 48px; }
.pager:empty { display: none; }
.pager a, .pager span {
  display: inline-grid;
  place-items: center;
  min-width: 40px;
  height: 40px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.9375rem;
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}
.pager a { color: var(--link); }
.pager a:hover { background: var(--raised); }
.pager a:focus-visible { outline: 2px solid var(--accent); }
.pager [aria-current] { background: var(--accent); color: var(--bg); font-weight: 600; }
.pager .step { font-weight: 500; }

/* Footer */

.foot { display: flex; flex-wrap: wrap; gap: 6px 22px; padding: 16px var(--gutter); background: var(--raised); color: var(--muted); font-size: 0.8125rem; }
.foot .grow { flex: 1; }
.foot span:empty:not(.grow) { display: none; }
.foot a { color: var(--muted); }
.foot a:hover { color: var(--ink); }
body[data-view="results"] .foot { padding-left: calc(var(--gutter) + var(--rail) + var(--gap)); }

/* Narrower screens drop the side panel, then the rail */

@media (max-width: 1180px) {
  main { grid-template-columns: minmax(0, var(--col)); }
  .panel { display: none !important; }
}

@media (max-width: 860px) {
  :root { --gutter: 16px; }
  body[data-view="results"] .top { grid-template-columns: auto minmax(0, 1fr); column-gap: 12px; padding: 10px var(--gutter); }
  body[data-view="results"] .word { display: none; }
  main { padding-left: var(--gutter); }
  body[data-view="results"] .foot { padding-left: var(--gutter); }
  .title { font-size: 1.125rem; }
  .bar { grid-template-columns: 8em minmax(0, 1fr) 2.4em; }
}

@media (prefers-reduced-motion: reduce) {
  .ghost .g { animation: none; }
  .search { transition: none; }
}

/* The bot page and other plain documents */

body.doc .doc-top { padding: 16px var(--gutter); border-bottom: 1px solid var(--line); }
.doc-body { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding: 32px var(--gutter) 64px; color: var(--text); }
.doc-body h1 { margin: 0; color: var(--ink); font-size: 2rem; letter-spacing: -0.02em; }
.doc-body h2 { margin: 36px 0 10px; color: var(--ink); font-size: 1.125rem; }
.doc-body .lead { margin: 12px 0 0; font-size: 1.0625rem; }
.doc-body li + li { margin-top: 6px; }
.doc-body pre { margin: 12px 0; padding: 14px 16px; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--raised); }
.doc-body code { font-size: 0.875rem; }
.doc-body :not(pre) > code { padding: 1px 6px; border-radius: 5px; background: var(--raised); }
