/* The `chem` figure kit (ui/figures/chem.js): the molecule pictures (P0j).
   Linked from index.html; the kit's rules live here and nowhere else (never in styles.css). Rules are `.cx-figure--molecule` and `.mol-*`
   classes; colour tokens are declared three times, as in geo.css (:root, the dark preference and data-theme="dark"). See docs/figures/README.md.
   Builds on the shared .cx, .cx-figure rules in styles.css and on its tokens (--surface, --surface-2, --text, --muted, --wire, --accent, --user-line). */

/* ---- Colours -----------------------------------------------------------------------------------------------------
   Every fill or stroke that carries meaning is at least 3:1 against the card (--surface) in both themes (tests/ui-figures-chem.test.js and the
   kit's browser test measure it), and none is the only cue: each atom has its letter (O, H, Na⁺, Cl⁻), oxygen is the larger circle and a chloride
   ion the larger ion, the shared electrons carry a minus, a hydrogen bond is dashed where a bond is solid, and the angle has its number. The letters
   are 4.5:1 against their own fill (data-on-fill). The hydrogen atom is a light disc with a dark outline: the outline is what is 3:1 on the card. */
:root {
  --mol-o: #c92a2a;
  --mol-o-ink: #ffffff;
  --mol-na: #6741d9;
  --mol-na-ink: #ffffff;
  --mol-cl: #237a35;
  --mol-cl-ink: #ffffff;
  --mol-electron: #3b5bdb;
  --mol-electron-mark: #ffffff;
  --mol-h: color-mix(in srgb, var(--muted) 12%, var(--surface));
  --mol-hbond: #3b5bdb;
  --mol-angle: #e8590c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --mol-o: #ff8787;
    --mol-o-ink: #12141c;
    --mol-na: #b197fc;
    --mol-na-ink: #12141c;
    --mol-cl: #69db7c;
    --mol-cl-ink: #12141c;
    --mol-electron: #8ea2ff;
    --mol-electron-mark: #12141c;
    --mol-hbond: #8ea2ff;
    --mol-angle: #ff922b;
  }
}
:root[data-theme="dark"] {
  --mol-o: #ff8787;
  --mol-o-ink: #12141c;
  --mol-na: #b197fc;
  --mol-na-ink: #12141c;
  --mol-cl: #69db7c;
  --mol-cl-ink: #12141c;
  --mol-electron: #8ea2ff;
  --mol-electron-mark: #12141c;
  --mol-hbond: #8ea2ff;
  --mol-angle: #ff922b;
}

/* ---- The picture ------------------------------------------------------------------------------------------------- */
.cx-figure--molecule { max-width: 360px; }
/* Text is at least 12 units of a 320-unit picture, bold: the width estimate (textWidth in data-chart.js) is for bold text. The letters in the atoms
   and the charges are larger (set in the drawing). */
.mol-text { font-size: 13px; font-weight: 600; fill: var(--text); font-family: inherit; font-variant-numeric: tabular-nums; }
.mol-text--muted { fill: var(--muted); }
.mol-text--strong { font-weight: 800; }
.mol-charge { font-weight: 800; }
.mol-letter { font-weight: 800; }

/* ---- atoms and bonds ----------------------------------------------------------------------------------------------- */
.mol-atom { stroke: var(--wire); stroke-width: 2.5; }
.mol-atom--o { fill: var(--mol-o); }
.mol-atom--h { fill: var(--mol-h); }
.mol-ion--na { fill: var(--mol-na); }
.mol-ion--cl { fill: var(--mol-cl); }
/* the letter of an atom is read against its own fill: white (or dark in the dark theme) on the colours, the text colour on the light hydrogen */
.mol-letter { fill: var(--text); }
.mol-letter[data-on-fill=".mol-atom--o"] { fill: var(--mol-o-ink); }
.mol-letter[data-on-fill=".mol-ion--na"] { fill: var(--mol-na-ink); }
.mol-letter[data-on-fill=".mol-ion--cl"] { fill: var(--mol-cl-ink); }
.mol-bond { stroke: var(--wire); stroke-width: 4; stroke-linecap: round; }
/* A hydrogen bond is dashed, so that it differs from a bond by more than its colour. */
.mol-hbond { stroke: var(--mol-hbond); stroke-width: 3; stroke-dasharray: 7 5; stroke-linecap: butt; }
.mol-electron { fill: var(--mol-electron); stroke: var(--surface); stroke-width: 1.5; }
.mol-electron-mark { fill: none; stroke: var(--mol-electron-mark); stroke-width: 2.2; stroke-linecap: round; }
.mol-leader { stroke: var(--muted); stroke-width: 1.5; }
/* The angle: the continuations of the two bonds are thin and dotted, the arc between them is the heavier line in orange. */
.mol-ext { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 2 4; stroke-linecap: round; }
.mol-arc { fill: none; stroke: var(--mol-angle); stroke-width: 3; stroke-linecap: round; }
