/* ==========================================================================
   style.css — all of the site's styling.

   The variables in :root are the knobs worth turning. Change --measure to
   make the text column wider or narrower, --accent to change link colour,
   or --font-body to change the typeface everywhere. Everything below the
   variables inherits from them.
   ========================================================================== */

:root {
  /* Typography. The serif stack mirrors the Times-family face used in the
     PDF CV, using fonts already present on most machines (no web fonts to
     download, so pages render instantly). */
  --font-body: Charter, Charis SIL, Georgia, "Times New Roman", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;

  --measure: 44rem;          /* width of the text column */
  --size-base: 1.0625rem;    /* body text size */
  --leading: 1.6;            /* line height */

  /* Colour. Deliberately close to black-on-white: high contrast, no tint. */
  --ink: #1a1a1a;
  --ink-muted: #5c5c5c;
  --paper: #fdfdfc;
  --rule: #e0ded9;
  --accent: #7a2020;         /* deep red for links */
  --accent-hover: #a83232;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e6e4e0;
    --ink-muted: #a09d98;
    --paper: #16161a;
    --rule: #33323a;
    --accent: #e39a9a;
    --accent-hover: #f2bcbc;
  }
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--size-base);
  line-height: var(--leading);
  text-rendering: optimizeLegibility;
}

.wrap {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 1.5rem;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
a:hover { color: var(--accent-hover); }

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

/* Struck-through text on the archived course pages: an edit Kenny made
   part-way through the term, kept visible rather than deleted. Muted so it
   reads as superseded rather than as an error. */
del {
  color: var(--ink-muted);
  text-decoration-thickness: 1px;
}

/* Two survey charts for the same question, one term beside the other. The
   wrapper is wider than the text measure, since a pair of charts side by side
   needs the room; it drops to a single column on narrow screens. Markdown puts
   each image in its own <p>, which `display: contents` neutralises. */
.chart-pair {
  display: flex;
  gap: 1rem;
  margin: 0.5rem 0 1.75rem;
  width: min(64rem, 100%);
  margin-inline-start: calc((var(--measure) - min(64rem, 100%)) / 2);
}

.chart-pair p { display: contents; }

.chart-pair img {
  flex: 1 1 0;
  min-width: 0;
  height: auto;
  border: 1px solid var(--rule);
  border-radius: 3px;
}

@media (max-width: 60rem) {
  .chart-pair {
    flex-direction: column;
    width: 100%;
    margin-inline-start: 0;
  }
}

.skip-link {
  position: absolute;
  left: -9999px;
}
.skip-link:focus {
  left: 1rem; top: 1rem;
  background: var(--paper);
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--rule);
  z-index: 10;
}

/* --------------------------------------------------------------------------
   Header and navigation
   -------------------------------------------------------------------------- */

.site-header {
  border-bottom: 1px solid var(--rule);
  margin-bottom: 3rem;
  font-family: var(--font-ui);
}

.site-header .wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  padding-top: 1.5rem;
  padding-bottom: 1.25rem;
}

.site-name {
  font-family: var(--font-body);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: 0.01em;
}
.site-name:hover { color: var(--accent); }

.site-header nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.9375rem;
}

.site-header nav a {
  color: var(--ink-muted);
  text-decoration: none;
  padding-bottom: 2px;
  border-bottom: 2px solid transparent;
}
.site-header nav a:hover { color: var(--accent); }
.site-header nav a[aria-current="page"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

/* --------------------------------------------------------------------------
   Headings and prose
   -------------------------------------------------------------------------- */

main { padding-bottom: 4rem; }

h1, h2, h3, h4 {
  line-height: 1.25;
  font-weight: 600;
  margin-top: 2.5em;
  margin-bottom: 0.6em;
  letter-spacing: -0.005em;
}

h1 {
  font-size: 2rem;
  margin-top: 0;
  margin-bottom: 1.5rem;
}

h2 {
  font-size: 1.375rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--rule);
}

