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

:root {
  --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  /* Brand palette from Grofolio design system */
  --brand-espresso: #27221b;
  --brand-coral: #fe7264;
  --brand-brown: #423117;
  --brand-white: #ffffff;
}

::selection {
  background: #fe7264;
  color: #ffffff;
}

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

a {
  transition: color 0.15s ease;
}

.prose a {
  text-decoration-color: #fe7264;
  text-underline-offset: 3px;
}
.prose a:hover {
  color: #fe7264;
}

html.dark {
  color-scheme: dark;
}

/* Headings wrap cleanly with modern balanced proportions. */
h1, h2, h3, h4 {
  font-family: var(--font-sans);
  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;
}

/* Code blocks scroll smoothly with touch momentum on mobile devices */
pre {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* On mobile (<640px), keep text left-aligned with natural word spacing to prevent gaping whitespace holes (rivers).
   On desktop (>=640px), apply full justification for crisp, straight margins. */
.prose p,
.text-justify p {
  text-align: left;
  text-align-last: left;
  text-wrap: pretty;
  hyphens: auto;
  -webkit-hyphens: auto;
}

@media (min-width: 640px) {
  .prose p,
  .text-justify p {
    text-align: justify;
    text-justify: inter-word;
    text-align-last: left;
  }
}

.prose h1,
.prose h2,
.prose h3,
.prose h4,
.prose li,
.prose pre {
  text-align: left;
  text-align-last: left;
}

.prose figcaption {
  text-align: center;
  font-size: 0.875rem;
  color: #78716c;
}

/* Mobile-tuned reading typography */
@media (max-width: 639px) {
  .prose {
    font-size: 1rem;
    line-height: 1.72;
  }
  .prose h2 {
    font-size: 1.3rem;
    line-height: 1.35;
    margin-top: 1.6em;
    margin-bottom: 0.6em;
  }
  .prose pre code {
    font-size: 0.8125rem;
  }
  .code-bar {
    padding: 0.35rem 0.65rem;
    font-size: 0.7rem;
  }
}

/* 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-3xl / px-4, so nothing changes when it does. */
main {
  max-width: 48rem;
  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; }
}
