/* =========================================================
   THOMPSON SORTED — ANIMATED PROCESS EXPLAINER (js/explainer.js)
   A four-scene looping animation that sits under the three
   steps in How It Works. Pure CSS animation; the script only
   switches the active scene. Reduced motion: no autoplay and
   no movement, but the scenes can still be stepped through.
   ========================================================= */

.explainer {
  margin-top: 56px;
  background: var(--charcoal-900);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(31, 36, 34, 0.22);
  color: var(--white);
}

.ex-stage {
  position: relative;
  min-height: 480px;
  background:
    radial-gradient(600px circle at 15% 0%, rgba(31, 138, 130, .28), transparent 60%),
    radial-gradient(500px circle at 100% 100%, rgba(92, 196, 186, .14), transparent 60%),
    var(--charcoal-900);
}

.ex-scene {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 28px 24px;
  opacity: 0;
  visibility: hidden;
  transition: opacity .45s ease, visibility 0s linear .45s;
}
.ex-scene.active {
  opacity: 1;
  visibility: visible;
  transition: opacity .45s ease;
}

/* Shared entrance for everything inside the active scene */
.ex-scene.active .ex-in {
  animation: ex-in .6s cubic-bezier(.2, .7, .2, 1) both;
  animation-delay: var(--d, 0s);
}
.ex-scene:not(.active) .ex-in { opacity: 0; }
@keyframes ex-in {
  from { opacity: 0; transform: translateY(14px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

/* ---- Scene 1: chat ---- */
.ex-chat { width: min(460px, 100%); display: flex; flex-direction: column; gap: 12px; }
.ex-bubble {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: .95rem;
  line-height: 1.45;
}
.ex-bubble.them { align-self: flex-start; background: rgba(255, 255, 255, .1); border-bottom-left-radius: 4px; }
.ex-bubble.me   { align-self: flex-end; background: var(--teal); border-bottom-right-radius: 4px; }
.ex-typing { align-self: flex-start; display: inline-flex; gap: 5px; padding: 14px 16px; background: rgba(255, 255, 255, .1); border-radius: 16px; border-bottom-left-radius: 4px; }
/* The typing dots appear, then give way to the reply */
.ex-scene.active .ex-chat .ex-typing {
  animation: ex-in .6s cubic-bezier(.2, .7, .2, 1) 1.4s both, ex-gone .3s ease 2.5s forwards;
}
@keyframes ex-gone { to { opacity: 0; height: 0; padding-top: 0; padding-bottom: 0; margin-top: -12px; overflow: hidden; } }
.ex-typing i { width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 255, 255, .7); animation: ex-dot 1s ease-in-out infinite; }
.ex-typing i:nth-child(2) { animation-delay: .15s; }
.ex-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes ex-dot { 0%, 100% { opacity: .3; transform: none; } 50% { opacity: 1; transform: translateY(-3px); } }
.ex-chip {
  align-self: center;
  background: var(--teal-light);
  color: var(--teal-dark);
  font-weight: 600;
  font-size: .85rem;
  padding: 7px 14px;
  border-radius: 999px;
}

/* ---- Browser window (scenes 2-4) ---- */
.ex-browser {
  width: min(480px, 100%);
  background: var(--white);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .35);
  color: var(--charcoal-900);
}
.ex-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 12px;
  background: #ecebe6;
}
.ex-bar i { width: 9px; height: 9px; border-radius: 50%; background: #c9c6bd; }
.ex-url {
  flex: 1;
  margin-left: 8px;
  padding: 3px 10px;
  border-radius: 6px;
  background: var(--white);
  font-size: .72rem;
  color: var(--charcoal-500);
  white-space: nowrap;
  overflow: hidden;
}
.ex-page { padding: 16px; display: grid; gap: 10px; }
.ex-nav { display: flex; justify-content: space-between; align-items: center; }
.ex-logo { width: 70px; height: 10px; border-radius: 5px; background: var(--charcoal-900); }
.ex-links { display: flex; gap: 6px; }
.ex-links i { width: 28px; height: 6px; border-radius: 3px; background: var(--border); }
.ex-line { height: 12px; border-radius: 6px; background: var(--charcoal-900); }
.ex-line.l1 { width: 78%; }
.ex-line.l2 { width: 54%; }
.ex-line.thin { height: 7px; background: var(--border); width: 66%; }
.ex-btn { width: 96px; height: 26px; border-radius: 6px; background: var(--teal); }
.ex-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 4px; }
.ex-cards i { height: 54px; border-radius: 8px; background: var(--teal-light); border: 1px solid var(--border); }

