:root {
  color-scheme: light dark;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-size: inherit;
  font-family: inherit;
  color: inherit;
  font-weight: inherit;
  scroll-margin-top: 20px;
}

html {
  font-size: 16px;
  font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: light-dark(#444, #aaa);
  background-color: light-dark(#fff, #171717);
  font-weight: 400;
  scroll-behavior: smooth;
  scroll-margin-top: 70px;
}

body {
  width: 100vw;

  @media screen and (width<=800px) {
    & > main {
      padding-bottom: 50vh;
    }
  }

  @media screen and (800px<width) and (width<1400px) {
    display: grid;
    grid-template-columns: 300px 1fr;
    justify-content: left;
    align-items: start;
    gap: 20px;

    & > header {
      grid-column: 1 / 3;
    }

    & > #navs {
      grid-column: 1 / 2;
      grid-row: 2 / 3;

      display: flex;
      flex-direction: column;
      gap: 20px;
      padding: 0 0 20px 20px;

      height: 100%;
      position: relative;

      & > #toc {
        position: sticky;
        top: 0;
      }
    }

    & > main {
      grid-column: 2 / 3;
      grid-row: 2 / 3;
      overflow-x: hidden;
      padding-bottom: 50vh;
      padding-right: 20px;
    }
  }

  @media screen and (1400px<=width) {
    display: grid;
    grid-template-columns: 350px 1fr 350px;
    justify-content: space-between;
    align-items: start;
    gap: 0 20px;

    position: relative;

    & > header {
      grid-column: 1 / 4;
    }

    & > #navs {
      display: contents;

      & > nav#sitemap {
        grid-column: 1 / 2;
        grid-row: 2 / 3;
        top: 0;
        position: sticky;
        padding: 20px 0 20px 20px;
      }

      & > nav#toc {
        grid-column: 3 / 4;
        grid-row: 2 / 3;
        top: 0;
        position: sticky;
        padding: 20px 20px 20px 0;
      }
    }

    & > main {
      grid-column: 2 / 3;
      grid-row: 2 / 3;
      justify-self: center;
      width: 100%;
      overflow: hidden;
      padding: 20px 0 50vh;
    }
  }
}


body {
  position: relative;
}

