/**
 * content-progressive.css
 *
 * F-079: Progressive Content Reveal ("Story Mode")
 * Vertical progress sidebar, fade-in reveal, milestone toasts,
 * KO floating panel, and soft pause at quick-checks.
 */

/* ===== Chapter Wrappers ===== */
.content-chapter {
  margin-bottom: var(--space-md, 16px);
}

/* ===== Reveal Animation ===== */
/* Pending: collapsed, invisible, takes no space */
.content-reveal[data-reveal-state="pending"] {
  max-height: 0;
  overflow: hidden;
  margin: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}

/* Visible: full height, fade+slide animation plays once */
.content-reveal[data-reveal-state="visible"] {
  max-height: none;
  overflow: visible;
  pointer-events: auto;
  animation: contentRevealIn 0.6s ease both;
}

@keyframes contentRevealIn {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Soft pause after quick-check: next section slightly dimmed until scrolled to */
.content-reveal--pause[data-reveal-state="visible"] {
  animation: contentRevealDimmed 0.5s ease both;
}

@keyframes contentRevealDimmed {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 0.35;
    transform: translateY(0);
  }
}

/* Un-pause: full opacity once user scrolls to it */
.content-reveal--unpaused[data-reveal-state="visible"] {
  animation: contentRevealIn 0.4s ease both !important;
}


/* ======================================================
   VERTICAL PROGRESS SIDEBAR
   Fixed on right side, milestone-timeline style
   ====================================================== */

.progress-sidebar {
  position: fixed;
  /* Sit just outside the 800px content area's right edge.
     On narrow screens (<~900px), the media queries below take over. */
  left: calc(50% + 408px);
  right: auto;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  z-index: 40;
  opacity: 0.4;
  transition: opacity 0.8s ease;
  pointer-events: none;
}

/* Highlight pulse: opacity jumps to 0.9 when a checkpoint is reached */
.progress-sidebar--highlight {
  opacity: 0.9;
  transition: opacity 0.3s ease;
}

/* ===== Progress Node (dot + label) ===== */
.progress-node {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 1px 0;
  pointer-events: auto;
  cursor: default;
}

.progress-dot {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.progress-dot svg {
  display: block;
}

/* ===== Node Labels ===== */
.progress-label {
  font-size: 0.6rem;
  font-weight: 500;
  color: var(--text-muted, #94a3b8);
  white-space: nowrap;
  opacity: 0.7;
  transition: opacity 0.4s ease, color 0.4s ease;
  letter-spacing: 0.02em;
}

/* Flash label on milestone hit — used on tablet/mobile where labels are normally hidden */
.progress-label--flash {
  display: inline !important;
  animation: labelFlash 2.5s ease forwards;
}

@keyframes labelFlash {
  0% { opacity: 0; transform: translateX(4px); }
  15% { opacity: 1; transform: translateX(0); }
  70% { opacity: 1; }
  100% { opacity: 0; display: none; }
}

.progress-node[data-progress="active"] .progress-label {
  color: var(--accent, #2563EB);
  opacity: 1;
  font-weight: 600;
}

.progress-node[data-progress="complete"] .progress-label {
  color: #22c55e;
  opacity: 1;
  font-weight: 600;
}

/* ===== Connector Line Between Nodes ===== */
.progress-connector {
  width: 2px;
  height: 16px;
  margin-left: 7px; /* center under 16px dot */
  background: var(--border-subtle, rgba(148, 163, 184, 0.25));
  transition: background 0.6s ease;
  flex-shrink: 0;
}

.progress-connector[data-filled="true"] {
  background: #22c55e;
}

.progress-connector[data-active="true"] {
  background: var(--accent, #2563EB);
}

/* ===== SVG Icon States ===== */

/* Pending: empty circle outline */
.progress-dot--pending circle {
  fill: none;
  stroke: var(--text-muted, #94a3b8);
  stroke-width: 2;
  opacity: 0.5;
}

/* Active: pulsing accent ring */
.progress-dot--active circle {
  fill: none;
  stroke: var(--accent, #2563EB);
  stroke-width: 2.5;
  animation: sidebarPulse 1.5s ease-in-out infinite;
}

/* Complete: green filled with white tick */
.progress-dot--complete circle {
  fill: #22c55e;
  stroke: none;
}

.progress-dot--complete path {
  fill: none;
  stroke: white;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Complete node entrance animation */
.progress-dot--complete {
  animation: checkpointPop 0.4s ease;
}

@keyframes checkpointPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.4); }
  100% { transform: scale(1); }
}

@keyframes sidebarPulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}


/* ===== Milestone Toast ===== */
.content-milestone {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: var(--bg-secondary, rgba(255, 255, 255, 0.95));
  border: 1px solid var(--accent, #2563EB);
  border-radius: var(--radius-lg, 12px);
  padding: 8px 18px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary, #1e293b);
  z-index: 200;
  opacity: 0;
  animation: milestoneIn 0.4s ease forwards;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  white-space: nowrap;
  pointer-events: none;
}

.content-milestone--out {
  animation: milestoneOut 0.4s ease forwards !important;
}

@keyframes milestoneIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes milestoneOut {
  from { opacity: 1; transform: translateX(-50%) translateY(0); }
  to { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}


/* ===== KO Floating Reference Button ===== */
.ko-reference-btn {
  position: fixed;
  bottom: 80px;
  /* Sit just outside the content area's right edge, aligned with sidebar */
  left: calc(50% + 408px);
  right: auto;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #22c55e;
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.4);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: koEnter 0.5s ease 0.8s both;
}

.ko-reference-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(34, 197, 94, 0.5);
}

@keyframes koEnter {
  from { opacity: 0; transform: scale(0.5); }
  to { opacity: 1; transform: scale(1); }
}

/* ===== KO Slide-Up Panel ===== */
.ko-reference-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.ko-reference-backdrop--visible {
  opacity: 1;
  pointer-events: auto;
}

.ko-reference-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 60vh;
  background: var(--bg-primary, #ffffff);
  border-top-left-radius: var(--radius-xl, 16px);
  border-top-right-radius: var(--radius-xl, 16px);
  z-index: 100;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
}

.ko-reference-panel--visible {
  transform: translateY(0);
}

.ko-reference-panel-header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-primary, #ffffff);
  border-bottom: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.08));
  z-index: 1;
}

