/* New Loci chart library: chart colours (light and dark) and the chart card.
 *
 * THEME. The app shell sets data-theme="light|dark" on <html>. With no attribute at all, the browser's
 * prefers-color-scheme decides. A chart can also be pinned: renderChart(..., {theme}) sets data-lc-theme on the card.
 * Colours are plain custom properties (--lc-*), read back by palette.js on every draw, so a theme switch only needs
 * redraw(). The values below are CSG brand colours and tints of them (the same roles as the approved mock); the
 * brand values match css/tokens.css, and tests/css.test.mjs fails if they drift. Keep the two dark blocks identical.
 *
 * FONTS. Inter and Barlow Condensed Medium are loaded by the host page (the library declares no @font-face and
 * names no other family). The Arial fallbacks are the tokens' own.
 */

/* light (default) */
.lc-fig,
.lc-fig[data-lc-theme="light"] {
  --lc-dark: 0;
  --lc-paper: #f4f4f4;       /* off-white  (tokens --bg) */
  --lc-sheet: #ffffff;       /* white      (tokens --surface) */
  --lc-sunk: #EDEDF3;
  --lc-ink: #000033;         /* midnight   (tokens --fg) */
  --lc-ink-2: #5d5d72;       /* tokens --muted */
  --lc-ink-3: #66667E;       /* a step darker than tokens --meta so small text clears AA on off-white */
  --lc-ink-4: #9C9CB1;
  --lc-rule: #E2E2EA;
  --lc-rule-2: #CDCDDA;
  --lc-loci: #005cff;        /* cobalt: Loci, the answer, "after", the pick (tokens --accent) */
  --lc-loci-fill: #005cff;
  --lc-loci-ink: #0048cc;    /* tokens --accent-active */
  --lc-loci-soft: #E8F0FF;
  --lc-hist: #130470;        /* navy: what the corpus remembers, "before" (tokens --fg-2) */
  --lc-hist-fill: #130470;
  --lc-hist-soft: #ECEAF6;
  --lc-mem: #f29f05;         /* ochre: site memory, anything to notice (tokens --ochre) */
  --lc-mem-ink: #8A5800;
  --lc-mem-soft: #FEF3DC;
  --lc-limit: #f23030;       /* coral: limits and slips only (tokens --coral) */
  --lc-limit-ink: #C21F1F;
  --lc-limit-soft: #FDECEC;
  --lc-s-turq: #22babb;      /* extra series from the secondaries */
  --lc-s-forest: #267365;
  --lc-s-aub: #6a1b4d;
  --lc-s-mag: #c40084;
  --lc-heat-0: #FBF1DC;      /* clear to brown: ochre into aubergine */
  --lc-heat-1: #F7D28A;
  --lc-heat-2: #F29F05;
  --lc-heat-3: #B9531C;
  --lc-heat-4: #6A1B4D;
  --lc-shadow: 0 1px 2px rgba(0, 0, 51, .06);
  color-scheme: light;
}

