/*
 * Django 6 Blog - Кастомные стили
 * 
 * Цветовая схема:
 * - Белый фон (#ffffff)
 * - Черные кнопки (Bootstrap dark)
 * - Желтые акценты (Bootstrap warning)
 */

:root {
  --accent-yellow: #ffc107;
  --accent-yellow-hover: #ffcd39;
  --text-dark: #212529;
  --text-muted: #6c757d;
}

/* Общие стили */
body {
  background-color: #ffffff;
  color: var(--text-dark);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
}

/* Навигация */
.site-header {
  z-index: 1030;
  box-shadow: 0 0.25rem 1rem rgba(33, 37, 41, 0.04);
}

.navbar-brand {
  font-weight: 700;
  font-size: 1.5rem;
}

.nav-link.active {
  background-color: var(--accent-yellow) !important;
  color: var(--text-dark) !important;
  border-radius: 0.25rem;
  padding: 0.5rem 1rem !important;
  font-weight: 600;
}

.nav-link {
  transition: all 0.2s ease;
}

.nav-link:hover:not(.active) {
  background-color: rgba(255, 193, 7, 0.1);
  border-radius: 0.25rem;
}

/* Карточки постов */
.card {
  border: 1px solid #dee2e6;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.card-title a {
  color: var(--text-dark);
  transition: color 0.2s ease;
}

.card-title a:hover {
  color: var(--accent-yellow);
}

/* Кнопки */
.btn-dark {
  background-color: var(--text-dark);
  border-color: var(--text-dark);
  transition: all 0.2s ease;
}

