html {
  box-sizing: border-box;
}

*,
*::before,
*::after {
  box-sizing: inherit;
}

:root {
  --white: rgb(255 255 255);
  --wheat: #F5DFBB;
  --caput-mortuum: #562C2C;
  --cinnabar: #F2542D;
  --dark-cyan: #0E9594;
  --carribean-current: #127475;
}

ol,
ul {
  list-style-position: outside;
  margin-inline-start: 2rem;

  margin-block-end: 0.5rem;

  li {
    margin-block: 0.5rem;
  }
}

em {
  font-style: italic;
}

ol {
  list-style-type: decimal;
}

ul {
  list-style-type: disc;
}

p {
  margin-block: 1rem;
}


body {
  background-color: var(--wheat);
  color: var(--caput-mortuum);

  padding: 0;
  margin: 0 auto;
  min-height: calc(100vh - 5px);
  border-top: 5px solid var(--dark-cyan);

  font: 1.25rem 'Computer Modern Sans', sans-serif;
  line-height: 1.5;

  &>header {
    max-width: 90ch;
    margin: 0 auto;
    font-size: 1.5rem;

    &>nav {
      padding: 5px 10px;

      display: flex;
      flex-wrap: wrap;
      gap: 1rem;
      align-items: center;
      justify-content: center;

      &>a {
        text-decoration: none;
        color: inherit;

        &:hover {
          text-decoration: underline;
        }

        /* The first link is the title, e.g., Michael Engen */
        &:first-child {
          min-width: max-content;
          flex-grow: 1;
          flex-shrink: 0;

          font-size: 2rem;

          /* For small viewports, make the title take up the full width. */
          @media (max-width: 60ch) {
            flex-basis: 100%;
            text-align: center;
          }
        }
      }
    }
  }

  &>main {
    max-width: 100ch;
    margin: 0 auto;
    text-align: left;
    padding: 16px;

    &>article {

      & code {
        font-family: monospace;
        font-size: 0.8em;

        white-space: pre;

        background-color: var(--caput-mortuum);
        color: var(--wheat);
        padding: 3px;
        border-radius: 3px;
      }

      & pre {
        background-color: black;
        color: white;
        padding: 1rem;

        border-radius: 1rem;
        margin-block: 1rem;
        margin-inline: -1rem;

        overflow-x: auto;

        &>code {
          overflow-x: scroll;

          background-color: inherit;
          color: inherit;
          padding: none;
          border: none;
        }
      }
    }
  }
}

button {
  cursor: pointer;
}

h1 {
  font-size: 1.5em;
  text-align: center;
  margin: 0.5em;
}

nav.nav-toc {
  #nav-toc {
    display: none;
  }

  ol {
    counter-reset: item
  }

  li {
    display: block
  }

  li:before {
    content: counters(item, ".") ". ";
    counter-increment: item
  }
}

img {
  max-width: 100%;
}

