/* Alasdair Cannon: alasdaircannon.co.uk */

@font-face {
  font-family: "EB Garamond";
  src: url("fonts/EBGaramond-var.woff2") format("woff2");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("fonts/EBGaramond-Italic-var.woff2") format("woff2");
  font-weight: 400 800;
  font-style: italic;
  font-display: swap;
}

:root {
  --bg: #ffffff;
  --ink: #111111;
  --muted: #555555;
  --rule: #d9d6d0;
  --red: #8b2e22;
  --serif: "EB Garamond", Garamond, Georgia, "Times New Roman", Times, serif;
  --measure: 36rem;
  --wide: 52rem;
  --gutter: 1.25rem;
  --nav-h: 3.5rem;
  --space: clamp(4.5rem, 10vw, 7.5rem);
  color-scheme: light;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--nav-h) + 1rem);
}
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(1.1875rem, 1.1rem + 0.3vw, 1.25rem); /* 19-20px */
  line-height: 1.65;
  font-variant-numeric: oldstyle-nums proportional-nums;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
}

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

p { margin: 0 0 1.1em; }

h1, h2, h3, h4 { font-weight: 400; line-height: 1.2; margin: 0; }

cite { font-style: italic; }

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { color: var(--red); }

:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 3px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute;
  left: var(--gutter); top: -4rem;
  z-index: 100;
  padding: 0.5rem 1rem;
  background: var(--ink); color: #fff;
  text-decoration: none;
}
.skip-link:focus { top: 0.5rem; color: #fff; }

/* Small caps, used for labels and headings */
.smallcaps,
.nav,
.section-title,
.subsection-title,
.eyebrow,
.card-meta,
.article-pub,
.tag,
.project-url,
.button,
.site-footer {
  font-variant-caps: all-small-caps;
  letter-spacing: 0.07em;
}

/* ---------- Navigation ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--rule);
}
@supports (backdrop-filter: blur(4px)) {
  .site-header { background: rgba(255, 255, 255, 0.88); backdrop-filter: blur(6px); }
}

.nav {
  max-width: calc(var(--wide) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 var(--gutter);
  min-height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 1.15rem;
}

.nav a { text-decoration: none; }

.nav-name { font-size: 1.2rem; letter-spacing: 0.09em; }

.nav-links {
  display: flex;
  gap: 1.5rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav-links a { color: var(--ink); padding: 0.5rem 0; }
.nav-links a:hover,
.nav-links a[aria-current="true"] { color: var(--red); }

.nav-toggle { display: none; }

@media (max-width: 44.99rem) {
  .js .nav { flex-wrap: wrap; padding-block: 0.5rem; }
  .js .nav-toggle {
    display: block;
    font: inherit;
    letter-spacing: inherit;
    font-variant-caps: inherit;
    color: var(--ink);
    background: none;
    border: 1px solid var(--rule);
    padding: 0.15rem 0.8rem;
    cursor: pointer;
  }
  .js .nav-toggle:hover,
  .js .nav-toggle[aria-expanded="true"] { border-color: var(--red); color: var(--red); }
  .js .nav-links { display: none; }
  .js .nav-links.is-open {
    display: flex;
    flex-direction: column;
    gap: 0;
    width: 100%;
    padding: 0.25rem 0 0.75rem;
  }
  .js .nav-links.is-open a { display: block; padding: 0.55rem 0; }

  /* Without JavaScript the links stay visible and wrap. */
  .nav-links { flex-wrap: wrap; gap: 0.25rem 1.1rem; }
  html:not(.js) .nav { flex-direction: column; align-items: flex-start; padding-block: 0.5rem; }
}

/* ---------- Layout ---------- */

.column,
.wide {
  margin: 0 auto;
  padding: 0 var(--gutter);
}
.column { max-width: calc(var(--measure) + 2 * var(--gutter)); }
.wide { max-width: calc(var(--wide) + 2 * var(--gutter)); }

.section { padding-top: var(--space); }

/* Centred tilde between sections */
.section::before {
  content: "~";
  display: block;
  text-align: center;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  margin-bottom: var(--space);
}

