/* --- Syntax highlighting: Monokai Light + Monokai Dark ---
 *
 * Light = darkened-Monokai variant (dark hues on light bg for readability);
 * Dark = classic Monokai. YAML is what most of this site's code blocks are,
 * so the string and key colours are the ones worth checking after an edit.
 */

:root,
[data-md-color-scheme="default"] {
  --md-code-fg-color: #272822;
  --md-code-bg-color: #fafafa;

  --md-code-hl-keyword-color:     #d11f72;   /* darkened pink */
  --md-code-hl-string-color:      #998800;   /* mustard yellow */
  --md-code-hl-number-color:      #6f42c1;   /* purple */
  --md-code-hl-function-color:    #4d8d04;   /* green */
  --md-code-hl-comment-color:     #75715e;   /* olive-gray */
  --md-code-hl-name-color:        #272822;   /* default text */
  --md-code-hl-operator-color:    #d11f72;   /* pink */
  --md-code-hl-punctuation-color: #272822;
  --md-code-hl-constant-color:    #6f42c1;   /* purple — None, True, False */
  --md-code-hl-special-color:     #4d8d04;   /* green — decorators */
  --md-code-hl-variable-color:    #d35400;   /* burnt orange */
  --md-code-hl-generic-color:     #272822;
}

[data-md-color-scheme="slate"] {
  --md-code-fg-color: #f8f8f2;
  /* Derived from slate body bg hsla(var(--md-hue), 15%, 14%, 1):
     same hue, less saturated (6%), brighter (18%). Subtle slate hint, mostly gray. */
  --md-code-bg-color: hsla(var(--md-hue), 6%, 18%, 1);

  --md-code-hl-keyword-color:     #f92672;   /* hot pink */
  --md-code-hl-string-color:      #e6db74;   /* yellow */
  --md-code-hl-number-color:      #ae81ff;   /* purple */
  --md-code-hl-function-color:    #a6e22e;   /* green */
  --md-code-hl-comment-color:     #75715e;   /* olive-gray */
  --md-code-hl-name-color:        #f8f8f2;   /* default text */
  --md-code-hl-operator-color:    #f92672;   /* pink */
  --md-code-hl-punctuation-color: #f8f8f2;
  --md-code-hl-constant-color:    #ae81ff;   /* purple — None, True, False */
  --md-code-hl-special-color:     #a6e22e;   /* green — decorators */
  --md-code-hl-variable-color:    #fd971f;   /* orange */
  --md-code-hl-generic-color:     #f8f8f2;
}

/* --- Custom palette: soft dark slate primary + sky accent --- */

:root,
[data-md-color-primary="custom"] {
  --md-primary-fg-color: #334155;          /* slate-700 — soft dark header */
  --md-primary-fg-color--light: #475569;   /* slate-600 */
  --md-primary-fg-color--dark: #1e293b;    /* slate-800 — hover/active */
  --md-primary-bg-color: #ffffff;
  --md-primary-bg-color--light: #ffffffb3;
}

/* Light-mode accent: deeper sky for contrast on white */
[data-md-color-accent="custom"] {
  --md-accent-fg-color: #0284c7;           /* sky-600 */
  --md-accent-fg-color--transparent: rgba(2, 132, 199, 0.1);
  --md-accent-bg-color: #ffffff;
  --md-accent-bg-color--light: #ffffffb3;
}

/* Dark-mode accent: brighter sky for contrast on slate background */
[data-md-color-scheme="slate"][data-md-color-accent="custom"] {
  --md-accent-fg-color: #38bdf8;           /* sky-400 — brighter for dark bg */
  --md-accent-fg-color--transparent: rgba(56, 189, 248, 0.15);
}

/* Light-mode resting link: brighter than the accent for prominence.
   Hover keeps the accent (sky-600) for darken-on-hover affordance. */
.md-typeset a {
  color: #0284c7;                          /* sky-600 */
}

.md-typeset a:hover {
  color: #0ea5e9;                          /* sky-500 — brighten on hover */
}

[data-md-color-scheme="slate"] .md-typeset a {
  color: #38bdf8;                          /* sky-400 */
}

[data-md-color-scheme="slate"] .md-typeset a:hover {
  color: #7dd3fc;                          /* sky-300 */
}

