/* ==========================================================================
   Blog experience layer — interactive article layout + enhanced index.
   Progressive enhancement: everything degrades to readable single-column
   without JS. Uses the site design tokens from /styles.css.
   ========================================================================== */

:root { --blog-nav-offset: 104px; }

/* Offset anchored jumps for the fixed nav (html already has smooth scroll). */
html { scroll-padding-top: var(--blog-nav-offset); }

/* The site sets `body{overflow-x:hidden}`, which makes <body> a scroll
   container and breaks position:sticky. On article pages (class added by
   blog.js) switch to overflow-x:clip: same horizontal-overflow protection,
   but no scroll container, so the sticky TOC pins correctly. Falls back to
   the inherited `hidden` (non-sticky, still readable) where clip is unsupported. */
body.has-sticky-toc { overflow-x: clip; }

/* --------------------------------------------------------------------------
   Reading progress bar (article pages)
   -------------------------------------------------------------------------- */
.blog-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  z-index: 1100; transition: width .1s linear; will-change: width;
}

/* --------------------------------------------------------------------------
   Two-column article layout (built by blog.js)
   -------------------------------------------------------------------------- */
.blog-layout { position: relative; }
.blog-article { max-width: 760px; }

/* Section anchors clear the fixed nav + sticky mobile TOC. */
.blog-article h2[id], .blog-article h3[id] { scroll-margin-top: var(--blog-nav-offset); }

/* Heading anchor link (appears on hover, desktop) */
.blog-anchor {
  opacity: 0; margin-left: .4em; color: var(--primary); text-decoration: none;
  font-weight: 600; transition: opacity .15s; font-size: .8em;
}
.blog-article h2:hover .blog-anchor, .blog-article h3:hover .blog-anchor { opacity: .7; }
.blog-anchor:hover { opacity: 1 !important; }

/* --------------------------------------------------------------------------
   Interactive outline (TOC)
   -------------------------------------------------------------------------- */
.blog-toc-card {
  background: var(--white); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px 18px 14px;
}
.blog-toc-title {
  font-family: var(--font-heading); font-size: .78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--primary);
  margin: 0 0 10px; display: flex; align-items: center; gap: 7px;
}
.blog-toc-title svg { width: 15px; height: 15px; fill: var(--primary); }
.blog-toc nav ol, .blog-toc-panel nav ol { list-style: none; margin: 0; padding: 0; }
.blog-toc nav li, .blog-toc-panel nav li { margin: 0; list-style: none; }
.blog-toc nav a, .blog-toc-panel nav a {
  display: block; padding: 8px 10px; border-left: 2px solid transparent;
  color: var(--text-medium); text-decoration: none; font-size: .86rem;
  line-height: 1.4; border-radius: 0 6px 6px 0; transition: color .15s, background .15s, border-color .15s;
}
.blog-toc nav a:hover, .blog-toc-panel nav a:hover { color: var(--primary); background: var(--bg-sage); }
.blog-toc nav a.lvl-3, .blog-toc-panel nav a.lvl-3 { padding-left: 22px; font-size: .82rem; }
.blog-toc nav a.is-active, .blog-toc-panel nav a.is-active {
  color: var(--primary); font-weight: 600;
  border-left-color: var(--primary); background: var(--bg-sage);
}
.blog-toc-progress {
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border);
  font-size: .76rem; color: var(--text-light); display: flex; justify-content: space-between;
}

/* Desktop / large tablet: sticky right sidebar */
@media (min-width: 1024px) {
  .blog-layout {
    display: grid; grid-template-columns: minmax(0, 760px) 270px;
    gap: 48px; justify-content: center; align-items: start;
  }
  .blog-toc-wrap { position: sticky; top: var(--blog-nav-offset); align-self: start; }
  .blog-toc { max-height: calc(100vh - var(--blog-nav-offset) - 32px); overflow-y: auto; }
  .blog-toc-mobile { display: none; }
}

/* Mobile / small tablet: collapsible "On this page" panel */
@media (max-width: 1023px) {
  .blog-toc-wrap { display: none; }
  .blog-toc-mobile {
    position: sticky; top: var(--blog-nav-offset); z-index: 40; margin: 0 0 22px;
    background: var(--white); border: 1px solid var(--border); border-radius: 12px;
    box-shadow: 0 6px 18px rgba(0,0,0,.05); overflow: hidden;
  }
  .blog-toc-toggle {
    width: 100%; display: flex; align-items: center; justify-content: space-between;
    gap: 10px; background: none; border: 0; cursor: pointer; padding: 14px 16px;
    font-family: var(--font-heading); font-weight: 700; font-size: .9rem;
    color: var(--text-dark); min-height: var(--tap-target); text-align: left;
  }
  .blog-toc-toggle .chev { transition: transform .2s; flex: none; width: 18px; height: 18px; fill: var(--primary); }
  .blog-toc-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
  .blog-toc-panel { display: none; padding: 0 10px 10px; max-height: 50vh; overflow-y: auto; }
  .blog-toc-mobile.open .blog-toc-panel { display: block; }
  .blog-toc-mobile .blog-toc-progress { padding: 10px; margin: 0; }
}

/* --------------------------------------------------------------------------
   Key-takeaways / suggested reading modules (article pages)
   -------------------------------------------------------------------------- */
