:root {
  --ink: #14201f;
  --ink-2: #4a5857;
  --muted: #6c7a79;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --line: #e2ded4;
  --accent: #0f3d3e;
  --accent-2: #1f6f6b;
  --accent-soft: #e3efec;
  --preprint: #9a5b00;
  --preprint-soft: #fbefd9;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --oa: #2f6b2f;
  --oa-soft: #e5f2e1;
  --radius: 12px;
  --serif: "Iowan Old Style", "Charter", "Source Serif Pro", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e9eeec;
    --ink-2: #b9c4c2;
    --muted: #8d9b99;
    --bg: #101615;
    --surface: #172120;
    --line: #26332f;
    --accent: #7fd1c4;
    --accent-2: #9fe0d5;
    --accent-soft: #1d3330;
    --preprint: #f0b862;
    --preprint-soft: #3a2c14;
    --danger: #ff8a7e;
    --danger-soft: #3d1b18;
    --oa: #9bd39b;
    --oa-soft: #1d2f1d;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.5 var(--sans);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
a { color: inherit; }
code { font-size: 0.9em; background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; font: 600 18px/1 var(--serif); letter-spacing: 0.2px; }
.brand-lg { font-size: 28px; justify-content: center; }
.mark {
  width: 22px; height: 22px; border-radius: 6px; flex: none;
  background:
    linear-gradient(var(--surface), var(--surface)) 5px 6px / 12px 2px no-repeat,
    linear-gradient(var(--surface), var(--surface)) 5px 10px / 12px 2px no-repeat,
    linear-gradient(var(--surface), var(--surface)) 5px 14px / 8px 2px no-repeat,
    var(--accent);
}
.brand-lg .mark { width: 30px; height: 30px; }

/* ---------- buttons & inputs ---------- */
.btn {
  font: 500 15px/1 var(--sans); color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 16px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--accent-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); color: var(--surface); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-sm { padding: 7px 11px; font-size: 14px; }
.btn-wide { display: block; width: 100%; margin: 16px 0 8px; }
.btn-danger { color: var(--danger); }

input[type="search"], input[type="text"], input[type="password"], select {
  font: 16px/1.3 var(--sans); color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent-2); outline-offset: 2px;
}

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 32px 26px; display: grid; gap: 14px; text-align: center;
}
.login-card p { margin: 0 0 6px; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px;
  padding: 12px max(16px, env(safe-area-inset-left)); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tabs button {
  font: 500 15px/1 var(--sans); background: none; border: 0; color: var(--ink-2);
  padding: 9px 12px; border-radius: 8px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
main { max-width: 820px; margin: 0 auto; padding: 20px 16px 60px; }
.view-head h1 { font: 600 26px/1.2 var(--serif); margin: 4px 0 2px; }
.view-head p { margin: 0 0 16px; }

/* ---------- search ---------- */
.searchbar { display: flex; gap: 8px; }
.searchbar input { font-size: 17px; padding: 13px 15px; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin: 12px 0 6px; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.segmented button {
  font: 500 14px/1 var(--sans); background: none; border: 0; color: var(--ink-2);
  padding: 9px 13px; cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--surface); }
.select { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-2); }
.select select { width: auto; padding: 8px 10px; font-size: 14px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.status { font-size: 14px; color: var(--muted); min-height: 1.4em; margin: 10px 2px; }
.status .warn { color: var(--preprint); }
.save-alert {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--accent-soft); border-radius: var(--radius); padding: 10px 12px 10px 14px; margin: 0 0 8px; font-size: 14px;
}
.save-alert strong { font-weight: 600; word-break: break-word; }

/* ---------- results ---------- */
.results { list-style: none; margin: 0; padding: 0; }
.paper {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px 16px 13px; margin: 10px 0;
}
.paper.retracted { border-color: var(--danger); box-shadow: inset 4px 0 0 var(--danger); }
.paper .title { font: 600 18px/1.35 var(--serif); margin: 4px 0 6px; }
.paper .title a { text-decoration: none; }
.paper .title a:hover { text-decoration: underline; text-underline-offset: 3px; }
.paper .meta { margin: 0; font-size: 14px; color: var(--ink-2); }
.paper .meta .venue { font-style: italic; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  font: 600 11px/1 var(--sans); letter-spacing: .4px; text-transform: uppercase;
  padding: 4px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
}
.badge.preprint { background: var(--preprint-soft); color: var(--preprint); }
.badge.retracted { background: var(--danger-soft); color: var(--danger); }
.badge.oa { background: var(--oa-soft); color: var(--oa); }
.badge.kw { background: transparent; color: var(--muted); border: 1px solid var(--line); text-transform: none; letter-spacing: 0; font-weight: 500;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.abstract { margin-top: 8px; }
.abstract summary { cursor: pointer; font-size: 14px; color: var(--accent-2); font-weight: 500; }
.abstract p { margin: 8px 0 2px; font-size: 15px; color: var(--ink-2); }
.no-abstract { font-size: 13px; margin: 8px 0 0; }
.notices { display: grid; gap: 6px; }
.notice { margin-top: 8px; font-size: 14px; padding: 8px 10px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); }
.notice a { font-weight: 600; }
.notice.minor { background: var(--accent-soft); color: var(--ink-2); }

.empty { text-align: center; padding: 40px 10px; color: var(--muted); }
.skeleton { height: 110px; border-radius: var(--radius); margin: 10px 0; background: linear-gradient(90deg, var(--surface), var(--line), var(--surface)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.help { margin-top: 28px; font-size: 14px; color: var(--ink-2); }
.help summary { cursor: pointer; font-weight: 500; }
.help table { border-collapse: collapse; margin: 10px 0; }
.help td { padding: 4px 14px 4px 0; }

/* ---------- alerts ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.kw-form { display: grid; gap: 10px; }
.kw-form > label { font-weight: 600; font-size: 14px; }
.sources { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px 16px; }
.sources legend { font-size: 13px; color: var(--muted); padding: 0; margin-bottom: 4px; }
.row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.kw-list { list-style: none; padding: 0; margin: 16px 0; }
.kw {
  display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 12px 12px 14px; margin: 8px 0;
}
.kw.off { opacity: .55; }
.kw .q { flex: 1; min-width: 0; }
.kw .q code { background: none; padding: 0; font-size: 14px; word-break: break-word; }
.kw .q small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.switch { position: relative; width: 40px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: var(--surface); border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--accent-2); }
.switch input:checked + span::before { transform: translateX(16px); }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 10;
}

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding-bottom: 8px; }
  .tabs { order: 3; width: 100%; margin: 0; }
  .tabs button { flex: 1; }
  #logout { margin-left: auto; }
  .searchbar .btn { padding: 0 14px; }
  .paper .title { font-size: 17px; }
  .save-alert { flex-direction: column; align-items: stretch; }
  .kw { flex-wrap: wrap; row-gap: 8px; }
  .kw .q { flex-basis: calc(100% - 56px); }
  .kw .btn:first-of-type { margin-left: 52px; }
}
