/* ═══════════════════════════════════════════════════════════════════════
   Tao Liu — Article Viewer · Magazine-grade Typography
   Dual-column layout · TOC sidebar · Lightbox · Code highlighting
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Article Page Layout (dual column) ── */
.article-page {
  display: flex;
  gap: 3rem;
  max-width: 1300px;
  margin: 0 auto;
  padding: calc(var(--navbar-height) + 28px) 28px 40px;
  align-items: flex-start;
}
.article-body {
  flex: 1;
  min-width: 0;
  max-width: 1100px;
}
.article-sidebar {
  width: 220px;
  flex-shrink: 0;
  position: sticky;
  top: calc(var(--navbar-height) + 28px);
  max-height: calc(100vh - var(--navbar-height) - 60px);
  overflow-y: auto;
}

/* ── Reading Progress ── */
.scroll-progress {
  position: fixed; top: 0; left: 0; height: 2.5px;
  background: linear-gradient(90deg, var(--accent), var(--accent-teal), var(--accent-warm));
  z-index: 1001; width: 0%;
  border-radius: 0 2px 2px 0;
  transition: width 80ms linear;
}

/* ═══════════════════════════════════════════════════════════════════════
   TOC SIDEBAR
   ═══════════════════════════════════════════════════════════════════════ */
.toc-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.8rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
}
.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.toc-item {
  margin-bottom: 2px;
}
.toc-link {
  display: block;
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-radius: 6px;
  border-left: 2px solid transparent;
  transition: all var(--transition-fast);
  line-height: 1.4;
  text-decoration: none;
}
.toc-link:hover {
  color: var(--text-secondary);
  background: rgba(255,255,255,0.03);
}
.toc-link.active {
  color: var(--accent);
  background: rgba(124,111,247,0.08);
  border-left-color: var(--accent);
  font-weight: 500;
}
/* TOC sub-items (H3) */
.toc-link.toc-h3 {
  padding-left: 1.4rem;
  font-size: 0.75rem;
}

/* ═══════════════════════════════════════════════════════════════════════
   MARKDOWN CONTENT — Magazine Typography
   ═══════════════════════════════════════════════════════════════════════ */
.markdown-content {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-xl);
  padding: 3rem 3.5rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  line-height: 1.9;
  font-size: 1.08rem;
  letter-spacing: 0.005em;
}

/* ── H1: Article Title ── */
.markdown-content h1 {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.2;
  color: var(--text-primary);
  margin-top: 0;
  margin-bottom: 0.6em;
  padding-bottom: 0.45em;
  position: relative;
}
.markdown-content h1::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0;
  width: 60px; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-teal));
  border-radius: 2px;
}

/* ── H2: Section Heading ── */
.markdown-content h2 {
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  color: var(--text-primary);
  margin-top: 2.2em;
  margin-bottom: 0.55em;
  padding-left: 0.85rem;
  border-left: 3px solid var(--accent);
  line-height: 1.35;
}

/* ── H3 ── */
.markdown-content h3 {
  font-size: 1.12rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 1.6em;
  margin-bottom: 0.45em;
}

/* ── Paragraphs ── */
.markdown-content p {
  margin-bottom: 1.25em;
  color: var(--text-secondary);
  line-height: 1.9;
}

/* ── Drop cap: first paragraph after H1 ── */
.markdown-content h1 + p::first-letter {
  float: left;
  font-size: 3.8em;
  font-weight: 700;
  line-height: 0.78;
  padding-right: 0.12em;
  padding-top: 0.04em;
  background: linear-gradient(135deg, var(--accent), var(--accent-warm));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Links ── */
.markdown-content a {
  color: var(--accent-teal);
  text-decoration: none;
  border-bottom: 1px solid rgba(0,206,201,0.25);
  transition: all var(--transition-fast);
  padding-bottom: 1px;
}
.markdown-content a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Strong / Bold ── */
.markdown-content strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* ── Horizontal Rule ── */
.markdown-content hr {
  border: none;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-card) 20%, var(--border-card) 80%, transparent);
  margin: 2.5em 0;
}

/* ── Blockquote ── */
.markdown-content blockquote {
  margin: 1.8em 0;
  padding: 1.2em 1.6em;
  border-left: 3px solid var(--accent);
  background: rgba(124,111,247,0.04);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: var(--text-secondary);
  font-style: italic;
  position: relative;
}
.markdown-content blockquote::before {
  content: '"';
  position: absolute;
  top: -8px; left: 10px;
  font-size: 3rem;
  color: var(--accent);
  opacity: 0.2;
  font-family: Georgia, serif;
  line-height: 1;
}
.markdown-content blockquote p {
  margin-bottom: 0.5em;
  color: inherit;
}

/* ── Inline Code ── */
.markdown-content code {
  padding: 0.2em 0.5em;
  font-size: 0.9em;
  font-family: var(--font-mono);
  background: rgba(0,0,0,0.28);
  border-radius: 5px;
  color: var(--accent-warm);
  font-weight: 450;
}

/* ── Code Blocks (highlight.js) ── */
.markdown-content pre {
  margin: 1.6em 0;
  padding: 1.5rem;
  overflow-x: auto;
  font-size: 0.88em;
  line-height: 1.65;
  background: #0d0d1a;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  position: relative;
}
.markdown-content pre code {
  padding: 0;
  background: none;
  color: #e0e0f0;
  font-weight: 400;
  font-size: inherit;
}
/* Language tag */
.markdown-content pre[class*="language-"]::before {
  content: attr(data-lang);
  position: absolute;
  top: 8px; right: 14px;
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: var(--font-sans);
}

