:root {
  --background: #f3f4f1;
  --surface: #ffffff;
  --surface-subtle: #e9ece7;
  --text: #171716;
  --muted: #686865;
  --line: #d7dad4;
  --accent: #b23a2a;
  --code: #f0f0ec;
  --article-text: #30302e;
  --content-width: 1120px;
  --reading-width: 760px;
}

[data-theme="dark"] {
  --background: #111310;
  --surface: #1b1e1a;
  --surface-subtle: #242823;
  --text: #eeeeea;
  --muted: #a4a49c;
  --line: #383834;
  --accent: #e27968;
  --code: #222220;
  --article-text: #d0d0ca;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--background);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
}

.skip-link {
  position: fixed;
  top: 0;
  left: 1rem;
  z-index: 10;
  padding: 0.6rem 0.9rem;
  color: white;
  background: var(--text);
  transform: translateY(-110%);
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header,
.site-footer,
#main-content {
  width: min(calc(100% - 3rem), var(--content-width));
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  border-bottom: 1px solid var(--line);
}

.wordmark {
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  text-decoration: none;
}

.wordmark span {
  color: var(--accent);
}

.site-header nav {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 3vw, 2rem);
}

.site-header nav a {
  color: var(--muted);
  font-size: 0.84rem;
  text-decoration: none;
}

.site-header nav a:hover,
.site-header nav a:focus-visible {
  color: var(--text);
}

.theme-toggle {
  display: grid;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  place-items: center;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  color: var(--text);
  border-color: var(--muted);
}

.theme-icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-icon-sun,
[data-theme="dark"] .theme-icon-moon {
  display: none;
}

[data-theme="dark"] .theme-icon-sun {
  display: block;
}

.intro {
  display: grid;
  max-width: none;
  padding: clamp(3rem, 6vw, 5rem) 0 clamp(2.75rem, 5vw, 4rem);
  grid-template-columns: minmax(260px, 0.85fr) minmax(320px, 1.15fr);
  gap: clamp(2rem, 6vw, 5rem);
  align-items: end;
}

.kicker {
  margin: 0 0 0.8rem;
  color: var(--accent);
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.intro h1 {
  max-width: 620px;
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.8rem, 5vw, 4.8rem);
  font-weight: 400;
  letter-spacing: -0.05em;
  line-height: 1;
}

.intro-copy {
  max-width: 620px;
  margin: 0 0 0.35rem;
  padding-left: clamp(1.25rem, 3vw, 2.25rem);
  border-left: 2px solid var(--accent);
  color: var(--muted);
  font-size: clamp(1rem, 1.5vw, 1.12rem);
}

.research {
  padding: 0 0 clamp(4rem, 8vw, 6rem);
}

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border: 1px solid var(--line);
  background: var(--surface-subtle);
}

.section-header h2,
.about h2 {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.research-tools {
  display: grid;
  grid-template-columns: minmax(220px, 0.7fr) minmax(280px, 1.3fr);
  gap: 0.75rem;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-top: 0;
  background: var(--surface-subtle);
}

.research-tools[hidden] {
  display: none;
}

.category-field,
.search-field {
  position: relative;
  display: grid;
  gap: 0.2rem;
  min-width: 0;
  padding: 0.65rem 0.85rem 0.7rem;
  border: 1px solid var(--line);
  background: var(--surface);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.category-field:hover,
.search-field:hover {
  border-color: var(--muted);
}

.category-field:focus-within,
.search-field:focus-within {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.filter-label {
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.2;
  text-transform: uppercase;
}

.category-field::after {
  position: absolute;
  right: 1rem;
  bottom: 1.1rem;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  content: "";
  pointer-events: none;
  transform: rotate(45deg);
}

.category-field select {
  appearance: none;
  width: 100%;
  min-width: 0;
  padding: 0.15rem 2rem 0 0;
  border: 0;
  color: var(--text);
  background: transparent;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}

.category-field select:hover,
.category-field select:focus {
  outline: 0;
}

.category-field option {
  color: var(--text);
  background: var(--surface);
}

.search-field input {
  width: 100%;
  min-width: 0;
  padding: 0.15rem 0 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font: inherit;
  font-size: 0.88rem;
}

.search-field input::placeholder {
  color: var(--muted);
}

.article-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  padding-top: 1rem;
}

.article-card {
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--surface);
}

.article-card[hidden] {
  display: none;
}

.article-card > a {
  display: grid;
  min-height: 100%;
  grid-template-columns: minmax(230px, 0.78fr) minmax(0, 1.5fr);
  text-decoration: none;
}

.article-preview {
  min-height: 220px;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--surface-subtle);
}

