/* ── Animations ── */
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
@keyframes badgeFadeIn { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: scale(1); } }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Mobile full player */
@media (max-width: 640px) {
  .fp-player-side { justify-content:flex-start; padding-bottom:env(safe-area-inset-bottom,0px); }
  .fp-header { padding:8px 14px 4px; }
  .fp-drag-handle { margin-top:7px; }
  .fp-art-wrap { flex:0 0 auto; width:100%; padding:4px 20px 0; overflow:visible; }
  .fp-art { width:min(76vw,42vh,320px); max-width:320px; }
  .fp-title { font-size: 18px; }
  .fp-artist { font-size: 13px; }
  .fp-actions .fp-vol-wrap { display: none; }
  .fp-info { padding:12px 20px 0; }
  .fp-progress { padding:10px 20px 0; }
  .fp-controls { gap:clamp(18px,8vw,42px); padding:8px 0; width:100%; }
  .fp-controls button { width:42px; height:42px; }
  .fp-controls .fp-play-btn { width:56px; height:56px; }
  .fp-actions { gap:8px; padding:0 14px 10px; flex-wrap:nowrap; justify-content:center; width:100%; }
  .fp-actions-group { gap:8px; }
  .fp-actions button { width:36px; height:36px; }
  #fpQueueTop,#fpActionsGroupDj,#fpDevicesBtn { display:none!important; }
  /* Keep one balanced five-action row on phones. Desktop-only group
     separators/output controls otherwise leave two orphan vertical lines. */
  .fp-actions > .fp-actions-divider,
  .fp-actions > .fp-actions-output,
  .fp-actions > .tv-actions-group { display:none!important; }
  .fp-actions > .fp-actions-listening {
    width:min(100%,330px); justify-content:center;
    gap:clamp(14px,6vw,28px);
  }
  .fp-actions > .fp-actions-listening > button { flex:0 0 40px; width:40px; height:40px; }
  .np-next { min-height:44px; margin-bottom:6px; padding:8px 12px; }
}

@media (max-width: 640px) and (max-height: 760px) {
  .fp-header { padding:8px 14px; }
  .fp-art-wrap { flex:0 0 auto; padding:0 20px; overflow:visible; }
  .fp-art { width:min(42vh,230px); }
  .fp-info { padding-top:10px; }
  .fp-progress { padding-top:8px; }
  .fp-controls { padding:6px 0; }
  .np-next { margin-bottom:7px; min-height:46px; }
}
/* Desktop full player — split layout */
@media (min-width: 641px) {
  .full-player { flex-direction: row; }
  .fp-player-side { flex: 1; max-width: none; }
  .fp-queue-side { display: none; }
  /* Match the mobile player's height-aware square artwork when a desktop
     window is shortened. A fixed desktop width could exceed the remaining
     flex height, so the wrapper clipped the bottom of the cover. */
  .fp-art { width:clamp(140px,32vh,280px); max-width:100%; height:auto; flex:0 0 auto; }
}

