/* Foundation */

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

:root {
  color-scheme: light;
  --paper: #faf9f6;
  --surface: #f2f0eb;
  --ink: #24221f;
  --heading: #1f1d1a;
  --muted: #6c675f;
  --line: #d9d4cb;
  --accent: #75552d;
  --danger: #7d392e;
  --syntax-keyword: #cf222e;
  --syntax-string: #0a3069;
  --syntax-number: #0550ae;
  --sans: ui-sans-serif, system-ui, sans-serif;
  --serif: Iowan Old Style, Palatino Linotype, Georgia, serif;
  --mono: SFMono-Regular, Consolas, monospace;
}

.dark-theme {
  color-scheme: dark;
  --paper: #181716;
  --surface: #242321;
  --ink: #e5e0d7;
  --heading: #fffaf1;
  --muted: #aaa49b;
  --line: #4a4640;
  --accent: #dfb978;
  --danger: #efaaa0;
  --syntax-keyword: #ff7b72;
  --syntax-string: #a5d6ff;
  --syntax-number: #79c0ff;
}

/* Typography */

body {
  min-height: 100vh;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: clamp(1.06rem, 1rem + 0.22vw, 1.19rem) / 1.68 var(--serif);
  text-rendering: optimizeLegibility;
}

a {
  color: inherit;
  text-decoration-thickness: 0.06em;
  text-underline-offset: 0.16em;
}

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

:where(a, button, input, textarea):focus-visible {
  outline: 0.14rem solid var(--accent);
  outline-offset: 0.18rem;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  color: var(--heading);
  font-family: var(--sans);
  line-height: 1.12;
  text-wrap: balance;
}

h1 {
  font-size: clamp(2.1rem, 1.7rem + 1.5vw, 3rem);
  letter-spacing: -0.04em;
}

h2 {
  font-size: clamp(1.6rem, 1.4rem + 0.9vw, 2.1rem);
}

h3 {
  font-size: clamp(1.25rem, 1.1rem + 0.5vw, 1.5rem);
}

/* Site layout and navigation */

.page {
  width: min(calc(100% - 2.5rem), 45rem);
  margin-inline: auto;
}

.site-header,
.navigation,
.search-form > div {
  display: flex;
}

.site-header {
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding-block: clamp(2rem, 5vw, 3rem) 1.5rem;
  border-bottom: 1px solid var(--line);
}

.site-name {
  margin: 0;
  font: 750 1.35rem var(--sans);
  letter-spacing: -0.025em;
  line-height: 1;
}

.site-name a,
.navigation a,
.article-summary h2 a,
.pagination a {
  text-decoration: none;
}

.navigation {
  align-items: center;
  gap: clamp(0.8rem, 2.5vw, 1.5rem);
  font: 0.86rem var(--sans);
  line-height: 1;
}

.navigation a,
.theme-button {
  color: var(--muted);
}

.navigation .current {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 0.4em;
}

.site-header :is(a, .theme-button):is(:hover, :focus-visible) {
  color: var(--accent);
}

/* Theme switcher */

.theme-button {
  width: 2rem;
  height: 2rem;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
}

.theme-icon {
  width: 1.15rem;
  aspect-ratio: 1;
  background: currentColor;
  mask: center / contain no-repeat;
}

.theme-icon-system { mask-image: url("/static/icons/monitor.svg"); }
.theme-icon-dark { mask-image: url("/static/icons/moon.svg"); }
.theme-icon-light { mask-image: url("/static/icons/sun.svg"); }

/* Page structure */

#content {
  padding-block: clamp(3rem, 8vw, 5rem);
}

.site-footer {
  padding-block: 1.5rem 3rem;
  border-top: 1px solid var(--line);
}

.page-heading,
.article-header {
  margin-bottom: clamp(2rem, 6vw, 4rem);
}

.page-heading > p {
  max-width: 36rem;
  margin: 0.8rem 0 0;
  color: var(--muted);
  font-size: 1.25rem;
}

/* Article lists and metadata */

.article-list {
  display: grid;
  gap: clamp(2rem, 6vw, 3rem);
}

.article-summary h2 {
  margin-bottom: 0.35rem;
}

.article-summary > p:last-child {
  margin: 0.6rem 0 0;
}

.site-footer,
.article-date,
.comment-meta,
.search-status {
  color: var(--muted);
  font: 0.82rem var(--sans);
}

.article-date,
.comment-meta {
  margin: 0.7rem 0 0;
}

.article-tags,
.pagination ul {
  display: flex;
  flex-wrap: wrap;
  padding: 0;
  list-style: none;
}

.article-tags {
  gap: 0.4rem;
  margin: 0.8rem 0 0;
  font: 0.76rem var(--sans);
}

.article-tags li {
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
}

.article-tags a {
  color: inherit;
  text-decoration: none;
}

.article-tags a:hover {
  color: var(--text);
}

