:root {
  --ink: #111111;
  --ink-soft: #444444;
  --ink-faint: #888888;
  --paper: #ffffff;
  --paper-2: #f6f6f4;
  --line: #e3e3df;
  --line-strong: #c9c9c3;
  --accent: #111111;
  --radius: 4px;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--ink); text-underline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--paper);
  z-index: 20;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark { font-size: 26px; line-height: 1; }
.brand-name { font-weight: 600; font-size: 22px; letter-spacing: -0.01em; }
.topnav { display: flex; gap: 4px; }
.navbtn {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: none;
  border: 1px solid transparent;
  color: var(--ink-faint);
  padding: 7px 12px;
  border-radius: var(--radius);
  cursor: pointer;
}
.navbtn:hover { color: var(--ink); }
.navbtn.is-active { color: var(--ink); border-color: var(--line-strong); }

/* ---------- layout ---------- */
.wrap { max-width: 820px; margin: 0 auto; padding: 32px 28px 96px; }
.view { display: none; }
.view.is-active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

h2 { font-weight: 600; font-size: 28px; letter-spacing: -0.015em; margin: 0 0 6px; }
h3 { font-weight: 600; font-size: 15px; text-transform: uppercase; letter-spacing: 0.06em; font-family: var(--mono); color: var(--ink-soft); margin: 0 0 10px; }
.muted { color: var(--ink-faint); }
.hint { font-size: 13px; color: var(--ink-faint); margin: 8px 0 0; }

/* ---------- add panel ---------- */
.add-panel { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 36px; overflow: hidden; }
.seg { display: flex; border-bottom: 1px solid var(--line); background: var(--paper-2); }
.seg-btn {
  flex: 1;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  background: none;
  border: 0;
  border-right: 1px solid var(--line);
  padding: 12px;
  cursor: pointer;
  color: var(--ink-faint);
}
.seg-btn:last-child { border-right: 0; }
.seg-btn.is-active { background: var(--paper); color: var(--ink); }
.add-body { padding: 18px; }
.add-field.is-hidden { display: none; }

input, textarea, select {
  width: 100%;
  font-family: var(--serif);
  font-size: 17px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 11px 12px;
  margin-bottom: 10px;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--ink); }

.dropzone {
  display: flex; align-items: center; justify-content: center;
  min-height: 110px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--ink-faint);
  font-family: var(--mono); font-size: 13px;
  cursor: pointer;
  margin-bottom: 10px;
  text-align: center;
  padding: 16px;
}
.dropzone.is-drag { border-color: var(--ink); color: var(--ink); background: var(--paper-2); }

.add-actions { display: flex; align-items: center; gap: 14px; }

