:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1b1f24;
  --muted: #5d6673;
  --line: #dde1e6;
  --accent: #2f6fde;
  --accent-ink: #ffffff;
  --chip: #eef3fc;
  --warn-bg: #fff6e5;
  --warn-ink: #7a4b00;
  --err-bg: #fdecec;
  --err-ink: #8a1c1c;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --panel: #1a1e24;
    --ink: #e7eaee;
    --muted: #9aa3ae;
    --line: #2c323a;
    --accent: #6ea0ff;
    --accent-ink: #0d1117;
    --chip: #222a36;
    --warn-bg: #3a2c10;
    --warn-ink: #ffd88a;
    --err-bg: #3a1717;
    --err-ink: #ffb3b3;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
h2 { font-size: 1rem; margin: 1.25rem 0 .6rem; }
h2:first-child { margin-top: 0; }
h3 { font-size: .85rem; margin: 0 0 .4rem; color: var(--muted); font-weight: 600; }
h3 small { font-weight: 400; }
button, input, select { font: inherit; color: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: .8rem 1.25rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.05rem; }
.brand svg { width: 26px; height: 26px; color: var(--accent); }
.examples { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .9rem; }

.layout {
  display: grid; grid-template-columns: minmax(340px, 520px) 1fr; gap: 1.25rem;
  padding: 1.25rem; max-width: 1500px; margin: 0 auto;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; padding: 1rem; } }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; min-width: 0; }