.article-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 300ms ease;
}

.article-card-content {
  display: flex;
  min-width: 0;
  padding: 1.5rem;
  flex-direction: column;
}

.article-card h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.35rem, 2.3vw, 1.8rem);
  font-weight: 400;
  letter-spacing: -0.025em;
  line-height: 1.25;
}

.article-card p {
  display: -webkit-box;
  margin: 0.9rem 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.6;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.article-meta {
  display: flex;
  gap: 0.35rem 0.85rem;
  align-items: center;
  margin-bottom: 0.8rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.7rem;
  line-height: 1.75;
}

.article-meta span:first-child {
  color: var(--accent);
}

.read-link {
  margin-top: auto;
  padding-top: 1.2rem;
  white-space: nowrap;
  font-size: 0.8rem;
  font-weight: 600;
}

.empty-results {
  margin: 0;
  padding: 4rem 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
}

.pagination,
.pagination-pages {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.pagination {
  justify-content: center;
  padding: 2rem 0;
}

.pagination[hidden] {
  display: none;
}

.pagination button {
  min-width: 2.4rem;
  min-height: 2.4rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--surface);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.pagination button:hover:not(:disabled),
.pagination button:focus-visible,
.pagination button.is-current {
  border-color: var(--accent);
  color: var(--accent);
}

.pagination button.is-current {
  font-weight: 700;
}

.pagination button:disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.5;
}

.pagination-ellipsis {
  min-width: 1.5rem;
  color: var(--muted);
  text-align: center;
}

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

.article-card > a:hover h3,
.article-card > a:focus-visible h3,
.article-card > a:hover .read-link,
.article-card > a:focus-visible .read-link {
  color: var(--accent);
}

.article-card:hover,
.article-card:focus-within {
  border-color: var(--muted);
}

.article-card > a:hover .article-preview img,
.article-card > a:focus-visible .article-preview img {
  transform: scale(1.025);
}

.about {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 3rem;
  margin-bottom: clamp(5rem, 10vw, 8rem);
  padding-top: 3rem;
  border-top: 1px solid var(--text);
}

.about p {
  max-width: 680px;
  margin: 0;
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.2rem, 2vw, 1.55rem);
  line-height: 1.55;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  padding: 2rem 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.75rem;
}

.site-footer p {
  margin: 0;
}

.article-page {
  width: min(100%, var(--reading-width));
  margin: 0 auto;
  padding: clamp(4rem, 9vw, 7rem) 0;
}

.article-header {
  margin-bottom: 4rem;
  padding-bottom: 3rem;
  border-bottom: 1px solid var(--line);
}

.back-link {
  color: var(--muted);
  font-size: 0.8rem;
  text-decoration: none;
}

.back-link:hover,
.back-link:focus-visible {
  color: var(--accent);
}

.article-byline {
  display: flex;
  gap: 0.5rem;
  margin: 3rem 0 1rem;
  color: var(--accent);
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
}

.article-header h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.5rem, 6vw, 4.6rem);
  font-weight: 400;
  letter-spacing: -0.05em;
  line-height: 1.05;
}

.article-description {
  margin: 1.7rem 0 0;
  color: var(--muted);
  font-size: 1.08rem;
}

.article-content {
  color: var(--article-text);
}

.article-content h2,
.article-content h3,
.article-content h4 {
  color: var(--text);
  line-height: 1.25;
  scroll-margin-top: 2rem;
}