/* ── Responsive ── */
@media (max-width: 768px) {
  :root { --nav-height: 52px; }

  /* iOS zooms the page when a focused form control is rendered below 16px. */
  html { -webkit-text-size-adjust:100%; text-size-adjust:100%; }
  input, textarea, select { font-size:16px !important; }
  #profileGatePin { font-size:22px !important; }

  /* Hide top nav on mobile — bottom nav handles navigation */
  nav { display:flex; margin-left:0; height:calc(var(--nav-height) + env(safe-area-inset-top,0px)); padding:env(safe-area-inset-top,0px) 10px 0; background:transparent; border-bottom:0; box-shadow:none; backdrop-filter:none; -webkit-backdrop-filter:none; }
  nav > .nav-btn, nav > .downloads-btn, nav > .nav-account-icon, nav > .nav-spacer { display:none; }
  /* The avatar's desktop `.nav-account-icon.avatar-art` display rule is more
     specific. Force it out of Search and Playlists on mobile; account access
     remains available through Settings. */
  body[data-page="search"] nav > .nav-account-icon,
  body[data-page="library"] nav > .nav-account-icon { display:none!important; }
  .nav-search-cluster { position:relative; inset:auto; transform:none; width:100%; max-width:none; flex:1; gap:0; }
  .nav-search-cluster .nav-home-near-search, .nav-search-cluster .nav-more-wrap { display:none; }
  .nav-global-search { width:100%; height:40px; }

  /* Album-only collapsing search. Scrolling down turns the full-width control
     into a top-left search button; scrolling upward restores the normal bar. */
  body.album-detail-open nav,
  body.album-detail-open .nav-search-cluster,
  body.album-detail-open .nav-global-search {
    transition:width .28s cubic-bezier(.2,.75,.25,1),max-width .28s cubic-bezier(.2,.75,.25,1),
      transform .28s cubic-bezier(.2,.75,.25,1),opacity .2s ease,background-color .2s ease;
  }
  body.album-detail-open.album-search-compact nav {
    position:sticky; top:env(safe-area-inset-top,0px); left:auto; right:auto;
    width:48px; height:48px; padding:4px; margin-left:8px; z-index:120;
    background:transparent; pointer-events:none;
  }
  body.album-detail-open.album-search-compact .nav-search-cluster {
    flex:0 0 40px; width:40px; max-width:40px; pointer-events:auto;
  }
  body.album-detail-open.album-search-compact .nav-global-search {
    flex:0 0 40px; width:40px; height:40px; padding:0; gap:0;
    justify-content:center; border-radius:50%;
    background:color-mix(in srgb,var(--bg-card) 94%,transparent);
    box-shadow:0 8px 22px rgba(0,0,0,.32);
  }
  body.album-detail-open.album-search-compact .nav-global-search > svg { margin:0; }
  body.album-detail-open.album-search-compact .nav-global-search input,
  body.album-detail-open.album-search-compact .nav-global-search #searchClear,
  body.album-detail-open.album-search-compact .nav-global-search .nav-search-mic,
  body.album-detail-open.album-search-compact .nav-search-menu {
    width:0; min-width:0; flex:0 0 0; padding:0; margin:0; border:0;
    opacity:0; visibility:hidden; pointer-events:none; overflow:hidden;
  }

  /* Bottom nav bar */
  .bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
    background: rgba(10,10,15,0.95);
    backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
    border-top: 1px solid rgba(42,42,61,.6);
    display: flex; align-items: center; justify-content: space-around;
    height: var(--bottom-nav-height);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .bottom-nav .bnav-btn {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    background: none; border: none; color: var(--text-dim);
    font-size: 10px; font-weight: 600; cursor: pointer; padding: 8px 12px;
    border-radius: 12px; transition: all var(--transition);
    font-family: inherit; letter-spacing: 0.3px; min-width: 56px;
    position: relative;
  }
  .bottom-nav .bnav-btn svg { width: 22px; height: 22px; }
  .bottom-nav .bnav-btn.active { color: var(--accent); }
  .bottom-nav .bnav-btn .bnav-badge {
    position: absolute; top: 2px; right: 6px;
    background: var(--accent); color: #000; font-size: 9px; font-weight: 700;
    padding: 1px 5px; border-radius: 8px; min-width: 14px; text-align: center;
  }
  .bottom-nav .bnav-btn .bnav-badge:empty { display: none; }
  .bottom-nav .bnav-now-playing { color: var(--accent); }
  .bottom-nav .bnav-now-playing svg { animation: npPulse 2s ease-in-out infinite; }
  @keyframes npPulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }

  main {
    padding:16px 16px calc(var(--bottom-nav-height) + 16px);
  }
  body.player-active main { padding-bottom:calc(var(--bottom-nav-height) + 88px + 16px); }
  body.player-active .bottom-nav { bottom:0; }
  body.keyboard-open .bottom-nav { display: none !important; }
  body.keyboard-open .player-bar { display: none !important; }
  .player-bar { left:12px; right:12px; bottom:calc(var(--bottom-nav-height) + 8px); width:auto; height:62px; padding:7px 10px 11px; gap:8px; border:1px solid var(--border); border-radius:18px; cursor:pointer; }
  .player-bar .player-text { display:block; flex:1; min-width:0; }
  .player-progress-wrap { position:absolute; left:58px; right:92px; bottom:2px; display:flex; min-width:0; max-width:none; height:9px; gap:0; }
  .player-progress-bar { height:9px; }
  .player-progress-bar::after,.player-progress-fill { height:2px; }
  .player-time { display:none; }
  .player-volume { display: none !important; }
  /* Declutter the mini-bar: keep only play/pause + like + queue. All hidden
     controls remain available in the full player, so nothing is lost. */
  .player-actions { display:none!important; }
  .player-bar .player-img { width:40px; height:40px; }
  .player-controls { margin-left:auto; gap:0; }
  .player-controls button { width:30px; height:30px; }
  .player-controls .player-play-btn { width:42px; height:42px; }
  .bpm-filter { display:none!important; }
  #bnavDownloads,.bnav-now-playing { display:none !important; }
  .bottom-nav { left:0; right:0; bottom:0; width:100%; border:1px solid var(--border); border-left:0; border-right:0; border-bottom:0; border-radius:0; }
  .bottom-nav .bnav-btn { flex:1 1 0; min-width:0; padding-inline:4px; }
  .card-play-btn { opacity: .85; transform: translateY(0); }
  .card-dl-btn { opacity: .85; transform: translateY(0); }
  .card-radio-btn { opacity: .85; transform: translateY(0); }
  .card-fav-btn { opacity: .85; }
  .queue-panel { height: 80vh; border-radius: 0 0 16px 16px; }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
  }
  .skeleton-card { height: 220px; }

  .card-body { padding: 10px; }
  .card-title { font-size: 13px; }
  .card-sub { font-size: 12px; }

  /* Downloads panel: full screen on mobile */
  .downloads-panel {
    width: 100%; top: 0;
    border-radius: 0; border-left: none;
  }

  /* Modal: bottom sheet on mobile */
  .modal-overlay { align-items: flex-end; }
  .modal {
    width: 100%; max-width: 100%;
    border-radius: 20px 20px 0 0;
    padding: 28px 24px calc(28px + env(safe-area-inset-bottom, 0));
    transform: translateY(100%);
    max-height: 90vh; overflow-y: auto;
  }
  .modal-overlay.open .modal { transform: translateY(0); }

  .modal-img { width: 72px; height: 72px; }

  .page-title { font-size: 22px; }

  .search-input { padding: 14px 44px 14px 46px; font-size: 15px; }
  .btn-mic { width: 48px; height: 48px; }

  /* Playlist hero stacks on mobile */
  .playlist-hero {
    flex-direction: column; align-items: flex-start; padding: 18px;
  }
  .playlist-hero-actions {
    flex-direction: row; flex-wrap: wrap; align-items: center; width: 100%; gap: 8px;
  }
  .playlist-hero-actions .btn-download { padding: 10px 16px !important; font-size: 13px; }
  .playlist-hero-actions .btn-download:nth-child(-n+2) { flex: 1; }
  .playlist-hero-actions .btn-download:nth-child(n+3) { flex: 0 0 auto; }
  #libraryDetail .playlist-hero { display:grid; grid-template-columns:100px minmax(0,1fr); align-items:center; gap:16px; }
  #libraryDetail .playlist-hero-info { align-self:center; }
  #libraryDetail .library-hero-actions { grid-column:1/-1; display:flex; flex-direction:column; align-items:stretch; }
  #libraryDetail .album-icon-actions { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:8px; }
  #libraryDetail .album-action-icon { width:100%; height:48px; border-radius:12px; }
  #libraryDetail .library-hero-actions #downloadLibPlaylist { width:100%; flex:none; }
  #libraryTracks .card-drag-handle { opacity:.85!important; }

  /* Recognize result responsive */
  .recognize-result .rr-header { flex-wrap: wrap; }
  .recognize-result .rr-actions { width: 100%; margin-top: 12px; margin-left: 0; }
}

