:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --subtle: #f4f6f7;
  --text: #16202a;
  --muted: #5d6772;
  --border: #e2e6ea;
  --accent: #0f5c63;
  --accent-hover: #0a474d;
  --accent-text: #ffffff;
  --accent-soft: #eaf3f3;
  --free: #1d7148;
  --free-soft: #eef7f2;
  --maybe: #8a5a00;
  --maybe-soft: #fcf6e9;
  --closed: #9a3b33;
  --closed-soft: #fbefee;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 32, 0.04), 0 4px 16px rgba(16, 24, 32, 0.05);
  --serif: "Iowan Old Style", Charter, "Palatino Linotype", Palatino, "Source Serif Pro", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1417;
    --surface: #161d21;
    --subtle: #141a1e;
    --text: #e7ebee;
    --muted: #9aa5ad;
    --border: #263138;
    --accent: #6cc4bc;
    --accent-hover: #8ad3cc;
    --accent-text: #0b1517;
    --accent-soft: #15282a;
    --free: #72d0a0;
    --free-soft: #13241b;
    --maybe: #e8bd62;
    --maybe-soft: #272114;
    --closed: #ee9a92;
    --closed-soft: #2a1918;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

main, .site-header, .site-footer {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 24px;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; }

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
code { font-size: 0.92em; background: var(--subtle); padding: 1px 5px; border-radius: 4px; word-break: break-all; }

/* ---------- Header and footer ---------- */

.site-header {
  display: flex; align-items: center; gap: 16px;
  padding-top: 22px; padding-bottom: 22px;
}
.brand {
  font-family: var(--serif); font-weight: 600; font-size: 1.2rem; letter-spacing: -0.01em;
  color: var(--text); text-decoration: none;
}
.brand:hover { color: var(--text); }
.beta {
  margin-left: -6px; padding: 1px 7px; border: 1px solid var(--border); border-radius: 4px;
  color: var(--muted); font-size: 0.7rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  cursor: help;
}
.site-nav { margin-left: auto; display: flex; gap: 24px; font-size: 0.95rem; }
.site-nav a { color: var(--muted); text-decoration: none; }
.site-nav a:hover { color: var(--text); }

.site-footer {
  margin-top: 72px; padding-top: 24px; padding-bottom: 40px;
  color: var(--muted); font-size: 0.85rem; line-height: 1.55;
  border-top: 1px solid var(--border);
}
.site-footer p { max-width: 640px; margin: 0 0 8px; }

/* ---------- Home ---------- */

.hero { max-width: 680px; margin: 0 auto; padding: 64px 0 24px; text-align: center; }
.eyebrow {
  margin: 0 0 14px; color: var(--accent);
  font-size: 0.8rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
}
.hero h1 { font-size: clamp(2rem, 5.5vw, 3rem); line-height: 1.12; margin: 0 0 18px; }
.lead { font-size: 1.12rem; color: var(--muted); margin: 0 0 32px; }
.hero .search { margin: 0 auto; }
.search-note { color: var(--muted); font-size: 0.88rem; margin: 12px 0 0; }

.search {
  display: flex; gap: 6px; margin: 20px 0;
  padding: 6px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.search:focus-within { border-color: var(--accent); }
.search input {
  flex: 1; min-width: 0; font: inherit; padding: 10px 12px;
  border: 0; background: transparent; color: var(--text);
}
.search input:focus-visible { outline: none; }
.search input::-webkit-search-cancel-button { cursor: pointer; }

.outcomes {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 40px;
  margin: 72px 0 0; padding-top: 32px; border-top: 1px solid var(--border);
}
.outcome-label {
  margin: 0 0 6px; color: var(--accent);
  font-size: 0.78rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
}
.outcome h2 { font-size: 1.3rem; line-height: 1.25; margin: 0 0 8px; }
.outcome p:last-child { margin: 0; color: var(--muted); font-size: 0.97rem; }

.why {
  display: grid; grid-template-columns: 1.15fr 1fr; gap: 48px;
  margin-top: 72px; padding: 40px; border-radius: 14px; background: var(--subtle);
}
.why h2 { font-size: 1.6rem; margin: 0 0 12px; }
.why-text p { margin: 0 0 12px; }
.why-text p:last-child { margin: 18px 0 0; }
.arrow-link { font-weight: 600; text-decoration: none; }
.arrow-link::after { content: " \2192"; }
.arrow-link:hover { text-decoration: underline; }
.stats { margin: 0; display: flex; flex-direction: column; gap: 22px; }
.stats div + div { padding-top: 22px; border-top: 1px solid var(--border); }
.stats dt { font-family: var(--serif); font-size: 1.75rem; font-weight: 600; line-height: 1.1; letter-spacing: -0.01em; }
.stats dd { margin: 4px 0 0; color: var(--muted); font-size: 0.95rem; }

/* ---------- About ---------- */

.prose { max-width: 680px; padding-top: 32px; }
.prose h1 { font-size: clamp(1.9rem, 5vw, 2.5rem); line-height: 1.15; margin: 0 0 12px; }
.prose h2 { font-size: 1.35rem; margin: 40px 0 8px; }
.prose ul { padding-left: 22px; }
.prose li { margin: 8px 0; }
.prose .button { margin-top: 20px; }

/* ---------- Buttons and forms ---------- */

button, .button {
  font: inherit; font-weight: 600; cursor: pointer;
  display: inline-block; text-decoration: none; text-align: center;
  padding: 10px 20px; border-radius: 8px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text);
  transition: background-color 0.15s, border-color 0.15s;
}
button:hover, .button:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-text); }
button:disabled { opacity: 0.6; cursor: wait; }
.button-secondary { background: transparent; color: var(--accent); }
.button-secondary:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
button:focus-visible, .button:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

