/* RESET & VARS */

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

:root {
  /* Fluid Spacing */
  --half-pad: calc(var(--pad) * 0.5);
  --double-pad: calc(var(--pad) * 2);

  /* Common Colors */
  --green: hsl(160, 100%, 40%);
  --mid-green: hsl(160, 100%, 30%);
  --dark-grey: hsl(160, 40%, 16%);
  --deep-green: hsl(160, 100%, 10%);

  /* Light theme */
  --page-bg: hsl(160, 30%, 97%);
  --main-bg: white;
  --main-shadow: #00000008;
  --text-color: var(--dark-grey);
  --code-color: hsl(160, 40%, 30%);
  --code-bg: hsl(160, 10%, 97%);
  --link-color: var(--mid-green);
  --nav-link-hover-bg: hsl(160, 50%, 90%);
  --nav-link-border: hsl(160, 40%, 80%);
  --edit-link-color: var(--deep-green);
  --edit-link-bg: var(--green);
  --edit-link-border: #0003;
}

/* Dark theme */
@media (prefers-color-scheme: dark) {
  :root {
    --page-bg: hsl(160, 100%, 3%);
    --main-bg: hsl(200, 10%, 10%);
    --main-shadow: #0005;
    --text-color: hsl(160, 30%, 90%);
    --code-color: hsl(160, 10%, 75%);
    --code-bg: #000c;
    --link-color: var(--green);
    --nav-link-hover-bg: var(--dark-grey);
    --nav-link-border: #0003;
    --edit-link-color: var(--deep-green);
    --edit-link-bg: var(--green);
    --edit-link-border: #0003;
  }
}

@media(min-width: 801px) { /* Wide layout */
  :root {
    --pad: 2rem;
  }
}

@media(max-width: 800px) { /* Narrow layout */
  :root {
    --pad: 1rem;
  }
}

/* MAJOR LAYOUT ELEMENTS */

body {
  margin: 0;
  text-align: center;
  font-size: 16px;
  line-height: 1.5;
  font-family: system-ui, sans-serif;
  color: var(--text-color);
  background-color: var(--page-bg);

  /* Prevent Safari on iPhone from adjusting text size when the phone is turned to landscape */
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
}

main {
  display: inline-grid;
  padding: var(--pad);
  text-align: left;
  background: var(--main-bg);
  box-shadow: 0 .2em 1em var(--main-shadow);
}

@media(min-width: 801px) { /* Wide layout */
  main {
    grid-template:
      "header article"
      "aside article";
    grid-template-rows: auto 1fr; /* Pull the aside up towards the top */
    grid-template-columns: 10em minmax(0, 48em); /* Set the header/aside width explicitly, and shrink article to fit */
    gap: 0 var(--pad);
    margin: var(--pad);
    border-radius: 3px;
  }
}

@media(max-width: 800px) { /* Narrow layout */
  main {
    grid-template:
      "header"
      "article"
      "aside";
    grid-template-columns: minmax(0, 100%);
    width: 100%;
    padding-bottom: var(--double-pad);
    margin-bottom: var(--double-pad);
  }
}

header {
  grid-area: header;
  display: flex;
  gap: var(--half-pad);
}

@media(min-width: 801px) { /* Wide layout */
  header {
    flex-flow: column;
  }
}

@media(max-width: 800px) { /* Narrow layout */
  header {
    text-align: right;
    flex-flow: row;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--double-pad);
  }
}

@media(max-width: 800px) {
  a#logo {
    width: 7em;
  }
}

a#logo img {
  width: 100%;
  height: auto;
  border-radius: 1px; /* For consistency with <a> style */
  border-bottom: 5px solid var(--edit-link-border);
  background: var(--green);
}

nav {
  flex: 0 0 auto;
  display: inline-flex;
  flex-flow: column;
}

nav a {
  border-bottom: 5px solid transparent;
  font-weight: 700;
  font-size: 0.9em;
}