.editor { width: 100%; height: 360px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.editor-loading { color: #666; padding: 1rem; margin: 0; }

input[type=text], select {
  width: 100%; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
input[type=text]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.examples select { width: auto; }

button {
  border: 1px solid var(--line); background: var(--bg); padding: .45rem .8rem; border-radius: 8px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; padding: .55rem 1.1rem; }
button.primary:disabled { opacity: .6; cursor: progress; }
button.ghost { background: transparent; }

.smiles-row { display: flex; gap: .5rem; margin-top: .6rem; }
.smiles-row input { font-family: ui-monospace, Menlo, Consolas, monospace; }
.add-row { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-top: .6rem; }
.add-row span { color: var(--muted); font-size: .9rem; margin-right: .2rem; }

.slots { display: grid; gap: .7rem; }
.slot { border: 1px dashed var(--line); border-radius: 8px; padding: .6rem; }
.slot input { margin-top: .4rem; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; min-height: 1.5rem; }
.chips:empty::before { content: "Nothing yet"; color: var(--muted); font-size: .85rem; }

.chip {
  position: relative; display: flex; flex-direction: column; align-items: center;
  background: var(--chip); border: 1px solid var(--line); border-radius: 8px; padding: .3rem .4rem .25rem; cursor: pointer;
  max-width: 150px;
}
.chip svg { width: 110px; height: 80px; }
.chip.text-only { padding: .35rem .7rem; flex-direction: row; }
.chip code { font-size: .72rem; color: var(--muted); max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .x {
  position: absolute; top: -8px; right: -8px; width: 20px; height: 20px; padding: 0; border-radius: 50%;
  line-height: 1; font-size: 13px; background: var(--panel);
}

.field { display: block; margin-top: .8rem; font-size: .9rem; color: var(--muted); }
.field input, .field select { margin-top: .25rem; color: var(--ink); }
.controls { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-top: .4rem; }
.field.inline { flex: 0 0 180px; }
.hint { color: var(--muted); font-size: .85rem; margin: .6rem 0 0; }

/* ---------- Results ---------- */
.empty { color: var(--muted); max-width: 520px; margin: 3rem auto; text-align: center; }
.loading { text-align: center; color: var(--muted); margin: 4rem 0; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 1rem; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error { background: var(--err-bg); color: var(--err-ink); padding: .8rem 1rem; border-radius: 8px; }

#result header h2 { font-size: 1.35rem; margin: 0 0 .2rem; }
.rtype { color: var(--accent); font-weight: 600; font-size: .9rem; margin: 0 0 .6rem; }
.summary { margin: 0 0 1rem; }
.warning { background: var(--warn-bg); color: var(--warn-ink); padding: .7rem .9rem; border-radius: 8px; margin-bottom: 1rem; }

.scheme {
  display: flex; align-items: center; gap: .4rem; overflow-x: auto; padding: .8rem;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
.mol { display: flex; flex-direction: column; align-items: center; flex: 0 0 auto; }
.mol svg { width: 150px; height: 115px; }
.mol .label { font-size: .78rem; color: var(--muted); text-align: center; max-width: 160px; }
.mol .role { font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); }
.mol.byproduct { opacity: .7; }
.plus { font-size: 1.4rem; color: var(--muted); flex: 0 0 auto; }
.arrow { display: flex; flex-direction: column; align-items: center; flex: 0 0 auto; min-width: 110px; padding: 0 .3rem; }
.arrow .above, .arrow .below { font-size: .78rem; text-align: center; max-width: 170px; }
.arrow .below { color: var(--muted); }
.arrow svg { width: 100%; height: 18px; color: var(--ink); }

.steps { list-style: none; padding: 0; margin: 1.4rem 0 0; counter-reset: step; }
.step { border: 1px solid var(--line); border-radius: 8px; margin-bottom: .9rem; overflow: hidden; }
.step > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: .7rem; padding: .7rem .9rem;
}
.step > summary::-webkit-details-marker { display: none; }
.step .num {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; font-size: .85rem;
}
.step .stitle { font-weight: 600; }
.step .stype { font-size: .78rem; color: var(--muted); margin-left: auto; text-align: right; }
.step .body { padding: 0 .9rem .9rem; }
.step .scheme { margin-bottom: .7rem; }
.step .mol svg { width: 130px; height: 100px; }
.flow { margin: .4rem 0 .6rem; padding-left: 1.1rem; }
.flow li { margin: .15rem 0; }
.flow li::marker { content: "↷  "; color: var(--accent); }

.extras { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .8rem; margin-top: 1rem; }
.extras section { border: 1px solid var(--line); border-radius: 8px; padding: .7rem .9rem; }
.extras h3 { margin-bottom: .3rem; }
.extras ul { margin: 0; padding-left: 1.1rem; }
.result-actions { display: flex; gap: .5rem; margin-top: 1rem; }

@media print {
  .topbar, .draw-panel, .result-actions { display: none !important; }
  .layout { display: block; padding: 0; }
  .panel { border: 0; }
  .step { break-inside: avoid; }
}

/* ---------- Accounts & billing ---------- */
.topbar-right { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.account { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.account .email { color: var(--muted); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: .72rem; font-weight: 700; padding: .1rem .45rem; border-radius: 999px; background: var(--chip); border: 1px solid var(--line); }
.badge.pro { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.banner { max-width: 1500px; margin: 1rem auto 0; padding: .7rem 1rem; border-radius: 8px; background: var(--chip); border: 1px solid var(--line); width: calc(100% - 2.5rem); }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }

.dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--panel); color: var(--ink); width: min(440px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgb(0 0 0 / .45); }
.dialog form, .dialog .dialog-body { position: relative; padding: 1.4rem; }
.dialog h2 { margin: 0 0 .3rem; font-size: 1.2rem; }
.dialog input[type=email], .dialog input[type=password] { width: 100%; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.dialog .close { position: absolute; top: .6rem; right: .6rem; border: 0; background: transparent; font-size: 1.4rem; line-height: 1; padding: .2rem .5rem; }
button.wide { width: 100%; margin-top: 1rem; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.switch { text-align: center; margin: .9rem 0 0; font-size: .9rem; }
.form-error { background: var(--err-bg); color: var(--err-ink); padding: .5rem .7rem; border-radius: 8px; margin: .8rem 0 0; font-size: .9rem; }

.plans { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; margin-top: 1rem; }
.plan { border: 1px solid var(--line); border-radius: 10px; padding: .8rem; }
.plan.pro { border: 2px solid var(--accent); }
.plan h3 { margin: 0; color: var(--ink); font-size: 1rem; }
.plan .price { font-size: 1.15rem; font-weight: 700; margin: .2rem 0 .4rem; }
.plan ul { margin: 0; padding-left: 1.1rem; font-size: .88rem; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 0 1rem 1.5rem; }
@media print { .footer, .banner { display: none !important; } }

/* ---------- Pricing section & info pages ---------- */
a { color: var(--accent); }
a.brand { color: var(--ink); text-decoration: none; }
.pricing { max-width: 760px; margin: 1rem auto 2rem; padding: 0 1rem; text-align: center; }
.pricing h2 { font-size: 1.3rem; margin-bottom: 1rem; }
.pricing .plans { text-align: left; }
.pricing .plan { background: var(--panel); padding: 1.1rem; display: flex; flex-direction: column; }
.pricing .plan ul { flex: 1; margin-bottom: .4rem; }
.pricing .plan .muted.small { margin: -.3rem 0 .5rem; }
@media (max-width: 600px) { .plans { grid-template-columns: 1fr; } }
.footer p { margin: .3rem 0; }

.doc-nav { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .9rem; }
.doc { max-width: 760px; margin: 0 auto; padding: 1.5rem 1rem 2rem; line-height: 1.65; }
.doc h1 { font-size: 1.7rem; margin: .5rem 0 .2rem; }
.doc h2 { font-size: 1.1rem; margin: 1.6rem 0 .4rem; }
.doc ul { padding-left: 1.3rem; }
.contact-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .4rem 1.1rem; margin: 1rem 0; }
mark.todo { background: #ffe58a; color: #5a4300; padding: 0 .25rem; border-radius: 4px; font-weight: 600; }

/* ---------- Curly-arrow mechanisms ---------- */
:root { --arrow: #d6336c; }
@media (prefers-color-scheme: dark) { :root { --arrow: #ff7aa8; } }
.step .scheme.mech { padding: 38px 16px; align-items: center; }
.mech-group { position: relative; display: flex; align-items: center; gap: .5rem; flex: 0 0 auto; }
.mech .mol svg { width: auto; height: auto; display: block; }
.arrow-layer { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.curly path { fill: none; stroke: var(--arrow); stroke-width: 1.8; stroke-linecap: round; }
.curly .head { fill: var(--arrow); stroke: none; }
.curly .dot { fill: var(--arrow); }
.curly .num { fill: var(--panel); stroke: var(--arrow); stroke-width: 1.2; }
.curly .num-text { fill: var(--arrow); font-weight: 700; font-family: system-ui, sans-serif; }
.charge-badge { fill: var(--panel); stroke: var(--ink); stroke-width: .8; }
.charge-sign, .mol-label, .mol-charge { fill: var(--ink); font-family: system-ui, sans-serif; }
.hide-arrows .arrow-layer { display: none; }
.mech-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-top: 1.4rem; }
.arrow-toggle { font-size: .85rem; color: var(--muted); cursor: pointer; }
ol.flow { margin: .4rem 0 .6rem; padding-left: 0; list-style: none; counter-reset: flow; }
ol.flow li { counter-increment: flow; position: relative; padding-left: 1.9rem; margin: .3rem 0; }
ol.flow li::before {
  content: counter(flow); position: absolute; left: 0; top: .05rem; width: 1.25rem; height: 1.25rem; border-radius: 50%;
  border: 1.5px solid var(--arrow); color: var(--arrow); font-size: .72rem; font-weight: 700; display: grid; place-items: center;
}
.hide-arrows ol.flow { filter: blur(4px); transition: filter .2s; }
.hide-arrows ol.flow:hover { filter: none; }
@media print { .arrow-toggle { display: none; } }
ol.flow li::marker { content: none; }

/* ---------- Saved scheme history ---------- */
.dialog-wide { width: min(640px, calc(100vw - 32px)); }
#historySearch { width: 100%; margin: .6rem 0 .4rem; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.history-list { list-style: none; margin: .4rem 0 0; padding: 0; max-height: min(60vh, 520px); overflow-y: auto; }
.history-list li { display: flex; align-items: stretch; gap: .4rem; border: 1px solid var(--line); border-radius: 8px; margin-bottom: .5rem; }
.history-list li.muted { border: 0; padding: .5rem 0; }
.history-open { flex: 1; min-width: 0; text-align: left; border: 0; background: transparent; padding: .6rem .7rem; display: flex; flex-direction: column; gap: .15rem; }
.history-open:hover { background: var(--chip); }
.h-title { font-weight: 600; }
.h-meta { font-size: .8rem; color: var(--muted); }
.h-smiles { font-size: .75rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.small-btn { align-self: center; margin-right: .5rem; font-size: .8rem; padding: .3rem .6rem; white-space: nowrap; }
.small-btn.confirm { border-color: var(--err-ink); color: var(--err-ink); }
.saved-note { font-size: .85rem; color: var(--muted); margin: 0 0 .6rem; }

/* ---------- Password reset ---------- */
.info-note { background: var(--chip); border: 1px solid var(--line); padding: .6rem .75rem; border-radius: 8px; margin: .8rem 0 0; font-size: .9rem; }
.reset-page { max-width: 440px; }
.reset-page input[type=password] { width: 100%; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); margin-top: .25rem; }
.button-link { display: inline-block; background: var(--accent); color: var(--accent-ink); padding: .55rem 1.1rem; border-radius: 8px; text-decoration: none; font-weight: 600; }

/* ---------- Homepage intro & mechanism library ---------- */
.hero { max-width: 1500px; margin: 0 auto; padding: 1.1rem 1.25rem 0; }
.hero h1 { font-size: 1.35rem; margin: 0 0 .3rem; }
.hero p { margin: 0; color: var(--muted); max-width: 820px; }
.popular { max-width: 760px; margin: 1.5rem auto 0; padding: 0 1rem; }
.popular h2 { font-size: 1.15rem; margin: 0 0 .5rem; }
.popular ul { columns: 2; column-gap: 2rem; padding-left: 1.1rem; margin: 0 0 .5rem; }
.popular li { margin: .2rem 0; break-inside: avoid; }
@media (max-width: 600px) { .popular ul { columns: 1; } }

.reaction-page, .reaction-index { max-width: 1050px; }
.reaction-page h1, .reaction-index h1 { font-size: 1.75rem; line-height: 1.25; }
.crumbs { font-size: .85rem; color: var(--muted); margin-top: .5rem; }
.lead { font-size: 1.05rem; }
h2.sec { font-size: 1.15rem; margin: 1.6rem 0 .6rem; }
.mech-head h2.sec { margin: 0; }
.card-list { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .7rem; }
.card-list a { display: flex; flex-direction: column; gap: .25rem; height: 100%; padding: .8rem .9rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); text-decoration: none; }
.card-list a:hover { border-color: var(--accent); }
.card-list span { color: var(--muted); font-size: .88rem; }
.reaction-page .scheme { background: var(--bg); }
.reaction-page .mol svg { width: 150px; height: 115px; }
.reaction-page .mech .mol svg { width: auto; height: auto; }
@media print { .crumbs, .related, .button-link { display: none !important; } }

/* Keep the top bar inside small screens */
.topbar-right { min-width: 0; max-width: 100%; }
.examples { min-width: 0; max-width: 100%; }
.examples select { min-width: 0; max-width: 100%; flex: 1 1 auto; }
@media (max-width: 600px) { .examples { flex: 1 1 100%; } .examples select { width: 100%; } }
.radical-dot { fill: var(--arrow); }
