/**
 * global colors and other css variable definitions
 */
:root {
  --font: "Avenir Next",Avenir,"Nimbus Sans L",Roboto,"Noto Sans","Segoe UI",Arial,Helvetica,"Helvetica Neue";
  --font-mono: "Roboto Mono","Droid Sans Mono",Consolas,"Courier New",monospace;

  --border-radius: 0.3rem;

  /* TODO: use hsl to define a color palette */

  --color-bg: #212121;
  --color-bg-accent: #2b2b2b;
  --color-bg-stripe1: #323232;
  --color-bg-stripe2: #424242;
  --color-bg-code-block: #22272e;
  --color-bg-code-block-header: #12171e;
  --color-border: #252525;
  --color-border-light: #454545;
  --color-text: #dcdcdc;
  --color-text-light: #ababab;
  --color-text-medium: #999;
  --color-text-dark: #666;
  --color-acc: #ffe099;
  --color-acc-focus: #ffd066;
  --color-acc-hover: #ffb033;
  --color-error: #ff6666;
  --color-code: #f06292;
  --color-pre: #ccc;
  --color-disabled: #111;
  --color-btn: #87cefa;
  --color-btn-hover: #00bfff;
  --color-btn-focus: #1e90ff;
  --color-btn-active: #87cefa;
  --color-btn-text: #4b3f36;
  --color-link: #87cefa;
  --color-link-hover: #00bfff;
  --color-link-focus: #1e90ff;
  --color-link-active: #87cefa;
  --color-link-visited: #8795fa;
}

@font-face {
  font-family: 'Roboto Mono';
  font-display: swap;
  font-style: normal;
  font-weight: 400;
  src: url('../fonts/roboto-mono-variable.woff2') format('woff2');
}

/**
 * inherit defaults across all elements
 */
* {
  margin: 0;
  box-sizing: border-box;

  line-height: inherit;
  font-family: inherit;
  background-color: inherit;
  color: inherit;
}

/**
 * uniform margin between adjacent block elements
 */
* + * {
  margin-top: 0.5rem;
}

/**
 * exceptions to uniform margin between adjacent block elements
 */
body, br, li, dt, dd, th, td, option {
  margin-top: 0;
}

/**
 * set uniform values for inherited styles
 */
html {
  line-height: 1.6;
  font-size: 110%;
  font-family: var(--font),sans-serif;
  color: var(--color-text);
  background-color: var(--color-bg);
}

body {
  display: flex;
  flex-direction: column;
  min-width: 300px;
  min-height: 100vh;
}

header, footer {
  display: flex;
  flex-grow: 0;
  align-items: center;
  justify-content: center;
  background-color: var(--color-bg-accent);
  padding-top: clamp(0.1rem, 0.5rem, 1rem);
  padding-bottom: clamp(0.1rem, 0.5em, 1rem);

  & * {
    margin-top: 0;
  }

  & nav {
    display: flex;
    flex-grow: 1;
    margin-left: 1rem;
    margin-right: 1rem;

    & ul {
      display: flex;
      flex-grow: 1;
      justify-content: space-between;
      align-items: center;
      gap: 1rem;

      list-style: none;
      padding: 0;
      margin: 0;

      & li {
        display: flex;
        align-items: center;
        height: 100%;
      }
    }
  }
}

header {
  border-bottom: 1px solid var(--color-border);

  & nav ul {
    display: flex;
    align-items: center;
    justify-content: space-between;

    /* logo and site name -------------------- */
    & li:first-child {
      margin-right: auto;

      /* vertically center site name text next to logo */
      & a {
        display: flex;
        align-items: center;
        gap: 0.5em;

        color: var(--color-text-medium);

        &:hover {
          color: white;
        }

        & img {
          height: clamp(1.5rem, 3rem, 4rem);
          width: auto;
          max-width: 100%;
          border-radius: 50%;
        }
      }
    }

    /* navigation links -----------------------*/
    & li:not(:first-child) a {
      /* animated underline and grow effect on hover */
      position: relative;
      transition: font-size 0.1s ease, color 0.1s ease;

      /* animated properties active */
      &:hover {
        font-size: 1.5rem;
        &::after {
          width: 100%;
        }
      }

      /* animated underline - inactive */
      &::after {
        content: "";
        position: absolute;
        left: 0;
        bottom: -2px;
        width: 0;
        height: 2px;
        background-color: var(--color-acc-hover);
      }
    }

    /* remove normal link styles including :hover, etc... */
    & a:any-link {
      text-decoration: none;
      font-size: 1.25rem;
      color: var(--color-text);
    }
  }
}

footer {
  border-top: 1px solid var(--color-border);

  & nav {
    justify-content: space-between;
    align-content: space-between;
    align-items: stretch;

    & li {
      color: var(--color-text-dark);

      &:first-of-type {
        font-size: 0.6rem;
      }
    }

    & img {
      display: block;
      height: 1.5rem;
      width: auto;
      max-width: 100%;
    }
  }
}

main {
  flex-grow: 1;
  margin: 2em 3em;

  & section > p > img {
    width: 256px;
    height: 256px;
    margin: 0 auto;
  }
}

