/* Public blog styles — built on the same design tokens as the main Astro
   site (site.css, a direct copy of src/styles/global.css) so typography,
   color, spacing, and dark/light theming stay visually consistent without
   touching the Astro codebase. */
@import url("site.css");

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans, system-ui, sans-serif);
}

.container { max-width: 1120px; margin: 0 auto; padding: 0 var(--space-5, 20px); }

/* --- Header (simplified nav, same brand mark + tokens as the main site) --- */
.header {
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 72px; gap: 10px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--color-text); font-weight: 700; flex-shrink: 0; }
.brand-mark { width: 36px; height: 36px; border-radius: 50%; background: var(--color-primary); color: #111; display: grid; place-items: center; font-weight: 800; flex-shrink: 0; }
.nav { display: flex; align-items: center; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav-link { padding: 8px 14px; border-radius: var(--radius-full); color: var(--color-text-muted); text-decoration: none; font-size: var(--fs-sm); font-weight: 500; white-space: nowrap; flex-shrink: 0; }
.nav-link:hover, .nav-link.is-active { color: var(--color-text); background: var(--color-surface); }
.header-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
@media (max-width: 640px) {
  .nav { display: none; }
}
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: var(--radius-full); border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text-muted); cursor: pointer; }
.icon-btn svg { width: 18px; height: 18px; }

/* --- Footer --- */
.footer { border-top: 1px solid var(--color-border); margin-top: var(--space-8, 64px); padding: var(--space-7, 48px) 0; }
.footer-links { display: flex; flex-wrap: wrap; gap: 16px; font-size: var(--fs-sm); }
.footer-links a { color: var(--color-text-muted); text-decoration: none; }
.footer-links a:hover { color: var(--color-text); }
.footer-bottom { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--color-border); font-size: var(--fs-sm); color: var(--color-text-subtle); }

/* --- Blog listing --- */
.blog-hero {
  padding: var(--space-9, 72px) 0 var(--space-7, 48px);
  text-align: center;
  background: var(--gradient-mesh);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-6, 40px);
}
.blog-hero h1 { font-size: clamp(2.2rem, 5vw, 3.2rem); margin: 0 0 14px; letter-spacing: -0.02em; }
.blog-hero p { color: var(--color-text-muted); max-width: 620px; margin: 0 auto; font-size: 1.05rem; }

/* --- Category / blog-index hero header --- */
/* Blog hero — deliberately reuses the Homepage Hero's own decorative
   language (grid drift, mesh, blobs, floating shapes, glass, gradient text,
   eyebrow/btn utilities from site.css) so the blog immediately reads as the
   same site, not a different template. Only the shapes/blobs are redeclared
   here (they live in Hero.astro's component-scoped <style>, unreachable from
   a plain PHP page) — everything else is shared, zero duplicate tokens. */
.blog-category-hero {
  position: relative;
  overflow: hidden;
  padding: var(--space-8, 64px) 0 var(--space-8, 56px);
  text-align: center;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-6, 40px);
}
.hero-grid {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: var(--grid-size, 48px) var(--grid-size, 48px);
  mask-image: radial-gradient(ellipse 80% 70% at 50% 0%, #000 40%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 80% 70% at 50% 0%, #000 40%, transparent 100%);
  animation: blogGridDrift 40s linear infinite;
}
@keyframes blogGridDrift {
  from { background-position: 0 0; }
  to { background-position: var(--grid-size, 48px) var(--grid-size, 48px); }
}
.hero-mesh { position: absolute; inset: 0; z-index: 0; background: var(--gradient-mesh); }

.hero-blob { position: absolute; border-radius: 50%; filter: blur(70px); z-index: 0; opacity: 0.55; animation: blogDrift 18s ease-in-out infinite; }
.hero-blob-1 { width: 400px; height: 400px; top: -130px; right: -80px; background: radial-gradient(circle, rgba(var(--secondary-rgb), 0.38), transparent 70%); }
.hero-blob-2 { width: 320px; height: 320px; bottom: -110px; left: -70px; background: radial-gradient(circle, rgba(var(--primary-rgb), 0.32), transparent 70%); animation-delay: 3s; animation-direction: reverse; }
@keyframes blogDrift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-24px, 24px) scale(1.08); }
}