.ko-reference-panel-header h4 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-primary, #1e293b);
}

.ko-reference-panel-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted, #64748b);
  padding: 4px 8px;
  border-radius: var(--radius-sm, 6px);
}

.ko-reference-panel-close:hover {
  background: var(--bg-secondary, rgba(0, 0, 0, 0.05));
}

.ko-reference-panel-content {
  padding: 16px;
}


/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  .content-reveal[data-reveal-state="pending"] {
    max-height: none !important;
    overflow: visible !important;
    opacity: 1 !important;
    margin: unset !important;
    padding: unset !important;
    pointer-events: auto !important;
  }

  .content-reveal[data-reveal-state="visible"] {
    animation: none !important;
  }

  .content-reveal--pause[data-reveal-state="visible"] {
    animation: none !important;
    opacity: 1 !important;
  }

  .progress-sidebar {
    opacity: 0.9 !important;
  }

  .progress-dot--active circle {
    animation: none !important;
  }

  .progress-dot--complete {
    animation: none !important;
  }

  .content-milestone {
    animation: none !important;
    opacity: 1 !important;
    transform: translateX(-50%) translateY(0) !important;
  }

  .ko-reference-btn {
    animation: none !important;
    opacity: 1 !important;
  }

  .ko-reference-panel,
  .ko-reference-backdrop {
    transition: none !important;
  }
}


/* ===== Responsive: Hide sidebar on narrow screens ===== */
@media (max-width: 1100px) {
  .progress-sidebar {
    left: auto;
    right: 8px;
  }

  .ko-reference-btn {
    left: auto;
    right: 16px;
  }

  .progress-label {
    display: none;
  }

  .progress-dot {
    width: 12px;
    height: 12px;
  }

  .progress-connector {
    height: 12px;
    margin-left: 5px;
  }
}

@media (max-width: 768px) {
  /* Compact dot-only sidebar on mobile — no labels, tiny dots, flush right */
  .progress-sidebar {
    left: auto;
    right: 4px;
    gap: 0;
  }

  .progress-label {
    display: none;
  }

  .progress-dot {
    width: 10px;
    height: 10px;
  }

  .progress-node {
    gap: 0;
    padding: 0;
  }

  .progress-connector {
    height: 10px;
    margin-left: 4px;
    width: 2px;
  }

  .ko-reference-panel {
    max-height: 70vh;
  }
}

@media (max-width: 480px) {
  .progress-sidebar {
    right: 3px;
  }

  .progress-dot {
    width: 8px;
    height: 8px;
  }

  .progress-connector {
    height: 8px;
    margin-left: 3px;
  }

  .ko-reference-btn {
    width: 42px;
    height: 42px;
    bottom: 70px;
    right: 12px;
    font-size: 18px;
  }

  .content-milestone {
    font-size: 0.78rem;
    padding: 6px 12px;
  }
}


/* ===== Dark Mode ===== */
[data-theme="dark"] .progress-sidebar {
  /* dots and labels inherit dark mode colors via CSS vars */
}

[data-theme="dark"] .progress-connector {
  background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .progress-connector[data-filled="true"] {
  background: #22c55e;
}

[data-theme="dark"] .content-milestone {
  background: rgba(15, 23, 42, 0.95);
  color: var(--text-primary);
  border-color: var(--accent, #2563EB);
}

[data-theme="dark"] .ko-reference-panel {
  background: var(--bg-primary, #0f172a);
}

[data-theme="dark"] .ko-reference-panel-header {
  background: var(--bg-primary, #0f172a);
  border-bottom-color: rgba(255, 255, 255, 0.08);
}
