/* ==========================================================================
   Tufte-inspired stylesheet for willismonroe.com
   Modernised with CSS custom properties and CSS Grid for margin notes.
   Based on the design principles of Edward Tufte's books.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Fonts: ET Book
   -------------------------------------------------------------------------- */
@font-face {
  font-family: "ET Book";
  src: url("../fonts/et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.woff") format("woff"),
       url("../fonts/et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "ET Book";
  src: url("../fonts/et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.woff") format("woff"),
       url("../fonts/et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.ttf") format("truetype");
  font-weight: normal;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "ET Book";
  src: url("../fonts/et-book/et-book-bold-line-figures/et-book-bold-line-figures.woff") format("woff"),
       url("../fonts/et-book/et-book-bold-line-figures/et-book-bold-line-figures.ttf") format("truetype");
  font-weight: bold;
  font-style: normal;
  font-display: swap;
}

/* --------------------------------------------------------------------------
   Custom properties
   -------------------------------------------------------------------------- */
:root {
  --color-bg:       #fffff8;
  --color-text:     #111111;
  --color-mid:      #555555;
  --color-light:    #aaaaaa;
  --color-rule:     #ddddcc;

  --font-body:      "ET Book", Palatino, "Palatino Linotype", "Palatino LT STD", Georgia, serif;
  --font-sans:      "Gill Sans", "Gill Sans MT", Calibri, sans-serif;
  --font-mono:      Consolas, "Liberation Mono", Menlo, monospace;

  --text-size:      1.4rem;
  --line-height:    2rem;

  /* Layout: body column + gutter + margin column */
  --body-width:     55%;
  --gutter:         5%;
  --margin-width:   35%;
  --max-width:      1400px;

  --nav-height:     5rem;
}

/* --------------------------------------------------------------------------
   Reset & base
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 15px;
}

body {
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-size);
  line-height: var(--line-height);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --------------------------------------------------------------------------
   Navigation
   -------------------------------------------------------------------------- */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--color-bg);
  border-bottom: 1px solid var(--color-rule);
  height: var(--nav-height);
  display: flex;
  align-items: center;
  padding: 0 2rem;
}

.site-nav__inner {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 2rem;
}

.site-nav__home {
  font-size: 1.1rem;
  font-variant: small-caps;
  letter-spacing: 0.05em;
  color: var(--color-text);
  text-decoration: none;
  margin-right: auto;
}

.site-nav__links {
  display: flex;
  gap: 1.8rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-nav__links a {
  font-size: 1.1rem;
  color: var(--color-text);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s ease;
}

.site-nav__links a:hover,
.site-nav__links a[aria-current="page"] {
  border-bottom-color: var(--color-text);
}

/* --------------------------------------------------------------------------
   Page layout
   -------------------------------------------------------------------------- */
.page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 2rem 6rem;
}

/* Two-column grid: text body | margin */
.page__body {
  display: grid;
  grid-template-columns: var(--body-width) var(--gutter) var(--margin-width);
  grid-template-areas: "content gutter margin";
  align-items: start;
}

/* Everything in the content area by default */
.page__body > * {
  grid-column: content;
}

/* No sidenotes/margin notes on this page — collapse to full width */
.page__body:not(:has(.sidenote, .marginnote)) {
  grid-template-columns: 1fr;
  grid-template-areas: "content";
}

/* --------------------------------------------------------------------------
   Typography
   -------------------------------------------------------------------------- */
h1, h2, h3 {
  font-weight: normal;
  font-style: italic;
  line-height: 1;
  margin-top: 4rem;
  margin-bottom: 1.5rem;
}

h1 {
  font-size: 3.2rem;
  margin-top: 3rem;
}

h2 {
  font-size: 2.2rem;
}

h3 {
  font-size: 1.7rem;
}

p {
  margin: 0 0 var(--line-height);
  padding: 0;
  vertical-align: baseline;
}

/* First paragraph after heading: no top margin */
h1 + p, h2 + p, h3 + p {
  margin-top: 0;
}

a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: var(--color-light);
  transition: text-decoration-color 0.15s ease;
}

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

blockquote {
  margin: 2rem 0 2rem 2.5rem;
  padding: 0;
  border: none;
}

blockquote p {
  font-style: italic;
  color: var(--color-mid);
}

blockquote footer {
  font-size: 1.1rem;
  color: var(--color-mid);
}

blockquote footer::before {
  content: "— ";
}

ul, ol {
  padding-left: 2rem;
  margin: 0 0 var(--line-height);
}

li {
  margin-bottom: 0.5rem;
}

code {
  font-family: var(--font-mono);
  font-size: 1rem;
  background: rgba(0,0,0,0.04);
  padding: 0.1em 0.3em;
  border-radius: 2px;
}

pre {
  font-family: var(--font-mono);
  font-size: 1rem;
  line-height: 1.6;
  background: rgba(0,0,0,0.04);
  padding: 1.2rem 1.5rem;
  overflow-x: auto;
  margin: 0 0 var(--line-height);
}

pre code {
  background: none;
  padding: 0;
}

hr {
  border: none;
  border-top: 1px solid var(--color-rule);
  margin: 3rem 0;
}

/* --------------------------------------------------------------------------
   Sidenotes and margin notes
   -------------------------------------------------------------------------- */

/* The checkbox toggle — hidden but functional */
.margin-toggle {
  display: none;
}

/* Sidenote/marginnote widths and gutter */
:root {
  --sidenote-width: 220px;
  --sidenote-gutter: 2rem;
  /* Total push outside content box = width + gutter */
  --sidenote-offset: calc(var(--sidenote-width) + var(--sidenote-gutter));
}

