/* Custom tweaks only. Everything else comes from Tailwind (CDN) + the typography plugin. */

:root {
  --font-serif: "Iowan Old Style", Charter, Georgia, Cambria, "Times New Roman", serif;
}

body {
  font-family: var(--font-serif);
}

html.dark {
  color-scheme: dark;
}

/* Short headings wrap to balanced lines instead of leaving one orphan word. */
h1, h2, h3 {
  text-wrap: balance;
}

/* Dates and counts line up in the post feed. */
time {
  font-variant-numeric: tabular-nums;
}

/* Code blocks scroll instead of widening the page on mobile. */
pre {
  overflow-x: auto;
}
pre code {
  display: block;
  min-width: max-content;
  font-size: 0.875em;
}

/* Code card with language label and copy button, built by main.js. */
.code-block {
  margin-block: 1.75em;
  border: 1px solid #292524;
  border-radius: 0.5rem;
  background: #1c1917;
  overflow: hidden;
}
.code-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid #292524;
  color: #a8a29e;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.75rem;
  line-height: 1.5;
}
.code-copy {
  border: 1px solid #44403c;
  border-radius: 0.375rem;
  padding: 0.1rem 0.5rem;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.code-copy:hover {
  color: #fafaf9;
  border-color: #78716c;
}
.code-copy:focus-visible {
  outline: 2px solid #fafaf9;
  outline-offset: 2px;
}
.prose .code-block pre {
  margin: 0;
  border-radius: 0;
  background: transparent;
}
/* highlight.js paints its own box; the card already provides background and padding. */
.prose .code-block pre code.hljs {
  padding: 0;
  overflow: visible;
  background: transparent;
}

/* Inline code reads as code, not as a link. */
:not(pre) > code {
  font-size: 0.875em;
  padding: 0.1em 0.35em;
  border-radius: 0.25rem;
  background: rgb(0 0 0 / 0.06);
}
html.dark :not(pre) > code {
  background: rgb(255 255 255 / 0.1);
}

/* The typography plugin adds decorative backticks around inline code; the padding already marks it. */
.prose :not(pre) > code::before,
.prose :not(pre) > code::after {
  content: none;
}

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

/* Theme consent bar (built by main.js). Fixed to the bottom; the script pads
   <body> by its height so it never sits on top of the footer. */
.theme-consent {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 1rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid #e7e5e4;
  background: #fafaf9;
  color: #44403c;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.875rem;
  line-height: 1.5;
}
.theme-consent p {
  margin: 0;
  max-width: 32rem;
}
.theme-consent-actions {
  display: flex;
  gap: 0.5rem;
}
.theme-consent button {
  border: 1px solid #d6d3d1;
  border-radius: 0.375rem;
  padding: 0.3rem 0.75rem;
  background: #fff;
  color: #292524;
  font: inherit;
  cursor: pointer;
}
.theme-consent button:hover {
  border-color: #a8a29e;
}
.theme-consent button:focus-visible {
  outline: 2px solid #1c1917;
  outline-offset: 2px;
}
html.dark .theme-consent {
  border-color: #292524;
  background: #1c1917;
  color: #d6d3d1;
}
html.dark .theme-consent button {
  border-color: #44403c;
  background: transparent;
  color: #e7e5e4;
}
html.dark .theme-consent button:hover {
  border-color: #78716c;
}
html.dark .theme-consent button:focus-visible {
  outline-color: #fafaf9;
}

/* Long URLs and hashes wrap instead of forcing a horizontal scrollbar. */
p, li, figcaption {
  overflow-wrap: break-word;
}

/* Avoids a lonely last word on short paragraphs. Ignored by older browsers. */
p {
  text-wrap: pretty;
}

/* Wide tables scroll like code blocks instead of breaking the page width. */
.prose table {
  display: block;
  overflow-x: auto;
}

/* Fallback layout: keeps the page readable if the Tailwind CDN never arrives.
   Same values as Tailwind's max-w-2xl / px-4, so nothing changes when it does. */
main {
  max-width: 42rem;
  margin-inline: auto;
  padding-inline: 1rem;
}

/* Paper is white: undo the dark palette and let code wrap instead of clipping. */
@media print {
  html.dark body { background: #fff !important; }
  html.dark body * { background: transparent !important; color: #111 !important; }
  pre, pre code { white-space: pre-wrap !important; min-width: 0 !important; }
  #theme-toggle, [data-search], .code-bar, .theme-consent { display: none !important; }
  body { padding-bottom: 0 !important; }
  .prose .code-block { background: #f5f5f4 !important; border-color: #d6d3d1 !important; }
  .prose .code-block pre,
  .prose .code-block pre code,
  .prose .code-block pre code * { color: #111 !important; background: transparent !important; }
}
