/* GNOME theme for mdBook */

@view-transition { navigation: auto; }

:root {
  /* Adwaita palette */
  --rounded-corner: 12px;
  --blue1: rgb(153, 193, 241);
  --blue2: rgb(98, 160, 234);
  --blue3: rgb(53, 132, 228);
  --blue4: rgb(28, 113, 216);
  --blue5: rgb(26, 95, 180);
  --green1: rgb(143, 240, 164);
  --green2: rgb(87, 227, 137);
  --green3: rgb(51, 209, 122);
  --green4: rgb(46, 194, 126);
  --green5: rgb(38, 162, 105);
  --yellow1: rgb(249, 240, 107);
  --yellow2: rgb(248, 228, 92);
  --yellow3: rgb(246, 211, 45);
  --yellow4: rgb(245, 194, 17);
  --yellow5: rgb(229, 165, 10);
  --orange1: rgb(255, 190, 111);
  --orange2: rgb(255, 163, 72);
  --orange3: rgb(255, 120, 0);
  --orange4: rgb(230, 97, 0);
  --orange5: rgb(198, 70, 0);
  --red1: rgb(246, 97, 81);
  --red2: rgb(237, 51, 59);
  --red3: rgb(224, 27, 36);
  --red4: rgb(192, 28, 40);
  --red5: rgb(165, 29, 45);
  --purple1: rgb(220, 138, 221);
  --purple2: rgb(192, 97, 203);
  --purple3: rgb(145, 65, 172);
  --purple4: rgb(129, 61, 156);
  --purple5: rgb(97, 53, 131);
  --brown1: rgb(205, 171, 143);
  --brown2: rgb(181, 131, 90);
  --brown3: rgb(152, 106, 68);
  --brown4: rgb(134, 94, 60);
  --brown5: rgb(99, 69, 44);
  --light1: rgb(255, 255, 255);
  --light2: rgb(246, 245, 244);
  --light3: rgb(222, 221, 218);
  --light4: rgb(192, 191, 188);
  --light5: rgb(154, 153, 150);
  --dark1: rgb(119, 118, 123);
  --dark2: rgb(94, 92, 100);
  --dark3: rgb(61, 56, 70);
  --dark4: rgb(36, 31, 49);
  --dark5: rgb(0, 0, 0);

  /* Semantic variables — light mode */
  --sidebar-bg: var(--light2);
  --sidebar-fg: var(--dark3);
  --sidebar-active-bg: rgba(0, 0, 0, 0.06);
  --sidebar-spacer: var(--light3);
  --bg: var(--light1);
  --fg: var(--dark5);
  --links: var(--blue5);
  --link-underline: var(--blue1);
  --tocbg: var(--light2);
  --borders: var(--light3);
  --pagewidth: 78rem;
  --pagepad: 1.5rem;
  --content-max-width: none;
  --mono-font: 'Departure Mono', monospace;
  --code-font-size: 11px;
  --inline-code-color: var(--dark3);
  --code-bg: var(--light2);
  --code-fg: var(--dark3);
  --icons: var(--dark1);
  --icons-hover: var(--dark3);

  @media (prefers-color-scheme: dark) {
    --sidebar-bg: var(--dark5);
    --sidebar-fg: var(--light5);
    --sidebar-active-bg: rgba(255, 255, 255, 0.06);
    --sidebar-spacer: var(--dark3);
    --bg: var(--dark4);
    --fg: var(--light1);
    --links: var(--blue1);
    --link-underline: var(--blue5);
    --tocbg: var(--dark5);
    --borders: var(--dark3);
    --inline-code-color: var(--light3);
    --code-bg: var(--dark3);
    --code-fg: var(--light2);
    --icons: var(--light5);
    --icons-hover: var(--light1);
  }
}

/* Override mdBook theme class variables */
.light, .ayu, .coal, .navy, .rust,
html:not(.js) {
  --bg: var(--light1);
  --fg: var(--dark5);
  --sidebar-bg: var(--light2);
  --sidebar-fg: var(--dark3);
  --sidebar-non-existant: var(--light5);
  --sidebar-active: var(--blue5);
  --sidebar-spacer: var(--light3);
  --icons: var(--dark1);
  --icons-hover: var(--dark3);
  --links: var(--blue5);
  --inline-code-color: var(--dark3);
  --theme-popup-bg: var(--bg);
  --theme-hover: var(--sidebar-active-bg);
  --quote-bg: var(--light2);
  --quote-border: var(--blue3);
  --table-header-bg: var(--light2);
  --table-alternate-bg: var(--light2);
  --searchbar-border-color: var(--light3);
  --searchbar-bg: var(--light1);
  --searchbar-fg: var(--dark5);
  --searchresults-header-fg: var(--dark1);
  --searchresults-border-color: var(--light3);
  --searchresults-li-bg: var(--light2);
  --search-mark-bg: var(--blue1);
  --color-scheme: light;

  @media (prefers-color-scheme: dark) {
    --bg: var(--dark4);
    --fg: var(--light1);
    --sidebar-bg: var(--dark5);
    --sidebar-fg: var(--light5);
    --sidebar-non-existant: var(--dark1);
    --sidebar-active: var(--blue1);
    --sidebar-spacer: var(--dark3);
    --icons: var(--light5);
    --icons-hover: var(--light1);
    --links: var(--blue1);
    --inline-code-color: var(--light3);
    --theme-hover: var(--sidebar-active-bg);
    --quote-bg: var(--dark3);
    --quote-border: var(--blue5);
    --table-header-bg: var(--dark3);
    --table-alternate-bg: var(--dark3);
    --searchbar-border-color: var(--dark3);
    --searchbar-bg: var(--dark4);
    --searchbar-fg: var(--light1);
    --searchresults-header-fg: var(--light5);
    --searchresults-border-color: var(--dark3);
    --searchresults-li-bg: var(--dark3);
    --search-mark-bg: var(--blue5);
    --color-scheme: dark;
  }
}

