/* ============================================================
   cognitive.css — Cognitive Accessibility
   Load order: 9
   ============================================================ */

/* ────────────────────────────────────────
   READING PROGRESS BAR
   ──────────────────────────────────────── */

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: var(--z-fixed);
  background: transparent;
  pointer-events: none;
}
.reading-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--color-primary-500), var(--color-accent-500));
  transition: width 100ms linear;
}

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

/* ────────────────────────────────────────
   ESTIMATED READING TIME
   ──────────────────────────────────────── */

.reading-time {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  font-weight: var(--font-medium);
  letter-spacing: var(--tracking-wide);
}
.reading-time::before {
  content: '📖';
  font-size: 12px;
}

/* ────────────────────────────────────────
   TABLE OF CONTENTS (Article)
   ──────────────────────────────────────── */

.toc {
  padding: var(--space-5);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  margin: var(--rhythm-loose) 0;
}
.toc h2, .toc-heading {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  margin-top: 0;
  margin-bottom: var(--space-3);
  color: var(--color-text-primary);
  letter-spacing: 0;
  text-transform: none;
}
.toc ol {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  counter-reset: toc-counter;
  padding-left: 0;
}
.toc li {
  counter-increment: toc-counter;
  position: relative;
  padding-left: var(--space-6);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}
.toc li::before {
  content: counter(toc-counter) '.';
  position: absolute;
  left: 0;
  color: var(--color-text-tertiary);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  top: 2px;
}
.toc a {
  color: var(--color-text-secondary);
  text-decoration: none;
  display: block;
  padding: var(--space-1) 0;
}
.toc a:hover { color: var(--color-primary-600); }
.toc a.toc-active {
  color: var(--color-primary-700);
  font-weight: var(--font-semibold);
}

/* Sticky TOC (desktop) */
@media (min-width: 1024px) {
  .toc-sticky {
    position: sticky;
    top: calc(var(--header-height) + var(--space-4));
    max-height: calc(100vh - var(--header-height) - var(--space-8));
    overflow-y: auto;
    padding-right: var(--space-2);
  }
}

/* Mobile TOC — collapsible */
@media (max-width: 1023px) {
  .toc {
    margin: var(--rhythm-normal) 0;
  }
  .toc ol {
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--duration-slow) var(--ease-out);
  }
  .toc[open] ol,
  .toc.toc-open ol {
    max-height: 800px;
  }
}

/* ────────────────────────────────────────
   BACK TO TOP BUTTON
   ──────────────────────────────────────── */

.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-600);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  z-index: var(--z-fixed);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all var(--duration-normal) var(--ease-out);
  font-size: var(--text-lg);
  text-decoration: none;
  border: none;
  cursor: pointer;
}
.back-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.back-to-top:hover {
  background: var(--color-primary-700);
  transform: translateY(-2px);
  color: white;
}

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

/* ────────────────────────────────────────
   SECTION ANCHORS
   ──────────────────────────────────────── */

.section-anchor {
  position: relative;
}
.section-anchor .anchor-link {
  position: absolute;
  left: -28px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-tertiary);
  text-decoration: none;
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease-out);
  font-size: var(--text-base);
  border-radius: var(--radius-sm);
}
.section-anchor:hover .anchor-link,
.anchor-link:focus {
  opacity: 1;
}
.anchor-link:hover {
  color: var(--color-primary-600);
  background: var(--color-surface);
}

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

/* ────────────────────────────────────────
   PROGRESSIVE DISCLOSURE
   ──────────────────────────────────────── */

