/* 13 October: source-audited narrow screens, short screens and touch controls. */
/* Consent must remain scrollable if text zoom or a short viewport makes it tall. */
:root body .analytics-consent {
  --consent-bottom: max(18px, env(safe-area-inset-bottom, 0px));
  bottom: var(--consent-bottom);
  max-height: calc(100dvh - var(--consent-bottom) - max(16px, env(safe-area-inset-top, 0px)));
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-block: 16px;
}
:root body .analytics-consent .btn { white-space: normal; overflow-wrap: anywhere; }

@media (max-width: 760px) {
  :root body .analytics-consent { --consent-bottom: calc(var(--mobile-dock-height, 70px) + 12px); }

  /* New planners and search fields do not all use the older .field wrapper. */
  :root body:has(main input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=button]):not([type=submit]):focus, main textarea:focus, main select:focus) :is(.mobile-contact, .chat-launcher) {
    visibility: hidden;
  }
  :root body .chat-header button,
  :root body .chat-prompts button { min-width: 44px; min-height: 44px; }
  :root body .chat-handoff { flex-wrap: wrap; gap: 4px 12px; }
  :root body .chat-handoff a { display: inline-flex; align-items: center; min-height: 44px; }

  /* Keep the close control and composer reachable above the phone keyboard. */
  :root body .chat-panel[data-keyboard-open=true] { overflow-y: auto; }
  :root body .chat-panel[data-keyboard-open=true] .chat-log { flex: 1 0 120px; }
  :root body .chat-panel[data-keyboard-open=true] .chat-header { position: sticky; top: 0; z-index: 1; }

  /* Variable header height also applies to the newer section jump links. */
  main :is(.value-section, .pg-panel, .consultancy-enquiry) {
    scroll-margin-top: calc(var(--header-height, 134px) + 20px);
  }
  .pg-rail a { min-width: 0; overflow-wrap: anywhere; }
}

@media (max-width: 420px) {
  /* Four intrinsic-width columns can outgrow the game at 320px. */
  :root body .rr .rr-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  :root body .rr .rr-stat { min-width: 0; }
  :root body .rr .rr-stat small { overflow-wrap: anywhere; }
  :root body .rr .rr-right { min-width: 0; flex-wrap: wrap; }
  :root body .rr .rr-right > button { flex-shrink: 0; }
  :root body .rr .rr-lives { flex-shrink: 0; }
}

@media (max-width: 760px) and (max-height: 600px) {
  :root body .chat-panel { overflow-y: auto; }
  :root body .chat-log { flex: 1 0 120px; }
  :root body .chat-header { position: sticky; top: 0; z-index: 1; }
}
@media (max-height: 380px) {
  /* The choice panel may cover the dock; its own actions take precedence. */
  :root body .analytics-consent { --consent-bottom: max(8px, env(safe-area-inset-bottom, 0px)); }
}
@media print {
  :root body .analytics-consent { display: none !important; }
}
