:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --border: #e2e6ea;
  --text: #1c2733;
  --muted: #7a8794;
  --pos: #1a9d5a;
  --pos-bg: #e6f6ec;
  --neg: #c0392b;
  --neg-bg: #fbeae8;
  --accent: #2b6cb0;
  --accent-bg: #e8f0f9;
  --warn-bg: #fff4e0;
  --warn: #b9770e;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
/* top bar (styled after chebifier.hastingslab.org) */
header.navbar {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 16px; background: #282c34; color: #fff;
  position: sticky; top: 0; z-index: 20;
}
.navbar-left { display: flex; align-items: center; gap: 24px; }
.logo { margin: 0; font-size: 40px; font-weight: 700; line-height: 1.3; }
.logo a { color: #fff; text-decoration: none; }
.logo .version { margin-left: 8px; font-size: 13px; font-weight: 400; color: #d5d8de; }
.nav-links { display: flex; gap: 16px; font-size: 16px; }
.nav-links a { color: #fff; text-decoration: none; }
.nav-links a:hover { text-decoration: underline; }
.navbar-right { display: flex; align-items: center; gap: 14px; }
.counts { font-size: 13px; color: #d5d8de; }
header.navbar button.ghost { color: #d5d8de; border-color: rgba(255,255,255,.3); }
header.navbar button.ghost:hover { color: #fff; border-color: rgba(255,255,255,.6); }
h1 { font-size: 20px; margin: 0; }
main { max-width: 1440px; margin: 20px auto; padding: 0 24px; display: flex; flex-direction: column; gap: 18px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; }
h2 { font-size: 15px; margin: 0 0 14px; }
h3 { font-size: 13px; margin: 0 0 8px; }
.muted { color: var(--muted); font-weight: 400; font-size: 12px; }

button {
  background: var(--accent); color: #fff; border: none; border-radius: 6px;
  padding: 7px 13px; font-size: 13px; cursor: pointer;
}
button:hover { filter: brightness(1.06); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
input, textarea { font-family: inherit; font-size: 13px; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; }
textarea { width: 100%; resize: vertical; }
label { font-size: 12px; color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.mini input { width: 56px; }

/* class picker */
.class-picker { margin-bottom: 18px; }
.class-row { display: flex; align-items: center; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
.autocomplete { position: relative; flex: 1; min-width: 260px; }
.autocomplete > input { width: 100%; }
.ac-results {
  position: absolute; top: 100%; left: 0; right: 0; background: var(--card);
  border: 1px solid var(--border); border-radius: 6px; margin-top: 3px; max-height: 260px;
  overflow-y: auto; z-index: 30; box-shadow: 0 6px 20px rgba(0,0,0,.08);
}
.ac-item { padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--border); }
.ac-item:hover { background: var(--accent-bg); }
.ac-item .ac-id { color: var(--muted); font-size: 11px; margin-left: 6px; }
.ac-item .ac-n { float: right; color: var(--muted); font-size: 11px; }
.selected-class { margin-top: 8px; font-size: 12px; color: var(--accent); }

/* examples */
.examples-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }
.example-col { border-radius: 10px; padding: 12px 14px; border: 1px solid var(--border); border-top-width: 3px; }
.pos-col { background: var(--pos-bg); border-top-color: var(--pos); }
.neg-col { background: var(--neg-bg); border-top-color: var(--neg); }
.pos-head { color: var(--pos); margin-top: 4px; }
.neg-head { color: var(--neg); margin-top: 4px; }
.pill { background: var(--border); border-radius: 10px; padding: 1px 8px; font-size: 11px; color: var(--text); font-weight: 600; }
.add-box { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 10px; }
.add-box textarea { flex: 1; }
.add-box button { white-space: nowrap; }
/* structure-card grid for pos/neg examples */
.struct-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 12px; }
.struct-card {
  position: relative; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; padding: 4px; cursor: pointer; transition: box-shadow .12s, border-color .12s;
}
.struct-card:hover { box-shadow: 0 3px 12px rgba(0,0,0,.09); border-color: #cbd4dd; }
.struct-card.drag-src { opacity: .4; }
.struct-card.flash { animation: card-flash 1.6s ease-out 2; }
@keyframes card-flash {
  0% { box-shadow: 0 0 0 3px var(--accent); border-color: var(--accent); }
  100% { box-shadow: 0 0 0 3px transparent; }
}
.example-col.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; }
.struct-card .thumb { width: 100%; aspect-ratio: 1 / 0.82; display: block; }
.struct-card .thumb img { width: 100%; height: 100%; object-fit: contain; }
.struct-card .card-ctrls { position: absolute; top: 4px; right: 4px; display: flex; gap: 4px; opacity: 0; transition: opacity .12s; }
.struct-card:hover .card-ctrls { opacity: 1; }
.struct-card .mini-btn {
  border: none; color: #fff; font-weight: 700;
  border-radius: 5px; font-size: 15px; line-height: 1; padding: 5px 9px; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.22);
}
.struct-card .mini-btn.swap.pos { background: var(--pos); }
.struct-card .mini-btn.swap.neg { background: var(--neg); }
.struct-card .mini-btn.x { background: #3d4750; }
.struct-card .mini-btn:hover { filter: brightness(1.1); }
.struct-card .card-badge { position: absolute; top: 3px; left: 3px; }
.struct-card .cap { font-size: 12px; color: var(--muted); text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px 2px; }

.badge { font-size: 10px; font-weight: 700; border-radius: 4px; padding: 1px 5px; }
.badge.TP { background: var(--pos-bg); color: var(--pos); }
.badge.TN { background: var(--pos-bg); color: var(--pos); }
.badge.FP { background: var(--neg-bg); color: var(--neg); }
.badge.FN { background: var(--neg-bg); color: var(--neg); }
.badge.pos_pred { background: var(--pos-bg); color: var(--pos); }
.badge.neg_pred { background: var(--neg-bg); color: var(--neg); }
.swap { background: transparent; border: 1px solid var(--border); color: var(--muted); font-size: 11px; padding: 2px 6px; border-radius: 4px; cursor: pointer; }

/* suggestions — one-by-one (tinder) */
.tinder { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-top: 8px; }
.tinder-card {
  width: 340px; max-width: 100%; border: 1px solid var(--border); border-radius: 12px;
  background: #fff; box-shadow: 0 4px 18px rgba(0,0,0,.08); padding: 12px; position: relative;
  cursor: grab; user-select: none; touch-action: pan-y;
  transition: transform .22s ease, opacity .22s ease;
}
.tinder-card.dragging { cursor: grabbing; transition: none; }
/* drop zones either side of the card, shown while swiping */
.tinder-stage { position: relative; width: 100%; display: flex; justify-content: center; }
.tinder-stage .tinder-card { z-index: 1; }
.swipe-zone {
  position: absolute; top: 0; bottom: 0; width: max(70px, calc(50% - 190px));
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px; font-weight: 700; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .15s, background .15s, color .15s;
}
.swipe-zone.pos { left: 0; background: var(--pos-bg); color: var(--pos); }
.swipe-zone.neg { right: 0; background: var(--neg-bg); color: var(--neg); }
.tinder-stage.swiping .swipe-zone { opacity: 1; }
.swipe-zone.pos.armed { background: var(--pos); color: #fff; }
.swipe-zone.neg.armed { background: var(--neg); color: #fff; }
.tinder-meta-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; min-height: 20px; }
.t-sim { font-size: 12px; color: var(--accent); font-weight: 700; }
.t-sim::before { content: "similarity "; color: var(--muted); font-weight: 400; }
.t-struct { width: 100%; aspect-ratio: 1 / 0.78; }
.t-struct img { width: 100%; height: 100%; object-fit: contain; }
.tinder-secondary { text-align: center; margin-top: 8px; }
.t-name { font-size: 15px; font-weight: 600; }
.t-id { font-size: 12px; color: var(--muted); margin-top: 2px; }
.t-def { font-size: 12px; color: var(--muted); margin-top: 8px; line-height: 1.4; max-height: 4.6em; overflow-y: auto; }
.tinder-actions { display: flex; gap: 10px; }
.big { padding: 10px 18px; font-size: 14px; border-radius: 8px; }
.btn-pos { background: var(--pos); }
.btn-neg { background: var(--neg); }
.t-pred .badge { font-size: 11px; }

/* rule + report */
/* live Popper output */
.learn-progress { margin: 6px 0 12px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.lp-head { display: flex; justify-content: space-between; align-items: center;
  background: #f0f3f6; padding: 5px 10px; }
.lp-title { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.linkbtn { background: transparent; color: var(--accent); border: none; font-size: 12px; cursor: pointer; padding: 0; }
.log-view { margin: 0; padding: 8px 10px; font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11.5px; line-height: 1.4; color: #2a3947; background: #fbfcfd;
  white-space: pre-wrap; word-break: break-word; max-height: 90px; overflow-y: auto; }
.log-view.full { max-height: 320px; border-top: 1px solid var(--border); background: #fff; }

.rule-text { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.rule-label { display: block; margin: 6px 0 6px; }
.concept-box { margin: 0 0 12px; padding: 10px 12px; background: var(--accent-bg);
  border: 1px solid #d3e2f2; border-radius: 8px; }
.concept-box .rule-text { width: 100%; box-sizing: border-box; font-family: inherit; }
.concept-box #concept-name { font-weight: 600; margin-bottom: 6px; }
.aux-area { margin: 8px 0 10px; }
.aux-list { margin-top: 8px; display: flex; flex-direction: column; gap: 10px; }
.aux-item { border-left: 3px solid var(--border); padding-left: 10px; }
.aux-name { font-size: 12px; font-weight: 600; margin-bottom: 2px; color: var(--accent); }
.aux-desc { font-size: 12px; margin-bottom: 4px; }
.aux-item .rule-text { width: 100%; }
.rule-nl-box { background: var(--accent-bg); border: 1px solid #d3e2f2; border-radius: 8px; padding: 8px 12px; }
.rule-nl-label { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); font-weight: 700; margin-bottom: 4px; }
.rule-nl { font-size: 13px; line-height: 1.45; white-space: pre-line; }

/* The block editor's own styles come with viloch (viloch/blocks.css). */

.advanced-prolog { margin: 12px 0 4px; }
.advanced-prolog > summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.advanced-prolog #rule-text { width: 100%; margin-top: 6px; }
.advanced-prolog .adv-hint { margin: 4px 0 8px; }
.advanced-prolog .rule-nl-label { margin-top: 6px; }

/* "?" explain button on cards (once a rule exists; grey when the rule rejects the molecule) */
.struct-card .explain-btn {
  position: absolute; right: 5px; bottom: 24px;
  background: var(--accent); color: #fff; border: none; border-radius: 50%;
  width: 21px; height: 21px; font-size: 13px; font-weight: 700; line-height: 1;
  cursor: pointer; padding: 0; box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.struct-card .explain-btn:hover { filter: brightness(1.1); }
.struct-card .explain-btn.rejected { background: var(--muted); }
.explain-struct { text-align: center; margin: 8px 0; }
.explain-struct img { max-width: 100%; border: 1px solid var(--border); border-radius: 8px; }
.confusion { display: flex; gap: 10px; margin: 14px 0; }
.conf-cell { padding: 8px 14px; border-radius: 6px; text-align: center; min-width: 60px; }
.conf-cell .n { font-size: 18px; font-weight: 700; display: block; }
.conf-cell .l { font-size: 10px; color: var(--muted); }
.conf-cell.good { background: var(--pos-bg); }
.conf-cell.bad { background: var(--neg-bg); }
.report-box { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-top: 10px; }
.report-box h4 { margin: 0 0 8px; font-size: 13px; }
.report-box.warn { background: var(--warn-bg); border-color: #f0d9a8; }
.mismatch { font-size: 12px; padding: 3px 0; }

/* rule history */
.rule-history-area { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 12px; }
.rh-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.rh-head h3 { margin: 0; }
.rule-history-list { display: flex; flex-direction: column; gap: 10px; }
.rh-item { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; cursor: pointer; transition: border-color .12s, box-shadow .12s; }
.rh-item:hover { border-color: #cbd4dd; box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.rh-item.selected { border-color: var(--accent); background: var(--accent-bg); cursor: default; }
.rh-item-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.rh-origin { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  border-radius: 4px; padding: 2px 7px; background: var(--accent-bg); color: var(--accent); }
.rh-origin.origin-edited { background: var(--warn-bg); color: var(--warn); }
.rh-time { flex: 1; }
.rh-selected { font-size: 11px; color: var(--accent); font-weight: 600; }
.rh-select { flex: none; }
.rh-rule { font-size: 12px; white-space: pre-wrap; word-break: break-word; color: var(--text);
  max-height: 96px; overflow-y: auto; line-height: 1.4; }
.rh-conf { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.rh-conf-cells { display: inline-flex; gap: 6px; }
.rh-c { font-size: 11px; font-weight: 600; border-radius: 4px; padding: 1px 6px; }
.rh-c.good { background: var(--pos-bg); color: var(--pos); }
.rh-c.bad { background: var(--neg-bg); color: var(--neg); }
.rh-stale { font-size: 11px; color: var(--warn); background: var(--warn-bg); border-radius: 4px; padding: 1px 6px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.change-line { font-size: 12px; padding: 2px 0; }
.hidden { display: none !important; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #23303d; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 80%;
}
/* molecule detail modal */
.modal { position: fixed; inset: 0; background: rgba(20,28,36,.5); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-box { background: #fff; border-radius: 12px; max-width: 460px; width: 100%;
  padding: 18px 20px; position: relative; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.modal-box.explain-box { max-width: 720px; max-height: calc(100vh - 40px); overflow-y: auto; }
.explain-box h3 { margin: 0 24px 6px 0; font-size: 15px; }
.modal-close { position: absolute; top: 8px; right: 10px; background: transparent;
  color: var(--muted); border: none; font-size: 22px; cursor: pointer; z-index: 1; }
.modal-struct { width: 100%; height: 220px; display: flex; justify-content: center;
  overflow: hidden; cursor: zoom-in; position: relative; border-radius: 8px; }
.modal-struct img { max-width: 100%; max-height: 100%; object-fit: contain;
  transition: transform .12s ease-out; pointer-events: none; }
.modal-struct.zooming { background: #fafbfc; outline: 1px solid var(--border); }
.modal-struct .zoom-hint { position: absolute; right: 6px; bottom: 4px; font-size: 11px;
  color: var(--muted); pointer-events: none; opacity: .8; }
.modal-struct.zooming .zoom-hint { display: none; }
.modal-body { margin-top: 10px; }
.modal-body h3 { font-size: 16px; margin: 0 0 4px; }
.detail-row { margin-top: 10px; }
.detail-row .k { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.detail-row .v { font-size: 13px; word-break: break-all; }
.detail-row .v.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.chebi-link { color: var(--accent); text-decoration: none; }
.chebi-link:hover { text-decoration: underline; }
.modal-actions { display: flex; gap: 8px; margin-top: 18px; }
.modal-actions .action-btn { flex: 1; padding: 10px 12px; font-size: 13px; font-weight: 600;
  border: none; border-radius: 7px; color: #fff; cursor: pointer; }
.modal-actions .action-btn.pos { background: var(--pos); }
.modal-actions .action-btn.neg { background: var(--neg); }
.modal-actions .action-btn.remove { background: #3d4750; }
.modal-actions .action-btn:hover { filter: brightness(1.1); }

@media (max-width: 720px) { .examples-grid { grid-template-columns: 1fr; } }

/* about and tutorial pages: one centred column, every card the same width */
main.doc-main { max-width: 960px; }
.doc-prose, .tut-intro, .tut-step { font-size: 14px; line-height: 1.6; }
.doc-prose p, .tut-intro p, .tut-step p { margin: 0 0 10px; }
.doc-prose ul, .tut-step ul { margin: 0 0 10px; padding-left: 20px; }
.doc-prose li, .tut-step li { margin-bottom: 6px; }
.doc-prose > :last-child, .tut-intro > :last-child, .tut-step > :last-child { margin-bottom: 0; }
.doc-prose a, .tut-intro a, .tut-step a { color: var(--accent); }
/* prominent project links (ICaRuS, Popper, Aleph) */
.doc-links { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.doc-links a { border: 1px solid var(--border); border-radius: 6px; padding: 5px 12px;
  font-size: 13px; font-weight: 600; text-decoration: none; background: var(--bg); }
.doc-links a:hover { border-color: var(--accent); }

/* tutorial page */
.tut-intro h3 { margin-top: 16px; }
.tut-toc { margin: 0; padding-left: 20px; line-height: 1.8; font-size: 13px; }
.tut-toc a { text-decoration: none; }
.tut-toc a:hover { text-decoration: underline; }
.tut-step code, .tut-step kbd { font-size: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
.tut-fig { margin: 12px 0; }
.tut-fig figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; text-align: center; }
.tut-shot { display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid var(--border); border-radius: 8px; }
.tut-shot-narrow { max-width: min(480px, 100%); }

/* learn settings (library predicate kinds) */
.learn-settings { margin: -2px 0 10px; font-size: 12px; }
.learn-settings summary { cursor: pointer; color: var(--muted); }
.learn-settings .settings-note { margin: 4px 0 6px; }
.learn-settings label.mini { margin-right: 14px; }
.learn-settings input[type="checkbox"] { width: auto; vertical-align: middle; }

/* rule explanation (picture + sentence) next to the block editor */
.rule-explain img { display: block; max-width: 100%; height: auto; margin: 4px 0 4px;
  border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.rule-explain .report-box { margin: 4px 0 10px; }