/* TOC + nav active item: Material binds .md-nav__link--active to
   --md-typeset-a-color, which defaults to --md-primary-fg-color (slate-700).
   That makes the selected item near-invisible (slate-on-white in light,
   slate-on-dark in dark). Re-bind to our sky link colors. */
:root,
[data-md-color-scheme="default"] {
  --md-typeset-a-color: #0284c7;           /* sky-600 — matches link color */
}

[data-md-color-scheme="slate"] {
  --md-typeset-a-color: #38bdf8;           /* sky-400 — matches link color */
}

/* macOS-style nav items (left sidebar + right TOC): rounded pill on hover and
   active, no harsh borders. */
.md-nav__link {
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  margin: 0.05rem -0.5rem;
  transition: background 100ms, color 100ms;
}

.md-nav__link:hover {
  background: rgba(2, 132, 199, 0.07);     /* sky-600 tint */
  color: var(--md-typeset-a-color);
}

[data-md-color-scheme="slate"] .md-nav__link:hover {
  background: rgba(56, 189, 248, 0.10);    /* sky-400 tint */
}

.md-nav__link--active {
  background: rgba(2, 132, 199, 0.10);
  font-weight: 500;
}

[data-md-color-scheme="slate"] .md-nav__link--active {
  background: rgba(56, 189, 248, 0.14);
}

/* Material fades .md-nav__link--passed (already-scrolled-past TOC items + the
   previous nav page) to --md-default-fg-color--light, which in slate is 56%
   opacity → unreadable. Keep some fade but make it legible. */
.md-nav__link--passed,
.md-nav__link--passed code {
  color: var(--md-default-fg-color);
  opacity: 0.85;
}

/* --- Layout: wider content, denser sidebars --- */

:root {
  --md-grid-max-width: 80rem;  /* default 61rem — the gallery's construct matrix
                                  and the benchmark tables are both wide */
}

.md-grid {
  max-width: var(--md-grid-max-width);
}

/* Narrower sidebars — defaults are 12.1rem each.
   Both kept visible (no toc.integrate) so the per-page TOC stays on the right. */
.md-sidebar--primary {
  width: 11rem;
}

.md-sidebar--secondary {
  width: 10rem;
}

/* Tighter heading spacing site-wide */
.md-typeset h1 {
  margin: 0 0 0.5em;
  font-weight: 600;
}

.md-typeset h2 {
  margin: 0.8em 0 0.3em;
}

.md-typeset h3 {
  margin: 0.6em 0 0.2em;
}

.md-typeset h4 {
  margin: 0.5em 0 0.15em;
}

/* Material defaults to 0.85em on code blocks, which is hard to scan for YAML
   with meaningful indentation. Bump it; leave inline `code` at default so it
   still stands out mid-sentence. */
.md-typeset pre > code,
.md-typeset .highlight pre {
  font-size: 0.92em;
}

/* Code fences get a sky left stripe — enough to separate a model's YAML from
   the prose around it without a box. */
.md-typeset .highlight {
  border-left: 2px solid #0284c7;
  border-radius: 0 2px 2px 0;
  transition: border-left-color 150ms, box-shadow 150ms;
}

