/* ==========================================================================
   Splitiva — signature demo animations
   Pure CSS, compositor-only, synced to a single master duration per demo.
   These show what screenshots cannot: the auto-log and the settle-up.
   ========================================================================== */

.demo-frame {
  position: relative;
  width: 100%;
  max-width: 380px;
  margin-inline: auto;
  padding: var(--space-5);
  border-radius: var(--r-xl);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

@media (max-width: 939px) {
  .demo-frame {
    max-width: none;
    padding: var(--space-4);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-md);
  }

  .sms-demo {
    min-height: 268px;
  }

  .sms-banner {
    padding: var(--space-3);
    gap: var(--space-2);
    box-shadow: 0 10px 22px rgba(20, 12, 60, 0.28);
  }

  .sms-banner-text {
    font-size: 0.75rem;
    line-height: 1.4;
    /* Prefer wrapping over clipping mid-ref on narrow cards. */
    overflow-wrap: anywhere;
  }

  .sms-banner-icon {
    width: 26px;
    height: 26px;
    font-size: 0.6875rem;
  }

  .sms-demo-title {
    margin-bottom: var(--space-3);
    font-size: var(--t-sm);
  }
}

.on-brand .demo-frame {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 24px 60px rgba(8, 6, 30, 0.4);
}

.demo-caption {
  margin-top: var(--space-4);
  font-size: var(--t-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  text-align: center;
}

/* ==========================================================================
   Demo 1 — Bank SMS morphing into a logged expense
   Master timeline: 10s. Every child keyframes across the same 10s so the
   whole sequence stays in sync without a single line of JavaScript.
   ========================================================================== */

.sms-demo {
  --demo-dur: 10s;
  position: relative;
  min-height: 292px;
}

.sms-demo-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
  font-size: var(--t-sm);
  font-weight: 800;
  color: var(--text);
}

.sms-demo-title .pill {
  font-size: 0.625rem;
  padding: 0.25rem 0.625rem;
}

/* --- incoming SMS banner --- */

.sms-banner {
  position: absolute;
  inset-inline: 0;
  top: 34px;
  z-index: 3;
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--brand) 92%, #000);
  color: #fff;
  box-shadow: 0 16px 34px rgba(20, 12, 60, 0.36);
  transform: translate3d(0, -140%, 0);
  opacity: 0;
  overflow: hidden;
  animation: sms-banner var(--demo-dur) var(--ease-out) infinite;
}

/* Scan sweep — the missing beat between "message arrives" and "tokens light
   up". Without it the highlights appeared with no visible cause. */
.sms-banner::after {
  content: '';
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: 38%;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(241, 196, 66, 0.28) 55%,
    rgba(241, 196, 66, 0.5) 78%,
    transparent
  );
  opacity: 0;
  animation: sms-scan var(--demo-dur) var(--ease-in-out) infinite;
}

.sms-banner-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 0.75rem;
  font-weight: 800;
}

.sms-banner-body {
  min-width: 0;
}

.sms-banner-from {
  font-size: 0.6875rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 2px;
}

.sms-banner-text {
  font-size: 0.8125rem;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.95);
}

/* tokens the parser locks onto */
.tok {
  position: relative;
  border-radius: 4px;
  padding: 0 3px;
  font-weight: 800;
  color: #fff;
  background: transparent;
  animation: tok-lock var(--demo-dur) var(--ease-out) infinite;
}

.tok-amount {
  animation-delay: 0s;
}

.tok-merchant {
  animation-delay: 0.45s;
}

/* --- the ledger the expense lands in --- */

.sms-ledger {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.ledger-row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid transparent;
}

.on-brand .ledger-row {
  background: rgba(255, 255, 255, 0.06);
}

.ledger-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--brand) 15%, transparent);
  color: var(--brand);
  font-size: 0.9375rem;
}

.on-brand .ledger-icon {
  background: rgba(255, 255, 255, 0.12);
  color: var(--accent);
}

