/* ==========================================================================
   xie'blog Advanced Reading Experience & Chinese Typography
   ========================================================================== */

/* 1. Fixed Reading Progress Bar */
#reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0%;
  background: var(--color-text);
  z-index: 99999;
  transition: width 80ms ease-out;
  opacity: 0.85;
}

/* 2. Reading Layout Structure (Desktop Multi-column) */
.reading-layout {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: var(--space-xl, 3rem);
  width: 100%;
  max-width: 1300px;
  margin: 0 auto;
}

.reading-main {
  flex: 1;
  max-width: 44rem;
  width: 100%;
}

/* 3. Floating Sticky TOC (Desktop) */
.reading-aside {
  position: sticky;
  top: 6rem;
  width: 220px;
  max-height: calc(100vh - 8rem);
  overflow-y: auto;
  font-family: var(--mono-font);
  font-size: 0.8rem;
  display: none;
  padding-left: 1rem;
  border-left: 1px dashed rgba(128, 128, 128, 0.25);
  scrollbar-width: thin;
}

@media (min-width: 1100px) {
  .reading-aside {
    display: block;
  }
}

.toc-heading {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  opacity: 0.7;
  margin-bottom: 0.75rem;
  text-transform: uppercase;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toc-item--depth-3 {
  padding-left: 0.75rem;
  opacity: 0.85;
  font-size: 0.75rem;
}

.toc-link {
  color: var(--color-text);
  opacity: 0.65;
  text-decoration: none;
  display: block;
  line-height: 1.4;
  transition: opacity 0.2s, transform 0.2s;
  position: relative;
  font-family: var(--serif-font) !important;
  font-style: italic;
  font-size: 0.88rem;
  text-transform: none !important;
}

.toc-link:hover {
  opacity: 1;
  text-decoration: underline;
  text-decoration-style: dotted;
}

.toc-link.active {
  opacity: 1;
  font-weight: bold;
}

.toc-link.active::before {
  content: '✶ ';
  color: var(--color-text);
}

/* 4. Enhanced Chinese Typography in .letter-body */
.letter-body {
  font-family: var(--serif-font);
  font-size: 17.5px;
  line-height: 1.88;
  color: var(--color-text);
  word-break: break-word;
}

.letter-body p {
  margin-bottom: 1.35em;
  text-align: justify;
  text-justify: inter-ideograph;
}

.letter-body h1, 
.letter-body h2, 
.letter-body h3, 
.letter-body h4 {
  font-family: var(--serif-font);
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.4;
  scroll-margin-top: 5rem;
}

.letter-body h2 {
  font-size: 1.5rem;
  margin-top: 2.6em;
  margin-bottom: 0.8em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid rgba(128, 128, 128, 0.15);
}

.letter-body h3 {
  font-size: 1.25rem;
  margin-top: 2em;
  margin-bottom: 0.6em;
}

.letter-body strong, 
.letter-body b {
  font-weight: 700;
}

.letter-body blockquote {
  margin: 1.8em 0;
  padding: 0.6em 1.2em;
  border-left: 2px solid var(--color-text);
  opacity: 0.9;
  font-style: italic;
  background: rgba(128, 128, 128, 0.04);
}

.letter-body ul, 
.letter-body ol {
  margin: 1.2em 0 1.5em 1.5em;
  padding: 0;
}

.letter-body li {
  margin-bottom: 0.5em;
  line-height: 1.8;
}

.letter-body hr {
  border: 0;
  border-top: 1px dashed rgba(128, 128, 128, 0.3);
  margin: 3em 0;
}

/* 5. Terminal-Styled Code Blocks */
.code-block-wrapper {
  margin: 1.8em 0;
  border: 1px solid rgba(128, 128, 128, 0.25);
  background: rgba(0, 0, 0, 0.03);
}

:root.dark .code-block-wrapper,
[data-theme="dark"] .code-block-wrapper {
  background: rgba(255, 255, 255, 0.03);
}

.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: rgba(128, 128, 128, 0.08);
  border-bottom: 1px solid rgba(128, 128, 128, 0.15);
  font-family: var(--mono-font);
  font-size: 0.75rem;
}

.code-lang {
  letter-spacing: 0.05em;
  opacity: 0.8;
}

.code-copy-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--color-text);
  font-family: var(--mono-font);
  font-size: 0.75rem;
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 0.2s, color 0.2s;
}

.code-copy-btn:hover {
  opacity: 1;
  text-decoration: underline;
  text-decoration-style: dotted;
}

.letter-body pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: var(--mono-font);
  font-size: 0.88rem;
  line-height: 1.6;
}

.letter-body code:not(pre code) {
  font-family: var(--mono-font);
  font-size: 0.88em;
  padding: 2px 6px;
  background: rgba(128, 128, 128, 0.12);
  border: 1px solid rgba(128, 128, 128, 0.15);
  vertical-align: baseline;
}

/* 6. Post Epilogue & Next/Prev Navigation */
.post-epilogue {
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px dashed rgba(128, 128, 128, 0.3);
}

.author-signature {
  font-family: var(--serif-font);
  font-style: italic;
  font-size: 1rem;
  opacity: 0.85;
  margin-bottom: 2.5rem;
  text-align: right;
}

.post-nav-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 2rem;
}

@media (min-width: 640px) {
  .post-nav-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.post-nav-card {
  display: block;
  padding: 14px 16px;
  border: 1px solid rgba(128, 128, 128, 0.25);
  text-decoration: none;
  color: var(--color-text);
  transition: border-color 0.2s, background 0.2s;
}

.post-nav-card:hover {
  border-color: var(--color-text);
  background: rgba(128, 128, 128, 0.04);
}

.post-nav-dir {
  font-family: var(--mono-font);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  opacity: 0.65;
  margin-bottom: 4px;
}

.post-nav-title {
  font-family: var(--serif-font);
  font-style: italic;
  font-size: 0.95rem;
  line-height: 1.4;
}

.post-footer-actions {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono-font);
  font-size: var(--text-ui);
  padding-top: 1rem;
}

/* 7. Mobile Floating TOC Pill & Drawer */
.mobile-toc-toggle-btn {
  position: fixed;
  bottom: 2rem;
  right: 1.5rem;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-family: var(--mono-font);
  font-size: 0.78rem;
  background: var(--color-bg, #fff);
  color: var(--color-text);
  border: 1px solid var(--color-text);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  cursor: pointer;
}

@media (min-width: 1100px) {
  .mobile-toc-toggle-btn {
    display: none;
  }
}

.mobile-toc-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 70vh;
  background: var(--color-bg, #fff);
  border-top: 1px solid var(--color-text);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  padding: 1.5rem;
  overflow-y: auto;
}

.mobile-toc-drawer.open {
  transform: translateY(0);
}

.mobile-toc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--mono-font);
  font-size: 0.85rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px dashed rgba(128, 128, 128, 0.3);
}

.mobile-toc-close-btn {
  background: none;
  border: none;
  font-family: var(--mono-font);
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--color-text);
}
