/* ============================================================
   Blueprint Component Kit — kit/color-engine.css   (Phase 1)

   ONE seed in, the whole palette out. Set a single brand colour
   (--bp-brand) and this file derives the accent ramp, an
   auto-contrast on-accent, a brand-tinted neutral ramp, and a
   semantic family — in pure CSS, no JS, via OKLCH relative colour.

   Load order: contract.css  ->  THIS FILE  ->  themes/*.css
   Because it loads after contract.css, the derived colour tokens
   win over contract's neutral fallbacks. A theme then sets
   --bp-brand (and may PIN a couple of hand-sampled values to stay
   pixel-right). The arbitrary-hex input sets --bp-brand inline and
   lets every line below do the work.

   HONEST SCOPE. The four presets are hand-tuned. An arbitrary hex
   is a strong, accessible STARTING point, not a guarantee — OKLCH
   lightness is a good proxy for contrast, not a perfect one. Treat
   a brand-new client hex as 90% there, then eyeball.

   Requires a Chromium with relative-colour syntax (the kit already
   assumes bleeding-edge Chrome via corner-shape: squircle).
   ============================================================ */

/* Derivations are declared on EVERY element that can carry the seed:
   :root (the default), any themed stage (.bp-theme-*), and any element
   with an inline --bp-brand (the live hex input). This is required so
   each var(--bp-brand) resolves against the brand set on THAT element,
   not the one inherited from :root. Theme pins (literal strong/tint/fg
   in themes/*.css) load after this and still win. */
:root,
[class*="bp-theme-"],
[style*="--bp-brand"] {
  /* The single seed. A theme or the hex input overrides this.
     Default = the old contract accent, so a no-theme page is sane. */
  --bp-brand: #4b5563;

  /* ---- Accent ramp (derived; a preset may pin strong/tint) ---- */
  --bp-accent:        var(--bp-brand);
  --bp-accent-strong: oklch(from var(--bp-brand) clamp(.12, calc(l - .07), .92) c h);  /* darker: hover/press */
  --bp-accent-light:  oklch(from var(--bp-brand) clamp(.12, calc(l + .08), .97) c h);  /* lighter step */
  --bp-accent-tint:   oklch(from var(--bp-brand) .96 calc(c * .22) h);                  /* soft wash background */
  --bp-accent-tint-stroke: oklch(from var(--bp-brand) .88 calc(c * .35) h);            /* border on a tinted area */

  /* ---- Auto-contrast on-accent ----
     White text until the brand gets pale (L > .72), then black.
     The *-1000 turns the threshold into a hard step inside clamp;
     chroma 0 makes the result pure black or white. */
  --bp-accent-foreground: oklch(from var(--bp-brand)
                            clamp(0, calc((l - .72) * -1000), 1) 0 h);

  /* ---- Brand-tinted neutral ramp ----
     Fixed lightness steps, brand hue, a whisper of brand chroma.
     Warm brand -> warm greys; cool brand -> cool greys; a near-grey
     brand -> near-neutral greys. Multiplier stays low so text greys
     never read coloured. */
  --bp-gray-50:  oklch(from var(--bp-brand) .985 calc(c * .03) h);   /* lightest steps tint-down: green stays punchy at high L */
  --bp-gray-100: oklch(from var(--bp-brand) .965 calc(c * .035) h);
  --bp-gray-200: oklch(from var(--bp-brand) .925 calc(c * .06) h);
  --bp-gray-300: oklch(from var(--bp-brand) .875 calc(c * .06) h);
  --bp-gray-400: oklch(from var(--bp-brand) .740 calc(c * .05) h);
  --bp-gray-500: oklch(from var(--bp-brand) .600 calc(c * .05) h);
  --bp-gray-600: oklch(from var(--bp-brand) .480 calc(c * .04) h);
  --bp-gray-700: oklch(from var(--bp-brand) .380 calc(c * .04) h);
  --bp-gray-800: oklch(from var(--bp-brand) .280 calc(c * .03) h);
  --bp-gray-900: oklch(from var(--bp-brand) .190 calc(c * .03) h);
  --bp-gray-950: oklch(from var(--bp-brand) .130 calc(c * .02) h);

  /* ---- Semantic family — KEEP HUE, MATCH CHARACTER ----
     Hue is pinned per role (red / amber / green / blue). The brand's
     own chroma is borrowed (clamped to a usable band) so semantics
     read MUTED on a muted brand (book-cloth) and VIVID on a vivid
     brand (Heatmap), without ever hiding success on a green brand or
     danger on a red one. -fg is the text/icon on a solid fill;
     -tint is the soft alert-background wash. */

  /* success · green */
  --bp-success:      oklch(from var(--bp-brand) .62 clamp(.09, c, .16) 150);
  --bp-success-fg:   #ffffff;
  --bp-success-tint: oklch(from var(--bp-brand) .95 clamp(.02, calc(c * .3), .05) 150);

  /* warning · amber (dark text — amber is too light for white) */
  --bp-warning:      oklch(from var(--bp-brand) .76 clamp(.10, c, .17) 75);
  --bp-warning-fg:   oklch(from var(--bp-brand) .28 clamp(.03, calc(c * .4), .08) 75);
  --bp-warning-tint: oklch(from var(--bp-brand) .95 clamp(.02, calc(c * .3), .06) 75);

  /* danger · red  (separate from the legacy --bp-error field token) */
  --bp-danger:       oklch(from var(--bp-brand) .58 clamp(.11, c, .18) 27);
  --bp-danger-fg:    #ffffff;
  --bp-danger-tint:  oklch(from var(--bp-brand) .95 clamp(.02, calc(c * .3), .05) 27);

  /* info · blue */
  --bp-info:         oklch(from var(--bp-brand) .57 clamp(.10, c, .17) 250);
  --bp-info-fg:      #ffffff;
  --bp-info-tint:    oklch(from var(--bp-brand) .95 clamp(.02, calc(c * .3), .05) 250);
}