.ledger-name {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.ledger-meta {
  font-size: 0.6875rem;
  color: var(--text-faint);
}

.ledger-amt {
  font-size: 0.875rem;
  font-weight: 800;
  color: var(--neg);
  font-variant-numeric: tabular-nums;
}

/* the row that materialises out of the SMS */
.ledger-row-new {
  overflow: hidden;
  transform-origin: top;
  animation: row-appear var(--demo-dur) var(--ease-out) infinite;
}

.ledger-row-new .ledger-icon {
  background: color-mix(in srgb, var(--accent) 24%, transparent);
  color: var(--accent-deep);
}

/* "Auto-logged" flag that pops with the new row */
.ledger-flag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
  padding: 1px 6px;
  border-radius: var(--r-full);
  background: color-mix(in srgb, var(--pos) 16%, transparent);
  color: var(--pos);
  font-size: 0.5625rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* existing rows nudge down to make space */
.ledger-rest {
  animation: rest-shift var(--demo-dur) var(--ease-out) infinite;
}

@keyframes sms-banner {
  0%,
  4% {
    transform: translate3d(0, -140%, 0);
    opacity: 0;
  }
  11%,
  46% {
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
  /* collapse toward the ledger as it converts */
  54% {
    transform: translate3d(0, 26px, 0) scale(0.9);
    opacity: 0;
  }
  100% {
    transform: translate3d(0, -140%, 0);
    opacity: 0;
  }
}

@keyframes sms-scan {
  0%,
  12% {
    transform: translate3d(-110%, 0, 0);
    opacity: 0;
  }
  14% {
    opacity: 1;
  }
  26% {
    transform: translate3d(280%, 0, 0);
    opacity: 1;
  }
  30%,
  100% {
    transform: translate3d(280%, 0, 0);
    opacity: 0;
  }
}

@keyframes tok-lock {
  0%,
  16% {
    background: transparent;
    box-shadow: none;
  }
  22%,
  46% {
    background: rgba(241, 196, 66, 0.34);
    box-shadow: 0 0 0 1px rgba(241, 196, 66, 0.6);
  }
  54%,
  100% {
    background: transparent;
    box-shadow: none;
  }
}

@keyframes row-appear {
  0%,
  50% {
    opacity: 0;
    max-height: 0;
    transform: translate3d(0, -8px, 0) scale(0.96);
    margin-bottom: calc(var(--space-2) * -1);
  }
  60% {
    opacity: 1;
    max-height: 70px;
    transform: translate3d(0, 0, 0) scale(1);
    margin-bottom: 0;
  }
  62% {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent);
  }
  72%,
  92% {
    opacity: 1;
    max-height: 70px;
    transform: none;
    box-shadow: none;
    margin-bottom: 0;
  }
  100% {
    opacity: 0;
    max-height: 0;
    transform: translate3d(0, -8px, 0) scale(0.96);
    margin-bottom: calc(var(--space-2) * -1);
  }
}

@keyframes rest-shift {
  0%,
  50% {
    transform: translate3d(0, 0, 0);
  }
  60%,
  92% {
    transform: translate3d(0, 0, 0);
  }
  100% {
    transform: translate3d(0, 0, 0);
  }
}

/* ==========================================================================
   Demo 2 — Splitting a bill, then settling it
   Master timeline: 11s.
   ========================================================================== */

.split-demo {
  --demo-dur: 11s;
  position: relative;
  min-height: 292px;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.split-bill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4);
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--brand) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--brand) 22%, transparent);
}

.on-brand .split-bill {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.16);
}

.split-bill-label {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--text-dim);
}

.split-bill-total {
  font-size: 1.375rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.split-people {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
}

.split-person {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-2);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  /* Entrance plays once and holds. Looping it left the card looking empty
     for a fifth of every cycle, which read as broken rather than animated. */
  animation: person-in 680ms var(--ease-spring) both;
  animation-delay: calc(var(--p) * 90ms + 200ms);
}

