:root {
  --bg: #0f1419;
  --card: #1a222c;
  --line: #2a3542;
  --text: #e8eef4;
  --muted: #9aa8b5;
  --accent: #2a9d8f;
  --accent2: #3d9cf0;
  --danger: #e35d6a;
  --ok: #3ecf8e;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, #163a36 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #1e2a44 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}
a { color: var(--accent2); }
.top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.85rem 1.25rem; border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20;
  background: rgba(15,20,25,0.85);
}
.brand { font-weight: 700; letter-spacing: 0.02em; }
.top-actions { display: flex; align-items: center; gap: 0.65rem; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 0.9rem; }
.btn {
  border: 0; border-radius: 8px; padding: 0.55rem 1rem; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn.secondary { background: #243040; }
.actions-add-prior { margin-top: 0.85rem; }
.btn-add-prior {
  width: 100%;
  padding: 0.85rem 1.1rem;
  font-size: 1.05rem;
  font-weight: 700;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  background: color-mix(in srgb, var(--accent) 18%, #243040);
  color: var(--text);
}
.btn-add-prior:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 28%, #243040);
  filter: brightness(1.05);
}
.actions-run { margin-top: 1.25rem; }
.btn-run {
  width: 100%;
  padding: 1rem 1.25rem;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(42, 157, 143, 0.28);
}
.btn-run:hover:not(:disabled) { filter: brightness(1.06); }
.run-countdown {
  margin-top: 0.85rem;
  padding: 1.1rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #121820;
  text-align: center;
}
.run-countdown.hidden { display: none; }
.run-countdown__time {
  font-size: 2.4rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  color: var(--accent);
  line-height: 1.1;
}
.run-countdown__label {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}
.hidden { display: none !important; }
main { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
h1 { font-size: 1.75rem; margin: 0 0 0.4rem; }
.grid {
  display: grid; grid-template-columns: 1fr; gap: 1rem; margin-top: 1rem;
}
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 1.1rem 1.2rem;
}
label.field { display: block; margin: 0.75rem 0 0.35rem; font-size: 0.9rem; color: var(--muted); }
input, select, textarea {
  width: 100%; padding: 0.6rem 0.75rem; border-radius: 8px; border: 1px solid var(--line);
  background: #121820; color: var(--text); font: inherit;
}
textarea { min-height: 64px; resize: vertical; font-family: ui-monospace, monospace; font-size: 0.9rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
@media (max-width: 720px) { .row { grid-template-columns: 1fr; } }
.actions { margin-top: 1rem; display: flex; gap: 0.6rem; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 0.75rem; line-height: 1.45; }
.product, .prior, .reactant {
  border: 1px solid var(--line); border-radius: 10px; padding: 0.75rem; margin-top: 0.65rem; background: #121820;
}
.product-head, .prior-head, .reactant-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin-bottom: 0.35rem; }
.prior .row { margin-top: 0.35rem; }
.prior-fit {
  margin-top: 0.85rem; padding-top: 0.75rem; border-top: 1px solid var(--line);
}
.prior-fit h3 { margin: 0 0 0.5rem; font-size: 1rem; }
.badge {
  font-size: 0.75rem; font-weight: 600; padding: 0.2rem 0.55rem; border-radius: 999px;
  background: #243040; color: var(--muted); border: 1px solid var(--line);
}
.badge.main { color: var(--ok); border-color: #2a5a45; background: #142820; }
.badge.by { color: #e0b15a; border-color: #5a4a2a; background: #2a2414; }
.badge.trust-library_cited { color: #8fd4a8; border-color: #2a5a45; background: #142820; }
.badge.trust-library { color: #9ec4e8; border-color: #2a4560; background: #142030; }
.badge.trust-ai { color: #c9b4e8; border-color: #4a3a60; background: #221830; }
.badge.trust-prior_neighborhood { color: #e0b15a; border-color: #5a4a2a; background: #2a2414; }
.badge.trust-current { color: var(--muted); border-color: var(--line); }
.rec-card--library_cited { border-color: #2a5a45; }
.rec-card--ai { opacity: 0.96; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.55rem 0.4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.error { color: var(--danger); font-size: 0.88rem; min-height: 1.2em; }
.ok-msg { color: var(--ok); font-size: 0.88rem; }
dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--card); color: var(--text);
  max-width: 420px; width: calc(100% - 2rem);
}
dialog::backdrop { background: rgba(0,0,0,0.55); }
.dlg { padding: 1.1rem 1.2rem 1.25rem; }
.tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.tabs .on { border-color: var(--accent); color: var(--accent); }
.captcha-row { display: flex; gap: 0.5rem; align-items: center; }
.captcha-row img {
  height: 40px; border-radius: 6px; border: 1px solid var(--line); cursor: pointer; background: #fff;
}
#profilePanel {
  position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,0.55);
  display: flex; align-items: flex-start; justify-content: center; padding: 2rem 1rem; overflow: auto;
}
#profilePanel .inner {
  width: min(720px, 100%); background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 1.2rem;
}
.profile-meta { color: var(--muted); font-size: 0.9rem; }
.password-panel { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: 0.75rem; }
.hist-table { font-size: 0.85rem; }
.tip { font-size: 0.85rem; }
.page.hidden { display: none !important; }
.field-row {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap;
}
.field-row .field { margin: 0.75rem 0 0.35rem; }
.btn.sm { padding: 0.35rem 0.75rem; font-size: 0.82rem; }
.draw-topbar {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.draw-topbar h1 { margin: 0; font-size: 1.35rem; }
.ketcher-stage {
  position: relative; width: 100%; height: min(68vh, 580px); min-height: 420px;
  background: #fff; border-radius: 8px; overflow: hidden; border: 1px solid var(--line);
}
#ketcherFrame { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
.ketcher-loading {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 24px;
  background: rgba(15, 20, 25, 0.92); color: var(--text);
}
.ketcher-loading.hidden { display: none; }
.ketcher-loading__title { margin: 0; font-weight: 650; }
.ketcher-loading__pct {
  margin: 0; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent);
}
.ketcher-loading__detail { margin: 0; text-align: center; color: var(--muted); font-size: 0.85rem; }
.ketcher-loading__detail:empty { display: none; }
.ketcher-progress {
  width: min(360px, 86%); height: 10px; border-radius: 999px;
  background: #243044; overflow: hidden;
}
.ketcher-progress__bar {
  height: 100%; width: 0%; border-radius: inherit;
  background: linear-gradient(90deg, #5aa2ff, var(--accent));
  transition: width 0.18s ease-out;
}
.ketcher-progress--indeterminate .ketcher-progress__bar {
  width: 36% !important;
  animation: ketcher-indeterminate 1.1s ease-in-out infinite;
}
@keyframes ketcher-indeterminate {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}
.page-draw main { max-width: 1200px; }
.page-draw .ketcher-stage {
  height: min(72vh, 640px); min-height: 460px;
}
.kg-guide-modal {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center;
  padding: 16px; background: rgba(8, 30, 28, 0.55);
}
.kg-guide-modal.hidden { display: none; }
.kg-guide-modal__panel {
  width: min(1100px, 96vw); height: min(90vh, 920px);
  display: flex; flex-direction: column; gap: 10px;
  background: #fff; border-radius: 16px; padding: 12px;
  box-shadow: 0 18px 50px rgba(0,0,0,.2);
  color: #1a222c;
}
.kg-guide-modal__bar {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 2px 2px 4px; flex-shrink: 0;
}
.kg-guide-modal__bar strong { color: #12302b; font-size: 1rem; }
.kg-guide-modal__close {
  flex-shrink: 0;
  border: 0;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  background: #0f766e;
  color: #fff;
  box-shadow: 0 1px 2px rgba(15, 118, 110, 0.35);
}
.kg-guide-modal__close:hover { background: #0d9488; }
.kg-guide-modal__close:focus-visible {
  outline: 2px solid #0d9488;
  outline-offset: 2px;
}
#ketcherGuideFrame { flex: 1; width: 100%; min-height: 0; border: 1px solid #d7e2df; border-radius: 12px; }
.rxn-scheme {
  margin: 0.35rem 0 0.85rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #f7fafc;
  color: #1a222c;
  min-height: 96px;
}
.rxn-scheme.empty {
  display: flex; align-items: center; justify-content: center;
  color: #6a7a88; font-size: 0.9rem;
}
.rxn-scheme img {
  display: block; max-width: 100%; max-height: 160px; margin: 0 auto; background: #fff;
}
.rxn-scheme__full {
  display: block; max-width: 100%; max-height: 200px; margin: 0 auto; background: #fff;
}
.rxn-scheme__row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.35rem 0.5rem;
}
.rxn-scheme__mol {
  display: flex; flex-direction: column; align-items: center; gap: 0.25rem; max-width: 180px;
}
.rxn-scheme__mol img {
  max-width: 160px; max-height: 110px; border-radius: 6px; border: 1px solid #d7e2df;
}
.rxn-scheme__mol .smi {
  font-size: 0.72rem; color: #5b6f6a; word-break: break-all; text-align: center; line-height: 1.25;
  max-width: 160px;
}
.rxn-scheme__plus, .rxn-scheme__arrow {
  font-weight: 700; color: #3a4a58; font-size: 1.25rem; padding: 0 0.1rem;
}
.rxn-scheme__arrow { font-size: 1.6rem; color: #2a6cb0; padding: 0 0.15rem; }
.rec-list { display: flex; flex-direction: column; gap: 0.85rem; }
.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin: 1.1rem 0 0.85rem;
  padding: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(18, 24, 32, 0.9);
}
.mode-switch__btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.85rem 0.9rem;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  font-size: 0.98rem;
  line-height: 1.35;
  cursor: pointer;
  text-align: center;
}
.mode-switch__btn:hover {
  color: var(--text);
  background: #1a2430;
}
.mode-switch__btn.on {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  background: color-mix(in srgb, var(--accent) 18%, #1a2430);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent);
}
.mode-panel.hidden,
.mode-panel[hidden],
[data-ft-factor-panel].hidden,
[data-ft-factor-panel][hidden] { display: none !important; }
.ft-factor-switch {
  margin: 0.85rem 0 0.75rem;
}
.ft-factor-panels .tweak-block {
  border-top: 0;
  padding-top: 0.15rem;
  margin-bottom: 0.5rem;
}
.module-lead { margin: 0 0 0.85rem; max-width: 52rem; }
@media (max-width: 720px) {
  .mode-switch { grid-template-columns: 1fr; }
  .ft-factor-switch.mode-switch { grid-template-columns: 1fr 1fr; }
}
.panel-tweak {
  border-color: #2a5a78;
  background: linear-gradient(180deg, #142028 0%, #10161e 100%);
}
.panel-tweak .panel__title {
  margin: 0 0 0.4rem;
  font-size: 1.02rem;
}
.checkline {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.55rem;
  margin-top: 0.75rem;
  font-size: 0.92rem;
  line-height: 1.45;
  width: 100%;
  cursor: pointer;
}
.checkline input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  flex: 0 0 auto;
  accent-color: var(--accent);
  cursor: pointer;
}
.checkline > span {
  flex: 1 1 auto;
  min-width: 0;
  white-space: normal;
  writing-mode: horizontal-tb;
}
.warn-list {
  margin: 0 0 0.85rem;
  padding: 0.65rem 0.85rem 0.65rem 1.35rem;
  border: 1px solid #5a3a2a;
  border-radius: 10px;
  background: #1c1510;
  color: #e0b15a;
  font-size: 0.88rem;
}
.baseline-box,
.tweak-block,
.lit-block {
  margin: 0 0 1.15rem;
  padding: 0.85rem 0 0.2rem;
  border-top: 1px solid var(--line);
}
.baseline-box:first-child,
.tweak-block:first-child,
.lit-block:first-child { border-top: 0; padding-top: 0; }
.baseline-box h3,
.tweak-block h3,
.lit-block h3 { margin: 0 0 0.35rem; font-size: 1.02rem; }
.rec-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  background: #121820;
}
.rec-card--tweak {
  border-color: #2a5a78;
  background: linear-gradient(180deg, #142028 0%, #121820 100%);
}
.delta-up { color: #3ecf8e; }
.delta-down { color: #e07a7a; }
.rec-card__head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem 0.65rem;
  margin-bottom: 0.65rem;
}
.rec-card__grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.55rem 0.75rem;
  font-size: 0.92rem;
}
.rec-card__grid .muted { display: block; font-size: 0.78rem; margin-bottom: 0.12rem; }
@media (max-width: 900px) {
  .rec-card__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.rec-card__evidence { margin-top: 0.75rem; }
.ev-fold {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0f151c;
  overflow: hidden;
}
.ev-fold__summary {
  cursor: pointer;
  list-style: none;
  padding: 0.7rem 0.85rem;
  font-weight: 650;
  color: var(--text);
  user-select: none;
}
.ev-fold__summary::-webkit-details-marker { display: none; }
.ev-fold__summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 0.45rem;
  color: var(--accent2);
  transition: transform 0.15s ease;
}
.ev-fold[open] > .ev-fold__summary::before { transform: rotate(90deg); }
.ev-fold__summary:hover { background: rgba(61, 156, 240, 0.08); }
.ev-fold__body {
  border-top: 1px solid var(--line);
  padding: 0.65rem 0.85rem 0.85rem;
  max-height: min(420px, 55vh);
  overflow: auto;
}
.ev-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 0.55rem; }
.ev-item {
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #121820;
}
.ev-item__top {
  display: flex; align-items: center; justify-content: space-between; gap: 0.65rem; flex-wrap: wrap;
}
.ev-item__title { font-size: 0.9rem; }
.ev-item__meta { margin-top: 0.3rem; font-size: 0.78rem; line-height: 1.4; word-break: break-word; }
.ev-link {
  display: inline-block;
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent2) 40%, var(--line));
  background: color-mix(in srgb, var(--accent2) 14%, transparent);
  color: #d7e8ff;
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  flex-shrink: 0;
}
.ev-link:hover { filter: brightness(1.08); text-decoration: underline; }
.rec-card__note { margin: 0.65rem 0 0; line-height: 1.45; }