@media(min-width: 801px) { /* Wide layout */
  nav a {
    padding: .7rem 1rem .5rem;
  }
}

@media(max-width: 800px) { /* Narrow layout */
  nav a {
    align-self: end; /* Shrink the tappable area to just around the text */
    padding: .4rem .6rem .3rem;
    border-bottom-width: 4px;
  }
}

nav a:hover,
nav a:active,
nav a:focus {
  text-decoration: none;
  background: var(--nav-link-hover-bg);
  border-bottom-color: var(--nav-link-border);
}

a#edit {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  margin-bottom: var(--half-pad);
  border-bottom-color: var(--edit-link-border);
  color: var(--edit-link-color);
  background: var(--edit-link-bg);
}

@media(max-width: 800px) {
  a#edit img {
    order: -1;
  }
}


aside {
  grid-area: aside;
  display: flex;
  flex-flow: column;
  gap: var(--pad);
}

@media(min-width: 801px) {
  aside {
    margin-top: var(--pad);
  }
}

@media(max-width: 800px) {
  aside {
    flex-flow: row wrap;
    margin-top: var(--double-pad);
  }
}

@media(max-width: 800px) {
  aside section {
    flex: 1 1 15em;
  }
}

aside section h1 {
  margin: 0;
  border: none;
}

aside section ul {
  margin: 0;
  padding-left: 1em;
  word-break: break-word;
}

aside section li {
  margin-top: .15em;
}

article {
  grid-area: article;
}

article a {
  text-decoration: underline;
}

footer {
  margin: 0 0 var(--pad);
  text-wrap: balance;
  font-weight: 200;
}

footer a {
  display: inline-block;
}

footer p.cc0 img {
  vertical-align: -.3em;
}

footer a.initials {
  width: 40px;
  height: 40px;
  border-radius: 20px;
  background: var(--green);
}

/* MINOR ELEMENTS */

/* The tab title doubles as the page title */
/* This angers the validator, but 🤷 seems fine, come at me! */
title {
  display: block;
  margin-bottom: .5em;
  padding-bottom: .4em;
  border-bottom: 4px solid currentcolor;
  font-size: clamp(2em, 6vw, 3em);
  font-weight: 300;
  line-height: 1.1;
  text-wrap: balance;
}

article h1 { font-size: clamp(1.6em, 4vw, 2em); }
article h2 { font-size: clamp(1.4em, 3vw, 1.5em); }
article h3 { font-size: clamp(1.2em, 2.5vw, 1.25em); }

h1 { border-bottom: 3px solid currentcolor }
h2 { border-bottom: 2px solid currentcolor }

h1, h2, h3 {
  font-weight: 300;
  margin: 1.5em 0 .5em;
}

h2 {
  width: fit-content;
}

p {
  margin: 0 0 1.2em;
}

p:last-child {
  margin: 0;
}

img {
  vertical-align: middle; /* Remove default space under images */
}

a {
  color: var(--link-color);
  text-decoration: none;
  border-radius: 1px; /* This rounds the corners of the focus outline */
  outline-offset: 2px;
}

a:hover, a:active {
  text-decoration: underline;
  opacity: .9;
}

a:focus {
  outline: solid 3px var(--link-color);
}

code {
  padding: .15em .3em;
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  line-height: 1.3;
  background: var(--code-bg);
  color: var(--code-color);
}

pre {
  padding: .6em 0;
  padding-right: 0;
  border-radius: 6px;
  background: var(--code-bg);
}

pre code {
  display: block;
  max-width: 100%;
  padding: 0 1rem;
  overflow-x: scroll;
  background: none;
}

blockquote {
  margin: 0;
  padding-left: .5em;
  border-left: 2px solid currentcolor;
}

ul {
  margin: 1em 0;
  list-style-type: square;
}

li + li {
  margin-top: .5em;
}

li a {
  display: block; /* Makes outlines look nicer */
}

/* When a list item contains a link, color the bullet too */
li:has(> a)::marker {
  color: var(--link-color);
}
