/* Self-hosted IBM Plex fonts */
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/assets/fonts/ibm-plex-mono-400.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("/assets/fonts/ibm-plex-mono-400-italic.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/assets/fonts/ibm-plex-mono-700.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Serif";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/assets/fonts/ibm-plex-serif-600.woff2") format("woff2");
}

    :root {
  /* === Type scale from https://utopia.fyi/type/calculator/ === */
  --step--2: clamp(0.7813rem, 0.7747rem + 0.0326vw, 0.8rem);
  --step--1: clamp(0.9375rem, 0.9158rem + 0.1087vw, 1rem);
  --step-0: clamp(1.125rem, 1.0815rem + 0.2174vw, 1.25rem);
  --step-1: clamp(1.35rem, 1.2761rem + 0.3696vw, 1.5625rem);
  --step-2: clamp(1.62rem, 1.5041rem + 0.5793vw, 1.9531rem);
  --step-3: clamp(1.944rem, 1.771rem + 0.8652vw, 2.4414rem);
  --step-4: clamp(2.3328rem, 2.0827rem + 1.2504vw, 3.0518rem);
  --step-5: clamp(2.7994rem, 2.4462rem + 1.7658vw, 3.8147rem);

  /* === Space scale from https://utopia.fyi/space/calculator/ === */
  --space-3xs: clamp(0.3125rem, 0.3125rem + 0vw, 0.3125rem);
  --space-2xs: clamp(0.5625rem, 0.5408rem + 0.1087vw, 0.625rem);
  --space-xs: clamp(0.875rem, 0.8533rem + 0.1087vw, 0.9375rem);
  --space-s: clamp(1.125rem, 1.0815rem + 0.2174vw, 1.25rem);
  --space-m: clamp(1.6875rem, 1.6223rem + 0.3261vw, 1.875rem);
  --space-l: clamp(2.25rem, 2.163rem + 0.4348vw, 2.5rem);
  --space-xl: clamp(3.375rem, 3.2446rem + 0.6522vw, 3.75rem);
  --space-2xl: clamp(4.5rem, 4.3261rem + 0.8696vw, 5rem);
  --space-3xl: clamp(6.75rem, 6.4891rem + 1.3043vw, 7.5rem);

  --flow-space: var(--space-s);

  /* === Fonts === */
  --font-body: "IBM Plex Mono", ui-monospace, monospace;
  --font-heading-serif: "IBM Plex Serif", Georgia, serif;

  /* === Colors (theme-independent) === */
  --color-dark: #353d4d;
  --color-light: #C7E2F6;

  /* === Sizing === */
  --accent-width: 1px;
  --accent-width-heavy: 3px;
  --blockquote-border: 4px;
  --radius: 10px;

  /* Carried from current site */
  --max-book-width: 200px;
  --caption-size: var(--step-0);
  --post-title-size: var(--step-2);

  /* SVG icon for external links */
  --icon-external-link: url('data:image/svg+xml,\
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">\
  <g style="stroke:currentColor;stroke-width:1">\
    <line x1="5" y1="5" x2="5" y2="14" />\
    <line x1="14" y1="9" x2="14" y2="14" />\
    <line x1="5" y1="14" x2="14" y2="14" />\
    <line x1="5" y1="5" x2="9" y2="5" />\
    <line x1="10" y1="2" x2="17" y2="2" />\
    <line x1="17" y1="2" x2="17" y2="9" />\
    <line x1="10" y1="9" x2="17" y2="2" style="stroke-width:1.5" />\
  </g>\
</svg>');
}

/* === Colors: Default (fallback when data-theme not yet set) === */
:root {
  --bg-primary: #C7E2F6;
  --bg-card: #C7E2F6;
  --text-color: black;
  --text-muted: black;
  --accent-line: black;
  --accent-line-heavy: black;
  --link-color: black;
  --link-hover-color: black;
  --link-hover-bg: #fff066;
  --image-link-hover-outline: var(--color-dark);
}

