/* How It Works — animated REBT story */

.hiw-page {
  max-width: 960px;
  margin: 0 auto 3rem;
  padding: 1.5rem 1rem 2rem;
}

.hiw-intro {
  text-align: center;
  margin-bottom: 1.5rem;
}

.hiw-intro h1 {
  font-family: 'Poppins', var(--site_font_family);
  font-weight: 800;
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  color: var(--font-color);
  margin-bottom: 0.5rem;
}

.hiw-intro-lead {
  max-width: 36rem;
  margin: 0 auto;
  color: var(--text-muted);
  font-size: 1.05rem;
  line-height: 1.5;
}

.hiw-stage {
  position: relative;
  background:
    linear-gradient(165deg, rgba(236, 245, 234, 0.95) 0%, rgba(198, 235, 190, 0.55) 45%, rgba(236, 245, 234, 0.9) 100%),
    radial-gradient(ellipse at 20% 0%, rgba(145, 218, 115, 0.25), transparent 50%);
  border: 2px solid var(--primary_color_deeper);
  border-radius: 16px;
  overflow: hidden;
  padding: 1rem 1rem 1.25rem;
}

.hiw-step-badge {
  position: absolute;
  top: 0.85rem;
  left: 1rem;
  z-index: 2;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  background: var(--primary_color_dark);
  color: #fff;
  font-family: 'Poppins', var(--site_font_family);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.hiw-canvas {
  width: 100%;
  margin-top: 1.75rem;
}

.hiw-scene {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(52vh, 420px);
}

/* Scene visibility via data-scene on stage */
.hiw-bubble,
.hiw-rumination,
.hiw-calm-shield,
.hiw-ripples,
.hiw-affect {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.55s ease, transform 0.55s ease;
}

.hiw-boss {
  transition: transform 0.55s ease;
}

.hiw-person {
  transition: transform 0.55s ease;
}

.hiw-person-shirt,
.hiw-person-sleeve,
.hiw-person-arm ellipse {
  transition: fill 0.45s ease;
}

.hiw-person-face,
.hiw-boss-face {
  transition: opacity 0.35s ease;
}

.hiw-boss-head-group {
  transition: transform 0.55s ease;
  transform-origin: 55px 42px;
}

.hiw-person-arm-r {
  transition: transform 0.45s ease;
  transform-origin: 94px 100px;
}

.hiw-rumination-ring {
  transform-origin: 60px 60px;
}

.hiw-ripple-1,
.hiw-ripple-2,
.hiw-ripple-3 {
  transform-origin: center;
}

/* Default faces */
.hiw-person-face-hurt,
.hiw-person-face-calm,
.hiw-boss-face-away {
  opacity: 0;
}

.hiw-person-face-ok,
.hiw-boss-face-forward {
  opacity: 1;
}

/* Intro — boss looks toward person */
.hiw-stage[data-scene="intro"] .hiw-boss-face-forward {
  opacity: 1;
}

.hiw-stage[data-scene="intro"] .hiw-boss-face-away {
  opacity: 0;
}

/* A — Activating event: boss looks away at screen / papers */
.hiw-stage[data-scene="a"] .hiw-boss-face-forward,
.hiw-stage[data-scene="b"] .hiw-boss-face-forward,
.hiw-stage[data-scene="c"] .hiw-boss-face-forward,
.hiw-stage[data-scene="d"] .hiw-boss-face-forward,
.hiw-stage[data-scene="e"] .hiw-boss-face-forward,
.hiw-stage[data-scene="replay"] .hiw-boss-face-forward,
.hiw-stage[data-scene="calm"] .hiw-boss-face-forward,
.hiw-stage[data-scene="outward"] .hiw-boss-face-forward,
.hiw-stage[data-scene="end"] .hiw-boss-face-forward {
  opacity: 0;
}

.hiw-stage[data-scene="a"] .hiw-boss-face-away,
.hiw-stage[data-scene="b"] .hiw-boss-face-away,
.hiw-stage[data-scene="c"] .hiw-boss-face-away,
.hiw-stage[data-scene="d"] .hiw-boss-face-away,
.hiw-stage[data-scene="e"] .hiw-boss-face-away,
.hiw-stage[data-scene="replay"] .hiw-boss-face-away,
.hiw-stage[data-scene="calm"] .hiw-boss-face-away,
.hiw-stage[data-scene="outward"] .hiw-boss-face-away,
.hiw-stage[data-scene="end"] .hiw-boss-face-away {
  opacity: 1;
}

.hiw-stage[data-scene="a"] .hiw-boss-head-group,
.hiw-stage[data-scene="replay"] .hiw-boss-head-group {
  transform: rotate(-12deg) translate(-6px, 2px);
}

.hiw-stage[data-scene="a"] .hiw-person-arm-r,
.hiw-stage[data-scene="replay"] .hiw-person-arm-r {
  transform: rotate(-28deg);
}

/* B — Belief bubble */
.hiw-stage[data-scene="b"] .hiw-bubble-belief {
  opacity: 1;
}

/* C — Consequence + rumination */
.hiw-stage[data-scene="c"] .hiw-rumination {
  opacity: 1;
}

.hiw-stage[data-scene="c"] .hiw-affect {
  opacity: 0.55;
  stroke-width: 8;
}

.hiw-stage[data-scene="c"] .hiw-person-face-ok {
  opacity: 0;
}

.hiw-stage[data-scene="c"] .hiw-person-face-hurt {
  opacity: 1;
}

.hiw-stage[data-scene="c"] .hiw-person-shirt,
.hiw-stage[data-scene="c"] .hiw-person-sleeve {
  fill: #7a2e28;
}

.hiw-stage[data-scene="c"] .hiw-rumination-ring {
  animation: hiw-spin 3.2s linear infinite;
}

.hiw-stage[data-scene="c"] .hiw-rumination-word {
  animation: hiw-pulse 1.6s ease-in-out infinite;
}

.hiw-stage[data-scene="c"] .hiw-rumination-w2 {
  animation-delay: 0.35s;
}

.hiw-stage[data-scene="c"] .hiw-rumination-w3 {
  animation-delay: 0.7s;
}

/* D — Dispute */
.hiw-stage[data-scene="d"] .hiw-bubble-dispute {
  opacity: 1;
}

.hiw-stage[data-scene="d"] .hiw-person-face-ok {
  opacity: 0.35;
}

.hiw-stage[data-scene="d"] .hiw-person-face-hurt {
  opacity: 0.65;
}

/* E — Effective thinking */
.hiw-stage[data-scene="e"] .hiw-bubble-effective {
  opacity: 1;
}

.hiw-stage[data-scene="e"] .hiw-person-face-ok {
  opacity: 0;
}

.hiw-stage[data-scene="e"] .hiw-person-face-calm {
  opacity: 1;
}

/* Replay — same ignore again */
.hiw-stage[data-scene="replay"] .hiw-calm-shield {
  opacity: 0.85;
}

.hiw-stage[data-scene="replay"] .hiw-person-face-ok {
  opacity: 0;
}

.hiw-stage[data-scene="replay"] .hiw-person-face-calm {
  opacity: 1;
}

/* Calm — no rumination */
.hiw-stage[data-scene="calm"] .hiw-calm-shield {
  opacity: 1;
}

.hiw-stage[data-scene="calm"] .hiw-rumination {
  opacity: 0.15;
  transform: scale(0.85);
}

.hiw-stage[data-scene="calm"] .hiw-person-face-ok {
  opacity: 0;
}

.hiw-stage[data-scene="calm"] .hiw-person-face-calm {
  opacity: 1;
}

/* Outward insight */
.hiw-stage[data-scene="outward"] .hiw-ripples,
.hiw-stage[data-scene="end"] .hiw-ripples {
  opacity: 1;
}

.hiw-stage[data-scene="outward"] .hiw-calm-shield,
.hiw-stage[data-scene="end"] .hiw-calm-shield {
  opacity: 0.5;
}

.hiw-stage[data-scene="outward"] .hiw-person-face-ok,
.hiw-stage[data-scene="end"] .hiw-person-face-ok {
  opacity: 0;
}

.hiw-stage[data-scene="outward"] .hiw-person-face-calm,
.hiw-stage[data-scene="end"] .hiw-person-face-calm {
  opacity: 1;
}

.hiw-stage[data-scene="outward"] .hiw-ripple-2 {
  animation: hiw-ripple-out 2.4s ease-out infinite;
}

.hiw-stage[data-scene="outward"] .hiw-ripple-3 {
  animation: hiw-ripple-out 2.4s ease-out 0.6s infinite;
}

.hiw-stage[data-scene="end"] .hiw-ripple-2,
.hiw-stage[data-scene="end"] .hiw-ripple-3 {
  animation: none;
  opacity: 0.5;
}

@keyframes hiw-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes hiw-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

@keyframes hiw-ripple-out {
  0% { transform: scale(0.7); opacity: 0.55; }
  100% { transform: scale(1.35); opacity: 0; }
}

.hiw-caption-panel {
  margin-top: 0.75rem;
  padding: 0.85rem 1rem 0.5rem;
  text-align: center;
  min-height: 7.5rem;
}

.hiw-step-label {
  margin: 0 0 0.35rem;
  font-family: 'Poppins', var(--site_font_family);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--primary_color_dark);
}