/* Hide bottom nav on desktop */
@media (min-width: 769px) {
  .bottom-nav { display: none; }
}

@media (max-width:520px) {
  .player-bar { padding-inline:8px; gap:6px; }
  .player-bar .player-img { width:38px; height:38px; }
  .player-bar .player-title { font-size:12px; }
  .player-bar .player-artist { font-size:10px; }
  .player-controls button { width:30px; height:30px; }
  .player-controls .player-play-btn { width:38px; height:38px; }
  .player-controls { gap:0; }
  .player-progress-wrap { left:54px; right:88px; min-width:0; gap:0; }
}

/* Touch devices have no hover: reveal card controls permanently so the
   quick-add "+", download/radio/play and the drag handle are discoverable. */
@media (hover: none) {
  .card-play-btn, .card-dl-btn, .card-radio-btn, .card-addpl-btn, .card-fav-btn, .card-drag-handle { opacity: 1 !important; transform: none !important; }
}

/* The compact mobile navigation is intentionally last so legacy full-width
   mobile-bar rules above cannot override the floating, theme-aware layout. */
@media (max-width:768px) {
  .bottom-nav {
    left:50%; right:auto; bottom:calc(6px + env(safe-area-inset-bottom,0px));
    width:min(calc(100% - 42px),348px); height:58px; padding:4px;
    transform:translateX(-50%); justify-content:space-between;
    border:1px solid rgba(255,255,255,.36);
    border-radius:999px;
    background:
      radial-gradient(110% 130% at 10% -20%,rgba(255,255,255,.34),transparent 48%),
      radial-gradient(85% 120% at 88% 130%,color-mix(in srgb,var(--accent) 24%,transparent),transparent 62%),
      linear-gradient(155deg,rgba(255,255,255,.22),rgba(255,255,255,.07) 46%,rgba(0,0,0,.18)),
      color-mix(in srgb,var(--bg-card) 58%,transparent);
    box-shadow:
      inset 0 1.5px 0 rgba(255,255,255,.52),
      inset 0 -1.5px 0 rgba(0,0,0,.28),
      inset 14px 0 28px rgba(255,255,255,.035),
      0 14px 38px rgba(0,0,0,.5),
      0 0 22px color-mix(in srgb,var(--accent) 24%,transparent);
    backdrop-filter:blur(34px) saturate(1.8) brightness(1.08); -webkit-backdrop-filter:blur(34px) saturate(1.8) brightness(1.08);
    overflow:hidden;
    transition:background .2s ease,box-shadow .2s ease;
  }
  .bottom-nav::before {
    content:''; position:absolute; inset:1px 4px auto; height:48%; border-radius:999px;
    background:linear-gradient(180deg,rgba(255,255,255,.28),rgba(255,255,255,.07) 48%,transparent); opacity:.8; pointer-events:none;
    mask-image:linear-gradient(90deg,transparent,black 12%,black 88%,transparent);
    -webkit-mask-image:linear-gradient(90deg,transparent,black 12%,black 88%,transparent);
  }
  .bottom-nav::after {
    content:''; position:absolute; left:8%; right:8%; bottom:1px; height:20%; border-radius:0 0 999px 999px;
    background:radial-gradient(80% 120% at 50% 100%,color-mix(in srgb,var(--accent) 18%,rgba(255,255,255,.14)),transparent 72%);
    filter:blur(2px); pointer-events:none;
  }
  .bottom-nav .bnav-btn { z-index:1; }
  .bottom-nav .bnav-btn {
    flex:1 1 0; min-width:0; height:50px; padding:3px 2px; gap:1px; border-radius:999px;
    font-size:0; justify-content:center; color:var(--text-muted);
    transition:background .2s ease,color .2s ease;
  }
  .bottom-nav .bnav-btn.active {
    color:var(--accent);
    border:1px solid rgba(255,255,255,.34);
    background:
      radial-gradient(100% 120% at 25% 0,rgba(255,255,255,.30),transparent 55%),
      linear-gradient(145deg,color-mix(in srgb,var(--accent) 26%,rgba(255,255,255,.12)),color-mix(in srgb,var(--accent) 12%,rgba(0,0,0,.12)));
    box-shadow:inset 0 1px 0 rgba(255,255,255,.46),inset 0 -1px 0 rgba(0,0,0,.22),0 5px 14px rgba(0,0,0,.28),0 0 14px var(--accent-dim);
    text-shadow:0 1px 7px color-mix(in srgb,var(--accent) 42%,transparent);
  }
  .bottom-nav .bnav-btn svg { width:23px; height:23px; flex:0 0 auto; transition:width .28s ease,height .28s ease; }
  .bottom-nav .bnav-label { display:block; max-height:14px; opacity:1; color:currentColor; font-size:9px; font-weight:700; line-height:11px; transform:translateY(0); transition:max-height .24s ease,opacity .2s ease,transform .24s ease; }
  body.player-shell main { padding-bottom:calc(140px + env(safe-area-inset-bottom,0px)); }
  body.player-shell .player-bar { bottom:calc(68px + env(safe-area-inset-bottom,0px)); }
  .bpm-filter { display:none!important; }
  .track-playing-list .song-row.now-playing .playlist-playing-indicator i { animation:playlist-playing-bars .8s ease-in-out infinite alternate!important; }

  html[data-amoled="on"] body,
  html[data-amoled="on"] main { background:#000!important; }
  html[data-amoled="on"] .mobile-theme-card,
  html[data-amoled="on"] .mobile-display-card,
  html[data-amoled="on"] #pageSettings.settings-compact .profile-card,
  html[data-amoled="on"] #pageSettings.settings-compact .account-profile-hero,
  html[data-amoled="on"] .bottom-nav { background:radial-gradient(110% 130% at 10% -20%,rgba(255,255,255,.25),transparent 48%),linear-gradient(155deg,rgba(255,255,255,.14),rgba(255,255,255,.04) 44%,rgba(0,0,0,.34)),rgba(5,5,5,.66)!important; }

  html[data-mobile-nav-glow="off"] .bottom-nav { box-shadow:inset 0 1.5px 0 rgba(255,255,255,.52),inset 0 -1.5px 0 rgba(0,0,0,.28),inset 14px 0 28px rgba(255,255,255,.035),0 10px 28px rgba(0,0,0,.45)!important; }
  html[data-mobile-nav-mode="classic"] .bottom-nav {
    left:0; right:0; bottom:0; width:100%; height:62px; padding:4px 10px env(safe-area-inset-bottom,0px);
    transform:none; border-right:0; border-bottom:0; border-left:0; border-radius:0;
  }
  html[data-mobile-nav-mode="classic"] body.player-shell .player-bar { bottom:calc(62px + env(safe-area-inset-bottom,0px)); }
}
