/* ── Mike Sans (display font, matches the logo) ───────────────────────────
   Self-hosted under the same paid FType Studio "Studio Bundle" license as
   web-static's copy (see source/_static/fonts/README.md); only the 4
   weights web-static ships (400/500/600/700, pre-converted to WOFF2) are
   reused here, same as that site. */
@font-face {
  font-family: "Mike Sans";
  src: url("fonts/mike-sans-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Mike Sans";
  src: url("fonts/mike-sans-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Mike Sans";
  src: url("fonts/mike-sans-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Mike Sans";
  src: url("fonts/mike-sans-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ── Website brand tokens ─────────────────────────────────────────────────
   Mirrors the design tokens from web-static's app/scss/_pico-overrides.scss
   (Manrope / JetBrains Mono, warm cream palette, USyd ochre accent), mapped
   onto pydata-sphinx-theme's --pst-color-* / --pst-font-family-* variables
   so theme components (admonitions, buttons, TOC highlighting, search,
   copy button) pick the palette up automatically. Google Fonts is loaded
   as a CSS entry in conf.py's html_css_files, same as the site's <link>. */

:root,
html[data-theme="light"] {
  /* Fonts */
  --pst-font-family-base: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --pst-font-family-heading: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --pst-font-family-monospace: "JetBrains Mono", "Fira Code", Menlo, Monaco, Consolas, "Courier New", monospace;
  /* Display font (issue #59): web-static's --mg-font-serif, used for the
     header title and title-page title, matching the logo's lettering.
     Falls back to the heading font if it fails to load. */
  --mg-font-serif: "Mike Sans", var(--pst-font-family-heading);

  /* Brand accent */
  --mg-ochre: #B63A1D;
  --mg-ochre-hover: #8F2E17;
  /* Sampled from the Magma logo's triangle/chevrons (MagmaLogoOfficial.png) */
  --mg-logo-red: #A93E28;

  /* Secondary accents, matching web-static's .cit-card type-colour scheme
     (references.css uses these for citation-type badges/accents) */
  --mg-navy: #1B355E;
  --mg-purple: #7C3AED;
  --mg-teal: #0F766E;
  --mg-amber: #D97706;

  /* Backgrounds (warm cream palette) */
  --pst-color-background: #F5F0EA;
  --pst-color-on-background: #FAF7F4;
  --pst-color-surface: #EDE7DF;

  /* Text */
  --pst-color-text-base: #424242;
  --pst-color-text-muted: #706A66;
  --pst-color-heading: #0A0A0A;
  /* sphinx-book-theme colors h1-h5/captions via this variable instead of
     --pst-color-heading (see _typography.scss / _sidebar-secondary.scss) */
  --pst-color-muted: #0A0A0A;

  /* Borders */
  --pst-color-border: #DDD5CC;
  --pst-color-border-muted: #DDD5CC;

  /* Accent / links */
  --pst-color-primary: var(--mg-ochre);
  --pst-color-primary-bg: rgba(230, 71, 37, 0.12);
  --pst-color-secondary: var(--mg-ochre-hover);
  --pst-color-secondary-bg: rgba(200, 63, 30, 0.12);
  --pst-color-link: var(--mg-ochre);
  --pst-color-link-hover: var(--mg-ochre-hover);
  /* Muted (not ochre) so plain inline code doesn't read as a link; theme
     default here is a leftover purple (#912583) unrelated to the brand. */
  --pst-color-inline-code: var(--pst-color-text-muted);
  --pst-color-inline-code-links: var(--mg-ochre);

  /* Keyboard focus rings (search box, nav links, buttons, cards, copy
     button, toctree toggles): theme default here is a leftover magenta
     (#c132af) unrelated to the brand. */
  --pst-color-accent: var(--mg-ochre);
  --pst-color-accent-bg: var(--pst-color-primary-bg);

  /* Match the main Magma website's compact header. */
  --pst-header-height: 60px;
}

html[data-theme="dark"] {
  --pst-color-background: #141210;
  --pst-color-on-background: #1e1b18;
  --pst-color-surface: #272420;

  --pst-color-text-base: #e8e3de;
  --pst-color-text-muted: #8c8680;
  --pst-color-heading: #f5f0ea;
  --pst-color-muted: #f5f0ea;

  --pst-color-border: #3a3530;
  --pst-color-border-muted: #3a3530;

  --mg-ochre: #F06A4D;
  --mg-ochre-hover: #FF927A;
  --mg-logo-red: #F06A4D;
  --pst-color-primary: var(--mg-ochre);
  --pst-color-primary-bg: rgba(230, 71, 37, 0.18);
  --pst-color-secondary: var(--mg-ochre-hover);
  --pst-color-secondary-bg: rgba(200, 63, 30, 0.18);
  --pst-color-link: var(--mg-ochre);
  --pst-color-link-hover: var(--mg-ochre-hover);
  --pst-color-inline-code: var(--pst-color-text-muted);
  --pst-color-inline-code-links: var(--mg-ochre);
  --pst-color-accent: var(--mg-ochre);
  --pst-color-accent-bg: var(--pst-color-primary-bg);

  /* Lightened for contrast against the dark cream background */
  --mg-navy: #7EB2F0;
  --mg-purple: #A78BFA;
  --mg-teal: #2DD4BF;
  --mg-amber: #FBBF24;
}

/* Website-style header: logo/title left, navigation centred, utilities right. */
.bd-header {
  background: var(--pst-color-background) !important;
  border-bottom: 1px solid var(--pst-color-border);
  box-shadow: none;
}

.bd-header .bd-header__inner {
  min-height: var(--pst-header-height);
  position: relative;
}

/* Keep the handbook identity against the browser edge, independently of the
   theme's centred page-width shell. */
.bd-header .bd-header__inner.bd-page-width {
  max-width: none;
}

.bd-header .navbar-brand.logo {
  gap: 0.65rem;
  padding: 0;
  text-decoration: none;
  transition: opacity 0.15s;
}

.bd-header .navbar-brand.logo:hover {
  opacity: 0.85;
  text-decoration: none;
}

.bd-header .navbar-brand.logo .logo__image {
  height: 32px;
  width: auto;
}

.bd-header .navbar-brand.logo .logo__title {
  color: var(--pst-color-heading);
  font-family: var(--mg-font-serif);
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
}

@media (min-width: 960px) {
  .bd-header .navbar-header-items {
    min-width: 0;
  }

  .bd-header .navbar-header-items__center {
    left: 50%;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
  }

  .bd-header .navbar-header-items__center ul.navbar-nav {
    gap: 1.5rem;
  }

  .bd-header .navbar-header-items__center ul.navbar-nav > li.nav-item {
    margin: 0;
  }

  /* Descendant (not direct-child) selector: the "Explore" item's .nav-link
     is a <summary> nested inside <details>, one level deeper than the plain
     <a class="nav-link"> siblings, so a > combinator here would miss it and
     leave it at the browser's default (larger) summary font size. */
  .bd-header .navbar-header-items__center ul.navbar-nav > li.nav-item .nav-link {
    color: var(--pst-color-text-base);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0;
    white-space: nowrap;
  }

  .bd-header .navbar-header-items__center ul.navbar-nav > li.nav-item .nav-link:hover {
    color: var(--mg-ochre);
  }

  .handbook-navbar-dropdown {
    position: relative;
  }

  .handbook-navbar-dropdown details > summary {
    align-items: center;
    cursor: pointer;
    display: flex;
    list-style: none;
  }

  .handbook-navbar-dropdown details > summary::-webkit-details-marker {
    display: none;
  }

  .handbook-navbar-dropdown details > summary::after {
    border-bottom: 1.5px solid currentColor;
    border-right: 1.5px solid currentColor;
    content: "";
    height: 6px;
    margin-left: 0.4rem;
    transform: translateY(-2px) rotate(45deg);
    transition: transform 0.15s;
    width: 6px;
  }

  .handbook-navbar-dropdown details[open] > summary::after {
    transform: translateY(2px) rotate(225deg);
  }

  .handbook-navbar-dropdown-menu {
    background: var(--pst-color-on-background);
    border: 1px solid var(--pst-color-border);
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.04), 0 12px 32px rgba(0, 0, 0, 0.1);
    left: 50%;
    min-width: 180px;
    padding: 0.4rem;
    position: absolute;
    top: calc(100% + 0.85rem);
    transform: translateX(-50%);
    z-index: 1000;
  }

  .handbook-navbar-dropdown-menu a {
    border-radius: 8px;
    color: var(--pst-color-text-base);
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.5rem 0.85rem;
    text-decoration: none;
    white-space: nowrap;
  }

  .handbook-navbar-dropdown-menu a:hover {
    background: var(--pst-color-surface);
    color: var(--mg-ochre);
  }

  .bd-header .navbar-header-items__end {
    flex-flow: row nowrap;
    margin-left: auto;
  }
}

/* Match web-static's compact, icon-only search and theme controls. */
.bd-header .search-button-field,
.bd-header .theme-switch-button {
  align-items: center;
  background: transparent;
  border: 1px solid var(--pst-color-border);
  border-radius: 10px;
  box-shadow: none;
  color: var(--pst-color-text-muted);
  display: inline-flex;
  flex-shrink: 0;
  height: 32px;
  justify-content: center;
  margin: 0;
  padding: 0;
  width: 32px;
}

.bd-header .search-button-field:hover,
.bd-header .theme-switch-button:hover {
  background: var(--pst-color-on-background);
  border-color: var(--pst-color-heading);
  color: var(--pst-color-heading);
}

.bd-header .search-button-field .search-button__default-text,
.bd-header .search-button-field .search-button__kbd-shortcut {
  display: none;
}

/* Anchor the handbook navigation to the browser's left edge on wide screens. */
@media (min-width: 960px) {
  .bd-container {
    justify-content: flex-start;
  }

  .bd-sidebar-primary {
    padding-top: 0.75rem;
  }

  .bd-sidebar-primary .sidebar-primary-items__start .sidebar-primary-item:first-of-type {
    padding-top: 0;
  }
}

body.left-sidebar-collapsed .bd-sidebar-primary {
  display: none !important;
}

@media (min-width: 960px) {
  .bd-header-article {
    position: relative;
  }

  body.left-sidebar-collapsed .bd-header-article .header-article-items__start {
    padding-left: 2rem;
  }
}

.left-sidebar-toggle {
  align-items: center;
  background: var(--pst-color-on-background);
  border: 1px solid var(--pst-color-border);
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  display: flex;
  height: 28px;
  justify-content: center;
  margin: 0;
  padding: 0;
  flex: 0 0 28px;
  transition: border-color 0.15s, background 0.15s;
  width: 28px;
}

.left-sidebar-toggle.is-inside {
  margin: 0 0 0.125rem auto;
  position: static;
}

.left-sidebar-toggle.is-outside {
  border-left: 0;
  border-radius: 0 8px 8px 0;
  left: 0;
  margin: 0;
  position: absolute;
  top: 0;
  z-index: 20;
}

.left-sidebar-toggle:hover {
  background: var(--pst-color-surface);
  border-color: var(--pst-color-primary);
}

.left-sidebar-toggle span {
  color: var(--pst-color-text-muted);
  font-size: 12px;
  pointer-events: none;
}

.left-sidebar-toggle:hover span {
  color: var(--pst-color-primary);
}

@media (max-width: 959.98px) {
  .left-sidebar-toggle {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .left-sidebar-toggle {
    transition: none;
  }
}

/* Headings: match the website's weight + tracking on h1-h3 */
h1, h2, h3 {
  font-family: var(--pst-font-family-heading);
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Reduced text spacing (issue #38): theme defaults are loose
   (line-height: 1.65, p margin-bottom: 1.15rem), leaving large gaps within
   and between paragraphs/text blocks. Tighten to a more compact reading
   density, scoped to the article body so sidebar/nav chrome is untouched. */
.bd-article-container {
  line-height: 1.35;
}

/* Paragraph gap (issue #53): 0.6rem still read as a much bigger jump than
   the tightened in-paragraph line gap above. Bring it down further so
   consecutive paragraphs feel like one reading rhythm. */
.bd-article-container p {
  margin-bottom: 0.5rem;
}

/* Card-like surfaces: bump toward the website's rounder card radius */
div.admonition,
.sd-card {
  border-radius: 10px;
}

/* Rows with a single grid-item-card (intro text, Preface): the grid still
   reserves a topic-card-width column, so center that lone card instead of
   leaving it pinned to the left. */
.index-solo-row .sd-row {
  justify-content: center;
}

/* Buttons / inputs: match the website's 8px control radius */
.btn,
.bd-search-button__click-hint,
input[type="search"],
.search-button-field {
  border-radius: 8px;
}

/* ── 404 page (issue #54) ─────────────────────────────────────────────────
   Mirrors web-static's app/scss/_404.scss (same class names), remapped from
   its --mg-* tokens onto this file's --pst-color-* / --mg-ochre equivalents.
   The real doctree title stays in the DOM (for the <title> tag and
   breadcrumb) but is hidden here since the raw-HTML block below supplies
   its own centered heading text. */
.bd-article-container:has(.e404-page) h1:first-of-type {
  display: none;
}

.e404-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--pst-header-height) - 4rem);
  padding: 4rem 2rem;
}

.e404-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 480px;
}

/* No "display" here: the theme-aware light/dark toggle rules in
   magma-parameter.css (.logo-light / .logo-dark) already set display on
   these classes, and this file loads after that one, so redeclaring
   display here (even to "block") would win the cascade and un-hide the
   inactive logo. */
.e404-logo-img {
  width: 160px;
  height: 160px;
  object-fit: contain;
  margin-bottom: 2rem;
}

.e404-code {
  font-size: clamp(3.5rem, 8vw, 5.5rem);
  font-weight: 600;
  line-height: 1;
  color: var(--mg-ochre);
  opacity: 0.18;
  margin: 0 0 0.5rem;
  user-select: none;
}

.e404-title {
  font-family: var(--pst-font-family-heading);
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--pst-color-heading);
  margin: 0 0 0.85rem;
  line-height: 1.2;
}

.e404-desc {
  font-size: 0.975rem;
  line-height: 1.7;
  color: var(--pst-color-text-muted);
  margin: 0 0 2rem;
}

.e404-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

.e404-btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.65rem 1.35rem;
  background: var(--mg-ochre);
  /* !important: pydata-sphinx-theme's global `a:visited { color:
     var(--pst-color-text-base) }` is more specific than a bare class
     selector, so once the homepage link has been visited the text would
     otherwise fall back to a muted grey instead of staying white. */
  color: #fff !important;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none !important;
  transition: opacity 0.15s, box-shadow 0.15s;
}

.e404-btn-primary:hover {
  opacity: 0.88;
  color: #fff !important;
  box-shadow: 0 4px 14px rgba(230, 70, 38, 0.3);
}

.e404-btn-ghost {
  display: inline-flex;
  align-items: center;
  padding: 0.65rem 1.35rem;
  border: 1px solid var(--pst-color-border);
  border-radius: 10px;
  background: var(--pst-color-surface);
  color: var(--pst-color-text-base);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none !important;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.e404-btn-ghost:hover {
  border-color: var(--mg-ochre);
  color: var(--mg-ochre);
  background: var(--pst-color-on-background);
}

/* ── Site footer (issue #58) ──────────────────────────────────────────────
   Ported from web-static's app/scss/_footer.scss, remapped from its --mg-*
   tokens onto this file's --pst-color-* equivalents. Those already flip
   for dark mode (see the html[data-theme="dark"] block above), so unlike
   the source stylesheet this needs no separate dark-mode override block. */
.site-footer {
  background: var(--pst-color-on-background);
  border-top: 1px solid var(--pst-color-border);
  margin-top: auto;
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 3.5rem 2rem 2.5rem;
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr 1fr;
  gap: 2.5rem;
}

@media (max-width: 900px) {
  .footer-inner {
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
  }
}

@media (max-width: 520px) {
  .footer-inner {
    grid-template-columns: 1fr;
    padding: 2.5rem 1.5rem 2rem;
  }
}

.footer-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.85rem;
}

.footer-logo-link {
  display: block;
  line-height: 0;
}

/* No "display" here for the same reason as .e404-logo-img: the
   .logo-light/.logo-dark toggle in magma-parameter.css already sets it,
   and this file loads after that one. */
.footer-logo-img {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.footer-desc {
  font-size: 0.85rem;
  color: var(--pst-color-text-muted);
  line-height: 1.65;
  margin: 0;
  max-width: 260px;
}

.footer-usyd {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--mg-ochre);
  text-decoration: none !important;
}

.footer-usyd svg {
  flex-shrink: 0;
}

.footer-usyd:hover {
  text-decoration: underline !important;
}

.footer-col {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
}

.footer-col-heading {
  font-family: var(--pst-font-family-base);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--pst-color-text-base);
  margin: 0 0 1rem;
}

.footer-links {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.footer-links li {
  list-style: none;
  padding: 0;
  margin: 0;
}

.footer-links a {
  font-size: 0.875rem;
  color: var(--pst-color-text-muted) !important;
  text-decoration: none !important;
  transition: color 0.15s;
}

.footer-links a:hover {
  color: var(--mg-ochre) !important;
}

.footer-bottom {
  border-top: 1px solid var(--pst-color-border);
  background: var(--pst-color-surface);
}

.footer-bottom-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

@media (max-width: 520px) {
  .footer-bottom-inner {
    padding: 1rem 1.5rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }
}

.footer-copyright,
.footer-built {
  font-size: 0.78rem;
  color: var(--pst-color-text-muted);
}
