/*
 * ECCCA responsive refinement
 * Loaded last so this is the single authoritative phone/tablet layout pass.
 */

@media (max-width: 1120px) {
  :root {
    --mobile-gutter: clamp(16px, 3vw, 28px);
  }

  .shell {
    width: calc(100% - (var(--mobile-gutter) * 2)) !important;
    max-width: 1180px !important;
  }

  .section {
    padding-block: clamp(54px, 7vw, 78px) !important;
  }

  .nav {
    min-height: 76px !important;
  }

  .brand,
  .brand--full {
    width: min(300px, calc(100vw - 190px)) !important;
    min-width: 0 !important;
  }

  .brand img,
  .brand--full img {
    max-width: 100% !important;
    height: auto !important;
  }

  .navlinks.open {
    top: var(--mobile-menu-top, 76px) !important;
    max-height: calc(100dvh - var(--mobile-menu-top, 76px) - 12px) !important;
    overscroll-behavior: contain;
  }

  .hero,
  .pagehero {
    min-height: 0 !important;
  }

  .hero__grid,
  .pagehero__grid {
    gap: clamp(24px, 4vw, 44px) !important;
  }

  .heritage-join .join-grid,
  .heritage-contact .contact-grid,
  .evergreen-hero {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .heritage-join .join-grid > .full {
    grid-column: 1 / -1 !important;
  }

  .pagehero__grid {
    padding-block: clamp(44px, 7vw, 72px) !important;
  }

  .heading {
    gap: clamp(20px, 4vw, 42px) !important;
    margin-bottom: clamp(26px, 4vw, 42px) !important;
  }

  .cards,
  .feature-cards,
  .schedule,
  .board,
  .directory-grid {
    gap: clamp(12px, 2vw, 20px) !important;
  }

  .card,
  .feature-card,
  .schedule-card,
  .info-box,
  .contact-card,
  .directory-card,
  .person {
    min-height: 0 !important;
    padding: clamp(18px, 2.5vw, 26px) !important;
  }

  .feature-card__art,
  .card__symbol {
    font-size: clamp(3.4rem, 8vw, 6rem) !important;
  }

  .footer {
    padding-top: clamp(48px, 7vw, 72px) !important;
  }

  .footer-grid {
    gap: clamp(28px, 5vw, 52px) !important;
  }

  .directory-tools {
    position: static !important;
    grid-template-columns: 1fr !important;
  }

  .directory-filters {
    justify-content: flex-start !important;
  }

  .event-feature {
    gap: clamp(22px, 4vw, 40px) !important;
  }
}

/* Tablets and larger landscape phones */
@media (max-width: 900px) {
  body.tradition-in-motion {
    font-size: 16px !important;
  }

  .notice__in {
    min-height: 42px !important;
  }

  .notice p {
    font-size: 0.82rem !important;
  }

  .hero {
    padding-block: clamp(30px, 5vw, 52px) !important;
  }

  .hero__grid,
  .pagehero__grid,
  .heading,
  .story-layout,
  .content-grid,
  .contact-grid,
  .home-update-grid,
  .evergreen-hero,
  .heritage-evergreen .pagehero__grid,
  .heritage-join .join-grid {
    grid-template-columns: 1fr !important;
  }

  /* Keep section headings on one predictable reading axis on tablets. */
  .heading {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    align-items: start !important;
    text-align: left !important;
  }

  .heading > * {
    min-width: 0 !important;
    max-width: 100% !important;
    text-align: left !important;
  }

  .heading > .textlink {
    width: auto !important;
    justify-self: start !important;
  }

  /* The timeline previously added its left padding outside its 100% width. */
  .story-timeline {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  .story-motion-ready:not(.is-story-visible) .story-timeline li {
    transform: none !important;
  }

  .pagehero__grid {
    min-height: 0 !important;
    align-content: center !important;
  }

  .pagehero__grid > p {
    width: min(100%, 680px) !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 16px 18px !important;
  }

  /* Events uses a bright poster above a pale illustration. Keep its copy on a
     dedicated red reading panel instead of white type on cream. */
  body.heritage-events .pagehero__grid {
    align-self: end !important;
    padding: clamp(22px, 5vw, 34px) !important;
    border: 1px solid rgba(241, 194, 94, .42) !important;
    border-radius: 22px !important;
    color: #fff8e9 !important;
    background: rgba(126, 14, 31, .94) !important;
    box-shadow: 0 18px 42px rgba(78, 8, 19, .2) !important;
  }

  body.heritage-events .pagehero__grid :is(h1, .eyebrow) {
    color: #fff8e9 !important;
    text-shadow: none !important;
  }

  body.heritage-events .pagehero__grid .eyebrow {
    color: #f3cb72 !important;
  }

  body.heritage-events .pagehero__grid > p {
    color: rgba(255, 248, 233, .9) !important;
    border-color: rgba(243, 203, 114, .3) !important;
    background: rgba(56, 4, 13, .28) !important;
  }

  .hero__visual {
    width: min(100%, 720px);
    min-height: 0 !important;
    margin-inline: auto;
  }

  /* Keep the home photo caption inside the tablet viewport while preserving
     its intentional overlap with the image. */
  .float--event {
    left: 16px !important;
    right: auto !important;
    max-width: calc(100% - 32px) !important;
  }

  .hero__photo {
    height: clamp(280px, 48vw, 430px) !important;
    min-height: 0 !important;
  }

  .quick {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    margin-top: 54px !important;
  }

  .quick a {
    min-height: 78px !important;
    padding: 14px 16px !important;
  }

  .cards,
  .feature-cards,
  .board,
  .schedule,
  .evergreen-benefits,
  .heritage-evergreen .cards,
  .directory-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .card,
  .feature-card,
  .schedule-card,
  .directory-card,
  .person {
    grid-column: auto !important;
    grid-row: auto !important;
  }

  .heritage-join .join-grid > * {
    grid-column: auto !important;
    grid-row: auto !important;
    width: 100% !important;
  }

  .event-feature {
    grid-template-columns: minmax(230px, 0.8fr) minmax(0, 1.2fr) !important;
    padding: 18px !important;
  }

  .event-feature__details h2 {
    font-size: clamp(2rem, 5vw, 3.25rem) !important;
  }

  .heritage-evergreen .evergreen-hero-slider .photo-slider__slide,
  .heritage-evergreen .evergreen-hero-slider .photo-slider__viewport,
  .photo-slider__slide {
    height: clamp(280px, 48vw, 390px) !important;
    min-height: 0 !important;
  }

  .photo-slider__controls {
    bottom: 10px !important;
    min-height: 38px !important;
    padding: 4px 7px !important;
  }

  .photo-slider__prev,
  .photo-slider__next {
    width: 36px !important;
    height: 36px !important;
  }

  .directory-emergency > .shell {
    grid-template-columns: 1fr !important;
  }

  .directory-emergency__numbers a {
    min-height: 92px !important;
  }

  .footer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .footer-grid > div:first-child {
    grid-column: 1 / -1 !important;
  }
}

/* Landscape phone: retain a useful two-column rhythm without tall panels. */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 620px) {
  .section {
    padding-block: 38px !important;
  }

  body.tradition-in-motion h1 {
    font-size: clamp(2.15rem, 6vw, 3.35rem) !important;
  }

  body.tradition-in-motion h2 {
    font-size: clamp(1.7rem, 4.5vw, 2.5rem) !important;
  }

  .hero__grid,
  .pagehero__grid {
    grid-template-columns: minmax(0, 1.05fr) minmax(260px, 0.95fr) !important;
    align-items: center !important;
    padding-block: 28px !important;
  }

  .heritage-join .join-grid,
  .heritage-contact .contact-grid,
  .evergreen-hero {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .heritage-join .join-grid > .full {
    grid-column: 1 / -1 !important;
  }

  .hero__photo,
  .heritage-evergreen .evergreen-hero-slider .photo-slider__slide,
  .heritage-evergreen .evergreen-hero-slider .photo-slider__viewport,
  .photo-slider__slide {
    height: 250px !important;
  }

  .hero__lead {
    margin-bottom: 18px !important;
  }

  .quick {
    margin-top: 22px !important;
  }

  .pagehero__grid > p {
    padding: 14px 16px !important;
  }

  .cards,
  .feature-cards,
  .schedule,
  .board,
  .directory-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .card,
  .feature-card,
  .schedule-card,
  .info-box,
  .directory-card,
  .person {
    padding: 16px !important;
  }
}

.quick-scroll-hint {
  display: none;
}

/* Portrait phones */
@media (max-width: 640px) {
  :root {
    --mobile-gutter: 12px;
  }

  html {
    scroll-padding-top: 74px;
  }

  body.tradition-in-motion {
    font-size: 15.5px !important;
  }

  body.tradition-in-motion h1 {
    font-size: clamp(2.25rem, 11vw, 3.15rem) !important;
    line-height: 0.98 !important;
    overflow-wrap: anywhere;
  }

  body.tradition-in-motion h2 {
    font-size: clamp(1.75rem, 8vw, 2.35rem) !important;
    line-height: 1.05 !important;
  }

  body.tradition-in-motion h3 {
    font-size: clamp(1.05rem, 5vw, 1.3rem) !important;
  }

  body.tradition-in-motion :is(h1, h2, h3, p, a, span) {
    overflow-wrap: break-word;
  }

  .section {
    padding-block: 42px !important;
  }

  .notice__in {
    min-height: 38px !important;
    padding-block: 5px !important;
  }

  .notice p {
    -webkit-line-clamp: 1 !important;
    line-height: 1.3 !important;
  }

  .nav {
    min-height: 70px !important;
    gap: 7px !important;
  }

  .brand,
  .brand--full {
    width: min(205px, calc(100vw - 156px)) !important;
  }

  .brand img,
  .brand--full img {
    max-height: 50px !important;
  }

  .lang {
    min-width: 72px !important;
    height: 42px !important;
  }

  .lang span {
    min-width: 31px !important;
    padding-inline: 4px !important;
    font-size: 0.75rem !important;
  }

  .menu {
    width: 42px !important;
    height: 42px !important;
  }

  .navlinks.open {
    top: var(--mobile-menu-top, 70px) !important;
    right: 8px !important;
    left: 8px !important;
    padding: 8px !important;
    border-radius: 15px !important;
  }

  .navlinks a {
    min-height: 43px !important;
    padding: 7px 12px !important;
    font-size: 0.9rem !important;
  }

  .hero {
    padding-block: 28px 34px !important;
  }

  .hero__grid,
  .pagehero__grid {
    gap: 20px !important;
  }

  .hero__lead {
    font-size: 1rem !important;
    line-height: 1.65 !important;
  }

  .hero__actions,
  .event-feature__actions,
  .community-closing__content > div {
    gap: 10px !important;
  }

  /* Compact, fully aligned community call-to-action below the home photo. */
  body.heritage-home .community-closing__image {
    height: clamp(220px, 66vw, 300px) !important;
    background-position: 54% center !important;
  }

  body.heritage-home .community-closing__content {
    width: calc(100% - (var(--mobile-gutter) * 2)) !important;
    padding-block: 24px 28px !important;
    gap: 10px !important;
    align-items: flex-start !important;
    text-align: left !important;
  }

  body.heritage-home .community-closing__content > .eyebrow {
    width: auto !important;
    margin: 0 !important;
    align-self: flex-start !important;
    text-align: left !important;
  }

  body.heritage-home .community-closing__content > h2,
  body.heritage-home .community-closing__content > p:not(.eyebrow) {
    width: 100% !important;
    margin-inline: 0 !important;
    text-align: left !important;
  }

  body.heritage-home .community-closing__content > h2 {
    max-width: 12ch !important;
    margin-top: 2px !important;
  }

  body.heritage-home .community-closing__content > p:not(.eyebrow) {
    max-width: 32ch !important;
    margin-top: 2px !important;
    font-size: 1rem !important;
    line-height: 1.55 !important;
  }

  body.heritage-home .community-closing__content > div {
    width: 100% !important;
    margin-top: 8px !important;
    flex-flow: row wrap !important;
    align-items: center !important;
  }

  body.heritage-home .community-closing__content > div :is(.btn, .textlink) {
    min-height: 44px !important;
    margin: 0 !important;
  }

  /* The events artwork is pale on phones, so the former cream label vanished. */
  html body.heritage-home.tradition-in-motion #main > .section.section--cream .heading .eyebrow {
    color: #811a2b !important;
    text-shadow: 0 1px 0 rgba(255, 252, 244, .9), 0 1px 8px rgba(255, 252, 244, .72) !important;
  }

  /* Give the tanghulu room without letting its cards spill past the viewport. */
  html body.heritage-home.tradition-in-motion .story-scroll .story-timeline {
    padding-left: 64px !important;
  }

  html body.heritage-home.tradition-in-motion .story-scroll .story-timeline::before {
    left: 24px !important;
  }

  html body.heritage-home.tradition-in-motion .story-scroll .story-timeline::after {
    left: 20px !important;
  }

  html body.heritage-home.tradition-in-motion .story-scroll .story-timeline li {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 6px !important;
    padding: 16px !important;
  }

  .heritage-evergreen .evergreen-photo,
  .heritage-evergreen .evergreen-photo img {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  html body.heritage-home.tradition-in-motion .story-scroll .story-timeline .tanghulu-fruit,
  html body.heritage-home.tradition-in-motion .story-scroll .story-timeline .tanghulu-fruit[data-fruit] {
    left: -40px !important;
  }

  .hero__actions .btn,
  .hero__actions .textlink,
  .event-feature__actions .btn,
  .event-feature__actions .textlink {
    width: 100% !important;
    min-height: 44px !important;
    justify-content: center !important;
    text-align: center;
  }

  .hero__photo {
    height: 245px !important;
    border-radius: 34px 34px 16px 16px !important;
  }

  .float--hello {
    top: 10px !important;
    right: 8px !important;
    transform: scale(0.82) !important;
    transform-origin: top right;
  }

  .float--event {
    right: 10px !important;
    bottom: 10px !important;
    left: 10px !important;
    padding: 11px 13px !important;
  }

  /* A short, swipeable quick-link rail uses far less vertical space. */
  .quick {
    display: flex !important;
    gap: 9px !important;
    margin-top: 44px !important;
    padding: 2px 0 8px !important;
    overflow-x: auto;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    scroll-padding-inline: 2px;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
  }

  /* The compact cards continue horizontally on phones. Keep the hint in
     normal flow so it never covers a card or the hero photograph. */
  html body.heritage-home .hero::after {
    content: "Swipe to see all four options  \2192" !important;
    display: block !important;
    width: calc(100% - (var(--mobile-gutter) * 2));
    margin: 8px auto 0;
    color: #7f1a29;
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-align: right;
  }

  html[lang^="zh"] body.heritage-home .hero::after {
    content: "左右滑動查看四個選項  \2192" !important;
  }

  .quick a {
    flex: 0 0 min(78vw, 270px) !important;
    min-height: 68px !important;
    padding: 11px 13px !important;
    border: 1px solid rgba(171, 117, 45, 0.24) !important;
    border-radius: 15px !important;
    background: rgba(255, 252, 246, 0.94) !important;
    scroll-snap-align: start;
  }

  .quick__icon {
    width: 38px !important;
    height: 38px !important;
  }

  .quick__copy small,
  .quick__copy b {
    line-height: 1.2 !important;
  }

  .pagehero__grid {
    padding-block: 32px !important;
  }

  .pagehero__grid > div:first-child,
  .pagehero__grid > p {
    padding: 16px !important;
    border-radius: 18px !important;
  }

  .pagehero__grid > div:first-child::after {
    width: 76px !important;
    margin-top: 1rem !important;
  }

  .heading {
    margin-bottom: 24px !important;
  }

  .heading::before {
    width: 56px !important;
  }

  .heading .eyebrow,
  .pagehero .eyebrow,
  .story-intro .eyebrow,
  .eyebrow {
    min-height: 0 !important;
    padding: 0.2rem 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
  }

  .cards,
  .feature-cards,
  .board,
  .schedule,
  .evergreen-benefits,
  .heritage-evergreen .cards,
  .directory-grid,
  .footer-grid {
    grid-template-columns: 1fr !important;
    gap: 11px !important;
  }

  .card,
  .feature-card,
  .schedule-card,
  .info-box,
  .contact-card,
  .directory-card,
  .person {
    padding: 16px !important;
    border-radius: 16px !important;
  }

  .card p,
  .feature-card p,
  .schedule-card p,
  .info-box p,
  .directory-card p {
    margin-block: 7px !important;
    line-height: 1.48 !important;
  }

  .card h3 {
    margin: 2.4rem 0 0.55rem !important;
  }

  .feature-card {
    grid-template-columns: 68px 1fr !important;
    align-items: center !important;
    gap: 12px !important;
  }

  .feature-card__art,
  .card__symbol {
    font-size: 3rem !important;
  }

  .event,
  .hospital-announcement,
  .event-feature {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
    padding: 14px !important;
    border-radius: 18px !important;
  }

  .event-feature__poster {
    width: min(100%, 330px) !important;
  }

  .event-feature__details {
    padding: 2px !important;
  }

  .event-feature__details h2 {
    font-size: 2rem !important;
  }

  .weekly-resource-placeholder,
  .weekly-summary-heading {
    padding: 16px !important;
  }

  .schedule-card header {
    gap: 8px !important;
  }

  .heritage-evergreen .evergreen-hero-slider .photo-slider__slide,
  .heritage-evergreen .evergreen-hero-slider .photo-slider__viewport,
  .photo-slider__slide,
  .evergreen-photo {
    height: 220px !important;
    min-height: 0 !important;
  }

  .photo-slider__controls {
    right: 8px !important;
    bottom: 8px !important;
    left: 8px !important;
    width: auto !important;
  }

  .photo-slider__dots {
    max-width: 112px !important;
  }

  .heritage-gallery .gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    grid-auto-rows: 96px !important;
    gap: 7px !important;
  }

  .heritage-gallery .gallery figure,
  .heritage-gallery .gallery figure:nth-child(n),
  .heritage-gallery .gallery figure.is-wide,
  .heritage-gallery .gallery figure.is-portrait {
    grid-column: span 1 !important;
    grid-row: span 2 !important;
    border-radius: 10px !important;
  }

  .heritage-gallery .gallery figure:nth-child(5n + 1) {
    grid-column: span 2 !important;
    grid-row: span 3 !important;
  }

  .heritage-gallery .gallery figcaption {
    right: 5px !important;
    bottom: 5px !important;
    left: 5px !important;
    padding: 6px 8px !important;
    font-size: 0.68rem !important;
  }

  .directory-emergency > .shell {
    padding-block: 30px !important;
  }

  .directory-emergency__numbers {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 7px !important;
  }

  .directory-emergency__numbers a {
    min-height: 78px !important;
    padding: 9px 4px !important;
    border-radius: 13px !important;
  }

  .directory-emergency__numbers strong {
    font-size: 1.9rem !important;
  }

  .directory-tools {
    gap: 9px !important;
    padding: 10px !important;
    border-radius: 14px !important;
  }

  .directory-tools input {
    min-height: 44px !important;
  }

  .directory-filters {
    flex-wrap: nowrap !important;
    justify-content: flex-start !important;
    padding-bottom: 5px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
  }

  .directory-filters button {
    flex: 0 0 auto;
    min-height: 40px !important;
    scroll-snap-align: start;
  }

  .directory-card__top {
    grid-template-columns: 36px 1fr !important;
    gap: 10px !important;
  }

  .directory-card__mark {
    width: 36px !important;
  }

  .contact-grid form {
    grid-template-columns: 1fr !important;
  }

  .contact-grid form > *,
  .contact-grid form .full {
    grid-column: auto !important;
  }

  .funders {
    padding-block: 42px !important;
  }

  .funder-row {
    gap: 18px !important;
  }

  .funder-bubble {
    width: 220px !important;
    min-width: 220px !important;
    min-height: 128px !important;
    flex: 0 0 220px !important;
    padding: 12px !important;
  }

  .funder-bubble img {
    max-width: 190px !important;
    max-height: 88px !important;
  }

  .footer-grid > div:first-child {
    grid-column: auto !important;
  }

  .footer-bottom {
    align-items: flex-start !important;
    flex-direction: column !important;
    gap: 8px !important;
  }

  .lantern-top {
    right: 8px !important;
    bottom: 8px !important;
    transform: scale(0.76) !important;
    transform-origin: bottom right;
  }
}

/* Low-end phones still receive the lightweight, compositor-only sponsor loop.
   Reduced-motion users retain the static, horizontally scrollable list. */
@media (max-width: 1180px) and (prefers-reduced-motion: no-preference) {
  html.performance-ready .funders {
    content-visibility: visible !important;
  }

  .quick-scroll-hint {
    display: block !important;
    margin: 6px auto 0;
    padding-inline: 2px;
    color: #7f1a29;
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-align: right;
  }

  html body.heritage-home .hero::after {
    content: none !important;
    display: none !important;
  }

  html.performance-lite:not(.reduce-motion) .sponsor-marquee {
    animation: sponsor-scroll 42s linear infinite !important;
    will-change: transform !important;
    backface-visibility: hidden;
  }

  html.performance-lite:not(.reduce-motion) .sponsor-marquee:not(.is-offscreen) {
    animation-play-state: running !important;
  }

  html.performance-lite:not(.reduce-motion) .sponsor-marquee.is-offscreen {
    animation-play-state: paused !important;
  }
}

@media (max-width: 1180px) {
  .sponsor-viewport {
    touch-action: pan-x;
  }
}

/* Desktop transition artwork should be fully visible rather than cropped to
   fill a wide monitor. The surrounding colour belongs to each page palette. */
/*@media (min-width: 901px) {
  .page-transition[data-destination] {
    background-size: contain !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
  }

  .page-transition[data-destination="home"],
  .page-transition[data-destination="events"],
  .page-transition[data-destination="join"] { background-color: #650c17 !important; }
  .page-transition[data-destination="about"] { background-color: #120e0b !important; }
  .page-transition[data-destination="weekly"] { background-color: #efe2c7 !important; }
  .page-transition[data-destination="evergreen"] { background-color: #173f33 !important; }
  .page-transition[data-destination="gallery"],
  .page-transition[data-destination="directory"] { background-color: #dcecf4 !important; }
  .page-transition[data-destination="contact"] { background-color: #fff8fa !important; }
}I*/

@media (max-width: 390px) {
  .brand,
  .brand--full {
    width: min(170px, calc(100vw - 146px)) !important;
  }

  .hero__photo {
    height: 215px !important;
  }

  .directory-emergency__numbers span {
    font-size: 0.68rem !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .quick,
  .directory-filters {
    scroll-behavior: auto !important;
  }
}