.hiw-caption-title {
  margin: 0 0 0.4rem;
  font-family: 'Poppins', var(--site_font_family);
  font-size: clamp(1.15rem, 2.5vw, 1.45rem);
  font-weight: 700;
  color: var(--font-color);
}

.hiw-caption-body {
  margin: 0 auto;
  max-width: 38rem;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.5;
}

.hiw-progress {
  height: 4px;
  margin: 0.75rem 0.5rem 1rem;
  background: rgba(14, 51, 56, 0.12);
  border-radius: 2px;
  overflow: hidden;
}

.hiw-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--primary_color);
  border-radius: 2px;
  transition: width 0.35s ease;
}

.hiw-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  align-items: center;
}

.hiw-controls .hiw-btn {
  min-width: 5.5rem;
  font-family: 'Poppins', var(--site_font_family);
  font-weight: 600;
}

.hiw-controls .btn-secondary {
  background: #fff;
  border: 2px solid var(--primary_color_dark);
  color: var(--primary_color_dark);
}

.hiw-controls .btn-secondary:hover,
.hiw-controls .btn-secondary:focus {
  background: var(--secondary_light_color);
  color: var(--primary_color_dark);
}

.hiw-end-cta {
  margin-top: 2rem;
  text-align: center;
  padding: 1.5rem 1rem;
  background: linear-gradient(180deg, rgba(145, 218, 115, 0.18), transparent);
  border-radius: 12px;
}

