/* ==========================================
   CANADIAN GATOR — COMPACT MOBILE UI V3
   Applies only at phone-sized widths
   ========================================== */

#gatorBackToTop {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 9000;

  width: 48px;
  height: 48px;

  display: grid;
  place-items: center;

  border-radius: 50%;
  border: 1px solid #36a889;

  background: #126b60;
  color: white;

  font-size: 22px;
  font-weight: 700;

  cursor: pointer;
  box-shadow: 0 5px 20px rgba(0,0,0,.4);

  opacity: 0;
  visibility: hidden;
  pointer-events: none;

  transform: translateY(12px);

  transition:
    opacity .2s ease,
    transform .2s ease,
    visibility .2s ease;
}

#gatorBackToTop.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

#gatorBackToTop:focus-visible {
  outline: 3px solid #5eead4;
  outline-offset: 3px;
}

/* Phones */
@media (max-width: 700px) {

  /* Keep room for the Sections button */
  .page-shell {
    padding-top: 68px !important;
    padding-bottom: 30px !important;
  }

  /* More compact Canadian Gator header */
  .page-shell > .header {
    gap: 12px !important;
    margin-bottom: 16px !important;
  }

  .page-shell > .header h1 {
    font-size: clamp(27px, 7vw, 38px) !important;
    line-height: 1.1;
    letter-spacing: -.035em;
  }

  .page-shell > .header .title-pill {
    font-size: 10px;
    letter-spacing: .04em;
    padding: 5px 10px;
    vertical-align: middle;
  }

  .page-shell > .header .title-block > p {
    font-size: 13px;
    line-height: 1.5;
    margin: 8px 0 0;
  }

  /* Compact system status badges */
  .page-shell > .header .stats-strip {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 8px;
  }

  .page-shell > .header .stat-pill {
    padding: 8px 11px;
    border-radius: 12px;
    max-width: 100%;
    min-width: 0;
  }

  .page-shell > .header .stat-pill span {
    font-size: 10px;
  }

  .page-shell > .header .stat-pill strong {
    font-size: 12px;
    overflow-wrap: anywhere;
  }

  /* Reduce wasted panel spacing */
  .page-shell > .section {
    margin-bottom: 16px;
    padding: 16px 13px;
  }

  .page-shell > .section > h2 {
    font-size: clamp(20px, 5.5vw, 27px);
    line-height: 1.2;
    margin-bottom: 8px;
  }

  .page-shell > .section > .section-subtitle {
    font-size: 12px;
    line-height: 1.5;
    margin-bottom: 14px;
  }

  /* Two-column collection command center */
  .page-shell > .section .dash-grid {
    display: grid;
    grid-template-columns:
      repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .page-shell > .section .dash-grid > * {
    min-width: 0;
    max-width: 100%;
  }

  .page-shell > .section .dash-card {
    padding: 12px 10px;
    min-width: 0;
    border-radius: 12px;
    overflow-wrap: anywhere;
  }

  .page-shell > .section .dash-card strong {
    font-size: clamp(19px, 5vw, 26px);
    line-height: 1.2;
  }

  .page-shell > .section .dash-card span {
    font-size: 10px;
    line-height: 1.3;
  }

  .page-shell > .section .dash-card em {
    font-size: 10px;
    line-height: 1.4;
  }

  /* Prevent Commander Lab content from
     forcing the page wider than the phone */
  #commanderLabDashboard,
  #gatorBattleArena,
  #commanderLabDashboard .lab-panel {
    min-width: 0;
    max-width: 100%;
  }

  #commanderLabDashboard .lab-head {
    gap: 10px;
  }

  #commanderLabDashboard .lab-card {
    padding: 12px;
  }

  #commanderLabDashboard .lab-card-number {
    font-size: 25px;
  }

  #commanderLabDashboard .lab-table-wrap {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Keep floating controls accessible */
  #gatorNavOpen {
    min-height: 44px;
  }

  #gatorBattleArena button,
  #gatorBattleArena select {
    min-height: 44px;
  }
}

/* Very narrow phones: prioritize readability */
@media (max-width: 349px) {
  .page-shell > .section .dash-grid {
    grid-template-columns: minmax(0,1fr);
  }
}

/* No motion for users who disable animations */
@media (prefers-reduced-motion: reduce) {
  #gatorBackToTop {
    transition: none;
  }
}
