/* Color & Typography Variables */
:root {
  --body-font: Georgia, serif;
  --heading-font: 'Helvetica Neue', system-ui, sans-serif;

  --fs-base: 18px;
  --fs-h1: 2rem;
  --fs-h2: 1.7rem;
  --fs-h3: 1.4rem;
  --fs-h4: 1.25rem;
  --fs-h5: 1.125rem;
  --fs-h6: 1rem;
  --fs-nav: 0.95rem;
  --fs-footer-text: 0.85rem;

  --color-bg: rgb(255 255 255);
  --color-text: rgb(20 20 20);
  --color-divider: rgb(238 238 238);
  --color-border: rgb(221 221 221);
  --color-link: rgb(0 102 204);
  --color-footer-text: rgb(100 100 100);
  --color-blockquote: rgb(80 80 80);
  --color-figcaption: rgb(60 60 60);
  --color-table-header-bg: rgb(44 62 80);
  --color-table-header: rgb(255 255 255);
  --color-table-row-hover: rgb(248 249 250);

  --color-essay-title: rgb(17 17 17);
  --color-essay-year: rgb(100 100 136);
  --color-essay-blurb: rgb(60 60 60);
  --color-section-heading: rgb(34 34 34);

  @media (max-width: 768px) {
    --fs-h1: 1.5rem;
    --fs-h2: 1.25rem;
    --fs-h3: 1.1rem;
    --fs-h4: 1rem;
    --fs-h5: 0.9rem;
    --fs-h6: 0.8rem;
    --fs-nav: 0.75rem;
    --fs-footer-text: 0.8rem;
  }

  @media (prefers-color-scheme: dark) {
    --color-bg: rgb(20 20 20);
    --color-text: rgb(235 235 235);
    --color-divider: rgb(58  58  58);
    --color-border: rgb(80  80  80);
    --color-link: rgb(100 180 255);
    --color-footer-text: rgb(150 150 150);
    --color-blockquote: rgb(180 180 180);
    --color-figcaption: rgb(180 180 180);
    --color-table-header: rgb(200 240 240);
    --color-table-header-bg: rgb(30 30 30);
    --color-table-row-hover: rgb(40 40 40);

    --color-essay-title: rgb(220 220 220);
    --color-essay-year: rgb(150 150 200);
    --color-essay-blurb: rgb(195 195 195);
    --color-section-heading: rgb(210 210 210);
  }
}

/* Reset & Base Styles */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: var(--fs-base);
  color: var(--color-text);
  background-color: var(--color-bg);
}

body {
  font-family: var(--body-font);
  line-height: 1.6;
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--heading-font);
}
h2, h3, h4, h5, h6 {
  margin-bottom: 0.5em;
  line-height: 1.2;
}
h1 {
  font-size: var(--fs-h1);
}
h2 {
  font-size: var(--fs-h2);
}
h3 {
  font-size: var(--fs-h3);
}
h4 {
  font-size: var(--fs-h4);
}
h5 {
  font-size: var(--fs-h5);
}
h6 {
  font-size: var(--fs-h6);
}

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

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

p, details, table {
  margin-bottom: 1em;
}

summary {
  cursor: pointer;
}

table {
    border-collapse: collapse;
    border: var(--color-border) 1px solid;
}

th {
    background-color: var(--color-table-header-bg);
    color: var(--color-table-header);
    padding: 12px;
    text-align: left;
    font-weight: 600;
}

td {
    padding: 12px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: top;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover {
    background-color: var(--color-table-row-hover);
}

/* Base layout elements */

body > header {
  display: flex;
  justify-content: space-between;
  padding: 1rem 0;

  @media (max-width: 768px) {
    padding: 0;
  }

  h1, nav li {
    text-box-trim: trim-start;
    text-box-edge: cap alphabetic;
  }

  nav ul {
    list-style: none;
    display: flex;
    gap: 1rem;
    font-size: var(--fs-nav);
    text-transform: uppercase;

    @media (max-width: 768px) {
      flex-direction: column;
      align-items: end;
      gap: 0;
    }
  }
}

body > footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border-top: 1px solid var(--color-divider);
  padding-top: 1rem;

  color: var(--color-footer-text);
  font-size: var(--fs-footer-text);

  @media (max-width: 768px) {
    flex-direction: column;
    gap: 0;

    p {
      margin-bottom: 0;
    }
  }
}

/* Essay list */

.essay-list {
  --fs-essay-title: 1.1rem;
  --fs-essay-year: 0.85rem;
  --fs-essay-blurb: 0.95rem;

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

  > li {
    margin-bottom: 1rem;
  }

  .title {
    font-family: var(--heading-font);
    font-size: var(--fs-essay-title);
    color: var(--color-essay-title);
  }

  time {
    font-size: var(--fs-essay-year);
    color: var(--color-essay-year);

    &::before, &::after {
      display: inline;
    }
    &::before {
      content: "(";
    }
    &::after {
      content: ")";
    }
  }

  .blurb {
    font-size: var(--fs-essay-blurb);
    color: var(--color-essay-blurb);
    margin-top: 0.25rem;
  }
}

