/* ============ tokens ============ */
:root {
  /* drafting-table neutrals: cool paper, navy ink, indigo accent; graph-paper grid behind figures */
  --bg: #f2f4f8;
  --bg2: #e8ecf2;
  --panel: #ffffff;
  --ink: #162033;
  --ink2: #45526b;
  --ink3: #60697e;
  --line: #dde3ec;
  --line2: #cad2de;
  --grid: #e6ebf3;
  --accent: #4b45d6;
  --accent-soft: #e9e8fd;
  --accent-ink: #3730a3;
  --concept: #6d28d9;
  --concept-bg: #f3edff;

  --k-def: #0f766e;  --k-def-bg: #dff5f1;
  --k-thm: #4338ca;  --k-thm-bg: #e7e6fd;
  --k-formula: #a64c08; --k-formula-bg: #fdf0dc;
  --k-axiom: #475569; --k-axiom-bg: #e8ecf1;

  /* diagram palette */
  --g-base: #1f2937;
  --g-given: #2563eb;
  --g-concl: #e8590c;
  --g-hl: #7c3aed;
  --g-aux: #8f99ab;
  --g-faint: #c4cad4;
  --g-c1: #0d9488;
  --g-c2: #db2777;
  --g-c3: #ca8a04;
  --g-c4: #16a34a;
  --fig-bg: #fbfcfe;
  /* text on an --accent background, and the given / conclusion labels as text (WCAG AA: 4.5:1) */
  --on-accent: #ffffff;
  --t-given: #1e54d4;
  --t-concl: #b3440a;

  --shadow: 0 1px 2px rgba(20, 24, 40, .05), 0 4px 14px rgba(20, 24, 40, .05);
  --radius: 14px;
  --font: 'Rubik', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  --display: 'Secular One', 'Rubik', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  --math: 'Cambria Math', 'STIX Two Math', 'Times New Roman', Times, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10131a; --bg2: #181c26; --panel: #1b202b; --ink: #e7eaf1; --ink2: #b3bccd; --ink3: #8892a7;
    --line: #2a303d; --line2: #384052; --grid: #222937; --accent: #8b85ff; --accent-soft: #2a2950; --accent-ink: #c7c3ff;
    --concept: #c4a5ff; --concept-bg: #2c2440;
    --k-def: #5eead4; --k-def-bg: #133a37; --k-thm: #a5b4fc; --k-thm-bg: #24264a; --k-formula: #fbbf77; --k-formula-bg: #3b2a14; --k-axiom: #cbd5e1; --k-axiom-bg: #2a3140;
    --g-base: #e5e7eb; --g-given: #60a5fa; --g-concl: #fb923c; --g-hl: #b197fc; --g-aux: #7d879a; --g-faint: #4b5262;
    --g-c1: #2dd4bf; --g-c2: #f472b6; --g-c3: #facc15; --g-c4: #4ade80; --fig-bg: #151922;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
    --on-accent: #14122e; --t-given: #60a5fa; --t-concl: #fb923c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #10131a; --bg2: #181c26; --panel: #1b202b; --ink: #e7eaf1; --ink2: #b3bccd; --ink3: #8892a7;
  --line: #2a303d; --line2: #384052; --grid: #222937; --accent: #8b85ff; --accent-soft: #2a2950; --accent-ink: #c7c3ff;
  --concept: #c4a5ff; --concept-bg: #2c2440;
  --k-def: #5eead4; --k-def-bg: #133a37; --k-thm: #a5b4fc; --k-thm-bg: #24264a; --k-formula: #fbbf77; --k-formula-bg: #3b2a14; --k-axiom: #cbd5e1; --k-axiom-bg: #2a3140;
  --g-base: #e5e7eb; --g-given: #60a5fa; --g-concl: #fb923c; --g-hl: #b197fc; --g-aux: #7d879a; --g-faint: #4b5262;
  --g-c1: #2dd4bf; --g-c2: #f472b6; --g-c3: #facc15; --g-c4: #4ade80; --fig-bg: #151922;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
  --on-accent: #14122e; --t-given: #60a5fa; --t-concl: #fb923c;
  color-scheme: dark;
}

