/* ---------- Responsive / mobile ---------- */
html,body{ overflow-x:hidden; }

@media (max-width: 860px){
  .layout{ grid-template-columns: 1fr; }
  /* overflow-y:auto is required alongside max-height here — without it,
     content taller than the cap doesn't get clipped/scrolled, it just
     spills out past the box (default overflow:visible) and visually
     overlaps whatever grid row comes after it. Pre-existing gap that a
     generous 48-52vh cap rarely triggered in practice; became clearly
     visible once the ID-scoped 32-36vh overrides below made the cap
     tighter. */
  .col-left{ border-right:none; border-bottom:1px solid var(--line); max-height:48vh; overflow-y:auto; }
  /* #panel-tabs-col and #panel-now-playlist-col both use .col-left, so the
     rule above alone lets a phone user with both panels open face up to
     ~2x48vh of stacked scrollable panels before reaching the slide-card
     area. These ID-scoped overrides (higher specificity than .col-left
     alone) give each its own smaller share instead. */
  #panel-tabs-col.col-left, #panel-now-playlist-col.col-left{ max-height:32vh; }
  .slide-grid{ grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}

/* ==========================================================
   Mobile shell: below 640px the desktop header and 3-column workspace
   are replaced by a compact header, a Tools-only slide-in drawer, a
   persistent top band showing the current playlist or a library search
   (matches the large-screen layout, just reorganized into two vertical
   bands instead of side-by-side columns), a scrollable slide grid, and
   a bottom nav. Deliberately NOT a single full-screen "hero" slide —
   every slide is shown at once, the active one bordered exactly like
   desktop (gold when selected, red via the existing .live-mode rule
   when actually projecting), per explicit request to keep that look.
   This does NOT duplicate state or rendering: the top band pins the
   SAME #panel-now-playlist-col panel desktop already shows, Library
   (reached via the drawer) opens the SAME #panel-tabs-col as a
   full-screen overlay, the drawer's Tools entries proxy clicks to the
   existing header buttons, and the slide grid is the exact same
   #slide-area/.slide-card markup every category already renders, just
   narrower. The mobile-fixed-bar constants below are plain numbers
   rather than JS-measured custom properties since the bars are
   fixed-height by design. */
:root{ --mob-header-h:52px; --mob-navbar-h:60px; --mob-slide-cols:1; }
#mobile-header, #mobile-drawer-backdrop, #mobile-drawer, #mobile-bottom-nav, #mobile-slide-cols{ display:none; }
body.mobile-drawer-locked{ overflow:hidden; }

/* max-height:500px is the landscape-phone fallback: a phone rotated
   sideways (e.g. 812x375, 932x430) is wider than 640px but far too
   short to fit the desktop header/3-column workspace either — without
   this OR condition it fell through to the 641-860px tablet tier
   instead of the mobile shell, showing the full stacked desktop header
   with almost no room left for the slide grid. Real tablets in
   landscape (e.g. 1024x768) stay well above 500px tall, so they're
   correctly unaffected. */
@media (max-width: 640px), (max-height: 500px){
  header{ display:none; }
  #mobile-header{
    display:flex; align-items:center; gap:10px; height:var(--mob-header-h);
    padding:0 8px; position:fixed; top:0; left:0; right:0; z-index:25;
    background:linear-gradient(180deg, var(--ink-soft), var(--ink));
    border-bottom:1px solid var(--line);
  }
  #mobile-header .icon-btn{ font-size:20px; padding:8px 10px; flex-shrink:0; }
  #mobile-header-title{ flex:1; min-width:0; text-align:center; }
  #mobile-header-title-main{
    display:block; font-family:var(--font-display); font-weight:600; font-size:15px;
    white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
  }
  #mobile-header-title-sub{
    display:block; font-size:11px; color:var(--text-dim);
    white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
  }

  #mobile-drawer-backdrop{
    display:block; position:fixed; inset:0; background:rgba(0,0,0,0.55); z-index:44;
    opacity:0; pointer-events:none; transition:opacity .2s ease;
  }
  #mobile-drawer-backdrop.open{ opacity:1; pointer-events:auto; }
  #mobile-drawer{
    display:flex; flex-direction:column; position:fixed; top:0; bottom:0; left:0; z-index:45;
    width:min(300px, 84vw); background:var(--ink-soft); border-right:1px solid var(--line);
    transform:translateX(-100%); transition:transform .2s ease; overflow-y:auto; padding-bottom:16px;
  }
  #mobile-drawer.open{ transform:translateX(0); }
  @media (prefers-reduced-motion: reduce){
    #mobile-drawer-backdrop, #mobile-drawer{ transition:none; }
  }
  .mobile-drawer-header{
    display:flex; align-items:center; gap:8px; padding:16px;
    font-family:var(--font-display); font-weight:600; font-size:16px;
    border-bottom:1px solid var(--line);
  }
  .mobile-drawer-header .mark{ font-family:var(--font-ethiopic); color:var(--gold); font-size:20px; }
  .mobile-drawer-header .icon-btn{ margin-left:auto; font-size:18px; }
  .mobile-drawer-section-label{
    font-size:11px; letter-spacing:0.09em; text-transform:uppercase; color:var(--text-dim);
    padding:14px 16px 6px;
  }
  .mobile-drawer-row{
    display:flex; align-items:center; gap:12px; width:100%; text-align:left;
    background:transparent; border:none; border-radius:0; padding:13px 16px;
    font-size:14.5px; color:var(--parchment); min-height:48px;
  }
  .mobile-drawer-row:hover, .mobile-drawer-row:active{ background:var(--ink-softer); }
  .mobile-drawer-row.active{ color:var(--gold); }

  #mobile-bottom-nav{
    display:flex; position:fixed; bottom:0; left:0; right:0; z-index:25;
    height:var(--mob-navbar-h); padding-bottom:env(safe-area-inset-bottom, 0);
    background:linear-gradient(0deg, var(--ink-soft), var(--ink));
    border-top:1px solid var(--line);
  }
  #mobile-bottom-nav button{
    flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center;
    gap:2px; background:transparent; border:none; border-radius:0; font-size:10.5px;
    color:var(--text-dim); min-height:100%;
  }
  #mobile-bottom-nav button .nav-icon{ font-size:19px; }
  #mobile-bottom-nav button.active, #mobile-bottom-nav button:active{ color:var(--gold); }
  #mobile-nav-present.live{ color:var(--vermillion); }

  /* Stays a flex container (not display:block) so .col-main — the only
     visible child once .col-left is display:none below — keeps the
     stretch-to-fill sizing it already gets on every other breakpoint;
     losing that was what left a large dead gap between the hero card
     and the fixed control bars (the card was sizing to its own content
     instead of filling available height). */
  .layout{ display:flex; flex-direction:column; padding-top:var(--mob-header-h); padding-bottom:var(--mob-navbar-h); min-height:100vh; }
  .col-main{ flex:1; min-height:0; }
  .col-left{ display:none; }
  #update-status-wrap, #generate-latin-status-wrap, #dup-scan-status-wrap, #cleanup-scan-status-wrap, #download-bible-status-wrap{ min-width:0; width:100%; max-width:none; }

  .section-label-row{ padding:12px 12px 8px; flex-wrap:wrap; gap:8px; }
  /* The compact header already shows the loaded song/reading's title and
     singer (see syncMobileHeaderTitle) — repeating it here just eats
     into the playlist's small share of the screen for no reason. */
  #now-selected-strip{ display:none; }
  .search-wrap{ padding:0 12px 12px; }
  .browse-toolbar{ padding:0 12px 8px; }
  .browse-list, .results-dropdown{ margin-left:12px; margin-right:12px; }

  .main-toolbar{ padding:8px 14px; gap:8px; }
  /* The compact mobile header already shows the current item's title/sub
     (see syncMobileHeaderTitle) — showing it again here just eats into
     the hero slide's share of the viewport for no reason. The Edit/Add
     to playlist/Delete buttons stay; they're not available elsewhere. */
  .now-playing{ display:none; }

  /* Slide grid: matches desktop's behavior (every slide shown at once,
     active one bordered — gold when just selected, red via the existing
     .live-mode rule below when actually projecting, per the user's
     explicit request to match the large-screen look) instead of a
     single full-screen "hero" card. Column count is user-chosen via the
     -/+ buttons below (see #mobile-slide-cols in JS), default 1. */
  #slide-area.slide-grid{
    grid-template-columns: repeat(var(--mob-slide-cols), 1fr);
    gap:10px; padding:12px; flex:1; min-height:0; overflow-y:auto;
  }
  #slide-area.placeholder{ flex:1; min-height:0; display:flex; align-items:center; justify-content:center; }
  #mobile-slide-cols{ display:flex; align-items:center; gap:2px; }
  #mobile-slide-cols button{ padding:6px 10px; min-height:36px; }
  #mobile-slide-cols button:disabled{ opacity:0.35; }
  #mobile-slide-cols-label{ font-size:12px; color:var(--text-dim); min-width:16px; text-align:center; }

  /* Main window is slides-only, full height — Library opens as a
     full-screen overlay when tapped, matching how .settings-panel/
     #database-panel already work below, rather than a persistent
     band eating into the slide grid. */
  #panel-tabs-col.mobile-open{
    display:flex; position:fixed; inset:0; z-index:40; max-height:none;
    background:var(--ink); border:none; overflow-y:auto;
  }
  /* Playlist opens as a bottom sheet over the lower 2/3 of the screen
     (not full-screen like Library) so the slide area stays partly
     visible above it; overflow-y:auto lets a long playlist scroll.
     Stops above the bottom nav (not at the viewport edge) so its
     buttons — Slides in particular — stay visible and tappable to
     dismiss the sheet, instead of being covered by it. */
  #panel-now-playlist-col.mobile-open{
    display:flex; position:fixed; top:33.34vh; left:0; right:0; bottom:var(--mob-navbar-h); z-index:40; max-height:none;
    background:var(--ink); border:none; border-top:1px solid var(--line); overflow-y:auto;
  }
  /* Single-column playlist list — a 2-column grid was tried and turned
     out too cramped for the title/singer text plus the reorder/edit/
     delete icon cluster each row already carries, so this just falls
     back to the plain single-column list every other breakpoint uses
     (no override needed beyond that removal). */

  .settings-section-label{ display:block; }

  .main-content-row{ position:relative; display:flex; flex-direction:column; }
  .settings-panel, #database-panel{
    position:fixed; inset:0; z-index:40; width:100%; border-left:none; max-height:none;
  }

  .modal{ width:100%; max-width:100vw; max-height:100dvh; border-radius:0; padding:16px; }
  .modal.modal-wide{ width:100%; }
  #cleanup-preview-modal-backdrop .modal{ width:100%; }
  #cleanup-preview-modal-backdrop .lyrics-textarea{ height:32vh; min-height:200px; }
  .modal-actions{ justify-content:stretch; }
  .modal-actions button{ flex:1; }
  .line-translation-row{ grid-template-columns: 1fr; gap:4px; padding:10px 2px; }
  .line-original{ white-space:normal; }

  .toast{ left:12px; right:12px; bottom:12px; text-align:center; }

  button, .icon-btn, input[type=checkbox], input[type=color],
  .category-tabs button, .media-item-remove-btn, .media-item-move-btn, .clear-input-btn,
  .geez-keyboard-toggle-btn, #dup-select-menu-btn, #cleanup-select-menu-btn{ min-height:44px; }
  /* .switch keeps its compact pill shape (inflating it to 44px would make
     it look like a square button, not a toggle) — instead an invisible
     pseudo-element pads out its actual hit area. */
  .switch::before{ content:''; position:absolute; inset:-12px; }
}
:focus-visible{ outline:2px solid var(--gold); outline-offset:2px; }
