/* ==========================================================================
   cognitive.css · 认知可访问性
   topfootballers.com · B01-9/68
   阅读进度条/预计阅读时间/目录导航/回到顶部/章节锚点/渐进式披露
   ========================================================================== */

/* ==========================================================================
   1. 阅读进度条
   ========================================================================== */

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: transparent;
  z-index: var(--z-fixed);
  pointer-events: none;
}

.reading-progress-bar {
  height: 100%;
  background: linear-gradient(90deg,
    var(--color-primary-500),
    var(--color-accent));
  width: 0;
  transition: width 100ms linear;
}

@media (max-width: 768px) {
  .reading-progress {
    height: 2px;
  }
}

/* ==========================================================================
   2. 预计阅读时间
   ========================================================================== */

.reading-time {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  background: var(--color-surface);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  font-weight: var(--font-medium);
}

.reading-time::before {
  content: '📖';
}

/* ==========================================================================
   3. 目录导航（桌面端 sticky，移动端折叠）
   ========================================================================== */

.toc-desktop {
  position: sticky;
  top: 88px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  padding: var(--space-4);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  font-size: var(--text-sm);
  width: 240px;
}

.toc-desktop h4 {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

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

.toc-desktop li {
  margin-bottom: var(--space-1);
}

.toc-desktop a {
  display: block;
  padding: var(--space-2) var(--space-3);
  color: var(--color-text-secondary);
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  transition: all var(--duration-fast) var(--ease-out);
}

.toc-desktop a:hover {
  background: var(--color-primary-50);
  color: var(--color-primary-600);
  border-left-color: var(--color-primary-500);
}

.toc-desktop a.is-active {
  background: var(--color-primary-50);
  color: var(--color-primary-600);
  border-left-color: var(--color-primary-500);
  font-weight: var(--font-semibold);
}

/* 移动端折叠目录 */
.toc-mobile {
  margin: var(--space-4) 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.toc-mobile summary {
  padding: var(--space-3) var(--space-4);
  font-weight: var(--font-semibold);
  cursor: pointer;
  list-style: none;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toc-mobile summary::-webkit-details-marker { display: none; }

.toc-mobile summary::after {
  content: '▾';
  transition: transform var(--duration-fast) var(--ease-out);
}

.toc-mobile[open] summary::after {
  transform: rotate(180deg);
}

.toc-mobile ul {
  list-style: none;
  padding: 0 var(--space-4) var(--space-4);
  margin: 0;
}

.toc-mobile li {
  margin-bottom: var(--space-1);
}

.toc-mobile a {
  display: block;
  padding: var(--space-2) 0;
  color: var(--color-text-secondary);
  min-height: 40px;
}

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

@media (max-width: 768px) {
  .toc-desktop { display: none; }
}

/* ==========================================================================
   4. 回到顶部按钮
   ========================================================================== */

.back-to-top {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--color-primary-500);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xl);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: all var(--duration-normal) var(--ease-out);
  z-index: var(--z-fixed);
}

.back-to-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.back-to-top:hover {
  background: var(--color-primary-600);
  transform: translateY(-2px);
}

.back-to-top::before {
  content: '↑';
  font-weight: var(--font-bold);
}

@media (max-width: 768px) {
  .back-to-top {
    bottom: var(--space-4);
    right: var(--space-4);
    width: 44px;
    height: 44px;
  }
}

/* ==========================================================================
   5. 章节锚点（H2/H3 旁 # 图标）
   ========================================================================== */

.anchor-heading {
  position: relative;
}

.anchor-heading .anchor-link {
  position: absolute;
  left: -24px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-tertiary);
  opacity: 0;
  text-decoration: none;
  font-size: var(--text-base);
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  transition: all var(--duration-fast) var(--ease-out);
}

.anchor-heading:hover .anchor-link {
  opacity: 1;
}

.anchor-heading .anchor-link:hover {
  background: var(--color-primary-50);
  color: var(--color-primary-500);
}

.anchor-heading .anchor-link::before {
  content: '#';
}

@media (max-width: 768px) {
  .anchor-heading .anchor-link {
    display: none;
  }
}

/* ==========================================================================
   6. 渐进式披露（details/summary 折叠）
   ========================================================================== */

.progressive-disclosure {
  margin: var(--rhythm-normal) 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.progressive-disclosure > p {
  padding: var(--space-4) var(--space-5);
  margin: 0;
  font-size: var(--text-base);
  color: var(--color-text-primary);
  font-weight: var(--font-medium);
}

.progressive-disclosure details {
  border-top: 1px solid var(--color-border);
}

.progressive-disclosure summary {
  padding: var(--space-3) var(--space-5);
  cursor: pointer;
  list-style: none;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--color-primary-600);
  font-weight: var(--font-medium);
  font-size: var(--text-sm);
}

.progressive-disclosure summary::-webkit-details-marker { display: none; }

.progressive-disclosure summary::after {
  content: '▸';
  transition: transform var(--duration-fast) var(--ease-out);
}

.progressive-disclosure details[open] summary::after {
  transform: rotate(90deg);
}

.progressive-disclosure details > p,
.progressive-disclosure details > div {
  padding: 0 var(--space-5) var(--space-4);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  margin: 0;
}

/* ==========================================================================
   7. 选项分组（超过 3 项时折叠/分组）
   ========================================================================== */

.options-group {
  margin: var(--rhythm-normal) 0;
}

.options-group summary {
  cursor: pointer;
  list-style: none;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-weight: var(--font-semibold);
  color: var(--color-text-primary);
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.options-group summary::-webkit-details-marker { display: none; }

.options-group summary::after {
  content: '+';
  font-size: var(--text-xl);
  color: var(--color-primary-500);
  font-weight: var(--font-bold);
  transition: transform var(--duration-normal) var(--ease-out);
}

.options-group[open] summary::after {
  transform: rotate(45deg);
}

.options-group ul {
  list-style: none;
  padding: var(--space-3) 0 0;
  margin: 0;
}

.options-group li {
  margin-bottom: var(--space-2);
}

.options-group li a {
  display: block;
  padding: var(--space-3) var(--space-4);
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  color: var(--color-text-primary);
  border-left: 3px solid var(--color-primary-200);
}

.options-group li a:hover {
  background: var(--color-primary-50);
  border-left-color: var(--color-primary-500);
}

/* ==========================================================================
   8. 认知负荷辅助（阅读宽度限制）
   ========================================================================== */

.reading-content {
  max-width: var(--reading-max-width);
  margin: 0 auto;
  font-size: var(--reading-font-size);
  line-height: var(--reading-line-height);
}

.reading-content p {
  margin-bottom: var(--reading-paragraph-gap);
}

/* ==========================================================================
   9. 移动端
   ========================================================================== */

@media (max-width: 768px) {
  .reading-time {
    font-size: var(--text-xs);
  }

  .reading-content {
    font-size: var(--text-base);
  }
}
