.sa-banner {
  margin: 12px 18px 0; padding: 10px 14px; border-left: 3px solid #245be0;
  background: #edf3ff; color: #334155; font: 12px/1.5 var(--sans, system-ui);
}
.sa-banner > strong, .sa-banner > span { display: block; }
.sa-banner a { display: inline-block; margin-top: 4px; }
.sa-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 6px; }
.sa-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.sa-legend > span::before { content: ''; width: 9px; height: 9px; border-radius: 2px; background: var(--sa-mark-color); }
.sa-legend > span[data-sa-state="match"]::before { background: #e3e7ed; outline: 1px solid #94a3b8; }
.sa-legend > span[data-sa-state="differs"]::before { background: rgba(234, 88, 12, .45); }
.sa-legend > span[data-sa-state="one_side"]::before { background: repeating-linear-gradient(135deg, rgba(234, 88, 12, .6) 0 2px, transparent 2px 4px); }
.sa-legend > span[data-sa-state="low"]::before { content: '?'; width: 11px; height: 11px; border-radius: 50%; color: #fff; font: 700 8px/11px var(--sans, system-ui); text-align: center; }
.sa-load-error { background: #fff7ed; border-color: #d05a00; }
.sa-source-version { font-size: 10px; color: #64748b; margin-top: 4px; }

/* Only the selected paper item exposes its links, on both sides. */
.sa-anchor { cursor: inherit; }
.sa-linked { cursor: default; }
/* Highlighter marks, no rules: grey where the texts match, the difference colour where they are
   written differently, hatched where a part exists on one side only. */
.sa-linked[data-sa-state="match"] { --sa-fill: #e3e7ed; --sa-fill-active: #cbd3dd; }
.sa-linked[data-sa-state="differs"] { --sa-fill: rgba(234, 88, 12, .28); --sa-fill-active: rgba(234, 88, 12, .45); }
.sa-linked[data-sa-state="one_side"] { --sa-fill: rgba(234, 88, 12, .08); --sa-fill-active: rgba(234, 88, 12, .2);
  background-image: repeating-linear-gradient(135deg, rgba(234, 88, 12, .42) 0 4px, transparent 4px 9px); }
.sa-linked[data-sa-state="none"] { --sa-fill: #eef1f5; --sa-fill-active: #dfe4ea; }
.paper-html-statement .sa-linked {
  background-color: var(--sa-fill); border: 0; border-radius: 3px;
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
.paper-html-statement .sa-linked.sa-active {
  background-color: var(--sa-fill-active, var(--sa-fill));
  box-shadow: 0 0 0 1.5px var(--sa-hover-color);
}
/* A part decided with low confidence: a "?" after its last passage on each side. */
.sa-linked.sa-low::after, .sa-low-badge {
  content: '?'; display: inline-block; margin-left: 3px; width: 13px; height: 13px; border-radius: 50%;
  background: #334155; color: #fff; font: 700 10px/13px var(--sans, system-ui); text-align: center;
  vertical-align: 2px; text-indent: 0;
}
.sa-low-badge { vertical-align: 6px; }
.paper-html-statement g.sa-anchor { border: 0; background: none; }
.sa-svg-background, .sa-svg-underline { visibility: hidden; pointer-events: none; }
.sa-svg-background { fill: var(--sa-mark-color); stroke: none; }
/* Thickness in final pixels, so a formula's SVG scale cannot thin the rule out. */
.sa-svg-underline {
  fill: none; stroke: var(--sa-mark-color); stroke-width: 3;
  vector-effect: non-scaling-stroke;
}
.sa-linked > .sa-svg-background { visibility: visible; pointer-events: all; fill-opacity: .28; }
/* Formulas take the prose colours exactly: the same opaque grey, the same orange. */
.sa-linked[data-sa-state="match"] > .sa-svg-background { fill: #e3e7ed; fill-opacity: 1; }
.sa-linked[data-sa-state="none"] > .sa-svg-background { fill: #eef1f5; fill-opacity: 1; }
.sa-linked[data-sa-state="one_side"] > .sa-svg-background { fill-opacity: .14; }
.sa-linked > .sa-svg-underline { visibility: hidden; }
/* Hovered, as in prose: a darker fill and a thin ring. */
.sa-linked.sa-active > .sa-svg-background {
  fill-opacity: .45; stroke: var(--sa-hover-color); stroke-width: 1.5; vector-effect: non-scaling-stroke;
}
.sa-linked.sa-active[data-sa-state="match"] > .sa-svg-background { fill: #cbd3dd; fill-opacity: 1; }
.sa-linked.sa-active[data-sa-state="none"] > .sa-svg-background { fill: #dfe4ea; fill-opacity: 1; }
.sa-linked.sa-active[data-sa-state="one_side"] > .sa-svg-background { fill-opacity: .3; }
.paper-html-statement mjx-container svg { overflow: visible; }
.sa-linked:focus-visible { outline: 2px solid var(--sa-mark-color); outline-offset: 3px; }

.sa-source-review .source-editor-table .file-line { background: transparent; }
.sa-source-review .source-editor-table .file-line.focused.focus-signature {
  background: rgba(var(--source-rgb), .10) !important;
}
.sa-source-review .source-editor-table .file-line.focused.focus-proof {
  background: rgba(var(--source-rgb), .035) !important;
}
/* In the statement only the comparison with the paper is marked; references stay in the proof. */
.sa-source-review .source-editor .file-line.focus-signature .ref-mark {
  background: none !important; color: inherit !important; font-weight: inherit !important; box-shadow: none !important;
  border: 0 !important; outline: 0 !important; text-decoration: none !important; pointer-events: none;
}
.sa-source-review .source-editor-table .file-line .file-line-code,
.sa-source-review .source-editor-table .file-line.focused.focus-signature .file-line-code {
  background: transparent; font-weight: 400; box-shadow: none;
}
.sa-source-review .source-editor .sa-linked {
  cursor: text; border: 0; border-radius: 3px; background-color: var(--sa-fill);
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
.sa-source-review .source-editor .sa-linked.sa-active {
  background-color: var(--sa-fill-active, var(--sa-fill));
  box-shadow: 0 0 0 1.5px var(--sa-hover-color);
}

.sa-tooltip {
  position: fixed; z-index: 10000; width: min(380px, calc(100vw - 24px));
  box-sizing: border-box; max-height: min(420px, calc(100vh - 24px)); overflow: auto;
  padding: 12px 14px; border: 1px solid #c4ccd8; border-radius: 8px;
  background: #fff; box-shadow: 0 5px 20px #15233b29;
  color: #263244; font: 13px/1.5 var(--sans, system-ui); text-align: left;
}
.sa-tooltip[hidden] { display: none; }
/* Keep the gap hoverable without letting the next code line steal the tooltip.
   Fixed positioning lets this bridge extend outside the scrollable tooltip. */
.sa-tooltip::before {
  content: ''; position: fixed; inset: 0;
  clip-path: var(--sa-hover-bridge, polygon(0 0, 0 0, 0 0));
}
.sa-tooltip-entry + .sa-tooltip-entry { margin-top: 10px; padding-top: 10px; border-top: 1px solid #e2e7ee; }
.sa-tooltip-type { display: flex; align-items: center; gap: 7px; color: var(--sa-mark-color); font-size: 12px; }
.sa-tooltip-type::before { content: ''; flex: 0 0 9px; height: 9px; border-radius: 2px; background: currentColor; }
.sa-tooltip-low { display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: #334155; color: #fff;
  font: 700 10px/14px var(--sans, system-ui); text-align: center; }
.sa-tooltip-direction { display: block; margin-top: 3px; color: #475569; font-size: 12px; }
.sa-tooltip-derivation { padding: 6px 8px; background: #f3f6f9; border-radius: 4px; font-size: 12px; }
.sa-tooltip p { margin: 6px 0 0; }
.sa-tooltip-action { padding-top: 7px; border-top: 1px solid #e2e7ee; }
.sa-tooltip-action strong { font-weight: 600; }
.sa-tooltip-scope { display: block; margin-top: 7px; color: #58677b; overflow-wrap: anywhere; }

.sa-tooltip-destination { display: block; margin-top: 8px; color: #58677b; font-size: 11px; }
.sa-tooltip-context {
  margin: 6px 0 0; padding: 6px 8px; border-left: 3px solid var(--sa-mark-color);
  background: #f3f6f9; white-space: pre-wrap; overflow-wrap: anywhere;
  font: 12px/1.5 var(--mono, monospace); max-height: 140px; overflow: auto;
}