.section-title {
  font-size: 1.75rem;
  margin-bottom: 2.25rem;
}
.section-title::after,
.subsection-title::after {
  content: "";
  display: block;
  width: 2.5rem;
  height: 2px;
  margin-top: 0.55rem;
  background: var(--red);
}

.subsection-title {
  font-size: 1.35rem;
  margin: 3.5rem 0 1.5rem;
}

/* ---------- Hero ---------- */

.hero {
  max-width: calc(var(--wide) + 2 * var(--gutter));
  margin: 0 auto;
  padding: clamp(3.5rem, 9vw, 6.5rem) var(--gutter) 0;
}

.hero h1 {
  font-size: clamp(2.9rem, 2rem + 4.5vw, 4.6rem);
  line-height: 1.05;
  letter-spacing: -0.005em;
}

.tagline {
  margin: 0.9rem 0 0;
  font-size: clamp(1.3rem, 1.1rem + 0.8vw, 1.6rem);
  font-style: italic;
  color: var(--muted);
}

.hero-feature {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  margin-top: clamp(3rem, 7vw, 4.5rem);
}
.hero-cover {
  width: min(60vw, 17rem);
  border: 1px solid var(--rule);
}
.eyebrow {
  color: var(--red);
  font-size: 1.1rem;
  margin-bottom: 0.6rem;
}
.hero-book-title {
  font-size: clamp(1.7rem, 1.3rem + 1.6vw, 2.3rem);
  line-height: 1.15;
  margin: 0 0 0.6rem;
}
.hero-book-meta {
  color: var(--muted);
  margin-bottom: 1.6rem;
}
.hero-endorsement {
  font-style: italic;
  border-left: 2px solid var(--red);
  padding-left: 1rem;
  margin: -0.4rem 0 1.6rem;
  max-width: 30rem;
}

@media (min-width: 46rem) {
  .hero-feature {
    grid-template-columns: 17rem 1fr;
    gap: 3rem;
    align-items: center;
  }
  .hero-cover { width: 17rem; }
}

/* ---------- Buttons and links ---------- */

.button {
  display: inline-block;
  padding: 0.4rem 1.15rem 0.5rem;
  border: 1px solid var(--red);
  color: var(--red);
  text-decoration: none;
  font-size: 1.1rem;
  line-height: 1.3;
  transition: background-color 0.18s ease, color 0.18s ease;
}
.button:hover,
.button:focus-visible { background: var(--red); color: #fff; }

.secondary-link {
  color: var(--muted);
  font-size: 1rem;
}
.secondary-link:hover { color: var(--red); }

/* ---------- Cards ---------- */

/* Each card is clickable as a whole: its main link stretches over the card,
   and any secondary link sits above that layer. */
.card {
  position: relative;
  border: 1px solid var(--rule);
  background: var(--bg);
  transition: border-color 0.18s ease, transform 0.18s ease;
}
.card-link::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
}
.card .secondary-link { position: relative; z-index: 2; }
.card-link:focus-visible { outline: none; }
.card:focus-within { outline: 2px solid var(--red); outline-offset: 3px; }
.card:has(.secondary-link:focus-visible) { outline: none; }

.card:hover { border-color: var(--red); }
.card:hover .card-title { color: var(--red); }
@media (prefers-reduced-motion: no-preference) {
  .card:hover { transform: translateY(-2px); }
}

.card-title {
  font-size: 1.3rem;
  line-height: 1.25;
  margin-bottom: 0.35rem;
  transition: color 0.18s ease;
}
.card-title a { text-decoration: none; }
.card-meta {
  color: var(--muted);
  font-size: 1.05rem;
  margin-bottom: 0.5rem;
}
.card-line { margin-bottom: 1rem; }
.card-body > :last-child { margin-bottom: 0; }

.cover { border: 1px solid var(--rule); background: #f4f2ee; }
.card .cover { width: 100%; height: auto; }

.book-list,
.article-list,
.project-list,
.edited-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1.5rem;
}

/* Books: cover left, text right. On phones the buttons take a full-width
   row beneath, so they don't wrap inside the narrow text column. */
