:root {
  --max-width: 42rem;
  --bg: #fbfbf9;
  --fg: #1c1b1a;
  --muted: #6b6862;
  --rule: #e4e1da;
  --accent: #8a5a2b;
  --tag-bg: #efece4;
  --card-bg: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --font-serif: Charter, "Iowan Old Style", "Palatino Linotype", Palatino,
    Georgia, "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --fg: #e6e3dd;
    --muted: #9c988f;
    --rule: #2c2c32;
    --accent: #d7a35f;
    --tag-bg: #25252b;
    --card-bg: #1e1e24;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.45);
  }
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-serif);
  line-height: 1.65;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.25rem 4rem;
}

main.wide {
  max-width: 66rem;
}

/* --- Header --- */
.site-header {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2.5rem 1.25rem 1.25rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 2.5rem;
  text-align: center;
}

.site-title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--fg);
  text-decoration: none;
}

.site-tagline {
  margin: 0.2rem 0 0.9rem;
  color: var(--muted);
  font-style: italic;
}

.site-nav {
  display: flex;
  justify-content: center;
  gap: 1.4rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
}

.site-nav a {
  color: var(--muted);
  text-decoration: none;
}

.site-nav a:hover {
  color: var(--accent);
}

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

/* --- Archive / home list --- */
.year-group {
  margin-bottom: 2rem;
}

.year {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.6rem;
}

.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.post-list-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--rule);
}

.post-list-title {
  text-decoration: none;
  color: var(--fg);
}

.post-list-title:hover {
  color: var(--accent);
}

.post-list-meta {
  flex: none;
  display: inline-flex;
  align-items: baseline;
  gap: 0.6rem;
}

.post-list-date {
  flex: none;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  color: var(--muted);
}

/* --- Page titles (category / index pages) --- */
.page-title {
  font-size: 1.7rem;
  letter-spacing: -0.015em;
  margin: 0 0 0.2rem;
}

.page-sub {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0 0 1.5rem;
}

/* --- Category index --- */
.category-index {
  list-style: none;
  margin: 0;
  padding: 0;
}

.category-index li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--rule);
}

.category-index a {
  text-decoration: none;
  font-size: 1.1rem;
}

.category-count {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  color: var(--muted);
}

/* --- Category filter bar --- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin: -1.25rem 0 1.75rem; /* pull up to tighten gap below the header */
}

/* Hamburger toggle — only shown on narrow screens (see media query below). */
.filter-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--fg);
  background: none;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
}

.hamburger {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 22px;
}

.hamburger span {
  display: block;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}

@media (max-width: 760px) {
  .filter-toggle {
    display: flex;
    width: fit-content;
    margin: -0.75rem auto 2.25rem; /* centered, with spacing below */
  }
  .filter-bar {
    display: none;
    flex-flow: row wrap;
    justify-content: center;
    gap: 0.5rem;
    margin: 0 0 1.75rem;
  }
  .filter-bar.is-open {
    display: flex;
  }
}

.filter {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.filter:hover {
  color: var(--fg);
  border-color: var(--muted);
}

.filter.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* --- Front-page card grid --- */
/* No-JS fallback: a plain responsive grid (row-first). */
.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 760px) {
  .card-grid {
    grid-template-columns: 1fr;
  }
}

/* With JS: flex columns filled round-robin → tiled (masonry) + row-first. */
.card-grid.is-masonry {
  display: flex;
  align-items: flex-start;
}

.card-col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.card {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 0.6rem; /* padding all around, including around the image */
  color: inherit;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: transparent;
}

.card-hero {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 7px;
}

.card-body {
  padding: 0.7rem 0.55rem 0.5rem;
}

.card-date {
  display: block;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.card-title {
  font-size: 1.18rem;
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin: 0 0 0.5rem;
}

.card:hover .card-title {
  color: var(--accent);
}

.card-summary {
  margin: 0 0 0.7rem;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--fg);
  opacity: 0.82;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

/* --- Post --- */
.post-date {
  display: block;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0 0 0.6rem;
}

.post-header h1 {
  font-size: 2rem;
  line-height: 1.2;
  letter-spacing: -0.015em;
  margin: 0 0 0.75rem;
}

.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 2rem;
}

.tag {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 0.72rem;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  text-decoration: none;
  white-space: nowrap;
}

.tag:hover {
  background: var(--accent);
  color: #fff;
}

.post-body p {
  margin: 0 0 1.25rem;
}

.post-body h2,
.post-body h3,
.post-body h4,
.post-body h5 {
  line-height: 1.25;
  margin: 2rem 0 0.75rem;
}

.post-body blockquote {
  margin: 1.5rem 0;
  padding-left: 1rem;
  border-left: 3px solid var(--rule);
  color: var(--muted);
  font-style: italic;
}

.post-body img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
  border-radius: 4px;
}

.post-body figure {
  margin: 1.75rem 0;
}

.post-body figcaption {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.5rem;
}

.post-body hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 2.5rem 0;
}

.post-footer-nav {
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  font-family: var(--font-sans);
  font-size: 0.85rem;
}

.post-footer-nav a {
  text-decoration: none;
}

/* --- Footer --- */
.site-footer {
  max-width: var(--max-width);
  margin: 3rem auto 0;
  padding: 1.5rem 1.25rem 2.5rem;
  border-top: 1px solid var(--rule);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}
