/* ============================================
   Alexander Nikolov — Blog
   Typography-first, clean editorial design
   ============================================ */

:root {
  --text: #1a1a1a;
  --text-secondary: #555;
  --text-muted: #888;
  --bg: #fafaf8;
  --bg-code: #f2f0eb;
  --border: #ddd;
  --accent: #2a5a3a;
  --accent-hover: #1d4029;
  --tag-bg: #eef2ef;
  --max-width: 600px;
  --font-body: 'Public Sans', 'Inter', 'Fira Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Menlo', monospace;
}

/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-size: 1.125rem;
  font-weight: 400;
  line-height: 1.7;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Layout — constrain the Archie .content wrapper itself so header, main,
   and footer all share the same column width automatically. */
.content {
  max-width: var(--max-width);
}
main {
  padding: 2rem 0 4rem;
}

/* Visual separator between full posts on the homepage */
.list-item + .list-item {
  margin-top: 3rem;
  padding-top: 2.5rem;
  border-top: 1px solid var(--border);
}

/* ---- Header ---- */
/* Override Archie's flex-wrap:wrap so title and nav stay on one line.
   flex-end on both header and nav aligns bottom edges, so the red underlines
   on .main (title) and on each nav <a> sit on the same horizontal line. */
header {
  flex-wrap: nowrap;
  align-items: flex-end;
  gap: 0.5rem;
}
header .main {
  flex-shrink: 0;
  /* Title underline lives on the container (not the <a>) so flex-end
     alignment directly controls its vertical position. */
  border-bottom: 3px solid var(--color-primary, #dc143c);
}
/* Remove the <a> border inside .main — the underline is on .main now */
header .main a {
  border-bottom: none;
  border-block-end: none;
}
/* Compact gap slightly so everything fits in 600px without changing text size */
header nav {
  font-size: 0.95rem;
  gap: 0.75rem;
  flex-shrink: 1;
  /* flex-end so nav link bottoms (with their border-bottom) are at nav's
     bottom edge, which flex-end on header aligns with .main's bottom edge */
  align-items: flex-end;
}
header nav a {
  white-space: nowrap;
}

/* Light mode only: keep nav underlines visually quieter than the title mark. */
:root:not(:has(#dark-mode-toggle[data-theme="dark"])) header nav a {
  color: #6B6760;
  border-bottom-color: #C4BFB4;
  border-block-end-color: #C4BFB4;
}
/* Nav links wrapper: flex on all viewports (not display:contents, which
   caused links to lose their gap on mobile when switching to display:flex) */
header nav .nav-links {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
/* Warm Ink dark mode overrides.
   Scope to the JS toggle state so light mode is untouched. */
:root:has(#dark-mode-toggle[data-theme="dark"]) {
  --bg: #1D1B18;
  --bg-code: #2A2725;
  --text: #D4D0C8;
  --text-secondary: #8A8578;
  --text-muted: #8A8578;
  --border: #8A8578;
  --accent: #D4A04A;
  --accent-hover: #D4A04A;
  --color-background-dark: #1D1B18;
  --color-text-dark: #D4D0C8;
  --color-text-muted-dark: #8A8578;
  --color-primary-dark: #D4A04A;
  --color-primary-hover-dark: #D4A04A;
  --color-border-dark: #8A8578;
  --color-background-code-dark: #2A2725;
  --color-background-pre-dark: #2A2725;
  --color-background-toc-dark: #2A2725;
}

:root:has(#dark-mode-toggle[data-theme="dark"]) body {
  background-color: #1D1B18;
  color: #D4D0C8;
}

:root:has(#dark-mode-toggle[data-theme="dark"]) h1,
:root:has(#dark-mode-toggle[data-theme="dark"]) h2,
:root:has(#dark-mode-toggle[data-theme="dark"]) h3,
:root:has(#dark-mode-toggle[data-theme="dark"]) h4,
:root:has(#dark-mode-toggle[data-theme="dark"]) h5,
:root:has(#dark-mode-toggle[data-theme="dark"]) h6 {
  color: #E8E4DA;
}

:root:has(#dark-mode-toggle[data-theme="dark"]) a {
  color: #C8A96E;
}

:root:has(#dark-mode-toggle[data-theme="dark"]) a:hover,
:root:has(#dark-mode-toggle[data-theme="dark"]) a:focus {
  background-color: #D4A04A;
  color: #E8E4DA;
  border-radius: 3px;
  outline-color: #D4A04A;
}

:root:has(#dark-mode-toggle[data-theme="dark"]) header nav a {
  color: #878379;
  border-bottom-color: #878379;
  border-block-end-color: #878379;
}

:root:has(#dark-mode-toggle[data-theme="dark"]) header .main {
  border-bottom-color: #D4A04A;
}

:root:has(#dark-mode-toggle[data-theme="dark"]) h1::before,
:root:has(#dark-mode-toggle[data-theme="dark"]) h2::before,
:root:has(#dark-mode-toggle[data-theme="dark"]) h3::before,
:root:has(#dark-mode-toggle[data-theme="dark"]) h4::before,
:root:has(#dark-mode-toggle[data-theme="dark"]) h5::before,
:root:has(#dark-mode-toggle[data-theme="dark"]) h6::before {
  color: #D4A04A;
}

:root:has(#dark-mode-toggle[data-theme="dark"]) ul > li::before {
  color: #D4A04A;
}

:root:has(#dark-mode-toggle[data-theme="dark"]) .date,
:root:has(#dark-mode-toggle[data-theme="dark"]) .post-meta,
:root:has(#dark-mode-toggle[data-theme="dark"]) .footer-meta,
:root:has(#dark-mode-toggle[data-theme="dark"]) .footer-meta a,
:root:has(#dark-mode-toggle[data-theme="dark"]) .archive-entry time,
:root:has(#dark-mode-toggle[data-theme="dark"]) .archive-year h2,
:root:has(#dark-mode-toggle[data-theme="dark"]) .tag-count {
  color: #8A8578;
}

:root:has(#dark-mode-toggle[data-theme="dark"]) .nav-toggle .feather {
  stroke: #8A8578 !important;
}

:root:has(#dark-mode-toggle[data-theme="dark"]) code {
  background-color: #2A2725;
  color: #E8E4DA;
}

:root:has(#dark-mode-toggle[data-theme="dark"]) pre {
  background-color: #2A2725;
  border-color: #8A8578;
}

:root:has(#dark-mode-toggle[data-theme="dark"]) pre code {
  color: #D4D0C8;
}

:root:has(#dark-mode-toggle[data-theme="dark"]) header .main a {
  color: #D4D0C8;
  border-bottom: none;
  border-block-end: none;
}

/* ---- Homepage ---- */
.intro {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.intro p {
  font-size: 1.2rem;
  color: var(--text-secondary);
  margin: 0;
}

/* ---- Post previews ---- */
.post-preview {
  margin-bottom: 2rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}
.post-preview:last-child { border-bottom: none; }
.post-preview h2 {
  font-size: 1.35rem;
  font-weight: 600;
  margin: 0 0 0.25rem;
  line-height: 1.3;
}
.post-preview h2 a {
  color: var(--text);
  text-decoration: none;
}
.post-preview h2 a:hover { color: var(--accent); }
.post-preview time {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.post-preview .summary {
  color: var(--text-secondary);
  margin: 0.5rem 0 0;
  font-size: 1rem;
}

/* ---- Homepage post titles ---- */
/* .post-header wraps titles on the homepage list; keep them
   below the blog title (1.5rem) so the hierarchy is clear */
.post-header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.2;
  margin: 0 0 0.5rem;
}

/* ---- Single post ---- */
/* single.html uses <div class="title"><h1> — different from homepage */
.title h1 {
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.2;
  margin: 0 0 0.75rem;   /* zero top margin — Archie's h1 margin-top:2em
                             creates the excessive whitespace gap */
  letter-spacing: -0.01em;
}
.post-header {
  margin-bottom: 2rem;
}
.post-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  gap: 1rem;
}
.post-tags {
  margin-top: 0.75rem;
}

/* Post content */
.post-content h2 {
  font-size: 1.4rem;
  font-weight: 600;
  margin: 2.5rem 0 0.75rem;
}
.post-content h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 2rem 0 0.5rem;
}
.post-content p {
  margin: 0 0 1.6rem;
}
.post-content a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
.post-content a:hover {
  color: var(--accent-hover);
}

/* Light mode only: body-text links need high contrast on accent hover bg.
   Excludes header/title/nav and tag chips. */
:root:not(:has(#dark-mode-toggle[data-theme="dark"])) .post-content a:hover,
:root:not(:has(#dark-mode-toggle[data-theme="dark"])) .post-content a:focus,
:root:not(:has(#dark-mode-toggle[data-theme="dark"])) .intro a:hover,
:root:not(:has(#dark-mode-toggle[data-theme="dark"])) .intro a:focus,
:root:not(:has(#dark-mode-toggle[data-theme="dark"])) .post-preview .summary a:hover,
:root:not(:has(#dark-mode-toggle[data-theme="dark"])) .post-preview .summary a:focus,
:root:not(:has(#dark-mode-toggle[data-theme="dark"])) .footnotes a:hover,
:root:not(:has(#dark-mode-toggle[data-theme="dark"])) .footnotes a:focus,
:root:not(:has(#dark-mode-toggle[data-theme="dark"])) .archive-entry a:hover,
:root:not(:has(#dark-mode-toggle[data-theme="dark"])) .archive-entry a:focus,
:root:not(:has(#dark-mode-toggle[data-theme="dark"])) .back-link a:hover,
:root:not(:has(#dark-mode-toggle[data-theme="dark"])) .back-link a:focus {
  color: #F2F0E9;
}

/* Blockquote */
.post-content blockquote {
  margin: 2rem 0;
  padding: 1rem 1.5rem;
  border-left: 4px solid var(--accent);
  background: var(--bg-code);
  border-radius: 0 4px 4px 0;
  color: var(--text-secondary);
  font-style: italic;
}
.post-content blockquote p {
  margin: 0 0 0.5rem;
}
.post-content blockquote p:last-child {
  margin-bottom: 0;
}

.post-content img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}
.post-content code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-code);
  padding: 0.15em 0.35em;
  border-radius: 3px;
}
.post-content pre {
  background: var(--bg-code);
  padding: 1.25rem;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
  margin: 1.5rem 0;
}
.post-content pre code {
  background: none;
  padding: 0;
}
.post-content ul, .post-content ol {
  font-family: var(--font-body);
  padding-left: 1.5rem;
}
.post-content li {
  font-family: inherit;
  margin-bottom: 0.35rem;
}
.post-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

/* ---- Footnotes ---- */
/* Goldmark already renders an <hr> before the footnotes section;
   don't add a second line via border-top */
.footnotes {
  margin-top: 3rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
}
.footnotes ol {
  padding-left: 1.25rem;
}
.footnotes li {
  margin-bottom: 0.5rem;
}
.footnotes p {
  margin: 0;
}
/* Footnote reference in body text */
sup a[href^="#fn"] {
  font-size: 0.75em;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  padding: 0 0.1em;
}
sup a[href^="#fn"]:hover {
  text-decoration: underline;
}
/* Back-to-text arrow in footnote */
a[href^="#fnref"] {
  font-size: 0.8em;
  color: var(--text-muted);
  text-decoration: none;
  margin-left: 0.25em;
}
a[href^="#fnref"]:hover {
  color: var(--accent);
}

/* Post navigation */
.post-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
  gap: 1rem;
}
.post-nav a {
  color: var(--accent);
  text-decoration: none;
  max-width: 48%;
}
.post-nav a:hover { text-decoration: underline; }
.post-nav-next { margin-left: auto; text-align: right; }

/* ---- Tags ---- */
.post-tags ul.tags,
.tags-page ul.tags,
.tags-page .tag-cloud,
.tags-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.post-tags nav.tags {
  display: block;
}

.tags-label {
  display: block;
  margin-bottom: 6px;
  font-family: 'Commit Mono', monospace;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #878379;
}

/* Force the term page's inline font-size into the same chip scale. */
.tags a,
a.tag,
a.tag-small,
.tag-cloud .tag,
.tag-cloud .tag-cloud-item {
  display: inline-flex;
  align-items: center;
  font-family: 'Commit Mono', monospace;
  font-size: 0.85rem !important;
  line-height: 1.2;
  padding: 4px 12px;
  border-radius: 4px;
  color: #c94040;
  background: rgba(201, 64, 64, 0.08);
  border: 1px solid rgba(201, 64, 64, 0.2);
  text-decoration: none;
  border-bottom: none !important;
  border-block-end: none !important;
}

.tags a:hover,
.tags a:focus,
a.tag:hover,
a.tag:focus,
a.tag-small:hover,
a.tag-small:focus,
.tag-cloud .tag:hover,
.tag-cloud .tag:focus,
.tag-cloud .tag-cloud-item:hover,
.tag-cloud .tag-cloud-item:focus {
  color: #c94040;
  background: rgba(201, 64, 64, 0.15);
  text-decoration: none;
  border-bottom: none !important;
  border-block-end: none !important;
  outline: none;
}

/* Hide Archie list glyphs in tag lists. */
.tags li::before {
  content: none;
}

/* Cancel Archie's global list indentation in tag chips.
   Without this, each chip gets shifted left and can overlap. */
.tags li {
  text-indent: 0;
  margin: 0;
  padding: 0;
}

:root:has(#dark-mode-toggle[data-theme="dark"]) .tags a,
:root:has(#dark-mode-toggle[data-theme="dark"]) a.tag,
:root:has(#dark-mode-toggle[data-theme="dark"]) a.tag-small,
:root:has(#dark-mode-toggle[data-theme="dark"]) .tag-cloud .tag,
:root:has(#dark-mode-toggle[data-theme="dark"]) .tag-cloud .tag-cloud-item {
  color: #D4A04A;
  background: rgba(212, 160, 74, 0.09);
  border: 1px solid rgba(212, 160, 74, 0.25);
}

:root:has(#dark-mode-toggle[data-theme="dark"]) .tags a:hover,
:root:has(#dark-mode-toggle[data-theme="dark"]) .tags a:focus,
:root:has(#dark-mode-toggle[data-theme="dark"]) a.tag:hover,
:root:has(#dark-mode-toggle[data-theme="dark"]) a.tag:focus,
:root:has(#dark-mode-toggle[data-theme="dark"]) a.tag-small:hover,
:root:has(#dark-mode-toggle[data-theme="dark"]) a.tag-small:focus,
:root:has(#dark-mode-toggle[data-theme="dark"]) .tag-cloud .tag:hover,
:root:has(#dark-mode-toggle[data-theme="dark"]) .tag-cloud .tag:focus,
:root:has(#dark-mode-toggle[data-theme="dark"]) .tag-cloud .tag-cloud-item:hover,
:root:has(#dark-mode-toggle[data-theme="dark"]) .tag-cloud .tag-cloud-item:focus {
  color: #D4A04A;
  background: rgba(212, 160, 74, 0.18);
}
.tag-count {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ---- Archive ---- */
.archive-year h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 2rem 0 0.75rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}
.archive-entry {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.3rem 0;
  flex-wrap: wrap;
}
.archive-entry time {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 4rem;
  font-variant-numeric: tabular-nums;
}
.archive-entry a {
  color: var(--text);
  text-decoration: none;
}
.archive-entry a:hover { color: var(--accent); }
.tags-inline { margin-left: auto; }
.back-link {
  margin-top: 2rem;
  font-size: 0.9rem;
}
.back-link a {
  color: var(--accent);
  text-decoration: none;
}

/* ---- Search ---- */
.search-page {
  min-height: 50vh;
}
/* Pagefind UI overrides */
.pagefind-ui .pagefind-ui__search-input {
  font-family: var(--font-body) !important;
  font-size: 1rem !important;
  border-radius: 4px !important;
}

/* ---- Subscribe ---- */
.subscribe-box {
  margin-top: 1rem;
}
.subscribe-label {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
}

/* ---- Footer ---- */
.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}
.footer-content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1.5rem;
}
.footer-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 1.5rem;
  display: flex;
  gap: 1rem;
}
.footer-meta a {
  color: var(--text-muted);
  text-decoration: none;
}
.footer-meta a:hover { color: var(--accent); }

/* ---- Comments ---- */
.comments {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.comments h2 {
  font-size: 1.2rem;
  margin-bottom: 1rem;
}

/* ---- Post title wrapping fix ---- */
/* The Archie theme injects "# " via h1::before as an inline pseudo-element
   that sits OUTSIDE the <a> link. When a title wraps, line 2 starts at the
   h1's left edge (under "#"), not under the start of the link text — and the
   link's red border-bottom doesn't extend under "# ", leaving an orphan.
   Fix: pull ::before out of flow (position:absolute) into a left-padding slot.
   Every line of the title now indents by 2ch (= "# " width in Roboto Mono),
   the link underline is consistent across all lines, and wrapped titles look
   intentional rather than broken. */
.post-header h1,
.list-item h1.title {
  position: relative;
  padding-inline-start: 2ch;   /* reserve space for "# " on every line */
  line-height: 1.45;           /* was 1.2 — gives wrapped lines room to breathe */
}
.post-header h1::before,
.list-item h1.title::before {
  position: absolute;
  inset-inline-start: 0;      /* pin "# " to the left edge of the padding slot */
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
  body { font-size: 1rem; }
  main { padding: 1.5rem 1rem 3rem; }
  .archive-entry { gap: 0.5rem; }

  /* Mobile header: stack title and nav vertically, centred.
     The nav row uses position:relative so the toggle can be placed
     absolutely at the right edge — this removes it from flex flow,
     leaving the .nav-links group free to centre without offset. */
  header {
    flex-direction: column;
    align-items: center;
  }
  header nav {
    width: 100%;          /* full content-column width so centering is true */
    position: relative;   /* positioning context for the absolute toggle */
    justify-content: center;
    gap: 0;
    align-items: center;  /* override desktop flex-end for centred mobile row */
  }
  header nav .nav-links {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.6rem;
  }
  .nav-toggle {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
  }
}

/* ── Images and figures ─────────────────────────────────────── */

/* Make all content images responsive and centered */
article img {
  display: block;
  max-width: 100%;
  height: auto;
  margin-left: auto;
  margin-right: auto;
}

/* Cap portrait/tall images so they don't dominate the page */
article img {
  max-height: 70vh;
  width: auto;
  max-width: 100%;
}

/* Figure wrapper — match body text width */
article figure {
  margin: 1.5em 0;
  padding: 0;
  max-width: 100%;
}

/* Caption styling */
article figcaption {
  font-family: 'Public Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.8em;
  font-style: italic;
  color: #888;
  margin-top: 0.5em;
  line-height: 1.4;
}

:root:has(#dark-mode-toggle[data-theme="dark"]) article figcaption {
  color: #8A8578;
}