/* Pagination */

.pagination {
  margin-top: clamp(3rem, 8vw, 5rem);
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
  font: 0.86rem var(--sans);
}

.pagination ul {
  align-items: center;
  gap: 0.45rem;
  margin: 0;
}

.theme-button,
.pagination :is(a, span) {
  display: grid;
  place-items: center;
}

.pagination :is(a, span) {
  min-width: 2rem;
  height: 2rem;
  padding-inline: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
}

.pagination a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.pagination [aria-current="page"] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

/* Search */

.search-form {
  margin-bottom: 1rem;
}

.search-form label {
  margin-bottom: 0.45rem;
  font-weight: 650;
}

.search-form > div {
  gap: 0.6rem;
}

.search-form input {
  min-width: 0;
  flex: 1;
}

.search-form button,
.comment-form button[type="submit"] {
  padding: 0.65rem 1rem;
  border: 1px solid var(--ink);
  border-radius: 0.3rem;
  background: var(--ink);
  color: var(--paper);
  font: 650 0.86rem var(--sans);
  cursor: pointer;
}

.search-status {
  min-height: 1.5em;
  margin: 0 0 2rem;
}

/* Article content */

.prose {
  overflow-wrap: break-word;
}

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

.prose > * + * {
  margin-top: 1.35em;
}

.prose :is(h2, h3, h4) {
  margin-top: 1.8em;
}

.prose :is(ul, ol) {
  padding-left: 1.4em;
}

.prose blockquote {
  margin-left: 0;
  padding-left: 1.4rem;
  border-left: 0.18rem solid var(--line);
  color: var(--muted);
}

.prose :not(pre) > code {
  padding: 0.12em 0.28em;
  border-radius: 0.2rem;
  background: var(--surface);
  font: 0.86em var(--mono);
}

.prose pre {
  overflow-x: auto;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  background: var(--surface);
  font: 0.84em/1.55 var(--mono);
}

.prose table {
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
}

.prose :is(th, td) {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--line);
  text-align: left;
}

/* Comments */

#comments {
  margin-top: clamp(3rem, 8vw, 5rem);
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.comment {
  padding-block: 1.5rem;
  border-bottom: 1px solid var(--line);
}

.comment-meta {
  font-weight: 700;
}

.comment-body {
  white-space: pre-wrap;
}

.comment-form {
  margin-top: 4rem;
}

.comment-form > p {
  color: var(--muted);
  font: 0.86rem var(--sans);
}

.field {
  margin-top: 1.25rem;
}

.field label {
  margin-bottom: 0.35rem;
  font-weight: 700;
}

.search-form label,
.field label {
  display: block;
  font-family: var(--sans);
  font-size: 0.86rem;
}

.search-form input,
.field :is(input, textarea) {
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--muted);
  border-radius: 0.3rem;
  background: var(--paper);
  color: var(--ink);
  font: 1rem var(--sans);
}

.field :is(input, textarea) {
  width: 100%;
}

.field textarea {
  resize: vertical;
  line-height: 1.5;
}

.comment-form button[type="submit"] {
  margin-top: 1.25rem;
}

.notice,
.form-error {
  margin-block: 1.25rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
  background: var(--surface);
  font: 0.86rem var(--sans);
}

.form-error {
  border-color: var(--danger);
  color: var(--danger);
}

/* Comment administration */

.comment-admin {
  max-width: 48rem;
}

.admin-heading,
.admin-actions {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
}

.admin-heading form,
.admin-actions form {
  margin: 0;
}

.admin-comment-list {
  display: grid;
  gap: 1.25rem;
}

.admin-comment {
  border: 1px solid var(--line);
  padding: 1rem;
}

.admin-comment header p {
  margin-block: 0 0.4rem;
}

.admin-comment-body {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.admin-actions {
  justify-content: flex-start;
}

/* Accessibility */

.skip-link {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  translate: 0 -200%;
  padding: 0.5rem;
  background: var(--paper);
}

.skip-link:focus {
  translate: 0;
}

/* Syntax highlighting */

.hljs-comment,
.hljs-quote {
  color: var(--muted);
}

.hljs-keyword,
.hljs-literal {
  color: var(--syntax-keyword);
}

.hljs-string,
.hljs-title {
  color: var(--syntax-string);
}

.hljs-number,
.hljs-variable {
  color: var(--syntax-number);
}

/* Responsive layout */

@media (max-width: 36rem) {
  .site-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .navigation {
    flex-wrap: wrap;
  }

  .search-form > div {
    align-items: stretch;
    flex-direction: column;
  }

  .admin-heading {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* Printing */

@media print {
  :root,
  .dark-theme {
    color-scheme: light;
    --paper: #fff;
    --ink: #000;
    --heading: #000;
  }

  .page {
    width: 100%;
  }

  .navigation,
  #comments,
  .site-footer,
  .skip-link {
    display: none;
  }
}
