/* Mobile bottom navigation (home and Stats) */
body.stats-page .bottom-nav,
body.home .bottom-nav {
  display: none;
}

@media (max-width: 720px) {
  body.stats-page .bottom-nav,
  body.home .bottom-nav {
    --nav-index: 0;
    --nav-count: 5;
    --nav-padding-left: max(0.5rem, env(safe-area-inset-left, 0px));
    --nav-padding-right: max(0.5rem, env(safe-area-inset-right, 0px));
    display: flex;
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 1200;
    align-items: stretch;
    justify-content: space-around;
    gap: 4px;
    padding: 0.375rem max(0.5rem, env(safe-area-inset-right, 0px)) calc(0.375rem + env(safe-area-inset-bottom, 0px))
      max(0.5rem, env(safe-area-inset-left, 0px));
    background: linear-gradient(180deg, var(--color-surface-light, #fffaf1), var(--color-surface-soft, #fff3df));
    border-top: 1px solid rgba(183, 121, 31, 0.42);
    box-shadow:
      inset 0 2px 0 rgba(255, 253, 248, 0.9),
      0 -6px 24px rgba(79, 45, 19, 0.12);
  }

  /* Keep navigation above the splash through its fade, then restore normal overlay ordering. */
  body.home #home-loading-splash:not([hidden]) ~ #bottom-nav {
    z-index: 2147483001;
  }

  body.stats-page .bottom-nav-item,
  body.home .bottom-nav-item {
    position: relative;
    z-index: 1;
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 62px;
    padding: 0.25rem 0.125rem;
    border: 1px solid transparent;
    border-radius: var(--radius-control, 12px);
    background: transparent;
    color: var(--color-text-muted, #5d6878);
    font: inherit;
    font-size: 0.6875rem;
    font-weight: 800;
    line-height: 1.1;
    text-decoration: none;
    cursor: pointer;
    transition: color 220ms ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  body.stats-page .bottom-nav-item[hidden],
  body.home .bottom-nav-item[hidden] {
    display: none;
  }

  body.stats-page .bottom-nav-icon,
  body.home .bottom-nav-icon {
    display: block;
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    object-fit: contain;
    transition: transform 260ms var(--ease-out-snap, cubic-bezier(0.22, 1, 0.36, 1));
  }

  body.stats-page .bottom-nav-label,
  body.home .bottom-nav-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.stats-page .bottom-nav::before,
  body.home .bottom-nav::before {
    content: '';
    position: absolute;
    pointer-events: none;
    box-sizing: border-box;
    top: 0.375rem;
    bottom: calc(0.375rem + env(safe-area-inset-bottom, 0px));
    left: var(--nav-padding-left);
    width: calc(
      (100% - var(--nav-padding-left) - var(--nav-padding-right) - (var(--nav-count) - 1) * 4px) / var(--nav-count)
    );
    border: 1px solid rgba(183, 121, 31, 0.35);
    border-radius: var(--radius-control, 12px);
    transform: translateX(calc(var(--nav-index) * (100% + 4px)));
    transition: transform 280ms var(--ease-out-snap, cubic-bezier(0.22, 1, 0.36, 1));
    background: linear-gradient(180deg, var(--color-jade-wash-soft, #f1fbf9), var(--color-jade-soft, #d9f3ee));
    box-shadow:
      inset 0 1px 0 rgba(255, 253, 248, 0.9),
      inset 0 -2px 0 var(--color-jade, #178f86);
  }

  body.stats-page .bottom-nav-item.active,
  body.home .bottom-nav-item.active {
    color: var(--color-jade-dark, #0e625c);
  }

  body.home .bottom-nav:not([data-active-mode])::before {
    content: none;
  }

  body.stats-page .bottom-nav-item.active .bottom-nav-icon,
  body.home .bottom-nav-item.active .bottom-nav-icon {
    transform: translateY(-2px) scale(1.06);
  }

  body.stats-page .bottom-nav-item:active .bottom-nav-icon,
  body.home .bottom-nav-item:active .bottom-nav-icon {
    transform: scale(0.94);
  }

  body.stats-page .bottom-nav-item:focus-visible,
  body.home .bottom-nav-item:focus-visible {
    outline: 3px solid var(--color-focus-ring, #a46212);
    outline-offset: 2px;
  }

  body.stats-page .footer,
  body.home .footer {
    padding-bottom: calc(5.25rem + env(safe-area-inset-bottom, 0px));
  }

  body.stats-page .back-to-top.is-visible,
  body.home .back-to-top.is-visible {
    bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
  }
}

@media (prefers-reduced-motion: reduce) {
  body.stats-page .bottom-nav::before,
  body.home .bottom-nav::before,
  body.stats-page .bottom-nav-item,
  body.home .bottom-nav-item,
  body.stats-page .bottom-nav-icon,
  body.home .bottom-nav-icon {
    transition: none;
  }

  body.stats-page .bottom-nav-item.active .bottom-nav-icon,
  body.home .bottom-nav-item.active .bottom-nav-icon,
  body.stats-page .bottom-nav-item:active .bottom-nav-icon,
  body.home .bottom-nav-item:active .bottom-nav-icon {
    transform: none;
  }
}
