/* Black and white. Light by default, dark when the system asks, overridable via [data-theme]. */
:root {
  --bg: #ffffff;
  --fg: #000000;
  --muted: #5e5e5e;
  --faint: #737373;
  --line: #e4e4e4;
  --hover: #f3f3f3;
  --hl: #e2e2e2;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .06);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --fg: #ffffff;
    --muted: #a3a3a3;
    --faint: #8c8c8c;
    --line: #262626;
    --hover: #121212;
    --hl: #3a3a3a;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000;
  --fg: #ffffff;
  --muted: #a3a3a3;
  --faint: #8c8c8c;
  --line: #262626;
  --hover: #121212;
  --hl: #3a3a3a;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }

/* ---------------------------------------------------------------- buttons */

button { cursor: pointer; }
button.icon {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; padding: 0;
  border: 0; border-radius: 50%; background: none; color: var(--muted);
}
button.icon:hover { color: var(--fg); background: var(--hover); }
button.icon svg { width: 20px; height: 20px; }
button.text, a.text {
  border: 0; background: none; padding: 0; color: var(--muted);
  font-size: .85rem; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px;
}
button.text:hover, a.text:hover { color: var(--fg); text-decoration-color: currentColor; }
button.solid, dialog button {
  border: 1px solid var(--fg); border-radius: 6px; padding: 6px 14px; background: var(--bg);
}
button.solid { background: var(--fg); color: var(--bg); }
dialog button:hover:not(.solid) { background: var(--hover); }

/* ---------------------------------------------------------------- top bar / home */

.bar {
  display: flex; align-items: center; gap: 16px;
  max-width: 860px; margin: 0 auto; padding: 14px 16px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; flex-shrink: 0;
}
.logo { width: 34px; height: 34px; }
.wordmark { font-family: var(--serif); font-size: 1.2rem; letter-spacing: .01em; }

.search {
  position: relative; flex: 1; min-width: 0;
  display: flex; align-items: center;
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg);
  padding: 0 6px 0 44px; height: 46px;
  transition: border-color .15s, box-shadow .15s;
}
.search:hover { box-shadow: var(--shadow); }
.search:focus-within { border-color: var(--fg); box-shadow: var(--shadow); }
.search-icon { position: absolute; left: 16px; width: 18px; height: 18px; color: var(--faint); pointer-events: none; }
.search input {
  flex: 1; min-width: 0; height: 100%;
  border: 0; outline: 0; background: none; font-size: 1rem;
}
.search input::placeholder { color: var(--faint); }
.search input::-webkit-search-cancel-button { filter: grayscale(1); }
.corner { display: flex; gap: 2px; flex-shrink: 0; }

body.home .bar {
  flex-direction: column; gap: 28px;
  padding-top: max(48px, 22vh); max-width: 640px;
}
body.home .brand { flex-direction: column; gap: 14px; }
body.home .logo { width: 96px; height: 96px; }
body.home .wordmark { font-size: 2.1rem; }
body.home .search { width: 100%; flex: none; height: 52px; }
body.home .corner { position: fixed; top: 14px; right: 16px; }

body.results .bar {
  position: sticky; top: 0; z-index: 5; max-width: none;
  background: var(--bg); border-bottom: 1px solid var(--line);
  /* Full-width bar with a border, content aligned to the 860px column below. */
  padding-inline: max(16px, calc((100% - 860px) / 2 + 16px));
}
body.results .wordmark { display: none; }

.stats {
  text-align: center; color: var(--faint); font-size: .9rem;
  margin: 4px 0 0; padding: 0 16px;
}
.stats button { font-size: inherit; }

/* ---------------------------------------------------------------- notices */

