.demo-section {
  padding-block: var(--block-space-lg);
  padding-inline: 1rem;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: none;
  /* text-align: center; */
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: var(--block-space-lg);

  /* Fallback state (used by Firefox/unsupported browsers, and as JS fallback base) */
  --demo-scale-x: 1;
  --demo-radius: var(--border-radius-lg);
}

.demo-section > * {
  position: relative;
  z-index: 1;
}

.demo-section::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: var(--demo-bg);
  will-change: transform, border-radius;
  transform-origin: center center;
  transform: scaleX(var(--demo-scale-x, 1));
  border-radius: var(--demo-radius, var(--border-radius-lg));
}

.demo-section {
  --demo-bg: var(--neutral-200);
  /* --demo-bg:
    radial-gradient(
      circle at 70% 120%,
      var(--brand-accent-100),
      transparent 60%
    ),
    linear-gradient(to top, rgb(235 240 248) 0%, rgb(235 240 248) 100%); */
}

@keyframes demoScaleInOutOnScroll {
  0% {
    transform: scaleX(0.677);
    border-radius: var(--border-radius-xs);
  }

  30% {
    transform: scaleX(1) scaleY(1);
    border-radius: var(--border-radius-lg);
  }

  90% {
    transform: scaleX(1) scaleY(1);
    border-radius: var(--border-radius-lg);
  }

  100% {
    transform: scaleX(0.677);
    border-radius: var(--border-radius-xs);
  }
}

/* Scroll-driven animations (supported browsers only) */
@supports (animation-timeline: --demo-timeline) {
  .demo-section {
    view-timeline-name: --demo-timeline;
  }

  .demo-section::before {
    animation: demoScaleInOutOnScroll linear forwards;
    animation-timeline: --demo-timeline;
    animation-range: entry 0% exit 100%;
  }
}

.demo {
  /* max-width: fit-content;
  position: relative; */

  display: flex;
  gap: 60px;
  padding-bottom: var(--block-space-lg);

  .floating-box {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 180px;

    text-align: left;
    z-index: 1;
    position: absolute;
    /* box-shadow: 0 0 24px 0px var(--brand-accent); */

    /* color: var(--neutral-800); */
    padding: 1rem;
    /* width: clamp(180px, 18vw, 240px); */

    /* 4px -1px 2px -1px inset rgba(255, 255, 255, 0.7); */

    will-change: transform;
    border-radius: var(--border-radius-xs);
    top: -2%;
    --base-x: 0px;
    --base-y: 0px;
    --drift-x: 10px;
    --drift-y: 14px;
    --rot-0: -0.4deg;
    --rot-50: 0.4deg;

    box-shadow:
      -4px -10px 13px 0 inset rgba(255, 255, 255, 0.3),
      1px 1px 0 -1px inset rgba(255, 255, 255, 0.9),
      1px 1px 2px -1px inset rgba(255, 255, 255, 0.9),
      0px -1px 2px -1px inset rgba(255, 255, 255, 0.7),
      0 0 24px 0px var(--brand-accent);
    /* 4px -1px 2px -1px inset rgba(255, 255, 255, 0.7); */
    background: #fff;
    color: var(--neutral-800);
    border: 1px solid var(--neutral-800);

    @media (max-width: 768px) {
      position: static;
      width: min(420px, 92%);
      transform: none;
      animation: none;
    }

    @media (prefers-reduced-motion: reduce) {
      animation: none !important;
      transform: translate3d(var(--base-x), var(--base-y), 0) !important;
    }

    .floating-box-icon {
      width: 46px;
      height: 46px;
    }
  }

  .demo-media {
    overflow: hidden;
    /* border-radius: var(--border-radius-lg);
    border: 1px solid var(--neutral-300); */
  }

  .floating-box:nth-of-type(1) {
    left: 0;
    --base-x: clamp(-84px, -7vw, -44px);
    --drift-x: 12px;
    --drift-y: 18px;
    animation: floatSoft 10s cubic-bezier(0.45, 0, 0.55, 1) infinite;
  }

  .floating-box:nth-of-type(2) {
    right: 0;
    top: -4%;
    --base-x: clamp(44px, 7vw, 84px);
    --drift-x: -12px;
    --drift-y: 16px;
    --rot-0: 0.4deg;
    --rot-50: -0.4deg;
    animation: floatSoft 10s cubic-bezier(0.45, 0, 0.55, 1) infinite;
    animation-delay: -5s;
  }

  .floating-box:nth-of-type(3) {
    left: 0;
    top: auto;
    bottom: 2%;
    --base-x: clamp(-180px, -12vw, -90px);
    --drift-x: 10px;
    --drift-y: -16px;
    --rot-0: -0.3deg;
    --rot-50: 0.3deg;
    animation: floatSoft 11s cubic-bezier(0.45, 0, 0.55, 1) infinite;
    animation-delay: -3s;
  }

  .floating-box:nth-of-type(4) {
    right: 0;
    top: auto;
    bottom: 5%;
    --base-x: clamp(44px, 7vw, 84px);
    --drift-x: -10px;
    --drift-y: -18px;
    --rot-0: 0.3deg;
    --rot-50: -0.3deg;
    animation: floatSoft 11s cubic-bezier(0.45, 0, 0.55, 1) infinite;
    animation-delay: -8s;
  }
}

@keyframes floatSoft {
  0%,
  100% {
    transform: translate3d(var(--base-x), var(--base-y), 0) rotate(var(--rot-0));
  }

  50% {
    transform: translate3d(
        calc(var(--base-x) + var(--drift-x)),
        calc(var(--base-y) + var(--drift-y)),
        0
      )
      rotate(var(--rot-50));
  }
}

.schema {
  display: flex;
  gap: 2rem;
  width: 100%;
  max-width: 1290px;
  overflow: hidden;
}

/* ── Sidebar ── */
.demo-nav {
  flex: 0 0 300px;
  max-width: 300px;

  /* overflow-y: auto; */
}

.demo-nav-item:not(:last-child) {
  border-bottom: 1px solid var(--neutral-300);
}

.demo-nav-item-btn {
  appearance: none;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block: 16px;
  border: none;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font-weight: 500;
  gap: 8px;
  transition: color 0.2s;
  font-size: 20px;
}

.acc-chevron {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  transition:
    transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
    color 0.2s;
}

.demo-nav-item-btn.active .acc-chevron {
  transform: rotate(180deg);
}

.demo-nav-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.demo-nav-body.open {
  grid-template-rows: 1fr;
}

.demo-nav-body-inner {
  overflow: hidden;
}

.demo-nav-body p {
  padding-bottom: 0.85rem;
}

/* ── Right panel ── */
.demo-viewer {
  flex: 1;
  position: relative;
  overflow: hidden;
  width: 100%;

  border-radius: var(--border-radius-lg);
  border: 1px solid var(--neutral-300);
  aspect-ratio: 966/556;
}

.demo-viewer-item {
  position: absolute;
  inset: 0;
  opacity: 0;

  transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.demo-viewer-item.active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.demo-viewer-item :is(img, svg) {
  width: 100%;
  height: 100%;
  /* object-fit: contain; */
  display: block;
}

@media (prefers-reduced-motion: reduce) {
  .demo-nav-body,
  .demo-viewer-item,
  .acc-chevron {
    transition: none;
  }
}

@media (max-width: 768px) {
  .demo {
    flex-direction: column;
    height: auto;
  }

  .demo-nav {
    flex: none;
    max-width: none;
  }

  .demo-viewer {
    min-height: 280px;
  }
}