/* === Colors: Light mode === */
[data-theme="light"] {
  --bg-primary: #C7E2F6;
  --bg-card: #C7E2F6;
  --text-color: black;
  --text-muted: black;
  --accent-line: black;
  --accent-line-heavy: black;
  --link-color: black;
  --link-hover-color: black;
  --link-hover-bg: #fff066;
  --image-link-hover-outline: var(--color-dark);
}

/* === Colors: Dark mode === */
[data-theme="dark"] {
  --bg-primary: #353d4d;
  --bg-card: #353d4d;
  --text-color: white;
  --text-muted: white;
  --accent-line: white;
  --accent-line-heavy: white;
  --link-color: white;
  --link-hover-color: black;
  --link-hover-bg: #fff066;
  --image-link-hover-outline: var(--color-light);
}

    /* Reset and set default element styles */
html {
  scroll-behavior: smooth;
  overflow-y: scroll;
}

@view-transition {
  navigation: auto;
}

@supports (scrollbar-gutter: stable) {
  html {
    overflow-y: auto;
    scrollbar-gutter: stable;
  }
}

:where(body, h1, h2, h3, h4, h5, h6) {
  margin: 0;
  padding: 0;
}

:where(h1, h2) {
  line-height: 1.2;
  text-align: center;
  text-wrap: balance;
}

:where(h1) {
  font-size: var(--step-4);
  margin-block-end: var(--space-m);
}

:where(h2) {
  font-size: var(--step-2);
}

:where(h3) {
  font-size: var(--step-1);
}

:where(article h2) {
  font-size: var(--step-1);
  text-align: left;
  margin-block-end: var(--space-2xs);
}

:where(hr) {
  border: none;
  margin-block: var(--space-m);
}

:where(ol, ul) {
  margin-block: var(--space-xs);
  padding: 0;
}

:where(ol:not([class]), ul:not([class])) {
  margin-inline-start: var(--space-l);
}

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

/* Inherit fonts for inputs and buttons */
:where(input, button, textarea, select) {
  font: inherit;
}

:where(p) {
  margin-block: 0 var(--space-s);
  text-wrap: pretty;
}

/* Default img to handle fluid images */
:where(img) {
  border-radius: var(--radius);
  display: block;
  max-width: 100%;
}
:where(img[width]) {
  width: auto;
}
:where(img[width][height]) {
  height: auto;
}
:where(img:not([class])) {
  margin-block-end: var(--space-s);
}

/* Links */
:where(a) {
  color: var(--link-color);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: background-color 0.15s ease;
}
:where(a:hover, a:focus) {
  color: var(--link-hover-color);
  background-color: var(--link-hover-bg);
  text-decoration: none;
}

/* Lighter dashed outline on linked images to indicate clickability */
:where(a:has(img)) {
  text-decoration: none;
}
:where(a:has(img) img) {
  outline: 1px dashed var(--accent-line);
}
:where(a:has(img):hover img, a:has(img):focus img) {
  outline: 2px dashed var(--accent-line);
}

/* Indicate links to external sites */
a[href^="https"]:not(:has(img)):not(book-item a):not(.social-links a):not(.footer-meta a)::after {
  content: "\2060"; /* word joiner prevents orphaned icon */
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  margin-inline-start: 0.25em;
  vertical-align: -0.1em;
  background-color: currentColor;
  -webkit-mask: var(--icon-external-link) no-repeat center / contain;
  mask: var(--icon-external-link) no-repeat center / contain;
}

blockquote {
  border-inline-start: var(--blockquote-border) solid var(--accent-line-heavy);
  font-style: italic;
  font-size: var(--step-0);
  margin: var(--space-m) 0;
  padding: var(--space-s) var(--space-m);
}

@media (prefers-reduced-motion: reduce) {
  @view-transition {
    navigation: none;
  }
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

    /*
  Page structure:
   1 column grid, forcing footer to bottom
*/
body {
  background-color: var(--bg-primary);
  color: var(--text-color);
  display: grid;
  grid-template-rows: auto 1fr auto;
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.6;
  margin-inline: auto;
  max-width: 1800px;
  min-height: 100vh;
  min-height: 100dvh;
}

/* === Header === */
header {
  padding: var(--space-m) var(--space-m) var(--space-s);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-m);
  position: relative;
}