.blog-related {
  margin-top: 40px; padding-top: 8px;
}
.blog-related h2 {
  font-family: var(--font-heading); font-size: 1.3rem; color: var(--text-dark);
  margin: 0 0 4px;
}
.blog-related .br-sub { color: var(--text-light); font-size: .9rem; margin: 0 0 18px; }
.blog-related-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 620px) { .blog-related-grid { grid-template-columns: 1fr 1fr; } }
.br-card {
  display: flex; flex-direction: column; gap: 6px; background: var(--white);
  border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px;
  text-decoration: none; transition: transform .18s, box-shadow .18s, border-color .18s;
}
.br-card:hover { transform: translateY(-3px); box-shadow: 0 12px 28px rgba(0,0,0,.07); border-color: var(--primary-light); }
.br-tag { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--primary); }
.br-title { font-family: var(--font-heading); font-size: 1rem; color: var(--text-dark); margin: 0; line-height: 1.35; }
.br-desc { font-size: .85rem; color: var(--text-medium); margin: 0; line-height: 1.55; }
.br-more { margin-top: auto; font-size: .82rem; font-weight: 600; color: var(--primary); padding-top: 4px; }

/* --------------------------------------------------------------------------
   Back-to-top button (desktop)
   -------------------------------------------------------------------------- */
.blog-top {
  position: fixed; right: 24px; bottom: 28px; z-index: 60;
  width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--white); color: var(--primary); cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,.12); display: none; align-items: center; justify-content: center;
  opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s, background .2s;
}
.blog-top svg { width: 20px; height: 20px; fill: currentColor; }
.blog-top.show { display: flex; opacity: 1; transform: translateY(0); }
.blog-top:hover { background: var(--bg-sage); }
@media (max-width: 767px) { .blog-top { display: none !important; } }

/* ==========================================================================
   Enhanced blog index
   ========================================================================== */
.blog-index-intro { max-width: 640px; margin: 0 auto 8px; text-align: center; color: var(--text-medium); font-size: 1rem; line-height: 1.7; }

.blog-controls {
  display: flex; flex-direction: column; gap: 14px; max-width: 1080px;
  margin: 26px auto 30px; padding: 0 4px;
}
.blog-search {
  position: relative; display: flex; align-items: center;
}
.blog-search svg { position: absolute; left: 14px; width: 18px; height: 18px; fill: var(--text-light); pointer-events: none; }
.blog-search input {
  width: 100%; padding: 13px 16px 13px 42px; border: 1px solid var(--border); border-radius: 12px;
  font-family: var(--font-body); font-size: .95rem; color: var(--text-dark); background: var(--white);
  min-height: var(--tap-target); box-sizing: border-box;
}
.blog-search input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.blog-filters { display: flex; flex-wrap: wrap; gap: 9px; }
.blog-chip {
  border: 1px solid var(--border); background: var(--white); color: var(--text-medium);
  border-radius: 999px; padding: 9px 16px; font-size: .84rem; font-weight: 600;
  cursor: pointer; min-height: 40px; transition: background .15s, color .15s, border-color .15s;
}
.blog-chip:hover { border-color: var(--primary); color: var(--primary); }
.blog-chip[aria-pressed="true"] { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Card grid (overrides the inline grid in index markup) */
.blog-grid-v2 { display: grid; grid-template-columns: 1fr; gap: 20px; max-width: 1080px; margin: 0 auto; }
@media (min-width: 640px) { .blog-grid-v2 { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1024px) { .blog-grid-v2 { grid-template-columns: repeat(3, 1fr); } }

.post-card {
  display: flex; flex-direction: column; background: var(--white);
  border: 1px solid var(--border); border-radius: 16px; padding: 24px; gap: 10px;
  text-decoration: none; transition: transform .2s, box-shadow .2s, border-color .2s;
}
.post-card:hover { transform: translateY(-4px); box-shadow: 0 16px 34px rgba(0,0,0,.08); border-color: var(--primary-light); }
.post-card.is-hidden { display: none; }
.post-card-tagrow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.post-card-tag { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--primary); }
.post-card-badge { font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: #fff; background: var(--accent); border-radius: 999px; padding: 3px 9px; }
.post-card-title { font-family: var(--font-heading); font-size: 1.16rem; color: var(--text-dark); margin: 0; line-height: 1.32; }
.post-card:hover .post-card-title { color: var(--primary); }
.post-card-excerpt { font-size: .9rem; color: var(--text-medium); margin: 0; line-height: 1.6; }
.post-card-meta { margin-top: auto; padding-top: 8px; display: flex; align-items: center; gap: 10px; font-size: .78rem; color: var(--text-light); }
.post-card-meta .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--text-light); }
.post-card-more { font-weight: 700; color: var(--primary); font-size: .82rem; }

/* Featured card spans full width on wider screens */
@media (min-width: 640px) {
  .post-card.featured { grid-column: 1 / -1; flex-direction: row; align-items: center; gap: 28px; padding: 30px 34px; background: var(--bg-sage); }
  .post-card.featured .pc-body { flex: 1; display: flex; flex-direction: column; gap: 10px; }
  .post-card.featured .post-card-title { font-size: 1.5rem; }
  .post-card.featured .post-card-excerpt { font-size: .98rem; }
  .post-card.featured .pc-aside { flex: none; width: 150px; text-align: center; }
}
.post-card.featured .pc-aside { display: none; }
@media (min-width: 640px) { .post-card.featured .pc-aside { display: block; } }
.pc-aside-icon { width: 84px; height: 84px; margin: 0 auto 8px; border-radius: 20px; background: var(--white); display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 22px rgba(0,0,0,.06); }
.pc-aside-icon svg { width: 44px; height: 44px; fill: var(--primary); }

.blog-empty { display: none; text-align: center; color: var(--text-light); padding: 40px 0; font-size: .95rem; }
.blog-empty.show { display: block; }

/* --------------------------------------------------------------------------
   Motion & no-JS safety
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .blog-progress, .br-card, .post-card, .blog-top { transition: none; }
}
/* If JS is disabled, hide progressive-only chrome */
.no-js .blog-progress, .no-js .blog-top, .no-js .blog-toc-mobile { display: none; }
