/* Mobile-first overrides for touch, narrow screens, and safe-area devices. */
html { -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; }
button, input, select { touch-action: manipulation; }

@media (max-width: 980px) {
  .app-shell main { padding: 38px 20px 64px; }
  .hero { min-height: auto; align-items: stretch; }
  .grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-actions { flex-wrap: wrap; justify-content: flex-end; }
  .results-head { gap: 20px; }
  .packet-row { grid-template-columns: 48px minmax(0, 1fr) 58px; }
  .packet-row code { min-width: 0; }
}

@media (max-width: 700px) {
  .app-shell header {
    height: 62px;
    padding: 0 16px;
  }
  .wordmark { font-size: 16px; }
  .wordmark span { width: 31px; height: 31px; margin-right: 7px; }
  .header-meta { gap: 10px; }
  .header-meta .ghost { min-height: 42px; padding: 8px 12px; }
  .live { display: none; }

  .app-shell main { padding: 24px 12px 52px; }
  .hero { padding: 25px 20px; gap: 24px; margin-bottom: 18px; }
  .hero h1 { font-size: clamp(34px, 11vw, 46px); }
  .route-card { min-width: 0; width: 100%; }

  .panel { padding: 21px 16px; margin-bottom: 12px; }
  .section-title { gap: 12px; margin-bottom: 20px; }
  .section-title > span { flex: 0 0 33px; }
  .section-title h2, .results h2 { font-size: 19px; }
  .section-title p { line-height: 1.45; }
  .grid.three { grid-template-columns: 1fr; gap: 14px; }

  .panel input, .panel select, .login-card input {
    min-height: 48px;
    padding: 13px 14px;
    font-size: 16px;
  }
  .primary, .ghost, .journey-tab, .packet-row button {
    min-height: 44px;
  }

  .journey-tabs { margin: 0 0 20px; width: 100%; }
  .journey-tab { min-width: 0; padding: 10px 9px; font-size: 12px; }
  .journey-summary { grid-template-columns: 1fr; }
  .journey-summary div { padding: 15px 17px; }
  .map-actions, .upload-actions { align-items: stretch; flex-direction: column; }
  .map-actions .ghost, .upload-actions .ghost, .upload-actions .primary { width: 100%; }
  .upload-grid { grid-template-columns: 1fr; }
  .upload-box, .format-card { min-height: 0; padding: 17px; }

  .action-row, .results-head {
    align-items: stretch;
    flex-direction: column;
    gap: 17px;
  }
  .action-row .action-buttons, .action-row .action-buttons button, .upload-actions .action-buttons, .upload-actions .action-buttons button { width: 100%; }
  .action-row .action-buttons, .upload-actions .action-buttons { display: grid; grid-template-columns: 1fr; }
  .result-actions { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .result-actions button { width: 100%; min-width: 0; padding: 11px 8px; }

  .packet-list { max-height: 58vh; }
  .packet-row {
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 8px;
    padding: 14px 0;
  }
  .packet-row code { font-size: 11px; line-height: 1.55; word-break: break-word; }
  .packet-row button { grid-column: 2; justify-self: start; padding: 0 12px; }
  .relay-note { align-items: flex-start; padding: 14px; }

  .job-card { grid-template-columns: 1fr; gap: 12px; }
  .job-card > div:last-child { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  .job-progress { width: 100%; }

  footer { align-items: flex-start; flex-direction: column; gap: 9px; padding: 22px 16px; }
  #toast {
    left: 12px;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    text-align: center;
  }
}

@media (max-width: 480px) {
  .login-shell { min-height: 100dvh; }
  .login-card { min-height: 100dvh; padding: max(32px, env(safe-area-inset-top)) 20px max(28px, env(safe-area-inset-bottom)); }
  .brand-mark { width: 48px; height: 48px; margin-bottom: 38px; }
  .login-card h1 { font-size: clamp(35px, 11vw, 45px); }
  .intro { margin-bottom: 28px; }

  .hero { border-radius: 14px; }
  .hero h1 { font-size: 36px; }
  .panel { border-radius: 13px; }
  .journey-tabs { display: grid; grid-template-columns: 1fr; }
  .result-actions { grid-template-columns: 1fr; }
  .format-card code { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