/* On wide screens: sidenotes float into the space to the RIGHT of the content */
/* Breakpoint = content (860px) + 2×page-padding (4rem≈64px) + sidenote offset */
@media (min-width: 1100px) {
  /* Numbered sidenote */
  .sidenote-number {
    counter-increment: sidenote-counter;
    display: inline;
  }

  .sidenote-number::after,
  .sidenote::before {
    font-family: var(--font-body);
    font-size: 0.75rem;
    top: -0.5rem;
    position: relative;
  }

  .sidenote-number::after {
    content: counter(sidenote-counter);
    vertical-align: super;
  }

  .sidenote::before {
    content: counter(sidenote-counter) " ";
    top: -0.4rem;
  }

  .sidenote,
  .marginnote {
    float: right;
    clear: right;
    /* Negative margin-right pushes element entirely outside the content box.
       Text inside .page-content is unaffected because the float lands beyond
       the container's right edge. */
    width: var(--sidenote-width);
    margin-right: calc(-1 * var(--sidenote-offset));
    margin-left: var(--sidenote-gutter);
    margin-top: 0.3rem;
    margin-bottom: 0;
    font-size: 1.1rem;
    line-height: 1.6;
    color: var(--color-mid);
    vertical-align: baseline;
    position: relative;
  }

  /* Hide the toggle label on wide screens */
  label.margin-toggle:not(.sidenote-number) {
    display: none;
  }

  .margin-toggle:checked + .sidenote,
  .margin-toggle:checked + .marginnote {
    display: block;
  }
}

/* On narrow screens: inline toggleable notes */
@media (max-width: 1099px) {
  label.margin-toggle:not(.sidenote-number) {
    display: inline;
    cursor: pointer;
    color: var(--color-mid);
  }

  .sidenote-number::after {
    content: "[note]";
    font-size: 0.8rem;
    color: var(--color-mid);
    cursor: pointer;
  }

  .sidenote,
  .marginnote {
    display: none;
    font-size: 1.1rem;
    line-height: 1.6;
    margin: 0.5rem 0;
    padding: 0.5rem 1rem;
    border-left: 3px solid var(--color-rule);
    color: var(--color-mid);
  }

  .margin-toggle:checked ~ .sidenote,
  .margin-toggle:checked ~ .marginnote {
    display: block;
  }
}

/* Sidenote counter reset per article */
article {
  counter-reset: sidenote-counter;
}

/* Wrapper span generated by the markdown extension — transparent to layout */
.sidenote-wrapper {
  display: contents;
}

/* --------------------------------------------------------------------------
   Home page
   -------------------------------------------------------------------------- */
.home-profile {
  max-width: 860px;
  margin: 3rem auto;
  overflow: hidden; /* clearfix */
}

.home-profile__photo {
  float: left;
  width: 260px;
  margin: 0 2.5rem 1.5rem 0;
}

.home-profile__photo img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 4px;
}

.home-profile__bio {
  /* text naturally wraps around the float */
}

.home-body,
.page-content {
  max-width: 860px;
  margin-left: auto;
  margin-right: auto;
}

/* --------------------------------------------------------------------------
   Blog post listing
   -------------------------------------------------------------------------- */
.post-list {
  list-style: none;
  padding: 0;
  margin: 2rem 0;
}

.post-list__item {
  display: flex;
  align-items: baseline;
  gap: 1.5rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-rule);
}

.post-list__date {
  font-size: 1.1rem;
  color: var(--color-mid);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 9rem;
}

.post-list__title {
  font-size: 1.3rem;
}

.post-list__intro {
  font-size: 1.1rem;
  color: var(--color-mid);
  margin-top: 0.25rem;
}

/* --------------------------------------------------------------------------
   Post detail
   -------------------------------------------------------------------------- */
.post-meta {
  font-size: 1.1rem;
  color: var(--color-mid);
  margin-top: -1rem;
  margin-bottom: 2rem;
}

/* --------------------------------------------------------------------------
   Images and documents in body
   -------------------------------------------------------------------------- */
.block-image {
  margin: 2rem 0;
}

.block-image img {
  max-width: 100%;
  height: auto;
  display: block;
}

.block-image figcaption {
  font-size: 1.1rem;
  color: var(--color-mid);
  margin-top: 0.5rem;
  font-style: italic;
}

.block-image figcaption p {
  margin: 0;
}

.block-document {
  margin: 1.5rem 0;
}

.block-document a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 1.2rem;
}

.block-document a::before {
  content: "↓";
  font-style: normal;
}

/* --------------------------------------------------------------------------
   Pull quotes
   -------------------------------------------------------------------------- */
.block-pullquote {
  margin: 3rem 0 3rem 0;
  padding: 0 0 0 2.5rem;
  border-left: 3px solid var(--color-rule);
  font-size: 1.6rem;
  font-style: italic;
  line-height: 1.4;
  color: var(--color-mid);
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
.site-footer {
  border-top: 1px solid var(--color-rule);
  padding: 2rem;
  margin-top: 4rem;
  font-size: 1.1rem;
  color: var(--color-mid);
  text-align: center;
}

/* --------------------------------------------------------------------------
   Responsive overrides
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
  :root {
    --body-width: 100%;
    --gutter: 0;
    --margin-width: 0;
  }

  .page__body {
    display: block;
  }
}

@media (max-width: 600px) {
  html {
    font-size: 13px;
  }

  .site-nav {
    padding: 0 1rem;
  }

  .page {
    padding: 0 1rem 4rem;
  }

  .home-profile__photo {
    float: none;
    width: 140px;
    margin: 0 0 1.5rem 0;
  }

  h1 {
    font-size: 2.4rem;
  }
}