.btn-dark:hover {
  background-color: #000000;
  border-color: #000000;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Детальный просмотр поста */
.post-content {
  font-size: 1.1rem;
  line-height: 1.8;
  color: var(--text-dark);
}

.post-content p {
  margin-bottom: 1.5rem;
}

.post-content img.post-content-image {
  max-width: 100%;
  width: auto;
  max-height: min(72vh, 760px);
  object-fit: contain;
  border-radius: 0.75rem;
  box-shadow: 0 0.75rem 2rem rgba(33, 37, 41, 0.10);
}

article h1 {
  font-weight: 700;
  margin-bottom: 1.5rem;
}

.post-card-stats {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.post-reactions {
  background: linear-gradient(135deg, rgba(255, 193, 7, 0.14), rgba(255, 255, 255, 0.92));
  border: 1px solid rgba(255, 193, 7, 0.45);
  border-radius: 999px;
  padding: 0.75rem 1rem;
  width: fit-content;
  max-width: 100%;
}

.post-reaction-stat {
  color: var(--text-dark);
  font-weight: 600;
}

.post-like-form {
  margin: 0;
}

.post-like-button {
  border: 1px solid rgba(220, 53, 69, 0.35);
  background-color: #ffffff;
  color: #dc3545;
  border-radius: 999px;
  font-weight: 700;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.post-like-button:hover,
.post-like-button.is-liked {
  background-color: #dc3545;
  border-color: #dc3545;
  color: #ffffff;
  box-shadow: 0 0.5rem 1rem rgba(220, 53, 69, 0.16);
}

.post-like-button:active {
  transform: translateY(1px) scale(0.98);
}

/* Compact post detail header */
.post-detail-container {
  padding-top: clamp(0.85rem, 1.6vw, 1.35rem) !important;
}

.post-detail-header {
  border-bottom: 1px solid rgba(33, 37, 41, 0.08);
  padding-bottom: 0.8rem;
}

.post-detail-kicker .badge {
  font-size: 0.74rem;
  font-weight: 650;
}

.post-detail-title {
  font-size: clamp(1.65rem, 3vw, 2.35rem);
  letter-spacing: -0.025em;
  line-height: 1.08;
}

.post-detail-actions {
  font-size: 0.88rem;
}

.post-detail-actions .post-reactions {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  width: auto;
  gap: 0.55rem !important;
}

.post-detail-actions .post-reaction-stat {
  color: var(--text-muted);
  font-weight: 500;
}

.post-detail-actions .post-like-button {
  padding: 0.15rem 0.48rem;
  font-size: 0.8rem;
  font-weight: 650;
}

.post-detail-actions .share-link-button-detail {
  min-height: 0;
  padding: 0.2rem 0.52rem;
  font-size: 0.8rem;
}

.post-detail-bottom-actions .share-link-button-detail {
  display: none;
}

.post-detail-bottom-actions {
  justify-content: flex-end;
  gap: 0.5rem;
}

.post-toc-card {
  border-color: rgba(33, 37, 41, 0.10);
  box-shadow: none;
}

.post-toc-card:hover {
  transform: none;
  box-shadow: none;
}

.post-toc-toggle {
  color: var(--text-dark);
  background: #f8f9fa;
  border: 0;
  text-align: left;
  cursor: pointer;
}

.post-toc-toggle:hover,
.post-toc-toggle:focus-visible {
  background: #fff8e1;
}

.post-toc-count {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 500;
}

.post-toc-body {
  max-height: min(48vh, 28rem);
  overflow-y: auto;
  padding-block: 0.85rem;
}

.post-toc-list {
  display: grid;
  gap: 0.18rem;
}

.post-toc-item a {
  display: block;
  padding: 0.18rem 0;
  color: var(--text-dark);
  line-height: 1.35;
}

.post-toc-item a:hover,
.post-toc-item a:focus-visible {
  color: #6f5200;
  text-decoration: underline !important;
  text-decoration-color: var(--accent-yellow) !important;
  text-underline-offset: 0.18em;
}

.post-toc-level-3 a {
  color: var(--text-muted);
  font-size: 0.94em;
}

.markdown-content h2,
.markdown-content h3 {
  scroll-margin-top: 7rem;
}

@media (max-width: 576px) {
  .post-detail-actions {
    align-items: flex-start !important;
  }

  .post-detail-actions .post-reactions {
    width: 100%;
  }

  .post-card-actions,
  .post-detail-bottom-actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 0.5rem;
  }

  .post-card-actions .button-text,
  .post-detail-bottom-actions .button-text {
    display: none !important;
  }

  .post-card-actions .share-link-button-card {
    order: 1;
  }

  .post-card-actions .btn {
    order: 2;
  }

  .post-detail-bottom-actions .share-link-button-detail {
    order: 1;
  }

  .post-detail-bottom-actions .btn {
    order: 2;
  }

  .post-detail-actions .share-link-button-detail {
    display: none;
  }

  .post-detail-bottom-actions .share-link-button-detail {
    display: inline-flex;
  }

  .post-card-actions .btn,
  .post-card-actions .share-link-button-card,
  .post-detail-bottom-actions .btn,
  .post-detail-bottom-actions .share-link-button-detail {
    display: inline-flex;
    flex: 0 0 44px;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    gap: 0;
    border: 1px solid var(--text-dark);
    border-radius: 0.375rem;
    background: var(--text-dark);
    color: #fff;
    box-shadow: none;
    line-height: 1;
    transition: all 0.2s ease;
  }

  .post-card-actions .btn .button-icon,
  .post-detail-bottom-actions .btn .button-icon {
    margin: 0;
  }

  .post-card-actions .share-link-button-card:hover,
  .post-detail-bottom-actions .share-link-button-detail:hover {
    background: #000;
    border-color: #000;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transform: translateY(-2px);
  }

  .post-card-actions .share-link-button-card.is-copied,
  .post-detail-bottom-actions .share-link-button-detail.is-copied {
    border-color: rgba(25, 135, 84, 0.45);
    background: #eaf7ef;
    color: #146c43;
  }

  .post-card-actions .share-link-button-card.is-copy-error,
  .post-detail-bottom-actions .share-link-button-detail.is-copy-error {
    border-color: rgba(220, 53, 69, 0.45);
    background: #fff0f1;
    color: #b02a37;
  }

  .post-card-actions .share-link-button-card [data-share-label],
  .post-detail-bottom-actions .share-link-button-detail [data-share-label] {
    display: none;
  }
}

/* Footer */
footer {
  margin-top: auto;
}

.footer-heart {
  color: #dc3545;
}

.markdown-content .callout {
  display: block;
  position: relative;
  border-width: 1px 1px 1px 0.35rem;
  border-radius: 0.85rem;
  box-shadow: 0 0.6rem 1.5rem rgba(33, 37, 41, 0.06);
}

.markdown-content .callout-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.markdown-content .callout-icon {
  flex: 0 0 auto;
  font-size: 1.2rem;
}

.markdown-content .callout-abstract .callout-icon,
.markdown-content .callout-summary .callout-icon,
.markdown-content .callout-tldr .callout-icon,
.markdown-content .callout-info .callout-icon,
.markdown-content .callout-todo .callout-icon {
  color: #087990;
}

.markdown-content .callout-warning .callout-icon,
.markdown-content .callout-caution .callout-icon,
.markdown-content .callout-attention .callout-icon,
.markdown-content .callout-important .callout-icon,
.markdown-content .callout-question .callout-icon,
.markdown-content .callout-help .callout-icon,
.markdown-content .callout-faq .callout-icon {
  color: #997404;
}

.markdown-content .callout-success .callout-icon,
.markdown-content .callout-check .callout-icon,
.markdown-content .callout-done .callout-icon,
.markdown-content .callout-tip .callout-icon,
.markdown-content .callout-hint .callout-icon,
.markdown-content .callout-example .callout-icon {
  color: #146c43;
}

.markdown-content .callout-error .callout-icon,
.markdown-content .callout-danger .callout-icon,
.markdown-content .callout-failure .callout-icon,
.markdown-content .callout-fail .callout-icon,
.markdown-content .callout-missing .callout-icon,
.markdown-content .callout-bug .callout-icon {
  color: #b02a37;
}

.markdown-content .callout-note .callout-icon,
.markdown-content .callout-quote .callout-icon,
.markdown-content .callout-cite .callout-icon {
  color: #6c757d;
}

.markdown-content .callout-body > :last-child {
  margin-bottom: 0;
}

.markdown-content details.callout > .callout-summary {
  display: block;
  cursor: pointer;
  list-style: none;
}

.markdown-content details.callout > .callout-summary::-webkit-details-marker {
  display: none;
}

.markdown-content details.callout > .callout-summary .callout-title {
  margin-bottom: 0 !important;
}

.markdown-content details.callout[open] > .callout-summary {
  margin-bottom: 0.5rem;
}

.markdown-content details.callout > .callout-summary:focus-visible {
  outline: 3px solid rgba(13, 110, 253, 0.45);
  outline-offset: 0.25rem;
  border-radius: 0.5rem;
}

/* Акценты */
.text-accent {
  color: var(--accent-yellow);
}

.bg-accent {
  background-color: var(--accent-yellow);
}

/* Адаптивность */
@media (max-width: 768px) {
  .navbar-brand {
    font-size: 1.2rem;
  }

  .card {
    margin-bottom: 1rem;
  }
}

/* Плавная прокрутка */
html {
  scroll-behavior: smooth;
}

/* Улучшенная читаемость */
.text-muted {
  color: var(--text-muted) !important;
}

/* Иконки */
.bi {
  vertical-align: -0.125em;
}

/* ======================
   HTMX Анимации и стили
   ====================== */

/* Индикатор загрузки для HTMX */
.htmx-indicator {
  opacity: 0;
  transition: opacity 200ms ease-in;
}

.htmx-request .htmx-indicator {
  opacity: 1;
}

.htmx-request.htmx-indicator {
  opacity: 1;
}

/* Анимация появления новых элементов */
.htmx-swapping {
  opacity: 0;
  transition: opacity 200ms ease-out;
}

.htmx-added {
  animation: fadeInUp 300ms ease-in;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Анимация при удалении элементов */
.htmx-settling {
  transition: all 300ms ease-out;
}

/* Плавное появление контента при поиске */
#post-container > .col {
  animation: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Стили для поискового индикатора */
#search-indicator {
  background-color: transparent;
  border: none;
  padding-left: 0.5rem;
}

/* Hover эффект для кнопки "Загрузить еще" */
button[hx-get] {
  position: relative;
  overflow: hidden;
}

button[hx-get]::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.1);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

button[hx-get]:active::after {
  width: 300px;
  height: 300px;
}

/* ======================
   Code Blocks и Подсветка синтаксиса
   ====================== */

/* Wrapper для позиционирования copy-button */
.code-block-wrapper {
  position: relative;
  margin-bottom: 1.5rem;
}

/* Блоки кода */
.post-content pre {
  position: relative;
  background-color: #f6f8fa;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  padding: 16px;
  overflow-x: auto;
  line-height: 1.45;
  font-family: "Consolas", "Monaco", "Courier New", monospace;
  font-size: 0.9rem;
  margin-bottom: 0;
}

.post-content pre code {
  background-color: transparent;
  border: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
  word-break: normal;
  white-space: pre;
}

/* Inline код */
.post-content code:not(pre code) {
  background-color: rgba(175, 184, 193, 0.2);
  padding: 0.2em 0.4em;
  border-radius: 6px;
  font-family: "Consolas", "Monaco", "Courier New", monospace;
  font-size: 0.9em;
  color: #24292f;
}

/* Copy-button для code blocks */
.copy-button {
  position: absolute;
  top: 8px;
  right: 8px;
  background-color: rgba(255, 255, 255, 0.8);
  border: 1px solid #d0d7de;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.875rem;
  color: #57606a;
  transition: all 0.2s ease;
  backdrop-filter: blur(4px);
  z-index: 10;
}

.copy-button:hover {
  background-color: #ffffff;
  border-color: #6e7781;
  color: #24292f;
}

.copy-button.copied {
  background-color: #dafbe1;
  border-color: #2da44e;
  color: #1a7f37;
}

.copy-button.error {
  background-color: #ffebe9;
  border-color: #cf222e;
  color: #a40e26;
}

.copy-button i {
  font-size: 1rem;
  vertical-align: middle;
}

/* Mermaid диаграммы: векторный pan/zoom для больших схем */
.mermaid-panzoom-shell {
  position: relative;
  margin: 2rem 0;
  padding: 0;
  background-color: #f6f8fa;
  border: 1px solid #d0d7de;
  border-radius: 0.9rem;
  overflow: hidden;
  box-shadow: 0 0.75rem 2rem rgba(33, 37, 41, 0.08);
}

.mermaid-panzoom-shell .mermaid {
  width: 100%;
  height: min(70vh, 720px);
  min-height: 420px;
  margin: 0;
  padding: 1rem;
  cursor: grab;
}

.mermaid-panzoom-shell .mermaid:active {
  cursor: grabbing;
}

.mermaid-panzoom-shell svg {
  display: block;
}

.mermaid-toolbar {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 5;
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mermaid-toolbar .btn {
  border-radius: 999px;
  box-shadow: 0 0.35rem 1rem rgba(33, 37, 41, 0.14);
}

.mermaid-panzoom-shell.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 2000;
  margin: 0;
  border-radius: 0;
  border: 0;
  background: #ffffff;
}

.mermaid-panzoom-shell.is-fullscreen .mermaid {
  width: 100vw;
  height: 100vh;
  min-height: 100vh;
}

/* Адаптивность для code blocks */
@media (max-width: 768px) {
  .post-content pre {
    font-size: 0.8rem;
    padding: 12px;
  }

  .copy-button {
    padding: 4px 8px;
    font-size: 0.75rem;
  }

  .copy-button i {
    font-size: 0.875rem;
  }
}

/* Scrollbar для code blocks (webkit) */
.post-content pre::-webkit-scrollbar {
  height: 8px;
}

.post-content pre::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.post-content pre::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 4px;
}