.article-content h2 {
  margin: 4rem 0 1.2rem;
  padding-top: 1rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  font-weight: 400;
  letter-spacing: -0.03em;
}

.article-content h3 {
  margin: 2.8rem 0 1rem;
  font-size: 1.25rem;
}

.article-content h4 {
  margin: 2rem 0 0.8rem;
  font-size: 1rem;
}

.article-content p,
.article-content ul,
.article-content ol {
  margin-block: 1.15rem;
}

.article-content a {
  color: var(--accent);
  text-underline-offset: 0.16em;
}

.article-content blockquote {
  margin: 2rem 0;
  padding: 0.4rem 1.25rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  background: var(--surface);
}

.article-content blockquote p {
  margin: 0.6rem 0;
}

.article-content code {
  padding: 0.1em 0.3em;
  border-radius: 3px;
  background: var(--code);
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.88em;
}

.article-content pre {
  overflow-x: auto;
  margin: 1.8rem 0;
  padding: 1.2rem;
  border: 1px solid var(--line);
  background: var(--code);
  font-size: 0.82rem;
  line-height: 1.55;
}

.article-content pre code {
  padding: 0;
  background: transparent;
}

.mermaid-figure {
  margin: 2.5rem 0;
  padding: clamp(1rem, 3vw, 2rem);
  overflow-x: auto;
  border: 1px solid var(--line);
  background: var(--surface);
}

.mermaid-embed {
  display: flex;
  min-width: 620px;
  justify-content: center;
}

.mermaid-embed svg {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
}

.mermaid-figure figcaption {
  margin-top: 1rem;
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.68rem;
  text-align: center;
  text-transform: uppercase;
}

.article-figure {
  margin: 2.5rem 0;
  padding: clamp(0.5rem, 2vw, 1rem);
  border: 1px solid var(--line);
  background: #ffffff;
}

.article-figure img {
  display: block;
  width: 100%;
  height: auto;
}

.article-figure figcaption {
  margin-top: 1rem;
  color: #486581;
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.68rem;
  text-align: center;
  text-transform: uppercase;
}

.article-content table {
  display: block;
  width: 100%;
  overflow-x: auto;
  margin: 1.8rem 0;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.article-content th,
.article-content td {
  min-width: 130px;
  padding: 0.75rem;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.article-content th {
  background: var(--code);
}

.error-page {
  display: grid;
  min-height: 100vh;
  padding: 2rem;
  text-align: center;
  place-content: center;
}

.error-code {
  margin: 3rem 0 0;
  color: var(--accent);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}

.error-page h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3rem, 10vw, 6rem);
  font-weight: 400;
}

.error-page > p:not(.error-code) {
  color: var(--muted);
}

.button {
  justify-self: center;
  margin-top: 1rem;
  padding-bottom: 0.15rem;
  border-bottom: 1px solid currentColor;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
}

@media (max-width: 800px) {
  .intro {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .intro-copy {
    max-width: 680px;
  }

  .research-tools {
    grid-template-columns: 1fr;
  }

  .article-list {
    grid-template-columns: 1fr;
  }

  .article-card > a {
    grid-template-columns: minmax(180px, 0.7fr) minmax(0, 1.3fr);
  }

  .article-preview {
    min-height: 200px;
  }
}

@media (max-width: 560px) {
  .site-header,
  .site-footer,
  #main-content {
    width: min(calc(100% - 2rem), var(--content-width));
  }

  .site-header nav a:nth-child(2) {
    display: none;
  }

  .intro {
    padding: 3rem 0;
  }

  .intro h1 {
    font-size: 3rem;
  }

  .intro-copy {
    padding-left: 1rem;
  }

  .article-card > a {
    grid-template-columns: 1fr;
  }

  .article-preview {
    min-height: 0;
    aspect-ratio: 16 / 9;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .article-card-content {
    padding: 1.25rem;
  }

  .about {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .site-footer {
    display: block;
  }

  .site-footer p + p {
    margin-top: 0.3rem;
  }

  .article-byline {
    flex-wrap: wrap;
  }
}

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