.hero-shape { position: absolute; z-index: 0; animation: blogFloatShape 9s ease-in-out infinite; opacity: 0.7; }
.hero-shape-1 { top: 16%; left: 8%; width: 26px; height: 26px; border-radius: 8px; background: var(--gradient-brand); box-shadow: var(--shadow-md); }
.hero-shape-2 { top: 66%; left: 46%; width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--color-secondary); animation-delay: 1.5s; }
.hero-shape-3 { top: 28%; right: 40%; width: 0; height: 0; border-left: 12px solid transparent; border-right: 12px solid transparent; border-bottom: 20px solid var(--color-accent); opacity: 0.5; animation-delay: 2.5s; }
@keyframes blogFloatShape {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-16px) rotate(12deg); }
}
@media (prefers-reduced-motion: reduce) {
  .hero-grid, .hero-blob, .hero-shape { animation: none; }
}
@media (max-width: 640px) {
  .hero-blob-1, .hero-blob-2, .hero-shape-1, .hero-shape-2, .hero-shape-3 { display: none; } /* keep small screens clean/lightweight */
}

.blog-hero-inner { position: relative; z-index: 1; }
.blog-category-hero .breadcrumb { justify-content: center; margin-bottom: var(--space-4, 20px); }
.blog-category-hero h1 { font-size: clamp(2.2rem, 5vw, 3.2rem); margin: 0 0 14px; letter-spacing: -0.02em; }
.blog-hero-subtitle { color: var(--color-text-muted); max-width: 620px; margin: 0 auto; font-size: 1.05rem; line-height: var(--lh-snug, 1.5); }

.blog-hero-stats { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-3, 14px); margin: var(--space-6, 32px) 0 var(--space-5, 24px); }
.blog-stat { padding: var(--space-3, 14px) var(--space-5, 22px); border-radius: var(--radius-lg); text-align: center; min-width: 140px; }
.blog-stat strong { display: block; font-size: var(--fs-2xl, 1.6rem); font-weight: 800; color: var(--color-text); line-height: 1.1; }
.blog-stat span { font-size: var(--fs-xs, 0.75rem); color: var(--color-text-subtle); text-transform: uppercase; letter-spacing: 0.04em; }
.blog-hero-cta svg { width: 16px; height: 16px; }
.blog-search { max-width: 420px; margin: var(--space-5, 24px) auto 0; display: flex; gap: 8px; }
.blog-search input { flex: 1; padding: 10px 16px; border-radius: var(--radius-full); border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text); font-family: inherit; font-size: var(--fs-sm); }
.blog-search input:focus { outline: none; border-color: var(--color-primary); box-shadow: var(--focus-ring); }
.blog-search .btn { border-radius: var(--radius-full); }

/* --- Featured (latest) article --- */
.blog-featured {
  display: grid;
  grid-template-columns: 1fr;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl, 20px);
  overflow: hidden;
  background: var(--color-surface);
  text-decoration: none;
  color: inherit;
  margin: var(--space-2, 8px) 0 var(--space-7, 48px);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}
.blog-featured:hover { border-color: var(--color-primary); box-shadow: var(--shadow-glow-hover, var(--shadow-md)); transform: translateY(-2px); }
@media (min-width: 760px) {
  .blog-featured { grid-template-columns: 1.1fr 1fr; }
}
.blog-featured-thumb { aspect-ratio: 16/9; background: var(--color-surface-2); overflow: hidden; }
@media (min-width: 760px) { .blog-featured-thumb { aspect-ratio: auto; height: 100%; } }
.blog-featured-thumb img { width: 100%; height: 100%; object-fit: cover; }
.blog-featured-body { padding: var(--space-6, 28px); display: flex; flex-direction: column; gap: 10px; justify-content: center; }
.blog-featured-badge { margin-bottom: 2px; align-self: flex-start; }
.blog-featured-body h2 { font-size: clamp(1.3rem, 2.5vw, 1.7rem); margin: 0; line-height: 1.3; letter-spacing: -0.01em; }
.blog-featured-body p { color: var(--color-text-muted); margin: 0; font-size: var(--fs-base, 0.95rem); }

