/*
 * Leverva feature animations for leverva.app.
 *
 * Four small scenes drawn in HTML and CSS in the four-place design, to replace
 * the old MP4s in the Features section. Everything is sized from the box's
 * width (1em = 1/38 of it), so the scenes stay sharp at any size.
 *
 * Mount: <div class="lva" data-lva="handbook|gaps|verify|setup" role="img"
 *          aria-label="…"></div>  plus leverva-animations.js
 */

.lva {
  /* Colours from the app's theme (src/app/globals.css). */
  --lva-purple: #6700F4;
  --lva-purple-mid: #9056ED;
  --lva-purple-dark: #5200C4;
  --lva-purple-darker: #3D0094;
  --lva-purple-light: #EDE6FF;
  --lva-blue: #61A3F2;
  --lva-bg: #EEF2FF;
  --lva-white: #FFFFFF;
  --lva-strip: #F6F8FF;
  --lva-field: #FBFCFF;
  --lva-ink-1: #222530;
  --lva-ink-2: #4B4F5E;
  --lva-ink-3: #676A88;
  --lva-border: #DDE3FA;
  --lva-border-strong: #C9D2F5;
  --lva-success-bg: #E3F7EE;
  --lva-success-text: #145C3A;
  --lva-dot-ready: #2E9E6A;
  --lva-warning-bg: #FFF1DE;
  --lva-warning-text: #7A4400;
  --lva-info-bg: #E6F1FC;
  --lva-info-text: #1B4F86;
  --lva-checked-bg: #E6E9F2;
  --lva-checked-text: #3A3F4E;
  --lva-shadow-1: 0 1px 3px rgba(26, 26, 46, 0.08);
  --lva-shadow-2: 0 4px 16px rgba(26, 26, 46, 0.10);
  --lva-shadow-3: 0 8px 32px rgba(26, 26, 46, 0.16);
  --lva-font-sans: 'DM Sans Variable', 'DM Sans', system-ui, -apple-system, sans-serif;
  --lva-font-display: portada, 'Literata', Georgia, serif;
  --lva-ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  position: relative;
  container-type: inline-size;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--lva-bg);
  border-radius: inherit;
  font-family: var(--lva-font-sans);
  color: var(--lva-ink-1);
  -webkit-font-smoothing: antialiased;

  & *,
  & *::before,
  & *::after {
    box-sizing: border-box;
  }

  & p,
  & h3,
  & h4 {
    margin: 0;
  }

  /* Reduced motion, or paused: no transitions, the scene shows its last frame. */
  &.is-still * {
    transition: none !important;
    animation: none !important;
  }
}

/* The canvas: 38em wide by about 21.4em high, whatever the box size. */
.lva__stage {
  position: absolute;
  inset: 0;
  display: flex;
  font-size: calc(100cqw / 38);
  line-height: 1.4;
  transition: opacity 0.4s ease;

  &.is-out {
    opacity: 0;
  }
}

