/* ==========================================================================
   BioDesk
   A reading tool, so: paper-coloured ground, one accent per source, and type
   that stays out of the way. Light and dark both defined explicitly.
   Contrast is held at WCAG 2.1 AA or better throughout — the muted greys are
   the tightest pair at ~7:1, and every accent is used as a background only
   with white text over it.
   ========================================================================== */

:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #14161a;
  --ink-2: #3b414b;
  --muted: #5b6270;
  --line: #e0ddd5;
  --line-strong: #cbc7bd;
  --accent: #1f4e96;
  --accent-ink: #1a4485;
  --focus: #b45309;
  --shadow: 0 1px 2px rgba(20, 22, 26, .06), 0 6px 20px -12px rgba(20, 22, 26, .28);
  --radius: 12px;
  --maxw: 1220px;
  --bar-h: 60px;

  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101216;
    --surface: #171a20;
    --surface-2: #1d2128;
    --ink: #eef0f4;
    --ink-2: #c3c9d4;
    --muted: #9aa3b2;
    --line: #272c35;
    --line-strong: #39404c;
    --accent: #7ba7e8;
    --accent-ink: #9dbdf0;
    --focus: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -14px rgba(0, 0, 0, .8);
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 650; letter-spacing: -.011em; }

a { color: var(--accent-ink); }

button, input { font: inherit; color: inherit; }

/* Visible focus everywhere, and never removed. */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  background: var(--surface); color: var(--ink);
  padding: 10px 16px; border-radius: 8px; border: 2px solid var(--accent);
  text-decoration: none; font-weight: 600;
  transition: top .15s ease;
}
.skip-link:focus { top: 8px; }

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

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

.topbar-inner {
  max-width: var(--maxw); margin: 0 auto;
  padding: 10px 20px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
}

.brand {
  display: inline-flex; align-items: center; gap: 9px;
  color: var(--ink); text-decoration: none;
  font-weight: 700; font-size: 17px; letter-spacing: -.02em;
}
.brand-mark { color: var(--accent); display: inline-flex; }
.brand:hover .brand-text { text-decoration: underline; text-underline-offset: 3px; }

.search {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 4px 5px 4px 14px;
  box-shadow: var(--shadow);
  transition: border-color .15s ease, box-shadow .15s ease;
}
/* The input itself drops its outline (it would trace a rectangle inside a pill), so the
   wrapper has to carry a real, visible focus indicator — not just a border tint. */
.search:focus-within {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 45%, transparent), var(--shadow);
}
.search-icon { color: var(--muted); flex: none; }

.search input {
  flex: 1; min-width: 0;
  border: 0; background: none; padding: 8px 2px;
  font-size: 15px;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; }
.search input::-webkit-search-cancel-button { cursor: pointer; }

