/* ── Blog rich blocks ────────────────────
   Chat, stats, diff, YouTube facade, hosted video, lightbox, reveal, charts, mermaid,
   task lists, footnotes, TOC refinements. Native to blog.css (dark glass cards,
   violet #8b5cf6 / cyan #67e8f9 accents). Loaded on every post page. */

/* ── Code: highlighted lines ─────────── */

/* The band reaches the pre's padding edges through box-shadows and a ::before stripe, which never add
   scrollable overflow (a wider box did: a stray horizontal scrollbar under highlighted lines). */
.blog-code-block .hl-line {
  --hl-pad: 1.25rem;
  --hl-bg: rgba(139, 92, 246, 0.18);
  display: inline-block;
  position: relative;
  min-width: 100%;
  background: var(--hl-bg);
  box-shadow: calc(-1 * var(--hl-pad)) 0 0 var(--hl-bg), var(--hl-pad) 0 0 var(--hl-bg);
}
/* highlight.js' theme makes code.hljs its own scroll box, which would clip the band; the pre scrolls instead. */
.blog-code-block code.hljs { overflow: visible; }
.blog-code-block .hl-line::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(-1 * var(--hl-pad));
  width: 3px;
  background: var(--primary-vivid, #8b5cf6);
}

/* ── Diff ────────────────────────────── */

.blog-diff pre { padding-left: 0; padding-right: 0; }

.blog-diff code.hljs { display: block; }

.blog-diff .diff-line {
  display: inline-block;
  width: 100%;
  padding: 0 1.25rem 0 1.5rem;
  position: relative;
  min-height: 1.6em;
}

.blog-diff .diff-line::before {
  position: absolute;
  left: 0.55rem;
  opacity: 0.8;
}

