/* ============================================================
   Editorial refinements (additive pass over terminal.css)
   Loaded last so rules win without !important.

   Scope: only adds what visibly improves reading. If a rule
   doesn't pull weight, it gets removed — not stacked.
   ============================================================ */

:root {
  --measure: 68ch;
  --radius: 6px;
  --transition: 160ms cubic-bezier(0.2, 0, 0, 1);
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

html { scroll-behavior: smooth; }

body {
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern", "liga", "calt";
}

:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 3px;
  border-radius: 3px;
}

/* Scoped scrollbar styling (only the page, not every element) */
html { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
html::-webkit-scrollbar { width: 10px; }
html::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 2px solid var(--bg);
}

/* ---------- Header (no sticky, no animations that overflow) ---------- */
.header { border-bottom: 1px solid var(--border); }
.nav { padding-block: 0.5rem; }
#menu { gap: 1.25rem; }
#menu a { transition: color var(--transition); }

/* ---------- Homepage hero ---------- */
.home-info .entry-title {
  font-size: clamp(1.9rem, 1.5rem + 1.2vw, 2.4rem);
  line-height: 1.15;
}
.home-info .entry-content { max-width: 60ch; }

.social-icons {
  display: inline-flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.75rem;
}
.social-icons a {
  display: inline-flex;
  width: 32px; height: 32px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  transition: opacity var(--transition);
}

/* ---------- Post list ---------- */
.post-entry .entry-header {
  align-items: baseline;
  gap: 1.5rem;
}
.post-entry .entry-title {
  font-size: 1.2rem;
  letter-spacing: -0.005em;
  flex: 1 1 auto;
}
.post-entry .entry-hint {
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
  color: var(--text-subtle);
}
.post-entry .entry-content { max-width: 70ch; }

/* ---------- Post header ---------- */
.post-title {
  font-size: clamp(1.9rem, 1.5rem + 1.4vw, 2.5rem);
  line-height: 1.2;
}
.post-description {
  font-style: italic;
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin: 0.5rem 0 1rem;
  max-width: 60ch;
}
.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ---------- Single post layout: sidebar TOC on wide screens ---------- */
.post-body { display: block; }
.post-content { max-width: var(--measure); }

@media (min-width: 1180px) {
  .post-single { --post-main-width: 720px; }
  .main { max-width: min(1180px, 100%) !important; }

  .post-body {
    display: grid;
    grid-template-columns: minmax(0, var(--post-main-width)) minmax(180px, 220px);
    column-gap: 3.5rem;
    align-items: start;
  }
  .post-body > .post-content { grid-column: 1; min-width: 0; }
  .post-body > .toc { grid-column: 2; }

  /* Constrain article header/footer to the same column as text */
  .post-single > header,
  .post-single > .post-cover,
  .post-single > .post-footer,
  .post-single > .post-git-diff,
  .post-single > .related-posts,
  .post-single > .paginav,
  .post-single > section.comments {
    max-width: var(--post-main-width);
  }
}

/* ---------- TOC: an obvious, always-visible list (no <details> click) ---------- */
.toc {
  margin: 0 0 2rem;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  font-family: var(--font-ui);
}
.toc-title {
  margin: 0 0 0.6rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.toc #TableOfContents { padding: 0; }
.toc #TableOfContents > ul { padding-left: 0; margin: 0; }
.toc ul {
  list-style: none;
  padding-left: 0.9rem;
  margin: 0;
  border-left: 1px solid var(--border);
}
.toc li { margin: 0; }
.toc a {
  display: block;
  padding: 0.2rem 0 0.2rem 0.6rem;
  margin-left: -1px;
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--text-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}
.toc a:hover {
  color: var(--text);
  border-left-color: var(--border-strong);
}

/* Mobile / narrow: TOC sits inline; give it a soft frame so it reads as UI,
   not as the start of the article. */
@media (max-width: 1179px) {
  .toc {
    padding: 0.9rem 1rem;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius);
  }
}

/* Wide: sticky companion */
@media (min-width: 1180px) {
  .toc {
    position: sticky;
    top: 1.5rem;
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
    padding: 0;
  }
}

/* ---------- Post body typography ---------- */
.post-content h2,
.post-content h3 { scroll-margin-top: 1rem; }

