body, html {
  margin: 0;
  padding: 0;
}
body {
  font-family: sans-serif;
}

:root {
  --article-width: 50rem;
  --global-nav-height: 48px;
  --twisty-size: 1.1rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-color: #121212;
    --text-color: #f2f2f2;
    --nav-top-bg: #242424;
  }
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-color: white;
    --text-color: black;
    --nav-top-bg: #f2f2f2;
  }
}

body {
  background: var(--bg-color);
  color: var(--text-color);
}

h1 {
  max-width: var(--article-width);
  overflow: hidden ;
  text-overflow: ellipsis;
}

nav#nav-global {
  background-color: var(--nav-top-bg);
  height: var(--global-nav-height);
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;

  input#global-search {
    position: absolute;
    left: calc(50vw - var(--article-width) / 2);
    width: var(--article-width);
    top: 8px;
    height: calc(var(--global-nav-height) - 16px);
    border-radius: 5px;
    background: rgba(0,0,0,0.25);
    color: var(--text-color);
    border-width: 0px;
    padding: 0 1rem;
  }
  .avatar {
    font-size: 1.5rem;
    vertical-align: middle;
    position: absolute;
    right: 16px;
    top: 0px;
    line-height: var(--global-nav-height);
  }
}

/* Search functionality styles */
.search-results {
  position: absolute;
  top: calc(var(--global-nav-height) + 8px);
  left: calc(50vw - var(--article-width) / 2);
  width: var(--article-width);
  background: var(--bg-color);
  border: 1px solid var(--nav-top-bg);
  border-radius: 5px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  max-height: 400px;
  overflow-y: auto;
  z-index: 1001;
}

.search-results.hidden {
  display: none;
}

.search-result-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--nav-top-bg);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover,
.search-result-item.selected {
  background-color: var(--nav-top-bg);
}

.search-result-title {
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-color);
}

.search-result-path {
  font-size: 0.85em;
  color: var(--text-color);
  opacity: 0.7;
}

button.menu-button {
  color: var(--text-color);
  font-size: calc(var(--global-nav-height) / 2);
  line-height: calc(var(--global-nav-height) / 2);
  margin: calc(var(--global-nav-height) / 4);
  background: none;
  border: none;
  cursor: pointer;
}
button.menu-button:hover {
  opacity: 0.7;
}

nav#nav-main {
  position: fixed;
  top: calc(var(--global-nav-height) + 1rem);
  left: 1rem;
  max-width: calc(50vw - var(--article-width) / 2 - 2rem);
  max-height: calc(100vh - var(--global-nav-height) - 2rem);
  overflow-y: auto;

  ul {
    list-style: none;
    margin: 0 0 0 1rem;
    padding: 0;

    li {
      margin-bottom: 0.25rem;
      padding: 0;
      text-transform: capitalize;

      /* display: grid; */
      /* grid-template-columns: var(--twisty-size) 1fr; */

      > ul {
      max-height: 0;
      overflow: hidden;
      transition: max-height .3s ease;

      }

      .menu-twisty {
        cursor: pointer;
        display: inline-block;
        width: var(--twisty-size);
        text-align: center;
        margin-right: 0.5rem;
        transition: transform 0.3s ease;

        :hover {
          filter: brightness(1.3);
        }
      }
      .menu-no-twisty {
        display: inline-block;
        width: var(--twisty-size);
        text-align: center;
        margin-right: 0.25rem;
      }

      > a {
        text-decoration: none;        
      }

      .current-menu-item > a {
        color: aqua;
      }
    }
    li.expanded {
      > .menu-twisty {
        transform: rotate(90deg);
      }
      > ul {
      max-height: 100vh;
      }
    }
  }
}

/* Table of Contents - Right side navigation */
nav#nav-toc {
  position: fixed;
  top: calc(var(--global-nav-height) + 1rem);
  right: 1rem;
  max-width: calc(50vw - var(--article-width) / 2 - 2rem);
  max-height: calc(100vh - var(--global-nav-height) - 2rem);
  overflow-y: auto;
  z-index: 100;

  ul {
    list-style: none;
    margin: 0;
    padding: 0;

    li {
      margin-bottom: 0.25rem;
      padding: 0;

      > a {
        text-decoration: none;
        color: var(--text-color);
        opacity: 0.7;
        display: block;
        padding: 0.25rem 0.5rem;
        border-left: 2px solid transparent;
        transition: all 0.3s ease;
        font-size: 0.9rem;
      }

      > a:hover {
        opacity: 1;
        border-left-color: var(--text-color);
      }

      > a.active {
        opacity: 1;
        border-left-color: aqua;
        background-color: rgba(0, 255, 255, 0.1);
      }

      /* Indent nested headings */
      &.toc-h2 > a {
        padding-left: 1rem;
        font-size: 0.85rem;
      }
      
      &.toc-h3 > a {
        padding-left: 1.5rem;
        font-size: 0.8rem;
      }
    }
  }
}

article#main-content {
  width: var(--article-width);
  margin: calc(var(--global-nav-height) + 16px) auto 0 auto;
}

@media (max-width: 800px) {
  article#main-content {
    width: calc(100vw - 2rem);
    margin: calc(var(--global-nav-height) + 16px) 1rem 0 1rem;
  }
  h1 {
    font-size: 1.5rem;
  }
  nav#nav-toc {
    display: none !important;
  }
  nav#nav-main {
    display: none !important;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    max-width: none;
    background: var(--bg-color);
    z-index: 1000;
    overflow-y: auto;
    margin: 0;
    padding: 2rem 1rem;
  }
  nav#nav-main.active {
    display: block !important;
  }
  html {
    font-size: 18px;
    /* Prevents zoomed out appearance on mobile */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
}