/* Sizing safeguards only; existing colours, typography, cards and controls stay
   in their original stylesheets. Browser zoom remains enabled. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body, .phone { min-width: 0; }
.phone { max-width: 100%; }
.screen :is(input, select, textarea) { min-width: 0; max-width: 100%; }
/* The height range rotates into a narrow wrapper; keep its full vertical travel. */
.screen input.vertical-slider { max-width: none; touch-action: none; }

/* The legacy in-app detail view shares the same content on every screen. */
#meal-detail-screen .detail-hero > * { min-width: 0; max-width: 100%; }
#meal-detail-screen .detail-hero-image { flex: 1 1 0; width: 100%; height: 100%; object-fit: cover; }
#meal-detail-screen .detail-hero-content { flex: 1 1 0; overflow-wrap: anywhere; }
#meal-detail-screen .detail-method-step > * { min-width: 0; max-width: 100%; }
#meal-detail-screen .detail-method-step p { overflow-wrap: anywhere; }
#meal-detail-screen .ingredient-copy :is(span, small) { overflow-wrap: anywhere; }

/* Match the visible viewport when mobile browser chrome expands or collapses. */
#recipe-page-view { height: 100vh !important; height: 100dvh !important; }

@media (pointer: coarse) {
  .phone { max-width: calc(100% - env(safe-area-inset-left) - env(safe-area-inset-right)); margin-inline: env(safe-area-inset-left) env(safe-area-inset-right); }
}

@media (max-width: 767px), (pointer: coarse) {
  /* Avoid iOS zooming the whole page when a small text field receives focus. */
  .screen :is(input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=hidden]), select, textarea) { font-size: 16px; }
  .screen :is(#login-email, #login-password, #data-name, #scan-archive-date, #receipt-store, #receipt-date, #receipt-currency, #receipt-budget-total) { font-size: 16px !important; }
}
@media (max-width: 480px) {
  #meal-detail-screen .detail-method-step { display: grid; grid-template-columns: 22px minmax(0, 1fr); }
  #meal-detail-screen .detail-method-step > img { grid-column: 2; width: 100%; height: auto; }
  #meal-detail-screen .detail-method-step > p { grid-column: 2; }
  .nutrition-target-card > .meal-item { grid-column: 1 / -1; min-width: 0; flex-wrap: wrap; gap: 8px; }
  .nutrition-target-card > .meal-item .meal-kcal { max-width: 100%; overflow-wrap: anywhere; }
}
@media (max-width: 690px) {
  #home-screen .bottom-nav { padding-inline: max(10px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-right)); }
}

/* Float the existing mobile navigation above the screen edge on every tab. */
@media (max-width: 690px) {
  .phone { --mobile-dock-height: 70px; --mobile-dock-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  :root .phone :is(#home-screen, .screen) .bottom-nav {
    position: fixed;
    inset: auto;
    left: 50%;
    bottom: var(--mobile-dock-bottom);
    transform: translateX(-50%);
    z-index: 100;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 2px;
    width: calc(100vw - 28px);
    max-width: 660px;
    height: var(--mobile-dock-height);
    min-height: var(--mobile-dock-height);
    margin: 0;
    padding: 7px 6px;
    border: 1px solid var(--app-line, #dce6df);
    border-radius: 24px;
    background: #fff;
    box-shadow: 0 8px 28px rgba(24, 58, 43, .16);
    backdrop-filter: none;
  }
  :root[data-theme="dark"] .phone :is(#home-screen, .screen) .bottom-nav {
    background: #1c2a22f7;
  }
  :root .phone :is(#home-screen, .screen) .bottom-nav .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: 4px 2px;
    text-align: center;
  }
  :root .phone > .screen:has(.bottom-nav):not(#home-screen):not(#chat-screen) {
    padding-bottom: calc(var(--mobile-dock-height) + var(--mobile-dock-bottom) + 20px);
  }
  #home-screen .hd-main {
    padding-bottom: max(110px, calc(var(--mobile-dock-height) + var(--mobile-dock-bottom) + 20px));
  }
  :root .phone > #chat-screen {
    padding-bottom: calc(var(--mobile-dock-height) + var(--mobile-dock-bottom) + 4px);
  }
}

/* Keep long recipe titles below Back/Save/Share. Ordinary titles retain their
   existing height, margins and type; longer content can grow instead of overlap. */
@media (max-width: 767px) {
  :root body .recipe-app > .hero { display: flex !important; flex-direction: column !important; justify-content: flex-end !important; height: auto !important; padding-top: 76px !important; }
  :root body .recipe-app > .hero > img { position: absolute !important; inset: 0 !important; }
  :root body .recipe-app > .hero > .hero-content { position: relative !important; left: auto !important; right: auto !important; bottom: auto !important; margin: 0 14px 22px !important; }
}