/* Subtle # anchor on heading hover */
.post-content h2 > a,
.post-content h3 > a,
.post-content h4 > a { color: inherit; text-decoration: none; position: relative; }
.post-content h2 > a::before,
.post-content h3 > a::before {
  content: "#";
  position: absolute;
  left: -1.1em;
  color: var(--text-subtle);
  opacity: 0;
  font-weight: 400;
  transition: opacity var(--transition);
}
.post-content h2:hover > a::before,
.post-content h3:hover > a::before { opacity: 1; }

/* Blockquote: terracotta rule, italic only on the prose */
.post-content blockquote {
  border-left: 2px solid var(--accent);
  padding: 0.1rem 0 0.1rem 1.6rem;
  font-style: normal;
  color: var(--text-secondary);
}
.post-content blockquote p { font-style: italic; }

/* Inline links: thinner, calmer */
.post-content a {
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

/* Code copy button reveal on hover */
.post-content .highlight { position: relative; }
.copy-code {
  opacity: 0;
  transition: opacity var(--transition);
}
.post-content .highlight:hover .copy-code,
.copy-code:focus-visible { opacity: 1; }

/* Tabular numerals in tables */
.post-content table {
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}

/* ---------- Prev / Next navigation ----------
   Override terminal.css: that file gives .paginav margin-top: 4rem AND
   padding-top: 2.5rem (≈ 104px of empty space above the divider). It also
   forces flex-direction: column on each <a>, leaving the title label and
   the post title separated by a full body line-height. Tighten everything. */
.paginav {
  margin-top: 2.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 2rem;
}
.paginav a {
  display: inline-flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0;
  max-width: 48%;
}
.paginav a > br { display: none; }
.paginav .title {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-subtle);
  line-height: 1;
}
.paginav .post-title,
.paginav a > span:last-child {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.35;
  color: var(--text);
}
.paginav a:hover .post-title,
.paginav a:hover > span:last-child { color: var(--link); }

/* Subtle arrows; only one source of arrows now (partial has no « »). */
.paginav a.prev .title::before { content: "← "; letter-spacing: 0; }
.paginav a.next { text-align: right; margin-left: auto; }
.paginav a.next .title::after { content: " →"; letter-spacing: 0; }

@media (max-width: 640px) {
  .paginav { flex-direction: column; gap: 1.25rem; }
  .paginav a { max-width: 100%; }
  .paginav a.next { text-align: left; margin-left: 0; }
  .paginav a.next .title::after { content: none; }
  .paginav a.next .title::before { content: "→ "; letter-spacing: 0; }
}

/* ---------- Empty post-tags <ul> ----------
   PaperMod's single.html always renders <ul class="post-tags">…</ul>;
   Hugo emits whitespace inside, so :empty doesn't match. Use :not(:has(li)). */
.post-tags:not(:has(li)) { display: none; }

/* ---------- "Edited after publication" diff widget ----------
   Source partial (post_git_diff.html) emits per-line spans tagged
   diff-header / diff-hunk / diff-add / diff-del / diff-ctx, and the
   add/del prefix character is now stripped at the template level so
   the +/- can live in a CSS gutter and the line text aligns properly.

   Goals:
     - Reader-friendly summary chip (small-caps label + date), matches
       site's other section labels.
     - Hide git plumbing the reader can't act on (diff/index/+++/---/@@).
     - Wrap long prose lines (no horizontal scroll for paragraph edits).
     - Soft, light-theme red/green; inline gutter, not part of the text. */

.post-git-diff {
  margin: 2.5rem 0 0;
  padding: 0;
  border: 0;
  border-top: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
}
.post-git-diff > summary {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 1rem 0 0;
  background: transparent;
  border: 0;
  cursor: pointer;
  list-style: none;
}
.post-git-diff > summary::-webkit-details-marker { display: none; }
.post-git-diff > summary::before {
  content: "▸";
  display: inline-block;
  width: 0.7em;
  font-size: 0.7rem;
  color: var(--text-subtle);
  transition: transform var(--transition);
}
.post-git-diff[open] > summary::before { transform: rotate(90deg); }

.post-git-diff-label {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}
.post-git-diff-when {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--text-subtle);
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}

