/* Mobile & tablet navigation, touch, and rendering refinements (<= 960px) */

/* The Filters toggle only exists for the phone browse sheet; wider drawers always show their filters */
@media (min-width: 601px) {
  .filters-toggle {
    display: none;
  }
}

/* The floating "Find my place" pill belongs to the touch layouts; desktop keeps its own link */
@media (min-width: 961px) {
  .place-pill {
    display: none;
  }
}

/* ------------------------------------------------------------------
   Tablet & phone (<= 960px): touch targets, dock, page turns, rendering
   ------------------------------------------------------------------ */
@media (max-width: 960px) {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  .desk-shell {
    padding-left: max(clamp(12px, 3vw, 40px), env(safe-area-inset-left, 0px));
    padding-right: max(clamp(12px, 3vw, 40px), env(safe-area-inset-right, 0px));
    padding-bottom: calc(104px + env(safe-area-inset-bottom, 0px));
  }

  body.is-home-view .desk-shell {
    padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  }

  /* Every control answers a fingertip: no double-tap zoom delay, no grey flash */
  .tool-btn,
  .seg-btn,
  .dock-btn,
  .dock-center,
  .year-pill,
  .filter-pill,
  .sort-chip,
  .jump-chip,
  .toc-btn,
  .toc-more-btn,
  .close-btn,
  .search-clear,
  .reset-filters-btn,
  .place-pill,
  .art-frame,
  .lightbox-close,
  .lightbox-turn-btn,
  .lightbox-read-btn,
  .month-select {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  /* Quiet corner mark signals that tapping any painting opens it full screen */
  .art-frame:not(.is-vignette) .art-zoom-hint {
    opacity: 0.78;
  }

  .art-frame:not(.is-vignette):active {
    opacity: 0.92;
  }

  .lightbox-matte img {
    max-width: 100%;
    max-height: calc(100dvh - 224px);
  }

  .lightbox-caption {
    font-size: 0.88rem;
    line-height: 1.38;
  }

  .lightbox-turn-btn {
    padding: 6px 8px 6px 6px;
    gap: 4px;
  }

  .lightbox-turn-btn--right {
    padding: 6px 6px 6px 8px;
  }

  .lightbox-read-btn {
    padding: 6px 13px;
  }

  .tool-btn,
  .seg-btn {
    min-height: 40px;
  }

  .segmented--textsize .seg-btn {
    min-width: 42px;
  }

  .tool-btn:active,
  .segmented .seg-btn:not(.is-active):active {
    background: rgba(250, 248, 243, 0.2);
  }

  /* Book spread: one column, plate above reading page */
  .book-volume {
    border-radius: 6px;
    /* A page held mid-swipe slides under the book's own edge, never out over the cloth */
    overflow: hidden;
    overflow: clip;
    box-shadow:
      0 18px 40px rgba(10, 14, 11, 0.5),
      0 2px 8px rgba(10, 14, 11, 0.32),
      0 0 0 1px rgba(250, 248, 243, 0.08);
  }

  .book-spread {
    border-radius: 6px;
    transition:
      opacity 240ms ease-out,
      transform 300ms cubic-bezier(0.2, 0.75, 0.25, 1);
  }

  /* Page turn: the old page leaves toward the side it was turned to, the new one arrives from the other */
  .book-spread.is-turning {
    opacity: 0;
    transition-duration: 130ms;
    transition-timing-function: ease-in;
  }

  .book-spread.is-turning[data-turn="next"] {
    transform: translate3d(calc(var(--drag-x, 0px) - 22px), 0, 0);
  }

  .book-spread.is-turning[data-turn="prev"] {
    transform: translate3d(calc(var(--drag-x, 0px) + 22px), 0, 0);
  }

  .book-spread.is-entering {
    opacity: 0;
    transition: none;
  }

  .book-spread.is-entering[data-turn="next"] {
    transform: translate3d(22px, 0, 0);
  }

  .book-spread.is-entering[data-turn="prev"] {
    transform: translate3d(-22px, 0, 0);
  }

  /* The painting swaps while the page is out of sight, so it never fades in over the new text */
  .book-spread.is-turning .art-frame img,
  .book-spread.is-entering .art-frame img {
    transition: none;
  }

  /* Swipe: the page follows the finger a little, then settles or turns */
  .book-spread.is-dragging {
    transform: translate3d(var(--drag-x, 0px), 0, 0);
    opacity: calc(1 - var(--drag-fade, 0) * 0.32);
    transition: none;
    will-change: transform;
  }

  .book-spread.is-settling {
    transform: translate3d(0, 0, 0);
  }

  /* A page is as wide as the book, never as wide as its longest unbroken line */
  .page {
    min-width: 0;
    padding: clamp(18px, 4.6vw, 34px) clamp(20px, 5.2vw, 40px);
  }

  /* Plate page hands over to the reading page like a turned leaf: one soft crease, no hard band */
  .page--left {
    padding-bottom: clamp(16px, 4vw, 28px);
    box-shadow: inset 0 -22px 26px -24px rgba(25, 31, 26, 0.2);
  }

  .book-spine {
    background: linear-gradient(
      90deg,
      rgba(31, 36, 32, 0.05) 0%,
      rgba(31, 36, 32, 0.24) 18%,
      rgba(31, 36, 32, 0.24) 82%,
      rgba(31, 36, 32, 0.05) 100%
    );
  }

  .page--right {
    box-shadow: inset 0 16px 20px -20px rgba(25, 31, 26, 0.14);
  }

  .page-folio {
    padding-bottom: 9px;
    margin-bottom: 14px;
  }

  /* The painting is sized from the screen it is on, so the date and title that follow stay in the
     first view instead of being pushed under the dock. --plate-fit is set by the script only when
     an unusually long caption or title needs a little more room than that. */
  .art-plate {
    gap: 12px;
  }

  .art-frame {
    max-width: none;
    width: min(
      100%,
      390px,
      var(--plate-fit, 390px),
      max(var(--plate-min, 200px), calc((100vh - var(--plate-chrome, 430px)) * 0.75))
    );
    width: min(
      100%,
      390px,
      var(--plate-fit, 390px),
      max(var(--plate-min, 200px), calc((100svh - var(--plate-chrome, 430px)) * 0.75))
    );
  }

  .art-caption {
    font-size: 0.9rem;
    line-height: 1.5;
    text-wrap: balance;
  }

  .devotion-title {
    text-wrap: balance;
    overflow-wrap: break-word;
  }

  .devotion-body {
    overflow-wrap: break-word;
  }

  .devotion-body p {
    text-wrap: pretty;
  }

  .devotion-body.is-original p {
    overflow-wrap: anywhere;
  }

  .scripture-callout {
    padding: 12px 16px;
  }

  .year-switcher {
    gap: 8px;
  }

  .year-pills {
    gap: 5px;
  }

  .year-pill {
    min-height: 36px;
    min-width: 50px;
    padding: 0 9px;
    font-size: 0.8rem;
  }

  .year-pill:active {
    background: var(--moss-soft);
    border-color: var(--moss);
  }

  /* Sticky reader dock: back on the left, onward on the right, the open page between them */
  .mobile-dock {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 8px;
    padding: 8px max(10px, env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px))
      max(10px, env(safe-area-inset-left, 0px));
    background: rgba(27, 34, 30, 0.95);
    border-top: 1px solid rgba(250, 248, 243, 0.12);
    box-shadow: 0 -10px 26px rgba(0, 0, 0, 0.34);
  }

  .dock-btn {
    min-height: 50px;
    gap: 7px;
    padding: 6px 12px 6px 9px;
    border-radius: 10px;
    border-color: rgba(250, 248, 243, 0.13);
    background: rgba(250, 248, 243, 0.05);
    transition:
      background-color 140ms ease,
      border-color 140ms ease,
      color 140ms ease,
      transform 140ms ease,
      opacity 160ms ease;
  }

  .dock-btn--right {
    padding: 6px 9px 6px 12px;
  }

  .dock-btn svg {
    flex-shrink: 0;
    transition: transform 140ms ease;
  }

  .dock-btn:active:not(:disabled) {
    background: rgba(250, 248, 243, 0.17);
    border-color: rgba(250, 248, 243, 0.3);
    transform: scale(0.97);
  }

  .dock-btn:active:not(:disabled) svg {
    transform: translateX(-2px);
  }

  .dock-btn--right:active:not(:disabled) svg {
    transform: translateX(2px);
  }

  /* A swipe held far enough to turn lights the button it is about to press */
  .dock-btn.is-armed {
    background: rgba(250, 248, 243, 0.92);
    border-color: rgba(250, 248, 243, 0.92);
    color: var(--ink);
  }

  .dock-btn.is-armed .dock-dir {
    color: var(--ink);
  }

  .dock-btn.is-armed .dock-date {
    color: var(--muted-ink);
  }

  .dock-btn:disabled {
    opacity: 0.28;
  }

  .dock-dir {
    font-size: 0.84rem;
    transition: color 140ms ease;
  }

  .dock-date {
    font-size: 0.72rem;
    transition: color 140ms ease;
  }

  /* The open page, set like a slip of the book's own paper. Tap it to browse. */
  .dock-center {
    min-height: 50px;
    gap: 0;
    padding: 5px 16px 6px;
    border-radius: 10px;
    border: 1px solid rgba(250, 248, 243, 0.9);
    border-top: 2px solid var(--ochre-ribbon);
    background: var(--paper);
    color: var(--ink);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.32);
    transition:
      background-color 140ms ease,
      transform 140ms ease;
  }

  .dock-center:active {
    background: #ece7da;
    transform: scale(0.97);
  }

  .dock-current-date {
    font-family: var(--font-serif);
    font-size: 1.04rem;
    font-weight: 500;
    line-height: 1.2;
    color: var(--ink);
  }

  .dock-current-meta {
    display: block;
    font-size: 0.7rem;
    line-height: 1.25;
    color: var(--muted-ink);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }

  .dock-current-pos {
    font-size: inherit;
    color: inherit;
  }

  /* Two posts on one day: the dock says which. "Aug 19 eve" on a turn button, and
     "evening · 387 of 637" on the slip, which gives up its order note to make the room. */
  .dock-date-part {
    color: rgba(250, 248, 243, 0.9);
    font-weight: 500;
  }

  .dock-current-part {
    color: var(--ink);
    font-weight: 600;
  }

  .dock-current-part:empty,
  .dock-part-short {
    display: none;
  }

  .mobile-dock.is-daypart .dock-order {
    display: none;
  }

  /* Find my place: floats over the list only while the open devotion is out of sight */
  .index-drawer .place-pill {
    position: absolute;
    left: 50%;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    z-index: 3;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 42px;
    padding: 0 18px 0 14px;
    border: 1px solid rgba(250, 248, 243, 0.2);
    border-radius: 999px;
    background: var(--moss);
    color: #faf8f3;
    font-family: var(--font-sans);
    font-size: 0.84rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    box-shadow:
      0 8px 22px rgba(20, 28, 23, 0.34),
      0 1px 3px rgba(20, 28, 23, 0.3);
    transform: translateX(-50%);
    animation: bdp-pill-in 180ms ease both;
  }

  .index-drawer .place-pill[hidden] {
    display: none;
  }

  .place-pill svg {
    flex-shrink: 0;
  }

  .place-pill[data-where="down"] svg {
    transform: rotate(180deg);
  }

  /* Filtered out of the list altogether: no direction to point in */
  .place-pill[data-where="away"] {
    padding-left: 18px;
  }

  .place-pill[data-where="away"] svg {
    display: none;
  }

  .place-pill:active {
    background: #2f4a38;
  }

  .place-pill:focus-visible {
    outline: 2px solid var(--ochre-ribbon);
    outline-offset: 2px;
  }

  /* Browse drawer: fingertip-sized controls and no iOS zoom on focus (inputs stay at 16px) */
  .index-drawer {
    padding-right: env(safe-area-inset-right, 0px);
  }

  .index-drawer:focus {
    outline: none;
  }

  .close-btn {
    width: 44px;
    height: 44px;
    border-radius: 8px;
  }

  .close-btn:active {
    background: var(--moss-soft);
    border-color: var(--moss);
  }

  .search-input {
    min-height: 44px;
    font-size: 16px;
    padding: 9px 44px 9px 38px;
    border-radius: 8px;
  }

  .search-input::placeholder {
    font-size: 0.9rem;
  }

  .search-icon {
    left: 13px;
  }

  .search-clear {
    right: 2px;
    width: 40px;
    height: 40px;
    border-radius: 6px;
  }

  .month-select {
    min-height: 38px;
    font-size: 16px;
    padding: 4px 30px 4px 12px;
    border-radius: 999px;
  }

  .sort-chip,
  .jump-chip {
    min-height: 38px;
    padding: 0 12px;
    font-size: 0.8rem;
    white-space: nowrap;
  }

  .jump-chip {
    border-radius: 8px;
  }

  .drawer-sort {
    border-radius: 8px;
  }

  .jump-chip:active {
    border-color: var(--moss);
    background: var(--moss-soft);
  }

  .filter-pill {
    min-height: 36px;
    padding: 0 13px;
    font-size: 0.8rem;
    white-space: nowrap;
  }

  .reset-filters-btn {
    min-height: 32px;
    padding: 4px 6px;
    font-size: 0.8rem;
  }

  /* Room at the foot so the last rows can be read clear of the Find my place pill */
  .drawer-scroll {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }

  /* Buttons do not inherit type on their own; keep the list in the book's sans, not the system's */
  .toc-btn {
    font-family: var(--font-sans);
  }

  .toc-btn:active {
    border-color: var(--moss);
    background: var(--moss-soft);
  }

  .toc-more-btn {
    min-height: 44px;
  }
}

