/*
 * Searchling — public UI (landing page + results).
 *
 * Hand-rolled, no framework, no webfonts. The palette lives entirely in custom
 * properties on :root so dark mode is a single block of overrides at the end.
 * The admin console has its own stylesheet; the public layout links this file
 * explicitly rather than using stylesheet_link_tag :app.
 */

/* ---------------------------------------------------------------- tokens -- */

:root {
  color-scheme: light dark;

  /* Neutrals: very slightly warm, so long pages of text do not feel clinical. */
  --bg: #fbfaf8;
  --bg-elevated: #ffffff;
  --bg-sunken: #f2f0ec;
  --border: #e3e0d9;
  --border-strong: #cfcbc1;

  --text: #1b1a17;
  --text-soft: #4c4a44;
  --text-muted: #77746c;

  /* Accent: a deep, slightly dusty teal. */
  --accent: #0f6b63;
  --accent-hover: #0a534d;
  --accent-soft: #e2f1ef;
  --accent-ring: rgba(15, 107, 99, 0.28);

  --link: #1a4fa0;
  --link-visited: #6b3fa0;
  --url: #2e6b3d;             /* the muted green-ish display URL */
  --mark-bg: #fff2b8;
  --mark-text: #2f2a10;

  --shadow-sm: 0 1px 2px rgba(24, 22, 18, 0.06);
  --shadow-md: 0 2px 4px rgba(24, 22, 18, 0.06), 0 8px 24px rgba(24, 22, 18, 0.08);
  --shadow-focus: 0 0 0 4px var(--accent-ring);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-pill: 999px;

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;

  --measure: 46rem;
  --gutter: clamp(1rem, 4vw, 2rem);
}

/* ------------------------------------------------------------------ base -- */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: 5rem;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 {
  line-height: 1.2;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.011em;
}

p { margin: 0; }

a {
  color: var(--link);
  text-decoration-color: color-mix(in srgb, currentColor 35%, transparent);
  text-underline-offset: 2px;
}

a:hover { text-decoration-color: currentColor; }

code, kbd {
  font-family: var(--font-mono);
  font-size: 0.875em;
}

code {
  background: var(--bg-sunken);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}

kbd {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0.05em 0.4em;
  color: var(--text-soft);
}

mark {
  background: var(--mark-bg);
  color: var(--mark-text);
  border-radius: 2px;
  padding: 0 0.1em;
  font-weight: 600;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--accent);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 0 0 var(--radius-sm) 0;
  text-decoration: none;
}

.skip-link:focus {
  left: 0;
}

/* -------------------------------------------------------------- wordmark -- */

.wordmark {
  margin: 0;
  font-size: clamp(2.75rem, 12vw, 4.5rem);
  font-weight: 700;
  letter-spacing: -0.04em;
}

.wordmark__text { color: var(--text); }

.wordmark__accent {
  color: var(--accent);
  /* A faint underline that reads as a "line" under -ling. */
  box-shadow: inset 0 -0.12em 0 color-mix(in srgb, var(--accent) 22%, transparent);
}

/* ---------------------------------------------------------- landing page -- */

.landing {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(2rem, 10vh, 6rem) var(--gutter) 2rem;
}

.landing__inner {
  width: 100%;
  max-width: 40rem;
  text-align: center;
  /* Sit a touch above true centre — optically nicer. */
  margin-bottom: clamp(0rem, 6vh, 4rem);
}

.tagline {
  margin: 0.9rem 0 2rem;
  color: var(--text-muted);
  font-size: clamp(0.95rem, 2.6vw, 1.075rem);
  text-wrap: balance;
}

/* ------------------------------------------------------------ search box -- */

.searchbox { margin: 0; }

.searchbox__field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  padding: 0.35rem 0.35rem 0.35rem 0.9rem;
  transition: border-color 120ms ease, box-shadow 140ms ease, background-color 120ms ease;
}

.searchbox__field:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

