/* Mobile refinements for public pages only.
   Attached by scripts/build_site.py; borrower dashboard and admin pages are excluded. */

@media (max-width: 639px) {
  :root {
    --gutter: clamp(16px, 4.5vw, 22px);
    --gap-lg: 24px;
    --gap-xl: 36px;
    --gap-2xl: 48px;
    --fs-display: clamp(36px, 10vw, 48px);
    --fs-h2: clamp(25px, 7vw, 32px);
    --fs-h3: clamp(19px, 5.2vw, 22px);
    --fs-lead: clamp(16px, 4.5vw, 18px);
  }

  html,
  body {
    max-width: 100%;
  }

  .container {
    width: min(100%, var(--container));
    padding-inline: var(--gutter);
  }

  main,
  section,
  header,
  footer,
  nav,
  article,
  aside,
  .grid-2,
  .grid-3,
  .grid-4,
  .grid-2-1,
  .hero-grid,
  .img-split,
  .legal-wrap,
  .steps,
  .foot-grid,
  .card,
  .feature,
  .product,
  .prose {
    min-width: 0;
  }

  .section {
    padding-block: clamp(44px, 12vw, 64px);
  }

  .grid-2,
  .grid-3,
  .grid-4,
  .grid-2-1,
  .form-2,
  .key-clauses {
    grid-template-columns: minmax(0, 1fr);
  }

  .row-between {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .card,
  .feature,
  .product,
  .key-clause {
    padding: clamp(18px, 5vw, 24px);
  }

  .page-hero .container {
    padding-block: clamp(36px, 10vw, 56px);
  }

  .page-hero h1 {
    font-size: clamp(32px, 9vw, 42px);
    overflow-wrap: anywhere;
  }

  .lead,
  .prose p,
  .notice,
  .contact-methods,
  .breadcrumb {
    overflow-wrap: anywhere;
  }

  /* Keep the trust points in normal document flow on phones instead of creating
     a hidden horizontal carousel that can be mistaken for page overflow. */
  .trust-strip .grid-4 {
    grid-auto-flow: row;
    grid-auto-columns: auto;
    grid-template-columns: minmax(0, 1fr);
    overflow: visible;
    overscroll-behavior-inline: auto;
    scroll-snap-type: none;
    padding-bottom: 0;
  }

  .topnav-inner {
    min-height: 64px;
    gap: 12px;
  }

  .brand {
    flex: none;
    white-space: nowrap;
  }

  .topnav .nav-actions {
    flex: 0 0 auto;
    margin-left: auto;
    gap: 8px;
  }

  .topnav .login-link {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    padding-inline: 4px;
    white-space: nowrap;
  }

  .menu-btn {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
  }

  .mobile-menu a {
    display: flex;
    min-height: 48px;
    align-items: center;
    padding-block: 10px;
  }

  .mobile-menu .btn {
    justify-content: center;
    margin-block: 12px;
  }

  .announce .container {
    align-items: center;
    gap: 8px;
    padding-block: 8px;
  }

  .announce .close {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
  }

  .hero-grid {
    gap: var(--gap-lg);
  }

  .hero-cta {
    gap: 10px;
  }

  .hero-carousel-controls {
    right: 16px;
    left: 16px;
    justify-content: flex-end;
    gap: 4px;
    max-width: none;
  }

  .hero-carousel-arrow {
    width: 44px;
    height: 44px;
  }

  .hero-carousel-toggle {
    min-width: 64px;
    height: 44px;
    padding-inline: 9px;
  }

  .hero-carousel-dot {
    width: 44px;
    height: 44px;
  }

  .hero-carousel-count {
    display: none;
  }

  .calc {
    padding: 16px;
  }

  .calc-head,
  .calc-field .field-top,
  .sum-row {
    flex-wrap: wrap;
    gap: 8px;
  }

  .calc-field .field-top {
    align-items: center;
  }

  .amt-input {
    min-height: 44px;
    max-width: 100%;
  }

  .amt-input input {
    min-height: 40px;
    width: min(72px, 28vw);
  }

  input[type="range"].slider {
    height: 44px;
    margin-block: 4px;
    background: transparent;
    touch-action: pan-y;
  }

  input[type="range"].slider::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: var(--r-full);
    background: var(--border);
  }

  input[type="range"].slider::-moz-range-track {
    height: 6px;
    border-radius: var(--r-full);
    background: var(--border);
  }

  .calc-summary {
    padding: 14px;
  }

  .sum-row .k,
  .sum-row .v {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .cost-table {
    width: 100%;
    table-layout: fixed;
  }

  .cost-table th,
  .cost-table td {
    padding-block: 10px;
    padding-inline: 6px;
    font-size: 14px;
    overflow-wrap: anywhere;
  }

  .cost-table th:first-child,
  .cost-table td:first-child {
    width: 62%;
  }

  .cost-table th:last-child,
  .cost-table td:last-child {
    width: 38%;
  }

  .cost-table th {
    font-size: 11px;
    letter-spacing: .035em;
  }

  .cost-table .desc {
    font-size: 12px;
  }

  .img-band img {
    aspect-ratio: 4 / 3;
  }

  .prefooter .container {
    padding-block: clamp(48px, 13vw, 72px);
  }

  .prefooter .hero-cta .btn,
  .cta-dark .hero-cta .btn {
    min-height: 48px;
  }

  .pagefoot a,
  .feature a,
  .product .cost-link,
  .legal-index a,
  .key-clause a,
  .contact-methods a {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
  }

  .pagefoot a {
    display: flex;
    width: fit-content;
    padding-block: 8px;
  }

  .legal-index a {
    padding-inline: 11px;
  }

  .input,
  select.input,
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  select,
  textarea {
    min-height: 48px;
    max-width: 100%;
  }

  .consent-line {
    min-height: 44px;
  }

  .btn,
  .btn-ghost {
    min-height: 44px;
  }

  .pw-toggle {
    width: 44px;
    height: 44px;
  }

  .auth-shell,
  .auth-form-panel,
  .auth-visual,
  .auth-form-inner {
    min-width: 0;
    width: 100%;
  }

  .auth-form-panel {
    padding-inline: var(--gutter);
  }

  .auth-form-inner h2,
  .auth-story h1 {
    overflow-wrap: anywhere;
  }

  .auth-password-toggle {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
  }

  .auth-link-row a,
  .auth-secondary-link a {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
  }

  .auth-carousel-controls {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    grid-template-rows: 44px 44px;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .auth-round-control {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }

  .auth-carousel-dots {
    grid-column: 2;
    grid-row: 1;
    justify-content: center;
    gap: 0;
    min-width: 0;
  }

  .auth-carousel-dots button,
  .auth-carousel-dots button[aria-current="true"] {
    display: grid;
    place-items: center;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    min-height: 44px;
    background: transparent;
  }

  .auth-carousel-dots button::before {
    width: 8px;
    height: 8px;
    border-radius: 99px;
    background: rgba(255,255,255,.56);
    content: "";
  }

  .auth-carousel-dots button[aria-current="true"]::before {
    width: 24px;
    background: var(--lime, #dfff58);
  }

  .auth-carousel-toggle {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: center;
    min-width: 100px;
    min-height: 44px;
    padding: 8px 12px;
  }

  .auth-slide-count {
    display: none;
  }

  .auth-input,
  .auth-submit {
    min-height: 48px;
  }

  .apply-bar {
    right: max(12px, env(safe-area-inset-right));
    bottom: calc(12px + env(safe-area-inset-bottom));
    left: max(12px, env(safe-area-inset-left));
    gap: 8px;
  }

  .apply-bar .btn {
    min-width: 92px;
    min-height: 44px;
    padding-inline: 14px;
  }

  .apply-bar .ab-label {
    min-width: 0;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 480px) {
  .hero.section {
    min-height: max(640px, min(84svh, 740px));
  }

  .hero .display {
    max-width: 11ch;
    font-size: clamp(42px, 11.5vw, 54px);
  }

  .hero .hero-cta .btn {
    min-height: 48px;
  }

  .auth-visual {
    padding-inline: var(--gutter);
  }

  .auth-story h1 {
    font-size: clamp(30px, 8.4vw, 38px);
  }

  .auth-carousel-controls {
    gap: 6px;
  }

  .auth-carousel-dots button,
  .auth-carousel-dots button[aria-current="true"] {
    flex-basis: 44px;
    width: 44px;
  }

  .hero .hero-cta .btn {
    padding-inline: 12px;
    font-size: 14px;
  }
}

@media (max-width: 359px) {
  :root {
    --gutter: 16px;
  }

  .brand {
    gap: 7px;
    font-size: 18px;
  }

  .topnav .login-link {
    font-size: 14px;
  }

  .hero .display {
    font-size: 40px;
  }

  .hero .hero-cta .btn {
    width: 100%;
  }

  .hero-carousel-controls {
    gap: 0;
    justify-content: space-between;
  }

  .cost-table th,
  .cost-table td {
    padding-inline: 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