/* ------------------------------------------------------------------
   Phone (<= 600px): two-row top bar, reading header, browse sheet
   ------------------------------------------------------------------ */
@media (max-width: 600px) {
  /* Chrome that shares the first view with the painting: top bar, plate head, a three-line
     caption, the date line, a two-line title, and the dock with breathing room above it */
  .book-spread {
    --plate-chrome: 436px;
  }

  /* Top bar. Row one: the book's name with text size opposite. Row two: where to go, then which text. */
  .site-bar {
    padding: 8px 0 10px;
    gap: 8px 0;
    align-items: center;
    justify-content: flex-start;
  }

  .brand {
    flex: 1 0 calc(100% - 98px);
    min-width: 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
  }

  .brand-title {
    font-size: 1.32rem;
    line-height: 1.15;
    white-space: nowrap;
  }

  .brand-author {
    font-size: 0.78rem;
    line-height: 1.25;
  }

  .bar-controls {
    display: contents;
  }

  .tool-btn,
  .seg-btn,
  .segmented .seg-btn {
    min-height: 40px;
    padding: 0 12px;
    font-size: 0.82rem;
  }

  .seg-extra {
    display: none;
  }

  .segmented--textsize {
    order: 1;
    flex: 0 0 auto;
    margin-left: auto;
  }

  .segmented--textsize .seg-btn {
    width: 43px;
    padding: 0;
    font-size: 0.9rem;
  }

  .segmented--textsize .seg-btn--lg {
    font-size: 1.02rem;
  }

  /* Latest, Today and Browse read as one joined strip the width of the page */
  #latestBtn,
  #todayBtn,
  #openIndexBtn {
    order: 2;
    /* A real basis keeps the strip off row one, where only a sliver is spare */
    flex: 1 1 54px;
    min-width: 0;
    padding: 0 4px;
    border-radius: 0;
    position: relative;
  }

  #latestBtn {
    border-radius: 8px 0 0 8px;
  }

  #todayBtn,
  #openIndexBtn {
    margin-left: -1px;
  }

  #openIndexBtn {
    border-radius: 0 8px 8px 0;
  }

  /* Keep the two-row phone top bar intact while reading; surface Email updates on Home */
  body:not(.is-home-view) #topSubscribeBtn {
    display: none;
  }

  body.is-home-view #openIndexBtn {
    border-radius: 0 8px 8px 0;
  }

  body.is-home-view #topSubscribeBtn {
    order: 3;
    flex: 0 0 auto;
    margin-left: 8px;
    border-radius: 8px;
    padding: 0 11px;
  }

  #latestBtn.is-active,
  #todayBtn.is-active {
    z-index: 1;
  }

  .segmented--textmode {
    order: 3;
    flex: 0 0 auto;
    margin-left: 8px;
    border-radius: 8px;
  }

  .segmented--textsize {
    border-radius: 8px;
  }

  /* Book */
  .desk-shell {
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
  }

  .page {
    padding: 14px 20px 18px;
  }

  .page--left {
    padding-bottom: 15px;
  }

  .page--right {
    padding-bottom: 22px;
  }

  .page-folio--left {
    font-size: 0.88rem;
    padding-bottom: 8px;
    margin-bottom: 12px;
  }

  .art-plate {
    gap: 10px;
  }

  .art-caption {
    font-size: 0.88rem;
    line-height: 1.45;
    max-width: 42ch;
  }

  /* Reading header on a narrow page: the date leads, the title follows at once, and the
     time-of-day line sits beneath it, so nothing wraps into a cramped two-column head */
  .page-folio--right:not(.about-folio-right) {
    display: contents;
  }

  /* Back link and place share one line, both held clear of the ribbon bookmark */
  .about-folio-right {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    order: 0;
    min-width: 0;
    padding-right: 34px;
    padding-bottom: 8px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--paper-rule);
  }

  .about-back-btn,
  .signoff-about-btn,
  .brand-author-btn {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .about-back-btn {
    min-height: 36px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .about-place {
    flex: 0 1 auto;
    min-width: 0;
    font-size: 0.8rem;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Narrow phones: the ribbon hangs a little nearer the page edge, which leaves the header
     line room for both the back link and the place with clear paper before the ribbon */
  @media (max-width: 400px) {
    .ribbon-bookmark {
      right: 22px;
    }

    .about-folio-right {
      gap: 6px;
      padding-right: 29px;
    }

    .about-back-btn {
      gap: 3px;
      font-size: 0.78rem;
    }

    .about-place {
      font-size: 0.76rem;
    }
  }

  /* Only the narrowest phones have no room for the place beside the back link */
  @media (max-width: 344px) {
    .about-place {
      display: none;
    }
  }

  .page-folio--right time {
    order: 0;
    padding-right: 30px;
    margin-bottom: 5px;
    font-family: var(--font-serif);
    font-size: 0.96rem;
    line-height: 1.3;
  }

  .devotion-header {
    order: 1;
    margin-bottom: 6px;
  }

  /* Fred's page: clear paper follows the subtitle, so the pull quote starts beneath the dock
     in the first view instead of showing its top edge above it */
  .devotion-header.about-header {
    margin-bottom: 16px;
  }

  .devotion-title {
    font-size: 1.72rem;
    line-height: 1.16;
  }

  #entryTimeOfDay {
    order: 2;
    margin-bottom: 18px;
    padding-bottom: 9px;
    border-bottom: 1px solid var(--paper-rule);
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 0.96rem;
    line-height: 1.4;
    color: var(--muted-ink);
  }

  .year-switcher {
    order: 3;
    margin: -4px 0 18px;
    flex-wrap: nowrap;
    gap: 0;
    min-width: 0;
  }

  .year-switcher-label {
    flex: 0 0 auto;
  }

  /* The years ride one line that swipes sideways, fading where it runs on to the page edge */
  .year-pills {
    display: flex;
    flex: 1 1 auto;
    flex-wrap: nowrap;
    min-width: 0;
    margin-right: -20px;
    padding: 0 40px 0 10px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  /* Swipe cue shared by every sideways rail (the years on the page; order, filters and seasons
     in Browse): a soft fade wherever more lies beyond an edge. The script sets the two widths
     from how far the rail has been swiped, so each fade eases away as its edge is reached and
     the first and last chips always show whole. Each rail also keeps trailing room as wide as
     the fade, so its last chip clears it even before the script has measured anything. */
  .year-pills,
  .drawer-quick-row,
  .filter-row,
  .filter-row--split .filter-pills {
    --rail-mask: linear-gradient(
      90deg,
      transparent,
      #000 var(--rail-fade-before, 0px),
      #000 calc(100% - var(--rail-fade-after, 40px)),
      transparent
    );
    -webkit-mask-image: var(--rail-mask);
    mask-image: var(--rail-mask);
  }

  .year-pills::-webkit-scrollbar {
    display: none;
  }

  .year-pill {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  /* Narrow phones: a touch less padding, so the widest plain date ("Dec 30") never truncates */
  @media (max-width: 400px) {
    .dock-btn {
      gap: 6px;
      padding: 6px 10px 6px 8px;
    }

    .dock-btn--right {
      padding: 6px 8px 6px 10px;
    }
  }

  /* Same-day words in the dock: the turn buttons trim their own padding to fit "Aug 19 eve" */
  .mobile-dock.is-daypart .dock-btn {
    gap: 5px;
    padding: 6px 8px 6px 6px;
  }

  .mobile-dock.is-daypart .dock-btn--right {
    padding: 6px 6px 6px 8px;
  }

  @media (max-width: 400px) {
    .mobile-dock.is-daypart {
      gap: 6px;
      padding-left: max(8px, env(safe-area-inset-left, 0px));
      padding-right: max(8px, env(safe-area-inset-right, 0px));
    }

    .mobile-dock.is-daypart .dock-center {
      padding-left: 9px;
      padding-right: 9px;
    }

    .mobile-dock.is-daypart .dock-date {
      font-size: 0.68rem;
    }

    .dock-part-full {
      display: none;
    }

    .dock-part-short {
      display: inline;
    }
  }

  .scripture-callout {
    order: 4;
    margin-bottom: 22px;
  }

  .devotion-body {
    order: 5;
  }

  .songs-note {
    order: 6;
  }

  .devotion-share {
    order: 7;
    margin-top: 20px;
    padding: 14px 0 16px;
  }

  .devotion-share .share-icon-btn {
    width: 40px;
    height: 40px;
  }

  .devotion-signoff {
    order: 8;
  }

  /* Browse opens as a sheet rising from the dock, so the list sits under the thumb */
  .drawer-backdrop {
    animation: bdp-backdrop-in 200ms ease both;
  }

  .index-drawer {
    top: max(10px, env(safe-area-inset-top, 0px));
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    padding-right: 0;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -14px 40px rgba(0, 0, 0, 0.42);
    animation: bdp-sheet-rise 280ms cubic-bezier(0.2, 0.8, 0.25, 1) both;
  }

  .drawer-head {
    align-items: center;
    padding: 10px 10px 10px 18px;
  }

  .drawer-head h2 {
    margin-bottom: 1px;
    font-size: 1.34rem;
    line-height: 1.2;
  }

  .drawer-sub {
    font-size: 0.8rem;
  }

  .close-btn {
    border-color: transparent;
  }

  .drawer-filters {
    padding: 10px 16px;
    gap: 8px;
  }

  /* Order, filters and jumps ride one swipeable rail; a soft fade marks where it continues */
  .drawer-quick-row,
  .filter-row {
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 6px;
    margin: 0 -16px;
    padding: 0 16px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .drawer-quick-row::-webkit-scrollbar,
  .filter-row::-webkit-scrollbar {
    display: none;
  }

  .drawer-sort,
  .drawer-jumps,
  .filters-toggle,
  .filter-pills,
  .month-select-wrap {
    flex: 0 0 auto;
  }

  .filter-pills {
    flex-wrap: nowrap;
    gap: 6px;
  }

  /* Trailing room so the last chip clears the fade once the rail is scrolled to its end */
  .drawer-jumps,
  .filter-row .filter-pills {
    padding-right: 24px;
  }

  /* Year, season and month stay folded away until asked for, leaving the list most of the screen */
  .drawer-filters:not(.is-filters-open) .filter-row {
    display: none;
  }

  .filters-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }

  .filters-toggle::after {
    content: "";
    width: 6px;
    height: 6px;
    margin: -3px 1px 0 2px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg);
    transition: transform 160ms ease;
    opacity: 0.7;
  }

  .filters-toggle[aria-expanded="true"] {
    border-color: var(--moss);
    background: var(--moss-soft);
    color: var(--moss);
  }

  .filters-toggle[aria-expanded="true"]::after {
    margin-top: 3px;
    transform: rotate(-135deg);
  }

  .filters-toggle.has-active {
    border-color: var(--moss);
    color: var(--moss);
    font-weight: 600;
  }

  .filters-count:empty {
    display: none;
  }

  .filters-count {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--moss);
    color: #faf8f3;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
    font-variant-numeric: tabular-nums;
  }

  /* Month holds a fixed place at the head of its row. The seasons swipe in a rail of their
     own beside it, so choosing a season can never carry the Month menu out of sight. */
  .filter-row--split {
    gap: 8px;
    margin: 0;
    padding: 0;
    overflow: visible;
    -webkit-mask-image: none;
    mask-image: none;
  }

  .month-select-wrap {
    order: -1;
  }

  .filter-row--split .filter-pills {
    flex: 1 1 auto;
    min-width: 0;
    margin-right: -16px;
    padding: 0 40px 0 8px;
    border-left: 1px solid var(--paper-rule);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .filter-row--split .filter-pills::-webkit-scrollbar {
    display: none;
  }

  /* The count line only earns its row while a search or filter is narrowing the list */
  .filter-status {
    min-height: 32px;
  }

  .filter-status:has(.reset-filters-btn[hidden]) {
    display: none;
  }

  /* The list reads as a table of contents: ruled lines instead of boxed cards */
  .drawer-scroll {
    padding: 0 16px calc(76px + env(safe-area-inset-bottom, 0px));
  }

  .toc-list {
    gap: 0;
  }

  .toc-btn {
    grid-template-columns: 46px 1fr;
    gap: 13px;
    padding: 11px 6px 11px 4px;
    border: 0;
    border-bottom: 1px solid var(--paper-rule);
    border-radius: 0;
    background: transparent;
  }

  .toc-btn.is-current {
    margin: 0 -16px;
    width: calc(100% + 32px);
    padding-left: 17px;
    padding-right: 22px;
    box-shadow: inset 3px 0 0 var(--moss);
  }

  .toc-btn:active {
    background: var(--moss-soft);
  }

  .toc-thumb,
  .toc-thumb-placeholder {
    width: 46px;
    height: 61px;
  }

  .toc-title {
    font-size: 1.06rem;
    line-height: 1.25;
    text-wrap: balance;
  }

  .toc-more-wrap {
    margin-top: 16px;
  }
}

/* Short phone screens (and taller phones while the browser's own bars are showing): the top
   bar, plate and reading header close up so the painting, its caption, the date, both lines of
   a two-line title and the time-of-day line with its rule all sit clear of the dock in the
   first view. Nothing is left for the dock to cut through. */
@media (max-width: 600px) and (max-height: 760px) {
  .book-spread {
    --plate-chrome: 432px;
    --plate-min: 156px;
  }

  .site-bar {
    padding: 6px 0 8px;
    gap: 6px 0;
  }

  .page {
    padding-top: 10px;
  }

  .page--left {
    padding-bottom: 12px;
  }

  .page--right {
    padding-top: 12px;
  }

  .page-folio--left {
    font-size: 0.84rem;
    padding-bottom: 6px;
    margin-bottom: 8px;
  }

  .art-plate {
    gap: 8px;
  }

  .art-caption {
    font-size: 0.84rem;
    line-height: 1.4;
  }

  .page-folio--right time {
    margin-bottom: 4px;
  }

  .devotion-header {
    margin-bottom: 5px;
  }

  .devotion-title {
    font-size: 1.6rem;
    line-height: 1.14;
  }

  #entryTimeOfDay {
    font-size: 0.92rem;
    line-height: 1.36;
  }

  /* Fred's page carries a taller header line (the back link) and a subtitle that runs to two or
     three lines, so each gives up a little to keep the whole subtitle above the dock */
  .about-folio-right {
    padding-bottom: 3px;
    margin-bottom: 7px;
  }

  .about-subtitle {
    margin-top: 5px;
    font-size: 0.94rem;
    line-height: 1.38;
  }
}

/* Small phones (<= 359px wide): both bars keep every target on one row by trimming padding,
   and the dock drops its order note */
@media (max-width: 359px) {
  .tool-btn,
  .seg-btn,
  .segmented .seg-btn {
    padding: 0 9px;
    font-size: 0.76rem;
  }

  #latestBtn,
  #todayBtn,
  #openIndexBtn {
    flex-basis: 44px;
    padding: 0 2px;
  }

  .segmented--textmode {
    margin-left: 6px;
  }

  .brand-title {
    font-size: 1.2rem;
  }

  .mobile-dock {
    gap: 6px;
    padding-left: max(8px, env(safe-area-inset-left, 0px));
    padding-right: max(8px, env(safe-area-inset-right, 0px));
  }

  .dock-btn {
    gap: 4px;
    padding: 6px 7px 6px 4px;
  }

  .dock-btn--right {
    padding: 6px 4px 6px 7px;
  }

  .dock-order {
    display: none;
  }

  .dock-center {
    padding-left: 9px;
    padding-right: 9px;
  }

  /* Same-day words at this width: a post from the open day shows only its word ("eve"), and
     one from another day keeps only its date, so neither turn button runs out of room */
  .mobile-dock.is-daypart .dock-btn {
    gap: 4px;
    padding: 6px 7px 6px 4px;
  }

  .mobile-dock.is-daypart .dock-btn--right {
    padding: 6px 4px 6px 7px;
  }

  .mobile-dock.is-daypart .dock-date {
    font-size: 0.7rem;
  }

  .dock-btn.is-same-day .dock-date-day,
  .dock-btn:not(.is-same-day) .dock-date-part {
    display: none;
  }
}