.post-content pre::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Мобильная адаптивность для code блоков */
@media (max-width: 768px) {
  .post-content pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-x: auto;
  }

  .post-content pre code {
    white-space: pre-wrap;
    word-break: break-word;
  }
}

/* Lightbox — просмотр изображений */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.9);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.lightbox-overlay.active {
  opacity: 1;
  visibility: visible;
}

.lightbox-overlay.closing {
  opacity: 0;
  visibility: visible;
}

.lightbox-container {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 92vw;
  max-height: 92vh;
}

.lightbox-img {
  display: block;
  max-width: 92vw;
  max-height: 82vh;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.6);
  transform: scale(0.96);
  transition: transform 0.3s ease;
}

.lightbox-overlay.active .lightbox-img {
  transform: scale(1);
}

.lightbox-caption {
  margin-top: 0.75rem;
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.95rem;
  text-align: center;
  max-width: 80vw;
}

.lightbox-counter {
  position: absolute;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 0.3rem 0.85rem;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 999px;
  pointer-events: none;
}

.lightbox-close,
.lightbox-prev,
.lightbox-next {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  border: none;
  color: #fff;
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
  z-index: 1;
}

.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover {
  background: rgba(0, 0, 0, 0.7);
  color: #ffc107;
  transform: scale(1.08);
}