h3 { font-size: 1.125rem; }

h4 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

p { margin: 0 0 1.1em; }

blockquote {
  margin: 1.5em 0;
  padding-left: 1.25rem;
  border-left: 2px solid var(--rule);
  color: var(--ink-muted);
}

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

img { max-width: 100%; height: auto; }

code, pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

/* --------------------------------------------------------------------------
   Lists

   Bibliography-style lists (publications, talks, courses) use a hanging
   indent: the first line sits flush left and continuation lines are indented,
   which is how citations are set in print.
   -------------------------------------------------------------------------- */

ul, ol { padding-left: 1.3rem; }
li { margin-bottom: 0.5em; }
li > ul, li > ol { margin-top: 0.5em; }

main ul li::marker { color: var(--ink-muted); }

/* Wrap a list in `<div class="bib" markdown="1"> ... </div>` to get this.
   (A trailing `{: .bib }` would attach the class to the last list item
   rather than the list, which is why these use a wrapper.) */
.bib ul {
  list-style: none;
  padding-left: 0;
}
.bib li {
  margin-bottom: 0.9em;
  padding-left: 1.5rem;
  text-indent: -1.5rem;
}

/* Short bibliographic annotation, set inline and quietly after a citation. */
.entry-aside {
  font-size: 0.875em;
  color: var(--ink-muted);
}

/* Longer commentary on a single publication, set as a block under its entry. */
.entry-note {
  display: block;
  margin-top: 0.4em;
  padding-left: 0.9rem;
  border-left: 2px solid var(--rule);
  font-size: 0.9375em;
  color: var(--ink-muted);
  text-indent: 0;
}

/* Secondary links inside a citation — (journal), (publisher) — set smaller
   and quieter so the title stays dominant. */
.bib li a.alt, main a.alt {
  font-size: 0.875em;
  color: var(--ink-muted);
}
main a.alt:hover { color: var(--accent); }

/* Term-and-course lists on the Teaching page. Also wrapper-based. */
.terms > ul { list-style: none; padding-left: 0; }
.terms > ul > li { margin-bottom: 1.4em; }
.terms .term {
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-muted);
  display: block;
  margin-bottom: 0.25em;
}
.terms ul ul { list-style: none; padding-left: 0; margin: 0; }
.terms ul ul li { margin-bottom: 0.2em; }

/* --------------------------------------------------------------------------
   Home page intro
   -------------------------------------------------------------------------- */

.lede {
  font-size: 1.1875rem;
  line-height: 1.55;
  margin-bottom: 1.75rem;
}

/* Photos beside a block of text. Use <img class="photo right"> or
   <img class="photo left">; a section may carry one of each, in which case
   the text runs down the channel between them. 180px is chosen so that two
   photos plus their margins still leave a readable column in the middle. */

.photo {
  width: 180px;
  border-radius: 3px;
  display: block;
}

.photo.right {
  float: right;
  margin: 0.35rem 0 1.25rem 1.75rem;
}

.photo.left {
  float: left;
  margin: 0.35rem 1.75rem 1.25rem 0;
}

/* Two or more photos stacked vertically down one side of a section. Wrap them
   in <div class="photo-stack right"> or <div class="photo-stack left">.
   The wrapper is what floats — floating the images individually would let
   them sit side by side whenever the column happened to be wide enough. */

.photo-stack {
  width: 180px;
}

.photo-stack.right {
  float: right;
  margin: 0.35rem 0 1.25rem 1.75rem;
}

.photo-stack.left {
  float: left;
  margin: 0.35rem 1.75rem 1.25rem 0;
}

.photo-stack img {
  display: block;
  width: 100%;
  border-radius: 3px;
  margin-bottom: 0.75rem;
}

.photo-stack img:last-child { margin-bottom: 0; }

/* Each section starts below the previous section's photo, which is what keeps
   the alternating left/right rhythm from collapsing into a jumble. */
main h2 { clear: both; }