.blog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 24px; padding: var(--space-6, 40px) 0; }
.blog-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--color-surface);
  text-decoration: none;
  color: inherit;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.blog-card:hover { transform: translateY(-4px); border-color: var(--color-primary); box-shadow: var(--shadow-glow, var(--shadow-md)); }
.blog-card-thumb { position: relative; aspect-ratio: 16/9; background: var(--color-surface-2); overflow: hidden; }
.blog-card-thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.4s ease; }
.blog-card:hover .blog-card-thumb img { transform: scale(1.05); }
.blog-card img:not(.blog-card-thumb img) { width: 100%; aspect-ratio: 16/9; object-fit: cover; background: var(--color-surface-2); } /* legacy cards without the thumb wrapper */
.blog-card-cat-thumb {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(18, 18, 18, 0.72);
  backdrop-filter: blur(4px);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  color: #fff;
}
.blog-card-body { padding: 20px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.blog-card-cat { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--color-primary-text, var(--color-primary)); }
.blog-card-title { font-size: 1.08rem; font-weight: 700; margin: 0; line-height: 1.35; letter-spacing: -0.005em; }
.blog-card-excerpt { font-size: var(--fs-sm); color: var(--color-text-muted); flex: 1; line-height: 1.5; }
.blog-card-meta { font-size: 0.75rem; color: var(--color-text-subtle); display: flex; gap: 10px; padding-top: 6px; margin-top: 4px; border-top: 1px solid var(--color-border); }

.pagination { display: flex; justify-content: center; gap: 8px; padding: 20px 0 60px; }
.pagination a, .pagination span { padding: 8px 14px; border-radius: var(--radius-md); border: 1px solid var(--color-border); text-decoration: none; color: var(--color-text); font-size: var(--fs-sm); }
.pagination .is-active { background: var(--color-primary); color: #111; border-color: var(--color-primary); }

/* --- Breadcrumbs --- */
.breadcrumb { padding: 12px 0; font-size: var(--fs-sm); color: var(--color-text-subtle); display: flex; align-items: center; flex-wrap: wrap; }
.breadcrumb a { color: var(--color-text-subtle); text-decoration: none; }
.breadcrumb a:hover { color: var(--color-text); }
.breadcrumb .sep { margin: 0 6px; }
.breadcrumb [aria-current="page"] { color: var(--color-text); font-weight: 500; }

/* --- Single article --- */
.article-shell { display: grid; grid-template-columns: 1fr 260px; gap: 48px; padding: 20px 0 70px; align-items: start; }
@media (max-width: 900px) { .article-shell { grid-template-columns: 1fr; } }

.article-header { margin-bottom: 28px; }
.article-header h1 { font-size: clamp(1.8rem, 4vw, 2.5rem); margin: 0 0 14px; line-height: 1.2; }
.article-meta { display: flex; flex-wrap: wrap; gap: 14px; color: var(--color-text-subtle); font-size: var(--fs-sm); }
.article-featured-image { width: 100%; border-radius: var(--radius-lg); margin: 20px 0; aspect-ratio: 16/9; object-fit: cover; }

.article-body { font-size: 1.05rem; line-height: 1.75; }
.article-body h2 { font-size: 1.5rem; margin: 2.2em 0 .6em; scroll-margin-top: 90px; }
.article-body h3 { font-size: 1.2rem; margin: 1.8em 0 .5em; scroll-margin-top: 90px; }
.article-body h4 { font-size: 1.05rem; margin: 1.5em 0 .4em; scroll-margin-top: 90px; }
.article-body p { margin: 0 0 1.1em; color: var(--color-text); }
.article-body a { color: var(--color-primary-text, var(--color-primary)); text-decoration: underline; text-underline-offset: 2px; }
.article-body ul.blog-list, .article-body ol.blog-list { margin: 0 0 1.1em; padding-left: 1.4em; }
.article-body li { margin-bottom: .4em; }

.article-body::after { content: ''; display: block; clear: both; } /* contain floated (left/right) figures */
.blog-figure { margin: 1.6em 0; }
.blog-figure img { width: 100%; border-radius: var(--radius-lg); box-shadow: var(--shadow-md); }
.blog-figure figcaption { text-align: center; font-size: 0.85rem; color: var(--color-text-subtle); margin-top: 10px; }

/* Alignment + width (set from the editor's image toolbar). Default is full width. */
.blog-figure--center { margin-left: auto; margin-right: auto; }
.blog-figure--left { float: left; margin: 0.4em 1.4em 1em 0; }
.blog-figure--right { float: right; margin: 0.4em 0 1em 1.4em; }
.blog-figure--left, .blog-figure--right { max-width: 50%; }
@media (max-width: 640px) {
  /* On narrow screens floats look cramped — stack everything full width. */
  .blog-figure--left, .blog-figure--right { float: none; max-width: 100%; margin: 1.6em 0; width: 100% !important; }
}

.blog-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin: 1.6em 0; }
.blog-gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-md); }