.progressive-disclosure {
  margin: var(--rhythm-normal) 0;
}
.progressive-disclosure > details {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-top: var(--space-3);
}
.progressive-disclosure > details > summary {
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--color-primary-700);
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 32px;
}
.progressive-disclosure > details > summary::-webkit-details-marker { display: none; }
.progressive-disclosure > details > summary::before {
  content: '▸';
  transition: transform var(--duration-fast) var(--ease-out);
}
.progressive-disclosure > details[open] > summary::before {
  transform: rotate(90deg);
}
.progressive-disclosure > details[open] > summary {
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

/* Nested disclosure */
.progressive-disclosure details details {
  margin-left: var(--space-4);
  background: var(--color-bg);
}

/* ────────────────────────────────────────
   COGNITIVE LOAD — SINGLE FOCUS
   ──────────────────────────────────────── */

.focus-block {
  display: flex;
  flex-direction: column;
  gap: var(--rhythm-normal);
  padding: var(--rhythm-loose) 0;
}

.focus-block > .primary-action {
  align-self: flex-start;
}

/* ────────────────────────────────────────
   CHUNKED LIST (Reduce options)
   ──────────────────────────────────────── */

.chunked-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  margin: var(--rhythm-normal) 0;
}
@media (min-width: 480px) {
  .chunked-options.chunked-3 {
    grid-template-columns: repeat(3, 1fr);
  }
  .chunked-options.chunked-2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ────────────────────────────────────────
   READING WIDTH CONSTRAINT
   ──────────────────────────────────────── */

.reading-width {
  max-width: var(--reading-max-width);
  margin-inline: auto;
}

/* For sidebar layouts: keep the content column readable even when narrow */
@media (min-width: 1024px) {
  .reading-width-sidebar {
    max-width: 720px;
  }
}

/* ────────────────────────────────────────
   ADJUSTMENTS FOR COGNITIVE CLARITY
   ──────────────────────────────────────── */

.simple-list {
  padding-left: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.simple-list li {
  position: relative;
  padding-left: var(--space-6);
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
  color: var(--color-text-secondary);
}
.simple-list li::before {
  content: '';
  position: absolute;
  left: var(--space-2);
  top: 0.7em;
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-primary-400);
}

/* ────────────────────────────────────────
   KEY TAKEAWAY BOX
   ──────────────────────────────────────── */

.key-takeaway {
  padding: var(--space-5);
  background: linear-gradient(135deg,
    hsl(152 46% 97%) 0%,
    hsl(14 76% 97%) 100%);
  border: 1px solid var(--color-primary-200);
  border-radius: var(--radius-lg);
  margin: var(--rhythm-loose) 0;
  font-size: var(--text-base);
  color: var(--color-text-primary);
  line-height: var(--leading-relaxed);
  position: relative;
}
.key-takeaway::before {
  content: 'KEY POINT';
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  letter-spacing: var(--tracking-wider);
  color: var(--color-primary-700);
  margin-bottom: var(--space-2);
}
[data-theme="night"] .key-takeaway {
  background: linear-gradient(135deg,
    hsl(152 30% 18%) 0%,
    hsl(14 30% 18%) 100%);
  border-color: hsl(152 30% 30%);
}
[data-theme="night"] .key-takeaway::before {
  color: hsl(152 60% 70%);
}

/* ────────────────────────────────────────
   NO-INTERRUPTION RULE
   (no autoplay, no popup, no scroll hijack)
   ──────────────────────────────────────── */

* {
  /* prevent auto-scroll behaviors from being applied to animated elements */
  animation-fill-mode: both;
}

@media (prefers-reduced-motion: reduce) {
  .reading-progress-fill { transition: none; }
  .back-to-top { transition: none; }
  .toc ol { transition: none; }
  .progressive-disclosure > details > summary::before { transition: none; }
}

/* ────────────────────────────────────────
   MOBILE: SIMPLIFY
   ──────────────────────────────────────── */

@media (max-width: 768px) {
  .toc { padding: var(--space-4); }
  .toc li { font-size: var(--text-sm); }
  .key-takeaway { padding: var(--space-4); }
  .progressive-disclosure > details { padding: var(--space-3); }
  .simple-list li { padding-left: var(--space-5); }
  .simple-list li::before { left: var(--space-1); }
}