.md-typeset .highlight:hover {
  border-left-color: #0ea5e9;            /* sky-500 */
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

[data-md-color-scheme="slate"] .md-typeset .highlight {
  border-left-color: #38bdf8;            /* sky-400 — brighter for dark bg */
}

[data-md-color-scheme="slate"] .md-typeset .highlight:hover {
  border-left-color: #7dd3fc;            /* sky-300 */
  box-shadow: 0 1px 4px rgba(255, 255, 255, 0.06);
}

/* Mermaid renders onto its own white-ish canvas; the stripe reads as a bug
   there, and the diagrams set their own node colours. */
.md-typeset .mermaid {
  border-left: none;
}

/* --- Mermaid in dark mode ---
 *
 * The diagrams colour some nodes through `classDef`, e.g.
 * `classDef stream fill:#f0f7f0,stroke:#3a7d44,color:#111`. In slate that came
 * apart and the labels disappeared — near-white text on a near-white fill.
 *
 * The two halves of that declaration do not survive the same way, and neither
 * can be fixed by overriding a rule:
 *
 *   fill  — mermaid emits `#<generated-id> .stream > * { fill: … !important }`.
 *           An ID *and* `!important`: nothing we can write outranks it, so the
 *           pale fills are fixed in both schemes.
 *   color — never applies at all. It reaches the text only by inheritance,
 *           while Material styles `.nodeLabel` directly, and a directly-applied
 *           value beats an inherited one at any specificity. The label colour
 *           is always Material's, which is light in slate. Hence the clash.
 *
 * So the fills win and the labels follow the scheme — the one combination that
 * cannot work. Rather than fight it, render the whole diagram the way its
 * colours were chosen for: light, on its own card, in both schemes.
 *
 * This is variable shadowing, not a specificity contest. Material defines each
 * of these as `var(--md-mermaid-…)` and mermaid's generated CSS *reads* them
 * inside the SVG; redefining them on the container is what those `var()` calls
 * resolve against. The values below are what the default scheme computes.
 */
[data-md-color-scheme="slate"] .md-typeset .mermaid {
  --md-mermaid-label-fg-color: #272822;          /* = default's --md-code-fg-color */
  --md-mermaid-edge-color: #272822;
  --md-mermaid-node-bg-color: rgba(2, 132, 199, 0.1);
  --md-mermaid-node-fg-color: #0284c7;           /* sky-600, our light accent */
  --md-mermaid-label-bg-color: #ffffff;

  background: #ffffff;
  border-radius: 4px;
  padding: 0.8rem 0.4rem;
}

/* --- Landing page --- */

/* Centered hero: tagline, badges, CTA buttons */
.md-typeset .hero {
  max-width: 42rem;
  margin: 2rem auto 1rem;
  text-align: center;
}

.md-typeset .hero h1 {
  margin-bottom: 0.6rem;
  font-size: 2.6rem;
  font-weight: 700;
}

.md-typeset .hero p {
  font-size: 1.1rem;
  color: var(--md-default-fg-color--light);
}

/* Badge row: tight, centered, no paragraph spacing */
.md-typeset .hero p:has(img) {
  margin: 0.6rem 0 1.4rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  justify-content: center;
}

.md-typeset .hero img {
  margin: 0;
}

/* Landing-page content (cards, code, etc.) — narrower than full grid */
.md-typeset .landing {
  max-width: 64rem;
  margin: 0 auto;
}

.md-typeset .landing h2 {
  text-align: center;
  margin: 2.4rem 0 1rem;
}

/* Button row spacing — scoped to the landing hero where button rows appear */
.md-typeset .hero .md-button + .md-button {
  margin-left: 0.5rem;
}

/* Grid card hover lift — small polish */
.md-typeset .grid.cards > ul > li,
.md-typeset .grid > .card {
  transition: border-color 125ms, box-shadow 125ms;
}

.md-typeset .grid.cards > ul > li:hover,
.md-typeset .grid > .card:hover {
  border-color: var(--md-accent-fg-color);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* --- Anchor target highlight ---
 * When the URL has a #hash, the matching element gets :target. Flash the
 * background once on arrival so it's obvious where the page jumped to —
 * SPEC.md and ARCHITECTURE.md are long, and most arrivals are deep links. */
.md-content :target {
  animation: target-flash 1.5s ease-in-out;
  scroll-margin-top: 4rem;
}

@keyframes target-flash {
  0%, 100% {
    background-color: transparent;
    box-shadow: -0.4rem 0 0 0 transparent;
  }
  25%, 65% {
    background-color: rgba(2, 132, 199, 0.35);    /* sky-600 — matches accent */
    box-shadow: -0.4rem 0 0 0 rgba(2, 132, 199, 0.75);
  }
  45% {
    background-color: transparent;
    box-shadow: -0.4rem 0 0 0 transparent;
  }
}

[data-md-color-scheme="slate"] .md-content :target {
  animation: target-flash-dark 1.5s ease-in-out;
}

@keyframes target-flash-dark {
  0%, 100% {
    background-color: transparent;
    box-shadow: -0.4rem 0 0 0 transparent;
  }
  25%, 65% {
    background-color: rgba(56, 189, 248, 0.22);   /* sky-400 — matches dark accent */
    box-shadow: -0.4rem 0 0 0 rgba(56, 189, 248, 0.65);
  }
  45% {
    background-color: transparent;
    box-shadow: -0.4rem 0 0 0 transparent;
  }
}