/* dark: set on <html> by the shell, or pinned on the card */
[data-theme="dark"] .lc-fig:not([data-lc-theme="light"]),
.lc-fig[data-lc-theme="dark"] {
  --lc-dark: 1;
  --lc-paper: #000033;       /* midnight  (tokens --bg) */
  --lc-sheet: #0b0752;       /* deep navy (tokens --surface-warm) */
  --lc-sunk: #07063F;
  --lc-ink: #ffffff;         /* tokens --fg */
  --lc-ink-2: #c7c7d6;       /* tokens --muted */
  --lc-ink-3: #aaaac0;       /* tokens --meta */
  --lc-ink-4: #7C7CA0;
  --lc-rule: rgba(255, 255, 255, .12);
  --lc-rule-2: rgba(255, 255, 255, .22);
  --lc-loci: #4D8DFF;        /* cobalt, lifted to read on navy */
  --lc-loci-fill: #337CFF;
  --lc-loci-ink: #A9C6FF;
  --lc-loci-soft: rgba(0, 92, 255, .22);
  --lc-hist: #B9B3F6;        /* navy, lifted to lavender so history shows on midnight */
  --lc-hist-fill: #9B93EE;
  --lc-hist-soft: rgba(155, 147, 238, .15);
  --lc-mem: #F7B53B;
  --lc-mem-ink: #FFCB66;
  --lc-mem-soft: rgba(242, 159, 5, .16);
  --lc-limit: #FF5C5C;
  --lc-limit-ink: #FF9494;
  --lc-limit-soft: rgba(242, 48, 48, .17);
  --lc-s-turq: #3CD0D1;
  --lc-s-forest: #4FB19F;
  --lc-s-aub: #C470A7;
  --lc-s-mag: #F05CBA;
  --lc-heat-0: #1E1A67;
  --lc-heat-1: #4B2069;
  --lc-heat-2: #922E57;
  --lc-heat-3: #D9701F;
  --lc-heat-4: #F8BA45;
  --lc-shadow: 0 1px 2px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

/* dark by the browser's preference, only when the shell sets no data-theme at all */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .lc-fig:not([data-lc-theme="light"]) {
    --lc-dark: 1;
    --lc-paper: #000033;
    --lc-sheet: #0b0752;
    --lc-sunk: #07063F;
    --lc-ink: #ffffff;
    --lc-ink-2: #c7c7d6;
    --lc-ink-3: #aaaac0;
    --lc-ink-4: #7C7CA0;
    --lc-rule: rgba(255, 255, 255, .12);
    --lc-rule-2: rgba(255, 255, 255, .22);
    --lc-loci: #4D8DFF;
    --lc-loci-fill: #337CFF;
    --lc-loci-ink: #A9C6FF;
    --lc-loci-soft: rgba(0, 92, 255, .22);
    --lc-hist: #B9B3F6;
    --lc-hist-fill: #9B93EE;
    --lc-hist-soft: rgba(155, 147, 238, .15);
    --lc-mem: #F7B53B;
    --lc-mem-ink: #FFCB66;
    --lc-mem-soft: rgba(242, 159, 5, .16);
    --lc-limit: #FF5C5C;
    --lc-limit-ink: #FF9494;
    --lc-limit-soft: rgba(242, 48, 48, .17);
    --lc-s-turq: #3CD0D1;
    --lc-s-forest: #4FB19F;
    --lc-s-aub: #C470A7;
    --lc-s-mag: #F05CBA;
    --lc-heat-0: #1E1A67;
    --lc-heat-1: #4B2069;
    --lc-heat-2: #922E57;
    --lc-heat-3: #D9701F;
    --lc-heat-4: #F8BA45;
    --lc-shadow: 0 1px 2px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

/* ───────────── the card ───────────── */

.lc-fig {
  box-sizing: border-box; position: relative; width: 100%; margin: 0;
  background: var(--lc-sheet); color: var(--lc-ink);
  border: 1px solid var(--lc-rule); border-radius: var(--radius-lg, 12px);
  padding: 18px 22px 14px; box-shadow: var(--lc-shadow);
  font: 400 15px/1.6 var(--font-body, Inter, Arial, sans-serif);
  font-synthesis: none; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
.lc-fig *, .lc-fig *::before, .lc-fig *::after { box-sizing: border-box; }
.lc-fig[data-narrow] { padding: 14px 14px 12px; }
.lc-fig.lc-bare { background: transparent; border: 0; border-radius: 0; box-shadow: none; padding: 0; }
.lc-fig svg { display: block; overflow: visible; }

.lc-fig-t { font-weight: 600; font-size: 14.5px; line-height: 1.35; }
.lc-fig-s { color: var(--lc-ink-3); font-size: 12.5px; margin-top: 3px; line-height: 1.45; max-width: 640px; }

.lc-legend { display: flex; gap: 6px 16px; flex-wrap: wrap; font-size: 12px; color: var(--lc-ink-2); margin: 12px 0 0; }
.lc-legend:empty { display: none; }
.lc-legend span { display: inline-flex; align-items: center; gap: 7px; }
.lc-legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.lc-legend i.ring { background: transparent !important; border: 1.5px solid; }
.lc-legend i.ring.dashed { border-style: dashed; }
.lc-legend i.sq { border-radius: 2px; }
.lc-legend i.band { width: 18px; height: 10px; border-radius: 2px; }
.lc-legend i.dash { width: 18px; height: 0; border-radius: 0; border-top: 1.5px dashed; }
.lc-legend i.hatch { width: 18px; border-radius: 2px; background-image: repeating-linear-gradient(135deg, currentColor 0 1.5px, transparent 1.5px 5px); }
.lc-legend svg.lsym { flex: none; overflow: visible; }
.lc-legend .ramp { gap: 0; }
.lc-legend .ramp i { width: 15px; border-radius: 0; }
.lc-legend .ramp i:first-of-type { border-radius: 2px 0 0 2px; }
.lc-legend .ramp i:last-of-type { border-radius: 0 2px 2px 0; }
.lc-legend .ramp em { font-style: normal; margin: 0 7px; }
.lc-legend .ramp em:first-child { margin-left: 0; }

.lc-chart { margin-top: 10px; position: relative; min-height: 40px; --plot-background: var(--lc-sheet); }
.lc-chart svg text { font-family: var(--font-body, Inter, Arial, sans-serif); font-variant-numeric: tabular-nums; }

/* reading aids listed under the chart */
.lc-aids { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--lc-rule); }
.lc-aids[hidden] { display: none; }
.lc-aid { margin: 0; font-size: 13px; color: var(--lc-ink-2); line-height: 1.45; }
.lc-aid + .lc-aid { margin-top: 4px; }

/* tips: Plot's own (SVG) and ours (HTML, for the hand-drawn forms) look alike */
.lc-chart [aria-label="tip"] path { stroke: var(--lc-rule-2); filter: drop-shadow(0 6px 14px rgba(0, 0, 51, .16)); }
.lc-chart [aria-label="tip"] text { font-family: var(--font-body, Inter, Arial, sans-serif); font-size: 11.5px; fill: var(--lc-ink); }
.lc-tip {
  position: absolute; left: 0; top: 0; z-index: 3; pointer-events: none; max-width: 260px; padding: 7px 10px;
  background: var(--lc-sheet); color: var(--lc-ink); border: 1px solid var(--lc-rule-2); border-radius: 6px;
  font-size: 11.5px; line-height: 1.4; font-variant-numeric: tabular-nums; filter: drop-shadow(0 6px 14px rgba(0, 0, 51, .16));
}
.lc-tip[hidden] { display: none; }
.lc-tip-h { font-weight: 600; }

/* small multiples (jar ladder) */
.lc-sm { display: grid; grid-template-columns: repeat(var(--lc-cols, 4), minmax(0, 1fr)); gap: 6px 18px; }
.lc-sm-t { font-size: 12.5px; font-weight: 600; color: var(--lc-ink-2); margin-bottom: 2px; line-height: 1.5; }
.lc-sm-u { font-size: 11px; color: var(--lc-ink-3); font-weight: 400; margin-left: 4px; }

/* track record: dots, then the count */
.lc-track { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; align-items: center; }
.lc-track[data-stack] { grid-template-columns: 1fr; }
.lc-track-t { font-size: 13.5px; color: var(--lc-ink-2); line-height: 1.45; }
.lc-track-t b { font-weight: 600; color: var(--lc-ink); }

.lc-chart-err { color: var(--lc-limit-ink); font-size: 12.5px; padding: 12px 0; }