/* === Site name === */
.site-name {
  position: absolute;
  left: var(--space-m);
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--step-1);
  font-weight: 700;
  text-decoration: none;
  color: var(--text-color);
  white-space: nowrap;
}

.site-name:hover,
.site-name:focus {
  color: black;
}

@media (max-width: 699px) {
  .site-name {
    position: static;
    transform: none;
    text-align: center;
  }
}

/* === Hamburger menu === */
.menu-toggle {
  position: absolute;
  left: var(--space-m);
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-3xs);
  color: var(--text-color);
  display: grid;
  place-items: center;
  z-index: 20;
}
.menu-toggle:hover {
  opacity: 0.6;
}
.menu-toggle:focus-visible {
  opacity: 0.6;
  outline: 2px solid var(--text-color);
  outline-offset: 2px;
}
.menu-toggle svg {
  width: 1.5rem;
  height: 1.5rem;
}

/* Hide hamburger on larger screens */
@media (min-width: 700px) {
  .menu-toggle {
    display: none;
  }
}

/* Hide nav on mobile by default, show when open */
@media (max-width: 699px) {
  #main-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--accent-line);
    padding: var(--space-m);
    z-index: 15;
  }
  #main-nav.open {
    display: block;
  }
  #main-nav .listolinks {
    flex-direction: column;
    align-items: center;
    gap: var(--space-s);
  }
}

/* === Theme toggle === */
.theme-toggle {
  position: absolute;
  right: var(--space-m);
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-3xs);
  color: var(--text-color);
  display: grid;
  place-items: center;
}
.theme-toggle:hover {
  opacity: 0.6;
}
.theme-toggle:focus-visible {
  opacity: 0.6;
  outline: 2px solid var(--text-color);
  outline-offset: 2px;
}
.theme-toggle svg {
  width: 1.25rem;
  height: 1.25rem;
}

.theme-panel {
  position: absolute;
  right: var(--space-m);
  top: 100%;
  background: var(--bg-card);
  border: var(--accent-width) solid var(--accent-line);
  border-top: none;
  padding: var(--space-2xs) var(--space-s);
  display: flex;
  gap: var(--space-s);
  z-index: 10;
  opacity: 0;
  transform: translateY(-0.25rem);
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
}
.theme-panel.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.theme-panel label {
  display: flex;
  align-items: center;
  gap: var(--space-3xs);
  cursor: pointer;
  font-size: var(--step--1);
  font-family: var(--font-body);
  padding: var(--space-3xs) var(--space-2xs);
  border-bottom: var(--accent-width) solid transparent;
  transition: border-color 150ms ease;
}
.theme-panel label:hover,
.theme-panel label:focus-within {
  border-bottom-color: var(--accent-line);
}

.theme-panel input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.theme-panel svg {
  width: 1rem;
  height: 1rem;
  color: var(--text-color);
}

.skip-nav-link {
  position: fixed;
  top: 0;
  left: var(--space-xs);
  padding: 5px;
  transform: translateY(-100%);
  transition: transform 300ms ease-in;
  z-index: 100;
  background: var(--bg-primary);
}

.skip-nav-link:focus {
  transform: translateY(0);
}

/* Highlight the nav link of the current page */
nav a[aria-current="page"] {
  border-bottom: 1px solid var(--accent-line-heavy);
  text-decoration: none;
}

.stripe-buy-button {
  display: flex;
  justify-content: center;
  margin: var(--space-s) 0;
}

