@layer layout {
/* Bottom navigation bar - mobile style */
#bottom_nav {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: center;
  /* Sticky (not fixed) so the nav occupies real layout space: in-flow content
     can never end up hidden behind it, on any page. */
  position: sticky;
  bottom: 0;
  inset-inline-start: 0;
  width: 100%;
  height: calc(var(--tap-min) + var(--spacing-4));
  background-color: var(--surface);
  z-index: var(--z-index-50);
  border-block-start: var(--border-width) solid var(--border-strong);
  padding: 0;
  /* auto block-start margin pushes the nav to the bottom of the flex-column
     body on short pages; must come after the margin reset. */
  margin: 0;
  margin-block-start: auto;

  & li {
    display: flex;
    justify-content: center;
    align-items: center;
    /* Items share the row equally and may shrink below tap-min width on
       narrow screens (full-height row keeps the target tappable) — the nav
       itself must never exceed the viewport. */
    flex: 1 1 0;
    min-width: 0;
    max-width: 96px;
    height: 100%;
    text-align: center;
    padding: 0;
    margin: 0;

    & a,
    & button.more {
      background: none;
      border: none;
      cursor: pointer;
      font-family: var(--font-family-base);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 2px;
      width: 100%;
      height: 100%;
      min-height: var(--tap-min);
      min-width: 0;
      color: var(--text-muted);
      text-decoration: none;
      transition: color var(--transition-fast), transform var(--transition-fast);
      padding: var(--spacing-1);

      & .nav-glyph {
        font-size: var(--font-size-xl);
        line-height: 1;
      }

      & .nav-label {
        font-size: 0.625rem;
        font-weight: var(--font-weight-bold);
        text-transform: uppercase;
        letter-spacing: 0.04em;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      &:hover {
        color: var(--brand);
        transform: translateY(-2px);
      }

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

      &.active {
        background-color: var(--accent);
        color: var(--on-accent);
        font-weight: var(--font-weight-bold);
      }
    }
  }

  & li.back {
    & a {
      display: flex;
      justify-content: center;
      align-items: center;

      & img {
        width: var(--spacing-6);
        height: var(--spacing-6);
      }
    }
  }
}

/* Media query for smaller screens */
@media (max-width: 360px) {
  #bottom_nav li a {
    padding: var(--spacing-1);
  }

  #bottom_nav li.back a img {
    width: var(--spacing-5);
    height: var(--spacing-5);
  }
}

/* Always full-width and centered on every viewport (desktop + mobile).
   Icons are spread evenly across the full width via `li { flex: 1 }`. */
}

/* "More" bottom sheet — in the screens layer so it beats the generic dialog
   styles from components/dialog.css (full-screen on small viewports). */
@layer screens {
#more_sheet {
  position: fixed;
  /* Pin to the bottom edge: the UA dialog stylesheet uses logical inset
     properties, so physical top/bottom alone don't override it. */
  inset: auto 0 0 0;
  inset-block-start: auto;
  inset-block-end: 0;
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: 80dvh;
  overflow-y: auto;
  box-sizing: border-box;
  margin: 0;
  padding: var(--spacing-2) var(--spacing-4) var(--spacing-6);
  background-color: var(--surface);
  border: none;
  border-block-start: var(--border-width-thick) solid var(--border-strong);

  &::backdrop {
    background-color: rgb(0 0 0 / 50%);
  }

  & .more-sheet-handle {
    width: 48px;
    height: 4px;
    background: var(--border);
    margin: var(--spacing-1) auto var(--spacing-3);
  }

  & .more-sheet-nav {
    list-style: none;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 0;
    margin: 0;

    & li a {
      display: flex;
      align-items: center;
      min-height: var(--tap-min);
      padding: var(--spacing-2) var(--spacing-3);
      color: var(--text);
      text-decoration: none;
      font-weight: var(--font-weight-bold);
      border-block-end: var(--border-width) solid var(--border);

      &.active {
        background: var(--accent);
        color: var(--on-accent);
      }

      &:focus-visible {
        outline: 3px solid var(--focus-ring);
        outline-offset: -3px;
      }
    }
  }
}
}