.on-brand .split-person {
  background: rgba(255, 255, 255, 0.06);
}

.split-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 0.8125rem;
  font-weight: 800;
  color: #fff;
  background: var(--brand);
}

.split-person:nth-child(2) .split-avatar {
  background: #e2704a;
}
.split-person:nth-child(3) .split-avatar {
  background: var(--lent);
}
.split-person:nth-child(4) .split-avatar {
  background: #7b6ae0;
}

.split-share {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.split-status {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: auto;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--r-sm);
  font-size: 0.8125rem;
  font-weight: 700;
}

.split-status-owed {
  background: color-mix(in srgb, var(--owe) 12%, transparent);
  color: var(--owe);
  animation: status-owed var(--demo-dur) var(--ease-out) infinite;
}

.split-status-settled {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  background: color-mix(in srgb, var(--pos) 14%, transparent);
  color: var(--pos);
  opacity: 0;
  transform: translate3d(0, 10px, 0);
  animation: status-settled var(--demo-dur) var(--ease-spring) infinite;
}

.split-status svg {
  width: 17px;
  height: 17px;
  flex: none;
}

/* progress bar that fills as the settle-up completes */
.split-progress {
  position: relative;
  height: 4px;
  border-radius: var(--r-full);
  background: color-mix(in srgb, var(--text) 10%, transparent);
  overflow: hidden;
}

.split-progress::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  transform-origin: left;
  transform: scaleX(0);
  animation: progress-fill var(--demo-dur) var(--ease-in-out) infinite;
}

@keyframes person-in {
  from {
    opacity: 0;
    transform: translate3d(0, 14px, 0) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

/* The two status pills cross-fade, so the slot is never empty. */
@keyframes status-owed {
  0%,
  4% {
    opacity: 0;
  }
  12%,
  62% {
    opacity: 1;
  }
  72%,
  100% {
    opacity: 0;
  }
}

@keyframes status-settled {
  0%,
  64% {
    opacity: 0;
    transform: translate3d(0, 10px, 0);
  }
  74%,
  94% {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
  100% {
    opacity: 0;
    transform: translate3d(0, 10px, 0);
  }
}

@keyframes progress-fill {
  0%,
  30% {
    transform: scaleX(0);
  }
  72%,
  92% {
    transform: scaleX(1);
  }
  100% {
    transform: scaleX(0);
  }
}

/* ==========================================================================
   Visibility-gated playback
   site.js marks a demo as offscreen; until then it plays, so the animation
   still runs with JavaScript disabled. Pausing rather than cancelling means
   a demo resumes mid-story instead of restarting when it scrolls back.
   ========================================================================== */

[data-demo][data-play='false'],
[data-demo][data-play='false'] *,
[data-demo][data-play='false'] *::before,
[data-demo][data-play='false'] *::after {
  animation-play-state: paused !important;
}

/* ==========================================================================
   Reduced motion — freeze both demos on their most informative frame
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .sms-banner::after {
    animation: none !important;
    opacity: 0;
  }

  .sms-banner,
  .tok,
  .ledger-row-new,
  .ledger-rest,
  .split-person,
  .split-status-owed,
  .split-status-settled,
  .split-progress::after {
    animation: none !important;
  }

  .sms-banner {
    position: relative;
    top: 0;
    opacity: 1;
    transform: none;
    margin-bottom: var(--space-4);
  }

  .tok {
    background: rgba(241, 196, 66, 0.34);
    box-shadow: 0 0 0 1px rgba(241, 196, 66, 0.6);
  }

  .ledger-row-new {
    opacity: 1;
    max-height: none;
    transform: none;
    margin-bottom: 0;
  }

  .split-person {
    opacity: 1;
    transform: none;
  }

  .split-status-owed {
    opacity: 1;
  }

  .split-status-settled {
    display: none;
  }

  .split-progress::after {
    transform: scaleX(1);
  }
}
