/* assets/search.css
   ---------------------------------------------------------------------------
   Palette and type borrowed from ~/code/Portfolio: zinc ground, hairline
   borders, Cal Sans for display type, a sky focus ring.

   Hand-written rather than Tailwind: this is one stylesheet and the project
   has no node toolchain.

   Breakpoints (min-width, mobile first):
     -        0     single column, rail collapsed into a disclosure
     --bp-sm  30rem / 480px   two-up result metadata, roomier spacing
     --bp-md  48rem / 768px   inline search button, wider gutters
     --bp-lg  64rem / 1024px  rail becomes a permanent sidebar
     --bp-xl  90rem / 1440px  wider shell, larger measure

   Media queries cannot read custom properties, so the rem values above are
   repeated literally at each @media. Change both.
   --------------------------------------------------------------------------- */

@font-face {
  font-family: "Cal Sans";
  src: url("fonts/CalSans-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-display: swap;
}

:root {
  /* --- colour ------------------------------------------------------------ */
  --ground: #09090b;
  --raise: #101013;
  --surface: #18181b;
  --surface-hi: #202024;
  --line: #26262b;
  --line-hi: #35353c;

  --text: #f4f4f5;
  --muted: #a1a1aa;
  --faint: #6b6b76;

  --accent: #a78bfa;
  --accent-dim: #2a2340;
  --ring: #38bdf8;
  --mark: #fcd34d;

  /* --- type -------------------------------------------------------------- */
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --display: "Cal Sans", var(--sans);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Fluid scale: each step interpolates between its small and large screen
     size, so nothing needs a font-size media query. */
  --t-micro: 0.6875rem;
  --t-small: clamp(0.78rem, 0.74rem + 0.18vw, 0.86rem);
  --t-body: clamp(0.94rem, 0.90rem + 0.20vw, 1.02rem);
  --t-title: clamp(1.05rem, 0.98rem + 0.42vw, 1.30rem);
  --t-brand: clamp(1.00rem, 0.95rem + 0.30vw, 1.18rem);

  /* --- space ------------------------------------------------------------- */
  --gutter: clamp(1rem, 0.55rem + 2.2vw, 2rem);
  --shell: 78rem;
  --measure: 44rem;
  --rail: 15rem;

  --r-sm: 0.375rem;
  --r-md: 0.5rem;
  --r-lg: 0.75rem;
  --r-pill: 999px;

  /* Minimum comfortable touch target. */
  --tap: 2.75rem;
}

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

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

body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--t-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  /* Long story titles and tag strings must never widen the page. */
  overflow-wrap: break-word;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
p { margin: 0; }
ol, ul { margin: 0; padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }

:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.texture {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.022) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.022) 1px, transparent 1px);
  background-size: 72px 72px;
  -webkit-mask-image: linear-gradient(to bottom, #000, transparent 38%);
  mask-image: linear-gradient(to bottom, #000, transparent 38%);
}

.shell {
  width: 100%;
  max-width: var(--shell);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* ===========================================================================
   Masthead
   =========================================================================== */

.topbar {
  position: relative;
  z-index: 2;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 9, 11, 0.72);
  backdrop-filter: blur(10px);
}
.topbar .shell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.5rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--display);
  font-size: var(--t-brand);
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 14px rgba(167, 139, 250, 0.55);
}
.brand-note {
  color: var(--faint);
  font-size: var(--t-micro);
  letter-spacing: 0.04em;
}
/* The disclaimer is the first thing to go when width is scarce. */
@media (max-width: 47.99rem) { .brand-note { display: none; } }

/* ===========================================================================
   Search dock
   =========================================================================== */

.searchdock {
  position: sticky;
  top: 0;
  z-index: 30;
  padding-block: clamp(0.75rem, 0.4rem + 1.4vw, 1.35rem);
  background: rgba(9, 9, 11, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.searchbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
}
@media (min-width: 48rem) {
  .searchbar { grid-template-columns: 1fr auto; gap: 0.6rem; }
}

.combo { position: relative; min-width: 0; }

.combo-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  translate: 0 -50%;
  width: 1.05rem;
  height: 1.05rem;
  fill: none;
  stroke: var(--faint);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

.combo input {
  width: 100%;
  min-height: var(--tap);
  padding: 0.6rem 0.9rem 0.6rem 2.45rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  color: var(--text);
  font: inherit;
  font-size: var(--t-body);
}
.combo input::placeholder {
  color: var(--faint);
  /* The placeholder documents the query language; truncate it rather than
     let it stretch the field on narrow screens. */
  text-overflow: ellipsis;
}
.combo input:focus { border-color: var(--line-hi); background: var(--surface-hi); }
/* WebKit draws its own clear button, which does not match anything here. */
.combo input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }

.submit {
  min-height: var(--tap);
  padding-inline: 1.1rem;
  border: 0;
  border-radius: var(--r-md);
  background: var(--text);
  color: var(--ground);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}
.submit:hover { background: #fff; }
.submit-icon { display: none; }

#suggest {
  position: absolute;
  inset-inline: 0;
  top: calc(100% + 0.35rem);
  z-index: 40;
  padding: 0.25rem;
  background: var(--raise);
  border: 1px solid var(--line-hi);
  border-radius: var(--r-md);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.6);
  max-height: min(60vh, 24rem);
  overflow-y: auto;
}
#suggest[hidden] { display: none; }
#suggest a {
  display: block;
  padding: 0.55rem 0.65rem;
  border-radius: var(--r-sm);
  color: var(--muted);
  font-size: var(--t-small);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#suggest li.active a,
#suggest a:hover { background: var(--surface-hi); color: var(--text); }

/* ===========================================================================
   Layout
   =========================================================================== */

main { position: relative; z-index: 1; padding-block: clamp(1.1rem, 0.7rem + 1.6vw, 2rem) 5rem; }

#panel-wrap { transition: opacity 140ms ease; }
#panel-wrap.htmx-request { opacity: 0.4; }

.layout { display: grid; gap: clamp(1.1rem, 0.7rem + 1.6vw, 2.25rem); }
@media (min-width: 64rem) {
  .layout { grid-template-columns: var(--rail) minmax(0, 1fr); align-items: start; }
  .layout-solo { grid-template-columns: minmax(0, 1fr); }
}

.column { min-width: 0; }

/* ===========================================================================
   Filter rail  (a <details> below 1024px, a plain sidebar at and above)
   =========================================================================== */

.rail {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--raise);
}
.rail-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: var(--tap);
  padding-inline: 0.9rem;
  cursor: pointer;
  font-size: var(--t-small);
  font-weight: 600;
  color: var(--muted);
  list-style: none;
}
.rail-summary::-webkit-details-marker { display: none; }
.rail-caret {
  width: 0.5rem;
  height: 0.5rem;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  rotate: 45deg;
  transition: rotate 150ms ease;
}
.rail[open] .rail-caret { rotate: -135deg; }
.rail-body { padding: 0.25rem 0.9rem 1rem; }

@media (min-width: 64rem) {
  /* Permanent sidebar: no chrome, no toggle, sticky beneath the search dock. */
  .rail {
    position: sticky;
    top: 6.5rem;
    border: 0;
    border-right: 1px solid var(--line);
    border-radius: 0;
    background: none;
    padding-right: 1.25rem;
  }
  .rail-summary { display: none; }
  .rail-body { padding: 0; }
  /* The element is closed in the markup so phones get results first. Here it
     must always be visible, which means overriding both the old display-based
     hiding and the newer ::details-content content-visibility. */
  .rail > .rail-body { display: block !important; }
  .rail::details-content { content-visibility: visible !important; block-size: auto !important; }
}

.rail-group + .rail-group { margin-top: 1.15rem; }
.rail-heading {
  font-family: var(--mono);
  font-size: var(--t-micro);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--faint);
  margin-bottom: 0.5rem;
}
.rail-note {
  font-size: var(--t-micro);
  color: var(--faint);
  margin: -0.25rem 0 0.5rem;
  line-height: 1.4;
}

.pillset { display: flex; flex-wrap: wrap; gap: 0.35rem; }

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.9rem;
  padding: 0.2rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--muted);
  font-size: var(--t-small);
  line-height: 1.2;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}
.pill:hover { color: var(--text); border-color: var(--line-hi); background: var(--surface-hi); }
.pill[aria-current="true"] {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: #ddd2ff;
}
/* Coarse pointers need a bigger target than the visual pill implies. */
@media (pointer: coarse) { .pill { min-height: 2.25rem; padding-inline: 0.8rem; } }

/* --- switch, built from a link rather than a checkbox --------------------- */

.switch {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  min-height: var(--tap);
  color: var(--muted);
  font-size: var(--t-small);
}
.switch-track {
  position: relative;
  flex: none;
  width: 2.1rem;
  height: 1.2rem;
  border-radius: var(--r-pill);
  background: var(--surface-hi);
  border: 1px solid var(--line-hi);
  transition: background 140ms ease, border-color 140ms ease;
}
.switch-thumb {
  position: absolute;
  top: 50%;
  left: 0.15rem;
  translate: 0 -50%;
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 50%;
  background: var(--faint);
  transition: translate 140ms ease, background 140ms ease;
}
.switch[aria-checked="true"] .switch-track { background: var(--accent-dim); border-color: var(--accent); }
.switch[aria-checked="true"] .switch-thumb { translate: 0.9rem -50%; background: var(--accent); }
.switch:hover { color: var(--text); }