/* ── Icons ─────────────────────────────────────────── */
.lva-ic {
  flex: none;
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Side menu ─────────────────────────────────────── */
.lva-side {
  flex: 0 0 9em;
  display: flex;
  flex-direction: column;
  gap: 0.25em;
  padding: 1.2em 0.7em;
  overflow: hidden;
  white-space: nowrap;
  background: var(--lva-white);
  border-right: 1px solid var(--lva-border);
  transition: flex-basis 0.6s var(--lva-ease), padding 0.6s var(--lva-ease), opacity 0.4s ease;

  &.is-hidden {
    flex-basis: 0;
    padding-inline: 0;
    opacity: 0;
  }
}

.lva-logo {
  display: flex;
  align-items: center;
  gap: 0.14em;
  margin: 0 0 0.9em 0.45em;

  & i {
    width: 0.26em;
    height: 1em;
    border-radius: 0.08em;
    background: var(--lva-purple-darker);

    &:nth-child(2) { background: var(--lva-purple-mid); }
    &:nth-child(3) { background: var(--lva-blue); }
  }

  & span {
    margin-left: 0.3em;
    font-family: var(--lva-font-display);
    font-size: 1.1em;
    font-weight: 500;
    line-height: 1;
  }
}

.lva-nav {
  display: flex;
  align-items: center;
  gap: 0.55em;
  height: 1.85em;
  padding: 0 0.6em;
  border-radius: 0.55em;
  color: var(--lva-ink-1);
  transition: background 0.3s ease, color 0.3s ease;

  & .lva-ic {
    width: 0.9em;
    height: 0.9em;
  }

  & span {
    flex: 1;
    font-size: 0.72em;
    font-weight: 500;
  }

  &.is-active {
    background: var(--lva-purple);
    color: var(--lva-white);

    & .lva-badge {
      background: var(--lva-white);
    }
  }
}

.lva-badge {
  min-width: 2.2em;
  padding: 0.25em 0.6em;
  border-radius: 999px;
  background: var(--lva-purple-light);
  color: var(--lva-purple-darker);
  font-size: 0.52em;
  font-weight: 700;
  text-align: center;
}

/* ── Page area and views ───────────────────────────── */
.lva-main {
  position: relative;
  flex: 1;
  min-width: 0;
}

.lva-view {
  position: absolute;
  inset: 1.3em 1.5em 0;
  opacity: 0;
  translate: 0 0.6em;
  transition: opacity 0.45s ease, translate 0.45s var(--lva-ease);

  &.is-on {
    opacity: 1;
    translate: 0 0;
  }
}

/* ── Type ──────────────────────────────────────────── */
.lva-h {
  font-family: var(--lva-font-display);
  font-size: 1.4em;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.lva-h4 {
  font-family: var(--lva-font-display);
  font-size: 0.95em;
  font-weight: 600;
  line-height: 1.2;
}

.lva-kicker {
  margin-bottom: 0.2em;
  color: var(--lva-ink-2);
  font-size: 0.56em;
  font-weight: 700;
}

.lva-eyebrow {
  color: var(--lva-purple-dark);
  font-size: 0.52em;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.lva-sub {
  margin-top: 0.55em;
  color: var(--lva-ink-3);
  font-size: 0.62em;
}

.lva-t {
  font-size: 0.64em;
}

.lva-strong {
  font-size: 0.7em;
  font-weight: 700;
}

.lva-body {
  color: var(--lva-ink-2);
  font-size: 0.62em;
  line-height: 1.55;
}

.lva-meta {
  color: var(--lva-ink-3);
  font-size: 0.56em;
}

/* ── Building blocks ───────────────────────────────── */
.lva-card {
  background: var(--lva-white);
  border: 1px solid var(--lva-border);
  border-radius: 0.8em;
  box-shadow: var(--lva-shadow-1);
}

.lva-row {
  display: flex;
  align-items: center;
  gap: 0.4em;
}

.lva-stack {
  display: flex;
  flex-direction: column;
}

.lva-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.45em 0.75em;
  border-radius: 999px;
  font-size: 0.52em;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;

  & .lva-ic {
    width: 1.1em;
    height: 1.1em;
    stroke-width: 3;
  }

  &.lva-tag--ok { background: var(--lva-success-bg); color: var(--lva-success-text); }
  &.lva-tag--warn { background: var(--lva-warning-bg); color: var(--lva-warning-text); }
  &.lva-tag--info { background: var(--lva-info-bg); color: var(--lva-info-text); }
  &.lva-tag--checked { background: var(--lva-checked-bg); color: var(--lva-checked-text); }
  &.lva-tag--purple { background: var(--lva-purple-light); color: var(--lva-purple-darker); }
}

.lva-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  padding: 0.6em 1.1em;
  border: 1px solid var(--lva-purple);
  border-radius: 0.7em;
  background: var(--lva-purple);
  color: var(--lva-white);
  font-size: 0.56em;
  font-weight: 700;
  white-space: nowrap;
  transition: transform 0.15s ease, background 0.2s ease;

  &.lva-btn--quiet {
    background: var(--lva-white);
    border-color: var(--lva-border-strong);
    color: var(--lva-ink-1);
  }

  &.is-pressed {
    transform: scale(0.94);
    background: var(--lva-purple-dark);
  }
}

.lva-field {
  display: flex;
  align-items: center;
  gap: 0.5em;
  min-height: 2.3em;
  padding: 0.3em 0.3em 0.3em 0.8em;
  border: 2px solid var(--lva-purple);
  border-radius: 0.75em;
  background: var(--lva-white);
}

.lva-typed {
  flex: 1;
  font-size: 0.66em;

  &:empty::before {
    content: attr(data-ph);
    color: var(--lva-ink-3);
  }

  &.is-typing::after {
    content: '';
    display: inline-block;
    width: 1px;
    height: 1.1em;
    margin-left: 1px;
    vertical-align: -0.2em;
    background: currentColor;
    animation: lva-blink 0.9s steps(1) infinite;
  }
}

.lva-skel {
  height: 0.42em;
  border-radius: 0.2em;
  background: var(--lva-border);

  &.is-short {
    width: 60%;
  }
}

.lva-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.4em 0.75em;
  border: 1px solid var(--lva-border-strong);
  border-radius: 999px;
  background: var(--lva-white);
  font-size: 0.52em;
  font-weight: 500;
  white-space: nowrap;

  & b {
    display: grid;
    place-items: center;
    width: 1.6em;
    height: 1.6em;
    margin-left: -0.35em;
    border-radius: 50%;
    background: var(--lva-purple-light);
    color: var(--lva-purple-darker);
    font-size: 0.85em;
  }
}