/* ---------- Paper page ---------- */

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 24px; margin: 16px 0;
}
.card h2 { font-size: 1.25rem; margin: 0 0 10px; line-height: 1.35; }
.card p { margin: 0 0 10px; }

.paper-head { border: 0; padding: 20px 0 8px; background: transparent; }
.paper-head h1 { font-size: clamp(1.5rem, 4vw, 2rem); line-height: 1.2; margin: 4px 0 10px; }
.meta, .authors, .ids { color: var(--muted); margin: 0 0 4px; }
.meta { font-size: 0.9rem; }

.status { border-left-width: 4px; }
.status-free { background: var(--free-soft); border-color: var(--free-soft); border-left-color: var(--free); }
.status-maybe { background: var(--maybe-soft); border-color: var(--maybe-soft); border-left-color: var(--maybe); }
.status-closed { background: var(--closed-soft); border-color: var(--closed-soft); border-left-color: var(--closed); }

.badge {
  display: inline-block; font-family: var(--sans); font-size: 0.75rem; font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 4px; margin-right: 8px; vertical-align: 3px;
  color: var(--surface);
}
.badge-free { background: var(--free); }
.badge-maybe { background: var(--maybe); }
.badge-closed { background: var(--closed); }
.badge-library { background: var(--accent); }

.copies { list-style: none; padding: 0; margin: 12px 0 0; }
.copy { display: flex; gap: 14px; align-items: flex-start; padding: 10px 0; flex-wrap: wrap; }
.copy + .copy { border-top: 1px solid var(--border); }
.copy .button { flex: none; }
.copy-info { flex: 1; min-width: 200px; }
.pill {
  display: inline-block; font-size: 0.8rem; padding: 1px 8px; margin: 2px 4px 0 0;
  border-radius: 4px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); cursor: help;
}
.pill-quiet { cursor: default; }
.warn { color: var(--maybe); font-size: 0.92rem; margin: 6px 0 0; }
.hint { color: var(--muted); font-size: 0.92rem; }
.hint-list { color: var(--muted); font-size: 0.92rem; padding-left: 20px; margin: 12px 0 0; }

.request-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin: 14px 0 6px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-wide { grid-column: 1 / -1; }
.request-form button { grid-column: 1 / -1; justify-self: start; }
label { font-weight: 600; font-size: 0.92rem; }
select, input[type=text], textarea {
  font: inherit; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); width: 100%;
}
textarea { resize: vertical; line-height: 1.5; }
#ai-prompt { font-size: 0.93rem; }

.draft { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--border); }
.draft-to { font-weight: 600; word-break: break-all; }
.draft-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }

.card h3 { font-size: 1.05rem; margin: 18px 0 6px; }
.library-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; margin: 12px 0 4px; }
.library-form .field { width: 9rem; }
.library-result { margin: 12px 0 4px; padding: 14px 16px; border-radius: var(--radius); background: var(--accent-soft); }
.library-result .library-name { margin: 6px 0 2px; font-size: 1.05rem; }
.library-result .button { margin-top: 6px; }
#ill-citation { font-size: 0.92rem; }
.small { font-size: 0.8rem; }

.steps { padding-left: 20px; margin: 0; }
.steps li { margin: 6px 0; }

.abstract h3 { font-size: 1rem; margin: 14px 0 2px; }
.abstract p { margin: 0 0 8px; }

.loading { display: flex; gap: 14px; align-items: center; color: var(--muted); padding: 30px 0; }
.spinner {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.waking {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 10;
  display: flex; gap: 12px; align-items: center;
  width: min(520px, calc(100% - 32px)); padding: 14px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(16, 24, 32, 0.15); font-size: 0.95rem;
}
.waking p { margin: 0; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

@media (max-width: 760px) {
  .outcomes { grid-template-columns: 1fr; gap: 28px; margin-top: 56px; }
  .why { grid-template-columns: 1fr; gap: 32px; padding: 28px 22px; margin-top: 56px; }
}

@media (max-width: 560px) {
  body { font-size: 16px; }
  main, .site-header, .site-footer { padding: 0 16px; }
  .site-header { padding-top: 16px; padding-bottom: 16px; }
  .hero { padding-top: 36px; }
  .search { flex-direction: column; }
  .search button { width: 100%; }
  .request-form { grid-template-columns: 1fr; }
  .card { padding: 18px; }
}