/* ---- Scene 2: devices caption row ---- */
.ex-devices { display: flex; gap: 10px; align-items: flex-end; font-size: .8rem; color: rgba(255, 255, 255, .75); }
.ex-devices span { display: inline-flex; align-items: center; gap: 6px; }
.ex-devices svg { color: #5cc4ba; }

/* ---- Scene 3: sign-off ---- */
.ex-approve { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; background: #f3f1ec; border-top: 1px solid var(--border); font-size: .85rem; }
.ex-approve strong { font-weight: 600; }
.ex-ok {
  position: relative;
  padding: 8px 16px;
  border-radius: 8px;
  background: var(--teal);
  color: var(--white);
  font-weight: 600;
  font-size: .85rem;
  white-space: nowrap;
}
.ex-ok::after {
  content: "\2713  Signed off";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--teal-dark);
  opacity: 0;
}
.ex-scene.active .ex-ok::after { animation: ex-fadein .4s ease 2.2s both; }
@keyframes ex-fadein { to { opacity: 1; } }

/* ---- Scene 4: live ---- */
.ex-live-badge {
  display: inline-flex; align-items: center; gap: 7px;
  background: rgba(31, 138, 130, .18);
  color: #8be0d6;
  font-weight: 600; font-size: .8rem;
  padding: 6px 12px; border-radius: 999px;
}
.ex-live-badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #5cc4ba; animation: ex-pulse 1.4s ease-in-out infinite; }
@keyframes ex-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(92, 196, 186, .6); } 50% { box-shadow: 0 0 0 7px rgba(92, 196, 186, 0); } }
.ex-toasts { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.ex-toast { background: rgba(255, 255, 255, .1); padding: 9px 14px; border-radius: 10px; font-size: .85rem; }
.ex-toast b { color: #8be0d6; font-weight: 600; }

/* Address bar types itself out in scene 4 */
.ex-scene.active .ex-url-type {
  display: inline-block;
  overflow: hidden;
  white-space: nowrap;
  vertical-align: bottom;
  animation: ex-type 1.4s steps(18, end) .3s both;
}
@keyframes ex-type { from { max-width: 0; } to { max-width: 20ch; } }

/* ---- Scene title + controls ---- */
.ex-title { font-family: var(--font-heading); font-size: 1.15rem; font-weight: 600; text-align: center; margin: 0; }
.ex-sub { font-size: .9rem; color: rgba(255, 255, 255, .72); text-align: center; margin: 0; max-width: 44ch; }

.ex-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  background: rgba(0, 0, 0, .25);
}
.ex-play {
  width: 36px; height: 36px;
  flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--teal);
  color: var(--white);
  cursor: pointer;
  transition: background .2s ease;
}
.ex-play:hover { background: var(--teal-dark); }
.ex-play svg { width: 14px; height: 14px; }
.ex-play .i-play { display: none; }
.explainer.paused .ex-play .i-play { display: block; }
.explainer.paused .ex-play .i-pause { display: none; }

.ex-dots { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ex-dot {
  position: relative;
  border: 0;
  background: none;
  padding: 8px 0 0;
  color: rgba(255, 255, 255, .6);
  font: inherit;
  font-size: .78rem;
  text-align: left;
  cursor: pointer;
}
.ex-dot::before, .ex-dot::after {
  content: "";
  position: absolute;
  top: 0; left: 0;
  height: 3px;
  border-radius: 2px;
}
.ex-dot::before { right: 0; background: rgba(255, 255, 255, .18); }
.ex-dot::after { width: 0; background: #5cc4ba; }
.ex-dot[aria-current="true"] { color: var(--white); }
.ex-dot.done::after { width: 100%; }
.ex-dot[aria-current="true"]::after { animation: ex-fill var(--ex-dur, 5.5s) linear forwards; }
.explainer.paused .ex-dot[aria-current="true"]::after { animation-play-state: paused; }
@keyframes ex-fill { from { width: 0; } to { width: 100%; } }
.ex-dot:focus-visible, .ex-play:focus-visible { outline: 2px solid #8be0d6; outline-offset: 2px; }

@media (max-width: 640px) {
  .explainer { margin-top: 40px; }
  .ex-stage { min-height: 500px; }
  .ex-dot span { display: none; }
  .ex-dot { height: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .ex-scene, .ex-scene.active { transition: none; }
  .ex-scene.active .ex-in, .ex-scene.active .ex-ok::after, .ex-scene.active .ex-url-type { animation: none; }
  .ex-scene:not(.active) .ex-in { opacity: 1; }
  .ex-scene.active .ex-ok::after { opacity: 1; }
  .ex-typing i, .ex-live-badge::before { animation: none; }
  .ex-dot[aria-current="true"]::after { animation: none; width: 100%; }
}
