:root {
  --paper: #f4efe4;
  --card: #fffdf8;
  --sunk: #efe9dc;
  --ink: #1d2420;
  --muted: #6b6f66;
  --line: #e2dacb;
  --accent: #1f3a34;
  --accent-ink: #f8f4ea;
  --gold: #d9a520;
  --ok: #2f7a4f;
  --ok-soft: #e1efe4;
  --bad: #b4483c;
  --bad-soft: #f6e3df;
  --cite: #3d5a99;
  --cite-soft: #e4e9f5;
  --focus: #d9a52066;
  --shadow: 0 1px 0 #00000008, 0 10px 30px -18px #3b2f1a40;
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #131714;
    --card: #1b201c;
    --sunk: #161a17;
    --ink: #ece6d8;
    --muted: #9aa096;
    --line: #2c332e;
    --accent: #a9cdbd;
    --accent-ink: #10201b;
    --gold: #e9bd4f;
    --ok: #7fc79a;
    --ok-soft: #1d3326;
    --bad: #e58e82;
    --bad-soft: #3a211e;
    --cite: #9db3e6;
    --cite-soft: #1f2840;
    --focus: #e9bd4f55;
    --shadow: 0 1px 0 #00000040, 0 12px 30px -18px #000;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.55 var(--sans);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* Brand mark: three stacked lines like a reference list */
.mark { display: grid; gap: 5px; width: 44px; padding: 10px; border-radius: 12px; background: var(--accent); }
.mark span { height: 4px; border-radius: 4px; background: var(--accent-ink); }
.mark span:nth-child(2) { width: 70%; background: var(--gold); }
.mark.small { width: 30px; padding: 7px; gap: 3px; border-radius: 8px; }
.mark.small span { height: 3px; }

/* Buttons */
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-ink { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-ink:hover:not(:disabled) { border-color: var(--accent); filter: brightness(1.12); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn-quiet:hover:not(:disabled) { color: var(--ink); border-color: var(--line); }
.btn-wide { width: 100%; padding: 12px 16px; font-size: 15px; }
.btn-small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn-danger { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 30%, var(--line)); color: var(--bad); }
.btn-danger:hover:not(:disabled) { background: var(--bad); border-color: var(--bad); color: #fff; }

/* Sign in */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.gate-card {
  width: min(400px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 36px 32px 28px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 18px;
}
.gate-card h1 { font-size: 32px; margin-top: 4px; }
.gate-sub { margin: -10px 0 4px; color: var(--muted); }
.field { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input {
  color: var(--ink);
  font-weight: 400;
  border: 1px solid var(--line);
  background: var(--sunk);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 16px;
}
.secret { position: relative; }
.secret input { width: 100%; padding-right: 72px; }
.reveal {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--muted);
  font-size: 13px; font-weight: 600; padding: 6px 10px; border-radius: 7px; cursor: pointer;
}
.reveal:hover { color: var(--ink); background: var(--line); }
.gate-error { margin: 0; min-height: 1.4em; color: var(--bad); font-size: 14px; }

/* Workspace */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-size: 20px; font-weight: 600; }
.columns {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  gap: 28px;
  padding: 28px;
  max-width: 1320px;
  margin: 0 auto;
  align-items: start;
}
.compose { display: grid; gap: 16px; position: sticky; top: 86px; }
.block { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; display: grid; gap: 12px; }
.block h2 { font-size: 17px; }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pill { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--sunk); border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; }
.pill.on { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
textarea {
  width: 100%;
  min-height: 190px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--sunk);
  padding: 12px;
  font: 13px/1.6 var(--mono);
}
.note { margin: 0; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.block-head-end { display: flex; align-items: center; gap: 6px; }

.dup-banner {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  background: var(--bad-soft);
  border: 1px solid color-mix(in srgb, var(--bad) 30%, var(--line));
  border-radius: 8px;
  font-size: 12.5px;
}
.dup-label { flex: 1; color: var(--bad); font-weight: 600; }
.dup-detail {
  list-style: none; margin: 0; padding: 8px 12px;
  background: var(--sunk); border: 1px solid var(--line); border-radius: 8px;
  font: 12px/1.7 var(--mono); color: var(--muted);
  max-height: 120px; overflow-y: auto;
}
.dup-detail li { overflow-wrap: anywhere; }

.label-note { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 4px; }
.radio-row { display: flex; align-items: baseline; gap: 8px; font-size: 13.5px; cursor: pointer; }
.radio-row input[type="radio"] { accent-color: var(--accent); width: 14px; height: 14px; flex: none; margin-top: 2px; }
.fname-options { display: grid; gap: 6px; }
.fname-row { display: flex; align-items: center; gap: 10px; }
.fname-field-label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.fname-input { flex: 1; background: var(--sunk); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font: 13px var(--mono); color: var(--ink); outline: none; }
.fname-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.fname-serial-opts { display: grid; gap: 4px; padding-left: 20px; }
.fname-preview-box { background: var(--sunk); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font: 12.5px/1.7 var(--mono); color: var(--muted); white-space: pre-line; word-break: break-all; }
.rename-panel { background: var(--sunk); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-bottom: 16px; display: grid; gap: 8px; }
.rename-header { display: flex; align-items: center; justify-content: space-between; font-size: 13.5px; }
.rename-row { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; }
.rename-num { font: 600 12px var(--mono); color: var(--muted); text-align: center; }
.rename-input { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px; font: 13px var(--mono); color: var(--ink); outline: none; min-width: 0; }
.rename-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.rename-input.disabled { background: transparent; border-color: transparent; color: var(--muted); padding: 5px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rename-status { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 99px; }
.rename-status.bad { color: var(--bad); background: var(--bad-soft); }
.rename-status.wait { color: var(--muted); background: var(--line); }
.rename-actions { display: flex; align-items: center; gap: 6px; }
.zip-label { display: inline-flex; align-items: center; gap: 4px; font: 600 11px var(--sans); color: var(--muted); padding: 0 4px; cursor: pointer; }
.zip-check { accent-color: var(--accent); width: 14px; height: 14px; margin: 0; }

/* history */
.history { background: transparent; border: 1px dashed var(--line); border-radius: 10px; padding: 6px 10px; }
.history summary { list-style: none; display: flex; align-items: center; justify-content: space-between; cursor: pointer; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.history summary::-webkit-details-marker { display: none; }
.history[open] { padding-bottom: 10px; }
.history-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.history-item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; }
.history-load { flex: 1; text-align: left; font-family: var(--mono); font-weight: 400; color: var(--ink); text-decoration: none; padding: 4px 6px; border-radius: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-load:hover { background: var(--sunk); color: var(--accent); }
.history-del { color: var(--muted); padding: 2px 6px; text-decoration: none; }
.history-del:hover { color: var(--bad); }

/* card badge + layout polish */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 99px; font: 700 12px var(--sans); white-space: nowrap; flex: none; }
.badge-ok { background: var(--ok); color: #fff; }
.badge-bad { background: var(--bad); color: #fff; }
.badge-cite { background: var(--cite); color: #fff; }
.badge-wait { background: var(--line); color: var(--muted); }

.card.ok { border-color: color-mix(in srgb, var(--ok) 30%, var(--line)); }
.card.working { border-color: color-mix(in srgb, var(--gold) 30%, var(--line)); }
.pdf-body { display: grid; gap: 6px; }
.pdf-meta { font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px; align-items: baseline; }
.pdf-meta b { color: var(--ink); font-weight: 600; }
.origin-link { color: var(--cite); text-decoration: none; }
.origin-link:hover { text-decoration: underline; }
.card-fname-row { display: flex; align-items: center; gap: 6px; }
.card-fname-input { flex: 1; background: var(--sunk); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font: 13px var(--mono); color: var(--ink); outline: none; min-width: 0; }
.card-fname-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }

.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; font-weight: 500; }
.switch input { position: absolute; opacity: 0; }
.track { width: 38px; height: 22px; border-radius: 99px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--card); box-shadow: 0 1px 2px #0003; transition: transform .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 3px solid var(--focus); outline-offset: 2px; }

.format summary { list-style: none; display: flex; align-items: center; justify-content: space-between; cursor: pointer; }
.format summary::-webkit-details-marker { display: none; }
.chev { width: 9px; height: 9px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .15s; }
.format[open] .chev { transform: rotate(-135deg); }
.parts { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.part { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--sunk); }
.part label { flex: 1; display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; }
.part .num { font: 600 12px var(--mono); color: var(--muted); width: 14px; }
.arrow { width: 28px; height: 28px; padding: 0; border-radius: 7px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-size: 11px; color: var(--muted); }
.arrow:hover:not(:disabled) { color: var(--ink); }
.arrow:disabled { opacity: .3; cursor: default; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; cursor: pointer; }
.check input, .part input { accent-color: var(--accent); width: 16px; height: 16px; margin: 2px 0 0; }

/* Results */
.empty { text-align: center; padding: 90px 24px; color: var(--muted); border: 1.5px dashed var(--line); border-radius: 20px; }
.empty h2 { color: var(--ink); font-size: 22px; margin: 18px 0 6px; }
.empty p { max-width: 380px; margin: 0 auto; }
.empty-art { display: grid; gap: 7px; width: 120px; margin: 0 auto; }
.empty-art i { height: 9px; border-radius: 9px; background: var(--line); }
.empty-art i:nth-child(2) { width: 75%; }
.empty-art i:nth-child(3) { width: 88%; }

.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.tally { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.tally b { display: block; font: 600 26px/1.1 var(--serif); }
.tally span { font-size: 12.5px; color: var(--muted); }
.tally.ok b { color: var(--ok); }
.tally.cite b { color: var(--cite); }
.tally.bad b { color: var(--bad); }
.meter { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; margin: 14px 0; }
.meter-fill { height: 100%; width: 0; background: var(--gold); transition: width .25s; }
.bulk { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; box-shadow: var(--shadow); display: grid; gap: 12px; }
.card-head { display: flex; gap: 12px; align-items: flex-start; }
.idx { flex: none; font: 600 12px var(--mono); color: var(--muted); background: var(--sunk); border: 1px solid var(--line); border-radius: 8px; padding: 3px 7px; margin-top: 2px; }
.card-title { flex: 1; min-width: 0; }
.card-title h3 { margin: 0; font: 600 16px/1.35 var(--serif); }
.card-title .doi { font: 12px var(--mono); color: var(--muted); overflow-wrap: anywhere; text-decoration: none; }
.card-title .doi:hover { text-decoration: underline; }
.card-title .byline { font-size: 13px; color: var(--muted); }

.lane { display: grid; grid-template-columns: 88px 1fr auto; gap: 12px; align-items: start; border-top: 1px solid var(--line); padding-top: 12px; }
.lane-label { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding-top: 3px; }
.lane-body { min-width: 0; font-size: 14px; }
.lane-body .ref { font-family: var(--serif); font-size: 15px; line-height: 1.6; overflow-wrap: anywhere; }
.lane-body .ref i { font-style: italic; }
.lane-body .intext { margin-top: 4px; color: var(--muted); font-size: 13.5px; }
.lane-body .source { margin-top: 4px; font-size: 13.5px; }
.lane-body .origin { display: flex; align-items: baseline; gap: 10px; margin-top: 2px; font: 12px/1.5 var(--mono); }
.lane-body .origin a { color: var(--cite); overflow-wrap: anywhere; min-width: 0; }
.linkbtn { flex: none; border: 0; background: none; padding: 0; font: 600 12px var(--sans); color: var(--muted); cursor: pointer; text-decoration: underline; }
.linkbtn:hover { color: var(--ink); }
.lane-body .why { margin: 4px 0 0; padding: 0; list-style: none; font-size: 12.5px; color: var(--muted); }
.lane-body .why li { overflow-wrap: anywhere; }
.status { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status.ok { color: var(--ok); }
.status.ok::before { content: "✓"; width: auto; height: auto; border-radius: 0; background: none; font-size: 14px; line-height: 1; font-weight: 700; }
.status.bad { color: var(--bad); }
.status.wait { color: var(--muted); }
.status.wait::before { animation: pulse 1s ease-in-out infinite; }
.status.cite { color: var(--cite); }
.status .meta { font-weight: 400; color: var(--muted); }
@keyframes pulse { 50% { opacity: .25; } }
.card.failed { border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--paper);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .columns { grid-template-columns: 1fr; padding: 16px; gap: 16px; }
  .compose { position: static; }
  .topbar { padding: 12px 16px; }
  .summary { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .lane { grid-template-columns: 1fr auto; }
  .lane-label { grid-column: 1 / -1; padding: 0; }
  .gate-card { padding: 28px 20px 22px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
