/* Phone-first navigation and playback layout */
.mobile-nav, .mobile-song-menu { display: none; }

@media (max-width: 700px) {
  /* Keep the app frame fixed. Only .content-area can scroll vertically. */
  html, body {
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
    touch-action: pan-y;
  }
  .main-screen { height: 100vh; }
  .sidebar { display: none; }
  .content-area {
    min-width: 0;
    width: 100%;
    overflow-x: hidden;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
  }
  .content-header {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: .75rem;
    padding: .85rem 1rem .7rem;
  }
  .content-header h1 { font-size: 1.35rem; }
  .search-wrap { display: block; grid-column: 1 / -1; }
  .search-wrap input { display: block; width: 100%; height: 42px; font-size: 16px; }
  .queue-btn { display: none; }

  .view-container { padding: 1rem 1rem calc(190px + env(safe-area-inset-bottom)); }
  .song-item-row { min-height: 68px; padding: .5rem .15rem; gap: .35rem; }
  .song-meta-clickable { gap: .7rem; }
  .track-thumb { width: 48px; height: 48px; }
  .song-actions { flex: 0 0 auto; }
  .song-menu-btn { display: none; }
  .like-btn { min-width: 44px; min-height: 44px; font-size: 1.35rem; }
  .mobile-song-menu { position: relative; display: block; }
  .mobile-more-btn { width: 44px; height: 44px; border-radius: 50%; color: #fff; font-size: 1.55rem; line-height: 1; }
  .mobile-more-btn:active { background: #303030; }
  .mobile-song-popover { position: absolute; z-index: 50; right: 0; top: calc(100% + 4px); width: 164px; padding: .35rem; border: 1px solid #3d3d3d; border-radius: 10px; background: #292929; box-shadow: 0 12px 25px rgba(0,0,0,.45); }
  .mobile-song-popover button { width: 100%; padding: .75rem; text-align: left; border-radius: 7px; font-size: .82rem; font-weight: 700; }
  .mobile-song-popover button:active { background: #404040; }
  .mobile-song-popover [data-remove-from-playlist] { color: #ff9aa9; }
  .library-hero { padding: 1.45rem; margin-bottom: 1.5rem; border-radius: 14px; }
  .library-hero h2 { font-size: 2rem; }
  .events-hero { padding: 1.45rem; margin-bottom: 1.5rem; border-radius: 14px; }
  .events-hero h2 { font-size: 2rem; }
  .library-section { margin: 1.6rem 0; }
  .playlist-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
  .playlist-card { padding: .75rem; min-width: 0; }
  .playlist-card-cover { margin-bottom: .65rem; }
  .playlist-card-play { display: none; }
  .collection-hero { margin: -1rem -1rem 1.25rem; padding: 1rem; gap: 1rem; min-height: 190px; }
  .collection-hero > img, .collection-hero .collection-cover { width: 105px; height: 105px; flex-basis: 105px; }
  .collection-hero .event-cover-placeholder.collection-cover { width: 105px; height: 105px; flex-basis: 105px; }
  .collection-hero h2 { font-size: 1.75rem; overflow-wrap: anywhere; }

  .player {
    bottom: calc(64px + env(safe-area-inset-bottom));
    height: 64px;
    padding: .45rem .75rem;
    gap: .45rem;
    z-index: 900;
    flex-direction: row;
    justify-content: space-between;
  }
  .now-playing { width: auto; min-width: 0; max-width: none; flex: 1; gap: .55rem; text-align: left; }
  .now-playing img { width: 42px !important; height: 42px !important; }
  .now-playing > div { min-width: 0; }
  .now-playing strong { font-size: .84rem; }
  .now-playing span { font-size: .72rem; }
  .transport { width: auto; min-width: 0; }
  .transport .controls { gap: .15rem; }
  .transport .control-btn { width: 34px; height: 34px; min-width: 34px; padding: 0; }
  .transport #shuffleButton, .transport #repeatButton { display: none; }
  .transport .play-primary { width: 40px !important; height: 40px !important; min-width: 40px !important; min-height: 40px !important; }
  .seek-wrap { display: none; }
  .volume-wrap { width: auto !important; display: flex; align-items: center; }
  .volume-wrap .volume-icon, .volume-wrap .custom-slider, #expandPlayerButton { display: none; }
  .now-playing-screen { justify-content: flex-start; padding-top: max(4.5rem, env(safe-area-inset-top)); }
  .now-playing-screen > img { width: min(86vw, 430px); }
  .now-playing-details, .now-playing-seek { width: min(86vw, 430px); }
  .now-playing-controls { width: 100%; gap: .45rem; }
  .expanded-control { width: 48px; height: 48px; border-radius: 15px; font-size: 1.1rem; }
  .now-playing-controls #nowPlayingRepeatButton { width: 76px; }
  .now-playing-play { width: 56px; height: 56px; }

  .mobile-nav {
    position: fixed;
    inset: auto 0 0;
    height: calc(64px + env(safe-area-inset-bottom));
    padding: 5px 6px env(safe-area-inset-bottom);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    background: rgba(16, 19, 18, .98);
    border-top: 1px solid #303030;
    z-index: 950;
  }
  .mobile-nav:has(#mobileAdminTabBtn.hidden) { grid-template-columns: repeat(4, 1fr); }
  .mobile-nav > button, .mobile-nav-more > button {
    width: 100%;
    min-width: 0;
    min-height: 52px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: #aab4ad;
    border-radius: 10px;
  }
  .mobile-nav button span { font-size: 1.35rem; line-height: 1; }
  .mobile-nav button svg { width: 22px; height: 22px; fill: currentColor; }
  .mobile-nav button small { font-size: .65rem; font-weight: 700; }
  .mobile-nav > button.active { color: var(--spotify-green); background: rgba(30, 215, 96, .12); }
  .mobile-nav button:active { transform: scale(.96); }
  .mobile-nav-more { position: relative; min-width: 0; height: 52px; }
  .mobile-more-popover { position: absolute; right: 0; bottom: calc(100% + 8px); width: 170px; padding: .35rem; border: 1px solid #3d3d3d; border-radius: 12px; background: #292929; box-shadow: 0 12px 28px rgba(0,0,0,.5); }
  .mobile-more-popover button { display: block; width: 100%; padding: .8rem; text-align: left; border-radius: 8px; color: #fff; font-weight: 700; }
  .mobile-more-popover button:active { background: #414141; }

  .queue-sidebar { position: fixed; inset: 0; width: 100%; max-width: none; z-index: 1100; padding-bottom: env(safe-area-inset-bottom); }
  .queue-resize-handle { display: none; }
  .queue-items-container { padding: 1rem; }
  .queue-row { gap: .7rem; padding: .65rem .4rem; }
  .queue-row button[data-queue-action="up"], .queue-row button[data-queue-action="down"] { display: none !important; }
  .queue-more-menu { display: block; }
  .queue-row .queue-remove { display: inline-flex !important; align-items: center; justify-content: center; gap: .32rem; width: auto; min-width: 74px; height: 36px; padding: 0 .65rem; flex: 0 0 auto; border-radius: 999px; color: #ffabb7; background: rgba(255,91,118,.12); font-size: .76rem; font-weight: 800; }
  .queue-row .queue-remove-label { display: inline; }
  .queue-song-info { min-width: 0; display: grid; gap: .18rem; }
  .queue-song-info strong, .queue-song-info small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .queue-song-info small { color: #aab4ad; }
  .queue-dragging, .queue-dragging * { user-select: none; -webkit-user-select: none; }
  .fullscreen-button { display: inline-block; margin-top: 1rem; padding: .7rem 1.25rem; border: 1px solid #747474; border-radius: 999px; color: #fff; font-weight: 800; }
  .admin-card .logout-button { margin-left: .5rem; }
  .admin-card { padding: 1.35rem; }
  .event-admin-summary { grid-template-columns: 1fr; gap: .6rem; }
  .event-admin-summary > div { grid-template-columns: 52px 1fr; align-items: center; padding: .85rem 1rem; }
  .event-admin-summary strong { font-size: 1.55rem; }
  .event-cover-alert, .event-review { padding: 1rem; }
  .event-review-row { grid-template-columns: 1fr; gap: .7rem; padding: .85rem .2rem; }
  .event-review-actions { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; padding-bottom: .25rem; scrollbar-width: none; }
  .event-review-actions::-webkit-scrollbar { display: none; }
  .event-review-actions button { flex: 0 0 auto; min-height: 38px; }
  .event-review-commit { justify-content: flex-start; flex-wrap: wrap; }
  .event-review-commit button { min-height: 40px; }
  .event-editor, .ignored-event-songs { padding: 1rem; }
  .event-editor > .section-heading { align-items: flex-start; }
  .event-editor > .section-heading > span { display: none; }
  .event-editor-panel { padding: .75rem; }
  .event-editor-heading { align-items: center; }
  .event-editor-cover { width: 64px; height: 64px; flex-basis: 64px; }
  .event-editor-columns { grid-template-columns: 1fr; }
  .event-editor-song-list { max-height: 330px; }
  .ignored-event-songs .section-heading, .event-review .section-heading { align-items: flex-start; gap: .5rem; }
  .alphabet-browser { gap: .3rem; }
  .alphabet-section { scroll-margin-top: 0; margin-bottom: .8rem; }
  .alphabet-section > h2 { top: var(--content-header-height, 64px); padding: .25rem .35rem; font-size: .82rem; }
  .alphabet-rail {
    top: calc(var(--content-header-height, 64px) + .5rem);
    gap: 0;
    max-height: calc(100vh - 250px);
    padding: .2rem .1rem;
    border-radius: 12px;
  }
  .alphabet-rail button {
    width: 20px;
    height: 20px;
    flex-basis: 20px;
    font-size: .62rem;
  }
  #mobileSongsTabCount { color: var(--spotify-green); font-size: .65rem; line-height: inherit; }
}

/* Phone finish pass */
@media (max-width: 700px) {
  .main-screen, .app-shell { height: 100dvh; }
  .content-header { min-height: 0; padding: max(.8rem, env(safe-area-inset-top)) 1rem .7rem; gap: .65rem; border-bottom-color: rgba(255,255,255,.08); background: rgba(11,14,13,.97); backdrop-filter: blur(20px) saturate(130%); }
  .header-title-group { min-width: 0; gap: .55rem; }
  .header-title-group h1 { font-size: 1.3rem; }
  .connection-status { font-size: .58rem; letter-spacing: .05em; }
  .connection-status i { width: 6px; height: 6px; }
  .search-wrap input { min-height: 44px; padding-left: 2.55rem; border-radius: 14px; }
  /* Clear the floating mini-player and the phone navigation on every screen. */
  .view-container { padding: 1rem 1rem calc(190px + env(safe-area-inset-bottom)); }

  .songs-overview { grid-template-columns: 1fr; gap: 1.1rem; margin-bottom: 1.4rem; padding: 1.25rem; border-radius: 20px; }
  .songs-overview h2 { font-size: clamp(1.8rem, 9vw, 2.45rem); }
  .songs-overview p:last-child { font-size: .85rem; line-height: 1.45; }
  .quick-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; }
  .quick-action { min-height: 54px; gap: .5rem; padding: .55rem; border-radius: 14px; font-size: .76rem; }
  .quick-action span { width: 30px; height: 30px; border-radius: 9px; }

  .recent-strip { margin-bottom: 1.45rem; }
  .recent-track-list { display: flex; gap: .65rem; margin: 0 -1rem; padding: 0 1rem .35rem; overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none; }
  .recent-track-list::-webkit-scrollbar { display: none; }
  .recent-track { min-width: min(78vw, 285px); grid-template-columns: 48px minmax(0, 1fr) 28px; flex: 0 0 auto; scroll-snap-align: start; }

  .alphabet-browser { grid-template-columns: minmax(0, 1fr) 23px; }
  .alphabet-section { contain-intrinsic-size: auto 620px; }
  .song-item-row { min-height: 64px; border-bottom-color: rgba(255,255,255,.055); }
  .song-meta strong { font-size: .88rem; }
  .song-meta small { font-size: .74rem; }
  .mobile-more-btn { color: #c8d0cb; }
  .mobile-song-popover {
    position: fixed;
    inset: auto 1rem calc(142px + env(safe-area-inset-bottom)) 1rem;
    z-index: 1400;
    width: auto;
    padding: .5rem;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 18px;
    background: rgba(27,32,30,.98);
    box-shadow: 0 22px 60px rgba(0,0,0,.6);
    backdrop-filter: blur(20px);
  }
  .mobile-song-popover button { min-height: 46px; border-radius: 12px; font-size: .9rem; }
  .mobile-song-popover button + button { border-top: 1px solid rgba(255,255,255,.07); }
  .mobile-song-action-sheet { position: fixed; inset: 0; z-index: 1600; display: grid; align-items: end; }
  .action-sheet-backdrop { position: absolute; inset: 0; width: 100%; height: 100%; background: rgba(0,0,0,.64); backdrop-filter: blur(5px); }
  .action-sheet-panel { position: relative; display: grid; gap: .35rem; padding: 1rem 1rem max(1rem, env(safe-area-inset-bottom)); border: 1px solid rgba(255,255,255,.12); border-radius: 24px 24px 0 0; background: #1a1f1d; box-shadow: 0 -22px 60px rgba(0,0,0,.58); }
  .action-sheet-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .35rem .35rem .75rem; }
  .action-sheet-heading > div { min-width: 0; }
  .action-sheet-heading h2, .action-sheet-heading small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .action-sheet-heading h2 { margin-top: .15rem; font-size: 1.2rem; }
  .action-sheet-heading small { color: var(--muted); }
  .action-sheet-heading button { width: 40px; height: 40px; flex: 0 0 auto; border-radius: 50%; color: #fff; background: rgba(255,255,255,.09); font-size: 1.4rem; }
  .action-sheet-panel > button:not(.action-sheet-backdrop) { min-height: 50px; padding: .75rem 1rem; border-radius: 13px; color: #fff; background: rgba(255,255,255,.065); text-align: left; font-weight: 800; }
  .action-sheet-panel > button:active { background: rgba(109,242,124,.14); }
  .action-sheet-panel > .danger-action { color: #ff9bac; }

  .playlist-card { border-radius: 14px; }
  .playlist-card strong { min-height: 2.45em; line-height: 1.2; white-space: normal; overflow-wrap: anywhere; }
  .playlist-card small { min-height: 2.3em; line-height: 1.15; }
  .event-card .playlist-card-play { display: grid; height: 36px; margin-top: .55rem; }
  .event-card .event-lock { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .music-upload { display: grid; gap: 1rem; padding: 1rem; }
  .music-upload h2 { font-size: 1.3rem; }
  .upload-controls { min-width: 0; grid-template-columns: 1fr; }
  .upload-controls button, .upload-picker { width: 100%; }
  .upload-controls small { grid-column: auto; }

  .player { height: 66px; bottom: calc(62px + env(safe-area-inset-bottom)); padding: .45rem .65rem; border-radius: 14px 14px 0 0; }
  .now-playing img { border-radius: 9px !important; }
  .transport .controls { gap: .08rem; }
  .transport .control-btn { border: 0 !important; background: transparent !important; }
  .transport .play-primary { background: var(--green) !important; }
  .mobile-nav { height: calc(62px + env(safe-area-inset-bottom)); background: rgba(10,13,12,.96); backdrop-filter: blur(18px); }
  .mobile-nav > button.active { color: var(--green); background: rgba(109,242,124,.1); }
  .mobile-nav button small b { color: var(--green); font: inherit; }
  .mobile-more-popover { width: 190px; border-radius: 16px; background: #1b201e; }

  .queue-sidebar { height: 100dvh; background: #0e1110; }
  .queue-header { padding-top: max(1rem, env(safe-area-inset-top)); }
  .queue-row:hover { transform: none; }
  .queue-row .queue-remove { min-width: 72px; }
  .now-playing-screen { min-height: 100dvh; padding-inline: 1.25rem; background: radial-gradient(circle at 50% -5%, rgba(109,242,124,.36), transparent 48%), #0b0e0d; }
  .close-now-playing { top: max(1rem, env(safe-area-inset-top)); }
  .now-playing-screen > img { border-radius: 22px; }
  .now-playing-details strong { font-size: 1.35rem; }
  .now-playing-controls { margin-top: auto; padding-bottom: max(1.2rem, env(safe-area-inset-bottom)); }

  .toast-host { width: calc(100% - 2rem); bottom: calc(142px + env(safe-area-inset-bottom)) !important; }
  .toast { width: fit-content; max-width: 100%; min-width: 0 !important; font-size: .82rem !important; }
}

/* Keep the Songs welcome area readable and separate from its controls. */
@media (max-width: 700px) {
  .songs-overview {
    margin-bottom: 1.6rem !important;
    padding: .25rem 0 0 !important;
  }
  .songs-overview > div:first-child { margin: 0 0 1rem !important; }
  .songs-overview h2 {
    display: block;
    padding: 0 .1rem;
    font-size: 1.5rem !important;
    line-height: 1.2 !important;
    letter-spacing: -.03em !important;
    overflow: visible !important;
  }
  .quick-actions {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .6rem !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }
  .quick-action {
    min-width: 0;
    min-height: 52px !important;
    padding: .45rem .55rem !important;
    border-radius: 14px !important;
    font-size: .78rem !important;
    white-space: normal !important;
    text-align: left;
  }
}

@media (max-width: 390px) {
  .connection-status { display: none; }
  .quick-action { font-size: .7rem; }
  .quick-action span { width: 27px; height: 27px; }
  .playlist-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
  .playlist-card { padding: .62rem; }
}

/* Cleaner phone hierarchy: search first, then compact listening shortcuts. */
@media (max-width: 700px) {
  .content-header {
    grid-template-columns: minmax(0, 1fr);
    padding: max(.72rem, env(safe-area-inset-top)) 1rem .8rem;
    gap: .65rem;
    border-bottom: 1px solid rgba(255,255,255,.075);
    background: #0b0e0d;
    backdrop-filter: none;
    box-shadow: 0 8px 24px rgba(0,0,0,.22);
  }
  .header-title-group { justify-content: space-between; min-height: 28px; }
  .header-title-group h1 { font-size: 1.22rem; letter-spacing: -.035em; }
  .connection-status { display: none; }

  .search-wrap { position: relative; grid-column: auto; width: 100%; margin: 0; }
  .search-wrap::before {
    content: '';
    position: absolute;
    z-index: 1;
    left: 17px;
    top: 50%;
    width: 10px;
    height: 10px;
    border: 2px solid #9ca8a1;
    border-radius: 50%;
    transform: translateY(-62%);
    pointer-events: none;
  }
  .search-wrap::after {
    content: '';
    position: absolute;
    z-index: 1;
    left: 28px;
    top: 57%;
    width: 7px;
    height: 2px;
    border-radius: 2px;
    background: #9ca8a1;
    transform: rotate(45deg);
    transform-origin: left center;
    pointer-events: none;
  }
  .search-wrap input {
    height: 44px;
    min-height: 44px;
    padding: .65rem 1rem .65rem 2.65rem;
    border: 1px solid rgba(255,255,255,.09);
    border-radius: 999px;
    color: #fff;
    background: #191e1c;
    background-image: none;
    box-shadow: inset 0 1px rgba(255,255,255,.035);
  }
  .search-wrap input::placeholder { color: #8e9992; opacity: 1; }
  .search-wrap input:focus {
    color: #fff;
    border-color: rgba(109,242,124,.55);
    background: #202622;
    box-shadow: 0 0 0 3px rgba(109,242,124,.12);
  }

  .view-container { padding-top: 1.15rem; }
  .songs-overview {
    display: block;
    margin: 0 0 1.35rem;
    padding: 0;
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
  }
  .songs-overview > div:first-child { margin-bottom: .75rem; }
  .songs-overview .eyebrow, .songs-overview p:last-child { display: none; }
  .songs-overview h2 {
    margin: 0;
    font-size: 1.18rem;
    line-height: 1.25;
    letter-spacing: -.025em;
  }
  .quick-actions {
    display: flex;
    gap: .55rem;
    margin: 0 -1rem;
    padding: 0 1rem .3rem;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }
  .quick-actions::-webkit-scrollbar { display: none; }
  .quick-action {
    min-height: 46px;
    flex: 0 0 auto;
    gap: .48rem;
    padding: .4rem .78rem .4rem .45rem;
    border-color: rgba(255,255,255,.085);
    border-radius: 999px;
    background: #191e1c;
    box-shadow: none;
    scroll-snap-align: start;
    font-size: .76rem;
    white-space: nowrap;
  }
  .quick-action span {
    width: 29px;
    height: 29px;
    border-radius: 50%;
    background: rgba(255,255,255,.075);
  }
  .quick-action-primary { color: #071008; border-color: var(--green); background: var(--green); }
  .quick-action-primary span { background: rgba(0,0,0,.1); }
  .quick-action:hover { transform: none; }

  .recent-strip { margin-top: 0; }
  .recent-strip .section-heading { margin-bottom: .65rem; }
  .recent-strip .section-heading h2 { font-size: 1.18rem; }
  .recent-strip .eyebrow { margin-bottom: .15rem; font-size: .64rem; }
}

@media (max-width: 390px) {
  .quick-action { font-size: .74rem; }
  .quick-action span { width: 28px; height: 28px; }
}

/* The phone search belongs to the top of the page; it must not cover songs. */
@media (max-width: 700px) {
  .content-header {
    display: flex;
    position: relative;
    top: auto;
    z-index: 30;
    flex: 0 0 auto;
    min-height: 54px;
    padding: max(.72rem, env(safe-area-inset-top)) 1rem .72rem;
    box-shadow: none;
  }
  #searchWrap { display: none !important; }
  .mobile-search-slot {
    display: block;
    position: relative;
    z-index: 25;
    flex: 0 0 auto;
    width: 100%;
    padding: .55rem 1rem .8rem;
    border-bottom: 1px solid rgba(255,255,255,.075);
    background: #0b0e0d;
  }
  .mobile-search-slot.hidden { display: none; }
  .mobile-search-slot .search-wrap { display: block; width: 100%; }
  .mobile-search-slot .search-wrap input { width: 100%; }
  .view-container { padding-top: 1rem; }
  .alphabet-section { scroll-margin-top: 0; }
  .alphabet-section > h2 { top: var(--content-header-height, 64px); }
  .alphabet-rail {
    top: calc(var(--content-header-height, 64px) + .5rem);
    max-height: calc(100dvh - 165px);
  }
}