.lightbox-close:focus-visible,
.lightbox-prev:focus-visible,
.lightbox-next:focus-visible {
  outline: 2px solid #ffc107;
  outline-offset: 2px;
}

.lightbox-close {
  top: 1.25rem;
  right: 1.25rem;
  width: 44px;
  height: 44px;
}

.lightbox-prev,
.lightbox-next {
  top: 50%;
  transform: translateY(-50%);
  width: 52px;
  height: 52px;
}

.lightbox-prev { left: 1.25rem; }
.lightbox-next { right: 1.25rem; }

.lightbox-prev:hover,
.lightbox-next:hover {
  transform: translateY(-50%) scale(1.08);
}

@media (max-width: 576px) {
  .lightbox-prev { left: 0.5rem; }
  .lightbox-next { right: 0.5rem; }
  .lightbox-close { top: 0.75rem; right: 0.75rem; }
  .lightbox-img { max-width: 96vw; max-height: 78vh; }
}

/* Sticky breadcrumbs */
.breadcrumbs-dynamic {
  position: sticky;
  top: 56px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  padding: 0.45rem 0;
  border-bottom: 1px solid rgba(33, 37, 41, 0.08);
  z-index: 1020;
  font-size: 0.84rem;
}

.article-breadcrumbs-sticky {
  box-shadow: 0 0.25rem 0.9rem rgba(33, 37, 41, 0.035);
}

.breadcrumbs-dynamic .container {
  min-height: 2rem;
}

.breadcrumbs-dynamic .breadcrumb {
  max-width: min(58%, 42rem);
  color: var(--text-muted);
}

.breadcrumb-item {
  color: var(--text-muted);
  display: inline-block;
}

