/* Mobile interaction polish for the Bayes Pharma.ai portfolio homepage. */

@media (max-width: 1120px) {
  html,
  body {
    max-width: 100%;
    overflow-x: clip;
    overscroll-behavior-x: none;
  }

  body.root-mobile-scroll-locked {
    position: fixed;
    inset: var(--root-mobile-scroll-offset, 0px) 0 auto;
    width: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
  }

  /* The drawer is nested inside the sticky topbar. Keep that entire stacking
     context above the separate backdrop element; a child's z-index cannot
     escape a lower-z-index parent stacking context. */
  .topbar {
    z-index: 930;
  }

  /* backdrop-filter creates a containing block for fixed descendants in mobile
     Chromium/WebView. Disable it on the header so the drawer is anchored to the
     viewport instead of collapsing to the height of the navigation pill. */
  .nav {
    background: color-mix(in srgb, var(--surface) 97%, var(--bg));
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .nav-links {
    position: fixed !important;
    inset: calc(8px + env(safe-area-inset-top)) 8px auto auto;
    z-index: 940;
    width: min(376px, calc(100% - 16px));
    height: calc(var(--root-mobile-viewport-height, 100dvh) - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    min-height: 0;
    max-height: calc(var(--root-mobile-viewport-height, 100dvh) - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    border: 1px solid var(--line);
    border-radius: 24px;
    padding: 0.75rem 0.75rem 1rem;
    box-shadow: 0 28px 90px rgba(4, 18, 13, 0.28);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    transform: translate3d(calc(100% + 24px), 0, 0);
    will-change: transform;
  }

  .nav-links.open {
    transform: translate3d(0, 0, 0);
  }

  .nav-links::before {
    display: none;
  }

  .mobile-drawer-head {
    position: sticky;
    top: -0.75rem;
    z-index: 2;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: -0.1rem -0.1rem 0.65rem;
    padding: 0.72rem 0.68rem 0.78rem;
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 97%, transparent);
    -webkit-backdrop-filter: blur(18px) saturate(145%);
    backdrop-filter: blur(18px) saturate(145%);
  }

  .mobile-drawer-title {
    min-width: 0;
  }

  .mobile-drawer-title strong,
  .mobile-drawer-title small {
    display: block;
  }

  .mobile-drawer-title strong {
    color: var(--ink-strong);
    font-size: 0.92rem;
    font-weight: 900;
    letter-spacing: -0.02em;
  }

  .mobile-drawer-title small {
    margin-top: 0.16rem;
    color: var(--muted);
    font-size: 0.65rem;
    font-weight: 720;
    line-height: 1.35;
  }

  .mobile-drawer-close {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    display: grid;
    place-items: center;
    border: 1px solid color-mix(in srgb, var(--danger) 25%, var(--line));
    border-radius: 14px;
    background: color-mix(in srgb, var(--danger) 8%, var(--surface-2));
    color: var(--danger);
    font-size: 1.05rem;
    cursor: pointer;
    transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
  }

  .mobile-drawer-close:hover,
  .mobile-drawer-close:active {
    border-color: color-mix(in srgb, var(--danger) 48%, var(--line));
    background: color-mix(in srgb, var(--danger) 14%, var(--surface));
    transform: scale(0.96);
  }

  body.nav-open #menuButton {
    opacity: 0;
    pointer-events: none;
  }

  .nav-backdrop {
    z-index: 900;
    background: rgba(3, 12, 9, 0.64);
    -webkit-backdrop-filter: blur(10px) saturate(90%);
    backdrop-filter: blur(10px) saturate(90%);
    touch-action: none;
    overscroll-behavior: none;
  }

  body.nav-open .mobile-bottom-nav {
    opacity: 0;
    visibility: hidden;
    transform: translateY(calc(100% + 24px));
    pointer-events: none;
  }
}

@media (max-width: 700px) {
  body {
    padding-bottom: calc(92px + env(safe-area-inset-bottom));
  }

  main,
  footer,
  .topbar,
  .shell,
  .model-section,
  .trust-section {
    max-width: 100%;
  }

  .mobile-bottom-nav {
    inset: auto 10px calc(9px + env(safe-area-inset-bottom)) 10px;
    min-height: 68px;
    padding: 5px;
    gap: 4px;
    border-radius: 22px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    box-shadow: 0 18px 48px rgba(5, 23, 17, 0.2);
    overflow: visible;
    isolation: isolate;
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.22s ease;
  }

  .mobile-bottom-nav::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    border-radius: inherit;
    background: inherit;
    -webkit-backdrop-filter: blur(22px) saturate(150%);
    backdrop-filter: blur(22px) saturate(150%);
  }

  .mobile-bottom-nav a {
    position: relative;
    min-height: 56px;
    border-radius: 17px;
    padding: 0.38rem 0.2rem;
    color: var(--muted-strong);
    font-size: 0.59rem;
    font-weight: 820;
    line-height: 1;
    transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-bottom-nav a i {
    width: 30px;
    height: 26px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    font-size: 0.92rem;
  }

  .mobile-bottom-nav a.active,
  .mobile-bottom-nav a[aria-current="page"] {
    background: var(--ink-strong);
    color: var(--surface);
    box-shadow: 0 10px 24px rgba(4, 19, 14, 0.2);
    transform: translateY(-2px);
  }

  :root[data-theme="dark"] .mobile-bottom-nav a.active,
  :root[data-theme="dark"] .mobile-bottom-nav a[aria-current="page"] {
    background: var(--brand);
    color: #04140f;
  }

  .mobile-bottom-nav a.active i,
  .mobile-bottom-nav a[aria-current="page"] i {
    background: color-mix(in srgb, currentColor 13%, transparent);
  }

  .mobile-bottom-nav a:active {
    transform: scale(0.96);
  }

  .back-to-top {
    bottom: calc(92px + env(safe-area-inset-bottom));
  }

  .tour-tabs,
  .router-lanes,
  .portfolio-tour,
  .decision-record,
  .contact-card {
    max-width: 100%;
  }

  .tour-tabs {
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
  }

  .tour-tabs::-webkit-scrollbar {
    display: none;
  }
}

@media (max-width: 390px) {
  .nav-links {
    inset: calc(6px + env(safe-area-inset-top)) 6px auto auto;
    width: calc(100% - 12px);
    height: calc(var(--root-mobile-viewport-height, 100dvh) - 12px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    max-height: calc(var(--root-mobile-viewport-height, 100dvh) - 12px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    border-radius: 21px;
  }

  .mobile-bottom-nav {
    inset-inline: 6px;
  }

  .mobile-bottom-nav a span {
    font-size: 0.55rem;
  }
}