/* ===========================================================================
   Chips, results bar
   =========================================================================== */

.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.9rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 1.9rem;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--accent);
  border-radius: var(--r-pill);
  background: var(--accent-dim);
  color: #ddd2ff;
  font-size: var(--t-small);
}
.chip:hover { background: #322a4d; }
@media (pointer: coarse) { .chip { min-height: 2.25rem; } }

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  margin-bottom: 1.1rem;
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
  border-radius: var(--r-md);
  background: var(--raise);
  font-size: var(--t-small);
  color: var(--muted);
}
.banner strong { color: var(--text); font-weight: 600; }

.resultsbar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}
.meta {
  font-family: var(--mono);
  font-size: var(--t-micro);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--faint);
}
.meta strong { color: var(--muted); font-weight: 600; }
.meta-sep { padding-inline: 0.35rem; }

/* ===========================================================================
   Result cards
   =========================================================================== */

.result { padding-block: clamp(1.05rem, 0.85rem + 0.8vw, 1.5rem); border-bottom: 1px solid var(--line); }

.result-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.result-title {
  font-family: var(--display);
  font-size: var(--t-title);
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--text);
}
.result-title:hover { color: var(--accent); }
.result-out {
  display: inline-block;
  margin-left: 0.3rem;
  font-size: 0.7em;
  color: var(--faint);
  vertical-align: super;
}
.result-title:hover .result-out { color: var(--accent); }

.rating {
  flex: none;
  font-size: var(--t-small);
  font-variant-numeric: tabular-nums;
  color: var(--mark);
}

.series {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  font-size: var(--t-small);
}
.series-badge {
  padding: 0.1rem 0.45rem;
  border-radius: var(--r-sm);
  background: var(--accent-dim);
  color: #ddd2ff;
  font-size: var(--t-micro);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.series-note { color: var(--faint); font-size: var(--t-micro); }
.series-link { color: var(--accent); border-bottom: 1px solid transparent; }
.series-link:hover { border-bottom-color: currentColor; }

/* Capped in ch, not px: the limit is a character count, so it tracks the
   fluid font size instead of the viewport. Without it a 768px column runs to
   ~95 characters a line, well past comfortable reading. */
.snippet { margin-top: 0.55rem; color: var(--muted); max-width: 68ch; }
.snippet mark {
  background: transparent;
  color: var(--mark);
  font-weight: 600;
}

.facts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.9rem;
  margin-top: 0.65rem;
  font-size: var(--t-small);
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}
.facts .author { color: var(--muted); }

.tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.6rem; }
.tag {
  padding: 0.1rem 0.45rem;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--faint);
  font-size: var(--t-micro);
}
.tag:hover { color: var(--accent); border-color: var(--line-hi); }
@media (pointer: coarse) {
  .tag { padding: 0.3rem 0.55rem; }
  .tags { gap: 0.4rem; }
}

/* ===========================================================================
   Empty state and pager
   =========================================================================== */

.empty {
  padding: clamp(2rem, 1.5rem + 3vw, 3.5rem) 0;
  color: var(--muted);
  max-width: var(--measure);
}
.empty-head { font-family: var(--display); font-size: var(--t-title); color: var(--text); }
.empty-note { margin-top: 0.6rem; font-size: var(--t-small); color: var(--faint); }
.empty code {
  padding: 0.1rem 0.35rem;
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.92em;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
  padding-top: 1.75rem;
}
.pager a,
.pager .current,
.pager .gap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap);
  min-height: var(--tap);
  padding-inline: 0.6rem;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  color: var(--muted);
  font-size: var(--t-small);
  font-variant-numeric: tabular-nums;
}
.pager a { border-color: var(--line); background: var(--surface); }
.pager a:hover { color: var(--text); border-color: var(--line-hi); background: var(--surface-hi); }
.pager .current { background: var(--text); color: var(--ground); font-weight: 650; }
.pager .gap { color: var(--faint); min-width: 1.5rem; }

/* Prev/Next carry words; on the narrowest screens the numbers matter more. */
@media (max-width: 30rem) {
  .pager [rel="prev"], .pager [rel="next"] { flex: 1 1 100%; }
}

/* ===========================================================================
   Narrow-screen adjustments
   =========================================================================== */

@media (max-width: 47.99rem) {
  .submit-full { display: none; }
  .submit-icon { display: inline; font-size: 1.1rem; }
  /* Button sits beside the field rather than under it, so the dock stays
     one row tall and the results are not pushed down. */
  .searchbar { grid-template-columns: minmax(0, 1fr) var(--tap); }
  .submit { padding-inline: 0; }
}

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