.markdown {
  @media screen and (width<=800px) {
    padding-top: 50px;
  }

  p:not(:has(img, pre, table, ul, ol)) {
    max-width: 640px;
  }

  @media screen and (width<=800px) {
    > *:not(:has(pre, table, ul, ol)) {
      padding: 0 20px;
    }
  }

  strong {
    font-weight: 600;
  }

  *:not(pre) > code {
    font-family: "Fira Code", monospace !important;
  }

  h1 {
    --significance: 4;
  }

  h2 {
    --significance: 3;
  }

  h3 {
    --significance: 2;
  }

  h4,
  h5,
  h6 {
    --significance: 1;
  }

  :is(h1, h2, h3, h4, h5, h6) {
    font-size: calc(1em + var(--significance) * 0.35em);
    line-height: normal;
    font-weight: 500;

    margin: calc(var(--significance) * 10px) 0;
  }

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

  p {
    margin: 10px 0;
  }

  li,
  p {
    line-height: 2em;
  }

  a {
    text-decoration: underline;
    cursor: pointer;
    transition: 200ms color ease-out;
  }

  a:hover {
    color: light-dark(#000, #eee);
  }

  img {
    object-fit: scale-down;
    border-radius: 8px;
  }

  blockquote {
    padding: 10px 20px;
    color: light-dark(#6a4800, #de9e5f);
    background-color: light-dark(#fff8e9, #28231f);
    border-radius: 8px;

    code {
      color: light-dark(#885d00, #28231f);
      background-color: light-dark(#fbe4b4, #de9e5f);
    }
  }

  hr {
    color: none;
    width: 100%;
    border: none;
    border-bottom: 1px solid light-dark(#eee, #2a2e32);
    margin: 50px 0;
  }

  > ul,
  > ol {
    padding: 0 10px;
  }

  ul {
    counter-reset: li 0;

    position: relative;
    padding-left: 0px;

    display: block;

    li {
      display: list-item;

      text-align: match-parent;
      margin-left: 20px;
      list-style-position: inside;
    }
  }

  > ol {
    margin-bottom: 15px;
  }

  ol {
    counter-reset: li 0;
    list-style-type: none;

    position: relative;
    padding-left: 0px;

    display: block;

    padding-inline-start: 0;

    > li {
      display: list-item;
      list-style-type: none;
      text-align: match-parent;
      margin-top: 16px;
      margin-left: 40px;
    }

    > li > * {
      margin-top: 16px;
    }

    > li::before {
      display: inline;

      box-sizing: border-box;

      width: 1.6rem;
      height: 1.6rem;
      padding: 0.45rem 0 0.35rem 0;
      margin-top: 0.15rem;

      background-color: light-dark(black, #ddd);
      color: light-dark(white, black);

      position: absolute;
      left: 0px;

      border-radius: 100vh;

      font-size: 0.8rem;
      line-height: 0.8rem;
      font-weight: 600;
      text-align: center;

      content: counter(li);
      counter-increment: li 1;
    }
  }

  table {
    font-size: 0.9em;
    border-collapse: separate;
    border-spacing: 0;

    @media screen and (max-width: 700px) {
      min-width: calc(100% - 40px);
    }

    @media screen and (min-width: 700px) {
      min-width: 100%;
    }

    th {
      text-align: left;
    }

    th,
    td {
      padding: 10px 20px 10px 0px;
    }

    thead {
      tr {
        position: sticky;
        top: 0;
        font-weight: bolder;

        th {
          background-color: light-dark(white, #171717);
          border-bottom: 2px solid light-dark(#eee, #555);
        }
      }
    }

    tbody tr:not(:last-child) td {
      border-bottom: 1px solid light-dark(#eee, #333);
    }
  }

  pre.chroma {
    padding: 20px 30px 20px 40px;

    user-select: initial;
    -webkit-user-select: initial;

    font-optical-sizing: auto;
    line-height: 1.24;
    font-size: 11pt;

    width: max-content;
    max-width: 100%;
    overflow-x: scroll;

    counter-reset: line;

    color: light-dark(#444, #aaa);

    * {
      font-family: "Fira Code", monospace !important;
      font-weight: 400;
    }

    .nx {
      color: light-dark(#444, #aaa);
    }

    .s,
    .s1,
    .s2,
    .o,
    .nv,
    .kc {
      color: light-dark(#0550ae, #527aac);
    }

    .m,
    .kt {
      color: light-dark(#008775, #56908c);
    }

    .k,
    .kn,
    .kd {
      color: light-dark(#cf222e, #c96168);
    }

    .kr,
    .nf {
      color: light-dark(#8250df, #a286d6);
    }

    .nb {
      color: light-dark(#c44886, #db7eac);
    }

    .cm,
    .cp {
      color: light-dark(#6e7781, #78a7dd);
    }

    .c1 {
      color: light-dark(#6e7781, #7f858c);
    }
  }

  .line:before {
    display: inline-block;

    counter-increment: line;
    content: counter(line);

    width: 16px;

    color: light-dark(#888, #888);
    font-size: 12px;
    font-family: monospace;
    text-align: right;

    -moz-user-select: none;
    user-select: none;
    -webkit-user-select: none;

    transform: translateX(-22px);
  }

  > figure {
    &:has(pre.chroma) {
      display: flex;
      flex-direction: column-reverse;
      border-radius: 8px;
      overflow: hidden;
    }

    pre.chroma + figcaption {
      background-color: light-dark(#eee, #eee);
      padding: 10px 20px;
    }

    > pre.chroma {
      border-radius: 0px;
      padding: 20px 20px 20px 40px;
    }
  }
}


html {
  position: relative;
  scroll-padding-top: 60px;

  @media screen and (width<=800px) {
    &:has(#navs.open) {
      height: 100vh;
      overflow: hidden;
    }
  }
}

header {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: center;

  @media screen and (width<=800px) {
    position: sticky;
    top: 0;
    z-index: 2;

    -webkit-backdrop-filter: blur(30px);
    backdrop-filter: blur(30px);

    border-bottom: 1px solid light-dark(#0001, #fff1);
    background-color: light-dark(#fffa, #171717aa);
  }

  #logotype {
    display: inline-block;
    padding: 20px;

    @media screen and (width<=800px) {
      padding: 10px 20px;
    }

    font-size: 1.5em;
    line-height: normal;
    text-decoration: none;
    transition: color 90ms ease-out;

    &:hover {
      color: light-dark(#000, #fff);
    }
  }

  button {
    appearance: none;
    border: none;
    background: none;
    padding: 20px;
    cursor: pointer;
    & > svg {
      display: block;
    }
  }

  .header-icon {
    fill: light-dark(#444, #aaa);
  }

  @media screen and (width>800px) {
    button {
      display: none;
    }
  }
}

#navs {
  a {
    text-decoration: none;
  }

  nav {
    & > .nav-header {
      &:not(:first-child) {
        margin-top: 20px;
      }

      margin-bottom: 10px;
      font-size: 1.1em;
      line-height: 2em;
      color: light-dark(#aaa, #444);
    }

    & > ul {
      ul {
        margin-left: 20px;
      }

      li {
        list-style: none;
        text-indent: 1.6em hanging;
      }

      a,
      span {
        display: block;
        border-radius: 8px;
        text-align: left;
        line-height: 2em;
      }

      span {
        color: light-dark(#aaa, #444);
      }

      a {
        &:hover,
        &.active {
          color: light-dark(black, white);
        }
      }
    }

    &#sitemap > #link-grid {
      display: grid;
      grid-template-columns: min-content 1fr;
      justify-content: start;
      align-items: center;
      gap: 0 10px;

      a {
        display: contents;

        svg {
          width: 16px;
          fill: light-dark(#444, #aaa);
        }

        span {
          padding: 2px 0;
          line-height: normal;
        }

        &:hover {
          span {
            color: light-dark(#000, #fff);
          }

          svg {
            fill: light-dark(#000, #fff);
          }
        }
      }
    }
  }
}

@media screen and (width<=800px) {
  #navs {
    width: 100vw;
    height: 100vh;
    position: fixed;
    z-index: 1;
    inset: 0;

    display: flex;
    flex-direction: row;
    overflow: hidden;

    &:not(.open) {
      background-color: light-dark(#fff0, #17171700);
      display: none;
    }

    &.open {
      background-color: light-dark(#fffe, #171717ee);
      backdrop-filter: blur(100px);
    }

    transition-property: backdrop-filter, background-color, display;
    transition-duration: 300ms;
    transition-timing-function: ease-in-out;
    transition-behavior: allow-discrete;

    & > nav {
      width: 100vw;
      height: 100vh;
      padding: 80px 20px 20px;
      overflow: scroll;
      flex-shrink: 0;
      transition: opacity 300ms ease-out;

      &:not(.on-spot) {
        opacity: 0;
      }

      ul,
      #link-grid,
      #link-grid > a > span {
        transition: transform 300ms ease-out;
      }

      &:not(.on-spot) {
        ul,
        #link-grid,
        #link-grid > a > span {
          transform: translateX(-2px);
        }
      }

      &.on-spot,
      &.on-spot ul,
      &.on-spot #link-grid,
      &.on-spot #link-grid > a > span {
        transition-delay: 200ms;
      }
    }
  }

  @starting-style {
    #navs.open {
      display: flex;
      backdrop-filter: blur(0px);
      background-color: light-dark(#fff0, #17171700);
    }
  }
}