.lva-avatar {
  display: grid;
  place-items: center;
  width: 1.5em;
  height: 1.5em;
  border-radius: 50%;
  background: var(--lva-purple-light);
  color: var(--lva-purple-darker);

  & span {
    font-size: 0.6em;
    font-weight: 700;
  }
}

.lva-bar {
  flex: none;
  width: 5em;
  height: 0.32em;
  border-radius: 999px;
  background: var(--lva-border);
  overflow: hidden;

  & i {
    display: block;
    height: 100%;
    width: var(--lva-fill, 0%);
    border-radius: inherit;
    background: var(--lva-purple);
    transition: width 0.7s var(--lva-ease);
  }
}

/* ── Motion helpers ────────────────────────────────── */

/* Hidden until the scene turns it on. */
.lva-in {
  opacity: 0;
  transform: translateY(0.5em);
  transition: opacity 0.45s ease, transform 0.45s var(--lva-ease);

  &.is-on {
    opacity: 1;
    transform: none;
  }
}

.lva-collapse {
  max-height: 12em;
  overflow: hidden;
  transition: max-height 0.55s var(--lva-ease), opacity 0.3s ease, margin 0.55s var(--lva-ease),
    padding 0.55s var(--lva-ease), border-width 0.55s ease;

  &.is-gone {
    max-height: 0;
    margin: 0;
    padding-block: 0;
    border-width: 0;
    opacity: 0;
  }
}

.is-pop {
  animation: lva-pop 0.45s var(--lva-ease);
}

.is-glow {
  animation: lva-glow 1.4s ease;
}

/* The pointer that clicks things. */
.lva-cursor {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 5;
  width: 1.2em;
  height: 1.2em;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.75s var(--lva-ease), opacity 0.3s ease;

  &.is-on {
    opacity: 1;
  }

  & svg {
    width: 100%;
    height: 100%;
    fill: var(--lva-ink-1);
    stroke: var(--lva-white);
    stroke-width: 1.5;
    stroke-linejoin: round;
    filter: drop-shadow(0 1px 2px rgba(26, 26, 46, 0.3));
  }

  &::before {
    content: '';
    position: absolute;
    top: -0.5em;
    left: -0.5em;
    width: 1em;
    height: 1em;
    border-radius: 50%;
    background: var(--lva-purple);
    opacity: 0;
    transform: scale(0.2);
  }

  &.is-click::before {
    animation: lva-ripple 0.5s ease-out;
  }

  &.is-click svg {
    animation: lva-press 0.3s ease;
  }
}

/* Pause and play, for anyone who wants the movement to stop (WCAG 2.2.2). */
.lva-toggle {
  position: absolute;
  left: 3cqw;
  bottom: 3cqw;
  z-index: 6;
  display: grid;
  place-items: center;
  width: max(28px, 5.5cqw);
  height: max(28px, 5.5cqw);
  padding: 0;
  border: 1px solid var(--lva-border-strong);
  border-radius: 50%;
  background: var(--lva-white);
  color: var(--lva-ink-1);
  box-shadow: var(--lva-shadow-1);
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.2s ease;

  &:hover,
  &:focus-visible {
    opacity: 1;
  }

  &:focus-visible {
    outline: 2px solid var(--lva-purple);
    outline-offset: 2px;
  }

  & svg {
    width: 45%;
    height: 45%;
    fill: currentColor;
  }
}

@keyframes lva-blink {
  50% { opacity: 0; }
}