/* Hero Homepage mobile & tablet layout */
@media (max-width: 960px) {
  .home-art-plate {
    position: static;
    gap: 10px;
  }

  .home-art-frame {
    width: min(56vw, 240px);
    max-width: 240px;
  }

  .home-page-left {
    padding-top: 16px;
    padding-bottom: 16px;
  }

  .home-page-right {
    padding-top: 18px;
  }

  .home-colophon {
    font-size: 0.7rem;
  }
}

@media (max-width: 600px) {
  .home-art-frame {
    width: min(52vw, 196px);
    max-width: 196px;
  }

  .home-title {
    font-size: 1.82rem;
    margin-bottom: 8px;
  }

  .home-dek {
    font-size: 0.98rem;
    margin-bottom: 16px;
  }

  .home-actions {
    grid-template-columns: 1fr;
    gap: 9px;
  }

  .home-actions-secondary {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .home-btn {
    min-height: 48px;
  }

  .home-btn--secondary {
    min-height: 44px;
  }

  .home-hero {
    padding-bottom: 20px;
    margin-bottom: 20px;
  }

  .home-latest-meta {
    flex-wrap: wrap;
    gap: 4px 10px;
  }

  .home-signoff-actions {
    width: 100%;
  }

  .home-signoff-actions .home-btn {
    flex: 1 1 140px;
  }

  /* Song mini-player sits cleanly above the mobile dock on phones */
  .song-mini-player {
    left: 10px;
    right: 10px;
    bottom: calc(74px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-width: 420px;
    margin: 0 auto;
  }

  body.is-home-view .song-mini-player {
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }

  .mini-player-stage,
  .mini-player-iframe {
    height: 154px;
  }

  .song-play-btn {
    min-height: 36px;
    padding: 5px 12px;
    font-size: 0.78rem;
  }
}

@keyframes bdp-sheet-rise {
  from {
    transform: translate3d(0, 28px, 0);
    opacity: 0;
  }

  to {
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
}

@keyframes bdp-pill-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }

  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@keyframes bdp-backdrop-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@media (max-width: 960px) and (prefers-reduced-motion: reduce) {
  .book-spread,
  .book-spread.is-turning,
  .book-spread.is-entering,
  .book-spread.is-dragging,
  .book-spread.is-settling {
    transform: none !important;
    transition: opacity 120ms linear;
  }

  .dock-btn,
  .dock-btn svg,
  .dock-center,
  .filters-toggle::after {
    transition: none;
  }

  .dock-btn:active:not(:disabled),
  .dock-center:active {
    transform: none;
  }

  .index-drawer,
  .drawer-backdrop,
  .index-drawer .place-pill {
    animation: none;
  }
}
