/* ---------------------------------------------------------------------------
   The phone layer and the installable app (Branden, 2026-11-17).

   One file for what a phone needs on every page with Karl's header, loaded last
   by resources/views/stage/karl-head.blade.php so it wins over karl-shell.css
   and karl-notes.css:

   1. The bottom tab bar (stage/karl-tabbar.blade.php), at 820px and narrower.
      820px is where karl-shell.css folds the top menu into the Menu button, so
      the two always change together.
   2. A one-row phone header. With My Kidology and The Library in the tab bar,
      the header drops its own buttons for them and no longer wraps to two rows.
   3. Backstage menus that scroll sideways on a phone and stay one row tall.
   4. The installed app: a Back button (there is no browser one), and the
      "Get the app" card.

   Change a rule here and bump ?v= in karl-head.blade.php.
--------------------------------------------------------------------------- */

:root { --kapp-tabbar: 0px; }

.kapp-tabbar { display: none; }
.karl-shell .nav-back { display: none; }
.karl-shell .nav-install { display: none; }
.kapp-install[hidden] { display: none; }

/* --- 4a. The installed app's Back button ------------------------------------ */
.karl-shell .nav-back { flex: none; width: 40px; height: 40px; place-items: center; padding: 0; background: #fff; border: 0; border-radius: 50%; }
.karl-shell .nav-back svg { width: 22px; height: 22px; fill: none; stroke: var(--navy); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.kapp-standalone .karl-shell .nav-back:not([hidden]) { display: grid; }

/* --- 4b. "Get the app" ------------------------------------------------------ */
.kapp-install { position: fixed; z-index: 34; left: 8px; right: 8px; bottom: calc(var(--kapp-tabbar) + 8px); display: none; align-items: center; gap: 10px; padding: 10px 12px; font-family: "Poppins", system-ui, sans-serif; color: #14305c; background: #fff; border: 1px solid #e2e8f1; border-radius: 14px; box-shadow: 0 10px 30px rgba(12, 31, 63, .22); }
.kapp-install img { flex: none; width: 44px; height: 44px; border-radius: 10px; }
.kapp-install p { flex: 1; min-width: 0; margin: 0; font-size: 13px; line-height: 1.3; }
.kapp-install p strong { display: block; font-size: 15px; }
.kapp-install-go { flex: none; min-height: 40px; padding: 6px 16px; font: 700 14px/1 "Poppins", system-ui, sans-serif; color: #fff; background: #1f6fe0; border: 0; border-radius: 999px; cursor: pointer; }
.kapp-install-close { flex: none; width: 36px; height: 36px; padding: 0; font-size: 24px; line-height: 1; color: #5a6477; background: none; border: 0; border-radius: 50%; cursor: pointer; }
.kapp-ios { width: min(420px, calc(100% - 32px)); padding: 22px; font-family: "Poppins", system-ui, sans-serif; color: #14305c; background: #fff; border: 0; border-radius: 16px; }
.kapp-ios::backdrop { background: rgb(12 31 63 / 60%); }
.kapp-ios h2 { margin: 0 0 10px; font-size: 20px; line-height: 1.25; }
.kapp-ios ol { margin: 0 0 16px; padding-left: 22px; line-height: 1.5; }
.kapp-ios li + li { margin-top: 6px; }
.kapp-ios button { min-height: 44px; padding: 8px 22px; font: 700 15px/1 "Poppins", system-ui, sans-serif; color: #fff; background: #1f6fe0; border: 0; border-radius: 999px; cursor: pointer; }

@media (max-width: 820px) {
  /* --- 1. The tab bar ------------------------------------------------------- */
  :root { --kapp-tabbar: calc(60px + env(safe-area-inset-bottom, 0px)); }
  body:has(.kapp-tabbar) { padding-bottom: var(--kapp-tabbar); }
  .kapp-tabbar { position: fixed; z-index: 32; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); padding: 0 max(4px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(4px, env(safe-area-inset-left, 0px)); font-family: "Poppins", system-ui, sans-serif; background: #fff; border-top: 1px solid #e2e8f1; box-shadow: 0 -4px 18px rgba(20, 48, 92, .08); }
  .kapp-tabbar a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0; height: 60px; padding: 6px 2px 5px; font-size: 11px; font-weight: 600; line-height: 1.15; color: #5a6477; text-decoration: none; -webkit-tap-highlight-color: transparent; }
  .kapp-tabbar svg { flex: none; width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
  .kapp-tabbar span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .kapp-tabbar a[aria-current="page"] { color: #14305c; font-weight: 700; }
  .kapp-tabbar a[aria-current="page"] svg { fill: #ffc72c; stroke: #14305c; }
  .kapp-tabbar a[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 22%; right: 22%; height: 3px; background: #ffc72c; border-radius: 0 0 3px 3px; }
  .kapp-tabbar a:active { background: #eef3fb; }
  .kapp-tabbar a:focus-visible { outline: 3px solid #1f6fe0; outline-offset: -3px; border-radius: 8px; }

  /* The floating feedback buttons sit above the bar, and above the app card while it shows. */
  .kd-tell { bottom: calc(var(--kapp-tabbar) + 12px); }
  .karl-feedback > button { bottom: calc(var(--kapp-tabbar) + 12px); }
  body:has(.kapp-install.is-on) .kd-tell,
  body:has(.kapp-install.is-on) .karl-feedback > button { bottom: calc(var(--kapp-tabbar) + 84px); }

  /* --- 2. One header row ----------------------------------------------------- */
  /* My Kidology and The Library are tabs now. Their items stay in the Menu (.nav-me). */
  .karl-shell .kn-me { display: none; }
  .karl-shell .header-actions > a.icon-btn[href="/library"] { display: none; }
  .karl-shell .primary-nav.open { max-height: calc(100dvh - 72px - var(--kapp-tabbar)); }
  .karl-shell .nav-install:not([hidden]) { display: block; margin: 6px 0 4px; padding: 12px; width: 100%; font: 700 16px/1.3 "Poppins", system-ui, sans-serif; color: #fff; text-align: left; background: #1f6fe0; border: 0; border-radius: 10px; }

  /* --- 3. Backstage menus: one row, scrolled sideways ------------------------- */
  .kd-adminnav .kd-subnav { flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; margin-inline: -16px; padding: 2px 16px; scroll-padding-inline: 16px; -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 30px), transparent 100%); mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 30px), transparent 100%); }
  .kd-adminnav .kd-subnav::-webkit-scrollbar { display: none; }
  .kd-adminnav .kd-subnav > * { flex: none; }
  .kd-adminnav .kd-subnav-link { white-space: nowrap; }

  /* An iPhone zooms the whole page when a form control's text is under 16px. */
  .blog-filters select, .bs-filters select { font-size: 16px; }

  .kapp-install.is-on { display: flex; }
}

@media (max-width: 380px) {
  .kapp-tabbar { padding-inline: 0; }
  .kapp-tabbar a { padding-inline: 0; font-size: 10px; letter-spacing: -.1px; }
  .kapp-install p span { display: none; }
}

/* The smallest phones (an iPhone SE is 320px): keep the header to one row. */
@media (max-width: 360px) {
  .karl-shell { --gutter: 12px; }
  .karl-shell .header-row:has(.nav-logo) { gap: 4px; }
  .karl-shell .nav-logo { margin-right: 0; }
  .karl-shell .nav-logo img { height: 27px; }
  .karl-shell .header-row:has(.nav-logo) .nav-toggle { padding-inline: 8px; }
  .karl-shell .btn-join, .karl-shell .btn-login { padding-inline: 9px; font-size: 15px; letter-spacing: 0; }
}

/* Installed: the app card and the menu's install button have done their job. */
.kapp-standalone .kapp-install, .kapp-standalone .karl-shell .nav-install { display: none !important; }

@media print {
  .kapp-tabbar, .kapp-install { display: none !important; }
  body:has(.kapp-tabbar) { padding-bottom: 0; }
}