@keyframes lva-pop {
  0% { transform: scale(0.85); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes lva-glow {
  0%, 100% { box-shadow: var(--lva-shadow-1); }
  30% { box-shadow: 0 0 0 0.2em var(--lva-purple-light), var(--lva-shadow-2); }
}

@keyframes lva-ripple {
  0% { opacity: 0.35; transform: scale(0.2); }
  100% { opacity: 0; transform: scale(2); }
}

@keyframes lva-press {
  50% { transform: scale(0.85); }
}

/* ── Scene: guides write themselves ────────────────── */
.lva-guide {
  & .lva-head {
    display: flex;
    align-items: center;
    gap: 0.6em;
    margin-top: 0.35em;
  }

  & .lva-split {
    display: grid;
    grid-template-columns: 12.6em 1fr;
    gap: 0.7em;
    margin-top: 0.8em;
  }

  & .lva-toc {
    display: flex;
    flex-direction: column;
    gap: 0.1em;
    padding: 0.4em;
  }

  & .lva-toc .lva-row {
    justify-content: space-between;
    min-height: 1.65em;
    padding: 0.2em 0.5em;
    border-radius: 0.5em;
    transition: background 0.3s ease;

    &.is-active {
      background: var(--lva-bg);

      & .lva-t {
        font-weight: 700;
      }
    }
  }

  & .lva-detail {
    position: relative;
  }

  & .lva-doc {
    display: flex;
    flex-direction: column;
    gap: 0.5em;
    height: 100%;
    padding: 0.85em 0.95em;
  }

  & .lva-skels {
    display: flex;
    flex-direction: column;
    gap: 0.45em;
    margin-top: 0.2em;
    transition: opacity 0.3s ease;

    &.is-gone {
      opacity: 0;
    }
  }

  /* The placeholder lines and the written text share one spot. */
  & .lva-docbody {
    display: grid;

    & > * {
      grid-area: 1 / 1;
    }
  }

  & .lva-incoming {
    position: absolute;
    right: -0.3em;
    bottom: 0.4em;
    width: 13.4em;
    padding: 0.7em 0.8em;
    box-shadow: var(--lva-shadow-3);
    transition: opacity 0.45s ease, transform 0.75s var(--lva-ease);

    &.is-sent {
      opacity: 0;
      transform: translate(-10em, -4em) scale(0.25);
    }
  }
}

/* ── Scene: questions nobody can answer yet ────────── */
.lva-ask {
  & .lva-field {
    margin-top: 0.8em;
  }

  & .lva-answer {
    margin-top: 0.7em;
    padding: 0.85em 0.95em;
  }
}

.lva-qlist {
  display: flex;
  flex-direction: column;
  gap: 0.45em;
  margin-top: 0.8em;
}

.lva-q {
  display: flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.65em 0.8em;
  transition: opacity 0.45s ease, transform 0.45s var(--lva-ease), translate 0.6s var(--lva-ease),
    border-color 0.4s ease;

  & .lva-stack {
    flex: 1;
    gap: 0.3em;
  }

  &.is-new {
    border-color: var(--lva-purple);
  }
}

/* ── Scene: answers people have checked ────────────── */
.lva-check {
  & .lva-item {
    margin-top: 0.7em;
    padding: 0.8em 0.9em;
  }

  & .lva-item .lva-stack {
    gap: 0.35em;
  }

  & .lva-acts {
    margin-top: 0.2em;
  }
}

.lva-src {
  padding: 0.45em 0.65em;
  border-radius: 0.6em;
  background: var(--lva-strip);
  border: 1px solid var(--lva-border);

  & .lva-stack {
    gap: 0.3em;
  }
}

/* ── Scene: set up in a few minutes ────────────────── */
.lva-setup {
  width: 19em;
  margin: 1.1em auto 0;
  padding: 1em 1.1em;

  & .lva-stack {
    gap: 0.4em;
  }

  & .lva-field {
    border-width: 1.5px;
  }

  & .lva-found {
    padding: 0.6em 0.7em;
    border-radius: 0.6em;
    background: var(--lva-strip);
    border: 1px solid var(--lva-border);
  }
}

.lva-home {
  & .lva-banner {
    display: flex;
    align-items: center;
    gap: 0.8em;
    padding: 0.5em 0.85em;

    & .lva-bar {
      width: 3.5em;
    }
  }

  & .lva-checklist {
    margin-top: 0.55em;
    padding: 0.7em 0.9em 0.3em;
    border: 1.5px solid var(--lva-purple);
  }

  & .lva-checkhead {
    display: flex;
    align-items: center;
    gap: 0.6em;
    padding-bottom: 0.45em;
  }
}

.lva-step {
  display: flex;
  gap: 0.6em;
  padding: 0.35em 0.3em;
  border-top: 1px solid var(--lva-border);
  border-radius: 0.4em;
  transition: background 0.3s ease;

  & .lva-stack {
    flex: 1;
    gap: 0.3em;
  }

  & .lva-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3em;
  }

  &.is-current {
    background: var(--lva-strip);
  }
}

/* The round tick beside each set-up step. */
.lva-done {
  display: grid;
  flex: none;
  place-items: center;
  width: 1.1em;
  height: 1.1em;
  border: 1.5px solid var(--lva-border-strong);
  border-radius: 50%;
  color: transparent;
  transition: background 0.3s ease, border-color 0.3s ease, color 0.3s ease;

  & .lva-ic {
    width: 0.7em;
    height: 0.7em;
    stroke-width: 3.5;
  }

  .is-done & {
    background: var(--lva-dot-ready);
    border-color: var(--lva-dot-ready);
    color: var(--lva-white);
  }
}

/* Small layout helpers used inside the scenes. */
.lva-stack.lva-tight {
  gap: 0.35em;
}

.lva-grow {
  flex: 1;
}