/* Specific page styles */

main#home {
  --padding-columns: 0 1rem;
  --padding-categories: 1.5rem;
  --fs-category-heading: 1.2rem;
  --fs-bio: 1rem;
  --fs-socials: 0.9rem;

  @media (max-width: 768px) {
    --padding-columns: 0.5rem;
    --padding-categories: 0.5rem;
  }

  display: grid;
  row-gap: 1rem;

  /*
    Would be nice to use row-rule: https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/CSSGapDecorations/explainer.md
    Until then we'll make do with this:
  */
  > section + section {
    border-top: 1px solid var(--color-divider);
    padding-top: 1rem;
  }


  .hero {
    display: grid;
    grid-template-columns: 120px 1fr 120px;
    gap: 1rem;
    align-items: start;

    img {
      width: 120px;
      height: 120px;
      border-radius: 50%;
      object-fit: cover;
    }

    .bio p {
      font-size: var(--fs-bio);
    }

    .socials {
      display: flex;
      flex-direction: column;
      gap: 0.5rem;
      align-items: end;
      font-size: var(--fs-socials);

      .icon {
        width: 2rem;
        height: 2rem;
        display: block;
      }
    }
  }

  .featured {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: auto repeat(1, auto) auto;
    row-gap: 1.5rem;
    column-gap: 2rem;

    .column {
      display: grid;
      grid-row: 1 / -1;
      grid-template-rows: subgrid;
      padding: var(--padding-columns);

      h2 {
        color: var(--color-section-heading);
      }
    }
  }

  .categories {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    grid-template-rows: auto repeat(2, auto) auto;
    row-gap: 1.5rem;
    column-gap: 1rem;
  }

  .category {
    display: grid;
    grid-row: 1 / -1;
    grid-template-rows: subgrid;
    border: 1px solid var(--color-border);
    padding: var(--padding-categories);
    border-radius: 6px;

    h2 {
      font-size: var(--fs-category-heading);
      color: var(--color-section-heading);
    }
  }

  .view-all {
    display: inline-block;
    font-weight: bold;
  }

  @media (max-width: 768px) {
    .hero {
      display: grid;
      grid-template-columns: 120px 1fr;
      grid-template-rows: auto 1fr;
      gap: 1rem;
      grid-template-areas:
        "headshot socials"
        "bio       bio";

      img {
        grid-area: headshot;
      }

      .socials {
        grid-area: socials;

        display: grid;
        grid-template-columns: repeat(2, max-content);
        grid-auto-rows: max-content;
        gap: 1rem;

        justify-items: center;
        align-items: center;
        align-self: center;
        justify-self: center;
      }

      .bio {
        grid-area: bio;
      }
    }

    .featured, .categories {
      display: block;
    }

    .category {
      border: 0;
    }
  }
}

main#post {
  --fs-figcaption: 0.95rem;

  .post-header {
    margin-bottom: 1.5rem;
  }

  h1, h2, h3, h4, h5, h6, p, blockquote, pre, ul, ol, dl, figure, .highlight {
    margin-bottom: 15px;
  }

  ins {
    text-decoration-color: var(--color-border);
  }

  img {
    max-width: 100%;
    vertical-align: middle;
  }

  ul, ol {
    margin-left: 30px;
  }
  li > ul, li > ol {
    margin-bottom: 0;
  }

  blockquote {
    color: var(--color-blockquote);
    border-left: 4px solid var(--color-border);
    padding-left: 15px;
    font-size: 18px;
    letter-spacing: -1px;
    font-style: italic;
  }
  blockquote > :last-child {
    margin-bottom: 0;
  }

  pre, code {
    font-size: 15px;
    border: 1px solid var(--color-border);
    border-radius: 3px;
  }
  code {
    padding: 1px 5px;
  }
  pre {
    padding: 8px 12px;
    overflow-x: auto;
  }
  pre > code {
    border: 0;
    padding-right: 0;
    padding-left: 0;
  }

  figure {
    display: block;
    max-width: 100%;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 1rem;

    img:only-of-type {
      display: block;
      border-radius: 4px;
      margin: 0 auto;
    }

    img {
      width: auto;
      height: auto;
    }

    &.multi-images {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      gap: 1rem;
    }

    @media (max-width: 768px) {
      &.multi-images {
        grid-template-columns: repeat(2, 1fr);
      }
    }

    figcaption {
      margin-top: 0.75rem;

      font-size: var(--fs-figcaption);
      color: var(--color-figcaption);
      text-align: center;
    }
  }
}

main#category {
  #blurb {
    font-style: italic;
  }
}