/*
  Content structure
  - named grid lines for layout
  - for varying content widths within a page
*/
.content {
  --gap: clamp(0.25rem, 3vw, 1rem);
  --full: minmax(var(--gap), 1fr);
  --feature: minmax(0, 5rem);
  --popout: minmax(0, 2rem);
  --central: min(65ch, 100% - var(--gap) * 2);

  display: grid;
  grid-template-columns:
    [full-start] var(--full)
    [feature-start] var(--feature)
    [popout-start] var(--popout)
    [central-start] var(--central) [central-end]
    var(--popout) [popout-end]
    var(--feature) [feature-end]
    var(--full) [full-end];
  max-width: 100vw;
  place-content: start center;
}
.full {
  grid-column: full;
}
.feature {
  grid-column: feature;
}
.popout {
  grid-column: popout;
}
.central {
  grid-column: central;
}

/*
  Home page grid:
  - 1 column on small screens
  - 2 columns on medium & large via media query
*/
.homegrid {
  display: grid;
  grid-template-columns: 1fr;
  column-gap: var(--space-l);
  row-gap: 0;
  padding-inline: 0.25rem;
  padding-block: 0;
  place-content: center;
}

@media (min-width: 700px) {
  .homegrid {
    grid-template-columns: repeat(2, 1fr);
    padding-inline: var(--space-m);
  }
}
@media (min-width: 1250px) {
  #alltags .listolinks {
    margin-inline: auto;
    max-width: 70%;
  }
}

/* Home page secondary grid: adds bottom padding to homegrid */
.homegrid2 {
  padding-block-end: var(--space-s);
}

/* === Card styling === */
.card {
  background-color: var(--bg-card);
  padding-inline: var(--space-2xs);
  padding-block: 0;
}

@media (min-width: 700px) {
  .card {
    padding-inline: var(--space-m);
    padding-block: 0;
    position: relative;
  }
  /* Left accent — 75% height, from bottom */
  .card::before {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    height: 75%;
    width: 0;
    border-left: 1px solid var(--accent-line);
  }
  .homegrid .card:nth-child(3),
  .homegrid .card:nth-child(4) {
    padding-block-start: var(--space-m);
  }
  /* Bottom accent — 75% width, from left */
  .card::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 75%;
    height: 0;
    border-bottom: 1px solid var(--accent-line);
  }
}

.card img {
  margin-block: var(--space-xs);
  margin-inline: auto;
}

.card lite-youtube {
  margin-block-end: var(--space-xs);
}

/* === Project image link hover === */
.image-link:hover,
.image-link:focus {
  background-color: transparent;
}
.image-link:hover img,
.image-link:focus img {
  outline: 3px dashed var(--image-link-hover-outline);
}

/* === Section dividers === */
.section-divider {
  margin-block: 0;
  padding-block-start: var(--space-m);
  padding-inline: var(--space-m);
}

/* Top navigation links & list of all tags in footer */
.listolinks {
  display: flex;
  flex-wrap: wrap;
  font-size: var(--step-0);
  justify-content: space-around;
  list-style: none;
  text-align: center;
}
.listolinks a {
  padding: 0 var(--space-3xs);
}
.listolinks li {
  margin: var(--space-3xs) var(--space-2xs);
}

nav .listolinks {
  justify-content: center;
  gap: var(--space-s);
}

/* Heading font variant */
.heading-serif {
  font-family: var(--font-heading-serif);
  font-weight: 600;
  margin-block-end: var(--space-s);
}

/* === Blog date / meta === */
.blogdate {
  font-size: var(--step--1);
  color: var(--text-muted);
  margin-block-end: var(--space-s);
}

/* === Bookshelf === */
.bklist {
  display: grid;
  font-size: var(--step-0);
  gap: var(--space-l);
  grid-template-columns: repeat(auto-fit, minmax(var(--max-book-width), 1fr));
  margin-block-start: var(--space-l);
  place-items: start center;
}

book-item {
  align-items: center;
  display: grid;
  grid-template-rows: auto auto auto;
  justify-items: center;
  text-align: center;
}
book-item a {
  font-weight: bold;
}
book-item a img {
  height: auto;
  margin-block-end: 0.5em;
  width: 180px;
}

.bookyear {
  margin-block-start: var(--space-m);
  margin-inline: auto;
  width: 90%;
}
.bookyears a {
  margin-inline: var(--space-3xs);
}