.blog-diff .diff-line.ins { background: rgba(16, 185, 129, 0.14); color: #a7f3d0; }
.blog-diff .diff-line.ins::before { content: '+'; color: var(--accent-green, #10b981); }
.blog-diff .diff-line.del { background: rgba(244, 63, 94, 0.14); color: #fecdd3; }
.blog-diff .diff-line.del::before { content: '\2212'; color: var(--accent-hot, #f43f5e); }
.blog-diff .diff-line.hunk { background: rgba(103, 232, 249, 0.08); color: #67e8f9; font-style: italic; }
.blog-diff .diff-line.ctx { color: #9ca3af; }

/* ── Math (display math written inline as $$..$$) ── */

.blog-math-display-inline { display: block; overflow-x: auto; text-align: center; padding: 0.5rem 0; }

/* ── Images: variants + lightbox hint ── */

.blog-figure img[data-lightbox] { cursor: zoom-in; }

.blog-figure.blog-img-wide { max-width: min(960px, 100vw - 2rem); margin-left: 50%; transform: translateX(-50%); width: max-content; }
.blog-figure.blog-img-wide img { max-width: 100%; }
.blog-figure.blog-img-small img { max-width: min(360px, 100%); }
.blog-figure.blog-img-left { float: left; margin: 0.25rem 1.5rem 1rem 0; max-width: 45%; }
.blog-figure.blog-img-right { float: right; margin: 0.25rem 0 1rem 1.5rem; max-width: 45%; }
.blog-figure.blog-img-bordered img { border: 1px solid var(--border, rgba(139, 92, 246, 0.2)); }
.blog-figure.blog-img-round img { border-radius: 50%; }
.blog-figure.blog-img-flat img { box-shadow: none; }

/* ── Hosted video ────────────────────── */

.blog-video-fig video {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md, 0.625rem);
  background: #0a0a0f;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* ── YouTube facade ──────────────────── */

.blog-yt-facade,
.blog-yt-player {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  padding: 0;
  border: 1px solid rgba(139, 92, 246, 0.22);
  border-radius: var(--radius-md, 0.625rem);
  overflow: hidden;
  background: #0a0a0f;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.blog-yt-facade { cursor: pointer; color: inherit; font: inherit; }

.blog-yt-facade img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0;
  box-shadow: none;
  transition: transform 0.5s ease, filter 0.3s ease;
}

.blog-yt-ph {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 25% 20%, rgba(139, 92, 246, 0.45), transparent 55%),
    radial-gradient(circle at 80% 85%, rgba(103, 232, 249, 0.3), transparent 50%),
    linear-gradient(135deg, #1e1b2e 0%, #14101f 100%);
}

.blog-yt-facade:hover img { transform: scale(1.04); filter: brightness(1.08); }

.blog-yt-play {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4.5rem;
  height: 3.2rem;
  margin: -1.6rem 0 0 -2.25rem;
  border-radius: 0.9rem;
  background: linear-gradient(135deg, var(--accent-hot, #f43f5e), var(--primary, #6d28d9));
  box-shadow: 0 6px 24px rgba(244, 63, 94, 0.35);
  transition: var(--transition, all 0.35s ease);
}

.blog-yt-play::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  margin: -0.65rem 0 0 -0.4rem;
  border-style: solid;
  border-width: 0.65rem 0 0.65rem 1.1rem;
  border-color: transparent transparent transparent #fff;
}

.blog-yt-facade:hover .blog-yt-play,
.blog-yt-facade:focus-visible .blog-yt-play { transform: scale(1.08); }

.blog-yt-facade:focus-visible { outline: 2px solid var(--accent-cyan, #06b6d4); outline-offset: 3px; }

.blog-yt-player iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ── Lightbox ────────────────────────── */

.blog-lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2.5rem 1rem 1.5rem;
  background: rgba(8, 7, 14, 0.92);
  backdrop-filter: blur(8px);
  cursor: zoom-out;
  animation: blog-fade 0.2s ease;
}

.blog-lightbox img {
  max-width: 100%;
  max-height: calc(100vh - 6rem);
  object-fit: contain;
  border-radius: var(--radius-md, 0.625rem);
  box-shadow: 0 12px 60px rgba(0, 0, 0, 0.6);
  cursor: default;
}

.blog-lightbox-caption { color: var(--text-muted, #b8a89a); font-size: 0.9rem; font-style: italic; text-align: center; max-width: 720px; }

.blog-lightbox-close {
  position: absolute;
  top: 0.75rem;
  right: 0.9rem;
  width: 2.5rem;
  height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  line-height: 1;
  color: var(--text-light, #f8fafc);
  background: rgba(20, 18, 36, 0.85);
  border: 1px solid rgba(139, 92, 246, 0.35);
  border-radius: 50%;
  cursor: pointer;
  transition: var(--transition, all 0.35s ease);
}

.blog-lightbox-close:hover { background: rgba(139, 92, 246, 0.35); border-color: var(--primary-vivid, #8b5cf6); }

.blog-lightbox-open { overflow: hidden; }

@keyframes blog-fade { from { opacity: 0; } to { opacity: 1; } }

/* ── Reveal on scroll ────────────────── */

.blog-reveal.is-armed:not(.is-in) { opacity: 0; transform: translateY(18px); }
.blog-reveal.is-armed { transition: opacity 0.7s ease, transform 0.7s cubic-bezier(0.4, 0, 0.2, 1); }
.blog-reveal.is-in { opacity: 1; transform: none; }

/* ── Chat ────────────────────────────── */

.blog-chat {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin: 1.75rem 0;
  padding: 1.1rem;
  border: 1px solid rgba(139, 92, 246, 0.2);
  border-radius: var(--radius-lg, 1.25rem);
  background: linear-gradient(160deg, rgba(30, 27, 46, 0.85) 0%, rgba(20, 18, 34, 0.85) 100%);
  box-shadow: 0 4px 24px rgba(139, 92, 246, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.blog-chat-turn { display: flex; flex-direction: column; gap: 0.35rem; max-width: 92%; }
.blog-chat-turn.blog-chat-user { align-self: flex-end; align-items: flex-end; }
.blog-chat-turn.blog-chat-assistant { align-self: flex-start; }
.blog-chat-turn.blog-chat-system,
.blog-chat-turn.blog-chat-tool { align-self: stretch; max-width: 100%; }

.blog-chat-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; font-size: 0.75rem; color: var(--text-muted, #b8a89a); }

.blog-chat-role { font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; font-size: 0.7rem; color: var(--primary-light, #a78bfa); }
.blog-chat-user .blog-chat-role { color: var(--accent-cyan, #67e8f9); }
.blog-chat-system .blog-chat-role { color: var(--accent-orange, #f97316); }
.blog-chat-tool .blog-chat-role { color: var(--accent-green, #10b981); }

.blog-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 500;
  line-height: 1.5;
  color: #d4bcfa;
  background: rgba(139, 92, 246, 0.16);
  border: 1px solid rgba(139, 92, 246, 0.22);
  font-family: 'Ubuntu Mono', 'Fira Code', monospace;
  white-space: nowrap;
}

.blog-chip-tokens { color: #a5f3fc; background: rgba(103, 232, 249, 0.1); border-color: rgba(103, 232, 249, 0.2); }
.blog-chip-cost { color: #fcd34d; background: rgba(250, 204, 21, 0.1); border-color: rgba(250, 204, 21, 0.22); }
.blog-chip-time { color: #a7f3d0; background: rgba(16, 185, 129, 0.1); border-color: rgba(16, 185, 129, 0.22); }

.blog-chat-bubble {
  position: relative;
  padding: 0.75rem 1rem;
  border-radius: 1.1rem;
  font-size: 0.97rem;
  line-height: 1.65;
  color: #e5e7eb;
  overflow-wrap: anywhere;
  border: 1px solid rgba(139, 92, 246, 0.2);
  background: rgba(139, 92, 246, 0.1);
}

.blog-chat-bubble > :first-child { margin-top: 0; }
.blog-chat-bubble > :last-child { margin-bottom: 0; }
.blog-chat-bubble p { margin-bottom: 0.7rem; }
.blog-chat-bubble .blog-code-block { margin: 0.8rem 0; }
.blog-chat-bubble ul, .blog-chat-bubble ol { margin-bottom: 0.7rem; }

.blog-chat-user .blog-chat-bubble {
  border-bottom-right-radius: 0.3rem;
  border-color: rgba(103, 232, 249, 0.25);
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.18), rgba(6, 182, 212, 0.07));
}

.blog-chat-assistant .blog-chat-bubble { border-bottom-left-radius: 0.3rem; }

.blog-chat-system .blog-chat-bubble {
  font-size: 0.88rem;
  font-style: italic;
  color: #fdba74;
  border-color: rgba(249, 115, 22, 0.25);
  background: rgba(249, 115, 22, 0.08);
}

.blog-chat-tool .blog-chat-bubble {
  font-family: 'Ubuntu Mono', 'Fira Code', monospace;
  font-size: 0.85rem;
  border-style: dashed;
  border-color: rgba(16, 185, 129, 0.3);
  background: rgba(16, 185, 129, 0.07);
  color: #d1fae5;
}

.blog-chat-bubble.is-typing::after {
  content: '';
  display: inline-block;
  width: 0.5em;
  height: 1em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--accent-cyan, #67e8f9);
  animation: blog-caret 0.8s steps(2) infinite;
}

@keyframes blog-caret { 50% { opacity: 0; } }

.blog-chat-bubble.is-collapsible:not(.is-expanded) {
  max-height: 11.5rem;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(#000 70%, transparent);
  mask-image: linear-gradient(#000 70%, transparent);
}

.blog-chat-more {
  align-self: flex-start;
  padding: 0.2rem 0.75rem;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--primary-light, #a78bfa);
  background: rgba(20, 18, 36, 0.85);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: var(--radius-sm, 0.375rem);
  cursor: pointer;
  transition: var(--transition, all 0.35s ease);
}

.blog-chat-more:hover { color: #fff; background: rgba(139, 92, 246, 0.3); border-color: var(--primary-vivid, #8b5cf6); }
.blog-chat-user .blog-chat-more { align-self: flex-end; }

/* ── Stats ───────────────────────────── */

.blog-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin: 1.75rem 0;
}

.blog-stat {
  padding: 1.1rem 1.2rem;
  border: 1px solid rgba(139, 92, 246, 0.22);
  border-radius: var(--radius-md, 0.625rem);
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.14) 0%, rgba(30, 30, 46, 0.6) 100%);
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.03);
  text-align: center;
}

.blog-stat-value {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(135deg, #fff 30%, var(--accent-cyan, #67e8f9));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.blog-stat-label { margin-top: 0.3rem; font-size: 0.9rem; font-weight: 600; color: var(--text-light, #f8fafc); }
.blog-stat-note { margin-top: 0.15rem; font-size: 0.78rem; color: var(--text-muted, #b8a89a); }

/* ── Charts ──────────────────────────── */

.blog-chart {
  margin: 2rem 0;
  padding: 1rem 1rem 0.75rem;
  border: 1px solid rgba(139, 92, 246, 0.22);
  border-radius: var(--radius-md, 0.625rem);
  background: linear-gradient(160deg, #1e1b2e 0%, #1a1b26 100%);
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.blog-chart-title { margin-bottom: 0.5rem; text-align: center; font-weight: 700; font-size: 0.95rem; color: var(--text-light, #f8fafc); }
.blog-chart-canvas { position: relative; }
.blog-chart-canvas:empty { display: none; }
.blog-chart.is-drawn .blog-chart-fallback { display: none; }
.blog-chart .blog-table-wrap { margin: 0.25rem 0 0.5rem; }
.blog-chart-error { padding: 0.75rem 1rem; color: #fecdd3; font-size: 0.9rem; }

.blog-chart-tip {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  padding: 0.4rem 0.65rem;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--text-light, #f8fafc);
  background: rgba(10, 10, 15, 0.92);
  border: 1px solid rgba(139, 92, 246, 0.4);
  border-radius: var(--radius-sm, 0.375rem);
  white-space: nowrap;
  transition: opacity 0.12s ease;
}

.blog-chart svg text { font-family: "Ubuntu", sans-serif; }
.blog-chart svg rect { transition: opacity 0.15s ease; }
.blog-chart svg rect:hover { opacity: 1; }

/* ── Mermaid ─────────────────────────── */

pre.blog-mermaid {
  margin: 1.75rem 0;
  padding: 1rem;
  overflow-x: auto;
  text-align: center;
  font-family: 'Ubuntu Mono', 'Fira Code', monospace;
  font-size: 0.85rem;
  color: #9ca3af;
  white-space: pre;
  border: 1px solid rgba(139, 92, 246, 0.22);
  border-radius: var(--radius-md, 0.625rem);
  background: linear-gradient(160deg, #1e1b2e 0%, #1a1b26 100%);
}

pre.blog-mermaid[data-processed] { white-space: normal; color: inherit; }
pre.blog-mermaid svg { max-width: 100%; height: auto; }

/* ── Task lists ──────────────────────── */

.blog-content ul.contains-task-list { list-style: none; padding-left: 0.25rem; }

.blog-content .task-list-item { display: flex; align-items: baseline; gap: 0.6rem; }

.task-list-item-checkbox {
  flex: none;
  appearance: none;
  -webkit-appearance: none;
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  position: relative;
  top: 0.18rem;
  border: 1.5px solid rgba(139, 92, 246, 0.55);
  border-radius: 0.3rem;
  background: rgba(139, 92, 246, 0.08);
}

.task-list-item-checkbox:checked {
  background: linear-gradient(135deg, var(--primary-vivid, #8b5cf6), var(--accent-cyan, #06b6d4));
  border-color: transparent;
}

.task-list-item-checkbox:checked::after {
  content: '';
  position: absolute;
  left: 0.3rem;
  top: 0.08rem;
  width: 0.3rem;
  height: 0.6rem;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ── Footnotes ───────────────────────── */

.blog-content .footnote-ref { font-size: 0.75em; line-height: 0; }
.blog-content .footnote-ref a { text-decoration: none; padding: 0 0.1em; }

.blog-content .footnotes-sep {
  margin: 3rem 0 1rem;
}

.blog-content .footnotes { font-size: 0.88rem; color: var(--text-muted, #b8a89a); }
.blog-content .footnotes-list { padding-left: 1.4rem; }
.blog-content .footnotes-list p { margin-bottom: 0.35rem; }
.blog-content .footnote-backref { text-decoration: none; margin-left: 0.2rem; }
.blog-content .footnote-item:target { background: rgba(139, 92, 246, 0.12); border-radius: var(--radius-sm, 0.375rem); }

/* ── TOC refinements ─────────────────── */

.blog-toc ul { counter-reset: toc; }
.blog-toc li { line-height: 1.6; }
.blog-toc li.blog-toc-l3 { padding-left: 1.1rem; }
.blog-toc li.blog-toc-l3 a { font-size: 0.84rem; opacity: 0.85; }
.blog-toc a { display: inline-block; }
html { scroll-behavior: smooth; }

.blog-content h2[id],
.blog-content h3[id] { scroll-margin-top: 1.25rem; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .blog-reveal,
  .blog-reveal.is-armed,
  .blog-reveal.is-armed:not(.is-in) { opacity: 1; transform: none; transition: none; }
  .blog-lightbox { animation: none; }
  .blog-chat-bubble.is-typing::after { animation: none; }
}

/* ── Mobile ──────────────────────────── */

@media (max-width: 968px) {
  .blog-chat { padding: 0.75rem; margin-left: -0.5rem; margin-right: -0.5rem; border-radius: var(--radius-md, 0.625rem); }
  .blog-chat-turn { max-width: 100%; }
  .blog-stats { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
  .blog-yt-facade, .blog-yt-player, .blog-video-fig video { border-radius: 0; margin-left: -1rem; margin-right: -1rem; width: calc(100% + 2rem); max-width: none; }
  .blog-figure.blog-img-left,
  .blog-figure.blog-img-right { float: none; max-width: 100%; margin: 1.5rem 0; }
  .blog-figure.blog-img-wide { max-width: 100%; margin-left: 0; transform: none; width: auto; }
  .blog-chart { margin-left: -0.5rem; margin-right: -0.5rem; padding: 0.75rem 0.5rem 0.5rem; }
  .blog-diff .diff-line { padding-left: 1.4rem; padding-right: 1rem; }
  .blog-code-block .hl-line { --hl-pad: 1rem; }
  .blog-lightbox { padding: 3rem 0.5rem 1rem; }
}
