/* =========================================
   01) DESIGN TOKENS (Variables & Theming)
   ========================================= */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Default = Light mode */
:root {
  /* Colors */
  --bg: #fdfcf7;
  --bg-soft: #faf8f1;
  --text: #171717;
  --text-soft: #2b2b2b;
  --muted: #6b6b6b;
  --rule: rgba(0, 0, 0, 0.08);

  /* Links */
  --link: #1f3a8a;
  --link-hover: #122a68;

  /* Typography */
  --font-serif: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", "URW Palladio L", P052, serif;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;

  /* Layout */
  --sidebar-width: 190px;
  --layout-max: 1200px;
  --content-max: 72ch;
  --layout-gap: 4.5rem;
  --ui-radius: 12px;

  /* Spacing */
  --page-pad-x: 2rem;
  --page-pad-top: 4.5rem;
  --page-pad-bottom: 3.5rem;

  /* Theme extras */
  --shadow-soft: rgba(0, 0, 0, 0.04);
  --selection-bg: rgba(31, 58, 138, 0.14);
  --selection-text: var(--text);
}

/* Let the browser know both themes are supported */
html {
  color-scheme: light dark;
}

/* Auto dark mode (uses OS setting) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --bg-soft: #151821;
    --text: #eceff4;
    --text-soft: #cfd5df;
    --muted: #9aa3b2;
    --rule: rgba(255, 255, 255, 0.10);

    --link: #9db8ff;
    --link-hover: #c5d6ff;

    --shadow-soft: rgba(0, 0, 0, 0.35);
    --selection-bg: rgba(157, 184, 255, 0.22);
    --selection-text: #ffffff;
  }
}

/* Optional manual overrides (use later if you add a toggle) */
:root[data-theme="light"] {
  --bg: #fdfcf7;
  --bg-soft: #faf8f1;
  --text: #171717;
  --text-soft: #2b2b2b;
  --muted: #6b6b6b;
  --rule: rgba(0, 0, 0, 0.08);

  --link: #1f3a8a;
  --link-hover: #122a68;

  --shadow-soft: rgba(0, 0, 0, 0.04);
  --selection-bg: rgba(31, 58, 138, 0.14);
  --selection-text: #171717;
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --bg-soft: #151821;
  --text: #eceff4;
  --text-soft: #cfd5df;
  --muted: #9aa3b2;
  --rule: rgba(255, 255, 255, 0.10);

  --link: #9db8ff;
  --link-hover: #c5d6ff;

  --shadow-soft: rgba(0, 0, 0, 0.35);
  --selection-bg: rgba(157, 184, 255, 0.22);
  --selection-text: #ffffff;
}

/* Nice text selection in both modes */
::selection {
  background: var(--selection-bg);
  color: var(--selection-text);
}


/* =========================================
   02) BASE / DOCUMENT
   ========================================= */
html {
  font-size: 100%;
  position: relative;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  position: relative;
  isolation: isolate;
  overflow-x: clip;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 1.08rem;
  line-height: 1.68;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

img,
picture,
video,
svg {
  max-width: 100%;
  height: auto;
  display: block;
}

/* =========================================
   03) TYPOGRAPHY
   ========================================= */
h1,
h2,
h3,
h4 {
  margin-top: 0;
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.15;
  letter-spacing: -0.015em;
  overflow-wrap: break-word;
}

h1 {
  margin-bottom: 0.8rem;
  font-size: clamp(1.75rem, 4vw, 2.8rem);
}

h2 {
  margin-top: 2.2rem;
  margin-bottom: 0.55rem;
  font-size: clamp(1.35rem, 2vw, 1.7rem);
}

p,
li {
  color: var(--text-soft);
}

p {
  margin: 0 0 1.25rem;
}

a {
  color: var(--link);
  text-underline-offset: 0.12em;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, var(--link) 45%, transparent);
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

a:hover {
  color: var(--link-hover);
  text-decoration-color: currentColor;
}


/* =========================================
   04) SITE LAYOUT (Applied in base.njk)
   ========================================= */
.site-wrapper {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  gap: var(--layout-gap);
  max-width: var(--layout-max);
  margin: 0 auto;
  padding: var(--page-pad-top) var(--page-pad-x) var(--page-pad-bottom);
}

/* Vertical rule between sidebar and content */
.site-wrapper::before {
  content: "";
  position: absolute;
  top: 1.75rem;
  bottom: 1rem;
  left: calc(var(--sidebar-width) + 2.25rem);
  width: 1px;
  pointer-events: none;
  background: linear-gradient(to bottom, transparent, var(--rule), transparent);
}

main {
  position: relative;
  z-index: 1;
  max-width: 100%;
}

/* Common reading width */
main>* {
  max-width: 72ch;
  /* Optimal reading width */
}


/* =========================================
   05) HEADER & NAV (Applied in base.njk)
   ========================================= */
header {
  position: sticky;
  top: 1.5rem;
  height: fit-content;
  padding-right: 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.92rem;
}

.site-title {
  display: inline-block;
  color: var(--text);
  font-weight: 700;
  line-height: 1.5;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
}

nav ul {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.4rem 0;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.98rem;
}

nav a {
  display: inline-block;
  padding: 0.4rem 0;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.2s ease, transform 0.2s ease;
}

nav a:hover {
  color: var(--text);
  transform: translateX(1px);
}

nav a[aria-current="page"] {
  margin-left: -0.6rem;
  padding-left: 0.6rem;
  color: var(--text);
  font-weight: 600;
  border-left: 2px solid var(--link);
}


/* =========================================
   06) SHARED COMPONENTS (Tags & Meta)
   Used in both index.njk & post.njk
   ========================================= */
.entry-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem;
  letter-spacing: 0.05em;
  font-family: var(--font-mono);
  margin-bottom: 2.75rem;

}