.search-go {
  flex: none;
  border: 0; border-radius: 999px;
  background: var(--accent); color: #fff;
  padding: 9px 18px; font-weight: 600; font-size: 14px;
  cursor: pointer;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .search-go { color: #0d1017; }
}
.search-go:hover { filter: brightness(1.08); }

.tabs { display: flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.tab {
  border: 0; background: none; cursor: pointer;
  padding: 7px 15px; border-radius: 999px;
  font-size: 14px; font-weight: 600; color: var(--muted);
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.is-current { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

@media (max-width: 860px) {
  .topbar-inner { grid-template-columns: auto auto; grid-template-areas: "brand tabs" "search search"; row-gap: 10px; }
  .brand { grid-area: brand; }
  .tabs { grid-area: tabs; justify-self: end; }
  .search { grid-area: search; }
}

/* -------------------------------------------------------------------- main */

main { max-width: var(--maxw); margin: 0 auto; padding: 34px 20px 80px; }
main:focus { outline: none; }

.view-head { margin-bottom: 26px; max-width: 62ch; }
.view-head h1 { font-size: clamp(24px, 3.4vw, 33px); font-family: var(--serif); font-weight: 600; letter-spacing: -.02em; }
.lede { margin: 8px 0 0; color: var(--muted); font-size: 15.5px; }

.loading { color: var(--muted); }

/* ------------------------------------------------------------------- cards */

.group { margin-bottom: 42px; }
.group-head {
  display: flex; align-items: baseline; gap: 12px;
  margin: 0 0 14px; padding-bottom: 9px;
  border-bottom: 1px solid var(--line);
}
.group-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 700; }
.group-count { font-size: 13px; color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.card {
  position: relative;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 12px;
  box-shadow: var(--shadow);
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.card:focus-within { border-color: var(--accent); }

.card-top { display: flex; gap: 12px; align-items: flex-start; }

.card-icon {
  flex: none;
  width: 42px; height: 42px; border-radius: 10px;
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 15px; letter-spacing: -.03em;
  font-family: var(--mono);
}

.card-title { font-size: 16.5px; margin: 0 0 2px; }
.card-title button {
  border: 0; background: none; padding: 0; cursor: pointer;
  font: inherit; color: var(--ink); text-align: left;
}
/* The whole card is clickable for a mouse; the title stays the real control
   for a keyboard, so nothing here is mouse-only. */
.card-title button::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.card-title button:hover { color: var(--accent-ink); }

.card-blurb { margin: 4px 0 0; color: var(--muted); font-size: 13.6px; line-height: 1.5; }

.card-preview { margin: 13px 0 0; padding: 12px 0 0; border-top: 1px dashed var(--line); list-style: none; }
.card-preview li { margin: 0 0 7px; }
.card-preview li:last-child { margin-bottom: 0; }
.card-preview a {
  position: relative; z-index: 1;
  display: block; color: var(--ink-2); text-decoration: none;
  font-size: 13.4px; line-height: 1.45;
  padding-left: 13px;
}
.card-preview a::before {
  content: ""; position: absolute; left: 2px; top: .62em;
  width: 4px; height: 4px; border-radius: 50%; background: var(--line-strong);
}
.card-preview a:hover { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; }
/* Two lines each. Paper titles run long and a single greedy card would otherwise set the
   row height for every card beside it. */
.card-preview a {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-note { margin: 13px 0 0; padding: 12px 0 0; border-top: 1px dashed var(--line); color: var(--muted); font-size: 13px; font-style: italic; }

.card-foot {
  margin-top: auto; padding-top: 11px;
  display: flex; align-items: center; gap: 10px;
  font-size: 12px; color: var(--muted);
}
.card-foot .spacer { margin-left: auto; }
.card-foot a { position: relative; z-index: 1; color: var(--muted); text-decoration: none; }
.card-foot a:hover { color: var(--accent-ink); text-decoration: underline; }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--line-strong); border-radius: 999px;
  padding: 2px 8px; font-size: 11px; font-weight: 600;
  color: var(--muted); background: var(--surface-2);
  white-space: nowrap;
}
.pill.api { color: #fff; background: var(--accent); border-color: transparent; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pill.api { color: #0d1017; }
}

.deskfoot { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding-top: 14px; border-top: 1px solid var(--line); }

.live { display: inline-flex; align-items: center; gap: 8px; margin: 0; color: var(--muted); font-size: 13.5px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); flex: none; }
.live-dot[data-state="live"] { background: #2f855a; }
.live-dot[data-state="busy"] { background: var(--focus); animation: pulse 1.4s ease-in-out infinite; }
.live-dot[data-state="offline"] { background: var(--line-strong); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .live-dot[data-state="live"] { background: #68d391; }
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.pill.warn { color: #fff; background: #9b2c2c; border-color: transparent; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pill.warn { color: #1a0d0d; background: #f6a6a6; }
}
.ghost-btn {
  border: 1px solid var(--line-strong); background: var(--surface);
  border-radius: 8px; padding: 9px 16px; cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--ink-2);
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent-ink); }
.ghost-btn[disabled] { opacity: .55; cursor: progress; }
.muted-note { color: var(--muted); font-size: 13.5px; }

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

.results { display: grid; gap: 30px; }

.result-block h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--muted); font-weight: 700;
  margin-bottom: 12px; padding-bottom: 9px; border-bottom: 1px solid var(--line);
}

.hit {
  display: block; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 16px; margin-bottom: 10px;
  cursor: pointer;
}
.hit:hover { border-color: var(--line-strong); }
.hit-title { font-weight: 620; font-size: 15.5px; margin: 0 0 5px; color: var(--ink); }
.hit-snip { margin: 0; color: var(--muted); font-size: 13.6px; line-height: 1.55; }
.hit-meta { margin: 7px 0 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.hit-src { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; }
/* inline-block matters: outside a flex row (the What's new headings) an inline span would
   ignore width and height entirely, and the dot silently vanishes. */
.hit-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }
mark { background: color-mix(in srgb, var(--focus) 32%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--surface); padding: 7px 14px;
  font-size: 13.4px; font-weight: 600; color: var(--ink-2);
  text-decoration: none; cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent-ink); }

.empty { color: var(--muted); background: var(--surface); border: 1px dashed var(--line-strong); border-radius: 10px; padding: 22px; }

/* --------------------------------------------------------------- new feed */

.newfeed { display: grid; gap: 26px; }
.newfeed .group-head { margin-bottom: 10px; }
.newfeed ul { list-style: none; margin: 0; padding: 0; }
.newfeed li { border-bottom: 1px solid var(--line); }
.newfeed li:last-child { border-bottom: 0; }
.newfeed button {
  display: block; width: 100%; text-align: left;
  border: 0; background: none; cursor: pointer;
  padding: 11px 4px; font-size: 15px; color: var(--ink); line-height: 1.45;
}
.newfeed button:hover { color: var(--accent-ink); }
.newfeed .when { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ------------------------------------------------------------------ viewer */

.viewer {
  position: fixed; inset: 0; z-index: 60;
  display: flex; flex-direction: column;
  background: var(--bg);
}
.viewer[hidden] { display: none; }

.viewer-bar {
  flex: none; height: var(--bar-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.viewer-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.viewer-title {
  font-size: 15px; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 34vw;
}
.viewer-url {
  color: var(--muted); font-size: 12.5px; font-family: var(--mono);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 30vw;
}
.viewer-spacer { margin-left: auto; }
.viewer-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--surface); color: var(--ink-2);
  padding: 8px 13px; font-size: 13.5px; font-weight: 600;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.viewer-btn:hover { border-color: var(--accent); color: var(--accent-ink); }

.viewer-stage { position: relative; flex: 1; min-height: 0; background: var(--surface); }
.viewer-stage iframe { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
/* `display: block` above outranks the UA rule for [hidden], so without this the hidden
   iframe keeps its full height and pushes the reader panel below the fold — a blank
   viewer with all its content sitting off-screen. */
.viewer-stage iframe[hidden] { display: none; }

.viewer-loading {
  position: absolute; inset: 0; z-index: 2;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  background: var(--bg); color: var(--muted); font-size: 14.5px;
}
.viewer-loading[hidden] { display: none; }
.spinner {
  width: 17px; height: 17px; border-radius: 50%;
  border: 2px solid var(--line-strong); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 700px) {
  .viewer-url { display: none; }
  .viewer-title { max-width: 46vw; }
}

/* ------------------------------------------------------------ reader view */

/* Pinned to the stage rather than relying on flow, so it fills the viewer whatever else
   is or isn't in there. */
.reader { position: absolute; inset: 0; overflow: auto; padding: 34px 22px 70px; background: var(--surface); }
.reader-inner { max-width: 70ch; margin: 0 auto; }
.reader-note {
  display: flex; gap: 11px; align-items: flex-start;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 13px 15px; margin-bottom: 28px;
  font-size: 13.6px; color: var(--ink-2); line-height: 1.55;
}
/* The accent rides on the icon rather than a stripe down the edge: the glyph is already
   the thing drawing the eye, and it says "note" without the callout looking stencilled. */
.reader-note .note-icon { color: var(--accent); font-size: 15px; line-height: 1.4; flex: none; }
.reader h1 { font-family: var(--serif); font-size: 28px; font-weight: 600; margin-bottom: 6px; }
.reader .reader-src { color: var(--muted); font-size: 13.5px; margin: 0 0 26px; }
.reader p { margin: 0 0 15px; color: var(--ink-2); font-size: 16px; line-height: 1.72; }
.reader .abstract-label {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted); font-weight: 700;
  margin: 22px 0 7px;
}
.reader .abstract-label:first-of-type { margin-top: 4px; }
.reader-more { margin-top: 32px; padding-top: 18px; border-top: 1px solid var(--line); }
.reader-more h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); margin-bottom: 12px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  .card:hover { transform: none; }
}