/* A row of photos, equal widths, cropped square. Wrap the images in
   <div class="photo-row" markdown="1"> ... </div>. */

.photo-row {
  display: flex;
  gap: 0.75rem;
  margin: 0 0 1.5rem;
}

.photo-row p { margin: 0; display: contents; }

.photo-row img {
  flex: 1 1 0;
  min-width: 0;
  /* Capped so that a row of two doesn't balloon to half the page each; the
     row stays left-aligned and the tiles match the floated photos in scale. */
  max-width: 210px;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  object-position: center 30%;
  border-radius: 3px;
}

/* On narrow screens, stop floating: full-width photos read better than
   200px images squeezed against two words per line. */
@media (max-width: 34rem) {
  .photo {
    float: none;
    width: 100%;
    max-width: 320px;
    margin: 0 auto 1.5rem;
  }
  /* A stack becomes a side-by-side pair rather than one tall column, so a
     phone reader doesn't have to scroll past two full-width portraits to
     reach the next paragraph. */
  .photo-stack {
    float: none;
    width: 100%;
    margin: 0 0 1.5rem;
    display: flex;
    gap: 0.5rem;
  }
  .photo-stack img { margin-bottom: 0; }
  .photo-row { gap: 0.5rem; }
}

/* A small block of contact details under the intro. */
.contact ul {
  list-style: none;
  padding: 0;
  margin: 0 0 2rem;
  font-size: 0.9375rem;
  color: var(--ink-muted);
}
.contact li { margin-bottom: 0.15em; }

/* --------------------------------------------------------------------------
   Buttons / callouts
   -------------------------------------------------------------------------- */

.button {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: 0.875rem;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  color: var(--ink);
  text-decoration: none;
}
.button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.note {
  font-size: 0.9375rem;
  color: var(--ink-muted);
  border-left: 2px solid var(--rule);
  padding-left: 1rem;
  margin: 1.5em 0;
}

/* --------------------------------------------------------------------------
   Collapsible sections

   Generated by build.py for pages with `collapsible: true`. The <summary>
   contains the real <h2>, so the document outline is unchanged whether a
   section is open or shut.
   -------------------------------------------------------------------------- */

details.section > summary {
  list-style: none;          /* hide the default triangle; we draw our own */
  cursor: pointer;
  display: block;
}
details.section > summary::-webkit-details-marker { display: none; }

details.section > summary h2 {
  position: relative;
  padding-right: 1.5rem;
}

/* Chevron at the right-hand end of the heading rule, rotating when open. */
details.section > summary h2::after {
  content: "";
  position: absolute;
  right: 0.25rem;
  top: 0.5em;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 1.5px solid var(--ink-muted);
  border-bottom: 1.5px solid var(--ink-muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}
details.section[open] > summary h2::after {
  transform: rotate(-135deg);
}

details.section > summary:hover h2 { color: var(--accent); }
details.section > summary:hover h2::after {
  border-color: var(--accent);
}

details.section > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* A shut section shouldn't leave the next one jammed against it. */
details.section { margin-bottom: 0.5rem; }

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */

.site-footer {
  border-top: 1px solid var(--rule);
  padding: 1.5rem 0 3rem;
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--ink-muted);
}
.site-footer p { margin: 0 0 0.3em; }
.site-footer a { color: var(--ink-muted); }
.site-footer a:hover { color: var(--accent); }
.site-footer .sep { padding: 0 0.4rem; }

/* --------------------------------------------------------------------------
   Print
   -------------------------------------------------------------------------- */

@media print {
  .site-header nav, .skip-link { display: none; }
  body { font-size: 11pt; color: #000; background: #fff; }
  .wrap { max-width: none; padding: 0; }
  a { color: #000; text-decoration: none; }

  /* Print every section, whether or not the reader left it collapsed. */
  details.section > div,
  details.section > ul,
  details.section > p { display: block !important; }
  details.section > summary h2::after { display: none; }
}