.entry-date {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  /* letter-spacing: 0.06em; */
  text-transform: uppercase;
}

.entry-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.80rem;

}

.tag-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0;
  color: var(--link);
}

.tag-pill::before {
  content: "[";
  color: var(--muted);
  margin-right: 1px;
}

.tag-pill::after {
  content: "]";
  color: var(--muted);
  margin-left: 1px;
}


/* =========================================
   07) BLOG INDEX (Applied in index.njk)
   ========================================= */
.blog-title {
  position: relative;
  margin: 0 0 5rem 0;
  font-size: clamp(2rem, 3vw, 2.6rem);
  line-height: 1.05;
  letter-spacing: -0.025em;
  text-decoration: none;
}

.blog-title::after {
  content: "";
  display: block;
  width: 3.2rem;
  height: 2px;
  margin-top: 0.6rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--link) 72%, var(--text) 28%);
}

.blog-list {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.blog-item {
  padding: 0 0 1.35rem;
  border-bottom: 1px solid color-mix(in srgb, var(--text) 10%, transparent);
}

.blog-item:last-child {
  /* padding-bottom: 0; */
  border-bottom: none;
}

.blog-entry-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.45rem;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.blog-entry-sep {
  opacity: 0.5;
}

.blog-entry-title {
  margin: 0 0 0.45rem;
  font-size: clamp(1.25rem, 2vw, 1.55rem);
  line-height: 1.2;
}

.blog-entry-link {
  color: var(--text);
  text-decoration: none;
  transition: color 0.2s ease;
}

.blog-entry-link:hover .blog-entry-title a {
  color: var(--link);
}

.blog-entry-summary {
  max-width: 62ch;
  margin: 0;
  color: color-mix(in srgb, var(--text-soft) 92%, var(--text) 8%);
  font-size: 1.02rem;
  line-height: 1.62;
}


/* =========================================
   08) SINGLE POST (Applied in post.njk)
   ========================================= */

.post {
  padding-bottom: 2rem;
}

.post-title {
  font-size: clamp(2rem, 6vw, 2.5rem);
}

.post-meta-wrapper {
  margin-bottom: 2.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--rule);
}

.post-content {
  font-size: 1.05rem;
  line-height: 1.8;
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: break-word;
}

.post-content pre,
.post-content table {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* Smooth scrolling on iOS */
}


/* =========================================
   09) FOOTER (Applied in base.njk)
   ========================================= */
.footer-wrapper {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  gap: var(--layout-gap);
  max-width: var(--layout-max);
  margin: 0 auto;
  padding: 2.5rem var(--page-pad-x) 3rem;
  /* border-top: 1px solid var(--rule); */
  font-family: var(--font-sans);
  font-size: 0.88rem;
}

footer {
  grid-column: 2 / -1;
}

.footer-list {
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem;
  margin: 0 0 0.5rem 0;
  padding: 0;
  list-style: none;
}

.footer-list a {
  color: var(--muted);
  text-decoration: none;
}

.footer-list a:hover {
  color: var(--text);
}

footer small {
  color: var(--muted);
  line-height: 1.5;
}


/* =========================================
   10) MOTION & RESPONSIVE
   ========================================= */
@media (prefers-reduced-motion: reduce) {

  html::before,
  body::before {
    animation: none !important;
  }

  nav a {
    transition: none;
  }

  a {
    transition: none;
  }
}

@media (max-width: 850px) {

  /* 1. Tweak base typography so it fits comfortably on small screens */
  body {
    font-size: 1rem;
    line-height: 1.6;
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* old Edge/IE */
  }


  body::-webkit-scrollbar {
    display: none;
  }

  /* 2. Refine the wrapper padding for better edge framing */
  .site-wrapper,
  .footer-wrapper {
    /* CHANGE THIS LINE */
    grid-template-columns: minmax(0, 1fr);

    gap: 1.5rem;
    padding: 1.5rem .55rem 2.5rem .75rem;
  }

  footer {
    grid-column: 1 / -1;
  }

  .site-wrapper::before,
  .site-wrapper::after {
    display: none;
  }

  header {
    position: relative;
    top: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
    padding-bottom: 1.25rem;
    padding-right: 0;
    border-bottom: 1px solid var(--rule);
  }

  .site-title {
    margin-bottom: 0.5rem;
  }

  nav ul {
    flex-direction: row;
    gap: 1.25rem;
  }

  nav a[aria-current="page"] {
    margin-left: 0;
    padding-left: 0;
    border-left: none;
    border-bottom: 2px solid var(--link);
    padding-bottom: 0.2rem;
  }

  main>* {
    max-width: 100%;
  }

  .blog-title {
    margin-bottom: 3rem;
  }

  .blog-list {
    gap: 1.5rem;
  }

  /* 3. Scale down the post title and content text slightly */
  .post-title {
    font-size: clamp(1.6rem, 7vw, 2.1rem);
  }

  .post-content {
    font-size: 1rem;
    line-height: 1.65;
  }

  /* 4. Ensure nothing inside the post ever pushes the screen wider */
  .post-content>* {
    max-width: 100%;
  }
}