/* Mobile and tablet optimisation. Desktop rules at 901px and above remain untouched. */

@media (max-width: 900px) {
  :root {
    --section: clamp(58px, 12vw, 92px);
  }

  html {
    scroll-padding-top: calc(68px + env(safe-area-inset-top));
  }

  body {
    min-width: 0;
    overflow-x: clip;
  }

  main {
    overflow-x: clip;
  }

  .site-header {
    height: calc(68px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
  }

  .brand {
    min-width: 0;
    min-height: 44px;
    gap: 9px;
  }

  .brand-logo {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
  }

  .brand span {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .menu-toggle,
  .avatar {
    min-width: 44px;
    width: 44px;
    min-height: 44px;
    height: 44px;
    place-items: center;
  }

  .menu-toggle {
    margin-right: -8px;
    display: grid;
  }

  .main-nav {
    max-height: calc(100dvh - 68px - env(safe-area-inset-top));
    inset: calc(68px + env(safe-area-inset-top)) 0 auto;
    padding: 14px max(18px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .main-nav > a,
  .main-nav .search-nav,
  .main-nav .account,
  .account-menu a,
  .account-menu button {
    min-height: 48px;
  }

  .main-nav > a,
  .main-nav .search-nav {
    align-items: center;
    padding: 13px 8px;
    display: flex;
  }

  .main-nav .account {
    padding: 6px 8px;
  }

  .section-pad,
  .archive-page,
  .memories-archive > .large-search,
  .memories-archive > .filter-row {
    width: min(calc(100% - 40px), var(--container));
  }

  .section-heading {
    align-items: flex-start;
    gap: 18px;
  }

  .section-heading h2 {
    font-size: clamp(2.8rem, 10vw, 4.6rem);
  }

  .button {
    min-height: 48px;
    padding-inline: 18px;
    touch-action: manipulation;
  }

  .text-link,
  .timeline-card-back a,
  .site-footer a {
    min-height: 44px;
    align-items: center;
    display: inline-flex;
  }

  /* Home: retain the reveal, but make every stage fit a touch viewport. */
  .split-opener-hero {
    height: 100svh;
    min-height: 600px;
  }

  .split-hero-surface {
    background:
      linear-gradient(180deg, rgba(3, 15, 24, .18), rgba(3, 15, 24, .86)),
      url('/archive/hero-archive-room.webp') center / cover;
  }

  @supports (height: 100dvh) {
    .split-opener-hero {
      height: 100dvh;
    }
  }

  .hero-reference-image {
    display: none;
  }

  .mobile-reference-actions {
    bottom: calc(22px + env(safe-area-inset-bottom));
  }

  .mobile-reference-actions::before {
    content: "Every year leaves a mark.";
    color: #f5efe4;
    grid-column: 1 / -1;
    max-width: 620px;
    margin: 0 auto clamp(12px, 3vh, 24px);
    text-align: center;
    text-wrap: balance;
    font: 500 clamp(3.1rem, 12vw, 5rem)/.82 var(--font-display);
    letter-spacing: -.05em;
    text-shadow: 0 8px 30px rgba(0, 0, 0, .34);
  }

  .intro-section {
    padding-inline: 20px;
  }

  .intro-reading-line {
    font-size: clamp(2.35rem, 8.8vw, 4rem);
    line-height: 1;
  }

  .home-stats,
  .stat-line {
    margin-top: 48px;
  }

  .home-stats > div,
  .stat-line > div {
    min-height: 118px;
  }

  .featured-memory {
    gap: 32px;
  }

  .featured-memory h2,
  .on-this-day h2 {
    font-size: clamp(2.8rem, 10vw, 4.5rem);
  }

  .explore-tile,
  .portrait-rail > a,
  .leadership-archive > a,
  .vacation-card,
  .project-overview-grid > a {
    -webkit-tap-highlight-color: transparent;
  }

  .journey-showcase {
    padding-block: 62px 48px;
  }

  .journey-top {
    width: 100%;
  }

  .journey-top h2 {
    font-size: clamp(2.65rem, 10vw, 3.8rem);
  }

  .journey-stage {
    margin: 32px 0 8px;
  }

  .journey-card {
    contain: layout paint;
  }

  .journey-timeline,
  .book-chapters,
  .project-year-rail,
  .project-category-row,
  .category-row,
  .result-tabs,
  .people-inline {
    scrollbar-width: none;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  .journey-timeline::-webkit-scrollbar,
  .book-chapters::-webkit-scrollbar,
  .project-year-rail::-webkit-scrollbar,
  .project-category-row::-webkit-scrollbar,
  .category-row::-webkit-scrollbar,
  .result-tabs::-webkit-scrollbar,
  .people-inline::-webkit-scrollbar {
    display: none;
  }

  .journey-timeline button,
  .book-chapters button,
  .project-year-rail button,
  .category-row button,
  .result-tabs button,
  .filter-reset {
    min-height: 44px;
    touch-action: manipulation;
  }

  .journey-active-cta {
    min-height: 44px;
    align-items: center;
    justify-content: center;
    display: flex;
  }

  /* Public page heroes and detail views. */
  .page-hero,
  .journey-page-intro,
  .memories-intro,
  .search-hero,
  .project-year-hero,
  .vacation-intro {
    padding-inline: 20px;
  }

  .page-hero,
  .journey-page-intro,
  .memories-intro {
    padding-top: calc(104px + env(safe-area-inset-top));
    padding-bottom: 58px;
  }

  .page-hero h1,
  .journey-page-intro h1,
  .memories-intro h1,
  .search-hero h1,
  .project-year-hero h1,
  .vacation-intro h1,
  .year-hero h1,
  .project-hero h1,
  .profile-hero h1 {
    max-width: 100%;
    overflow-wrap: anywhere;
    text-wrap: balance;
  }

  .year-hero,
  .project-hero {
    min-height: min(76svh, 720px);
    padding: calc(104px + env(safe-area-inset-top)) 20px 52px;
    background-position: center;
  }

  .profile-hero {
    min-height: auto;
    padding: calc(104px + env(safe-area-inset-top)) 20px 62px;
  }

  .year-intro,
  .profile-hero,
  .leader-feature,
  .highlights article,
  .highlights article.reverse {
    direction: ltr;
    gap: 34px;
  }

  .year-intro img,
  .profile-hero > img,
  .leader-feature img {
    max-height: 68svh;
    object-position: center top;
  }

  .project-strip > a {
    grid-template-columns: minmax(150px, .7fr) 1fr;
    gap: 24px;
  }

  .project-strip > a,
  .committee-list a,
  .documents button,
  .member-directory > a,
  .result-row,
  .year-pager a {
    min-height: 48px;
  }

  .large-search {
    min-height: 58px;
    padding-inline: 16px;
  }

  .large-search input {
    min-height: 44px;
    font-size: 16px;
  }

  .large-search button {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
  }

  .filter-row,
  .category-row,
  .result-tabs {
    touch-action: pan-x;
  }

  .filter-row select,
  .directory-heading input,
  .login-page input,
  .form-fields input,
  .form-fields select,
  .form-fields textarea {
    min-height: 48px;
    font-size: 16px;
  }

  .leadership-archive,
  .portrait-rail {
    gap: 14px;
  }

  .leadership-archive a,
  .portrait-rail a {
    min-width: 0;
  }

  .member-directory > a {
    grid-template-columns: 74px minmax(0, 1fr) auto;
    gap: 16px;
  }

  .member-directory img {
    width: 74px;
    height: 74px;
  }

  .result-tabs,
  .category-row {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
  }

  .result-tabs button,
  .category-row button {
    flex: 0 0 auto;
    min-width: 44px;
  }

  .lightbox {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 52svh) auto;
    align-content: start;
    padding: calc(66px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
    overflow-y: auto;
  }

  .lightbox > img {
    height: 100%;
    min-height: 0;
  }

  .lightbox article {
    padding: 24px 4px 40px;
  }

  .lightbox h2 {
    font-size: clamp(2.5rem, 10vw, 3.5rem);
  }

  .lightbox-close {
    top: calc(14px + env(safe-area-inset-top));
    right: 14px;
  }

  .lightbox-prev,
  .lightbox-next {
    top: calc(30svh + env(safe-area-inset-top));
  }

  .lightbox-prev { left: 12px; }
  .lightbox-next { right: 12px; }

  /* Vacations. */
  .vacation-detail-hero {
    padding-top: calc(68px + env(safe-area-inset-top));
  }

  .vacation-detail-image {
    min-height: min(54svh, 540px);
  }

  .vacation-detail-copy {
    padding: 48px 20px 60px;
  }

  .vacation-back {
    min-height: 44px;
    margin-bottom: 34px;
    align-items: center;
    display: inline-flex;
  }

  .vacation-gallery {
    width: min(calc(100% - 40px), var(--container));
  }

  /* Login, admin and forms. */
  .login-page,
  .memory-form-page {
    min-height: 100svh;
    padding-top: calc(68px + env(safe-area-inset-top));
  }

  .login-page form,
  .memory-form-page form {
    padding-inline: 20px;
  }

  .login-page label,
  .form-fields label {
    font-size: .74rem;
  }

  .login-forgot,
  .admin-shell > nav a,
  .admin-shell > nav button {
    min-height: 44px;
  }

  .admin-shell > nav {
    scrollbar-width: none;
  }

  .upload-zone {
    min-height: 260px;
  }

  .site-footer {
    padding: 52px 20px calc(36px + env(safe-area-inset-bottom));
  }
}

@media (min-width: 769px) and (max-width: 900px) {
  .journey-stage {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .journey-card {
    height: 540px;
  }

  .realistic-book {
    background: transparent;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    display: grid;
  }

  .book-sheet {
    min-width: 0;
    height: 520px;
    margin: 0;
  }

  .book-chapters {
    flex-wrap: nowrap;
    overflow-x: auto;
  }
}

@media (max-width: 768px) {
  .section-heading {
    display: block;
  }

  .section-heading a {
    min-height: 44px;
    margin-top: 18px;
    align-items: center;
    display: inline-flex;
  }

  .mobile-reference-actions {
    grid-template-columns: 1fr 1fr;
    display: grid;
    align-items: end;
  }

  .intro-section {
    padding-block: 68px;
  }

  .intro-kicker {
    margin-bottom: 40px;
  }

  .journey-showcase {
    padding-inline: 20px;
    overflow: clip;
  }

  .journey-card {
    width: 100%;
    height: clamp(410px, 55svh, 470px);
    margin-bottom: 18px;
    position: relative;
    inset: auto;
    transform-origin: center bottom;
  }

  .journey-card:last-child {
    margin-bottom: 8px;
  }

  .journey-card-copy {
    min-height: 0;
    padding: 14px 8px 5px;
  }

  .journey-card-copy h3 {
    font-size: clamp(1.55rem, 7vw, 1.95rem);
  }

  .journey-timeline {
    top: calc(68px + env(safe-area-inset-top));
    margin-inline: -20px;
    width: calc(100% + 40px);
    padding: 8px 20px 10px;
  }

  .journey-timeline button {
    flex: 0 0 auto;
    padding-inline: 12px;
  }

  .journey-active-cta {
    bottom: calc(12px + env(safe-area-inset-bottom));
    max-width: calc(100% - 40px);
    min-height: 44px;
    align-items: center;
    justify-content: center;
    display: flex;
  }

  .journey-scroll-hint {
    display: none;
  }

  .journey-page-intro h1,
  .memories-intro h1,
  .page-hero h1 {
    font-size: clamp(3.25rem, 14vw, 4.5rem);
  }

  .flip-timeline {
    padding: 52px 16px 74px;
  }

  .flip-timeline-rail {
    left: 27px;
  }

  .flip-timeline-step,
  .flip-timeline-step.is-reverse {
    grid-template-columns: 22px minmax(0, 1fr);
    gap: 13px;
    margin-bottom: 52px;
  }

  .timeline-node {
    width: 22px;
    height: 22px;
    box-shadow: 0 0 0 5px var(--paper);
  }

  .timeline-side-note span {
    font-size: 1.75rem;
  }

  .timeline-flip-card,
  .flip-timeline-step.is-reverse .timeline-flip-card {
    height: clamp(430px, 64svh, 540px);
  }

  .timeline-card-front > div {
    bottom: 22px;
    left: 22px;
    right: 22px;
  }

  .timeline-card-front h2,
  .timeline-card-back h2 {
    font-size: clamp(2.35rem, 10vw, 3.15rem);
  }

  .timeline-card-back {
    padding: clamp(27px, 8vw, 38px);
  }

  .timeline-card-back > p {
    font-size: .74rem;
    line-height: 1.6;
  }

  .timeline-card-stats {
    margin-block: 16px 20px;
  }

  .realistic-book-scroll {
    padding: 48px 20px 62px;
  }

  .book-heading {
    margin-bottom: 20px;
  }

  .book-heading h2 {
    font-size: clamp(2.65rem, 11vw, 3.6rem);
    line-height: .92;
  }

  .book-chapters {
    margin: 18px -20px 18px;
    padding-inline: 20px;
  }

  .realistic-book {
    border-width: 8px;
    width: 100%;
    height: clamp(470px, 68svh, 590px);
    touch-action: pan-x;
  }

  .book-sheet-face {
    padding: 7%;
  }

  .book-sheet-face figure {
    border-width: 5px;
    height: 48%;
  }

  .book-sheet-face > strong,
  .book-verso-copy strong {
    font-size: clamp(1.6rem, 7.5vw, 2.25rem);
    line-height: .96;
  }

  .page-hero,
  .page-hero.compact {
    min-height: 48svh;
  }

  .year-hero h1,
  .project-hero h1,
  .profile-hero h1 {
    font-size: clamp(3.3rem, 14vw, 4.7rem);
  }

  .highlights article,
  .highlights article.reverse {
    margin-block: 46px;
  }

  .highlights h3 {
    font-size: clamp(2.35rem, 9vw, 3rem);
  }

  .project-strip > a {
    grid-template-columns: 112px minmax(0, 1fr);
    gap: 16px;
  }

  .project-strip h3 {
    font-size: 1.65rem;
  }

  .project-overview-grid > a:nth-child(n) {
    min-height: 390px;
  }

  .project-year-hero,
  .vacation-intro {
    min-height: 56svh;
    padding: calc(112px + env(safe-area-inset-top)) 20px 48px;
  }

  .project-year-hero h1,
  .vacation-intro h1 {
    font-size: clamp(3.25rem, 12vw, 4.5rem);
  }

  .project-year-controls,
  .vacation-years {
    padding-inline: 20px;
  }

  .project-category-row {
    flex-wrap: wrap;
    overflow: visible;
    gap: 4px 8px;
  }

  .project-category-row button {
    flex: 0 1 auto;
    min-height: 44px;
    padding-inline: 10px;
  }

  .vacation-grid {
    grid-template-columns: 1fr;
  }

  .vacation-cover {
    aspect-ratio: 1.32;
  }

  .vacation-story {
    grid-template-columns: 1fr;
    gap: 42px;
  }

  .vacation-story h2 {
    font-size: clamp(2.8rem, 11vw, 4.2rem);
  }

  .vacation-gallery {
    grid-template-columns: 1fr;
    grid-template-rows: 58vw 48vw 48vw;
  }

  .vacation-gallery-image:first-child {
    grid-row: auto;
  }

  .search-hero {
    min-height: auto;
    padding: calc(116px + env(safe-area-inset-top)) 20px 48px;
  }

  .search-hero h1 {
    font-size: clamp(3.35rem, 14vw, 4.5rem);
  }

  .search-results > header {
    padding-top: 32px;
  }

  .result-row {
    grid-template-columns: 76px minmax(0, 1fr) auto;
    gap: 12px;
  }

  .result-row > img {
    width: 76px;
    height: 76px;
  }

  .result-row h3 {
    overflow-wrap: anywhere;
  }

  .login-visual {
    min-height: 260px;
  }

  .login-page form {
    padding-block: 40px calc(48px + env(safe-area-inset-bottom));
  }

  .login-page h1 {
    font-size: clamp(2.9rem, 12vw, 4rem);
  }

  .admin-shell > nav {
    margin-inline: -20px;
    padding-inline: 20px;
  }

  .recent-table > div {
    grid-template-columns: 54px minmax(0, 1fr) auto;
  }

  .memory-form-page form > footer {
    gap: 12px;
  }
}

@media (max-width: 480px) {
  .site-header {
    padding-inline: max(14px, env(safe-area-inset-left));
  }

  .brand span {
    max-width: 205px;
    font-size: .98rem;
  }

  .brand i {
    display: none;
  }

  .section-pad,
  .archive-page,
  .memories-archive > .large-search,
  .memories-archive > .filter-row {
    width: min(calc(100% - 32px), var(--container));
  }

  .mobile-reference-actions {
    grid-template-columns: 1fr;
    left: 16px;
    right: 16px;
  }

  .mobile-reference-actions::before {
    margin-bottom: 10px;
    font-size: clamp(2.9rem, 14vw, 3.75rem);
  }

  .mobile-reference-actions .button {
    width: 100%;
  }

  .intro-section {
    padding-inline: 16px;
  }

  .intro-reading-line {
    font-size: clamp(2.15rem, 11vw, 3rem);
  }

  .home-stats > div,
  .stat-line > div {
    min-height: 108px;
    padding-inline: 14px;
  }

  .explore-layout {
    grid-template-rows: repeat(4, 225px);
  }

  .on-this-day > img {
    height: 300px;
  }

  .portrait-rail,
  .leadership-archive {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .journey-card {
    height: clamp(390px, 54svh, 440px);
  }

  .journey-card-image {
    min-height: 0;
  }

  .timeline-flip-card,
  .flip-timeline-step.is-reverse .timeline-flip-card {
    height: clamp(410px, 66svh, 510px);
  }

  .timeline-card-back::before {
    inset: 9px;
  }

  .timeline-card-back > p {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
  }

  .timeline-card-stats {
    gap: 8px;
  }

  .realistic-book {
    height: clamp(450px, 68svh, 540px);
  }

  .book-sheet-face figure {
    margin-block: 10px;
  }

  .page-hero,
  .journey-page-intro,
  .memories-intro,
  .search-hero,
  .project-year-hero,
  .vacation-intro {
    padding-inline: 16px;
  }

  .page-hero h1,
  .journey-page-intro h1,
  .memories-intro h1,
  .search-hero h1,
  .project-year-hero h1,
  .vacation-intro h1,
  .year-hero h1,
  .project-hero h1,
  .profile-hero h1 {
    font-size: clamp(3rem, 14.5vw, 4.05rem);
  }

  .project-strip > a {
    grid-template-columns: 92px minmax(0, 1fr);
  }

  .project-strip h3 {
    font-size: 1.45rem;
  }

  .member-directory > a {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .member-directory img {
    width: 64px;
    height: 64px;
  }

  .member-directory > a > :last-child {
    grid-column: 2;
  }

  .result-row {
    grid-template-columns: 68px minmax(0, 1fr);
  }

  .result-row > img {
    width: 68px;
    height: 68px;
  }

  .result-row > :last-child {
    grid-column: 2;
  }

  .vacation-meta {
    grid-template-columns: 1fr 1fr;
    gap: 22px 16px;
  }

  .vacation-detail-copy h1 {
    font-size: clamp(3.3rem, 15vw, 4.25rem);
  }

  .site-footer > div {
    align-items: start;
  }
}

/* Keep the 16:9 opening artwork undistorted on portrait screens while
   preserving the two-panel reveal. Both halves reference the same centered
   image coordinates, so the seal stays circular and the seam stays aligned. */
@media (max-width: 900px) and (orientation: portrait) {
  .opener-half {
    background-color: #050c15;
    background-image:
      url('/archive/opener-seal.webp'),
      linear-gradient(180deg, transparent 0 81%, rgba(3, 8, 15, 1) 87% 100%),
      url('/archive/opener-seal.webp');
    background-size: auto 72dvh, 100% 100%, auto 100dvh;
    background-position-y: center, center, center;
  }

  .opener-half-left {
    background-position-x:
      calc((100vw - 128dvh) / 2),
      center,
      calc((100vw - 177.7778dvh) / 2);
  }

  .opener-half-right {
    background-position-x: calc(-64dvh), center, calc(-88.8889dvh);
  }
}

@media (max-width: 900px) and (orientation: landscape) and (max-height: 560px) {
  .split-opener-hero,
  .archive-seal-hero,
  .archive-window-stage {
    min-height: 520px;
  }

  .mobile-reference-actions {
    grid-template-columns: 1fr 1fr;
  }

  .journey-card,
  .timeline-flip-card,
  .flip-timeline-step.is-reverse .timeline-flip-card {
    height: 430px;
  }

  .login-visual {
    min-height: 220px;
  }
}

@media (hover: none) and (pointer: coarse) and (max-width: 900px) {
  .button:hover,
  .portrait-rail > a:hover,
  .vacation-card:hover,
  .vacation-card:hover .vacation-cover,
  .project-overview-grid > a:hover,
  .project-overview-grid > a:hover img,
  .memory-tile:hover,
  .memory-tile:hover img,
  .result-row:hover {
    transform: none;
    box-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) and (max-width: 900px) {
  .journey-card,
  .timeline-flip-inner,
  .realistic-book {
    will-change: auto !important;
  }
}