/* title and metadata for a post */
article > header {
  display: flex;
  flex-direction: column;
  background-color: var(--color-bg);

  & h1 {
    border: none;

    &:hover {
      border: none;
      color: white;
    }
  }

  & p {
    width: 100%;
    text-align: center;
    font-size: 0.8rem;
    color: var(--color-text-dark);
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border-light);
  }

  & img {}

  /* 'draft post' markers need their top margin shrunk */
  & + p:first-of-type {
    margin-top: 0.5em;
  }
}

img {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  border-radius: var(--border-radius);
}

a {
  color: var(--color-link);

  &:hover { color: var(--color-link-hover); }
  &:focus { color: var(--color-link-focus); }
  &:active { color: var(--color-link-active); }
  &:visited { color: var(--color-link-visited); }
}

/*
  45-75 characters per line is ideal for readability in a single column
  The Elements of Typographic Style ~ Robert Bringhurst
  width: clamp(45ch, 100%, 75ch);
*/
p {
}

/* headings should fill the parent width */
h1, h2, h3, h4, h5, h6 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: white;
  border-bottom: 2px solid var(--color-border);

  & a {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 0.5rem;

    &:any-link {
      color: white;
      text-decoration: none;
    }
  }

  &:hover {
    color: var(--color-acc-hover);
    border-bottom: 2px solid var(--color-acc-hover);

    & a {
      color: var(--color-acc-hover);
    }
  }

  /* show anchor icon on hover */
  &:hover > a::after {
    content: " 🔗";
    color: var(--color-acc-hover);
    filter: hue-rotate(180deg);
  }
}

/* high level headings get bottom border for visual separation */
h1, h2 {
  border-bottom: 2px solid var(--color-border-light);
}

label {
  display: block;
}

label + * {
  margin-top: 0.5rem;
}

input, textarea {
  border: 2px solid;
  padding: 0.5rem;
}

[aria-invalid] {
  padding-right: 1.5rem;
  border-color: var(--color-error);
  /*background: url(img/cross.svg) no-repeat center 0.5em;*/
}

button {
  padding: 0.75em;
  background-color: var(--color-btn);
  color: var(--color-btn-text);

  &:hover {
    outline: 0.1em solid var(--color-acc-hover);
    background-color: var(--color-btn-hover);
  }
  &:focus {
    outline: 0.2em solid var(--color-acc);
    background-color: var(--color-btn-focus);
  }
  &:active {
    outline: 0.2em solid var(--color-acc);
    background-color: var(--color-btn-active);
  }
}

code {
  font-family: var(--font-mono),monospace;
  font-size: 90%;
}

blockquote {
  position: relative;
  margin: 1em 3.5em;
  padding: 1em 2em;

  background-color: var(--color-bg-accent);
  border-radius: var(--border-radius);
  border-left: 1rem solid var(--color-border-light);

  &::after {
    content: "🗣️";
    font-size: 2em;
    position: absolute;
    bottom: 0;
    right: 0;
    transform: scaleX(-100%);
    filter: sepia(100%);
  }
}

figure {
  display: flex;
  flex-direction: column;
  align-items: center;

  & figcaption {
    font-size: 0.7rem;
    color: var(--color-text-dark);
    text-align: center;
    margin-top: 0.5rem;
  }
}

/* Override normal <figure> style for code controls associated with code blocks */
figure[data-type="code-controls"] {
  width: 100%;
  position: relative;
  margin: 0.5em 0;
  padding: 0;

  & * {
    margin-top: 0;
  }

  & figcaption {
    width: 100%;
    display: flex;
    justify-content: flex-start;
    gap: 0.5rem;

    padding: 0.5em 1em;
    border-top-left-radius: var(--border-radius);
    border-top-right-radius: var(--border-radius);

    background-color: var(--color-bg-code-block-header);
  }

  & div[role="group"] {
    display: flex;
    gap: 0.3rem;
    border-radius: 0.25rem;
    background-color: var(--color-bg);
  }

  & button {
    margin-top: 0;
    color: var(--color-text);

    border: none;
    border-radius: 0.25rem;
    background-color: var(--color-bg-accent);

    padding: 0.25em 0.4em;
    &[aria-label="Copy text"] {
      padding: 0.25em 1em;
    }

    &[aria-label="Reset text size"] {
      font-size: 110%;
      display: inline-block;
    }

    & img {
      width: 1rem;
      height: 1rem;
    }

    &:hover, &:focus, &:active {
      outline: 0.1em solid var(--color-acc-hover);
      background-color: var(--color-border-light);
    }
  }

  & pre {
    margin-top: 0;
    width: 100%;
  }
}

/* ------------------------------------------------------------------------- */
/* individual post table of contents styles
/* ------------------------------------------------------------------------- */

