@layer pw-ui {
  /* The frame uses the same sidebar tokens as the theme generator. */
  .pw-app-frame {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    min-height: 0;
    isolation: isolate;
    background: var(--theme-sidebar-bg, var(--theme-muted-panel-bg));
    color: var(--theme-app);
  }
  .pw-frame-body {
    display: flex;
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
  }
  .pw-frame-sidebar,
  .pw-frame-drawer {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    min-height: 0;
    background: var(--theme-sidebar-bg, var(--theme-muted-panel-bg));
    color: var(--theme-sidebar-text, var(--theme-app));
  }
  /* The navigation's colors, with the fallbacks its own items use, resolved here so content a page
     puts in the navigation can take them on without repeating every fallback. */
  .pw-frame-sidebar,
  .pw-frame-drawer {
    --pw-frame-bg: var(--theme-sidebar-bg, var(--theme-muted-panel-bg));
    --pw-frame-ink: var(--theme-sidebar-text, var(--theme-app));
    --pw-frame-hover: var(--theme-sidebar-hover, var(--theme-hover));
    --pw-frame-active-bg: var(--theme-sidebar-active-bg, var(--theme-accent-subtle));
    --pw-frame-active-ink: var(--theme-sidebar-active-text, var(--theme-accent));
    /* Each ink halfway to full contrast, as a hovered item's text is: a translucent ink also
       gains half its missing opacity. */
    --pw-frame-ink-strong: oklch(
      from var(--pw-frame-ink) calc(l + (l - 0.5) * 0.5) c h /
      calc(alpha + (1 - alpha) * 0.5)
    );
    --pw-frame-active-ink-strong: oklch(
      from var(--pw-frame-active-ink) calc(l + (l - 0.5) * 0.5) c h /
      calc(alpha + (1 - alpha) * 0.5)
    );
  }
  .pw-frame-sidebar {
    position: relative;
    transition: width 200ms cubic-bezier(0.25, 0.1, 0.25, 1);
  }
  .pw-frame-sidebar[data-resizing] {
    transition: none;
    user-select: none;
  }
  .pw-frame-brand {
    padding: 12px 12px 4px;
    flex-shrink: 0;
    min-width: 0;
    overflow: hidden;
  }
  .pw-frame-links {
    flex: 1;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 12px;
    min-width: 0;
    min-height: 0;
    scrollbar-width: none;
  }
  .pw-frame-links::-webkit-scrollbar {
    display: none;
  }
  .pw-frame-links nav {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }
  .pw-frame-footer {
    flex-shrink: 0;
    padding: 8px 12px;
  }
  .pw-frame-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 8px;
    padding: 0;
    color: inherit;
    background: transparent;
    cursor: pointer;
    flex-shrink: 0;
  }
  .pw-frame-toggle:hover {
    background: var(--theme-sidebar-hover, var(--theme-hover));
  }
  .pw-frame-toggle svg {
    width: 18px;
    height: 18px;
  }
  .pw-frame-sidebar :focus-visible,
  .pw-frame-drawer :focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
  }
  .pw-frame-resize {
    position: absolute;
    z-index: 1;
    inset-block: 0;
    inset-inline-end: -4px;
    width: 8px;
    cursor: col-resize;
    touch-action: none;
  }
  .pw-frame-resize::after {
    content: "";
    position: absolute;
    inset-block: 8px;
    inset-inline-start: 3px;
    width: 2px;
    border-radius: 2px;
  }
  .pw-frame-resize:hover::after,
  .pw-frame-resize:focus-visible::after {
    background: var(--theme-sidebar-text, var(--theme-accent));
    opacity: 0.5;
  }
  .pw-frame-surface-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    padding: 8px;
    padding-inline-start: 0;
  }
  .pw-frame-surface {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    isolation: isolate;
    border: 1px solid var(--theme-border);
    border-radius: 12px;
    background: var(--theme-app-bg);
    background-clip: padding-box;
  }
  .pw-frame-header,
  .pw-frame-banner {
    flex-shrink: 0;
  }
  .pw-frame-main {
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow: auto;
  }
  .pw-app-frame[data-full-bleed] .pw-frame-surface-wrap {
    padding: 0;
  }
  .pw-app-frame[data-full-bleed] .pw-frame-surface {
    border: 0;
    border-radius: 0;
  }
  .pw-app-frame[data-mobile] .pw-frame-surface-wrap {
    padding: 8px;
  }
  .pw-app-frame[data-mobile][data-full-bleed] .pw-frame-surface-wrap {
    padding: 0;
  }
  .pw-frame-backdrop {
    position: absolute;
    inset: 0;
    z-index: var(--layer-drawer, 1100);
    background: var(--theme-backdrop, rgb(0 0 0 / 0.35));
    transition: opacity 200ms cubic-bezier(0.25, 0.1, 0.25, 1);
  }
  .pw-frame-backdrop[data-starting-style],
  .pw-frame-backdrop[data-ending-style] {
    opacity: 0;
  }
  .pw-frame-drawer {
    position: absolute;
    inset-block: 8px;
    inset-inline-start: 8px;
    max-width: calc(100% - 48px);
    z-index: var(--layer-drawer, 1100);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgb(0 0 0 / 0.2);
    outline: none;
    transform: translateX(0);
    transition: transform 200ms cubic-bezier(0.25, 0.1, 0.25, 1);
  }
  .pw-frame-drawer[data-starting-style],
  .pw-frame-drawer[data-ending-style] {
    transform: translateX(calc(-100% - 16px));
  }
  .pw-frame-drawer:dir(rtl)[data-starting-style],
  .pw-frame-drawer:dir(rtl)[data-ending-style] {
    transform: translateX(calc(100% + 16px));
  }
  .pw-frame-mobile-close {
    display: flex;
    justify-content: flex-end;
    padding: 4px 4px 0;
  }
  /* Room for a focused brand link's outline (2px at a 2px offset), which the brand's hidden
     overflow would otherwise cut off at the top, under the drawer's close button. */
  .pw-frame-drawer .pw-frame-brand {
    padding-top: 4px;
  }
  .pw-app-frame[data-mobile] .pw-frame-toggle {
    min-height: 44px;
  }
  .pw-app-frame[data-mobile] .pw-frame-toggle {
    width: 44px;
    height: 44px;
  }
  .pw-frame-skip {
    position: fixed;
    inset-block-start: -100px;
    inset-inline-start: 8px;
    padding: 8px 16px;
    border-radius: 6px;
    background: var(--theme-panel-bg);
    color: var(--theme-app);
    z-index: var(--layer-popover, 1400);
  }
  .pw-frame-skip:focus {
    inset-block-start: 8px;
  }
  @media (prefers-reduced-motion: reduce) {
    .pw-frame-sidebar,
    .pw-frame-backdrop,
    .pw-frame-drawer {
      transition: none;
    }
  }
}
