/* How it works: animated, scroll-triggered story. Every scene is plain HTML
   and CSS; how-it-works.js adds .is-on when a step scrolls into view. */

.hiw-switch {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin-top: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}
.hiw-tab {
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  border: 0;
  border-radius: 999px;
  padding: 0.55rem 1.1rem;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.hiw-tab[aria-pressed='true'] {
  background: var(--accent);
  color: #fff;
}
.hiw-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Steps, joined by a line down the left. */
.hiw-track {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  max-width: 1040px;
  position: relative;
}
.hiw-track::before {
  content: '';
  position: absolute;
  left: 21px;
  top: 30px;
  bottom: 30px;
  width: 2px;
  background: var(--border);
}
.hiw-step {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 48px;
  align-items: center;
  padding: 40px 0 40px 72px;
}
.hiw-num {
  position: absolute;
  left: 0;
  top: 50%;
  translate: 0 -50%;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  background: var(--surface);
  border: 2px solid var(--border);
  color: var(--muted);
  transition: background 0.4s, color 0.4s, border-color 0.4s;
}
.hiw-step.is-on .hiw-num {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.hiw-text h2 {
  font-size: clamp(1.5rem, 2.6vw, 2rem);
}
.hiw-text,
.hiw-visual {
  opacity: 0;
  translate: 0 24px;
  transition: opacity 0.6s ease, translate 0.6s ease;
}
.hiw-visual {
  transition-delay: 0.1s;
}
.hiw-step.is-on .hiw-text,
.hiw-step.is-on .hiw-visual {
  opacity: 1;
  translate: 0 0;
}
.hiw-visual {
  display: flex;
  justify-content: center;
  min-height: 300px;
  align-items: center;
}

/* Devices */
.hiw-device {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.hiw-desk {
  width: min(100%, 420px);
  border-radius: 14px;
  padding: 0 18px 58px;
  min-height: 250px;
}
.hiw-desk-sm {
  width: 200px;
  min-height: 180px;
  padding: 0 14px 16px;
}
.hiw-phone {
  width: 220px;
  min-height: 330px;
  border-radius: 30px;
  border: 7px solid #1b1916;
  padding: 28px 14px 16px;
}
.hiw-notch {
  position: absolute;
  top: 8px;
  left: 50%;
  translate: -50% 0;
  width: 60px;
  height: 8px;
  border-radius: 8px;
  background: var(--surface-2);
}
.hiw-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 -18px 18px;
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}
.hiw-desk-sm .hiw-bar {
  margin: 0 -14px 14px;
}
.hiw-bar i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border);
}
.hiw-bar span {
  margin-left: 8px;
}
.hiw-line {
  font-size: 0.82rem;
  color: var(--muted);
}
.hiw-center {
  text-align: center;
}

