/* Phone app shell (≤ 760 px), index.html only.
   - Bottom tab bar: Home · Quiz · Explore · Compare. It only calls the existing
     navigation functions; which tab is active is read from the screen that is
     visible (the screens are toggled with inline style="display: …").
   - The website footer is hidden on phones in footer.css; Privacy and Terms
     live in the header menu instead (.nav-legal in header.css). */

.app-tabbar {
  display: none;
}

@media (max-width: 760px) {
  /* The tab bar already offers Start quiz / Explore / Compare */
  body:has(.app-tabbar) .nav-links .nav-right-group {
    display: none;
  }

  .app-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    -webkit-backdrop-filter: saturate(1.4) blur(16px);
    backdrop-filter: saturate(1.4) blur(16px);
    box-shadow: var(--shadow-bar);
  }

  body:has(.app-tabbar) {
    padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  }

  .app-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 54px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--text-3);
    font: 700 11px / 1 var(--font-ui);
    letter-spacing: .01em;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
  }

  .app-tab-icon {
    display: grid;
    place-items: center;
    width: 56px;
    height: 30px;
    border-radius: var(--r-pill);
    transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
  }

  .app-tab-icon svg {
    width: 22px;
    height: 22px;
  }

  .app-tab:active .app-tab-icon {
    background: var(--surface-2);
  }

  /* Active tab follows the visible screen */
  body:has(#landing:not([style*="none"])) .app-tab--home,
  body:has(#levelSelect[style*="block"]) .app-tab--quiz,
  body:has(#quiz[style*="block"]) .app-tab--quiz,
  body:has(#results[style*="block"]) .app-tab--quiz,
  body:has(#exploreValues[style*="block"]) .app-tab--explore,
  body:has(#compareUpload[style*="block"]) .app-tab--compare,
  body:has(#compareResults[style*="block"]) .app-tab--compare {
    color: var(--primary-ink);
  }

  body:has(#landing:not([style*="none"])) .app-tab--home .app-tab-icon,
  body:has(#levelSelect[style*="block"]) .app-tab--quiz .app-tab-icon,
  body:has(#quiz[style*="block"]) .app-tab--quiz .app-tab-icon,
  body:has(#results[style*="block"]) .app-tab--quiz .app-tab-icon,
  body:has(#exploreValues[style*="block"]) .app-tab--explore .app-tab-icon,
  body:has(#compareUpload[style*="block"]) .app-tab--compare .app-tab-icon,
  body:has(#compareResults[style*="block"]) .app-tab--compare .app-tab-icon {
    background: var(--primary-soft);
  }

  /* Re-tapping Quiz while in the quiz would open the "Test in progress" dialog */
  body:has(#levelSelect[style*="block"]) .app-tab--quiz,
  body:has(#quiz[style*="block"]) .app-tab--quiz,
  body:has(#results[style*="block"]) .app-tab--quiz {
    pointer-events: none;
  }

  /* Focused flows have their own bottom bar: the question pages and the growth plan */
  body:has(#quiz[style*="block"] > #quizContent:not([style*="none"])) .app-tabbar,
  body:has(#growthPlan[style*="block"]) .app-tabbar {
    display: none;
  }

  body:has(#quiz[style*="block"] > #quizContent:not([style*="none"])),
  body:has(#growthPlan[style*="block"]) {
    padding-bottom: 0;
  }
}
