/* ============================================
   Vector & Verse - Main Stylesheet
   Phase 1: UI Polish
   ============================================ */

/* --- Tag Bar (Simon Willison inspired) --- */
.tag-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0 1.5rem 0;
  font-family: var(--font-ui, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
}

.tag-bar-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: #555;
  margin-right: 0.25rem;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  background: #f5f5f7;
  border: 1px solid #e5e5e7;
  color: #333;
  border-radius: 20px;
  padding: 0.35em 0.85em;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s ease;
  min-height: 32px; /* Touch target */
}

.tag-pill:hover {
  background: #e8f0fe;
  border-color: #5a9570;
  color: #4a7c59;
  transform: translateY(-1px);
  text-decoration: none;
}

.tag-pill-name {
  margin-right: 0.35em;
}

.tag-pill-count {
  font-size: 0.8em;
  color: #777;
  font-weight: 400;
}

.tag-pill-more {
  background: #f0f0f2;
  color: #888;
  border: 1px solid #e0e0e2;
  cursor: default;
}

/* Tag pill as button (for client-side filtering) */
button.tag-pill {
  cursor: pointer;
  font-family: var(--font-ui, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
  outline: none;
}

.tag-pill-filter.active {
  background: #e8f0fe;
  border-color: #5a9570;
  color: #4a7c59;
}

.tag-pill-filter.active .tag-pill-count {
  color: #4a7c59;
}

/* --- Featured Topics Section --- */
.featured-topics {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  margin-top: 1.5rem;
}

.topic-section {
  background: #fafbfc;
  border-radius: 12px;
  border: 1px solid #eaedf0;
  padding: 1.25rem 1.5rem 1.5rem;
}

.topic-header {
  display: flex;
  align-items: center;
  margin-bottom: 0.5rem;
}

.topic-accent {
  display: inline-block;
  width: 4px;
  height: 20px;
  border-radius: 2px;
  background:  linear-gradient(180deg, #5a9570 60%, #7ed6df 100%);
  margin-right: 0.7rem;
}

.topic-title {
  font-size: 1rem;
  font-weight: 600;
  color: #1a1a1a;
  letter-spacing: -0.01em;
  margin: 0;
  font-family: var(--font-ui, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
}

.topic-posts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

/* --- Post Cards --- */
.post-card-modern {
  background: #fff;
  border-radius: 8px;
  border: 1px solid #eaedf0;
  padding: 1rem;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  transition: all 0.2s ease;
  position: relative;
  min-height: 100px;
}

.post-card-modern:hover {
  border-color: #c5d4f5;
  box-shadow: 0 4px 12px rgba(79, 140, 255, 0.08);
  transform: translateY(-2px);
}

.post-card-content {
  flex: 1 1 auto;
}

.post-title-modern {
  font-size: 0.95rem;
  font-weight: 600;
  color: #4a7c59;
  text-decoration: none;
  margin-bottom: 0.25rem;
  display: inline-block;
  font-family: var(--font-ui, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
  line-height: 1.4;
  transition: color 0.15s ease;
}

.post-title-modern:hover {
  color: #3d6449;
  text-decoration: none;
}

.post-meta-modern {
  font-size: 0.8rem;
  color: #666;
  margin-bottom: 0.5rem;
  font-family: var(--font-ui, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
}

.post-excerpt-modern {
  font-size: 0.8rem;
  color: #444;
  margin-top: 0.25rem;
  line-height: 1.5;
}

.read-more-arrow {
  font-size: 1.1rem;
  color: #5a9570;
  text-decoration: none;
  margin-left: 0.75rem;
  margin-top: 0.25rem;
  align-self: flex-start;
  transition: all 0.15s ease;
  opacity: 0.7;
}

.post-card-modern:hover .read-more-arrow {
  color: #4a7c59;
  transform: translateX(3px);
  opacity: 1;
}

/* --- Tag Page Tiles --- */
.tag-page-header {
  margin-bottom: 2rem;
  text-align: center;
}

.tag-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 0.5rem;
  font-family: var(--font-ui, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
}

.tag-description {
  font-size: 0.95rem;
  color: #666;
  margin: 0;
}

.tag-posts-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.5rem;
}

.tag-post-card {
  background: #fff;
  border-radius: 8px;
  border: 1px solid #eaedf0;
  padding: 1.25rem;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  transition: all 0.2s ease;
  position: relative;
  min-height: 100px;
  width: 100%;
}

.tag-post-card:hover {
  border-color: #c5d4f5;
  box-shadow: 0 4px 12px rgba(79, 140, 255, 0.08);
  transform: translateY(-2px);
}

.tag-post-card .post-card-content {
  flex: 1 1 auto;
}

.tag-post-card .post-title-modern {
  font-size: 1rem;
  font-weight: 600;
  color: #4a7c59;
  text-decoration: none;
  margin-bottom: 0.5rem;
  display: inline-block;
  font-family: var(--font-ui, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
  transition: color 0.15s ease;
  line-height: 1.4;
}

.tag-post-card .post-title-modern:hover {
  color: #3d6449;
  text-decoration: none;
}

.tag-post-card .post-meta-modern {
  font-size: 0.8rem;
  color: #666;
  margin-bottom: 0.5rem;
}

.tag-post-card .post-excerpt-modern {
  font-size: 0.85rem;
  color: #444;
  line-height: 1.55;
  margin-top: 0.25rem;
}

.tag-post-card .read-more-arrow {
  font-size: 1.1rem;
  color: #5a9570;
  text-decoration: none;
  margin-left: 0.75rem;
  margin-top: 0.25rem;
  align-self: flex-start;
  transition: all 0.15s ease;
  opacity: 0.7;
}

.tag-post-card:hover .read-more-arrow {
  color: #4a7c59;
  transform: translateX(3px);
  opacity: 1;
}

/* --- Posts Page --- */
.posts-page-header {
  margin-bottom: 2rem;
  text-align: center;
}

.posts-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 0.5rem;
  font-family: var(--font-ui, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
}

.posts-description {
  font-size: 0.95rem;
  color: #666;
  margin: 0;
}

.all-posts-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.5rem;
}

.post-tags-modern {
  margin-left: 0.75rem;
  font-size: 0.8rem;
  color: #666;
}

.post-tag-link {
  color: #5a9570;
  text-decoration: none;
  transition: color 0.15s ease;
}

.post-tag-link:hover {
  color: #4a7c59;
  text-decoration: underline;
}

/* --- Post Content Width & Reading Experience --- */
.page__content,
.post__content {
  max-width: 720px;
  margin: 0 auto;
}


.page__content p,
.post__content p {
  /* line-height: 1.25; */
  font-size: 1em;
}

.page__content strong,
.post__content strong,
.page__content b,
.post__content b {
  font-weight: 700;
}

.page__content h2,
.post__content h2 {
  margin-top: 0.2em;
  padding-bottom: 0.3em;
}

.page__content h3,
.post__content h3 {
  margin-top: 1.75em;
}

/* Lists */
.page__content ul,
.page__content ol,
.post__content ul,
.post__content ol {
  margin-bottom: 1.25em;
  padding-left: 1.5em;
}

.page__content li,
.post__content li {
  margin-bottom: 0.35em;
  line-height: 1.65;
}

/* Images in posts */
.page__content img,
.post__content img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 1.5em 0;
}

/* --- Social Share Bar --- */
.social-share-bar {
  border-radius: 8px !important;
  padding: 1rem !important;
  margin: 2.5rem 0 !important;
}

.social-share-bar a {
  opacity: 0.7;
  transition: all 0.2s ease;
}

.social-share-bar a:hover {
  opacity: 1;
  transform: translateY(-2px);
}

/* --- Page Taxonomy (Tags on posts) --- */
.page__taxonomy {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid #eaedf0;
  font-family: var(--font-ui, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
  font-size: 0.9rem;
}

.page__taxonomy-item {
  display: inline-block;
  background: #f5f5f7;
  padding: 0.25em 0.6em;
  border-radius: 4px;
  margin-right: 0.25em;
  font-size: 0.85em;
  transition: all 0.15s ease;
}

.page__taxonomy-item:hover {
  background: #e8f0fe;
  color: #4a7c59;
  text-decoration: none;
}

/* --- Responsive Design --- */
@media (max-width: 900px) {
  .topic-posts {
    grid-template-columns: 1fr 1fr;
  }

  .topic-section {
    padding: 1rem 1.25rem 1.25rem;
  }
}

@media (max-width: 600px) {
  /* Touch-friendly spacing */
  .topic-section {
    padding: 1rem;
    border-radius: 8px;
  }

  .topic-title {
    font-size: 0.95rem;
  }

  .topic-posts {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  /* Tag bar mobile */
  .tag-bar {
    gap: 0.5rem;
    margin: 0.75rem 0 1.25rem 0;
  }

  .tag-bar-label {
    font-size: 0.85rem;
  }

  .tag-pill {
    font-size: 0.85rem;
    padding: 0.4em 0.75em;
    min-height: 36px; /* Larger touch target on mobile */
  }

  /* Post cards mobile */
  .post-card-modern {
    padding: 0.875rem;
    min-height: 90px;
  }

  .post-title-modern {
    font-size: 0.9rem;
  }

  .post-excerpt-modern {
    font-size: 0.78rem;
  }

  /* Tag page mobile */
  .tag-post-card {
    padding: 1rem;
    min-height: 90px;
  }

  .tag-title {
    font-size: 1.25rem;
  }

  .tag-description {
    font-size: 0.85rem;
  }

  .tag-posts-grid {
    gap: 0.75rem;
    margin-top: 1rem;
  }

  .tag-page-header {
    margin-bottom: 1.25rem;
  }

  /* Posts page mobile */
  .posts-title {
    font-size: 1.25rem;
  }

  .posts-description {
    font-size: 0.85rem;
  }

  .all-posts-grid {
    gap: 0.75rem;
    margin-top: 1rem;
  }

  .posts-page-header {
    margin-bottom: 1.25rem;
  }

  .post-tags-modern {
    margin-left: 0.5rem;
    font-size: 0.75rem;
  }

  /* Content area mobile */
  .page__content,
  .post__content {
    padding: 0 0.5rem;
  }
}

/* Ensure touch targets are accessible */
@media (hover: none) and (pointer: coarse) {
  .tag-pill,
  .post-title-modern,
  .read-more-arrow,
  .post-tag-link,
  .page__taxonomy-item {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
}

/* ============================================
   Sidenotes (Tufte-style margin notes)
   ============================================ */

/* Enable sidenotes layout - shift content left to make room for margin */
.page__content.sidenotes-enabled,
.post__content.sidenotes-enabled {
  max-width: 720px;
  margin-left: calc(50% - 360px - 150px);
  margin-right: auto;
  position: relative;
  counter-reset: sidenote-counter;
}

/* Sidenote reference number in text */
.sidenote-ref {
  counter-increment: sidenote-counter;
  font-size: 0.75em;
  vertical-align: super;
  line-height: 0;
  color: var(--link-color, #4a7c59);
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  padding: 0 0.1em;
}

.sidenote-ref::after {
  content: "[" counter(sidenote-counter) "]";
}

.sidenote-ref:hover {
  color: var(--link-hover, #3d6449);
  text-decoration: underline;
}

/* The sidenote itself - floated to right margin */
.sidenote {
  float: right;
  clear: right;
  width: 280px;
  margin-right: -320px;
  margin-bottom: 1rem;
  margin-top: 0.25rem;
  font-family: warnock-pro, Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif;
  font-size: 0.7rem;
  line-height: 1.5;
  color: var(--text-muted, #666);
  position: relative;
}

/* Sidenote number prefix - uses same counter as ref (no increment here) */
.sidenote::before {
  content: counter(sidenote-counter) ". ";
  font-weight: 600;
  color: var(--link-color, #4a7c59);
  font-size: 0.9em;
}

/* Sidenote highlight on hover */
.sidenote.sidenote-highlight {
  background: rgba(0, 0, 0, 0.04);
  border-radius: 4px;
  padding: 0.5rem;
  margin-left: -0.5rem;
  transition: background 0.15s ease;
}

/* Links in sidenotes */
.sidenote a {
  color: #4a7c59;
  text-decoration: none;
}

.sidenote a:hover {
  text-decoration: underline;
}

/* Medium screens - narrower sidenote column */
@media (max-width: 1300px) {
  .page__content.sidenotes-enabled,
  .post__content.sidenotes-enabled {
    max-width: 680px;
    margin-left: calc(50% - 340px - 120px);
  }

  .sidenote {
    width: 220px;
    margin-right: -260px;
    font-size: 0.8rem;
  }
}

/* Mobile/tablet: Convert sidenotes to inline expandable notes */
@media (max-width: 1100px) {
  .page__content.sidenotes-enabled,
  .post__content.sidenotes-enabled {
    max-width: 720px;
    margin: 0 auto;
  }

  /* Hide sidenotes by default on mobile */
  .sidenote {
    display: none;
    float: none;
    width: auto;
    margin-right: 0;
    font-size: 0.9rem;
    background: var(--topic-background, #fafbfc);
    border-left: 3px solid var(--link-color, #4a7c59);
    padding: 0.75rem 1rem;
    margin: 0.75rem 0;
    border-radius: 0 6px 6px 0;
  }

  .sidenote.sidenote-visible {
    display: block;
  }

  /* Make ref look more clickable on mobile */
  .sidenote-ref {
    background: var(--tag-background, #f5f5f7);
    padding: 0.1em 0.4em;
    border-radius: 3px;
    font-size: 0.8em;
  }

  .sidenote-ref:hover,
  .sidenote-ref.active {
    background: var(--tag-hover-bg, #e8f0fe);
  }
}

@media (max-width: 600px) {
  .sidenote {
    font-size: 0.85rem;
    padding: 0.6rem 0.8rem;
  }
}

/* Auto-generated footnotes section */
.footnotes-section {
  margin-top: 3rem;
}

.footnotes-section hr {
  border: none;
  border-top: 1px solid var(--border-color, #eaedf0);
  margin-bottom: 1.5rem;
}

.footnotes-section h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.footnotes-list {
  font-family: warnock-pro, Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif;
  font-size: 0.7rem;
  line-height: 1.5;
  color: var(--text-muted, #666);
  padding-left: 1.5rem;
}

.footnotes-list li {
  margin-bottom: 0.75rem;
  padding-left: 0.25rem;
}

.footnotes-list li::marker {
  color: var(--link-color, #4a7c59);
  font-weight: 600;
}

/* ============================================
   Left TOC Navigation
   ============================================ */

.toc-left {
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  z-index: 100;
  display: flex;
  align-items: stretch;
}

/* Thin indicator strip - always visible */
.toc-left-indicator {
  width: 4px;
  background: linear-gradient(180deg, var(--link-color, #4a7c59) 0%, #7ed6df 100%);
  opacity: 0.3;
  transition: opacity 0.2s ease;
}

.toc-left:hover .toc-left-indicator {
  opacity: 1;
}

/* Content panel - hidden by default */
.toc-left-content {
  width: 0;
  overflow: hidden;
  background: var(--background-color, #fff);
  border-right: 1px solid var(--border-color, #eaedf0);
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.08);
  transition: width 0.25s ease;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.toc-left:hover .toc-left-content {
  width: 300px;
  padding: 2rem 1.5rem;
}

/* Title section */
.toc-left-title {
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color, #eaedf0);
}

.toc-title-text {
  display: block;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--heading-color, #1a1a1a);
  text-transform: uppercase;
  letter-spacing: 0.01em;
  line-height: 1.3;
}

.toc-reading-time {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted, #666);
  margin-top: 0.5rem;
}

/* TOC list - continuous vertical line */
.toc-left-list {
  list-style: none;
  padding: 0;
  margin: 0;
  position: relative;
  padding-left: 1.25rem;
}

/* Continuous vertical line */
.toc-left-list::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--border-color, #e0e0e0);
  border-radius: 2px;
}

.toc-left-item {
  position: relative;
  margin-bottom: 0.25rem;
}

/* Active indicator - thicker bar overlaying the line */
.toc-left-item::before {
  content: '';
  position: absolute;
  left: -1.25rem;
  top: 0.25rem;
  bottom: 0.25rem;
  width: 3px;
  background: transparent;
  border-radius: 2px;
  transition: background 0.15s ease;
}

.toc-left-item.active::before {
  background: var(--link-color, #4a7c59);
}

.toc-left-link {
  display: block;
  font-size: 0.8rem;
  color: #5a9aa8;
  text-decoration: none;
  padding: 0.4rem 0;
  line-height: 1.45;
  transition: color 0.15s ease;
}

.toc-left-link:hover {
  color: #3d7a87;
}

.toc-left-item.active .toc-left-link {
  color: var(--heading-color, #1a1a1a);
  font-weight: 500;
}

/* Hide on smaller screens */
@media (max-width: 1300px) {
  .toc-left {
    display: none;
  }
}