.notices {
  max-width: 860px; margin: 0 auto; padding: 0 16px;
  display: grid; gap: 6px;
}
body.home .notices { max-width: 640px; margin-top: 20px; }
body.results .notices:not(:empty) { margin-top: 12px; }
.notice {
  display: flex; align-items: flex-start; gap: 10px;
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; font-size: .9rem;
}
.notice .state { width: 16px; flex-shrink: 0; text-align: center; font-weight: 700; }
.notice .msg { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.notice .sub { display: block; color: var(--muted); font-size: .85rem; }
.notice.err { border-color: var(--fg); }
.notice .close { width: 24px; height: 24px; margin: -3px -4px -3px 0; }
.notice .close svg { width: 14px; height: 14px; }
.notice button.text { font-size: inherit; }
.spinner {
  display: inline-block; width: 12px; height: 12px; margin-top: 4px;
  border: 1.5px solid var(--line); border-top-color: var(--fg); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- results */

main { max-width: 860px; margin: 0 auto; padding: 0 16px 48px; }
.results-head {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px;
  color: var(--muted); font-size: .88rem; padding: 18px 0 6px;
}
.filter { display: flex; gap: 14px; }
.filter button {
  border: 0; background: none; padding: 2px 0; color: var(--faint); font-size: .88rem;
  border-bottom: 1px solid transparent;
}
.filter button:hover { color: var(--fg); }
.filter button.active { color: var(--fg); border-bottom-color: var(--fg); }
.filter .n { font-variant-numeric: tabular-nums; margin-left: 3px; }

.papers { list-style: none; margin: 0; padding: 0; }
.paper {
  display: grid; grid-template-columns: 22px 1fr; gap: 0 10px;
  padding: 16px 0; border-top: 1px solid var(--line);
}
.paper:first-child { border-top: 0; }
.paper.flash { animation: flash 1.8s ease-out; }
@keyframes flash { from { background: var(--hl); } to { background: transparent; } }

.dot {
  width: 22px; height: 22px; margin-top: 3px; padding: 0; border: 0; background: none;
  display: grid; place-items: center;
}
.dot::before {
  content: ""; width: 9px; height: 9px; border-radius: 50%;
  border: 1.5px solid var(--fg); background: var(--fg);
}
.paper.read .dot::before { background: transparent; border-color: var(--faint); }
.dot:hover::before { transform: scale(1.25); }

.paper .title {
  font-family: var(--serif); font-size: 1.12rem; line-height: 1.35;
  text-decoration: none; font-weight: 600;
}
a.title:hover { text-decoration: underline; text-underline-offset: 3px; }
.paper.read .title { font-weight: 400; color: var(--muted); }
.meta { color: var(--muted); font-size: .86rem; margin-top: 3px; overflow-wrap: anywhere; }
.meta a { text-decoration-color: var(--line); text-underline-offset: 2px; }
.meta a:hover { text-decoration-color: currentColor; }
.excerpt { font-size: .9rem; margin: 6px 0 0; color: var(--muted); overflow-wrap: anywhere; }
.excerpt.clamp {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer;
}
.excerpt.clamp.open { -webkit-line-clamp: unset; }
.excerpt.clamp:focus-visible { outline-offset: 4px; }
#load-more:disabled { opacity: .5; cursor: progress; }
mark { background: var(--hl); color: var(--fg); border-radius: 2px; padding: 0 1px; }
.notes {
  font-size: .88rem; margin-top: 8px; white-space: pre-wrap;
  border-left: 2px solid var(--fg); padding-left: 10px;
}
.tags { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; }
.tags button {
  border: 0; background: none; padding: 0; font-size: .8rem; color: var(--faint);
}
.tags button::before { content: "#"; opacity: .6; }
.tags button:hover { color: var(--fg); }
.actions-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; margin-top: 10px; }
.actions-row .no-pdf { font-size: .82rem; color: var(--faint); }

.import-prompt {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px dashed var(--faint); border-radius: 8px; padding: 16px; margin-top: 8px;
}
.import-prompt p { margin: 0; overflow-wrap: anywhere; min-width: 0; }
.import-prompt kbd {
  font: .78rem var(--sans); border: 1px solid currentColor; border-radius: 4px; padding: 0 5px;
  color: inherit; opacity: .75; margin-left: 4px;
}
.empty { color: var(--muted); padding: 24px 0; }
.more { text-align: center; margin-top: 16px; }

/* ---------------------------------------------------------------- drop overlay */

.drop-overlay {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  pointer-events: none;
}
.drop-overlay span {
  border: 1.5px dashed var(--fg); border-radius: 14px; padding: 40px 56px;
  font-family: var(--serif); font-size: 1.4rem;
}

/* ---------------------------------------------------------------- editor dialog */

dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 0;
  background: var(--bg); color: var(--fg);
  width: min(640px, calc(100vw - 32px));
}
dialog::backdrop { background: rgb(0 0 0 / .5); }
#edit-form { padding: 20px 22px; display: grid; gap: 12px; }
#edit-form h2 { margin: 0 0 2px; font: 600 1.25rem var(--serif); }
#edit-form label { display: grid; gap: 4px; font-size: .82rem; color: var(--muted); }
#edit-form input:not([type="checkbox"]), #edit-form textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: var(--bg);
  color: var(--fg); font-size: .95rem; min-width: 0;
}
#edit-form input:not([type="checkbox"]):focus, #edit-form textarea:focus { outline: 0; border-color: var(--fg); }
#edit-form .check { display: flex; align-items: center; gap: 8px; color: var(--fg); font-size: .9rem; }
#edit-form .check input { accent-color: var(--fg); }
.hint { font-size: .76rem; color: var(--faint); }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row .grow { flex: 1 1 200px; }
.actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.actions .grow { flex: 1; }

/* ---------------------------------------------------------------- small screens */

@media (max-width: 560px) {
  body.home .logo { width: 76px; height: 76px; }
  body.home .wordmark { font-size: 1.7rem; }
  body.results .bar { gap: 8px; padding: 10px 12px; }
  body.results .logo { width: 28px; height: 28px; }
  .search { height: 44px; padding-left: 40px; }
  .search-icon { left: 14px; }
}

/* ---------------------------------------------------------------- login page */

body.login { display: grid; place-items: center; padding: 16px; }
.login-box { width: min(340px, 100%); display: grid; justify-items: center; gap: 14px; margin-top: -8vh; }
.login-box .logo { width: 76px; height: 76px; }
.login-box .wordmark { font-size: 1.8rem; font-weight: 400; margin: 0 0 10px; }
.login-form { width: 100%; display: grid; gap: 12px; }
.login-form label { display: grid; gap: 4px; font-size: .82rem; color: var(--muted); }
.login-form input {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--bg); color: var(--fg);
  font-size: 1rem;
}
.login-form input:focus { outline: 0; border-color: var(--fg); }
.login-form button { padding: 10px; border: 1px solid var(--fg); border-radius: 8px; margin-top: 6px; font-weight: 600; }
.login-error { margin: 0; padding: 9px 12px; border: 1px solid var(--fg); border-radius: 8px; font-size: .9rem; }