/* The real focus state: ring on the whole field, not an outline on the input. */
.searchbox__field:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow-focus), var(--shadow-sm);
  background: var(--bg-elevated);
}

.searchbox__icon {
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 2;
  stroke-linecap: round;
  transition: stroke 120ms ease;
}

.searchbox__field:focus-within .searchbox__icon { stroke: var(--accent); }

.searchbox__input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1.0625rem;
  padding: 0.55rem 0.15rem;
  appearance: none;
}

.searchbox__input:focus { outline: none; }

.searchbox__input::placeholder { color: var(--text-muted); opacity: 0.85; }

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

.searchbox__clear {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.searchbox__clear:hover { background: var(--bg-sunken); color: var(--text); }

.searchbox__clear svg {
  width: 0.9rem;
  height: 0.9rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}

.searchbox__submit {
  flex: none;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 0.9375rem;
  padding: 0.5rem 1.15rem;
  cursor: pointer;
  transition: background-color 120ms ease, transform 80ms ease, opacity 120ms ease;
}

.searchbox__submit:hover { background: var(--accent-hover); }
.searchbox__submit:active { transform: translateY(1px); }

/* Icon-only fallback, swapped in for the label on narrow screens. */
.searchbox__submit-icon {
  display: none;
  width: 1.05rem;
  height: 1.05rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}

.searchbox__submit[disabled] {
  background: var(--bg-sunken);
  color: var(--text-muted);
  cursor: not-allowed;
}

.searchbox__hint {
  margin: 0.85rem 0 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Only the landing page shows the hotkey hint. */
.searchbox--compact .searchbox__hint { display: none; }

.searchbox--compact .searchbox__field {
  padding-left: 0.75rem;
  box-shadow: none;
}

.searchbox--compact .searchbox__input {
  font-size: 0.9375rem;
  padding-block: 0.4rem;
}

.searchbox--compact .searchbox__submit {
  padding: 0.35rem 0.9rem;
  font-size: 0.875rem;
}

/* Nudge fired by the Stimulus controller when an empty query is submitted. */
.searchbox.is-nudged .searchbox__field {
  animation: searchbox-nudge 320ms ease;
  border-color: var(--border-strong);
}

@keyframes searchbox-nudge {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-4px); }
  75%      { transform: translateX(4px); }
}

/* -------------------------------------------------------- results topbar -- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar__inner {
  display: flex;
  align-items: center;
  gap: clamp(0.75rem, 3vw, 1.75rem);
  max-width: 60rem;
  margin: 0 auto;
  padding: 0.7rem var(--gutter);
}

.topbar__brand {
  flex: none;
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  text-decoration: none;
  color: var(--text);
}

.topbar__brand:hover .wordmark__accent { color: var(--accent-hover); }

.topbar__search {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 34rem;
}

/* -------------------------------------------------------------- results -- */

.results {
  flex: 1;
  width: 100%;
  max-width: 60rem;
  margin: 0 auto;
  padding: 1.5rem var(--gutter) 3rem;
}

/* Line the results column up under the search box, not the brand. */
@media (min-width: 48rem) {
  .results { padding-left: calc(var(--gutter) + 8.5rem); }
}

.results__meta {
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin-bottom: 1.5rem;
}

.results__query { color: var(--text-soft); font-weight: 600; }

.results__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1.65rem;
  max-width: var(--measure);
}

.result {
  position: relative;
  padding: 0.35rem 0.6rem 0.45rem;
  margin-inline: -0.6rem;
  border-radius: var(--radius-md);
  transition: background-color 120ms ease;
}

.result:hover { background: var(--bg-sunken); }

.result__link {
  display: block;
  text-decoration: none;
  color: inherit;
}

.result__url {
  display: block;
  color: var(--url);
  font-size: 0.8125rem;
  line-height: 1.35;
  word-break: break-all;
}

.result__title {
  margin: 0.15rem 0 0.3rem;
  font-size: 1.1875rem;
  font-weight: 500;
  color: var(--link);
  text-wrap: pretty;
}

