/* ========================================
   Mobile re-skin (<= 640px) — "Tube Glow"

   Loaded LAST in the stylesheet list so it wins the cascade over every
   component sheet (nav, player, catalog, performance, dashboard, responsive).
   This keeps the whole mobile layout — and the fixed bottom-stack geometry —
   in one coherent place.

   Adds: compact faceplate, tape-transport tab bar, slim docked player,
   chip-rail filters, single-column catalog rows, single-column performance,
   and the segmented "My Collection" switch.

   Every Stimulus / Turbo / test contract is preserved: this is CSS over the
   existing ERB, except the new _tab_bar partial and the dashboard switch.
   Targets that the audio-player controller needs (wave, volumeBar, seekBar…)
   stay in the DOM — hidden, never removed. System tests run at 1400px, so none
   of these <=640px rules affect them.
   ======================================== */

/* Hidden at all widths by default; revealed only at the mobile breakpoint. */
.tab-bar { display: none; }
.site-nav__search { display: none; }
.dashboard__switch { display: none; }

@media (max-width: 640px) {
  :root {
    /* Tab bar height includes the bottom safe-area inset (notched phones). */
    --tab-bar-h: calc(56px + env(safe-area-inset-bottom, 0px));
    --mobile-player-h: 54px;
  }

  /* Reserve room for the slim player; add the tab bar's height only when the
     tab bar is actually present (signed in), so signed-out pages don't get a
     dead strip of empty floor. */
  body {
    padding-bottom: calc(var(--mobile-player-h) + 6px);
  }
  body:has(.tab-bar) {
    padding-bottom: calc(var(--tab-bar-h) + var(--mobile-player-h) + 6px);
  }

  /* ============================================================
     Compact faceplate (top bar ~52px)
     ============================================================ */
  .site-nav {
    height: 52px;
    gap: 10px;
    padding: 0 14px;
  }
  .site-nav__knobs,
  .site-nav__invites {
    display: none;
  }
  /* Hide the desktop selector row only when signed in — the tab bar replaces it.
     Signed-out, .site-nav__links holds the only "sign in" link, so keep it. */
  .site-nav:has(.site-nav__account) .site-nav__links {
    display: none;
  }

  .site-nav__brand {
    flex: 1;
    min-width: 0;
    gap: 9px;
    padding: 7px 12px;
  }
  .site-nav__wordmark-line1 { font-size: 8.5px; letter-spacing: 2px; }
  .site-nav__wordmark-line2 { font-size: 11px; letter-spacing: 4px; margin-top: 3px; }

  /* Search affordance → the catalog (which holds the real search field) */
  .site-nav__search {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-control);
    background: var(--field);
    border: 1px solid rgba(224, 162, 60, 0.22);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.7);
    color: var(--amber);
    font-size: 15px;
    line-height: 1;
    text-decoration: none;
  }
  .site-nav__search:hover { text-decoration: none; }

  .site-nav__account { gap: 8px; flex-shrink: 0; }
  /* keep "sign out" present + tappable, just compact */
  .site-nav__signout { font-size: 8.5px; padding: 7px 8px; }

  /* ============================================================
     Tape-transport tab bar (fixed, bottom)
     ============================================================ */
  .tab-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 150;
    display: flex;
    align-items: flex-start;
    justify-content: space-around;
    height: var(--tab-bar-h);
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
    font-family: var(--font-mono);
    background-image: var(--brush), linear-gradient(180deg, #15120d, #0a0807);
    border-top: 1px solid rgba(224, 162, 60, 0.18);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 -4px 16px -10px rgba(0, 0, 0, 0.8);
  }

  .tab-bar__tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 2px 6px;
    text-decoration: none;
  }
  .tab-bar__tab:hover { text-decoration: none; }

  .tab-bar__led {
    width: 14px;
    height: 3px;
    border-radius: 2px;
    background: var(--seg-off);
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.85);
  }

  .tab-bar__label {
    font-size: 8.5px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--ink-30);
  }

  .tab-bar__tab--active .tab-bar__led {
    background: var(--amber);
    box-shadow: 0 0 8px 1px rgba(224, 162, 60, 0.85);
  }
  .tab-bar__tab--active .tab-bar__label {
    color: #f0d9a8;
    text-shadow: 0 0 8px rgba(224, 162, 60, 0.6);
  }

  /* ============================================================
     Slim docked player (rides directly above the tab bar)
     ============================================================ */
  .persistent-player {
    height: var(--mobile-player-h);
    gap: 10px;
    padding: 4px 14px;
    overflow: visible;
  }
  /* Dock above the tab bar (keeps the JS-controlled display:none -> flex).
     Skip the slide-up enter animation here — it would sweep the player over the
     tab bar for 200ms before settling. */
  .persistent-player.player--visible {
    bottom: var(--tab-bar-h);
    animation: none;
  }

  /* Desktop-only chrome — hidden, but kept in the DOM for the controller. */
  .persistent-player__thumb,
  .persistent-player__wave,
  .persistent-player__volume-group,
  .persistent-player__eyebrow,
  .persistent-player__time {
    display: none;
  }

  .persistent-player__now {
    width: auto;
    flex: 1;
    gap: 9px;
    min-width: 0;
  }
  .persistent-player__vu { height: 16px; }
  .persistent-player__now-playing { font-size: 13px; }
  .persistent-player__subtitle { font-size: 8.5px; }

  .persistent-player__play-pause {
    width: 34px;
    height: 34px;
    font-size: 12px;
  }

  /* Seek collapses to a 2px progress hairline pinned to the player's bottom
     edge. The dim track + amber fill are pseudo-elements; the amber width is
     driven by --seek-progress, which audio_player_controller sets on
     #persistent-player (inherited down here — no JS change). The native range
     input stays on top, transparent, so tap/drag seek still fires. */
  .persistent-player__seek-group {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    flex: none;
    gap: 0;
    height: 12px;
    align-items: flex-end;
  }
  .persistent-player__wave-wrap {
    position: relative;
    flex: 1;
    height: 12px;
    min-width: 0;
  }
  .persistent-player__wave-wrap::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    background: #1a160f;
  }
  .persistent-player__wave-wrap::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    height: 2px;
    width: var(--seek-progress, 0%);
    background: var(--amber);
    box-shadow: 0 0 6px rgba(224, 162, 60, 0.7);
  }
  .persistent-player__seek { height: 12px; }
  .persistent-player__seek::-webkit-slider-thumb {
    width: 2px;
    height: 12px;
    background: transparent;
    box-shadow: none;
  }
  .persistent-player__seek::-moz-range-thumb {
    width: 2px;
    height: 12px;
    background: transparent;
    box-shadow: none;
  }

  /* ============================================================
     Catalog — chip-rail filters + single-column rows
     ============================================================ */
  .catalog__search-bar {
    margin: 16px 16px 12px;
    padding: 12px 13px;
    gap: 10px;
  }
  .catalog__search { font-size: 16px; } /* >=16px stops iOS focus-zoom */
  .catalog__search-tag { display: none; }

  /* Filters become a single horizontal scroll rail of compact selector chips. */
  .catalog__filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    align-items: center;
    gap: 8px;
    margin: 0 16px;
    padding: 12px 0 4px;
    scrollbar-width: none;
  }
  .catalog__filters::-webkit-scrollbar { display: none; }

  .catalog__filter-group {
    flex-shrink: 0;
    flex-direction: row;
    align-items: center;
  }
  .catalog__filter-label { display: none; }
  .catalog__filter-field { min-width: 0; }
  .catalog__filter-field select { padding: 8px 24px 8px 10px; }

  .catalog__sort { margin-left: 0; }
  .catalog__sort .catalog__filter-field { min-width: 0; }

  .catalog__toolbar { padding: 12px 16px 8px; gap: 10px; }
  .catalog__pagination { flex-wrap: wrap; padding: 16px 12px; gap: 6px; }

  /* Single-column rows. The 7 flat children are re-placed with grid areas
     (DOM order unchanged, so :first-child[data-song-id] ordering is intact). */
  .catalog__col-header { display: none; }

  .catalog__row {
    grid-template-columns: auto auto minmax(0, 1fr) auto auto;
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "vu type date fav play"
      "vu link link fav play"
      "vu dur  dur  fav play";
    column-gap: 9px;
    row-gap: 2px;
    padding: 13px 16px;
    align-items: center;
  }
  .catalog__quality-dot { grid-area: vu; align-self: center; }
  .catalog__row-type { grid-area: type; justify-self: start; }
  .catalog__row-date { grid-area: date; justify-self: start; align-self: center; }
  .catalog__row-main { grid-area: link; align-self: center; }
  .catalog__row-notes { display: none; }
  .catalog__row-duration { grid-area: dur; justify-self: start; text-align: left; }
  .catalog__row-fav { grid-area: fav; }
  .catalog__row-play-cell { grid-area: play; }

  /* ============================================================
     Performance detail — single scroll column, full-bleed thumbnail
     ============================================================ */
  .perf {
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
  .perf__left { padding: 16px; }
  /* Break the 16:9 well out to the screen edges. */
  .perf__well {
    margin: -16px -16px 18px;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
  .perf__right { padding: 20px 16px; }
  .perf__title { font-size: 26px; }
  /* Keep the About key/value list as rows (the 880px block would otherwise
     force it into the 2-up LCD grid). */
  .perf__details--meta { grid-template-columns: auto 1fr; }

  /* ============================================================
     My Collection — segmented switch toggles one section at a time
     ============================================================ */
  .dashboard { padding: 20px 16px; }
  .dashboard__title { font-size: 24px; }
  .dashboard__grid { grid-template-columns: 1fr; gap: 0; }

  .dashboard__switch {
    display: flex;
    gap: 7px;
    margin: 14px 0 4px;
  }
  .dashboard__switch-seg {
    flex: 1;
    text-align: center;
    padding: 9px;
    border-radius: var(--radius-control);
    background: linear-gradient(180deg, #16130e, #0d0a07);
    border: 1px solid rgba(0, 0, 0, 0.7);
    font-family: var(--font-mono);
    font-size: 9.5px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--ink-30);
    cursor: pointer;
  }
  .dashboard__switch-seg--active {
    background: linear-gradient(180deg, #2a1d0d, #180f07);
    border-color: rgba(224, 162, 60, 0.5);
    box-shadow: 0 0 14px -3px rgba(224, 162, 60, 0.4), inset 0 1px 0 rgba(224, 162, 60, 0.18);
    color: #f0d9a8;
    text-shadow: 0 0 7px rgba(224, 162, 60, 0.5);
  }

  .dashboard__section { display: none; }
  .dashboard__section--active { display: block; }

  /* ============================================================
     Songbook picker + song dossier — single-column reflow
     ============================================================ */
  .songbook__head { padding: 22px 16px 4px; }
  .songbook__title { font-size: 22px; }
  .songbook__search-bar { margin: 14px 16px; padding: 12px 13px; }
  .songbook__search { font-size: 16px; } /* >=16px stops iOS focus-zoom */
  .songbook__toolbar { padding: 4px 16px 10px; }
  .songbook__row { padding: 13px 16px; gap: 10px; }

  .journey__header { padding: 22px 16px 18px; gap: 16px; }
  .journey__title { font-size: 30px; }
  .journey__plates { gap: 14px; flex-wrap: wrap; }
  .journey__plate { flex: 0 0 calc(50% - 7px); text-align: left; } /* 2x2 */

  .journey__dial-panel { padding: 16px 16px 14px; }
  .journey__dial-row { gap: 12px; }
  .journey__dial-label,
  .journey__dial-range { display: none; } /* reclaim width for the well; Span is a plate */
  .journey__tick--lit { width: 1px; }
  /* Full-width well is the scrub target here (base sets touch-action:none);
     a little extra height makes the horizontal drag comfortable on touch. */
  .journey__dial-well { height: 72px; }

  /* Era strip becomes a horizontal chip rail (override the proportional grow). */
  .journey__era-strip { margin-left: 0; overflow-x: auto; scrollbar-width: none; }
  .journey__era-strip::-webkit-scrollbar { display: none; }
  .journey__era-seg { flex-grow: 0 !important; flex-shrink: 0; padding: 7px 12px; }

  .journey__body { grid-template-columns: 1fr; } /* stack rail above the list */
  .journey__rail { border-right: none; border-bottom: 1px solid var(--line); }
  .journey__panel { padding: 18px 16px; }
  .journey__gauge-name { width: 90px; }

  .journey__versions-head { padding: 14px 16px 10px; }
  .journey__col-header { display: none; }

  /* Single-column version row (DOM order preserved for data-song-id ordering). */
  .journey__row {
    grid-template-columns: auto auto minmax(0, 1fr) auto auto;
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "vu badge date fav play"
      "vu meta  meta fav play"
      "vu dur   dur  fav play";
    column-gap: 9px;
    row-gap: 2px;
    padding: 13px 16px;
    align-items: center;
  }
  .journey__row > .catalog__quality-dot { grid-area: vu; align-self: center; }
  .journey__badge { grid-area: badge; justify-self: start; }
  .journey__date { grid-area: date; justify-self: start; }
  .journey__meta { grid-area: meta; }
  .journey__dur { grid-area: dur; justify-self: start; text-align: left; }
  .journey__fav { grid-area: fav; }
  .journey__play-cell { grid-area: play; }
}