.breadcrumb-item a {
  color: #495057;
  text-decoration: none;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

.breadcrumb-item a:hover,
.breadcrumb-item a:focus-visible {
  color: var(--text-dark);
  text-decoration: underline;
  text-decoration-color: rgba(33, 37, 41, 0.35);
  text-underline-offset: 0.18em;
}

.breadcrumb-item.active,
.breadcrumbs-current {
  color: #6c757d;
  font-weight: 500;
}

.breadcrumb-separator,
.breadcrumb-item + .breadcrumb-item::before {
  color: #adb5bd;
}

.breadcrumbs-section {
  min-width: 0;
  max-width: 42%;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.breadcrumbs-section.is-empty {
  display: none;
}

.article-section-label {
  color: #adb5bd;
  flex: 0 0 auto;
}

.article-section-link {
  min-width: 0;
  max-width: 18rem;
  overflow: hidden;
  color: #495057;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

.article-section-link:hover,
.article-section-link:focus-visible {
  color: var(--text-dark);
  text-decoration: underline;
  text-decoration-color: rgba(255, 193, 7, 0.85);
  text-underline-offset: 0.18em;
}

.article-section-link-h3 {
  color: #6c757d;
}

.article-section-separator {
  color: #ced4da;
  flex: 0 0 auto;
}

/* Backward guard: if a browser still has old breadcrumbs.js cached, do not let
   the retired H2 dropdown expand into the sticky bar. */
.breadcrumb-dropdown-menu {
  display: none !important;
}

.breadcrumb-h2-link {
  color: #495057;
  text-decoration: none;
}

.breadcrumb-h2-link:hover,
.breadcrumb-h2-link:focus-visible {
  color: var(--text-dark) !important;
  background: transparent !important;
  text-decoration: underline;
  text-decoration-color: rgba(255, 193, 7, 0.85);
  text-underline-offset: 0.18em;
}

/* Мобильная адаптивность для breadcrumbs */
@media (max-width: 768px) {
  .breadcrumbs-dynamic {
    font-size: 0.78rem;
    padding: 0.4rem 0;
  }

  .breadcrumbs-dynamic .breadcrumb {
    max-width: 52%;
  }

  .breadcrumbs-section {
    max-width: 46%;
  }

  .article-section-label {
    display: none;
  }

  .article-section-link-h3,
  .article-section-separator {
    display: none;
  }
}

/* ======================
   Blog index UI polish
   ====================== */
.navbar-nav {
  gap: 0.5rem;
  align-items: center;
}

.navbar .btn {
  border-radius: 999px;
  padding-inline: 1rem;
}

.navbar .btn.border-warning {
  background: #fff7df;
  color: var(--text-dark);
  box-shadow: inset 0 0 0 1px rgba(255, 193, 7, 0.35);
}

.blog-index {
  max-width: 1180px;
}

.blog-hero {
  background: linear-gradient(135deg, #fff8df 0%, #ffffff 52%, #f6f8fa 100%);
  border: 1px solid rgba(33, 37, 41, 0.08);
  border-radius: 1.5rem;
  padding: clamp(1.25rem, 3vw, 2rem);
  box-shadow: 0 16px 40px rgba(33, 37, 41, 0.06);
}

.blog-eyebrow {
  color: #8a6400;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.filter-panel {
  background: #ffffff;
  border: 1px solid rgba(33, 37, 41, 0.08);
  border-radius: 1.25rem;
  padding: 1rem;
  box-shadow: 0 10px 30px rgba(33, 37, 41, 0.05);
}

.blog-search-group {
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(33, 37, 41, 0.08);
}

.blog-search-icon,
.blog-search-input,
.blog-search-indicator {
  min-height: 3rem;
}

.blog-search-icon {
  border-top-left-radius: 999px !important;
  border-bottom-left-radius: 999px !important;
  background: #fff8df;
  border-color: #f2dfaa;
  color: #8a6400;
  padding-left: 1rem;
}

.blog-search-input {
  border-color: #f2dfaa;
}

.blog-search-input:focus {
  border-color: var(--accent-yellow);
  box-shadow: none;
}

.blog-search-button {
  border-top-right-radius: 999px !important;
  border-bottom-right-radius: 999px !important;
  padding-inline: 1.3rem;
  font-weight: 700;
}

.blog-search-indicator {
  border: 0;
  background: transparent;
  padding-inline: 0.75rem 1rem;
  border-top-right-radius: 999px !important;
  border-bottom-right-radius: 999px !important;
}

.post-badge {
  border-radius: 999px;
  font-weight: 700;
  padding: 0.45rem 0.7rem;
}

.post-badge-category {
  background: #ffe8a3;
  color: #523d00;
  border: 1px solid #f5d36f;
}

.post-badge-category:hover {
  background: #ffd75a;
  color: #2b2100;
}

.post-badge-tag {
  background: #f6f8fa;
  color: #495057;
  border: 1px solid #dfe5eb;
}

.post-badge-tag:hover {
  background: #e9ecef;
  color: #212529;
}

.post-badge-type {
  background: #212529;
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow: 0 0.4rem 1rem rgba(0, 0, 0, 0.18);
}

.post-badge-type-overlay {
  position: absolute;
  top: 0.85rem;
  left: 0.85rem;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  backdrop-filter: blur(8px);
  background: rgba(33, 37, 41, 0.88);
}

.post-badge-type-article {
  background: rgba(33, 37, 41, 0.92);
}

.post-badge-type-video {
  background: rgba(13, 110, 253, 0.92);
}

.post-badge-type-audio {
  background: rgba(25, 135, 84, 0.92);
}

.post-badge-type-podcast {
  background: rgba(111, 66, 193, 0.92);
}

.post-card {
  border: 1px solid rgba(33, 37, 41, 0.08);
  border-radius: 1.25rem;
  overflow: hidden;
  box-shadow: 0 10px 28px rgba(33, 37, 41, 0.07);
}

.post-card-cover-link {
  display: block;
  color: inherit;
  text-decoration: none;
  position: relative;
}

.post-card-cover {
  width: 100%;
  height: 190px;
  display: block;
  object-fit: cover;
  background: #f6f8fa;
}

.post-card-cover-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 18% 22%, rgba(255, 193, 7, 0.42), transparent 27%),
    radial-gradient(circle at 84% 76%, rgba(255, 255, 255, 0.12), transparent 28%),
    linear-gradient(135deg, #2b2f36 0%, #121417 100%);
  color: rgba(255, 255, 255, 0.9);
}

.post-card-cover-placeholder-mark {
  width: 6.25rem;
  height: 6.25rem;
  border-radius: 2rem;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.24);
  box-shadow: 0 1rem 2rem rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(10px);
}

.post-card-cover-placeholder-mark .bi {
  font-size: 2.65rem;
  line-height: 1;
}

.post-card-cover-placeholder-mark span {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.post-card-cover-placeholder-article {
  background:
    radial-gradient(circle at 18% 22%, rgba(255, 193, 7, 0.44), transparent 27%),
    linear-gradient(135deg, #2b2f36 0%, #121417 100%);
}

.post-card-cover-placeholder-video {
  background:
    radial-gradient(circle at 18% 22%, rgba(13, 110, 253, 0.48), transparent 27%),
    linear-gradient(135deg, #1d3557 0%, #111827 100%);
}

.post-card-cover-placeholder-audio {
  background:
    radial-gradient(circle at 18% 22%, rgba(25, 135, 84, 0.48), transparent 27%),
    linear-gradient(135deg, #164b35 0%, #111827 100%);
}

.post-card-cover-placeholder-podcast {
  background:
    radial-gradient(circle at 18% 22%, rgba(111, 66, 193, 0.52), transparent 27%),
    linear-gradient(135deg, #3d2a68 0%, #111827 100%);
}

.post-card-title-link {
  color: var(--text-dark);
  text-decoration: none;
  background-image: linear-gradient(var(--accent-yellow), var(--accent-yellow));
  background-position: 0 100%;
  background-repeat: no-repeat;
  background-size: 0 0.18em;
  transition: background-size 0.2s ease, color 0.2s ease;
}

.post-card-title-link:hover {
  color: #000;
  background-size: 100% 0.18em;
}

.post-card-byline,
.post-card-date {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.post-card-author {
  color: #343a40;
  font-weight: 600;
}

.post-detail-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  font-size: 0.95rem;
}

.post-detail-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}

.post-detail-author {
  color: var(--text-dark);
  font-weight: 700;
}

.post-detail-meta-spacer {
  flex: 1 1 auto;
}

.about-page {
  max-width: 1180px;
}

.about-hero,
.about-card,
.about-side-card {
  border-radius: 1.5rem;
  border: 1px solid rgba(33, 37, 41, 0.08);
  box-shadow: 0 16px 40px rgba(33, 37, 41, 0.06);
}

.about-hero {
  padding: clamp(1.5rem, 3vw, 2.5rem);
  background: linear-gradient(135deg, #fff8df 0%, #ffffff 58%, #f6f8fa 100%);
}

.about-quote {
  border-left: 0.35rem solid var(--accent-yellow);
  padding: 1rem 1.25rem;
  background: #fff8df;
  border-radius: 0.75rem;
}

.about-list li + li {
  margin-top: 0.7rem;
}

.post-card-excerpt {
  color: #495057;
  line-height: 1.65;
}

.post-card-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.post-share-panel {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

@media (max-width: 576px) {
  .blog-search-group {
    border-radius: 1rem;
    box-shadow: none;
  }

  .blog-search-icon {
    display: none;
  }

  .blog-search-input {
    border-top-left-radius: 1rem !important;
    border-bottom-left-radius: 1rem !important;
  }

  .blog-search-input {
    width: 100% !important;
  }

  .breadcrumbs-section {
    display: none;
  }

  .post-detail-meta-spacer {
    display: none;
  }

  .mermaid-toolbar {
    left: 0.75rem;
    right: 0.75rem;
  }
}

/* Audio/video post players and clickable timecodes */
.post-media-section {
  border-radius: 1.25rem;
}

.post-media-card {
  overflow: hidden;
  border: 1px solid rgba(33, 37, 41, 0.08);
  border-radius: 1.25rem;
  background: linear-gradient(135deg, #111827, #343a40);
  box-shadow: 0 1rem 2.5rem rgba(15, 23, 42, 0.12);
}

.post-media-player {
  display: block;
  width: 100%;
  max-height: 72vh;
  border-radius: 1.25rem;
}

.timecode-list {
  padding: clamp(1rem, 2vw, 1.25rem);
  border: 1px solid rgba(33, 37, 41, 0.08);
  border-radius: 1.25rem;
  background:
    radial-gradient(circle at 12% 0%, rgba(255, 193, 7, 0.16), transparent 32%),
    linear-gradient(135deg, #fffdf5 0%, #ffffff 58%, #f8fafc 100%);
  box-shadow: 0 1rem 2.25rem rgba(33, 37, 41, 0.06);
}

.timecode-list-header {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.timecode-list-icon {
  width: 2.65rem;
  height: 2.65rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border-radius: 0.9rem;
  color: #4c3900;
  background: linear-gradient(135deg, #ffc107 0%, #ffe8a3 100%);
  box-shadow: 0 0.75rem 1.5rem rgba(255, 193, 7, 0.22);
}

.timecode-list-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.timecode-grid {
  display: grid;
  gap: 0.65rem;
}

.timecode-button {
  position: relative;
  display: grid;
  grid-template-columns: minmax(4.5rem, auto) 1fr;
  gap: 0.75rem;
  align-items: center;
  width: 100%;
  min-height: 3.15rem;
  padding: 0.65rem 0.85rem 0.65rem 0.7rem;
  border: 1px solid rgba(222, 226, 230, 0.92);
  border-radius: 1rem;
  color: #343a40;
  text-align: left;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 0.35rem 1rem rgba(33, 37, 41, 0.04);
  transition:
    transform 0.16s ease,
    border-color 0.16s ease,
    background 0.16s ease,
    box-shadow 0.16s ease,
    color 0.16s ease;
}

.timecode-button::before {
  content: "";
  position: absolute;
  inset: 0.55rem auto 0.55rem 0.45rem;
  width: 0.22rem;
  border-radius: 999px;
  background: transparent;
  transition: background 0.16s ease, box-shadow 0.16s ease;
}

.timecode-button:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 193, 7, 0.72);
  color: #212529;
  background: #fffaf0;
  box-shadow: 0 0.75rem 1.4rem rgba(33, 37, 41, 0.07);
}

.timecode-button.is-active,
.timecode-button:focus-visible {
  color: #111827;
  background: linear-gradient(135deg, #fff7df 0%, #ffffff 100%);
  border-color: #ffc107;
  box-shadow:
    0 0 0 0.2rem rgba(255, 193, 7, 0.18),
    0 0.9rem 1.8rem rgba(255, 193, 7, 0.16);
  outline: none;
}

.timecode-button.is-active::before,
.timecode-button:focus-visible::before {
  background: #ffc107;
  box-shadow: 0 0 0.9rem rgba(255, 193, 7, 0.55);
}

.timecode-time {
  min-width: 4.35rem;
  justify-self: start;
  padding: 0.32rem 0.55rem;
  border-radius: 999px;
  color: #4c3900;
  background: #fff3cd;
  font-size: 0.88rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.timecode-label {
  flex: 1;
  font-weight: 650;
  line-height: 1.35;
}

@media (max-width: 576px) {
  .timecode-button {
    grid-template-columns: 1fr;
    gap: 0.45rem;
  }

  .timecode-time {
    min-width: 0;
  }
}

/* Reading progress bar */
.reading-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: #ffc107;
  z-index: 1031;
  width: 0;
  transition: width 0.1s ease-out;
  box-shadow: 0 0 4px rgba(255, 193, 7, 0.5);
}

/* ─── Accessibility: skip link ─── */
.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  z-index: 1100;
  padding: 0.5rem 1.5rem;
  background: var(--accent-yellow);
  color: var(--text-dark);
  font-weight: 600;
  border-radius: 0 0 0.375rem 0;
  transition: top 0.2s;
}
.skip-link:focus {
  top: 0;
  outline: 2px solid var(--text-dark);
  outline-offset: 2px;
}

/* ─── Accessibility: improved focus states ─── */
a:focus-visible,
button:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent-yellow);
  outline-offset: 2px;
  border-radius: 0.125rem;
}

.navbar-toggler:focus-visible {
  outline: 2px solid var(--accent-yellow);
}

/* ─── Lazy-load images: fade in when loaded ─── */
.markdown-content img {
  opacity: 0;
  transition: opacity 0.3s ease;
}
.markdown-content img.loaded,
.markdown-content img[data-src] {
  opacity: 1;
}
.markdown-content img.no-lazy {
  opacity: 1;
}

/* ─── Skeleton loading for HTMX ─── */
.htmx-skeleton {
  display: none;
}
.htmx-request .htmx-skeleton,
.htmx-loading .htmx-skeleton {
  display: block;
}
.skeleton-card {
  background: #f0f0f0;
  border-radius: 0.5rem;
  padding: 1.5rem;
  margin-bottom: 1rem;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-line {
  height: 1rem;
  background: #e0e0e0;
  border-radius: 0.25rem;
  margin-bottom: 0.5rem;
}
.skeleton-line:last-child {
  width: 60%;
}
.skeleton-image {
  height: 200px;
  background: #e8e8e8;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
}
@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ─── Mobile typography improvements ─── */
@media (max-width: 576px) {
  .post-content {
    font-size: 0.95rem;
    line-height: 1.7;
  }
  .post-content p {
    margin-bottom: 1.1rem;
  }
  .post-content h2 {
    font-size: 1.35rem;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
  }
  .post-content h3 {
    font-size: 1.15rem;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
  }
  .post-content pre {
    font-size: 0.85rem;
    overflow-x: auto;
  }
  .post-content code {
    font-size: 0.85rem;
  }
  .display-5 {
    font-size: 1.75rem;
  }
}

/* ─── Related posts ─── */
.related-posts {
  margin-top: 3rem;
}
.related-posts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}
.related-post-card {
  background: #f8f9fa;
  border-radius: 0.5rem;
  padding: 1rem;
  transition: box-shadow 0.2s;
}
.related-post-card:hover {
  box-shadow: 0 0.25rem 0.75rem rgba(0,0,0,0.08);
}
.related-post-card a {
  text-decoration: none;
  color: var(--text-dark);
}
.related-post-card h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.related-post-card .related-type-badge {
  font-size: 0.75rem;
}

/* ─── TOC card ─── */
.toc-card {
  background: #f8f9fa;
  border-radius: 0.5rem;
  padding: 1rem 1.25rem;
  margin-bottom: 2rem;
}
.toc-card .toc-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.toc-card ol {
  list-style: none;
  padding-left: 0;
  margin: 0;
}
.toc-card li {
  padding: 0.2rem 0;
}
.toc-card a {
  text-decoration: none;
  color: var(--text-dark);
  font-size: 0.9rem;
}
.toc-card a:hover {
  color: var(--accent-yellow-hover);
}
.toc-card .toc-level-3 {
  padding-left: 1.2rem;
}

/* ─── Series landing page ─── */
.series-detail-header {
  background: #f8f9fa;
  border-radius: 0.75rem;
  padding: 2rem;
  margin-bottom: 2rem;
}
.series-post-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  border-bottom: 1px solid #eee;
}
.series-post-item:last-child {
  border-bottom: none;
}
.series-post-number {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--accent-yellow);
  color: var(--text-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
}

/* Mobile action-pair geometry contract */
@media (max-width: 576px) {
  .post-card-actions .btn,
  .post-card-actions .share-link-button-card,
  .post-detail-bottom-actions .btn,
  .post-detail-bottom-actions .share-link-button-detail {
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
  }

  .post-card-actions .btn:hover,
  .post-card-actions .btn:active,
  .post-card-actions .share-link-button-card:hover,
  .post-card-actions .share-link-button-card:active,
  .post-detail-bottom-actions .btn:hover,
  .post-detail-bottom-actions .btn:active,
  .post-detail-bottom-actions .share-link-button-detail:hover,
  .post-detail-bottom-actions .share-link-button-detail:active {
    transform: none;
  }

  .post-card-actions .btn:focus-visible,
  .post-card-actions .share-link-button-card:focus-visible,
  .post-detail-bottom-actions .btn:focus-visible,
  .post-detail-bottom-actions .share-link-button-detail:focus-visible {
    outline: 3px solid rgba(255, 193, 7, 0.85);
    outline-offset: 3px;
  }
}

/* Detail breadcrumb responsive contract */
@media (max-width: 576px) {
  .breadcrumbs-dynamic {
    position: static;
    top: auto;
    padding: 0;
    backdrop-filter: none;
  }

  .breadcrumbs-dynamic .container {
    min-height: 44px;
    flex-wrap: nowrap;
  }

  .breadcrumbs-dynamic .breadcrumb {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
    overflow: hidden;
    white-space: nowrap;
  }

  .breadcrumbs-dynamic .breadcrumbs-root {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
  }

  .breadcrumbs-dynamic .breadcrumbs-root:nth-child(n + 3) {
    display: none;
  }

  .breadcrumbs-dynamic .breadcrumbs-root a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }

  .breadcrumbs-dynamic .breadcrumbs-current {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .breadcrumbs-section {
    display: none;
  }
}

@media (min-width: 577px) {
  .breadcrumbs-dynamic {
    top: var(--site-header-height, 56px);
  }

  .breadcrumbs-dynamic .container {
    flex-wrap: nowrap;
  }

  .breadcrumbs-dynamic .breadcrumb {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
  }

  .breadcrumbs-dynamic .breadcrumbs-root {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .breadcrumbs-dynamic .breadcrumbs-current {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .breadcrumbs-section {
    flex: 0 1 42%;
    min-width: 0;
  }
}

/* Detail return-to-top */
#post-start {
  scroll-margin-top: 8.5rem;
}

.post-back-to-top {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-top: 0.5rem;
  margin-left: auto;
  border: 1px solid var(--text-dark);
  border-radius: 0.375rem;
  background: var(--text-dark);
  color: #fff;
  text-decoration: none;
}

.post-back-to-top:hover {
  background: #000;
  border-color: #000;
  color: #fff;
}

.post-back-to-top:focus-visible {
  outline: 3px solid rgba(255, 193, 7, 0.85);
  outline-offset: 3px;
}

.post-back-to-top.is-enhanced {
  position: fixed;
  right: calc(1rem + env(safe-area-inset-right, 0px));
  bottom: calc(5.25rem + env(safe-area-inset-bottom, 0px));
  z-index: 1010;
  margin: 0;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.post-back-to-top.is-enhanced.is-visible {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

@media (min-width: 577px) {
  .post-back-to-top.is-enhanced {
    right: calc(1.5rem + env(safe-area-inset-right, 0px));
    bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .post-back-to-top {
    transition: none;
  }
}