.result__link:hover .result__title,
.result__link:focus-visible .result__title { text-decoration: underline; }

.result__link:visited .result__title { color: var(--link-visited); }

.result__snippet {
  color: var(--text-soft);
  font-size: 0.9375rem;
  line-height: 1.6;
  max-width: 44rem;
  text-wrap: pretty;
}

/* -------------------------------------------- empty / prompt / notices --- */

.notice {
  max-width: var(--measure);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: clamp(1.25rem, 4vw, 2rem);
}

.notice--prompt { margin-top: 2rem; }

.notice__title {
  font-size: 1.25rem;
  margin-bottom: 0.75rem;
}

.notice__body { color: var(--text-soft); font-size: 0.9375rem; }

.notice__body--muted {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.notice__list {
  margin: 0;
  padding-left: 1.15rem;
  color: var(--text-soft);
  font-size: 0.9375rem;
}

.notice__list li { margin-bottom: 0.35rem; }

/* ----------------------------------------------------------- pagination -- */

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  max-width: var(--measure);
  font-size: 0.9375rem;
}

.pagination__pages {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  list-style: none;
  margin: 0 auto;
  padding: 0;
}

.pagination__page,
.pagination__step {
  display: inline-block;
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--link);
  white-space: nowrap;
}

.pagination__page { min-width: 2.25rem; text-align: center; }

.pagination__page:hover,
.pagination__step:hover { background: var(--bg-sunken); }

.pagination__page--current {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.pagination__page--current:hover { background: var(--accent-soft); }

.pagination__step--off,
.pagination__gap {
  color: var(--text-muted);
  opacity: 0.55;
}

.pagination__step--off:hover { background: none; }

.pagination__gap { padding: 0.35rem 0.3rem; }

/* --------------------------------------------------------------- footer -- */

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-sunken);
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.site-footer__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1.25rem;
  max-width: 60rem;
  margin: 0 auto;
  padding: 1rem var(--gutter);
}

.site-footer__stats strong { color: var(--text-soft); font-weight: 600; }

.site-footer__links {
  display: flex;
  gap: 1rem;
  margin-left: auto;
}

.site-footer__link {
  color: var(--text-muted);
  text-decoration: none;
}

.site-footer__link:hover { color: var(--text); text-decoration: underline; }

.site-footer__link--muted { opacity: 0.75; }

/* ----------------------------------------------------------- responsive -- */

@media (max-width: 30rem) {
  .searchbox__submit-label { display: none; }
  .searchbox__submit-icon { display: block; }

  .searchbox__submit {
    display: grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
  }

  .topbar__inner { gap: 0.6rem; }
  .topbar__brand { font-size: 0; }

  /* Keep just the "S" glyph as a compact home affordance. */
  .topbar__brand::before {
    content: "S";
    font-size: 1.375rem;
    color: var(--accent);
  }

  .topbar__brand .wordmark__text { display: none; }

  .pagination { justify-content: center; }
  .pagination__pages { margin: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ------------------------------------------------------------ dark mode -- */

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --bg-elevated: #1c1f25;
    --bg-sunken: #21252c;
    --border: #2c313a;
    --border-strong: #3b414c;

    --text: #e8e6e1;
    --text-soft: #bdbab3;
    --text-muted: #8b8880;

    --accent: #4ec3b4;
    --accent-hover: #6bd4c6;
    --accent-soft: rgba(78, 195, 180, 0.14);
    --accent-ring: rgba(78, 195, 180, 0.26);

    --link: #8ab4f8;
    --link-visited: #c4a7ec;
    --url: #85c99a;
    --mark-bg: rgba(255, 214, 92, 0.26);
    --mark-text: #ffe9a8;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.4);
  }

  .searchbox__submit { color: #10201e; }

  .skip-link { color: #10201e; }

  .searchbox__submit[disabled] { color: var(--text-muted); }

  .topbar { background: color-mix(in srgb, var(--bg) 85%, transparent); }
}