/* Base typography */
html, body {
  font-family: InterVariable, sans-serif;
  -webkit-font-smoothing: antialiased;
  background-color: var(--bg);
  color: var(--fg);
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 800;
  color: var(--fg);
}

a {
  color: var(--links);
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  transition: text-decoration-color 0.2s ease-in-out;

  &:hover {
    text-decoration-color: var(--links);
  }
}

/* Sidebar */
.sidebar {
  background-color: var(--sidebar-bg);
  color: var(--sidebar-fg);
  z-index: 10;

  .section {
    padding-inline-start: 0 !important;
  }

  .part-title {
    padding-left: 22px;
  }

  .chapter li a {
    color: var(--sidebar-fg);
    border-radius: 6px;
    margin: 1px 12px;
    padding: 5px 10px;
    text-decoration: none;

    &:hover {
      background-color: rgba(0, 0, 0, 0.03);

      @media (prefers-color-scheme: dark) {
        background-color: rgba(255, 255, 255, 0.03);
      }
    }

    &.active {
      background-color: var(--sidebar-active-bg);
      color: var(--fg);
      font-weight: 600;
    }
  }
}

/* Content area */
.content {
  max-width: none !important;
  display: flex !important;
  flex-direction: column;
  align-items: center;
  padding: 0 var(--pagepad) 3rem !important;

  & main,
  & .nav-wrapper {
    width: 100%;
    max-width: var(--pagewidth) !important;
  }
}

/* Code blocks */
pre {
  background-color: var(--code-bg) !important;
  color: var(--code-fg) !important;
  border-radius: var(--rounded-corner);
  padding: 1rem !important;

  & > code,
  & > code .hljs {
    color: inherit !important;
    background: transparent !important;
  }
}

.light pre,
.coal pre,
.ayu pre,
.navy pre,
.rust pre {
  background-color: var(--code-bg) !important;
  color: var(--code-fg) !important;
  border-radius: var(--rounded-corner);
  padding: 1rem !important;
}

:not(pre) > code,
:not(pre) > .hljs,
:not(pre):not(a) > .hljs {
  background-color: var(--code-bg) !important;
  color: var(--inline-code-color) !important;
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

/* Hide theme selector */
#mdbook-theme-toggle,
#mdbook-theme-list {
  display: none !important;
}

/* GNOME inline SVG icons */
.gnome-icon {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  vertical-align: middle;
}

/* Menu bar */
.menu-bar a {
  color: inherit;
}

.menu-title {
  font-weight: 400 !important;
  font-size: inherit !important;
}

/* Navigation — matches GNOME Handbook Sphinx style */
.nav-wide-wrapper {
  display: none !important;
}

.nav-wrapper {
  font-size: 10pt;
  font-weight: 800;
  display: flex !important;
  flex-direction: row !important;
  align-items: stretch;
  justify-content: space-between;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--borders);

  @media (min-width: 700px) {
    font-size: 14pt;
  }
}

.previous,
.next {
  float: none !important;
}

.mobile-nav-chapters {
  display: flex !important;
  align-items: center;
  text-decoration: none !important;
  border-radius: 8px;
  padding: 8px 24px 8px 8px;
  transition: background-color 0.2s ease-in-out;
  color: var(--fg) !important;
  max-width: inherit;
  float: none !important;
  font-size: inherit !important;
  width: auto !important;
  background-color: transparent !important;

  &:hover {
    background-color: var(--tocbg) !important;

    & .nav-title {
      color: var(--links);
    }
  }

  &.next {
    padding: 8px 8px 8px 24px;

    &:only-child {
      margin-left: auto;
    }
  }

  @media (min-width: 700px) {
    border-radius: 24px;
    padding: 16px 48px 16px 16px;

    &.next {
      padding: 16px 16px 16px 48px;
    }
  }

  .nav-text {
    display: flex;
    flex-direction: column;
  }

  &.previous .nav-text {
    text-align: left;
  }

  &.next .nav-text {
    text-align: right;
  }

  .nav-label {
    font-size: 0.75em;
    font-weight: 600;
    color: var(--dark1);
  }

  .nav-title {
    color: var(--dark1);
  }

  .nav-icon {
    display: flex;
    align-items: center;

    & svg {
      width: 32px;
      height: 32px;
      color: var(--dark1);
    }
  }

  &.previous .nav-icon {
    margin-right: 16px;
  }

  &.next .nav-icon {
    margin-left: 16px;
  }
}

/* Print styles */
@media print {
  #mdbook-help-container,
  #mdbook-sidebar,
  .sidebar-resize-handle,
  #mdbook-menu-bar,
  #mdbook-menu-bar-hover-placeholder,
  #mdbook-search-wrapper,
  .nav-wrapper,
  .nav-wide-wrapper,
  .mobile-nav-chapters {
    display: none !important;
    height: 0 !important;
    overflow: hidden !important;
  }

  #mdbook-body-container {
    overflow: visible !important;
  }

  #mdbook-page-wrapper,
  .page-wrapper {
    transform: none !important;
    margin: 0 !important;
    margin-inline-start: 0 !important;
  }

  .page {
    margin: 0 !important;
    margin-block-start: 0 !important;
    padding: 0 !important;
  }

  .content {
    display: block !important;
    padding: 0 !important;
    max-width: 100% !important;

    & main {
      max-width: 100% !important;
    }
  }
}