.blog-embed { position: relative; aspect-ratio: 16/9; margin: 1.6em 0; border-radius: var(--radius-lg); overflow: hidden; }
.blog-embed iframe { width: 100%; height: 100%; border: 0; }

.blog-table-wrap { overflow-x: auto; margin: 1.6em 0; }
.blog-table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.blog-table th, .blog-table td { border: 1px solid var(--color-border); padding: 10px 12px; text-align: left; }
.blog-table th { background: var(--color-surface); font-weight: 600; }

.blog-code { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 16px; overflow-x: auto; margin: 1.6em 0; font-size: 0.9rem; }
.blog-code code { font-family: ui-monospace, SFMono-Regular, monospace; }

.blog-quote { border-left: 4px solid var(--color-primary); margin: 1.6em 0; padding: 4px 0 4px 20px; font-style: italic; color: var(--color-text-muted); }
.blog-quote cite { display: block; margin-top: 8px; font-size: 0.85rem; font-style: normal; color: var(--color-text-subtle); }

.blog-callout { border-radius: var(--radius-lg); padding: 16px 18px; margin: 1.6em 0; border: 1px solid; }
.blog-callout-info { background: color-mix(in srgb, #3b82f6 10%, transparent); border-color: #3b82f6; }
.blog-callout-tip { background: color-mix(in srgb, #22c55e 10%, transparent); border-color: #22c55e; }
.blog-callout-warning { background: color-mix(in srgb, #f59e0b 10%, transparent); border-color: #f59e0b; }

.blog-btn { display: inline-block; margin: 1em 0; text-decoration: none; }

/* --- Sidebar (TOC) --- */
.toc-box { position: sticky; top: 90px; border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 18px; background: var(--color-surface); }
.toc-box h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: .04em; margin: 0 0 10px; color: var(--color-text-subtle); }
.toc-box ul { list-style: none; margin: 0; padding: 0; font-size: 0.85rem; }
.toc-box li { margin-bottom: 6px; }
.toc-box li.level-3 { padding-left: 14px; }
.toc-box li.level-4 { padding-left: 28px; }
.toc-box a { color: var(--color-text-muted); text-decoration: none; }
.toc-box a:hover { color: var(--color-primary-text, var(--color-primary)); }

/* --- FAQ --- */
.blog-faq { margin: 40px 0; }
.blog-faq h2 { font-size: 1.4rem; margin-bottom: 16px; }
.blog-faq details { border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 14px 16px; margin-bottom: 10px; background: var(--color-surface); }
.blog-faq summary { cursor: pointer; font-weight: 600; }
.blog-faq p { margin: 10px 0 0; color: var(--color-text-muted); }

/* --- Related articles --- */
.related-articles { margin: 50px 0; }
.related-articles h2 { font-size: 1.4rem; margin-bottom: 16px; }

/* --- Category/tag pills --- */
.pill-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.pill { display: inline-block; padding: 5px 12px; border-radius: var(--radius-full); background: var(--color-surface); border: 1px solid var(--color-border); font-size: 0.8rem; color: var(--color-text-muted); text-decoration: none; }

/* --- Reading progress bar --- */
.reading-progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 100; background: transparent; }
.reading-progress-bar { height: 100%; width: 0%; background: var(--gradient-brand); transition: width 80ms linear; }

/* --- Share buttons --- */
.share-row { display: flex; gap: 8px; margin: 16px 0; }
.share-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: var(--radius-full);
  border: 1px solid var(--color-border); background: var(--color-surface);
  color: var(--color-text-muted); text-decoration: none; font-size: 0.85rem; font-weight: 700;
  cursor: pointer; transition: all var(--duration-fast) var(--ease-out);
}
.share-btn:hover { border-color: var(--color-primary); color: var(--color-primary-text, var(--color-primary)); transform: translateY(-1px); }

/* --- CTA block --- */
.cta-block {
  margin: 2.4em 0; padding: 32px; border-radius: var(--radius-xl); text-align: center;
  background: var(--gradient-brand-soft); border: 1px solid var(--color-border);
}
.cta-block h2 { margin: 0 0 8px; font-size: 1.3rem; }
.cta-block p { color: var(--color-text-muted); margin: 0 0 18px; }

/* --- Author box --- */
.author-box {
  display: flex; gap: 16px; align-items: flex-start; margin: 2.4em 0; padding: 20px;
  border: 1px solid var(--color-border); border-radius: var(--radius-lg); background: var(--color-surface);
}
.author-avatar { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.author-avatar-fallback {
  display: grid; place-items: center; background: var(--gradient-brand); color: var(--color-on-primary);
  font-weight: 800; font-size: 1.3rem;
}
.author-box h3 { margin: 0 0 6px; font-size: 1rem; }
.author-box p { margin: 0 0 8px; color: var(--color-text-muted); font-size: 0.9rem; }
.author-social { display: flex; gap: 12px; }
.author-social a { font-size: 0.8rem; color: var(--color-primary-text, var(--color-primary)); text-decoration: none; font-weight: 600; }

/* --- Prev/next navigation --- */
.prev-next-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 2.4em 0; }
.prev-next-link {
  display: flex; flex-direction: column; gap: 6px; padding: 16px; border-radius: var(--radius-lg);
  border: 1px solid var(--color-border); text-decoration: none; color: inherit; transition: border-color var(--duration-fast) var(--ease-out);
}
.prev-next-link:hover { border-color: var(--color-primary); }
.prev-next-link span { font-size: 0.75rem; color: var(--color-text-subtle); text-transform: uppercase; letter-spacing: 0.04em; }
.prev-next-link strong { font-size: 0.9rem; line-height: 1.3; }
.prev-next-link.next { text-align: right; align-items: flex-end; }
@media (max-width: 640px) { .prev-next-nav { grid-template-columns: 1fr; } }

/* --- Newsletter block --- */
.newsletter-block {
  margin: 3em 0 1em; padding: 32px; border-radius: var(--radius-xl); text-align: center;
  background: var(--color-surface); border: 1px solid var(--color-border);
}
.newsletter-block h2 { margin: 0 0 8px; font-size: 1.2rem; }
.newsletter-block p { color: var(--color-text-muted); margin: 0 0 18px; font-size: 0.9rem; }
.newsletter-form { display: flex; gap: 8px; max-width: 420px; margin: 0 auto; flex-wrap: wrap; }
.newsletter-form input { flex: 1; min-width: 200px; padding: 11px 14px; border-radius: var(--radius-md); border: 1px solid var(--color-border); background: var(--color-bg); color: var(--color-text); font-size: 0.9rem; }
.newsletter-form input:focus { outline: none; border-color: var(--color-primary); }
.newsletter-status { font-size: 0.85rem; color: var(--color-text-subtle); margin: 10px 0 0; }
.pill:hover { border-color: var(--color-primary); color: var(--color-text); }
