: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, #191a1b);
  line-height: 2;
  font-weight: 400;
  scroll-behavior: smooth;
  scroll-margin-top: 70px;
}

a {
  text-decoration: none;
}

.nowrap {
  white-space: nowrap;
}


h1 {
  --heading-order: 1;
  font-size: 1.4rem
}

h2 {
  --heading-order: 2;
  font-size: 1.2rem
}

h3 {
  --heading-order: 3;
  font-size: 1.1rem
}

h4 {
  --heading-order: 4;
}

h5 {
  --heading-order: 5;
}

h6 {
  --heading-order: 6;
}

p {
  --heading-order: 7;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 600;
}

h1:not(:first-child),
h2:not(:first-child),
h3:not(:first-child),
h4:not(:first-child),
h5:not(:first-child),
h6:not(:first-child),
p:not(:first-child) {
  margin: calc(((7 - var(--heading-order)) / 6 + 1) * 10px) 0;
}

footer {
  width: 100%;
  padding: 20px 20px 100px;
  border-top: 0.5px solid #eee;
}

html {
  width: 100%;
}

.site-wide-note {
  padding: 10px 20px;
  background-color: light-dark(#f6e0ff, #280039);
  color: light-dark(#7a08aa, #e4a4ff);
  text-align: center;

  a {
    text-decoration: underline;
  }
}

body {
  width: 100%;
  padding-bottom: 200px;

  #markdown-page-column-layout {
    padding: 20px;

    @media screen and (width<700px) {
      position: relative;
      display: flex;
      flex-direction: column;
      gap: 20px;

      &>header {
        display: contents;
      }
    }

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

      position: relative;

      &>header {
        grid-column: 1 / 2;
        grid-row: 1 / 2;

        display: flex;
        flex-direction: column;
        gap: 20px;
      }

      &>main {
        grid-column: 2 / 3;
        grid-row: 1 / 2;
        overflow-x: hidden;
      }
    }

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

      position: relative;

      &>header {
        display: contents;

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

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

      &>main {
        grid-column: 2 / 3;
        grid-row: 1 / 2;
        justify-self: center;
      }
    }
  }
}

body {
  position: relative;
}

.markdown {

  p:not(:has(img)),
  li:not(:has(pre)),
  blockquote {
    max-width: 600px;
  }

  >p:not(:has(img)),
  >li:not(:has(pre)),
  >blockquote {
    width: min(100%, 600px);
  }

  >p:has(img),
  >table,
  >pre.chroma,
  >figure:has(pre.chroma),
  >ul,
  >ol {
    margin-top: 10px;
  }


  strong {
    font-weight: 600;
  }

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

  *:not(pre)>code {
    background-color: light-dark(#ececec, #212326);

    font-family: "Fira Mono", monospace !important;
    font-weight: 400;

    border-radius: 8px;
    padding: 0.1em 0.4em;
  }

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

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

  img {
    object-fit: scale-down;
  }

  blockquote {
    padding: 10px 20px;
    color: light-dark(#6a4800, #ffbf35);
    background-color: light-dark(#fff8e9, #2d2700);
    border-radius: 8px;
  }

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

  >ul,
  >ol {
    margin-left: 10px;
  }

  ul {
    counter-reset: li 0;

    position: relative;
    padding-left: 0px;

    display: block;

    li {
      display: list-item;

      text-align: match-parent;
      margin-left: 20px;
    }
  }

  >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, #191a1b);
          border-bottom: 2px solid light-dark(#eee, #555);
        }
      }
    }

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

  pre.chroma {
    background-color: light-dark(#f9f9f9, #212326);

    border-radius: 8px;
    padding: 20px 20px 20px 40px;

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

    max-width: 100%;
    overflow-x: scroll;
    overflow-y: visible;

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

    color: light-dark(#24292f, #a7b1bc);

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

    .nx {
      color: light-dark(#24292f, #a7b1bc);
    }

    .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);
    }
  }

  pre.chroma {
    counter-reset: line;
  }

  .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;
    }
  }
}

header {
  nav {
    ul ul {
      margin-left: 20px;
    }

    li {
      list-style: none;
    }

    a,
    span {
      display: block;
      min-width: 200px;
      padding: 0 5px;
      border-radius: 8px;
      text-align: left;
    }

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

    a {

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

  @media screen and (width<700px) {
    display: flex;
    flex-direction: column;
    gap: 20px;

    details {
      border-radius: 8px;
      overflow: hidden;

      summary {
        padding: 10px;
        background-color: light-dark(#eee, #000);
        cursor: pointer;
      }

      .summarized {
        padding: 10px;
        background-color: light-dark(#f8f8f8, #111);
      }
    }
  }

  @media screen and (700px<=width) {
    &>nav>details {

      &,
      &>* {
        display: block;
      }
    }
  }
}