/* Hide the scary git plumbing entirely */
.post-git-diff .diff-header,
.post-git-diff .diff-hunk { display: none; }

/* Diff body: prose-friendly, wraps, no big chrome */
.post-git-diff-body {
  margin: 0.85rem 0 0;
  padding: 0;
  background: transparent;
  border: 0;
}
.post-git-diff-block {
  margin: 0;
  padding: 0;
  background: transparent;
  font-family: var(--font-body);
  font-size: 0.95rem;
  line-height: 1.55;
  font-weight: normal;
  overflow-x: visible;
}
.post-git-diff-block .diff-add,
.post-git-diff-block .diff-del,
.post-git-diff-block .diff-ctx {
  display: block;
  position: relative;
  padding: 0.15rem 0.6rem 0.15rem 1.6rem;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  border-left: 2px solid transparent;
  border-radius: 0 3px 3px 0;
}
.post-git-diff-block .diff-ctx {
  color: var(--text-muted);
}
.post-git-diff-block .diff-add {
  background: rgba(34, 139, 84, 0.07);
  border-left-color: rgb(34, 139, 84);
}
.post-git-diff-block .diff-del {
  background: rgba(180, 83, 9, 0.07);
  border-left-color: var(--accent);
  color: var(--text-secondary);
  text-decoration: line-through;
  text-decoration-color: rgba(180, 83, 9, 0.4);
}
.post-git-diff-block .diff-add::before,
.post-git-diff-block .diff-del::before {
  position: absolute;
  left: 0.45rem;
  top: 0.15rem;
  font-family: var(--font-mono);
  font-size: 0.85em;
  font-weight: 600;
  width: 0.9rem;
  text-align: center;
}
.post-git-diff-block .diff-add::before {
  content: "+";
  color: rgb(34, 139, 84);
}
.post-git-diff-block .diff-del::before {
  content: "−";
  color: var(--accent);
}

/* ---------- Related posts: clean line-style (no pill cards) ---------- */
.related-posts {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.related-posts-title {
  margin: 0 0 1rem;
  font-family: var(--font-ui);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}
.related-posts-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.related-post-item { margin: 0; }
.related-post-link {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1.5rem;
  padding: 0.65rem 0;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  text-decoration: none;
}
.related-post-item:last-child .related-post-link { border-bottom: none; }
.related-post-link:hover {
  background: none;
  border-color: var(--border);
}
.related-post-title {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.4;
  transition: color var(--transition);
}
.related-post-link:hover .related-post-title { color: var(--link); }
.related-post-date {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
  color: var(--text-subtle);
  white-space: nowrap;
}

@media (max-width: 640px) {
  .related-post-link {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
  }
}

/* ---------- Footer: minimal, single line ---------- */
/* PaperMod renders two <span>s separated by a " · " text node.
   Hide the second span ("Powered by Hugo & PaperMod") and the bullet. */
.footer {
  border-top: 1px solid var(--border);
  background: var(--bg);
  margin-top: 4rem;
  padding: 1.75rem 1.5rem;
  text-align: center;
  font-family: var(--font-ui);
  /* zero out direct text nodes (the " · " separator); restore on children */
  font-size: 0;
}
.footer > * { font-size: 0.8rem; }
.footer span:nth-of-type(2) { display: none; }
.footer span,
.footer a {
  color: var(--text-subtle);
}
.footer a {
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition), color var(--transition);
}
.footer a:hover {
  color: var(--text);
  border-bottom-color: var(--border-strong);
}

/* ---------- Print ---------- */
@media print {
  .header, .footer, .top-link, .paginav, .related-posts,
  .share-buttons, .post-tags, .toc, .breadcrumbs,
  .copy-code, .post-git-diff { display: none !important; }
  body { font-size: 11pt; line-height: 1.55; color: #000; background: #fff; }
  .post-content a { color: #000; text-decoration: underline; }
  .post-content a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.85em; }
  .post-content pre, .post-content code {
    background: #f5f5f4 !important;
    color: #000 !important;
    border: 1px solid #ddd;
  }
  .post-title { font-size: 22pt; }
  h2, h3 { page-break-after: avoid; }
  pre, blockquote, figure, table { page-break-inside: avoid; }
}
