/* Colors follow the system light or dark setting. The header toggle can
   override it by setting data-theme on <html>. */
:root {
  color-scheme: light dark;
  --bg: light-dark(#f6f3ec, #0d0f14);
  --ink: light-dark(#1f1d1a, #e6e2d8);
  --muted: light-dark(#4e4943, #aaa59a);
  --line: light-dark(#dcd6c9, #272b33);
  --sand: light-dark(#cdc5b4, #3a3b36);
  --stone: light-dark(#7a7468, #848075);
  --accent: light-dark(#963522, #e57a61);
  --code-bg: light-dark(#ece8de, #181b21);
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --measure: 38rem;
  --col: 10rem; /* label column in the project and contact lists */
  --rhythm: 3rem; /* space between sections */
  --gap: 2rem; /* space under a page heading */
  --indent: 1.4rem; /* quotes and lists */
  --radius: 3px;
  --tap: 2.75rem; /* smallest hit area on touch screens */
  --label-size: 0.75rem;
  --label-weight: 500;
  --label-spacing: 0.12em;
  --shade: color-mix(in srgb, var(--ink) 14%, transparent);
}

:root[data-theme='light'] {
  color-scheme: light;
}

:root[data-theme='dark'] {
  color-scheme: dark;
}

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

html {
  background: var(--bg);
  scroll-padding-top: 2rem;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0 auto;
  max-width: calc(var(--measure) + 3rem);
  padding: 0 1.5rem;
  color: var(--ink);
  font: 1.1875rem/1.6 var(--serif);
  text-rendering: optimizeLegibility;
}

a {
  color: var(--ink);
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

a:hover {
  color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  scroll-margin-block: 1rem;
  border-radius: var(--radius);
}

/* Small links get a 44px tall hit area without moving or restyling the text,
   so focus rings still hug the text. */
.top a,
.bottom a,
.contact a,
.pager a,
.more a,
.lost a {
  position: relative;
}

.top a::after,
.bottom a::after,
.contact a::after,
.pager a::after,
.more a::after,
.lost a::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: max(100%, var(--tap));
  height: max(100%, var(--tap));
  transform: translate(-50%, -50%);
}

h1,
h2,
h3 {
  font-weight: 500;
  line-height: 1.2;
  text-wrap: balance;
}

h1 {
  margin: 0.4rem 0 0.8rem;
  font-size: clamp(2.2rem, 7vw, 3.2rem);
  letter-spacing: -0.02em;
}

/* The one label style: small sans capitals. */
.label,
main > section > h2,
time,
.top nav,
.bottom,
.prose th,
.tag {
  font-family: var(--sans);
  font-size: var(--label-size);
  font-weight: var(--label-weight);
  letter-spacing: var(--label-spacing);
  text-transform: uppercase;
  color: var(--muted);
}

main > section > h2 {
  margin: 0 0 0.9rem;
}

main > section > h2::before {
  content: '';
  display: inline-block;
  width: 0.45rem;
  height: 0.45rem;
  margin-right: 0.7rem;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 0.08em;
}

.label {
  margin: 0;
}

.lede {
  margin: 0;
  max-width: 28rem;
  font-size: 1.25rem;
  line-height: 1.55;
  color: var(--muted);
  text-wrap: balance;
}

.quiet {
  color: var(--muted);
}

.skip {
  position: absolute;
  left: -999rem;
}

.skip:focus {
  left: 1rem;
  top: 1rem;
  padding: 0.4rem 0.8rem;
  background: var(--bg);
}

/* Header and footer */
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  padding: 1.25rem 0;
}

.top a {
  text-decoration: none;
}

.name {
  font-size: 1.05rem;
}

.top nav {
  display: flex;
  align-items: center;
  gap: 1.4rem;
  padding: 0.5rem 0;
}

/* Theme toggle: a half-filled circle. Hidden until the script enables it. */
.theme {
  position: relative;
  display: grid;
  place-items: center;
  width: 1rem;
  height: 1rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.theme:hover {
  color: var(--accent);
}

.theme::after {
  content: '';
  position: absolute;
  inset: 50% auto auto 50%;
  width: var(--tap);
  height: var(--tap);
  transform: translate(-50%, -50%);
}

.theme svg {
  width: 100%;
  height: 100%;
}

.theme circle {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
}

.theme path {
  fill: currentColor;
}

/* Chrome links (header nav, footer): muted, no underline, accent on hover. */
.top nav a,
.bottom a {
  color: var(--muted);
  text-decoration: none;
}

.top nav a:hover,
.bottom a:hover {
  color: var(--accent);
}

.top nav a[aria-current] {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 0.6em;
}

.bottom {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: var(--rhythm);
  padding: 1.25rem 0 2rem;
  border-top: 1px solid var(--line);
}

.bottom p {
  margin: 0;
}

.bottom p:last-child {
  margin-left: auto;
}

.seal {
  width: 1.4rem;
  height: 1.4rem;
}

.seal-bg {
  fill: var(--accent);
}

.seal-mark {
  fill: none;
  stroke: var(--bg);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Sections */
main > section {
  margin: var(--rhythm) 0;
}

.hero {
  margin-top: 1.5rem;
}

.page-head {
  margin: 1.5rem 0 var(--gap);
}

/* The sand garden fills the window behind the page and stays put while
   the text scrolls over it. It is faint everywhere, and fainter still
   behind the text column, so the words always come first. Its height uses
   the largest window size (lvh) so phones do not re-size it as the address
   bar slides away. */
.garden {
  position: fixed;
  inset: 0 auto auto 0;
  z-index: -1;
  width: 100%;
  height: 100vh;
  height: 100lvh;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.4s ease;
  /* a crisp edge just outside the text column, not a long fade */
  mask-image: linear-gradient(
    to right,
    #000 calc(50% - var(--measure) / 2 - 2rem),
    rgb(0 0 0 / 0.5) calc(50% - var(--measure) / 2 - 1.5rem),
    rgb(0 0 0 / 0.5) calc(50% + var(--measure) / 2 + 1.5rem),
    #000 calc(50% + var(--measure) / 2 + 2rem)
  );
}

.garden.garden-ready {
  opacity: 0.62;
}

.garden.garden-ready.garden-night {
  opacity: 0.5;
}

/* With no margins beside the text, the whole scene sits under it. */
@media (max-width: 60rem) {
  .garden {
    mask-image: none;
  }

  .garden.garden-ready {
    opacity: 0.22;
  }

  .garden.garden-ready.garden-night {
    opacity: 0.22;
  }
}

.ripples {
  flex: none;
  width: 2.25rem;
  height: 2.25rem;
  fill: none;
  stroke: var(--stone);
  stroke-width: 1.1;
  stroke-linecap: round;
}

.ripples circle {
  fill: var(--accent);
  stroke: none;
}

/* Lists */
.projects,
.posts,
.contact {
  margin: 0;
  padding: 0;
  list-style: none;
}

.projects li,
.posts li {
  border-top: 1px solid var(--line);
}

.projects li:last-child,
.posts li:last-child {
  border-bottom: 1px solid var(--line);
}

/* A list that ends the page lets the footer rule close it. */
main > .posts:last-child li:last-child {
  border-bottom: 0;
}

.projects a,
.posts a {
  display: grid;
  gap: 0.1rem 1.5rem;
  padding: 0.7rem 0;
  text-decoration: none;
}

.projects a {
  grid-template-columns: var(--col) 1fr;
  align-items: baseline;
}

.project-name {
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 0.92rem;
}

.project-name::after {
  content: ' ↗';
  color: var(--muted);
}

.project-desc,
.post-desc {
  text-wrap: pretty;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.5;
}

/* Icon and date line up with the title's first line at every width. */
.posts a {
  grid-template-columns: auto 1fr auto;
  align-items: start;
  padding: 0.95rem 0; /* room for the ripple mark above the title line */
}

.posts .ripples {
  margin-top: calc((1.2rem * 1.3 - 2.25rem) / 2); /* centred on the title line */
}

.post-text {
  display: grid;
  gap: 0.15rem;
}

.post-title {
  font-size: 1.2rem;
  line-height: 1.3;
}

.projects a:hover .project-desc,
.posts a:hover .post-desc {
  color: var(--ink);
}

.posts time {
  white-space: nowrap;
  line-height: calc(1.2rem * 1.3);
}

.more {
  margin: 1.2rem 0 0;
}

.tag {
  padding: 0.1rem 0.4rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  line-height: normal;
  color: var(--accent);
  vertical-align: 0.15em;
}

.contact {
  margin-top: 1.4rem;
}

.contact li {
  display: grid;
  grid-template-columns: var(--col) 1fr;
  column-gap: 1.5rem;
  align-items: baseline;
  padding: 0.5rem 0;
}

.contact a {
  justify-self: start;
}

/* Long-form text */
.prose > :first-child {
  margin-top: 0;
}

.prose > :last-child {
  margin-bottom: 0;
}

.prose p,
.prose ul,
.prose ol,
.prose pre,
.prose blockquote,
.prose .table-scroll,
.prose figure {
  margin: 0 0 1.4rem;
}

.prose h2 {
  margin: 2.6rem 0 0.9rem;
  font-size: 1.55rem;
}

.prose h3 {
  margin: 2rem 0 0.7rem;
  font-size: 1.25rem;
}

.prose ul,
.prose ol {
  padding-left: var(--indent);
}

.prose li {
  margin: 0.3rem 0;
}

.prose li::marker {
  color: var(--muted);
}

.prose blockquote {
  padding-left: var(--indent);
  border-left: 2px solid var(--accent);
  color: var(--muted);
  font-style: italic;
}

.prose code {
  padding: 0.1em 0.35em;
  border-radius: var(--radius);
  background: var(--code-bg);
  font-family: var(--mono);
  font-size: 0.85em;
}

/* The padding sits on the code so it holds on both sides when scrolled.
   A soft shade at an edge, and a thin scrollbar, show there is more. */
.prose pre {
  overflow-x: auto;
  padding: 0;
  border-radius: var(--radius);
  background:
    linear-gradient(to right, var(--code-bg) 40%, transparent) left / 2rem 100% no-repeat local,
    linear-gradient(to left, var(--code-bg) 40%, transparent) right / 2rem 100% no-repeat local,
    linear-gradient(to right, var(--shade), transparent) left / 0.75rem 100% no-repeat scroll,
    linear-gradient(to left, var(--shade), transparent) right / 0.75rem 100% no-repeat scroll,
    var(--code-bg);
  line-height: 1.55;
  tab-size: 4;
  scrollbar-width: thin;
  scrollbar-color: var(--stone) transparent;
}

.prose pre::-webkit-scrollbar {
  height: 6px;
}

.prose pre::-webkit-scrollbar-thumb {
  border-radius: var(--radius);
  background: var(--stone);
}

.prose pre code {
  display: block;
  width: max-content;
  min-width: 100%;
  padding: 1rem 1.2rem;
  border-radius: 0;
  background: none;
}

.prose img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

.prose hr {
  width: 4rem;
  margin: 2.6rem 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.prose .table-scroll {
  overflow-x: auto;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
}

.prose th,
.prose td {
  padding: 0.45rem 0.9rem 0.45rem 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
}


/* Pager titles are content links: ink with the accent underline.
   The label above them is an inline-block, so it is not underlined. */
.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-top: var(--rhythm);
}

.pager a {
  justify-self: start;
}

.pager a:last-child {
  justify-self: end;
  text-align: right;
}

.pager .label {
  display: inline-block;
  width: 100%;
  margin-bottom: 0.3rem;
}

@media (max-width: 34rem) {
  :root {
    --rhythm: 2.5rem;
  }

  body {
    font-size: 1.0625rem;
  }

  .top {
    padding: 1rem 0;
  }

  .top nav {
    gap: 1.1rem;
  }


  .projects a {
    grid-template-columns: 1fr;
  }

  .posts a {
    grid-template-columns: auto 1fr;
  }

  .posts time {
    grid-column: 2;
    margin-top: 0.6rem;
    line-height: inherit;
  }

  .contact li {
    grid-template-columns: 5.5rem 1fr;
    column-gap: 0;
    padding: 0.6rem 0;
  }
}

.label .tag {
  vertical-align: baseline;
}

.prose tbody tr:last-child td {
  border-bottom: 0;
}

/* Red is kept for the seal, hover and focus, so it keeps its weight. */
main > section > h2::before {
  content: none;
}

a {
  text-decoration-color: var(--stone);
}

.top nav a[aria-current] {
  text-decoration-color: var(--ink);
  text-underline-offset: 0.5em;
}

.project-name::after {
  content: none;
}

/* The seal closes the page, small, after the name. */
.bottom .seal {
  order: 1;
  width: 1.1rem;
  height: 1.1rem;
}

.bottom p:last-child {
  order: 2;
}