/* ── Images in content ── */
.markdown-content img {
  max-width: 100%;
  border-radius: var(--radius-md);
  margin: 1.6em auto;
  box-shadow: var(--shadow-md);
  cursor: zoom-in;
  transition: all var(--transition-base);
  display: block;
}
.markdown-content img:hover {
  box-shadow: var(--shadow-lg);
  transform: scale(1.01);
}
.markdown-content div[align="center"] {
  margin: 1.6em 0;
}

/* ── Audio / Video ── */
.markdown-content audio,
.markdown-content video {
  max-width: 100%;
  margin: 1.2em 0;
  border-radius: var(--radius-md);
  outline: none;
}
.markdown-content audio {
  width: 100%;
  height: 40px;
  filter: invert(0.85) hue-rotate(180deg);
}
.markdown-content video {
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

/* ── Lists ── */
.markdown-content ul,
.markdown-content ol {
  margin: 1em 0;
  padding-left: 1.5em;
  color: var(--text-secondary);
}
.markdown-content li {
  margin-bottom: 0.35em;
  line-height: 1.75;
}
.markdown-content li::marker {
  color: var(--accent);
}

/* ── Tables ── */
.markdown-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.6em 0;
  font-size: 0.9em;
  border-radius: var(--radius-md);
  overflow: hidden;
}
.markdown-content th,
.markdown-content td {
  padding: 0.7em 1em;
  border: 1px solid var(--border-card);
  text-align: left;
}
.markdown-content th {
  background: rgba(0,0,0,0.2);
  font-weight: 600;
  color: var(--text-primary);
}
.markdown-content td {
  color: var(--text-secondary);
}

/* ═══════════════════════════════════════════════════════════════════════
   IMAGE LIGHTBOX
   ═══════════════════════════════════════════════════════════════════════ */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.35s ease;
  cursor: zoom-out;
}
.lightbox-overlay.open {
  opacity: 1;
  visibility: visible;
}
.lightbox-overlay img {
  max-width: 88vw;
  max-height: 88vh;
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 80px rgba(0,0,0,0.7);
  transform: scale(0.9);
  transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1);
}
.lightbox-overlay.open img {
  transform: scale(1);
}
.lightbox-close {
  position: absolute;
  top: 24px; right: 32px;
  width: 42px; height: 42px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 50%;
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  z-index: 1;
}
.lightbox-close:hover {
  background: rgba(255,255,255,0.18);
  transform: rotate(90deg);
}

/* ═══════════════════════════════════════════════════════════════════════
   PREV / NEXT CARD NAVIGATION
   ═══════════════════════════════════════════════════════════════════════ */
.navigation-buttons {
  display: flex;
  justify-content: space-between;
  margin-top: 32px;
  gap: 14px;
}
.nav-button {
  flex: 1;
  padding: 1rem 1.3rem;
  font-size: 0.88rem;
  font-family: var(--font-sans);
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-base);
  text-align: center;
  position: relative;
  overflow: hidden;
}
.nav-button::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(124,111,247,0.06), rgba(0,206,201,0.04));
  opacity: 0;
  transition: opacity var(--transition-base);
}
.nav-button:hover {
  color: var(--text-primary);
  border-color: var(--border-active);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.nav-button:hover::after {
  opacity: 1;
}
.nav-button .nav-label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.nav-button .nav-doc-title {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 32px 0;
}

/* ── Back Button ── */
.back-to-left {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 28px auto 40px;
  width: 44px; height: 44px;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-card);
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  transition: all var(--transition-base);
}
.back-to-left:hover {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 4px 24px var(--accent-glow);
  transform: translateX(-4px);
}

/* ═══════════════════════════════════════════════════════════════════════
   VALINE COMMENTS — Dark Theme Adaptation
   ═══════════════════════════════════════════════════════════════════════ */
.comment {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-top: 8px;
}
/* Valine text color overrides */
#valine .vinput,
#valine .vtextarea,
#valine input,
#valine textarea {
  color: var(--text-primary) !important;
  background: var(--bg-secondary) !important;
  border-color: var(--border-card) !important;
}
#valine .vcard .vnick,
#valine .vcard .vmeta,
#valine .vcard .vcontent {
  color: var(--text-secondary) !important;
}
#valine .vbtn {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #fff !important;
  border-radius: var(--radius-full) !important;
}

/* ═══════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════════════ */
@media (max-width: 860px) {
  .article-page {
    flex-direction: column;
    padding: calc(var(--navbar-height) + 16px) 16px 32px;
    gap: 1.5rem;
  }
  .article-body {
    max-width: 100%;
  }
  .article-sidebar {
    width: 100%;
    position: static;
    max-height: none;
    order: -1;
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: var(--radius-md);
    padding: 1rem;
  }
  .toc-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
  }
  .toc-item {
    margin-bottom: 0;
  }
  .toc-link {
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
    border-left: none;
    border-radius: var(--radius-full);
  }
  .toc-link.toc-h3 {
    padding-left: 0.8rem;
  }

  .markdown-content {
    padding: 1.8rem;
    border-radius: var(--radius-lg);
  }
  .markdown-content h1 {
    font-size: 1.5rem;
  }
  .markdown-content h2 {
    font-size: 1.15rem;
  }

  .navigation-buttons {
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .markdown-content {
    padding: 1.3rem;
  }
  .markdown-content h1 {
    font-size: 1.3rem;
  }
  .markdown-content h1 + p::first-letter {
    font-size: 2.6em;
  }
}
