@layer tokens {
  @property --flip {
    syntax: "<number>";
    /* children below read the parent's --flip in their own flex-basis calc(), so it must inherit */
    inherits: true;
    initial-value: 0;
  }
}

@layer layout {
  .stage {
    --stage-max: 750px;
  }
}

@layer components {
  .panel {
    --bp: 30rem;
    --switch: clamp(0px, (var(--bp) - 100cqi) * 999, 1px);
    /* identical formula to demo 16's --flip, but because it's registered as a typed <number>
       above, the browser can interpolate it — an unregistered custom property can only ever
       jump discretely, which is why demo 16's version snaps instead of easing */
    --flip: calc(var(--switch) / 1px);
    display: flex;
    flex-wrap: wrap;
    gap: calc((1 - var(--flip)) * var(--space-12));
    border-radius: calc((1 - var(--flip)) * var(--radius-l));
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    overflow: hidden;

    @media (prefers-reduced-motion: no-preference) {
      /* transitioning the custom property itself is enough: every calc() that reads
         var(--flip) below, including the children's flex-basis, recomputes every frame as
         this one value eases from 0 to 1 */
      transition: --flip .35s ease;
    }

    > .side,
    > .content {
      flex-grow: 1;
      flex-basis: calc(var(--flip) * 999%);
      padding: var(--space-12);
    }

    > .side {
      background: var(--color-surface-2);
    }
  }
}
