@layer layout {
  .stage {
    --stage-max: 900px;
    --stage-min: 220px;
  }
}

@layer components {
  .progressive-nav {
    display: flex;
    align-items: center;
    gap: var(--space-m);
    min-inline-size: max-content;
    padding: var(--space-l);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
  }

  :is(.inline-link, .nav-menu a) {
    color: var(--color-text);
    text-decoration: none;
    white-space: nowrap;

    &:hover {
      text-decoration: underline;
    }
  }

  .brand {
    margin-inline-end: auto;
  }

  .inline-link {
    display: none;
  }

  @container (width >= 320px) { .inline-link.t1 { display: inline; } }
  @container (width >= 560px) { .inline-link.t2 { display: inline; } }
  @container (width >= 800px) { .inline-link.t3 { display: inline; } }
  @container (width >= 1040px) { .inline-link.t4 { display: inline; } }

  .more {
    /* .stage needs overflow: auto for its resize handle, which would clip a
       plain absolutely-positioned dropdown at the stage's edge; anchor-name
       + [popover] below renders the menu in the top layer instead, so it
       escapes that clipping entirely */
    anchor-name: --nav-trigger;
    display: none;
    align-items: center;
    justify-content: center;
    inline-size: 2rem;
    block-size: 2rem;
    padding: 0;
    border-radius: var(--radius-s);
    cursor: pointer;

    &:hover {
      background: var(--color-surface-2);
    }

    @container (width < 1040px) {
      display: inline-flex;
    }
  }

  .nav-menu {
    position: fixed;
    /* physical: anchor()'s side keywords (top/right/bottom/left) are what
       anchor positioning actually resolves against here, logical
       inset-block/inline equivalents don't carry the same meaning for a
       physically-anchored popup */
    /* lint-ignore: no-physical-property */
    top: anchor(--nav-trigger bottom);
    right: anchor(--nav-trigger right);
    /* the UA stylesheet sets all four [popover] insets to 0 by default;
       bottom/left have to be reset to auto or this box stays
       over-constrained and the anchor() values above lose */
    /* lint-ignore: no-physical-property */
    bottom: auto;
    left: auto;
    margin-block-start: var(--space-3xs);
    padding: var(--space-3xs);
    display: grid;
    gap: var(--space-3xs);
    min-inline-size: 10rem;
    list-style: none;
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-s);
    box-shadow: 0 var(--space-2xs) var(--space-l) var(--shadow-color);
    opacity: 0;
    translate: 0 calc(var(--space-2xs) * -1);

    @media (prefers-reduced-motion: no-preference) {
      transition: opacity .15s ease, translate .15s ease, display .15s allow-discrete;
    }

    &:popover-open {
      opacity: 1;
      translate: 0 0;

      @starting-style {
        opacity: 0;
        translate: 0 calc(var(--space-2xs) * -1);
      }
    }

    li {
      display: none;
      margin: 0;
    }

    a {
      display: block;
      padding-block: var(--space-2xs);
      padding-inline: var(--space-xs);
      border-radius: var(--space-3xs);

      &:hover {
        background: var(--color-surface-2);
      }
    }
  }

  @container (width < 320px) { .nav-menu li.t1 { display: block; } }
  @container (width < 560px) { .nav-menu li.t2 { display: block; } }
  @container (width < 800px) { .nav-menu li.t3 { display: block; } }
  @container (width < 1040px) { .nav-menu li.t4 { display: block; } }
}