/* Image captions */
.caption {
  font-size: var(--caption-size);
  font-style: italic;
  margin-block-start: var(--space-3xs);
  text-align: center;
}

/* Table of contents and email comment boxes */
.table-of-contents,
.email-comment {
  margin: var(--space-m) auto;
  padding: var(--space-m);
  width: fit-content;
  background-color: var(--bg-card);
  border: var(--accent-width) solid var(--accent-line);
  border-radius: var(--radius);
}
.table-of-contents h2 {
  text-align: center;
}

/* Blockquote uses popout column in content grid */
blockquote {
  grid-column: popout;
}

/* Position the copy code button */
pre:has(code) {
  position: relative;
  margin: 5px 0;
  padding: 1.75rem 0 1.75rem 1rem;
}

pre:has(code) button {
  position: absolute;
  top: 3px;
  right: 3px;
  border-radius: calc(var(--radius) / 2);
  font-size: var(--step--2);
}

/*
  "scroll to top" link
*/
.stt {
  position: fixed;
  right: var(--space-s);
  bottom: var(--space-s);
  width: 2.5rem;
  height: 2.5rem;
  display: grid;
  place-items: center;
  border-top: var(--accent-width) solid var(--accent-line);
  border-left: var(--accent-width) solid var(--accent-line);
  color: var(--text-color);
  text-decoration: none;
  font-size: var(--step-0);
  transition: opacity 0.15s ease;
}
.stt:hover {
  opacity: 0.6;
  background-color: transparent;
  color: var(--text-color);
}
.stt:focus-visible {
  outline: 2px solid var(--text-color);
  outline-offset: 2px;
  background-color: transparent;
}

.taglist {
  display: flex;
  flex-wrap: wrap;
  font-size: var(--step--1);
  font-style: italic;
  list-style: none;
  margin-block: 0 var(--space-xl);
  padding: 0;
}
.taglist::before {
  content: "Tags:\00a0";
}

.postmeta {
  text-align: center;
}
.postmeta .taglist {
  justify-content: center;
  margin-block-end: var(--space-s);
}
.postmeta img {
  margin-block-end: var(--space-2xs);
}

    footer {
  padding-block-start: 0;
  margin-block-start: 0;
}

#alltags {
  margin-inline: var(--space-m);
}

@media (min-width: 700px) {
  footer {
    padding-block-start: var(--space-m);
  }
}

footer .footer-meta {
  padding-block: var(--space-xs);
  margin-block-start: var(--space-m);
  text-align: center;
  font-size: var(--step--1);
  color: var(--text-color);
}

/* Social icons appearing in the footer of every page */
.social-links {
  display: flex;
  flex-wrap: wrap;
  list-style: none;
  margin-block: var(--space-m);
  justify-content: center;
  gap: var(--space-m);
  font-size: var(--step--1);
}

.social-links a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3xs);
  padding: var(--space-3xs) var(--space-2xs);
}
.social-links svg {
  width: 1.25em;
  height: 1.25em;
}

    /* Utility classes */

.bold {
  font-weight: bold;
}

.flow > * + * {
  margin-block-start: var(--flow-space);
}

.hidden {
  display: none;
}

.visually-hidden {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.ital {
  font-style: italic;
}

.list-none {
  list-style: none;
}

.round-img {
  clip-path: circle(50%);
}

.strikethrough {
  text-decoration: line-through;
}

.text-center {
  text-align: center;
}

.text-left {
  text-align: left;
}

.text-right {
  text-align: right;
}

.no-bot-margin {
  margin-block-end: 0;
}

.parenthetical {
  font-size: var(--step--1);
  font-weight: normal;
  font-style: italic;
}

/* Accent line utilities — single edges only */
.border-top {
  border-top: var(--accent-width) solid var(--accent-line);
}

.border-bottom {
  border-bottom: var(--accent-width) solid var(--accent-line);
}

.border-left {
  border-left: var(--accent-width) solid var(--accent-line);
  padding-left: var(--space-s);
}