/* ============ base ============ */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.6 var(--font);
}
a { color: inherit; }
button { font: inherit; color: inherit; }
.m { font-family: var(--math); font-size: 1.06em; white-space: nowrap; unicode-bidi: isolate; direction: ltr; display: inline-block; }
.m i { font-style: italic; }
.m sub, .m sup { font-size: .7em; }
.arcn { position: relative; display: inline-block; padding-top: .28em; }
.arcn::before { content: ''; position: absolute; top: .05em; left: 8%; right: 8%; height: .5em; border: 1.3px solid currentColor; border-bottom: 0; border-radius: 50% 50% 0 0 / 100% 100% 0 0; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 .12em; line-height: 1.05; font-size: .92em; }
.frac .num { border-bottom: 1.2px solid currentColor; padding: 0 .15em .05em; }
.frac .den { padding: .05em .15em 0; }

/* ============ diagram ============ */
.gd { display: block; max-width: 100%; height: auto; overflow: visible; direction: ltr; unicode-bidi: isolate; }
.gd .r-base { --c: var(--g-base); }
.gd .r-given { --c: var(--g-given); }
.gd .r-concl { --c: var(--g-concl); }
.gd .r-hl { --c: var(--g-hl); }
.gd .r-aux { --c: var(--g-aux); }
.gd .r-faint { --c: var(--g-faint); }
.gd .r-c1 { --c: var(--g-c1); }
.gd .r-c2 { --c: var(--g-c2); }
.gd .r-c3 { --c: var(--g-c3); }
.gd .r-c4 { --c: var(--g-c4); }
.gd .ln, .gd .arc { stroke: var(--c); stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.gd .ln.r-given, .gd .ln.r-concl, .gd .ln.r-hl, .gd .ln.r-c1, .gd .ln.r-c2, .gd .ln.r-c3, .gd .ln.r-c4 { stroke-width: 2.7; }
.gd .arc { stroke-width: 4; stroke-opacity: .85; }
.gd .arc.thin { stroke-width: 1.8; stroke-opacity: 1; }
.gd .ln.r-aux { stroke-width: 1.4; }
.gd .ln.r-faint { stroke-width: 1.4; }
.gd .nofill { fill: none; }
.gd .fl { fill: var(--c); fill-opacity: .13; stroke: none; }
.gd .fl.r-base { fill-opacity: .06; }
.gd .wedge { fill: var(--c); fill-opacity: .26; stroke: none; }
.gd .amark, .gd .rmark, .gd .tick, .gd .pmark { stroke: var(--c); stroke-width: 1.7; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.gd .r-base.wedge { fill-opacity: .1; }
.gd .dot { fill: var(--c); }
.gd text { fill: var(--c); font-family: var(--math); font-size: 15px; }
.gd .plab { font-style: italic; fill: var(--g-base); font-size: 15.5px; }
.gd .alab, .gd .slab, .gd .mlab { font-style: italic; font-size: 14px; font-weight: 600; }
.gd .ftext { font-size: 13px; }
.gd .ftext.heb { font-family: var(--font); font-style: normal; direction: rtl; unicode-bidi: embed; }
.gd text { paint-order: stroke; stroke: var(--fig-bg); stroke-width: 3px; stroke-linejoin: round; }
/* labels in the light theme are a shade darker than their lines, so every colour reads at 4.5:1 */
.gd text { fill: color-mix(in srgb, var(--c) 74%, #000); }
:root[data-theme="dark"] .gd text { fill: var(--c); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .gd text { fill: var(--c); } }

/* ============ cards ============ */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px 12px; position: relative;
  scroll-margin-top: 90px;
}
.card-h { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.kind { font-size: 12.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--k-thm-bg); color: var(--k-thm); white-space: nowrap; }
.kind.k-def { background: var(--k-def-bg); color: var(--k-def); }
.kind.k-formula { background: var(--k-formula-bg); color: var(--k-formula); }
.kind.k-axiom { background: var(--k-axiom-bg); color: var(--k-axiom); }
.num { font-size: 12.5px; color: var(--ink3); font-variant-numeric: tabular-nums; }
.title { margin: 0; font-size: 18.5px; font-weight: 700; line-height: 1.35; flex: 1 1 260px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; }
.badge { font-size: 12.5px; padding: 2px 9px; border-radius: 8px; border: 1px dashed var(--line2); color: var(--ink2); }
.badge.cite { border-style: solid; border-color: transparent; background: var(--accent-soft); color: var(--accent-ink); }
.badge.st-extra { color: #8a5a00; border-color: #e8c98a; background: #fff8e8; }
.badge.st-practice, .badge.st-removed { color: #a3261b; border-color: #f0b4ad; background: #fff1ef; }
:root[data-theme="dark"] .badge.st-extra { color: #f5c46b; background: #33270f; border-color: #6b5321; }
:root[data-theme="dark"] .badge.st-practice, :root[data-theme="dark"] .badge.st-removed { color: #ff9c90; background: #3a1b18; border-color: #6e2f29; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge.st-extra { color: #f5c46b; background: #33270f; border-color: #6b5321; }
  :root:not([data-theme="light"]) .badge.st-practice, :root:not([data-theme="light"]) .badge.st-removed { color: #ff9c90; background: #3a1b18; border-color: #6e2f29; }
}
.card-b { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px; margin-top: 10px; align-items: start; }
.stmt { margin: 0 0 10px; font-size: 17px; font-weight: 500; }
.gp { display: grid; gap: 4px; margin: 0 0 10px; padding: 8px 12px; background: var(--bg2); border-radius: 10px; font-size: 15px; }
.gp > div { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.gp-l { font-size: 12.5px; font-weight: 700; min-width: 44px; }
.gp .g .gp-l { color: var(--t-given); }
.gp .p .gp-l { color: var(--t-concl); }
.explain { margin: 0 0 8px; }
.ex-l { display: inline-block; font-size: 12.5px; font-weight: 700; color: var(--ink3); margin-bottom: 1px; }
.explain p { margin: 0; color: var(--ink2); }
.note { margin: 6px 0; font-size: 14.5px; color: var(--ink2); padding-inline-start: 10px; border-inline-start: 3px solid var(--line2); }
.xlinks { font-size: 14.5px; margin: 6px 0 0; color: var(--ink2); }
.xl-l { font-weight: 600; }
.fig {
  margin: 0; background-color: var(--fig-bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px;
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 16px 16px; background-position: -1px -1px; display: flex; flex-direction: column; align-items: center; min-width: 200px; max-width: 380px; }
.fig .gd { max-height: 300px; width: auto; }
.fig.err { color: #b91c1c; font-size: 13px; }
.legend { display: flex; gap: 12px; font-size: 12.5px; color: var(--ink3); margin-top: 6px; }
.lg i { display: inline-block; width: 14px; height: 4px; border-radius: 2px; margin-inline-end: 5px; vertical-align: middle; }
.lg-given i { background: var(--g-given); }
.lg-concl i { background: var(--g-concl); }
.lg-hl i { background: var(--g-hl); }
.card-f { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); }
.tags-l { font-size: 12.5px; color: var(--ink3); margin-inline-end: 2px; }

a.concept {
  color: var(--concept); text-decoration: none; font-weight: 600;
  background: var(--concept-bg); border-radius: 6px; padding: 0 4px; margin: 0 -1px;
  box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--concept) 35%, transparent);
  cursor: pointer; transition: background .15s;
}
a.concept:hover, a.concept[aria-expanded="true"] { background: color-mix(in srgb, var(--concept) 22%, var(--panel)); }
a.itemlink { color: var(--accent); font-weight: 500; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }

/* ============ chips ============ */
.chip {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
  border: 1px solid var(--line2); background: var(--panel); color: var(--ink);
  border-radius: 999px; padding: 5px 12px; font-size: 14.5px; line-height: 1.3; cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s, transform .08s;
  user-select: none; white-space: nowrap;
}
.chip:hover { border-color: var(--accent); }
.chip:active { transform: scale(.97); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
/* no shared items with the current selection: still clickable, so it keeps readable contrast */
.chip.dim { color: var(--ink3); border-style: dashed; background: transparent; }
.chip.sm { font-size: 12.5px; padding: 2px 9px; }
.chip .cnt { font-size: 11.5px; color: var(--ink3); font-variant-numeric: tabular-nums; }
.chip.on .cnt { color: inherit; opacity: .9; }
.chip svg { width: 18px; height: 18px; flex: none; }
.chip svg path, .chip svg circle { fill: color-mix(in srgb, currentColor 12%, transparent); stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }

/* ============ preview page (tools/preview.html) ============ */
.preview-wrap { max-width: 980px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }

@media (max-width: 720px) {
  .card { padding: 14px 14px 10px; }
  .card-b { grid-template-columns: minmax(0, 1fr); }
  /* long chains such as ∢A + ∢B = ∢B + ∢C = … may wrap at their spaces instead of widening the page */
  .m { white-space: normal; max-width: 100%; }
  .fig { max-width: 100%; min-width: 0; }
  .title { font-size: 17px; }
  .stmt { font-size: 16px; }
}
