/*
 * SPDX-FileCopyrightText: mathspec contributors
 *
 * SPDX-License-Identifier: MIT
 */

/* --- 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);
}

/* The active entry in the right-hand table of contents, and a `code` span
   inside it, are bound to --md-typeset-a-color, which defaults to
   --md-primary-fg-color (slate-700). In slate that is slate-700 on a near-black
   chip, measured at rgb(51,65,85) on rgb(43,45,49) — unreadable. Re-bind to the
   sky link colours. The left sidebar needs nothing: the theme colours its
   active item with the accent already. */
: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 */
}

/* 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 */
}

/* --- 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;
}

/* Benefit cards: the README bullet's bold lead-in is the card's title, and its
 * one link covers the whole card, since the README cannot carry card markup. */
.md-typeset .landing .grid.cards {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
}

.md-typeset .landing .grid.cards > ul > li {
  position: relative;
  color: var(--md-default-fg-color--light);
}

.md-typeset .landing .grid.cards > ul > li > strong:first-child {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--md-default-fg-color);
  font-size: 0.9rem;
}

.md-typeset .landing .grid.cards > ul > li > a:last-child {
  display: block;
  margin-top: 0.6rem;
  font-weight: 700;
}

.md-typeset .landing .grid.cards > ul > li > a:last-child::after {
  content: "";
  position: absolute;
  inset: 0;
}

/* A card's icon is chosen by where its link points, so reordering the README
 * list cannot move an icon onto another card. */
.md-typeset .landing .grid.cards > ul > li::before {
  display: block;
  width: 1.6rem;
  height: 1.6rem;
  margin-bottom: 0.6rem;
  background-color: var(--md-accent-fg-color);
  mask: center / contain no-repeat;
}

.md-typeset .landing .grid.cards > ul > li:has(> a[href$="/reference/language/errors/"])::before {
  content: "";
  mask-image: url("icons/checklist.svg");
}

.md-typeset .landing .grid.cards > ul > li:has(> a[href$="/reference/typeset/"])::before {
  content: "";
  mask-image: url("icons/sigma.svg");
}

.md-typeset .landing .grid.cards > ul > li:has(> a[href$="/reference/program/"])::before {
  content: "";
  mask-image: url("icons/puzzle.svg");
}

.md-typeset .landing .grid.cards > ul > li:has(> a[href$="/examples/pypsa/"])::before {
  content: "";
  mask-image: url("icons/transmission-tower.svg");
}

/* --- 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 — the
 * language reference and the ceiling 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;
  }
}

/* --- Wide display math --------------------------------------------------
 * The typesetter does not line-break, and that is deliberate: where a model's
 * constraint wraps is a formatting decision this project does not make for the
 * reader. But a wide equation still has to be *reachable*. Material gives
 * `mjx-container` no overflow handling of its own — only `margin: 0` — so on a
 * narrow column the right-hand side was clipped with nothing to scroll: on the
 * notation reference at phone width, 32 of 55 equations ended mid-`∀`.
 *
 * So this is the wide-content rule already applied to tables, applied to the
 * one other thing on this site that is wider than its column. The wrapper is
 * arithmatex's own, and a block; inline math keeps the `span` and wraps with
 * the sentence around it.
 */
.md-typeset div.arithmatex {
  overflow-x: auto;
  overflow-y: hidden;
  /* Room under the equation so the scrollbar does not sit on a subscript. */
  padding-bottom: 0.4rem;
}

/* Centred while it fits, left-aligned once it does not. Centring an
   overflowing box pushes its left edge out of reach — `scrollLeft` stops at 0
   — so the equation would lose its opening rather than its tail. */
.md-typeset div.arithmatex > mjx-container {
  display: inline-block;
  min-width: 100%;
}

/* --- Python API --- */

/* API indentation. */
div.doc-contents:not(.first) {
  padding-left: 25px;
  border-left: 4px solid rgba(230, 230, 230);
}

/* Allow tables to be horizontally scrollable. The notation reference and the
   ten-rules table are both wider than the column on a narrow screen. */
.md-typeset__scrollwrap {
  overflow-x: auto;
}