/* Pop-in helper used by many parts. */
@keyframes hiw-pop {
  from {
    opacity: 0;
    transform: scale(0.6);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}
@keyframes hiw-rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.hiw-toast {
  position: absolute;
  left: 50%;
  bottom: 14px;
  translate: -50% 0;
  white-space: nowrap;
  background: var(--ok);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  opacity: 0;
}
.is-on .hiw-toast {
  animation: hiw-rise 0.5s 2.4s ease forwards;
}

/* 1. Units */
.hiw-chips {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.hiw-chip {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}
.hiw-chip-cur {
  position: relative;
  width: 3.6rem;
  height: 1.7rem;
  overflow: hidden;
}
.hiw-chip-cur b {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  top: 0.25rem;
  opacity: 0;
}
.hiw-chip-cur b:first-child {
  opacity: 1;
}
.is-on .hiw-chip-cur b {
  animation: hiw-cycle 8s infinite;
}
.is-on .hiw-chip-cur b:nth-child(2) {
  animation-delay: 2s;
}
.is-on .hiw-chip-cur b:nth-child(3) {
  animation-delay: 4s;
}
.is-on .hiw-chip-cur b:nth-child(4) {
  animation-delay: 6s;
}
@keyframes hiw-cycle {
  0%,
  24% {
    opacity: 1;
    transform: none;
  }
  25%,
  100% {
    opacity: 0;
    transform: translateY(-100%);
  }
}
.hiw-units {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.hiw-units i {
  height: 26px;
  border-radius: 6px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  opacity: 0;
}
.is-on .hiw-units i {
  animation: hiw-pop 0.35s ease forwards;
}

/* 2. Invite */
.hiw-pair {
  display: flex;
  align-items: center;
  gap: 10px;
}
.hiw-code {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: center;
  padding: 0.5rem;
  border: 2px dashed var(--accent);
  border-radius: 10px;
  margin-bottom: 8px;
  color: var(--accent-strong);
}
.hiw-fly {
  position: relative;
  width: 60px;
  height: 2px;
  background: var(--border);
}
.hiw-fly span {
  position: absolute;
  top: -5px;
  left: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0;
}
.is-on .hiw-fly span {
  animation: hiw-fly 1s 0.8s ease-in-out forwards;
}
@keyframes hiw-fly {
  0% {
    opacity: 1;
    left: 0;
  }
  90% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    left: 48px;
  }
}
.hiw-input {
  font-family: ui-monospace, Menlo, monospace;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: center;
  padding: 0.45rem;
  margin: 30px 0 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: transparent;
}
.is-on .hiw-input {
  animation: hiw-type 0.01s 1.8s forwards;
}
@keyframes hiw-type {
  to {
    color: var(--text);
  }
}
.hiw-ok {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 2rem;
  color: #fff;
  background: var(--ok);
  opacity: 0;
}
.is-on .hiw-ok {
  animation: hiw-pop 0.5s 2.2s ease forwards;
}
.hiw-pair .hiw-phone .hiw-line {
  opacity: 0;
}
.is-on .hiw-pair .hiw-phone .hiw-line {
  animation: hiw-rise 0.4s 2.6s forwards;
}

/* 3. Chat */
.hiw-status {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}
.hiw-status span {
  flex: 1;
  text-align: center;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.2rem 0;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
}
.is-on .hiw-status span {
  animation: hiw-light 0.3s forwards;
}
.is-on .hiw-status span:nth-child(1) {
  animation-delay: 0.6s;
}
.is-on .hiw-status span:nth-child(2) {
  animation-delay: 1.4s;
}
.is-on .hiw-status span:nth-child(3) {
  animation-delay: 3s;
}
@keyframes hiw-light {
  to {
    background: var(--accent);
    color: #fff;
  }
}
.hiw-chat {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.hiw-chat p {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.35;
  padding: 0.45rem 0.65rem;
  border-radius: 12px;
  max-width: 85%;
  opacity: 0;
}
.hiw-chat .me {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.hiw-chat .them {
  align-self: flex-start;
  background: var(--surface-2);
  border-bottom-left-radius: 4px;
}
.is-on .hiw-chat p {
  animation: hiw-rise 0.4s ease forwards;
}
.is-on .hiw-chat p:nth-child(1) {
  animation-delay: 0.5s;
}
.is-on .hiw-chat p:nth-child(2) {
  animation-delay: 1.3s;
}
.is-on .hiw-chat p:nth-child(3) {
  animation-delay: 2.1s;
}
.is-on .hiw-chat p:nth-child(4) {
  animation-delay: 2.9s;
}
.is-on .hiw-chat p:nth-child(5) {
  animation-delay: 3.7s;
}
.hiw-photo {
  display: block;
  width: 100%;
  height: 48px;
  margin-top: 6px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgb(255 255 255 / 45%), rgb(255 255 255 / 15%));
}

/* 4. Gate */
.hiw-qr {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  width: 140px;
  margin: 24px auto 18px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.hiw-qr i {
  aspect-ratio: 1;
  border-radius: 2px;
  background: var(--text);
}
.hiw-qr i:nth-child(3n + 2),
.hiw-qr i:nth-child(7n) {
  background: transparent;
}
.hiw-scan {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  background: var(--ok);
  box-shadow: 0 0 12px var(--ok);
  opacity: 0;
}
.is-on .hiw-scan {
  animation: hiw-scan 1.6s 0.6s ease-in-out 2;
}
@keyframes hiw-scan {
  0% {
    top: 0;
    opacity: 1;
  }
  50% {
    top: calc(100% - 3px);
    opacity: 1;
  }
  100% {
    top: 0;
    opacity: 0;
  }
}
.hiw-allow {
  display: grid;
  gap: 2px;
  text-align: center;
  padding: 0.7rem;
  border-radius: 12px;
  background: var(--ok);
  color: #fff;
  opacity: 0;
}
.hiw-allow strong {
  font-size: 1.15rem;
}
.hiw-allow span {
  font-size: 0.78rem;
}
.is-on .hiw-allow {
  animation: hiw-pop 0.45s 3.9s ease forwards;
}

/* 5. Invoice */
.hiw-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.hiw-row span {
  color: var(--muted);
}
.hiw-invoice .hiw-pay {
  opacity: 0;
}
.is-on .hiw-invoice .hiw-pay {
  animation: hiw-rise 0.4s 0.9s forwards;
}
.hiw-total {
  border-bottom: 0;
  font-size: 1rem;
}
.hiw-total b {
  position: relative;
}
.hiw-zero {
  position: absolute;
  right: 0;
  opacity: 0;
  color: var(--ok) !important;
}
.is-on .hiw-due {
  animation: hiw-out 0.3s 1.6s forwards;
}
.is-on .hiw-zero {
  animation: hiw-rise 0.3s 1.7s forwards;
}
@keyframes hiw-out {
  to {
    opacity: 0;
  }
}
.hiw-stamp {
  position: absolute;
  right: 120px;
  bottom: 52px;
  padding: 0.2rem 0.8rem;
  border: 3px solid var(--ok);
  border-radius: 8px;
  color: var(--ok);
  font-weight: 800;
  font-size: 1.3rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  rotate: -12deg;
  opacity: 0;
}
.is-on .hiw-stamp {
  animation: hiw-stamp 0.4s 1.9s cubic-bezier(0.3, 1.6, 0.5, 1) forwards;
}
@keyframes hiw-stamp {
  from {
    opacity: 0;
    transform: scale(2.2);
  }
  to {
    opacity: 0.9;
    transform: scale(1);
  }
}

/* 6. Dashboard */
.hiw-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.hiw-stats div {
  padding: 0.6rem;
  border-radius: 10px;
  background: var(--surface-2);
}
.hiw-stats small {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
}
.hiw-stats small:last-child {
  display: inline;
}
.hiw-stats b {
  font-size: 1.5rem;
}
.hiw-bars {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 90px;
}
.hiw-bars i {
  flex: 1;
  border-radius: 6px 6px 0 0;
  background: var(--accent);
  height: 0;
  transition: height 0.9s ease;
}
.is-on .hiw-bars i:nth-child(1) {
  height: 45%;
}
.is-on .hiw-bars i:nth-child(2) {
  height: 62%;
  transition-delay: 0.1s;
}
.is-on .hiw-bars i:nth-child(3) {
  height: 55%;
  transition-delay: 0.2s;
}
.is-on .hiw-bars i:nth-child(4) {
  height: 78%;
  transition-delay: 0.3s;
}
.is-on .hiw-bars i:nth-child(5) {
  height: 70%;
  transition-delay: 0.4s;
}
.is-on .hiw-bars i:nth-child(6) {
  height: 92%;
  transition-delay: 0.5s;
}

/* Landlord calendar */
.hiw-cal {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.hiw-cal i {
  aspect-ratio: 1;
  border-radius: 6px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-style: normal;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--muted);
}
.is-on .hiw-cal .hiw-day {
  animation: hiw-light 0.4s 0.8s forwards, hiw-pulse 1s 1.2s 2;
}
@keyframes hiw-pulse {
  50% {
    transform: scale(1.18);
  }
}

/* Stagger the unit tiles. */
.hiw-units i:nth-child(1) { animation-delay: 0.3s; }
.hiw-units i:nth-child(2) { animation-delay: 0.38s; }
.hiw-units i:nth-child(3) { animation-delay: 0.46s; }
.hiw-units i:nth-child(4) { animation-delay: 0.54s; }
.hiw-units i:nth-child(5) { animation-delay: 0.62s; }
.hiw-units i:nth-child(6) { animation-delay: 0.7s; }
.hiw-units i:nth-child(7) { animation-delay: 0.78s; }
.hiw-units i:nth-child(8) { animation-delay: 0.86s; }
.hiw-units i:nth-child(9) { animation-delay: 0.94s; }
.hiw-units i:nth-child(10) { animation-delay: 1.02s; }
.hiw-units i:nth-child(11) { animation-delay: 1.1s; }
.hiw-units i:nth-child(12) { animation-delay: 1.18s; }
.hiw-units i:nth-child(13) { animation-delay: 1.26s; }
.hiw-units i:nth-child(14) { animation-delay: 1.34s; }
.hiw-units i:nth-child(15) { animation-delay: 1.42s; }
.hiw-units i:nth-child(16) { animation-delay: 1.5s; }

/* For people who prefer less motion: scenes jump to their finished state. */
@media (prefers-reduced-motion: reduce) {
  .hiw-step *,
  .hiw-step *::before {
    animation-duration: 0.01s !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01s !important;
    transition-delay: 0s !important;
  }
}

@media (max-width: 860px) {
  .hiw-step {
    grid-template-columns: 1fr;
    gap: 24px;
    padding: 28px 0 28px 60px;
  }
  .hiw-num {
    top: 28px;
    translate: none;
    width: 38px;
    height: 38px;
  }
  .hiw-track::before {
    left: 18px;
  }
  .hiw-visual {
    justify-content: flex-start;
    min-height: 0;
  }
}
@media (max-width: 520px) {
  .hiw-step {
    padding-left: 48px;
  }
  .hiw-num {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
  }
  .hiw-track::before {
    left: 15px;
  }
  .hiw-pair {
    flex-direction: column;
  }
  .hiw-fly {
    width: 2px;
    height: 30px;
  }
  .hiw-fly span {
    display: none;
  }
  .hiw-desk-sm {
    width: 220px;
  }
  .hiw-tab {
    padding: 0.5rem 0.8rem;
    font-size: 0.88rem;
  }
}
