:root {
  color-scheme: light dark;
  --paper: light-dark(#fdfdfa, #080808);
  --ink: light-dark(#20211f, #f6f6f4);
  --muted: light-dark(#555851, #c6c6c4);
  --line: light-dark(#d7d8d2, #606060);
  --link: light-dark(#2545a3, #a9c1ff);
  --visited: light-dark(#60437d, #d1b5ed);
  --matrix-accent: light-dark(#10602c, #85ffa1);
  background: var(--paper);
}

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

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

[hidden] {
  display: none !important;
}

body {
  max-width: 40.4375rem;
  margin: 0 auto;
  padding: clamp(1.5rem, 5vw, 2.625rem) clamp(1rem, 5vw, 1.5rem);
  color: var(--ink);
  font-family: "Times New Roman", Times, serif;
  font-size: 1rem;
  line-height: 1.618;
  overflow-wrap: break-word;
  position: relative;
  isolation: isolate;
}

h1,
h2,
p,
figure,
ul {
  margin: 0;
}

h1 {
  font-size: 1.625rem;
  font-weight: 400;
  line-height: 1.236;
}

h2 {
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.45;
}

a {
  color: var(--link);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
}

a:visited {
  color: var(--visited);
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 3px;
}

.reader-controls {
  display: flex;
  gap: 0.25rem;
}

.reader-controls button {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  font: inherit;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 2px;
  cursor: pointer;
}

.reader-controls button:is(:hover, :focus-visible) {
  color: var(--ink);
  border-color: var(--line);
}

.swatch {
  width: 1rem;
  height: 1rem;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: linear-gradient(to right, currentColor 50%, transparent 50%);
}

.columns {
  display: grid;
  grid-template-columns: 7.5rem minmax(0, 1fr);
  column-gap: 2rem;
  align-items: baseline;
}

.profile {
  align-items: start;
  row-gap: 1.125rem;
}

.portrait {
  grid-row: span 2;
  position: relative;
}

.portrait img {
  display: block;
  width: 100%;
  height: auto;
}

body:has(#matrix-rain:not([hidden])) .portrait::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url("./giacomo-matrix.png") center / 100% 100% no-repeat;
  pointer-events: none;
}

.dateline {
  margin-top: 0.625rem;
  color: var(--muted);
}

.entry-meta {
  display: inline-block;
  margin-inline-start: 0.4rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.index,
.note-footer {
  margin-top: 2.75rem;
}

.note-footer {
  padding-top: 1.75rem;
  border-top: 1px solid var(--line);
}

.index section + section {
  margin-top: 2.5rem;
}

.now-list,
.now-list ul {
  padding-inline-start: 1.25em;
}

.archive-link {
  margin-top: 1em;
}

.entries {
  padding: 0;
  list-style: none;
}

.entries li + li {
  margin-top: 1.125rem;
}

.archive {
  margin-top: 1.625rem;
}

.entries p {
  margin-top: 0.2rem;
  color: var(--muted);
}

.appearances h3 {
  margin: 0;
  font-size: 1rem;
}

.appearances details {
  margin-top: 1rem;
}

.appearances summary {
  font-weight: 700;
  cursor: pointer;
}

.appearances ul,
.appearances li + li {
  margin-top: 0.5rem;
}

.links,
.social-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.25rem;
}

.links {
  flex: 1 1 11rem;
  overflow-wrap: anywhere;
}

.home-footer {
  margin-top: 3.5rem;
}

.home-footer .footer-row {
  grid-column: 2;
}

.footer-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1.25rem;
}

body:has(#matrix-rain:not([hidden])) #matrix-toggle {
  color: var(--matrix-accent);
}

#matrix-rain {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -2;
  pointer-events: none;
}

body:has(#matrix-rain:not([hidden]))::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(
    to right,
    transparent,
    var(--paper) 1rem,
    var(--paper) calc(100% - 1rem),
    transparent
  );
  mask-image: linear-gradient(transparent, black 2rem, black calc(100% - 2rem), transparent);
  opacity: 0.84;
}

.note-nav,
article header {
  margin-bottom: 1.625rem;
}

article > * + *,
article blockquote p + p {
  margin-top: 1em;
}

article h2 {
  margin-top: 2.625rem;
  font-size: 1rem;
  font-weight: 700;
}

article h3 {
  margin-bottom: 0;
  font-size: 1rem;
  font-style: italic;
}

article blockquote {
  margin-inline: 0;
  padding-inline-start: 1rem;
  border-inline-start: 1px solid var(--line);
}

article img {
  display: block;
  max-width: 100%;
  height: auto;
  margin-inline: auto;
}

.protocol-figure {
  container-type: inline-size;
  margin: 1.75em 0;
}

.protocol-figure ol {
  display: grid;
  gap: 0.5em 2.25em;
  margin: 0;
  padding-inline-start: 1.5em;
}

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

@container (min-width: 38em) {
  .protocol-figure ol {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.protocol-figure table {
  width: 100%;
  border-collapse: collapse;
}

.protocol-figure :is(th, td) {
  padding: 0.2em 0.75em 0.2em 0;
  text-align: start;
  vertical-align: top;
}

.protocol-figure thead {
  border-bottom: 1px solid var(--line);
}

@container (max-width: 16em) {
  .protocol-figure :is(table, thead, tbody, tr),
  .protocol-figure :is(th, td):first-child {
    display: block;
  }

  .protocol-figure tr {
    padding-block: 0.35em;
  }

  .protocol-figure :is(th, td) {
    display: inline;
    padding: 0;
  }

  .protocol-figure :is(th, td):last-child::before {
    content: " → " / "";
  }
}

.katex {
  display: inline-flex;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.katex-block .katex {
  display: block;
}

article math {
  min-width: max-content;
  padding-block: 0.25em;
}

article pre {
  overflow-x: auto;
}

@media (max-width: 36rem), (pointer: coarse) {
  .reader-controls button {
    width: 2.75rem;
    height: 2.75rem;
  }

  .note-nav a,
  footer nav a {
    display: inline-flex;
    align-items: center;
    min-width: 1.5rem;
    min-height: 2.75rem;
    vertical-align: middle;
  }
}

@media (max-width: 36rem) {
  .columns {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 0.5rem;
  }

  .profile {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
  }

  .portrait {
    width: clamp(5.25rem, 22vw, 6rem);
  }

  .intro {
    flex-basis: 100%;
  }

  .index,
  .index section + section,
  .home-footer,
  .note-footer {
    margin-top: 2rem;
  }

  article h2 {
    margin-top: 1.5rem;
  }

  .note-nav,
  article header {
    margin-bottom: 1.25rem;
  }

  article > h2 + * {
    margin-top: 0.5rem;
  }

  .home-footer .footer-row {
    grid-column: 1;
    align-items: flex-end;
    column-gap: 0.75rem;
  }

  .links,
  .social-links {
    gap: 0 1rem;
  }

  .note-footer {
    padding-top: 0.75rem;
  }
}
