html {
  scroll-behavior: smooth;
  /* No overscroll bounce past the page edges */
  overscroll-behavior-y: none;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

.container {
  position: relative;
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--sp-4);
}

main {
  display: flex;
  flex-direction: column;
  flex: 1;
  /* No background: .margin-band supplies the margin tint. Flex so short pages still reach the footer. */
}

/* The only translucent margin tint on the page. Stacking several washes out the checkerboard. */
.margin-band {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  will-change: transform;
  background: rgb(var(--c-taupe-rgb) / 0.24);
}

section,
.writing {
  position: relative;
  padding-block: var(--sp-5);
}

/* Content column stripe, slightly translucent so the checkerboard shows through */
section {
  background: linear-gradient(
    to right,
    transparent calc(50% - var(--container) / 2),
    rgb(var(--c-bg-alt-rgb) / 0.9) calc(50% - var(--container) / 2),
    rgb(var(--c-bg-alt-rgb) / 0.9) calc(50% + var(--container) / 2),
    transparent calc(50% + var(--container) / 2)
  );
}

/* Taupe fade behind the carousels, blending into the sections above and below */
section.carousel-section {
  padding-block: var(--sp-4);
  background: linear-gradient(
    to bottom,
    rgb(var(--c-bg-alt-rgb) / 0.9) 0%,
    rgb(var(--c-taupe-rgb) / 0.3) 50%,
    rgb(var(--c-bg-alt-rgb) / 0.9) 100%
  ) center / min(100%, var(--container)) 100% no-repeat;
}

section.carousel-section > .container::before {
  display: none;
}

.writing {
  flex: 1;
  /* Posts sit on the darker surface colour */
  background: linear-gradient(
    to right,
    transparent calc(50% - var(--container) / 2),
    var(--c-surface) calc(50% - var(--container) / 2),
    var(--c-surface) calc(50% + var(--container) / 2),
    transparent calc(50% + var(--container) / 2)
  );
}

/* Stretch the last section of the visible panel down to the footer */
.topic-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* display: flex above would otherwise override [hidden] */
.topic-panel[hidden] {
  display: none;
}

.topic-panel > section:last-child {
  flex: 1;
}

/* Outline around the content column */
section::after,
.writing::after {
  content: "";
  position: absolute;
  inset: 0;
  width: min(100%, var(--container));
  margin-inline: auto;
  border: 1px solid var(--c-taupe);
  pointer-events: none;
}

.topic-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  width: min(100%, var(--container));
  margin-inline: auto;
  border: 1px solid var(--c-taupe);
  pointer-events: none;
}

/* Divider between sections, not under the page header */
section:not(.page-header) + section > .container::before {
  content: "";
  position: absolute;
  top: calc(-1 * var(--sp-5));
  left: 50%;
  transform: translateX(-50%);
  width: 80%;
  height: 1px;
  background: var(--c-border);
}

.hero {
  padding-block: var(--sp-4);
  display: flex;
  align-items: center;
}

.hero-content {
  position: relative;
  z-index: 1;
}

.hero-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-5);
}

@media (min-width: 768px) {
  .hero-grid {
    grid-template-columns: 1fr 1fr;
    align-items: center;
    gap: var(--sp-4);
  }
}

.hero-writings {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

/* Panels start at the top of <main>, so this pins a #panel jump to scrollY 0 under the sticky header. */
.topic-panel {
  scroll-margin-top: 100vh;
}

/* Text with a photo floated to the right (About) */
.split-grid {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

@media (min-width: 768px) {
  .split-grid {
    display: block;
  }

  /* Clearfix for the floated photo */
  .split-grid::after {
    content: "";
    display: table;
    clear: both;
  }

  .split-photo {
    float: right;
    width: 23%;
    margin-left: var(--sp-3);
    margin-bottom: var(--sp-3);
  }
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--sp-3);
  margin-top: var(--sp-4);
}

/* Centered image above text (Astronomy research) */
.wide-photo {
  width: 66.67%;
  margin-inline: auto;
  margin-bottom: var(--sp-3);
}

.wide-photo.is-small {
  width: min(100%, 420px);
}

.page-header {
  padding-block: var(--sp-4) var(--sp-3);
}

.writings-compact {
  padding-block: var(--sp-4);
}

.writing-back {
  margin-bottom: var(--sp-3);
}

.writing-back a {
  font-family: var(--f-label);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: var(--fs-xs);
}

.prose {
  margin-top: var(--sp-3);
}

.prose p {
  max-width: none;
  margin-bottom: var(--sp-2);
}

.prose picture {
  display: block;
  margin-block: var(--sp-3);
}

.prose img {
  display: block;
  margin-inline: auto;
  max-width: 100%;
  height: auto;
  border: 2px solid var(--c-accent);
}

.prose figure picture {
  margin-bottom: 0;
}

.prose .katex-display {
  overflow-x: auto;
  padding-block: var(--sp-1);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--sp-3);
  margin-top: var(--sp-3);
}