article {
  &.post {

    h1 {
      font-size: 2.2rem;
      font-weight: bolder;
    }

    .heading-wrapper {
      display: flex;
      margin-block-end: 0.75rem;

      @media (min-width: 105ch) {
        margin-inline-start: -1.75rem;
      }

      /* Headings */
      &.h2,
      &.h3 {

        &.h2 {
          font-size: 2rem;
        }

        &.h3 {
          font-size: 1.8rem;
        }

        h2,
        h3 {
          font-weight: bolder;
          margin: 0;
        }
      }


      .anchor {
        font-size: 0.75em;
        order: -1;
        align-self: center;

        margin-inline-end: 0.75rem;
        text-underline-offset: 0.75ex;

        text-decoration: none;

        .heading-wrapper:hover & {
          text-decoration: underline;
        }

        [hidden] {
          display: block;
        }
      }
    }

    >ol,
    >ul {
      line-height: 1.25;
      margin-block-end: 1rem;
    }

    figure {
      display: grid;
      justify-items: center;
      gap: 1rem;
      margin-inline: -1rem;
      margin-block: 1rem;

      em {
        display: inline-block;
      }

      img {
        width: max(80%, 60ch);
        padding-inline: 1rem;
        background-color: white;
      }
    }
  }

  &:not(.post):has(h2),
  &:not(.post):has(h1) {
    padding-block: 0.5rem;
    padding-inline: 1rem;
    margin-block-end: 20px;
    border: 2px var(--caput-mortuum) solid;
    border-radius: 10px;

    display: grid;
    gap: 0.5rem 1rem;

    /* Default to one column for small viewports */
    grid-template-columns: minmax(0, 1fr);

    &>header {
      &>h2 {
        font-size: 1.2em;
        font-weight: 550;
        margin: 0;
      }

      a {
        color: inherit;
      }
    }

    &>figure {
      max-width: 80%;
      color: black;
      margin: 0 auto;

      &>img,
      &>svg {
        width: 100%;
        max-width: 100%;
      }

      #about>& {
        &>img {
          clip-path: circle();
        }
      }
    }

    /* For wide viewports, use different settings. */
    @media (min-width: 40ch) {
      grid-template-columns: minmax(0, 1fr) minmax(0, 3fr);

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

      &>figure {
        grid-column: 1;
        grid-row: 2;

        max-width: 100%;
      }

      &>span {
        grid-column: 2;
        grid-row: 2;
      }

      &>footer {
        grid-column: 2;
        grid-row: 3;

        text-align: end;
      }
    }
  }
}

.hidden {
  display: none;
}

svg {
  display: block;
  margin: auto;
}

.fieldset-figure-container {
  display: grid;
  grid-template-columns: minmax(auto, 1fr) minmax(auto, 2fr);
  grid-template-areas:
    "header header"
    "fieldset figure"
  ;
  gap: 1em;
  align-items: start;

  button {
    --button-border-width: 1px;
    --button-border-style: solid;
    --button-border-color: currentColor;
    --button-border-radius: 8px;

    border-width: var(--button-border-width);
    border-style: var(--button-border-style);
    border-color: var(--button-border-color);
    border-radius: var(--button-border-radius);

    color: inherit;
  }

  >header {
    grid-area: header;
    justify-self: center;
  }

  >fieldset {
    grid-area: fieldset;

    display: grid;
    grid-template-columns: minmax(auto, 1fr);
    justify-items: stretch;

    column-gap: 0.5em;
    row-gap: 0.25em;


    label {
      display: grid;
      grid-template-columns: repeat(2, auto);
      align-content: center;
      justify-content: space-between;

      &:has(+ input),
      &:has(+ select) {
        margin-block-end: -0.25em;

        &:has(+ input[type=range]) {
          margin-block-end: -0.5em;
        }
      }

      button {
        grid-column: 2;
        margin-block-end: 0.125em;

        background-color: transparent;
        --button-border-width: 0;

        &:has(svg) {
          padding: 0.125em;
        }

        svg {
          --shuffle-height: 1em;
          height: var(--shuffle-height);
          max-height: var(--shuffle-height);
        }
      }
    }

    input[type=color] {
      justify-self: end;
    }

    label,
    input,
    select,
    button {
      white-space: nowrap;
      font: inherit;
    }

    @media (max-width: 50rem) {
      grid-template-columns: repeat(2, minmax(auto, 1fr));

      label:has(input[type=color]) {
        grid-column-end: span 2;
      }
    }
  }

  >figure {
    grid-area: figure;

    svg {
      width: 100%;
      max-width: 80vw;

      background-color: var(--svg-background-color, currentColor);
      border-width: 2px;
      border-style: solid;
      border-color: var(--svg-background-color, currentColor);
    }

    button {
      width: 100%;
      padding-block: 1em;
      margin-block: 1em;
    }
  }

  @media (max-width: 50rem) {
    grid-template-columns: minmax(auto, 1fr);
    grid-template-areas: "header"
      "fieldset"
      "figure"
    ;
  }
}