/* ============================================
   Research Shared Styles — ToC, References, Comments
   ============================================ */

/* --- Table of Contents --- */
.research-toc-toggle {
  display: none;
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text, #1a1a2e);
  cursor: pointer;
  text-align: left;
  margin-bottom: 0.5rem;
}

.research-toc-nav {
  position: sticky;
  top: 80px;
  align-self: start;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  padding-right: 1rem;
}

.research-toc-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted, #64748b);
  margin-bottom: 1rem;
}

.research-toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.research-toc-list li a {
  display: block;
  color: var(--text-muted, #64748b);
  text-decoration: none;
  font-size: 0.82rem;
  padding: 0.3rem 0 0.3rem 0.75rem;
  border-left: 2px solid transparent;
  transition: all 0.2s;
  line-height: 1.4;
}

.research-toc-list li.toc-h3 a {
  padding-left: 1.5rem;
  font-size: 0.78rem;
}

.research-toc-list li a:hover,
.research-toc-list li a.active {
  color: var(--accent, #2563eb);
  border-left-color: var(--accent, #2563eb);
}

/* --- References --- */
.research-references {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border, #e2e8f0);
}

.research-references h2 {
  border-top: none !important;
  margin-top: 0 !important;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.research-references ol {
  font-size: 0.85rem;
  color: var(--text-muted, #64748b);
  padding-left: 1.5rem;
}

.research-references li {
  margin-bottom: 0.5rem;
  line-height: 1.5;
}

.research-references li a {
  color: var(--accent, #2563eb);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* --- Comments --- */
.research-comments {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 2px solid var(--border, #e2e8f0);
}

.research-comments-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  border-top: none !important;
  margin-top: 0 !important;
}

.research-comments-title .comment-count {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-muted, #64748b);
}

.comment-sort {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.sort-btn {
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 6px;
  background: var(--bg-secondary, #fff);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted, #64748b);
  cursor: pointer;
  transition: all 0.2s;
}

.sort-btn.active,
.sort-btn:hover {
  background: var(--accent, #2563eb);
  color: #fff;
  border-color: var(--accent, #2563eb);
}

.comment-form {
  margin-bottom: 2rem;
}

.comment-form-meta {
  font-size: 0.85rem;
  color: var(--text-muted, #64748b);
  margin-bottom: 0.5rem;
}

.comment-form textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  resize: vertical;
  min-height: 80px;
  background: var(--bg-secondary, #fff);
  color: var(--text, #1a1a2e);
  margin-bottom: 0.75rem;
}

.comment-form textarea:focus {
  outline: none;
  border-color: var(--accent, #2563eb);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.comment-submit-btn {
  background: var(--accent, #2563eb);
  color: #fff;
  border: none;
  padding: 0.6rem 1.5rem;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s;
}

.comment-submit-btn:hover {
  background: var(--accent-hover, #1d4ed8);
}

.comment-submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.comment-auth-prompt {
  background: var(--code-bg, #f1f5f9);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 2rem;
  font-size: 0.9rem;
  color: var(--text-muted, #64748b);
}

.comment-auth-prompt a {
  color: var(--accent, #2563eb);
  font-weight: 600;
}

.comment-empty {
  color: var(--text-muted, #64748b);
  font-size: 0.9rem;
  padding: 1rem 0;
}

.comment-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.comment-item {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border, #e2e8f0);
}

.comment-item:last-child {
  border-bottom: none;
}

.comment-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.3rem;
}

.comment-author {
  font-weight: 600;
  font-size: 0.9rem;
}

.comment-date {
  color: var(--text-muted, #64748b);
  font-size: 0.8rem;
}

.comment-text {
  font-size: 0.95rem;
  line-height: 1.6;
}

/* --- Mobile Responsiveness --- */
html, body {
  overflow-x: hidden;
}

pre, code {
  overflow-x: auto;
  max-width: 100%;
}

pre {
  word-wrap: break-word;
  white-space: pre-wrap;
  white-space: -moz-pre-wrap;
}

img {
  max-width: 100%;
  height: auto;
}

table {
  display: block;
  overflow-x: auto;
  max-width: 100%;
}

audio {
  width: 100%;
  max-width: 100%;
}

.article-content,
.article-container {
  word-break: break-word;
  overflow-wrap: break-word;
}

@media (max-width: 600px) {
  body {
    font-size: 16px;
  }

  .article-content,
  .article-container {
    padding: 0.75rem !important;
  }

  pre {
    font-size: 0.8rem;
    padding: 0.75rem !important;
  }

  h1 {
    font-size: 1.4rem !important;
  }

  h2 {
    font-size: 1.2rem !important;
  }

  h3 {
    font-size: 1.05rem !important;
  }

  .site-header {
    padding: 0.75rem 1rem;
  }

  .share-bar {
    flex-wrap: wrap;
  }

  .share-bar a,
  .share-bar button {
    min-height: 44px;
    min-width: 44px;
  }

  .audio-player {
    padding: 0.75rem !important;
  }

  .research-references ol {
    padding-left: 1rem;
  }
}

/* --- Mobile ToC --- */
@media (max-width: 900px) {
  .research-toc-toggle {
    display: block;
  }

  .research-toc-nav {
    position: relative;
    top: 0;
    max-height: none;
    display: none;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    background: var(--bg-secondary, #fff);
  }

  .research-toc-nav.open {
    display: block;
  }

  .research-toc-title {
    display: none;
  }
}

/* --- Print --- */
@media print {
  .research-toc-toggle,
  .research-toc-nav,
  .research-comments,
  .comment-form,
  .comment-sort {
    display: none !important;
  }
}