.book {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  gap: 1.1rem 1.25rem;
  align-items: start;
  padding: 1.25rem;
}
.book .card-line { font-size: 1.1rem; margin-bottom: 0; }
.book .card-line + .card-note { margin-top: 0.6rem; }
.card-note { font-size: 1.05rem; font-style: italic; color: var(--muted); margin-bottom: 0; }
.book .card-actions { grid-column: 1 / -1; }
.card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  margin: 0;
}

@media (min-width: 46rem) {
  .book {
    grid-template-columns: 9rem 1fr;
    grid-template-rows: auto 1fr;
    gap: 1.25rem 1.75rem;
    padding: 1.5rem;
  }
  .book .cover { grid-row: 1 / 3; }
  .book .card-actions { grid-column: 2; align-self: start; }
  .book--featured { grid-template-columns: 12rem 1fr; padding: 2rem; }
}
.book--featured { border-color: #c9c4bc; }
.book--featured .card-title { font-size: clamp(1.45rem, 1.2rem + 0.9vw, 1.8rem); }

/* Articles */
@media (min-width: 46rem) {
  .article-list { grid-template-columns: 1fr 1fr; }
}
.article { padding: 1.4rem 1.5rem 1.3rem; }
.numeral {
  display: block;
  color: var(--red);
  font-size: 1.25rem;
  letter-spacing: 0.06em;
  line-height: 1;
  margin-bottom: 0.8rem;
}
.article-pub {
  color: var(--ink);
  font-size: 1.1rem;
  margin: 0.4rem 0 0.25rem;
}
.article-meta {
  color: var(--muted);
  font-size: 1.05rem;
  margin: 0;
}
.tag {
  display: inline-block;
  border: 1px solid var(--rule);
  padding: 0 0.45rem 0.1rem;
  margin-right: 0.4rem;
  line-height: 1.4;
}

/* Projects */
.project { padding: 1.5rem 1.75rem; }
.project .card-title { font-size: clamp(1.45rem, 1.25rem + 0.7vw, 1.75rem); }
.project .card-line { margin-bottom: 0.4rem; }
.project-url { color: var(--muted); font-size: 1.05rem; margin: 0; }

@media (min-width: 46rem) {
  .edited-list { grid-template-columns: 1fr 1fr; }
}
.edited {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 1.1rem;
  align-items: start;
  padding: 1.1rem;
}
.edited .card-title { font-size: 1.2rem; }
.edited .card-line { font-size: 1.05rem; font-style: italic; color: var(--muted); }

/* ---------- Contact ---------- */

.contact .column {
  border-top: 2px solid var(--red);
  padding-top: 2.5rem;
  max-width: calc(var(--measure) + 2 * var(--gutter));
}
@media (min-width: 46rem) {
  .contact .column { padding-left: 0; padding-right: 0; max-width: var(--measure); }
}
.contact-note { font-size: 1.3rem; }
.contact-email {
  font-size: clamp(1.55rem, 1.2rem + 1.6vw, 2.25rem);
  line-height: 1.25;
  margin: 1.5rem 0 1.75rem;
  overflow-wrap: anywhere;
}
.email-link { color: var(--red); text-decoration-thickness: 1px; }
.email-link:hover { text-decoration-thickness: 2px; }
.contact-links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
  font-size: 1.15rem;
}

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

.site-footer {
  width: calc(100% - 2 * var(--gutter));
  max-width: var(--wide);
  margin: var(--space) auto 0;
  padding: 2rem 0 3rem;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 1.05rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 2rem;
}
.site-footer p { margin: 0; }

/* ---------- Fade-in on scroll ---------- */

@media (prefers-reduced-motion: no-preference) {
  .js .reveal {
    opacity: 0;
    transform: translateY(14px);
    transition: opacity 0.7s ease, transform 0.7s ease, border-color 0.18s ease;
  }
  .js .reveal.is-visible {
    opacity: 1;
    transform: none;
  }
  .js .card.reveal.is-visible:hover { transform: translateY(-2px); }
}

@media print {
  .site-header, .skip-link, .button { display: none; }
  .section::before { margin-bottom: 2rem; }
  .js .reveal { opacity: 1 !important; transform: none !important; }
}

.not-found { padding-top: 6rem; padding-bottom: 6rem; }