.hiw-end-cta p {
  font-family: 'Poppins', var(--site_font_family);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--font-color);
  margin-bottom: 1rem;
}

.hiw-end-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

.hiw-end-actions .how-it-works-cta.btn-outline-primary {
  display: inline-block;
  padding: 0.55rem 1.35rem;
  font-family: 'Poppins', var(--site_font_family);
  font-weight: 600;
  border: 2px solid var(--primary_color_dark);
  color: var(--primary_color_dark);
  background: transparent;
  border-radius: 8px;
  text-decoration: none;
}

.hiw-end-actions .how-it-works-cta.btn-outline-primary:hover,
.hiw-end-actions .how-it-works-cta.btn-outline-primary:focus {
  background-color: var(--primary_color);
  color: #fff;
  text-decoration: none;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .hiw-bubble,
  .hiw-rumination,
  .hiw-calm-shield,
  .hiw-ripples,
  .hiw-affect,
  .hiw-boss,
  .hiw-person,
  .hiw-person-shirt,
  .hiw-person-sleeve,
  .hiw-person-arm-r,
  .hiw-person-face,
  .hiw-boss-face,
  .hiw-boss-head-group,
  .hiw-progress-bar {
    transition: none !important;
    animation: none !important;
  }

  .hiw-stage[data-scene="c"] .hiw-rumination-ring,
  .hiw-stage[data-scene="c"] .hiw-rumination-word,
  .hiw-stage[data-scene="outward"] .hiw-ripple-2,
  .hiw-stage[data-scene="outward"] .hiw-ripple-3 {
    animation: none !important;
  }
}

@media (max-width: 767px) {
  .hiw-page {
    padding: 1rem 0.65rem 2rem;
  }

  .hiw-caption-panel {
    min-height: 8.5rem;
  }

  .hiw-controls .hiw-btn {
    flex: 1 1 40%;
  }
}