nav[data-type="toc"] {

  & details {
    width: 100%;
    padding: 0.25rem 0.5rem;
    border: 2px solid var(--color-border-light);
    border-radius: var(--border-radius);
    background-color: var(--color-bg-accent);
    cursor: pointer;

    &[open] {
      color: var(--color-acc-hover);
    }

    & > ul {
      border-top: 1px solid var(--color-border-light);
    }
  }

  & summary {
    font-weight: bold;

    &:hover {
      color: var(--color-acc-hover);
    }
  }

  & ul {
    padding-inline-start: 2em;
    list-style: disc;
    margin-top: 0;
  }

  /* items that contain only a nested list shouldn't have a bullet */
  & li:has(> ul:only-child) {
    list-style: none;
  }

  & a {
    &:any-link {
      text-decoration: none;
      color: var(--color-text);
      font-size: 90%;
      border-bottom: 1px solid transparent;
    }

    &:hover {
      color: var(--color-acc-hover);
      border-bottom: 1px dotted var(--color-acc-hover);
    }
  }
}

/* ------------------------------------------------------------------------- */
/* posts table of contents styles
/* ------------------------------------------------------------------------- */

header[data-page="toc"] {}

ul[data-page="toc"] {
  width: 100%;
  margin-top: 0;
  list-style: none;
  padding-inline-start: 0;

  & li {
    position: relative;
    display: block;
    width: 100%;
    text-align: center;
    margin-top: 1.5rem;
    border-radius: var(--border-radius);
    border: 2px solid var(--color-text-dark);
    background-color: var(--color-bg-stripe2);

    &:hover {
      border: 2px solid var(--color-acc-hover);
      & > a {
        color: var(--color-acc-hover);
      }
      & time {
        color: var(--color-text);
        border: 2px dotted var(--color-acc-hover);
      }
    }

    /*&:not(:hover) {*/
    /*  &:nth-child(even) { background-color: var(--color-bg-stripe1); }*/
    /*  &:nth-child(odd)  { background-color: var(--color-bg-stripe2); }*/
    /*}*/
  }

  & a:any-link {
    display: block;
    width: 100%;
    padding: 1rem;
    text-decoration: none;
    font-weight: bold;
    font-size: 120%;
    color: var(--color-text);

    &:hover {
      color: var(--color-acc-hover);
    }
  }

  & time {
    margin-top: 0;
    padding: 0.25rem 0.5rem;
    position: absolute;

    font-family: var(--font-mono),monospace;
    font-size: 0.8rem;
    color: var(--color-text-light);
    border-radius: 1rem;
    border: 2px dotted var(--color-text-dark);
    background-color: var(--color-bg-stripe1);

    &[data-type="updated"] {
      &::before { content: "💫 Updated: "; }
      transform: translateY(-50%);
      top: 0;
      left: 0;
    }

    &[data-type="created"] {
      &::before { content: "Created: "; }
      &::after  { content: " ✨"}
      transform: translateY(50%);
      bottom: 0;
      right: 0;
    }
  }
}

/* ------------------------------------------------------------------------- */
/* custom styles for the index page                                          */
/* ------------------------------------------------------------------------- */

#topic-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 300px));
  justify-content: center;
  gap: 1rem;
  max-width: 100%;
  margin: 0 auto;
  padding: 1rem;

  & a:any-link {
    text-decoration: none;
    color: var(--color-text);
  }

  & article {
    display: flex;
    flex-direction: column;
    height: 100%;
    margin-top: 0;
    border-radius: var(--border-radius);
    background-color: var(--color-bg-code-block);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);

    border: 2px solid transparent;
    &:hover {
      border: 2px solid var(--color-acc-hover);
    }

    & header {
      padding: 0.75rem 1rem;
      border-top-left-radius: var(--border-radius);
      border-top-right-radius: var(--border-radius);
      background-color: var(--color-bg-accent);

      & h2 {
        margin: 0;
        font-size: 110%;
        border-bottom: none;
      }
    }

    & img {
      width: 100%;
      height: 180px;
      object-fit: cover;
      border-radius: 0;
      padding: 0.25rem;
    }

    & p {
      padding: 1rem;
      flex-grow: 1;
      margin: 0;
      line-height: 1.5;
    }
  }
}


/* ------------------------------------------------------------------------- */
/* utility classes for local scopes                                          */
/* ------------------------------------------------------------------------- */

/*
 * center a block element and their children
 */
.centered {
  text-align: center;
  margin-bottom: -1rem; /* adjust for leftover bottom margin of children */
}
.centered > * {
  display: inline-block;
  margin: 0 0.5rem 1rem;
}

.font-large {
  font-size: 1.5rem;
}
.font-medium {
  font-size: 1.25rem;
}

/* ------------------------------------------------------------------------- */
/* media queries
/* ------------------------------------------------------------------------- */

@media (max-width: 576px) {
  main {
    margin: 0.5em 1em;
  }

  code {
    font-size: 80%;
  }

  blockquote {
    margin: 1em;
    padding: 0.5em;
  }

  #topic-cards {
    grid-template-columns: 1fr;
  }

  ul[data-page="toc"] {
    & li {
      margin-top: 2.5rem;
    }

    & a:any-link {
      padding: 1.5rem;
    }
  }

  /* iframe youtube embed */
  iframe {
    width: 237px;
    height: 148px;
  }
}
