/* =============================================================
   LightningLM Cookbook — shared design tokens & primitives
   Every widget MUST link this file and use only these tokens.
   Do not introduce ad-hoc colors, fonts, radii, or animations.
   ============================================================= */

/* ---------- Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=JetBrains+Mono:ital,wght@0,100..800;1,100..800&display=swap');

/* ---------- Tokens ---------- */
:root {
  /* Base palette (re-themed to Axiom LMS LIGHT) */
  --bg:           #FFFFFF;
  --surface:      #FFFFFF;
  --surface-alt:  #FAFAFA;
  --ink:          #111111;
  --ink-body:     #1A1A1A;
  --ink-muted:    #555555;
  --rule:         #E8E8E8;
  --rule-strong:  #D0D0D0;

  /* Accent (Axiom blue) */
  --accent:       #2563EB;
  --accent-soft:  rgba(37, 99, 235, 0.08);
  --accent-ink:   #1D4ED8;
  --highlight:    #FEF3C7; /* warm amber wash, pairs with blue */

  /* Chart series (use in numerical order; do not reassign).
     UI-only — the chart-stage paper-identity colors live in figures.js. */
  --series-1:     #2563EB; /* blue (matches accent) */
  --series-2:     #DC2626; /* red */
  --series-3:     #16A34A; /* green */
  --series-4:     #7C3AED; /* purple */
  --series-5:     #D97706; /* amber */
  --series-6:     #0891B2; /* teal */

  /* Typography */
  --font-sans:  'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-serif: 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, 'Times New Roman', serif;
  --font-mono:  'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;

  /* Type scale (bumped one step for editorial weight) */
  --fs-xs:   13px;
  --fs-sm:   14px;
  --fs-base: 16px;
  --fs-md:   18px;
  --fs-lg:   22px;
  --fs-xl:   30px;
  --fs-2xl:  40px;

  /* Editorial tracking (mirrors Axiom tokens) */
  --tracking-tight:    -0.025em;
  --tracking-headline: -0.035em;
  --tracking-display:  -0.04em;

  /* Spacing scale */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  24px;
  --sp-6:  32px;
  --sp-7:  48px;
  --sp-8:  64px;

  /* Radii (rounder per Axiom) */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  /* Shadow (Axiom layered cool-blue-tinged) */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.03),
               0 1px 3px 0 rgba(0, 20, 60, 0.02);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05),
               0 2px 4px -2px rgba(0, 20, 60, 0.03);
  --shadow-lg: 0 10px 20px -4px rgba(0, 0, 0, 0.07),
               0 4px 8px -4px rgba(0, 20, 60, 0.03);

  /* Motion */
  --dur-fast:  140ms;
  --dur-base:  240ms;
  --dur-slow:  400ms;
  --ease:      cubic-bezier(.2,.7,.2,1);

  /* Layout */
  --content-max: 720px;
  --widget-max:  960px;
}

/* ---------- Reset (light) ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink-body);
  font-family: var(--font-serif);
  font-size: var(--fs-md);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg, canvas { display: block; max-width: 100%; }
button { font: inherit; cursor: pointer; }
button:focus-visible, [role="button"]:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Typography ---------- */
h1, h2, h3, h4 {
  font-family: var(--font-serif);
  color: var(--ink);
  font-weight: 700;
  line-height: 1.2;
  margin: 0 0 var(--sp-3);
  text-rendering: optimizeLegibility;
}
h1 { font-size: var(--fs-2xl); letter-spacing: var(--tracking-display); font-weight: 800; line-height: 1.1; }
h2 { font-size: var(--fs-xl);  letter-spacing: var(--tracking-headline); font-weight: 700; }
h3 { font-size: var(--fs-lg);  letter-spacing: var(--tracking-tight);    font-weight: 700; }
h4 { font-size: var(--fs-md);  font-weight: 700; }
p  { margin: 0 0 var(--sp-4); }
a  { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-soft); }
a:hover { border-bottom-color: var(--accent); color: var(--accent-ink); }
code, kbd, samp { font-family: var(--font-mono); font-size: 0.92em; }
code { background: var(--accent-soft); color: var(--accent-ink); padding: 1px 6px; border-radius: var(--r-sm); }
kbd {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  padding: 1px 6px;
  border-radius: var(--r-sm);
  color: var(--ink);
  font-size: var(--fs-xs);
}

/* ---------- Page layout ---------- */
.page {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--sp-7) var(--sp-5);
}
.page--wide { max-width: var(--widget-max); }

/* ---------- Widget shell ---------- */
.widget {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
  margin: var(--sp-5) auto;
  max-width: var(--widget-max);
  font-family: var(--font-sans);
  color: var(--ink-body);
  position: relative;
}
.widget__header { margin-bottom: var(--sp-4); }
.widget__eyebrow {
  font-family: var(--font-sans);
  font-size: var(--fs-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: var(--sp-1);
}
.widget__title {
  font-family: var(--font-serif);
  font-size: var(--fs-lg);
  color: var(--ink);
  margin: 0 0 var(--sp-1);
}
.widget__subtitle {
  font-family: var(--font-serif);
  font-size: var(--fs-base);
  color: var(--ink-muted);
  margin: 0;
  font-style: italic;
}
.widget__canvas {
  background: var(--surface-alt);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  margin: var(--sp-4) 0;
  min-height: 220px;
}
.widget__controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
  margin-bottom: var(--sp-3);
}
.widget__footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-4);
  margin-top: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--rule);
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
}
.widget__hint {
  color: var(--ink-muted);
}
.widget__hint::before {
  content: 'Try: ';
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Controls ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--surface-alt);
  color: var(--ink-body);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  padding: 6px 12px;
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  font-weight: 500;
  transition: background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn--primary:hover { background: var(--accent-ink); color: #fff; }
.btn--ghost { background: transparent; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  background: var(--surface-alt);
  color: var(--ink-body);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 4px 10px;
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  user-select: none;
  transition: background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
}
.chip:hover { background: var(--accent-soft); border-color: var(--accent); }
.chip[aria-pressed="true"], .chip--selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--rule);
  border-radius: 2px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  cursor: pointer;
}

.label {
  font-family: var(--font-sans);
  font-size: var(--fs-xs);
  color: var(--ink-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.readout {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  padding: 2px 8px;
}

/* ---------- Axes (D3 + SVG) ---------- */
.axis path,
.axis line {
  stroke: var(--rule-strong);
  shape-rendering: crispEdges;
  fill: none;
}
.axis text {
  font-family: var(--font-sans);
  font-size: var(--fs-xs);
  fill: var(--ink-muted);
}
.gridline {
  stroke: var(--rule);
  stroke-dasharray: 2 3;
}

/* ---------- Tooltip ---------- */
.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: #fff;
  font-family: var(--font-sans);
  font-size: var(--fs-xs);
  padding: 6px 10px;
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity var(--dur-fast) var(--ease);
  white-space: nowrap;
  z-index: 10;
}
.tooltip--visible { opacity: 1; }

/* ---------- Math (KaTeX) ---------- */
.katex { font-size: 1em; color: var(--ink); }

/* ---------- Utility ---------- */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.flex { display: flex; }
.flex-col { flex-direction: column; }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.muted { color: var(--ink-muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