/* ---------- buttons ---------- */
button.primary {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  padding: 11px 20px;
  cursor: pointer;
}
button.primary:hover { background: #000; }
button.primary:disabled { opacity: .45; cursor: default; }
button.ghost {
  font-family: var(--mono); font-size: 12px; letter-spacing: 0.04em;
  background: none; border: 1px solid var(--line-strong); color: var(--ink-soft);
  border-radius: var(--radius); padding: 9px 14px; cursor: pointer; margin-right: 10px;
}
button.ghost:hover { border-color: var(--ink); color: var(--ink); }
.danger-btn { color: #a11; border-color: #e3c4c4; }
.danger-btn:hover { color: #fff; background: #a11; border-color: #a11; }

.status { font-family: var(--mono); font-size: 12px; color: var(--ink-faint); }
.status.err { color: #a11; }
.status.ok { color: #1a7f37; }

/* ---------- library ---------- */
.library-head { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.library-head input { margin-bottom: 0; }
.lib-count { font-family: var(--mono); font-size: 12px; color: var(--ink-faint); white-space: nowrap; }

.lib-list { list-style: none; margin: 0; padding: 0; }
.lib-item {
  border-top: 1px solid var(--line);
  padding: 18px 4px;
  cursor: pointer;
}
.lib-item:hover { background: var(--paper-2); }
.lib-item:last-child { border-bottom: 1px solid var(--line); }
.lib-item .li-title { font-weight: 600; font-size: 20px; letter-spacing: -0.01em; margin: 0 0 4px; }
.lib-item .li-meta { font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em; color: var(--ink-faint); text-transform: uppercase; margin: 0 0 8px; }
.lib-item .li-summary { color: var(--ink-soft); font-size: 16px; margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lib-item .li-pending { font-family: var(--mono); font-size: 12px; color: var(--ink-faint); }

.empty { text-align: center; padding: 60px 0; }
.empty.is-hidden, .is-hidden { display: none; }
.empty p { margin: 4px 0; }

/* ---------- ask ---------- */
.ask-intro { margin-bottom: 22px; }
.ask-box { display: flex; gap: 12px; align-items: flex-start; }
.ask-box textarea { margin-bottom: 0; }
.ask-box button { white-space: nowrap; }
.answer {
  margin-top: 26px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--ink);
  border-radius: var(--radius);
  padding: 22px 24px;
  font-size: 18px;
  line-height: 1.65;
}
.answer p { margin: 0 0 14px; }
.answer p:last-child { margin-bottom: 0; }
.answer strong { font-weight: 600; }
.answer .cite { font-family: var(--mono); font-size: 11px; color: var(--ink-faint); vertical-align: super; }
.ask-sources { margin-top: 24px; }
.ask-sources ul { list-style: none; margin: 0; padding: 0; }
.ask-sources li { font-family: var(--mono); font-size: 13px; padding: 6px 0; border-top: 1px solid var(--line); color: var(--ink-soft); cursor: pointer; }
.ask-sources li:hover { color: var(--ink); }
.ask-sources .src-n { color: var(--ink-faint); margin-right: 8px; }

/* ---------- settings ---------- */
.key-row { display: flex; gap: 12px; align-items: flex-start; margin: 18px 0 6px; }
.key-row input { margin-bottom: 0; font-family: var(--mono); font-size: 14px; }
.checkrow { font-family: var(--mono); font-size: 12px; color: var(--ink-faint); display: flex; gap: 8px; align-items: center; }
.checkrow input { width: auto; margin: 0; }
.settings-block { margin-top: 32px; }
.settings-block label { display: block; font-family: var(--mono); font-size: 12px; letter-spacing: 0.04em; color: var(--ink-soft); margin-bottom: 8px; text-transform: uppercase; }
.settings-block select { max-width: 360px; }
.settings-block.danger { border-top: 1px solid var(--line); padding-top: 24px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(17,17,17,.4); display: flex; align-items: flex-start; justify-content: center; padding: 48px 20px; z-index: 50; overflow-y: auto; }
.modal.is-hidden { display: none; }
.modal-card { background: var(--paper); border-radius: var(--radius); max-width: 720px; width: 100%; padding: 36px 40px 40px; position: relative; box-shadow: 0 18px 50px rgba(0,0,0,.18); }
.modal-close { position: absolute; top: 14px; right: 16px; background: none; border: 0; font-size: 28px; line-height: 1; color: var(--ink-faint); cursor: pointer; }
.modal-close:hover { color: var(--ink); }
.modal-card h2 { margin-right: 28px; }
.modal-meta { font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-faint); margin: 0 0 24px; }
.modal-section { margin-bottom: 26px; }
.modal-summary { font-size: 18px; line-height: 1.6; }
.modal-summary p { margin: 0 0 12px; }
.modal-highlights { margin: 0; padding-left: 22px; }
.modal-highlights li { margin-bottom: 10px; line-height: 1.5; }
.modal-fulltext { white-space: pre-wrap; font-size: 15px; line-height: 1.6; color: var(--ink-soft); max-height: 420px; overflow-y: auto; margin-top: 12px; padding: 14px; background: var(--paper-2); border-radius: var(--radius); }
details summary { cursor: pointer; font-family: var(--mono); font-size: 13px; color: var(--ink-soft); }
.modal-actions { display: flex; gap: 0; margin-top: 8px; }

@media (max-width: 560px) {
  body { font-size: 17px; }
  .wrap { padding: 24px 18px 80px; }
  .ask-box { flex-direction: column; }
  .ask-box button { width: 100%; }
  .modal-card { padding: 28px 22px 30px; }
}
