/* Engagement — progress bar, predict-and-reveal, completion card.
 * Loaded on every WebR tutorial.
 * Class-prefixed with `engagement-` so it cannot collide with any other styles.
 * Design language: monochromatic, glass surfaces, single easing curve.
 */

/* When engagement is loaded, drop webr-header's sticky so it doesn't compete
   with the progress bar for top:0. Progress bar is the single sticky anchor. */
.webr-header { position: static !important; }

/* =========================================================
   Tutorial metadata strip (S5) — under H1, above progress bar
   ========================================================= */
.engagement-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 12px;
  color: #64748b;
  margin: 0.4em 0 1em;
  letter-spacing: 0.01em;
}
.engagement-header:empty { display: none; }
.engagement-meta-diff {
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.engagement-meta-diff-beginner     { background: #dcfce7; color: #166534; }
.engagement-meta-diff-intermediate { background: #fef3c7; color: #854d0e; }
.engagement-meta-diff-advanced     { background: #fee2e2; color: #991b1b; }
.engagement-meta-dot { opacity: 0.4; }
.engagement-meta-xp { color: #059669; font-weight: 600; }
html.dark .engagement-header { color: #94a3b8; }
html.dark .engagement-meta-diff-beginner     { background: #14532d; color: #86efac; }
html.dark .engagement-meta-diff-intermediate { background: #78350f; color: #fde68a; }
html.dark .engagement-meta-diff-advanced     { background: #7f1d1d; color: #fca5a5; }
html.dark .engagement-meta-xp { color: #34d399; }

/* =========================================================
   Progress bar — sticky segmented pill indicator
   ========================================================= */
.engagement-progress {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  margin: 1.2em 0 1.6em;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  backdrop-filter: blur(12px) saturate(180%);
  background: rgba(255, 255, 255, 0.72);
  min-height: 32px;
}

.engagement-progress-label {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 11px;
  font-weight: 500;
  color: #64748b;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.engagement-progress-label strong {
  color: #0f172a;
  font-weight: 600;
}

.engagement-progress-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  align-items: center;
  position: relative;
  padding: 2px 0;
}

.engagement-progress-pill {
  width: 20px;
  height: 4px;
  border-radius: 2px;
  border: 1px solid rgba(15, 23, 42, 0.25);
  background: transparent;
  transition:
    background-color 280ms cubic-bezier(0.22, 1, 0.36, 1),
    border-color 280ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 280ms cubic-bezier(0.22, 1, 0.36, 1);
}

.engagement-progress-pill.is-filled {
  background: #0f172a;
  border-color: #0f172a;
}

.engagement-progress-pill.just-filled {
  animation: engagementPillPulse 300ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes engagementPillPulse {
  0%   { transform: scaleY(1);   opacity: 1;    }
  50%  { transform: scaleY(1.7); opacity: 0.85; }
  100% { transform: scaleY(1);   opacity: 1;    }
}

.engagement-progress-pills.is-complete {
  overflow: hidden;
}

.engagement-progress-pills.is-complete::after {
  content: '';
  position: absolute;
  top: 0;
  left: -30%;
  height: 100%;
  width: 30%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(15, 23, 42, 0.14) 50%,
    transparent 100%
  );
  animation: engagementShimmer 450ms cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

@keyframes engagementShimmer {
  0%   { left: -30%;  }
  100% { left: 130%; }
}

/* =========================================================
   Completion card — frosted glass notification, bottom-right
   ========================================================= */
.engagement-completion {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 360px;
  max-width: calc(100vw - 48px);
  z-index: 1000;
  padding: 18px 20px 18px 22px;
  background: rgba(255, 255, 255, 0.92);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 14px;
  box-shadow:
    0 10px 40px -12px rgba(15, 23, 42, 0.18),
    0 2px 6px rgba(15, 23, 42, 0.05);
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  transition:
    opacity 420ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 420ms cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.engagement-completion.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.engagement-completion-eyebrow {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #64748b;
  margin: 0 0 6px 0;
}

.engagement-completion-headline {
  font-family: 'Inter', sans-serif;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: #0f172a;
  margin: 0 0 4px 0;
  line-height: 1.35;
  padding-right: 28px;
}

.engagement-completion-stat {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: #64748b;
  margin: 0 0 14px 0;
  font-variant-numeric: tabular-nums;
}

.engagement-completion-cta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  background: #0f172a;
  color: #ffffff !important;
  border: none;
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  text-decoration: none !important;
  transition:
    transform 150ms cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 150ms cubic-bezier(0.22, 1, 0.36, 1);
  cursor: pointer;
}

.engagement-completion-cta:hover,
.engagement-completion-cta:focus {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px -2px rgba(15, 23, 42, 0.25);
  color: #ffffff !important;
  text-decoration: none !important;
}

.engagement-completion-cta-arrow {
  display: inline-block;
  transition: transform 150ms cubic-bezier(0.22, 1, 0.36, 1);
}

.engagement-completion-cta:hover .engagement-completion-cta-arrow {
  animation: engagementArrowNudge 2s cubic-bezier(0.22, 1, 0.36, 1) infinite;
}

@keyframes engagementArrowNudge {
  0%, 60%, 100% { transform: translateX(0); }
  75%           { transform: translateX(3px); }
}

.engagement-completion-dismiss {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 24px;
  height: 24px;
  padding: 0;
  background: transparent;
  border: none;
  color: #64748b;
  opacity: 0.45;
  cursor: pointer;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  transition: opacity 150ms cubic-bezier(0.22, 1, 0.36, 1);
}

.engagement-completion-dismiss:hover,
.engagement-completion-dismiss:focus-visible {
  opacity: 0.85;
  outline: none;
}

/* =========================================================
   Predict & Reveal — blurred expected output overlay
   ========================================================= */
.engagement-prediction {
  position: relative;
  padding: 16px 20px 42px 20px;
  min-height: 96px;
  opacity: 1;
  transform: scale(1);
  transition:
    opacity 350ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 350ms cubic-bezier(0.22, 1, 0.36, 1);
  overflow: hidden;
  border-radius: 6px;
}

.engagement-prediction.is-revealing {
  opacity: 0;
  transform: scale(0.985);
}

.engagement-prediction-content {
  filter: blur(6px);
  opacity: 0.72;
  pointer-events: none;
  user-select: none;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 13px;
  line-height: 1.55;
  color: #0f172a;
  white-space: pre-wrap;
  margin: 0;
}

.engagement-prediction-content svg {
  width: 100%;
  height: auto;
  max-height: 180px;
  display: block;
}

.engagement-prediction::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(ellipse at center, transparent 45%, rgba(15, 23, 42, 0.06) 100%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.05 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  pointer-events: none;
  z-index: 1;
}

.engagement-prediction-badge {
  position: absolute;
  top: 10px;
  left: 14px;
  padding: 3px 8px;
  background: rgba(15, 23, 42, 0.06);
  color: #64748b;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-radius: 4px;
  z-index: 2;
}

.engagement-prediction-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.88);
  -webkit-backdrop-filter: blur(8px) saturate(160%);
  backdrop-filter: blur(8px) saturate(160%);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 999px;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #334155;
  white-space: nowrap;
  animation: engagementHintPulse 3s ease-in-out infinite;
  z-index: 2;
}

@keyframes engagementHintPulse {
  0%, 100% { opacity: 0.62; }
  50%      { opacity: 0.95; }
}

/* =========================================================
   Dark mode
   ========================================================= */
html.dark .engagement-progress {
  border-bottom-color: rgba(226, 232, 240, 0.1);
  background: rgba(15, 23, 42, 0.72);
}

html.dark .engagement-progress-label {
  color: #94a3b8;
}

html.dark .engagement-progress-label strong {
  color: #e2e8f0;
}

html.dark .engagement-progress-pill {
  border-color: rgba(226, 232, 240, 0.25);
}

html.dark .engagement-progress-pill.is-filled {
  background: #e2e8f0;
  border-color: #e2e8f0;
}

html.dark .engagement-progress-pills.is-complete::after {
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(226, 232, 240, 0.16) 50%,
    transparent 100%
  );
}

html.dark .engagement-completion {
  background: rgba(15, 23, 42, 0.88);
  border-color: rgba(226, 232, 240, 0.1);
  box-shadow:
    0 10px 40px -12px rgba(0, 0, 0, 0.5),
    0 2px 6px rgba(0, 0, 0, 0.3);
}

html.dark .engagement-completion-eyebrow,
html.dark .engagement-completion-stat,
html.dark .engagement-completion-dismiss {
  color: #94a3b8;
}

html.dark .engagement-completion-headline {
  color: #f1f5f9;
}

html.dark .engagement-completion-cta {
  background: #e2e8f0;
  color: #0f172a !important;
}

html.dark .engagement-completion-cta:hover,
html.dark .engagement-completion-cta:focus {
  color: #0f172a !important;
}

html.dark .engagement-prediction-content {
  color: #e2e8f0;
}

html.dark .engagement-prediction-content svg circle {
  fill: #e2e8f0 !important;
}

html.dark .engagement-prediction-badge {
  background: rgba(226, 232, 240, 0.08);
  color: #94a3b8;
}

html.dark .engagement-prediction-hint {
  background: rgba(30, 41, 59, 0.88);
  border-color: rgba(226, 232, 240, 0.1);
  color: #cbd5e1;
}

html.dark .engagement-prediction::before {
  background-image:
    radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, 0.25) 100%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.05 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

/* =========================================================
   Responsive + accessibility + print safeguards
   ========================================================= */
@media (max-width: 640px) {
  .engagement-progress {
    padding: 8px 0;
    margin: 1em 0 1.4em;
    gap: 10px;
  }
  .engagement-progress-label {
    font-size: 10px;
    letter-spacing: 0.06em;
  }
  .engagement-progress-pill {
    width: 14px;
    height: 3px;
  }
  .engagement-completion {
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
  }
  .engagement-prediction {
    padding: 14px 16px 40px 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .engagement-progress-pill,
  .engagement-completion,
  .engagement-prediction,
  .engagement-completion-cta,
  .engagement-completion-cta-arrow {
    transition: none !important;
    animation: none !important;
  }
  .engagement-progress-pills.is-complete::after { display: none; }
  .engagement-prediction-hint { animation: none; opacity: 0.85; }
}

@media print {
  .engagement-progress,
  .engagement-completion,
  .engagement-prediction {
    display: none !important;
  }
}
