:root {
  font-family:
    system-ui,
    segoe ui,
    Roboto,
    Helvetica,
    Arial,
    sans-serif,
    apple color emoji,
    segoe ui emoji;
  --sidebar-width: 12rem;
  --bg: white;
}

@media (prefers-color-scheme: dark) {
  :root {
    filter: invert(100%) hue-rotate(180deg) contrast(85%);
  }
}

body {
  margin: 0;
  background-color: var(--bg);
}

main {
  display: flex;
  --top-padding: 1.5rem;
}

article {
  width: 100%;
  font-weight: 320;
  line-height: 1.4;
  overflow-x: hidden;
  padding: 0 2rem;
  padding-top: var(--top-padding);
}

/* Navigation bar */

input#menu-control {
  display: none;
}

label#menu-button {
  cursor: pointer;
}

nav {
  #sidebar-title {
    margin-top: 0.53rem;
    margin-bottom: 1.4rem;
  }

  position: fixed;
  height: 100vh;
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  overflow-y: scroll;
  overflow-x: hidden;
  scrollbar-width: none;
  white-space: nowrap;

  box-sizing: border-box;
  padding-left: 1rem;
  padding-top: var(--top-padding);
  font-size: 0.9rem;
  line-height: 1.9;

  --open-duration: 200ms;
  --stretch-duration: 500ms;

  transition:
    /* menu open/close */
    left var(--open-duration),
    /* menu unstretching to normal width */ box-shadow ease-in-out
      var(--stretch-duration),
    min-width ease-in-out var(--stretch-duration);
  box-shadow: 5px 0 0px -5px #0000;
  z-index: 1;

  &:not(.stretched) > ul {
    mask-image: linear-gradient(to right, black 95%, transparent);
  }

  &.stretched {
    /* how fast menu stretches out */
    transition: 500ms;
    box-shadow: 5px 0 10px -5px #0003;
  }

  p {
    margin: 0;
    /* glitchy when combined with overflow */
  }

  a {
    text-decoration: none;
  }

  & > ul > li {
    margin-top: 1rem;
  }

  ul {
    list-style: none;
    padding: 0;

    ul ul {
      padding-left: 1em;
      font-weight: 300;
      font-size: 0.9em;
    }
  }

  span[data-depth="3"] {
    padding-left: 1em;
  }

  details ul {
    padding-left: 1rem;
  }

  details {
    summary {
      list-style: none;
      cursor: pointer;
    }

    summary::after {
      content: "+";
      float: right;
      margin-right: 1em;
    }

    &[open] summary::after {
      content: "−";
    }
  }
}

@media screen and (min-width: 45rem) {
  /* Wide page */

  nav {
    background: color-mix(in srgb, var(--bg) 90%, transparent);
    backdrop-filter: blur(5px);
  }

  main {
    margin: auto;
    width: calc(min(40rem + 30vw, 100vw));
  }

  article {
    margin-left: var(--sidebar-width);
  }

  #menu-button {
    display: none;
  }
}

@media screen and not (min-width: 45rem) {
  /* Narrow page */

  #menu-button {
    position: fixed;
    top: 0;
    left: 0;
    background-color: var(--bg);
    padding: 1rem;
    border-bottom-right-radius: 1rem;
    box-shadow: 0 0 1rem #0002;
  }

  h2 {
    font-size: 1.3em;
  }

  nav {
    background: var(--bg);
    left: calc(-1 * var(--sidebar-width));
  }

  article {
    margin-top: 4em;
    padding: 0 5vw;
  }

  #menu-control:checked ~ nav {
    left: 0px;
    box-shadow: 0 0 15px #0003;
  }

  #menu-control:not(:checked) ~ .menu-overlay {
    opacity: 0;
    pointer-events: none;
  }

  .menu-overlay {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    transition: opacity 0.2s;
  }
}

#page-nav {
  display: flex;
  gap: 1em;
  margin: 2em 0;

  div {
    flex: 1;
    text-align: center;
    position: relative;

    a {
      padding: 1em;
      display: flex;
      align-items: center;
      justify-content: center;
      border: 1px solid #eee;
      border-radius: 5px;

      &:hover {
        border-color: #888;
      }
    }
  }
}

#wip-banner {
  position: fixed;
  top: 0;
  right: 0;
  font-size: 10pt;
  padding: 0.5em;
  background: repeating-linear-gradient(-45deg, yellow 0 10px, black 10px 20px);
  box-shadow: 0 2px 5px #0002;
  z-index: 10;

  &::after {
    content: "Site Work In Progress";
    background: yellow;
    padding: 0.25em;
    display: block;
  }
}

/* Text styles */

h1,
h2 {
  font-weight: 300;
}

h2 {
  margin-top: 0;
}

h4 {
  margin-bottom: 1em;
}

a {
  color: unset;
  cursor: pointer;

  &:hover {
    text-decoration: underline;
  }
}

strong {
  font-weight: 500;
}

code {
  font-family: monospace, monospace;
  font-size: 0.95em;
}

table {
  border-collapse: collapse;

  th,
  td {
    padding: 0.2em 0.5em;
  }

  td {
    border: 1px solid #d0d7de;
    overflow: hidden;
  }
}

/* Elements */

.frame-row {
  display: flex;
  flex-direction: row;
  justify-content: space-evenly;
  flex-wrap: wrap;
  align-items: center;
}

pre {
  overflow-x: scroll;
  scrollbar-width: thin;
  padding-right: 1em;
  margin-right: -1em;
}

.codeblock pre {
  background: #f9fcff;
  border: 1px solid #d0d7de;
  padding: 0.5em;
  border-radius: 0.75em;
  font-size: 0.85em;
  box-shadow: 0 1px 4px #0001;
}

.code-example {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;

  .codeblock {
    flex-grow: 1;
    min-width: 0;
    mask-image: linear-gradient(to right, black 80%, transparent);
  }

  & > svg {
    margin-left: -3em;
  }
}

.side-figure {
  display: flex;
  gap: 1em;

  :first-child {
    flex-grow: 1;
  }
}

.bordered-section {
  border-top: 1px solid #aaa;
  border-radius: 0.8rem 0.8rem 0 0;
  box-shadow: 0 -4px 8px -8px #0003;
  padding: 1rem;
  margin: 2em 0;

  & > :first-child {
    margin-top: 0;
  }
}

.gallery-example {
  border-radius: 0.5rem;
  border: 1px dashed transparent;

  &:hover {
    border-color: #aaa;
    box-shadow: -2px 4px 8px #0002;
  }
}

/* Function docs */

.fn-arg {
  border-top: 1px solid #aaa;
  border-radius: 0.8rem 0.8rem 0 0;
  box-shadow: 0 -4px 8px -8px #0003;
  padding: 1rem;
  margin: 2em 0;

  :is(h1, h2, h3, h4, h5, h6):first-child {
    margin-top: 0;
    display: inline-block;
  }
}

.fn-arg-details {
  display: inline-block;
  margin-left: 1em;
  font-size: 0.8em;
}

.fn-signature {
  line-height: 1.6;
}

.type {
  border-radius: 0.3rem;
  padding: 1px 4px;
  display: inlineblock;
}
