/* Homepage phone layout. Let long sections grow and keep scrolling natural. */
@media (max-width: 640px) {
  body {
    --home-gutter: clamp(18px, 6.15vw, 36px);
    --home-section-space: clamp(62px, 9svh, 88px);
  }

  .hero {
    min-height: 100vh;
    min-height: 100svh;
  }

  .hero-media::after {
    background: linear-gradient(
      180deg,
      rgba(8, 18, 28, 0.24),
      rgba(8, 18, 28, 0.05) 35%,
      rgba(8, 18, 28, 0.64) 66%,
      rgba(8, 18, 28, 0.92)
    );
  }

  .hero-content {
    gap: 24px;
    padding: 112px var(--home-gutter) max(88px, 11svh, calc(76px + env(safe-area-inset-bottom)));
  }

  .hero h1 {
    max-width: min(100%, 16ch);
    font-size: clamp(1.75rem, 9.1vw, 3.75rem);
    line-height: 1.06;
    text-wrap: balance;
  }

  .hero h1 span {
    display: inline;
  }

  .hero-visit {
    justify-items: start;
    gap: 12px;
  }

  .hero-visit p {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.45;
  }

  .hero-visit-button {
    width: fit-content;
    max-width: 100%;
    padding-inline: 28px;
  }

  /* Use a stable full screen even after the phone's browser toolbar retracts. */
  .latest-sermon {
    min-height: 100vh;
    min-height: 100lvh;
    scroll-margin-top: 0;
    display: grid;
    align-items: stretch;
    padding: 0;
  }

  .latest-sermon-inner {
    grid-template-rows: minmax(min-content, 1.38fr) minmax(min-content, 1fr);
    align-items: stretch;
    gap: 0;
  }

  .sermon-showcase {
    align-self: center;
    padding: max(96px, 11svh) var(--home-gutter) clamp(36px, 6svh, 62px);
  }

  .sermon-showcase h2 {
    margin-bottom: 18px;
    font-size: clamp(1.85rem, 7.7vw, 2.65rem);
    line-height: 1.08;
  }

  .mission-block {
    align-content: center;
    gap: 20px;
    padding: clamp(32px, 6svh, 60px) var(--home-gutter);
    border-top: 1px solid rgba(58, 84, 109, 0.1);
    background: linear-gradient(180deg, #f7fafb, #ecf3f7);
  }

  .mission-block p {
    max-width: 25ch;
    font-size: clamp(1.35rem, 5.8vw, 2rem);
    line-height: 1.24;
    text-wrap: pretty;
  }

  .social-links {
    justify-content: flex-start;
    gap: 12px;
  }

  .social-links a {
    width: 44px;
    height: 44px;
  }

  .community-section {
    padding: var(--home-section-space) var(--home-gutter);
    padding-top: max(96px, var(--home-section-space));
  }

  .community-section h2,
  .expect-heading h2,
  .new-here h2 {
    font-size: clamp(1.9rem, 8.5vw, 3rem);
    line-height: 1.06;
    text-wrap: balance;
  }

  .community-summary {
    max-width: 29ch;
    font-size: 1rem;
    line-height: 1.55;
  }

  .ministry-grid {
    gap: 22px;
    grid-auto-rows: minmax(190px, auto);
  }

  /* Let the visible back size the track and keep all of its copy accessible. */
  .ministry-card.is-flipped,
  .ministry-card.is-flipped .ministry-card-inner {
    display: grid;
  }

  .ministry-card.is-flipped .ministry-card-inner {
    height: auto;
  }

  .ministry-card.is-flipped .ministry-card-back {
    position: relative;
    inset: auto;
    min-height: inherit;
  }

  .first-visit-section {
    background: var(--white);
  }

  .first-visit-section .rolling-welcome {
    scroll-margin-top: 0;
    padding-block: clamp(100px, 13svh, 120px) 0;
  }

  .first-visit-section .expect-section {
    padding: clamp(34px, 6svh, 54px) var(--home-gutter) var(--home-section-space);
    background: transparent;
  }

  .expect-heading {
    margin-bottom: 8px;
    padding-bottom: 22px;
    border-bottom-width: 1px;
  }

  .expect-grid {
    gap: 0;
  }

  .expect-item {
    gap: 14px;
    padding-block: 18px;
    border-bottom: 1px solid rgba(58, 84, 109, 0.14);
  }

  .expect-item:last-child {
    border-bottom: 0;
    padding-bottom: 0;
  }

  .expect-icon {
    box-shadow: none;
  }

  .expect-item h3 {
    margin-bottom: 6px;
    font-size: 1.16rem;
    line-height: 1.16;
  }

  .expect-item p {
    font-size: 1rem;
    line-height: 1.5;
  }

  .expect-full {
    display: none;
  }

  .expect-brief[hidden] {
    display: inline;
  }

  .new-here {
    min-height: 100vh;
    min-height: 100lvh;
    align-content: start;
    gap: 22px;
    padding: 94px var(--home-gutter) max(30px, env(safe-area-inset-bottom));
  }

  .new-here .section-kicker,
  .visit-title-full,
  .new-here .visit-info-card {
    display: none;
  }

  .visit-title-brief[hidden] {
    display: inline;
  }

  .new-copy .new-intro {
    max-width: 36ch;
    margin-top: 12px;
    font-size: 1rem;
    line-height: 1.5;
  }

  .new-here .visit-details {
    margin-top: 16px;
  }

  .new-here .visit-compact[hidden] {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    min-height: 56px;
    padding: 11px 14px;
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: var(--radius-card);
    background: rgba(255, 255, 255, 0.1);
    color: var(--white);
    text-decoration: none;
  }

  .visit-compact > span:first-child {
    display: grid;
    gap: 3px;
    font-size: 0.92rem;
    line-height: 1.35;
  }

  .visit-compact > span:first-child > span {
    color: rgba(255, 255, 255, 0.86);
  }

  .visit-compact-arrow {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 1px solid rgba(255, 255, 255, 0.32);
    border-radius: 50%;
  }

  .visit-compact:focus-visible {
    outline: 2px solid var(--white);
    outline-offset: 3px;
  }
}

@media (max-width: 520px) {
  /* Match the photo-cover titles and insets to the Rhythm Kids card. */
  .ministry-card .ministry-card-front h3 {
    font-size: clamp(2.9rem, 5.5vw, 6rem);
  }

  .ministry-card-front h3 br[hidden] {
    display: inline;
  }

  .ministry-card:not(.kids-feature) .ministry-card-front {
    padding: clamp(20px, 2vw, 30px);
  }

  /* The old 250px tracks were shorter than the 270px cards, eating the gaps. */
  .ministry-grid {
    grid-auto-rows: minmax(270px, auto);
  }

  .ministry-card.kids-feature.is-flipped {
    grid-row: auto;
    min-height: 270px;
  }
}

@media (max-width: 820px), (hover: none) and (pointer: coarse) {
  .is-visit-form-editing .site-header {
    visibility: hidden;
    pointer-events: none;
  }

  /* Keep fields readable for iOS focus without restricting user zoom. */
  .new-here .visit-form input:is([type="text"], [type="tel"]) {
    font-size: max(16px, 1rem);
    line-height: 1.4;
  }

  /* A tap should not trigger the form's entrance scaling or desktop hover lift. */
  .new-here .visit-form {
    animation: none;
    opacity: 1;
    transform: none;
    will-change: auto;
  }
}
